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) {
case kPseudoPictureInPicture:
case kPseudoSpatialNavigationFocus:
case kPseudoSpatialNavigationInterest:
case kPseudoHasDatalist:
case kPseudoIsHtml:
case kPseudoListBox:
case kPseudoMultiSelectFocus:
......@@ -316,6 +317,7 @@ struct NameToPseudoStruct {
const static NameToPseudoStruct kPseudoTypeWithoutArgumentsMap[] = {
{"-internal-autofill-previewed", CSSSelector::kPseudoAutofillPreviewed},
{"-internal-autofill-selected", CSSSelector::kPseudoAutofillSelected},
{"-internal-has-datalist", CSSSelector::kPseudoHasDatalist},
{"-internal-is-html", CSSSelector::kPseudoIsHtml},
{"-internal-list-box", CSSSelector::kPseudoListBox},
{"-internal-media-controls-overlay-cast-button",
......@@ -590,6 +592,7 @@ void CSSSelector::UpdatePseudoType(const AtomicString& value,
if (match_ != kPseudoElement || mode != kUASheetMode)
pseudo_type_ = kPseudoUnknown;
break;
case kPseudoHasDatalist:
case kPseudoHostHasAppearance:
case kPseudoIsHtml:
case kPseudoListBox:
......@@ -983,6 +986,7 @@ static bool ValidateSubSelector(const CSSSelector* selector) {
case CSSSelector::kPseudoNot:
case CSSSelector::kPseudoSpatialNavigationFocus:
case CSSSelector::kPseudoSpatialNavigationInterest:
case CSSSelector::kPseudoHasDatalist:
case CSSSelector::kPseudoIsHtml:
case CSSSelector::kPseudoListBox:
case CSSSelector::kPseudoHostHasAppearance:
......
......@@ -243,6 +243,7 @@ class CORE_EXPORT CSSSelector {
kPseudoUnresolved,
kPseudoDefined,
kPseudoContent,
kPseudoHasDatalist,
kPseudoHost,
kPseudoHostContext,
kPseudoShadow,
......
......@@ -164,6 +164,7 @@ bool SupportsInvalidation(CSSSelector::PseudoType type) {
case CSSSelector::kPseudoShadow:
case CSSSelector::kPseudoSpatialNavigationFocus:
case CSSSelector::kPseudoSpatialNavigationInterest:
case CSSSelector::kPseudoHasDatalist:
case CSSSelector::kPseudoIsHtml:
case CSSSelector::kPseudoListBox:
case CSSSelector::kPseudoMultiSelectFocus:
......@@ -555,6 +556,7 @@ InvalidationSet* RuleFeatureSet::InvalidationSetForSimpleSelector(
case CSSSelector::kPseudoVideoPersistentAncestor:
case CSSSelector::kPseudoXrOverlay:
case CSSSelector::kPseudoSpatialNavigationInterest:
case CSSSelector::kPseudoHasDatalist:
case CSSSelector::kPseudoMultiSelectFocus:
return &EnsurePseudoInvalidationSet(selector.GetPseudoType(), type,
position);
......
......@@ -86,6 +86,11 @@ static bool MatchesSpatialNavigationFocusPseudoClass(const Element& 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) {
auto* html_select_element = DynamicTo<HTMLSelectElement>(element);
return html_select_element && !html_select_element->UsesMenuList();
......@@ -1296,6 +1301,9 @@ bool SelectorChecker::CheckPseudoClass(const SelectorCheckingContext& context,
case CSSSelector::kPseudoSpatialNavigationInterest:
DCHECK(is_ua_rule_);
return MatchesSpatialNavigationInterestPseudoClass(element);
case CSSSelector::kPseudoHasDatalist:
DCHECK(is_ua_rule_);
return MatchesHasDatalistPseudoClass(element);
case CSSSelector::kPseudoIsHtml:
DCHECK(is_ua_rule_);
return IsA<HTMLDocument>(element.GetDocument());
......
......@@ -447,6 +447,9 @@ void HTMLInputElement::UpdateType() {
PseudoStateChanged(CSSSelector::kPseudoInRange);
PseudoStateChanged(CSSSelector::kPseudoOutOfRange);
}
if (input_type_->ShouldRespectListAttribute() !=
new_type->ShouldRespectListAttribute())
PseudoStateChanged(CSSSelector::kPseudoHasDatalist);
bool placeholder_changed =
input_type_->SupportsPlaceholder() != new_type->SupportsPlaceholder();
......@@ -882,6 +885,7 @@ void HTMLInputElement::ParseAttribute(
ResetListAttributeTargetObserver();
ListAttributeTargetChanged();
}
PseudoStateChanged(CSSSelector::kPseudoHasDatalist);
UseCounter::Count(GetDocument(), WebFeature::kListAttribute);
} else if (name == html_names::kWebkitdirectoryAttr) {
TextControlElement::ParseAttribute(params);
......@@ -1752,6 +1756,7 @@ void HTMLInputElement::ResetListAttributeTargetObserver() {
void HTMLInputElement::ListAttributeTargetChanged() {
input_type_view_->ListAttributeTargetChanged();
PseudoStateChanged(CSSSelector::kPseudoHasDatalist);
}
bool HTMLInputElement::IsSteppable() const {
......
......@@ -643,6 +643,14 @@ input[type="range" i]::-webkit-slider-container, input[type="range" i]::-webkit-
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 {
flex: 1;
min-inline-size: 0;
......
......@@ -360,6 +360,7 @@ const char* PseudoTypeToString(CSSSelector::PseudoType pseudo_type) {
DEFINE_STRING_MAPPING(PseudoSlotted)
DEFINE_STRING_MAPPING(PseudoSpatialNavigationFocus)
DEFINE_STRING_MAPPING(PseudoSpatialNavigationInterest)
DEFINE_STRING_MAPPING(PseudoHasDatalist)
DEFINE_STRING_MAPPING(PseudoIsHtml)
DEFINE_STRING_MAPPING(PseudoListBox)
DEFINE_STRING_MAPPING(PseudoMultiSelectFocus)
......
......@@ -36,7 +36,6 @@
#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/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
namespace blink {
......@@ -52,41 +51,6 @@ inline static Decimal SliderPosition(HTMLInputElement* element) {
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 sizes;
sizes += LayoutUnit(kDefaultTrackLength * StyleRef().EffectiveZoom()) +
......
......@@ -38,16 +38,12 @@ namespace blink {
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 {
public:
static const int kDefaultTrackLength;
LayoutSliderContainer(SliderContainerElement*);
void ComputeLogicalHeight(LayoutUnit logical_height,
LayoutUnit logical_top,
LogicalExtentComputedValues&) const override;
explicit LayoutSliderContainer(SliderContainerElement*);
MinMaxSizes ComputeIntrinsicLogicalWidths() const override;
private:
......
......@@ -4,6 +4,8 @@
#include "third_party/blink/renderer/core/layout/layout_theme_android.h"
#include "ui/base/ui_base_features.h"
namespace blink {
scoped_refptr<LayoutTheme> LayoutThemeAndroid::Create() {
......@@ -17,4 +19,17 @@ LayoutTheme& LayoutTheme::NativeTheme() {
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
......@@ -13,6 +13,7 @@ class LayoutThemeAndroid final : public LayoutThemeMobile {
public:
static scoped_refptr<LayoutTheme> Create();
bool DelegatesMenuListRendering() const override { return true; }
String ExtraDefaultStyleSheet() override;
private:
~LayoutThemeAndroid() override;
......
......@@ -106,6 +106,8 @@ Color LayoutThemeDefault::PlatformInactiveSelectionForegroundColor(
}
IntSize LayoutThemeDefault::SliderTickSize() const {
// The value should be synchronized with a -webkit-slider-container rule in
// html.css.
if (features::IsFormControlsRefreshEnabled())
return IntSize(1, 4);
else
......@@ -113,6 +115,8 @@ IntSize LayoutThemeDefault::SliderTickSize() 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())
return 7;
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