1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/timer/timer.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/extension_icon_image.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/label.h"
class FullscreenController;
namespace content {
class NotificationDetails;
class NotificationSource;
class WebContents;
}
namespace views {
class ImageButton;
} // namespace views
// View used to display the zoom percentage when it has changed.
class ZoomBubbleView : public LocationBarBubbleDelegateView,
public views::ButtonListener,
public ImmersiveModeController::Observer,
public extensions::IconImage::Observer {
public:
// Shows the bubble and automatically closes it after a short time period if
// |reason| is AUTOMATIC.
static void ShowBubble(content::WebContents* web_contents,
DisplayReason reason);
// Closes the showing bubble (if one exists).
static void CloseCurrentBubble();
// Returns the zoom bubble if the zoom bubble is showing. Returns NULL
// otherwise.
static ZoomBubbleView* GetZoomBubble();
private:
FRIEND_TEST_ALL_PREFIXES(ZoomBubbleBrowserTest, ImmersiveFullscreen);
// Stores information about the extension that initiated the zoom change, if
// any.
struct ZoomBubbleExtensionInfo {
ZoomBubbleExtensionInfo();
~ZoomBubbleExtensionInfo();
// The unique id of the extension, which is used to find the correct
// extension after clicking on the image button in the zoom bubble.
std::string id;
// The name of the extension, which appears in the tooltip of the image
// button in the zoom bubble.
std::string name;
// An image of the extension's icon, which appears in the zoom bubble as an
// image button.
scoped_ptr<const extensions::IconImage> icon_image;
};
ZoomBubbleView(views::View* anchor_view,
content::WebContents* web_contents,
DisplayReason reason,
ImmersiveModeController* immersive_mode_controller);
~ZoomBubbleView() override;
// LocationBarBubbleDelegateView:
void OnGestureEvent(ui::GestureEvent* event) override;
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
void Init() override;
void WindowClosing() override;
void CloseBubble() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// ImmersiveModeController::Observer:
void OnImmersiveRevealStarted() override;
void OnImmersiveModeControllerDestroyed() override;
// extensions::IconImage::Observer:
void OnExtensionIconImageChanged(extensions::IconImage* /* image */) override;
// Refreshes the bubble by changing the zoom percentage appropriately and
// resetting the timer if necessary.
void Refresh();
// Sets information about the extension that initiated the zoom change.
// Calling this method asserts that the extension |extension| did initiate
// the zoom change.
void SetExtensionInfo(const extensions::Extension* extension);
// Starts a timer which will close the bubble if |auto_close_| is true.
void StartTimerIfNecessary();
// Stops the auto-close timer.
void StopTimer();
ZoomBubbleExtensionInfo extension_info_;
// Singleton instance of the zoom bubble. The zoom bubble can only be shown on
// the active browser window, so there is no case in which it will be shown
// twice at the same time.
static ZoomBubbleView* zoom_bubble_;
// Timer used to auto close the bubble.
base::OneShotTimer timer_;
// Image button in the zoom bubble that will show the |extension_icon_| image
// if an extension initiated the zoom change, and links to that extension at
// "chrome://extensions".
views::ImageButton* image_button_;
// Label displaying the zoom percentage.
views::Label* label_;
// The WebContents for the page whose zoom has changed.
content::WebContents* web_contents_;
// Whether the currently displayed bubble will automatically close.
bool auto_close_;
// The immersive mode controller for the BrowserView containing
// |web_contents_|.
// Not owned.
ImmersiveModeController* immersive_mode_controller_;
DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView);
};
#endif // CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
|