Bug 333896 Convert GetAttr calls to AttrValueIs and FindAttrValueIn

Patch by alfred.peng@sun.com.
roc: review+
mark: review+
roc: superreview+
This commit is contained in:
leon.sha%sun.com 2006-05-16 05:40:33 +00:00
Родитель 72a2b98461
Коммит e44da34528
23 изменённых файлов: 249 добавлений и 283 удалений

Просмотреть файл

@ -89,7 +89,6 @@
#include "nsIURI.h"
#include "nsIImageLoadingContent.h"
#include "nsITimer.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIMutableArray.h"
#ifdef NS_DEBUG

Просмотреть файл

@ -54,29 +54,46 @@
******/
WIDGET_ATOM(accesskey, "accesskey") // The shortcut key for a menu or menu item
WIDGET_ATOM(ascending, "ascending")
WIDGET_ATOM(autocheck, "autocheck")
WIDGET_ATOM(checkbox, "checkbox")
WIDGET_ATOM(checked, "checked")
WIDGET_ATOM(_class, "class")
WIDGET_ATOM(collapsed, "collapsed")
WIDGET_ATOM(menuseparator, "menuseparator") // Divider between menu items
WIDGET_ATOM(modifiers, "modifiers") // The modifiers attribute
WIDGET_ATOM(key, "key") // The key element / attribute
WIDGET_ATOM(command, "command")
WIDGET_ATOM(curpos, "curpos")
WIDGET_ATOM(_default, "default")
WIDGET_ATOM(descending, "descending")
WIDGET_ATOM(disabled, "disabled")
WIDGET_ATOM(_false, "false")
WIDGET_ATOM(firsttab, "first-tab")
WIDGET_ATOM(focused, "focused")
WIDGET_ATOM(hidden, "hidden")
WIDGET_ATOM(horizontal, "horizontal")
WIDGET_ATOM(id, "id")
WIDGET_ATOM(increment, "increment")
WIDGET_ATOM(input, "input")
WIDGET_ATOM(key, "key") // The key element / attribute
WIDGET_ATOM(label, "label")
WIDGET_ATOM(maxpos, "maxpos")
WIDGET_ATOM(menu, "menu") // Represents an XP menu
WIDGET_ATOM(menuitem, "menuitem") // Represents an XP menu item
WIDGET_ATOM(open, "open") // Whether or not a menu, tree, etc. is open
WIDGET_ATOM(menupopup, "menupopup") // The XP menu's children.
WIDGET_ATOM(id, "id")
WIDGET_ATOM(accesskey, "accesskey") // The shortcut key for a menu or menu item
WIDGET_ATOM(menuseparator, "menuseparator") // Divider between menu items
WIDGET_ATOM(mode, "mode")
WIDGET_ATOM(modifiers, "modifiers") // The modifiers attribute
WIDGET_ATOM(mozinputchecked, "_moz-input-checked")
WIDGET_ATOM(mozmenuactive, "_moz-menuactive")
WIDGET_ATOM(name, "name")
WIDGET_ATOM(type, "type")
WIDGET_ATOM(autocheck, "autocheck")
WIDGET_ATOM(checked, "checked")
WIDGET_ATOM(disabled, "disabled")
WIDGET_ATOM(label, "label")
WIDGET_ATOM(hidden, "hidden")
WIDGET_ATOM(curpos, "curpos")
WIDGET_ATOM(maxpos, "maxpos")
WIDGET_ATOM(increment, "increment")
WIDGET_ATOM(pageincrement, "pageincrement")
WIDGET_ATOM(open, "open") // Whether or not a menu, tree, etc. is open
WIDGET_ATOM(orient, "orient")
WIDGET_ATOM(pageincrement, "pageincrement")
WIDGET_ATOM(radio, "radio")
WIDGET_ATOM(readonly, "readonly")
WIDGET_ATOM(selected, "selected")
WIDGET_ATOM(sortdirection, "sortDirection")
WIDGET_ATOM(_true, "true")
WIDGET_ATOM(type, "type")
WIDGET_ATOM(value, "value")

Просмотреть файл

@ -422,9 +422,8 @@ nsMenuBarX::MenuConstruct(const nsMenuEvent & aMenuEvent, nsIWidget* aParentWind
// Make nsMenu a child of nsMenuBar. nsMenuBar takes ownership.
AddMenu(pnsMenu);
nsAutoString menuIDstring;
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::id, menuIDstring);
if (menuIDstring.EqualsLiteral("menu_Help")) {
if (menu->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::id,
NS_LITERAL_STRING("menu_Help"), eCaseMatters)) {
nsMenuEvent event(PR_TRUE, 0, nsnull);
event.mCommand = (unsigned int)nsnull;
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(pnsMenu));
@ -495,9 +494,9 @@ NS_IMETHODIMP nsMenuBarX::AddMenu(nsIMenu * aMenu)
nsCOMPtr<nsIContent> menu;
aMenu->GetMenuContent(getter_AddRefs(menu));
nsAutoString menuHidden;
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, menuHidden);
if (!menuHidden.EqualsLiteral("true") && menu->GetChildCount() > 0) {
if (!menu->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters) &&
menu->GetChildCount() > 0) {
NSMenuItem* newMenuItem = [[[NSMenuItem alloc] initWithTitle:@"SomeMenuItem" action:NULL keyEquivalent:@""] autorelease];
[mRootMenu addItem:newMenuItem];
[newMenuItem setSubmenu:menuRef];

Просмотреть файл

@ -389,9 +389,8 @@ nsMenuItemX::UncheckRadioSiblings(nsIContent* inCheckedContent)
if (sibling) {
if (sibling != inCheckedContent) { // skip this node
// if the current sibling is in the same group, clear it
nsAutoString currGroupName;
sibling->GetAttr(kNameSpaceID_None, nsWidgetAtoms::name, currGroupName);
if (currGroupName == myGroupName)
if (sibling->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::name,
myGroupName, eCaseMatters))
sibling->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, NS_LITERAL_STRING("false"), PR_TRUE);
}
}
@ -411,9 +410,8 @@ nsMenuItemX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIA
// if we're a radio menu, uncheck our sibling radio items. No need to
// do any of this if we're just a normal check menu.
if (mMenuType == eRadio) {
nsAutoString checked;
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, checked);
if (checked.EqualsLiteral("true"))
if (mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
nsWidgetAtoms::_true, eCaseMatters))
UncheckRadioSiblings(mContent);
}
nsCOMPtr<nsIMenuListener> listener = do_QueryInterface(mMenuParent);

Просмотреть файл

@ -147,10 +147,10 @@ nsMenuX::Create(nsISupports * aParent, const nsAString &aLabel, const nsAString
SetLabel(aLabel);
nsAutoString hiddenValue, collapsedValue;
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hiddenValue);
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::collapsed, collapsedValue);
if (hiddenValue.EqualsLiteral("true") || collapsedValue.EqualsLiteral("true"))
if (mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters) ||
mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::collapsed,
nsWidgetAtoms::_true, eCaseMatters))
mVisible = PR_FALSE;
if (menubar && mMenuContent->GetChildCount() == 0)
@ -584,33 +584,31 @@ void nsMenuX::LoadMenuItem(nsIMenu* inParentMenu, nsIContent* inMenuItemContent)
return;
// if menu should be hidden, bail
nsAutoString hidden;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
if (hidden.EqualsLiteral("true"))
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters))
return;
// create nsMenuItem
nsCOMPtr<nsIMenuItem> pnsMenuItem = do_CreateInstance(kMenuItemCID);
if (pnsMenuItem) {
nsAutoString disabled;
nsAutoString checked;
nsAutoString type;
nsAutoString menuitemName;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, disabled);
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, checked);
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::type, type);
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuitemName);
// printf("menuitem %s \n", NS_LossyConvertUTF16toASCII(menuitemName).get());
PRBool enabled = !(disabled.EqualsLiteral("true"));
PRBool enabled =
! (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
nsWidgetAtoms::_true, eCaseMatters));
static nsIContent::AttrValuesArray strings[] =
{&nsWidgetAtoms::checkbox, &nsWidgetAtoms::radio, nsnull};
nsIMenuItem::EMenuItemType itemType = nsIMenuItem::eRegular;
if (type.EqualsLiteral("checkbox"))
itemType = nsIMenuItem::eCheckbox;
else if (type.EqualsLiteral("radio"))
itemType = nsIMenuItem::eRadio;
switch (inMenuItemContent->FindAttrValueIn(kNameSpaceID_None, nsWidgetAtoms::type,
strings, eCaseMatters)) {
case 0: itemType = nsIMenuItem::eCheckbox; break;
case 1: itemType = nsIMenuItem::eRadio; break;
}
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
if (!docShell)
@ -650,7 +648,8 @@ void nsMenuX::LoadMenuItem(nsIMenu* inParentMenu, nsIContent* inMenuItemContent)
pnsMenuItem->SetModifiers(modifiers);
}
if (checked.EqualsLiteral("true"))
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
nsWidgetAtoms::_true, eCaseMatters))
pnsMenuItem->SetChecked(PR_TRUE);
else
pnsMenuItem->SetChecked(PR_FALSE);
@ -665,9 +664,8 @@ void
nsMenuX::LoadSubMenu(nsIMenu * pParentMenu, nsIContent* inMenuItemContent)
{
// if menu should be hidden, bail
nsAutoString hidden;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
if (hidden.EqualsLiteral("true"))
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters))
return;
nsAutoString menuName;
@ -685,9 +683,8 @@ nsMenuX::LoadSubMenu(nsIMenu * pParentMenu, nsIContent* inMenuItemContent)
pnsMenu->Create(supports, menuName, EmptyString(), mManager, docShell, inMenuItemContent);
// set if it's enabled or disabled
nsAutoString disabled;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, disabled);
if (disabled.EqualsLiteral("true"))
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
nsWidgetAtoms::_true, eCaseMatters))
pnsMenu->SetEnabled(PR_FALSE);
else
pnsMenu->SetEnabled(PR_TRUE);
@ -703,9 +700,8 @@ void
nsMenuX::LoadSeparator(nsIContent* inMenuItemContent)
{
// if item should be hidden, bail
nsAutoString hidden;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
if (hidden.EqualsLiteral("true"))
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters))
return;
AddSeparator();
@ -974,12 +970,11 @@ nsMenuX::CountVisibleBefore(PRUint32* outVisibleBefore)
nsCOMPtr<nsIContent> menuContent;
currMenu->GetMenuContent(getter_AddRefs(menuContent));
if (menuContent) {
nsAutoString hiddenValue, collapsedValue;
menuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hiddenValue);
menuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::collapsed, collapsedValue);
if (menuContent->GetChildCount() > 0 ||
!hiddenValue.EqualsLiteral("true") &&
!collapsedValue.EqualsLiteral("true")) {
!menuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters) &&
!menuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::collapsed,
nsWidgetAtoms::_true, eCaseMatters)) {
++(*outVisibleBefore);
}
}
@ -1008,9 +1003,8 @@ nsMenuX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIAtom
if (aAttribute == nsWidgetAtoms::disabled) {
SetRebuild(PR_TRUE);
nsAutoString valueString;
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, valueString);
if (valueString.EqualsLiteral("true"))
if (mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
nsWidgetAtoms::_true, eCaseMatters))
SetEnabled(PR_FALSE);
else
SetEnabled(PR_TRUE);
@ -1038,12 +1032,11 @@ nsMenuX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIAtom
}
else if (aAttribute == nsWidgetAtoms::hidden || aAttribute == nsWidgetAtoms::collapsed) {
SetRebuild(PR_TRUE);
nsAutoString hiddenValue, collapsedValue;
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hiddenValue);
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::collapsed, collapsedValue);
if (hiddenValue.EqualsLiteral("true") || collapsedValue.EqualsLiteral("true")) {
if (mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters) ||
mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::collapsed,
nsWidgetAtoms::_true, eCaseMatters)) {
if (mVisible) {
if (menubarParent) {
PRUint32 indexToRemove = 0;

Просмотреть файл

@ -417,9 +417,8 @@ nsNativeScrollbar::SetContent(nsIContent* inContent, nsISupports* inScrollbar,
// we may have to re-create the scrollbar view as horizontal. Check the
// 'orient' attribute and rebuild the view with all the settings
// present in the current view
nsAutoString orient;
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::orient, orient);
if ( orient.Equals(NS_LITERAL_STRING("horizontal")) )
if (mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::orient,
nsWidgetAtoms::horizontal, eCaseMatters))
RecreateHorizontalScrollbar();
}

Просмотреть файл

@ -143,6 +143,7 @@ endif
LOCAL_INCLUDES = \
-I$(srcdir)/../xpwidgets \
-I$(srcdir)/../../public \
-I$(srcdir) \
-I$(topsrcdir)/gfx/src/gtk \
$(NULL)

Просмотреть файл

@ -55,6 +55,7 @@
#include "nsTransform2D.h"
#include "nsIMenuFrame.h"
#include "nsIMenuParent.h"
#include "nsWidgetAtoms.h"
#include "prlink.h"
#include <gdk/gdkprivate.h>
@ -77,12 +78,6 @@ nsNativeThemeGTK::nsNativeThemeGTK()
do_GetService("@mozilla.org/observer-service;1");
obsServ->AddObserver(this, "xpcom-shutdown", PR_FALSE);
mInputCheckedAtom = do_GetAtom("_moz-input-checked");
mInputAtom = do_GetAtom("input");
mCurPosAtom = do_GetAtom("curpos");
mMaxPosAtom = do_GetAtom("maxpos");
mMenuActiveAtom = do_GetAtom("_moz-menuactive");
memset(mDisabledWidgetTypes, 0, sizeof(mDisabledWidgetTypes));
memset(mSafeWidgetStates, 0, sizeof(mSafeWidgetStates));
@ -199,13 +194,15 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
// widgets, so don't adjust stateFrame here.
aFrame = aFrame->GetParent();
}
} else if (content->Tag() == mInputAtom) {
atom = mInputCheckedAtom;
} else if (content->Tag() == nsWidgetAtoms::input) {
atom = nsWidgetAtoms::mozinputchecked;
}
if (aWidgetFlags) {
if (!atom) {
atom = (aWidgetType == NS_THEME_CHECKBOX || aWidgetType == NS_THEME_CHECKBOX_LABEL) ? mCheckedAtom : mSelectedAtom;
atom = (aWidgetType == NS_THEME_CHECKBOX ||
aWidgetType == NS_THEME_CHECKBOX_LABEL) ? nsWidgetAtoms::checked
: nsWidgetAtoms::selected;
}
*aWidgetFlags = CheckBooleanAttr(aFrame, atom);
}
@ -237,8 +234,8 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
// the slider to the actual scrollbar object
nsIFrame *tmpFrame = aFrame->GetParent()->GetParent();
aState->curpos = CheckIntAttr(tmpFrame, mCurPosAtom);
aState->maxpos = CheckIntAttr(tmpFrame, mMaxPosAtom);
aState->curpos = CheckIntAttr(tmpFrame, nsWidgetAtoms::curpos);
aState->maxpos = CheckIntAttr(tmpFrame, nsWidgetAtoms::maxpos);
}
// menu item state is determined by the attribute "_moz-menuactive",
@ -264,7 +261,7 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
menuFrame->MenuIsOpen(isOpen);
aState->inHover = isOpen;
} else {
aState->inHover = CheckBooleanAttr(aFrame, mMenuActiveAtom);
aState->inHover = CheckBooleanAttr(aFrame, nsWidgetAtoms::mozmenuactive);
}
aState->active = FALSE;
@ -272,8 +269,8 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
if (aWidgetType == NS_THEME_CHECKMENUITEM ||
aWidgetType == NS_THEME_RADIOMENUITEM) {
*aWidgetFlags = aFrame && aFrame->GetContent()->
AttrValueIs(kNameSpaceID_None, mCheckedAtom,
NS_LITERAL_STRING("true"), eIgnoreCase);
AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
nsWidgetAtoms::_true, eIgnoreCase);
}
}
}
@ -366,12 +363,13 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
*aWidgetFlags = 0;
if (aWidgetType == NS_THEME_TAB &&
CheckBooleanAttr(aFrame, mSelectedAtom))
CheckBooleanAttr(aFrame, nsWidgetAtoms::selected))
*aWidgetFlags |= MOZ_GTK_TAB_SELECTED;
else if (aWidgetType == NS_THEME_TAB_LEFT_EDGE)
*aWidgetFlags |= MOZ_GTK_TAB_BEFORE_SELECTED;
if (aFrame->GetContent()->HasAttr(kNameSpaceID_None, mFirstTabAtom))
if (aFrame->GetContent()->HasAttr(kNameSpaceID_None,
nsWidgetAtoms::firsttab))
*aWidgetFlags |= MOZ_GTK_TAB_FIRST;
}
@ -693,9 +691,11 @@ nsNativeThemeGTK::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
// Check the attribute to see if it's relevant.
// disabled, checked, dlgtype, default, etc.
*aShouldRepaint = PR_FALSE;
if (aAttribute == mDisabledAtom || aAttribute == mCheckedAtom ||
aAttribute == mSelectedAtom || aAttribute == mFocusedAtom ||
aAttribute == mMenuActiveAtom)
if (aAttribute == nsWidgetAtoms::disabled ||
aAttribute == nsWidgetAtoms::checked ||
aAttribute == nsWidgetAtoms::selected ||
aAttribute == nsWidgetAtoms::focused ||
aAttribute == nsWidgetAtoms::mozmenuactive)
*aShouldRepaint = PR_TRUE;
}

Просмотреть файл

@ -97,13 +97,6 @@ private:
void RefreshWidgetWindow(nsIFrame* aFrame);
nsCOMPtr<nsIAtom> mTypeAtom;
nsCOMPtr<nsIAtom> mInputCheckedAtom;
nsCOMPtr<nsIAtom> mInputAtom;
nsCOMPtr<nsIAtom> mCurPosAtom;
nsCOMPtr<nsIAtom> mMaxPosAtom;
nsCOMPtr<nsIAtom> mMenuActiveAtom;
PRUint8 mDisabledWidgetTypes[32];
PRUint8 mSafeWidgetStates[1024]; // 256 widgets * 32 bits per widget
static const char* sDisabledEngines[];

Просмотреть файл

@ -130,7 +130,7 @@ EXTRA_DSO_LDOPTS += -lthebes
endif
EXPORTS = \
nsIGdkPixbufImage.h \
nsIGdkPixbufImage.h \
mozdrawingarea.h \
mozcontainer.h \
$(NULL)
@ -161,6 +161,7 @@ endif
DEFINES +=
INCLUDES += \
-I$(srcdir)/../xpwidgets \
-I$(srcdir)/../../public \
$(NULL)
test_container: mozdrawingarea.o mozcontainer.o test_container.c

Просмотреть файл

@ -57,6 +57,7 @@
#include "nsIMenuParent.h"
#include "prlink.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsWidgetAtoms.h"
#include <gdk/gdkprivate.h>
#include <gdk/gdkx.h>
@ -83,12 +84,6 @@ nsNativeThemeGTK::nsNativeThemeGTK()
do_GetService("@mozilla.org/observer-service;1");
obsServ->AddObserver(this, "xpcom-shutdown", PR_FALSE);
mInputCheckedAtom = do_GetAtom("_moz-input-checked");
mInputAtom = do_GetAtom("input");
mCurPosAtom = do_GetAtom("curpos");
mMaxPosAtom = do_GetAtom("maxpos");
mMenuActiveAtom = do_GetAtom("_moz-menuactive");
memset(mDisabledWidgetTypes, 0, sizeof(mDisabledWidgetTypes));
memset(mSafeWidgetStates, 0, sizeof(mSafeWidgetStates));
@ -207,7 +202,9 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
}
if (aWidgetFlags) {
if (!atom) {
atom = (aWidgetType == NS_THEME_CHECKBOX || aWidgetType == NS_THEME_CHECKBOX_LABEL) ? mCheckedAtom : mSelectedAtom;
atom = (aWidgetType == NS_THEME_CHECKBOX ||
aWidgetType == NS_THEME_CHECKBOX_LABEL) ? nsWidgetAtoms::checked
: nsWidgetAtoms::selected;
}
*aWidgetFlags = CheckBooleanAttr(aFrame, atom);
}
@ -249,8 +246,8 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
// the slider to the actual scrollbar object
nsIFrame *tmpFrame = aFrame->GetParent()->GetParent();
aState->curpos = CheckIntAttr(tmpFrame, mCurPosAtom);
aState->maxpos = CheckIntAttr(tmpFrame, mMaxPosAtom);
aState->curpos = CheckIntAttr(tmpFrame, nsWidgetAtoms::curpos);
aState->maxpos = CheckIntAttr(tmpFrame, nsWidgetAtoms::maxpos);
}
// menu item state is determined by the attribute "_moz-menuactive",
@ -276,7 +273,7 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
menuFrame->MenuIsOpen(isOpen);
aState->inHover = isOpen;
} else {
aState->inHover = CheckBooleanAttr(aFrame, mMenuActiveAtom);
aState->inHover = CheckBooleanAttr(aFrame, nsWidgetAtoms::mozmenuactive);
}
aState->active = FALSE;
@ -284,8 +281,8 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
if (aWidgetType == NS_THEME_CHECKMENUITEM ||
aWidgetType == NS_THEME_RADIOMENUITEM) {
*aWidgetFlags = aFrame && aFrame->GetContent()->
AttrValueIs(kNameSpaceID_None, mCheckedAtom,
NS_LITERAL_STRING("true"), eIgnoreCase);
AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
nsWidgetAtoms::_true, eIgnoreCase);
}
}
}
@ -378,12 +375,13 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
*aWidgetFlags = 0;
if (aWidgetType == NS_THEME_TAB &&
CheckBooleanAttr(aFrame, mSelectedAtom))
CheckBooleanAttr(aFrame, nsWidgetAtoms::selected))
*aWidgetFlags |= MOZ_GTK_TAB_SELECTED;
else if (aWidgetType == NS_THEME_TAB_LEFT_EDGE)
*aWidgetFlags |= MOZ_GTK_TAB_BEFORE_SELECTED;
if (aFrame->GetContent()->HasAttr(kNameSpaceID_None, mFirstTabAtom))
if (aFrame->GetContent()->HasAttr(kNameSpaceID_None,
nsWidgetAtoms::firsttab))
*aWidgetFlags |= MOZ_GTK_TAB_FIRST;
}
@ -872,9 +870,11 @@ nsNativeThemeGTK::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
// Check the attribute to see if it's relevant.
// disabled, checked, dlgtype, default, etc.
*aShouldRepaint = PR_FALSE;
if (aAttribute == mDisabledAtom || aAttribute == mCheckedAtom ||
aAttribute == mSelectedAtom || aAttribute == mFocusedAtom ||
aAttribute == mMenuActiveAtom)
if (aAttribute == nsWidgetAtoms::disabled ||
aAttribute == nsWidgetAtoms::checked ||
aAttribute == nsWidgetAtoms::selected ||
aAttribute == nsWidgetAtoms::focused ||
aAttribute == nsWidgetAtoms::mozmenuactive)
*aShouldRepaint = PR_TRUE;
}

Просмотреть файл

@ -97,13 +97,6 @@ private:
void RefreshWidgetWindow(nsIFrame* aFrame);
nsCOMPtr<nsIAtom> mTypeAtom;
nsCOMPtr<nsIAtom> mInputCheckedAtom;
nsCOMPtr<nsIAtom> mInputAtom;
nsCOMPtr<nsIAtom> mCurPosAtom;
nsCOMPtr<nsIAtom> mMaxPosAtom;
nsCOMPtr<nsIAtom> mMenuActiveAtom;
PRUint8 mDisabledWidgetTypes[32];
PRUint8 mSafeWidgetStates[1024]; // 256 widgets * 32 bits per widget
static const char* sDisabledEngines[];

Просмотреть файл

@ -443,9 +443,8 @@ nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWin
// Make nsMenu a child of nsMenuBar. nsMenuBar takes ownership
AddMenu(pnsMenu);
nsAutoString menuIDstring;
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::id, menuIDstring);
if ( menuIDstring.EqualsLiteral("menu_Help") ) {
if (menu->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::id,
NS_LITERAL_STRING("menu_Help"), eCaseMatters)) {
nsMenuEvent event(PR_TRUE, 0, nsnull);
nsCOMPtr<nsIMenuListener> listener(do_QueryInterface(pnsMenu));
listener->MenuSelected(event);
@ -529,9 +528,9 @@ NS_METHOD nsMenuBarX::AddMenu(nsIMenu * aMenu)
if(!helpMenu) {
nsCOMPtr<nsIContent> menu;
aMenu->GetMenuContent(getter_AddRefs(menu));
nsAutoString menuHidden;
menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, menuHidden);
if(!menuHidden.EqualsLiteral("true") && menu->GetChildCount() > 0) {
if(!menu->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters) &&
menu->GetChildCount() > 0) {
// make sure we only increment |mNumMenus| if the menu is visible, since
// we use it as an index of where to insert the next menu.
mNumMenus++;

Просмотреть файл

@ -257,9 +257,8 @@ NS_METHOD nsMenuItemX::DoCommand()
{
// flip "checked" state if we're a checkbox menu, or an un-checked radio menu
if (mMenuType == nsIMenuItem::eCheckbox || (mMenuType == nsIMenuItem::eRadio && !mIsChecked)) {
nsAutoString value;
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::autocheck, value);
if (!value.EqualsLiteral("false"))
if (!mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::autocheck,
nsWidgetAtoms::_false, eCaseMatters))
SetChecked(!mIsChecked);
/* the AttributeChanged code will update all the internal state */
}
@ -365,9 +364,8 @@ nsMenuItemX :: UncheckRadioSiblings(nsIContent* inCheckedContent)
if ( sibling ) {
if ( sibling != inCheckedContent ) { // skip this node
// if the current sibling is in the same group, clear it
nsAutoString currGroupName;
sibling->GetAttr(kNameSpaceID_None, nsWidgetAtoms::name, currGroupName);
if ( currGroupName == myGroupName )
if (sibling->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::name,
myGroupName, eCaseMatters))
sibling->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, NS_LITERAL_STRING("false"), PR_TRUE);
}
}
@ -389,9 +387,8 @@ nsMenuItemX :: AttributeChanged ( nsIDocument *aDocument, PRInt32 aNameSpaceID,
// if we're a radio menu, uncheck our sibling radio items. No need to
// do any of this if we're just a normal check menu.
if ( mMenuType == eRadio ) {
nsAutoString checked;
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, checked);
if (checked.EqualsLiteral("true") )
if (mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
nsWidgetAtoms::_true, eCaseMatters))
UncheckRadioSiblings(mContent);
}

Просмотреть файл

@ -165,10 +165,10 @@ nsMenuX::Create(nsISupports * aParent, const nsAString &aLabel, const nsAString
SetLabel(aLabel);
SetAccessKey(aAccessKey);
nsAutoString hiddenValue, collapsedValue;
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hiddenValue);
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::collapsed, collapsedValue);
if ( hiddenValue.EqualsLiteral("true") || collapsedValue.EqualsLiteral("true") )
if (mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters) ||
mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::collapsed,
nsWidgetAtoms::_true, eCaseMatters))
mVisible = PR_FALSE;
if (menubar && mMenuContent->GetChildCount() == 0)
@ -816,25 +816,16 @@ void nsMenuX::LoadMenuItem( nsIMenu* inParentMenu, nsIContent* inMenuItemContent
return;
// if menu should be hidden, bail
nsAutoString hidden;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
if ( hidden.EqualsLiteral("true") )
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters))
return;
// Create nsMenuItem
nsCOMPtr<nsIMenuItem> pnsMenuItem = do_CreateInstance ( kMenuItemCID ) ;
if ( pnsMenuItem ) {
nsAutoString disabled;
nsAutoString checked;
nsAutoString type;
nsAutoString menuitemName;
nsAutoString menuitemCmd;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, disabled);
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, checked);
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::type, type);
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuitemName);
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, menuitemCmd);
// Bug 164155 - Carbon interprets a leading hyphen on a menu item as
// a separator. We want a real menu item, so "escape" the hyphen by inserting
@ -844,13 +835,18 @@ void nsMenuX::LoadMenuItem( nsIMenu* inParentMenu, nsIContent* inMenuItemContent
//printf("menuitem %s \n", NS_LossyConvertUTF16toASCII(menuitemName).get());
PRBool enabled = ! (disabled.EqualsLiteral("true"));
PRBool enabled =
! (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
nsWidgetAtoms::_true, eCaseMatters));
static nsIContent::AttrValuesArray strings[] =
{&nsWidgetAtoms::checkbox, &nsWidgetAtoms::radio, nsnull};
nsIMenuItem::EMenuItemType itemType = nsIMenuItem::eRegular;
if ( type.EqualsLiteral("checkbox") )
itemType = nsIMenuItem::eCheckbox;
else if ( type.EqualsLiteral("radio") )
itemType = nsIMenuItem::eRadio;
switch (inMenuItemContent->FindAttrValueIn(kNameSpaceID_None, nsWidgetAtoms::type,
strings, eCaseMatters)) {
case 0: itemType = nsIMenuItem::eCheckbox; break;
case 1: itemType = nsIMenuItem::eRadio; break;
}
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShellWeakRef);
if (!docShell)
@ -908,7 +904,8 @@ void nsMenuX::LoadMenuItem( nsIMenu* inParentMenu, nsIContent* inMenuItemContent
pnsMenuItem->SetModifiers ( modifiers );
}
if ( checked.EqualsLiteral("true") )
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
nsWidgetAtoms::_true, eCaseMatters))
pnsMenuItem->SetChecked(PR_TRUE);
else
pnsMenuItem->SetChecked(PR_FALSE);
@ -923,9 +920,8 @@ void
nsMenuX::LoadSubMenu( nsIMenu * pParentMenu, nsIContent* inMenuItemContent )
{
// if menu should be hidden, bail
nsAutoString hidden;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
if ( hidden.EqualsLiteral("true") )
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters))
return;
nsAutoString menuName;
@ -943,9 +939,8 @@ nsMenuX::LoadSubMenu( nsIMenu * pParentMenu, nsIContent* inMenuItemContent )
pnsMenu->Create(supports, menuName, EmptyString(), mManager, docShell, inMenuItemContent);
// set if it's enabled or disabled
nsAutoString disabled;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, disabled);
if ( disabled.EqualsLiteral("true") )
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
nsWidgetAtoms::_true, eCaseMatters))
pnsMenu->SetEnabled ( PR_FALSE );
else
pnsMenu->SetEnabled ( PR_TRUE );
@ -961,9 +956,8 @@ void
nsMenuX::LoadSeparator ( nsIContent* inMenuItemContent )
{
// if item should be hidden, bail
nsAutoString hidden;
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hidden);
if ( hidden.EqualsLiteral("true") )
if (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters))
return;
AddSeparator();
@ -1231,12 +1225,11 @@ nsMenuX :: CountVisibleBefore ( PRUint32* outVisibleBefore )
nsCOMPtr<nsIContent> menuContent;
currMenu->GetMenuContent(getter_AddRefs(menuContent));
if ( menuContent ) {
nsAutoString hiddenValue, collapsedValue;
menuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hiddenValue);
menuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::collapsed, collapsedValue);
if ( menuContent->GetChildCount() > 0 ||
!hiddenValue.EqualsLiteral("true") &&
!collapsedValue.EqualsLiteral("true"))
!menuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters) &&
!menuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::collapsed,
nsWidgetAtoms::_true, eCaseMatters))
++(*outVisibleBefore);
}
}
@ -1270,9 +1263,8 @@ nsMenuX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIAtom
if (aAttribute == nsWidgetAtoms::disabled) {
SetRebuild(PR_TRUE);
nsAutoString valueString;
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, valueString);
if (valueString.EqualsLiteral("true"))
if (mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
nsWidgetAtoms::_true, eCaseMatters))
SetEnabled(PR_FALSE);
else
SetEnabled(PR_TRUE);
@ -1306,11 +1298,10 @@ nsMenuX::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIAtom
else if (aAttribute == nsWidgetAtoms::hidden || aAttribute == nsWidgetAtoms::collapsed) {
SetRebuild(PR_TRUE);
nsAutoString hiddenValue, collapsedValue;
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::hidden, hiddenValue);
mMenuContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::collapsed, collapsedValue);
if (hiddenValue.EqualsLiteral("true") || collapsedValue.EqualsLiteral("true")) {
if (mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::hidden,
nsWidgetAtoms::_true, eCaseMatters) ||
mMenuContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::collapsed,
nsWidgetAtoms::_true, eCaseMatters)) {
if ( mVisible ) {
if ( menubarParent ) {
PRUint32 indexToRemove = 0;

Просмотреть файл

@ -56,6 +56,7 @@
#include "nsRegionPool.h"
#include "nsGfxUtils.h"
#include "nsUnicharUtils.h"
#include "nsWidgetAtoms.h"
static PRBool sInitializedBorders = PR_FALSE;
@ -112,8 +113,6 @@ nsNativeThemeMac::nsNativeThemeMac()
sListboxBGTransparent = PR_TRUE;
sTextfieldDisabledBGColorID = nsILookAndFeel::eColor__moz_field;
}
mMenuActiveAtom = do_GetAtom("_moz-menuactive");
}
nsNativeThemeMac::~nsNativeThemeMac()
@ -375,7 +374,8 @@ nsNativeThemeMac::DrawWidgetBackground(nsIRenderingContext* aContext, nsIFrame*
case NS_THEME_MENUITEM:
::SetThemeBackground(kThemeBrushDialogBackgroundActive, 24, true);
DrawMenuItem(macRect, kThemeMenuItemPlain, IsDisabled(aFrame), CheckBooleanAttr(aFrame, mMenuActiveAtom));
DrawMenuItem(macRect, kThemeMenuItemPlain, IsDisabled(aFrame),
CheckBooleanAttr(aFrame, nsWidgetAtoms::mozmenuactive));
::SetThemeBackground(kThemeBrushWhite, 24, true);
break;
@ -764,9 +764,11 @@ nsNativeThemeMac::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
// Check the attribute to see if it's relevant.
// disabled, checked, dlgtype, default, etc.
*aShouldRepaint = PR_FALSE;
if (aAttribute == mDisabledAtom || aAttribute == mCheckedAtom ||
aAttribute == mSelectedAtom || aAttribute == mMenuActiveAtom ||
aAttribute == mSortDirectionAtom)
if (aAttribute == nsWidgetAtoms::disabled ||
aAttribute == nsWidgetAtoms::checked ||
aAttribute == nsWidgetAtoms::selected ||
aAttribute == nsWidgetAtoms::mozmenuactive ||
aAttribute == nsWidgetAtoms::sortdirection)
*aShouldRepaint = PR_TRUE;
}

Просмотреть файл

@ -121,5 +121,4 @@ protected:
private:
ThemeEraseUPP mEraseProc;
nsCOMPtr<nsIAtom> mMenuActiveAtom;
};

Просмотреть файл

@ -117,7 +117,12 @@ endif # BUILD_STATIC_LIBS
EXPORTS = nsdefs.h
LOCAL_INCLUDES = -I. -I$(srcdir)/../xpwidgets -I$(srcdir)
LOCAL_INCLUDES = \
-I. \
-I$(srcdir)/../xpwidgets \
-I$(srcdir)/../../public \
-I$(srcdir) \
$(NULL)
FORCE_STATIC_LIB = 1

Просмотреть файл

@ -56,6 +56,7 @@
#include "nsIDOMHTMLInputElement.h"
#include "nsIMenuFrame.h"
#include "nsIMenuParent.h"
#include "nsWidgetAtoms.h"
#include <malloc.h>
#ifdef MOZ_CAIRO_GFX
@ -202,11 +203,6 @@ nsNativeThemeWin::nsNativeThemeWin() {
getThemeColor = (GetThemeColorPtr)GetProcAddress(mThemeDLL, "GetThemeColor");
}
mInputAtom = do_GetAtom("input");
mInputCheckedAtom = do_GetAtom("_moz-input-checked");
mTypeAtom = do_GetAtom("type");
mMenuActiveAtom = do_GetAtom("_moz-menuactive");
UpdateConfig();
// If there is a relevant change in forms.css for windows platform,
@ -388,7 +384,8 @@ nsNativeThemeWin::GetThemePartAndState(nsIFrame* aFrame, PRUint8 aWidgetType,
// XXXdwh This check will need to be more complicated, since HTML radio groups
// use checked, but XUL radio groups use selected. There will need to be an
// IsNodeOfType test for HTML vs. XUL here.
nsIAtom* atom = (aWidgetType == NS_THEME_CHECKBOX) ? mCheckedAtom : mSelectedAtom;
nsIAtom* atom = (aWidgetType == NS_THEME_CHECKBOX) ? nsWidgetAtoms::checked
: nsWidgetAtoms::selected;
PRBool isHTML = PR_FALSE;
PRBool isHTMLChecked = PR_FALSE;
@ -1070,9 +1067,11 @@ nsNativeThemeWin::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType,
// Check the attribute to see if it's relevant.
// disabled, checked, dlgtype, default, etc.
*aShouldRepaint = PR_FALSE;
if (aAttribute == mDisabledAtom || aAttribute == mCheckedAtom ||
aAttribute == mSelectedAtom || aAttribute == mReadOnlyAtom ||
aAttribute == mMenuActiveAtom)
if (aAttribute == nsWidgetAtoms::disabled ||
aAttribute == nsWidgetAtoms::checked ||
aAttribute == nsWidgetAtoms::selected ||
aAttribute == nsWidgetAtoms::readonly ||
aAttribute == nsWidgetAtoms::mozmenuactive)
*aShouldRepaint = PR_TRUE;
}
@ -1520,7 +1519,7 @@ nsresult nsNativeThemeWin::ClassicGetThemePartAndState(nsIFrame* aFrame, PRUint8
aState |= DFCS_RTL;
}
if (CheckBooleanAttr(aFrame, mMenuActiveAtom))
if (CheckBooleanAttr(aFrame, nsWidgetAtoms::mozmenuactive))
aState |= DFCS_HOT;
// Only menu items of the appropriate type may have tick or bullet marks.

Просмотреть файл

@ -127,11 +127,6 @@ private:
HANDLE mHeaderTheme;
BOOL mFlatMenus;
nsCOMPtr<nsIAtom> mInputAtom;
nsCOMPtr<nsIAtom> mInputCheckedAtom;
nsCOMPtr<nsIAtom> mTypeAtom;
nsCOMPtr<nsIAtom> mMenuActiveAtom;
};
// Creator function

Просмотреть файл

@ -77,15 +77,12 @@ CPPSRCS = \
nsPrimitiveHelpers.cpp \
nsXPLookAndFeel.cpp \
nsClipboardHelper.cpp \
nsPrintOptionsImpl.cpp \
nsPrintOptionsImpl.cpp \
nsPrintSettingsImpl.cpp \
nsPrintSession.cpp \
nsPrintSession.cpp \
nsWidgetAtoms.cpp \
$(NULL)
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
CPPSRCS += nsWidgetAtoms.cpp
endif
ifneq (,$(filter beos os2 mac qt cocoa windows,$(MOZ_WIDGET_TOOLKIT)))
CPPSRCS += nsBaseClipboard.cpp
endif
@ -101,6 +98,7 @@ endif
LOCAL_INCLUDES = \
-I$(srcdir)/../$(MOZ_WIDGET_TOOLKIT) \
-I$(srcdir)/../../public \
-I$(srcdir) \
$(NULL)

Просмотреть файл

@ -73,17 +73,6 @@ nsILookAndFeel::nsColorID nsNativeTheme::sListboxDisabledBGColorID = nsILookAndF
nsNativeTheme::nsNativeTheme()
{
mDisabledAtom = do_GetAtom("disabled");
mCheckedAtom = do_GetAtom("checked");
mSelectedAtom = do_GetAtom("selected");
mFocusedAtom = do_GetAtom("focused");
mFirstTabAtom = do_GetAtom("first-tab");
mDefaultAtom = do_GetAtom("default");
mValueAtom = do_GetAtom("value");
mModeAtom = do_GetAtom("mode");
mClassAtom = do_GetAtom("class");
mSortDirectionAtom = do_GetAtom("sortDirection");
mReadOnlyAtom = do_GetAtom("readonly");
}
nsIPresShell *
@ -157,16 +146,6 @@ nsNativeTheme::CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom)
return value;
}
PRBool
nsNativeTheme::GetAttr(nsIFrame* aFrame, nsIAtom* aAtom, nsAString& attrValue)
{
if (!aFrame)
return PR_FALSE;
aFrame->GetContent()->GetAttr(kNameSpaceID_None, aAtom, attrValue);
return !attrValue.IsEmpty();
}
PRBool
nsNativeTheme::GetCheckedOrSelected(nsIFrame* aFrame, PRBool aCheckSelected)
{
@ -189,7 +168,8 @@ nsNativeTheme::GetCheckedOrSelected(nsIFrame* aFrame, PRBool aCheckSelected)
}
}
return CheckBooleanAttr(aFrame, aCheckSelected ? mSelectedAtom : mCheckedAtom);
return CheckBooleanAttr(aFrame, aCheckSelected ? nsWidgetAtoms::selected
: nsWidgetAtoms::checked);
}
static void
@ -317,3 +297,47 @@ nsNativeTheme::IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
return PR_FALSE;
}
// treeheadercell:
nsNativeTheme::TreeSortDirection
nsNativeTheme::GetTreeSortDirection(nsIFrame* aFrame)
{
if (!aFrame)
return eTreeSortDirection_Natural;
static nsIContent::AttrValuesArray strings[] =
{&nsWidgetAtoms::descending, &nsWidgetAtoms::ascending, nsnull};
switch (aFrame->GetContent()->FindAttrValueIn(kNameSpaceID_None,
nsWidgetAtoms::sortdirection,
strings, eCaseMatters)) {
case 0: return eTreeSortDirection_Descending;
case 1: return eTreeSortDirection_Ascending;
}
return eTreeSortDirection_Natural;
}
// tab:
PRBool
nsNativeTheme::IsBottomTab(nsIFrame* aFrame)
{
if (!aFrame)
return PR_FALSE;
nsAutoString classStr;
aFrame->GetContent()->GetAttr(kNameSpaceID_None, nsWidgetAtoms::_class, classStr);
return !classStr.IsEmpty() && classStr.Find("tab-bottom") != kNotFound;
}
// progressbar:
PRBool
nsNativeTheme::IsIndeterminateProgress(nsIFrame* aFrame)
{
if (!aFrame)
return PR_FALSE;
// return aFrame->GetContent()->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::mode,
// NS_LITERAL_STRING("undetermined"),
// eCaseMatters);
return PR_TRUE;
}

Просмотреть файл

@ -45,6 +45,7 @@
#include "nsString.h"
#include "nsMargin.h"
#include "nsILookAndFeel.h"
#include "nsWidgetAtoms.h"
class nsIFrame;
class nsIPresShell;
@ -75,12 +76,12 @@ class nsNativeTheme
// all widgets:
PRBool IsDisabled(nsIFrame* aFrame) {
return CheckBooleanAttr(aFrame, mDisabledAtom);
return CheckBooleanAttr(aFrame, nsWidgetAtoms::disabled);
}
// button:
PRBool IsDefaultButton(nsIFrame* aFrame) {
return CheckBooleanAttr(aFrame, mDefaultAtom);
return CheckBooleanAttr(aFrame, nsWidgetAtoms::_default);
}
// checkbox:
@ -94,55 +95,35 @@ class nsNativeTheme
}
PRBool IsFocused(nsIFrame* aFrame) {
return CheckBooleanAttr(aFrame, mFocusedAtom);
return CheckBooleanAttr(aFrame, nsWidgetAtoms::focused);
}
// tab:
PRBool IsSelectedTab(nsIFrame* aFrame) {
return CheckBooleanAttr(aFrame, mSelectedAtom);
return CheckBooleanAttr(aFrame, nsWidgetAtoms::selected);
}
// toolbarbutton:
PRBool IsCheckedButton(nsIFrame* aFrame) {
return CheckBooleanAttr(aFrame, mCheckedAtom);
return CheckBooleanAttr(aFrame, nsWidgetAtoms::checked);
}
// treeheadercell:
TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame) {
nsAutoString sortdir;
if (GetAttr(aFrame, mSortDirectionAtom, sortdir)) {
if (sortdir.EqualsLiteral("descending"))
return eTreeSortDirection_Descending;
else if (sortdir.EqualsLiteral("ascending"))
return eTreeSortDirection_Ascending;
}
return eTreeSortDirection_Natural;
}
TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
// tab:
PRBool IsBottomTab(nsIFrame* aFrame) {
nsAutoString classStr;
if (GetAttr(aFrame, mClassAtom, classStr))
return classStr.Find("tab-bottom") != kNotFound;
return PR_FALSE;
}
PRBool IsBottomTab(nsIFrame* aFrame);
// progressbar:
PRBool IsIndeterminateProgress(nsIFrame* aFrame) {
nsAutoString mode;
if (GetAttr(aFrame, mModeAtom, mode))
return mode.EqualsLiteral("undetermined");
return PR_FALSE;
}
PRBool IsIndeterminateProgress(nsIFrame* aFrame);
PRInt32 GetProgressValue(nsIFrame* aFrame) {
return CheckIntAttr(aFrame, mValueAtom);
return CheckIntAttr(aFrame, nsWidgetAtoms::value);
}
// textfield:
PRBool IsReadOnly(nsIFrame* aFrame) {
return CheckBooleanAttr(aFrame, mReadOnlyAtom);
return CheckBooleanAttr(aFrame, nsWidgetAtoms::readonly);
}
// These are used by nsNativeThemeGtk
@ -151,20 +132,9 @@ class nsNativeTheme
PRBool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom);
private:
PRBool GetAttr(nsIFrame* aFrame, nsIAtom* aAtom, nsAString& attrValue);
PRBool GetCheckedOrSelected(nsIFrame* aFrame, PRBool aCheckSelected);
protected:
// these are available to subclasses because they are useful in
// implementing WidgetStateChanged()
nsCOMPtr<nsIAtom> mDisabledAtom;
nsCOMPtr<nsIAtom> mCheckedAtom;
nsCOMPtr<nsIAtom> mSelectedAtom;
nsCOMPtr<nsIAtom> mReadOnlyAtom;
nsCOMPtr<nsIAtom> mFirstTabAtom;
nsCOMPtr<nsIAtom> mFocusedAtom;
nsCOMPtr<nsIAtom> mSortDirectionAtom;
// these should be set to appropriate platform values by the subclass, to
// match the values in forms.css. These defaults match forms.css
static nsMargin sButtonBorderSize;
@ -187,10 +157,4 @@ protected:
static PRBool sListboxBGTransparent;
static nsILookAndFeel::nsColorID sListboxBGColorID;
static nsILookAndFeel::nsColorID sListboxDisabledBGColorID;
private:
nsCOMPtr<nsIAtom> mDefaultAtom;
nsCOMPtr<nsIAtom> mValueAtom;
nsCOMPtr<nsIAtom> mModeAtom;
nsCOMPtr<nsIAtom> mClassAtom;
};