1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ 6 #define CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ 7 8 #include "base/timer/timer.h" 9 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 10 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" 11 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_registrar.h" 13 #include "ui/base/animation/animation_delegate.h" 14 #include "ui/base/events/event_handler.h" 15 16 class Browser; 17 class TabStrip; 18 19 namespace gfx { 20 class Point; 21 } 22 23 // Class to enable quick tab switching via Ctrl-left-drag. 24 // Notes: this is experimental, and disables ctrl-clicks. It should not be 25 // enabled other than through flags until we implement 3 finger drag as the 26 // mechanism to invoke it. At that point we will add test coverage. 27 class TabScrubber : public ui::EventHandler, 28 public content::NotificationObserver, 29 public TabStripObserver { 30 public: 31 enum Direction {LEFT, RIGHT}; 32 33 // Returns a the single instance of a TabScrubber. 34 static TabScrubber* GetInstance(); 35 36 // Returns the virtual position of a swipe starting in the tab at |index|, 37 // base on the |direction|. 38 static gfx::Point GetStartPoint(TabStrip* tab_strip, 39 int index, 40 TabScrubber::Direction direction); 41 42 void set_activation_delay(int activation_delay) { 43 activation_delay_ = activation_delay; 44 use_default_activation_delay_ = false; 45 } 46 int activation_delay() const { return activation_delay_; } 47 int highlighted_tab() const { return highlighted_tab_; } 48 bool IsActivationPending(); 49 50 private: 51 TabScrubber(); 52 virtual ~TabScrubber(); 53 54 // ui::EventHandler overrides: 55 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; 56 57 // content::NotificationObserver overrides: 58 virtual void Observe(int type, 59 const content::NotificationSource& source, 60 const content::NotificationDetails& details) OVERRIDE; 61 62 // TabStripObserver overrides. 63 virtual void TabStripAddedTabAt(TabStrip* tab_strip, int index) OVERRIDE; 64 virtual void TabStripMovedTab(TabStrip* tab_strip, 65 int from_index, 66 int to_index) OVERRIDE; 67 virtual void TabStripRemovedTabAt(TabStrip* tab_strip, int index) OVERRIDE; 68 virtual void TabStripDeleted(TabStrip* tab_strip) OVERRIDE; 69 70 Browser* GetActiveBrowser(); 71 void FinishScrub(bool activate); 72 73 // Are we currently scrubbing?. 74 bool scrubbing_; 75 // The last browser we used for scrubbing, NULL if |scrubbing_| is 76 // false and there is no pending work. 77 Browser* browser_; 78 // The current accumulated x and y positions of a swipe, in 79 // the coordinates of the TabStrip of |browser_| 80 float swipe_x_; 81 float swipe_y_; 82 // The direction the current swipe is headed. 83 Direction swipe_direction_; 84 // The index of the tab that is currently highlighted. 85 int highlighted_tab_; 86 // Timer to control a delayed activation of the |highlighted_tab_|. 87 base::Timer activate_timer_; 88 // Time to wait in ms before newly selected tab becomes active. 89 int activation_delay_; 90 // Set if activation_delay had been explicitly set. 91 bool use_default_activation_delay_; 92 // Forces the tabs to be revealed if we are in immersive fullscreen. 93 scoped_ptr<ImmersiveRevealedLock> immersive_reveal_lock_; 94 95 content::NotificationRegistrar registrar_; 96 base::WeakPtrFactory<TabScrubber> weak_ptr_factory_; 97 98 DISALLOW_COPY_AND_ASSIGN(TabScrubber); 99 }; 100 101 #endif // CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ 102