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.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
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"
|
1999-07-18 06:36:37 +00:00
|
|
|
|
1999-07-18 06:48:03 +00:00
|
|
|
#define NS_MENU_POPUP_LIST_INDEX (NS_AREA_FRAME_ABSOLUTE_LIST_INDEX + 1)
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
}
|
1999-12-04 23:49:50 +00:00
|
|
|
nsMenuFrame* it = new (aPresShell) nsMenuFrame;
|
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
|
|
|
|
//
|
|
|
|
// Since we inherit from a base class with its own implementation of QI, we
|
|
|
|
// need to rely on that for the other interfaces supported, yet we still want
|
|
|
|
// to use the map macros. Currently, there is no macro to let you use the
|
|
|
|
// inherited version of QI, so we cheat. Hopefully this will change in the near
|
|
|
|
// future (pinkerton)
|
|
|
|
//
|
1999-12-21 19:28:15 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMenuFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMenuFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
|
1999-12-22 01:57:29 +00:00
|
|
|
foundInterface = 0;
|
|
|
|
nsresult status;
|
|
|
|
if ( !foundInterface )
|
|
|
|
status = nsBoxFrame::QueryInterface(aIID, NS_REINTERPRET_CAST(void**,&foundInterface)); \
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_ADDREF(foundInterface);
|
|
|
|
status = NS_OK;
|
|
|
|
}
|
|
|
|
*aInstancePtr = foundInterface;
|
|
|
|
return status;
|
|
|
|
}
|
1999-07-18 06:36:37 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsMenuFrame cntr
|
|
|
|
//
|
|
|
|
nsMenuFrame::nsMenuFrame()
|
1999-09-03 03:47:06 +00:00
|
|
|
: mIsMenu(PR_FALSE),
|
|
|
|
mMenuOpen(PR_FALSE),
|
1999-09-17 20:12:02 +00:00
|
|
|
mHasAnonymousContent(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),
|
1999-10-17 21:37:37 +00:00
|
|
|
mPresContext(nsnull),
|
|
|
|
mGroupName("")
|
1999-07-18 06:36:37 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
} // cntr
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Set our menu parent.
|
|
|
|
nsCOMPtr<nsIMenuParent> menuparent = do_QueryInterface(aParent);
|
|
|
|
mMenuParent = menuparent.get();
|
|
|
|
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
|
|
|
|
nsMenuFrame::FirstChild(nsIAtom* aListName,
|
|
|
|
nsIFrame** aFirstChild) const
|
|
|
|
{
|
|
|
|
if (nsLayoutAtoms::popupList == aListName) {
|
|
|
|
*aFirstChild = mPopupFrames.FirstChild();
|
|
|
|
} else {
|
1999-07-21 02:56:23 +00:00
|
|
|
nsBoxFrame::FirstChild(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) {
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
frame->GetContent(getter_AddRefs(content));
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
content->GetTag(*getter_AddRefs(tag));
|
1999-07-31 11:29:03 +00:00
|
|
|
if (tag.get() == nsXULAtoms::menupopup) {
|
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
|
|
|
|
{
|
1999-07-21 02:56:23 +00:00
|
|
|
return nsBoxFrame::GetAdditionalChildListName(aIndex, aListName);
|
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
|
|
|
{
|
|
|
|
// Cleanup frames in popup child list
|
1999-07-22 04:00:57 +00:00
|
|
|
mPopupFrames.DestroyFrames(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
|
1999-10-26 04:44:41 +00:00
|
|
|
nsMenuFrame::GetFrameForPoint(nsIPresContext* aPresContext,
|
|
|
|
const nsPoint& aPoint,
|
1999-07-19 09:36:24 +00:00
|
|
|
nsIFrame** aFrame)
|
|
|
|
{
|
1999-10-26 04:44:41 +00:00
|
|
|
nsresult result = nsBoxFrame::GetFrameForPoint(aPresContext, aPoint, aFrame);
|
1999-10-15 07:54:43 +00:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (*aFrame) {
|
|
|
|
(*aFrame)->GetContent(getter_AddRefs(content));
|
|
|
|
if (content) {
|
|
|
|
// This allows selective overriding for subcontent.
|
|
|
|
nsAutoString value;
|
|
|
|
content->GetAttribute(kNameSpaceID_None, nsXULAtoms::allowevents, value);
|
|
|
|
if (value == "true")
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
1999-07-19 09:36:24 +00:00
|
|
|
*aFrame = this; // Capture all events so that we can perform selection
|
|
|
|
return NS_OK;
|
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);
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
1999-07-26 01:35:39 +00:00
|
|
|
|
|
|
|
if (IsDisabled()) // Disabled menus process no events.
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-07-20 09:50:48 +00:00
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) {
|
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.
|
|
|
|
if (mIsMenu)
|
1999-07-31 11:29:03 +00:00
|
|
|
ToggleMenuState();
|
1999-09-01 00:39:12 +00:00
|
|
|
|
|
|
|
if (isMenuBar && mIsMenu) {
|
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
if (!IsOpen()) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
1999-07-25 00:16:11 +00:00
|
|
|
else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP && !IsMenu() &&
|
|
|
|
mMenuParent) {
|
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)) {
|
1999-10-15 21:13:24 +00:00
|
|
|
nsAutoString checked;
|
|
|
|
|
|
|
|
if (mChecked)
|
|
|
|
checked = "false";
|
|
|
|
else
|
|
|
|
checked = "true";
|
|
|
|
mContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked, checked,
|
|
|
|
PR_TRUE);
|
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
|
|
|
}
|
1999-07-21 07:42:16 +00:00
|
|
|
else if (aEvent->message == NS_MOUSE_EXIT) {
|
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) {
|
|
|
|
// Submenus don't get closed up.
|
|
|
|
}
|
|
|
|
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.
|
1999-07-25 01:14:43 +00:00
|
|
|
if (!isMenuBar && IsMenu() && !mMenuOpen && !mOpenTimer) {
|
1999-08-02 08:15:30 +00:00
|
|
|
// We're a menu, we're built, we're closed, and no timer has been kicked off.
|
1999-08-02 07:26:24 +00:00
|
|
|
NS_NewTimer(getter_AddRefs(mOpenTimer));
|
1999-08-02 08:15:30 +00:00
|
|
|
mOpenTimer->Init(this, 250); // 250 ms delay
|
1999-07-25 01:14:43 +00:00
|
|
|
}
|
1999-07-21 07:42:16 +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)
|
|
|
|
{
|
|
|
|
if (aActivateFlag) {
|
|
|
|
// Highlight the menu.
|
|
|
|
mContent->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "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);
|
1999-08-02 08:15:30 +00:00
|
|
|
if (genVal == "")
|
|
|
|
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);
|
1999-07-31 11:29:03 +00:00
|
|
|
if (genVal == "")
|
1999-09-10 08:47:12 +00:00
|
|
|
child->SetAttribute(kNameSpaceID_None, nsXULAtoms::menugenerated, "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)
|
|
|
|
{
|
|
|
|
// Activate the menu without opening it.
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
GetMenuChildrenElement(getter_AddRefs(child));
|
|
|
|
|
|
|
|
// We've got some children for real.
|
|
|
|
if (child) {
|
|
|
|
if (aActivateFlag)
|
|
|
|
child->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
|
|
|
|
else child->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
|
|
|
}
|
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);
|
|
|
|
if (value == "true")
|
1999-09-08 03:51:41 +00:00
|
|
|
OpenMenuInternal(PR_TRUE);
|
1999-09-17 20:12:02 +00:00
|
|
|
else
|
|
|
|
OpenMenuInternal(PR_FALSE);
|
1999-10-17 21:37:37 +00:00
|
|
|
} else if (aAttribute == nsHTMLAtoms::checked) {
|
|
|
|
if (mType != eMenuType_Normal)
|
|
|
|
UpdateMenuSpecialState();
|
1999-10-15 21:13:24 +00:00
|
|
|
} else if (aAttribute == nsHTMLAtoms::type) {
|
|
|
|
UpdateMenuType();
|
1999-09-17 20:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mHasAnonymousContent) {
|
|
|
|
if (aAttribute == nsXULAtoms::accesskey ||
|
|
|
|
aAttribute == nsHTMLAtoms::value) {
|
|
|
|
/* update accesskey or value on menu-left */
|
|
|
|
aChild->GetAttribute(kNameSpaceID_None, aAttribute, value);
|
|
|
|
mMenuText->SetAttribute(kNameSpaceID_None, aAttribute, value, PR_TRUE);
|
|
|
|
} else if (aAttribute == nsXULAtoms::acceltext) {
|
|
|
|
/* update content in accel-text */
|
|
|
|
aChild->GetAttribute(kNameSpaceID_None, aAttribute, value);
|
1999-10-14 23:59:18 +00:00
|
|
|
mAccelText->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value,
|
|
|
|
PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need to reflow, if these change */
|
|
|
|
if (aAttribute == nsHTMLAtoms::value ||
|
1999-10-15 21:13:24 +00:00
|
|
|
aAttribute == nsXULAtoms::acceltext ||
|
|
|
|
aAttribute == nsHTMLAtoms::type ||
|
|
|
|
aAttribute == nsHTMLAtoms::checked) {
|
1999-10-14 23:59:18 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIReflowCommand> reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(getter_AddRefs(reflowCmd), this,
|
|
|
|
nsIReflowCommand::StyleChanged);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
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)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(mContent);
|
|
|
|
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();
|
|
|
|
|
|
|
|
domElement->SetAttribute("open", "true");
|
|
|
|
}
|
|
|
|
else domElement->RemoveAttribute("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;
|
|
|
|
|
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;
|
|
|
|
|
1999-08-12 20:45:47 +00:00
|
|
|
if (menuPopup) {
|
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
|
|
|
|
|
|
|
// Sync up the view.
|
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;
|
1999-07-31 11:29:03 +00:00
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->IsMenuBar(onMenuBar);
|
|
|
|
|
1999-12-08 11:30:47 +00:00
|
|
|
if (onMenuBar) {
|
|
|
|
if (popupAnchor == "")
|
|
|
|
popupAnchor = "bottomleft";
|
|
|
|
if (popupAlign == "")
|
|
|
|
popupAlign = "topleft";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (popupAnchor == "")
|
|
|
|
popupAnchor = "topright";
|
|
|
|
if (popupAlign == "")
|
|
|
|
popupAlign = "topleft";
|
|
|
|
}
|
|
|
|
|
|
|
|
menuPopup->SyncViewWithFrame(mPresContext, popupAnchor, popupAlign, this, -1, -1);
|
1999-07-22 09:01:55 +00:00
|
|
|
}
|
|
|
|
|
1999-09-28 23:25:48 +00:00
|
|
|
ActivateMenu(PR_TRUE);
|
1999-10-06 23:00:53 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIMenuParent> childPopup = do_QueryInterface(frame);
|
|
|
|
UpdateDismissalListener(childPopup);
|
1999-09-28 23:25:48 +00:00
|
|
|
|
1999-07-20 09:35:35 +00:00
|
|
|
mMenuOpen = 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_TRUE);
|
|
|
|
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
1999-07-21 07:42:16 +00:00
|
|
|
else {
|
1999-07-24 22:02:23 +00:00
|
|
|
// Close the menu.
|
1999-07-31 01:43:33 +00:00
|
|
|
// Execute the ondestroy handler
|
|
|
|
if (!OnDestroy())
|
|
|
|
return;
|
|
|
|
|
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.
|
|
|
|
if (menuPopup)
|
|
|
|
menuPopup->SetCurrentMenuItem(nsnull);
|
|
|
|
|
1999-08-12 20:45:47 +00:00
|
|
|
ActivateMenu(PR_FALSE);
|
|
|
|
|
1999-07-21 07:42:16 +00:00
|
|
|
mMenuOpen = PR_FALSE;
|
1999-09-25 03:39:35 +00:00
|
|
|
/*
|
1999-07-26 02:26:26 +00:00
|
|
|
nsIView* view;
|
|
|
|
GetView(&view);
|
|
|
|
if (!view) {
|
|
|
|
nsPoint offset;
|
|
|
|
GetOffsetFromView(offset, &view);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
view->GetWidget(*getter_AddRefs(widget));
|
|
|
|
widget->SetFocus();
|
1999-09-25 03:39:35 +00:00
|
|
|
*/
|
|
|
|
if (nsMenuFrame::mDismissalListener)
|
|
|
|
nsMenuFrame::mDismissalListener->EnableListener(PR_TRUE);
|
1999-07-21 07:42:16 +00:00
|
|
|
}
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::GetMenuChildrenElement(nsIContent** aResult)
|
|
|
|
{
|
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;
|
|
|
|
child->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag && tag.get() == nsXULAtoms::menupopup) {
|
|
|
|
*aResult = child.get();
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return;
|
|
|
|
}
|
1999-07-20 09:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::Reflow(nsIPresContext* aPresContext,
|
1999-07-20 09:35:35 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
1999-07-21 02:56:23 +00:00
|
|
|
nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1999-07-20 09:35:35 +00:00
|
|
|
nsIFrame* frame = mPopupFrames.FirstChild();
|
|
|
|
|
1999-07-21 09:45:21 +00:00
|
|
|
if (!frame || (rv != NS_OK))
|
|
|
|
return rv;
|
1999-07-20 10:35:24 +00:00
|
|
|
|
1999-07-21 09:45:21 +00:00
|
|
|
// Constrain the child's width and height to aAvailableWidth and aAvailableHeight
|
|
|
|
nsSize availSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame,
|
|
|
|
availSize);
|
|
|
|
kidReflowState.mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
kidReflowState.mComputedHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
|
|
|
// Reflow child
|
|
|
|
nscoord w = aDesiredSize.width;
|
|
|
|
nscoord h = aDesiredSize.height;
|
1999-09-24 05:22:55 +00:00
|
|
|
|
|
|
|
if (kidReflowState.reason == eReflowReason_Incremental)
|
|
|
|
kidReflowState.reason = eReflowReason_Resize;
|
|
|
|
|
1999-07-21 09:45:21 +00:00
|
|
|
nsRect rect;
|
|
|
|
frame->GetRect(rect);
|
1999-11-19 15:33:29 +00:00
|
|
|
rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState,
|
|
|
|
rect.x, rect.y, NS_FRAME_NO_MOVE_VIEW, aStatus);
|
|
|
|
|
|
|
|
// Set the child's width and height to its desired size
|
|
|
|
// Note: don't position or size the view now, we'll do that in the
|
|
|
|
// DidReflow() function
|
1999-11-24 06:03:41 +00:00
|
|
|
frame->SizeTo(aPresContext, aDesiredSize.width, aDesiredSize.height);
|
1999-11-19 15:33:29 +00:00
|
|
|
frame->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1999-07-21 09:45:21 +00:00
|
|
|
|
|
|
|
// Don't let it affect our size.
|
|
|
|
aDesiredSize.width = w;
|
|
|
|
aDesiredSize.height = h;
|
1999-09-24 05:22:55 +00:00
|
|
|
|
1999-07-20 09:35:35 +00:00
|
|
|
return rv;
|
1999-07-20 10:13:43 +00:00
|
|
|
}
|
1999-07-22 09:01:55 +00:00
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::DidReflow(nsIPresContext* aPresContext,
|
1999-07-31 11:29:03 +00:00
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
1999-09-24 05:22:55 +00:00
|
|
|
nsresult rv;
|
|
|
|
rv = nsBoxFrame::DidReflow(aPresContext, aStatus);
|
1999-07-31 11:29:03 +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) {
|
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) {
|
|
|
|
if (popupAnchor == "")
|
|
|
|
popupAnchor = "bottomleft";
|
|
|
|
if (popupAlign == "")
|
|
|
|
popupAlign = "topleft";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (popupAnchor == "")
|
|
|
|
popupAnchor = "topright";
|
|
|
|
if (popupAlign == "")
|
|
|
|
popupAlign = "topleft";
|
|
|
|
}
|
|
|
|
|
|
|
|
menuPopup->SyncViewWithFrame(aPresContext, popupAnchor, popupAlign, this, -1, -1);
|
1999-09-24 05:22:55 +00:00
|
|
|
}
|
1999-07-31 11:29:03 +00:00
|
|
|
|
1999-09-24 05:22:55 +00:00
|
|
|
return rv;
|
1999-07-31 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
// Overridden Box method.
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +00:00
|
|
|
nsMenuFrame::Dirty(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsIFrame*& incrementalChild)
|
1999-07-31 01:43:33 +00:00
|
|
|
{
|
|
|
|
incrementalChild = nsnull;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Dirty any children that need it.
|
|
|
|
nsIFrame* frame;
|
|
|
|
aReflowState.reflowCommand->GetNext(frame, PR_FALSE);
|
1999-07-31 11:29:03 +00:00
|
|
|
if (frame == nsnull) {
|
|
|
|
incrementalChild = this;
|
|
|
|
return rv;
|
|
|
|
}
|
1999-07-31 01:43:33 +00:00
|
|
|
|
|
|
|
// Now call our original box frame method
|
1999-10-29 22:13:57 +00:00
|
|
|
rv = nsBoxFrame::Dirty(aPresContext, aReflowState, incrementalChild);
|
1999-07-31 01:43:33 +00:00
|
|
|
if (rv != NS_OK || incrementalChild)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsIFrame* popup = mPopupFrames.FirstChild();
|
|
|
|
if (popup && (frame == popup)) {
|
|
|
|
// In order for the child box to know what it needs to reflow, we need
|
|
|
|
// to call its Dirty method...
|
|
|
|
nsIBox* ibox;
|
|
|
|
if (NS_SUCCEEDED(popup->QueryInterface(nsIBox::GetIID(), (void**)&ibox)) && ibox)
|
1999-10-29 22:13:57 +00:00
|
|
|
ibox->Dirty(aPresContext, aReflowState, incrementalChild);
|
1999-09-24 05:22:55 +00:00
|
|
|
else
|
|
|
|
incrementalChild = frame;
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-09-21 01:03:00 +00:00
|
|
|
NS_IMETHODIMP
|
1999-07-24 22:02:23 +00:00
|
|
|
nsMenuFrame::Enter()
|
|
|
|
{
|
|
|
|
if (!mMenuOpen) {
|
|
|
|
// The enter key press applies to us.
|
1999-07-25 00:16:11 +00:00
|
|
|
if (!IsMenu() && mMenuParent) {
|
1999-08-01 19:55:00 +00:00
|
|
|
// Execute our event handler
|
|
|
|
Execute();
|
1999-07-24 22:02:23 +00:00
|
|
|
}
|
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()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
mContent->GetTag(*getter_AddRefs(tag));
|
1999-07-31 11:29:03 +00:00
|
|
|
if (tag.get() == nsXULAtoms::menu)
|
1999-07-25 00:16:11 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
1999-07-25 01:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
// Our timer has fired.
|
1999-07-26 04:38:28 +00:00
|
|
|
if (aTimer == mOpenTimer.get()) {
|
|
|
|
if (!mMenuOpen && mMenuParent) {
|
|
|
|
nsAutoString active = "";
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, active);
|
|
|
|
if (active == "true") {
|
|
|
|
// We're still the active menu.
|
|
|
|
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);
|
|
|
|
if (disabled == "true")
|
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-07-31 01:43:33 +00:00
|
|
|
|
1999-10-15 21:13:24 +00:00
|
|
|
void
|
|
|
|
nsMenuFrame::UpdateMenuType()
|
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value);
|
1999-10-17 21:37:37 +00:00
|
|
|
if (value == "checkbox") {
|
|
|
|
mType = eMenuType_Checkbox;
|
|
|
|
} else if (value == "radio") {
|
|
|
|
mType = eMenuType_Radio;
|
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
1999-10-17 21:37:37 +00:00
|
|
|
UpdateMenuSpecialState();
|
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
|
1999-10-17 21:37:37 +00:00
|
|
|
nsMenuFrame::UpdateMenuSpecialState() {
|
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);
|
1999-10-17 21:37:37 +00:00
|
|
|
newChecked = (value == "true");
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
mGroupName = value;
|
|
|
|
} 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;
|
|
|
|
|
|
|
|
rv = parent->FirstChild(NULL, &sib);
|
|
|
|
NS_ASSERTION((NS_SUCCEEDED(rv) && sib),
|
|
|
|
"couldn't get first sib of radio menu frame\n");
|
|
|
|
if (NS_FAILED(rv) || !sib) return;
|
|
|
|
|
|
|
|
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
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren)
|
|
|
|
{
|
|
|
|
// Create anonymous children only if the menu has no children or
|
|
|
|
// only has a menuchildren as its child.
|
|
|
|
nsCOMPtr<nsIDOMNode> dummyResult;
|
|
|
|
|
|
|
|
PRInt32 childCount;
|
|
|
|
mContent->ChildCount(childCount);
|
1999-09-17 20:12:02 +00:00
|
|
|
mHasAnonymousContent = PR_TRUE;
|
1999-07-31 11:29:03 +00:00
|
|
|
for (PRInt32 i = 0; i < childCount; i++) {
|
|
|
|
// XXX Should optimize this to look for a display type of none.
|
|
|
|
// Not sure how to do this. For now screen out some known tags.
|
1999-07-31 01:43:33 +00:00
|
|
|
nsCOMPtr<nsIContent> childContent;
|
1999-07-31 11:29:03 +00:00
|
|
|
mContent->ChildAt(i, *getter_AddRefs(childContent));
|
1999-07-31 01:43:33 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
childContent->GetTag(*getter_AddRefs(tag));
|
1999-07-31 11:29:03 +00:00
|
|
|
if (tag.get() != nsXULAtoms::menupopup &&
|
|
|
|
tag.get() != nsXULAtoms::templateAtom &&
|
|
|
|
tag.get() != nsXULAtoms::observes) {
|
1999-09-17 20:12:02 +00:00
|
|
|
mHasAnonymousContent = PR_FALSE;
|
1999-07-31 11:29:03 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
|
|
|
|
1999-09-17 20:12:02 +00:00
|
|
|
if (!mHasAnonymousContent)
|
1999-07-31 01:43:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> idocument;
|
|
|
|
mContent->GetDocument(*getter_AddRefs(idocument));
|
|
|
|
nsCOMPtr<nsIDOMNSDocument> nsDocument(do_QueryInterface(idocument));
|
|
|
|
nsCOMPtr<nsIDOMDocument> document(do_QueryInterface(idocument));
|
|
|
|
|
1999-09-03 03:47:06 +00:00
|
|
|
nsAutoString xulNamespace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
|
|
|
|
nsAutoString htmlNamespace("http://www.w3.org/TR/REC-html40");
|
1999-07-31 01:43:33 +00:00
|
|
|
nsCOMPtr<nsIAtom> classAtom = dont_AddRef(NS_NewAtom("class"));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> node;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
|
|
|
|
PRBool onMenuBar = PR_FALSE;
|
|
|
|
if (mMenuParent)
|
|
|
|
mMenuParent->IsMenuBar(onMenuBar);
|
|
|
|
|
1999-09-17 20:12:02 +00:00
|
|
|
/* Create .menu-left (.menubar-left) titledbutton for icon. */
|
|
|
|
nsDocument->CreateElementWithNameSpace("titledbutton", xulNamespace,
|
|
|
|
getter_AddRefs(node));
|
1999-07-31 01:43:33 +00:00
|
|
|
content = do_QueryInterface(node);
|
1999-09-17 20:12:02 +00:00
|
|
|
content->SetAttribute(kNameSpaceID_None, classAtom,
|
|
|
|
onMenuBar ? "menubar-left" : "menu-left" , PR_FALSE);
|
1999-07-31 01:43:33 +00:00
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
|
1999-09-17 20:12:02 +00:00
|
|
|
/*
|
|
|
|
* Create the .menu-text titledbutton, and propagate crop, accesskey and
|
|
|
|
* value attributes. If we're a menubar, make the class menubar-text
|
|
|
|
* instead.
|
|
|
|
*/
|
|
|
|
nsDocument->CreateElementWithNameSpace("titledbutton", xulNamespace,
|
|
|
|
getter_AddRefs(node));
|
|
|
|
content = do_QueryInterface(node);
|
|
|
|
content->SetAttribute(kNameSpaceID_None, classAtom,
|
|
|
|
onMenuBar ? "menubar-text" : "menu-text", PR_FALSE);
|
|
|
|
nsAutoString accessKey, value, crop;
|
1999-07-31 01:43:33 +00:00
|
|
|
|
1999-09-17 20:12:02 +00:00
|
|
|
mMenuText = content;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value);
|
|
|
|
content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value, PR_FALSE);
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::accesskey, accessKey);
|
|
|
|
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::accesskey, accessKey,
|
|
|
|
PR_FALSE);
|
|
|
|
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::crop, crop);
|
1999-09-17 21:29:50 +00:00
|
|
|
if (crop == "")
|
|
|
|
crop = "right";
|
|
|
|
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::crop, crop, PR_FALSE);
|
1999-12-08 04:52:42 +00:00
|
|
|
// XXX Causes menu items to disappear.
|
|
|
|
// content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, "1", PR_FALSE);
|
1999-07-31 01:43:33 +00:00
|
|
|
|
1999-09-17 20:12:02 +00:00
|
|
|
// append now, after we've set all the attributes
|
|
|
|
aAnonymousChildren.AppendElement(content);
|
1999-07-31 01:43:33 +00:00
|
|
|
|
1999-10-15 21:13:24 +00:00
|
|
|
// Do the type="checkbox" magic
|
|
|
|
UpdateMenuType();
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
// Create a spring that serves as padding between the text and the
|
|
|
|
// accelerator.
|
1999-07-31 11:29:03 +00:00
|
|
|
if (!onMenuBar) {
|
|
|
|
nsDocument->CreateElementWithNameSpace("spring", xulNamespace, getter_AddRefs(node));
|
1999-07-31 01:43:33 +00:00
|
|
|
content = do_QueryInterface(node);
|
1999-10-14 23:59:18 +00:00
|
|
|
content->SetAttribute(kNameSpaceID_None, classAtom, "menu-spring",
|
|
|
|
PR_FALSE);
|
1999-12-05 20:17:10 +00:00
|
|
|
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, "100000",
|
1999-10-14 23:59:18 +00:00
|
|
|
PR_FALSE);
|
1999-07-31 01:43:33 +00:00
|
|
|
aAnonymousChildren.AppendElement(content);
|
1999-07-31 11:29:03 +00:00
|
|
|
|
|
|
|
// Build the accelerator out of the corresponding key node.
|
1999-09-03 03:47:06 +00:00
|
|
|
nsAutoString accelString;
|
1999-07-31 11:29:03 +00:00
|
|
|
BuildAcceleratorText(accelString);
|
|
|
|
if (accelString != "") {
|
1999-10-14 23:59:18 +00:00
|
|
|
// Create the accelerator (a titledbutton)
|
|
|
|
nsDocument->CreateElementWithNameSpace("titledbutton", xulNamespace,
|
|
|
|
getter_AddRefs(node));
|
1999-07-31 11:29:03 +00:00
|
|
|
content = do_QueryInterface(node);
|
1999-10-14 23:59:18 +00:00
|
|
|
mAccelText = content;
|
|
|
|
content->SetAttribute(kNameSpaceID_None, classAtom, "menu-accel",
|
|
|
|
PR_FALSE);
|
|
|
|
content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, accelString,
|
|
|
|
PR_FALSE);
|
1999-07-31 11:29:03 +00:00
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
|
|
|
|
}
|
1999-07-31 01:43:33 +00:00
|
|
|
|
1999-07-31 11:29:03 +00:00
|
|
|
// Create the "menu-right" object. It's a titledbutton.
|
|
|
|
// XXX Maybe we should make one for a .menubar-right class so that the option exists
|
1999-07-31 01:43:33 +00:00
|
|
|
nsDocument->CreateElementWithNameSpace("titledbutton", xulNamespace, getter_AddRefs(node));
|
|
|
|
content = do_QueryInterface(node);
|
|
|
|
content->SetAttribute(kNameSpaceID_None, classAtom, "menu-right", PR_FALSE);
|
|
|
|
aAnonymousChildren.AppendElement(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::SplitOnShortcut(nsString& aBeforeString, nsString& aAccessString, nsString& aAfterString)
|
|
|
|
{
|
|
|
|
nsString value;
|
|
|
|
nsString accessKey;
|
|
|
|
aBeforeString = value;
|
|
|
|
aAccessString = "";
|
|
|
|
aAfterString = "";
|
|
|
|
|
|
|
|
if (accessKey == "") // Nothing to do.
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Find the index of the first occurrence of the accessKey
|
1999-09-03 03:47:06 +00:00
|
|
|
PRInt32 indx = value.Find(accessKey, PR_TRUE);
|
1999-07-31 01:43:33 +00:00
|
|
|
|
1999-09-03 03:47:06 +00:00
|
|
|
if (indx == -1) // Wasn't in there. Just return.
|
1999-07-31 01:43:33 +00:00
|
|
|
return;
|
|
|
|
|
1999-09-03 03:47:06 +00:00
|
|
|
// It was in the value string. Split based on the indx.
|
|
|
|
value.Left(aBeforeString, indx);
|
|
|
|
value.Mid(aAccessString, indx, 1);
|
|
|
|
value.Right(aAfterString, value.Length()-indx-1);
|
1999-07-31 01:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::BuildAcceleratorText(nsString& aAccelString)
|
|
|
|
{
|
|
|
|
nsString accelText;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::acceltext, accelText);
|
|
|
|
if (accelText != "") {
|
|
|
|
// Just use this.
|
|
|
|
aAccelString = accelText;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we have a key node and use that instead.
|
|
|
|
nsString keyValue;
|
|
|
|
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::key, keyValue);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
mContent->GetDocument(*getter_AddRefs(document));
|
|
|
|
|
|
|
|
// Turn the document into a XUL document so we can use getElementById
|
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDocument = do_QueryInterface(document);
|
|
|
|
if (!xulDocument)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> keyElement;
|
|
|
|
xulDocument->GetElementById(keyValue, getter_AddRefs(keyElement));
|
|
|
|
|
|
|
|
if (!keyElement)
|
|
|
|
return;
|
1999-12-08 04:52:42 +00:00
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
nsAutoString keyAtom("key");
|
|
|
|
nsAutoString shiftAtom("shift");
|
|
|
|
nsAutoString altAtom("alt");
|
|
|
|
nsAutoString commandAtom("command");
|
|
|
|
nsAutoString controlAtom("control");
|
|
|
|
|
|
|
|
nsString shiftValue;
|
|
|
|
nsString altValue;
|
|
|
|
nsString commandValue;
|
|
|
|
nsString controlValue;
|
|
|
|
nsString keyChar = " ";
|
|
|
|
|
|
|
|
keyElement->GetAttribute(keyAtom, keyChar);
|
|
|
|
keyElement->GetAttribute(shiftAtom, shiftValue);
|
|
|
|
keyElement->GetAttribute(altAtom, altValue);
|
|
|
|
keyElement->GetAttribute(commandAtom, commandValue);
|
|
|
|
keyElement->GetAttribute(controlAtom, controlValue);
|
|
|
|
|
1999-12-08 04:52:42 +00:00
|
|
|
nsAutoString xulkey;
|
|
|
|
keyElement->GetAttribute(nsAutoString("xulkey"), xulkey);
|
|
|
|
if (xulkey == "true") {
|
|
|
|
// Set the default for the xul key modifier
|
|
|
|
#ifdef XP_MAC
|
|
|
|
commandValue = "true";
|
|
|
|
#elif XP_PC
|
|
|
|
controlValue = "true";
|
|
|
|
#else
|
|
|
|
altValue = "true";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-07-31 01:43:33 +00:00
|
|
|
PRBool prependPlus = PR_FALSE;
|
|
|
|
|
1999-08-12 21:20:04 +00:00
|
|
|
if(commandValue != "" && commandValue != "false") {
|
1999-07-31 01:43:33 +00:00
|
|
|
prependPlus = PR_TRUE;
|
|
|
|
aAccelString += "Ctrl"; // Hmmm. Kinda defeats the point of having an abstraction.
|
|
|
|
}
|
|
|
|
|
1999-08-12 21:20:04 +00:00
|
|
|
if(controlValue != "" && controlValue != "false") {
|
1999-07-31 01:43:33 +00:00
|
|
|
prependPlus = PR_TRUE;
|
|
|
|
aAccelString += "Ctrl";
|
|
|
|
}
|
|
|
|
|
1999-08-12 21:20:04 +00:00
|
|
|
if(shiftValue != "" && shiftValue != "false") {
|
1999-07-31 01:43:33 +00:00
|
|
|
if (prependPlus)
|
|
|
|
aAccelString += "+";
|
|
|
|
prependPlus = PR_TRUE;
|
|
|
|
aAccelString += "Shift";
|
|
|
|
}
|
|
|
|
|
1999-08-12 21:20:04 +00:00
|
|
|
if (altValue != "" && altValue != "false") {
|
1999-07-31 01:43:33 +00:00
|
|
|
if (prependPlus)
|
|
|
|
aAccelString += "+";
|
|
|
|
prependPlus = PR_TRUE;
|
|
|
|
aAccelString += "Alt";
|
|
|
|
}
|
|
|
|
|
|
|
|
keyChar.ToUpperCase();
|
|
|
|
if (keyChar != "") {
|
|
|
|
if (prependPlus)
|
|
|
|
aAccelString += "+";
|
|
|
|
prependPlus = PR_TRUE;
|
|
|
|
aAccelString += keyChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
1999-08-12 20:45:47 +00:00
|
|
|
// First hide all of the open menus.
|
|
|
|
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;
|
1999-11-24 06:03:41 +00:00
|
|
|
mContent->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
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));
|
|
|
|
|
1999-08-12 20:45:47 +00:00
|
|
|
// Now properly close them all up.
|
1999-08-13 23:49:53 +00:00
|
|
|
if (doc && mMenuParent)
|
1999-08-12 20:45:47 +00:00
|
|
|
mMenuParent->DismissChain();
|
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;
|
|
|
|
if (child)
|
1999-11-24 06:03:41 +00:00
|
|
|
rv = child->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
else rv = mContent->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (child)
|
1999-11-24 06:03:41 +00:00
|
|
|
rv = child->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
else rv = mContent->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &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);
|
1999-08-19 03:51:25 +00:00
|
|
|
rv = GenerateDirtyReflowCommand(aPresContext, aPresShell);
|
|
|
|
} 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)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> frameChild;
|
|
|
|
aFrameList->GetContent(getter_AddRefs(frameChild));
|
|
|
|
|
1999-08-06 19:12:23 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
1999-08-19 03:51:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-08-06 19:12:23 +00:00
|
|
|
frameChild->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag && tag.get() == nsXULAtoms::menupopup) {
|
1999-07-31 11:29:03 +00:00
|
|
|
mPopupFrames.InsertFrames(nsnull, nsnull, aFrameList);
|
1999-08-19 03:51:25 +00:00
|
|
|
rv = GenerateDirtyReflowCommand(aPresContext, aPresShell);
|
|
|
|
} 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-07-31 11:29:03 +00:00
|
|
|
nsCOMPtr<nsIContent> frameChild;
|
|
|
|
aFrameList->GetContent(getter_AddRefs(frameChild));
|
|
|
|
|
1999-08-06 19:12:23 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
1999-08-19 03:51:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-08-06 19:12:23 +00:00
|
|
|
frameChild->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag && tag.get() == nsXULAtoms::menupopup) {
|
1999-07-31 11:29:03 +00:00
|
|
|
mPopupFrames.AppendFrames(nsnull, aFrameList);
|
1999-08-19 03:51:25 +00:00
|
|
|
rv = GenerateDirtyReflowCommand(aPresContext, aPresShell);
|
|
|
|
} 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
|
|
|
}
|