2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2014-10-14 20:15:21 +00:00
|
|
|
|
2001-08-18 01:04:47 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIRootBox.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIContent.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2001-09-10 07:34:54 +00:00
|
|
|
#include "nsMenuPopupFrame.h"
|
2013-06-10 21:00:00 +00:00
|
|
|
#include "nsView.h"
|
2013-09-23 11:55:35 +00:00
|
|
|
#include "mozilla/AppUnits.h"
|
2013-09-20 10:21:03 +00:00
|
|
|
#include "mozilla/dom/DOMRect.h"
|
2014-10-14 20:15:21 +00:00
|
|
|
#include "mozilla/dom/PopupBoxObject.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/Event.h"
|
|
|
|
#include "mozilla/dom/PopupBoxObjectBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-09-20 10:21:03 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(PopupBoxObject, BoxObject)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(PopupBoxObject, BoxObject)
|
|
|
|
NS_INTERFACE_MAP_BEGIN(PopupBoxObject)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(BoxObject)
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
PopupBoxObject::PopupBoxObject()
|
2001-08-18 01:04:47 +00:00
|
|
|
{
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
PopupBoxObject::~PopupBoxObject()
|
|
|
|
{
|
|
|
|
}
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
nsIContent* PopupBoxObject::GetParentObject() const
|
|
|
|
{
|
|
|
|
return BoxObject::GetParentObject();
|
|
|
|
}
|
2001-08-18 01:04:47 +00:00
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
JSObject* PopupBoxObject::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-10-14 20:15:21 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return PopupBoxObjectBinding::Wrap(aCx, this, aGivenProto);
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsPopupSetFrame*
|
2014-10-14 20:15:21 +00:00
|
|
|
PopupBoxObject::GetPopupSetFrame()
|
2001-08-18 01:04:47 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIRootBox* rootBox = nsIRootBox::GetRootBox(GetPresShell(false));
|
2001-08-18 01:04:47 +00:00
|
|
|
if (!rootBox)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
return rootBox->GetPopupSetFrame();
|
2005-12-31 23:34:46 +00:00
|
|
|
}
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::HidePopup(bool aCancel)
|
2005-12-31 23:34:46 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2014-10-14 20:15:21 +00:00
|
|
|
if (pm && mContent) {
|
2014-09-24 16:15:49 +00:00
|
|
|
pm->HidePopup(mContent, false, true, false, aCancel);
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
2001-08-18 01:04:47 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::ShowPopup(Element* aAnchorElement,
|
|
|
|
Element& aPopupElement,
|
|
|
|
int32_t aXPos, int32_t aYPos,
|
|
|
|
const nsAString& aPopupType,
|
|
|
|
const nsAString& aAnchorAlignment,
|
|
|
|
const nsAString& aPopupAlignment)
|
2001-08-18 01:04:47 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2008-08-18 17:58:13 +00:00
|
|
|
if (pm && mContent) {
|
2007-07-04 15:49:38 +00:00
|
|
|
nsCOMPtr<nsIContent> anchorContent(do_QueryInterface(aAnchorElement));
|
|
|
|
nsAutoString popupType(aPopupType);
|
|
|
|
nsAutoString anchor(aAnchorAlignment);
|
|
|
|
nsAutoString align(aPopupAlignment);
|
|
|
|
pm->ShowPopupWithAnchorAlign(mContent, anchorContent, anchor, align,
|
2014-10-14 20:15:21 +00:00
|
|
|
aXPos, aYPos,
|
|
|
|
popupType.EqualsLiteral("context"));
|
2007-06-29 22:15:59 +00:00
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::OpenPopup(Element* aAnchorElement,
|
|
|
|
const nsAString& aPosition,
|
|
|
|
int32_t aXPos, int32_t aYPos,
|
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aAttributesOverride,
|
|
|
|
Event* aTriggerEvent)
|
2007-07-04 15:49:38 +00:00
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2008-08-18 17:58:13 +00:00
|
|
|
if (pm && mContent) {
|
2007-07-04 15:49:38 +00:00
|
|
|
nsCOMPtr<nsIContent> anchorContent(do_QueryInterface(aAnchorElement));
|
|
|
|
pm->ShowPopup(mContent, anchorContent, aPosition, aXPos, aYPos,
|
2011-10-17 14:59:28 +00:00
|
|
|
aIsContextMenu, aAttributesOverride, false, aTriggerEvent);
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::OpenPopupAtScreen(int32_t aXPos, int32_t aYPos,
|
|
|
|
bool aIsContextMenu,
|
|
|
|
Event* aTriggerEvent)
|
2007-07-04 15:49:38 +00:00
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2008-08-18 17:58:13 +00:00
|
|
|
if (pm && mContent)
|
2010-08-09 16:17:19 +00:00
|
|
|
pm->ShowPopupAtScreen(mContent, aXPos, aYPos, aIsContextMenu, aTriggerEvent);
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 18:49:54 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::OpenPopupAtScreenRect(const nsAString& aPosition,
|
|
|
|
int32_t aXPos, int32_t aYPos,
|
|
|
|
int32_t aWidth, int32_t aHeight,
|
|
|
|
bool aIsContextMenu,
|
|
|
|
bool aAttributesOverride,
|
|
|
|
Event* aTriggerEvent)
|
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm && mContent) {
|
|
|
|
pm->ShowPopupAtScreenRect(mContent, aPosition,
|
|
|
|
nsIntRect(aXPos, aYPos, aWidth, aHeight),
|
|
|
|
aIsContextMenu, aAttributesOverride, aTriggerEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::MoveTo(int32_t aLeft, int32_t aTop)
|
2001-09-10 07:34:54 +00:00
|
|
|
{
|
2012-10-23 12:11:09 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
|
2005-12-31 23:34:46 +00:00
|
|
|
if (menuPopupFrame) {
|
2015-09-29 00:17:34 +00:00
|
|
|
menuPopupFrame->MoveTo(CSSIntPoint(aLeft, aTop), true);
|
2005-12-31 23:34:46 +00:00
|
|
|
}
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::MoveToAnchor(Element* aAnchorElement,
|
|
|
|
const nsAString& aPosition,
|
|
|
|
int32_t aXPos, int32_t aYPos,
|
|
|
|
bool aAttributesOverride)
|
2012-10-23 12:11:13 +00:00
|
|
|
{
|
2012-10-30 19:55:00 +00:00
|
|
|
if (mContent) {
|
2012-10-23 12:11:13 +00:00
|
|
|
nsCOMPtr<nsIContent> anchorContent(do_QueryInterface(aAnchorElement));
|
|
|
|
|
|
|
|
nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2014-07-14 17:39:04 +00:00
|
|
|
if (menuPopupFrame && menuPopupFrame->IsVisible()) {
|
2012-10-23 12:11:13 +00:00
|
|
|
menuPopupFrame->MoveToAnchor(anchorContent, aPosition, aXPos, aYPos, aAttributesOverride);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::SizeTo(int32_t aWidth, int32_t aHeight)
|
2001-09-10 07:34:54 +00:00
|
|
|
{
|
2008-08-18 17:58:13 +00:00
|
|
|
if (!mContent)
|
2014-10-14 20:15:21 +00:00
|
|
|
return;
|
2008-08-18 17:58:13 +00:00
|
|
|
|
2001-09-10 07:34:54 +00:00
|
|
|
nsAutoString width, height;
|
|
|
|
width.AppendInt(aWidth);
|
|
|
|
height.AppendInt(aHeight);
|
2006-09-03 20:25:58 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = mContent;
|
2012-11-07 00:58:01 +00:00
|
|
|
|
|
|
|
// We only want to pass aNotify=true to SetAttr once, but must make sure
|
|
|
|
// we pass it when a value is being changed. Thus, we check if the height
|
2012-11-17 02:04:39 +00:00
|
|
|
// is the same and if so, pass true when setting the width.
|
2012-11-07 00:58:01 +00:00
|
|
|
bool heightSame = content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::height, height, eCaseMatters);
|
|
|
|
|
|
|
|
content->SetAttr(kNameSpaceID_None, nsGkAtoms::width, width, heightSame);
|
2011-10-17 14:59:28 +00:00
|
|
|
content->SetAttr(kNameSpaceID_None, nsGkAtoms::height, height, true);
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
bool
|
|
|
|
PopupBoxObject::AutoPosition()
|
2001-09-10 07:34:54 +00:00
|
|
|
{
|
2012-10-23 12:11:09 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
|
2005-12-31 23:34:46 +00:00
|
|
|
if (menuPopupFrame) {
|
2014-10-14 20:15:21 +00:00
|
|
|
return menuPopupFrame->GetAutoPosition();
|
2005-12-31 23:34:46 +00:00
|
|
|
}
|
2014-10-14 20:15:21 +00:00
|
|
|
return true;
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::SetAutoPosition(bool aShouldAutoPosition)
|
2001-09-10 07:34:54 +00:00
|
|
|
{
|
2012-10-23 12:11:09 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
|
2005-12-31 23:34:46 +00:00
|
|
|
if (menuPopupFrame) {
|
|
|
|
menuPopupFrame->SetAutoPosition(aShouldAutoPosition);
|
|
|
|
}
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::EnableRollup(bool aShouldRollup)
|
2001-09-10 07:34:54 +00:00
|
|
|
{
|
2008-08-18 17:58:13 +00:00
|
|
|
// this does nothing now
|
2005-12-31 23:34:46 +00:00
|
|
|
}
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::SetConsumeRollupEvent(uint32_t aConsume)
|
2005-12-31 23:34:46 +00:00
|
|
|
{
|
2012-07-31 00:43:28 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
|
2005-12-31 23:34:46 +00:00
|
|
|
if (menuPopupFrame) {
|
|
|
|
menuPopupFrame->SetConsumeRollupEvent(aConsume);
|
|
|
|
}
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::EnableKeyboardNavigator(bool aEnableKeyboardNavigator)
|
2001-09-10 07:34:54 +00:00
|
|
|
{
|
2008-08-18 17:58:13 +00:00
|
|
|
if (!mContent)
|
2014-10-14 20:15:21 +00:00
|
|
|
return;
|
2008-08-18 17:58:13 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
// Use ignorekeys="true" on the popup instead of using this function.
|
|
|
|
if (aEnableKeyboardNavigator)
|
2011-10-17 14:59:28 +00:00
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::ignorekeys, true);
|
2007-10-01 15:20:32 +00:00
|
|
|
else
|
2007-07-04 15:49:38 +00:00
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::ignorekeys,
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_LITERAL_STRING("true"), true);
|
2001-08-18 01:04:47 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::GetPopupState(nsString& aState)
|
2007-08-15 23:52:47 +00:00
|
|
|
{
|
2009-08-26 16:19:38 +00:00
|
|
|
// set this here in case there's no frame for the popup
|
|
|
|
aState.AssignLiteral("closed");
|
|
|
|
|
2012-10-23 12:11:09 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
|
2007-08-15 23:52:47 +00:00
|
|
|
if (menuPopupFrame) {
|
|
|
|
switch (menuPopupFrame->PopupState()) {
|
2014-07-14 17:39:04 +00:00
|
|
|
case ePopupShown:
|
|
|
|
aState.AssignLiteral("open");
|
|
|
|
break;
|
2007-08-15 23:52:47 +00:00
|
|
|
case ePopupShowing:
|
2014-07-14 17:39:04 +00:00
|
|
|
case ePopupOpening:
|
|
|
|
case ePopupVisible:
|
2007-08-15 23:52:47 +00:00
|
|
|
aState.AssignLiteral("showing");
|
|
|
|
break;
|
|
|
|
case ePopupHiding:
|
|
|
|
case ePopupInvisible:
|
|
|
|
aState.AssignLiteral("hiding");
|
|
|
|
break;
|
2008-09-16 11:25:35 +00:00
|
|
|
case ePopupClosed:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Bad popup state");
|
|
|
|
break;
|
2007-08-15 23:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
nsINode*
|
|
|
|
PopupBoxObject::GetTriggerNode() const
|
2010-08-09 16:17:19 +00:00
|
|
|
{
|
2012-10-23 12:11:09 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
|
2014-10-14 20:15:21 +00:00
|
|
|
return nsMenuPopupFrame::GetTriggerContent(menuPopupFrame);
|
2010-08-09 16:17:19 +00:00
|
|
|
}
|
2007-08-15 23:52:47 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
Element*
|
|
|
|
PopupBoxObject::GetAnchorNode() const
|
2010-09-21 17:53:01 +00:00
|
|
|
{
|
2012-10-23 12:11:09 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
|
2014-10-14 20:15:21 +00:00
|
|
|
if (!menuPopupFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-09-21 17:53:01 +00:00
|
|
|
|
|
|
|
nsIContent* anchor = menuPopupFrame->GetAnchor();
|
2014-10-14 20:15:21 +00:00
|
|
|
return anchor && anchor->IsElement() ? anchor->AsElement() : nullptr;
|
2010-09-21 17:53:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
already_AddRefed<DOMRect>
|
|
|
|
PopupBoxObject::GetOuterScreenRect()
|
2011-06-03 19:38:23 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DOMRect> rect = new DOMRect(mContent);
|
2011-06-03 19:38:23 +00:00
|
|
|
|
|
|
|
// Return an empty rectangle if the popup is not open.
|
2014-07-14 17:39:04 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
|
2014-10-14 20:15:21 +00:00
|
|
|
if (!menuPopupFrame || !menuPopupFrame->IsOpen()) {
|
|
|
|
return rect.forget();
|
|
|
|
}
|
2011-06-03 19:38:23 +00:00
|
|
|
|
2013-01-03 13:23:11 +00:00
|
|
|
nsView* view = menuPopupFrame->GetView();
|
2011-06-03 19:38:23 +00:00
|
|
|
if (view) {
|
|
|
|
nsIWidget* widget = view->GetWidget();
|
|
|
|
if (widget) {
|
|
|
|
nsIntRect screenRect;
|
2015-11-10 05:37:32 +00:00
|
|
|
widget->GetScreenBoundsUntyped(screenRect);
|
2011-06-03 19:38:23 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t pp = menuPopupFrame->PresContext()->AppUnitsPerDevPixel();
|
2015-04-21 15:04:57 +00:00
|
|
|
rect->SetLayoutRect(ToAppUnits(screenRect, pp));
|
2011-06-03 19:38:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-14 20:15:21 +00:00
|
|
|
return rect.forget();
|
2011-06-03 19:38:23 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
PopupBoxObject::GetAlignmentPosition(nsString& positionStr)
|
2013-04-19 00:47:27 +00:00
|
|
|
{
|
|
|
|
positionStr.Truncate();
|
|
|
|
|
|
|
|
// This needs to flush layout.
|
|
|
|
nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(true));
|
|
|
|
if (!menuPopupFrame)
|
2014-10-14 20:15:21 +00:00
|
|
|
return;
|
2013-04-19 00:47:27 +00:00
|
|
|
|
|
|
|
int8_t position = menuPopupFrame->GetAlignmentPosition();
|
|
|
|
switch (position) {
|
|
|
|
case POPUPPOSITION_AFTERSTART:
|
|
|
|
positionStr.AssignLiteral("after_start");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_AFTEREND:
|
|
|
|
positionStr.AssignLiteral("after_end");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_BEFORESTART:
|
|
|
|
positionStr.AssignLiteral("before_start");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_BEFOREEND:
|
|
|
|
positionStr.AssignLiteral("before_end");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_STARTBEFORE:
|
|
|
|
positionStr.AssignLiteral("start_before");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_ENDBEFORE:
|
|
|
|
positionStr.AssignLiteral("end_before");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_STARTAFTER:
|
|
|
|
positionStr.AssignLiteral("start_after");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_ENDAFTER:
|
|
|
|
positionStr.AssignLiteral("end_after");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_OVERLAP:
|
|
|
|
positionStr.AssignLiteral("overlap");
|
|
|
|
break;
|
|
|
|
case POPUPPOSITION_AFTERPOINTER:
|
|
|
|
positionStr.AssignLiteral("after_pointer");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Leave as an empty string.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
int32_t
|
|
|
|
PopupBoxObject::AlignmentOffset()
|
2013-05-08 22:59:03 +00:00
|
|
|
{
|
2013-06-24 21:06:56 +00:00
|
|
|
nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
|
2013-05-08 22:59:03 +00:00
|
|
|
if (!menuPopupFrame)
|
2014-10-14 20:15:21 +00:00
|
|
|
return 0;
|
2013-05-08 22:59:03 +00:00
|
|
|
|
2013-09-23 11:55:35 +00:00
|
|
|
int32_t pp = mozilla::AppUnitsPerCSSPixel();
|
2013-05-08 22:59:03 +00:00
|
|
|
// Note that the offset might be along either the X or Y axis, but for the
|
|
|
|
// sake of simplicity we use a point with only the X axis set so we can
|
|
|
|
// use ToNearestPixels().
|
|
|
|
nsPoint appOffset(menuPopupFrame->GetAlignmentOffset(), 0);
|
|
|
|
nsIntPoint popupOffset = appOffset.ToNearestPixels(pp);
|
2014-10-14 20:15:21 +00:00
|
|
|
return popupOffset.x;
|
2013-05-08 22:59:03 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2001-08-18 01:04:47 +00:00
|
|
|
// Creation Routine ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewPopupBoxObject(nsIBoxObject** aResult)
|
|
|
|
{
|
2014-10-14 20:15:21 +00:00
|
|
|
*aResult = new mozilla::dom::PopupBoxObject();
|
2001-08-18 01:04:47 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|