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 "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "extensions/browser/extension_icon_image.h"
16 #include "ui/views/bubble/bubble_delegate.h"
17 #include "ui/views/controls/button/button.h"
18 #include "ui/views/controls/label.h"
20 class FullscreenController
;
23 class NotificationDetails
;
24 class NotificationSource
;
32 // View used to display the zoom percentage when it has changed.
33 class ZoomBubbleView
: public ManagedFullScreenBubbleDelegateView
,
34 public views::ButtonListener
,
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 // Returns the zoom bubble if the zoom bubble is showing. Returns NULL
48 static ZoomBubbleView
* GetZoomBubble();
51 FRIEND_TEST_ALL_PREFIXES(ZoomBubbleBrowserTest
, ImmersiveFullscreen
);
53 // Stores information about the extension that initiated the zoom change, if
55 struct ZoomBubbleExtensionInfo
{
56 ZoomBubbleExtensionInfo();
57 ~ZoomBubbleExtensionInfo();
59 // The unique id of the extension, which is used to find the correct
60 // extension after clicking on the image button in the zoom bubble.
63 // The name of the extension, which appears in the tooltip of the image
64 // button in the zoom bubble.
67 // An image of the extension's icon, which appears in the zoom bubble as an
69 scoped_ptr
<const extensions::IconImage
> icon_image
;
72 ZoomBubbleView(views::View
* anchor_view
,
73 content::WebContents
* web_contents
,
75 ImmersiveModeController
* immersive_mode_controller
);
76 ~ZoomBubbleView() override
;
78 // ManagedFullScreenBubbleDelegateView:
79 void OnGestureEvent(ui::GestureEvent
* event
) override
;
80 void OnMouseEntered(const ui::MouseEvent
& event
) override
;
81 void OnMouseExited(const ui::MouseEvent
& event
) override
;
83 void WindowClosing() override
;
84 void Close() override
;
86 // views::ButtonListener:
87 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
89 // ImmersiveModeController::Observer:
90 void OnImmersiveRevealStarted() override
;
91 void OnImmersiveModeControllerDestroyed() override
;
93 // extensions::IconImage::Observer:
94 void OnExtensionIconImageChanged(extensions::IconImage
* /* image */) override
;
96 // Refreshes the bubble by changing the zoom percentage appropriately and
97 // resetting the timer if necessary.
100 // Sets information about the extension that initiated the zoom change.
101 // Calling this method asserts that the extension |extension| did initiate
103 void SetExtensionInfo(const extensions::Extension
* extension
);
105 // Starts a timer which will close the bubble if |auto_close_| is true.
106 void StartTimerIfNecessary();
108 // Stops the auto-close timer.
111 ZoomBubbleExtensionInfo extension_info_
;
113 // Singleton instance of the zoom bubble. The zoom bubble can only be shown on
114 // the active browser window, so there is no case in which it will be shown
115 // twice at the same time.
116 static ZoomBubbleView
* zoom_bubble_
;
118 // Timer used to close the bubble when |auto_close_| is true.
119 base::OneShotTimer
<ZoomBubbleView
> timer_
;
121 // Image button in the zoom bubble that will show the |extension_icon_| image
122 // if an extension initiated the zoom change, and links to that extension at
123 // "chrome://extensions".
124 views::ImageButton
* image_button_
;
126 // Label displaying the zoom percentage.
127 views::Label
* label_
;
129 // The WebContents for the page whose zoom has changed.
130 content::WebContents
* web_contents_
;
132 // Whether the currently displayed bubble will automatically close.
135 // The immersive mode controller for the BrowserView containing
138 ImmersiveModeController
* immersive_mode_controller_
;
140 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView
);
143 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_