1999-09-17 20:12:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
1999-07-18 06:36:37 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1999-07-18 06:36:37 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-07-18 06:36:37 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2000-03-21 13:24:48 +00:00
|
|
|
* Original Author: David W. Hyatt (hyatt@netscape.com)
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* Contributor(s):
|
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>
|
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"
|
|
|
|
#include "nsIPresContext.h"
|
1999-10-14 23:59:18 +00:00
|
|
|
#include "nsIPresShell.h"
|
1999-07-18 06:36:37 +00:00
|
|
|
#include "nsIStyleContext.h"
|
1999-07-31 01:43:33 +00:00
|
|
|
#include "nsIReflowCommand.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 "nsIDOMXULDocument.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-04-06 22:32:39 +00:00
|
|
|
#include "nsIXBLBinding.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"
|
|
|
|
#include "nsIPref.h"
|
2000-12-09 07:28:19 +00:00
|
|
|
#include "nsIScrollableView.h"
|
2001-01-09 01:28:36 +00:00
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsIStringBundle.h"
|
2000-08-17 00:09:16 +00:00
|
|
|
|
2000-07-28 22:09:45 +00:00
|
|
|
#define NS_MENU_POPUP_LIST_INDEX 0
|
1999-07-18 06:48:03 +00:00
|
|
|
|
2001-03-29 03:33:09 +00:00
|
|
|
#ifdef XP_PC
|
|
|
|
#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
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
nsMenuDismissalListener* nsMenuFrame::mDismissalListener = nsnull;
|
|
|
|
|
2000-01-21 21:56:09 +00:00
|
|
|
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
|
|
|
|
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),
|
2000-08-03 00:22:36 +00:00
|
|
|
mLastPref(-1,-1),
|
|
|
|
mFrameConstructor(nsnull)
|
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);
|
2000-05-26 22:45:26 +00:00
|
|
|
nsIFrame* currFrame = (nsIFrame*)aParent;
|
|
|
|
while (!mMenuParent && currFrame) {
|
|
|
|
// Set our menu parent.
|
|
|
|
nsCOMPtr<nsIMenuParent> menuparent(do_QueryInterface(currFrame));
|
|
|
|
mMenuParent = menuparent.get();
|
|
|
|
|
|
|
|
currFrame->GetParent(&currFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::Init(nsIPresContext* aPresContext,
|
1999-07-21 07:42:16 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
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.
|
|
|
|
nsCOMPtr<nsIMenuParent> menuparent(do_QueryInterface(currFrame));
|
|
|
|
mMenuParent = menuparent.get();
|
|
|
|
|
|
|
|
currFrame->GetParent(&currFrame);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
nsAutoString accelString;
|
|
|
|
BuildAcceleratorText(accelString);
|
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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.
|
1999-07-18 06:41:41 +00:00
|
|
|
NS_IMETHODIMP
|
2000-01-22 01:16:50 +00:00
|
|
|
nsMenuFrame::FirstChild(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame** aFirstChild) const
|
1999-07-18 06:41:41 +00:00
|
|
|
{
|
|
|
|
if (nsLayoutAtoms::popupList == aListName) {
|
|
|
|
*aFirstChild = mPopupFrames.FirstChild();
|
|
|
|
} else {
|
2000-01-22 01:16:50 +00:00
|
|
|
nsBoxFrame::FirstChild(aPresContext, aListName, aFirstChild);
|
1999-07-18 06:41:41 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-18 06:44:03 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::SetInitialChildList(nsIPresContext* 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) {
|
2000-08-06 08:11:05 +00:00
|
|
|
nsCOMPtr<nsIMenuParent> menuPar(do_QueryInterface(frame));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
frame->GetNextSibling(&frame);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::GetAdditionalChildListName(PRInt32 aIndex,
|
|
|
|
nsIAtom** aListName) const
|
|
|
|
{
|
2000-07-28 22:09:45 +00:00
|
|
|
NS_PRECONDITION(nsnull != aListName, "null OUT parameter pointer");
|
|
|
|
|
|
|
|
*aListName = nsnull;
|
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) {
|
|
|
|
*aListName = nsLayoutAtoms::popupList;
|
|
|
|
NS_ADDREF(*aListName);
|
|
|
|
}
|
2000-08-03 00:22:36 +00:00
|
|
|
#endif
|
2000-07-28 22:09:45 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-07-18 06:48:03 +00:00
|
|
|
}
|
1999-07-18 06:52:06 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::Destroy(nsIPresContext* aPresContext)
|
1999-07-18 06:52:06 +00:00
|
|
|
{
|
2000-08-03 00:22:36 +00:00
|
|
|
// Remove our frame mappings
|
|
|
|
if (mFrameConstructor) {
|
|
|
|
nsIFrame* curFrame = mPopupFrames.FirstChild();
|
|
|
|
while (curFrame) {
|
|
|
|
mFrameConstructor->RemoveMappingsForFrameSubtree(aPresContext, curFrame, nsnull);
|
|
|
|
curFrame->GetNextSibling(&curFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2000-08-03 00:22:36 +00:00
|
|
|
|
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
|
1999-10-26 04:44:41 +00:00
|
|
|
nsMenuFrame::GetFrameForPoint(nsIPresContext* aPresContext,
|
|
|
|
const nsPoint& aPoint,
|
2000-03-31 07:02:06 +00:00
|
|
|
nsFramePaintLayer aWhichLayer,
|
1999-07-19 09:36:24 +00:00
|
|
|
nsIFrame** aFrame)
|
|
|
|
{
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
if ((aWhichLayer != NS_FRAME_PAINT_LAYER_FOREGROUND))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
// if it is not inside us or not in the layer in which we paint, fail
|
|
|
|
if (!mRect.Contains(aPoint))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-03-22 02:43:08 +00:00
|
|
|
nsresult result = nsBoxFrame::GetFrameForPoint(aPresContext, aPoint, aWhichLayer, aFrame);
|
|
|
|
if ((result != NS_OK) || (*aFrame == this)) {
|
|
|
|
return result;
|
|
|
|
}
|
1999-10-15 07:54:43 +00:00
|
|
|
nsCOMPtr<nsIContent> content;
|
2000-03-22 02:43:08 +00:00
|
|
|
(*aFrame)->GetContent(getter_AddRefs(content));
|
|
|
|
if (content) {
|
|
|
|
// This allows selective overriding for subcontent.
|
|
|
|
nsAutoString value;
|
|
|
|
content->GetAttribute(kNameSpaceID_None, nsXULAtoms::allowevents, value);
|
2001-01-09 01:28:36 +00:00
|
|
|
if (value.Equals(NS_LITERAL_STRING("true")))
|
2000-03-22 02:43:08 +00:00
|
|
|
return result;
|
1999-10-15 07:54:43 +00:00
|
|
|
}
|
2000-03-22 02:43:08 +00:00
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (disp->IsVisible()) {
|
|
|
|
*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
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::HandleEvent(nsIPresContext* 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);
|
2000-08-16 23:14:50 +00:00
|
|
|
*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;
|
|
|
|
if (keyCode == NS_VK_UP || keyCode == NS_VK_DOWN) {
|
|
|
|
if (!IsOpen())
|
|
|
|
OpenMenu(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
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;
|
2000-03-01 03:12:51 +00:00
|
|
|
Execute();
|
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-10-17 21:37:37 +00:00
|
|
|
// First, flip "checked" state if we're a checkbox menu, or
|
|
|
|
// an un-checked radio menu
|
|
|
|
if (mType == eMenuType_Checkbox ||
|
|
|
|
(mType == eMenuType_Radio && !mChecked)) {
|
2000-03-03 02:08:02 +00:00
|
|
|
if (mChecked) {
|
|
|
|
mContent->UnsetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked,
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
|
|
|
else {
|
2000-08-30 02:37:27 +00:00
|
|
|
mContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked, NS_LITERAL_STRING("true"),
|
1999-10-15 21:13:24 +00:00
|
|
|
PR_TRUE);
|
2000-03-03 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
1999-10-17 21:37:37 +00:00
|
|
|
/* the AttributeChanged code will update all the internal state */
|
1999-10-15 21:13:24 +00:00
|
|
|
}
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
// Execute the execute event handler.
|
1999-08-01 19:55:00 +00:00
|
|
|
Execute();
|
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
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsILookAndFeel> lookAndFeel(do_CreateInstance(kLookAndFeelCID));
|
|
|
|
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");
|
2000-01-21 21:56:09 +00:00
|
|
|
mOpenTimer->Init(this, menuDelay, NS_PRIORITY_HIGHEST);
|
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 {
|
|
|
|
OpenMenu(PR_TRUE);
|
|
|
|
}
|
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;
|
|
|
|
}
|
1999-07-21 07:42:16 +00:00
|
|
|
if (aActivateFlag) {
|
|
|
|
// Highlight the menu.
|
2000-08-30 02:37:27 +00:00
|
|
|
mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, NS_LITERAL_STRING("true"), PR_TRUE);
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-07-21 07:42:16 +00:00
|
|
|
// Unhighlight the menu.
|
|
|
|
mContent->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
|
|
|
}
|
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;
|
1999-09-10 08:47:12 +00:00
|
|
|
child->GetAttribute(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;
|
1999-09-10 08:47:12 +00:00
|
|
|
child->GetAttribute(kNameSpaceID_None, nsXULAtoms::menugenerated, genVal);
|
2000-03-26 10:06:21 +00:00
|
|
|
if (genVal.IsEmpty())
|
2000-08-30 02:37:27 +00:00
|
|
|
child->SetAttribute(kNameSpaceID_None, nsXULAtoms::menugenerated, NS_LITERAL_STRING("true"), PR_TRUE);
|
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
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
nsRect rect;
|
|
|
|
menuPopup->GetRect(rect);
|
|
|
|
nsIView* view = nsnull;
|
|
|
|
menuPopup->GetView(mPresContext, &view);
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
viewManager->ResizeView(view, rect.width, rect.height);
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
scrollframe->ScrollTo(mPresContext, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
viewManager->UpdateView(view, nsRect(0,0, rect.width, rect.height), NS_VMREFRESH_IMMEDIATE);
|
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kShow);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
nsIView* view = nsnull;
|
|
|
|
menuPopup->GetView(mPresContext, &view);
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
viewManager->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
|
|
viewManager->ResizeView(view, 0, 0);
|
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
|
|
|
|
nsMenuFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
1999-10-15 23:16:45 +00:00
|
|
|
PRInt32 aNameSpaceID,
|
1999-09-08 03:51:41 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
1999-09-17 20:12:02 +00:00
|
|
|
nsAutoString value;
|
|
|
|
|
1999-09-08 03:51:41 +00:00
|
|
|
if (aAttribute == nsXULAtoms::open) {
|
1999-09-17 20:12:02 +00:00
|
|
|
aChild->GetAttribute(kNameSpaceID_None, aAttribute, value);
|
2001-01-09 01:28:36 +00:00
|
|
|
if (value.Equals(NS_LITERAL_STRING("true")))
|
1999-09-08 03:51:41 +00:00
|
|
|
OpenMenuInternal(PR_TRUE);
|
2000-05-18 00:21:32 +00:00
|
|
|
else {
|
1999-09-17 20:12:02 +00:00
|
|
|
OpenMenuInternal(PR_FALSE);
|
2000-05-18 00:21:32 +00:00
|
|
|
mCreateHandlerSucceeded = PR_FALSE;
|
|
|
|
}
|
1999-10-17 21:37:37 +00:00
|
|
|
} else if (aAttribute == nsHTMLAtoms::checked) {
|
|
|
|
if (mType != eMenuType_Normal)
|
2000-01-22 01:16:50 +00:00
|
|
|
UpdateMenuSpecialState(aPresContext);
|
2000-02-22 01:50:48 +00:00
|
|
|
} else if ( aAttribute == nsHTMLAtoms::type || aAttribute == nsHTMLAtoms::name )
|
2000-01-22 01:16:50 +00:00
|
|
|
UpdateMenuType(aPresContext);
|
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)
|
|
|
|
{
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(mContent));
|
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();
|
|
|
|
|
2000-08-30 02:37:27 +00:00
|
|
|
domElement->SetAttribute(NS_LITERAL_STRING("open"), NS_LITERAL_STRING("true"));
|
1999-09-08 03:51:41 +00:00
|
|
|
}
|
2000-08-30 02:37:27 +00:00
|
|
|
else domElement->RemoveAttribute(NS_LITERAL_STRING("open"));
|
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.
|
|
|
|
if (nsMenuFrame::mDismissalListener)
|
|
|
|
nsMenuFrame::mDismissalListener->EnableListener(PR_FALSE);
|
|
|
|
|
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
|
|
|
|
1999-12-08 11:30:47 +00:00
|
|
|
nsCOMPtr<nsIContent> menuPopupContent;
|
|
|
|
menuPopup->GetContent(getter_AddRefs(menuPopupContent));
|
|
|
|
|
2000-02-25 08:37:49 +00:00
|
|
|
// Sync up the view.
|
1999-12-08 11:30:47 +00:00
|
|
|
nsAutoString popupAnchor, popupAlign;
|
|
|
|
|
|
|
|
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupanchor, popupAnchor);
|
|
|
|
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupalign, popupAlign);
|
|
|
|
|
|
|
|
if (onMenuBar) {
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAnchor.IsEmpty())
|
2001-01-09 01:28:36 +00:00
|
|
|
popupAnchor = NS_LITERAL_STRING("bottomleft");
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAlign.IsEmpty())
|
2001-01-09 01:28:36 +00:00
|
|
|
popupAlign = NS_LITERAL_STRING("topleft");
|
1999-12-08 11:30:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAnchor.IsEmpty())
|
2001-01-09 01:28:36 +00:00
|
|
|
popupAnchor = NS_LITERAL_STRING("topright");
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAlign.IsEmpty())
|
2001-01-09 01:28:36 +00:00
|
|
|
popupAlign = NS_LITERAL_STRING("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);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
shell->FlushPendingNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect curRect;
|
2000-06-26 21:00:44 +00:00
|
|
|
menuPopup->GetBounds(curRect);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
nsIView* view = nsnull;
|
|
|
|
menuPopup->GetView(mPresContext, &view);
|
|
|
|
view->SetVisibility(nsViewVisibility_kHide);
|
1999-12-08 11:30:47 +00:00
|
|
|
menuPopup->SyncViewWithFrame(mPresContext, popupAnchor, popupAlign, this, -1, -1);
|
2000-05-15 04:12:31 +00:00
|
|
|
nsRect rect;
|
2000-06-26 21:00:44 +00:00
|
|
|
menuPopup->GetBounds(rect);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
// if the height is different then reflow. It might need scrollbars force a reflow
|
|
|
|
if (curRect.height != rect.height || mLastPref.height != rect.height)
|
|
|
|
{
|
|
|
|
menuPopup->MarkDirty(state);
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
shell->FlushPendingNotifications();
|
|
|
|
}
|
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
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIMenuParent> childPopup(do_QueryInterface(frame));
|
2000-05-15 04:12:31 +00:00
|
|
|
UpdateDismissalListener(childPopup);
|
|
|
|
|
|
|
|
}
|
1999-09-25 03:39:35 +00:00
|
|
|
|
|
|
|
// Set the focus back to our view's widget.
|
|
|
|
if (nsMenuFrame::mDismissalListener)
|
|
|
|
nsMenuFrame::mDismissalListener->EnableListener(PR_TRUE);
|
|
|
|
|
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;
|
|
|
|
|
2000-07-26 23:57:24 +00:00
|
|
|
mMenuOpen = PR_FALSE;
|
|
|
|
|
1999-09-25 03:39:35 +00:00
|
|
|
// Set the focus back to our view's widget.
|
|
|
|
if (nsMenuFrame::mDismissalListener) {
|
|
|
|
nsMenuFrame::mDismissalListener->EnableListener(PR_FALSE);
|
|
|
|
nsMenuFrame::mDismissalListener->SetCurrentMenuParent(mMenuParent);
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2000-05-16 20:46:08 +00:00
|
|
|
// activate false will also set the mMenuOpen to false.
|
1999-08-12 20:45:47 +00:00
|
|
|
ActivateMenu(PR_FALSE);
|
|
|
|
|
1999-09-25 03:39:35 +00:00
|
|
|
if (nsMenuFrame::mDismissalListener)
|
|
|
|
nsMenuFrame::mDismissalListener->EnableListener(PR_TRUE);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2000-08-06 08:11:05 +00:00
|
|
|
nsresult rv;
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIXBLService, xblService, "@mozilla.org/xbl;1", &rv);
|
2000-08-06 08:11:05 +00:00
|
|
|
PRInt32 dummy;
|
1999-07-31 11:29:03 +00:00
|
|
|
PRInt32 count;
|
|
|
|
mContent->ChildCount(count);
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
mContent->ChildAt(i, *getter_AddRefs(child));
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
2000-08-06 08:11:05 +00:00
|
|
|
xblService->ResolveTag(child, &dummy, getter_AddRefs(tag));
|
1999-07-31 11:29:03 +00:00
|
|
|
if (tag && tag.get() == nsXULAtoms::menupopup) {
|
|
|
|
*aResult = child.get();
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return;
|
|
|
|
}
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2000-11-28 08:52:36 +00:00
|
|
|
nsAutoString sizedToPopup;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::sizetopopup, sizedToPopup);
|
|
|
|
PRBool sizeToPopup = (sizedToPopup.EqualsIgnoreCase("true"));
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
nsIBox* ibox = nsnull;
|
|
|
|
nsresult rv2 = popupChild->QueryInterface(NS_GET_IID(nsIBox), (void**)&ibox);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv2) && ibox,"popupChild is not box!!");
|
|
|
|
|
|
|
|
// then get its preferred size
|
|
|
|
nsSize prefSize(0,0);
|
|
|
|
nsSize minSize(0,0);
|
|
|
|
nsSize maxSize(0,0);
|
|
|
|
|
|
|
|
ibox->GetPrefSize(aState, prefSize);
|
|
|
|
ibox->GetMinSize(aState, minSize);
|
|
|
|
ibox->GetMaxSize(aState, maxSize);
|
|
|
|
|
|
|
|
BoundsCheck(minSize, prefSize, maxSize);
|
|
|
|
|
2000-11-28 08:52:36 +00:00
|
|
|
if (sizeToPopup && prefSize.width < contentRect.width)
|
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) {
|
|
|
|
ibox->SetBounds(aState, nsRect(0,0,prefSize.width, prefSize.height));
|
|
|
|
RePositionPopup(aState);
|
|
|
|
mLastPref = prefSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// is the new size too small? Make sure we handle scrollbars correctly
|
|
|
|
nsIBox* child;
|
|
|
|
ibox->GetChildBox(&child);
|
|
|
|
|
|
|
|
nsRect bounds(0,0,0,0);
|
|
|
|
ibox->GetBounds(bounds);
|
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIScrollableFrame> scrollframe(do_QueryInterface(child));
|
2000-05-15 04:12:31 +00:00
|
|
|
if (scrollframe) {
|
|
|
|
nsIScrollableFrame::nsScrollPref pref;
|
2000-05-17 04:45:44 +00:00
|
|
|
scrollframe->GetScrollPreference(aState.GetPresContext(), &pref);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
|
|
|
if (pref == nsIScrollableFrame::Auto)
|
|
|
|
{
|
|
|
|
// if our pref height
|
|
|
|
if (bounds.height < prefSize.height) {
|
|
|
|
// layout the child
|
|
|
|
ibox->Layout(aState);
|
|
|
|
|
|
|
|
nscoord width;
|
|
|
|
nscoord height;
|
|
|
|
scrollframe->GetScrollbarSizes(aState.GetPresContext(), &width, &height);
|
|
|
|
if (bounds.width < prefSize.width + width)
|
|
|
|
{
|
|
|
|
bounds.width += width;
|
2000-10-28 22:17:53 +00:00
|
|
|
//printf("Width=%d\n",width);
|
2000-05-15 04:12:31 +00:00
|
|
|
ibox->SetBounds(aState, bounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// layout the child
|
|
|
|
ibox->Layout(aState);
|
|
|
|
|
|
|
|
// Only size the popups view if open.
|
|
|
|
if (mMenuOpen) {
|
|
|
|
nsIView* view = nsnull;
|
|
|
|
popupChild->GetView(aState.GetPresContext(), &view);
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
viewManager->ResizeView(view, bounds.width, bounds.height);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
nsIBox* ibox = nsnull;
|
|
|
|
nsresult rv2 = popupChild->QueryInterface(NS_GET_IID(nsIBox), (void**)&ibox);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv2) && ibox,"popupChild is not box!!");
|
|
|
|
|
|
|
|
return ibox->MarkChildrenStyleChange();
|
|
|
|
}
|
2000-03-31 07:02:06 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
nsIBox* ibox = nsnull;
|
|
|
|
if (NS_SUCCEEDED(aList->QueryInterface(NS_GET_IID(nsIBox), (void**)&ibox)) && ibox) {
|
2000-03-31 07:02:06 +00:00
|
|
|
ibox->SetDebug(aState, aDebug);
|
2000-03-02 03:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aList->GetNextSibling(&aList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2000-05-15 04:12:31 +00:00
|
|
|
nsIPresContext* presContext = aState.GetPresContext();
|
|
|
|
|
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) {
|
1999-12-08 11:30:47 +00:00
|
|
|
nsCOMPtr<nsIContent> menuPopupContent;
|
|
|
|
menuPopup->GetContent(getter_AddRefs(menuPopupContent));
|
|
|
|
nsAutoString popupAnchor, popupAlign;
|
|
|
|
|
|
|
|
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupanchor, popupAnchor);
|
|
|
|
menuPopupContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::popupalign, 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())
|
2001-01-09 01:28:36 +00:00
|
|
|
popupAnchor = NS_LITERAL_STRING("bottomleft");
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAlign.IsEmpty())
|
2001-01-09 01:28:36 +00:00
|
|
|
popupAlign = NS_LITERAL_STRING("topleft");
|
1999-12-08 11:30:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAnchor.IsEmpty())
|
2001-01-09 01:28:36 +00:00
|
|
|
popupAnchor = NS_LITERAL_STRING("topright");
|
2000-03-26 10:06:21 +00:00
|
|
|
if (popupAlign.IsEmpty())
|
2001-01-09 01:28:36 +00:00
|
|
|
popupAlign = NS_LITERAL_STRING("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
|
1999-07-23 05:47:43 +00:00
|
|
|
nsMenuFrame::ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag)
|
|
|
|
{
|
1999-07-23 07:39:16 +00:00
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (frame) {
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*)frame;
|
|
|
|
popup->ShortcutNavigation(aLetter, aHandledFlag);
|
|
|
|
}
|
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
|
1999-07-22 09:01:55 +00:00
|
|
|
nsMenuFrame::KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
if (frame) {
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*)frame;
|
|
|
|
popup->KeyboardNavigation(aDirection, aHandledFlag);
|
|
|
|
}
|
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
|
|
|
{
|
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()
|
|
|
|
{
|
2000-08-25 01:59:53 +00:00
|
|
|
if ( IsDisabled() )
|
|
|
|
return NS_OK;
|
|
|
|
|
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)
|
|
|
|
Execute(); // 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
|
|
|
}
|
|
|
|
|
2000-01-21 21:56:09 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
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) {
|
2000-04-16 11:19:26 +00:00
|
|
|
nsAutoString active;
|
1999-07-26 04:38:28 +00:00
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, active);
|
2001-01-09 01:28:36 +00:00
|
|
|
if (active.Equals(NS_LITERAL_STRING("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;
|
|
|
|
}
|
1999-07-26 01:35:39 +00:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMenuFrame::IsDisabled()
|
|
|
|
{
|
1999-09-03 03:47:06 +00:00
|
|
|
nsAutoString disabled;
|
1999-07-26 01:35:39 +00:00
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, disabled);
|
2001-01-09 01:28:36 +00:00
|
|
|
if (disabled.Equals(NS_LITERAL_STRING("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
|
2000-01-22 01:16:50 +00:00
|
|
|
nsMenuFrame::UpdateMenuType(nsIPresContext* aPresContext)
|
1999-10-15 21:13:24 +00:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value);
|
2001-01-09 01:28:36 +00:00
|
|
|
if (value.Equals(NS_LITERAL_STRING("checkbox")))
|
1999-10-17 21:37:37 +00:00
|
|
|
mType = eMenuType_Checkbox;
|
2001-01-09 01:28:36 +00:00
|
|
|
else if (value.Equals(NS_LITERAL_STRING("radio"))) {
|
1999-10-17 21:37:37 +00:00
|
|
|
mType = eMenuType_Radio;
|
2000-02-22 01:50:48 +00:00
|
|
|
|
2000-03-30 03:21:26 +00:00
|
|
|
nsAutoString valueName;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::name, valueName);
|
|
|
|
if ( mGroupName != valueName )
|
|
|
|
mGroupName = valueName;
|
2000-02-22 01:50:48 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-10-17 21:37:37 +00:00
|
|
|
if (mType != eMenuType_Normal)
|
1999-10-15 21:13:24 +00:00
|
|
|
mContent->UnsetAttribute(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
|
2000-01-22 01:16:50 +00:00
|
|
|
nsMenuFrame::UpdateMenuSpecialState(nsIPresContext* aPresContext) {
|
1999-10-15 21:13:24 +00:00
|
|
|
nsAutoString value;
|
1999-10-17 21:37:37 +00:00
|
|
|
PRBool newChecked;
|
|
|
|
|
1999-10-15 21:13:24 +00:00
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked,
|
|
|
|
value);
|
2001-01-09 01:28:36 +00:00
|
|
|
newChecked = (value.Equals(NS_LITERAL_STRING("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
|
|
|
|
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::name, value);
|
|
|
|
if (value == mGroupName)
|
|
|
|
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"
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!mChecked)
|
|
|
|
/*
|
|
|
|
* If we're not checked, then it must have been a name change, and a name
|
|
|
|
* change on an unchecked item doesn't require any magic.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 */
|
|
|
|
nsIFrame *parent, *sib;
|
|
|
|
nsIMenuFrame *sibMenu;
|
|
|
|
nsMenuType sibType;
|
|
|
|
nsAutoString sibGroup;
|
|
|
|
PRBool sibChecked;
|
|
|
|
|
|
|
|
nsresult rv = GetParent(&parent);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't get parent of radio menu frame\n");
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
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.
|
2000-01-22 01:16:50 +00:00
|
|
|
rv = parent->FirstChild(aPresContext, NULL, &sib);
|
2000-02-22 01:50:48 +00:00
|
|
|
if ( NS_FAILED(rv) || !sib )
|
|
|
|
return;
|
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)) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (NS_FAILED(sib->GetContent(getter_AddRefs(content))))
|
|
|
|
continue; // break?
|
|
|
|
|
|
|
|
/* uncheck the old item */
|
|
|
|
content->UnsetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked,
|
|
|
|
PR_TRUE);
|
|
|
|
|
|
|
|
/* XXX in DEBUG, check to make sure that there aren't two checked items */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(NS_SUCCEEDED(sib->GetNextSibling(&sib)) && sib);
|
|
|
|
|
1999-10-15 21:13:24 +00:00
|
|
|
}
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
void
|
|
|
|
nsMenuFrame::BuildAcceleratorText(nsString& aAccelString)
|
|
|
|
{
|
2000-03-28 00:41:33 +00:00
|
|
|
nsAutoString accelText;
|
1999-07-31 01:43:33 +00:00
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::acceltext, accelText);
|
2000-03-26 10:06:21 +00:00
|
|
|
if (!accelText.IsEmpty()) {
|
1999-07-31 01:43:33 +00:00
|
|
|
// Just use this.
|
|
|
|
aAccelString = accelText;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we have a key node and use that instead.
|
2000-03-28 00:41:33 +00:00
|
|
|
nsAutoString keyValue;
|
1999-07-31 01:43:33 +00:00
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::key, keyValue);
|
|
|
|
|
2000-07-28 21:48:08 +00:00
|
|
|
if (keyValue.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
mContent->GetDocument(*getter_AddRefs(document));
|
|
|
|
|
|
|
|
// Turn the document into a XUL document so we can use getElementById
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDocument(do_QueryInterface(document));
|
1999-07-31 01:43:33 +00:00
|
|
|
if (!xulDocument)
|
|
|
|
return;
|
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> keyDOMElement;
|
|
|
|
xulDocument->GetElementById(keyValue, getter_AddRefs(keyDOMElement));
|
|
|
|
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;
|
|
|
|
keyElement->GetAttribute(kNameSpaceID_None, nsXULAtoms::keytext, accelString);
|
|
|
|
|
|
|
|
if (accelString.IsEmpty()) {
|
|
|
|
keyElement->GetAttribute(kNameSpaceID_None, nsXULAtoms::key, accelString);
|
|
|
|
|
|
|
|
if (!accelString.IsEmpty()) {
|
|
|
|
accelString.ToUpperCase();
|
|
|
|
} else {
|
|
|
|
nsAutoString keyCode;
|
|
|
|
keyElement->GetAttribute(kNameSpaceID_None, nsXULAtoms::keycode, keyCode);
|
|
|
|
keyCode.ToUpperCase();
|
|
|
|
|
|
|
|
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;
|
|
|
|
rv = bundle->GetStringFromName(keyCode.GetUnicode(), getter_Copies(keyName));
|
|
|
|
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.
|
1999-12-08 04:52:42 +00:00
|
|
|
#ifdef XP_MAC
|
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:
|
|
|
|
nsresult rv;
|
2000-09-13 23:57:52 +00:00
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
2000-08-17 00:09:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && prefs)
|
2000-09-18 23:04:07 +00:00
|
|
|
rv = prefs->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-01-09 01:28:36 +00:00
|
|
|
keyElement->GetAttribute(kNameSpaceID_None, nsXULAtoms::modifiers, modifiers);
|
2000-09-22 05:02:20 +00:00
|
|
|
|
|
|
|
char* str = modifiers.ToNewCString();
|
|
|
|
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-01-09 01:28:36 +00:00
|
|
|
aAccelString += NS_LITERAL_STRING("Shift");
|
2000-09-22 05:02:20 +00:00
|
|
|
else if (PL_strcmp(token, "alt") == 0)
|
2001-01-09 01:28:36 +00:00
|
|
|
aAccelString += NS_LITERAL_STRING("Alt");
|
2000-09-22 05:02:20 +00:00
|
|
|
else if (PL_strcmp(token, "meta") == 0)
|
2001-01-09 01:28:36 +00:00
|
|
|
aAccelString += NS_LITERAL_STRING("Meta");
|
2000-09-22 05:02:20 +00:00
|
|
|
else if (PL_strcmp(token, "control") == 0)
|
2001-01-09 01:28:36 +00:00
|
|
|
aAccelString += NS_LITERAL_STRING("Ctrl");
|
2000-09-22 05:02:20 +00:00
|
|
|
else if (PL_strcmp(token, "accel") == 0) {
|
|
|
|
switch (accelKey)
|
|
|
|
{
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META:
|
2001-04-16 08:42:12 +00:00
|
|
|
aAccelString += NS_LITERAL_STRING("Meta");
|
2000-09-22 05:02:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT:
|
2001-01-09 01:28:36 +00:00
|
|
|
aAccelString += NS_LITERAL_STRING("Alt");
|
2000-09-22 05:02:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL:
|
|
|
|
default:
|
2001-01-09 01:28:36 +00:00
|
|
|
aAccelString += NS_LITERAL_STRING("Ctrl");
|
2000-09-22 05:02:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
aAccelString += NS_LITERAL_STRING("+");
|
|
|
|
|
|
|
|
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-01-09 01:28:36 +00:00
|
|
|
aAccelString += accelString;
|
2000-01-25 06:35:27 +00:00
|
|
|
|
2001-01-09 01:28:36 +00:00
|
|
|
mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::acceltext, aAccelString, PR_FALSE);
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::Execute()
|
|
|
|
{
|
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.
|
|
|
|
if ( nsMenuFrame::mDismissalListener ) {
|
|
|
|
nsMenuFrame::mDismissalListener->EnableListener(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
1999-08-13 23:49:53 +00:00
|
|
|
// Get our own content node and hold on to it to keep it from going away.
|
|
|
|
nsCOMPtr<nsIContent> content = dont_QueryInterface(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.
|
1999-08-12 20:45:47 +00:00
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->HideChain();
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_MENU_ACTION;
|
2000-01-16 17:06:08 +00:00
|
|
|
event.isShift = PR_FALSE;
|
|
|
|
event.isControl = PR_FALSE;
|
|
|
|
event.isAlt = PR_FALSE;
|
|
|
|
event.isMeta = PR_FALSE;
|
2000-01-15 17:25:14 +00:00
|
|
|
event.clickCount = 0;
|
|
|
|
event.widget = nsnull;
|
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.
|
|
|
|
nsCOMPtr<nsIViewManager> kungFuDeathGrip;
|
2000-06-29 02:02:43 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult result = mPresContext->GetShell(getter_AddRefs(shell));
|
2000-09-03 06:22:21 +00:00
|
|
|
nsIFrame* me = this;
|
2000-06-29 02:02:43 +00:00
|
|
|
if (NS_SUCCEEDED(result) && shell) {
|
2000-10-18 17:36:54 +00:00
|
|
|
shell->GetViewManager(getter_AddRefs(kungFuDeathGrip));
|
2001-03-21 08:15:49 +00:00
|
|
|
|
|
|
|
// See if we have a command elt. If so, we execute on the command instead
|
|
|
|
// of on our content element.
|
|
|
|
nsAutoString command;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::command, command);
|
|
|
|
if (!command.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
mContent->GetDocument(*getter_AddRefs(doc));
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
|
|
|
|
nsCOMPtr<nsIDOMElement> commandElt;
|
|
|
|
domDoc->GetElementById(command, getter_AddRefs(commandElt));
|
|
|
|
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
|
|
|
|
if (commandContent)
|
|
|
|
shell->HandleDOMEventWithTarget(commandContent, &event, &status);
|
2001-04-20 01:45:07 +00:00
|
|
|
else
|
|
|
|
NS_ASSERTION(PR_FALSE, "A XUL <menuitem> is attached to a command that doesn't exist! Unable to execute menu item!\n");
|
2001-03-21 08:15:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
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.
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
content->GetDocument(*getter_AddRefs(doc));
|
|
|
|
|
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.
|
2000-09-03 06:22:21 +00:00
|
|
|
if (doc && (primary == me) && mMenuParent) // <-- HACK IS HERE. ICK.
|
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.
|
|
|
|
if ( nsMenuFrame::mDismissalListener ) {
|
|
|
|
nsMenuFrame::mDismissalListener->EnableListener(PR_TRUE);
|
|
|
|
}
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMenuFrame::OnCreate()
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_MENU_CREATE;
|
2000-01-16 17:06:08 +00:00
|
|
|
event.isShift = PR_FALSE;
|
|
|
|
event.isControl = PR_FALSE;
|
|
|
|
event.isAlt = PR_FALSE;
|
|
|
|
event.isMeta = PR_FALSE;
|
2000-01-15 17:25:14 +00:00
|
|
|
event.clickCount = 0;
|
|
|
|
event.widget = nsnull;
|
1999-09-08 03:51:41 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
|
|
|
nsresult rv;
|
2000-06-29 02:02:43 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
|
|
|
if (child) {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(child, &event, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
|
|
|
}
|
|
|
|
}
|
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) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
child->GetDocument(*getter_AddRefs(doc));
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
|
|
|
|
|
|
|
|
PRInt32 count;
|
|
|
|
child->ChildCount(count);
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsCOMPtr<nsIContent> grandChild;
|
|
|
|
child->ChildAt(i, *getter_AddRefs(grandChild));
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
grandChild->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag.get() == nsXULAtoms::menuitem) {
|
|
|
|
// See if we have a command attribute.
|
|
|
|
nsAutoString command;
|
|
|
|
grandChild->GetAttribute(kNameSpaceID_None, nsXULAtoms::command, command);
|
|
|
|
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;
|
|
|
|
commandContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, commandAttr);
|
|
|
|
grandChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, menuAttr);
|
|
|
|
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-03-23 02:56:24 +00:00
|
|
|
grandChild->UnsetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, PR_TRUE);
|
2001-04-29 02:57:29 +00:00
|
|
|
else grandChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, commandAttr, PR_TRUE);
|
2001-03-23 02:56:24 +00:00
|
|
|
}
|
|
|
|
|
2001-04-29 02:57:29 +00:00
|
|
|
commandAttr.AssignWithConversion("");
|
|
|
|
menuAttr.AssignWithConversion("");
|
|
|
|
|
|
|
|
// The menu's label and checked states need to be updated to match the command.
|
|
|
|
// 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-04-29 02:57:29 +00:00
|
|
|
commandContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked, commandAttr);
|
|
|
|
grandChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked, menuAttr);
|
|
|
|
if (!commandAttr.Equals(menuAttr)) {
|
|
|
|
if (!commandAttr.IsEmpty())
|
|
|
|
grandChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked, commandAttr, PR_TRUE);
|
2001-04-28 06:38:23 +00:00
|
|
|
}
|
|
|
|
|
2001-04-29 02:57:29 +00:00
|
|
|
commandAttr.AssignWithConversion("");
|
|
|
|
menuAttr.AssignWithConversion("");
|
|
|
|
|
|
|
|
commandContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::label, commandAttr);
|
|
|
|
grandChild->GetAttribute(kNameSpaceID_None, nsXULAtoms::label, menuAttr);
|
|
|
|
if (!commandAttr.Equals(menuAttr)) {
|
|
|
|
if (!commandAttr.IsEmpty())
|
|
|
|
grandChild->SetAttribute(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMenuFrame::OnDestroy()
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_MENU_DESTROY;
|
2000-01-16 17:06:08 +00:00
|
|
|
event.isShift = PR_FALSE;
|
|
|
|
event.isControl = PR_FALSE;
|
|
|
|
event.isAlt = PR_FALSE;
|
|
|
|
event.isMeta = PR_FALSE;
|
2000-01-15 17:25:14 +00:00
|
|
|
event.clickCount = 0;
|
|
|
|
event.widget = nsnull;
|
1999-09-08 03:51:41 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
|
|
|
nsresult rv;
|
2000-06-29 02:02:43 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell) {
|
|
|
|
if (child) {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(child, &event, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = shell->HandleDOMEventWithTarget(mContent, &event, &status);
|
|
|
|
}
|
|
|
|
}
|
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
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::RemoveFrame(nsIPresContext* aPresContext,
|
1999-07-31 11:29:03 +00:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
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.
|
|
|
|
mPopupFrames.DestroyFrame(aPresContext, aOldFrame);
|
2000-03-31 07:02:06 +00:00
|
|
|
nsBoxLayoutState state(aPresContext);
|
|
|
|
rv = MarkDirtyChildren(state);
|
1999-08-19 03:51:25 +00:00
|
|
|
} else {
|
|
|
|
rv = nsBoxFrame::RemoveFrame(aPresContext, aPresShell, 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
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::InsertFrames(nsIPresContext* aPresContext,
|
1999-07-31 11:29:03 +00:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
1999-08-06 19:12:23 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
1999-08-19 03:51:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2000-08-06 08:11:05 +00:00
|
|
|
nsCOMPtr<nsIMenuParent> menuPar(do_QueryInterface(aFrameList));
|
|
|
|
if (menuPar) {
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIBox> menupopup(do_QueryInterface(aFrameList));
|
2000-05-15 04:12:31 +00:00
|
|
|
NS_ASSERTION(menupopup,"Popup is not a box!!!");
|
|
|
|
menupopup->SetParentBox(this);
|
1999-07-31 11:29:03 +00:00
|
|
|
mPopupFrames.InsertFrames(nsnull, nsnull, aFrameList);
|
2000-05-15 04:12:31 +00:00
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
nsBoxLayoutState state(aPresContext);
|
|
|
|
SetDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG);
|
|
|
|
rv = MarkDirtyChildren(state);
|
1999-08-19 03:51:25 +00:00
|
|
|
} else {
|
|
|
|
rv = nsBoxFrame::InsertFrames(aPresContext, aPresShell, 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
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::AppendFrames(nsIPresContext* aPresContext,
|
1999-07-31 11:29:03 +00:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
1999-08-04 21:36:30 +00:00
|
|
|
if (!aFrameList)
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-08-06 19:12:23 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
1999-08-19 03:51:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2000-08-06 08:11:05 +00:00
|
|
|
nsCOMPtr<nsIMenuParent> menuPar(do_QueryInterface(aFrameList));
|
|
|
|
if (menuPar) {
|
2001-01-09 01:28:36 +00:00
|
|
|
nsCOMPtr<nsIBox> menupopup(do_QueryInterface(aFrameList));
|
2000-05-15 04:12:31 +00:00
|
|
|
NS_ASSERTION(menupopup,"Popup is not a box!!!");
|
|
|
|
menupopup->SetParentBox(this);
|
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
mPopupFrames.AppendFrames(nsnull, aFrameList);
|
2000-03-31 07:02:06 +00:00
|
|
|
nsBoxLayoutState state(aPresContext);
|
|
|
|
SetDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG);
|
|
|
|
rv = MarkDirtyChildren(state);
|
1999-08-19 03:51:25 +00:00
|
|
|
} else {
|
|
|
|
rv = nsBoxFrame::AppendFrames(aPresContext, aPresShell, 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)
|
|
|
|
{
|
|
|
|
if (!nsMenuFrame::mDismissalListener) {
|
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.
|
1999-09-21 21:41:31 +00:00
|
|
|
nsMenuFrame::mDismissalListener->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);
|
|
|
|
|
2000-11-28 08:52:36 +00:00
|
|
|
nsAutoString sizedToPopup;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::sizetopopup, sizedToPopup);
|
|
|
|
PRBool sizeToPopup = (sizedToPopup.EqualsIgnoreCase("true"));
|
|
|
|
|
|
|
|
if (sizeToPopup) {
|
|
|
|
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
|
|
|
|
|
|
|
nsIBox* ibox = nsnull;
|
|
|
|
nsresult rv2 = frame->QueryInterface(NS_GET_IID(nsIBox), (void**)&ibox);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv2) && ibox,"popupChild is not box!!");
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2000-11-28 08:52:36 +00:00
|
|
|
ibox->GetPrefSize(aState, tmpSize);
|
|
|
|
aSize.width = tmpSize.width;
|
|
|
|
}
|
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);
|
2000-08-17 09:15:51 +00:00
|
|
|
nsCOMPtr<nsIContent> c;
|
|
|
|
f->GetContent(getter_AddRefs(c));
|
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(c));
|
|
|
|
*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));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
nsIFrame* kid;
|
|
|
|
shell->GetPrimaryFrameFor(child, &kid);
|
|
|
|
if (!kid)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsIMenuFrame> menuFrame(do_QueryInterface(kid));
|
|
|
|
if (!menuFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
menuPopup->SetCurrentMenuItem(menuFrame);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::GetScrollableView(nsIScrollableView** aView)
|
|
|
|
{
|
|
|
|
*aView = nsnull;
|
|
|
|
if (!mPopupFrames.FirstChild())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsMenuPopupFrame* popup = (nsMenuPopupFrame*) mPopupFrames.FirstChild();
|
|
|
|
nsIFrame* childFrame = nsnull;
|
|
|
|
popup->FirstChild(mPresContext, nsnull, &childFrame);
|
|
|
|
if (childFrame) {
|
|
|
|
*aView = popup->GetScrollableView(childFrame);
|
|
|
|
nsRect itemRect;
|
|
|
|
childFrame->GetRect(itemRect);
|
|
|
|
(*aView)->SetLineHeight(itemRect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
|
nsMenuFrame::GetBoxInfo(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsBoxInfo& aSize)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBox> box(do_QueryInterface(frame));
|
2000-03-31 07:02:06 +00:00
|
|
|
nsCalculatedBoxInfo childInfo(frame);
|
2000-02-25 08:37:49 +00:00
|
|
|
box->GetBoxInfo(aPresContext, aReflowState, childInfo);
|
|
|
|
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
|
|
|
|