Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / zoom_bubble_view.h
blob83bb3f34a55b778db3229ef979f9c246b0fa4aaa
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;
22 namespace content {
23 class NotificationDetails;
24 class NotificationSource;
25 class WebContents;
28 namespace views {
29 class ImageButton;
30 } // namespace views
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 {
37 public:
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,
41 bool auto_close);
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
47 // otherwise.
48 static ZoomBubbleView* GetZoomBubble();
50 private:
51 FRIEND_TEST_ALL_PREFIXES(ZoomBubbleBrowserTest, ImmersiveFullscreen);
53 // Stores information about the extension that initiated the zoom change, if
54 // any.
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.
61 std::string id;
63 // The name of the extension, which appears in the tooltip of the image
64 // button in the zoom bubble.
65 std::string name;
67 // An image of the extension's icon, which appears in the zoom bubble as an
68 // image button.
69 scoped_ptr<const extensions::IconImage> icon_image;
72 ZoomBubbleView(views::View* anchor_view,
73 content::WebContents* web_contents,
74 bool auto_close,
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;
82 void Init() 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.
98 void Refresh();
100 // Sets information about the extension that initiated the zoom change.
101 // Calling this method asserts that the extension |extension| did initiate
102 // the zoom change.
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.
109 void StopTimer();
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.
133 bool auto_close_;
135 // The immersive mode controller for the BrowserView containing
136 // |web_contents_|.
137 // Not owned.
138 ImmersiveModeController* immersive_mode_controller_;
140 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView);
143 #endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_