[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / zoom_bubble_view.h
blobcc5437229ea2ddf91a3f7fa4712c8df26c7bd86a
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
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"
17 class FullscreenController;
19 namespace content {
20 class NotificationDetails;
21 class NotificationSource;
22 class WebContents;
25 // View used to display the zoom percentage when it has changed.
26 class 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);
36 // Closes the showing bubble (if one exists).
37 static void CloseBubble();
39 // Whether the zoom bubble is currently showing.
40 static bool IsShowing();
42 // Returns the zoom bubble if the zoom bubble is showing. Returns NULL
43 // otherwise.
44 static const ZoomBubbleView* GetZoomBubbleForTest();
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();
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);
60 // Refreshes the bubble by changing the zoom percentage appropriately and
61 // resetting the timer if necessary.
62 void Refresh();
64 void Close();
66 // Starts a timer which will close the bubble if |auto_close_| is true.
67 void StartTimerIfNecessary();
69 // Stops the auto-close timer.
70 void StopTimer();
72 // views::View methods.
73 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
74 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
76 // ui::EventHandler method.
77 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
79 // views::ButtonListener method.
80 virtual void ButtonPressed(views::Button* sender,
81 const ui::Event& event) OVERRIDE;
83 // views::BubbleDelegateView method.
84 virtual void Init() OVERRIDE;
85 virtual void WindowClosing() OVERRIDE;
87 // content::NotificationObserver method.
88 virtual void Observe(int type,
89 const content::NotificationSource& source,
90 const content::NotificationDetails& details) OVERRIDE;
92 // ImmersiveModeController::Observer methods.
93 virtual void OnImmersiveRevealStarted() OVERRIDE;
94 virtual void OnImmersiveModeControllerDestroyed() OVERRIDE;
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_;
101 // Timer used to close the bubble when |auto_close_| is true.
102 base::OneShotTimer<ZoomBubbleView> timer_;
104 // Label displaying the zoom percentage.
105 views::Label* label_;
107 // The WebContents for the page whose zoom has changed.
108 content::WebContents* web_contents_;
110 // Whether the currently displayed bubble will automatically close.
111 bool auto_close_;
113 // The immersive mode controller for the BrowserView containing
114 // |web_contents_|.
115 // Not owned.
116 ImmersiveModeController* immersive_mode_controller_;
118 // Used to register for fullscreen change notifications.
119 content::NotificationRegistrar registrar_;
121 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView);
124 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_