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

Side by Side Diff: ui/views/controls/scrollbar/cocoa_scroll_bar.mm

Issue 2189583004: [not for review - epic CL] Adding Elastic+Momentum+Layered scrolling to views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #import "ui/views/controls/scrollbar/cocoa_scroll_bar.h" 5 #import "ui/views/controls/scrollbar/cocoa_scroll_bar.h"
6 6
7 #import "base/mac/sdk_forward_declarations.h" 7 #import "base/mac/sdk_forward_declarations.h"
8 #include "third_party/skia/include/core/SkColor.h" 8 #include "third_party/skia/include/core/SkColor.h"
9 #include "third_party/skia/include/effects/SkGradientShader.h" 9 #include "third_party/skia/include/effects/SkGradientShader.h"
10 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // CocoaScrollBar class 161 // CocoaScrollBar class
162 162
163 CocoaScrollBar::CocoaScrollBar(bool horizontal) 163 CocoaScrollBar::CocoaScrollBar(bool horizontal)
164 : BaseScrollBar(horizontal, new CocoaScrollBarThumb(this)), 164 : BaseScrollBar(horizontal, new CocoaScrollBarThumb(this)),
165 hide_scrollbar_timer_( 165 hide_scrollbar_timer_(
166 FROM_HERE, 166 FROM_HERE,
167 base::TimeDelta::FromMilliseconds(kScrollbarHideTimeoutMs), 167 base::TimeDelta::FromMilliseconds(kScrollbarHideTimeoutMs),
168 base::Bind(&CocoaScrollBar::HideScrollbar, base::Unretained(this)), 168 base::Bind(&CocoaScrollBar::HideScrollbar, base::Unretained(this)),
169 false), 169 false),
170 thickness_animation_(this), 170 thickness_animation_(this),
171 last_contents_scroll_offset_(0),
171 is_expanded_(false), 172 is_expanded_(false),
172 did_start_dragging_(false) { 173 did_start_dragging_(false) {
173 bridge_.reset([[ViewsScrollbarBridge alloc] initWithDelegate:this]); 174 bridge_.reset([[ViewsScrollbarBridge alloc] initWithDelegate:this]);
174 scroller_style_ = [ViewsScrollbarBridge getPreferredScrollerStyle]; 175 scroller_style_ = [ViewsScrollbarBridge getPreferredScrollerStyle];
175 176
176 thickness_animation_.SetSlideDuration(kExpandDurationMs); 177 thickness_animation_.SetSlideDuration(kExpandDurationMs);
177 178
178 SetPaintToLayer(true); 179 SetPaintToLayer(true);
179 has_scrolltrack_ = scroller_style_ == NSScrollerStyleLegacy; 180 has_scrolltrack_ = scroller_style_ == NSScrollerStyleLegacy;
180 layer()->SetOpacity(scroller_style_ == NSScrollerStyleOverlay ? 0.0f : 1.0f); 181 layer()->SetOpacity(scroller_style_ == NSScrollerStyleOverlay ? 0.0f : 1.0f);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 316 }
316 317
317 hide_scrollbar_timer_.Reset(); 318 hide_scrollbar_timer_.Reset();
318 } 319 }
319 320
320 void CocoaScrollBar::OnMouseExited(const ui::MouseEvent& event) { 321 void CocoaScrollBar::OnMouseExited(const ui::MouseEvent& event) {
321 ResetOverlayScrollbar(); 322 ResetOverlayScrollbar();
322 } 323 }
323 324
324 ////////////////////////////////////////////////////////////////// 325 //////////////////////////////////////////////////////////////////
325 // CocoaScrollBar::BaseScrollBar: 326 // CocoaScrollBar::ScrollBar:
326 327
327 void CocoaScrollBar::ScrollToPosition(int position) { 328 void CocoaScrollBar::Update(int viewport_size,
328 BaseScrollBar::ScrollToPosition(position); 329 int content_size,
330 int contents_scroll_offset) {
331 // TODO(tapted): Pass in overscroll amounts from the Layer and "Squish" the
332 // scroller thumb accordingly.
333 BaseScrollBar::Update(viewport_size, content_size, contents_scroll_offset);
334
335 // Only reveal the scroller when |contents_scroll_offset| changes. Note this
336 // is different to GetPosition() which can change due to layout. A layout
337 // change can also change the offset; show the scroller in these cases. This
338 // is consistent with WebContents (Cocoa will also show a scroller with any
339 // mouse-initiated layout, put not programmatic size changes).
340 if (contents_scroll_offset == last_contents_scroll_offset_)
341 return;
342
343 last_contents_scroll_offset_ = contents_scroll_offset;
329 344
330 if (GetCocoaScrollBarThumb()->IsStatePressed()) 345 if (GetCocoaScrollBarThumb()->IsStatePressed())
331 did_start_dragging_ = true; 346 did_start_dragging_ = true;
332 347
333 if (scroller_style_ == NSScrollerStyleOverlay) { 348 if (scroller_style_ == NSScrollerStyleOverlay) {
334 ShowScrollbar(); 349 ShowScrollbar();
335 hide_scrollbar_timer_.Reset(); 350 hide_scrollbar_timer_.Reset();
336 } 351 }
337 } 352 }
338 353
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 void CocoaScrollBar::SetScrolltrackVisible(bool visible) { 494 void CocoaScrollBar::SetScrolltrackVisible(bool visible) {
480 has_scrolltrack_ = visible; 495 has_scrolltrack_ = visible;
481 SchedulePaint(); 496 SchedulePaint();
482 } 497 }
483 498
484 CocoaScrollBarThumb* CocoaScrollBar::GetCocoaScrollBarThumb() const { 499 CocoaScrollBarThumb* CocoaScrollBar::GetCocoaScrollBarThumb() const {
485 return static_cast<CocoaScrollBarThumb*>(GetThumb()); 500 return static_cast<CocoaScrollBarThumb*>(GetThumb());
486 } 501 }
487 502
488 } // namespace views 503 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scrollbar/cocoa_scroll_bar.h ('k') | ui/views/controls/scrollbar/scroll_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698