Commit e2396cbc authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[cleanup] Move SetMinimumSizeIfAuto, SetSizeIfAuto to LayoutThemeDefault

Additionally simplify the logic with SetMinimumSizeIfAuto.

There should be no behaviour change.

Change-Id: I9baf6d3737fc2d0de5531b7f02a53f425d3ccb94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2365313
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800418}
parent 53af49fd
......@@ -776,41 +776,6 @@ bool LayoutTheme::SupportsCalendarPicker(const AtomicString& type) const {
type == input_type_names::kMonth || type == input_type_names::kWeek;
}
// static
void LayoutTheme::SetSizeIfAuto(ComputedStyle& style, const IntSize& size) {
if (style.Width().IsIntrinsicOrAuto())
style.SetWidth(Length::Fixed(size.Width()));
if (style.Height().IsIntrinsicOrAuto())
style.SetHeight(Length::Fixed(size.Height()));
}
// static
void LayoutTheme::SetMinimumSize(ComputedStyle& style,
const LengthSize* part_size,
const LengthSize* min_part_size) {
DCHECK(part_size || min_part_size);
// We only want to set a minimum size if no explicit size is specified, to
// avoid overriding author intentions.
if (part_size && style.MinWidth().IsIntrinsicOrAuto() &&
style.Width().IsIntrinsicOrAuto())
style.SetMinWidth(part_size->Width());
else if (min_part_size && min_part_size->Width() != style.MinWidth())
style.SetMinWidth(min_part_size->Width());
if (part_size && style.MinHeight().IsIntrinsicOrAuto() &&
style.Height().IsIntrinsicOrAuto())
style.SetMinHeight(part_size->Height());
else if (min_part_size && min_part_size->Height() != style.MinHeight())
style.SetMinHeight(min_part_size->Height());
}
// static
void LayoutTheme::SetMinimumSizeIfAuto(ComputedStyle& style,
const IntSize& size) {
LengthSize length_size(Length::Fixed(size.Width()),
Length::Fixed(size.Height()));
SetMinimumSize(style, &length_size);
}
void LayoutTheme::AdjustControlPartStyle(ComputedStyle& style) {
// Call the appropriate style adjustment method based off the appearance
// value.
......
......@@ -45,7 +45,6 @@ class ComputedStyle;
class Element;
class File;
class FontDescription;
class LengthSize;
class LocalFrame;
class Node;
class ThemePainter;
......@@ -63,17 +62,6 @@ class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
virtual ThemePainter& Painter() = 0;
static void SetSizeIfAuto(ComputedStyle&, const IntSize&);
// Sets the minimum size to |part_size| or |min_part_size| as appropriate
// according to the given style, if they are specified.
static void SetMinimumSize(ComputedStyle&,
const LengthSize* part_size,
const LengthSize* min_part_size = nullptr);
// SetMinimumSizeIfAuto must be called before SetSizeIfAuto, because we
// will not set a minimum size if an explicit size is set, and SetSizeIfAuto
// sets an explicit size.
static void SetMinimumSizeIfAuto(ComputedStyle&, const IntSize&);
// This method is called whenever style has been computed for an element and
// the appearance property has been set to a value other than "none".
// The theme should map in all of the appropriate metrics and defaults given
......
......@@ -197,6 +197,27 @@ void LayoutThemeDefault::SetSelectionColors(Color active_background_color,
PlatformColorsDidChange();
}
namespace {
void SetSizeIfAuto(const IntSize& size, ComputedStyle& style) {
if (style.Width().IsIntrinsicOrAuto())
style.SetWidth(Length::Fixed(size.Width()));
if (style.Height().IsIntrinsicOrAuto())
style.SetHeight(Length::Fixed(size.Height()));
}
void SetMinimumSizeIfAuto(const IntSize& size, ComputedStyle& style) {
// We only want to set a minimum size if no explicit size is specified, to
// avoid overriding author intentions.
if (style.MinWidth().IsIntrinsicOrAuto() && style.Width().IsIntrinsicOrAuto())
style.SetMinWidth(Length::Fixed(size.Width()));
if (style.MinHeight().IsIntrinsicOrAuto() &&
style.Height().IsIntrinsicOrAuto())
style.SetMinHeight(Length::Fixed(size.Height()));
}
} // namespace
void LayoutThemeDefault::SetCheckboxSize(ComputedStyle& style) const {
// If the width and height are both specified, then we have nothing to do.
if (!style.Width().IsIntrinsicOrAuto() && !style.Height().IsAuto())
......@@ -207,8 +228,8 @@ void LayoutThemeDefault::SetCheckboxSize(ComputedStyle& style) const {
float zoom_level = style.EffectiveZoom();
size.SetWidth(size.Width() * zoom_level);
size.SetHeight(size.Height() * zoom_level);
SetMinimumSizeIfAuto(style, size);
SetSizeIfAuto(style, size);
SetMinimumSizeIfAuto(size, style);
SetSizeIfAuto(size, style);
}
void LayoutThemeDefault::SetRadioSize(ComputedStyle& style) const {
......@@ -221,8 +242,8 @@ void LayoutThemeDefault::SetRadioSize(ComputedStyle& style) const {
float zoom_level = style.EffectiveZoom();
size.SetWidth(size.Width() * zoom_level);
size.SetHeight(size.Height() * zoom_level);
SetMinimumSizeIfAuto(style, size);
SetSizeIfAuto(style, size);
SetMinimumSizeIfAuto(size, style);
SetSizeIfAuto(size, style);
}
void LayoutThemeDefault::AdjustInnerSpinButtonStyle(
......
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