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

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

Issue 2555973002: Views (native UI) overlay scrollbars: match blink overlay scrollbar (Closed)
Patch Set: Created 4 years 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/views/controls/scrollbar/overlay_scroll_bar.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 "third_party/skia/include/core/SkColor.h" 8 #include "third_party/skia/include/core/SkColor.h"
9 #include "ui/compositor/scoped_layer_animation_settings.h" 9 #include "ui/compositor/scoped_layer_animation_settings.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 130
131 int OverlayScrollBar::GetLayoutSize() const { 131 int OverlayScrollBar::GetLayoutSize() const {
132 return 0; 132 return 0;
133 } 133 }
134 134
135 int OverlayScrollBar::GetContentOverlapSize() const { 135 int OverlayScrollBar::GetContentOverlapSize() const {
136 return kThumbThickness; 136 return kThumbThickness;
137 } 137 }
138 138
139 void OverlayScrollBar::Layout() {
140 gfx::Rect thumb_bounds = GetTrackBounds();
141 BaseScrollBarThumb* thumb = GetThumb();
142 if (IsHorizontal()) {
143 thumb_bounds.set_x(thumb->x());
144 thumb_bounds.set_width(thumb->width());
145 } else {
146 thumb_bounds.set_y(thumb->y());
147 thumb_bounds.set_height(thumb->height());
148 }
149 thumb->SetBoundsRect(thumb_bounds);
150 }
151
152 bool OverlayScrollBar::CanAcceptEvent(const ui::Event& event) {
153 return layer()->opacity() > 0 && BaseScrollBar::CanAcceptEvent(event);
154 }
155
139 void OverlayScrollBar::OnMouseEntered(const ui::MouseEvent& event) { 156 void OverlayScrollBar::OnMouseEntered(const ui::MouseEvent& event) {
140 Show(); 157 // Note that events are only accepted when the scrollbar is already visible
158 // (due to a change in the scroll value). Don't let the scrollbar vanish from
159 // under the mouse pointer.
160 hide_timer_.Stop();
141 } 161 }
142 162
143 void OverlayScrollBar::OnMouseExited(const ui::MouseEvent& event) { 163 void OverlayScrollBar::OnMouseExited(const ui::MouseEvent& event) {
144 StartHideCountdown(); 164 StartHideCountdown();
145 } 165 }
146 166
147 void OverlayScrollBar::Show() { 167 void OverlayScrollBar::Show() {
148 layer()->SetOpacity(1.0f); 168 layer()->SetOpacity(1.0f);
149 hide_timer_.Stop(); 169 hide_timer_.Stop();
150 } 170 }
151 171
152 void OverlayScrollBar::Hide() { 172 void OverlayScrollBar::Hide() {
153 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); 173 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
154 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(200)); 174 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(200));
155 layer()->SetOpacity(0.0f); 175 layer()->SetOpacity(0.0f);
156 } 176 }
157 177
158 void OverlayScrollBar::StartHideCountdown() { 178 void OverlayScrollBar::StartHideCountdown() {
159 if (IsMouseHovered()) 179 if (IsMouseHovered())
160 return; 180 return;
161 hide_timer_.Start( 181 hide_timer_.Start(
162 FROM_HERE, base::TimeDelta::FromSeconds(1), 182 FROM_HERE, base::TimeDelta::FromSeconds(1),
163 base::Bind(&OverlayScrollBar::Hide, base::Unretained(this))); 183 base::Bind(&OverlayScrollBar::Hide, base::Unretained(this)));
164 } 184 }
165 185
166 void OverlayScrollBar::Layout() {
167 gfx::Rect thumb_bounds = GetTrackBounds();
168 BaseScrollBarThumb* thumb = GetThumb();
169 if (IsHorizontal()) {
170 thumb_bounds.set_x(thumb->x());
171 thumb_bounds.set_width(thumb->width());
172 } else {
173 thumb_bounds.set_y(thumb->y());
174 thumb_bounds.set_height(thumb->height());
175 }
176 thumb->SetBoundsRect(thumb_bounds);
177 }
178
179 } // namespace views 186 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scrollbar/overlay_scroll_bar.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698