Commit a3616611 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Pass ScrollableArea ColorScheme for scrollbar painting.

Bug: 939811
Change-Id: I17964cd5d3dbfd699103f645b7a9ec45c46e0579
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1742148
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686750}
parent 368596e5
......@@ -271,6 +271,10 @@ ScrollBehavior RootFrameViewport::ScrollBehaviorStyle() const {
return LayoutViewport().ScrollBehaviorStyle();
}
WebColorScheme RootFrameViewport::UsedColorScheme() const {
return LayoutViewport().UsedColorScheme();
}
ScrollOffset RootFrameViewport::ClampToUserScrollableOffset(
const ScrollOffset& offset) const {
ScrollOffset scroll_offset = offset;
......
......@@ -115,6 +115,7 @@ class CORE_EXPORT RootFrameViewport final
void UpdateCompositorScrollAnimations() override;
void CancelProgrammaticScrollAnimation() override;
ScrollBehavior ScrollBehaviorStyle() const override;
WebColorScheme UsedColorScheme() const override;
void ClearScrollableArea() override;
LayoutBox* GetLayoutBox() const override;
FloatQuad LocalToVisibleContentQuad(const FloatQuad&,
......
......@@ -1450,6 +1450,8 @@ class ScrollbarAppearanceTest
class StubWebThemeEngine : public WebThemeEngine {
public:
StubWebThemeEngine() { painted_color_scheme_.fill(WebColorScheme::kLight); }
WebSize GetSize(Part part) override {
switch (part) {
case kPartScrollbarHorizontalThumb:
......@@ -1469,6 +1471,24 @@ class StubWebThemeEngine : public WebThemeEngine {
}
static constexpr int kMinimumHorizontalLength = 51;
static constexpr int kMinimumVerticalLength = 52;
void Paint(cc::PaintCanvas*,
Part part,
State,
const WebRect&,
const ExtraParams*,
blink::WebColorScheme color_scheme) override {
// Make sure we don't overflow the array.
DCHECK(part <= kPartProgressBar);
painted_color_scheme_[part] = color_scheme;
}
WebColorScheme GetPaintedPartColorScheme(Part part) const {
return painted_color_scheme_[part];
}
private:
std::array<WebColorScheme, kPartProgressBar + 1> painted_color_scheme_;
};
constexpr int StubWebThemeEngine::kMinimumHorizontalLength;
......@@ -2647,6 +2667,61 @@ TEST_F(ScrollbarTrackMarginsTest,
EXPECT_EQ(51, vertical_track_->MarginBottom());
}
class ScrollbarColorSchemeTest : public ScrollbarAppearanceTest {};
INSTANTIATE_TEST_SUITE_P(NonOverlay,
ScrollbarColorSchemeTest,
testing::Values(false));
#if defined(OS_ANDROID) || defined(OS_MACOSX)
// Not able to paint non-overlay scrollbars through ThemeEngine on Android or
// Mac.
#define MAYBE_ThemeEngineScrollbarThumb DISABLED_ThemeEngineScrollbarThumb
#else
#define MAYBE_ThemeEngineScrollbarThumb ThemeEngineScrollbarThumb
#endif
TEST_P(ScrollbarColorSchemeTest, MAYBE_ThemeEngineScrollbarThumb) {
ScopedTestingPlatformSupport<ScrollbarTestingPlatformSupport> platform;
ScopedCSSColorSchemeForTest css_feature_scope(true);
WebView().MainFrameWidget()->Resize(WebSize(800, 600));
SimRequest request("https://example.com/test.html", "text/html");
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<style>
#scrollable {
width: 100px;
height: 100px;
overflow: scroll;
color-scheme: dark;
}
#filler {
width: 200px;
height: 200px;
}
</style>
<div id="scrollable">
<div id="filler"></div>
</div>
)HTML");
GetDocument().GetSettings()->SetPreferredColorScheme(
PreferredColorScheme::kDark);
Compositor().BeginFrame();
auto* theme_engine =
static_cast<StubWebThemeEngine*>(Platform::Current()->ThemeEngine());
EXPECT_EQ(WebColorScheme::kDark,
theme_engine->GetPaintedPartColorScheme(
WebThemeEngine::kPartScrollbarHorizontalThumb));
EXPECT_EQ(WebColorScheme::kDark,
theme_engine->GetPaintedPartColorScheme(
WebThemeEngine::kPartScrollbarVerticalThumb));
}
} // namespace
} // namespace blink
......@@ -1115,6 +1115,10 @@ ScrollBehavior PaintLayerScrollableArea::ScrollBehaviorStyle() const {
return GetLayoutBox()->StyleRef().GetScrollBehavior();
}
WebColorScheme PaintLayerScrollableArea::UsedColorScheme() const {
return GetLayoutBox()->StyleRef().UsedColorScheme();
}
bool PaintLayerScrollableArea::HasHorizontalOverflow() const {
// TODO(szager): Make the algorithm for adding/subtracting overflow:auto
// scrollbars memoryless (crbug.com/625300). This client_width hack will
......
......@@ -335,6 +335,7 @@ class CORE_EXPORT PaintLayerScrollableArea final
bool ShouldPlaceVerticalScrollbarOnLeft() const override;
int PageStep(ScrollbarOrientation) const override;
ScrollBehavior ScrollBehaviorStyle() const override;
WebColorScheme UsedColorScheme() const override;
cc::AnimationHost* GetCompositorAnimationHost() const override;
CompositorAnimationTimeline* GetCompositorAnimationTimeline() const override;
void GetTickmarks(Vector<IntRect>&) const override;
......
......@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SCROLL_SCROLLABLE_AREA_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCROLL_SCROLLABLE_AREA_H_
#include "third_party/blink/public/platform/web_color_scheme.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
#include "third_party/blink/renderer/core/scroll/scrollbar.h"
......@@ -364,6 +365,10 @@ class CORE_EXPORT ScrollableArea : public GarbageCollectedMixin {
return kScrollBehaviorInstant;
}
virtual WebColorScheme UsedColorScheme() const {
return WebColorScheme::kLight;
}
// Subtracts space occupied by this ScrollableArea's scrollbars.
// Does nothing if overlay scrollbars are enabled.
IntSize ExcludeScrollbars(const IntSize&) const;
......
......@@ -807,6 +807,10 @@ bool Scrollbar::ContainerIsRightToLeft() const {
return false;
}
WebColorScheme Scrollbar::UsedColorScheme() const {
return scrollable_area_->UsedColorScheme();
}
STATIC_ASSERT_ENUM(kWebScrollbarOverlayColorThemeDark,
kScrollbarOverlayColorThemeDark);
STATIC_ASSERT_ENUM(kWebScrollbarOverlayColorThemeLight,
......
......@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SCROLL_SCROLLBAR_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCROLL_SCROLLBAR_H_
#include "third_party/blink/public/platform/web_color_scheme.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/scroll/scroll_types.h"
#include "third_party/blink/renderer/platform/graphics/compositor_element_id.h"
......@@ -199,6 +200,8 @@ class CORE_EXPORT Scrollbar : public GarbageCollectedFinalized<Scrollbar>,
// is the element that owns our PaintLayerScrollableArea.
Element* StyleSource() const { return style_source_.Get(); }
WebColorScheme UsedColorScheme() const;
virtual void Trace(blink::Visitor*);
protected:
......
......@@ -263,9 +263,7 @@ void ScrollbarThemeAura::PaintTrackPiece(GraphicsContext& gc,
scrollbar.Orientation() == kHorizontalScrollbar
? WebThemeEngine::kPartScrollbarHorizontalTrack
: WebThemeEngine::kPartScrollbarVerticalTrack,
state, WebRect(rect), &extra_params,
WebColorScheme::
kLight /* TODO(futhark): pass color scheme to scrollbar parts */);
state, WebRect(rect), &extra_params, scrollbar.UsedColorScheme());
}
void ScrollbarThemeAura::PaintButton(GraphicsContext& gc,
......@@ -288,8 +286,7 @@ void ScrollbarThemeAura::PaintButton(GraphicsContext& gc,
scrollbar.ContainerIsRightToLeft();
Platform::Current()->ThemeEngine()->Paint(
gc.Canvas(), params.part, params.state, WebRect(rect), &extra_params,
WebColorScheme::
kLight /* TODO(futhark): pass color scheme to scrollbar parts */);
scrollbar.UsedColorScheme());
}
void ScrollbarThemeAura::PaintThumb(GraphicsContext& gc,
......@@ -315,9 +312,7 @@ void ScrollbarThemeAura::PaintThumb(GraphicsContext& gc,
scrollbar.Orientation() == kHorizontalScrollbar
? WebThemeEngine::kPartScrollbarHorizontalThumb
: WebThemeEngine::kPartScrollbarVerticalThumb,
state, WebRect(rect), nullptr,
WebColorScheme::
kLight /* TODO(futhark): pass color scheme to scrollbars */);
state, WebRect(rect), nullptr, scrollbar.UsedColorScheme());
}
bool ScrollbarThemeAura::ShouldRepaintAllPartsOnInvalidation() const {
......
......@@ -196,8 +196,8 @@ void ScrollbarThemeOverlay::PaintThumb(GraphicsContext& context,
canvas->scale(-1, 1);
}
Platform::Current()->ThemeEngine()->Paint(canvas, part, state, WebRect(rect),
&params, WebColorScheme::kLight);
Platform::Current()->ThemeEngine()->Paint(
canvas, part, state, WebRect(rect), &params, scrollbar.UsedColorScheme());
if (scrollbar.IsLeftSideVerticalScrollbar())
canvas->restore();
......
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