Commit 45d47c71 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Remove LayoutSliderContainer::ComputeIntrinsicLogicalWidths()

* Fold it into LayoutBox like other form control elements.
* Introduce IsSliderContainer() to share identical code between
  LayoutBox and LayoutTheme.
* Move kDefaultTrackLength from LayoutSliderContainer to
  SliderIntrinsicInlineSize() in layout_box.cc

This CL has no behavior changes.

Bug: 1040826
Change-Id: I70bb3c67a1fbdc40502e36ca68d890719fc02f2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392280Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804133}
parent d1c3e060
......@@ -536,6 +536,8 @@ blink_core_sources("html") {
"shadow/progress_shadow_element.h",
"shadow/shadow_element_names.cc",
"shadow/shadow_element_names.h",
"shadow/shadow_element_utils.cc",
"shadow/shadow_element_utils.h",
"table_constants.h",
"text_document.cc",
"text_document.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/html/shadow/shadow_element_utils.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
namespace blink {
bool IsSliderContainer(const Element& element) {
if (!element.IsInUserAgentShadowRoot())
return false;
const AtomicString& shadow_pseudo = element.ShadowPseudoId();
return shadow_pseudo == "-webkit-media-slider-container" ||
shadow_pseudo == "-webkit-slider-container";
}
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_SHADOW_SHADOW_ELEMENT_UTILS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_SHADOW_SHADOW_ELEMENT_UTILS_H_
namespace blink {
class Element;
bool IsSliderContainer(const Element& elmenet);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_SHADOW_SHADOW_ELEMENT_UTILS_H_
......@@ -49,6 +49,7 @@
#include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/html/html_frame_element_base.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_utils.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/api/line_layout_block_flow.h"
......@@ -66,7 +67,6 @@
#include "third_party/blink/renderer/core/layout/layout_list_marker.h"
#include "third_party/blink/renderer/core/layout/layout_multi_column_flow_thread.h"
#include "third_party/blink/renderer/core/layout/layout_multi_column_spanner_placeholder.h"
#include "third_party/blink/renderer/core/layout/layout_slider_container.h"
#include "third_party/blink/renderer/core/layout/layout_table_cell.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/ng/custom/custom_layout_child.h"
......@@ -158,10 +158,9 @@ LayoutUnit FileUploadControlIntrinsicInlineSize(const HTMLInputElement& input,
ceilf(std::max(min_default_label_width, default_label_width)));
}
LayoutUnit SliderIntrinsicInlineSize(const HTMLInputElement& input,
const LayoutBox& box) {
return LayoutUnit(LayoutSliderContainer::kDefaultTrackLength *
box.StyleRef().EffectiveZoom());
LayoutUnit SliderIntrinsicInlineSize(const LayoutBox& box) {
constexpr int kDefaultTrackLength = 129;
return LayoutUnit(kDefaultTrackLength * box.StyleRef().EffectiveZoom());
}
LayoutUnit ListBoxDefaultItemHeight(const LayoutBox& box) {
......@@ -1007,18 +1006,25 @@ LayoutUnit LayoutBox::DefaultIntrinsicContentInlineSize() const {
// get here.
DCHECK(!HasOverrideIntrinsicContentLogicalWidth());
auto* select = DynamicTo<HTMLSelectElement>(GetNode());
if (!IsA<Element>(GetNode()))
return kIndefiniteSize;
const Element& element = *To<Element>(GetNode());
auto* select = DynamicTo<HTMLSelectElement>(element);
if (UNLIKELY(select && select->UsesMenuList())) {
return MenuListIntrinsicInlineSize(*select, *this);
}
auto* input = DynamicTo<HTMLInputElement>(GetNode());
auto* input = DynamicTo<HTMLInputElement>(element);
if (UNLIKELY(input)) {
const AtomicString& type = input->type();
if (type == input_type_names::kFile)
return FileUploadControlIntrinsicInlineSize(*input, *this);
else if (type == input_type_names::kRange)
return SliderIntrinsicInlineSize(*input, *this);
return SliderIntrinsicInlineSize(*this);
return kIndefiniteSize;
}
if (IsSliderContainer(element))
return SliderIntrinsicInlineSize(*this);
return kIndefiniteSize;
}
......
......@@ -39,8 +39,6 @@
namespace blink {
const int LayoutSliderContainer::kDefaultTrackLength = 129;
LayoutSliderContainer::LayoutSliderContainer(SliderContainerElement* element)
: LayoutFlexibleBox(element) {}
......@@ -51,13 +49,6 @@ inline static Decimal SliderPosition(HTMLInputElement* element) {
return step_range.ProportionFromValue(step_range.ClampValue(old_value));
}
MinMaxSizes LayoutSliderContainer::ComputeIntrinsicLogicalWidths() const {
MinMaxSizes sizes;
sizes += LayoutUnit(kDefaultTrackLength * StyleRef().EffectiveZoom()) +
BorderAndPaddingLogicalWidth();
return sizes;
}
void LayoutSliderContainer::UpdateLayout() {
auto* input = To<HTMLInputElement>(GetNode()->OwnerShadowHost());
const bool is_vertical = !StyleRef().IsHorizontalWritingMode();
......
......@@ -40,12 +40,8 @@ class SliderContainerElement;
class LayoutSliderContainer final : public LayoutFlexibleBox {
public:
static const int kDefaultTrackLength;
explicit LayoutSliderContainer(SliderContainerElement*);
MinMaxSizes ComputeIntrinsicLogicalWidths() const override;
private:
void UpdateLayout() override;
};
......
......@@ -44,6 +44,7 @@
#include "third_party/blink/renderer/core/html/html_collection.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_utils.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
......@@ -128,11 +129,9 @@ ControlPart AutoAppearanceFor(const Element& element) {
return kSearchFieldCancelButtonPart;
// Slider container elements and -webkit-meter-inner-element don't have IDs.
const AtomicString& shadow_pseudo = element.ShadowPseudoId();
if (shadow_pseudo == "-webkit-media-slider-container" ||
shadow_pseudo == "-webkit-slider-container")
if (IsSliderContainer(element))
return kSliderHorizontalPart;
if (shadow_pseudo == "-webkit-meter-inner-element")
if (element.ShadowPseudoId() == "-webkit-meter-inner-element")
return kMeterPart;
}
return kNoControlPart;
......
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