Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / location_bar / zoom_bubble_view.h
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/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"
18
19 class FullscreenController;
20
21 namespace content {
22 class NotificationDetails;
23 class NotificationSource;
24 class WebContents;
25 }
26
27 namespace views {
28 class ImageButton;
29 }  // namespace views
30
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 {
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);
42
43   // Closes the showing bubble (if one exists).
44   static void CloseBubble();
45
46   // Whether the zoom bubble is currently showing.
47   static bool IsShowing();
48
49   // Returns the zoom bubble if the zoom bubble is showing. Returns NULL
50   // otherwise.
51   static const ZoomBubbleView* GetZoomBubbleForTest();
52
53  private:
54   FRIEND_TEST_ALL_PREFIXES(ZoomBubbleBrowserTest, ImmersiveFullscreen);
55
56   // Stores information about the extension that initiated the zoom change, if
57   // any.
58   struct ZoomBubbleExtensionInfo {
59     ZoomBubbleExtensionInfo();
60     ~ZoomBubbleExtensionInfo();
61
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.
64     std::string id;
65
66     // The name of the extension, which appears in the tooltip of the image
67     // button in the zoom bubble.
68     std::string name;
69
70     // An image of the extension's icon, which appears in the zoom bubble as an
71     // image button.
72     scoped_ptr<const extensions::IconImage> icon_image;
73   };
74
75   ZoomBubbleView(views::View* anchor_view,
76                  content::WebContents* web_contents,
77                  bool auto_close,
78                  ImmersiveModeController* immersive_mode_controller,
79                  FullscreenController* fullscreen_controller);
80   ~ZoomBubbleView() override;
81
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);
87
88   // Refreshes the bubble by changing the zoom percentage appropriately and
89   // resetting the timer if necessary.
90   void Refresh();
91
92   void Close();
93
94   // Sets information about the extension that initiated the zoom change.
95   // Calling this method asserts that the extension |extension| did initiate
96   // the zoom change.
97   void SetExtensionInfo(const extensions::Extension* extension);
98
99   // Starts a timer which will close the bubble if |auto_close_| is true.
100   void StartTimerIfNecessary();
101
102   // Stops the auto-close timer.
103   void StopTimer();
104
105   // extensions::IconImage::Observer overrides:
106   void OnExtensionIconImageChanged(extensions::IconImage* /* image */) override;
107
108   // views::View methods.
109   void OnMouseEntered(const ui::MouseEvent& event) override;
110   void OnMouseExited(const ui::MouseEvent& event) override;
111
112   // ui::EventHandler method.
113   void OnGestureEvent(ui::GestureEvent* event) override;
114
115   // views::ButtonListener method.
116   void ButtonPressed(views::Button* sender, const ui::Event& event) override;
117
118   // views::BubbleDelegateView method.
119   void Init() override;
120   void WindowClosing() override;
121
122   // content::NotificationObserver method.
123   void Observe(int type,
124                const content::NotificationSource& source,
125                const content::NotificationDetails& details) override;
126
127   // ImmersiveModeController::Observer methods.
128   void OnImmersiveRevealStarted() override;
129   void OnImmersiveModeControllerDestroyed() override;
130
131   ZoomBubbleExtensionInfo extension_info_;
132
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_;
137
138   // Timer used to close the bubble when |auto_close_| is true.
139   base::OneShotTimer<ZoomBubbleView> timer_;
140
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_;
145
146   // Label displaying the zoom percentage.
147   views::Label* label_;
148
149   // The WebContents for the page whose zoom has changed.
150   content::WebContents* web_contents_;
151
152   // Whether the currently displayed bubble will automatically close.
153   bool auto_close_;
154
155   // The immersive mode controller for the BrowserView containing
156   // |web_contents_|.
157   // Not owned.
158   ImmersiveModeController* immersive_mode_controller_;
159
160   // Used to register for fullscreen change notifications.
161   content::NotificationRegistrar registrar_;
162
163   DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView);
164 };
165
166 #endif  // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_