Second try at fixing bug 130778. Create a new content interface, nsIMenuElement, which is implemeneted on nsHTMLSelectElement, nsHTMLOptGroupElement, and the newly-created nsXULMenuElement. Create a nsXULMenuElement instance for XUL menubar and menupopup tags. Use this interface to set and get the active item from the XUL menuframe code and the :-moz-menuactive pseudoclass matching code. Should eliminate the Txul slowdown resulting from fetching the active item through js from the pseudoclass matching code. r=jkeiser, sr=jst, a=scc.

git-svn-id: svn://10.0.0.236/trunk@117391 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bryner%netscape.com 2002-03-24 22:38:21 +00:00
parent c34115e075
commit 8b0b1784d6
25 changed files with 280 additions and 206 deletions

View File

@ -41,8 +41,7 @@
#include "nsAccessible.h"
#include "nsIAccessible.h"
#include "nsIDOMElement.h"
#include "nsIDOMXULPopupElement.h"
#include "nsIDOMXULMenuBarElement.h"
#include "nsIMenuElement.h"
// ------------------------ Menu Item -----------------------------
@ -57,26 +56,18 @@ NS_IMETHODIMP nsXULMenuitemAccessible::GetAccState(PRUint32 *_retval)
nsAccessible::GetAccState(_retval);
// Focused?
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
NS_ASSERTION(element, "No DOM element for menu node!");
nsCOMPtr<nsIDOMNode> parentNode;
mDOMNode->GetParentNode(getter_AddRefs(parentNode));
if (parentNode) {
nsCOMPtr<nsIDOMElement> currentItem;
nsCOMPtr<nsIDOMXULPopupElement> popupEl = do_QueryInterface(parentNode);
if (popupEl)
popupEl->GetActiveItem(getter_AddRefs(currentItem));
else {
nsCOMPtr<nsIDOMXULMenuBarElement> menubar = do_QueryInterface(parentNode);
if (menubar)
menubar->GetActiveMenu(getter_AddRefs(currentItem));
}
if (currentItem == element)
*_retval |= STATE_FOCUSED;
nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
nsCOMPtr<nsIContent> parent;
content->GetParent(*getter_AddRefs(parent));
if (parent) {
nsCOMPtr<nsIMenuElement> menuEl = do_QueryInterface(parent);
if (content == menuEl->GetActiveItem())
*_retval |= STATE_FOCUSED;
}
// Has Popup?
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
NS_ASSERTION(element, "No DOM element for menu node!");
nsAutoString tagName;
element->GetLocalName(tagName);
if (tagName.Equals(NS_LITERAL_STRING("menu")))

View File

@ -27,3 +27,4 @@ nsIStyleSheet.h
nsIStyleSheetLinkingElement.h
nsITextContent.h
nsIContentList.h
nsIMenuElement.h

View File

@ -56,6 +56,7 @@ nsIPrivateDOMImplementation.h \
nsIContentSerializer.h \
nsIHTMLToTextSink.h \
nsIContentList.h \
nsIMenuElement.h \
$(NULL)
XPIDLSRCS = \

View File

@ -48,6 +48,7 @@ EXPORTS = \
nsIContentSerializer.h \
nsIHTMLToTextSink.h \
nsIContentList.h \
nsIMenuElement.h \
$(NULL)
MODULE=content

View File

@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* nsIMenuElement is an interface to be implemented on the
* parent nodes of elements which can be in the :-moz-menuactive
* state (this corresponds to hovering over the item or going to
* it with the arrow keys). It is used by the CSS pseudoclass
* matching code to decide if a menu item matches :-moz-menuactive.
*/
#ifndef _nsIMenuElement_h_
#define _nsIMenuElement_h_
#include "nsISupports.h"
// IID for the nsIMenuElement interface
#define NS_IMENUELEMENT_IID \
{ 0xbfede654, 0x1dd1, 0x11b2, \
{ 0x89, 0x35, 0x87, 0x92, 0xfc, 0xb7, 0xc9, 0xa1 } }
class nsIMenuElement : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IMENUELEMENT_IID);
/**
* Get the current active item for this menu.
*/
virtual const nsIContent* GetActiveItem() const = 0;
/**
* Set the active item for this menu.
* @ param aItem The new active item
*/
virtual void SetActiveItem(const nsIContent* aItem) = 0;
};
#endif

View File

@ -49,10 +49,12 @@
#include "nsISelectElement.h"
#include "nsIDOMHTMLSelectElement.h"
#include "nsIMenuElement.h"
class nsHTMLOptGroupElement : public nsGenericHTMLContainerElement,
public nsIDOMHTMLOptGroupElement
public nsIDOMHTMLOptGroupElement,
public nsIMenuElement
{
public:
nsHTMLOptGroupElement();
@ -85,6 +87,11 @@ public:
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent,
nsIDOMEvent** aDOMEvent, PRUint32 aFlags,
nsEventStatus* aEventStatus);
// nsIMenuElement
virtual const nsIContent* GetActiveItem() const;
virtual void SetActiveItem(const nsIContent* aItem);
#ifdef DEBUG
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
#endif
@ -92,6 +99,8 @@ public:
protected:
nsresult GetSelect(nsISelectElement **aSelectElement);
const nsIContent* mActiveItem;
};
nsresult
@ -122,6 +131,7 @@ NS_NewHTMLOptGroupElement(nsIHTMLContent** aInstancePtrResult,
nsHTMLOptGroupElement::nsHTMLOptGroupElement()
: mActiveItem(nsnull)
{
}
@ -138,6 +148,7 @@ NS_IMPL_RELEASE_INHERITED(nsHTMLOptGroupElement, nsGenericElement);
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLOptGroupElement,
nsGenericHTMLContainerElement)
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLOptGroupElement)
NS_INTERFACE_MAP_ENTRY(nsIMenuElement)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLOptGroupElement)
NS_HTML_CONTENT_INTERFACE_MAP_END
@ -312,3 +323,15 @@ nsHTMLOptGroupElement::RemoveChildAt(PRInt32 aIndex, PRBool aNotify)
return rv;
}
const nsIContent*
nsHTMLOptGroupElement::GetActiveItem() const
{
return mActiveItem;
}
void
nsHTMLOptGroupElement::SetActiveItem(const nsIContent* aItem)
{
mActiveItem = aItem;
}

View File

@ -79,7 +79,7 @@
#include "nsIPresShell.h"
#include "nsIFormControlFrame.h"
#include "nsIFrame.h"
#include "nsIMenuElement.h"
#include "nsRuleNode.h"
@ -125,7 +125,8 @@ class nsHTMLSelectElement : public nsGenericHTMLContainerFormElement,
public nsIDOMHTMLSelectElement,
public nsIDOMNSHTMLSelectElement,
public nsIDOMNSXBLFormControl,
public nsISelectElement
public nsISelectElement,
public nsIMenuElement
{
public:
nsHTMLSelectElement();
@ -189,6 +190,9 @@ public:
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32 aModType, PRInt32& aHint) const;
// nsIMenuElement
virtual const nsIContent* GetActiveItem() const;
virtual void SetActiveItem(const nsIContent* aItem);
protected:
// Helper Methods
@ -242,6 +246,7 @@ protected:
PRUint32 mArtifactsAtTopLevel;
PRInt32 mSelectedIndex;
nsString* mRestoreState;
const nsIContent* mActiveItem;
};
@ -289,6 +294,7 @@ nsHTMLSelectElement::nsHTMLSelectElement()
mRestoreState = nsnull;
mSelectedIndex = -1;
mActiveItem = nsnull;
}
nsHTMLSelectElement::~nsHTMLSelectElement()
@ -318,6 +324,7 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLSelectElement,
NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLSelectElement)
NS_INTERFACE_MAP_ENTRY(nsIDOMNSXBLFormControl)
NS_INTERFACE_MAP_ENTRY(nsISelectElement)
NS_INTERFACE_MAP_ENTRY(nsIMenuElement)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLSelectElement)
NS_HTML_CONTENT_INTERFACE_MAP_END
@ -2036,6 +2043,17 @@ nsHTMLSelectElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission,
return NS_OK;
}
const nsIContent*
nsHTMLSelectElement::GetActiveItem() const
{
return mActiveItem;
}
void
nsHTMLSelectElement::SetActiveItem(const nsIContent* aItem)
{
mActiveItem = aItem;
}
//----------------------------------------------------------------------
//

View File

@ -98,10 +98,9 @@
#include "nsISizeOfHandler.h"
#include "nsStyleUtil.h"
#include "nsQuickSort.h"
#include "nsIMenuElement.h"
#ifdef MOZ_XUL
#include "nsIXULContent.h"
#include "nsIDOMXULPopupElement.h"
#include "nsIDOMXULMenuBarElement.h"
#include "nsXULAtoms.h"
#endif
@ -3342,21 +3341,9 @@ RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext,
(mContent->IsContentOfType(nsIContent::eXUL) &&
(mContentTag == nsXULAtoms::menuitem || mContentTag == nsXULAtoms::menu))) {
nsCOMPtr<nsIDOMElement> currentItem;
nsCOMPtr<nsIDOMXULPopupElement> popupEl = do_QueryInterface(mParentContent);
if (popupEl)
popupEl->GetActiveItem(getter_AddRefs(currentItem));
else {
nsCOMPtr<nsIDOMXULMenuBarElement> menubar = do_QueryInterface(mParentContent);
if (menubar)
menubar->GetActiveMenu(getter_AddRefs(currentItem));
}
if (currentItem) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mContent);
if (currentItem == element)
mIsMenuActive = PR_TRUE;
}
nsCOMPtr<nsIMenuElement> menuEl = do_QueryInterface(mParentContent);
if (menuEl)
mIsMenuActive = (mContent == menuEl->GetActiveItem());
}
}
}

View File

@ -2114,6 +2114,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsXULMenuElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsParserUtils.cpp</PATH>
@ -3305,6 +3312,11 @@
<PATH>nsXULElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsXULMenuElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsParserUtils.cpp</PATH>
@ -5603,6 +5615,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsXULMenuElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsParserUtils.cpp</PATH>
@ -6794,6 +6813,11 @@
<PATH>nsXULElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsXULMenuElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsParserUtils.cpp</PATH>
@ -8122,6 +8146,12 @@
<PATH>nsXULElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>content.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsXULMenuElement.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>xul/document</NAME>
<FILEREF>

View File

@ -55,6 +55,7 @@ CPPSRCS = \
nsXULAttributes.cpp \
nsXULElement.cpp \
nsXULPopupListener.cpp \
nsXULMenuElement.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

View File

@ -51,6 +51,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsXULAttributes.obj \
.\$(OBJDIR)\nsXULElement.obj \
.\$(OBJDIR)\nsXULPopupListener.obj \
.\$(OBJDIR)\nsXULMenuElement.obj \
$(NULL)
LINCS= \

View File

@ -129,6 +129,7 @@
#include "nsITreeBoxObject.h"
#include "nsContentUtils.h"
#include "nsGenericElement.h"
#include "nsXULMenuElement.h"
#include "nsMutationEvent.h"
#include "nsIDOMMutationEvent.h"
@ -560,7 +561,15 @@ nsXULElement::Create(nsXULPrototypeElement* aPrototype,
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsXULElement* element = new nsXULElement();
nsXULElement* element;
if (aPrototype->mNodeInfo &&
(aPrototype->mNodeInfo->Equals(nsXULAtoms::menubar) ||
aPrototype->mNodeInfo->Equals(nsXULAtoms::menupopup)))
element = new nsXULMenuElement();
else
element = new nsXULElement();
if (! element)
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -1,3 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -35,11 +36,27 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsIDOMXULElement.idl"
#include "nsXULMenuElement.h"
[scriptable, uuid(159c637c-1dd2-11b2-ab18-811904c2e7fb)]
interface nsIDOMXULMenuBarElement : nsIDOMXULElement {
nsXULMenuElement::nsXULMenuElement()
: mActiveItem(nsnull)
{
}
attribute nsIDOMElement activeMenu;
nsXULMenuElement::~nsXULMenuElement()
{
}
};
NS_IMPL_ISUPPORTS_INHERITED1(nsXULMenuElement, nsXULElement, nsIMenuElement);
const nsIContent*
nsXULMenuElement::GetActiveItem() const
{
return mActiveItem;
}
void
nsXULMenuElement::SetActiveItem(const nsIContent* aItem)
{
mActiveItem = aItem;
}

View File

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* 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.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _nsXULMenuElement_h_
#define _nsXULMenuElement_h_
#include "nsXULElement.h"
#include "nsIMenuElement.h"
class nsXULMenuElement : public nsXULElement,
public nsIMenuElement
{
public:
nsXULMenuElement();
virtual ~nsXULMenuElement();
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIMenuElement
virtual const nsIContent* GetActiveItem() const;
virtual void SetActiveItem(const nsIContent* aItem);
private:
const nsIContent* mActiveItem;
};
#endif

View File

@ -815,13 +815,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIDOMXULMenuBarElement.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@ -899,11 +892,6 @@
<PATH>nsIDOMXULPopupElement.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIDOMXULMenuBarElement.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
<TARGET>
@ -1668,13 +1656,6 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIDOMXULMenuBarElement.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@ -1752,11 +1733,6 @@
<PATH>nsIDOMXULPopupElement.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIDOMXULMenuBarElement.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
</TARGETLIST>
@ -1845,12 +1821,6 @@
<PATH>nsIDOMXULPopupElement.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIDOMXULMenuBarElement.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

View File

@ -1,4 +1,3 @@
nsIDOMXULCommandDispatcher.idl
nsIDOMXULDocument.idl
nsIDOMXULElement.idl
nsIDOMXULMenuBarElement.idl

View File

@ -45,7 +45,6 @@ XPIDLSRCS = \
nsIDOMXULSelectCntrlEl.idl \
nsIDOMXULSelectCntrlItemEl.idl \
nsIDOMXULMultSelectCntrlEl.idl \
nsIDOMXULMenuBarElement.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -41,7 +41,6 @@ XPIDLSRCS = \
.\nsIDOMXULSelectCntrlEl.idl \
.\nsIDOMXULSelectCntrlItemEl.idl \
.\nsIDOMXULMultSelectCntrlEl.idl \
.\nsIDOMXULMenuBarElement.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -54,8 +54,7 @@ interface nsIDOMXULPopupElement : nsIDOMXULElement {
const unsigned short AFTER_POINTER = 11;
attribute DOMString position;
attribute nsIDOMElement activeItem;
void showPopup(in unsigned short alignment,
in nsIDOMElement target,
in nsIDOMElement anchor);

View File

@ -98,10 +98,9 @@
#include "nsISizeOfHandler.h"
#include "nsStyleUtil.h"
#include "nsQuickSort.h"
#include "nsIMenuElement.h"
#ifdef MOZ_XUL
#include "nsIXULContent.h"
#include "nsIDOMXULPopupElement.h"
#include "nsIDOMXULMenuBarElement.h"
#include "nsXULAtoms.h"
#endif
@ -3342,21 +3341,9 @@ RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext,
(mContent->IsContentOfType(nsIContent::eXUL) &&
(mContentTag == nsXULAtoms::menuitem || mContentTag == nsXULAtoms::menu))) {
nsCOMPtr<nsIDOMElement> currentItem;
nsCOMPtr<nsIDOMXULPopupElement> popupEl = do_QueryInterface(mParentContent);
if (popupEl)
popupEl->GetActiveItem(getter_AddRefs(currentItem));
else {
nsCOMPtr<nsIDOMXULMenuBarElement> menubar = do_QueryInterface(mParentContent);
if (menubar)
menubar->GetActiveMenu(getter_AddRefs(currentItem));
}
if (currentItem) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mContent);
if (currentItem == element)
mIsMenuActive = PR_TRUE;
}
nsCOMPtr<nsIMenuElement> menuEl = do_QueryInterface(mParentContent);
if (menuEl)
mIsMenuActive = (mContent == menuEl->GetActiveItem());
}
}
}

View File

@ -1,88 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dean Tessman <dean_tessman@hotmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIMenuParent_h___
#define nsIMenuParent_h___
// {D407BF61-3EFA-11d3-97FA-00400553EEF0}
#define NS_IMENUPARENT_IID \
{ 0xd407bf61, 0x3efa, 0x11d3, { 0x97, 0xfa, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
class nsIMenuFrame;
class nsIMenuParent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IMENUPARENT_IID; return iid; }
NS_IMETHOD GetCurrentMenuItem(nsIMenuFrame** aMenuItem) = 0;
NS_IMETHOD SetCurrentMenuItem(nsIMenuFrame* aMenuItem) = 0;
NS_IMETHOD GetNextMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult) = 0;
NS_IMETHOD GetPreviousMenuItem(nsIMenuFrame* aStart, nsIMenuFrame** aResult) = 0;
NS_IMETHOD SetActive(PRBool aActiveFlag) = 0;
NS_IMETHOD GetIsActive(PRBool& isActive) = 0;
NS_IMETHOD GetWidget(nsIWidget **aWidget) = 0;
NS_IMETHOD IsMenuBar(PRBool& isMenuBar) = 0;
NS_IMETHOD DismissChain() = 0;
NS_IMETHOD HideChain() = 0;
NS_IMETHOD KillPendingTimers() = 0;
NS_IMETHOD CreateDismissalListener() = 0;
NS_IMETHOD InstallKeyboardNavigator() = 0;
NS_IMETHOD RemoveKeyboardNavigator() = 0;
// Used to move up, down, left, and right in menus.
NS_IMETHOD KeyboardNavigation(PRUint32 aDirection, PRBool& aHandledFlag) = 0;
NS_IMETHOD ShortcutNavigation(PRUint32 aLetter, PRBool& aHandledFlag) = 0;
// Called when the ESC key is held down to close levels of menus.
NS_IMETHOD Escape(PRBool& aHandledFlag) = 0;
// Called to execute a menu item.
NS_IMETHOD Enter() = 0;
NS_IMETHOD SetIsContextMenu(PRBool aIsContextMenu) = 0;
NS_IMETHOD GetIsContextMenu(PRBool& aIsContextMenu) = 0;
};
#endif

View File

@ -58,7 +58,7 @@
#include "nsMenuPopupFrame.h"
#include "nsGUIEvent.h"
#include "nsUnicharUtils.h"
#include "nsIDOMXULMenuBarElement.h"
#include "nsIMenuElement.h"
#ifdef XP_WIN
#include "nsISound.h"
#include "nsWidgetsCID.h"
@ -236,16 +236,14 @@ nsMenuBarFrame::ToggleMenuActiveState()
}
// Update the state on the menubar content node
nsCOMPtr<nsIDOMXULMenuBarElement> menubar = do_QueryInterface(mContent);
nsCOMPtr<nsIDOMElement> newActive;
nsCOMPtr<nsIMenuElement> menubar = do_QueryInterface(mContent);
nsCOMPtr<nsIContent> newActive;
if (mCurrentMenu) {
nsIFrame* frame = nsnull;
CallQueryInterface(mCurrentMenu, &frame);
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
newActive = do_QueryInterface(content);
frame->GetContent(getter_AddRefs(newActive));
}
menubar->SetActiveMenu(newActive);
menubar->SetActiveItem(newActive);
// Now send a CSS state change notification
if (mCurrentMenu)
@ -558,17 +556,15 @@ NS_IMETHODIMP nsMenuBarFrame::SetCurrentMenuItem(nsIMenuFrame* aMenuItem)
mCurrentMenu = aMenuItem;
// Update the menubar content node
nsCOMPtr<nsIDOMXULMenuBarElement> menubar = do_QueryInterface(mContent);
nsCOMPtr<nsIDOMElement> newActive;
nsCOMPtr<nsIMenuElement> menubar = do_QueryInterface(mContent);
nsCOMPtr<nsIContent> newActive;
if (mCurrentMenu) {
nsIFrame* frame = nsnull;
CallQueryInterface(mCurrentMenu, &frame);
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
newActive = do_QueryInterface(content);
frame->GetContent(getter_AddRefs(newActive));
}
menubar->SetActiveMenu(newActive);
menubar->SetActiveItem(newActive);
// Now send a CSS state change notification
if (mCurrentMenu)

View File

@ -69,7 +69,7 @@
#include "nsIFrameManager.h"
#include "nsGUIEvent.h"
#include "nsIRootBox.h"
#include "nsIDOMXULPopupElement.h"
#include "nsIMenuElement.h"
#ifdef XP_WIN
#include "nsISound.h"
#endif
@ -1442,9 +1442,8 @@ NS_IMETHODIMP nsMenuPopupFrame::SetCurrentMenuItem(nsIMenuFrame* aMenuItem)
frame->GetContent(getter_AddRefs(newContent));
}
nsCOMPtr<nsIDOMXULPopupElement> popupEl = do_QueryInterface(mContent);
nsCOMPtr<nsIDOMElement> domEl = do_QueryInterface(newContent);
popupEl->SetActiveItem(domEl);
nsCOMPtr<nsIMenuElement> popupEl = do_QueryInterface(mContent);
popupEl->SetActiveItem(newContent);
// Send menuactive state notification.
if (mCurrentMenu)
@ -1880,7 +1879,7 @@ NS_IMETHODIMP
nsMenuPopupFrame::Destroy(nsIPresContext* aPresContext)
{
// Make sure the content node doesn't think we still have an active item.
nsCOMPtr<nsIDOMXULPopupElement> popupEl = do_QueryInterface(mContent);
nsCOMPtr<nsIMenuElement> popupEl = do_QueryInterface(mContent);
if (popupEl)
popupEl->SetActiveItem(nsnull);

View File

@ -18,7 +18,6 @@
</content>
<implementation implements="nsIDOMXULPopupElement, nsIAccessibleProvider">
<field name="activeItem"/>
<property name="accessible">
<getter>
<![CDATA[

View File

@ -177,8 +177,7 @@
</xul:hbox>
</content>
<implementation implements="nsIDOMXULMenuBarElement, nsIAccessibleProvider">
<field name="activeMenu"/>
<implementation implements="nsIAccessibleProvider">
<property name="accessible">
<getter>
<![CDATA[