2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** 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:36:37 +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:36:37 +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:36:37 +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-02-02 22:24:56 +00:00
|
|
|
* Michael Lowe <michael.lowe@bigfoot.com>
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2000-03-01 03:12:51 +00:00
|
|
|
* Dean Tessman <dean_tessman@hotmail.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:36:37 +00:00
|
|
|
|
1999-07-20 08:19:47 +00:00
|
|
|
#include "nsXULAtoms.h"
|
1999-07-26 01:35:39 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
1999-10-14 23:59:18 +00:00
|
|
|
#include "nsHTMLParts.h"
|
1999-07-18 06:36:37 +00:00
|
|
|
#include "nsMenuFrame.h"
|
1999-07-21 02:56:23 +00:00
|
|
|
#include "nsBoxFrame.h"
|
1999-07-18 06:36:37 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsIAtom.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1999-10-14 23:59:18 +00:00
|
|
|
#include "nsIPresShell.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
1999-07-18 06:36:37 +00:00
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
1999-07-18 06:41:41 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-07-20 09:35:35 +00:00
|
|
|
#include "nsMenuPopupFrame.h"
|
1999-07-21 07:42:16 +00:00
|
|
|
#include "nsMenuBarFrame.h"
|
1999-07-26 02:26:26 +00:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIWidget.h"
|
1999-07-31 01:43:33 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMNSDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIDOMText.h"
|
2000-01-21 21:56:09 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsBoxLayoutState.h"
|
2000-05-15 04:12:31 +00:00
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsIViewManager.h"
|
2000-05-09 21:42:40 +00:00
|
|
|
#include "nsIBindingManager.h"
|
2000-08-06 08:11:05 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIXBLService.h"
|
2000-08-03 00:22:36 +00:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2000-08-17 00:09:16 +00:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2000-12-09 07:28:19 +00:00
|
|
|
#include "nsIScrollableView.h"
|
2001-01-09 01:28:36 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2001-01-09 01:28:36 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
2002-08-03 01:20:08 +00:00
|
|
|
#include "nsIEventStateManager.h"
|
2002-09-07 05:38:16 +00:00
|
|
|
#include "nsITimerInternal.h"
|
2004-04-29 23:34:19 +00:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
2000-07-28 22:09:45 +00:00
|
|
|
#define NS_MENU_POPUP_LIST_INDEX 0
|
1999-07-18 06:48:03 +00:00
|
|
|
|
2003-04-02 22:45:08 +00:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2001-03-29 03:33:09 +00:00
|
|
|
#define NSCONTEXTMENUISMOUSEUP 1
|
|
|
|
#endif
|
|
|
|
|
1999-08-07 06:01:31 +00:00
|
|
|
static PRInt32 gEatMouseMove = PR_FALSE;
|
1999-07-26 06:29:48 +00:00
|
|
|
|
2001-09-10 07:34:54 +00:00
|
|
|
nsMenuDismissalListener* nsMenuFrame::sDismissalListener = nsnull;
|
1999-09-21 01:03:00 +00:00
|
|
|
|
2000-01-21 21:56:09 +00:00
|
|
|
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
|
|
|
|
2001-07-03 00:26:41 +00:00
|
|
|
nsrefcnt nsMenuFrame::gRefCnt = 0;
|
|
|
|
nsString *nsMenuFrame::gShiftText = nsnull;
|
|
|
|
nsString *nsMenuFrame::gControlText = nsnull;
|
|
|
|
nsString *nsMenuFrame::gMetaText = nsnull;
|
|
|
|
nsString *nsMenuFrame::gAltText = nsnull;
|
|
|
|
nsString *nsMenuFrame::gModifierSeparator = nsnull;
|
|
|
|
|
1999-07-18 06:36:37 +00:00
|
|
|
//
|
|
|
|
// NS_NewMenuFrame
|
|
|
|
//
|
|
|
|
// Wrapper for creating a new menu popup container
|
|
|
|
//
|
|
|
|
nsresult
|
1999-12-04 23:49:50 +00:00
|
|
|
NS_NewMenuFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRUint32 aFlags)
|
1999-07-18 06:36:37 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2000-03-02 03:01:30 +00:00
|
|
|
nsMenuFrame* it = new (aPresShell) nsMenuFrame (aPresShell);
|
1999-07-18 06:36:37 +00:00
|
|
|
if ( !it )
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
*aNewFrame = it;
|
1999-07-23 05:10:57 +00:00
|
|
|
if (aFlags)
|
|
|
|
it->SetIsMenu(PR_TRUE);
|
1999-07-18 06:36:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsMenuFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-01 00:39:12 +00:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
1999-07-21 07:42:16 +00:00
|
|
|
nsMenuFrame::Release(void)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-22 01:57:29 +00:00
|
|
|
//
|
|
|
|
// QueryInterface
|
|
|
|
//
|
1999-12-21 19:28:15 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMenuFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMenuFrame)
|
2000-12-09 07:28:19 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollableViewProvider)
|
2000-01-26 22:35:53 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsBoxFrame)
|
1999-07-18 06:36:37 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuFrame cntr
|
|
|
|
//
|
2000-03-02 03:01:30 +00:00
|
|
|
nsMenuFrame::nsMenuFrame(nsIPresShell* aShell):nsBoxFrame(aShell),
|
|
|
|
mIsMenu(PR_FALSE),
|
1999-09-03 03:47:06 +00:00
|
|
|
mMenuOpen(PR_FALSE),
|
2000-05-18 00:21:32 +00:00
|
|
|
mCreateHandlerSucceeded(PR_FALSE),
|
1999-10-15 21:13:24 +00:00
|
|
|
mChecked(PR_FALSE),
|
1999-10-17 21:37:37 +00:00
|
|
|
mType(eMenuType_Normal),
|
1999-09-03 03:47:06 +00:00
|
|
|
mMenuParent(nsnull),
|
2000-05-15 04:12:31 +00:00
|
|
|
mPresContext(nsnull),
|
2005-02-18 16:11:53 +00:00
|
|
|
mLastPref(-1,-1)
|
1999-07-18 06:36:37 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
} // cntr
|
|
|
|
|
2000-05-26 22:45:26 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::SetParent(const nsIFrame* aParent)
|
|
|
|
{
|
2000-08-17 00:09:16 +00:00
|
|
|
nsBoxFrame::SetParent(aParent);
|
2003-08-04 12:39:51 +00:00
|
|
|
const nsIFrame* currFrame = aParent;
|
2000-05-26 22:45:26 +00:00
|
|
|
while (!mMenuParent && currFrame) {
|
|
|
|
// Set our menu parent.
|
2003-08-04 12:39:51 +00:00
|
|
|
CallQueryInterface(NS_CONST_CAST(nsIFrame*, currFrame), &mMenuParent);
|
2000-05-26 22:45:26 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
currFrame = currFrame->GetParent();
|
2000-05-26 22:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMenuFrame::Init(nsPresContext* aPresContext,
|
1999-07-21 07:42:16 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* aContext,
|
1999-07-21 07:42:16 +00:00
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
mPresContext = aPresContext; // Don't addref it. Our lifetime is shorter.
|
1999-07-31 01:43:33 +00:00
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
|
2000-05-24 08:26:04 +00:00
|
|
|
nsIFrame* currFrame = aParent;
|
|
|
|
while (!mMenuParent && currFrame) {
|
|
|
|
// Set our menu parent.
|
2002-08-06 12:48:28 +00:00
|
|
|
CallQueryInterface(currFrame, &mMenuParent);
|
2000-05-24 08:26:04 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
currFrame = currFrame->GetParent();
|
2000-05-24 08:26:04 +00:00
|
|
|
}
|
2000-01-25 06:35:27 +00:00
|
|
|
|
|
|
|
// Do the type="checkbox" magic
|
2000-01-25 07:26:02 +00:00
|
|
|
UpdateMenuType(aPresContext);
|
2000-01-25 06:35:27 +00:00
|
|
|
|
2001-07-03 00:26:41 +00:00
|
|
|
//load the display strings for the keyboard accelerators, but only once
|
|
|
|
if (gRefCnt++ == 0) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
if (NS_SUCCEEDED(rv) && bundleService) {
|
|
|
|
rv = bundleService->CreateBundle( "chrome://global-platform/locale/platformKeys.properties",
|
|
|
|
getter_AddRefs(bundle));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && bundle, "chrome://global/locale/platformKeys.properties could not be loaded");
|
|
|
|
nsXPIDLString shiftModifier;
|
|
|
|
nsXPIDLString metaModifier;
|
|
|
|
nsXPIDLString altModifier;
|
|
|
|
nsXPIDLString controlModifier;
|
|
|
|
nsXPIDLString modifierSeparator;
|
|
|
|
if (NS_SUCCEEDED(rv) && bundle) {
|
|
|
|
//macs use symbols for each modifier key, so fetch each from the bundle, which also covers i18n
|
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("VK_SHIFT").get(), getter_Copies(shiftModifier));
|
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("VK_META").get(), getter_Copies(metaModifier));
|
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("VK_ALT").get(), getter_Copies(altModifier));
|
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("VK_CONTROL").get(), getter_Copies(controlModifier));
|
|
|
|
rv = bundle->GetStringFromName(NS_LITERAL_STRING("MODIFIER_SEPARATOR").get(), getter_Copies(modifierSeparator));
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
//if any of these don't exist, we get an empty string
|
|
|
|
gShiftText = new nsString(shiftModifier);
|
|
|
|
gMetaText = new nsString(metaModifier);
|
|
|
|
gAltText = new nsString(altModifier);
|
|
|
|
gControlText = new nsString(controlModifier);
|
|
|
|
gModifierSeparator = new nsString(modifierSeparator);
|
|
|
|
}
|
|
|
|
|
2001-10-11 03:03:42 +00:00
|
|
|
BuildAcceleratorText();
|
2000-01-25 06:35:27 +00:00
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-07-03 00:26:41 +00:00
|
|
|
nsMenuFrame::~nsMenuFrame()
|
|
|
|
{
|
|
|
|
// Clean up shared statics
|
|
|
|
if (--gRefCnt == 0) {
|
|
|
|
delete gShiftText;
|
|
|
|
gShiftText = nsnull;
|
|
|
|
delete gControlText;
|
|
|
|
gControlText = nsnull;
|
|
|
|
delete gMetaText;
|
|
|
|
gMetaText = nsnull;
|
|
|
|
delete gAltText;
|
|
|
|
gAltText = nsnull;
|
|
|
|
delete gModifierSeparator;
|
|
|
|
gModifierSeparator = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
// The following methods are all overridden to ensure that the menupopup frame
|
1999-07-18 06:44:03 +00:00
|
|
|
// is placed in the appropriate list.
|
2004-01-09 14:20:53 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsMenuFrame::GetFirstChild(nsIAtom* aListName) const
|
1999-07-18 06:41:41 +00:00
|
|
|
{
|
|
|
|
if (nsLayoutAtoms::popupList == aListName) {
|
2004-01-09 14:20:53 +00:00
|
|
|
return mPopupFrames.FirstChild();
|
1999-07-18 06:41:41 +00:00
|
|
|
}
|
2004-01-09 14:20:53 +00:00
|
|
|
return nsBoxFrame::GetFirstChild(aListName);
|
1999-07-18 06:41:41 +00:00
|
|
|
}
|
|
|
|
|
1999-07-18 06:44:03 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMenuFrame::SetInitialChildList(nsPresContext* aPresContext,
|
1999-07-18 06:44:03 +00:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (nsLayoutAtoms::popupList == aListName) {
|
|
|
|
mPopupFrames.SetFrames(aChildList);
|
|
|
|
} else {
|
1999-07-20 08:19:47 +00:00
|
|
|
|
|
|
|
nsFrameList frames(aChildList);
|
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
// We may have a menupopup in here. Get it out, and move it into
|
1999-07-20 08:19:47 +00:00
|
|
|
// the popup frame list.
|
|
|
|
nsIFrame* frame = frames.FirstChild();
|
|
|
|
while (frame) {
|
2002-08-06 12:48:28 +00:00
|
|
|
nsIMenuParent *menuPar;
|
|
|
|
CallQueryInterface(frame, &menuPar);
|
2000-08-06 08:11:05 +00:00
|
|
|
if (menuPar) {
|
1999-07-20 08:19:47 +00:00
|
|
|
// Remove this frame from the list and place it in the other list.
|
|
|
|
frames.RemoveFrame(frame);
|
|
|
|
mPopupFrames.AppendFrame(this, frame);
|
1999-07-31 11:29:03 +00:00
|
|
|
nsIFrame* first = frames.FirstChild();
|
|
|
|
rv = nsBoxFrame::SetInitialChildList(aPresContext, aListName, first);
|
1999-07-20 08:19:47 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2003-08-04 12:39:51 +00:00
|
|
|
frame = frame->GetNextSibling();
|
1999-07-20 08:19:47 +00:00
|
|
|
}
|
1999-07-31 11:29:03 +00:00
|
|
|
|
|
|
|
// Didn't find it.
|
1999-07-21 02:56:23 +00:00
|
|
|
rv = nsBoxFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
1999-07-18 06:44:03 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-18 06:48:03 +00:00
|
|
|
|
2004-01-09 14:20:53 +00:00
|
|
|
nsIAtom*
|
|
|
|
nsMenuFrame::GetAdditionalChildListName(PRInt32 aIndex) const
|
1999-07-18 06:48:03 +00:00
|
|
|
{
|
2000-08-03 00:22:36 +00:00
|
|
|
// don't expose the child frame list, it slows things down
|
|
|
|
#if 0
|
2000-07-28 22:09:45 +00:00
|
|
|
if (NS_MENU_POPUP_LIST_INDEX == aIndex) {
|
2004-01-09 14:20:53 +00:00
|
|
|
return nsLayoutAtoms::popupList;
|
2000-07-28 22:09:45 +00:00
|
|
|
}
|
2000-08-03 00:22:36 +00:00
|
|
|
#endif
|
2000-07-28 22:09:45 +00:00
|
|
|
|
2004-01-09 14:20:53 +00:00
|
|
|
return nsnull;
|
1999-07-18 06:48:03 +00:00
|
|
|
}
|
1999-07-18 06:52:06 +00:00
|
|
|
|
2001-12-17 22:51:39 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMenuFrame::DestroyPopupFrames(nsPresContext* aPresContext)
|
1999-07-18 06:52:06 +00:00
|
|
|
{
|
2000-08-03 00:22:36 +00:00
|
|
|
// Remove our frame mappings
|
2005-02-18 16:11:53 +00:00
|
|
|
nsCSSFrameConstructor* frameConstructor =
|
|
|
|
aPresContext->PresShell()->FrameConstructor();
|
|
|
|
nsIFrame* curFrame = mPopupFrames.FirstChild();
|
|
|
|
while (curFrame) {
|
|
|
|
frameConstructor->RemoveMappingsForFrameSubtree(curFrame, nsnull);
|
|
|
|
curFrame = curFrame->GetNextSibling();
|
2000-08-03 00:22:36 +00:00
|
|
|
}
|
|
|
|
|
1999-07-18 06:52:06 +00:00
|
|
|
// Cleanup frames in popup child list
|
1999-07-22 04:00:57 +00:00
|
|
|
mPopupFrames.DestroyFrames(aPresContext);
|
2001-12-17 22:51:39 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-03 00:22:36 +00:00
|
|
|
|
2001-12-17 22:51:39 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMenuFrame::Destroy(nsPresContext* aPresContext)
|
2001-12-17 22:51:39 +00:00
|
|
|
{
|
2005-01-07 23:59:12 +00:00
|
|
|
// are we our menu parent's current menu item?
|
|
|
|
if (mMenuParent) {
|
|
|
|
nsIMenuFrame *curItem = nsnull;
|
|
|
|
mMenuParent->GetCurrentMenuItem(&curItem);
|
|
|
|
if (curItem == this) {
|
|
|
|
// yes; tell it that we're going away
|
|
|
|
mMenuParent->SetCurrentMenuItem(nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-26 09:56:38 +00:00
|
|
|
UngenerateMenu();
|
2001-12-17 22:51:39 +00:00
|
|
|
DestroyPopupFrames(aPresContext);
|
1999-07-22 02:24:52 +00:00
|
|
|
return nsBoxFrame::Destroy(aPresContext);
|
1999-07-18 06:52:06 +00:00
|
|
|
}
|
1999-07-19 09:36:24 +00:00
|
|
|
|
|
|
|
// Called to prevent events from going to anything inside the menu.
|
|
|
|
NS_IMETHODIMP
|
2005-01-01 17:26:29 +00:00
|
|
|
nsMenuFrame::GetFrameForPoint(const nsPoint& aPoint,
|
2000-03-31 07:02:06 +00:00
|
|
|
nsFramePaintLayer aWhichLayer,
|
1999-07-19 09:36:24 +00:00
|
|
|
nsIFrame** aFrame)
|
|
|
|
{
|
2005-01-01 17:26:29 +00:00
|
|
|
nsresult result = nsBoxFrame::GetFrameForPoint(aPoint, aWhichLayer, aFrame);
|
2003-11-15 00:47:43 +00:00
|
|
|
if (NS_FAILED(result) || *aFrame == this) {
|
2000-03-22 02:43:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIContent* content = (*aFrame)->GetContent();
|
2000-03-22 02:43:08 +00:00
|
|
|
if (content) {
|
|
|
|
// This allows selective overriding for subcontent.
|
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
content->GetAttr(kNameSpaceID_None, nsXULAtoms::allowevents, value);
|
2004-04-30 13:23:43 +00:00
|
|
|
if (value.EqualsLiteral("true"))
|
2000-03-22 02:43:08 +00:00
|
|
|
return result;
|
1999-10-15 07:54:43 +00:00
|
|
|
}
|
2003-05-15 03:42:21 +00:00
|
|
|
if (GetStyleVisibility()->IsVisible()) {
|
2000-03-22 02:43:08 +00:00
|
|
|
*aFrame = this; // Capture all events so that we can perform selection
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-07-20 08:19:47 +00:00
|
|
|
}
|
1999-07-20 09:35:35 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMenuFrame::HandleEvent(nsPresContext* aPresContext,
|
1999-07-20 09:35:35 +00:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1999-07-20 09:35:35 +00:00
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
2004-08-19 18:36:42 +00:00
|
|
|
if (*aEventStatus == nsEventStatus_eIgnore)
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
1999-07-26 01:35:39 +00:00
|
|
|
|
2000-03-13 10:37:57 +00:00
|
|
|
if (aEvent->message == NS_KEY_PRESS && !IsDisabled()) {
|
2000-02-25 08:37:49 +00:00
|
|
|
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
|
|
|
PRUint32 keyCode = keyEvent->keyCode;
|
2005-03-23 10:43:45 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// On mac, open menulist on either up/down arrow or space (w/o Cmd pressed)
|
|
|
|
if (!IsOpen() && ((keyEvent->charCode == NS_VK_SPACE && !keyEvent->isMeta) ||
|
|
|
|
(keyCode == NS_VK_UP || keyCode == NS_VK_DOWN)))
|
|
|
|
OpenMenu(PR_TRUE);
|
|
|
|
#else
|
|
|
|
// On other platforms, toggle menulist on unmodified F4 or Alt arrow
|
2004-07-03 21:00:07 +00:00
|
|
|
if ((keyCode == NS_VK_F4 && !keyEvent->isAlt) ||
|
|
|
|
((keyCode == NS_VK_UP || keyCode == NS_VK_DOWN) && keyEvent->isAlt))
|
2005-03-23 10:43:45 +00:00
|
|
|
OpenMenu(!IsOpen());
|
|
|
|
#endif
|
2000-02-25 08:37:49 +00:00
|
|
|
}
|
2000-04-13 20:14:23 +00:00
|
|
|
else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN && !IsDisabled() && IsMenu() ) {
|
1999-09-01 00:39:12 +00:00
|
|
|
PRBool isMenuBar = PR_FALSE;
|
1999-07-25 00:16:11 +00:00
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->IsMenuBar(isMenuBar);
|
1999-09-01 00:39:12 +00:00
|
|
|
|
|
|
|
// The menu item was selected. Bring up the menu.
|
|
|
|
// We have children.
|
2000-04-13 20:14:23 +00:00
|
|
|
if ( isMenuBar || !mMenuParent ) {
|
1999-07-31 11:29:03 +00:00
|
|
|
ToggleMenuState();
|
1999-09-01 00:39:12 +00:00
|
|
|
|
2000-04-13 20:14:23 +00:00
|
|
|
if (!IsOpen() && mMenuParent) {
|
1999-07-31 11:29:03 +00:00
|
|
|
// We closed up. The menu bar should always be
|
|
|
|
// deactivated when this happens.
|
|
|
|
mMenuParent->SetActive(PR_FALSE);
|
1999-07-23 08:36:39 +00:00
|
|
|
}
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
2000-04-13 20:14:23 +00:00
|
|
|
else
|
2000-08-16 00:35:04 +00:00
|
|
|
if ( !IsOpen() ) {
|
|
|
|
// one of our siblings is probably open and even possibly waiting
|
|
|
|
// for its close timer to fire. Tell our parent to close it down. Not
|
|
|
|
// doing this before its timer fires will cause the rollup state to
|
|
|
|
// get very confused.
|
|
|
|
if ( mMenuParent )
|
|
|
|
mMenuParent->KillPendingTimers();
|
|
|
|
|
|
|
|
// safe to open up
|
2000-04-13 20:14:23 +00:00
|
|
|
OpenMenu(PR_TRUE);
|
2000-08-16 00:35:04 +00:00
|
|
|
}
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
2001-03-29 03:33:09 +00:00
|
|
|
else if (
|
|
|
|
#ifndef NSCONTEXTMENUISMOUSEUP
|
|
|
|
aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP &&
|
|
|
|
#else
|
|
|
|
aEvent->message == NS_CONTEXTMENU &&
|
|
|
|
#endif
|
2001-04-03 21:20:43 +00:00
|
|
|
mMenuParent && !IsMenu() && !IsDisabled()) {
|
2000-03-01 03:12:51 +00:00
|
|
|
// if this menu is a context menu it accepts right-clicks...fire away!
|
2001-03-29 03:33:09 +00:00
|
|
|
// Make sure we cancel default processing of the context menu event so
|
|
|
|
// that it doesn't bubble and get seen again by the popuplistener and show
|
|
|
|
// another context menu.
|
|
|
|
//
|
|
|
|
// Furthermore (there's always more, isn't there?), on some platforms (win32
|
|
|
|
// being one of them) we get the context menu event on a mouse up while
|
|
|
|
// on others we get it on a mouse down. For the ones where we get it on a
|
|
|
|
// mouse down, we must continue listening for the right button up event to
|
|
|
|
// dismiss the menu.
|
2000-03-01 03:12:51 +00:00
|
|
|
PRBool isContextMenu = PR_FALSE;
|
|
|
|
mMenuParent->GetIsContextMenu(isContextMenu);
|
2001-03-29 03:33:09 +00:00
|
|
|
if ( isContextMenu ) {
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2002-09-26 23:21:59 +00:00
|
|
|
Execute(aEvent);
|
2001-03-29 03:33:09 +00:00
|
|
|
}
|
2000-03-01 03:12:51 +00:00
|
|
|
}
|
2000-03-13 10:37:57 +00:00
|
|
|
else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP && !IsMenu() && mMenuParent && !IsDisabled()) {
|
1999-07-31 01:43:33 +00:00
|
|
|
// Execute the execute event handler.
|
2002-09-26 23:21:59 +00:00
|
|
|
Execute(aEvent);
|
1999-07-24 01:59:32 +00:00
|
|
|
}
|
2000-04-24 04:41:27 +00:00
|
|
|
else if (aEvent->message == NS_MOUSE_EXIT_SYNTH) {
|
1999-07-25 00:16:11 +00:00
|
|
|
// Kill our timer if one is active.
|
|
|
|
if (mOpenTimer) {
|
|
|
|
mOpenTimer->Cancel();
|
|
|
|
mOpenTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
// Deactivate the menu.
|
1999-07-23 08:36:39 +00:00
|
|
|
PRBool isActive = PR_FALSE;
|
|
|
|
PRBool isMenuBar = PR_FALSE;
|
|
|
|
if (mMenuParent) {
|
|
|
|
mMenuParent->IsMenuBar(isMenuBar);
|
1999-07-26 01:58:51 +00:00
|
|
|
PRBool cancel = PR_TRUE;
|
1999-07-23 08:36:39 +00:00
|
|
|
if (isMenuBar) {
|
|
|
|
mMenuParent->GetIsActive(isActive);
|
1999-07-26 01:58:51 +00:00
|
|
|
if (isActive) cancel = PR_FALSE;
|
1999-07-23 08:36:39 +00:00
|
|
|
}
|
1999-07-26 01:58:51 +00:00
|
|
|
|
1999-07-26 04:38:28 +00:00
|
|
|
if (cancel) {
|
|
|
|
if (IsMenu() && !isMenuBar && mMenuOpen) {
|
2000-02-13 08:33:39 +00:00
|
|
|
// Submenus don't get closed up immediately.
|
1999-07-26 04:38:28 +00:00
|
|
|
}
|
|
|
|
else mMenuParent->SetCurrentMenuItem(nsnull);
|
|
|
|
}
|
1999-07-23 08:36:39 +00:00
|
|
|
}
|
1999-07-21 07:42:16 +00:00
|
|
|
}
|
1999-07-25 01:14:43 +00:00
|
|
|
else if (aEvent->message == NS_MOUSE_MOVE && mMenuParent) {
|
1999-07-26 06:29:48 +00:00
|
|
|
if (gEatMouseMove) {
|
|
|
|
gEatMouseMove = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-01 00:39:12 +00:00
|
|
|
// we checked for mMenuParent right above
|
|
|
|
|
|
|
|
PRBool isMenuBar = PR_FALSE;
|
1999-07-25 01:14:43 +00:00
|
|
|
mMenuParent->IsMenuBar(isMenuBar);
|
1999-07-25 00:16:11 +00:00
|
|
|
|
1999-08-02 07:26:24 +00:00
|
|
|
// Let the menu parent know we're the new item.
|
|
|
|
mMenuParent->SetCurrentMenuItem(this);
|
|
|
|
|
1999-07-25 00:16:11 +00:00
|
|
|
// If we're a menu (and not a menu item),
|
|
|
|
// kick off the timer.
|
2000-03-13 10:37:57 +00:00
|
|
|
if (!IsDisabled() && !isMenuBar && IsMenu() && !mMenuOpen && !mOpenTimer) {
|
2000-01-21 21:56:09 +00:00
|
|
|
|
2000-02-13 08:33:39 +00:00
|
|
|
PRInt32 menuDelay = 300; // ms
|
2000-01-21 21:56:09 +00:00
|
|
|
|
2004-10-28 07:25:57 +00:00
|
|
|
nsCOMPtr<nsILookAndFeel> lookAndFeel(do_GetService(kLookAndFeelCID));
|
2001-01-09 01:28:36 +00:00
|
|
|
if (lookAndFeel)
|
2000-01-21 21:56:09 +00:00
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_SubmenuDelay, menuDelay);
|
|
|
|
|
|
|
|
// We're a menu, we're built, we're closed, and no timer has been kicked off.
|
2000-09-13 23:57:52 +00:00
|
|
|
mOpenTimer = do_CreateInstance("@mozilla.org/timer;1");
|
2002-09-07 05:38:16 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsITimerInternal> ti = do_QueryInterface(mOpenTimer);
|
2002-09-20 22:32:32 +00:00
|
|
|
ti->SetIdle(PR_FALSE);
|
2002-09-07 05:38:16 +00:00
|
|
|
|
|
|
|
mOpenTimer->InitWithCallback(this, menuDelay, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
|
1999-07-25 01:14:43 +00:00
|
|
|
}
|
1999-07-21 07:42:16 +00:00
|
|
|
}
|
2000-08-16 23:14:50 +00:00
|
|
|
|
1999-07-20 09:35:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-20 09:35:35 +00:00
|
|
|
nsMenuFrame::ToggleMenuState()
|
1999-07-21 07:42:16 +00:00
|
|
|
{
|
1999-07-20 09:35:35 +00:00
|
|
|
if (mMenuOpen) {
|
1999-07-21 07:42:16 +00:00
|
|
|
OpenMenu(PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
2003-01-20 11:58:30 +00:00
|
|
|
PRBool justRolledUp = PR_FALSE;
|
|
|
|
if (mMenuParent) {
|
|
|
|
mMenuParent->RecentlyRolledUp(this, &justRolledUp);
|
|
|
|
}
|
|
|
|
if (justRolledUp) {
|
|
|
|
// Don't let a click reopen a menu that was just rolled up
|
|
|
|
// from the same click. Otherwise, the user can't click on
|
|
|
|
// a menubar item to toggle its submenu closed.
|
|
|
|
OpenMenu(PR_FALSE);
|
|
|
|
SelectMenu(PR_TRUE);
|
2003-02-27 02:08:06 +00:00
|
|
|
mMenuParent->SetActive(PR_FALSE);
|
2003-01-20 11:58:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-02-27 02:08:06 +00:00
|
|
|
if (mMenuParent) {
|
|
|
|
mMenuParent->SetActive(PR_TRUE);
|
|
|
|
}
|
2003-01-20 11:58:30 +00:00
|
|
|
OpenMenu(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMenuParent) {
|
|
|
|
// Make sure the current menu which is being toggled on
|
|
|
|
// the menubar is highlighted
|
|
|
|
mMenuParent->SetCurrentMenuItem(this);
|
|
|
|
// We've successfully prevented the same click from both
|
|
|
|
// dismissing and reopening this menu.
|
|
|
|
// Clear the recent rollup state so we don't prevent
|
|
|
|
// this menu from being opened by the next click.
|
|
|
|
mMenuParent->ClearRecentlyRolledUp();
|
1999-07-21 07:42:16 +00:00
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-21 07:42:16 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-21 07:42:16 +00:00
|
|
|
nsMenuFrame::SelectMenu(PRBool aActivateFlag)
|
|
|
|
{
|
2000-11-28 00:28:01 +00:00
|
|
|
if (!mContent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
Bug 109851, bug 108629, bug 109921, bug 109977, bug 109153, bug 109187, bug 109213, bug 109221. Check in latest XUL accessibility support - menus, <colorpicker>, <progressmeter>, <groupbox>, mixed states for checkboxes, buttons that can be 'checked' ie pressed down, fixes extra MSAA events being generated, couldn't see HTML content
2001-11-20 02:05:26 +00:00
|
|
|
|
|
|
|
nsAutoString domEventToFire;
|
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
if (aActivateFlag) {
|
2002-03-27 07:01:26 +00:00
|
|
|
// Highlight the menu.
|
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsXULAtoms::menuactive, NS_LITERAL_STRING("true"), PR_TRUE);
|
Bug 109851, bug 108629, bug 109921, bug 109977, bug 109153, bug 109187, bug 109213, bug 109221. Check in latest XUL accessibility support - menus, <colorpicker>, <progressmeter>, <groupbox>, mixed states for checkboxes, buttons that can be 'checked' ie pressed down, fixes extra MSAA events being generated, couldn't see HTML content
2001-11-20 02:05:26 +00:00
|
|
|
// The menuactivated event is used by accessibility to track the user's movements through menus
|
2004-06-17 00:13:25 +00:00
|
|
|
domEventToFire.AssignLiteral("DOMMenuItemActive");
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-03-27 07:01:26 +00:00
|
|
|
// Unhighlight the menu.
|
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
2004-06-17 00:13:25 +00:00
|
|
|
domEventToFire.AssignLiteral("DOMMenuItemInactive");
|
1999-07-21 07:42:16 +00:00
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
2005-02-11 13:18:40 +00:00
|
|
|
FireDOMEvent(domEventToFire);
|
1999-09-21 01:03:00 +00:00
|
|
|
return NS_OK;
|
1999-07-21 07:42:16 +00:00
|
|
|
}
|
|
|
|
|
1999-08-02 08:15:30 +00:00
|
|
|
PRBool nsMenuFrame::IsGenerated()
|
1999-07-21 07:42:16 +00:00
|
|
|
{
|
1999-08-02 08:15:30 +00:00
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
|
|
|
// Generate the menu if it hasn't been generated already. This
|
|
|
|
// takes it from display: none to display: block and gives us
|
|
|
|
// a menu forevermore.
|
|
|
|
if (child) {
|
|
|
|
nsString genVal;
|
2001-08-17 08:14:14 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsXULAtoms::menugenerated, genVal);
|
2000-03-26 10:06:21 +00:00
|
|
|
if (genVal.IsEmpty())
|
1999-08-02 08:15:30 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-07-26 06:29:48 +00:00
|
|
|
|
1999-08-02 08:15:30 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1999-07-23 05:10:57 +00:00
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::MarkAsGenerated()
|
1999-08-02 08:15:30 +00:00
|
|
|
{
|
1999-07-21 07:42:16 +00:00
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
// Generate the menu if it hasn't been generated already. This
|
|
|
|
// takes it from display: none to display: block and gives us
|
|
|
|
// a menu forevermore.
|
|
|
|
if (child) {
|
1999-09-03 03:47:06 +00:00
|
|
|
nsAutoString genVal;
|
2001-08-17 08:14:14 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsXULAtoms::menugenerated, genVal);
|
2004-08-10 03:24:41 +00:00
|
|
|
if (genVal.IsEmpty()) {
|
2001-08-17 08:14:14 +00:00
|
|
|
child->SetAttr(kNameSpaceID_None, nsXULAtoms::menugenerated, NS_LITERAL_STRING("true"), PR_TRUE);
|
2004-08-10 03:24:41 +00:00
|
|
|
}
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-08-02 08:15:30 +00:00
|
|
|
}
|
|
|
|
|
2001-12-17 22:51:39 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::UngenerateMenu()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
|
|
|
if (child) {
|
|
|
|
nsAutoString genVal;
|
|
|
|
child->GetAttr(kNameSpaceID_None, nsXULAtoms::menugenerated, genVal);
|
|
|
|
if (!genVal.IsEmpty())
|
|
|
|
child->UnsetAttr(kNameSpaceID_None, nsXULAtoms::menugenerated, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-08-12 20:45:47 +00:00
|
|
|
nsMenuFrame::ActivateMenu(PRBool aActivateFlag)
|
|
|
|
{
|
2000-05-15 04:12:31 +00:00
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
nsMenuPopupFrame* menuPopup = (nsMenuPopupFrame*)frame;
|
|
|
|
|
|
|
|
if (!menuPopup)
|
|
|
|
return NS_OK;
|
1999-08-12 20:45:47 +00:00
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
if (aActivateFlag) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsRect rect = menuPopup->GetRect();
|
|
|
|
nsIView* view = menuPopup->GetView();
|
|
|
|
nsIViewManager* viewManager = view->GetViewManager();
|
2001-12-01 14:31:45 +00:00
|
|
|
rect.x = rect.y = 0;
|
|
|
|
viewManager->ResizeView(view, rect);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
// make sure the scrolled window is at 0,0
|
|
|
|
if (mLastPref.height <= rect.height) {
|
|
|
|
nsIBox* child;
|
|
|
|
menuPopup->GetChildBox(&child);
|
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIScrollableFrame> scrollframe(do_QueryInterface(child));
|
2000-05-15 04:12:31 +00:00
|
|
|
if (scrollframe) {
|
2004-09-06 02:44:43 +00:00
|
|
|
scrollframe->ScrollTo(nsPoint(0,0));
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-01 14:31:45 +00:00
|
|
|
viewManager->UpdateView(view, rect, NS_VMREFRESH_IMMEDIATE);
|
2000-05-15 04:12:31 +00:00
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kShow);
|
|
|
|
|
|
|
|
} else {
|
2005-02-11 13:18:40 +00:00
|
|
|
if (mMenuOpen) {
|
|
|
|
menuPopup->FireDOMEvent(NS_LITERAL_STRING("DOMMenuInactive"));
|
|
|
|
}
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = menuPopup->GetView();
|
2001-07-25 06:51:49 +00:00
|
|
|
NS_ASSERTION(view, "View is gone, looks like someone forgot to rollup the popup!");
|
|
|
|
if (view) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIViewManager* viewManager = view->GetViewManager();
|
2002-04-10 09:32:22 +00:00
|
|
|
if (viewManager) { // the view manager can be null during widget teardown
|
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
|
2003-08-04 12:39:51 +00:00
|
|
|
viewManager->ResizeView(view, nsRect(0, 0, 0, 0));
|
2002-04-10 09:32:22 +00:00
|
|
|
}
|
2001-07-25 06:51:49 +00:00
|
|
|
}
|
2000-05-16 20:46:08 +00:00
|
|
|
// set here so hide chain can close the menu as well.
|
|
|
|
mMenuOpen = PR_FALSE;
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
return NS_OK;
|
1999-08-12 20:45:47 +00:00
|
|
|
}
|
|
|
|
|
1999-09-08 03:51:41 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-31 01:13:27 +00:00
|
|
|
nsMenuFrame::AttributeChanged(nsIContent* aChild,
|
1999-10-15 23:16:45 +00:00
|
|
|
PRInt32 aNameSpaceID,
|
1999-09-08 03:51:41 +00:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-11 21:16:12 +00:00
|
|
|
PRInt32 aModType)
|
1999-09-08 03:51:41 +00:00
|
|
|
{
|
1999-09-17 20:12:02 +00:00
|
|
|
nsAutoString value;
|
|
|
|
|
2005-02-23 10:08:51 +00:00
|
|
|
if (aAttribute == nsHTMLAtoms::checked) {
|
1999-10-17 21:37:37 +00:00
|
|
|
if (mType != eMenuType_Normal)
|
2004-12-31 01:13:27 +00:00
|
|
|
UpdateMenuSpecialState(GetPresContext());
|
2001-10-11 03:03:42 +00:00
|
|
|
} else if (aAttribute == nsXULAtoms::acceltext) {
|
|
|
|
// someone reset the accelText attribute, so clear the bit that says *we* set it
|
2003-08-04 12:39:51 +00:00
|
|
|
AddStateBits(NS_STATE_ACCELTEXT_IS_DERIVED);
|
2001-10-11 03:03:42 +00:00
|
|
|
BuildAcceleratorText();
|
|
|
|
} else if (aAttribute == nsXULAtoms::key) {
|
|
|
|
BuildAcceleratorText();
|
2000-02-22 01:50:48 +00:00
|
|
|
} else if ( aAttribute == nsHTMLAtoms::type || aAttribute == nsHTMLAtoms::name )
|
2004-12-31 01:13:27 +00:00
|
|
|
UpdateMenuType(GetPresContext());
|
1999-09-17 20:12:02 +00:00
|
|
|
|
1999-09-08 03:51:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-09-08 03:51:41 +00:00
|
|
|
nsMenuFrame::OpenMenu(PRBool aActivateFlag)
|
|
|
|
{
|
2002-06-28 03:10:08 +00:00
|
|
|
if (!mContent)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-09-08 03:51:41 +00:00
|
|
|
if (aActivateFlag) {
|
|
|
|
// Now that the menu is opened, we should have a menupopup child built.
|
|
|
|
// Mark it as generated, which ensures a frame gets built.
|
|
|
|
MarkAsGenerated();
|
|
|
|
|
2005-02-23 10:08:51 +00:00
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsXULAtoms::open, NS_LITERAL_STRING("true"), PR_TRUE);
|
1999-09-08 03:51:41 +00:00
|
|
|
}
|
2005-02-23 10:08:51 +00:00
|
|
|
else mContent->UnsetAttr(kNameSpaceID_None, nsXULAtoms::open, PR_TRUE);
|
|
|
|
OpenMenuInternal(aActivateFlag);
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-09-08 03:51:41 +00:00
|
|
|
}
|
|
|
|
|
1999-08-02 08:15:30 +00:00
|
|
|
void
|
1999-09-08 03:51:41 +00:00
|
|
|
nsMenuFrame::OpenMenuInternal(PRBool aActivateFlag)
|
1999-08-02 08:15:30 +00:00
|
|
|
{
|
|
|
|
gEatMouseMove = PR_TRUE;
|
|
|
|
|
|
|
|
if (!mIsMenu)
|
|
|
|
return;
|
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
if (aActivateFlag) {
|
1999-07-31 01:43:33 +00:00
|
|
|
// Execute the oncreate handler
|
|
|
|
if (!OnCreate())
|
|
|
|
return;
|
|
|
|
|
2000-05-18 00:21:32 +00:00
|
|
|
mCreateHandlerSucceeded = PR_TRUE;
|
|
|
|
|
1999-09-25 03:39:35 +00:00
|
|
|
// Set the focus back to our view's widget.
|
2001-09-10 07:34:54 +00:00
|
|
|
if (nsMenuFrame::sDismissalListener)
|
|
|
|
nsMenuFrame::sDismissalListener->EnableListener(PR_FALSE);
|
1999-09-25 03:39:35 +00:00
|
|
|
|
1999-09-08 03:51:41 +00:00
|
|
|
// XXX Only have this here because of RDF-generated content.
|
1999-08-04 21:36:30 +00:00
|
|
|
MarkAsGenerated();
|
|
|
|
|
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
nsMenuPopupFrame* menuPopup = (nsMenuPopupFrame*)frame;
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
mMenuOpen = PR_TRUE;
|
|
|
|
|
1999-08-12 20:45:47 +00:00
|
|
|
if (menuPopup) {
|
2000-07-28 00:25:18 +00:00
|
|
|
// inherit whether or not we're a context menu from the parent
|
2000-07-28 04:10:12 +00:00
|
|
|
if ( mMenuParent ) {
|
|
|
|
PRBool parentIsContextMenu = PR_FALSE;
|
|
|
|
mMenuParent->GetIsContextMenu(parentIsContextMenu);
|
|
|
|
menuPopup->SetIsContextMenu(parentIsContextMenu);
|
|
|
|
}
|
2000-07-28 00:25:18 +00:00
|
|
|
|
2000-02-09 09:34:35 +00:00
|
|
|
// Install a keyboard navigation listener if we're the root of the menu chain.
|
|
|
|
PRBool onMenuBar = PR_TRUE;
|
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->IsMenuBar(onMenuBar);
|
|
|
|
|
|
|
|
if (mMenuParent && onMenuBar)
|
|
|
|
mMenuParent->InstallKeyboardNavigator();
|
|
|
|
else if (!mMenuParent)
|
|
|
|
menuPopup->InstallKeyboardNavigator();
|
|
|
|
|
1999-07-22 09:01:55 +00:00
|
|
|
// Tell the menu bar we're active.
|
1999-09-01 00:39:12 +00:00
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->SetActive(PR_TRUE);
|
1999-07-31 11:29:03 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIContent* menuPopupContent = menuPopup->GetContent();
|
1999-12-08 11:30:47 +00:00
|
|
|
|
2000-02-25 08:37:49 +00:00
|
|
|
// Sync up the view.
|
1999-12-08 11:30:47 +00:00
|
|
|
nsAutoString popupAnchor, popupAlign;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
menuPopupContent->GetAttr(kNameSpaceID_None, nsXULAtoms::popupanchor, popupAnchor);
|
|
|
|
menuPopupContent->GetAttr(kNameSpaceID_None, nsXULAtoms::popupalign, popupAlign);
|
1999-12-08 11:30:47 +00:00
|
|
|
|
|
|
|
if (onMenuBar) {
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAnchor.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
popupAnchor.AssignLiteral("bottomleft");
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAlign.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
popupAlign.AssignLiteral("topleft");
|
1999-12-08 11:30:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAnchor.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
popupAnchor.AssignLiteral("topright");
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAlign.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
popupAlign.AssignLiteral("topleft");
|
1999-12-08 11:30:47 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
nsBoxLayoutState state(mPresContext);
|
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
// if height never set we need to do an initial reflow.
|
|
|
|
if (mLastPref.height == -1)
|
|
|
|
{
|
|
|
|
menuPopup->MarkDirty(state);
|
|
|
|
|
2004-05-27 22:08:42 +00:00
|
|
|
mPresContext->PresShell()->FlushPendingNotifications(Flush_OnlyReflow);
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
nsRect curRect(menuPopup->GetRect());
|
2000-06-26 21:00:44 +00:00
|
|
|
menuPopup->SetBounds(state, nsRect(0,0,mLastPref.width, mLastPref.height));
|
2000-05-15 04:12:31 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = menuPopup->GetView();
|
|
|
|
nsIViewManager* vm = view->GetViewManager();
|
2001-12-01 14:31:45 +00:00
|
|
|
if (vm) {
|
|
|
|
vm->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
|
|
}
|
1999-12-08 11:30:47 +00:00
|
|
|
menuPopup->SyncViewWithFrame(mPresContext, popupAnchor, popupAlign, this, -1, -1);
|
2004-09-28 18:37:50 +00:00
|
|
|
nscoord newHeight = menuPopup->GetRect().height;
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
// if the height is different then reflow. It might need scrollbars force a reflow
|
2004-09-28 18:37:50 +00:00
|
|
|
if (curRect.height != newHeight || mLastPref.height != newHeight)
|
2000-05-15 04:12:31 +00:00
|
|
|
{
|
|
|
|
menuPopup->MarkDirty(state);
|
2004-05-27 22:08:42 +00:00
|
|
|
mPresContext->PresShell()->FlushPendingNotifications(Flush_OnlyReflow);
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
1999-07-22 09:01:55 +00:00
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
ActivateMenu(PR_TRUE);
|
1999-09-28 23:25:48 +00:00
|
|
|
|
2002-08-06 12:48:28 +00:00
|
|
|
nsIMenuParent *childPopup = nsnull;
|
|
|
|
CallQueryInterface(frame, &childPopup);
|
2000-05-15 04:12:31 +00:00
|
|
|
UpdateDismissalListener(childPopup);
|
|
|
|
|
2001-08-06 21:49:35 +00:00
|
|
|
OnCreated();
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
1999-09-25 03:39:35 +00:00
|
|
|
|
|
|
|
// Set the focus back to our view's widget.
|
2001-09-10 07:34:54 +00:00
|
|
|
if (nsMenuFrame::sDismissalListener)
|
|
|
|
nsMenuFrame::sDismissalListener->EnableListener(PR_TRUE);
|
1999-09-25 03:39:35 +00:00
|
|
|
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
1999-07-21 07:42:16 +00:00
|
|
|
else {
|
2000-05-15 04:12:31 +00:00
|
|
|
|
1999-07-24 22:02:23 +00:00
|
|
|
// Close the menu.
|
2000-05-11 00:52:34 +00:00
|
|
|
// Execute the ondestroy handler, but only if we're actually open
|
2000-05-18 00:21:32 +00:00
|
|
|
if ( !mCreateHandlerSucceeded || !OnDestroy() )
|
1999-07-31 01:43:33 +00:00
|
|
|
return;
|
|
|
|
|
1999-09-25 03:39:35 +00:00
|
|
|
// Set the focus back to our view's widget.
|
2001-09-10 07:34:54 +00:00
|
|
|
if (nsMenuFrame::sDismissalListener) {
|
|
|
|
nsMenuFrame::sDismissalListener->EnableListener(PR_FALSE);
|
|
|
|
nsMenuFrame::sDismissalListener->SetCurrentMenuParent(mMenuParent);
|
1999-09-25 03:39:35 +00:00
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
1999-08-04 21:36:30 +00:00
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
nsMenuPopupFrame* menuPopup = (nsMenuPopupFrame*)frame;
|
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
// Make sure we clear out our own items.
|
2000-02-09 09:34:35 +00:00
|
|
|
if (menuPopup) {
|
1999-07-31 11:29:03 +00:00
|
|
|
menuPopup->SetCurrentMenuItem(nsnull);
|
2000-02-13 08:33:39 +00:00
|
|
|
menuPopup->KillCloseTimer();
|
1999-07-31 11:29:03 +00:00
|
|
|
|
2000-02-09 09:34:35 +00:00
|
|
|
PRBool onMenuBar = PR_TRUE;
|
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->IsMenuBar(onMenuBar);
|
|
|
|
|
|
|
|
if (mMenuParent && onMenuBar)
|
|
|
|
mMenuParent->RemoveKeyboardNavigator();
|
|
|
|
else if (!mMenuParent)
|
|
|
|
menuPopup->RemoveKeyboardNavigator();
|
2002-08-03 01:20:08 +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 untill we find the better approach.
|
2004-02-27 17:17:37 +00:00
|
|
|
|
|
|
|
nsIEventStateManager *esm = mPresContext->EventStateManager();
|
|
|
|
|
2002-08-03 01:20:08 +00:00
|
|
|
PRInt32 state;
|
2003-08-04 12:39:51 +00:00
|
|
|
esm->GetContentState(menuPopup->GetContent(), state);
|
2004-02-27 17:17:37 +00:00
|
|
|
|
2002-08-03 01:20:08 +00:00
|
|
|
if (state & NS_EVENT_STATE_HOVER)
|
|
|
|
esm->SetContentState(nsnull, NS_EVENT_STATE_HOVER);
|
2000-02-09 09:34:35 +00:00
|
|
|
}
|
|
|
|
|
1999-08-12 20:45:47 +00:00
|
|
|
ActivateMenu(PR_FALSE);
|
2005-02-11 13:18:40 +00:00
|
|
|
// XXX hack: ensure that mMenuOpen is set to false, in case where
|
|
|
|
// there is actually no popup. because ActivateMenu() will return
|
|
|
|
// early without setting it. It could be that mMenuOpen is true
|
|
|
|
// in that case, because OpenMenuInternal(true) gets called if
|
|
|
|
// the attribute open="true", whether there is a popup or not.
|
|
|
|
// We should not allow mMenuOpen unless there is a popup in the first place,
|
|
|
|
// in which case this line would not be necessary.
|
|
|
|
mMenuOpen = PR_FALSE;
|
1999-08-12 20:45:47 +00:00
|
|
|
|
2001-08-06 21:49:35 +00:00
|
|
|
OnDestroyed();
|
|
|
|
|
2001-09-10 07:34:54 +00:00
|
|
|
if (nsMenuFrame::sDismissalListener)
|
|
|
|
nsMenuFrame::sDismissalListener->EnableListener(PR_TRUE);
|
2005-02-23 10:08:51 +00:00
|
|
|
|
|
|
|
mCreateHandlerSucceeded = PR_FALSE;
|
1999-07-21 07:42:16 +00:00
|
|
|
}
|
2000-05-15 04:12:31 +00:00
|
|
|
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::GetMenuChildrenElement(nsIContent** aResult)
|
|
|
|
{
|
2002-03-18 23:39:48 +00:00
|
|
|
if (!mContent)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-08-06 08:11:05 +00:00
|
|
|
nsresult rv;
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIXBLService> xblService =
|
|
|
|
do_GetService("@mozilla.org/xbl;1", &rv);
|
2000-08-06 08:11:05 +00:00
|
|
|
PRInt32 dummy;
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 count = mContent->GetChildCount();
|
1999-07-31 11:29:03 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
for (PRUint32 i = 0; i < count; i++) {
|
|
|
|
nsIContent *child = mContent->GetChildAt(i);
|
1999-07-31 11:29:03 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
2000-08-06 08:11:05 +00:00
|
|
|
xblService->ResolveTag(child, &dummy, getter_AddRefs(tag));
|
2003-09-27 04:18:26 +00:00
|
|
|
if (tag == nsXULAtoms::menupopup) {
|
|
|
|
*aResult = child;
|
1999-07-31 11:29:03 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return;
|
|
|
|
}
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-17 23:41:22 +00:00
|
|
|
PRBool
|
|
|
|
nsMenuFrame::IsSizedToPopup(nsIContent* aContent, PRBool aRequireAlways)
|
|
|
|
{
|
|
|
|
PRBool sizeToPopup;
|
2003-11-19 01:20:56 +00:00
|
|
|
if (aContent->Tag() == nsHTMLAtoms::select)
|
2002-03-17 23:41:22 +00:00
|
|
|
sizeToPopup = PR_TRUE;
|
|
|
|
else {
|
|
|
|
nsAutoString sizedToPopup;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsXULAtoms::sizetopopup, sizedToPopup);
|
2004-04-30 13:23:43 +00:00
|
|
|
sizeToPopup = sizedToPopup.EqualsLiteral("always") ||
|
|
|
|
!aRequireAlways && sizedToPopup.EqualsLiteral("pref");
|
2002-03-17 23:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sizeToPopup;
|
|
|
|
}
|
|
|
|
|
2002-02-28 07:28:39 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize)
|
|
|
|
{
|
|
|
|
// Our min size is the popup size (same as the pref size) if
|
|
|
|
// sizetopopup="always" is set. However, we first need to check
|
|
|
|
// to see if a min size was set in CSS.
|
|
|
|
PRBool collapsed = PR_FALSE;
|
|
|
|
IsCollapsed(aBoxLayoutState, collapsed);
|
|
|
|
if (collapsed) {
|
|
|
|
aSize.width = aSize.height = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* popupChild = mPopupFrames.FirstChild();
|
|
|
|
|
2002-03-17 23:41:22 +00:00
|
|
|
if (popupChild && IsSizedToPopup(mContent, PR_TRUE))
|
|
|
|
return GetPrefSize(aBoxLayoutState, aSize);
|
2002-02-28 07:28:39 +00:00
|
|
|
|
|
|
|
return nsBoxFrame::GetMinSize(aBoxLayoutState, aSize);
|
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHODIMP
|
2000-07-07 22:24:06 +00:00
|
|
|
nsMenuFrame::DoLayout(nsBoxLayoutState& aState)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
|
|
|
nsRect contentRect;
|
|
|
|
GetContentRect(contentRect);
|
|
|
|
|
|
|
|
// lay us out
|
2000-07-07 22:24:06 +00:00
|
|
|
nsresult rv = nsBoxFrame::DoLayout(aState);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// layout the popup. First we need to get it.
|
|
|
|
nsIFrame* popupChild = mPopupFrames.FirstChild();
|
|
|
|
|
|
|
|
if (popupChild) {
|
2002-03-17 23:41:22 +00:00
|
|
|
PRBool sizeToPopup = IsSizedToPopup(mContent, PR_FALSE);
|
2004-09-28 18:37:50 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(popupChild->IsBoxFrame(), "popupChild is not box!!");
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
// then get its preferred size
|
|
|
|
nsSize prefSize(0,0);
|
|
|
|
nsSize minSize(0,0);
|
|
|
|
nsSize maxSize(0,0);
|
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
popupChild->GetPrefSize(aState, prefSize);
|
|
|
|
popupChild->GetMinSize(aState, minSize);
|
|
|
|
popupChild->GetMaxSize(aState, maxSize);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
BoundsCheck(minSize, prefSize, maxSize);
|
|
|
|
|
2001-11-27 00:03:36 +00:00
|
|
|
if (sizeToPopup)
|
2000-03-31 07:02:06 +00:00
|
|
|
prefSize.width = contentRect.width;
|
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
// if the pref size changed then set bounds to be the pref size
|
|
|
|
// and sync the view. And set new pref size.
|
|
|
|
if (mLastPref != prefSize) {
|
2004-09-28 18:37:50 +00:00
|
|
|
popupChild->SetBounds(aState, nsRect(0,0,prefSize.width, prefSize.height));
|
2000-05-15 04:12:31 +00:00
|
|
|
RePositionPopup(aState);
|
|
|
|
mLastPref = prefSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// is the new size too small? Make sure we handle scrollbars correctly
|
|
|
|
nsIBox* child;
|
2004-09-28 18:37:50 +00:00
|
|
|
popupChild->GetChildBox(&child);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
nsRect bounds(popupChild->GetRect());
|
2000-05-15 04:12:31 +00:00
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIScrollableFrame> scrollframe(do_QueryInterface(child));
|
2004-09-03 00:43:46 +00:00
|
|
|
if (scrollframe &&
|
|
|
|
scrollframe->GetScrollbarStyles().mVertical == NS_STYLE_OVERFLOW_AUTO) {
|
|
|
|
if (bounds.height < prefSize.height) {
|
|
|
|
// layout the child
|
2004-09-28 18:37:50 +00:00
|
|
|
popupChild->Layout(aState);
|
2004-09-03 00:43:46 +00:00
|
|
|
|
|
|
|
nsMargin scrollbars = scrollframe->GetActualScrollbarSizes();
|
|
|
|
if (bounds.width < prefSize.width + scrollbars.left + scrollbars.right)
|
|
|
|
{
|
|
|
|
bounds.width += scrollbars.left + scrollbars.right;
|
|
|
|
//printf("Width=%d\n",width);
|
2004-09-28 18:37:50 +00:00
|
|
|
popupChild->SetBounds(aState, bounds);
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// layout the child
|
2004-09-28 18:37:50 +00:00
|
|
|
popupChild->Layout(aState);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
// Only size the popups view if open.
|
|
|
|
if (mMenuOpen) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIView* view = popupChild->GetView();
|
2001-12-01 14:31:45 +00:00
|
|
|
nsRect r(0, 0, bounds.width, bounds.height);
|
2003-08-04 12:39:51 +00:00
|
|
|
view->GetViewManager()->ResizeView(view, r);
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SyncLayout(aState);
|
|
|
|
|
2000-05-15 04:12:31 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-08-30 02:37:27 +00:00
|
|
|
nsMenuFrame::MarkChildrenStyleChange()
|
2000-05-15 04:12:31 +00:00
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::MarkChildrenStyleChange();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsIFrame* popupChild = mPopupFrames.FirstChild();
|
|
|
|
|
|
|
|
if (popupChild) {
|
2004-09-28 18:37:50 +00:00
|
|
|
NS_ASSERTION(popupChild->IsBoxFrame(), "popupChild is not box!!");
|
|
|
|
return popupChild->MarkChildrenStyleChange();
|
2000-05-15 04:12:31 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2004-06-19 09:07:47 +00:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2000-03-02 03:01:30 +00:00
|
|
|
NS_IMETHODIMP
|
2000-03-31 07:02:06 +00:00
|
|
|
nsMenuFrame::SetDebug(nsBoxLayoutState& aState, PRBool aDebug)
|
2000-03-02 03:01:30 +00:00
|
|
|
{
|
|
|
|
// see if our state matches the given debug state
|
|
|
|
PRBool debugSet = mState & NS_STATE_CURRENTLY_IN_DEBUG;
|
|
|
|
PRBool debugChanged = (!aDebug && debugSet) || (aDebug && !debugSet);
|
|
|
|
|
|
|
|
// if it doesn't then tell each child below us the new debug state
|
|
|
|
if (debugChanged)
|
|
|
|
{
|
2000-03-31 07:02:06 +00:00
|
|
|
nsBoxFrame::SetDebug(aState, aDebug);
|
|
|
|
SetDebug(aState, mPopupFrames.FirstChild(), aDebug);
|
2000-03-02 03:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-03-31 07:02:06 +00:00
|
|
|
nsMenuFrame::SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, PRBool aDebug)
|
2000-03-02 03:01:30 +00:00
|
|
|
{
|
|
|
|
if (!aList)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
while (aList) {
|
2004-09-28 18:37:50 +00:00
|
|
|
if (aList->IsBoxFrame())
|
|
|
|
aList->SetDebug(aState, aDebug);
|
2000-03-02 03:01:30 +00:00
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
aList = aList->GetNextSibling();
|
2000-03-02 03:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-06-19 09:07:47 +00:00
|
|
|
#endif
|
2000-03-02 03:01:30 +00:00
|
|
|
|
2001-08-08 01:38:05 +00:00
|
|
|
static void ConvertPosition(nsIContent* aPopupElt, nsString& aAnchor, nsString& aAlign)
|
|
|
|
{
|
|
|
|
nsAutoString position;
|
2001-08-17 08:14:14 +00:00
|
|
|
aPopupElt->GetAttr(kNameSpaceID_None, nsXULAtoms::position, position);
|
2001-08-08 01:38:05 +00:00
|
|
|
if (position.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2004-04-30 13:23:43 +00:00
|
|
|
if (position.EqualsLiteral("before_start")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("topleft");
|
|
|
|
aAlign.AssignLiteral("bottomleft");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (position.EqualsLiteral("before_end")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("topright");
|
|
|
|
aAlign.AssignLiteral("bottomright");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (position.EqualsLiteral("after_start")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("bottomleft");
|
|
|
|
aAlign.AssignLiteral("topleft");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (position.EqualsLiteral("after_end")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("bottomright");
|
|
|
|
aAlign.AssignLiteral("topright");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (position.EqualsLiteral("start_before")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("topleft");
|
|
|
|
aAlign.AssignLiteral("topright");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (position.EqualsLiteral("start_after")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("bottomleft");
|
|
|
|
aAlign.AssignLiteral("bottomright");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (position.EqualsLiteral("end_before")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("topright");
|
|
|
|
aAlign.AssignLiteral("topleft");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (position.EqualsLiteral("end_after")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("bottomright");
|
|
|
|
aAlign.AssignLiteral("bottomleft");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (position.EqualsLiteral("overlap")) {
|
2004-06-17 00:13:25 +00:00
|
|
|
aAnchor.AssignLiteral("topleft");
|
|
|
|
aAlign.AssignLiteral("topleft");
|
2001-08-08 01:38:05 +00:00
|
|
|
}
|
|
|
|
}
|
1999-07-31 11:29:03 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
void
|
2000-05-15 04:12:31 +00:00
|
|
|
nsMenuFrame::RePositionPopup(nsBoxLayoutState& aState)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* presContext = aState.PresContext();
|
2000-05-15 04:12:31 +00:00
|
|
|
|
1999-09-24 05:22:55 +00:00
|
|
|
// Sync up the view.
|
1999-07-31 11:29:03 +00:00
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
nsMenuPopupFrame* menuPopup = (nsMenuPopupFrame*)frame;
|
1999-09-24 05:22:55 +00:00
|
|
|
if (mMenuOpen && menuPopup) {
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIContent* menuPopupContent = menuPopup->GetContent();
|
1999-12-08 11:30:47 +00:00
|
|
|
nsAutoString popupAnchor, popupAlign;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
menuPopupContent->GetAttr(kNameSpaceID_None, nsXULAtoms::popupanchor, popupAnchor);
|
|
|
|
menuPopupContent->GetAttr(kNameSpaceID_None, nsXULAtoms::popupalign, popupAlign);
|
1999-12-08 11:30:47 +00:00
|
|
|
|
2001-08-08 01:38:05 +00:00
|
|
|
ConvertPosition(menuPopupContent, popupAnchor, popupAlign);
|
|
|
|
|
1999-09-24 05:22:55 +00:00
|
|
|
PRBool onMenuBar = PR_TRUE;
|
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->IsMenuBar(onMenuBar);
|
|
|
|
|
1999-12-08 11:30:47 +00:00
|
|
|
if (onMenuBar) {
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAnchor.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
popupAnchor.AssignLiteral("bottomleft");
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAlign.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
popupAlign.AssignLiteral("topleft");
|
1999-12-08 11:30:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAnchor.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
popupAnchor.AssignLiteral("topright");
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAlign.IsEmpty())
|
2004-06-17 00:13:25 +00:00
|
|
|
popupAlign.AssignLiteral("topleft");
|
1999-12-08 11:30:47 +00:00
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
menuPopup->SyncViewWithFrame(presContext, popupAnchor, popupAlign, this, -1, -1);
|
1999-09-24 05:22:55 +00:00
|
|
|
}
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
2002-04-24 07:15:35 +00:00
|
|
|
nsMenuFrame::ShortcutNavigation(nsIDOMKeyEvent* aKeyEvent, PRBool& aHandledFlag)
|
1999-07-23 05:47:43 +00:00
|
|
|
{
|
1999-07-23 07:39:16 +00:00
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (frame) {
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*)frame;
|
2002-04-24 07:15:35 +00:00
|
|
|
popup->ShortcutNavigation(aKeyEvent, aHandledFlag);
|
1999-07-23 07:39:16 +00:00
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-23 05:47:43 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
2002-08-06 23:47:01 +00:00
|
|
|
nsMenuFrame::KeyboardNavigation(PRUint32 aKeyCode, PRBool& aHandledFlag)
|
1999-07-22 09:01:55 +00:00
|
|
|
{
|
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (frame) {
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*)frame;
|
2002-08-06 23:47:01 +00:00
|
|
|
popup->KeyboardNavigation(aKeyCode, aHandledFlag);
|
1999-07-22 09:01:55 +00:00
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-22 09:01:55 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-23 08:36:39 +00:00
|
|
|
nsMenuFrame::Escape(PRBool& aHandledFlag)
|
1999-07-23 07:49:43 +00:00
|
|
|
{
|
2003-01-20 11:58:30 +00:00
|
|
|
if (mMenuParent) {
|
|
|
|
mMenuParent->ClearRecentlyRolledUp();
|
|
|
|
}
|
1999-07-23 08:36:39 +00:00
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (frame) {
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*)frame;
|
|
|
|
popup->Escape(aHandledFlag);
|
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-23 07:49:43 +00:00
|
|
|
}
|
|
|
|
|
2000-08-25 01:59:53 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Enter
|
|
|
|
//
|
|
|
|
// Called when the user hits the <Enter>/<Return> keys or presses the
|
|
|
|
// shortcut key. If this is a leaf item, the item's action will be executed.
|
|
|
|
// If it is a submenu parent, open the submenu and select the first time.
|
|
|
|
// In either case, do nothing if the item is disabled.
|
|
|
|
//
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-24 22:02:23 +00:00
|
|
|
nsMenuFrame::Enter()
|
|
|
|
{
|
2002-02-15 03:53:26 +00:00
|
|
|
if (IsDisabled()) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// behavior on Windows - close the popup chain
|
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->DismissChain();
|
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
// this menu item was disabled - exit
|
2000-08-25 01:59:53 +00:00
|
|
|
return NS_OK;
|
2002-02-15 03:53:26 +00:00
|
|
|
}
|
2000-08-25 01:59:53 +00:00
|
|
|
|
1999-07-24 22:02:23 +00:00
|
|
|
if (!mMenuOpen) {
|
|
|
|
// The enter key press applies to us.
|
2000-08-25 01:59:53 +00:00
|
|
|
if (!IsMenu() && mMenuParent)
|
2002-09-26 23:21:59 +00:00
|
|
|
Execute(0); // Execute our event handler
|
1999-07-25 00:16:11 +00:00
|
|
|
else {
|
1999-07-24 22:02:23 +00:00
|
|
|
OpenMenu(PR_TRUE);
|
|
|
|
SelectFirstItem();
|
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
return NS_OK;
|
1999-07-24 22:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (frame) {
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*)frame;
|
|
|
|
popup->Enter();
|
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-24 22:02:23 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-22 09:01:55 +00:00
|
|
|
nsMenuFrame::SelectFirstItem()
|
|
|
|
{
|
1999-07-23 09:34:14 +00:00
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (frame) {
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*)frame;
|
1999-09-21 01:03:00 +00:00
|
|
|
nsIMenuFrame* result;
|
1999-07-23 09:34:14 +00:00
|
|
|
popup->GetNextMenuItem(nsnull, &result);
|
|
|
|
popup->SetCurrentMenuItem(result);
|
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-25 00:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMenuFrame::IsMenu()
|
|
|
|
{
|
2000-03-13 10:20:34 +00:00
|
|
|
return mIsMenu;
|
1999-07-25 01:14:43 +00:00
|
|
|
}
|
|
|
|
|
2002-09-07 05:38:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-25 01:14:43 +00:00
|
|
|
nsMenuFrame::Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
// Our timer has fired.
|
1999-07-26 04:38:28 +00:00
|
|
|
if (aTimer == mOpenTimer.get()) {
|
|
|
|
if (!mMenuOpen && mMenuParent) {
|
2002-03-27 07:01:26 +00:00
|
|
|
nsAutoString active;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsXULAtoms::menuactive, active);
|
2004-04-30 13:23:43 +00:00
|
|
|
if (active.EqualsLiteral("true")) {
|
2000-08-30 02:37:27 +00:00
|
|
|
// We're still the active menu. Make sure all submenus/timers are closed
|
|
|
|
// before opening this one
|
|
|
|
mMenuParent->KillPendingTimers();
|
1999-07-26 04:38:28 +00:00
|
|
|
OpenMenu(PR_TRUE);
|
|
|
|
}
|
1999-07-25 01:14:43 +00:00
|
|
|
}
|
1999-07-26 04:38:28 +00:00
|
|
|
mOpenTimer->Cancel();
|
|
|
|
mOpenTimer = nsnull;
|
1999-07-25 01:14:43 +00:00
|
|
|
}
|
1999-07-26 04:38:28 +00:00
|
|
|
|
1999-07-25 01:14:43 +00:00
|
|
|
mOpenTimer = nsnull;
|
2002-09-07 05:38:16 +00:00
|
|
|
return NS_OK;
|
1999-07-25 01:14:43 +00:00
|
|
|
}
|
1999-07-26 01:35:39 +00:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMenuFrame::IsDisabled()
|
|
|
|
{
|
1999-09-03 03:47:06 +00:00
|
|
|
nsAutoString disabled;
|
2001-08-17 08:14:14 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, disabled);
|
2004-04-30 13:23:43 +00:00
|
|
|
if (disabled.EqualsLiteral("true"))
|
1999-07-26 01:35:39 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-07-31 01:43:33 +00:00
|
|
|
|
1999-10-15 21:13:24 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMenuFrame::UpdateMenuType(nsPresContext* aPresContext)
|
1999-10-15 21:13:24 +00:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, value);
|
2004-04-30 13:23:43 +00:00
|
|
|
if (value.EqualsLiteral("checkbox"))
|
1999-10-17 21:37:37 +00:00
|
|
|
mType = eMenuType_Checkbox;
|
2004-04-30 13:23:43 +00:00
|
|
|
else if (value.EqualsLiteral("radio")) {
|
1999-10-17 21:37:37 +00:00
|
|
|
mType = eMenuType_Radio;
|
2004-05-06 20:39:21 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, mGroupName);
|
2000-02-22 01:50:48 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-10-17 21:37:37 +00:00
|
|
|
if (mType != eMenuType_Normal)
|
2001-08-17 08:14:14 +00:00
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::checked,
|
|
|
|
PR_TRUE);
|
1999-10-17 21:37:37 +00:00
|
|
|
mType = eMenuType_Normal;
|
1999-10-15 21:13:24 +00:00
|
|
|
}
|
2000-01-22 01:16:50 +00:00
|
|
|
UpdateMenuSpecialState(aPresContext);
|
1999-10-15 21:13:24 +00:00
|
|
|
}
|
|
|
|
|
1999-10-17 21:37:37 +00:00
|
|
|
/* update checked-ness for type="checkbox" and type="radio" */
|
1999-10-15 21:13:24 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMenuFrame::UpdateMenuSpecialState(nsPresContext* aPresContext) {
|
1999-10-15 21:13:24 +00:00
|
|
|
nsAutoString value;
|
1999-10-17 21:37:37 +00:00
|
|
|
PRBool newChecked;
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::checked,
|
|
|
|
value);
|
2004-04-30 13:23:43 +00:00
|
|
|
newChecked = (value.EqualsLiteral("true"));
|
1999-10-17 21:37:37 +00:00
|
|
|
|
|
|
|
if (newChecked == mChecked) {
|
|
|
|
/* checked state didn't change */
|
|
|
|
|
|
|
|
if (mType != eMenuType_Radio)
|
|
|
|
return; // only Radio possibly cares about other kinds of change
|
|
|
|
|
2004-05-06 20:39:21 +00:00
|
|
|
if (!mChecked || mGroupName.IsEmpty())
|
1999-10-17 21:37:37 +00:00
|
|
|
return; // no interesting change
|
|
|
|
} else {
|
|
|
|
mChecked = newChecked;
|
|
|
|
if (mType != eMenuType_Radio || !mChecked)
|
|
|
|
/*
|
|
|
|
* Unchecking something requires no further changes, and only
|
|
|
|
* menuRadio has to do additional work when checked.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we get this far, we're type=radio, and:
|
|
|
|
* - our name= changed, or
|
|
|
|
* - we went from checked="false" to checked="true"
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Behavioural note:
|
|
|
|
* If we're checked and renamed _into_ an existing radio group, we are
|
|
|
|
* made the new checked item, and we unselect the previous one.
|
|
|
|
*
|
|
|
|
* The only other reasonable behaviour would be to check for another selected
|
|
|
|
* item in that group. If found, unselect ourselves, otherwise we're the
|
|
|
|
* selected item. That, however, would be a lot more work, and I don't think
|
|
|
|
* it's better at all.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* walk siblings, looking for the other checked item with the same name */
|
|
|
|
nsIMenuFrame *sibMenu;
|
|
|
|
nsMenuType sibType;
|
|
|
|
nsAutoString sibGroup;
|
|
|
|
PRBool sibChecked;
|
|
|
|
|
2000-02-22 01:50:48 +00:00
|
|
|
// get the first sibling in this menu popup. This frame may be it, and if we're
|
|
|
|
// being called at creation time, this frame isn't yet in the parent's child list.
|
|
|
|
// All I'm saying is that this may fail, but it's most likely alright.
|
2004-01-09 14:20:53 +00:00
|
|
|
nsIFrame* sib = GetParent()->GetFirstChild(nsnull);
|
|
|
|
if ( !sib )
|
2000-02-22 01:50:48 +00:00
|
|
|
return;
|
1999-10-17 21:37:37 +00:00
|
|
|
|
2001-06-16 23:35:43 +00:00
|
|
|
// XXX - egcs 1.1.2 & gcc 2.95.x -Oy builds, where y > 1,
|
|
|
|
// are known to break if we declare nsCOMPtrs inside this loop.
|
|
|
|
// Moving the declaration out of the loop works around this problem.
|
|
|
|
// http://bugzilla.mozilla.org/show_bug.cgi?id=80988
|
|
|
|
|
1999-10-17 21:37:37 +00:00
|
|
|
do {
|
|
|
|
if (NS_FAILED(sib->QueryInterface(NS_GET_IID(nsIMenuFrame),
|
|
|
|
(void **)&sibMenu)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sibMenu != (nsIMenuFrame *)this && // correct way to check?
|
|
|
|
(sibMenu->GetMenuType(sibType), sibType == eMenuType_Radio) &&
|
|
|
|
(sibMenu->MenuIsChecked(sibChecked), sibChecked) &&
|
|
|
|
(sibMenu->GetRadioGroupName(sibGroup), sibGroup == mGroupName)) {
|
|
|
|
|
|
|
|
/* uncheck the old item */
|
2003-08-04 12:39:51 +00:00
|
|
|
sib->GetContent()->UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::checked,
|
|
|
|
PR_TRUE);
|
1999-10-17 21:37:37 +00:00
|
|
|
|
|
|
|
/* XXX in DEBUG, check to make sure that there aren't two checked items */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
} while ((sib = sib->GetNextSibling()) != nsnull);
|
1999-10-17 21:37:37 +00:00
|
|
|
|
1999-10-15 21:13:24 +00:00
|
|
|
}
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
void
|
2001-10-11 03:03:42 +00:00
|
|
|
nsMenuFrame::BuildAcceleratorText()
|
1999-07-31 01:43:33 +00:00
|
|
|
{
|
2000-03-28 00:41:33 +00:00
|
|
|
nsAutoString accelText;
|
2001-10-11 03:03:42 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
if ((GetStateBits() & NS_STATE_ACCELTEXT_IS_DERIVED) == 0) {
|
2001-10-11 03:03:42 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsXULAtoms::acceltext, accelText);
|
|
|
|
if (!accelText.IsEmpty())
|
|
|
|
return;
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
2001-10-11 03:03:42 +00:00
|
|
|
// accelText is definitely empty here.
|
|
|
|
|
|
|
|
// Now we're going to compute the accelerator text, so remember that we did.
|
2003-08-04 12:39:51 +00:00
|
|
|
AddStateBits(NS_STATE_ACCELTEXT_IS_DERIVED);
|
2001-10-11 03:03:42 +00:00
|
|
|
|
|
|
|
// If anything below fails, just leave the accelerator text blank.
|
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsXULAtoms::acceltext, PR_FALSE);
|
1999-07-31 01:43:33 +00:00
|
|
|
|
|
|
|
// See if we have a key node and use that instead.
|
2000-03-28 00:41:33 +00:00
|
|
|
nsAutoString keyValue;
|
2001-08-17 08:14:14 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsXULAtoms::key, keyValue);
|
2000-07-28 21:48:08 +00:00
|
|
|
if (keyValue.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2003-03-26 07:41:30 +00:00
|
|
|
// Turn the document into a DOM document so we can use getElementById
|
2003-07-28 21:25:13 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(mContent->GetDocument()));
|
2003-03-26 07:41:30 +00:00
|
|
|
if (!domDocument)
|
1999-07-31 01:43:33 +00:00
|
|
|
return;
|
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> keyDOMElement;
|
2003-03-26 07:41:30 +00:00
|
|
|
domDocument->GetElementById(keyValue, getter_AddRefs(keyDOMElement));
|
2001-01-09 01:28:36 +00:00
|
|
|
if (!keyDOMElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> keyElement(do_QueryInterface(keyDOMElement));
|
1999-07-31 01:43:33 +00:00
|
|
|
if (!keyElement)
|
|
|
|
return;
|
2000-08-17 00:09:16 +00:00
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
// get the string to display as accelerator text
|
|
|
|
// check the key element's attributes in this order:
|
|
|
|
// |keytext|, |key|, |keycode|
|
|
|
|
nsAutoString accelString;
|
2001-08-17 08:14:14 +00:00
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsXULAtoms::keytext, accelString);
|
2001-01-09 01:28:36 +00:00
|
|
|
|
|
|
|
if (accelString.IsEmpty()) {
|
2001-08-17 08:14:14 +00:00
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsXULAtoms::key, accelString);
|
2001-01-09 01:28:36 +00:00
|
|
|
|
|
|
|
if (!accelString.IsEmpty()) {
|
2001-12-17 07:14:49 +00:00
|
|
|
ToUpperCase(accelString);
|
2001-01-09 01:28:36 +00:00
|
|
|
} else {
|
|
|
|
nsAutoString keyCode;
|
2001-08-17 08:14:14 +00:00
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsXULAtoms::keycode, keyCode);
|
2001-12-17 07:14:49 +00:00
|
|
|
ToUpperCase(keyCode);
|
2001-01-09 01:28:36 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
|
|
|
|
if (NS_SUCCEEDED(rv) && bundleService) {
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
rv = bundleService->CreateBundle("chrome://global/locale/keys.properties",
|
|
|
|
getter_AddRefs(bundle));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && bundle) {
|
|
|
|
nsXPIDLString keyName;
|
2001-06-30 11:02:25 +00:00
|
|
|
rv = bundle->GetStringFromName(keyCode.get(), getter_Copies(keyName));
|
2001-01-09 01:28:36 +00:00
|
|
|
if (keyName)
|
|
|
|
accelString = keyName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nothing usable found, bail
|
|
|
|
if (accelString.IsEmpty())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRInt32 accelKey = 0;
|
2000-08-17 00:09:16 +00:00
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
if (!accelKey)
|
2000-08-17 00:09:16 +00:00
|
|
|
{
|
|
|
|
// Compiled-in defaults, in case we can't get LookAndFeel --
|
|
|
|
// command for mac, control for all other platforms.
|
2001-11-10 23:30:13 +00:00
|
|
|
#if defined(XP_MAC) || defined(XP_MACOSX)
|
2000-08-17 00:09:16 +00:00
|
|
|
accelKey = nsIDOMKeyEvent::DOM_VK_META;
|
|
|
|
#else
|
|
|
|
accelKey = nsIDOMKeyEvent::DOM_VK_CONTROL;
|
1999-12-08 04:52:42 +00:00
|
|
|
#endif
|
1999-07-31 01:43:33 +00:00
|
|
|
|
2000-08-17 00:09:16 +00:00
|
|
|
// Get the accelerator key value from prefs, overriding the default:
|
2004-04-29 23:34:19 +00:00
|
|
|
accelKey = nsContentUtils::GetIntPref("ui.key.accelKey", accelKey);
|
2000-09-22 05:02:20 +00:00
|
|
|
}
|
2000-08-17 00:09:16 +00:00
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
nsAutoString modifiers;
|
2001-08-17 08:14:14 +00:00
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsXULAtoms::modifiers, modifiers);
|
2000-09-22 05:02:20 +00:00
|
|
|
|
2001-09-29 08:28:41 +00:00
|
|
|
char* str = ToNewCString(modifiers);
|
2000-09-22 05:02:20 +00:00
|
|
|
char* newStr;
|
2001-01-09 01:28:36 +00:00
|
|
|
char* token = nsCRT::strtok(str, ", ", &newStr);
|
|
|
|
while (token) {
|
2000-09-22 05:02:20 +00:00
|
|
|
|
|
|
|
if (PL_strcmp(token, "shift") == 0)
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += *gShiftText;
|
2000-09-22 05:02:20 +00:00
|
|
|
else if (PL_strcmp(token, "alt") == 0)
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += *gAltText;
|
2000-09-22 05:02:20 +00:00
|
|
|
else if (PL_strcmp(token, "meta") == 0)
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += *gMetaText;
|
2000-09-22 05:02:20 +00:00
|
|
|
else if (PL_strcmp(token, "control") == 0)
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += *gControlText;
|
2000-09-22 05:02:20 +00:00
|
|
|
else if (PL_strcmp(token, "accel") == 0) {
|
|
|
|
switch (accelKey)
|
|
|
|
{
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META:
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += *gMetaText;
|
2000-09-22 05:02:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT:
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += *gAltText;
|
2000-09-22 05:02:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL:
|
|
|
|
default:
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += *gControlText;
|
2000-09-22 05:02:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += *gModifierSeparator;
|
2001-01-09 01:28:36 +00:00
|
|
|
|
|
|
|
token = nsCRT::strtok(newStr, ", ", &newStr);
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
|
|
|
|
2000-09-22 05:02:20 +00:00
|
|
|
nsMemory::Free(str);
|
|
|
|
|
2001-10-11 03:03:42 +00:00
|
|
|
accelText += accelString;
|
|
|
|
|
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsXULAtoms::acceltext, accelText, PR_FALSE);
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-09-26 23:21:59 +00:00
|
|
|
nsMenuFrame::Execute(nsGUIEvent *aEvent)
|
1999-07-31 01:43:33 +00:00
|
|
|
{
|
2002-11-18 14:01:20 +00:00
|
|
|
// flip "checked" state if we're a checkbox menu, or an un-checked radio menu
|
|
|
|
if (mType == eMenuType_Checkbox || (mType == eMenuType_Radio && !mChecked)) {
|
|
|
|
nsAutoString value;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::autocheck, value);
|
2004-04-30 13:23:43 +00:00
|
|
|
if (!value.EqualsLiteral("false")) {
|
2002-10-08 18:02:34 +00:00
|
|
|
if (mChecked) {
|
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::checked,
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::checked, NS_LITERAL_STRING("true"),
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
|
|
|
/* the AttributeChanged code will update all the internal state */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-01 04:43:45 +00:00
|
|
|
// Temporarily disable rollup events on this menu. This is
|
|
|
|
// to suppress this menu getting removed in the case where
|
|
|
|
// the oncommand handler opens a dialog, etc.
|
2001-09-10 07:34:54 +00:00
|
|
|
if ( nsMenuFrame::sDismissalListener ) {
|
|
|
|
nsMenuFrame::sDismissalListener->EnableListener(PR_FALSE);
|
1999-10-01 04:43:45 +00:00
|
|
|
}
|
|
|
|
|
1999-08-13 23:49:53 +00:00
|
|
|
// Get our own content node and hold on to it to keep it from going away.
|
2003-06-21 00:15:41 +00:00
|
|
|
nsCOMPtr<nsIContent> content = mContent;
|
1999-10-01 04:43:45 +00:00
|
|
|
|
2000-10-02 23:23:55 +00:00
|
|
|
// Deselect ourselves.
|
|
|
|
SelectMenu(PR_FALSE);
|
|
|
|
|
|
|
|
// Now hide all of the open menus.
|
2003-01-20 11:58:30 +00:00
|
|
|
if (mMenuParent) {
|
1999-08-12 20:45:47 +00:00
|
|
|
mMenuParent->HideChain();
|
|
|
|
|
2003-01-20 11:58:30 +00:00
|
|
|
// Since menu was not dismissed via click outside menu
|
|
|
|
// we don't want to keep track of this rollup.
|
|
|
|
// Otherwise, we keep track so that the same click
|
|
|
|
// won't both dismiss and then reopen a menu.
|
|
|
|
mMenuParent->ClearRecentlyRolledUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2004-01-12 08:25:18 +00:00
|
|
|
nsMouseEvent event(NS_XUL_COMMAND);
|
2002-09-26 23:21:59 +00:00
|
|
|
if (aEvent && (aEvent->eventStructType == NS_MOUSE_EVENT ||
|
|
|
|
aEvent->eventStructType == NS_KEY_EVENT ||
|
|
|
|
aEvent->eventStructType == NS_ACCESSIBLE_EVENT)) {
|
|
|
|
|
|
|
|
event.isShift = NS_STATIC_CAST(nsInputEvent *, aEvent)->isShift;
|
|
|
|
event.isControl = NS_STATIC_CAST(nsInputEvent *, aEvent)->isControl;
|
|
|
|
event.isAlt = NS_STATIC_CAST(nsInputEvent *, aEvent)->isAlt;
|
|
|
|
event.isMeta = NS_STATIC_CAST(nsInputEvent *, aEvent)->isMeta;
|
|
|
|
}
|
2004-01-12 08:25:18 +00:00
|
|
|
|
2000-10-18 17:36:54 +00:00
|
|
|
// The order of the nsIViewManager and nsIPresShell COM pointers is
|
|
|
|
// important below. We want the pres shell to get released before the
|
|
|
|
// associated view manager on exit from this function.
|
|
|
|
// See bug 54233.
|
2003-08-04 12:39:51 +00:00
|
|
|
nsCOMPtr<nsIViewManager> kungFuDeathGrip = mPresContext->GetViewManager();
|
2003-12-21 05:36:36 +00:00
|
|
|
// keep a reference so we can safely use this after dispatching the DOM event
|
|
|
|
nsCOMPtr<nsIPresShell> shell = mPresContext->GetPresShell();
|
2000-09-03 06:22:21 +00:00
|
|
|
nsIFrame* me = this;
|
2003-12-21 05:36:36 +00:00
|
|
|
if (shell) {
|
2003-03-25 03:15:37 +00:00
|
|
|
shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
2003-12-21 05:36:36 +00:00
|
|
|
// shell may no longer be alive, don't use it here unless you keep a ref
|
2000-06-29 02:02:43 +00:00
|
|
|
}
|
1999-08-12 20:45:47 +00:00
|
|
|
|
1999-08-13 23:49:53 +00:00
|
|
|
// XXX HACK. Just gracefully exit if the node has been removed, e.g., window.close()
|
|
|
|
// was executed.
|
2000-09-03 06:22:21 +00:00
|
|
|
nsIFrame* primary = nsnull;
|
2000-10-18 17:36:54 +00:00
|
|
|
if (shell) shell->GetPrimaryFrameFor(content, &primary);
|
|
|
|
|
1999-08-12 20:45:47 +00:00
|
|
|
// Now properly close them all up.
|
2003-07-28 21:25:13 +00:00
|
|
|
if (content->GetDocument() && // <-- HACK IS HERE. ICK.
|
|
|
|
(primary == me) && mMenuParent)
|
1999-08-12 20:45:47 +00:00
|
|
|
mMenuParent->DismissChain();
|
2000-09-03 06:22:21 +00:00
|
|
|
// END HACK
|
1999-10-01 04:43:45 +00:00
|
|
|
|
|
|
|
// Re-enable rollup events on this menu.
|
2001-09-10 07:34:54 +00:00
|
|
|
if ( nsMenuFrame::sDismissalListener ) {
|
|
|
|
nsMenuFrame::sDismissalListener->EnableListener(PR_TRUE);
|
1999-10-01 04:43:45 +00:00
|
|
|
}
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMenuFrame::OnCreate()
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2004-01-12 08:25:18 +00:00
|
|
|
nsMouseEvent event(NS_XUL_POPUP_SHOWING);
|
1999-09-08 03:51:41 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsIPresShell *shell = mPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
2000-06-29 02:02:43 +00:00
|
|
|
if (child) {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(child, &event, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
|
|
|
}
|
2003-12-21 05:36:36 +00:00
|
|
|
// shell may no longer be alive, don't use it here unless you keep a ref
|
2000-06-29 02:02:43 +00:00
|
|
|
}
|
1999-09-08 03:51:41 +00:00
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
|
|
|
|
return PR_FALSE;
|
2001-03-21 08:15:49 +00:00
|
|
|
|
|
|
|
// The menu is going to show, and the create handler has executed.
|
|
|
|
// We should now walk all of our menu item children, checking to see if any
|
|
|
|
// of them has a command attribute. If so, then several attributes must
|
|
|
|
// potentially be updated.
|
|
|
|
if (child) {
|
2003-07-28 21:25:13 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(child->GetDocument()));
|
2001-03-21 08:15:49 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 count = child->GetChildCount();
|
|
|
|
for (PRUint32 i = 0; i < count; i++) {
|
|
|
|
nsIContent *grandChild = child->GetChildAt(i);
|
2003-11-19 01:20:56 +00:00
|
|
|
|
|
|
|
if (grandChild->Tag() == nsXULAtoms::menuitem) {
|
2001-03-21 08:15:49 +00:00
|
|
|
// See if we have a command attribute.
|
|
|
|
nsAutoString command;
|
2001-08-17 08:14:14 +00:00
|
|
|
grandChild->GetAttr(kNameSpaceID_None, nsXULAtoms::command, command);
|
2001-03-21 08:15:49 +00:00
|
|
|
if (!command.IsEmpty()) {
|
|
|
|
// We do! Look it up in our document
|
|
|
|
nsCOMPtr<nsIDOMElement> commandElt;
|
|
|
|
domDoc->GetElementById(command, getter_AddRefs(commandElt));
|
|
|
|
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
|
|
|
|
|
2001-03-23 02:56:24 +00:00
|
|
|
if ( commandContent ) {
|
2001-04-29 02:57:29 +00:00
|
|
|
nsAutoString commandAttr, menuAttr;
|
2001-08-17 08:14:14 +00:00
|
|
|
commandContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, commandAttr);
|
|
|
|
grandChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, menuAttr);
|
2001-04-29 02:57:29 +00:00
|
|
|
if (!commandAttr.Equals(menuAttr)) {
|
2001-03-23 02:56:24 +00:00
|
|
|
// The menu's disabled state needs to be updated to match the command.
|
2001-04-29 02:57:29 +00:00
|
|
|
if (commandAttr.IsEmpty())
|
2001-08-17 08:14:14 +00:00
|
|
|
grandChild->UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, PR_TRUE);
|
|
|
|
else grandChild->SetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, commandAttr, PR_TRUE);
|
2001-03-23 02:56:24 +00:00
|
|
|
}
|
|
|
|
|
2002-02-13 04:14:26 +00:00
|
|
|
// The menu's label, accesskey, and checked states need to be updated to match the command.
|
2001-04-29 02:57:29 +00:00
|
|
|
// Note that (unlike the disabled state) if the command has *no* label for either, we
|
2001-04-28 06:38:23 +00:00
|
|
|
// assume the menu is supplying its own.
|
2001-08-17 08:14:14 +00:00
|
|
|
commandContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::checked, commandAttr);
|
|
|
|
grandChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::checked, menuAttr);
|
2001-04-29 02:57:29 +00:00
|
|
|
if (!commandAttr.Equals(menuAttr)) {
|
|
|
|
if (!commandAttr.IsEmpty())
|
2001-08-17 08:14:14 +00:00
|
|
|
grandChild->SetAttr(kNameSpaceID_None, nsHTMLAtoms::checked, commandAttr, PR_TRUE);
|
2001-04-28 06:38:23 +00:00
|
|
|
}
|
2002-02-13 04:14:26 +00:00
|
|
|
|
|
|
|
commandContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::accesskey, commandAttr);
|
|
|
|
grandChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::accesskey, menuAttr);
|
|
|
|
if (!commandAttr.Equals(menuAttr)) {
|
|
|
|
if (!commandAttr.IsEmpty())
|
|
|
|
grandChild->SetAttr(kNameSpaceID_None, nsHTMLAtoms::accesskey, commandAttr, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2001-08-17 08:14:14 +00:00
|
|
|
commandContent->GetAttr(kNameSpaceID_None, nsXULAtoms::label, commandAttr);
|
|
|
|
grandChild->GetAttr(kNameSpaceID_None, nsXULAtoms::label, menuAttr);
|
2001-04-29 02:57:29 +00:00
|
|
|
if (!commandAttr.Equals(menuAttr)) {
|
|
|
|
if (!commandAttr.IsEmpty())
|
2001-08-17 08:14:14 +00:00
|
|
|
grandChild->SetAttr(kNameSpaceID_None, nsXULAtoms::label, commandAttr, PR_TRUE);
|
2001-03-23 02:56:24 +00:00
|
|
|
}
|
2001-03-21 08:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2001-08-06 21:49:35 +00:00
|
|
|
PRBool
|
|
|
|
nsMenuFrame::OnCreated()
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2004-01-12 08:25:18 +00:00
|
|
|
nsMouseEvent event(NS_XUL_POPUP_SHOWN);
|
2001-08-06 21:49:35 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIPresShell *shell = mPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
2001-08-06 21:49:35 +00:00
|
|
|
if (child) {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(child, &event, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
|
|
|
}
|
2003-12-21 05:36:36 +00:00
|
|
|
// shell may no longer be alive, don't use it here unless you keep a ref
|
2001-08-06 21:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
|
|
|
|
return PR_FALSE;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
PRBool
|
|
|
|
nsMenuFrame::OnDestroy()
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2004-01-12 08:25:18 +00:00
|
|
|
nsMouseEvent event(NS_XUL_POPUP_HIDING);
|
2001-08-06 21:49:35 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIPresShell *shell = mPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
2001-08-06 21:49:35 +00:00
|
|
|
if (child) {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(child, &event, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
|
|
|
}
|
2003-12-21 05:36:36 +00:00
|
|
|
// shell may no longer be alive, don't use it here unless you keep a ref
|
2001-08-06 21:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
|
|
|
|
return PR_FALSE;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMenuFrame::OnDestroyed()
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2004-01-12 08:25:18 +00:00
|
|
|
nsMouseEvent event(NS_XUL_POPUP_HIDDEN);
|
1999-09-08 03:51:41 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIPresShell *shell = mPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
2000-06-29 02:02:43 +00:00
|
|
|
if (child) {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(child, &event, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
|
|
|
}
|
2003-12-21 05:36:36 +00:00
|
|
|
// shell may no longer be alive, don't use it here unless you keep a ref
|
2000-06-29 02:02:43 +00:00
|
|
|
}
|
1999-09-08 03:51:41 +00:00
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
|
|
|
|
return PR_FALSE;
|
|
|
|
return PR_TRUE;
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:58:25 +00:00
|
|
|
nsMenuFrame::RemoveFrame(nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
1999-07-31 11:29:03 +00:00
|
|
|
{
|
1999-08-19 03:51:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-08-06 19:12:23 +00:00
|
|
|
if (mPopupFrames.ContainsFrame(aOldFrame)) {
|
1999-07-31 11:29:03 +00:00
|
|
|
// Go ahead and remove this frame.
|
2005-02-07 01:58:25 +00:00
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
mPopupFrames.DestroyFrame(presContext, aOldFrame);
|
|
|
|
nsBoxLayoutState state(presContext);
|
2000-03-31 07:02:06 +00:00
|
|
|
rv = MarkDirtyChildren(state);
|
1999-08-19 03:51:25 +00:00
|
|
|
} else {
|
2005-02-07 01:58:25 +00:00
|
|
|
rv = nsBoxFrame::RemoveFrame(aListName, aOldFrame);
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
1999-08-19 03:51:25 +00:00
|
|
|
return rv;
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:58:25 +00:00
|
|
|
nsMenuFrame::InsertFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
1999-07-31 11:29:03 +00:00
|
|
|
{
|
1999-08-19 03:51:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2002-08-06 12:48:28 +00:00
|
|
|
nsIMenuParent *menuPar;
|
|
|
|
if (aFrameList && NS_SUCCEEDED(CallQueryInterface(aFrameList, &menuPar))) {
|
2004-09-28 18:37:50 +00:00
|
|
|
NS_ASSERTION(aFrameList->IsBoxFrame(),"Popup is not a box!!!");
|
1999-07-31 11:29:03 +00:00
|
|
|
mPopupFrames.InsertFrames(nsnull, nsnull, aFrameList);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
2005-02-07 01:58:25 +00:00
|
|
|
nsBoxLayoutState state(GetPresContext());
|
2004-06-19 09:07:47 +00:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2000-03-31 07:02:06 +00:00
|
|
|
SetDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG);
|
2004-06-19 09:07:47 +00:00
|
|
|
#endif
|
2000-03-31 07:02:06 +00:00
|
|
|
rv = MarkDirtyChildren(state);
|
1999-08-19 03:51:25 +00:00
|
|
|
} else {
|
2005-02-07 01:58:25 +00:00
|
|
|
rv = nsBoxFrame::InsertFrames(aListName, aPrevFrame, aFrameList);
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
1999-08-19 03:51:25 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:58:25 +00:00
|
|
|
nsMenuFrame::AppendFrames(nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
1999-07-31 11:29:03 +00:00
|
|
|
{
|
1999-08-04 21:36:30 +00:00
|
|
|
if (!aFrameList)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-08-19 03:51:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2002-08-06 12:48:28 +00:00
|
|
|
nsIMenuParent *menuPar;
|
|
|
|
if (aFrameList && NS_SUCCEEDED(CallQueryInterface(aFrameList, &menuPar))) {
|
2004-09-28 18:37:50 +00:00
|
|
|
NS_ASSERTION(aFrameList->IsBoxFrame(),"Popup is not a box!!!");
|
2000-05-15 04:12:31 +00:00
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
mPopupFrames.AppendFrames(nsnull, aFrameList);
|
2005-02-07 01:58:25 +00:00
|
|
|
nsBoxLayoutState state(GetPresContext());
|
2004-06-19 09:07:47 +00:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2000-03-31 07:02:06 +00:00
|
|
|
SetDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG);
|
2004-06-19 09:07:47 +00:00
|
|
|
#endif
|
2000-03-31 07:02:06 +00:00
|
|
|
rv = MarkDirtyChildren(state);
|
1999-08-19 03:51:25 +00:00
|
|
|
} else {
|
2005-02-07 01:58:25 +00:00
|
|
|
rv = nsBoxFrame::AppendFrames(aListName, aFrameList);
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
1999-08-19 03:51:25 +00:00
|
|
|
|
|
|
|
return rv;
|
1999-07-31 18:39:47 +00:00
|
|
|
}
|
1999-09-21 01:03:00 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::UpdateDismissalListener(nsIMenuParent* aMenuParent)
|
|
|
|
{
|
2001-09-10 07:34:54 +00:00
|
|
|
if (!nsMenuFrame::sDismissalListener) {
|
1999-09-25 03:39:35 +00:00
|
|
|
if (!aMenuParent)
|
|
|
|
return;
|
1999-09-21 01:03:00 +00:00
|
|
|
// Create the listener and attach it to the outermost window.
|
|
|
|
aMenuParent->CreateDismissalListener();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the menu dismissal listener knows what the current
|
|
|
|
// innermost menu popup frame is.
|
2001-09-10 07:34:54 +00:00
|
|
|
nsMenuFrame::sDismissalListener->SetCurrentMenuParent(aMenuParent);
|
1999-09-21 01:03:00 +00:00
|
|
|
}
|
2000-02-25 08:37:49 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::GetPrefSize(nsBoxLayoutState& aState, nsSize& aSize)
|
|
|
|
{
|
|
|
|
aSize.width = 0;
|
|
|
|
aSize.height = 0;
|
|
|
|
nsresult rv = nsBoxFrame::GetPrefSize(aState, aSize);
|
|
|
|
|
2002-03-17 23:41:22 +00:00
|
|
|
if (IsSizedToPopup(mContent, PR_FALSE)) {
|
2000-11-28 08:52:36 +00:00
|
|
|
nsSize tmpSize(-1,0);
|
|
|
|
nsIBox::AddCSSPrefSize(aState, this, tmpSize);
|
|
|
|
nscoord flex;
|
|
|
|
GetFlex(aState, flex);
|
|
|
|
|
|
|
|
if (tmpSize.width == -1 && flex==0) {
|
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (!frame) {
|
|
|
|
MarkAsGenerated();
|
|
|
|
frame = mPopupFrames.FirstChild();
|
|
|
|
// No child - just return
|
|
|
|
if (!frame) return NS_OK;
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
2000-11-28 08:52:36 +00:00
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
NS_ASSERTION(frame->IsBoxFrame(), "popupChild is not box!!");
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2004-09-28 18:37:50 +00:00
|
|
|
frame->GetPrefSize(aState, tmpSize);
|
2000-11-28 08:52:36 +00:00
|
|
|
aSize.width = tmpSize.width;
|
2002-04-16 23:51:07 +00:00
|
|
|
|
|
|
|
// We now need to ensure that aSize is within the min size - max size range.
|
|
|
|
// If we are using sizetopopup="always", we know the min size will be the same
|
|
|
|
// as the pref size, and do not need to call GetMinSize (in fact, doing so will
|
|
|
|
// result in infinite recursion).
|
|
|
|
|
|
|
|
nsSize minSize, maxSize;
|
|
|
|
if (IsSizedToPopup(mContent, PR_TRUE))
|
|
|
|
minSize = aSize;
|
|
|
|
else
|
|
|
|
GetMinSize(aState, minSize);
|
|
|
|
|
|
|
|
GetMaxSize(aState, maxSize);
|
|
|
|
BoundsCheck(minSize, aSize, maxSize);
|
2000-11-28 08:52:36 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-08-17 09:15:51 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::GetActiveChild(nsIDOMElement** aResult)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
nsMenuPopupFrame* menuPopup = (nsMenuPopupFrame*)frame;
|
|
|
|
if (!frame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIMenuFrame* menuFrame;
|
|
|
|
menuPopup->GetCurrentMenuItem(&menuFrame);
|
|
|
|
|
|
|
|
if (!menuFrame) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* f;
|
2001-01-04 20:44:42 +00:00
|
|
|
menuFrame->QueryInterface(NS_GET_IID(nsIFrame), (void**)&f);
|
2003-08-04 12:39:51 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(f->GetContent()));
|
2000-08-17 09:15:51 +00:00
|
|
|
*aResult = elt;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::SetActiveChild(nsIDOMElement* aChild)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
nsMenuPopupFrame* menuPopup = (nsMenuPopupFrame*)frame;
|
|
|
|
if (!frame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-08-24 03:58:42 +00:00
|
|
|
if (!aChild) {
|
|
|
|
// Remove the current selection
|
|
|
|
menuPopup->SetCurrentMenuItem(nsnull);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-17 09:15:51 +00:00
|
|
|
nsCOMPtr<nsIContent> child(do_QueryInterface(aChild));
|
|
|
|
|
|
|
|
nsIFrame* kid;
|
2003-12-21 05:36:36 +00:00
|
|
|
mPresContext->PresShell()->GetPrimaryFrameFor(child, &kid);
|
2000-08-17 09:15:51 +00:00
|
|
|
if (!kid)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsIMenuFrame> menuFrame(do_QueryInterface(kid));
|
|
|
|
if (!menuFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
menuPopup->SetCurrentMenuItem(menuFrame);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-06 02:44:43 +00:00
|
|
|
nsIScrollableView* nsMenuFrame::GetScrollableView()
|
2000-12-09 07:28:19 +00:00
|
|
|
{
|
|
|
|
if (!mPopupFrames.FirstChild())
|
2004-09-06 02:44:43 +00:00
|
|
|
return nsnull;
|
2000-12-09 07:28:19 +00:00
|
|
|
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*) mPopupFrames.FirstChild();
|
2004-01-09 14:20:53 +00:00
|
|
|
nsIFrame* childFrame = popup->GetFirstChild(nsnull);
|
2000-12-09 07:28:19 +00:00
|
|
|
if (childFrame) {
|
2004-09-06 02:44:43 +00:00
|
|
|
return popup->GetScrollableView(childFrame);
|
2000-12-09 07:28:19 +00:00
|
|
|
}
|
2004-09-06 02:44:43 +00:00
|
|
|
return nsnull;
|
2000-12-09 07:28:19 +00:00
|
|
|
}
|
2000-08-17 09:15:51 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
/* Need to figure out what this does.
|
2000-02-25 08:37:49 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsMenuFrame::GetBoxInfo(nsPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize)
|
2000-02-25 08:37:49 +00:00
|
|
|
{
|
|
|
|
nsresult rv = nsBoxFrame::GetBoxInfo(aPresContext, aReflowState, aSize);
|
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menulist(do_QueryInterface(mContent));
|
|
|
|
if (menulist) {
|
2000-03-31 07:02:06 +00:00
|
|
|
nsCalculatedBoxInfo boxInfo(this);
|
2000-02-25 08:37:49 +00:00
|
|
|
boxInfo.prefSize.width = NS_UNCONSTRAINEDSIZE;
|
|
|
|
boxInfo.prefSize.height = NS_UNCONSTRAINEDSIZE;
|
|
|
|
boxInfo.flex = 0;
|
|
|
|
GetRedefinedMinPrefMax(aPresContext, this, boxInfo);
|
|
|
|
if (boxInfo.prefSize.width == NS_UNCONSTRAINEDSIZE &&
|
|
|
|
boxInfo.prefSize.height == NS_UNCONSTRAINEDSIZE &&
|
|
|
|
boxInfo.flex == 0) {
|
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (!frame) {
|
|
|
|
MarkAsGenerated();
|
|
|
|
frame = mPopupFrames.FirstChild();
|
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
nsCalculatedBoxInfo childInfo(frame);
|
2004-09-28 18:37:50 +00:00
|
|
|
frame->GetBoxInfo(aPresContext, aReflowState, childInfo);
|
2000-02-25 08:37:49 +00:00
|
|
|
GetRedefinedMinPrefMax(aPresContext, this, childInfo);
|
|
|
|
aSize.prefSize.width = childInfo.prefSize.width;
|
|
|
|
}
|
2000-03-13 10:20:34 +00:00
|
|
|
|
2000-03-17 11:27:01 +00:00
|
|
|
// This retrieval guarantess that the selectedItem will
|
|
|
|
// be set before we lay out.
|
2000-03-13 10:20:34 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
menulist->GetSelectedItem(getter_AddRefs(element));
|
2000-02-25 08:37:49 +00:00
|
|
|
}
|
|
|
|
return rv;
|
2000-02-25 23:45:53 +00:00
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
*/
|
2000-02-25 23:45:53 +00:00
|
|
|
|