From e362bed5faeac27d48815758232ff63f66cfead4 Mon Sep 17 00:00:00 2001 From: "shaver%netscape.com" Date: Thu, 14 Oct 1999 23:59:18 +0000 Subject: [PATCH] Fix for 15480 (menu reflow from content change). Use , not
, for accelerator text to fix alignment and improve performance _ever_ so slightly. Initial support for checked menus (needs more magic). (r=hyatt) --- layout/xul/base/src/nsMenuFrame.cpp | 42 +++++++++++++++++++++++------ layout/xul/base/src/nsMenuFrame.h | 2 +- xpfe/global/resources/skin/skin.css | 14 +++++++++- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/layout/xul/base/src/nsMenuFrame.cpp b/layout/xul/base/src/nsMenuFrame.cpp index 32a7b1a6a07..4510baa8319 100644 --- a/layout/xul/base/src/nsMenuFrame.cpp +++ b/layout/xul/base/src/nsMenuFrame.cpp @@ -18,12 +18,14 @@ #include "nsXULAtoms.h" #include "nsHTMLAtoms.h" +#include "nsHTMLParts.h" #include "nsMenuFrame.h" #include "nsBoxFrame.h" #include "nsIContent.h" #include "prtypes.h" #include "nsIAtom.h" #include "nsIPresContext.h" +#include "nsIPresShell.h" #include "nsIStyleContext.h" #include "nsIReflowCommand.h" #include "nsCSSRendering.h" @@ -401,7 +403,26 @@ nsMenuFrame::AttributeChanged(nsIPresContext* aPresContext, } else if (aAttribute == nsXULAtoms::acceltext) { /* update content in accel-text */ aChild->GetAttribute(kNameSpaceID_None, aAttribute, value); - mAccelText->SetData(value); + mAccelText->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, value, + PR_TRUE); + } + + /* we need to reflow, if these change */ + if (aAttribute == nsHTMLAtoms::value || + aAttribute == nsXULAtoms::acceltext) { + + nsCOMPtr shell; + nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr reflowCmd; + rv = NS_NewHTMLReflowCommand(getter_AddRefs(reflowCmd), this, + nsIReflowCommand::StyleChanged); + if (NS_FAILED(rv)) + return rv; + + shell->AppendReflowCommand(reflowCmd); } } @@ -833,22 +854,27 @@ nsMenuFrame::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren) if (!onMenuBar) { nsDocument->CreateElementWithNameSpace("spring", xulNamespace, getter_AddRefs(node)); content = do_QueryInterface(node); - content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, "100", PR_FALSE); + content->SetAttribute(kNameSpaceID_None, classAtom, "menu-spring", + PR_FALSE); + content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, "100", + PR_FALSE); aAnonymousChildren.AppendElement(content); // Build the accelerator out of the corresponding key node. nsAutoString accelString; BuildAcceleratorText(accelString); if (accelString != "") { - // Create the accelerator (it's a div) - nsDocument->CreateElementWithNameSpace("div", htmlNamespace, getter_AddRefs(node)); + // Create the accelerator (a titledbutton) + nsDocument->CreateElementWithNameSpace("titledbutton", xulNamespace, + getter_AddRefs(node)); content = do_QueryInterface(node); + mAccelText = content; + content->SetAttribute(kNameSpaceID_None, classAtom, "menu-accel", + PR_FALSE); + content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, accelString, + PR_FALSE); aAnonymousChildren.AppendElement(content); - nsCOMPtr accelNode; - document->CreateTextNode(accelString, getter_AddRefs(accelNode)); - mAccelText = accelNode; - node->AppendChild(accelNode, getter_AddRefs(dummyResult)); } // Create the "menu-right" object. It's a titledbutton. diff --git a/layout/xul/base/src/nsMenuFrame.h b/layout/xul/base/src/nsMenuFrame.h index 782f2f74cbf..1674088064b 100644 --- a/layout/xul/base/src/nsMenuFrame.h +++ b/layout/xul/base/src/nsMenuFrame.h @@ -176,7 +176,7 @@ protected: PRBool mMenuOpen; PRBool mHasAnonymousContent; // Do we have anonymous content frames? nsCOMPtr mMenuText; - nsCOMPtr mAccelText; + nsCOMPtr mAccelText; nsIMenuParent* mMenuParent; // Our parent menu. nsCOMPtr mOpenTimer; nsIPresContext* mPresContext; // Our pres context. diff --git a/xpfe/global/resources/skin/skin.css b/xpfe/global/resources/skin/skin.css index c976118747d..9366d154d4b 100644 --- a/xpfe/global/resources/skin/skin.css +++ b/xpfe/global/resources/skin/skin.css @@ -328,7 +328,7 @@ popup > menuitem[menuactive="true"] { margin-right: 2px; } -.menu-text { +.menu-text, .menu-accel { color: inherit; padding: 0px; border: 0px; @@ -350,6 +350,18 @@ menuitem > .menu-left { list-style-image: none; } +menuitem[checked="true"] > .menu-left { + list-style-image: url("chrome://global/skin/menu-check.gif"); +} + +menuitem[checked="true"][disabled="true"] > .menu-left { + list-style-image: url("chrome://global/skin/menu-check-disabled.gif"); +} + +menuitem[checked="true"][menuactive="true"] > .menu-left { + list-style-image: url("chrome://global/skin/menu-check-hover.gif"); +} + menu > .menu-right { list-style-image: url("chrome://global/skin/menu-arrow.gif"); }