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_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "ui/views/bubble/bubble_delegate.h" | 10 #include "ui/views/bubble/bubble_delegate.h" |
11 #include "ui/views/controls/button/button.h" | 11 #include "ui/views/controls/button/button.h" |
12 #include "ui/views/controls/button/text_button.h" | |
12 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
14 #include "ui/views/events/event.h" | |
15 | |
16 class TabContents; | |
13 | 17 |
14 // View used to display the zoom percentage when it has changed. | 18 // View used to display the zoom percentage when it has changed. |
15 class ZoomBubbleView : public views::BubbleDelegateView { | 19 class ZoomBubbleView : public views::ButtonListener, |
Peter Kasting
2012/07/26 01:36:14
Nit: Maybe makes sense to put BubbleDelegateView f
Kyle Horimoto
2012/08/03 03:33:29
Done.
| |
20 public views::BubbleDelegateView { | |
16 public: | 21 public: |
17 // Shows the bubble and automatically closes it after a short time period if | 22 // Shows the bubble and automatically closes it after a short time period if |
18 // |auto_close| is true. | 23 // |auto_close| is true. |
19 static void ShowBubble(views::View* anchor_view, | 24 static void ShowBubble(views::View* anchor_view, |
20 int zoom_percent, | 25 TabContents* tab_contents, |
21 bool auto_close); | 26 bool auto_close); |
22 static void CloseBubble(); | 27 static void CloseBubble(); |
23 static bool IsShowing(); | 28 static bool IsShowing(); |
24 | 29 |
25 private: | 30 private: |
26 ZoomBubbleView(views::View* anchor_view, | 31 ZoomBubbleView(views::View* anchor_view, |
27 int zoom_percent, | 32 TabContents* tab_contents, |
28 bool auto_close); | 33 bool auto_close); |
29 virtual ~ZoomBubbleView(); | 34 virtual ~ZoomBubbleView(); |
30 | 35 |
36 // Refreshes the bubble by changing the zoom percentage appropriately and | |
37 // resetting the timer if necessary. | |
38 void Refresh(); | |
39 | |
31 void Close(); | 40 void Close(); |
32 | 41 |
42 // Starts a timer which will close the bubble if |auto_close_| is true. | |
43 void StartTimerIfNecessary(); | |
44 | |
45 // Stops the auto-close timer. | |
46 void StopTimer(); | |
47 | |
48 // views::View method. | |
49 virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; | |
50 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | |
51 | |
52 // views::ButtonListener method. | |
53 virtual void ButtonPressed(views::Button* sender, | |
54 const views::Event& event) OVERRIDE; | |
55 | |
33 // views::BubbleDelegateView method. | 56 // views::BubbleDelegateView method. |
34 virtual void Init() OVERRIDE; | 57 virtual void Init() OVERRIDE; |
58 virtual gfx::Rect GetAnchorRect() OVERRIDE; | |
35 | 59 |
36 // views::BubbleDelegateView: | 60 // views::BubbleDelegateView method. |
Peter Kasting
2012/07/26 01:36:14
Nit: Group all overrides from the same base class
Kyle Horimoto
2012/08/03 03:33:29
Done.
| |
37 virtual void WindowClosing() OVERRIDE; | 61 virtual void WindowClosing() OVERRIDE; |
38 | 62 |
39 // Singleton instance of the zoom bubble. The zoom bubble can only be shown on | 63 // Singleton instance of the zoom bubble. The zoom bubble can only be shown on |
40 // the active browser window, so there is no case in which it will be shown | 64 // the active browser window, so there is no case in which it will be shown |
41 // twice at the same time. | 65 // twice at the same time. |
42 static ZoomBubbleView* zoom_bubble_; | 66 static ZoomBubbleView* zoom_bubble_; |
43 | 67 |
44 // Timer used to close the bubble when |auto_close_| is true. | 68 // Timer used to close the bubble when |auto_close_| is true. |
45 base::OneShotTimer<ZoomBubbleView> timer_; | 69 base::OneShotTimer<ZoomBubbleView> timer_; |
46 | 70 |
47 // Label displaying the zoom percentage. | 71 // Label displaying the zoom percentage. |
48 views::Label* label_; | 72 views::Label* label_; |
49 | 73 |
50 // The zoom percentage to show in the bubble. | 74 // The TabContents for the page whose zoom has changed. |
51 int zoom_percent_; | 75 TabContents* tab_contents_; |
52 | 76 |
53 // Whether the currently displayed bubble will automatically close. | 77 // Whether the currently displayed bubble will automatically close. |
54 bool auto_close_; | 78 bool auto_close_; |
55 | 79 |
80 // Private class used to display a text button to use custom mouse events. | |
81 // Because TextButtons already override mouse event handler methods to draw | |
82 // borders, this class is necessary to continue to provide that functionality | |
83 // while correctly handling auto-closing behavior of the zoom bubble. | |
84 class ZoomBubbleViewTextButton : public views::TextButton { | |
85 public: | |
86 ZoomBubbleViewTextButton(ZoomBubbleView* listener, const string16& text); | |
87 virtual ~ZoomBubbleViewTextButton() {} | |
88 virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; | |
89 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | |
90 | |
91 private: | |
92 ZoomBubbleView* delegate_; | |
93 }; | |
94 | |
95 // Give the button access to ZoomBubbleView's internals. | |
Peter Kasting
2012/07/26 01:36:14
It seems better to me to make Start/StopTimer() be
Kyle Horimoto
2012/08/03 03:33:29
Ended up fixing the other part, so this is no long
| |
96 friend class ZoomBubbleViewTextButton; | |
97 | |
56 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView); | 98 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView); |
57 }; | 99 }; |
58 | 100 |
59 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_ | 101 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_ |
OLD | NEW |