OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ |
7 | 7 |
| 8 #include "base/timer.h" |
8 #include "content/public/browser/notification_observer.h" | 9 #include "content/public/browser/notification_observer.h" |
9 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
| 11 #include "ui/base/animation/animation_delegate.h" |
10 #include "ui/base/events/event_handler.h" | 12 #include "ui/base/events/event_handler.h" |
11 | 13 |
12 class Browser; | 14 class Browser; |
13 class Tab; | 15 class TabStrip; |
| 16 |
| 17 namespace gfx { |
| 18 class Point; |
| 19 } |
14 | 20 |
15 // Class to enable quick tab switching via Ctrl-left-drag. | 21 // Class to enable quick tab switching via Ctrl-left-drag. |
16 // Notes: this is experimental, and disables ctrl-clicks. It should not be | 22 // Notes: this is experimental, and disables ctrl-clicks. It should not be |
17 // enabled other than through flags until we implement 3 finger drag as the | 23 // enabled other than through flags until we implement 3 finger drag as the |
18 // mechanism to invoke it. At that point we will add test coverage. | 24 // mechanism to invoke it. At that point we will add test coverage. |
19 class TabScrubber : public ui::EventHandler, | 25 class TabScrubber : public ui::EventHandler, |
20 public content::NotificationObserver { | 26 public content::NotificationObserver { |
21 public: | 27 public: |
| 28 enum Direction {LEFT, RIGHT}; |
| 29 |
| 30 // Returns a the single instance of a TabScrubber. |
22 static TabScrubber* GetInstance(); | 31 static TabScrubber* GetInstance(); |
23 | 32 |
| 33 // Returns the virtual position of a swipe starting in the tab at |index|, |
| 34 // base on the |direction|. |
| 35 static gfx::Point GetStartPoint(TabStrip* tab_strip, |
| 36 int index, |
| 37 TabScrubber::Direction direction); |
| 38 |
| 39 void set_activation_delay(base::TimeDelta activation_delay) { |
| 40 activation_delay_ = activation_delay; |
| 41 } |
| 42 base::TimeDelta activation_delay() const { return activation_delay_; } |
| 43 |
24 private: | 44 private: |
25 TabScrubber(); | 45 TabScrubber(); |
26 virtual ~TabScrubber(); | 46 virtual ~TabScrubber(); |
27 | 47 |
28 // ui::EventHandler overrides: | 48 // ui::EventHandler overrides: |
29 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 49 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
30 | 50 |
31 // content::NotificationObserver overrides: | 51 // content::NotificationObserver overrides: |
32 virtual void Observe(int type, | 52 virtual void Observe(int type, |
33 const content::NotificationSource& source, | 53 const content::NotificationSource& source, |
34 const content::NotificationDetails& details) OVERRIDE; | 54 const content::NotificationDetails& details) OVERRIDE; |
35 | 55 |
36 Browser* GetActiveBrowser(); | 56 Browser* GetActiveBrowser(); |
37 void StartScrubbing(); | 57 void FinishScrub(bool activate); |
38 void StopScrubbing(); | 58 void CancelImmersiveReveal(); |
39 | 59 |
40 // Indicates that we are currently scrubbing. | 60 // Are we currently scrubbing?. |
41 bool scrubbing_; | 61 bool scrubbing_; |
42 // The browser that we are scrubbing. | 62 // The last browser we used for scrubbing, NULL if |scrubbing_| is |
| 63 // false and there is no pending work. |
43 Browser* browser_; | 64 Browser* browser_; |
44 // The x value of the event that initiated scrubbing. | 65 // The current accumulated x and y positions of a swipe, in |
45 float scroll_x_; | 66 // the coordinates of the TabStrip of |browser_| |
46 float scroll_y_; | 67 float swipe_x_; |
| 68 float swipe_y_; |
| 69 // The direction the current swipe is headed. |
| 70 Direction swipe_direction_; |
| 71 // The index of the tab that is currently highlighted. |
| 72 int highlighted_tab_; |
| 73 // Timer to control a delayed activation of the |highlighted_tab_|. |
| 74 base::Timer activate_timer_; |
| 75 // Time to wait before newly selected tab becomes active. |
| 76 base::TimeDelta activation_delay_; |
| 77 // Indicates if we were in immersive mode and forced the tabs to be |
| 78 // revealed. |
| 79 bool should_cancel_immersive_reveal_; |
| 80 // Timer to control the cancel of an immersive reveal. |
| 81 base::Timer cancel_immersive_reveal_timer_; |
47 | 82 |
48 content::NotificationRegistrar registrar_; | 83 content::NotificationRegistrar registrar_; |
| 84 // Note: This should remain the last member so it'll be destroyed and |
| 85 // invalidate its weak pointers before any other members are destroyed. |
| 86 base::WeakPtrFactory<TabScrubber> weak_ptr_factory_; |
49 | 87 |
50 DISALLOW_COPY_AND_ASSIGN(TabScrubber); | 88 DISALLOW_COPY_AND_ASSIGN(TabScrubber); |
51 }; | 89 }; |
52 | 90 |
53 #endif // CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ | 91 #endif // CHROME_BROWSER_UI_VIEWS_ASH_TAB_SCRUBBER_H_ |
OLD | NEW |