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

Side by Side Diff: chrome/browser/ui/views/ash/tab_scrubber.cc

Issue 2703373009: Make the tab scrubber speed proportional with the number of tabs (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/ui/views/ash/tab_scrubber.h" 5 #include "chrome/browser/ui/views/ash/tab_scrubber.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm>
10
9 #include "ash/shell.h" 11 #include "ash/shell.h"
10 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
11 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
12 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h" 16 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h" 18 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "chrome/browser/ui/views/tabs/tab.h" 19 #include "chrome/browser/ui/views/tabs/tab.h"
18 #include "chrome/browser/ui/views/tabs/tab_strip.h" 20 #include "chrome/browser/ui/views/tabs/tab_strip.h"
19 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_source.h" 22 #include "content/public/browser/notification_source.h"
21 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
22 #include "ui/events/event.h" 24 #include "ui/events/event.h"
23 #include "ui/events/event_utils.h" 25 #include "ui/events/event_utils.h"
24 #include "ui/events/gesture_detection/gesture_configuration.h" 26 #include "ui/events/gesture_detection/gesture_configuration.h"
25 #include "ui/views/controls/glow_hover_controller.h" 27 #include "ui/views/controls/glow_hover_controller.h"
26 28
27 namespace { 29 namespace {
30
28 const int64_t kActivationDelayMS = 200; 31 const int64_t kActivationDelayMS = 200;
32
33 inline float Clamp(float value, float low, float high) {
34 return std::min(high, std::max(value, low));
35 }
29 } 36 }
30 37
31 // static 38 // static
32 TabScrubber* TabScrubber::GetInstance() { 39 TabScrubber* TabScrubber::GetInstance() {
33 static TabScrubber* instance = NULL; 40 static TabScrubber* instance = NULL;
34 if (!instance) 41 if (!instance)
35 instance = new TabScrubber(); 42 instance = new TabScrubber();
36 return instance; 43 return instance;
37 } 44 }
38 45
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 swipe_direction_); 306 swipe_direction_);
300 swipe_x_ = start_point.x(); 307 swipe_x_ = start_point.x();
301 swipe_y_ = start_point.y(); 308 swipe_y_ = start_point.y();
302 } 309 }
303 310
304 void TabScrubber::UpdateSwipeX(float x_offset) { 311 void TabScrubber::UpdateSwipeX(float x_offset) {
305 DCHECK(browser_); 312 DCHECK(browser_);
306 DCHECK(tab_strip_); 313 DCHECK(tab_strip_);
307 DCHECK(scrubbing_); 314 DCHECK(scrubbing_);
308 315
309 swipe_x_ += x_offset; 316 // Make the swipe speed inversely proportional with the number or tabs:
317 // Each added tab introduces a reduction of 2% in |x_offset|, with a value of
318 // one fourth of |x_offset| as the minimum (i.e. we need 38 tabs to reach
319 // that minimum reduction).
320 swipe_x_ += Clamp(x_offset - (tab_strip_->tab_count() * 0.02f * x_offset),
321 0.25f * x_offset, x_offset);
310 322
311 // In an RTL layout, everything is mirrored, i.e. the index of the first tab 323 // In an RTL layout, everything is mirrored, i.e. the index of the first tab
312 // (with the smallest X mirrored co-ordinates) is actually the index of the 324 // (with the smallest X mirrored co-ordinates) is actually the index of the
313 // last tab. Same for the index of the last tab. 325 // last tab. Same for the index of the last tab.
314 int first_tab_index = base::i18n::IsRTL() ? tab_strip_->tab_count() - 1 : 0; 326 int first_tab_index = base::i18n::IsRTL() ? tab_strip_->tab_count() - 1 : 0;
315 int last_tab_index = base::i18n::IsRTL() ? 0 : tab_strip_->tab_count() - 1; 327 int last_tab_index = base::i18n::IsRTL() ? 0 : tab_strip_->tab_count() - 1;
316 328
317 Tab* first_tab = tab_strip_->tab_at(first_tab_index); 329 Tab* first_tab = tab_strip_->tab_at(first_tab_index);
318 int first_tab_center = first_tab->GetMirroredBounds().CenterPoint().x(); 330 int first_tab_center = first_tab->GetMirroredBounds().CenterPoint().x();
319 Tab* last_tab = tab_strip_->tab_at(last_tab_index); 331 Tab* last_tab = tab_strip_->tab_at(last_tab_index);
(...skipping 17 matching lines...) Expand all
337 tab->hover_controller()->HideImmediately(); 349 tab->hover_controller()->HideImmediately();
338 } 350 }
339 351
340 if (new_index != browser_->tab_strip_model()->active_index()) { 352 if (new_index != browser_->tab_strip_model()->active_index()) {
341 highlighted_tab_ = new_index; 353 highlighted_tab_ = new_index;
342 new_tab->hover_controller()->Show(views::GlowHoverController::PRONOUNCED); 354 new_tab->hover_controller()->Show(views::GlowHoverController::PRONOUNCED);
343 } else { 355 } else {
344 highlighted_tab_ = -1; 356 highlighted_tab_ = -1;
345 } 357 }
346 } 358 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698