2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsMenuPopupFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2013-01-04 19:12:24 -08:00
|
|
|
#include "nsViewManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsMenuFrame.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsMenuBarFrame.h"
|
|
|
|
#include "nsPopupSetFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-10-22 06:27:36 -07:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMScreen.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsIRootBox.h"
|
2013-11-20 11:18:25 -08:00
|
|
|
#include "nsIDocShell.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2008-09-08 05:58:07 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#include "nsIPopupBoxObject.h"
|
2010-08-09 09:17:19 -07:00
|
|
|
#include "nsPIWindowRoot.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIReflowCallback.h"
|
2007-07-05 21:23:56 -07:00
|
|
|
#include "nsBindingManager.h"
|
2007-11-28 12:18:11 -08:00
|
|
|
#include "nsIDocShellTreeOwner.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsISound.h"
|
2009-05-06 11:29:56 -07:00
|
|
|
#include "nsIScreenManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2009-12-30 07:24:11 -08:00
|
|
|
#include "nsThemeConstants.h"
|
2014-06-16 11:43:07 -07:00
|
|
|
#include "nsTransitionManager.h"
|
2011-04-25 18:37:20 -07:00
|
|
|
#include "nsDisplayList.h"
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-31 21:09:23 -07:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2011-05-24 23:31:59 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-09-08 19:27:13 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2011-05-24 23:31:59 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t nsMenuPopupFrame::sDefaultLevelIsTop = -1;
|
2008-09-08 05:58:07 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// NS_NewMenuPopupFrame
|
|
|
|
//
|
|
|
|
// Wrapper for creating a new menu popup container
|
|
|
|
//
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewMenuPopupFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMenuPopupFrame (aPresShell, aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMenuPopupFrame)
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
NS_QUERYFRAME_HEAD(nsMenuPopupFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsMenuPopupFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// nsMenuPopupFrame ctor
|
|
|
|
//
|
|
|
|
nsMenuPopupFrame::nsMenuPopupFrame(nsIPresShell* aShell, nsStyleContext* aContext)
|
|
|
|
:nsBoxFrame(aShell, aContext),
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentMenu(nullptr),
|
2009-05-12 03:13:09 -07:00
|
|
|
mPrefSize(-1, -1),
|
2011-12-01 13:35:42 -08:00
|
|
|
mLastClientOffset(0, 0),
|
2007-07-04 08:49:38 -07:00
|
|
|
mPopupType(ePopupTypePanel),
|
2007-08-03 07:05:07 -07:00
|
|
|
mPopupState(ePopupClosed),
|
2009-05-12 03:13:09 -07:00
|
|
|
mPopupAlignment(POPUPALIGNMENT_NONE),
|
|
|
|
mPopupAnchor(POPUPALIGNMENT_NONE),
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition(POPUPPOSITION_UNKNOWN),
|
2011-07-26 23:43:37 -07:00
|
|
|
mConsumeRollupEvent(nsIPopupBoxObject::ROLLUP_DEFAULT),
|
2014-01-22 12:09:03 -08:00
|
|
|
mFlip(FlipType_Default),
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsOpenChanged(false),
|
|
|
|
mIsContextMenu(false),
|
|
|
|
mAdjustOffsetForContextMenu(false),
|
|
|
|
mGeneratedChildren(false),
|
|
|
|
mMenuCanOverlapOSBar(false),
|
|
|
|
mShouldAutoPosition(true),
|
|
|
|
mInContentShell(true),
|
|
|
|
mIsMenuLocked(false),
|
2014-01-31 05:27:43 -08:00
|
|
|
mMouseTransparent(false),
|
2011-10-17 07:59:28 -07:00
|
|
|
mHFlip(false),
|
|
|
|
mVFlip(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-27 06:38:03 -07:00
|
|
|
// the preference name is backwards here. True means that the 'top' level is
|
|
|
|
// the default, and false means that the 'parent' level is the default.
|
|
|
|
if (sDefaultLevelIsTop >= 0)
|
2008-09-08 05:58:07 -07:00
|
|
|
return;
|
2010-07-27 06:38:03 -07:00
|
|
|
sDefaultLevelIsTop =
|
2011-09-28 23:19:26 -07:00
|
|
|
Preferences::GetBool("ui.panel.default_level_parent", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
} // ctor
|
|
|
|
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsMenuPopupFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// lookup if we're allowed to overlap the OS bar (menubar/taskbar) from the
|
|
|
|
// look&feel object
|
2011-09-08 19:27:13 -07:00
|
|
|
mMenuCanOverlapOSBar =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_MenusCanOverlapOSBar) != 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
CreatePopupView();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// XXX Hack. The popup's view should float above all other views,
|
2013-01-03 05:23:11 -08:00
|
|
|
// so we use the nsView::SetFloating() to tell the view manager
|
2007-03-22 10:30:00 -07:00
|
|
|
// about that constraint.
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* ourView = GetView();
|
2013-01-04 19:12:24 -08:00
|
|
|
nsViewManager* viewManager = ourView->GetViewManager();
|
2011-10-17 07:59:28 -07:00
|
|
|
viewManager->SetViewFloating(ourView, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
mPopupType = ePopupTypePanel;
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* doc = aContent->OwnerDoc();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t namespaceID;
|
2011-10-18 04:19:44 -07:00
|
|
|
nsCOMPtr<nsIAtom> tag = doc->BindingManager()->ResolveTag(aContent, &namespaceID);
|
|
|
|
if (namespaceID == kNameSpaceID_XUL) {
|
|
|
|
if (tag == nsGkAtoms::menupopup || tag == nsGkAtoms::popup)
|
|
|
|
mPopupType = ePopupTypeMenu;
|
|
|
|
else if (tag == nsGkAtoms::tooltip)
|
|
|
|
mPopupType = ePopupTypeTooltip;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
2013-11-20 11:18:25 -08:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = PresContext()->GetDocShell();
|
2014-01-19 23:58:26 -08:00
|
|
|
if (dsti && dsti->ItemType() == nsIDocShellTreeItem::typeChrome) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mInContentShell = false;
|
2014-01-19 23:58:26 -08:00
|
|
|
}
|
2007-04-20 11:20:03 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// To improve performance, create the widget for the popup only if it is not
|
|
|
|
// a leaf. Leaf popups such as menus will create their widgets later when
|
|
|
|
// the popup opens.
|
|
|
|
if (!IsLeaf() && !ourView->HasWidget()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
CreateWidgetForView(ourView);
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:31:33 -08:00
|
|
|
if (aContent->NodeInfo()->Equals(nsGkAtoms::tooltip, kNameSpaceID_XUL) &&
|
|
|
|
aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::_default,
|
|
|
|
nsGkAtoms::_true, eIgnoreCase)) {
|
|
|
|
nsIRootBox* rootBox =
|
|
|
|
nsIRootBox::GetRootBox(PresContext()->GetPresShell());
|
|
|
|
if (rootBox) {
|
|
|
|
rootBox->SetDefaultTooltip(aContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-28 22:39:01 -07:00
|
|
|
AddStateBits(NS_FRAME_IN_POPUP);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-07-27 06:38:03 -07:00
|
|
|
nsMenuPopupFrame::IsNoAutoHide() const
|
2007-11-28 12:18:11 -08:00
|
|
|
{
|
|
|
|
// Panels with noautohide="true" don't hide when the mouse is clicked
|
|
|
|
// outside of them, or when another application is made active. Non-autohide
|
|
|
|
// panels cannot be used in content windows.
|
|
|
|
return (!mInContentShell && mPopupType == ePopupTypePanel &&
|
|
|
|
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::noautohide,
|
|
|
|
nsGkAtoms::_true, eIgnoreCase));
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
nsPopupLevel
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuPopupFrame::PopupLevel(bool aIsNoAutoHide) const
|
2008-09-08 05:58:07 -07:00
|
|
|
{
|
2010-07-27 06:38:03 -07:00
|
|
|
// The popup level is determined as follows, in this order:
|
|
|
|
// 1. non-panels (menus and tooltips) are always topmost
|
|
|
|
// 2. any specified level attribute
|
2010-07-27 06:38:03 -07:00
|
|
|
// 3. if a titlebar attribute is set, use the 'floating' level
|
|
|
|
// 4. if this is a noautohide panel, use the 'parent' level
|
|
|
|
// 5. use the platform-specific default level
|
2008-09-08 05:58:07 -07:00
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// If this is not a panel, this is always a top-most popup.
|
|
|
|
if (mPopupType != ePopupTypePanel)
|
|
|
|
return ePopupLevelTop;
|
|
|
|
|
|
|
|
// If the level attribute has been set, use that.
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::top, &nsGkAtoms::parent, &nsGkAtoms::floating, nullptr};
|
2010-07-27 06:38:03 -07:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::level,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
return ePopupLevelTop;
|
|
|
|
case 1:
|
|
|
|
return ePopupLevelParent;
|
|
|
|
case 2:
|
|
|
|
return ePopupLevelFloating;
|
|
|
|
}
|
2008-09-08 05:58:07 -07:00
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// Panels with titlebars most likely want to be floating popups.
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::titlebar))
|
|
|
|
return ePopupLevelFloating;
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// If this panel is a noautohide panel, the default is the parent level.
|
|
|
|
if (aIsNoAutoHide)
|
|
|
|
return ePopupLevelParent;
|
2008-09-08 05:58:07 -07:00
|
|
|
|
|
|
|
// Otherwise, the result depends on the platform.
|
2010-07-27 06:38:03 -07:00
|
|
|
return sDefaultLevelIsTop ? ePopupLevelTop : ePopupLevelParent;
|
2008-09-08 05:58:07 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::EnsureWidget()
|
|
|
|
{
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* ourView = GetView();
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!ourView->HasWidget()) {
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_ASSERTION(!mGeneratedChildren && !GetFirstPrincipalChild(),
|
2007-07-04 08:49:38 -07:00
|
|
|
"Creating widget for MenuPopupFrame with children");
|
|
|
|
CreateWidgetForView(ourView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2013-01-03 05:23:11 -08:00
|
|
|
nsMenuPopupFrame::CreateWidgetForView(nsView* aView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Create a widget for ourselves.
|
|
|
|
nsWidgetInitData widgetData;
|
|
|
|
widgetData.mWindowType = eWindowType_popup;
|
|
|
|
widgetData.mBorderStyle = eBorderStyle_default;
|
2011-10-17 07:59:28 -07:00
|
|
|
widgetData.clipSiblings = true;
|
2008-03-08 03:32:25 -08:00
|
|
|
widgetData.mPopupHint = mPopupType;
|
2010-07-27 06:38:03 -07:00
|
|
|
widgetData.mNoAutoHide = IsNoAutoHide();
|
2014-01-31 05:27:43 -08:00
|
|
|
|
|
|
|
if (!mInContentShell) {
|
|
|
|
// A drag popup may be used for non-static translucent drag feedback
|
|
|
|
if (mPopupType == ePopupTypePanel &&
|
|
|
|
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::drag, eIgnoreCase)) {
|
|
|
|
widgetData.mIsDragPopup = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If mousethrough="always" is set directly on the popup, then the widget
|
|
|
|
// should ignore mouse events, passing them through to the content behind.
|
|
|
|
mMouseTransparent = GetStateBits() & NS_FRAME_MOUSE_THROUGH_ALWAYS;
|
|
|
|
widgetData.mMouseTransparent = mMouseTransparent;
|
|
|
|
}
|
2010-07-27 06:38:04 -07:00
|
|
|
|
|
|
|
nsAutoString title;
|
2010-07-27 06:38:03 -07:00
|
|
|
if (mContent && widgetData.mNoAutoHide) {
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::titlebar,
|
|
|
|
nsGkAtoms::normal, eCaseMatters)) {
|
|
|
|
widgetData.mBorderStyle = eBorderStyle_title;
|
2010-07-27 06:38:04 -07:00
|
|
|
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, title);
|
2010-07-27 06:38:04 -07:00
|
|
|
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::close,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
|
|
widgetData.mBorderStyle =
|
|
|
|
static_cast<enum nsBorderStyle>(widgetData.mBorderStyle | eBorderStyle_close);
|
|
|
|
}
|
2010-07-27 06:38:03 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-13 15:08:13 -07:00
|
|
|
nsTransparencyMode mode = nsLayoutUtils::GetFrameTransparency(this, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* parentContent = GetContent()->GetParent();
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIAtom *tag = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parentContent)
|
|
|
|
tag = parentContent->Tag();
|
2012-11-13 18:04:42 -08:00
|
|
|
widgetData.mSupportTranslucency = mode == eTransparencyTransparent;
|
2014-04-09 06:31:06 -07:00
|
|
|
widgetData.mDropShadow = !(mode == eTransparencyTransparent || tag == nsGkAtoms::menulist);
|
2010-07-27 06:38:03 -07:00
|
|
|
widgetData.mPopupLevel = PopupLevel(widgetData.mNoAutoHide);
|
2007-11-28 12:18:11 -08:00
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
// panels which have a parent level need a parent widget. This allows them to
|
2008-09-08 05:58:07 -07:00
|
|
|
// always appear in front of the parent window but behind other windows that
|
|
|
|
// should be in front of it.
|
2007-11-28 12:18:11 -08:00
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
2010-07-27 06:38:03 -07:00
|
|
|
if (widgetData.mPopupLevel != ePopupLevelTop) {
|
2013-11-20 11:18:25 -08:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = PresContext()->GetDocShell();
|
2007-11-28 12:18:11 -08:00
|
|
|
if (!dsti)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
dsti->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
if (!treeOwner) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(treeOwner));
|
|
|
|
if (baseWindow)
|
|
|
|
baseWindow->GetMainWidget(getter_AddRefs(parentWidget));
|
|
|
|
}
|
|
|
|
|
2011-02-21 11:00:48 -08:00
|
|
|
nsresult rv = aView->CreateWidgetForPopup(&widgetData, parentWidget,
|
2011-10-17 07:59:28 -07:00
|
|
|
true, true);
|
2011-02-21 11:00:48 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2010-08-20 12:29:02 -07:00
|
|
|
|
2008-10-14 08:33:40 -07:00
|
|
|
nsIWidget* widget = aView->GetWidget();
|
2008-10-20 01:42:22 -07:00
|
|
|
widget->SetTransparencyMode(mode);
|
2009-12-30 07:24:11 -08:00
|
|
|
widget->SetWindowShadowStyle(GetShadowStyle());
|
2010-07-27 06:38:04 -07:00
|
|
|
|
|
|
|
// most popups don't have a title so avoid setting the title if there isn't one
|
|
|
|
if (!title.IsEmpty()) {
|
|
|
|
widget->SetTitle(title);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2009-12-30 07:24:11 -08:00
|
|
|
nsMenuPopupFrame::GetShadowStyle()
|
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
uint8_t shadow = StyleUIReset()->mWindowShadow;
|
2009-12-30 07:24:11 -08:00
|
|
|
if (shadow != NS_STYLE_WINDOW_SHADOW_DEFAULT)
|
|
|
|
return shadow;
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
switch (StyleDisplay()->mAppearance) {
|
2009-12-30 07:24:11 -08:00
|
|
|
case NS_THEME_TOOLTIP:
|
|
|
|
return NS_STYLE_WINDOW_SHADOW_TOOLTIP;
|
|
|
|
case NS_THEME_MENUPOPUP:
|
|
|
|
return NS_STYLE_WINDOW_SHADOW_MENU;
|
|
|
|
}
|
|
|
|
return NS_STYLE_WINDOW_SHADOW_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
NS_IMETHODIMP nsXULPopupShownEvent::Run()
|
2007-07-04 08:49:38 -07:00
|
|
|
{
|
2014-07-14 10:39:04 -07:00
|
|
|
nsMenuPopupFrame* popup = do_QueryFrame(mPopup->GetPrimaryFrame());
|
|
|
|
// Set the state to visible if the popup is still open.
|
|
|
|
if (popup && popup->IsOpen()) {
|
|
|
|
popup->SetPopupState(ePopupShown);
|
|
|
|
}
|
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
WidgetMouseEvent event(true, NS_XUL_POPUP_SHOWN, nullptr,
|
|
|
|
WidgetMouseEvent::eReal);
|
|
|
|
return EventDispatcher::Dispatch(mPopup, mPresContext, &event);
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
NS_IMETHODIMP nsXULPopupShownEvent::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsMenuPopupFrame* popup = do_QueryFrame(mPopup->GetPrimaryFrame());
|
|
|
|
if (popup) {
|
|
|
|
// ResetPopupShownDispatcher will delete the reference to this, so keep
|
|
|
|
// another one until Run is finished.
|
|
|
|
nsRefPtr<nsXULPopupShownEvent> event = this;
|
|
|
|
// Only call Run if it the dispatcher was assigned. This avoids calling the
|
|
|
|
// Run method if the transitionend event fires multiple times.
|
|
|
|
if (popup->ClearPopupShownDispatcher()) {
|
|
|
|
return Run();
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
CancelListener();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsXULPopupShownEvent::CancelListener()
|
|
|
|
{
|
|
|
|
mPopup->RemoveSystemEventListener(NS_LITERAL_STRING("transitionend"), this, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsXULPopupShownEvent, nsRunnable, nsIDOMEventListener);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2014-05-28 12:36:58 -07:00
|
|
|
void
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMenuPopupFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-07-04 08:49:38 -07:00
|
|
|
{
|
|
|
|
// unless the list is empty, indicate that children have been generated.
|
2009-07-28 05:53:20 -07:00
|
|
|
if (aChildList.NotEmpty())
|
2011-10-17 07:59:28 -07:00
|
|
|
mGeneratedChildren = true;
|
2014-05-28 12:36:58 -07:00
|
|
|
nsBoxFrame::SetInitialChildList(aListID, aChildList);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-09-16 08:51:27 -07:00
|
|
|
nsMenuPopupFrame::IsLeaf() const
|
|
|
|
{
|
|
|
|
if (mGeneratedChildren)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-09-16 08:51:27 -07:00
|
|
|
|
|
|
|
if (mPopupType != ePopupTypeMenu) {
|
|
|
|
// any panel with a type attribute, such as the autocomplete popup,
|
|
|
|
// is always generated right away.
|
|
|
|
return !mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::type);
|
|
|
|
}
|
|
|
|
|
|
|
|
// menu popups generate their child frames lazily only when opened, so
|
|
|
|
// behave like a leaf frame. However, generate child frames normally if
|
|
|
|
// the parent menu has a sizetopopup attribute. In this case the size of
|
2010-07-27 06:38:03 -07:00
|
|
|
// the parent menu is dependent on the size of the popup, so the frames
|
2007-09-16 08:51:27 -07:00
|
|
|
// need to exist in order to calculate this size.
|
|
|
|
nsIContent* parentContent = mContent->GetParent();
|
|
|
|
return (parentContent &&
|
|
|
|
!parentContent->HasAttr(kNameSpaceID_None, nsGkAtoms::sizetopopup));
|
|
|
|
}
|
|
|
|
|
2007-12-19 08:37:32 -08:00
|
|
|
void
|
2014-01-28 08:28:45 -08:00
|
|
|
nsMenuPopupFrame::LayoutPopup(nsBoxLayoutState& aState, nsIFrame* aParentMenu,
|
|
|
|
nsIFrame* aAnchor, bool aSizedToPopup)
|
2007-12-19 08:37:32 -08:00
|
|
|
{
|
2010-09-05 20:30:17 -07:00
|
|
|
if (!mGeneratedChildren)
|
2010-05-13 06:42:57 -07:00
|
|
|
return;
|
|
|
|
|
2012-10-24 16:04:41 -07:00
|
|
|
SchedulePaint();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shouldPosition = true;
|
|
|
|
bool isOpen = IsOpen();
|
2010-09-05 20:30:17 -07:00
|
|
|
if (!isOpen) {
|
|
|
|
// if the popup is not open, only do layout while showing or if the menu
|
|
|
|
// is sized to the popup
|
|
|
|
shouldPosition = (mPopupState == ePopupShowing);
|
2014-02-28 05:18:22 -08:00
|
|
|
if (!shouldPosition && !aSizedToPopup) {
|
|
|
|
RemoveStateBits(NS_FRAME_FIRST_REFLOW);
|
2010-09-05 20:30:17 -07:00
|
|
|
return;
|
2014-02-28 05:18:22 -08:00
|
|
|
}
|
2010-09-05 20:30:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the popup has just been opened, make sure the scrolled window is at 0,0
|
|
|
|
if (mIsOpenChanged) {
|
2014-05-24 15:20:41 -07:00
|
|
|
nsIScrollableFrame *scrollframe = do_QueryFrame(nsBox::GetChildBox(this));
|
2010-09-05 20:30:17 -07:00
|
|
|
if (scrollframe) {
|
2013-08-08 15:04:59 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2010-09-05 20:30:17 -07:00
|
|
|
scrollframe->ScrollTo(nsPoint(0,0), nsIScrollableFrame::INSTANT);
|
2013-08-08 15:04:59 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-09-05 20:30:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-13 06:42:57 -07:00
|
|
|
// get the preferred, minimum and maximum size. If the menu is sized to the
|
|
|
|
// popup, then the popup's width is the menu's width.
|
|
|
|
nsSize prefSize = GetPrefSize(aState);
|
|
|
|
nsSize minSize = GetMinSize(aState);
|
|
|
|
nsSize maxSize = GetMaxSize(aState);
|
|
|
|
|
|
|
|
if (aSizedToPopup) {
|
|
|
|
prefSize.width = aParentMenu->GetRect().width;
|
|
|
|
}
|
|
|
|
prefSize = BoundsCheck(minSize, prefSize, maxSize);
|
|
|
|
|
|
|
|
// if the size changed then set the bounds to be the preferred size
|
2011-09-28 23:19:26 -07:00
|
|
|
bool sizeChanged = (mPrefSize != prefSize);
|
2010-05-13 06:42:57 -07:00
|
|
|
if (sizeChanged) {
|
2011-10-17 07:59:28 -07:00
|
|
|
SetBounds(aState, nsRect(0, 0, prefSize.width, prefSize.height), false);
|
2010-05-13 06:42:57 -07:00
|
|
|
mPrefSize = prefSize;
|
|
|
|
}
|
|
|
|
|
2010-09-05 20:30:17 -07:00
|
|
|
if (shouldPosition) {
|
2014-01-28 08:28:45 -08:00
|
|
|
SetPopupPosition(aAnchor, false, aSizedToPopup);
|
2010-05-13 06:42:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect bounds(GetRect());
|
|
|
|
Layout(aState);
|
|
|
|
|
|
|
|
// if the width or height changed, readjust the popup position. This is a
|
|
|
|
// special case for tooltips where the preferred height doesn't include the
|
|
|
|
// real height for its inline element, but does once it is laid out.
|
|
|
|
// This is bug 228673 which doesn't have a simple fix.
|
|
|
|
if (!aParentMenu) {
|
|
|
|
nsSize newsize = GetSize();
|
|
|
|
if (newsize.width > bounds.width || newsize.height > bounds.height) {
|
|
|
|
// the size after layout was larger than the preferred size,
|
|
|
|
// so set the preferred size accordingly
|
|
|
|
mPrefSize = newsize;
|
|
|
|
if (isOpen) {
|
2014-01-28 08:28:45 -08:00
|
|
|
SetPopupPosition(nullptr, false, aSizedToPopup);
|
2010-05-13 06:42:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
nsPresContext* pc = PresContext();
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = GetView();
|
2012-09-12 17:10:09 -07:00
|
|
|
|
|
|
|
if (sizeChanged) {
|
|
|
|
// If the size of the popup changed, apply any size constraints.
|
|
|
|
nsIWidget* widget = view->GetWidget();
|
|
|
|
if (widget) {
|
|
|
|
SetSizeConstraints(pc, widget, minSize, maxSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-05 20:30:17 -07:00
|
|
|
if (isOpen) {
|
2013-01-04 19:12:24 -08:00
|
|
|
nsViewManager* viewManager = view->GetViewManager();
|
2010-09-05 20:30:17 -07:00
|
|
|
nsRect rect = GetRect();
|
|
|
|
rect.x = rect.y = 0;
|
|
|
|
viewManager->ResizeView(view, rect);
|
2010-07-27 06:38:03 -07:00
|
|
|
|
2014-07-14 10:39:04 -07:00
|
|
|
if (mPopupState == ePopupOpening) {
|
|
|
|
mPopupState = ePopupVisible;
|
|
|
|
}
|
|
|
|
|
2010-09-05 20:30:17 -07:00
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kShow);
|
2012-07-30 07:20:58 -07:00
|
|
|
nsContainerFrame::SyncFrameViewProperties(pc, this, nullptr, view, 0);
|
2010-09-05 20:30:17 -07:00
|
|
|
}
|
2010-05-13 06:42:57 -07:00
|
|
|
|
2010-09-05 20:30:17 -07:00
|
|
|
// finally, if the popup just opened, send a popupshown event
|
2010-05-13 06:42:57 -07:00
|
|
|
if (mIsOpenChanged) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsOpenChanged = false;
|
2014-06-16 11:43:07 -07:00
|
|
|
|
|
|
|
#ifndef MOZ_WIDGET_GTK
|
|
|
|
// If the animate attribute is set to open, check for a transition and wait
|
|
|
|
// for it to finish before firing the popupshown event.
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::animate,
|
|
|
|
nsGkAtoms::open, eCaseMatters) &&
|
2014-10-01 23:14:13 -07:00
|
|
|
nsLayoutUtils::HasCurrentAnimations(mContent,
|
|
|
|
nsGkAtoms::transitionsProperty)) {
|
2014-06-16 11:43:07 -07:00
|
|
|
mPopupShownDispatcher = new nsXULPopupShownEvent(mContent, pc);
|
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("transitionend"),
|
|
|
|
mPopupShownDispatcher, false, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// If there are no transitions, fire the popupshown event right away.
|
2010-05-13 06:42:57 -07:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsXULPopupShownEvent(GetContent(), pc);
|
|
|
|
NS_DispatchToCurrentThread(event);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 13:24:25 -07:00
|
|
|
nsIContent*
|
|
|
|
nsMenuPopupFrame::GetTriggerContent(nsMenuPopupFrame* aMenuPopupFrame)
|
|
|
|
{
|
|
|
|
while (aMenuPopupFrame) {
|
|
|
|
if (aMenuPopupFrame->mTriggerContent)
|
|
|
|
return aMenuPopupFrame->mTriggerContent;
|
|
|
|
|
|
|
|
// check up the menu hierarchy until a popup with a trigger node is found
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(aMenuPopupFrame->GetParent());
|
2010-09-10 13:24:25 -07:00
|
|
|
if (!menuFrame)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsMenuParent* parentPopup = menuFrame->GetMenuParent();
|
|
|
|
if (!parentPopup || !parentPopup->IsMenu())
|
|
|
|
break;
|
|
|
|
|
|
|
|
aMenuPopupFrame = static_cast<nsMenuPopupFrame *>(parentPopup);
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-09-10 13:24:25 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::InitPositionFromAnchorAlign(const nsAString& aAnchor,
|
|
|
|
const nsAString& aAlign)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mTriggerContent = nullptr;
|
2010-08-09 09:17:19 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (aAnchor.EqualsLiteral("topleft"))
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
else if (aAnchor.EqualsLiteral("topright"))
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPRIGHT;
|
|
|
|
else if (aAnchor.EqualsLiteral("bottomleft"))
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMLEFT;
|
|
|
|
else if (aAnchor.EqualsLiteral("bottomright"))
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMRIGHT;
|
2010-12-05 14:09:36 -08:00
|
|
|
else if (aAnchor.EqualsLiteral("leftcenter"))
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_LEFTCENTER;
|
|
|
|
else if (aAnchor.EqualsLiteral("rightcenter"))
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_RIGHTCENTER;
|
|
|
|
else if (aAnchor.EqualsLiteral("topcenter"))
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPCENTER;
|
|
|
|
else if (aAnchor.EqualsLiteral("bottomcenter"))
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMCENTER;
|
2007-07-04 08:49:38 -07:00
|
|
|
else
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_NONE;
|
|
|
|
|
|
|
|
if (aAlign.EqualsLiteral("topleft"))
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
else if (aAlign.EqualsLiteral("topright"))
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPRIGHT;
|
|
|
|
else if (aAlign.EqualsLiteral("bottomleft"))
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMLEFT;
|
|
|
|
else if (aAlign.EqualsLiteral("bottomright"))
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMRIGHT;
|
|
|
|
else
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_NONE;
|
2013-04-18 17:47:27 -07:00
|
|
|
|
|
|
|
mPosition = POPUPPOSITION_UNKNOWN;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::InitializePopup(nsIContent* aAnchorContent,
|
2010-08-09 09:17:19 -07:00
|
|
|
nsIContent* aTriggerContent,
|
2007-07-04 08:49:38 -07:00
|
|
|
const nsAString& aPosition,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aXPos, int32_t aYPos,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAttributesOverride)
|
2007-07-04 08:49:38 -07:00
|
|
|
{
|
|
|
|
EnsureWidget();
|
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
mPopupState = ePopupShowing;
|
2007-07-04 08:49:38 -07:00
|
|
|
mAnchorContent = aAnchorContent;
|
2010-08-09 09:17:19 -07:00
|
|
|
mTriggerContent = aTriggerContent;
|
2007-07-04 08:49:38 -07:00
|
|
|
mXPos = aXPos;
|
|
|
|
mYPos = aYPos;
|
2011-10-17 07:59:28 -07:00
|
|
|
mAdjustOffsetForContextMenu = false;
|
2012-12-20 17:26:32 -08:00
|
|
|
mVFlip = false;
|
|
|
|
mHFlip = false;
|
2013-05-08 15:59:03 -07:00
|
|
|
mAlignmentOffset = 0;
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// if aAttributesOverride is true, then the popupanchor, popupalign and
|
|
|
|
// position attributes on the <popup> override those values passed in.
|
|
|
|
// If false, those attributes are only used if the values passed in are empty
|
|
|
|
if (aAnchorContent) {
|
2010-10-13 12:41:37 -07:00
|
|
|
nsAutoString anchor, align, position, flip;
|
2007-07-04 08:49:38 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::popupanchor, anchor);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::popupalign, align);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::position, position);
|
2010-10-13 12:41:37 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::flip, flip);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
if (aAttributesOverride) {
|
|
|
|
// if the attributes are set, clear the offset position. Otherwise,
|
|
|
|
// the offset is used to adjust the position from the anchor point
|
|
|
|
if (anchor.IsEmpty() && align.IsEmpty() && position.IsEmpty())
|
|
|
|
position.Assign(aPosition);
|
|
|
|
else
|
|
|
|
mXPos = mYPos = 0;
|
|
|
|
}
|
|
|
|
else if (!aPosition.IsEmpty()) {
|
|
|
|
position.Assign(aPosition);
|
|
|
|
}
|
|
|
|
|
2014-01-22 12:09:03 -08:00
|
|
|
if (flip.EqualsLiteral("none")) {
|
|
|
|
mFlip = FlipType_None;
|
|
|
|
} else if (flip.EqualsLiteral("both")) {
|
|
|
|
mFlip = FlipType_Both;
|
|
|
|
} else if (flip.EqualsLiteral("slide")) {
|
|
|
|
mFlip = FlipType_Slide;
|
|
|
|
}
|
2010-10-13 12:41:37 -07:00
|
|
|
|
2010-12-05 14:09:36 -08:00
|
|
|
position.CompressWhitespace();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t spaceIdx = position.FindChar(' ');
|
2010-12-05 14:09:36 -08:00
|
|
|
// if there is a space in the position, assume it is the anchor and
|
|
|
|
// alignment as two separate tokens.
|
|
|
|
if (spaceIdx >= 0) {
|
|
|
|
InitPositionFromAnchorAlign(Substring(position, 0, spaceIdx), Substring(position, spaceIdx + 1));
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("before_start")) {
|
2007-07-04 08:49:38 -07:00
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMLEFT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_BEFORESTART;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("before_end")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPRIGHT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMRIGHT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_BEFOREEND;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("after_start")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPLEFT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_AFTERSTART;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("after_end")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMRIGHT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPRIGHT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_AFTEREND;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("start_before")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPRIGHT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_STARTBEFORE;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("start_after")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMRIGHT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_STARTAFTER;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("end_before")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPRIGHT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPLEFT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_ENDBEFORE;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("end_after")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMRIGHT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMLEFT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_ENDAFTER;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("overlap")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPLEFT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_OVERLAP;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("after_pointer")) {
|
2009-10-06 06:26:34 -07:00
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPLEFT;
|
2013-04-18 17:47:27 -07:00
|
|
|
mPosition = POPUPPOSITION_AFTERPOINTER;
|
2007-07-04 08:49:38 -07:00
|
|
|
// XXXndeakin this is supposed to anchor vertically after, but with the
|
|
|
|
// horizontal position as the mouse pointer.
|
|
|
|
mYPos += 21;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
InitPositionFromAnchorAlign(anchor, align);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mScreenXPos = -1;
|
|
|
|
mScreenYPos = -1;
|
|
|
|
|
|
|
|
if (aAttributesOverride) {
|
|
|
|
// Use |left| and |top| dimension attributes to position the popup if
|
|
|
|
// present, as they may have been persisted.
|
|
|
|
nsAutoString left, top;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::left, left);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::top, top);
|
|
|
|
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult err;
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!left.IsEmpty()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t x = left.ToInteger(&err);
|
2007-07-04 08:49:38 -07:00
|
|
|
if (NS_SUCCEEDED(err))
|
|
|
|
mScreenXPos = x;
|
|
|
|
}
|
|
|
|
if (!top.IsEmpty()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t y = top.ToInteger(&err);
|
2007-07-04 08:49:38 -07:00
|
|
|
if (NS_SUCCEEDED(err))
|
|
|
|
mScreenYPos = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-09 09:17:19 -07:00
|
|
|
nsMenuPopupFrame::InitializePopupAtScreen(nsIContent* aTriggerContent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aXPos, int32_t aYPos,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsContextMenu)
|
2007-07-04 08:49:38 -07:00
|
|
|
{
|
|
|
|
EnsureWidget();
|
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
mPopupState = ePopupShowing;
|
2012-07-30 07:20:58 -07:00
|
|
|
mAnchorContent = nullptr;
|
2010-08-09 09:17:19 -07:00
|
|
|
mTriggerContent = aTriggerContent;
|
2007-07-04 08:49:38 -07:00
|
|
|
mScreenXPos = aXPos;
|
|
|
|
mScreenYPos = aYPos;
|
2014-01-22 12:09:03 -08:00
|
|
|
mFlip = FlipType_Default;
|
2007-07-04 08:49:38 -07:00
|
|
|
mPopupAnchor = POPUPALIGNMENT_NONE;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_NONE;
|
2008-04-23 14:25:34 -07:00
|
|
|
mIsContextMenu = aIsContextMenu;
|
|
|
|
mAdjustOffsetForContextMenu = aIsContextMenu;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::InitializePopupWithAnchorAlign(nsIContent* aAnchorContent,
|
|
|
|
nsAString& aAnchor,
|
|
|
|
nsAString& aAlign,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aXPos, int32_t aYPos)
|
2007-07-04 08:49:38 -07:00
|
|
|
{
|
|
|
|
EnsureWidget();
|
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
mPopupState = ePopupShowing;
|
2011-10-17 07:59:28 -07:00
|
|
|
mAdjustOffsetForContextMenu = false;
|
2014-01-22 12:09:03 -08:00
|
|
|
mFlip = FlipType_Default;
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// this popup opening function is provided for backwards compatibility
|
|
|
|
// only. It accepts either coordinates or an anchor and alignment value
|
|
|
|
// but doesn't use both together.
|
|
|
|
if (aXPos == -1 && aYPos == -1) {
|
|
|
|
mAnchorContent = aAnchorContent;
|
|
|
|
mScreenXPos = -1;
|
|
|
|
mScreenYPos = -1;
|
2007-07-06 05:12:47 -07:00
|
|
|
mXPos = 0;
|
|
|
|
mYPos = 0;
|
2007-07-04 08:49:38 -07:00
|
|
|
InitPositionFromAnchorAlign(aAnchor, aAlign);
|
|
|
|
}
|
|
|
|
else {
|
2012-07-30 07:20:58 -07:00
|
|
|
mAnchorContent = nullptr;
|
2007-07-04 08:49:38 -07:00
|
|
|
mPopupAnchor = POPUPALIGNMENT_NONE;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_NONE;
|
|
|
|
mScreenXPos = aXPos;
|
|
|
|
mScreenYPos = aYPos;
|
2007-07-06 05:12:47 -07:00
|
|
|
mXPos = aXPos;
|
|
|
|
mYPos = aYPos;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuPopupFrame::ShowPopup(bool aIsContextMenu, bool aSelectFirstItem)
|
2007-07-04 08:49:38 -07:00
|
|
|
{
|
|
|
|
mIsContextMenu = aIsContextMenu;
|
|
|
|
|
2013-01-22 21:46:36 -08:00
|
|
|
InvalidateFrameSubtree();
|
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
if (mPopupState == ePopupShowing) {
|
2014-07-14 10:39:04 -07:00
|
|
|
mPopupState = ePopupOpening;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsOpenChanged = true;
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(GetParent());
|
2010-08-09 09:17:19 -07:00
|
|
|
if (menuFrame) {
|
2007-07-04 08:49:38 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2010-08-09 09:17:19 -07:00
|
|
|
menuFrame->PopupOpened();
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!weakFrame.IsAlive())
|
2010-09-05 20:30:17 -07:00
|
|
|
return;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
2010-09-05 20:30:17 -07:00
|
|
|
// do we need an actual reflow here?
|
|
|
|
// is SetPopupPosition all that is needed?
|
|
|
|
PresContext()->PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
|
2008-12-10 09:23:20 -08:00
|
|
|
if (mPopupType == ePopupTypeMenu) {
|
|
|
|
nsCOMPtr<nsISound> sound(do_CreateInstance("@mozilla.org/sound;1"));
|
|
|
|
if (sound)
|
2009-07-08 18:55:46 -07:00
|
|
|
sound->PlayEventSound(nsISound::EVENT_MENU_POPUP);
|
2008-12-10 09:23:20 -08:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mShouldAutoPosition = true;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuPopupFrame::HidePopup(bool aDeselectMenu, nsPopupState aNewState)
|
2007-07-04 08:49:38 -07:00
|
|
|
{
|
2007-08-03 07:05:07 -07:00
|
|
|
NS_ASSERTION(aNewState == ePopupClosed || aNewState == ePopupInvisible,
|
|
|
|
"popup being set to unexpected state");
|
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
ClearPopupShownDispatcher();
|
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
// don't hide the popup when it isn't open
|
|
|
|
if (mPopupState == ePopupClosed || mPopupState == ePopupShowing)
|
|
|
|
return;
|
|
|
|
|
2010-08-09 09:17:19 -07:00
|
|
|
// clear the trigger content if the popup is being closed. But don't clear
|
|
|
|
// it if the popup is just being made invisible as a popuphiding or command
|
|
|
|
// event may want to retrieve it.
|
|
|
|
if (aNewState == ePopupClosed) {
|
|
|
|
// if the popup had a trigger node set, clear the global window popup node
|
|
|
|
// as well
|
|
|
|
if (mTriggerContent) {
|
|
|
|
nsIDocument* doc = mContent->GetCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
nsPIDOMWindow* win = doc->GetWindow();
|
|
|
|
if (win) {
|
|
|
|
nsCOMPtr<nsPIWindowRoot> root = win->GetTopWindowRoot();
|
|
|
|
if (root) {
|
2012-07-30 07:20:58 -07:00
|
|
|
root->SetPopupNode(nullptr);
|
2010-08-09 09:17:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mTriggerContent = nullptr;
|
|
|
|
mAnchorContent = nullptr;
|
2010-08-09 09:17:19 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
// when invisible and about to be closed, HidePopup has already been called,
|
|
|
|
// so just set the new state to closed and return
|
|
|
|
if (mPopupState == ePopupInvisible) {
|
|
|
|
if (aNewState == ePopupClosed)
|
|
|
|
mPopupState = ePopupClosed;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPopupState = aNewState;
|
|
|
|
|
|
|
|
if (IsMenu())
|
2012-07-30 07:20:58 -07:00
|
|
|
SetCurrentMenuItem(nullptr);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
mIncrementalString.Truncate();
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
LockMenuUntilClosed(false);
|
2010-04-19 07:12:58 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsOpenChanged = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentMenu = nullptr; // make sure no current menu is set
|
2011-10-17 07:59:28 -07:00
|
|
|
mHFlip = mVFlip = false;
|
2009-12-23 10:45:44 -08:00
|
|
|
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = GetView();
|
2013-01-04 19:12:24 -08:00
|
|
|
nsViewManager* viewManager = view->GetViewManager();
|
2007-08-03 07:05:07 -07:00
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-08-03 07:05:07 -07:00
|
|
|
FireDOMEvent(NS_LITERAL_STRING("DOMMenuInactive"), mContent);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// XXX, bug 137033, In Windows, if mouse is outside the window when the menupopup closes, no
|
|
|
|
// mouse_enter/mouse_exit event will be fired to clear current hover state, we should clear it manually.
|
|
|
|
// This code may not the best solution, but we can leave it here until we find the better approach.
|
2011-05-31 18:46:56 -07:00
|
|
|
NS_ASSERTION(mContent->IsElement(), "How do we have a non-element?");
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates state = mContent->AsElement()->State();
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2011-05-31 18:46:56 -07:00
|
|
|
if (state.HasState(NS_EVENT_STATE_HOVER)) {
|
2014-03-31 21:09:23 -07:00
|
|
|
EventStateManager* esm = PresContext()->EventStateManager();
|
2012-07-30 07:20:58 -07:00
|
|
|
esm->SetContentState(nullptr, NS_EVENT_STATE_HOVER);
|
2011-05-31 18:46:56 -07:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(GetParent());
|
2010-08-09 09:17:19 -07:00
|
|
|
if (menuFrame) {
|
|
|
|
menuFrame->PopupClosed(aDeselectMenu);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMenuPopupFrame::GetLayoutFlags(uint32_t& aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aFlags = NS_FRAME_NO_SIZE_VIEW | NS_FRAME_NO_MOVE_VIEW | NS_FRAME_NO_VISIBILITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetRootViewForPopup
|
|
|
|
// Retrieves the view for the popup widget that contains the given frame.
|
|
|
|
// If the given frame is not contained by a popup widget, return the
|
|
|
|
// root view of the root viewmanager.
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView*
|
2007-08-27 09:23:52 -07:00
|
|
|
nsMenuPopupFrame::GetRootViewForPopup(nsIFrame* aStartFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = aStartFrame->GetClosestView();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(view, "frame must have a closest view!");
|
2007-08-27 09:23:52 -07:00
|
|
|
while (view) {
|
|
|
|
// Walk up the view hierarchy looking for a view whose widget has a
|
|
|
|
// window type of eWindowType_popup - in other words a popup window
|
|
|
|
// widget. If we find one, this is the view we want.
|
|
|
|
nsIWidget* widget = view->GetWidget();
|
2014-03-19 09:48:08 -07:00
|
|
|
if (widget && widget->WindowType() == eWindowType_popup) {
|
|
|
|
return view;
|
2007-08-27 09:23:52 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* temp = view->GetParent();
|
2007-08-27 09:23:52 -07:00
|
|
|
if (!temp) {
|
|
|
|
// Otherwise, we've walked all the way up to the root view and not
|
|
|
|
// found a view for a popup window widget. Just return the root view.
|
|
|
|
return view;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-27 09:23:52 -07:00
|
|
|
view = temp;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
nsPoint
|
2010-12-05 14:09:36 -08:00
|
|
|
nsMenuPopupFrame::AdjustPositionForAnchorAlign(nsRect& anchorRect,
|
2010-10-13 12:41:37 -07:00
|
|
|
FlipStyle& aHFlip, FlipStyle& aVFlip)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-10 07:19:16 -08:00
|
|
|
// flip the anchor and alignment for right-to-left
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t popupAnchor(mPopupAnchor);
|
|
|
|
int8_t popupAlign(mPopupAlignment);
|
2011-01-13 06:02:20 -08:00
|
|
|
if (IsDirectionRTL()) {
|
2012-12-18 09:08:08 -08:00
|
|
|
// no need to flip the centered anchor types vertically
|
|
|
|
if (popupAnchor <= POPUPALIGNMENT_LEFTCENTER) {
|
2010-12-05 14:09:36 -08:00
|
|
|
popupAnchor = -popupAnchor;
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
popupAlign = -popupAlign;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// first, determine at which corner of the anchor the popup should appear
|
|
|
|
nsPoint pnt;
|
|
|
|
switch (popupAnchor) {
|
2010-12-05 14:09:36 -08:00
|
|
|
case POPUPALIGNMENT_LEFTCENTER:
|
|
|
|
pnt = nsPoint(anchorRect.x, anchorRect.y + anchorRect.height / 2);
|
|
|
|
anchorRect.y = pnt.y;
|
2014-02-06 17:08:31 -08:00
|
|
|
anchorRect.height = 0;
|
2010-12-05 14:09:36 -08:00
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_RIGHTCENTER:
|
|
|
|
pnt = nsPoint(anchorRect.XMost(), anchorRect.y + anchorRect.height / 2);
|
|
|
|
anchorRect.y = pnt.y;
|
2014-02-06 17:08:31 -08:00
|
|
|
anchorRect.height = 0;
|
2010-12-05 14:09:36 -08:00
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_TOPCENTER:
|
|
|
|
pnt = nsPoint(anchorRect.x + anchorRect.width / 2, anchorRect.y);
|
|
|
|
anchorRect.x = pnt.x;
|
2014-02-06 17:08:31 -08:00
|
|
|
anchorRect.width = 0;
|
2010-12-05 14:09:36 -08:00
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_BOTTOMCENTER:
|
|
|
|
pnt = nsPoint(anchorRect.x + anchorRect.width / 2, anchorRect.YMost());
|
|
|
|
anchorRect.x = pnt.x;
|
2014-02-06 17:08:31 -08:00
|
|
|
anchorRect.width = 0;
|
2010-12-05 14:09:36 -08:00
|
|
|
break;
|
2008-12-10 07:19:16 -08:00
|
|
|
case POPUPALIGNMENT_TOPRIGHT:
|
|
|
|
pnt = anchorRect.TopRight();
|
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_BOTTOMLEFT:
|
|
|
|
pnt = anchorRect.BottomLeft();
|
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_BOTTOMRIGHT:
|
|
|
|
pnt = anchorRect.BottomRight();
|
|
|
|
break;
|
2010-03-10 22:42:20 -08:00
|
|
|
case POPUPALIGNMENT_TOPLEFT:
|
|
|
|
default:
|
|
|
|
pnt = anchorRect.TopLeft();
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// If the alignment is on the right edge of the popup, move the popup left
|
|
|
|
// by the width. Similarly, if the alignment is on the bottom edge of the
|
|
|
|
// popup, move the popup up by the height. In addition, account for the
|
|
|
|
// margins of the popup on the edge on which it is aligned.
|
2009-02-17 07:51:11 -08:00
|
|
|
nsMargin margin(0, 0, 0, 0);
|
2013-02-16 13:51:02 -08:00
|
|
|
StyleMargin()->GetMargin(margin);
|
2008-12-10 07:19:16 -08:00
|
|
|
switch (popupAlign) {
|
|
|
|
case POPUPALIGNMENT_TOPRIGHT:
|
|
|
|
pnt.MoveBy(-mRect.width - margin.right, margin.top);
|
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_BOTTOMLEFT:
|
|
|
|
pnt.MoveBy(margin.left, -mRect.height - margin.bottom);
|
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_BOTTOMRIGHT:
|
|
|
|
pnt.MoveBy(-mRect.width - margin.right, -mRect.height - margin.bottom);
|
|
|
|
break;
|
2010-03-10 22:42:20 -08:00
|
|
|
case POPUPALIGNMENT_TOPLEFT:
|
|
|
|
default:
|
|
|
|
pnt.MoveBy(margin.left, margin.top);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// Flipping horizontally is allowed as long as the popup is above or below
|
|
|
|
// the anchor. This will happen if both the anchor and alignment are top or
|
|
|
|
// both are bottom, but different values. Similarly, flipping vertically is
|
|
|
|
// allowed if the popup is to the left or right of the anchor. In this case,
|
|
|
|
// the values of the constants are such that both must be positive or both
|
|
|
|
// must be negative. A special case, used for overlap, allows flipping
|
|
|
|
// vertically as well.
|
2010-10-13 12:41:37 -07:00
|
|
|
// If we are flipping in both directions, we want to set a flip style both
|
|
|
|
// horizontally and vertically. However, we want to flip on the inside edge
|
|
|
|
// of the anchor. Consider the example of a typical dropdown menu.
|
|
|
|
// Vertically, we flip the popup on the outside edges of the anchor menu,
|
|
|
|
// however horizontally, we want to to use the inside edges so the popup
|
|
|
|
// still appears underneath the anchor menu instead of floating off the
|
|
|
|
// side of the menu.
|
2012-12-18 09:08:08 -08:00
|
|
|
switch (popupAnchor) {
|
|
|
|
case POPUPALIGNMENT_LEFTCENTER:
|
|
|
|
case POPUPALIGNMENT_RIGHTCENTER:
|
2010-12-05 14:09:36 -08:00
|
|
|
aHFlip = FlipStyle_Outside;
|
|
|
|
aVFlip = FlipStyle_Inside;
|
2012-12-18 09:08:08 -08:00
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_TOPCENTER:
|
|
|
|
case POPUPALIGNMENT_BOTTOMCENTER:
|
2010-12-05 14:09:36 -08:00
|
|
|
aHFlip = FlipStyle_Inside;
|
|
|
|
aVFlip = FlipStyle_Outside;
|
2012-12-18 09:08:08 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
2014-01-22 12:09:03 -08:00
|
|
|
FlipStyle anchorEdge = mFlip == FlipType_Both ? FlipStyle_Inside : FlipStyle_None;
|
2012-12-18 09:08:08 -08:00
|
|
|
aHFlip = (popupAnchor == -popupAlign) ? FlipStyle_Outside : anchorEdge;
|
|
|
|
if (((popupAnchor > 0) == (popupAlign > 0)) ||
|
|
|
|
(popupAnchor == POPUPALIGNMENT_TOPLEFT && popupAlign == POPUPALIGNMENT_TOPLEFT))
|
|
|
|
aVFlip = FlipStyle_Outside;
|
|
|
|
else
|
|
|
|
aVFlip = anchorEdge;
|
|
|
|
break;
|
2010-12-05 14:09:36 -08:00
|
|
|
}
|
|
|
|
}
|
2008-12-10 07:19:16 -08:00
|
|
|
|
|
|
|
return pnt;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-08 15:59:03 -07:00
|
|
|
nscoord
|
|
|
|
nsMenuPopupFrame::SlideOrResize(nscoord& aScreenPoint, nscoord aSize,
|
|
|
|
nscoord aScreenBegin, nscoord aScreenEnd,
|
|
|
|
nscoord *aOffset)
|
|
|
|
{
|
|
|
|
// The popup may be positioned such that either the left/top or bottom/right
|
|
|
|
// is outside the screen - but never both.
|
2014-01-08 01:35:19 -08:00
|
|
|
nscoord newPos =
|
|
|
|
std::max(aScreenBegin, std::min(aScreenEnd - aSize, aScreenPoint));
|
|
|
|
*aOffset = newPos - aScreenPoint;
|
|
|
|
aScreenPoint = newPos;
|
2013-05-08 15:59:03 -07:00
|
|
|
return std::min(aSize, aScreenEnd - aScreenPoint);
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
nscoord
|
|
|
|
nsMenuPopupFrame::FlipOrResize(nscoord& aScreenPoint, nscoord aSize,
|
|
|
|
nscoord aScreenBegin, nscoord aScreenEnd,
|
|
|
|
nscoord aAnchorBegin, nscoord aAnchorEnd,
|
|
|
|
nscoord aMarginBegin, nscoord aMarginEnd,
|
2010-10-13 12:41:37 -07:00
|
|
|
nscoord aOffsetForContextMenu, FlipStyle aFlip,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aFlipSide)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-10 07:19:16 -08:00
|
|
|
// all of the coordinates used here are in app units relative to the screen
|
|
|
|
nscoord popupSize = aSize;
|
|
|
|
if (aScreenPoint < aScreenBegin) {
|
|
|
|
// at its current position, the popup would extend past the left or top
|
|
|
|
// edge of the screen, so it will have to be moved or resized.
|
|
|
|
if (aFlip) {
|
2010-10-13 12:41:37 -07:00
|
|
|
// for inside flips, we flip on the opposite side of the anchor
|
|
|
|
nscoord startpos = aFlip == FlipStyle_Outside ? aAnchorBegin : aAnchorEnd;
|
|
|
|
nscoord endpos = aFlip == FlipStyle_Outside ? aAnchorEnd : aAnchorBegin;
|
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// check whether there is more room to the left and right (or top and
|
|
|
|
// bottom) of the anchor and put the popup on the side with more room.
|
2010-10-13 12:41:37 -07:00
|
|
|
if (startpos - aScreenBegin >= aScreenEnd - endpos) {
|
2008-12-10 07:19:16 -08:00
|
|
|
aScreenPoint = aScreenBegin;
|
2010-10-13 12:41:37 -07:00
|
|
|
popupSize = startpos - aScreenPoint - aMarginEnd;
|
2008-12-10 07:19:16 -08:00
|
|
|
}
|
|
|
|
else {
|
2013-04-18 17:47:27 -07:00
|
|
|
// If the newly calculated position is different than the existing
|
|
|
|
// position, flip such that the popup is to the right or bottom of the
|
|
|
|
// anchor point instead . However, when flipping use the same margin
|
|
|
|
// size.
|
|
|
|
nscoord newScreenPoint = endpos + aMarginEnd;
|
|
|
|
if (newScreenPoint != aScreenPoint) {
|
|
|
|
*aFlipSide = true;
|
|
|
|
aScreenPoint = newScreenPoint;
|
|
|
|
// check if the new position is still off the right or bottom edge of
|
|
|
|
// the screen. If so, resize the popup.
|
|
|
|
if (aScreenPoint + aSize > aScreenEnd) {
|
|
|
|
popupSize = aScreenEnd - aScreenPoint;
|
|
|
|
}
|
2009-01-06 11:21:23 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-12-10 07:19:16 -08:00
|
|
|
else {
|
|
|
|
aScreenPoint = aScreenBegin;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-12-10 07:19:16 -08:00
|
|
|
else if (aScreenPoint + aSize > aScreenEnd) {
|
|
|
|
// at its current position, the popup would extend past the right or
|
|
|
|
// bottom edge of the screen, so it will have to be moved or resized.
|
|
|
|
if (aFlip) {
|
2010-10-13 12:41:37 -07:00
|
|
|
// for inside flips, we flip on the opposite side of the anchor
|
|
|
|
nscoord startpos = aFlip == FlipStyle_Outside ? aAnchorBegin : aAnchorEnd;
|
|
|
|
nscoord endpos = aFlip == FlipStyle_Outside ? aAnchorEnd : aAnchorBegin;
|
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// check whether there is more room to the left and right (or top and
|
|
|
|
// bottom) of the anchor and put the popup on the side with more room.
|
2010-10-13 12:41:37 -07:00
|
|
|
if (aScreenEnd - endpos >= startpos - aScreenBegin) {
|
2009-01-06 11:21:23 -08:00
|
|
|
if (mIsContextMenu) {
|
|
|
|
aScreenPoint = aScreenEnd - aSize;
|
|
|
|
}
|
|
|
|
else {
|
2011-08-05 12:24:24 -07:00
|
|
|
aScreenPoint = endpos + aMarginBegin;
|
2009-01-06 11:21:23 -08:00
|
|
|
popupSize = aScreenEnd - aScreenPoint;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-10 07:19:16 -08:00
|
|
|
else {
|
2013-04-18 17:47:27 -07:00
|
|
|
// if the newly calculated position is different than the existing
|
|
|
|
// position, we flip such that the popup is to the left or top of the
|
|
|
|
// anchor point instead.
|
|
|
|
nscoord newScreenPoint = startpos - aSize - aMarginBegin - aOffsetForContextMenu;
|
|
|
|
if (newScreenPoint != aScreenPoint) {
|
|
|
|
*aFlipSide = true;
|
|
|
|
aScreenPoint = newScreenPoint;
|
|
|
|
|
|
|
|
// check if the new position is still off the left or top edge of the
|
|
|
|
// screen. If so, resize the popup.
|
|
|
|
if (aScreenPoint < aScreenBegin) {
|
|
|
|
aScreenPoint = aScreenBegin;
|
|
|
|
if (!mIsContextMenu) {
|
|
|
|
popupSize = startpos - aScreenPoint - aMarginBegin;
|
|
|
|
}
|
2009-01-06 11:21:23 -08:00
|
|
|
}
|
2008-12-10 07:19:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aScreenPoint = aScreenEnd - aSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-05 12:24:24 -07:00
|
|
|
// Make sure that the point is within the screen boundaries and that the
|
|
|
|
// size isn't off the edge of the screen. This can happen when a large
|
|
|
|
// positive or negative margin is used.
|
|
|
|
if (aScreenPoint < aScreenBegin) {
|
|
|
|
aScreenPoint = aScreenBegin;
|
|
|
|
}
|
|
|
|
if (aScreenPoint > aScreenEnd) {
|
|
|
|
aScreenPoint = aScreenEnd - aSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If popupSize ended up being negative, or the original size was actually
|
|
|
|
// smaller than the calculated popup size, just use the original size instead.
|
|
|
|
if (popupSize <= 0 || aSize < popupSize) {
|
|
|
|
popupSize = aSize;
|
|
|
|
}
|
2013-01-15 04:22:03 -08:00
|
|
|
return std::min(popupSize, aScreenEnd - aScreenPoint);
|
2008-12-10 07:19:16 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsresult
|
2014-01-28 08:28:45 -08:00
|
|
|
nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame, bool aIsMove, bool aSizedToPopup)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-23 10:45:44 -08:00
|
|
|
if (!mShouldAutoPosition)
|
2007-07-04 08:49:38 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-25 18:37:20 -07:00
|
|
|
// If this is due to a move, return early if the popup hasn't been laid out
|
|
|
|
// yet. On Windows, this can happen when using a drag popup before it opens.
|
|
|
|
if (aIsMove && (mPrefSize.width == -1 || mPrefSize.height == -1)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
2007-08-27 09:23:52 -07:00
|
|
|
nsIFrame* rootFrame = presContext->PresShell()->FrameManager()->GetRootFrame();
|
2008-09-06 01:52:56 -07:00
|
|
|
NS_ASSERTION(rootFrame->GetView() && GetView() &&
|
|
|
|
rootFrame->GetView() == GetView()->GetParent(),
|
|
|
|
"rootFrame's view is not our view's parent???");
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// if the frame is not specified, use the anchor node passed to OpenPopup. If
|
2007-07-04 08:49:38 -07:00
|
|
|
// that wasn't specified either, use the root frame. Note that mAnchorContent
|
|
|
|
// might be a different document so its presshell must be used.
|
|
|
|
if (!aAnchorFrame) {
|
|
|
|
if (mAnchorContent) {
|
2010-07-27 06:38:02 -07:00
|
|
|
aAnchorFrame = mAnchorContent->GetPrimaryFrame();
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-08-19 09:55:18 -07:00
|
|
|
|
|
|
|
if (!aAnchorFrame) {
|
2007-08-27 09:23:52 -07:00
|
|
|
aAnchorFrame = rootFrame;
|
2007-08-19 09:55:18 -07:00
|
|
|
if (!aAnchorFrame)
|
|
|
|
return NS_OK;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
}
|
2007-07-18 08:24:57 -07:00
|
|
|
|
2014-06-09 04:40:48 -07:00
|
|
|
// In order to deal with transforms, we need the root prescontext:
|
|
|
|
nsPresContext* rootPresContext = presContext->GetRootPresContext();
|
|
|
|
|
|
|
|
// If we can't reach a root pres context, don't bother continuing:
|
|
|
|
if (!rootPresContext) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And then we need its root frame for a reference
|
|
|
|
nsIFrame* referenceFrame = rootPresContext->FrameManager()->GetRootFrame();
|
|
|
|
|
|
|
|
// the dimensions of the anchor
|
|
|
|
nsRect parentRect = aAnchorFrame->GetRectRelativeToSelf();
|
|
|
|
// Relative to the root
|
|
|
|
parentRect = nsLayoutUtils::TransformFrameRectToAncestor(aAnchorFrame,
|
|
|
|
parentRect,
|
|
|
|
referenceFrame);
|
|
|
|
// Relative to the screen
|
|
|
|
parentRect.MoveBy(referenceFrame->GetScreenRectInAppUnits().TopLeft());
|
|
|
|
// In its own app units
|
|
|
|
parentRect.ConvertAppUnitsRoundOut(rootPresContext->AppUnitsPerDevPixel(),
|
|
|
|
presContext->AppUnitsPerDevPixel());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-19 08:37:32 -08:00
|
|
|
// Set the popup's size to the preferred size. Below, this size will be
|
|
|
|
// adjusted to fit on the screen or within the content area. If the anchor
|
|
|
|
// is sized to the popup, use the anchor's width instead of the preferred
|
|
|
|
// width. The preferred size should already be set by the parent frame.
|
|
|
|
NS_ASSERTION(mPrefSize.width >= 0 || mPrefSize.height >= 0,
|
|
|
|
"preferred size of popup not set");
|
2014-01-28 08:28:45 -08:00
|
|
|
mRect.width = aSizedToPopup ? parentRect.width : mPrefSize.width;
|
2007-12-19 08:37:32 -08:00
|
|
|
mRect.height = mPrefSize.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// the screen position in app units where the popup should appear
|
|
|
|
nsPoint screenPoint;
|
|
|
|
|
|
|
|
// For anchored popups, the anchor rectangle. For non-anchored popups, the
|
|
|
|
// size will be 0.
|
2009-01-14 19:27:09 -08:00
|
|
|
nsRect anchorRect = parentRect;
|
2007-08-27 09:23:52 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// indicators of whether the popup should be flipped or resized.
|
2010-10-13 12:41:37 -07:00
|
|
|
FlipStyle hFlip = FlipStyle_None, vFlip = FlipStyle_None;
|
|
|
|
|
2009-02-17 07:51:11 -08:00
|
|
|
nsMargin margin(0, 0, 0, 0);
|
2013-02-16 13:51:02 -08:00
|
|
|
StyleMargin()->GetMargin(margin);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// the screen rectangle of the root frame, in dev pixels.
|
2008-06-15 18:26:41 -07:00
|
|
|
nsRect rootScreenRect = rootFrame->GetScreenRectInAppUnits();
|
2007-08-27 09:23:52 -07:00
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext* devContext = presContext->DeviceContext();
|
2008-04-23 14:25:34 -07:00
|
|
|
nscoord offsetForContextMenu = 0;
|
2011-07-29 02:38:39 -07:00
|
|
|
|
2014-02-07 09:35:09 -08:00
|
|
|
bool isNoAutoHide = IsNoAutoHide();
|
|
|
|
nsPopupLevel popupLevel = PopupLevel(isNoAutoHide);
|
|
|
|
|
2011-07-29 02:38:39 -07:00
|
|
|
if (IsAnchored()) {
|
2008-12-10 07:19:16 -08:00
|
|
|
// if we are anchored, there are certain things we don't want to do when
|
|
|
|
// repositioning the popup to fit on the screen, such as end up positioned
|
|
|
|
// over the anchor, for instance a popup appearing over the menu label.
|
|
|
|
// When doing this reposition, we want to move the popup to the side with
|
|
|
|
// the most room. The combination of anchor and alignment dictate if we
|
|
|
|
// readjust above/below or to the left/right.
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mAnchorContent) {
|
2008-12-10 07:19:16 -08:00
|
|
|
// move the popup according to the anchor and alignment. This will also
|
|
|
|
// tell us which axis the popup is flush against in case we have to move
|
|
|
|
// it around later. The AdjustPositionForAnchorAlign method accounts for
|
|
|
|
// the popup's margin.
|
|
|
|
screenPoint = AdjustPositionForAnchorAlign(anchorRect, hFlip, vFlip);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else {
|
2007-08-27 09:23:52 -07:00
|
|
|
// with no anchor, the popup is positioned relative to the root frame
|
2008-12-10 07:19:16 -08:00
|
|
|
anchorRect = rootScreenRect;
|
|
|
|
screenPoint = anchorRect.TopLeft() + nsPoint(margin.left, margin.top);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// mXPos and mYPos specify an additonal offset passed to OpenPopup that
|
2012-12-20 17:26:32 -08:00
|
|
|
// should be added to the position. We also add the offset to the anchor
|
|
|
|
// pos so a later flip/resize takes the offset into account.
|
|
|
|
nscoord anchorXOffset = presContext->CSSPixelsToAppUnits(mXPos);
|
|
|
|
if (IsDirectionRTL()) {
|
|
|
|
screenPoint.x -= anchorXOffset;
|
|
|
|
anchorRect.x -= anchorXOffset;
|
|
|
|
} else {
|
|
|
|
screenPoint.x += anchorXOffset;
|
|
|
|
anchorRect.x += anchorXOffset;
|
|
|
|
}
|
|
|
|
nscoord anchorYOffset = presContext->CSSPixelsToAppUnits(mYPos);
|
|
|
|
screenPoint.y += anchorYOffset;
|
|
|
|
anchorRect.y += anchorYOffset;
|
2010-07-27 06:38:03 -07:00
|
|
|
|
|
|
|
// If this is a noautohide popup, set the screen coordinates of the popup.
|
|
|
|
// This way, the popup stays at the location where it was opened even when
|
|
|
|
// the window is moved. Popups at the parent level follow the parent
|
|
|
|
// window as it is moved and remained anchored, so we want to maintain the
|
|
|
|
// anchoring instead.
|
2014-02-07 09:35:09 -08:00
|
|
|
if (isNoAutoHide && popupLevel != ePopupLevelParent) {
|
2010-07-27 06:38:03 -07:00
|
|
|
// Account for the margin that will end up being added to the screen coordinate
|
|
|
|
// the next time SetPopupPosition is called.
|
|
|
|
mScreenXPos = presContext->AppUnitsToIntCSSPixels(screenPoint.x - margin.left);
|
|
|
|
mScreenYPos = presContext->AppUnitsToIntCSSPixels(screenPoint.y - margin.top);
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
else {
|
2007-11-22 06:12:03 -08:00
|
|
|
// the popup is positioned at a screen coordinate.
|
|
|
|
// first convert the screen position in mScreenXPos and mScreenYPos from
|
|
|
|
// CSS pixels into device pixels, ignoring any scaling as mScreenXPos and
|
|
|
|
// mScreenYPos are unscaled screen coordinates.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t factor = devContext->UnscaledAppUnitsPerDevPixel();
|
2007-11-22 06:12:03 -08:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// context menus should be offset by two pixels so that they don't appear
|
|
|
|
// directly where the cursor is. Otherwise, it is too easy to have the
|
|
|
|
// context menu close up again.
|
2008-04-23 14:25:34 -07:00
|
|
|
if (mAdjustOffsetForContextMenu) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t offsetForContextMenuDev =
|
2012-09-14 14:17:08 -07:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(CONTEXT_MENU_OFFSET_PIXELS) / factor;
|
2008-04-23 14:25:34 -07:00
|
|
|
offsetForContextMenu = presContext->DevPixelsToAppUnits(offsetForContextMenuDev);
|
|
|
|
}
|
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// next, convert into app units accounting for the scaling
|
|
|
|
screenPoint.x = presContext->DevPixelsToAppUnits(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(mScreenXPos) / factor);
|
|
|
|
screenPoint.y = presContext->DevPixelsToAppUnits(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(mScreenYPos) / factor);
|
2009-01-06 11:21:23 -08:00
|
|
|
anchorRect = nsRect(screenPoint, nsSize(0, 0));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// add the margins on the popup
|
|
|
|
screenPoint.MoveBy(margin.left + offsetForContextMenu,
|
|
|
|
margin.top + offsetForContextMenu);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// screen positioned popups can be flipped vertically but never horizontally
|
2010-10-13 12:41:37 -07:00
|
|
|
vFlip = FlipStyle_Outside;
|
2007-04-20 11:20:03 -07:00
|
|
|
}
|
|
|
|
|
2014-01-22 12:09:03 -08:00
|
|
|
// If a panel is being moved or has flip="none", don't constrain or flip it. But always do this for
|
2011-04-13 10:53:24 -07:00
|
|
|
// content shells, so that the popup doesn't extend outside the containing frame.
|
2014-01-22 12:09:03 -08:00
|
|
|
if (mInContentShell || (mFlip != FlipType_None && (!aIsMove || mPopupType != ePopupTypePanel))) {
|
2014-02-07 09:35:09 -08:00
|
|
|
nsRect screenRect = GetConstraintRect(anchorRect, rootScreenRect, popupLevel);
|
2011-04-13 10:53:24 -07:00
|
|
|
|
2014-02-06 17:08:31 -08:00
|
|
|
// Ensure that anchorRect is on screen.
|
|
|
|
anchorRect = anchorRect.Intersect(screenRect);
|
2010-02-01 07:11:08 -08:00
|
|
|
|
2011-04-13 10:53:24 -07:00
|
|
|
// shrink the the popup down if it is larger than the screen size
|
|
|
|
if (mRect.width > screenRect.width)
|
|
|
|
mRect.width = screenRect.width;
|
|
|
|
if (mRect.height > screenRect.height)
|
|
|
|
mRect.height = screenRect.height;
|
|
|
|
|
|
|
|
// at this point the anchor (anchorRect) is within the available screen
|
|
|
|
// area (screenRect) and the popup is known to be no larger than the screen.
|
2013-05-08 15:59:03 -07:00
|
|
|
|
|
|
|
// We might want to "slide" an arrow if the panel is of the correct type -
|
|
|
|
// but we can only slide on one axis - the other axis must be "flipped or
|
|
|
|
// resized" as normal.
|
2014-01-08 01:35:06 -08:00
|
|
|
bool slideHorizontal = false, slideVertical = false;
|
2014-01-22 12:09:03 -08:00
|
|
|
if (mFlip == FlipType_Slide) {
|
2014-01-08 01:35:06 -08:00
|
|
|
int8_t position = GetAlignmentPosition();
|
|
|
|
slideHorizontal = position >= POPUPPOSITION_BEFORESTART &&
|
|
|
|
position <= POPUPPOSITION_AFTEREND;
|
|
|
|
slideVertical = position >= POPUPPOSITION_STARTBEFORE &&
|
|
|
|
position <= POPUPPOSITION_ENDAFTER;
|
|
|
|
}
|
2013-05-08 15:59:03 -07:00
|
|
|
|
2011-04-13 10:53:24 -07:00
|
|
|
// Next, check if there is enough space to show the popup at full size when
|
|
|
|
// positioned at screenPoint. If not, flip the popups to the opposite side
|
|
|
|
// of their anchor point, or resize them as necessary.
|
2013-05-08 15:59:03 -07:00
|
|
|
if (slideHorizontal) {
|
|
|
|
mRect.width = SlideOrResize(screenPoint.x, mRect.width, screenRect.x,
|
|
|
|
screenRect.XMost(), &mAlignmentOffset);
|
|
|
|
} else {
|
|
|
|
mRect.width = FlipOrResize(screenPoint.x, mRect.width, screenRect.x,
|
|
|
|
screenRect.XMost(), anchorRect.x, anchorRect.XMost(),
|
|
|
|
margin.left, margin.right, offsetForContextMenu, hFlip,
|
|
|
|
&mHFlip);
|
|
|
|
}
|
|
|
|
if (slideVertical) {
|
|
|
|
mRect.height = SlideOrResize(screenPoint.y, mRect.height, screenRect.y,
|
|
|
|
screenRect.YMost(), &mAlignmentOffset);
|
|
|
|
} else {
|
|
|
|
mRect.height = FlipOrResize(screenPoint.y, mRect.height, screenRect.y,
|
|
|
|
screenRect.YMost(), anchorRect.y, anchorRect.YMost(),
|
|
|
|
margin.top, margin.bottom, offsetForContextMenu, vFlip,
|
|
|
|
&mVFlip);
|
|
|
|
}
|
2011-04-13 10:53:24 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(screenPoint.x >= screenRect.x && screenPoint.y >= screenRect.y &&
|
|
|
|
screenPoint.x + mRect.width <= screenRect.XMost() &&
|
|
|
|
screenPoint.y + mRect.height <= screenRect.YMost(),
|
|
|
|
"Popup is offscreen");
|
2008-04-29 18:41:56 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-28 18:00:27 -07:00
|
|
|
// snap the popup's position in screen coordinates to device pixels,
|
|
|
|
// see bug 622507, bug 961431
|
|
|
|
screenPoint.x = presContext->RoundAppUnitsToNearestDevPixels(screenPoint.x);
|
|
|
|
screenPoint.y = presContext->RoundAppUnitsToNearestDevPixels(screenPoint.y);
|
|
|
|
|
2008-12-10 07:19:16 -08:00
|
|
|
// determine the x and y position of the view by subtracting the desired
|
|
|
|
// screen position from the screen position of the root frame.
|
|
|
|
nsPoint viewPoint = screenPoint - rootScreenRect.TopLeft();
|
2011-02-21 00:52:42 -08:00
|
|
|
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = GetView();
|
2010-07-27 06:38:03 -07:00
|
|
|
NS_ASSERTION(view, "popup with no view");
|
|
|
|
|
|
|
|
// Offset the position by the width and height of the borders and titlebar.
|
|
|
|
// Even though GetClientOffset should return (0, 0) when there is no
|
|
|
|
// titlebar or borders, we skip these calculations anyway for non-panels
|
|
|
|
// to save time since they will never have a titlebar.
|
|
|
|
nsIWidget* widget = view->GetWidget();
|
|
|
|
if (mPopupType == ePopupTypePanel && widget) {
|
2011-12-01 13:35:42 -08:00
|
|
|
mLastClientOffset = widget->GetClientOffset();
|
|
|
|
viewPoint.x += presContext->DevPixelsToAppUnits(mLastClientOffset.x);
|
|
|
|
viewPoint.y += presContext->DevPixelsToAppUnits(mLastClientOffset.y);
|
2010-07-27 06:38:03 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
presContext->GetPresShell()->GetViewManager()->
|
|
|
|
MoveViewTo(view, viewPoint.x, viewPoint.y);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Now that we've positioned the view, sync up the frame's origin.
|
2008-12-10 07:19:16 -08:00
|
|
|
nsBoxFrame::SetPosition(viewPoint - GetParent()->GetOffsetTo(rootFrame));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-28 08:28:45 -08:00
|
|
|
if (aSizedToPopup) {
|
2007-07-04 08:49:38 -07:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2008-12-10 07:19:16 -08:00
|
|
|
// XXXndeakin can parentSize.width still extend outside?
|
2009-01-14 19:27:09 -08:00
|
|
|
SetBounds(state, nsRect(mRect.x, mRect.y, parentRect.width, mRect.height));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
/* virtual */ nsMenuFrame*
|
|
|
|
nsMenuPopupFrame::GetCurrentMenuItem()
|
2007-06-29 15:15:59 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
return mCurrentMenu;
|
2007-06-29 15:15:59 -07:00
|
|
|
}
|
|
|
|
|
2009-12-23 10:45:44 -08:00
|
|
|
nsRect
|
2010-08-02 08:06:04 -07:00
|
|
|
nsMenuPopupFrame::GetConstraintRect(const nsRect& aAnchorRect,
|
2014-02-07 09:35:09 -08:00
|
|
|
const nsRect& aRootScreenRect,
|
|
|
|
nsPopupLevel aPopupLevel)
|
2009-12-23 10:45:44 -08:00
|
|
|
{
|
|
|
|
nsIntRect screenRectPixels;
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
|
|
|
|
// determine the available screen space. It will be reduced by the OS chrome
|
|
|
|
// such as menubars. It addition, for content shells, it will be the area of
|
|
|
|
// the content rather than the screen.
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1"));
|
|
|
|
if (sm) {
|
|
|
|
// for content shells, get the screen where the root frame is located.
|
|
|
|
// This is because we need to constrain the content to this content area,
|
|
|
|
// so we should use the same screen. Otherwise, use the screen where the
|
|
|
|
// anchor is located.
|
2010-08-02 08:06:04 -07:00
|
|
|
nsRect rect = mInContentShell ? aRootScreenRect : aAnchorRect;
|
2012-10-16 12:41:19 -07:00
|
|
|
// nsIScreenManager::ScreenForRect wants the coordinates in CSS pixels
|
2013-01-15 04:22:03 -08:00
|
|
|
int32_t width = std::max(1, nsPresContext::AppUnitsToIntCSSPixels(rect.width));
|
|
|
|
int32_t height = std::max(1, nsPresContext::AppUnitsToIntCSSPixels(rect.height));
|
2012-10-16 12:41:19 -07:00
|
|
|
sm->ScreenForRect(nsPresContext::AppUnitsToIntCSSPixels(rect.x),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(rect.y),
|
2010-08-02 08:06:04 -07:00
|
|
|
width, height, getter_AddRefs(screen));
|
2009-12-23 10:45:44 -08:00
|
|
|
if (screen) {
|
2014-02-07 09:35:09 -08:00
|
|
|
// Non-top-level popups (which will always be panels)
|
|
|
|
// should never overlap the OS bar:
|
|
|
|
bool dontOverlapOSBar = aPopupLevel != ePopupLevelTop;
|
2009-12-23 10:45:44 -08:00
|
|
|
// get the total screen area if the popup is allowed to overlap it.
|
2014-02-07 09:35:09 -08:00
|
|
|
if (!dontOverlapOSBar && mMenuCanOverlapOSBar && !mInContentShell)
|
2009-12-23 10:45:44 -08:00
|
|
|
screen->GetRect(&screenRectPixels.x, &screenRectPixels.y,
|
|
|
|
&screenRectPixels.width, &screenRectPixels.height);
|
|
|
|
else
|
|
|
|
screen->GetAvailRect(&screenRectPixels.x, &screenRectPixels.y,
|
|
|
|
&screenRectPixels.width, &screenRectPixels.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect screenRect = screenRectPixels.ToAppUnits(presContext->AppUnitsPerDevPixel());
|
|
|
|
if (mInContentShell) {
|
|
|
|
// for content shells, clip to the client area rather than the screen area
|
|
|
|
screenRect.IntersectRect(screenRect, aRootScreenRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
return screenRect;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void nsMenuPopupFrame::CanAdjustEdges(int8_t aHorizontalSide, int8_t aVerticalSide, nsIntPoint& aChange)
|
2009-12-23 10:45:44 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t popupAlign(mPopupAlignment);
|
2011-01-13 06:02:20 -08:00
|
|
|
if (IsDirectionRTL()) {
|
2009-12-23 10:45:44 -08:00
|
|
|
popupAlign = -popupAlign;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aHorizontalSide == (mHFlip ? NS_SIDE_RIGHT : NS_SIDE_LEFT)) {
|
|
|
|
if (popupAlign == POPUPALIGNMENT_TOPLEFT || popupAlign == POPUPALIGNMENT_BOTTOMLEFT) {
|
|
|
|
aChange.x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aHorizontalSide == (mHFlip ? NS_SIDE_LEFT : NS_SIDE_RIGHT)) {
|
|
|
|
if (popupAlign == POPUPALIGNMENT_TOPRIGHT || popupAlign == POPUPALIGNMENT_BOTTOMRIGHT) {
|
|
|
|
aChange.x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aVerticalSide == (mVFlip ? NS_SIDE_BOTTOM : NS_SIDE_TOP)) {
|
|
|
|
if (popupAlign == POPUPALIGNMENT_TOPLEFT || popupAlign == POPUPALIGNMENT_TOPRIGHT) {
|
|
|
|
aChange.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aVerticalSide == (mVFlip ? NS_SIDE_TOP : NS_SIDE_BOTTOM)) {
|
|
|
|
if (popupAlign == POPUPALIGNMENT_BOTTOMLEFT || popupAlign == POPUPALIGNMENT_BOTTOMRIGHT) {
|
|
|
|
aChange.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsMenuPopupFrame::ConsumeOutsideClicks()
|
2007-06-29 15:15:59 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
// If the popup has explicitly set a consume mode, honor that.
|
|
|
|
if (mConsumeRollupEvent != nsIPopupBoxObject::ROLLUP_DEFAULT)
|
|
|
|
return (mConsumeRollupEvent == nsIPopupBoxObject::ROLLUP_CONSUME);
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2012-06-22 13:07:26 -07:00
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::consumeoutsideclicks,
|
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
|
|
|
return true;
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::consumeoutsideclicks,
|
|
|
|
nsGkAtoms::_false, eCaseMatters))
|
|
|
|
return false;
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsCOMPtr<nsIContent> parentContent = mContent->GetParent();
|
|
|
|
if (parentContent) {
|
2014-06-19 19:01:40 -07:00
|
|
|
dom::NodeInfo *ni = parentContent->NodeInfo();
|
2007-07-04 08:49:38 -07:00
|
|
|
if (ni->Equals(nsGkAtoms::menulist, kNameSpaceID_XUL))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true; // Consume outside clicks for combo boxes on all platforms
|
2014-02-10 14:57:01 -08:00
|
|
|
#if defined(XP_WIN)
|
2007-07-04 08:49:38 -07:00
|
|
|
// Don't consume outside clicks for menus in Windows
|
|
|
|
if (ni->Equals(nsGkAtoms::menu, kNameSpaceID_XUL) ||
|
2011-03-31 05:28:19 -07:00
|
|
|
ni->Equals(nsGkAtoms::splitmenu, kNameSpaceID_XUL) ||
|
2011-01-19 15:17:00 -08:00
|
|
|
ni->Equals(nsGkAtoms::popupset, kNameSpaceID_XUL) ||
|
2011-03-31 05:28:19 -07:00
|
|
|
((ni->Equals(nsGkAtoms::button, kNameSpaceID_XUL) ||
|
|
|
|
ni->Equals(nsGkAtoms::toolbarbutton, kNameSpaceID_XUL)) &&
|
|
|
|
(parentContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::menu, eCaseMatters) ||
|
|
|
|
parentContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::menuButton, eCaseMatters)))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-19 15:17:00 -08:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
#endif
|
|
|
|
if (ni->Equals(nsGkAtoms::textbox, kNameSpaceID_XUL)) {
|
|
|
|
// Don't consume outside clicks for autocomplete widget
|
|
|
|
if (parentContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::autocomplete, eCaseMatters))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-06-29 15:15:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-01 04:22:31 -07:00
|
|
|
// XXXroc this is megalame. Fossicking around for a frame of the right
|
|
|
|
// type is a recipe for disaster in the long term.
|
|
|
|
nsIScrollableFrame* nsMenuPopupFrame::GetScrollFrame(nsIFrame* aStart)
|
|
|
|
{
|
|
|
|
if (!aStart)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-09-01 04:22:31 -07:00
|
|
|
|
|
|
|
// try start frame and siblings
|
|
|
|
nsIFrame* currFrame = aStart;
|
|
|
|
do {
|
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(currFrame);
|
|
|
|
if (sf)
|
|
|
|
return sf;
|
|
|
|
currFrame = currFrame->GetNextSibling();
|
|
|
|
} while (currFrame);
|
|
|
|
|
|
|
|
// try children
|
|
|
|
currFrame = aStart;
|
|
|
|
do {
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* childFrame = currFrame->GetFirstPrincipalChild();
|
2009-09-01 04:22:31 -07:00
|
|
|
nsIScrollableFrame* sf = GetScrollFrame(childFrame);
|
|
|
|
if (sf)
|
|
|
|
return sf;
|
|
|
|
currFrame = currFrame->GetNextSibling();
|
|
|
|
} while (currFrame);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-09-01 04:22:31 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void nsMenuPopupFrame::EnsureMenuItemIsVisible(nsMenuFrame* aMenuItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
if (aMenuItem) {
|
2012-03-19 19:09:50 -07:00
|
|
|
aMenuItem->PresContext()->PresShell()->ScrollFrameRectIntoView(
|
|
|
|
aMenuItem,
|
|
|
|
nsRect(nsPoint(0,0), aMenuItem->GetRect().Size()),
|
|
|
|
nsIPresShell::ScrollAxis(),
|
|
|
|
nsIPresShell::ScrollAxis(),
|
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN |
|
|
|
|
nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
NS_IMETHODIMP nsMenuPopupFrame::SetCurrentMenuItem(nsMenuFrame* aMenuItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-06-29 15:15:59 -07:00
|
|
|
if (mCurrentMenu == aMenuItem)
|
|
|
|
return NS_OK;
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCurrentMenu) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aMenuItem) {
|
|
|
|
EnsureMenuItemIsVisible(aMenuItem);
|
2011-10-17 07:59:28 -07:00
|
|
|
aMenuItem->SelectMenu(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentMenu = aMenuItem;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::CurrentMenuIsBeingDestroyed()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentMenu = nullptr;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuPopupFrame::ChangeMenuItem(nsMenuFrame* aMenuItem,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSelectFirstItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mCurrentMenu == aMenuItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// When a context menu is open, the current menu is locked, and no change
|
|
|
|
// to the menu is allowed.
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (!mIsContextMenu && pm && pm->HasContextMenu(this))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// Unset the current child.
|
|
|
|
if (mCurrentMenu) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mCurrentMenu->SelectMenu(false);
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuPopupFrame* popup = mCurrentMenu->GetPopup();
|
|
|
|
if (popup) {
|
|
|
|
if (mCurrentMenu->IsOpen()) {
|
|
|
|
if (pm)
|
|
|
|
pm->HidePopupAfterDelay(popup);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// Set the new child.
|
|
|
|
if (aMenuItem) {
|
|
|
|
EnsureMenuItemIsVisible(aMenuItem);
|
2011-10-17 07:59:28 -07:00
|
|
|
aMenuItem->SelectMenu(true);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentMenu = aMenuItem;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame*
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuPopupFrame::Enter(WidgetGUIEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mIncrementalString.Truncate();
|
|
|
|
|
|
|
|
// Give it to the child.
|
|
|
|
if (mCurrentMenu)
|
2011-04-13 10:53:24 -07:00
|
|
|
return mCurrentMenu->Enter(aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame*
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuPopupFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, bool& doAction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t charCode, keyCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
aKeyEvent->GetCharCode(&charCode);
|
|
|
|
aKeyEvent->GetKeyCode(&keyCode);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
doAction = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Enumerate over our list of frames.
|
2014-05-24 15:20:39 -07:00
|
|
|
nsContainerFrame* immediateParent = PresContext()->PresShell()->
|
2013-05-01 15:50:08 -07:00
|
|
|
FrameConstructor()->GetInsertionPoint(GetContent(), nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!immediateParent)
|
|
|
|
immediateParent = this;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t matchCount = 0, matchShortcutCount = 0;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool foundActive = false;
|
|
|
|
bool isShortcut;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsMenuFrame* frameBefore = nullptr;
|
|
|
|
nsMenuFrame* frameAfter = nullptr;
|
|
|
|
nsMenuFrame* frameShortcut = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIContent* parentContent = mContent->GetParent();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isMenu = parentContent &&
|
2007-07-04 08:49:38 -07:00
|
|
|
!parentContent->NodeInfo()->Equals(nsGkAtoms::menulist, kNameSpaceID_XUL);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static DOMTimeStamp lastKeyTime = 0;
|
|
|
|
DOMTimeStamp keyTime;
|
|
|
|
aKeyEvent->GetTimeStamp(&keyTime);
|
|
|
|
|
|
|
|
if (charCode == 0) {
|
2013-10-22 06:27:36 -07:00
|
|
|
if (keyCode == nsIDOMKeyEvent::DOM_VK_BACK_SPACE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!isMenu && !mIncrementalString.IsEmpty()) {
|
|
|
|
mIncrementalString.SetLength(mIncrementalString.Length() - 1);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
|
|
|
if (soundInterface)
|
|
|
|
soundInterface->Beep();
|
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t uniChar = ToLowerCase(static_cast<char16_t>(charCode));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isMenu || // Menu supports only first-letter navigation
|
|
|
|
keyTime - lastKeyTime > INC_TYP_INTERVAL) // Interval too long, treat as new typing
|
|
|
|
mIncrementalString = uniChar;
|
|
|
|
else {
|
|
|
|
mIncrementalString.Append(uniChar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See bug 188199 & 192346, if all letters in incremental string are same, just try to match the first one
|
|
|
|
nsAutoString incrementalString(mIncrementalString);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t charIndex = 1, stringLength = incrementalString.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (charIndex < stringLength && incrementalString[charIndex] == incrementalString[charIndex - 1]) {
|
|
|
|
charIndex++;
|
|
|
|
}
|
|
|
|
if (charIndex == stringLength) {
|
|
|
|
incrementalString.Truncate(1);
|
|
|
|
stringLength = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastKeyTime = keyTime;
|
|
|
|
|
|
|
|
// NOTE: If you crashed here due to a bogus |immediateParent| it is
|
|
|
|
// possible that the menu whose shortcut is being looked up has
|
|
|
|
// been destroyed already. One strategy would be to
|
|
|
|
// setTimeout(<func>,0) as detailed in:
|
|
|
|
// <http://bugzilla.mozilla.org/show_bug.cgi?id=126675#c32>
|
2014-05-12 13:23:12 -07:00
|
|
|
nsIFrame* firstMenuItem = nsXULPopupManager::GetNextMenuItem(immediateParent, nullptr, true);
|
|
|
|
nsIFrame* currFrame = firstMenuItem;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t menuAccessKey = -1;
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// We start searching from first child. This process is divided into two parts
|
|
|
|
// -- before current and after current -- by the current item
|
|
|
|
while (currFrame) {
|
|
|
|
nsIContent* current = currFrame->GetContent();
|
2014-05-12 13:23:12 -07:00
|
|
|
nsAutoString textKey;
|
|
|
|
if (menuAccessKey >= 0) {
|
|
|
|
// Get the shortcut attribute.
|
|
|
|
current->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, textKey);
|
|
|
|
}
|
|
|
|
if (textKey.IsEmpty()) { // No shortcut, try first letter
|
|
|
|
isShortcut = false;
|
|
|
|
current->GetAttr(kNameSpaceID_None, nsGkAtoms::label, textKey);
|
|
|
|
if (textKey.IsEmpty()) // No label, try another attribute (value)
|
|
|
|
current->GetAttr(kNameSpaceID_None, nsGkAtoms::value, textKey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
isShortcut = true;
|
|
|
|
|
|
|
|
if (StringBeginsWith(textKey, incrementalString,
|
|
|
|
nsCaseInsensitiveStringComparator())) {
|
|
|
|
// mIncrementalString is a prefix of textKey
|
|
|
|
nsMenuFrame* menu = do_QueryFrame(currFrame);
|
|
|
|
if (menu) {
|
|
|
|
// There is one match
|
|
|
|
matchCount++;
|
|
|
|
if (isShortcut) {
|
|
|
|
// There is one shortcut-key match
|
|
|
|
matchShortcutCount++;
|
|
|
|
// Record the matched item. If there is only one matched shortcut item, do it
|
|
|
|
frameShortcut = menu;
|
|
|
|
}
|
|
|
|
if (!foundActive) {
|
|
|
|
// It's a first candidate item located before/on the current item
|
|
|
|
if (!frameBefore)
|
|
|
|
frameBefore = menu;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// It's a first candidate item located after the current item
|
|
|
|
if (!frameAfter)
|
|
|
|
frameAfter = menu;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2014-05-12 13:23:12 -07:00
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-12 13:23:12 -07:00
|
|
|
// Get the active status
|
|
|
|
if (current->AttrValueIs(kNameSpaceID_None, nsGkAtoms::menuactive,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
|
|
foundActive = true;
|
|
|
|
if (stringLength > 1) {
|
|
|
|
// If there is more than one char typed, the current item has highest priority,
|
|
|
|
// otherwise the item next to current has highest priority
|
|
|
|
if (currFrame == frameBefore)
|
|
|
|
return frameBefore;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2014-05-12 13:23:12 -07:00
|
|
|
|
|
|
|
nsMenuFrame* menu = do_QueryFrame(currFrame);
|
|
|
|
currFrame = nsXULPopupManager::GetNextMenuItem(immediateParent, menu, true);
|
|
|
|
if (currFrame == firstMenuItem)
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
doAction = (isMenu && (matchCount == 1 || matchShortcutCount == 1));
|
|
|
|
|
|
|
|
if (matchShortcutCount == 1) // We have one matched shortcut item
|
|
|
|
return frameShortcut;
|
|
|
|
if (frameAfter) // If we have matched item after the current, use it
|
|
|
|
return frameAfter;
|
|
|
|
else if (frameBefore) // If we haven't, use the item before the current
|
|
|
|
return frameBefore;
|
|
|
|
|
|
|
|
// If we don't match anything, rollback the last typing
|
|
|
|
mIncrementalString.SetLength(mIncrementalString.Length() - 1);
|
|
|
|
|
|
|
|
// didn't find a matching menu item
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// behavior on Windows - this item is in a menu popup off of the
|
|
|
|
// menu bar, so beep and do nothing else
|
|
|
|
if (isMenu) {
|
|
|
|
nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
|
|
|
if (soundInterface)
|
|
|
|
soundInterface->Beep();
|
|
|
|
}
|
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-19 07:12:58 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuPopupFrame::LockMenuUntilClosed(bool aLock)
|
2010-04-19 07:12:58 -07:00
|
|
|
{
|
|
|
|
mIsMenuLocked = aLock;
|
|
|
|
|
|
|
|
// Lock / unlock the parent, too.
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(GetParent());
|
|
|
|
if (menu) {
|
|
|
|
nsMenuParent* parentParent = menu->GetMenuParent();
|
2010-04-19 07:12:58 -07:00
|
|
|
if (parentParent) {
|
|
|
|
parentParent->LockMenuUntilClosed(aLock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
nsIWidget*
|
|
|
|
nsMenuPopupFrame::GetWidget()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView * view = GetRootViewForPopup(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!view)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
return view->GetWidget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuPopupFrame::AttachedDismissalListener()
|
|
|
|
{
|
|
|
|
mConsumeRollupEvent = nsIPopupBoxObject::ROLLUP_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// helpers /////////////////////////////////////////////////////////////
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMenuPopupFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::left || aAttribute == nsGkAtoms::top)
|
|
|
|
MoveToAttributePosition();
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
if (aAttribute == nsGkAtoms::label) {
|
|
|
|
// set the label for the titlebar
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = GetView();
|
2010-07-27 06:38:04 -07:00
|
|
|
if (view) {
|
|
|
|
nsIWidget* widget = view->GetWidget();
|
|
|
|
if (widget) {
|
|
|
|
nsAutoString title;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, title);
|
|
|
|
if (!title.IsEmpty()) {
|
|
|
|
widget->SetTitle(title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuPopupFrame::MoveToAttributePosition()
|
|
|
|
{
|
|
|
|
// Move the widget around when the user sets the |left| and |top| attributes.
|
|
|
|
// Note that this is not the best way to move the widget, as it results in lots
|
|
|
|
// of FE notifications and is likely to be slow as molasses. Use |moveTo| on
|
|
|
|
// nsIPopupBoxObject if possible.
|
|
|
|
nsAutoString left, top;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::left, left);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::top, top);
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult err1, err2;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t xpos = left.ToInteger(&err1);
|
|
|
|
int32_t ypos = top.ToInteger(&err2);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (NS_SUCCEEDED(err1) && NS_SUCCEEDED(err2))
|
2011-10-17 07:59:28 -07:00
|
|
|
MoveTo(xpos, ypos, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsMenuPopupFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(GetParent());
|
|
|
|
if (menu) {
|
2010-06-21 05:37:35 -07:00
|
|
|
// clear the open attribute on the parent menu
|
|
|
|
nsContentUtils::AddScriptRunner(
|
2012-07-30 17:43:28 -07:00
|
|
|
new nsUnsetAttrRunnable(menu->GetContent(), nsGkAtoms::open));
|
2010-06-21 05:37:35 -07:00
|
|
|
}
|
|
|
|
|
2014-06-16 11:43:07 -07:00
|
|
|
ClearPopupShownDispatcher();
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
|
|
|
pm->PopupDestroyed(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-31 01:29:22 -08:00
|
|
|
nsIRootBox* rootBox =
|
|
|
|
nsIRootBox::GetRootBox(PresContext()->GetPresShell());
|
|
|
|
if (rootBox && rootBox->GetDefaultTooltip() == mContent) {
|
2012-07-30 07:20:58 -07:00
|
|
|
rootBox->SetDefaultTooltip(nullptr);
|
2008-12-31 01:29:22 -08:00
|
|
|
}
|
|
|
|
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMenuPopupFrame::MoveTo(int32_t aLeft, int32_t aTop, bool aUpdateAttrs)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-01 13:35:42 -08:00
|
|
|
nsIWidget* widget = GetWidget();
|
|
|
|
if ((mScreenXPos == aLeft && mScreenYPos == aTop) &&
|
|
|
|
(!widget || widget->GetClientOffset() == mLastClientOffset)) {
|
2010-07-27 06:38:02 -07:00
|
|
|
return;
|
2011-12-01 13:35:42 -08:00
|
|
|
}
|
2010-07-27 06:38:02 -07:00
|
|
|
|
2009-02-17 07:51:11 -08:00
|
|
|
// reposition the popup at the specified coordinates. Don't clear the anchor
|
|
|
|
// and position, because the popup can be reset to its anchor position by
|
2010-07-27 06:38:03 -07:00
|
|
|
// using (-1, -1) as coordinates. Subtract off the margin as it will be
|
|
|
|
// added to the position when SetPopupPosition is called.
|
|
|
|
nsMargin margin(0, 0, 0, 0);
|
2013-02-16 13:51:02 -08:00
|
|
|
StyleMargin()->GetMargin(margin);
|
2012-09-14 14:17:08 -07:00
|
|
|
|
|
|
|
// Workaround for bug 788189. See also bug 708278 comment #25 and following.
|
|
|
|
if (mAdjustOffsetForContextMenu) {
|
|
|
|
nscoord offsetForContextMenu =
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(CONTEXT_MENU_OFFSET_PIXELS);
|
|
|
|
margin.left += offsetForContextMenu;
|
|
|
|
margin.top += offsetForContextMenu;
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
mScreenXPos = aLeft - presContext->AppUnitsToIntCSSPixels(margin.left);
|
|
|
|
mScreenYPos = aTop - presContext->AppUnitsToIntCSSPixels(margin.top);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-28 08:28:45 -08:00
|
|
|
SetPopupPosition(nullptr, true, false);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2009-02-17 07:51:11 -08:00
|
|
|
nsCOMPtr<nsIContent> popup = mContent;
|
|
|
|
if (aUpdateAttrs && (popup->HasAttr(kNameSpaceID_None, nsGkAtoms::left) ||
|
|
|
|
popup->HasAttr(kNameSpaceID_None, nsGkAtoms::top)))
|
|
|
|
{
|
|
|
|
nsAutoString left, top;
|
|
|
|
left.AppendInt(aLeft);
|
|
|
|
top.AppendInt(aTop);
|
2011-10-17 07:59:28 -07:00
|
|
|
popup->SetAttr(kNameSpaceID_None, nsGkAtoms::left, left, false);
|
|
|
|
popup->SetAttr(kNameSpaceID_None, nsGkAtoms::top, top, false);
|
2009-02-17 07:51:11 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-23 05:11:13 -07:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::MoveToAnchor(nsIContent* aAnchorContent,
|
|
|
|
const nsAString& aPosition,
|
|
|
|
int32_t aXPos, int32_t aYPos,
|
|
|
|
bool aAttributesOverride)
|
|
|
|
{
|
2014-07-14 10:39:04 -07:00
|
|
|
NS_ASSERTION(IsVisible(), "popup must be visible to move it");
|
2012-10-23 05:11:13 -07:00
|
|
|
|
2014-07-14 10:39:04 -07:00
|
|
|
nsPopupState oldstate = mPopupState;
|
2012-10-23 05:11:13 -07:00
|
|
|
InitializePopup(aAnchorContent, mTriggerContent, aPosition,
|
|
|
|
aXPos, aYPos, aAttributesOverride);
|
|
|
|
// InitializePopup changed the state so reset it.
|
2014-07-14 10:39:04 -07:00
|
|
|
mPopupState = oldstate;
|
2012-10-23 05:11:13 -07:00
|
|
|
|
|
|
|
// Pass false here so that flipping and adjusting to fit on the screen happen.
|
2014-01-28 08:28:45 -08:00
|
|
|
SetPopupPosition(nullptr, false, false);
|
2012-10-23 05:11:13 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-11-28 12:18:11 -08:00
|
|
|
nsMenuPopupFrame::GetAutoPosition()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-11-28 12:18:11 -08:00
|
|
|
return mShouldAutoPosition;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuPopupFrame::SetAutoPosition(bool aShouldAutoPosition)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mShouldAutoPosition = aShouldAutoPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMenuPopupFrame::SetConsumeRollupEvent(uint32_t aConsumeMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mConsumeRollupEvent = aConsumeMode;
|
2013-04-18 17:47:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int8_t
|
|
|
|
nsMenuPopupFrame::GetAlignmentPosition() const
|
|
|
|
{
|
|
|
|
// The code below handles most cases of alignment, anchor and position values. Those that are
|
|
|
|
// not handled just return POPUPPOSITION_UNKNOWN.
|
|
|
|
|
|
|
|
if (mPosition == POPUPPOSITION_OVERLAP || mPosition == POPUPPOSITION_AFTERPOINTER)
|
|
|
|
return mPosition;
|
|
|
|
|
|
|
|
int8_t position = mPosition;
|
|
|
|
|
|
|
|
if (position == POPUPPOSITION_UNKNOWN) {
|
|
|
|
switch (mPopupAnchor) {
|
|
|
|
case POPUPALIGNMENT_BOTTOMCENTER:
|
|
|
|
position = mPopupAlignment == POPUPALIGNMENT_TOPRIGHT ?
|
|
|
|
POPUPPOSITION_AFTEREND : POPUPPOSITION_AFTERSTART;
|
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_TOPCENTER:
|
|
|
|
position = mPopupAlignment == POPUPALIGNMENT_BOTTOMRIGHT ?
|
|
|
|
POPUPPOSITION_BEFOREEND : POPUPPOSITION_BEFORESTART;
|
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_LEFTCENTER:
|
|
|
|
position = mPopupAlignment == POPUPALIGNMENT_BOTTOMRIGHT ?
|
|
|
|
POPUPPOSITION_STARTAFTER : POPUPPOSITION_STARTBEFORE;
|
|
|
|
break;
|
|
|
|
case POPUPALIGNMENT_RIGHTCENTER:
|
|
|
|
position = mPopupAlignment == POPUPALIGNMENT_BOTTOMLEFT ?
|
|
|
|
POPUPPOSITION_ENDAFTER : POPUPPOSITION_ENDBEFORE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHFlip) {
|
|
|
|
position = POPUPPOSITION_HFLIP(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mVFlip) {
|
|
|
|
position = POPUPPOSITION_VFLIP(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
return position;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-29 06:51:05 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* KEEP THIS IN SYNC WITH nsContainerFrame::CreateViewForFrame
|
|
|
|
* as much as possible. Until we get rid of views finally...
|
|
|
|
*/
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2011-10-19 12:10:13 -07:00
|
|
|
nsMenuPopupFrame::CreatePopupView()
|
2011-04-29 06:51:05 -07:00
|
|
|
{
|
|
|
|
if (HasView()) {
|
2013-03-19 18:47:48 -07:00
|
|
|
return;
|
2011-04-29 06:51:05 -07:00
|
|
|
}
|
|
|
|
|
2013-01-04 19:12:24 -08:00
|
|
|
nsViewManager* viewManager = PresContext()->GetPresShell()->GetViewManager();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != viewManager, "null view manager");
|
2011-04-29 06:51:05 -07:00
|
|
|
|
|
|
|
// Create a view
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* parentView = viewManager->GetRootView();
|
2011-10-19 12:10:13 -07:00
|
|
|
nsViewVisibility visibility = nsViewVisibility_kHide;
|
2012-09-27 23:57:33 -07:00
|
|
|
int32_t zIndex = INT32_MAX;
|
2011-10-19 12:10:13 -07:00
|
|
|
bool autoZIndex = false;
|
2011-04-29 06:51:05 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(parentView, "no parent view");
|
|
|
|
|
|
|
|
// Create a view
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView *view = viewManager->CreateView(GetRect(), parentView, visibility);
|
2013-03-19 18:47:48 -07:00
|
|
|
viewManager->SetViewZIndex(view, autoZIndex, zIndex);
|
|
|
|
// XXX put view last in document order until we can do better
|
|
|
|
viewManager->InsertChild(parentView, view, nullptr, true);
|
2011-04-29 06:51:05 -07:00
|
|
|
|
|
|
|
// Remember our view
|
|
|
|
SetView(view);
|
|
|
|
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
2011-10-19 12:10:13 -07:00
|
|
|
("nsMenuPopupFrame::CreatePopupView: frame=%p view=%p", this, view));
|
2011-04-29 06:51:05 -07:00
|
|
|
}
|