From 93114688c3936d2758cce5dd56eef16981a43f7c Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Wed, 20 Mar 2002 22:48:24 +0000 Subject: [PATCH] Bug 130778 - fixing Txul regression from changing 'menuactive' attribute to :-moz-menuactive pseudoclass. Get the menuactive state from the frame instead of the content node so that we don't have to call through xpconnect and js. r=dbaron, sr=hyatt, a=asa. --- accessible/src/xul/nsXULMenuAccessible.cpp | 41 +++++---- content/html/style/src/nsCSSStyleSheet.cpp | 34 +++---- dom/macbuild/dom_xulIDL.xml | 30 ------- dom/public/idl/xul/MANIFEST_IDL | 1 - dom/public/idl/xul/Makefile.in | 1 - dom/public/idl/xul/makefile.win | 1 - .../idl/xul/nsIDOMXULMenuBarElement.idl | 0 dom/public/idl/xul/nsIDOMXULPopupElement.idl | 3 +- layout/style/nsCSSStyleSheet.cpp | 34 +++---- layout/xul/base/public/Makefile.in | 1 + layout/xul/base/public/Manifest | 1 + layout/xul/base/public/makefile.win | 3 +- layout/xul/base/public/nsIMenuParent.h | 1 + layout/xul/base/src/nsIMenuParent.h | 88 ------------------- layout/xul/base/src/nsMenuBarFrame.cpp | 26 ------ layout/xul/base/src/nsMenuPopupFrame.cpp | 18 ---- .../resources/content/bindings/popup.xml | 1 - .../resources/content/bindings/toolbar.xml | 3 +- 18 files changed, 66 insertions(+), 221 deletions(-) delete mode 100644 dom/public/idl/xul/nsIDOMXULMenuBarElement.idl delete mode 100644 layout/xul/base/src/nsIMenuParent.h diff --git a/accessible/src/xul/nsXULMenuAccessible.cpp b/accessible/src/xul/nsXULMenuAccessible.cpp index bc7fd89b412..cd111f3fb19 100644 --- a/accessible/src/xul/nsXULMenuAccessible.cpp +++ b/accessible/src/xul/nsXULMenuAccessible.cpp @@ -41,8 +41,9 @@ #include "nsAccessible.h" #include "nsIAccessible.h" #include "nsIDOMElement.h" -#include "nsIDOMXULPopupElement.h" -#include "nsIDOMXULMenuBarElement.h" +#include "nsIFrame.h" +#include "nsIMenuFrame.h" +#include "nsIMenuParent.h" // ------------------------ Menu Item ----------------------------- @@ -57,26 +58,30 @@ NS_IMETHODIMP nsXULMenuitemAccessible::GetAccState(PRUint32 *_retval) nsAccessible::GetAccState(_retval); // Focused? - nsCOMPtr element(do_QueryInterface(mDOMNode)); - NS_ASSERTION(element, "No DOM element for menu node!"); - nsCOMPtr parentNode; - mDOMNode->GetParentNode(getter_AddRefs(parentNode)); - if (parentNode) { - nsCOMPtr currentItem; - nsCOMPtr popupEl = do_QueryInterface(parentNode); - if (popupEl) - popupEl->GetActiveItem(getter_AddRefs(currentItem)); - else { - nsCOMPtr menubar = do_QueryInterface(parentNode); - if (menubar) - menubar->GetActiveMenu(getter_AddRefs(currentItem)); + nsCOMPtr shell = do_QueryReferent(mPresShell); + if (shell) { + nsCOMPtr content = do_QueryInterface(mDOMNode); + nsIFrame* itemFrame; + shell->GetPrimaryFrameFor(content, &itemFrame); + if (itemFrame) { + nsIMenuFrame* menuFrame = nsnull; + CallQueryInterface(itemFrame, &menuFrame); + if (menuFrame) { + nsIMenuParent* menuParent; + menuFrame->GetMenuParent(&menuParent); + if (menuParent) { + nsIMenuFrame* currentMenuFrame; + menuParent->GetCurrentMenuItem(¤tMenuFrame); + if (currentMenuFrame == menuFrame) + *_retval |= STATE_FOCUSED; + } + } } - - if (currentItem == element) - *_retval |= STATE_FOCUSED; } // Has Popup? + nsCOMPtr 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"))) diff --git a/content/html/style/src/nsCSSStyleSheet.cpp b/content/html/style/src/nsCSSStyleSheet.cpp index 9fa40ffeb22..17d6ae11454 100644 --- a/content/html/style/src/nsCSSStyleSheet.cpp +++ b/content/html/style/src/nsCSSStyleSheet.cpp @@ -95,8 +95,8 @@ #include "nsQuickSort.h" #ifdef MOZ_XUL #include "nsIXULContent.h" -#include "nsIDOMXULPopupElement.h" -#include "nsIDOMXULMenuBarElement.h" +#include "nsIMenuParent.h" +#include "nsIMenuFrame.h" #include "nsXULAtoms.h" #endif @@ -3327,20 +3327,22 @@ RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext, (mContent->IsContentOfType(nsIContent::eXUL) && (mContentTag == nsXULAtoms::menuitem || mContentTag == nsXULAtoms::menu))) { - nsCOMPtr currentItem; - nsCOMPtr popupEl = do_QueryInterface(mParentContent); - if (popupEl) - popupEl->GetActiveItem(getter_AddRefs(currentItem)); - else { - nsCOMPtr menubar = do_QueryInterface(mParentContent); - if (menubar) - menubar->GetActiveMenu(getter_AddRefs(currentItem)); - } - - if (currentItem) { - nsCOMPtr element = do_QueryInterface(mContent); - if (currentItem == element) - mIsMenuActive = PR_TRUE; + nsCOMPtr shell; + mPresContext->GetShell(getter_AddRefs(shell)); + if (shell) { + nsIFrame* optionFrame = nsnull; + nsIMenuFrame* itemFrame = nsnull; + shell->GetPrimaryFrameFor(mContent, &optionFrame); + if (optionFrame && + NS_SUCCEEDED(CallQueryInterface(optionFrame, &itemFrame))) { + nsIMenuParent* menuParent; + itemFrame->GetMenuParent(&menuParent); + nsIMenuFrame* currentItemFrame = nsnull; + if (menuParent && + NS_SUCCEEDED(menuParent->GetCurrentMenuItem(¤tItemFrame)) && + currentItemFrame == itemFrame) + mIsMenuActive = PR_TRUE; + } } } } diff --git a/dom/macbuild/dom_xulIDL.xml b/dom/macbuild/dom_xulIDL.xml index 27fcb046f7c..0f651ca53f7 100644 --- a/dom/macbuild/dom_xulIDL.xml +++ b/dom/macbuild/dom_xulIDL.xml @@ -815,13 +815,6 @@ Text - - Name - nsIDOMXULMenuBarElement.idl - MacOS - Text - - @@ -899,11 +892,6 @@ nsIDOMXULPopupElement.idl MacOS - - Name - nsIDOMXULMenuBarElement.idl - MacOS - @@ -1668,13 +1656,6 @@ Text - - Name - nsIDOMXULMenuBarElement.idl - MacOS - Text - - @@ -1752,11 +1733,6 @@ nsIDOMXULPopupElement.idl MacOS - - Name - nsIDOMXULMenuBarElement.idl - MacOS - @@ -1845,12 +1821,6 @@ nsIDOMXULPopupElement.idl MacOS - - headers - Name - nsIDOMXULMenuBarElement.idl - MacOS - headers Name diff --git a/dom/public/idl/xul/MANIFEST_IDL b/dom/public/idl/xul/MANIFEST_IDL index 95d6e70ad1a..89b917e2fc1 100644 --- a/dom/public/idl/xul/MANIFEST_IDL +++ b/dom/public/idl/xul/MANIFEST_IDL @@ -1,4 +1,3 @@ nsIDOMXULCommandDispatcher.idl nsIDOMXULDocument.idl nsIDOMXULElement.idl -nsIDOMXULMenuBarElement.idl diff --git a/dom/public/idl/xul/Makefile.in b/dom/public/idl/xul/Makefile.in index e0f257dba8a..c57f4a788b3 100644 --- a/dom/public/idl/xul/Makefile.in +++ b/dom/public/idl/xul/Makefile.in @@ -45,7 +45,6 @@ XPIDLSRCS = \ nsIDOMXULSelectCntrlEl.idl \ nsIDOMXULSelectCntrlItemEl.idl \ nsIDOMXULMultSelectCntrlEl.idl \ - nsIDOMXULMenuBarElement.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/public/idl/xul/makefile.win b/dom/public/idl/xul/makefile.win index 4c6ee81ede9..1beb2253fa8 100644 --- a/dom/public/idl/xul/makefile.win +++ b/dom/public/idl/xul/makefile.win @@ -41,7 +41,6 @@ XPIDLSRCS = \ .\nsIDOMXULSelectCntrlEl.idl \ .\nsIDOMXULSelectCntrlItemEl.idl \ .\nsIDOMXULMultSelectCntrlEl.idl \ - .\nsIDOMXULMenuBarElement.idl \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/dom/public/idl/xul/nsIDOMXULMenuBarElement.idl b/dom/public/idl/xul/nsIDOMXULMenuBarElement.idl deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/dom/public/idl/xul/nsIDOMXULPopupElement.idl b/dom/public/idl/xul/nsIDOMXULPopupElement.idl index 99856d6c2b6..1922750811e 100644 --- a/dom/public/idl/xul/nsIDOMXULPopupElement.idl +++ b/dom/public/idl/xul/nsIDOMXULPopupElement.idl @@ -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); diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index 9fa40ffeb22..17d6ae11454 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -95,8 +95,8 @@ #include "nsQuickSort.h" #ifdef MOZ_XUL #include "nsIXULContent.h" -#include "nsIDOMXULPopupElement.h" -#include "nsIDOMXULMenuBarElement.h" +#include "nsIMenuParent.h" +#include "nsIMenuFrame.h" #include "nsXULAtoms.h" #endif @@ -3327,20 +3327,22 @@ RuleProcessorData::RuleProcessorData(nsIPresContext* aPresContext, (mContent->IsContentOfType(nsIContent::eXUL) && (mContentTag == nsXULAtoms::menuitem || mContentTag == nsXULAtoms::menu))) { - nsCOMPtr currentItem; - nsCOMPtr popupEl = do_QueryInterface(mParentContent); - if (popupEl) - popupEl->GetActiveItem(getter_AddRefs(currentItem)); - else { - nsCOMPtr menubar = do_QueryInterface(mParentContent); - if (menubar) - menubar->GetActiveMenu(getter_AddRefs(currentItem)); - } - - if (currentItem) { - nsCOMPtr element = do_QueryInterface(mContent); - if (currentItem == element) - mIsMenuActive = PR_TRUE; + nsCOMPtr shell; + mPresContext->GetShell(getter_AddRefs(shell)); + if (shell) { + nsIFrame* optionFrame = nsnull; + nsIMenuFrame* itemFrame = nsnull; + shell->GetPrimaryFrameFor(mContent, &optionFrame); + if (optionFrame && + NS_SUCCEEDED(CallQueryInterface(optionFrame, &itemFrame))) { + nsIMenuParent* menuParent; + itemFrame->GetMenuParent(&menuParent); + nsIMenuFrame* currentItemFrame = nsnull; + if (menuParent && + NS_SUCCEEDED(menuParent->GetCurrentMenuItem(¤tItemFrame)) && + currentItemFrame == itemFrame) + mIsMenuActive = PR_TRUE; + } } } } diff --git a/layout/xul/base/public/Makefile.in b/layout/xul/base/public/Makefile.in index 2bf72138b92..ddd7972a5c7 100644 --- a/layout/xul/base/public/Makefile.in +++ b/layout/xul/base/public/Makefile.in @@ -32,6 +32,7 @@ XPIDL_MODULE = layout_xul EXPORTS = \ nsPIBoxObject.h \ nsIMenuFrame.h \ + nsIMenuParent.h \ nsIPopupSetFrame.h \ nsITreeFrame.h \ $(NULL) diff --git a/layout/xul/base/public/Manifest b/layout/xul/base/public/Manifest index 601ce8c3222..80f09c5254e 100644 --- a/layout/xul/base/public/Manifest +++ b/layout/xul/base/public/Manifest @@ -1,5 +1,6 @@ nsPIBoxObject.h nsIMenuFrame.h +nsIMenuParent.h nsIPopupSetFrame.h nsITreeFrame.h diff --git a/layout/xul/base/public/makefile.win b/layout/xul/base/public/makefile.win index ab831cc5e3d..0186dd51f26 100644 --- a/layout/xul/base/public/makefile.win +++ b/layout/xul/base/public/makefile.win @@ -23,9 +23,10 @@ DEPTH=..\..\..\.. EXPORTS = \ nsIMenuFrame.h \ + nsIMenuParent.h \ nsIPopupSetFrame.h \ nsITreeFrame.h \ - nsPIBoxObject.h \ + nsPIBoxObject.h \ $(NULL) XPIDLSRCS= .\nsIBoxObject.idl \ diff --git a/layout/xul/base/public/nsIMenuParent.h b/layout/xul/base/public/nsIMenuParent.h index fa26c32af80..a1cf08cf2c4 100644 --- a/layout/xul/base/public/nsIMenuParent.h +++ b/layout/xul/base/public/nsIMenuParent.h @@ -45,6 +45,7 @@ { 0xd407bf61, 0x3efa, 0x11d3, { 0x97, 0xfa, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } } class nsIMenuFrame; +class nsIWidget; class nsIMenuParent : public nsISupports { diff --git a/layout/xul/base/src/nsIMenuParent.h b/layout/xul/base/src/nsIMenuParent.h deleted file mode 100644 index fa26c32af80..00000000000 --- a/layout/xul/base/src/nsIMenuParent.h +++ /dev/null @@ -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 - * - * 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 - diff --git a/layout/xul/base/src/nsMenuBarFrame.cpp b/layout/xul/base/src/nsMenuBarFrame.cpp index e5673cc64e9..206841e9efa 100644 --- a/layout/xul/base/src/nsMenuBarFrame.cpp +++ b/layout/xul/base/src/nsMenuBarFrame.cpp @@ -58,7 +58,6 @@ #include "nsMenuPopupFrame.h" #include "nsGUIEvent.h" #include "nsUnicharUtils.h" -#include "nsIDOMXULMenuBarElement.h" #ifdef XP_WIN #include "nsISound.h" #include "nsWidgetsCID.h" @@ -235,18 +234,6 @@ nsMenuBarFrame::ToggleMenuActiveState() } } - // Update the state on the menubar content node - nsCOMPtr menubar = do_QueryInterface(mContent); - nsCOMPtr newActive; - if (mCurrentMenu) { - nsIFrame* frame = nsnull; - CallQueryInterface(mCurrentMenu, &frame); - nsCOMPtr content; - frame->GetContent(getter_AddRefs(content)); - newActive = do_QueryInterface(content); - } - menubar->SetActiveMenu(newActive); - // Now send a CSS state change notification if (mCurrentMenu) mCurrentMenu->NotifyStateChanged(oldCurrent); @@ -557,19 +544,6 @@ NS_IMETHODIMP nsMenuBarFrame::SetCurrentMenuItem(nsIMenuFrame* aMenuItem) mCurrentMenu = aMenuItem; - // Update the menubar content node - nsCOMPtr menubar = do_QueryInterface(mContent); - nsCOMPtr newActive; - if (mCurrentMenu) { - nsIFrame* frame = nsnull; - CallQueryInterface(mCurrentMenu, &frame); - nsCOMPtr content; - frame->GetContent(getter_AddRefs(content)); - newActive = do_QueryInterface(content); - } - - menubar->SetActiveMenu(newActive); - // Now send a CSS state change notification if (mCurrentMenu) mCurrentMenu->NotifyStateChanged(oldMenuFrame); diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index f6ea2cc2d3d..d5d9a31f756 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -69,7 +69,6 @@ #include "nsIFrameManager.h" #include "nsGUIEvent.h" #include "nsIRootBox.h" -#include "nsIDOMXULPopupElement.h" #ifdef XP_WIN #include "nsISound.h" #endif @@ -1434,18 +1433,6 @@ NS_IMETHODIMP nsMenuPopupFrame::SetCurrentMenuItem(nsIMenuFrame* aMenuItem) mCurrentMenu = aMenuItem; - // Update the content node's idea of the current item. - nsCOMPtr newContent; - if (mCurrentMenu) { - nsIFrame* frame = nsnull; - CallQueryInterface(mCurrentMenu, &frame); - frame->GetContent(getter_AddRefs(newContent)); - } - - nsCOMPtr popupEl = do_QueryInterface(mContent); - nsCOMPtr domEl = do_QueryInterface(newContent); - popupEl->SetActiveItem(domEl); - // Send menuactive state notification. if (mCurrentMenu) mCurrentMenu->NotifyStateChanged(oldMenuFrame); @@ -1870,11 +1857,6 @@ nsMenuPopupFrame::HandleEvent(nsIPresContext* aPresContext, NS_IMETHODIMP nsMenuPopupFrame::Destroy(nsIPresContext* aPresContext) { - // Make sure the content node doesn't think we still have an active item. - nsCOMPtr popupEl = do_QueryInterface(mContent); - if (popupEl) - popupEl->SetActiveItem(nsnull); - return nsBoxFrame::Destroy(aPresContext); } diff --git a/xpfe/global/resources/content/bindings/popup.xml b/xpfe/global/resources/content/bindings/popup.xml index d7b2d70cd10..529771d7418 100644 --- a/xpfe/global/resources/content/bindings/popup.xml +++ b/xpfe/global/resources/content/bindings/popup.xml @@ -18,7 +18,6 @@ - - - +