Commit 2a389bc9 authored by Jinfeng Ma's avatar Jinfeng Ma Committed by Commit Bot

Fix broken custom resizer for resizable HTML elements.

Some HTML elements may have a resizer which can be restyled by using CSS pseudo
element: -webkit-resizer, for example:
1. <textarea>;
2. <div> with overflow: hidden and resize: both;

The resizer of these elements can be displayed independently of the scrollbar.
So the custom resizer's construction, style updating, layout and paint offset
translation should be considered even if the scrollbar doesn't exist.

Bug: 863748
Change-Id: Ie097284fcf8f896c4a394548d0b553475d5f26b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757262
Commit-Queue: Philip Rogers <pdr@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689499}
parent 7427ffd8
......@@ -1188,6 +1188,10 @@ void PaintLayerScrollableArea::UpdateAfterStyleChange(
ComputeScrollbarExistence(needs_horizontal_scrollbar,
needs_vertical_scrollbar, kForbidAddingAutoBars);
if (!RuntimeEnabledFeatures::PaintNonFastScrollableRegionsEnabled())
UpdateResizerAreaSet();
UpdateResizerStyle(old_style);
// Avoid some unnecessary computation if there were and will be no scrollbars.
if (!HasScrollbar() && !needs_horizontal_scrollbar &&
!needs_vertical_scrollbar)
......@@ -1228,9 +1232,6 @@ void PaintLayerScrollableArea::UpdateAfterStyleChange(
VerticalScrollbar()->StyleChanged();
UpdateScrollCornerStyle();
if (!RuntimeEnabledFeatures::PaintNonFastScrollableRegionsEnabled())
UpdateResizerAreaSet();
UpdateResizerStyle(old_style);
}
void PaintLayerScrollableArea::UpdateAfterOverflowRecalc() {
......@@ -1647,7 +1648,7 @@ void PaintLayerScrollableArea::SnapAfterScrollbarScrolling(
}
void PaintLayerScrollableArea::PositionOverflowControls() {
if (!HasScrollbar() && !GetLayoutBox()->CanResize())
if (!HasOverflowControls() && !GetLayoutBox()->CanResize())
return;
const IntRect border_box =
......
......@@ -1155,4 +1155,27 @@ TEST_P(PaintLayerScrollableAreaTest, RtlScrollOriginSnapping) {
EXPECT_EQ(scrollable_area->MaximumScrollOffsetInt(), IntSize(0, 100));
}
TEST_P(PaintLayerScrollableAreaTest, ShowCustomResizerInTextarea) {
GetPage().GetSettings().SetTextAreasAreResizable(true);
SetBodyInnerHTML(R"HTML(
<!doctype HTML>
<style>
textarea {
width: 200px;
height: 100px;
}
::-webkit-resizer {
background-color: red;
}
</style>
<textarea id="target"></textarea>
)HTML");
const auto* paint_layer =
ToLayoutBoxModelObject(GetLayoutObjectByElementId("target"))->Layer();
ASSERT_TRUE(paint_layer);
EXPECT_NE(paint_layer->GetScrollableArea()->Resizer(), nullptr);
}
} // namespace blink
......@@ -321,11 +321,13 @@ static bool NeedsReplacedContentTransform(const LayoutObject& object) {
return false;
}
static bool NeedsPaintOffsetTranslationForScrollbars(
static bool NeedsPaintOffsetTranslationForOverflowControls(
const LayoutBoxModelObject& object) {
if (auto* area = object.GetScrollableArea()) {
if (area->HorizontalScrollbar() || area->VerticalScrollbar())
if (area->HorizontalScrollbar() || area->VerticalScrollbar() ||
area->Resizer()) {
return true;
}
}
return false;
}
......@@ -407,7 +409,7 @@ static bool NeedsPaintOffsetTranslation(
return true;
if (NeedsStickyTranslation(object))
return true;
if (NeedsPaintOffsetTranslationForScrollbars(box_model))
if (NeedsPaintOffsetTranslationForOverflowControls(box_model))
return true;
if (NeedsReplacedContentTransform(object))
return true;
......
......@@ -6090,6 +6090,34 @@ TEST_P(PaintPropertyTreeBuilderTest,
EXPECT_EQ(PhysicalOffset(100, 85), paint_offset("float-right-rtl-vlr"));
}
TEST_P(PaintPropertyTreeBuilderTest, PaintOffsetForTextareaWithResizer) {
GetPage().GetSettings().SetTextAreasAreResizable(true);
SetBodyInnerHTML(R"HTML(
<!doctype HTML>
<style>
div {
width: 100%;
height: 100px;
}
textarea {
width: 200px;
height: 100px;
}
::-webkit-resizer {
background-color: red;
}
</style>
<div></div>
<textarea id="target"></textarea>
)HTML");
const auto* box = ToLayoutBox(GetLayoutObjectByElementId("target"));
const auto& fragment = box->FirstFragment();
ASSERT_TRUE(fragment.PaintProperties());
EXPECT_NE(fragment.PaintProperties()->PaintOffsetTranslation(), nullptr);
EXPECT_EQ(PhysicalOffset(), fragment.PaintOffset());
}
TEST_P(PaintPropertyTreeBuilderTest, SubpixelPositionedScrollNode) {
SetBodyInnerHTML(R"HTML(
<!DOCTYPE html>
......
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