Commit a52c1959 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Ensure |is_upper| is initialized when painting scrollbar tracks.

This variable was never written, so we were always reading an uninitialized
value.  However, the only effect was to toggle between the UPPER and LOWER track
parts, which AFAIK always look the same.  So I don't think this could have a
user-visible effect.  Still, it was technically UB.

Fix it the right way by making ScrollBarViews paint the track in upper and lower
pieces and set the bit correctly for each one.  Thus, if the appearance actually
differs for any theme out there, this should get it right.

This also copies the parallel-meaning WebThemeEngine |is_back| member, so
scrollbars painted from that source have the bit set too.

Bug: 374410
Change-Id: Ib37f54e369f08dd6439d9edb969af13cc02ddf3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790474Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694540}
parent 48946365
...@@ -132,6 +132,8 @@ static void GetNativeThemeExtraParams( ...@@ -132,6 +132,8 @@ static void GetNativeThemeExtraParams(
switch (part) { switch (part) {
case WebThemeEngine::kPartScrollbarHorizontalTrack: case WebThemeEngine::kPartScrollbarHorizontalTrack:
case WebThemeEngine::kPartScrollbarVerticalTrack: case WebThemeEngine::kPartScrollbarVerticalTrack:
native_theme_extra_params->scrollbar_track.is_upper =
extra_params->scrollbar_track.is_back;
native_theme_extra_params->scrollbar_track.track_x = native_theme_extra_params->scrollbar_track.track_x =
extra_params->scrollbar_track.track_x; extra_params->scrollbar_track.track_x;
native_theme_extra_params->scrollbar_track.track_y = native_theme_extra_params->scrollbar_track.track_y =
......
...@@ -253,12 +253,14 @@ void ScrollBarViews::Layout() { ...@@ -253,12 +253,14 @@ void ScrollBarViews::Layout() {
size.height()); size.height());
} }
// All that matters here is updating the thumb X or Y coordinate (for vertical
// or horizontal scrollbars, respectively); the rest of the bounds will be
// overwritten by ScrollBar::Update() shortly.
GetThumb()->SetBoundsRect(GetTrackBounds()); GetThumb()->SetBoundsRect(GetTrackBounds());
} }
void ScrollBarViews::OnPaint(gfx::Canvas* canvas) { void ScrollBarViews::OnPaint(gfx::Canvas* canvas) {
gfx::Rect bounds = GetTrackBounds(); gfx::Rect bounds = GetTrackBounds();
if (bounds.IsEmpty()) if (bounds.IsEmpty())
return; return;
...@@ -267,8 +269,28 @@ void ScrollBarViews::OnPaint(gfx::Canvas* canvas) { ...@@ -267,8 +269,28 @@ void ScrollBarViews::OnPaint(gfx::Canvas* canvas) {
params_.scrollbar_track.track_width = bounds.width(); params_.scrollbar_track.track_width = bounds.width();
params_.scrollbar_track.track_height = bounds.height(); params_.scrollbar_track.track_height = bounds.height();
params_.scrollbar_track.classic_state = 0; params_.scrollbar_track.classic_state = 0;
const BaseScrollBarThumb* thumb = GetThumb();
params_.scrollbar_track.is_upper = true;
gfx::Rect upper_bounds = bounds;
if (IsHorizontal())
upper_bounds.set_width(thumb->x() - upper_bounds.x());
else
upper_bounds.set_height(thumb->y() - upper_bounds.y());
if (!upper_bounds.IsEmpty()) {
GetNativeTheme()->Paint(canvas->sk_canvas(), part_, state_, upper_bounds,
params_);
}
GetNativeTheme()->Paint(canvas->sk_canvas(), part_, state_, bounds, params_); params_.scrollbar_track.is_upper = false;
if (IsHorizontal())
bounds.Inset(thumb->bounds().right() - bounds.x(), 0, 0, 0);
else
bounds.Inset(0, thumb->bounds().bottom() - bounds.y(), 0, 0);
if (!bounds.IsEmpty()) {
GetNativeTheme()->Paint(canvas->sk_canvas(), part_, state_, bounds,
params_);
}
} }
gfx::Size ScrollBarViews::CalculatePreferredSize() const { gfx::Size ScrollBarViews::CalculatePreferredSize() const {
......
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