2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2006-01-06 20:49:19 +00:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2001-09-28 20:14:13 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-07-18 06:23:45 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-07-18 06:23:45 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-07-18 06:23:45 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2004-04-18 14:30:37 +00:00
|
|
|
* Original Author: David W. Hyatt (hyatt@netscape.com)
|
2000-03-23 21:10:09 +00:00
|
|
|
* Mike Pinkerton (pinkerton@netscape.com)
|
2000-03-01 03:12:51 +00:00
|
|
|
* Dean Tessman <dean_tessman@hotmail.com>
|
2001-06-04 23:03:24 +00:00
|
|
|
* Ben Goodger <ben@netscape.com>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-07-18 06:23:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsMenuPopupFrame.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1999-07-18 06:23:45 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsIAtom.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
1999-07-18 06:23:45 +00:00
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
1999-07-20 08:37:03 +00:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
1999-07-22 09:01:55 +00:00
|
|
|
#include "nsMenuFrame.h"
|
2007-07-04 15:49:38 +00:00
|
|
|
#include "nsMenuBarFrame.h"
|
|
|
|
#include "nsPopupSetFrame.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
2005-11-28 23:56:44 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
1999-11-23 03:02:01 +00:00
|
|
|
#include "nsIDOMScreen.h"
|
|
|
|
#include "nsIPresShell.h"
|
2004-09-02 03:08:51 +00:00
|
|
|
#include "nsFrameManager.h"
|
1999-11-23 03:02:01 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsRect.h"
|
2000-02-13 08:33:39 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2000-05-15 04:12:31 +00:00
|
|
|
#include "nsBoxLayoutState.h"
|
2000-11-13 21:25:07 +00:00
|
|
|
#include "nsIScrollableView.h"
|
2005-06-02 08:50:52 +00:00
|
|
|
#include "nsIScrollableFrame.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
2001-08-18 01:04:47 +00:00
|
|
|
#include "nsIRootBox.h"
|
2002-08-01 23:12:38 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2003-07-14 07:37:39 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2003-03-05 01:43:25 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2007-07-04 15:49:38 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2004-01-21 23:05:10 +00:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2007-07-04 15:49:38 +00:00
|
|
|
#include "nsIEventStateManager.h"
|
2004-09-28 18:37:50 +00:00
|
|
|
#include "nsIBoxLayout.h"
|
2005-12-31 23:34:46 +00:00
|
|
|
#include "nsIPopupBoxObject.h"
|
2007-03-05 21:55:23 +00:00
|
|
|
#include "nsIReflowCallback.h"
|
2007-07-06 04:23:56 +00:00
|
|
|
#include "nsBindingManager.h"
|
2002-02-15 03:53:26 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsISound.h"
|
|
|
|
#endif
|
1999-07-20 08:37:03 +00:00
|
|
|
|
|
|
|
const PRInt32 kMaxZ = 0x7fffffff; //XXX: Shouldn't there be a define somewhere for MaxInt for PRInt32
|
1999-07-18 06:23:45 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
static nsPopupSetFrame*
|
2004-07-31 23:15:21 +00:00
|
|
|
GetPopupSetFrame(nsPresContext* aPresContext)
|
2001-08-18 01:04:47 +00:00
|
|
|
{
|
2006-08-08 10:40:11 +00:00
|
|
|
nsIRootBox* rootBox = nsIRootBox::GetRootBox(aPresContext->PresShell());
|
2001-08-18 01:04:47 +00:00
|
|
|
if (!rootBox)
|
2005-01-25 18:18:34 +00:00
|
|
|
return nsnull;
|
2001-08-18 01:04:47 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
return rootBox->GetPopupSetFrame();
|
2001-08-18 01:04:47 +00:00
|
|
|
}
|
|
|
|
|
1999-07-18 06:23:45 +00:00
|
|
|
// NS_NewMenuPopupFrame
|
|
|
|
//
|
|
|
|
// Wrapper for creating a new menu popup container
|
|
|
|
//
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewMenuPopupFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-07-18 06:23:45 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsMenuPopupFrame (aPresShell, aContext);
|
1999-07-18 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2000-03-01 03:12:51 +00:00
|
|
|
// nsMenuPopupFrame ctor
|
1999-07-18 06:23:45 +00:00
|
|
|
//
|
2006-03-26 21:30:36 +00:00
|
|
|
nsMenuPopupFrame::nsMenuPopupFrame(nsIPresShell* aShell, nsStyleContext* aContext)
|
|
|
|
:nsBoxFrame(aShell, aContext),
|
|
|
|
mCurrentMenu(nsnull),
|
2007-07-04 15:49:38 +00:00
|
|
|
mPopupAlignment(POPUPALIGNMENT_NONE),
|
|
|
|
mPopupAnchor(POPUPALIGNMENT_NONE),
|
|
|
|
mPopupType(ePopupTypePanel),
|
2007-08-03 14:05:07 +00:00
|
|
|
mPopupState(ePopupClosed),
|
2007-07-04 15:49:38 +00:00
|
|
|
mIsOpenChanged(PR_FALSE),
|
|
|
|
mIsContextMenu(PR_FALSE),
|
|
|
|
mGeneratedChildren(PR_FALSE),
|
2006-03-26 21:30:36 +00:00
|
|
|
mMenuCanOverlapOSBar(PR_FALSE),
|
|
|
|
mShouldAutoPosition(PR_TRUE),
|
2007-04-20 18:20:03 +00:00
|
|
|
mConsumeRollupEvent(nsIPopupBoxObject::ROLLUP_DEFAULT),
|
|
|
|
mInContentShell(PR_TRUE)
|
1999-07-18 06:23:45 +00:00
|
|
|
{
|
2000-03-01 03:12:51 +00:00
|
|
|
} // ctor
|
1999-07-18 06:23:45 +00:00
|
|
|
|
|
|
|
|
1999-07-20 07:28:39 +00:00
|
|
|
NS_IMETHODIMP
|
2006-03-09 18:55:21 +00:00
|
|
|
nsMenuPopupFrame::Init(nsIContent* aContent,
|
1999-07-20 07:28:39 +00:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
nsresult rv = nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-05-14 00:42:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-03-14 22:48:09 +00:00
|
|
|
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
1999-07-20 09:50:48 +00:00
|
|
|
|
2000-03-23 21:10:09 +00:00
|
|
|
// lookup if we're allowed to overlap the OS bar (menubar/taskbar) from the
|
|
|
|
// look&feel object
|
2004-01-21 09:35:59 +00:00
|
|
|
PRBool tempBool;
|
2006-03-26 21:30:36 +00:00
|
|
|
presContext->LookAndFeel()->
|
2004-01-21 09:35:59 +00:00
|
|
|
GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, tempBool);
|
|
|
|
mMenuCanOverlapOSBar = tempBool;
|
1999-10-26 04:44:41 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
rv = CreateViewForFrame(presContext, this, GetStyleContext(), PR_TRUE, PR_TRUE);
|
2007-05-14 00:42:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-07-20 08:37:03 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
// XXX Hack. The popup's view should float above all other views,
|
2000-01-25 01:53:34 +00:00
|
|
|
// so we use the nsIView::SetFloating() to tell the view manager
|
|
|
|
// about that constraint.
|
2007-07-04 15:49:38 +00:00
|
|
|
nsIView* ourView = GetView();
|
|
|
|
nsIViewManager* viewManager = ourView->GetViewManager();
|
2001-12-01 14:31:45 +00:00
|
|
|
viewManager->SetViewFloating(ourView, PR_TRUE);
|
2000-01-25 01:53:34 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
mPopupType = ePopupTypePanel;
|
|
|
|
nsIDocument* doc = aContent->GetOwnerDoc();
|
|
|
|
if (doc) {
|
|
|
|
PRInt32 namespaceID;
|
|
|
|
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-04-20 18:20:03 +00:00
|
|
|
nsCOMPtr<nsISupports> cont = PresContext()->GetContainer();
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(cont);
|
|
|
|
PRInt32 type = -1;
|
|
|
|
if (dsti && NS_SUCCEEDED(dsti->GetItemType(&type)) &&
|
|
|
|
type == nsIDocShellTreeItem::typeChrome)
|
|
|
|
mInContentShell = PR_FALSE;
|
|
|
|
|
2007-07-04 15:49:38 +00: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()) {
|
2005-12-19 01:10:27 +00:00
|
|
|
CreateWidgetForView(ourView);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::EnsureWidget()
|
|
|
|
{
|
|
|
|
nsIView* ourView = GetView();
|
|
|
|
if (!ourView->HasWidget()) {
|
|
|
|
NS_ASSERTION(!mGeneratedChildren && !GetFirstChild(nsnull),
|
|
|
|
"Creating widget for MenuPopupFrame with children");
|
|
|
|
CreateWidgetForView(ourView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-19 01:10:27 +00:00
|
|
|
nsresult
|
|
|
|
nsMenuPopupFrame::CreateWidgetForView(nsIView* aView)
|
|
|
|
{
|
1999-07-20 08:37:03 +00:00
|
|
|
// Create a widget for ourselves.
|
|
|
|
nsWidgetInitData widgetData;
|
1999-07-27 04:27:17 +00:00
|
|
|
widgetData.mWindowType = eWindowType_popup;
|
|
|
|
widgetData.mBorderStyle = eBorderStyle_default;
|
2002-08-21 13:12:30 +00:00
|
|
|
widgetData.clipSiblings = PR_TRUE;
|
1999-09-26 22:45:35 +00:00
|
|
|
|
2007-05-10 15:46:42 +00:00
|
|
|
PRBool viewHasTransparentContent = !mInContentShell &&
|
|
|
|
nsLayoutUtils::FrameHasTransparency(this);
|
2005-12-19 01:10:27 +00:00
|
|
|
nsIContent* parentContent = GetContent()->GetParent();
|
2003-11-19 01:20:56 +00:00
|
|
|
nsIAtom *tag = nsnull;
|
2002-01-05 23:50:52 +00:00
|
|
|
if (parentContent)
|
2003-11-19 01:20:56 +00:00
|
|
|
tag = parentContent->Tag();
|
2006-12-26 17:47:52 +00:00
|
|
|
widgetData.mDropShadow = !(viewHasTransparentContent || tag == nsGkAtoms::menulist);
|
2002-01-05 23:50:52 +00:00
|
|
|
|
2006-04-11 20:44:17 +00:00
|
|
|
#if defined(XP_MACOSX) || defined(XP_BEOS)
|
1999-09-26 22:45:35 +00:00
|
|
|
static NS_DEFINE_IID(kCPopupCID, NS_POPUP_CID);
|
2005-12-19 01:10:27 +00:00
|
|
|
aView->CreateWidget(kCPopupCID, &widgetData, nsnull, PR_TRUE, PR_TRUE,
|
|
|
|
eContentTypeUI);
|
1999-09-26 22:45:35 +00:00
|
|
|
#else
|
1999-07-20 08:37:03 +00:00
|
|
|
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
|
2005-12-19 01:10:27 +00:00
|
|
|
aView->CreateWidget(kCChildCID, &widgetData, nsnull, PR_TRUE, PR_TRUE);
|
2005-12-19 02:44:40 +00:00
|
|
|
#endif
|
2006-09-07 08:50:43 +00:00
|
|
|
aView->GetWidget()->SetWindowTranslucency(viewHasTransparentContent);
|
2005-12-19 02:44:40 +00:00
|
|
|
return NS_OK;
|
1999-07-20 07:28:39 +00:00
|
|
|
}
|
1999-07-20 09:35:35 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
// this class is used for dispatching popupshowing events asynchronously.
|
|
|
|
class nsXULPopupShownEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsXULPopupShownEvent(nsIContent *aPopup, nsPresContext* aPresContext)
|
|
|
|
: mPopup(aPopup), mPresContext(aPresContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWN, nsnull, nsMouseEvent::eReal);
|
|
|
|
return nsEventDispatcher::Dispatch(mPopup, mPresContext, &event);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mPopup;
|
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuPopupFrame::SetInitialChildList(nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
|
|
|
// unless the list is empty, indicate that children have been generated.
|
|
|
|
if (aChildList)
|
|
|
|
mGeneratedChildren = PR_TRUE;
|
|
|
|
return nsBoxFrame::SetInitialChildList(aListName, aChildList);
|
|
|
|
}
|
|
|
|
|
2007-09-16 15:51:27 +00:00
|
|
|
PRBool
|
|
|
|
nsMenuPopupFrame::IsLeaf() const
|
|
|
|
{
|
|
|
|
if (mGeneratedChildren)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
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
|
|
|
|
// the parent menu is dependant on the size of the popup, so the frames
|
|
|
|
// need to exist in order to calculate this size.
|
|
|
|
nsIContent* parentContent = mContent->GetParent();
|
|
|
|
return (parentContent &&
|
|
|
|
!parentContent->HasAttr(kNameSpaceID_None, nsGkAtoms::sizetopopup));
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::AdjustView()
|
|
|
|
{
|
2007-08-03 14:05:07 +00:00
|
|
|
if (mPopupState == ePopupOpen || mPopupState == ePopupOpenAndVisible) {
|
2007-07-04 15:49:38 +00:00
|
|
|
// if the popup has just opened, make sure the scrolled window is at 0,0
|
|
|
|
if (mIsOpenChanged) {
|
|
|
|
nsIBox* child = GetChildBox();
|
|
|
|
nsCOMPtr<nsIScrollableFrame> scrollframe(do_QueryInterface(child));
|
|
|
|
if (scrollframe)
|
|
|
|
scrollframe->ScrollTo(nsPoint(0,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* view = GetView();
|
|
|
|
nsIViewManager* viewManager = view->GetViewManager();
|
|
|
|
nsRect rect = GetRect();
|
|
|
|
rect.x = rect.y = 0;
|
|
|
|
viewManager->ResizeView(view, rect);
|
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kShow);
|
2007-08-03 14:05:07 +00:00
|
|
|
mPopupState = ePopupOpenAndVisible;
|
2007-07-04 15:49:38 +00:00
|
|
|
|
|
|
|
nsPresContext* pc = PresContext();
|
|
|
|
nsContainerFrame::SyncFrameViewProperties(pc, this, nsnull, view, 0);
|
|
|
|
|
|
|
|
// fire popupshown event when the state has changed
|
|
|
|
if (mIsOpenChanged) {
|
|
|
|
mIsOpenChanged = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsXULPopupShownEvent(GetContent(), pc);
|
|
|
|
NS_DispatchToCurrentThread(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::InitPositionFromAnchorAlign(const nsAString& aAnchor,
|
|
|
|
const nsAString& aAlign)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::InitializePopup(nsIContent* aAnchorContent,
|
|
|
|
const nsAString& aPosition,
|
|
|
|
PRInt32 aXPos, PRInt32 aYPos,
|
|
|
|
PRBool aAttributesOverride)
|
|
|
|
{
|
|
|
|
EnsureWidget();
|
|
|
|
|
2007-08-03 14:05:07 +00:00
|
|
|
mPopupState = ePopupShowing;
|
2007-07-04 15:49:38 +00:00
|
|
|
mAnchorContent = aAnchorContent;
|
|
|
|
mXPos = aXPos;
|
|
|
|
mYPos = aYPos;
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
nsAutoString anchor, align, position;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::popupanchor, anchor);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::popupalign, align);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::position, position);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (position.EqualsLiteral("before_start")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMLEFT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("before_end")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPRIGHT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMRIGHT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("after_start")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("after_end")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMRIGHT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPRIGHT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("start_before")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPRIGHT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("start_after")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMRIGHT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("end_before")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPRIGHT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("end_after")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_BOTTOMRIGHT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_BOTTOMLEFT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("overlap")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_TOPLEFT;
|
|
|
|
}
|
|
|
|
else if (position.EqualsLiteral("after_pointer")) {
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_NONE;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_NONE;
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
PRInt32 err;
|
|
|
|
if (!left.IsEmpty()) {
|
|
|
|
PRInt32 x = left.ToInteger(&err);
|
|
|
|
if (NS_SUCCEEDED(err))
|
|
|
|
mScreenXPos = x;
|
|
|
|
}
|
|
|
|
if (!top.IsEmpty()) {
|
|
|
|
PRInt32 y = top.ToInteger(&err);
|
|
|
|
if (NS_SUCCEEDED(err))
|
|
|
|
mScreenYPos = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::InitializePopupAtScreen(PRInt32 aXPos, PRInt32 aYPos)
|
|
|
|
{
|
|
|
|
EnsureWidget();
|
|
|
|
|
2007-08-03 14:05:07 +00:00
|
|
|
mPopupState = ePopupShowing;
|
2007-07-04 15:49:38 +00:00
|
|
|
mAnchorContent = nsnull;
|
|
|
|
mScreenXPos = aXPos;
|
|
|
|
mScreenYPos = aYPos;
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_NONE;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::InitializePopupWithAnchorAlign(nsIContent* aAnchorContent,
|
|
|
|
nsAString& aAnchor,
|
|
|
|
nsAString& aAlign,
|
|
|
|
PRInt32 aXPos, PRInt32 aYPos)
|
|
|
|
{
|
|
|
|
EnsureWidget();
|
|
|
|
|
2007-08-03 14:05:07 +00:00
|
|
|
mPopupState = ePopupShowing;
|
2007-07-04 15:49:38 +00: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 12:12:47 +00:00
|
|
|
mXPos = 0;
|
|
|
|
mYPos = 0;
|
2007-07-04 15:49:38 +00:00
|
|
|
InitPositionFromAnchorAlign(aAnchor, aAlign);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mAnchorContent = nsnull;
|
|
|
|
mPopupAnchor = POPUPALIGNMENT_NONE;
|
|
|
|
mPopupAlignment = POPUPALIGNMENT_NONE;
|
|
|
|
mScreenXPos = aXPos;
|
|
|
|
mScreenYPos = aYPos;
|
2007-07-06 12:12:47 +00:00
|
|
|
mXPos = aXPos;
|
|
|
|
mYPos = aYPos;
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PR_CALLBACK
|
|
|
|
LazyGeneratePopupDone(nsIContent* aPopup, nsIFrame* aFrame, void* aArg)
|
|
|
|
{
|
|
|
|
// be safe and check the frame type
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::menuPopupFrame) {
|
|
|
|
nsWeakFrame weakFrame(aFrame);
|
2007-07-08 07:08:04 +00:00
|
|
|
nsMenuPopupFrame* popupFrame = static_cast<nsMenuPopupFrame*>(aFrame);
|
2007-07-04 15:49:38 +00:00
|
|
|
|
|
|
|
popupFrame->SetGeneratedChildren();
|
|
|
|
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm && popupFrame->IsMenu()) {
|
|
|
|
nsCOMPtr<nsIContent> popup = aPopup;
|
2007-07-04 18:37:33 +00:00
|
|
|
PRBool selectFirstItem = (PRBool)NS_PTR_TO_INT32(aArg);
|
2007-07-04 15:49:38 +00:00
|
|
|
if (selectFirstItem) {
|
|
|
|
nsMenuFrame* next = pm->GetNextMenuItem(popupFrame, nsnull, PR_TRUE);
|
|
|
|
popupFrame->SetCurrentMenuItem(next);
|
|
|
|
}
|
|
|
|
|
|
|
|
pm->UpdateMenuItems(popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (weakFrame.IsAlive()) {
|
|
|
|
popupFrame->PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(popupFrame, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMenuPopupFrame::ShowPopup(PRBool aIsContextMenu, PRBool aSelectFirstItem)
|
|
|
|
{
|
|
|
|
mIsContextMenu = aIsContextMenu;
|
|
|
|
|
|
|
|
PRBool hasChildren = PR_FALSE;
|
|
|
|
|
2007-08-03 14:05:07 +00:00
|
|
|
if (mPopupState == ePopupShowing) {
|
|
|
|
mPopupState = ePopupOpen;
|
2007-07-04 15:49:38 +00:00
|
|
|
mIsOpenChanged = PR_TRUE;
|
|
|
|
|
|
|
|
nsIFrame* parent = GetParent();
|
|
|
|
if (parent && parent->GetType() == nsGkAtoms::menuFrame) {
|
|
|
|
nsWeakFrame weakFrame(this);
|
2007-07-08 07:08:04 +00:00
|
|
|
(static_cast<nsMenuFrame*>(parent))->PopupOpened();
|
2007-07-04 15:49:38 +00:00
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the frames for the child menus have not been created yet, so tell the
|
|
|
|
// frame constructor to build them
|
|
|
|
if (mFrames.IsEmpty() && !mGeneratedChildren) {
|
|
|
|
PresContext()->PresShell()->FrameConstructor()->
|
2007-07-04 18:37:33 +00:00
|
|
|
AddLazyChildren(mContent, LazyGeneratePopupDone, NS_INT32_TO_PTR(aSelectFirstItem));
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
hasChildren = PR_TRUE;
|
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mShouldAutoPosition = PR_TRUE;
|
|
|
|
return hasChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-08-03 14:05:07 +00:00
|
|
|
nsMenuPopupFrame::HidePopup(PRBool aDeselectMenu, nsPopupState aNewState)
|
2007-07-04 15:49:38 +00:00
|
|
|
{
|
2007-08-03 14:05:07 +00:00
|
|
|
NS_ASSERTION(aNewState == ePopupClosed || aNewState == ePopupInvisible,
|
|
|
|
"popup being set to unexpected state");
|
|
|
|
|
|
|
|
// don't hide the popup when it isn't open
|
|
|
|
if (mPopupState == ePopupClosed || mPopupState == ePopupShowing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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())
|
|
|
|
SetCurrentMenuItem(nsnull);
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2007-08-03 14:05:07 +00:00
|
|
|
mIncrementalString.Truncate();
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2007-08-03 14:05:07 +00:00
|
|
|
mIsOpenChanged = PR_FALSE;
|
|
|
|
mCurrentMenu = nsnull; // make sure no current menu is set
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2007-08-03 14:05:07 +00:00
|
|
|
nsIView* view = GetView();
|
|
|
|
nsIViewManager* viewManager = view->GetViewManager();
|
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
|
|
viewManager->ResizeView(view, nsRect(0, 0, 0, 0));
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2007-08-03 14:05:07 +00:00
|
|
|
FireDOMEvent(NS_LITERAL_STRING("DOMMenuInactive"), mContent);
|
2007-07-04 15:49:38 +00: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.
|
|
|
|
nsIEventStateManager *esm = PresContext()->EventStateManager();
|
|
|
|
|
|
|
|
PRInt32 state;
|
|
|
|
esm->GetContentState(mContent, state);
|
|
|
|
|
|
|
|
if (state & NS_EVENT_STATE_HOVER)
|
|
|
|
esm->SetContentState(nsnull, NS_EVENT_STATE_HOVER);
|
|
|
|
|
|
|
|
nsIFrame* parent = GetParent();
|
|
|
|
if (parent && parent->GetType() == nsGkAtoms::menuFrame) {
|
2007-07-08 07:08:04 +00:00
|
|
|
(static_cast<nsMenuFrame*>(parent))->PopupClosed(aDeselectMenu);
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-08 01:11:43 +00:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::InvalidateInternal(const nsRect& aDamageRect,
|
|
|
|
nscoord aX, nscoord aY, nsIFrame* aForChild,
|
|
|
|
PRBool aImmediate)
|
|
|
|
{
|
|
|
|
InvalidateRoot(aDamageRect, aX, aY, aImmediate);
|
|
|
|
}
|
|
|
|
|
2000-04-25 07:10:48 +00:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::GetLayoutFlags(PRUint32& aFlags)
|
|
|
|
{
|
2000-05-18 00:37:27 +00:00
|
|
|
aFlags = NS_FRAME_NO_SIZE_VIEW | NS_FRAME_NO_MOVE_VIEW | NS_FRAME_NO_VISIBILITY;
|
2000-04-25 07:10:48 +00:00
|
|
|
}
|
|
|
|
|
2001-06-04 23:03:24 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GetRootViewForPopup
|
|
|
|
// Retrieves the view for the popup widget that contains the given frame.
|
2003-01-08 22:40:14 +00:00
|
|
|
// If the given frame is not contained by a popup widget, return the
|
|
|
|
// root view of the root viewmanager.
|
2007-07-04 15:49:38 +00:00
|
|
|
nsIView*
|
2007-08-27 16:23:52 +00:00
|
|
|
nsMenuPopupFrame::GetRootViewForPopup(nsIFrame* aStartFrame)
|
1999-09-10 08:47:12 +00:00
|
|
|
{
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = aStartFrame->GetClosestView();
|
|
|
|
NS_ASSERTION(view, "frame must have a closest view!");
|
2007-08-27 16:23:52 +00:00
|
|
|
nsIView* rootView = nsnull;
|
|
|
|
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();
|
|
|
|
if (widget) {
|
|
|
|
nsWindowType wtype;
|
|
|
|
widget->GetWindowType(wtype);
|
|
|
|
if (wtype == eWindowType_popup) {
|
2007-07-04 15:49:38 +00:00
|
|
|
return view;
|
2003-01-08 22:40:14 +00:00
|
|
|
}
|
2007-08-27 16:23:52 +00:00
|
|
|
}
|
2003-01-08 22:40:14 +00:00
|
|
|
|
2007-08-27 16:23:52 +00:00
|
|
|
nsIView* temp = view->GetParent();
|
|
|
|
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;
|
2001-06-04 23:03:24 +00:00
|
|
|
}
|
2007-08-27 16:23:52 +00:00
|
|
|
view = temp;
|
1999-09-10 08:47:12 +00:00
|
|
|
}
|
2007-06-29 22:15:59 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
2007-06-29 22:15:59 +00:00
|
|
|
|
2000-03-02 04:08:04 +00:00
|
|
|
//
|
|
|
|
// AdjustPositionForAnchorAlign
|
|
|
|
//
|
2007-07-04 15:49:38 +00:00
|
|
|
// Uses the anchor and alignment to move the popup around and anchor it to its
|
|
|
|
// parent. |outFlushWithTopBottom| will be TRUE if the popup is flush with
|
|
|
|
// either the top or bottom edge of its parent, and FALSE if it is flush with
|
|
|
|
// the left or right edge of the parent.
|
2000-03-02 04:08:04 +00:00
|
|
|
//
|
|
|
|
void
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuPopupFrame::AdjustPositionForAnchorAlign(PRInt32* ioXPos, PRInt32* ioYPos, const nsRect & inParentRect,
|
|
|
|
PRBool* outFlushWithTopBottom)
|
2000-03-02 04:08:04 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
PRInt8 popupAnchor(mPopupAnchor);
|
|
|
|
PRInt8 popupAlign(mPopupAlignment);
|
2001-08-15 04:09:41 +00:00
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
if (GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
2007-07-04 15:49:38 +00:00
|
|
|
popupAnchor = -popupAnchor;
|
|
|
|
popupAlign = -popupAlign;
|
2001-08-15 04:09:41 +00:00
|
|
|
}
|
|
|
|
|
2001-10-02 00:38:34 +00:00
|
|
|
// Adjust position for margins at the aligned corner
|
|
|
|
nsMargin margin;
|
2003-05-15 03:42:21 +00:00
|
|
|
GetStyleMargin()->GetMargin(margin);
|
2007-07-04 15:49:38 +00:00
|
|
|
if (popupAlign == POPUPALIGNMENT_TOPLEFT) {
|
2001-10-02 00:38:34 +00:00
|
|
|
*ioXPos += margin.left;
|
|
|
|
*ioYPos += margin.top;
|
2007-07-04 15:49:38 +00:00
|
|
|
} else if (popupAlign == POPUPALIGNMENT_TOPRIGHT) {
|
2001-10-02 00:38:34 +00:00
|
|
|
*ioXPos += margin.right;
|
|
|
|
*ioYPos += margin.top;
|
2007-07-04 15:49:38 +00:00
|
|
|
} else if (popupAlign == POPUPALIGNMENT_BOTTOMLEFT) {
|
2001-10-02 00:38:34 +00:00
|
|
|
*ioXPos += margin.left;
|
|
|
|
*ioYPos += margin.bottom;
|
2007-07-04 15:49:38 +00:00
|
|
|
} else if (popupAlign == POPUPALIGNMENT_BOTTOMRIGHT) {
|
2001-10-02 00:38:34 +00:00
|
|
|
*ioXPos += margin.right;
|
|
|
|
*ioYPos += margin.bottom;
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
if (popupAnchor == POPUPALIGNMENT_TOPRIGHT && popupAlign == POPUPALIGNMENT_TOPLEFT) {
|
2000-03-02 04:08:04 +00:00
|
|
|
*ioXPos += inParentRect.width;
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
else if (popupAnchor == POPUPALIGNMENT_TOPLEFT && popupAlign == POPUPALIGNMENT_TOPLEFT) {
|
2001-08-08 01:38:05 +00:00
|
|
|
*outFlushWithTopBottom = PR_TRUE;
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
else if (popupAnchor == POPUPALIGNMENT_TOPRIGHT && popupAlign == POPUPALIGNMENT_BOTTOMRIGHT) {
|
2000-03-02 04:08:04 +00:00
|
|
|
*ioXPos -= (mRect.width - inParentRect.width);
|
|
|
|
*ioYPos -= mRect.height;
|
|
|
|
*outFlushWithTopBottom = PR_TRUE;
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
else if (popupAnchor == POPUPALIGNMENT_BOTTOMRIGHT && popupAlign == POPUPALIGNMENT_BOTTOMLEFT) {
|
2000-03-02 04:08:04 +00:00
|
|
|
*ioXPos += inParentRect.width;
|
|
|
|
*ioYPos -= (mRect.height - inParentRect.height);
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
else if (popupAnchor == POPUPALIGNMENT_BOTTOMRIGHT && popupAlign == POPUPALIGNMENT_TOPRIGHT) {
|
2000-03-02 04:08:04 +00:00
|
|
|
*ioXPos -= (mRect.width - inParentRect.width);
|
|
|
|
*ioYPos += inParentRect.height;
|
|
|
|
*outFlushWithTopBottom = PR_TRUE;
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
else if (popupAnchor == POPUPALIGNMENT_TOPLEFT && popupAlign == POPUPALIGNMENT_TOPRIGHT) {
|
2000-03-02 04:08:04 +00:00
|
|
|
*ioXPos -= mRect.width;
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
else if (popupAnchor == POPUPALIGNMENT_TOPLEFT && popupAlign == POPUPALIGNMENT_BOTTOMLEFT) {
|
2000-03-02 04:08:04 +00:00
|
|
|
*ioYPos -= mRect.height;
|
|
|
|
*outFlushWithTopBottom = PR_TRUE;
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
else if (popupAnchor == POPUPALIGNMENT_BOTTOMLEFT && popupAlign == POPUPALIGNMENT_BOTTOMRIGHT) {
|
2000-03-02 04:08:04 +00:00
|
|
|
*ioXPos -= mRect.width;
|
|
|
|
*ioYPos -= (mRect.height - inParentRect.height);
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
else if (popupAnchor == POPUPALIGNMENT_BOTTOMLEFT && popupAlign == POPUPALIGNMENT_TOPLEFT) {
|
2000-03-02 04:08:04 +00:00
|
|
|
*ioYPos += inParentRect.height;
|
|
|
|
*outFlushWithTopBottom = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NS_WARNING ( "Hmmm, looks like you've hit a anchor/align case we weren't setup for." );
|
|
|
|
|
|
|
|
} // AdjustPositionForAnchorAlign
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// IsMoreRoomOnOtherSideOfParent
|
|
|
|
//
|
|
|
|
// Determine if there is more room on the screen for the popup to live if it was positioned
|
|
|
|
// on the flip side of the parent from the side it is flush against (ie, if it's top edge was
|
|
|
|
// flush against the bottom, is there more room if its bottom edge were flush against the top)
|
|
|
|
//
|
|
|
|
PRBool
|
2001-09-10 07:34:54 +00:00
|
|
|
nsMenuPopupFrame::IsMoreRoomOnOtherSideOfParent ( PRBool inFlushAboveBelow, PRInt32 inScreenViewLocX, PRInt32 inScreenViewLocY,
|
2000-03-02 04:08:04 +00:00
|
|
|
const nsRect & inScreenParentFrameRect, PRInt32 inScreenTopTwips, PRInt32 inScreenLeftTwips,
|
|
|
|
PRInt32 inScreenBottomTwips, PRInt32 inScreenRightTwips )
|
|
|
|
{
|
|
|
|
PRBool switchSides = PR_FALSE;
|
|
|
|
if ( inFlushAboveBelow ) {
|
|
|
|
PRInt32 availAbove = inScreenParentFrameRect.y - inScreenTopTwips;
|
|
|
|
PRInt32 availBelow = inScreenBottomTwips - (inScreenParentFrameRect.y + inScreenParentFrameRect.height) ;
|
|
|
|
if ( inScreenViewLocY > inScreenParentFrameRect.y ) // view is now below parent
|
|
|
|
switchSides = availAbove > availBelow;
|
|
|
|
else
|
|
|
|
switchSides = availBelow > availAbove;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRInt32 availLeft = inScreenParentFrameRect.x - inScreenLeftTwips;
|
|
|
|
PRInt32 availRight = inScreenRightTwips - (inScreenParentFrameRect.x + inScreenParentFrameRect.width) ;
|
|
|
|
if ( inScreenViewLocX > inScreenParentFrameRect.x ) // view is now to the right of parent
|
|
|
|
switchSides = availLeft > availRight;
|
|
|
|
else
|
|
|
|
switchSides = availRight > availLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
return switchSides;
|
|
|
|
|
|
|
|
} // IsMoreRoomOnOtherSideOfParent
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// MovePopupToOtherSideOfParent
|
|
|
|
//
|
|
|
|
// Move the popup to the other side of the parent (ie, if it the popup's top edge is flush against the
|
|
|
|
// bottom of its parent, move the popup so that its bottom edge is now flush against the top of its
|
|
|
|
// parent...same idea for left/right).
|
|
|
|
//
|
|
|
|
// NOTE: In moving the popup, it may need to change size in order to stay on the screen. This will
|
|
|
|
// have the side effect of touching |mRect|.
|
|
|
|
//
|
|
|
|
void
|
2001-09-10 07:34:54 +00:00
|
|
|
nsMenuPopupFrame::MovePopupToOtherSideOfParent ( PRBool inFlushAboveBelow, PRInt32* ioXPos, PRInt32* ioYPos,
|
|
|
|
PRInt32* ioScreenViewLocX, PRInt32* ioScreenViewLocY,
|
|
|
|
const nsRect & inScreenParentFrameRect, PRInt32 inScreenTopTwips, PRInt32 inScreenLeftTwips,
|
|
|
|
PRInt32 inScreenBottomTwips, PRInt32 inScreenRightTwips )
|
2000-03-02 04:08:04 +00:00
|
|
|
{
|
|
|
|
if ( inFlushAboveBelow ) {
|
|
|
|
if ( *ioScreenViewLocY > inScreenParentFrameRect.y ) { // view is currently below parent
|
|
|
|
// move it above.
|
|
|
|
PRInt32 shiftDistY = inScreenParentFrameRect.height + mRect.height;
|
|
|
|
*ioYPos -= shiftDistY;
|
|
|
|
*ioScreenViewLocY -= shiftDistY;
|
|
|
|
// trim it to fit.
|
|
|
|
if ( *ioScreenViewLocY < inScreenTopTwips ) {
|
|
|
|
PRInt32 trimY = inScreenTopTwips - *ioScreenViewLocY;
|
|
|
|
*ioYPos += trimY;
|
|
|
|
*ioScreenViewLocY += trimY;
|
|
|
|
mRect.height -= trimY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // view is currently above parent
|
|
|
|
// move it below
|
|
|
|
PRInt32 shiftDistY = inScreenParentFrameRect.height + mRect.height;
|
|
|
|
*ioYPos += shiftDistY;
|
|
|
|
*ioScreenViewLocY += shiftDistY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ( *ioScreenViewLocX > inScreenParentFrameRect.x ) { // view is currently to the right of the parent
|
|
|
|
// move it to the left.
|
|
|
|
PRInt32 shiftDistX = inScreenParentFrameRect.width + mRect.width;
|
|
|
|
*ioXPos -= shiftDistX;
|
|
|
|
*ioScreenViewLocX -= shiftDistX;
|
|
|
|
// trim it to fit.
|
|
|
|
if ( *ioScreenViewLocX < inScreenLeftTwips ) {
|
|
|
|
PRInt32 trimX = inScreenLeftTwips - *ioScreenViewLocX;
|
|
|
|
*ioXPos += trimX;
|
|
|
|
*ioScreenViewLocX += trimX;
|
|
|
|
mRect.width -= trimX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // view is currently to the right of the parent
|
|
|
|
// move it to the right
|
|
|
|
PRInt32 shiftDistX = inScreenParentFrameRect.width + mRect.width;
|
|
|
|
*ioXPos += shiftDistX;
|
|
|
|
*ioScreenViewLocX += shiftDistX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // MovePopupToOtherSideOfParent
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
// XXXndeakin this function will be reworked in bug 384062 such that positioning
|
|
|
|
// of the popup is done only when the popup is first opened, so that the popup doesn't
|
|
|
|
// move around when it is changed in some way.
|
|
|
|
nsresult
|
|
|
|
nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame)
|
2006-09-03 20:25:58 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
if (!mShouldAutoPosition && !mInContentShell)
|
|
|
|
return NS_OK;
|
2001-01-24 08:38:09 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
PRBool sizedToPopup = PR_FALSE;
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
2007-08-27 16:23:52 +00:00
|
|
|
nsIFrame* rootFrame = presContext->PresShell()->FrameManager()->GetRootFrame();
|
2007-06-29 22:15:59 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
// if the frame is not specified, use the anchor node passed to ShowPopup. If
|
|
|
|
// 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) {
|
|
|
|
nsCOMPtr<nsIDocument> document = mAnchorContent->GetDocument();
|
2007-08-19 16:55:18 +00:00
|
|
|
if (document) {
|
|
|
|
nsIPresShell *shell = document->GetPrimaryShell();
|
|
|
|
if (!shell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
aAnchorFrame = shell->GetPrimaryFrameFor(mAnchorContent);
|
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
2007-08-19 16:55:18 +00:00
|
|
|
|
|
|
|
if (!aAnchorFrame) {
|
2007-08-27 16:23:52 +00:00
|
|
|
aAnchorFrame = rootFrame;
|
2007-08-19 16:55:18 +00:00
|
|
|
if (!aAnchorFrame)
|
|
|
|
return NS_OK;
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-18 15:24:57 +00:00
|
|
|
|
|
|
|
if (aAnchorFrame->GetContent()) {
|
2007-07-04 15:49:38 +00:00
|
|
|
// the popup should be the same size as the anchor menu, for example, a menulist.
|
|
|
|
sizedToPopup = nsMenuFrame::IsSizedToPopup(aAnchorFrame->GetContent(), PR_FALSE);
|
|
|
|
}
|
2007-06-29 22:15:59 +00:00
|
|
|
|
2001-06-04 23:03:24 +00:00
|
|
|
// |parentRect|
|
|
|
|
// The dimensions of the frame invoking the popup.
|
2007-07-04 15:49:38 +00:00
|
|
|
nsRect parentRect = aAnchorFrame->GetRect();
|
1999-07-20 09:35:35 +00:00
|
|
|
|
2002-08-06 01:03:27 +00:00
|
|
|
// If we stick to our parent's width, set it here before we move the
|
|
|
|
// window around, because moving is done with respect to the width...
|
|
|
|
if (sizedToPopup) {
|
|
|
|
mRect.width = parentRect.width;
|
|
|
|
}
|
|
|
|
|
2000-02-04 07:27:30 +00:00
|
|
|
// |xpos| and |ypos| hold the x and y positions of where the popup will be moved to,
|
2007-08-27 16:23:52 +00:00
|
|
|
// in app units, in the coordinate system of the _parent view_.
|
2007-06-29 22:15:59 +00:00
|
|
|
PRBool readjustAboveBelow = PR_FALSE;
|
2007-07-04 15:49:38 +00:00
|
|
|
PRInt32 xpos = 0, ypos = 0;
|
2007-08-27 16:23:52 +00:00
|
|
|
nsMargin margin;
|
|
|
|
|
|
|
|
// the positon in app units where the popup should appear.
|
2007-07-04 15:49:38 +00:00
|
|
|
PRInt32 screenViewLocX, screenViewLocY;
|
|
|
|
|
2007-08-27 16:23:52 +00:00
|
|
|
// the screen rectangle of the anchor, or if null, the root frame, in dev pixels.
|
|
|
|
nsRect anchorScreenRect;
|
|
|
|
nsRect rootScreenRect = rootFrame->GetScreenRect();
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
if (mScreenXPos == -1 && mScreenYPos == -1) {
|
|
|
|
// if we are anchored to our parent, there are certain things we don't want to do
|
|
|
|
// when repositioning the view to fit on the screen, such as end up positioned over
|
|
|
|
// the parent. 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.
|
|
|
|
if (mAnchorContent) {
|
2007-08-27 16:23:52 +00:00
|
|
|
anchorScreenRect = aAnchorFrame->GetScreenRect();
|
|
|
|
xpos = presContext->DevPixelsToAppUnits(anchorScreenRect.x - rootScreenRect.x);
|
|
|
|
ypos = presContext->DevPixelsToAppUnits(anchorScreenRect.y - rootScreenRect.y);
|
2007-07-04 15:49:38 +00: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.
|
|
|
|
AdjustPositionForAnchorAlign(&xpos, &ypos, parentRect, &readjustAboveBelow);
|
|
|
|
}
|
|
|
|
else {
|
2007-08-27 16:23:52 +00:00
|
|
|
// with no anchor, the popup is positioned relative to the root frame
|
|
|
|
anchorScreenRect = rootScreenRect;
|
2007-07-04 15:49:38 +00:00
|
|
|
GetStyleMargin()->GetMargin(margin);
|
2007-08-27 16:23:52 +00:00
|
|
|
xpos = margin.left;
|
|
|
|
ypos = margin.top;
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
2001-10-02 00:38:34 +00:00
|
|
|
|
2007-08-27 16:23:52 +00:00
|
|
|
// add on the offset
|
|
|
|
xpos += presContext->CSSPixelsToAppUnits(mXPos);
|
|
|
|
ypos += presContext->CSSPixelsToAppUnits(mYPos);
|
|
|
|
|
|
|
|
screenViewLocX = presContext->DevPixelsToAppUnits(rootScreenRect.x) + xpos;
|
|
|
|
screenViewLocY = presContext->DevPixelsToAppUnits(rootScreenRect.y) + ypos;
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// positioned on screen
|
2003-05-15 03:42:21 +00:00
|
|
|
GetStyleMargin()->GetMargin(margin);
|
2007-07-04 15:49:38 +00:00
|
|
|
screenViewLocX = nsPresContext::CSSPixelsToAppUnits(mScreenXPos) + margin.left;
|
|
|
|
screenViewLocY = nsPresContext::CSSPixelsToAppUnits(mScreenYPos) + margin.top;
|
2007-02-07 07:46:44 +00:00
|
|
|
|
2007-08-27 16:23:52 +00:00
|
|
|
// determine the x and y position by subtracting the desired screen
|
|
|
|
// position from the screen position of the root frame.
|
|
|
|
xpos = screenViewLocX - presContext->DevPixelsToAppUnits(rootScreenRect.x);
|
|
|
|
ypos = screenViewLocY - presContext->DevPixelsToAppUnits(rootScreenRect.y);
|
1999-09-10 08:47:12 +00:00
|
|
|
}
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2000-04-21 06:55:13 +00:00
|
|
|
// Compute info about the screen dimensions. Because of multiple monitor systems,
|
|
|
|
// the left or top sides of the screen may be in negative space (main monitor is on the
|
|
|
|
// right, etc). We need to be sure to do the right thing.
|
2007-03-30 21:11:41 +00:00
|
|
|
nsIDeviceContext* devContext = PresContext()->DeviceContext();
|
2007-02-07 07:46:44 +00:00
|
|
|
nsRect rect;
|
2000-03-23 21:10:09 +00:00
|
|
|
if ( mMenuCanOverlapOSBar ) {
|
2007-02-07 07:46:44 +00:00
|
|
|
devContext->GetRect(rect);
|
2000-03-23 21:10:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-02-07 07:46:44 +00:00
|
|
|
devContext->GetClientRect(rect);
|
2000-03-23 21:10:09 +00:00
|
|
|
}
|
2005-06-09 15:35:31 +00:00
|
|
|
|
|
|
|
// keep 3px margin to the right and bottom of the screen for WinXP dropshadow
|
2007-02-07 07:46:44 +00:00
|
|
|
rect.width -= nsPresContext::CSSPixelsToAppUnits(3);
|
|
|
|
rect.height -= nsPresContext::CSSPixelsToAppUnits(3);
|
|
|
|
|
2007-04-20 18:20:03 +00:00
|
|
|
// for content shells, clip to the client area rather than the screen area
|
|
|
|
if (mInContentShell) {
|
2007-07-04 15:49:38 +00:00
|
|
|
rootScreenRect.ScaleRoundIn(presContext->AppUnitsPerDevPixel());
|
2007-04-20 18:20:03 +00:00
|
|
|
rect.IntersectRect(rect, rootScreenRect);
|
|
|
|
}
|
|
|
|
|
2007-02-08 23:23:31 +00:00
|
|
|
PRInt32 screenLeftTwips = rect.x;
|
|
|
|
PRInt32 screenTopTwips = rect.y;
|
2007-02-07 07:46:44 +00:00
|
|
|
PRInt32 screenWidthTwips = rect.width;
|
|
|
|
PRInt32 screenHeightTwips = rect.height;
|
|
|
|
PRInt32 screenRightTwips = rect.XMost();
|
|
|
|
PRInt32 screenBottomTwips = rect.YMost();
|
2007-06-29 22:15:59 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
if (mPopupAnchor != POPUPALIGNMENT_NONE) {
|
2007-08-27 16:23:52 +00:00
|
|
|
NS_ASSERTION(mScreenXPos == -1 && mScreenYPos == -1,
|
|
|
|
"screen position used with anchor");
|
2000-03-02 04:08:04 +00:00
|
|
|
//
|
|
|
|
// Popup is anchored to the parent, guarantee that it does not cover the parent. We
|
|
|
|
// shouldn't do anything funky if it will already fit on the screen as is.
|
|
|
|
//
|
|
|
|
|
2002-05-20 09:04:25 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// +------------------------+
|
|
|
|
// | /\ |
|
|
|
|
// parentPos -> - +------------------------+
|
|
|
|
// | | |
|
|
|
|
// offset | | |
|
|
|
|
// | | |
|
|
|
|
// | | | (screenViewLocX,screenViewLocY)
|
|
|
|
// - |========================|+--------------
|
|
|
|
// | parentRect > ||
|
|
|
|
// |========================||
|
|
|
|
// | || Submenu
|
|
|
|
// +------------------------+| ( = mRect )
|
|
|
|
// | \/ ||
|
|
|
|
// +------------------------+
|
|
|
|
|
2002-07-05 23:12:51 +00:00
|
|
|
// Don't let it spill off the screen to the top
|
2002-05-17 21:23:36 +00:00
|
|
|
if (screenViewLocY < screenTopTwips) {
|
|
|
|
PRInt32 moveDist = screenTopTwips - screenViewLocY;
|
|
|
|
screenViewLocY = screenTopTwips;
|
|
|
|
ypos += moveDist;
|
|
|
|
}
|
2000-03-02 04:08:04 +00:00
|
|
|
|
|
|
|
// if it doesn't fit on the screen, do our magic.
|
|
|
|
if ( (screenViewLocX + mRect.width) > screenRightTwips ||
|
2002-07-05 23:12:51 +00:00
|
|
|
screenViewLocX < screenLeftTwips ||
|
2000-03-02 04:08:04 +00:00
|
|
|
(screenViewLocY + mRect.height) > screenBottomTwips ) {
|
2007-08-27 16:23:52 +00:00
|
|
|
nsRect screenParentFrameRect(anchorScreenRect);
|
|
|
|
screenParentFrameRect.ScaleRoundOut(PresContext()->AppUnitsPerDevPixel());
|
|
|
|
|
2000-03-02 04:08:04 +00:00
|
|
|
// figure out which side of the parent has the most free space so we can move/resize
|
|
|
|
// the popup there. This should still work if the parent frame is partially screen.
|
|
|
|
PRBool switchSides = IsMoreRoomOnOtherSideOfParent ( readjustAboveBelow, screenViewLocX, screenViewLocY,
|
|
|
|
screenParentFrameRect, screenTopTwips, screenLeftTwips,
|
|
|
|
screenBottomTwips, screenRightTwips );
|
|
|
|
|
|
|
|
// move the popup to the correct side, if necessary. Note that MovePopupToOtherSideOfParent()
|
|
|
|
// can change width/height of |mRect|.
|
|
|
|
if ( switchSides )
|
|
|
|
MovePopupToOtherSideOfParent ( readjustAboveBelow, &xpos, &ypos, &screenViewLocX, &screenViewLocY,
|
|
|
|
screenParentFrameRect, screenTopTwips, screenLeftTwips,
|
|
|
|
screenBottomTwips, screenRightTwips );
|
|
|
|
|
|
|
|
// We are allowed to move the popup along the axis to which we're not anchored to the parent
|
|
|
|
// in order to get it to not spill off the screen.
|
|
|
|
if ( readjustAboveBelow ) {
|
2000-03-16 05:13:15 +00:00
|
|
|
// move left to be on screen, but don't let it go off the screen at the left
|
2000-03-02 04:08:04 +00:00
|
|
|
if ( (screenViewLocX + mRect.width) > screenRightTwips ) {
|
|
|
|
PRInt32 moveDistX = (screenViewLocX + mRect.width) - screenRightTwips;
|
2000-03-16 05:13:15 +00:00
|
|
|
if ( screenViewLocX - moveDistX < screenLeftTwips )
|
|
|
|
moveDistX = screenViewLocX - screenLeftTwips;
|
2000-03-02 04:08:04 +00:00
|
|
|
screenViewLocX -= moveDistX;
|
|
|
|
xpos -= moveDistX;
|
2002-07-05 23:12:51 +00:00
|
|
|
} else if (screenViewLocX < screenLeftTwips) {
|
|
|
|
// move right to be on screen, but don't let it go off the screen at the right
|
|
|
|
PRInt32 moveDistX = screenLeftTwips - screenViewLocX;
|
|
|
|
if ( (screenViewLocX + mRect.width + moveDistX) > screenRightTwips )
|
|
|
|
moveDistX = screenRightTwips - screenViewLocX - mRect.width;
|
|
|
|
screenViewLocX += moveDistX;
|
|
|
|
xpos += moveDistX;
|
2000-03-02 04:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2000-03-16 05:13:15 +00:00
|
|
|
// move it up to be on screen, but don't let it go off the screen at the top
|
2003-10-30 02:09:52 +00:00
|
|
|
/*
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* |+---- screenViewLocY
|
|
|
|
* ||
|
|
|
|
* || Submenu ( = mRect )
|
|
|
|
* -+|
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* - - - - - - - - - - screenBottomTwips (bottom of the screen)
|
|
|
|
* | \
|
|
|
|
* | } moveDistY
|
|
|
|
* | /
|
|
|
|
* +---- screenViewLocY + mRect.height
|
|
|
|
*/
|
2002-05-20 09:04:25 +00:00
|
|
|
|
2000-03-02 04:08:04 +00:00
|
|
|
if ( (screenViewLocY + mRect.height) > screenBottomTwips ) {
|
2002-05-20 09:04:25 +00:00
|
|
|
// XXX Bug 84121 comment 48 says the next line has to use screenHeightTwips, why not screenBottomTwips?
|
2002-01-14 05:45:53 +00:00
|
|
|
PRInt32 moveDistY = (screenViewLocY + mRect.height) - screenHeightTwips;
|
2000-03-16 05:13:15 +00:00
|
|
|
if ( screenViewLocY - moveDistY < screenTopTwips )
|
|
|
|
moveDistY = screenViewLocY - screenTopTwips;
|
2000-03-02 04:08:04 +00:00
|
|
|
screenViewLocY -= moveDistY;
|
|
|
|
ypos -= moveDistY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resize it to fit on the screen. By this point, we've given the popup as much
|
|
|
|
// room as we can w/out covering the parent. If it still can't be as big
|
|
|
|
// as it wants to be, well, it just has to suck up and deal.
|
2002-05-20 09:04:25 +00:00
|
|
|
//
|
|
|
|
// ySpillage is calculated the same way as moveDistY above. see picture there.
|
|
|
|
|
2000-03-02 04:08:04 +00:00
|
|
|
PRInt32 xSpillage = (screenViewLocX + mRect.width) - screenRightTwips;
|
|
|
|
if ( xSpillage > 0 )
|
|
|
|
mRect.width -= xSpillage;
|
2002-05-20 09:04:25 +00:00
|
|
|
PRInt32 ySpillage = (screenViewLocY + mRect.height) - screenBottomTwips;
|
2000-03-02 04:08:04 +00:00
|
|
|
if ( ySpillage > 0 )
|
|
|
|
mRect.height -= ySpillage;
|
|
|
|
|
2002-01-14 05:45:53 +00:00
|
|
|
// shrink to fit onto the screen, vertically and horizontally
|
|
|
|
if(mRect.width > screenWidthTwips)
|
|
|
|
mRect.width = screenWidthTwips;
|
|
|
|
if(mRect.height > screenHeightTwips)
|
|
|
|
mRect.height = screenHeightTwips;
|
|
|
|
|
2000-03-02 04:08:04 +00:00
|
|
|
} // if it doesn't fit on screen
|
|
|
|
} // if anchored to parent
|
|
|
|
else {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Popup not anchored to anything, just make sure it's on the screen by any
|
|
|
|
// means necessary
|
|
|
|
//
|
|
|
|
|
2005-02-16 15:21:20 +00:00
|
|
|
// If you decide to mess with this code in some way other than just
|
|
|
|
// converting it to be just like the anchored codepath, please make sure to
|
|
|
|
// not regress bug 120226, bug 172530, bug 245163.
|
|
|
|
|
|
|
|
// XXXbz this is really silly. We should be able to anchor popups to a
|
|
|
|
// point or rect, not a frame, and we should be doing so with context
|
|
|
|
// menus. Furthermore, we should not be adding in pixels manually to
|
|
|
|
// adjust position (in XULPopupListenerImpl::LaunchPopup comes to mind,
|
|
|
|
// though ConvertPosition in the same file has some 21-px bogosity in the
|
|
|
|
// y-direction too).
|
|
|
|
|
2000-03-02 04:08:04 +00:00
|
|
|
// shrink to fit onto the screen, vertically and horizontally
|
2007-07-04 15:49:38 +00:00
|
|
|
if(mRect.width > screenWidthTwips)
|
|
|
|
mRect.width = screenWidthTwips;
|
2000-03-02 04:08:04 +00:00
|
|
|
if(mRect.height > screenHeightTwips)
|
2007-07-04 15:49:38 +00:00
|
|
|
mRect.height = screenHeightTwips;
|
2005-02-16 15:21:20 +00:00
|
|
|
|
|
|
|
// First, adjust the X position. For the X position, we slide the popup
|
|
|
|
// left or right as needed to get it on screen.
|
2000-03-02 04:08:04 +00:00
|
|
|
if ( screenViewLocX < screenLeftTwips ) {
|
|
|
|
PRInt32 moveDistX = screenLeftTwips - screenViewLocX;
|
|
|
|
xpos += moveDistX;
|
|
|
|
screenViewLocX += moveDistX;
|
|
|
|
}
|
2005-02-16 15:21:20 +00:00
|
|
|
if ( (screenViewLocX + mRect.width) > screenRightTwips )
|
|
|
|
xpos -= (screenViewLocX + mRect.width) - screenRightTwips;
|
|
|
|
|
|
|
|
// Now the Y position. If the popup is up too high, slide it down so it's
|
|
|
|
// on screen.
|
2000-03-02 04:08:04 +00:00
|
|
|
if ( screenViewLocY < screenTopTwips ) {
|
|
|
|
PRInt32 moveDistY = screenTopTwips - screenViewLocY;
|
|
|
|
ypos += moveDistY;
|
|
|
|
screenViewLocY += moveDistY;
|
|
|
|
}
|
|
|
|
|
2005-02-16 15:21:20 +00:00
|
|
|
// Now if the popup extends down too far, either resize it or flip it to be
|
|
|
|
// above the anchor point and resize it to fit above, depending on where we
|
|
|
|
// have more room.
|
|
|
|
if ( (screenViewLocY + mRect.height) > screenBottomTwips ) {
|
|
|
|
// XXXbz it'd be good to make use of IsMoreRoomOnOtherSideOfParent and
|
|
|
|
// such here, but that's really focused on having a nonempty parent
|
|
|
|
// rect...
|
|
|
|
if (screenBottomTwips - screenViewLocY >
|
|
|
|
screenViewLocY - screenTopTwips) {
|
|
|
|
// More space below our desired point. Resize to fit in this space.
|
|
|
|
// Note that this is making mRect smaller; othewise we would not have
|
|
|
|
// reached this code.
|
|
|
|
mRect.height = screenBottomTwips - screenViewLocY;
|
|
|
|
} else {
|
|
|
|
// More space above our desired point. Flip and resize to fit in this
|
|
|
|
// space.
|
|
|
|
if (mRect.height > screenViewLocY - screenTopTwips) {
|
|
|
|
// We wouldn't fit. Shorten before flipping.
|
|
|
|
mRect.height = screenViewLocY - screenTopTwips;
|
|
|
|
}
|
|
|
|
ypos -= (mRect.height + margin.top + margin.bottom);
|
|
|
|
}
|
|
|
|
}
|
2000-03-02 04:08:04 +00:00
|
|
|
}
|
2000-02-04 07:27:30 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
presContext->GetViewManager()->MoveViewTo(GetView(), xpos, ypos);
|
2001-12-19 12:11:12 +00:00
|
|
|
|
2002-03-06 01:52:06 +00:00
|
|
|
// Now that we've positioned the view, sync up the frame's origin.
|
2003-08-04 12:39:51 +00:00
|
|
|
nsPoint frameOrigin = GetPosition();
|
|
|
|
nsPoint offsetToView;
|
2005-01-01 17:26:29 +00:00
|
|
|
GetOriginToViewOffset(offsetToView, nsnull);
|
2002-03-06 01:52:06 +00:00
|
|
|
frameOrigin -= offsetToView;
|
2003-08-04 12:39:51 +00:00
|
|
|
nsBoxFrame::SetPosition(frameOrigin);
|
2002-03-06 01:52:06 +00:00
|
|
|
|
2002-05-17 21:23:36 +00:00
|
|
|
if (sizedToPopup) {
|
2007-07-04 15:49:38 +00:00
|
|
|
nsBoxLayoutState state(PresContext());
|
|
|
|
SetBounds(state, nsRect(mRect.x, mRect.y, parentRect.width, mRect.height));
|
2000-03-03 01:50:43 +00:00
|
|
|
}
|
2000-02-15 17:14:59 +00:00
|
|
|
|
1999-07-20 09:35:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
/* virtual */ nsMenuFrame*
|
|
|
|
nsMenuPopupFrame::GetCurrentMenuItem()
|
2007-06-29 22:15:59 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
return mCurrentMenu;
|
2007-06-29 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
PRBool nsMenuPopupFrame::ConsumeOutsideClicks()
|
2007-06-29 22:15:59 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00: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 22:15:59 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsCOMPtr<nsIContent> parentContent = mContent->GetParent();
|
|
|
|
if (parentContent) {
|
|
|
|
nsINodeInfo *ni = parentContent->NodeInfo();
|
|
|
|
if (ni->Equals(nsGkAtoms::menulist, kNameSpaceID_XUL))
|
|
|
|
return PR_TRUE; // Consume outside clicks for combo boxes on all platforms
|
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
// Don't consume outside clicks for menus in Windows
|
|
|
|
if (ni->Equals(nsGkAtoms::menu, kNameSpaceID_XUL) ||
|
|
|
|
(ni->Equals(nsGkAtoms::popupset, kNameSpaceID_XUL)))
|
|
|
|
return PR_FALSE;
|
|
|
|
#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))
|
|
|
|
return PR_FALSE;
|
2007-06-29 22:15:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2002-11-06 02:27:57 +00:00
|
|
|
|
2005-06-02 08:50:52 +00:00
|
|
|
static nsIScrollableView* GetScrollableViewForFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIScrollableFrame* sf;
|
|
|
|
nsresult rv = CallQueryInterface(aFrame, &sf);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsnull;
|
|
|
|
return sf->GetScrollableView();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXroc this is megalame. Fossicking around for a view of the right
|
|
|
|
// type is a recipe for disaster in the long term.
|
2000-11-13 21:25:07 +00:00
|
|
|
nsIScrollableView* nsMenuPopupFrame::GetScrollableView(nsIFrame* aStart)
|
|
|
|
{
|
|
|
|
if ( ! aStart )
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsIFrame* currFrame;
|
|
|
|
nsIScrollableView* scrollableView=nsnull;
|
|
|
|
|
|
|
|
// try start frame and siblings
|
|
|
|
currFrame=aStart;
|
|
|
|
do {
|
2005-06-02 08:50:52 +00:00
|
|
|
scrollableView = GetScrollableViewForFrame(currFrame);
|
2000-11-13 21:25:07 +00:00
|
|
|
if ( scrollableView )
|
|
|
|
return scrollableView;
|
2003-08-04 12:39:51 +00:00
|
|
|
currFrame = currFrame->GetNextSibling();
|
2000-11-13 21:25:07 +00:00
|
|
|
} while ( currFrame );
|
|
|
|
|
|
|
|
// try children
|
|
|
|
nsIFrame* childFrame;
|
|
|
|
currFrame=aStart;
|
|
|
|
do {
|
2004-01-09 14:20:53 +00:00
|
|
|
childFrame = currFrame->GetFirstChild(nsnull);
|
2000-11-13 21:25:07 +00:00
|
|
|
scrollableView=GetScrollableView(childFrame);
|
|
|
|
if ( scrollableView )
|
|
|
|
return scrollableView;
|
2003-08-04 12:39:51 +00:00
|
|
|
currFrame = currFrame->GetNextSibling();
|
2000-11-13 21:25:07 +00:00
|
|
|
} while ( currFrame );
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void nsMenuPopupFrame::EnsureMenuItemIsVisible(nsMenuFrame* aMenuItem)
|
2000-11-13 21:25:07 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
if (aMenuItem) {
|
|
|
|
nsIFrame* childFrame = GetFirstChild(nsnull);
|
2000-11-13 21:25:07 +00:00
|
|
|
nsIScrollableView *scrollableView;
|
2007-07-04 15:49:38 +00:00
|
|
|
scrollableView = GetScrollableView(childFrame);
|
|
|
|
if (scrollableView) {
|
2004-09-20 22:25:07 +00:00
|
|
|
nscoord scrollX, scrollY;
|
|
|
|
|
|
|
|
nsRect viewRect = scrollableView->View()->GetBounds();
|
2007-07-04 15:49:38 +00:00
|
|
|
nsRect itemRect = aMenuItem->GetRect();
|
2004-09-20 22:25:07 +00:00
|
|
|
scrollableView->GetScrollPosition(scrollX, scrollY);
|
|
|
|
|
|
|
|
// scroll down
|
|
|
|
if ( itemRect.y + itemRect.height > scrollY + viewRect.height )
|
|
|
|
scrollableView->ScrollTo(scrollX, itemRect.y + itemRect.height - viewRect.height, NS_SCROLL_PROPERTY_ALWAYS_BLIT);
|
|
|
|
|
|
|
|
// scroll up
|
|
|
|
else if ( itemRect.y < scrollY )
|
|
|
|
scrollableView->ScrollTo(scrollX, itemRect.y, NS_SCROLL_PROPERTY_ALWAYS_BLIT);
|
2000-11-13 21:25:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
NS_IMETHODIMP nsMenuPopupFrame::SetCurrentMenuItem(nsMenuFrame* aMenuItem)
|
1999-07-21 07:42:16 +00:00
|
|
|
{
|
2007-06-29 22:15:59 +00:00
|
|
|
if (mCurrentMenu == aMenuItem)
|
|
|
|
return NS_OK;
|
2007-07-04 15:49:38 +00:00
|
|
|
|
1999-07-21 08:51:41 +00:00
|
|
|
if (mCurrentMenu) {
|
1999-09-25 03:39:35 +00:00
|
|
|
mCurrentMenu->SelectMenu(PR_FALSE);
|
1999-07-21 08:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aMenuItem) {
|
2000-11-13 21:25:07 +00:00
|
|
|
EnsureMenuItemIsVisible(aMenuItem);
|
1999-09-21 01:03:00 +00:00
|
|
|
aMenuItem->SelectMenu(PR_TRUE);
|
1999-07-21 08:51:41 +00:00
|
|
|
}
|
1999-07-22 09:01:55 +00:00
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
mCurrentMenu = aMenuItem;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-21 08:51:41 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::CurrentMenuIsBeingDestroyed()
|
|
|
|
{
|
|
|
|
mCurrentMenu = nsnull;
|
|
|
|
}
|
1999-07-21 08:51:41 +00:00
|
|
|
|
2000-02-09 09:34:35 +00:00
|
|
|
NS_IMETHODIMP
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuPopupFrame::ChangeMenuItem(nsMenuFrame* aMenuItem,
|
|
|
|
PRBool aSelectFirstItem)
|
1999-07-23 07:49:43 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
if (mCurrentMenu == aMenuItem)
|
2002-10-04 00:56:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-04 15:49:38 +00: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))
|
2000-02-09 09:34:35 +00:00
|
|
|
return NS_OK;
|
1999-07-23 07:49:43 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
// Unset the current child.
|
|
|
|
if (mCurrentMenu) {
|
|
|
|
mCurrentMenu->SelectMenu(PR_FALSE);
|
|
|
|
nsMenuPopupFrame* popup = mCurrentMenu->GetPopup();
|
|
|
|
if (popup) {
|
|
|
|
if (mCurrentMenu->IsOpen()) {
|
|
|
|
if (pm)
|
|
|
|
pm->HidePopupAfterDelay(popup);
|
|
|
|
}
|
1999-07-23 08:36:39 +00:00
|
|
|
}
|
|
|
|
}
|
2000-02-09 09:34:35 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
// Set the new child.
|
|
|
|
if (aMenuItem) {
|
|
|
|
EnsureMenuItemIsVisible(aMenuItem);
|
|
|
|
aMenuItem->SelectMenu(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentMenu = aMenuItem;
|
|
|
|
|
2000-02-09 09:34:35 +00:00
|
|
|
return NS_OK;
|
1999-07-23 07:49:43 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuFrame*
|
1999-07-24 22:02:23 +00:00
|
|
|
nsMenuPopupFrame::Enter()
|
|
|
|
{
|
2003-03-05 01:43:25 +00:00
|
|
|
mIncrementalString.Truncate();
|
2002-04-24 07:15:35 +00:00
|
|
|
|
1999-07-24 22:02:23 +00:00
|
|
|
// Give it to the child.
|
1999-09-21 01:03:00 +00:00
|
|
|
if (mCurrentMenu)
|
2007-07-04 15:49:38 +00:00
|
|
|
return mCurrentMenu->Enter();
|
2000-02-09 09:34:35 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
return nsnull;
|
2002-10-04 00:56:43 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuFrame*
|
2002-04-24 07:15:35 +00:00
|
|
|
nsMenuPopupFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, PRBool& doAction)
|
1999-07-23 07:49:43 +00:00
|
|
|
{
|
2002-04-24 07:15:35 +00:00
|
|
|
PRUint32 charCode, keyCode;
|
|
|
|
aKeyEvent->GetCharCode(&charCode);
|
|
|
|
aKeyEvent->GetKeyCode(&keyCode);
|
|
|
|
|
|
|
|
doAction = PR_FALSE;
|
2000-04-04 06:43:02 +00:00
|
|
|
|
1999-07-23 07:49:43 +00:00
|
|
|
// Enumerate over our list of frames.
|
2000-04-04 06:43:02 +00:00
|
|
|
nsIFrame* immediateParent = nsnull;
|
2007-07-04 15:49:38 +00:00
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameConstructor()->GetInsertionPoint(this, nsnull, &immediateParent);
|
2000-04-04 06:43:02 +00:00
|
|
|
if (!immediateParent)
|
|
|
|
immediateParent = this;
|
|
|
|
|
2002-04-24 07:15:35 +00:00
|
|
|
PRUint32 matchCount = 0, matchShortcutCount = 0;
|
|
|
|
PRBool foundActive = PR_FALSE;
|
|
|
|
PRBool isShortcut;
|
2007-07-04 15:49:38 +00:00
|
|
|
nsMenuFrame* frameBefore = nsnull;
|
|
|
|
nsMenuFrame* frameAfter = nsnull;
|
|
|
|
nsMenuFrame* frameShortcut = nsnull;
|
2002-04-24 07:15:35 +00:00
|
|
|
|
2003-07-28 21:25:13 +00:00
|
|
|
nsIContent* parentContent = mContent->GetParent();
|
2003-11-19 01:20:56 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
PRBool isMenu = parentContent &&
|
|
|
|
!parentContent->NodeInfo()->Equals(nsGkAtoms::menulist, kNameSpaceID_XUL);
|
2002-04-24 07:15:35 +00:00
|
|
|
|
|
|
|
static DOMTimeStamp lastKeyTime = 0;
|
|
|
|
DOMTimeStamp keyTime;
|
|
|
|
aKeyEvent->GetTimeStamp(&keyTime);
|
|
|
|
|
|
|
|
if (charCode == 0) {
|
|
|
|
if (keyCode == NS_VK_BACK) {
|
|
|
|
if (!isMenu && !mIncrementalString.IsEmpty()) {
|
|
|
|
mIncrementalString.SetLength(mIncrementalString.Length() - 1);
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
|
|
|
if (soundInterface)
|
|
|
|
soundInterface->Beep();
|
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
else {
|
2007-07-08 07:08:04 +00:00
|
|
|
PRUnichar uniChar = ToLowerCase(static_cast<PRUnichar>(charCode));
|
2002-04-24 07:15:35 +00:00
|
|
|
if (isMenu || // Menu supports only first-letter navigation
|
|
|
|
keyTime - lastKeyTime > INC_TYP_INTERVAL) // Interval too long, treat as new typing
|
2003-03-05 01:43:25 +00:00
|
|
|
mIncrementalString = uniChar;
|
2002-04-24 07:15:35 +00:00
|
|
|
else {
|
2003-03-05 01:43:25 +00:00
|
|
|
mIncrementalString.Append(uniChar);
|
2002-04-24 07:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-05 01:43:25 +00:00
|
|
|
// See bug 188199 & 192346, if all letters in incremental string are same, just try to match the first one
|
|
|
|
nsAutoString incrementalString(mIncrementalString);
|
|
|
|
PRUint32 charIndex = 1, stringLength = incrementalString.Length();
|
|
|
|
while (charIndex < stringLength && incrementalString[charIndex] == incrementalString[charIndex - 1]) {
|
|
|
|
charIndex++;
|
|
|
|
}
|
|
|
|
if (charIndex == stringLength) {
|
|
|
|
incrementalString.Truncate(1);
|
|
|
|
stringLength = 1;
|
|
|
|
}
|
|
|
|
|
2002-04-24 07:15:35 +00:00
|
|
|
lastKeyTime = keyTime;
|
|
|
|
|
2000-04-04 06:43:02 +00:00
|
|
|
nsIFrame* currFrame;
|
2002-03-19 03:23:31 +00:00
|
|
|
// 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>
|
2004-01-09 14:20:53 +00:00
|
|
|
currFrame = immediateParent->GetFirstChild(nsnull);
|
2000-04-04 06:43:02 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
PRInt32 menuAccessKey = -1;
|
|
|
|
nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
|
|
|
|
|
2002-04-24 07:15:35 +00:00
|
|
|
// We start searching from first child. This process is divided into two parts
|
|
|
|
// -- before current and after current -- by the current item
|
1999-07-23 07:49:43 +00:00
|
|
|
while (currFrame) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIContent* current = currFrame->GetContent();
|
1999-07-23 07:49:43 +00:00
|
|
|
|
|
|
|
// See if it's a menu item.
|
2007-07-04 15:49:38 +00:00
|
|
|
if (nsXULPopupManager::IsValidMenuItem(PresContext(), current, PR_TRUE)) {
|
2006-04-24 05:40:11 +00:00
|
|
|
nsAutoString textKey;
|
2007-07-04 15:49:38 +00:00
|
|
|
if (menuAccessKey >= 0) {
|
|
|
|
// Get the shortcut attribute.
|
|
|
|
current->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, textKey);
|
|
|
|
}
|
2002-04-24 07:15:35 +00:00
|
|
|
if (textKey.IsEmpty()) { // No shortcut, try first letter
|
|
|
|
isShortcut = PR_FALSE;
|
2006-12-26 17:47:52 +00:00
|
|
|
current->GetAttr(kNameSpaceID_None, nsGkAtoms::label, textKey);
|
2002-04-24 07:15:35 +00:00
|
|
|
if (textKey.IsEmpty()) // No label, try another attribute (value)
|
2006-12-26 17:47:52 +00:00
|
|
|
current->GetAttr(kNameSpaceID_None, nsGkAtoms::value, textKey);
|
2002-04-24 07:15:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
isShortcut = PR_TRUE;
|
|
|
|
|
2003-07-14 07:37:39 +00:00
|
|
|
if (StringBeginsWith(textKey, incrementalString,
|
|
|
|
nsCaseInsensitiveStringComparator())) {
|
2002-04-24 07:15:35 +00:00
|
|
|
// mIncrementalString is a prefix of textKey
|
2007-07-04 15:49:38 +00:00
|
|
|
if (currFrame->GetType() == nsGkAtoms::menuFrame) {
|
2002-04-24 07:15:35 +00:00
|
|
|
// 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
|
2007-07-08 07:08:04 +00:00
|
|
|
frameShortcut = static_cast<nsMenuFrame *>(currFrame);
|
2002-04-24 07:15:35 +00:00
|
|
|
}
|
|
|
|
if (!foundActive) {
|
|
|
|
// It's a first candidate item located before/on the current item
|
|
|
|
if (!frameBefore)
|
2007-07-08 07:08:04 +00:00
|
|
|
frameBefore = static_cast<nsMenuFrame *>(currFrame);
|
2002-04-24 07:15:35 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// It's a first candidate item located after the current item
|
|
|
|
if (!frameAfter)
|
2007-07-08 07:08:04 +00:00
|
|
|
frameAfter = static_cast<nsMenuFrame *>(currFrame);
|
2002-04-24 07:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1999-09-21 01:03:00 +00:00
|
|
|
return nsnull;
|
2002-04-24 07:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the active status
|
2006-12-26 17:47:52 +00:00
|
|
|
if (current->AttrValueIs(kNameSpaceID_None, nsGkAtoms::menuactive,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
2002-04-24 07:15:35 +00:00
|
|
|
foundActive = PR_TRUE;
|
2003-03-05 01:43:25 +00:00
|
|
|
if (stringLength > 1) {
|
2002-04-24 07:15:35 +00:00
|
|
|
// If there is more than one char typed, the current item has highest priority,
|
|
|
|
// otherwise the item next to current has highest priority
|
2007-07-04 15:49:38 +00:00
|
|
|
if (currFrame == frameBefore)
|
2002-04-24 07:15:35 +00:00
|
|
|
return frameBefore;
|
1999-07-23 07:49:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-04 12:39:51 +00:00
|
|
|
currFrame = currFrame->GetNextSibling();
|
1999-07-23 07:49:43 +00:00
|
|
|
}
|
2002-02-15 03:53:26 +00:00
|
|
|
|
2002-04-24 07:15:35 +00: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);
|
|
|
|
|
2002-02-15 03:53:26 +00:00
|
|
|
// didn't find a matching menu item
|
|
|
|
#ifdef XP_WIN
|
2002-04-24 07:15:35 +00:00
|
|
|
// 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();
|
|
|
|
}
|
2002-02-15 03:53:26 +00:00
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
|
1999-07-23 07:49:43 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1999-09-25 03:39:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuPopupFrame::GetWidget(nsIWidget **aWidget)
|
|
|
|
{
|
2007-08-27 16:23:52 +00:00
|
|
|
nsIView * view = GetRootViewForPopup(this);
|
1999-09-25 03:39:35 +00:00
|
|
|
if (!view)
|
|
|
|
return NS_OK;
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
*aWidget = view->GetWidget();
|
|
|
|
NS_IF_ADDREF(*aWidget);
|
1999-09-25 03:39:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void
|
2005-12-31 23:34:46 +00:00
|
|
|
nsMenuPopupFrame::AttachedDismissalListener()
|
|
|
|
{
|
|
|
|
mConsumeRollupEvent = nsIPopupBoxObject::ROLLUP_DEFAULT;
|
2000-02-09 09:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// helpers /////////////////////////////////////////////////////////////
|
|
|
|
|
2001-09-10 07:34:54 +00:00
|
|
|
NS_IMETHODIMP
|
2005-09-07 16:49:21 +00:00
|
|
|
nsMenuPopupFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
2001-09-10 07:34:54 +00:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-11 21:16:12 +00:00
|
|
|
PRInt32 aModType)
|
2001-09-10 07:34:54 +00:00
|
|
|
|
|
|
|
{
|
2005-09-07 16:49:21 +00:00
|
|
|
nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::left || aAttribute == nsGkAtoms::top)
|
2001-09-10 07:34:54 +00:00
|
|
|
MoveToAttributePosition();
|
2007-07-04 15:49:38 +00:00
|
|
|
|
|
|
|
// accessibility needs this to ensure the frames get constructed when the
|
|
|
|
// menugenerated attribute is set, see bug 279703 comment 42 for discussion
|
|
|
|
if (aAttribute == nsGkAtoms::menugenerated &&
|
|
|
|
mFrames.IsEmpty() && !mGeneratedChildren) {
|
|
|
|
PresContext()->PresShell()->FrameConstructor()->
|
|
|
|
AddLazyChildren(mContent, LazyGeneratePopupDone, nsnull);
|
|
|
|
}
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2002-11-19 05:06:36 +00:00
|
|
|
return rv;
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
void
|
2001-09-10 07:34:54 +00: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;
|
2006-12-26 17:47:52 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::left, left);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::top, top);
|
2007-07-04 15:49:38 +00:00
|
|
|
PRInt32 err1, err2;
|
|
|
|
mScreenXPos = left.ToInteger(&err1);
|
|
|
|
mScreenYPos = top.ToInteger(&err2);
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
if (NS_SUCCEEDED(err1) && NS_SUCCEEDED(err2))
|
|
|
|
MoveToInternal(mScreenXPos, mScreenYPos);
|
1999-09-10 08:47:12 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 00:16:29 +00:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::Destroy()
|
1999-09-10 08:47:12 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
|
|
|
pm->PopupDestroyed(this);
|
2006-03-14 22:48:09 +00:00
|
|
|
|
2006-04-10 00:16:29 +00:00
|
|
|
nsBoxFrame::Destroy();
|
1999-09-21 01:03:00 +00:00
|
|
|
}
|
|
|
|
|
2001-09-10 07:34:54 +00:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::MoveTo(PRInt32 aLeft, PRInt32 aTop)
|
|
|
|
{
|
|
|
|
// Set the 'left' and 'top' attributes
|
|
|
|
nsAutoString left, top;
|
|
|
|
left.AppendInt(aLeft);
|
|
|
|
top.AppendInt(aTop);
|
|
|
|
|
2006-09-03 20:25:58 +00:00
|
|
|
nsWeakFrame weakFrame(this);
|
2006-12-26 17:47:52 +00:00
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::left, left, PR_FALSE);
|
2006-09-03 20:25:58 +00:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::top, top, PR_FALSE);
|
2006-09-03 20:25:58 +00:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2006-09-03 20:25:58 +00:00
|
|
|
MoveToInternal(aLeft, aTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::MoveToInternal(PRInt32 aLeft, PRInt32 aTop)
|
|
|
|
{
|
2007-04-20 18:20:03 +00:00
|
|
|
// just don't support moving popups for content shells
|
|
|
|
if (mInContentShell)
|
|
|
|
return;
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = GetView();
|
2004-11-23 17:26:19 +00:00
|
|
|
NS_ASSERTION(view->GetParent(), "Must have parent!");
|
2007-07-04 15:49:38 +00:00
|
|
|
|
2001-09-10 07:34:54 +00:00
|
|
|
// Retrieve screen position of parent view
|
2004-11-23 17:26:19 +00:00
|
|
|
nsIntPoint screenPos = view->GetParent()->GetScreenPosition();
|
2001-09-10 07:34:54 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsPresContext* context = PresContext();
|
|
|
|
aLeft = context->AppUnitsToDevPixels(nsPresContext::CSSPixelsToAppUnits(aLeft));
|
|
|
|
aTop = context->AppUnitsToDevPixels(nsPresContext::CSSPixelsToAppUnits(aTop));
|
|
|
|
|
2001-09-10 07:34:54 +00:00
|
|
|
// Move the widget
|
2004-11-23 17:26:19 +00:00
|
|
|
// XXXbz don't we want screenPos to be the parent _widget_'s position, then?
|
2003-08-04 12:39:51 +00:00
|
|
|
view->GetWidget()->Move(aLeft - screenPos.x, aTop - screenPos.y);
|
2001-09-10 07:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::GetAutoPosition(PRBool* aShouldAutoPosition)
|
|
|
|
{
|
|
|
|
*aShouldAutoPosition = mShouldAutoPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuPopupFrame::SetAutoPosition(PRBool aShouldAutoPosition)
|
|
|
|
{
|
|
|
|
mShouldAutoPosition = aShouldAutoPosition;
|
|
|
|
}
|
|
|
|
|
2005-12-31 23:34:46 +00:00
|
|
|
void
|
|
|
|
nsMenuPopupFrame::SetConsumeRollupEvent(PRUint32 aConsumeMode)
|
|
|
|
{
|
|
|
|
mConsumeRollupEvent = aConsumeMode;
|
|
|
|
}
|