8000 `appearance: slider-vertical` should only apply to range inputs · WebKit/WebKit@b03a814 · GitHub
[go: up one dir, main page]

Skip to content

Commit b03a814

Browse files
committed
appearance: slider-vertical should only apply to range inputs
https://bugs.webkit.org/show_bug.cgi?id=250492 rdar://104147398 Reviewed by Tim Nguyen. `slider-vertical` is a non-standard `appearance` value, maintained as legacy `-webkit-appearance` behavior. It is not possible to paint `slider-vertical` without an `<input type=range>`. However, there is currently logic that guards against attempts to paint `slider-vertical` for non-range input elements, since the effective appearance is not always adjusted. Ensure that `slider-vertical` can only be an effective appearance for range inputs, and replace checks for range inputs with assertions. * LayoutTests/fast/forms/slider-track-not-input-element-expected.html: Added. * LayoutTests/fast/forms/slider-track-not-input-element-expected.txt: Removed. * LayoutTests/fast/forms/slider-track-not-input-element.html: Updated crash test to be a reference test. * Source/WebCore/rendering/RenderTheme.cpp: (WebCore::RenderTheme::adjustAppearanceForElement const): (WebCore::createSliderTrackPartForRenderer): Canonical link: https://commits.webkit.org/258924@main
1 parent 003ff7e commit b03a814

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<style>
2+
input {
3+
width: 70px;
4+
height: 200px;
5+
appearance: slider-vertical;
6+
}
7+
</style>
8+
<body>
9+
<input type="range">
10+
<div></div>
11+
</body>

LayoutTests/fast/forms/slider-track-not-input-element-expected.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<style>
2-
html {
3-
appearance: slider-vertical;
2+
input, div {
3+
width: 70px;
4+
height: 200px;
5+
appearance: slider-vertical;
46
}
57
</style>
68
<body>
7-
<p>This test passes if it does not crash.</p>
8-
<script>
9-
if (window.testRunner)
10-
testRunner.dumpAsText();
11-
</script>
9+
<input type="range">
10+
<div></div>
1211
</body>

Source/WebCore/rendering/RenderTheme.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,17 @@ StyleAppearance RenderTheme::adjustAppearanceForElement(RenderStyle& style, cons
145145
return autoAppearance;
146146
}
147147

148+
auto* inputElement = dynamicDowncast<HTMLInputElement>(element);
149+
148150
if (appearance == StyleAppearance::TextField) {
149-
if (is<HTMLInputElement>(*element) && downcast<HTMLInputElement>(*element).isSearchField())
151+
if (inputElement && inputElement->isSearchField())
152+
return appearance;
153+
style.setEffectiveAppearance(autoAppearance);
154+
return autoAppearance;
155+
}
156+
157+
if (appearance == StyleAppearance::SliderVertical) {
158+
if (inputElement && inputElement->isRangeControl())
150159
return appearance;
151160
style.setEffectiveAppearance(autoAppearance);
152161
return autoAppearance;
@@ -506,21 +515,20 @@ static RefPtr<ControlPart> createProgressBarPartForRenderer(const RenderObject&
506515
static RefPtr<ControlPart> createSliderTrackPartForRenderer(const RenderObject& renderer)
507516
{
508517 8000
auto type = renderer.style().effectiveAppearance();
509-
if (type != StyleAppearance::SliderHorizontal && type != StyleAppearance::SliderVertical)
510-
return nullptr;
518+
ASSERT(type == StyleAppearance::SliderHorizontal || type == StyleAppearance::SliderVertical);
511519

512-
auto* input = dynamicDowncast<HTMLInputElement>(renderer.node());
513-
if (!input || !input->isRangeControl())
514-
return nullptr;
520+
ASSERT(is<HTMLInputElement>(renderer.node()));
521+
auto& input = downcast<HTMLInputElement>(*renderer.node());
522+
ASSERT(input.isRangeControl());
515523

516524
IntSize thumbSize;
517-
if (const auto* thumbRenderer = input->sliderThumbElement()->renderer()) {
525+
if (const auto* thumbRenderer = input.sliderThumbElement()->renderer()) {
518526
const auto& thumbStyle = thumbRenderer->style();
519527
thumbSize = IntSize { thumbStyle.width().intValue(), thumbStyle.height().intValue() };
520528
}
521529

522530
IntRect trackBounds;
523-
if (const auto* trackRenderer = input->sliderTrackElement()->renderer()) {
531+
if (const auto* trackRenderer = input.sliderTrackElement()->renderer()) {
524532
trackBounds = trackRenderer->absoluteBoundingBoxRectIgnoringTransforms();
525533

526534
// We can ignoring transforms because transform is handled by the graphics context.
@@ -532,12 +540,12 @@ static RefPtr<ControlPart> createSliderTrackPartForRenderer(const RenderObject&
532540

533541
Vector<double> tickRatios;
534542
#if ENABLE(DATALIST_ELEMENT)
535-
if (auto dataList = input->dataList()) {
536-
double minimum = input->minimum();
537-
double maximum = input->maximum();
543+
if (auto dataList = input.dataList()) {
544+
double minimum = input.minimum();
545+
double maximum = input.maximum();
538546

539547
for (auto& optionElement : dataList->suggestions()) {
540-
auto optionValue = input->listOptionValueAsDouble(optionElement);
548+
auto optionValue = input.listOptionValueAsDouble(optionElement);
541549
if (!optionValue)
542550
continue;
543551
double tickRatio = (*optionValue - minimum) / (maximum - minimum);

0 commit comments

Comments
 (0)
0