зеркало из https://github.com/mozilla/pjs.git
Add support for type="checkbox" in <menuitem>.
Converted small pile of PRBool to PRPackedBool for space savings. r=hyatt
This commit is contained in:
Родитель
598cf87a74
Коммит
e220469f04
|
@ -113,6 +113,8 @@ nsMenuFrame::nsMenuFrame()
|
|||
: mIsMenu(PR_FALSE),
|
||||
mMenuOpen(PR_FALSE),
|
||||
mHasAnonymousContent(PR_FALSE),
|
||||
mIsCheckbox(PR_FALSE),
|
||||
mChecked(PR_FALSE),
|
||||
mMenuParent(nsnull),
|
||||
mPresContext(nsnull)
|
||||
{
|
||||
|
@ -254,6 +256,18 @@ nsMenuFrame::HandleEvent(nsIPresContext& aPresContext,
|
|||
}
|
||||
else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP && !IsMenu() &&
|
||||
mMenuParent) {
|
||||
// First, flip "checked" state if we're a checkbox menu
|
||||
if (mIsCheckbox) {
|
||||
nsAutoString checked;
|
||||
|
||||
if (mChecked)
|
||||
checked = "false";
|
||||
else
|
||||
checked = "true";
|
||||
mContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked, checked,
|
||||
PR_TRUE);
|
||||
}
|
||||
|
||||
// Execute the execute event handler.
|
||||
Execute();
|
||||
}
|
||||
|
@ -404,6 +418,10 @@ nsMenuFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|||
OpenMenuInternal(PR_TRUE);
|
||||
else
|
||||
OpenMenuInternal(PR_FALSE);
|
||||
} else if (mIsCheckbox && aAttribute == nsHTMLAtoms::checked) {
|
||||
UpdateMenuChecked();
|
||||
} else if (aAttribute == nsHTMLAtoms::type) {
|
||||
UpdateMenuType();
|
||||
}
|
||||
|
||||
if (mHasAnonymousContent) {
|
||||
|
@ -421,7 +439,9 @@ nsMenuFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|||
|
||||
/* we need to reflow, if these change */
|
||||
if (aAttribute == nsHTMLAtoms::value ||
|
||||
aAttribute == nsXULAtoms::acceltext) {
|
||||
aAttribute == nsXULAtoms::acceltext ||
|
||||
aAttribute == nsHTMLAtoms::type ||
|
||||
aAttribute == nsHTMLAtoms::checked) {
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));
|
||||
|
@ -777,6 +797,33 @@ nsMenuFrame::IsDisabled()
|
|||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
nsMenuFrame::UpdateMenuType()
|
||||
{
|
||||
nsAutoString value;
|
||||
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value);
|
||||
if (value != "checkbox") {
|
||||
if (mIsCheckbox)
|
||||
mContent->UnsetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked,
|
||||
PR_TRUE);
|
||||
mIsCheckbox = PR_FALSE;
|
||||
} else {
|
||||
mIsCheckbox = PR_TRUE;
|
||||
UpdateMenuChecked();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsMenuFrame::UpdateMenuChecked() {
|
||||
nsAutoString value;
|
||||
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::checked,
|
||||
value);
|
||||
if (value == "true")
|
||||
mChecked = PR_TRUE;
|
||||
else
|
||||
mChecked = PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuFrame::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren)
|
||||
{
|
||||
|
@ -861,6 +908,9 @@ nsMenuFrame::CreateAnonymousContent(nsISupportsArray& aAnonymousChildren)
|
|||
// append now, after we've set all the attributes
|
||||
aAnonymousChildren.AppendElement(content);
|
||||
|
||||
// Do the type="checkbox" magic
|
||||
UpdateMenuType();
|
||||
|
||||
// Create a spring that serves as padding between the text and the
|
||||
// accelerator.
|
||||
if (!onMenuBar) {
|
||||
|
|
|
@ -146,6 +146,8 @@ public:
|
|||
|
||||
protected:
|
||||
static void UpdateDismissalListener(nsIMenuParent* aMenuParent);
|
||||
void UpdateMenuType();
|
||||
void UpdateMenuChecked();
|
||||
|
||||
void OpenMenuInternal(PRBool aActivateFlag);
|
||||
void GetMenuChildrenElement(nsIContent** aResult);
|
||||
|
@ -172,9 +174,11 @@ protected:
|
|||
|
||||
protected:
|
||||
nsFrameList mPopupFrames;
|
||||
PRBool mIsMenu; // Whether or not we can even have children or not.
|
||||
PRBool mMenuOpen;
|
||||
PRBool mHasAnonymousContent; // Do we have anonymous content frames?
|
||||
PRPackedBool mIsMenu; // Whether or not we can even have children or not.
|
||||
PRPackedBool mMenuOpen;
|
||||
PRPackedBool mHasAnonymousContent; // Do we have anonymous content frames?
|
||||
PRPackedBool mIsCheckbox; // Are we a checkbox?
|
||||
PRPackedBool mChecked; // if so, are we checked?
|
||||
nsCOMPtr<nsIContent> mMenuText;
|
||||
nsCOMPtr<nsIContent> mAccelText;
|
||||
nsIMenuParent* mMenuParent; // Our parent menu.
|
||||
|
|
Загрузка…
Ссылка в новой задаче