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/gtest_prod_util.h"
10 #include "base/timer/timer.h"
11 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "extensions/browser/extension_icon_image.h"
15 #include "ui/views/bubble/bubble_delegate.h"
16 #include "ui/views/controls/button/button.h"
17 #include "ui/views/controls/label.h"
19 class FullscreenController;
22 class NotificationDetails;
23 class NotificationSource;
31 // View used to display the zoom percentage when it has changed.
32 class ZoomBubbleView : public views::BubbleDelegateView,
33 public views::ButtonListener,
34 public content::NotificationObserver,
35 public ImmersiveModeController::Observer,
36 public extensions::IconImage::Observer {
38 // Shows the bubble and automatically closes it after a short time period if
39 // |auto_close| is true.
40 static void ShowBubble(content::WebContents* web_contents,
43 // Closes the showing bubble (if one exists).
44 static void CloseBubble();
46 // Whether the zoom bubble is currently showing.
47 static bool IsShowing();
49 // Returns the zoom bubble if the zoom bubble is showing. Returns NULL
51 static const ZoomBubbleView* GetZoomBubbleForTest();
54 FRIEND_TEST_ALL_PREFIXES(ZoomBubbleBrowserTest, ImmersiveFullscreen);
56 // Stores information about the extension that initiated the zoom change, if
58 struct ZoomBubbleExtensionInfo {
59 ZoomBubbleExtensionInfo();
60 ~ZoomBubbleExtensionInfo();
62 // The unique id of the extension, which is used to find the correct
63 // extension after clicking on the image button in the zoom bubble.
66 // The name of the extension, which appears in the tooltip of the image
67 // button in the zoom bubble.
70 // An image of the extension's icon, which appears in the zoom bubble as an
72 scoped_ptr<const extensions::IconImage> icon_image;
75 ZoomBubbleView(views::View* anchor_view,
76 content::WebContents* web_contents,
78 ImmersiveModeController* immersive_mode_controller,
79 FullscreenController* fullscreen_controller);
80 ~ZoomBubbleView() override;
82 // If the bubble is not anchored to a view, places the bubble in the top
83 // right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s
84 // browser window. Because the positioning is based on the size of the
85 // bubble, this must be called after the bubble is created.
86 void AdjustForFullscreen(const gfx::Rect& screen_bounds);
88 // Refreshes the bubble by changing the zoom percentage appropriately and
89 // resetting the timer if necessary.
94 // Sets information about the extension that initiated the zoom change.
95 // Calling this method asserts that the extension |extension| did initiate
97 void SetExtensionInfo(const extensions::Extension* extension);
99 // Starts a timer which will close the bubble if |auto_close_| is true.
100 void StartTimerIfNecessary();
102 // Stops the auto-close timer.
105 // extensions::IconImage::Observer overrides:
106 void OnExtensionIconImageChanged(extensions::IconImage* /* image */) override;
108 // views::View methods.
109 void OnMouseEntered(const ui::MouseEvent& event) override;
110 void OnMouseExited(const ui::MouseEvent& event) override;
112 // ui::EventHandler method.
113 void OnGestureEvent(ui::GestureEvent* event) override;
115 // views::ButtonListener method.
116 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
118 // views::BubbleDelegateView method.
119 void Init() override;
120 void WindowClosing() override;
122 // content::NotificationObserver method.
123 void Observe(int type,
124 const content::NotificationSource& source,
125 const content::NotificationDetails& details) override;
127 // ImmersiveModeController::Observer methods.
128 void OnImmersiveRevealStarted() override;
129 void OnImmersiveModeControllerDestroyed() override;
131 ZoomBubbleExtensionInfo extension_info_;
133 // Singleton instance of the zoom bubble. The zoom bubble can only be shown on
134 // the active browser window, so there is no case in which it will be shown
135 // twice at the same time.
136 static ZoomBubbleView* zoom_bubble_;
138 // Timer used to close the bubble when |auto_close_| is true.
139 base::OneShotTimer<ZoomBubbleView> timer_;
141 // Image button in the zoom bubble that will show the |extension_icon_| image
142 // if an extension initiated the zoom change, and links to that extension at
143 // "chrome://extensions".
144 views::ImageButton* image_button_;
146 // Label displaying the zoom percentage.
147 views::Label* label_;
149 // The WebContents for the page whose zoom has changed.
150 content::WebContents* web_contents_;
152 // Whether the currently displayed bubble will automatically close.
155 // The immersive mode controller for the BrowserView containing
158 ImmersiveModeController* immersive_mode_controller_;
160 // Used to register for fullscreen change notifications.
161 content::NotificationRegistrar registrar_;
163 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView);
166 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_