Commit 26863e6f authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Slider NG: Remove LayoutSliderContainer::ComputeLogicalHeight()

It sets fixed values depending on platforms. The values can be
represented by UA stylesheets if we add a pseudo class to check
|input->list()|.

This CL introduces a UA-only pseudo class, :-internal-has-datalist, and
converts LayoutSliderContainer::ComputeLogicalHeight() to CSS rulesets.

This CL has no behavior changes.

Bug: 1040826
Change-Id: I996bb887fa18856a32a9670b91e09ad3ec315562
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387917Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804045}
parent 13fffaf3
...@@ -289,6 +289,7 @@ PseudoId CSSSelector::GetPseudoId(PseudoType type) { ...@@ -289,6 +289,7 @@ PseudoId CSSSelector::GetPseudoId(PseudoType type) {
case kPseudoPictureInPicture: case kPseudoPictureInPicture:
case kPseudoSpatialNavigationFocus: case kPseudoSpatialNavigationFocus:
case kPseudoSpatialNavigationInterest: case kPseudoSpatialNavigationInterest:
case kPseudoHasDatalist:
case kPseudoIsHtml: case kPseudoIsHtml:
case kPseudoListBox: case kPseudoListBox:
case kPseudoMultiSelectFocus: case kPseudoMultiSelectFocus:
...@@ -316,6 +317,7 @@ struct NameToPseudoStruct { ...@@ -316,6 +317,7 @@ struct NameToPseudoStruct {
const static NameToPseudoStruct kPseudoTypeWithoutArgumentsMap[] = { const static NameToPseudoStruct kPseudoTypeWithoutArgumentsMap[] = {
{"-internal-autofill-previewed", CSSSelector::kPseudoAutofillPreviewed}, {"-internal-autofill-previewed", CSSSelector::kPseudoAutofillPreviewed},
{"-internal-autofill-selected", CSSSelector::kPseudoAutofillSelected}, {"-internal-autofill-selected", CSSSelector::kPseudoAutofillSelected},
{"-internal-has-datalist", CSSSelector::kPseudoHasDatalist},
{"-internal-is-html", CSSSelector::kPseudoIsHtml}, {"-internal-is-html", CSSSelector::kPseudoIsHtml},
{"-internal-list-box", CSSSelector::kPseudoListBox}, {"-internal-list-box", CSSSelector::kPseudoListBox},
{"-internal-media-controls-overlay-cast-button", {"-internal-media-controls-overlay-cast-button",
...@@ -590,6 +592,7 @@ void CSSSelector::UpdatePseudoType(const AtomicString& value, ...@@ -590,6 +592,7 @@ void CSSSelector::UpdatePseudoType(const AtomicString& value,
if (match_ != kPseudoElement || mode != kUASheetMode) if (match_ != kPseudoElement || mode != kUASheetMode)
pseudo_type_ = kPseudoUnknown; pseudo_type_ = kPseudoUnknown;
break; break;
case kPseudoHasDatalist:
case kPseudoHostHasAppearance: case kPseudoHostHasAppearance:
case kPseudoIsHtml: case kPseudoIsHtml:
case kPseudoListBox: case kPseudoListBox:
...@@ -983,6 +986,7 @@ static bool ValidateSubSelector(const CSSSelector* selector) { ...@@ -983,6 +986,7 @@ static bool ValidateSubSelector(const CSSSelector* selector) {
case CSSSelector::kPseudoNot: case CSSSelector::kPseudoNot:
case CSSSelector::kPseudoSpatialNavigationFocus: case CSSSelector::kPseudoSpatialNavigationFocus:
case CSSSelector::kPseudoSpatialNavigationInterest: case CSSSelector::kPseudoSpatialNavigationInterest:
case CSSSelector::kPseudoHasDatalist:
case CSSSelector::kPseudoIsHtml: case CSSSelector::kPseudoIsHtml:
case CSSSelector::kPseudoListBox: case CSSSelector::kPseudoListBox:
case CSSSelector::kPseudoHostHasAppearance: case CSSSelector::kPseudoHostHasAppearance:
......
...@@ -243,6 +243,7 @@ class CORE_EXPORT CSSSelector { ...@@ -243,6 +243,7 @@ class CORE_EXPORT CSSSelector {
kPseudoUnresolved, kPseudoUnresolved,
kPseudoDefined, kPseudoDefined,
kPseudoContent, kPseudoContent,
kPseudoHasDatalist,
kPseudoHost, kPseudoHost,
kPseudoHostContext, kPseudoHostContext,
kPseudoShadow, kPseudoShadow,
......
...@@ -164,6 +164,7 @@ bool SupportsInvalidation(CSSSelector::PseudoType type) { ...@@ -164,6 +164,7 @@ bool SupportsInvalidation(CSSSelector::PseudoType type) {
case CSSSelector::kPseudoShadow: case CSSSelector::kPseudoShadow:
case CSSSelector::kPseudoSpatialNavigationFocus: case CSSSelector::kPseudoSpatialNavigationFocus:
case CSSSelector::kPseudoSpatialNavigationInterest: case CSSSelector::kPseudoSpatialNavigationInterest:
case CSSSelector::kPseudoHasDatalist:
case CSSSelector::kPseudoIsHtml: case CSSSelector::kPseudoIsHtml:
case CSSSelector::kPseudoListBox: case CSSSelector::kPseudoListBox:
case CSSSelector::kPseudoMultiSelectFocus: case CSSSelector::kPseudoMultiSelectFocus:
...@@ -555,6 +556,7 @@ InvalidationSet* RuleFeatureSet::InvalidationSetForSimpleSelector( ...@@ -555,6 +556,7 @@ InvalidationSet* RuleFeatureSet::InvalidationSetForSimpleSelector(
case CSSSelector::kPseudoVideoPersistentAncestor: case CSSSelector::kPseudoVideoPersistentAncestor:
case CSSSelector::kPseudoXrOverlay: case CSSSelector::kPseudoXrOverlay:
case CSSSelector::kPseudoSpatialNavigationInterest: case CSSSelector::kPseudoSpatialNavigationInterest:
case CSSSelector::kPseudoHasDatalist:
case CSSSelector::kPseudoMultiSelectFocus: case CSSSelector::kPseudoMultiSelectFocus:
return &EnsurePseudoInvalidationSet(selector.GetPseudoType(), type, return &EnsurePseudoInvalidationSet(selector.GetPseudoType(), type,
position); position);
......
...@@ -86,6 +86,11 @@ static bool MatchesSpatialNavigationFocusPseudoClass(const Element& element) { ...@@ -86,6 +86,11 @@ static bool MatchesSpatialNavigationFocusPseudoClass(const Element& element) {
IsFrameFocused(element); IsFrameFocused(element);
} }
static bool MatchesHasDatalistPseudoClass(const Element& element) {
auto* html_input_element = DynamicTo<HTMLInputElement>(element);
return html_input_element && html_input_element->list();
}
static bool MatchesListBoxPseudoClass(const Element& element) { static bool MatchesListBoxPseudoClass(const Element& element) {
auto* html_select_element = DynamicTo<HTMLSelectElement>(element); auto* html_select_element = DynamicTo<HTMLSelectElement>(element);
return html_select_element && !html_select_element->UsesMenuList(); return html_select_element && !html_select_element->UsesMenuList();
...@@ -1296,6 +1301,9 @@ bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context, ...@@ -1296,6 +1301,9 @@ bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context,
case CSSSelector::kPseudoSpatialNavigationInterest: case CSSSelector::kPseudoSpatialNavigationInterest:
DCHECK(is_ua_rule_); DCHECK(is_ua_rule_);
return MatchesSpatialNavigationInterestPseudoClass(element); return MatchesSpatialNavigationInterestPseudoClass(element);
case CSSSelector::kPseudoHasDatalist:
DCHECK(is_ua_rule_);
return MatchesHasDatalistPseudoClass(element);
case CSSSelector::kPseudoIsHtml: case CSSSelector::kPseudoIsHtml:
DCHECK(is_ua_rule_); DCHECK(is_ua_rule_);
return IsA<HTMLDocument>(element.GetDocument()); return IsA<HTMLDocument>(element.GetDocument());
......
...@@ -447,6 +447,9 @@ void HTMLInputElement::UpdateType() { ...@@ -447,6 +447,9 @@ void HTMLInputElement::UpdateType() {
PseudoStateChanged(CSSSelector::kPseudoInRange); PseudoStateChanged(CSSSelector::kPseudoInRange);
PseudoStateChanged(CSSSelector::kPseudoOutOfRange); PseudoStateChanged(CSSSelector::kPseudoOutOfRange);
} }
if (input_type_->ShouldRespectListAttribute() !=
new_type->ShouldRespectListAttribute())
PseudoStateChanged(CSSSelector::kPseudoHasDatalist);
bool placeholder_changed = bool placeholder_changed =
input_type_->SupportsPlaceholder() != new_type->SupportsPlaceholder(); input_type_->SupportsPlaceholder() != new_type->SupportsPlaceholder();
...@@ -882,6 +885,7 @@ void HTMLInputElement::ParseAttribute( ...@@ -882,6 +885,7 @@ void HTMLInputElement::ParseAttribute(
ResetListAttributeTargetObserver(); ResetListAttributeTargetObserver();
ListAttributeTargetChanged(); ListAttributeTargetChanged();
} }
PseudoStateChanged(CSSSelector::kPseudoHasDatalist);
UseCounter::Count(GetDocument(), WebFeature::kListAttribute); UseCounter::Count(GetDocument(), WebFeature::kListAttribute);
} else if (name == html_names::kWebkitdirectoryAttr) { } else if (name == html_names::kWebkitdirectoryAttr) {
TextControlElement::ParseAttribute(params); TextControlElement::ParseAttribute(params);
...@@ -1752,6 +1756,7 @@ void HTMLInputElement::ResetListAttributeTargetObserver() { ...@@ -1752,6 +1756,7 @@ void HTMLInputElement::ResetListAttributeTargetObserver() {
void HTMLInputElement::ListAttributeTargetChanged() { void HTMLInputElement::ListAttributeTargetChanged() {
input_type_view_->ListAttributeTargetChanged(); input_type_view_->ListAttributeTargetChanged();
PseudoStateChanged(CSSSelector::kPseudoHasDatalist);
} }
bool HTMLInputElement::IsSteppable() const { bool HTMLInputElement::IsSteppable() const {
......
...@@ -643,6 +643,14 @@ input[type="range" i]::-webkit-slider-container, input[type="range" i]::-webkit- ...@@ -643,6 +643,14 @@ input[type="range" i]::-webkit-slider-container, input[type="range" i]::-webkit-
display: flex; display: flex;
} }
input[type="range" i]:-internal-has-datalist::-webkit-slider-container {
/*
* See LayoutThemeDefault. "22px" is
* 2 * (SliderTickOffsetFromTrackCenter() + SliderTickSize().Height()).
*/
min-block-size: 22px;
}
input[type="range" i]::-webkit-slider-runnable-track { input[type="range" i]::-webkit-slider-runnable-track {
flex: 1; flex: 1;
min-inline-size: 0; min-inline-size: 0;
......
...@@ -360,6 +360,7 @@ const char* PseudoTypeToString(CSSSelector::PseudoType pseudo_type) { ...@@ -360,6 +360,7 @@ const char* PseudoTypeToString(CSSSelector::PseudoType pseudo_type) {
DEFINE_STRING_MAPPING(PseudoSlotted) DEFINE_STRING_MAPPING(PseudoSlotted)
DEFINE_STRING_MAPPING(PseudoSpatialNavigationFocus) DEFINE_STRING_MAPPING(PseudoSpatialNavigationFocus)
DEFINE_STRING_MAPPING(PseudoSpatialNavigationInterest) DEFINE_STRING_MAPPING(PseudoSpatialNavigationInterest)
DEFINE_STRING_MAPPING(PseudoHasDatalist)
DEFINE_STRING_MAPPING(PseudoIsHtml) DEFINE_STRING_MAPPING(PseudoIsHtml)
DEFINE_STRING_MAPPING(PseudoListBox) DEFINE_STRING_MAPPING(PseudoListBox)
DEFINE_STRING_MAPPING(PseudoMultiSelectFocus) DEFINE_STRING_MAPPING(PseudoMultiSelectFocus)
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "third_party/blink/renderer/core/html/forms/slider_thumb_element.h" #include "third_party/blink/renderer/core/html/forms/slider_thumb_element.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h" #include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h" #include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
namespace blink { namespace blink {
...@@ -52,41 +51,6 @@ inline static Decimal SliderPosition(HTMLInputElement* element) { ...@@ -52,41 +51,6 @@ inline static Decimal SliderPosition(HTMLInputElement* element) {
return step_range.ProportionFromValue(step_range.ClampValue(old_value)); return step_range.ProportionFromValue(step_range.ClampValue(old_value));
} }
void LayoutSliderContainer::ComputeLogicalHeight(
LayoutUnit logical_height,
LayoutUnit logical_top,
LogicalExtentComputedValues& computed_values) const {
auto* input = To<HTMLInputElement>(GetNode()->OwnerShadowHost());
if (input->GetLayoutObject() && input->list()) {
int offset_from_center =
LayoutTheme::GetTheme().SliderTickOffsetFromTrackCenter();
LayoutUnit track_height;
if (offset_from_center < 0) {
track_height = LayoutUnit(-2 * offset_from_center);
} else {
int tick_length = LayoutTheme::GetTheme().SliderTickSize().Height();
track_height = LayoutUnit(2 * (offset_from_center + tick_length));
}
float zoom_factor = StyleRef().EffectiveZoom();
if (zoom_factor != 1.0)
track_height *= zoom_factor;
// FIXME: The trackHeight should have been added before updateLogicalHeight
// was called to avoid this hack.
SetIntrinsicContentLogicalHeight(track_height);
LayoutBox::ComputeLogicalHeight(track_height, logical_top, computed_values);
return;
}
// FIXME: The trackHeight should have been added before updateLogicalHeight
// was called to avoid this hack.
SetIntrinsicContentLogicalHeight(logical_height);
LayoutBox::ComputeLogicalHeight(logical_height, logical_top, computed_values);
}
MinMaxSizes LayoutSliderContainer::ComputeIntrinsicLogicalWidths() const { MinMaxSizes LayoutSliderContainer::ComputeIntrinsicLogicalWidths() const {
MinMaxSizes sizes; MinMaxSizes sizes;
sizes += LayoutUnit(kDefaultTrackLength * StyleRef().EffectiveZoom()) + sizes += LayoutUnit(kDefaultTrackLength * StyleRef().EffectiveZoom()) +
......
...@@ -38,16 +38,12 @@ namespace blink { ...@@ -38,16 +38,12 @@ namespace blink {
class SliderContainerElement; class SliderContainerElement;
// FIXME: Find a way to cascade appearance and adjust heights, and get rid of
// this class. See http://webkit.org/b/62535
class LayoutSliderContainer final : public LayoutFlexibleBox { class LayoutSliderContainer final : public LayoutFlexibleBox {
public: public:
static const int kDefaultTrackLength; static const int kDefaultTrackLength;
LayoutSliderContainer(SliderContainerElement*); explicit LayoutSliderContainer(SliderContainerElement*);
void ComputeLogicalHeight(LayoutUnit logical_height,
LayoutUnit logical_top,
LogicalExtentComputedValues&) const override;
MinMaxSizes ComputeIntrinsicLogicalWidths() const override; MinMaxSizes ComputeIntrinsicLogicalWidths() const override;
private: private:
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "third_party/blink/renderer/core/layout/layout_theme_android.h" #include "third_party/blink/renderer/core/layout/layout_theme_android.h"
#include "ui/base/ui_base_features.h"
namespace blink { namespace blink {
scoped_refptr<LayoutTheme> LayoutThemeAndroid::Create() { scoped_refptr<LayoutTheme> LayoutThemeAndroid::Create() {
...@@ -17,4 +19,17 @@ LayoutTheme& LayoutTheme::NativeTheme() { ...@@ -17,4 +19,17 @@ LayoutTheme& LayoutTheme::NativeTheme() {
LayoutThemeAndroid::~LayoutThemeAndroid() {} LayoutThemeAndroid::~LayoutThemeAndroid() {}
String LayoutThemeAndroid::ExtraDefaultStyleSheet() {
String extra_sheet = LayoutThemeMobile::ExtraDefaultStyleSheet();
if (features::IsFormControlsRefreshEnabled())
return extra_sheet;
// "32px" comes from
// 2 * -LayoutThemeDefault::SliderTickOffsetFromTrackCenter().
return extra_sheet + R"CSS(
input[type="range" i]:-internal-has-datalist::-webkit-slider-container {
min-block-size: 32px;
})CSS";
}
} // namespace blink } // namespace blink
...@@ -13,6 +13,7 @@ class LayoutThemeAndroid final : public LayoutThemeMobile { ...@@ -13,6 +13,7 @@ class LayoutThemeAndroid final : public LayoutThemeMobile {
public: public:
static scoped_refptr<LayoutTheme> Create(); static scoped_refptr<LayoutTheme> Create();
bool DelegatesMenuListRendering() const override { return true; } bool DelegatesMenuListRendering() const override { return true; }
String ExtraDefaultStyleSheet() override;
private: private:
~LayoutThemeAndroid() override; ~LayoutThemeAndroid() override;
......
...@@ -106,6 +106,8 @@ Color LayoutThemeDefault::PlatformInactiveSelectionForegroundColor( ...@@ -106,6 +106,8 @@ Color LayoutThemeDefault::PlatformInactiveSelectionForegroundColor(
} }
IntSize LayoutThemeDefault::SliderTickSize() const { IntSize LayoutThemeDefault::SliderTickSize() const {
// The value should be synchronized with a -webkit-slider-container rule in
// html.css.
if (features::IsFormControlsRefreshEnabled()) if (features::IsFormControlsRefreshEnabled())
return IntSize(1, 4); return IntSize(1, 4);
else else
...@@ -113,6 +115,8 @@ IntSize LayoutThemeDefault::SliderTickSize() const { ...@@ -113,6 +115,8 @@ IntSize LayoutThemeDefault::SliderTickSize() const {
} }
int LayoutThemeDefault::SliderTickOffsetFromTrackCenter() const { int LayoutThemeDefault::SliderTickOffsetFromTrackCenter() const {
// The value should be synchronized with a -webkit-slider-container rule in
// html.css and LayoutThemeAndroid::ExtraDefaultStyleSheet().
if (features::IsFormControlsRefreshEnabled()) if (features::IsFormControlsRefreshEnabled())
return 7; return 7;
else else
......
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