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