Commit 89c5a0f9 authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[cleanup] Move LayoutTheme state methods into ThemePainterDefault.

There should be no behaviour change.

Change-Id: I8d7fee0a71ab8d167c0a525d91be4c8be60779d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392754Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804579}
parent 012b15c7
......@@ -432,42 +432,6 @@ bool LayoutTheme::ShouldDrawDefaultFocusRing(const Node* node,
return true;
}
bool LayoutTheme::IsChecked(const Node* node) {
if (auto* input = DynamicTo<HTMLInputElement>(node))
return input->ShouldAppearChecked();
return false;
}
bool LayoutTheme::IsIndeterminate(const Node* node) {
if (auto* input = DynamicTo<HTMLInputElement>(node))
return input->ShouldAppearIndeterminate();
return false;
}
bool LayoutTheme::IsEnabled(const Node* node) {
auto* element = DynamicTo<Element>(node);
if (!element)
return true;
return !element->IsDisabledFormControl();
}
bool LayoutTheme::IsPressed(const Node* node) {
if (!node)
return false;
return node->IsActive();
}
bool LayoutTheme::IsReadOnlyControl(const Node* node) {
auto* form_control_element = DynamicTo<HTMLFormControlElement>(node);
return form_control_element && form_control_element->IsReadOnly();
}
bool LayoutTheme::IsHovered(const Node* node) {
if (!node)
return false;
return node->IsHovered();
}
void LayoutTheme::AdjustCheckboxStyle(ComputedStyle& style) const {
// A summary of the rules for checkbox designed to match WinIE:
// width/height - honored (WinIE actually scales its control for small widths,
......
......@@ -216,16 +216,6 @@ class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
virtual void AdjustSearchFieldStyle(ComputedStyle&) const;
virtual void AdjustSearchFieldCancelButtonStyle(ComputedStyle&) const;
public:
// Methods for state querying
static bool IsChecked(const Node*);
static bool IsIndeterminate(const Node*);
static bool IsEnabled(const Node*);
static bool IsPressed(const Node*);
static bool IsHovered(const Node*);
static bool IsReadOnlyControl(const Node*);
protected:
bool HasCustomFocusRingColor() const;
Color GetCustomFocusRingColor() const;
......
......@@ -47,12 +47,38 @@ namespace {
const unsigned kDefaultButtonBackgroundColor = 0xffdddddd;
bool IsDisabled(const Node* node) {
if (const auto* element = DynamicTo<Element>(node))
return element->IsDisabledFormControl();
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))
return input->ShouldAppearChecked();
return false;
}
WebThemeEngine::State GetWebThemeState(const Node* node) {
if (!LayoutTheme::IsEnabled(node))
if (IsDisabled(node))
return WebThemeEngine::kStateDisabled;
if (LayoutTheme::IsPressed(node))
if (IsPressed(node))
return WebThemeEngine::kStatePressed;
if (LayoutTheme::IsHovered(node))
if (IsHovered(node))
return WebThemeEngine::kStateHover;
return WebThemeEngine::kStateNormal;
......@@ -146,8 +172,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 = LayoutTheme::IsChecked(node);
extra_params.button.indeterminate = LayoutTheme::IsIndeterminate(node);
extra_params.button.checked = IsChecked(node);
extra_params.button.indeterminate = IsIndeterminate(node);
float zoom_level = style.EffectiveZoom();
extra_params.button.zoom = zoom_level;
......@@ -176,7 +202,7 @@ 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 = LayoutTheme::IsChecked(node);
extra_params.button.checked = IsChecked(node);
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartRadio, GetWebThemeState(node), WebRect(rect),
......@@ -395,7 +421,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 = LayoutTheme::IsPressed(node);
extra_params.slider.in_drag = IsPressed(node);
float zoom_level = style.EffectiveZoom();
extra_params.slider.zoom = zoom_level;
......@@ -429,8 +455,12 @@ bool ThemePainterDefault::PaintInnerSpinButton(const Node* node,
spin_up = node->IsHovered() || node->IsActive();
}
bool read_only = false;
if (const auto* element = DynamicTo<HTMLFormControlElement>(node))
read_only = element->IsReadOnly();
extra_params.inner_spin.spin_up = spin_up;
extra_params.inner_spin.read_only = LayoutTheme::IsReadOnlyControl(node);
extra_params.inner_spin.read_only = read_only;
Platform::Current()->ThemeEngine()->Paint(
canvas, WebThemeEngine::kPartInnerSpinButton, GetWebThemeState(node),
......@@ -523,11 +553,10 @@ 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(
LayoutTheme::IsPressed(cancel_button_object.GetNode())
? color_scheme_adjusted_cancel_pressed_image
: color_scheme_adjusted_cancel_image,
Image::kSyncDecode, FloatRect(painting_rect));
paint_info.context.DrawImage(IsPressed(cancel_button_object.GetNode())
? color_scheme_adjusted_cancel_pressed_image
: color_scheme_adjusted_cancel_image,
Image::kSyncDecode, FloatRect(painting_rect));
return false;
}
......
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