Commit 8423facf authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

LayoutTheme, ThemePainter: Assume LayoutObject::GetNode() is a non-null Element

After LayoutTheme::AdjustStyle() call, we can assume a LayoutObject with
a HasEffectiveAppearnace() style always has a non-null Element for
GetNode(). This CL simplifies blink::LayoutTheme and blink::ThemePainter
by the assumption.

* Change the |const Element*| arguments of |LayoutTheme::
  AdjustSliderContainerStyle()| to |const Element&|.

* Remove unused |const Element*| arguments of |LayoutTheme::
  AdjustMenuList*Style()|.

* Change the argument order of LayoutTheme::AdjustStyle() to follow
  Google C++ style guide.

* Public methods of ThemePainter still take |const Node*| arguments,
  but the methods set up |const Element&| variables at the beginning.

* Protected methods of ThemePainter take |const Element&| arguments.

* Add |const Element&| arguments to some of ThemePainter methods because
  they refer to LayoutObject::GetNode().

* Remove IsDisabled(), IsPressed(), and IsHovered() in
  theme_painter_default.cc.  They are not helpful any longer.

This CL has no behavior changes.

Change-Id: I8a8fee402720ddeacfe77ebf920146b72bf6767e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404510
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806517}
parent 4c286eca
......@@ -695,7 +695,7 @@ void StyleAdjuster::AdjustComputedStyle(StyleResolverState& state,
style.AdjustMaskLayers();
// Let the theme also have a crack at adjusting the style.
LayoutTheme::GetTheme().AdjustStyle(style, element);
LayoutTheme::GetTheme().AdjustStyle(element, style);
AdjustStyleForEditing(style);
......
......@@ -228,7 +228,7 @@ ControlPart LayoutTheme::AdjustAppearanceWithElementType(
return part;
}
void LayoutTheme::AdjustStyle(ComputedStyle& style, Element* e) {
void LayoutTheme::AdjustStyle(const Element* e, ComputedStyle& style) {
ControlPart original_part = style.Appearance();
style.SetEffectiveAppearance(original_part);
if (original_part == ControlPart::kNoControlPart)
......@@ -262,6 +262,9 @@ void LayoutTheme::AdjustStyle(ComputedStyle& style, Element* e) {
DCHECK_NE(part, kAutoPart);
if (part == kNoControlPart)
return;
DCHECK(e);
// After this point, a Node must be non-null Element if
// EffectiveAppearance() != kNoControlPart.
AdjustControlPartStyle(style);
......@@ -269,14 +272,14 @@ void LayoutTheme::AdjustStyle(ComputedStyle& style, Element* e) {
// value.
switch (part) {
case kMenulistPart:
return AdjustMenuListStyle(style, e);
return AdjustMenuListStyle(style);
case kMenulistButtonPart:
return AdjustMenuListButtonStyle(style, e);
return AdjustMenuListButtonStyle(style);
case kSliderHorizontalPart:
case kSliderVerticalPart:
case kMediaSliderPart:
case kMediaVolumeSliderPart:
return AdjustSliderContainerStyle(style, e);
return AdjustSliderContainerStyle(*e, style);
case kSliderThumbHorizontalPart:
case kSliderThumbVerticalPart:
return AdjustSliderThumbStyle(style);
......@@ -469,20 +472,18 @@ void LayoutTheme::AdjustButtonStyle(ComputedStyle& style) const {}
void LayoutTheme::AdjustInnerSpinButtonStyle(ComputedStyle&) const {}
void LayoutTheme::AdjustMenuListStyle(ComputedStyle& style, Element*) const {
void LayoutTheme::AdjustMenuListStyle(ComputedStyle& style) const {
// Menulists should have visible overflow
// https://bugs.webkit.org/show_bug.cgi?id=21287
style.SetOverflowX(EOverflow::kVisible);
style.SetOverflowY(EOverflow::kVisible);
}
void LayoutTheme::AdjustMenuListButtonStyle(ComputedStyle&, Element*) const {}
void LayoutTheme::AdjustMenuListButtonStyle(ComputedStyle&) const {}
void LayoutTheme::AdjustSliderContainerStyle(ComputedStyle& style,
Element* e) const {
if (!e)
return;
const AtomicString& pseudo = e->ShadowPseudoId();
void LayoutTheme::AdjustSliderContainerStyle(const Element& e,
ComputedStyle& style) const {
const AtomicString& pseudo = e.ShadowPseudoId();
if (pseudo != shadow_element_names::kPseudoMediaSliderContainer &&
pseudo != shadow_element_names::kPseudoSliderContainer)
return;
......
......@@ -69,7 +69,7 @@ class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
// selection of control size based off the font, the disabling of appearance
// when certain other properties like "border" are set, or if the appearance
// is not supported by the theme.
void AdjustStyle(ComputedStyle&, Element*);
void AdjustStyle(const Element*, ComputedStyle&);
// The remaining methods should be implemented by the platform-specific
// portion of the theme, e.g., LayoutThemeMac.cpp for Mac OS X.
......@@ -209,9 +209,9 @@ class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
virtual void AdjustButtonStyle(ComputedStyle&) const;
virtual void AdjustInnerSpinButtonStyle(ComputedStyle&) const;
virtual void AdjustMenuListStyle(ComputedStyle&, Element*) const;
virtual void AdjustMenuListButtonStyle(ComputedStyle&, Element*) const;
virtual void AdjustSliderContainerStyle(ComputedStyle&, Element*) const;
virtual void AdjustMenuListStyle(ComputedStyle&) const;
virtual void AdjustMenuListButtonStyle(ComputedStyle&) const;
virtual void AdjustSliderContainerStyle(const Element&, ComputedStyle&) const;
virtual void AdjustSliderThumbStyle(ComputedStyle&) const;
virtual void AdjustSearchFieldStyle(ComputedStyle&) const;
virtual void AdjustSearchFieldCancelButtonStyle(ComputedStyle&) const;
......
......@@ -238,16 +238,14 @@ void LayoutThemeDefault::AdjustSearchFieldCancelButtonStyle(
style.SetHeight(Length::Fixed(cancel_button_size));
}
void LayoutThemeDefault::AdjustMenuListStyle(ComputedStyle& style,
Element* element) const {
LayoutTheme::AdjustMenuListStyle(style, element);
void LayoutThemeDefault::AdjustMenuListStyle(ComputedStyle& style) const {
LayoutTheme::AdjustMenuListStyle(style);
// Height is locked to auto on all browsers.
style.SetLineHeight(ComputedStyleInitialValues::InitialLineHeight());
}
void LayoutThemeDefault::AdjustMenuListButtonStyle(ComputedStyle& style,
Element* e) const {
AdjustMenuListStyle(style, e);
void LayoutThemeDefault::AdjustMenuListButtonStyle(ComputedStyle& style) const {
AdjustMenuListStyle(style);
}
// The following internal paddings are in addition to the user-supplied padding.
......
......@@ -80,8 +80,8 @@ class CORE_EXPORT LayoutThemeDefault : public LayoutTheme {
// In short, we either go down the MenuList code path or the MenuListButton
// codepath. We never go down both. And in both cases, they layout the
// entire menulist.
void AdjustMenuListStyle(ComputedStyle&, Element*) const override;
void AdjustMenuListButtonStyle(ComputedStyle&, Element*) const override;
void AdjustMenuListStyle(ComputedStyle&) const override;
void AdjustMenuListButtonStyle(ComputedStyle&) const override;
// These methods define the padding for the MenuList's inner block.
int PopupInternalPaddingStart(const ComputedStyle&) const override;
......
......@@ -67,19 +67,18 @@ ThemePainter::ThemePainter() = default;
#define COUNT_APPEARANCE(doc, feature) \
doc.CountUse(WebFeature::kCSSValueAppearance##feature##Rendered)
void CountAppearanceTextFieldPart(const Node* node) {
DCHECK(node);
if (auto* input = DynamicTo<HTMLInputElement>(node)) {
void CountAppearanceTextFieldPart(const Element& element) {
if (auto* input = DynamicTo<HTMLInputElement>(element)) {
const AtomicString& type = input->type();
if (type == input_type_names::kSearch) {
UseCounter::Count(node->GetDocument(),
UseCounter::Count(element.GetDocument(),
WebFeature::kCSSValueAppearanceTextFieldForSearch);
} else if (input->IsTextField()) {
UseCounter::Count(node->GetDocument(),
UseCounter::Count(element.GetDocument(),
WebFeature::kCSSValueAppearanceTextFieldForTextField);
} else if (IsMultipleFieldsTemporalInput(type)) {
UseCounter::Count(
node->GetDocument(),
element.GetDocument(),
WebFeature::kCSSValueAppearanceTextFieldForTemporalRendered);
}
}
......@@ -89,26 +88,27 @@ void CountAppearanceTextFieldPart(const Node* node) {
bool ThemePainter::Paint(const LayoutObject& o,
const PaintInfo& paint_info,
const IntRect& r) {
const Node* node = o.GetNode();
Document& doc = o.GetDocument();
const ComputedStyle& style = o.StyleRef();
ControlPart part = o.StyleRef().EffectiveAppearance();
// LayoutTheme::AdjustAppearanceWithElementType() ensures |node| is a
// non-null Element.
DCHECK(node);
DCHECK(o.GetNode());
DCHECK_NE(part, kNoControlPart);
const Element& element = *To<Element>(o.GetNode());
if (part == kButtonPart) {
if (IsA<HTMLButtonElement>(node)) {
if (IsA<HTMLButtonElement>(element)) {
UseCounter::Count(doc, WebFeature::kCSSValueAppearanceButtonForButton);
} else if (IsA<HTMLInputElement>(node) &&
To<HTMLInputElement>(node)->IsTextButton()) {
} else if (IsA<HTMLInputElement>(element) &&
To<HTMLInputElement>(element).IsTextButton()) {
// Text buttons (type=button, reset, submit) has
// -webkit-appearance:push-button by default.
UseCounter::Count(doc,
WebFeature::kCSSValueAppearanceButtonForOtherButtons);
} else if (IsA<HTMLInputElement>(node) &&
To<HTMLInputElement>(node)->type() == input_type_names::kColor) {
} else if (IsA<HTMLInputElement>(element) &&
To<HTMLInputElement>(element).type() ==
input_type_names::kColor) {
// 'button' for input[type=color], of which default appearance is
// 'square-button', is not deprecated.
}
......@@ -118,51 +118,51 @@ bool ThemePainter::Paint(const LayoutObject& o,
switch (part) {
case kCheckboxPart: {
COUNT_APPEARANCE(doc, Checkbox);
return PaintCheckbox(node, o.GetDocument(), style, paint_info, r);
return PaintCheckbox(element, o.GetDocument(), style, paint_info, r);
}
case kRadioPart: {
COUNT_APPEARANCE(doc, Radio);
return PaintRadio(node, o.GetDocument(), style, paint_info, r);
return PaintRadio(element, o.GetDocument(), style, paint_info, r);
}
case kPushButtonPart: {
COUNT_APPEARANCE(doc, PushButton);
return PaintButton(node, o.GetDocument(), style, paint_info, r);
return PaintButton(element, o.GetDocument(), style, paint_info, r);
}
case kSquareButtonPart: {
COUNT_APPEARANCE(doc, SquareButton);
return PaintButton(node, o.GetDocument(), style, paint_info, r);
return PaintButton(element, o.GetDocument(), style, paint_info, r);
}
case kButtonPart:
// UseCounter for this is handled at the beginning of the function.
return PaintButton(node, o.GetDocument(), style, paint_info, r);
return PaintButton(element, o.GetDocument(), style, paint_info, r);
case kInnerSpinButtonPart: {
COUNT_APPEARANCE(doc, InnerSpinButton);
return PaintInnerSpinButton(node, style, paint_info, r);
return PaintInnerSpinButton(element, style, paint_info, r);
}
case kMenulistPart:
COUNT_APPEARANCE(doc, MenuList);
return PaintMenuList(node, o.GetDocument(), style, paint_info, r);
return PaintMenuList(element, o.GetDocument(), style, paint_info, r);
case kMeterPart:
return true;
case kProgressBarPart:
COUNT_APPEARANCE(doc, ProgressBar);
// Note that |-webkit-appearance: progress-bar| works only for <progress>.
return PaintProgressBar(o, paint_info, r);
return PaintProgressBar(element, o, paint_info, r);
case kSliderHorizontalPart: {
COUNT_APPEARANCE(doc, SliderHorizontal);
return PaintSliderTrack(o, paint_info, r);
return PaintSliderTrack(element, o, paint_info, r);
}
case kSliderVerticalPart: {
COUNT_APPEARANCE(doc, SliderVertical);
return PaintSliderTrack(o, paint_info, r);
return PaintSliderTrack(element, o, paint_info, r);
}
case kSliderThumbHorizontalPart: {
COUNT_APPEARANCE(doc, SliderThumbHorizontal);
return PaintSliderThumb(node, style, paint_info, r);
return PaintSliderThumb(element, style, paint_info, r);
}
case kSliderThumbVerticalPart: {
COUNT_APPEARANCE(doc, SliderThumbVertical);
return PaintSliderThumb(node, style, paint_info, r);
return PaintSliderThumb(element, style, paint_info, r);
}
case kMediaSliderPart:
case kMediaSliderThumbPart:
......@@ -175,17 +175,17 @@ bool ThemePainter::Paint(const LayoutObject& o,
if (!features::IsFormControlsRefreshEnabled()) {
return true;
}
CountAppearanceTextFieldPart(node);
return PaintTextField(node, style, paint_info, r);
CountAppearanceTextFieldPart(element);
return PaintTextField(element, style, paint_info, r);
case kTextAreaPart:
if (!features::IsFormControlsRefreshEnabled()) {
return true;
}
COUNT_APPEARANCE(doc, TextArea);
return PaintTextArea(node, style, paint_info, r);
return PaintTextArea(element, style, paint_info, r);
case kSearchFieldPart: {
COUNT_APPEARANCE(doc, SearchField);
return PaintSearchField(node, style, paint_info, r);
return PaintSearchField(element, style, paint_info, r);
}
case kSearchFieldCancelButtonPart: {
COUNT_APPEARANCE(doc, SearchCancel);
......@@ -206,20 +206,23 @@ bool ThemePainter::PaintBorderOnly(const Node* node,
const ComputedStyle& style,
const PaintInfo& paint_info,
const IntRect& r) {
DCHECK(style.HasEffectiveAppearance());
DCHECK(node);
const Element& element = *To<Element>(node);
// Call the appropriate paint method based off the appearance value.
switch (style.EffectiveAppearance()) {
case kTextFieldPart:
if (features::IsFormControlsRefreshEnabled()) {
return false;
}
CountAppearanceTextFieldPart(node);
return PaintTextField(node, style, paint_info, r);
CountAppearanceTextFieldPart(element);
return PaintTextField(element, style, paint_info, r);
case kTextAreaPart:
if (features::IsFormControlsRefreshEnabled()) {
return false;
}
COUNT_APPEARANCE(node->GetDocument(), TextArea);
return PaintTextArea(node, style, paint_info, r);
COUNT_APPEARANCE(element.GetDocument(), TextArea);
return PaintTextArea(element, style, paint_info, r);
case kMenulistButtonPart:
case kSearchFieldPart:
case kListboxPart:
......@@ -241,7 +244,7 @@ bool ThemePainter::PaintBorderOnly(const Node* node,
return false;
default:
UseCounter::Count(
node->GetDocument(),
element.GetDocument(),
WebFeature::kCSSValueAppearanceNoImplementationSkipBorder);
// TODO(tkent): Should do CSS border painting for non-supported
// appearance values.
......@@ -256,11 +259,13 @@ bool ThemePainter::PaintDecorations(const Node* node,
const ComputedStyle& style,
const PaintInfo& paint_info,
const IntRect& r) {
DCHECK(node);
// Call the appropriate paint method based off the appearance value.
switch (style.EffectiveAppearance()) {
case kMenulistButtonPart:
COUNT_APPEARANCE(document, MenuListButton);
return PaintMenuListButton(node, document, style, paint_info, r);
return PaintMenuListButton(*To<Element>(node), document, style,
paint_info, r);
case kTextFieldPart:
case kTextAreaPart:
case kCheckboxPart:
......
......@@ -30,6 +30,7 @@ namespace blink {
class ComputedStyle;
class Document;
class Element;
class IntRect;
class LayoutObject;
class Node;
......@@ -64,76 +65,78 @@ class ThemePainter {
void PaintSliderTicks(const LayoutObject&, const PaintInfo&, const IntRect&);
protected:
virtual bool PaintCheckbox(const Node*,
virtual bool PaintCheckbox(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintRadio(const Node*,
virtual bool PaintRadio(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintButton(const Node*,
virtual bool PaintButton(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintInnerSpinButton(const Node*,
virtual bool PaintInnerSpinButton(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintTextField(const Node*,
virtual bool PaintTextField(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintTextArea(const Node*,
virtual bool PaintTextArea(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintMenuList(const Node*,
virtual bool PaintMenuList(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintMenuListButton(const Node* node,
virtual bool PaintMenuListButton(const Element& element,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintProgressBar(const LayoutObject&,
virtual bool PaintProgressBar(const Element& element,
const LayoutObject&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintSliderTrack(const LayoutObject&,
virtual bool PaintSliderTrack(const Element& element,
const LayoutObject&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintSliderThumb(const Node*,
virtual bool PaintSliderThumb(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
return true;
}
virtual bool PaintSearchField(const Node*,
virtual bool PaintSearchField(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) {
......
......@@ -41,54 +41,56 @@ class ThemePainterDefault final : public ThemePainter {
explicit ThemePainterDefault(LayoutThemeDefault&);
private:
bool PaintCheckbox(const Node*,
bool PaintCheckbox(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintRadio(const Node*,
bool PaintRadio(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintButton(const Node*,
bool PaintButton(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintTextField(const Node*,
bool PaintTextField(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintMenuList(const Node*,
bool PaintMenuList(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintMenuListButton(const Node*,
bool PaintMenuListButton(const Element&,
const Document&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintSliderTrack(const LayoutObject&,
bool PaintSliderTrack(const Element& element,
const LayoutObject&,
const PaintInfo&,
const IntRect&) override;
bool PaintSliderThumb(const Node*,
bool PaintSliderThumb(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintInnerSpinButton(const Node*,
bool PaintInnerSpinButton(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintProgressBar(const LayoutObject&,
bool PaintProgressBar(const Element& element,
const LayoutObject&,
const PaintInfo&,
const IntRect&) override;
bool PaintTextArea(const Node*,
bool PaintTextArea(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
bool PaintSearchField(const Node*,
bool PaintSearchField(const Element&,
const ComputedStyle&,
const PaintInfo&,
const IntRect&) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment