Skip to content

Commit

Permalink
Change Aura overlay scrollbars from solid color to painted scrollbars.
Browse files Browse the repository at this point in the history
With this change, the Aura overlay scrollbars are now painted by the native
theme. If the scroller is composited, these scrollbars will now be uploaded to
the compositor as PaintedScrollbarLayers rather than SolidColorScrollbarLayers.

Additionally, many of the MD scrollbar constants and properties are scattered
around the code. This patch moves them into a single location in
ui/native_theme. I've also updated the values to match the latest spec.
Follow-up patches will make use of these values from the compositor.

BUG=592098, 652520
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel

Review-Url: https://chromiumcodereview.appspot.com/2421913002
Cr-Commit-Position: refs/heads/master@{#426191}
  • Loading branch information
bokand authored and Commit bot committed Oct 19, 2016
1 parent 0f25428 commit 3d914bd
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 75 deletions.
13 changes: 7 additions & 6 deletions blimp/client/support/compositor/blimp_layer_tree_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings* settings) {
settings->gpu_rasterization_enabled = false;
settings->using_synchronous_renderer_compositor = false;
settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
settings->scrollbar_fade_delay_ms = 300;
settings->scrollbar_fade_resize_delay_ms = 2000;
settings->scrollbar_fade_duration_ms = 300;
settings->scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(300);
settings->scrollbar_fade_resize_delay = base::TimeDelta::FromSeconds(2);
settings->scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
settings->renderer_settings.highp_threshold_min = 2048;
settings->ignore_root_layer_flings = false;
Expand All @@ -89,9 +89,10 @@ void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings* settings) {
#elif !defined(OS_MACOSX)
settings->scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
settings->solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
settings->scrollbar_fade_delay_ms = 500;
settings->scrollbar_fade_resize_delay_ms = 500;
settings->scrollbar_fade_duration_ms = 300;
settings->scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(500);
settings->scrollbar_fade_resize_delay =
base::TimeDelta::FromMilliseconds(500);
settings->scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);

// When pinching in, only show the pinch-viewport overlay scrollbars if the
// page scale is at least some threshold away from the minimum. i.e. don't
Expand Down
6 changes: 4 additions & 2 deletions cc/layers/scrollbar_layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ class ScrollbarLayerTest : public testing::Test {
layer_tree_settings_.single_thread_proxy_scheduler = false;
layer_tree_settings_.use_zero_copy = true;
layer_tree_settings_.scrollbar_animator = LayerTreeSettings::LINEAR_FADE;
layer_tree_settings_.scrollbar_fade_delay_ms = 20;
layer_tree_settings_.scrollbar_fade_duration_ms = 20;
layer_tree_settings_.scrollbar_fade_delay =
base::TimeDelta::FromMilliseconds(20);
layer_tree_settings_.scrollbar_fade_duration =
base::TimeDelta::FromMilliseconds(20);
layer_tree_settings_.verify_transform_tree_calculations = true;
layer_tree_settings_.verify_clip_tree_calculations = true;

Expand Down
16 changes: 8 additions & 8 deletions cc/trees/layer_tree_host_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2730,8 +2730,8 @@ class LayerTreeHostImplTestScrollbarAnimation : public LayerTreeHostImplTest {
void RunTest(LayerTreeSettings::ScrollbarAnimator animator) {
LayerTreeSettings settings = DefaultSettings();
settings.scrollbar_animator = animator;
settings.scrollbar_fade_delay_ms = 20;
settings.scrollbar_fade_duration_ms = 20;
settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(20);
settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20);

// If no animator is set, scrollbar won't show and no animation is expected.
bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR;
Expand Down Expand Up @@ -2923,8 +2923,8 @@ class LayerTreeHostImplTestScrollbarOpacity : public LayerTreeHostImplTest {
void RunTest(LayerTreeSettings::ScrollbarAnimator animator) {
LayerTreeSettings settings = DefaultSettings();
settings.scrollbar_animator = animator;
settings.scrollbar_fade_delay_ms = 20;
settings.scrollbar_fade_duration_ms = 20;
settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(20);
settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20);
gfx::Size content_size(100, 100);

// If no animator is set, scrollbar won't show and no animation is expected.
Expand Down Expand Up @@ -3054,8 +3054,8 @@ TEST_F(LayerTreeHostImplTest, ScrollbarInnerLargerThanOuter) {
TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) {
LayerTreeSettings settings = DefaultSettings();
settings.scrollbar_animator = LayerTreeSettings::LINEAR_FADE;
settings.scrollbar_fade_delay_ms = 20;
settings.scrollbar_fade_duration_ms = 20;
settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(20);
settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20);
CreateHostImpl(settings, CreateCompositorFrameSink());

gfx::Size viewport_size(300, 200);
Expand Down Expand Up @@ -3174,8 +3174,8 @@ TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) {
void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
float device_scale_factor) {
LayerTreeSettings settings = DefaultSettings();
settings.scrollbar_fade_delay_ms = 500;
settings.scrollbar_fade_duration_ms = 300;
settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(500);
settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
settings.scrollbar_animator = LayerTreeSettings::THINNING;

gfx::Size viewport_size(300, 200);
Expand Down
13 changes: 5 additions & 8 deletions cc/trees/layer_tree_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1359,14 +1359,11 @@ const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const {

std::unique_ptr<ScrollbarAnimationController>
LayerTreeImpl::CreateScrollbarAnimationController(int scroll_layer_id) {
DCHECK(settings().scrollbar_fade_delay_ms);
DCHECK(settings().scrollbar_fade_duration_ms);
base::TimeDelta delay =
base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms);
base::TimeDelta resize_delay = base::TimeDelta::FromMilliseconds(
settings().scrollbar_fade_resize_delay_ms);
base::TimeDelta duration =
base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms);
DCHECK(!settings().scrollbar_fade_delay.is_zero());
DCHECK(!settings().scrollbar_fade_duration.is_zero());
base::TimeDelta delay = settings().scrollbar_fade_delay;
base::TimeDelta resize_delay = settings().scrollbar_fade_resize_delay;
base::TimeDelta duration = settings().scrollbar_fade_duration;
switch (settings().scrollbar_animator) {
case LayerTreeSettings::LINEAR_FADE: {
return ScrollbarAnimationControllerLinearFade::Create(
Expand Down
7 changes: 3 additions & 4 deletions cc/trees/layer_tree_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ bool LayerTreeSettings::operator==(const LayerTreeSettings& other) const {
other.gpu_rasterization_msaa_sample_count &&
create_low_res_tiling == other.create_low_res_tiling &&
scrollbar_animator == other.scrollbar_animator &&
scrollbar_fade_delay_ms == other.scrollbar_fade_delay_ms &&
scrollbar_fade_resize_delay_ms ==
other.scrollbar_fade_resize_delay_ms &&
scrollbar_fade_duration_ms == other.scrollbar_fade_duration_ms &&
scrollbar_fade_delay == other.scrollbar_fade_delay &&
scrollbar_fade_resize_delay == other.scrollbar_fade_resize_delay &&
scrollbar_fade_duration == other.scrollbar_fade_duration &&
solid_color_scrollbar_color == other.solid_color_scrollbar_color &&
timeout_and_draw_when_animation_checkerboards ==
other.timeout_and_draw_when_animation_checkerboards &&
Expand Down
8 changes: 5 additions & 3 deletions cc/trees/layer_tree_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <vector>

#include "base/time/time.h"
#include "cc/base/cc_export.h"
#include "cc/debug/layer_tree_debug_state.h"
#include "cc/output/managed_memory_policy.h"
Expand Down Expand Up @@ -56,9 +57,10 @@ class CC_EXPORT LayerTreeSettings {
THINNING,
};
ScrollbarAnimator scrollbar_animator = NO_ANIMATOR;
int scrollbar_fade_delay_ms = 0;
int scrollbar_fade_resize_delay_ms = 0;
int scrollbar_fade_duration_ms = 0;
base::TimeDelta scrollbar_fade_delay;
base::TimeDelta scrollbar_fade_resize_delay;
base::TimeDelta scrollbar_fade_duration;
base::TimeDelta scrollbar_thinning_duration;
SkColor solid_color_scrollbar_color = SK_ColorWHITE;
bool timeout_and_draw_when_animation_checkerboards = true;
bool layer_transforms_should_scale_layer_contents = false;
Expand Down
4 changes: 3 additions & 1 deletion content/browser/renderer_host/render_view_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ WebPreferences RenderViewHostImpl::ComputeWebkitPrefs() {
prefs.inert_visual_viewport =
command_line.HasSwitch(switches::kInertVisualViewport);

prefs.use_solid_color_scrollbars = ui::IsOverlayScrollbarEnabled();
prefs.use_solid_color_scrollbars = false;

prefs.history_entry_requires_user_gesture =
command_line.HasSwitch(switches::kHistoryEntryRequiresUserGesture);
Expand All @@ -482,6 +482,8 @@ WebPreferences RenderViewHostImpl::ComputeWebkitPrefs() {
base::FeatureList::IsEnabled(features::kAutoplayMutedVideos);

prefs.progress_bar_completion = GetProgressBarCompletionPolicy();

prefs.use_solid_color_scrollbars = true;
#endif

// Handle autoplay gesture override experiment.
Expand Down
25 changes: 18 additions & 7 deletions content/renderer/gpu/render_widget_compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "third_party/WebKit/public/web/WebSelection.h"
#include "ui/gl/gl_switches.h"
#include "ui/native_theme/native_theme_switches.h"
#include "ui/native_theme/overlay_scrollbar_constants_aura.h"

#if defined(OS_ANDROID)
#include "base/android/build_info.h"
Expand Down Expand Up @@ -383,9 +384,10 @@ cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings(
settings.gpu_rasterization_enabled = false;
settings.using_synchronous_renderer_compositor = using_synchronous_compositor;
settings.scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
settings.scrollbar_fade_delay_ms = 300;
settings.scrollbar_fade_resize_delay_ms = 2000;
settings.scrollbar_fade_duration_ms = 300;
settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(300);
settings.scrollbar_fade_resize_delay =
base::TimeDelta::FromMilliseconds(2000);
settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
settings.renderer_settings.highp_threshold_min = 2048;
// Android WebView handles root layer flings itself.
Expand Down Expand Up @@ -420,14 +422,23 @@ cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings(
#if !defined(OS_MACOSX)
if (ui::IsOverlayScrollbarEnabled()) {
settings.scrollbar_animator = cc::LayerTreeSettings::THINNING;
settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
settings.scrollbar_fade_delay = ui::kOverlayScrollbarFadeOutDelay;
settings.scrollbar_fade_resize_delay =
ui::kOverlayScrollbarFadeOutDelay;
settings.scrollbar_fade_duration =
ui::kOverlayScrollbarFadeOutDuration;
settings.scrollbar_thinning_duration =
ui::kOverlayScrollbarThinningDuration;
} else {
// TODO(bokan): This section is probably unneeded? We don't use scrollbar
// animations for non overlay scrollbars.
settings.scrollbar_animator = cc::LayerTreeSettings::LINEAR_FADE;
settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(500);
settings.scrollbar_fade_resize_delay =
base::TimeDelta::FromMilliseconds(500);
settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
}
settings.scrollbar_fade_delay_ms = 500;
settings.scrollbar_fade_resize_delay_ms = 500;
settings.scrollbar_fade_duration_ms = 300;
#endif // !defined(OS_MACOSX)

// On desktop, if there's over 4GB of memory on the machine, increase the
Expand Down
12 changes: 10 additions & 2 deletions third_party/WebKit/Source/platform/scroll/ScrollbarThemeAura.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,20 @@ PartPaintingParams buttonPartPaintingParams(
return PartPaintingParams(paintPart, state);
}

static int getScrollbarThickness() {
return Platform::current()
->themeEngine()
->getSize(WebThemeEngine::PartScrollbarVerticalThumb)
.width;
}

} // namespace

ScrollbarTheme& ScrollbarTheme::nativeTheme() {
if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) {
DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme,
(10, 0, ScrollbarThemeOverlay::AllowHitTest));
DEFINE_STATIC_LOCAL(
ScrollbarThemeOverlay, theme,
(getScrollbarThickness(), 0, ScrollbarThemeOverlay::AllowHitTest));
return theme;
}

Expand Down
1 change: 1 addition & 0 deletions ui/native_theme/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ component("native_theme") {
"native_theme_aura.h",
"native_theme_dark_aura.cc",
"native_theme_dark_aura.h",
"overlay_scrollbar_constants_aura.h",
]
}

Expand Down
92 changes: 64 additions & 28 deletions ui/native_theme/native_theme_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>

#include "base/logging.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "ui/base/layout.h"
#include "ui/base/material_design/material_design_controller.h"
Expand All @@ -21,40 +22,33 @@
#include "ui/gfx/skia_util.h"
#include "ui/native_theme/common_theme.h"
#include "ui/native_theme/native_theme_switches.h"
#include "ui/native_theme/overlay_scrollbar_constants_aura.h"

namespace ui {

namespace {

// Constants for painting overlay scrollbars. Other properties needed outside
// this painting code are defined in overlay_scrollbar_constants_aura.h.
constexpr int kOverlayScrollbarStrokeWidth = 1;
constexpr int kOverlayScrollbarMinimumLength = 12;
constexpr SkAlpha kOverlayScrollbarAlphaNormal = 0x4D;
constexpr SkAlpha kOverlayScrollbarAlphaHovered = 0x80;
constexpr SkAlpha kOverlayScrollbarAlphaPressed = 0x80;
constexpr SkColor kOverlayScrollbarThumbColor = SK_ColorBLACK;
constexpr SkColor kOverlayScrollbarStrokeColor = SK_ColorWHITE;

SkAlpha ThumbAlphaForState(NativeTheme::State state) {
bool overlay = IsOverlayScrollbarEnabled();
switch (state) {
case NativeTheme::kDisabled:
return 0x00;
case NativeTheme::kHovered:
return overlay ? 0xB2 : 0x4D;
return overlay ? kOverlayScrollbarAlphaHovered : 0x4D;
case NativeTheme::kNormal:
return overlay ? 0x8C : 0x33;
return overlay ? kOverlayScrollbarAlphaNormal : 0x33;
case NativeTheme::kPressed:
return overlay ? 0xB2 : 0x80;
case NativeTheme::kNumStates:
break;
}

NOTREACHED();
return 0xFF;
}

SkAlpha ThumbStrokeAlphaForState(NativeTheme::State state) {
DCHECK(IsOverlayScrollbarEnabled());
switch (state) {
case NativeTheme::kDisabled:
return 0x00;
case NativeTheme::kHovered:
case NativeTheme::kPressed:
return 0x33;
case NativeTheme::kNormal:
return 0x26;
return overlay ? kOverlayScrollbarAlphaPressed : 0x80;
case NativeTheme::kNumStates:
break;
}
Expand Down Expand Up @@ -84,6 +78,11 @@ NativeThemeAura::NativeThemeAura() {
set_scrollbar_button_length(0);
#endif

if (IsOverlayScrollbarEnabled()) {
scrollbar_width_ =
kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2;
}

// Images and alphas declarations assume the following order.
static_assert(kDisabled == 0, "states unexpectedly changed");
static_assert(kHovered == 1, "states unexpectedly changed");
Expand Down Expand Up @@ -196,20 +195,28 @@ void NativeThemeAura::PaintScrollbarThumbStateTransition(
State end_state,
double progress,
const gfx::Rect& rect) const {
TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumbStateTransition");
gfx::Rect thumb_rect(rect);
SkColor thumb_color;
if (IsOverlayScrollbarEnabled()) {
// In overlay mode, draw a stroke (border).
const int kStrokeWidth = 1;
constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth;
SkAlpha stroke_alpha = gfx::Tween::IntValueBetween(
progress, ThumbStrokeAlphaForState(start_state),
ThumbStrokeAlphaForState(end_state));
progress, ThumbAlphaForState(start_state),
ThumbAlphaForState(end_state));
SkPaint paint;
paint.setColor(SkColorSetA(SK_ColorWHITE, stroke_alpha));
paint.setColor(SkColorSetA(kOverlayScrollbarStrokeColor, stroke_alpha));
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(kStrokeWidth);
canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);

thumb_rect.Inset(kStrokeWidth, kStrokeWidth, kStrokeWidth, kStrokeWidth);
gfx::RectF stroke_rect(thumb_rect);
constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f;
stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth);
canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint);

// Inset the all the edges edges so we fill-in the stroke below.
thumb_rect.Inset(kStrokeWidth, kStrokeWidth);
thumb_color = kOverlayScrollbarThumbColor;
} else {
// If there are no scrollbuttons then provide some padding so that the thumb
// doesn't touch the top of the track.
Expand All @@ -220,12 +227,14 @@ void NativeThemeAura::PaintScrollbarThumbStateTransition(
thumb_rect.Inset(kThumbPadding, extra_padding);
else
thumb_rect.Inset(extra_padding, kThumbPadding);

thumb_color = SK_ColorBLACK;
}

SkPaint paint;
SkAlpha alpha = gfx::Tween::IntValueBetween(
progress, ThumbAlphaForState(start_state), ThumbAlphaForState(end_state));
paint.setColor(SkColorSetA(SK_ColorBLACK, alpha));
paint.setColor(SkColorSetA(thumb_color, alpha));
canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);
}

Expand All @@ -239,4 +248,31 @@ void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas,
canvas->drawIRect(RectToSkIRect(rect), paint);
}

gfx::Size NativeThemeAura::GetPartSize(Part part,
State state,
const ExtraParams& extra) const {
if (IsOverlayScrollbarEnabled()) {
constexpr int minimum_length =
kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth;

// Aura overlay scrollbars need a slight tweak from the base sizes.
switch (part) {
case kScrollbarHorizontalThumb:
return gfx::Size(minimum_length, scrollbar_width_);
case kScrollbarVerticalThumb:
return gfx::Size(scrollbar_width_, minimum_length);
default:
// TODO(bokan): We should probably make sure code using overlay
// scrollbars isn't asking for part sizes that don't exist. This
// currently breaks in Views layout code which indicates they aren't
// overlay aware yet. The Views code should be fixed and either this
// branch return 0 for parts that don't exist or assert NOTREACHED.
// crbug.com/657159.
break;
}
}

return NativeThemeBase::GetPartSize(part, state, extra);
}

} // namespace ui
Loading

0 comments on commit 3d914bd

Please sign in to comment.