Bug 1273423 - removed useless null pointer check on |aFrame|. r=karlt+@karlt.net

MozReview-Commit-ID: 1HCh1pKVUh1

--HG--
extra : rebase_source : 348d3ea21d6dc512dc711e1e82db005db2d9c314
This commit is contained in:
Andi-Bogdan Postelnicu 2016-05-23 11:04:51 +03:00
Родитель 8dbb362d18
Коммит e47f652b04
1 изменённых файлов: 174 добавлений и 180 удалений

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

@ -193,206 +193,200 @@ nsNativeThemeGTK::GetGtkWidgetAndState(uint8_t aWidgetType, nsIFrame* aFrame,
gint* aWidgetFlags)
{
if (aState) {
if (!aFrame) {
// reset the entire struct to zero
memset(aState, 0, sizeof(GtkWidgetState));
} else {
// For XUL checkboxes and radio buttons, the state of the parent
// determines our state.
nsIFrame *stateFrame = aFrame;
if (aFrame && ((aWidgetFlags && (aWidgetType == NS_THEME_CHECKBOX ||
aWidgetType == NS_THEME_RADIO)) ||
aWidgetType == NS_THEME_CHECKBOX_LABEL ||
aWidgetType == NS_THEME_RADIO_LABEL)) {
nsIAtom* atom = nullptr;
if (IsFrameContentNodeInNamespace(aFrame, kNameSpaceID_XUL)) {
if (aWidgetType == NS_THEME_CHECKBOX_LABEL ||
aWidgetType == NS_THEME_RADIO_LABEL) {
// Adjust stateFrame so GetContentState finds the correct state.
stateFrame = aFrame = aFrame->GetParent()->GetParent();
} else {
// GetContentState knows to look one frame up for radio/checkbox
// widgets, so don't adjust stateFrame here.
aFrame = aFrame->GetParent();
}
if (aWidgetFlags) {
if (!atom) {
atom = (aWidgetType == NS_THEME_CHECKBOX ||
aWidgetType == NS_THEME_CHECKBOX_LABEL) ? nsGkAtoms::checked
: nsGkAtoms::selected;
}
*aWidgetFlags = CheckBooleanAttr(aFrame, atom);
}
} else {
if (aWidgetFlags) {
nsCOMPtr<nsIDOMHTMLInputElement> inputElt(do_QueryInterface(aFrame->GetContent()));
*aWidgetFlags = 0;
if (inputElt) {
bool isHTMLChecked;
inputElt->GetChecked(&isHTMLChecked);
if (isHTMLChecked)
*aWidgetFlags |= MOZ_GTK_WIDGET_CHECKED;
}
if (GetIndeterminate(aFrame))
*aWidgetFlags |= MOZ_GTK_WIDGET_INCONSISTENT;
}
}
} else if (aWidgetType == NS_THEME_TOOLBARBUTTON_DROPDOWN ||
aWidgetType == NS_THEME_TREEHEADERSORTARROW ||
aWidgetType == NS_THEME_BUTTON_ARROW_PREVIOUS ||
aWidgetType == NS_THEME_BUTTON_ARROW_NEXT ||
aWidgetType == NS_THEME_BUTTON_ARROW_UP ||
aWidgetType == NS_THEME_BUTTON_ARROW_DOWN) {
// The state of an arrow comes from its parent.
stateFrame = aFrame = aFrame->GetParent();
}
EventStates eventState = GetContentState(stateFrame, aWidgetType);
aState->disabled = IsDisabled(aFrame, eventState) || IsReadOnly(aFrame);
aState->active = eventState.HasState(NS_EVENT_STATE_ACTIVE);
aState->focused = eventState.HasState(NS_EVENT_STATE_FOCUS);
aState->inHover = eventState.HasState(NS_EVENT_STATE_HOVER);
aState->isDefault = IsDefaultButton(aFrame);
aState->canDefault = FALSE; // XXX fix me
aState->depressed = FALSE;
if (aWidgetType == NS_THEME_FOCUS_OUTLINE) {
aState->disabled = FALSE;
aState->active = FALSE;
aState->inHover = FALSE;
aState->isDefault = FALSE;
aState->canDefault = FALSE;
aState->focused = TRUE;
aState->depressed = TRUE; // see moz_gtk_entry_paint()
} else if (aWidgetType == NS_THEME_BUTTON ||
aWidgetType == NS_THEME_TOOLBARBUTTON ||
aWidgetType == NS_THEME_DUALBUTTON ||
aWidgetType == NS_THEME_TOOLBARBUTTON_DROPDOWN ||
aWidgetType == NS_THEME_MENULIST ||
aWidgetType == NS_THEME_MENULIST_BUTTON) {
aState->active &= aState->inHover;
}
// For XUL checkboxes and radio buttons, the state of the parent
// determines our state.
nsIFrame *stateFrame = aFrame;
if (aFrame && ((aWidgetFlags && (aWidgetType == NS_THEME_CHECKBOX ||
aWidgetType == NS_THEME_RADIO)) ||
aWidgetType == NS_THEME_CHECKBOX_LABEL ||
aWidgetType == NS_THEME_RADIO_LABEL)) {
nsIAtom* atom = nullptr;
if (IsFrameContentNodeInNamespace(aFrame, kNameSpaceID_XUL)) {
// For these widget types, some element (either a child or parent)
// actually has element focus, so we check the focused attribute
// to see whether to draw in the focused state.
if (aWidgetType == NS_THEME_NUMBER_INPUT ||
aWidgetType == NS_THEME_TEXTFIELD ||
aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
aWidgetType == NS_THEME_MENULIST_TEXTFIELD ||
aWidgetType == NS_THEME_SPINNER_TEXTFIELD ||
aWidgetType == NS_THEME_RADIO_CONTAINER ||
if (aWidgetType == NS_THEME_CHECKBOX_LABEL ||
aWidgetType == NS_THEME_RADIO_LABEL) {
aState->focused = IsFocused(aFrame);
} else if (aWidgetType == NS_THEME_RADIO ||
aWidgetType == NS_THEME_CHECKBOX) {
// In XUL, checkboxes and radios shouldn't have focus rings, their labels do
aState->focused = FALSE;
// Adjust stateFrame so GetContentState finds the correct state.
stateFrame = aFrame = aFrame->GetParent()->GetParent();
} else {
// GetContentState knows to look one frame up for radio/checkbox
// widgets, so don't adjust stateFrame here.
aFrame = aFrame->GetParent();
}
if (aWidgetType == NS_THEME_SCROLLBARTHUMB_VERTICAL ||
aWidgetType == NS_THEME_SCROLLBARTHUMB_HORIZONTAL) {
// for scrollbars we need to go up two to go from the thumb to
// the slider to the actual scrollbar object
nsIFrame *tmpFrame = aFrame->GetParent()->GetParent();
aState->curpos = CheckIntAttr(tmpFrame, nsGkAtoms::curpos, 0);
aState->maxpos = CheckIntAttr(tmpFrame, nsGkAtoms::maxpos, 100);
if (CheckBooleanAttr(aFrame, nsGkAtoms::active)) {
aState->active = TRUE;
// Set hover state to emulate Gtk style of active scrollbar thumb
aState->inHover = TRUE;
if (aWidgetFlags) {
if (!atom) {
atom = (aWidgetType == NS_THEME_CHECKBOX ||
aWidgetType == NS_THEME_CHECKBOX_LABEL) ? nsGkAtoms::checked
: nsGkAtoms::selected;
}
*aWidgetFlags = CheckBooleanAttr(aFrame, atom);
}
if (aWidgetType == NS_THEME_SCROLLBARBUTTON_UP ||
aWidgetType == NS_THEME_SCROLLBARBUTTON_DOWN ||
aWidgetType == NS_THEME_SCROLLBARBUTTON_LEFT ||
aWidgetType == NS_THEME_SCROLLBARBUTTON_RIGHT) {
// set the state to disabled when the scrollbar is scrolled to
// the beginning or the end, depending on the button type.
int32_t curpos = CheckIntAttr(aFrame, nsGkAtoms::curpos, 0);
int32_t maxpos = CheckIntAttr(aFrame, nsGkAtoms::maxpos, 100);
if (ShouldScrollbarButtonBeDisabled(curpos, maxpos, aWidgetType)) {
aState->disabled = true;
} else {
if (aWidgetFlags) {
nsCOMPtr<nsIDOMHTMLInputElement> inputElt(do_QueryInterface(aFrame->GetContent()));
*aWidgetFlags = 0;
if (inputElt) {
bool isHTMLChecked;
inputElt->GetChecked(&isHTMLChecked);
if (isHTMLChecked)
*aWidgetFlags |= MOZ_GTK_WIDGET_CHECKED;
}
// In order to simulate native GTK scrollbar click behavior,
// we set the active attribute on the element to true if it's
// pressed with any mouse button.
// This allows us to show that it's active without setting :active
else if (CheckBooleanAttr(aFrame, nsGkAtoms::active))
aState->active = true;
if (GetIndeterminate(aFrame))
*aWidgetFlags |= MOZ_GTK_WIDGET_INCONSISTENT;
}
}
} else if (aWidgetType == NS_THEME_TOOLBARBUTTON_DROPDOWN ||
aWidgetType == NS_THEME_TREEHEADERSORTARROW ||
aWidgetType == NS_THEME_BUTTON_ARROW_PREVIOUS ||
aWidgetType == NS_THEME_BUTTON_ARROW_NEXT ||
aWidgetType == NS_THEME_BUTTON_ARROW_UP ||
aWidgetType == NS_THEME_BUTTON_ARROW_DOWN) {
// The state of an arrow comes from its parent.
stateFrame = aFrame = aFrame->GetParent();
}
if (aWidgetFlags) {
*aWidgetFlags = GetScrollbarButtonType(aFrame);
if (aWidgetType - NS_THEME_SCROLLBARBUTTON_UP < 2)
*aWidgetFlags |= MOZ_GTK_STEPPER_VERTICAL;
}
EventStates eventState = GetContentState(stateFrame, aWidgetType);
aState->disabled = IsDisabled(aFrame, eventState) || IsReadOnly(aFrame);
aState->active = eventState.HasState(NS_EVENT_STATE_ACTIVE);
aState->focused = eventState.HasState(NS_EVENT_STATE_FOCUS);
aState->inHover = eventState.HasState(NS_EVENT_STATE_HOVER);
aState->isDefault = IsDefaultButton(aFrame);
aState->canDefault = FALSE; // XXX fix me
aState->depressed = FALSE;
if (aWidgetType == NS_THEME_FOCUS_OUTLINE) {
aState->disabled = FALSE;
aState->active = FALSE;
aState->inHover = FALSE;
aState->isDefault = FALSE;
aState->canDefault = FALSE;
aState->focused = TRUE;
aState->depressed = TRUE; // see moz_gtk_entry_paint()
} else if (aWidgetType == NS_THEME_BUTTON ||
aWidgetType == NS_THEME_TOOLBARBUTTON ||
aWidgetType == NS_THEME_DUALBUTTON ||
aWidgetType == NS_THEME_TOOLBARBUTTON_DROPDOWN ||
aWidgetType == NS_THEME_MENULIST ||
aWidgetType == NS_THEME_MENULIST_BUTTON) {
aState->active &= aState->inHover;
}
if (IsFrameContentNodeInNamespace(aFrame, kNameSpaceID_XUL)) {
// For these widget types, some element (either a child or parent)
// actually has element focus, so we check the focused attribute
// to see whether to draw in the focused state.
if (aWidgetType == NS_THEME_NUMBER_INPUT ||
aWidgetType == NS_THEME_TEXTFIELD ||
aWidgetType == NS_THEME_TEXTFIELD_MULTILINE ||
aWidgetType == NS_THEME_MENULIST_TEXTFIELD ||
aWidgetType == NS_THEME_SPINNER_TEXTFIELD ||
aWidgetType == NS_THEME_RADIO_CONTAINER ||
aWidgetType == NS_THEME_RADIO_LABEL) {
aState->focused = IsFocused(aFrame);
} else if (aWidgetType == NS_THEME_RADIO ||
aWidgetType == NS_THEME_CHECKBOX) {
// In XUL, checkboxes and radios shouldn't have focus rings, their labels do
aState->focused = FALSE;
}
if (aWidgetType == NS_THEME_SCROLLBARTHUMB_VERTICAL ||
aWidgetType == NS_THEME_SCROLLBARTHUMB_HORIZONTAL) {
// for scrollbars we need to go up two to go from the thumb to
// the slider to the actual scrollbar object
nsIFrame *tmpFrame = aFrame->GetParent()->GetParent();
aState->curpos = CheckIntAttr(tmpFrame, nsGkAtoms::curpos, 0);
aState->maxpos = CheckIntAttr(tmpFrame, nsGkAtoms::maxpos, 100);
if (CheckBooleanAttr(aFrame, nsGkAtoms::active)) {
aState->active = TRUE;
// Set hover state to emulate Gtk style of active scrollbar thumb
aState->inHover = TRUE;
}
}
if (aWidgetType == NS_THEME_SCROLLBARBUTTON_UP ||
aWidgetType == NS_THEME_SCROLLBARBUTTON_DOWN ||
aWidgetType == NS_THEME_SCROLLBARBUTTON_LEFT ||
aWidgetType == NS_THEME_SCROLLBARBUTTON_RIGHT) {
// set the state to disabled when the scrollbar is scrolled to
// the beginning or the end, depending on the button type.
int32_t curpos = CheckIntAttr(aFrame, nsGkAtoms::curpos, 0);
int32_t maxpos = CheckIntAttr(aFrame, nsGkAtoms::maxpos, 100);
if (ShouldScrollbarButtonBeDisabled(curpos, maxpos, aWidgetType)) {
aState->disabled = true;
}
// menu item state is determined by the attribute "_moz-menuactive",
// and not by the mouse hovering (accessibility). as a special case,
// menus which are children of a menu bar are only marked as prelight
// if they are open, not on normal hover.
// In order to simulate native GTK scrollbar click behavior,
// we set the active attribute on the element to true if it's
// pressed with any mouse button.
// This allows us to show that it's active without setting :active
else if (CheckBooleanAttr(aFrame, nsGkAtoms::active))
aState->active = true;
if (aWidgetType == NS_THEME_MENUITEM ||
aWidgetType == NS_THEME_CHECKMENUITEM ||
aWidgetType == NS_THEME_RADIOMENUITEM ||
aWidgetType == NS_THEME_MENUSEPARATOR ||
aWidgetType == NS_THEME_MENUARROW) {
bool isTopLevel = false;
nsMenuFrame *menuFrame = do_QueryFrame(aFrame);
if (menuFrame) {
isTopLevel = menuFrame->IsOnMenuBar();
}
if (aWidgetFlags) {
*aWidgetFlags = GetScrollbarButtonType(aFrame);
if (aWidgetType - NS_THEME_SCROLLBARBUTTON_UP < 2)
*aWidgetFlags |= MOZ_GTK_STEPPER_VERTICAL;
}
}
if (isTopLevel) {
aState->inHover = menuFrame->IsOpen();
} else {
aState->inHover = CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
}
// menu item state is determined by the attribute "_moz-menuactive",
// and not by the mouse hovering (accessibility). as a special case,
// menus which are children of a menu bar are only marked as prelight
// if they are open, not on normal hover.
aState->active = FALSE;
if (aWidgetType == NS_THEME_CHECKMENUITEM ||
aWidgetType == NS_THEME_RADIOMENUITEM) {
*aWidgetFlags = 0;
if (aFrame && aFrame->GetContent()) {
*aWidgetFlags = aFrame->GetContent()->
AttrValueIs(kNameSpaceID_None, nsGkAtoms::checked,
nsGkAtoms::_true, eIgnoreCase);
}
}
if (aWidgetType == NS_THEME_MENUITEM ||
aWidgetType == NS_THEME_CHECKMENUITEM ||
aWidgetType == NS_THEME_RADIOMENUITEM ||
aWidgetType == NS_THEME_MENUSEPARATOR ||
aWidgetType == NS_THEME_MENUARROW) {
bool isTopLevel = false;
nsMenuFrame *menuFrame = do_QueryFrame(aFrame);
if (menuFrame) {
isTopLevel = menuFrame->IsOnMenuBar();
}
// A button with drop down menu open or an activated toggle button
// should always appear depressed.
if (aWidgetType == NS_THEME_BUTTON ||
aWidgetType == NS_THEME_TOOLBARBUTTON ||
aWidgetType == NS_THEME_DUALBUTTON ||
aWidgetType == NS_THEME_TOOLBARBUTTON_DROPDOWN ||
aWidgetType == NS_THEME_MENULIST ||
aWidgetType == NS_THEME_MENULIST_BUTTON) {
bool menuOpen = IsOpenButton(aFrame);
aState->depressed = IsCheckedButton(aFrame) || menuOpen;
// we must not highlight buttons with open drop down menus on hover.
aState->inHover = aState->inHover && !menuOpen;
if (isTopLevel) {
aState->inHover = menuFrame->IsOpen();
} else {
aState->inHover = CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
}
// When the input field of the drop down button has focus, some themes
// should draw focus for the drop down button as well.
if (aWidgetType == NS_THEME_MENULIST_BUTTON && aWidgetFlags) {
*aWidgetFlags = CheckBooleanAttr(aFrame, nsGkAtoms::parentfocused);
aState->active = FALSE;
if (aWidgetType == NS_THEME_CHECKMENUITEM ||
aWidgetType == NS_THEME_RADIOMENUITEM) {
*aWidgetFlags = 0;
if (aFrame && aFrame->GetContent()) {
*aWidgetFlags = aFrame->GetContent()->
AttrValueIs(kNameSpaceID_None, nsGkAtoms::checked,
nsGkAtoms::_true, eIgnoreCase);
}
}
}
// A button with drop down menu open or an activated toggle button
// should always appear depressed.
if (aWidgetType == NS_THEME_BUTTON ||
aWidgetType == NS_THEME_TOOLBARBUTTON ||
aWidgetType == NS_THEME_DUALBUTTON ||
aWidgetType == NS_THEME_TOOLBARBUTTON_DROPDOWN ||
aWidgetType == NS_THEME_MENULIST ||
aWidgetType == NS_THEME_MENULIST_BUTTON) {
bool menuOpen = IsOpenButton(aFrame);
aState->depressed = IsCheckedButton(aFrame) || menuOpen;
// we must not highlight buttons with open drop down menus on hover.
aState->inHover = aState->inHover && !menuOpen;
}
// When the input field of the drop down button has focus, some themes
// should draw focus for the drop down button as well.
if (aWidgetType == NS_THEME_MENULIST_BUTTON && aWidgetFlags) {
*aWidgetFlags = CheckBooleanAttr(aFrame, nsGkAtoms::parentfocused);
}
}
}