zoom_bubble_view.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
7
8#include "base/basictypes.h"
9#include "base/timer/timer.h"
10#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
11#include "content/public/browser/notification_observer.h"
12#include "content/public/browser/notification_registrar.h"
13#include "ui/views/bubble/bubble_delegate.h"
14#include "ui/views/controls/button/button.h"
15#include "ui/views/controls/label.h"
16
17class FullscreenController;
18
19namespace content {
20class NotificationDetails;
21class NotificationSource;
22class WebContents;
23}
24
25// View used to display the zoom percentage when it has changed.
26class ZoomBubbleView : public views::BubbleDelegateView,
27                       public views::ButtonListener,
28                       public content::NotificationObserver,
29                       public ImmersiveModeController::Observer {
30 public:
31  // Shows the bubble and automatically closes it after a short time period if
32  // |auto_close| is true.
33  static void ShowBubble(content::WebContents* web_contents,
34                         bool auto_close);
35
36  // Closes the showing bubble (if one exists).
37  static void CloseBubble();
38
39  // Whether the zoom bubble is currently showing.
40  static bool IsShowing();
41
42  // Returns the zoom bubble if the zoom bubble is showing. Returns NULL
43  // otherwise.
44  static const ZoomBubbleView* GetZoomBubbleForTest();
45
46 private:
47  ZoomBubbleView(views::View* anchor_view,
48                 content::WebContents* web_contents,
49                 bool auto_close,
50                 ImmersiveModeController* immersive_mode_controller,
51                 FullscreenController* fullscreen_controller);
52  virtual ~ZoomBubbleView();
53
54  // If the bubble is not anchored to a view, places the bubble in the top
55  // right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s
56  // browser window. Because the positioning is based on the size of the
57  // bubble, this must be called after the bubble is created.
58  void AdjustForFullscreen(const gfx::Rect& screen_bounds);
59
60  // Refreshes the bubble by changing the zoom percentage appropriately and
61  // resetting the timer if necessary.
62  void Refresh();
63
64  void Close();
65
66  // Starts a timer which will close the bubble if |auto_close_| is true.
67  void StartTimerIfNecessary();
68
69  // Stops the auto-close timer.
70  void StopTimer();
71
72  // views::View methods.
73  virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
74  virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
75
76  // ui::EventHandler method.
77  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
78
79  // views::ButtonListener method.
80  virtual void ButtonPressed(views::Button* sender,
81                             const ui::Event& event) OVERRIDE;
82
83  // views::BubbleDelegateView method.
84  virtual void Init() OVERRIDE;
85  virtual void WindowClosing() OVERRIDE;
86
87  // content::NotificationObserver method.
88  virtual void Observe(int type,
89                       const content::NotificationSource& source,
90                       const content::NotificationDetails& details) OVERRIDE;
91
92  // ImmersiveModeController::Observer methods.
93  virtual void OnImmersiveRevealStarted() OVERRIDE;
94  virtual void OnImmersiveModeControllerDestroyed() OVERRIDE;
95
96  // Singleton instance of the zoom bubble. The zoom bubble can only be shown on
97  // the active browser window, so there is no case in which it will be shown
98  // twice at the same time.
99  static ZoomBubbleView* zoom_bubble_;
100
101  // Timer used to close the bubble when |auto_close_| is true.
102  base::OneShotTimer<ZoomBubbleView> timer_;
103
104  // Label displaying the zoom percentage.
105  views::Label* label_;
106
107  // The WebContents for the page whose zoom has changed.
108  content::WebContents* web_contents_;
109
110  // Whether the currently displayed bubble will automatically close.
111  bool auto_close_;
112
113  // The immersive mode controller for the BrowserView containing
114  // |web_contents_|.
115  // Not owned.
116  ImmersiveModeController* immersive_mode_controller_;
117
118  // Used to register for fullscreen change notifications.
119  content::NotificationRegistrar registrar_;
120
121  DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView);
122};
123
124#endif  // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
125