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

Side by Side Diff: ui/views/controls/scrollbar/overlay_scroll_bar.cc

Issue 2639203007: Update SetPaintToLayer to accept LayerType (Closed)
Patch Set: Refactor Created 3 years, 11 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
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 "third_party/skia/include/core/SkColor.h" 8 #include "third_party/skia/include/core/SkColor.h"
9 #include "ui/compositor/layer_type.h"
9 #include "ui/compositor/scoped_layer_animation_settings.h" 10 #include "ui/compositor/scoped_layer_animation_settings.h"
10 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
11 #include "ui/views/background.h" 12 #include "ui/views/background.h"
12 #include "ui/views/border.h" 13 #include "ui/views/border.h"
13 14
14 namespace views { 15 namespace views {
15 namespace { 16 namespace {
16 17
17 // Total thickness of the thumb (matches visuals when hovered). 18 // Total thickness of the thumb (matches visuals when hovered).
18 const int kThumbThickness = 11; 19 const int kThumbThickness = 11;
19 // When hovered, the thumb takes up the full width. Otherwise, it's a bit 20 // When hovered, the thumb takes up the full width. Otherwise, it's a bit
20 // slimmer. 21 // slimmer.
21 const int kThumbHoverOffset = 4; 22 const int kThumbHoverOffset = 4;
22 const int kThumbStroke = 1; 23 const int kThumbStroke = 1;
23 const float kThumbHoverAlpha = 0.5f; 24 const float kThumbHoverAlpha = 0.5f;
24 const float kThumbDefaultAlpha = 0.3f; 25 const float kThumbDefaultAlpha = 0.3f;
25 26
26 } // namespace 27 } // namespace
27 28
28 OverlayScrollBar::Thumb::Thumb(OverlayScrollBar* scroll_bar) 29 OverlayScrollBar::Thumb::Thumb(OverlayScrollBar* scroll_bar)
29 : BaseScrollBarThumb(scroll_bar), scroll_bar_(scroll_bar) { 30 : BaseScrollBarThumb(scroll_bar), scroll_bar_(scroll_bar) {
30 // |scroll_bar| isn't done being constructed; it's not safe to do anything 31 // |scroll_bar| isn't done being constructed; it's not safe to do anything
31 // that might reference it yet. 32 // that might reference it yet.
32 } 33 }
33 34
34 OverlayScrollBar::Thumb::~Thumb() {} 35 OverlayScrollBar::Thumb::~Thumb() {}
35 36
36 void OverlayScrollBar::Thumb::Init() { 37 void OverlayScrollBar::Thumb::Init() {
37 SetPaintToLayer(true); 38 SetPaintToLayer(ui::LAYER_TEXTURED);
38 layer()->SetFillsBoundsOpaquely(false); 39 layer()->SetFillsBoundsOpaquely(false);
39 // Animate all changes to the layer except the first one. 40 // Animate all changes to the layer except the first one.
40 OnStateChanged(); 41 OnStateChanged();
41 layer()->SetAnimator(ui::LayerAnimator::CreateImplicitAnimator()); 42 layer()->SetAnimator(ui::LayerAnimator::CreateImplicitAnimator());
42 } 43 }
43 44
44 gfx::Size OverlayScrollBar::Thumb::GetPreferredSize() const { 45 gfx::Size OverlayScrollBar::Thumb::GetPreferredSize() const {
45 // The visual size of the thumb is kThumbThickness, but it slides back and 46 // The visual size of the thumb is kThumbThickness, but it slides back and
46 // forth by kThumbHoverOffset. To make event targetting work well, expand the 47 // forth by kThumbHoverOffset. To make event targetting work well, expand the
47 // width of the thumb such that it's always taking up the full width of the 48 // width of the thumb such that it's always taking up the full width of the
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 layer()->SetOpacity(kThumbHoverAlpha); 107 layer()->SetOpacity(kThumbHoverAlpha);
107 } 108 }
108 } 109 }
109 110
110 OverlayScrollBar::OverlayScrollBar(bool horizontal) 111 OverlayScrollBar::OverlayScrollBar(bool horizontal)
111 : BaseScrollBar(horizontal), hide_timer_(false, false) { 112 : BaseScrollBar(horizontal), hide_timer_(false, false) {
112 auto thumb = new Thumb(this); 113 auto thumb = new Thumb(this);
113 SetThumb(thumb); 114 SetThumb(thumb);
114 thumb->Init(); 115 thumb->Init();
115 set_notify_enter_exit_on_child(true); 116 set_notify_enter_exit_on_child(true);
116 SetPaintToLayer(true); 117 SetPaintToLayer(ui::LAYER_TEXTURED);
117 layer()->SetMasksToBounds(true); 118 layer()->SetMasksToBounds(true);
118 layer()->SetFillsBoundsOpaquely(false); 119 layer()->SetFillsBoundsOpaquely(false);
119 } 120 }
120 121
121 OverlayScrollBar::~OverlayScrollBar() {} 122 OverlayScrollBar::~OverlayScrollBar() {}
122 123
123 gfx::Rect OverlayScrollBar::GetTrackBounds() const { 124 gfx::Rect OverlayScrollBar::GetTrackBounds() const {
124 gfx::Rect local = GetLocalBounds(); 125 gfx::Rect local = GetLocalBounds();
125 // The track has to be wide enough for the thumb. 126 // The track has to be wide enough for the thumb.
126 local.Inset(gfx::Insets(IsHorizontal() ? -kThumbHoverOffset : 0, 127 local.Inset(gfx::Insets(IsHorizontal() ? -kThumbHoverOffset : 0,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 171
171 void OverlayScrollBar::StartHideCountdown() { 172 void OverlayScrollBar::StartHideCountdown() {
172 if (IsMouseHovered()) 173 if (IsMouseHovered())
173 return; 174 return;
174 hide_timer_.Start( 175 hide_timer_.Start(
175 FROM_HERE, base::TimeDelta::FromSeconds(1), 176 FROM_HERE, base::TimeDelta::FromSeconds(1),
176 base::Bind(&OverlayScrollBar::Hide, base::Unretained(this))); 177 base::Bind(&OverlayScrollBar::Hide, base::Unretained(this)));
177 } 178 }
178 179
179 } // namespace views 180 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698