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&) {
......
......@@ -47,38 +47,24 @@ namespace {
const unsigned kDefaultButtonBackgroundColor = 0xffdddddd;
bool IsDisabled(const Node* node) {
if (const auto* element = DynamicTo<Element>(node))
return element->IsDisabledFormControl();
bool IsIndeterminate(const Element& element) {
if (const auto* input = DynamicTo<HTMLInputElement>(element))
return input->ShouldAppearIndeterminate();
return false;
}
bool IsPressed(const Node* node) {
return node && node->IsActive();
}
bool IsHovered(const Node* node) {
return node && node->IsHovered();
}
bool IsIndeterminate(const Node* node) {
if (const auto* element = DynamicTo<HTMLInputElement>(node))
return element->ShouldAppearIndeterminate();
return false;
}
bool IsChecked(const Node* node) {
if (auto* input = DynamicTo<HTMLInputElement>(node))
bool IsChecked(const Element& element) {
if (const auto* input = DynamicTo<HTMLInputElement>(element))
return input->ShouldAppearChecked();
return false;
}
WebThemeEngine::State GetWebThemeState(const Node* node) {
if (IsDisabled(node))
WebThemeEngine::State GetWebThemeState(const Element& element) {
if (element.IsDisabledFormControl())
return WebThemeEngine::kStateDisabled;
if (IsPressed(node))
if (element.IsActive())
return WebThemeEngine::kStatePressed;
if (IsHovered(node))
if (element.IsHovered())
return WebThemeEngine::kStateHover;
return WebThemeEngine::kStateNormal;
......@@ -164,7 +150,7 @@ IntRect ConvertToPaintingRect(const LayoutObject& input_layout_object,
ThemePainterDefault::ThemePainterDefault(LayoutThemeDefault& theme)
: ThemePainter(), theme_(theme) {}
bool ThemePainterDefault::PaintCheckbox(const Node* node,
bool ThemePainterDefault::PaintCheckbox(const Element& element,
const Document&,
const ComputedStyle& style,
const PaintInfo& paint_info,
......@@ -172,8 +158,8 @@ bool ThemePainterDefault::PaintCheckbox(const Node* node,
WebThemeEngine::ExtraParams extra_params;
cc::PaintCanvas* canvas = paint_info.context.Canvas();
extra_params.button = WebThemeEngine::ButtonExtraParams();
extra_params.button.checked = IsChecked(node);
extra_params.button.indeterminate = IsIndeterminate(node);
extra_params.button.checked = IsChecked(element);
extra_params.button.indeterminate = IsIndeterminate(element);
float zoom_level = style.EffectiveZoom();
extra_params.button.zoom = zoom_level;
......@@ -189,12 +175,12 @@ bool ThemePainterDefault::PaintCheckbox(const Node* node,
}
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartCheckbox, GetWebThemeState(node),
canvas, WebThemeEngine::kPartCheckbox, GetWebThemeState(element),
WebRect(unzoomed_rect), &extra_params, style.UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintRadio(const Node* node,
bool ThemePainterDefault::PaintRadio(const Element& element,
const Document&,
const ComputedStyle& style,
const PaintInfo& paint_info,
......@@ -202,15 +188,15 @@ bool ThemePainterDefault::PaintRadio(const Node* node,
WebThemeEngine::ExtraParams extra_params;
cc::PaintCanvas* canvas = paint_info.context.Canvas();
extra_params.button = WebThemeEngine::ButtonExtraParams();
extra_params.button.checked = IsChecked(node);
extra_params.button.checked = IsChecked(element);
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartRadio, GetWebThemeState(node), WebRect(rect),
&extra_params, style.UsedColorScheme());
canvas, WebThemeEngine::kPartRadio, GetWebThemeState(element),
WebRect(rect), &extra_params, style.UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintButton(const Node* node,
bool ThemePainterDefault::PaintButton(const Element& element,
const Document&,
const ComputedStyle& style,
const PaintInfo& paint_info,
......@@ -225,12 +211,12 @@ bool ThemePainterDefault::PaintButton(const Node* node,
style.VisitedDependentColor(GetCSSPropertyBackgroundColor()).Rgb();
}
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartButton, GetWebThemeState(node),
canvas, WebThemeEngine::kPartButton, GetWebThemeState(element),
WebRect(rect), &extra_params, style.UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintTextField(const Node* node,
bool ThemePainterDefault::PaintTextField(const Element& element,
const ComputedStyle& style,
const PaintInfo& paint_info,
const IntRect& rect) {
......@@ -262,15 +248,15 @@ bool ThemePainterDefault::PaintTextField(const Node* node,
style.VisitedDependentColor(GetCSSPropertyBackgroundColor());
extra_params.text_field.background_color = background_color.Rgb();
extra_params.text_field.auto_complete_active =
DynamicTo<HTMLFormControlElement>(node)->IsAutofilled();
DynamicTo<HTMLFormControlElement>(element)->IsAutofilled();
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartTextField, GetWebThemeState(node),
canvas, WebThemeEngine::kPartTextField, GetWebThemeState(element),
WebRect(rect), &extra_params, style.UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintMenuList(const Node* node,
bool ThemePainterDefault::PaintMenuList(const Element& element,
const Document& document,
const ComputedStyle& style,
const PaintInfo& i,
......@@ -299,12 +285,12 @@ bool ThemePainterDefault::PaintMenuList(const Node* node,
cc::PaintCanvas* canvas = i.context.Canvas();
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartMenuList, GetWebThemeState(node),
canvas, WebThemeEngine::kPartMenuList, GetWebThemeState(element),
WebRect(rect), &extra_params, style.UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintMenuListButton(const Node* node,
bool ThemePainterDefault::PaintMenuListButton(const Element& element,
const Document& document,
const ComputedStyle& style,
const PaintInfo& paint_info,
......@@ -318,7 +304,7 @@ bool ThemePainterDefault::PaintMenuListButton(const Node* node,
cc::PaintCanvas* canvas = paint_info.context.Canvas();
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartMenuList, GetWebThemeState(node),
canvas, WebThemeEngine::kPartMenuList, GetWebThemeState(element),
WebRect(rect), &extra_params, style.UsedColorScheme());
return false;
}
......@@ -350,7 +336,8 @@ void ThemePainterDefault::SetupMenuListArrow(
style.VisitedDependentColor(GetCSSPropertyColor()).Rgb();
}
bool ThemePainterDefault::PaintSliderTrack(const LayoutObject& o,
bool ThemePainterDefault::PaintSliderTrack(const Element& element,
const LayoutObject& o,
const PaintInfo& i,
const IntRect& rect) {
WebThemeEngine::ExtraParams extra_params;
......@@ -374,7 +361,7 @@ bool ThemePainterDefault::PaintSliderTrack(const LayoutObject& o,
i.context.Translate(-unzoomed_rect.X(), -unzoomed_rect.Y());
}
auto* input = DynamicTo<HTMLInputElement>(o.GetNode());
auto* input = DynamicTo<HTMLInputElement>(element);
extra_params.slider.thumb_x = 0;
extra_params.slider.thumb_y = 0;
extra_params.slider.right_to_left = !o.StyleRef().IsLeftToRightDirection();
......@@ -408,12 +395,12 @@ bool ThemePainterDefault::PaintSliderTrack(const LayoutObject& o,
}
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartSliderTrack, GetWebThemeState(o.GetNode()),
canvas, WebThemeEngine::kPartSliderTrack, GetWebThemeState(element),
WebRect(unzoomed_rect), &extra_params, o.StyleRef().UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintSliderThumb(const Node* node,
bool ThemePainterDefault::PaintSliderThumb(const Element& element,
const ComputedStyle& style,
const PaintInfo& paint_info,
const IntRect& rect) {
......@@ -421,7 +408,7 @@ bool ThemePainterDefault::PaintSliderThumb(const Node* node,
cc::PaintCanvas* canvas = paint_info.context.Canvas();
extra_params.slider.vertical =
style.EffectiveAppearance() == kSliderThumbVerticalPart;
extra_params.slider.in_drag = IsPressed(node);
extra_params.slider.in_drag = element.IsActive();
float zoom_level = style.EffectiveZoom();
extra_params.slider.zoom = zoom_level;
......@@ -437,12 +424,12 @@ bool ThemePainterDefault::PaintSliderThumb(const Node* node,
}
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartSliderThumb, GetWebThemeState(node),
canvas, WebThemeEngine::kPartSliderThumb, GetWebThemeState(element),
WebRect(unzoomed_rect), &extra_params, style.UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintInnerSpinButton(const Node* node,
bool ThemePainterDefault::PaintInnerSpinButton(const Element& element,
const ComputedStyle& style,
const PaintInfo& paint_info,
const IntRect& rect) {
......@@ -450,25 +437,26 @@ bool ThemePainterDefault::PaintInnerSpinButton(const Node* node,
cc::PaintCanvas* canvas = paint_info.context.Canvas();
bool spin_up = false;
if (const auto* element = DynamicTo<SpinButtonElement>(node)) {
if (element->GetUpDownState() == SpinButtonElement::kUp)
spin_up = node->IsHovered() || node->IsActive();
if (const auto* spin_buttom = DynamicTo<SpinButtonElement>(element)) {
if (spin_buttom->GetUpDownState() == SpinButtonElement::kUp)
spin_up = element.IsHovered() || element.IsActive();
}
bool read_only = false;
if (const auto* element = DynamicTo<HTMLFormControlElement>(node))
read_only = element->IsReadOnly();
if (const auto* control = DynamicTo<HTMLFormControlElement>(element))
read_only = control->IsReadOnly();
extra_params.inner_spin.spin_up = spin_up;
extra_params.inner_spin.read_only = read_only;
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartInnerSpinButton, GetWebThemeState(node),
canvas, WebThemeEngine::kPartInnerSpinButton, GetWebThemeState(element),
WebRect(rect), &extra_params, style.UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintProgressBar(const LayoutObject& o,
bool ThemePainterDefault::PaintProgressBar(const Element& element,
const LayoutObject& o,
const PaintInfo& i,
const IntRect& rect) {
if (!o.IsProgress())
......@@ -487,23 +475,23 @@ bool ThemePainterDefault::PaintProgressBar(const LayoutObject& o,
DirectionFlippingScope scope(o, i, rect);
cc::PaintCanvas* canvas = i.context.Canvas();
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartProgressBar, GetWebThemeState(o.GetNode()),
canvas, WebThemeEngine::kPartProgressBar, GetWebThemeState(element),
WebRect(rect), &extra_params, o.StyleRef().UsedColorScheme());
return false;
}
bool ThemePainterDefault::PaintTextArea(const Node* node,
bool ThemePainterDefault::PaintTextArea(const Element& element,
const ComputedStyle& style,
const PaintInfo& paint_info,
const IntRect& rect) {
return PaintTextField(node, style, paint_info, rect);
return PaintTextField(element, style, paint_info, rect);
}
bool ThemePainterDefault::PaintSearchField(const Node* node,
bool ThemePainterDefault::PaintSearchField(const Element& element,
const ComputedStyle& style,
const PaintInfo& paint_info,
const IntRect& rect) {
return PaintTextField(node, style, paint_info, rect);
return PaintTextField(element, style, paint_info, rect);
}
bool ThemePainterDefault::PaintSearchFieldCancelButton(
......@@ -511,8 +499,6 @@ bool ThemePainterDefault::PaintSearchFieldCancelButton(
const PaintInfo& paint_info,
const IntRect& r) {
// Get the layoutObject of <input> element.
if (!cancel_button_object.GetNode())
return false;
Node* input = cancel_button_object.GetNode()->OwnerShadowHost();
const LayoutObject& base_layout_object = input && input->GetLayoutObject()
? *input->GetLayoutObject()
......@@ -553,7 +539,8 @@ bool ThemePainterDefault::PaintSearchFieldCancelButton(
Image* color_scheme_adjusted_cancel_pressed_image =
color_scheme == kLight ? cancel_pressed_image
: cancel_pressed_image_dark_mode;
paint_info.context.DrawImage(IsPressed(cancel_button_object.GetNode())
paint_info.context.DrawImage(
To<Element>(cancel_button_object.GetNode())->IsActive()
? color_scheme_adjusted_cancel_pressed_image
: color_scheme_adjusted_cancel_image,
Image::kSyncDecode, FloatRect(painting_rect));
......
......@@ -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