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

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

Issue 2535943002: Fix event targeting for overlay scrollbar thumbs (in native UI). (Closed)
Patch Set: Created 4 years, 1 month 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/views/controls/scrollbar/overlay_scroll_bar.h ('k') | ui/views/controls/scrollbar/scroll_bar_views.cc » ('j') | 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 de3b193e1760171e3f277a681fa73b7017d0657c..563a129e82284a2aad7f5598eeec2611c21e4d76 100644
--- a/ui/views/controls/scrollbar/overlay_scroll_bar.cc
+++ b/ui/views/controls/scrollbar/overlay_scroll_bar.cc
@@ -19,7 +19,7 @@ namespace {
const int kThumbThickness = 11;
// When hovered, the thumb takes up the full width. Otherwise, it's a bit
// slimmer.
-const int kThumbUnhoveredDifference = 4;
+const int kThumbHoverOffset = 4;
const int kThumbStroke = 1;
const float kThumbHoverAlpha = 0.5f;
const float kThumbDefaultAlpha = 0.3f;
@@ -28,16 +28,27 @@ const float kThumbDefaultAlpha = 0.3f;
OverlayScrollBar::Thumb::Thumb(OverlayScrollBar* scroll_bar)
: BaseScrollBarThumb(scroll_bar), scroll_bar_(scroll_bar) {
+ // |scroll_bar| isn't done being constructed; it's not safe to do anything
+ // that might reference it yet.
+}
+
+OverlayScrollBar::Thumb::~Thumb() {}
+
+void OverlayScrollBar::Thumb::Init() {
SetPaintToLayer(true);
+ layer()->SetFillsBoundsOpaquely(false);
// Animate all changes to the layer except the first one.
OnStateChanged();
layer()->SetAnimator(ui::LayerAnimator::CreateImplicitAnimator());
}
-OverlayScrollBar::Thumb::~Thumb() {}
-
gfx::Size OverlayScrollBar::Thumb::GetPreferredSize() const {
- return gfx::Size(kThumbThickness, kThumbThickness);
+ // The visual size of the thumb is kThumbThickness, but it slides back and
+ // forth by kThumbHoverOffset. To make event targetting work well, expand the
+ // width of the thumb such that it's always taking up the full width of the
+ // track regardless of the offset.
+ return gfx::Size(kThumbThickness + kThumbHoverOffset,
+ kThumbThickness + kThumbHoverOffset);
}
void OverlayScrollBar::Thumb::OnPaint(gfx::Canvas* canvas) {
@@ -45,6 +56,8 @@ void OverlayScrollBar::Thumb::OnPaint(gfx::Canvas* canvas) {
fill_paint.setStyle(SkPaint::kFill_Style);
fill_paint.setColor(SK_ColorBLACK);
gfx::RectF fill_bounds(GetLocalBounds());
+ fill_bounds.Inset(gfx::InsetsF(IsHorizontal() ? kThumbHoverOffset : 0,
+ IsHorizontal() ? 0 : kThumbHoverOffset, 0, 0));
fill_bounds.Inset(gfx::InsetsF(kThumbStroke, kThumbStroke,
IsHorizontal() ? 0 : kThumbStroke,
IsHorizontal() ? kThumbStroke : 0));
@@ -55,7 +68,7 @@ void OverlayScrollBar::Thumb::OnPaint(gfx::Canvas* canvas) {
stroke_paint.setColor(SK_ColorWHITE);
stroke_paint.setStrokeWidth(kThumbStroke);
gfx::RectF stroke_bounds(fill_bounds);
- stroke_bounds.Inset(gfx::InsetsF(-0.5f));
+ stroke_bounds.Inset(gfx::InsetsF(kThumbStroke / 2.f));
// The stroke doesn't apply to the far edge of the thumb.
SkPath path;
path.moveTo(gfx::PointFToSkPoint(stroke_bounds.top_right()));
@@ -82,8 +95,8 @@ void OverlayScrollBar::Thumb::OnStateChanged() {
if (GetState() == CustomButton::STATE_NORMAL) {
gfx::Transform translation;
translation.Translate(
- gfx::Vector2d(IsHorizontal() ? 0 : kThumbUnhoveredDifference,
- IsHorizontal() ? kThumbUnhoveredDifference : 0));
+ gfx::Vector2d(IsHorizontal() ? 0 : kThumbHoverOffset,
+ IsHorizontal() ? kThumbHoverOffset: 0));
layer()->SetTransform(translation);
layer()->SetOpacity(kThumbDefaultAlpha);
@@ -96,18 +109,24 @@ void OverlayScrollBar::Thumb::OnStateChanged() {
}
OverlayScrollBar::OverlayScrollBar(bool horizontal)
- : BaseScrollBar(horizontal, new Thumb(this)), hide_timer_(false, false) {
+ : BaseScrollBar(horizontal), hide_timer_(false, false) {
+ auto thumb = new Thumb(this);
+ SetThumb(thumb);
+ thumb->Init();
set_notify_enter_exit_on_child(true);
SetPaintToLayer(true);
layer()->SetMasksToBounds(true);
layer()->SetFillsBoundsOpaquely(false);
}
-OverlayScrollBar::~OverlayScrollBar() {
-}
+OverlayScrollBar::~OverlayScrollBar() {}
gfx::Rect OverlayScrollBar::GetTrackBounds() const {
- return GetLocalBounds();
+ gfx::Rect local = GetLocalBounds();
+ // The track has to be wide enough for the thumb.
+ local.Inset(gfx::Insets(IsHorizontal() ? -kThumbHoverOffset : 0,
+ IsHorizontal() ? 0 : -kThumbHoverOffset, 0, 0));
+ return local;
}
int OverlayScrollBar::GetLayoutSize() const {
« no previous file with comments | « ui/views/controls/scrollbar/overlay_scroll_bar.h ('k') | ui/views/controls/scrollbar/scroll_bar_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698