Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Unified Diff: ui/views/controls/scrollbar/overlay_scroll_bar.cc

Issue 2830163002: Adjust overlay scrollbar appearance. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/native_theme/overlay_scrollbar_constants_aura.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/scrollbar/overlay_scroll_bar.cc
diff --git a/ui/views/controls/scrollbar/overlay_scroll_bar.cc b/ui/views/controls/scrollbar/overlay_scroll_bar.cc
index ae0c2619822cd7ddd2940618bf6206e0c55c165f..0ed8d629f44bff9f471a7d35cfc862a352d4ae9a 100644
--- a/ui/views/controls/scrollbar/overlay_scroll_bar.cc
+++ b/ui/views/controls/scrollbar/overlay_scroll_bar.cc
@@ -9,6 +9,7 @@
#include "third_party/skia/include/core/SkColor.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h"
+#include "ui/native_theme/overlay_scrollbar_constants_aura.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
@@ -16,13 +17,15 @@ namespace views {
namespace {
// Total thickness of the thumb (matches visuals when hovered).
-const int kThumbThickness = 11;
+constexpr int kThumbThickness =
+ ui::kOverlayScrollbarThumbWidthPressed + ui::kOverlayScrollbarStrokeWidth;
// When hovered, the thumb takes up the full width. Otherwise, it's a bit
// slimmer.
-const int kThumbHoverOffset = 4;
-const int kThumbStroke = 1;
-const float kThumbHoverAlpha = 0.5f;
-const float kThumbDefaultAlpha = 0.3f;
+constexpr int kThumbHoverOffset = 4;
+// The layout size of the thumb stroke, in DIP.
+constexpr int kThumbStroke = ui::kOverlayScrollbarStrokeWidth;
+// The visual size of the thumb stroke, in px.
+constexpr int kThumbStrokeVisualSize = ui::kOverlayScrollbarStrokeWidth;
} // namespace
@@ -65,11 +68,20 @@ void OverlayScrollBar::Thumb::OnPaint(gfx::Canvas* canvas) {
cc::PaintFlags stroke_flags;
stroke_flags.setStyle(cc::PaintFlags::kStroke_Style);
- stroke_flags.setColor(SK_ColorWHITE);
- stroke_flags.setStrokeWidth(kThumbStroke);
+ stroke_flags.setColor(
+ SkColorSetA(SK_ColorWHITE, (ui::kOverlayScrollbarStrokeNormalAlpha /
+ ui::kOverlayScrollbarThumbNormalAlpha) *
+ SK_AlphaOPAQUE));
+ stroke_flags.setStrokeWidth(kThumbStrokeVisualSize);
stroke_flags.setStrokeCap(cc::PaintFlags::kSquare_Cap);
+
+ // The stroke is a single pixel, so we must deal with the unscaled canvas.
+ const float dsf = canvas->UndoDeviceScaleFactor();
gfx::RectF stroke_bounds(fill_bounds);
- stroke_bounds.Inset(gfx::InsetsF(kThumbStroke / 2.f));
+ stroke_bounds.Scale(dsf);
+ // The stroke should be aligned to the pixel center that is nearest the fill,
+ // so outset by a half pixel.
+ stroke_bounds.Inset(gfx::InsetsF(-kThumbStrokeVisualSize / 2.0f));
// The stroke doesn't apply to the far edge of the thumb.
SkPath path;
path.moveTo(gfx::PointFToSkPoint(stroke_bounds.top_right()));
@@ -99,13 +111,13 @@ void OverlayScrollBar::Thumb::OnStateChanged() {
gfx::Vector2d(IsHorizontal() ? 0 : kThumbHoverOffset,
IsHorizontal() ? kThumbHoverOffset: 0));
layer()->SetTransform(translation);
- layer()->SetOpacity(kThumbDefaultAlpha);
+ layer()->SetOpacity(ui::kOverlayScrollbarThumbNormalAlpha);
if (GetWidget())
scroll_bar_->StartHideCountdown();
} else {
layer()->SetTransform(gfx::Transform());
- layer()->SetOpacity(kThumbHoverAlpha);
+ layer()->SetOpacity(ui::kOverlayScrollbarThumbHoverAlpha);
}
}
@@ -166,7 +178,7 @@ void OverlayScrollBar::Show() {
void OverlayScrollBar::Hide() {
ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
- settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(200));
+ settings.SetTransitionDuration(ui::kOverlayScrollbarFadeOutDuration);
layer()->SetOpacity(0.0f);
}
@@ -174,7 +186,7 @@ void OverlayScrollBar::StartHideCountdown() {
if (IsMouseHovered())
return;
hide_timer_.Start(
- FROM_HERE, base::TimeDelta::FromSeconds(1),
+ FROM_HERE, ui::kOverlayScrollbarFadeOutDelay,
base::Bind(&OverlayScrollBar::Hide, base::Unretained(this)));
}
« no previous file with comments | « ui/native_theme/overlay_scrollbar_constants_aura.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698