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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/native_theme/overlay_scrollbar_constants_aura.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" 5 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "cc/paint/paint_flags.h" 8 #include "cc/paint/paint_flags.h"
9 #include "third_party/skia/include/core/SkColor.h" 9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/compositor/scoped_layer_animation_settings.h" 10 #include "ui/compositor/scoped_layer_animation_settings.h"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/native_theme/overlay_scrollbar_constants_aura.h"
12 #include "ui/views/background.h" 13 #include "ui/views/background.h"
13 #include "ui/views/border.h" 14 #include "ui/views/border.h"
14 15
15 namespace views { 16 namespace views {
16 namespace { 17 namespace {
17 18
18 // Total thickness of the thumb (matches visuals when hovered). 19 // Total thickness of the thumb (matches visuals when hovered).
19 const int kThumbThickness = 11; 20 constexpr int kThumbThickness =
21 ui::kOverlayScrollbarThumbWidthPressed + ui::kOverlayScrollbarStrokeWidth;
20 // When hovered, the thumb takes up the full width. Otherwise, it's a bit 22 // When hovered, the thumb takes up the full width. Otherwise, it's a bit
21 // slimmer. 23 // slimmer.
22 const int kThumbHoverOffset = 4; 24 constexpr int kThumbHoverOffset = 4;
23 const int kThumbStroke = 1; 25 // The layout size of the thumb stroke, in DIP.
24 const float kThumbHoverAlpha = 0.5f; 26 constexpr int kThumbStroke = ui::kOverlayScrollbarStrokeWidth;
25 const float kThumbDefaultAlpha = 0.3f; 27 // The visual size of the thumb stroke, in px.
28 constexpr int kThumbStrokeVisualSize = ui::kOverlayScrollbarStrokeWidth;
26 29
27 } // namespace 30 } // namespace
28 31
29 OverlayScrollBar::Thumb::Thumb(OverlayScrollBar* scroll_bar) 32 OverlayScrollBar::Thumb::Thumb(OverlayScrollBar* scroll_bar)
30 : BaseScrollBarThumb(scroll_bar), scroll_bar_(scroll_bar) { 33 : BaseScrollBarThumb(scroll_bar), scroll_bar_(scroll_bar) {
31 // |scroll_bar| isn't done being constructed; it's not safe to do anything 34 // |scroll_bar| isn't done being constructed; it's not safe to do anything
32 // that might reference it yet. 35 // that might reference it yet.
33 } 36 }
34 37
35 OverlayScrollBar::Thumb::~Thumb() {} 38 OverlayScrollBar::Thumb::~Thumb() {}
(...skipping 22 matching lines...) Expand all
58 gfx::RectF fill_bounds(GetLocalBounds()); 61 gfx::RectF fill_bounds(GetLocalBounds());
59 fill_bounds.Inset(gfx::InsetsF(IsHorizontal() ? kThumbHoverOffset : 0, 62 fill_bounds.Inset(gfx::InsetsF(IsHorizontal() ? kThumbHoverOffset : 0,
60 IsHorizontal() ? 0 : kThumbHoverOffset, 0, 0)); 63 IsHorizontal() ? 0 : kThumbHoverOffset, 0, 0));
61 fill_bounds.Inset(gfx::InsetsF(kThumbStroke, kThumbStroke, 64 fill_bounds.Inset(gfx::InsetsF(kThumbStroke, kThumbStroke,
62 IsHorizontal() ? 0 : kThumbStroke, 65 IsHorizontal() ? 0 : kThumbStroke,
63 IsHorizontal() ? kThumbStroke : 0)); 66 IsHorizontal() ? kThumbStroke : 0));
64 canvas->DrawRect(fill_bounds, fill_flags); 67 canvas->DrawRect(fill_bounds, fill_flags);
65 68
66 cc::PaintFlags stroke_flags; 69 cc::PaintFlags stroke_flags;
67 stroke_flags.setStyle(cc::PaintFlags::kStroke_Style); 70 stroke_flags.setStyle(cc::PaintFlags::kStroke_Style);
68 stroke_flags.setColor(SK_ColorWHITE); 71 stroke_flags.setColor(
69 stroke_flags.setStrokeWidth(kThumbStroke); 72 SkColorSetA(SK_ColorWHITE, (ui::kOverlayScrollbarStrokeNormalAlpha /
73 ui::kOverlayScrollbarThumbNormalAlpha) *
74 SK_AlphaOPAQUE));
75 stroke_flags.setStrokeWidth(kThumbStrokeVisualSize);
70 stroke_flags.setStrokeCap(cc::PaintFlags::kSquare_Cap); 76 stroke_flags.setStrokeCap(cc::PaintFlags::kSquare_Cap);
77
78 // The stroke is a single pixel, so we must deal with the unscaled canvas.
79 const float dsf = canvas->UndoDeviceScaleFactor();
71 gfx::RectF stroke_bounds(fill_bounds); 80 gfx::RectF stroke_bounds(fill_bounds);
72 stroke_bounds.Inset(gfx::InsetsF(kThumbStroke / 2.f)); 81 stroke_bounds.Scale(dsf);
82 // The stroke should be aligned to the pixel center that is nearest the fill,
83 // so outset by a half pixel.
84 stroke_bounds.Inset(gfx::InsetsF(-kThumbStrokeVisualSize / 2.0f));
73 // The stroke doesn't apply to the far edge of the thumb. 85 // The stroke doesn't apply to the far edge of the thumb.
74 SkPath path; 86 SkPath path;
75 path.moveTo(gfx::PointFToSkPoint(stroke_bounds.top_right())); 87 path.moveTo(gfx::PointFToSkPoint(stroke_bounds.top_right()));
76 path.lineTo(gfx::PointFToSkPoint(stroke_bounds.origin())); 88 path.lineTo(gfx::PointFToSkPoint(stroke_bounds.origin()));
77 path.lineTo(gfx::PointFToSkPoint(stroke_bounds.bottom_left())); 89 path.lineTo(gfx::PointFToSkPoint(stroke_bounds.bottom_left()));
78 if (IsHorizontal()) { 90 if (IsHorizontal()) {
79 path.moveTo(gfx::PointFToSkPoint(stroke_bounds.bottom_right())); 91 path.moveTo(gfx::PointFToSkPoint(stroke_bounds.bottom_right()));
80 path.close(); 92 path.close();
81 } else { 93 } else {
82 path.lineTo(gfx::PointFToSkPoint(stroke_bounds.bottom_right())); 94 path.lineTo(gfx::PointFToSkPoint(stroke_bounds.bottom_right()));
83 } 95 }
84 canvas->DrawPath(path, stroke_flags); 96 canvas->DrawPath(path, stroke_flags);
85 } 97 }
86 98
87 void OverlayScrollBar::Thumb::OnBoundsChanged( 99 void OverlayScrollBar::Thumb::OnBoundsChanged(
88 const gfx::Rect& previous_bounds) { 100 const gfx::Rect& previous_bounds) {
89 scroll_bar_->Show(); 101 scroll_bar_->Show();
90 // Don't start the hide countdown if the thumb is still hovered or pressed. 102 // Don't start the hide countdown if the thumb is still hovered or pressed.
91 if (GetState() == CustomButton::STATE_NORMAL) 103 if (GetState() == CustomButton::STATE_NORMAL)
92 scroll_bar_->StartHideCountdown(); 104 scroll_bar_->StartHideCountdown();
93 } 105 }
94 106
95 void OverlayScrollBar::Thumb::OnStateChanged() { 107 void OverlayScrollBar::Thumb::OnStateChanged() {
96 if (GetState() == CustomButton::STATE_NORMAL) { 108 if (GetState() == CustomButton::STATE_NORMAL) {
97 gfx::Transform translation; 109 gfx::Transform translation;
98 translation.Translate( 110 translation.Translate(
99 gfx::Vector2d(IsHorizontal() ? 0 : kThumbHoverOffset, 111 gfx::Vector2d(IsHorizontal() ? 0 : kThumbHoverOffset,
100 IsHorizontal() ? kThumbHoverOffset: 0)); 112 IsHorizontal() ? kThumbHoverOffset: 0));
101 layer()->SetTransform(translation); 113 layer()->SetTransform(translation);
102 layer()->SetOpacity(kThumbDefaultAlpha); 114 layer()->SetOpacity(ui::kOverlayScrollbarThumbNormalAlpha);
103 115
104 if (GetWidget()) 116 if (GetWidget())
105 scroll_bar_->StartHideCountdown(); 117 scroll_bar_->StartHideCountdown();
106 } else { 118 } else {
107 layer()->SetTransform(gfx::Transform()); 119 layer()->SetTransform(gfx::Transform());
108 layer()->SetOpacity(kThumbHoverAlpha); 120 layer()->SetOpacity(ui::kOverlayScrollbarThumbHoverAlpha);
109 } 121 }
110 } 122 }
111 123
112 OverlayScrollBar::OverlayScrollBar(bool horizontal) 124 OverlayScrollBar::OverlayScrollBar(bool horizontal)
113 : BaseScrollBar(horizontal), hide_timer_(false, false) { 125 : BaseScrollBar(horizontal), hide_timer_(false, false) {
114 auto* thumb = new Thumb(this); 126 auto* thumb = new Thumb(this);
115 SetThumb(thumb); 127 SetThumb(thumb);
116 thumb->Init(); 128 thumb->Init();
117 set_notify_enter_exit_on_child(true); 129 set_notify_enter_exit_on_child(true);
118 SetPaintToLayer(); 130 SetPaintToLayer();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 StartHideCountdown(); 171 StartHideCountdown();
160 } 172 }
161 173
162 void OverlayScrollBar::Show() { 174 void OverlayScrollBar::Show() {
163 layer()->SetOpacity(1.0f); 175 layer()->SetOpacity(1.0f);
164 hide_timer_.Stop(); 176 hide_timer_.Stop();
165 } 177 }
166 178
167 void OverlayScrollBar::Hide() { 179 void OverlayScrollBar::Hide() {
168 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); 180 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
169 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(200)); 181 settings.SetTransitionDuration(ui::kOverlayScrollbarFadeOutDuration);
170 layer()->SetOpacity(0.0f); 182 layer()->SetOpacity(0.0f);
171 } 183 }
172 184
173 void OverlayScrollBar::StartHideCountdown() { 185 void OverlayScrollBar::StartHideCountdown() {
174 if (IsMouseHovered()) 186 if (IsMouseHovered())
175 return; 187 return;
176 hide_timer_.Start( 188 hide_timer_.Start(
177 FROM_HERE, base::TimeDelta::FromSeconds(1), 189 FROM_HERE, ui::kOverlayScrollbarFadeOutDelay,
178 base::Bind(&OverlayScrollBar::Hide, base::Unretained(this))); 190 base::Bind(&OverlayScrollBar::Hide, base::Unretained(this)));
179 } 191 }
180 192
181 } // namespace views 193 } // namespace views
OLDNEW
« 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