Commit 614a0bfb authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Slider NG: Move SliderPosition() to HTMLInputElement

This CL makes SliderPosition() in layout_slider_track.cc a method of
blink::HTMLInputElement. This change will help to share the code
between the legacy layout and LayoutNG.

This CL has no behavior changes.

Bug: 1040826
Change-Id: I65bb04e8808820a812a4fabb82a7bf24c5f66341
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417780
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808240}
parent 5f4a50e0
......@@ -1264,6 +1264,14 @@ void HTMLInputElement::setValueAsNumber(double new_value,
input_type_->SetValueAsDouble(new_value, event_behavior, exception_state);
}
Decimal HTMLInputElement::RatioValue() const {
DCHECK_EQ(type(), input_type_names::kRange);
const StepRange step_range(CreateStepRange(kRejectAny));
const Decimal old_value =
ParseToDecimalForNumberType(value(), step_range.DefaultValue());
return step_range.ProportionFromValue(step_range.ClampValue(old_value));
}
void HTMLInputElement::SetValueFromRenderer(const String& value) {
// File upload controls will never use this.
DCHECK_NE(type(), input_type_names::kFile);
......
......@@ -174,6 +174,11 @@ class CORE_EXPORT HTMLInputElement
ExceptionState&,
TextFieldEventBehavior = TextFieldEventBehavior::kDispatchNoEvent);
// For type=range, returns a ratio of the current value in the range between
// min and max. i.e. (value - min) / (max - min)
// For other types, this function fails with DCHECK().
Decimal RatioValue() const;
String ValueOrDefaultLabel() const;
// This function dispatches 'input' event for non-textfield types. Callers
......
......@@ -33,9 +33,7 @@
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/slider_thumb_element.h"
#include "third_party/blink/renderer/core/html/forms/slider_track_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"
namespace blink {
......@@ -43,13 +41,6 @@ namespace blink {
LayoutSliderTrack::LayoutSliderTrack(SliderTrackElement* element)
: LayoutBlockFlow(element) {}
inline static Decimal SliderPosition(HTMLInputElement* element) {
const StepRange step_range(element->CreateStepRange(kRejectAny));
const Decimal old_value =
ParseToDecimalForNumberType(element->value(), step_range.DefaultValue());
return step_range.ProportionFromValue(step_range.ClampValue(old_value));
}
void LayoutSliderTrack::UpdateLayout() {
auto* input = To<HTMLInputElement>(GetNode()->OwnerShadowHost());
const bool is_vertical = !StyleRef().IsHorizontalWritingMode();
......@@ -73,7 +64,7 @@ void LayoutSliderTrack::UpdateLayout() {
if (!thumb)
return;
double percentage_offset = SliderPosition(input).ToDouble();
double percentage_offset = input->RatioValue().ToDouble();
LayoutUnit available_extent = is_vertical ? ContentHeight() : ContentWidth();
available_extent -=
is_vertical ? thumb->Size().Height() : thumb->Size().Width();
......
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