Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/ui/views/extensions/extension_popup.h

Issue 6334101: Removal of chrome.experimental.popup set of APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/ref_counted.h"
9 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_host.h"
10 #include "chrome/browser/ui/views/browser_bubble.h" 11 #include "chrome/browser/ui/views/browser_bubble.h"
11 #include "chrome/browser/ui/views/bubble_border.h" 12 #include "chrome/browser/ui/views/bubble_border.h"
12 #include "chrome/browser/ui/views/extensions/extension_view.h" 13 #include "chrome/browser/ui/views/extensions/extension_view.h"
13 #include "chrome/common/notification_observer.h" 14 #include "chrome/common/notification_observer.h"
14 #include "chrome/common/notification_registrar.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "ui/gfx/native_widget_types.h"
17 16
18 17
19 class Browser; 18 class Browser;
20 class ExtensionHost; 19 class ExtensionHost;
21 class Profile; 20 class Profile;
22 21
23 namespace views { 22 namespace views {
24 class Widget; 23 class Widget;
25 } 24 }
26 25
27 class ExtensionPopup : public BrowserBubble, 26 class ExtensionPopup : public BrowserBubble,
28 public BrowserBubble::Delegate, 27 public BrowserBubble::Delegate,
28 public ExtensionView::Container,
29 public NotificationObserver, 29 public NotificationObserver,
30 public ExtensionView::Container { 30 public base::RefCounted<ExtensionPopup> {
31 public: 31 public:
32 // Observer to ExtensionPopup events. 32 // Observer to ExtensionPopup events.
33 class Observer { 33 class Observer {
34 public: 34 public:
35 // Called when the ExtensionPopup is closing. Note that it 35 // Called when the ExtensionPopup is closing. Note that it
36 // is ref-counted, and thus will be released shortly after 36 // is ref-counted, and thus will be released shortly after
37 // making this delegate call. 37 // making this delegate call.
38 virtual void ExtensionPopupIsClosing(ExtensionPopup* popup) {} 38 virtual void ExtensionPopupIsClosing(ExtensionPopup* popup) {}
39
40 // Called after the ExtensionPopup has been closed and deleted.
41 // |popup_token| is the address of the deleted ExtensionPopup.
42 virtual void ExtensionPopupClosed(void* popup_token) {}
43
44 // Called when the ExtensionHost is first created for the pop-up view.
45 // Note that this is invoked BEFORE the ExtensionPopup is created, and can
46 // be used to provide extra configuration of the host before it is pushed
47 // into the popup. An example use is for automation resource routing in
48 // Chrome-Frame. See extension_popup_api.cc.
49 virtual void ExtensionHostCreated(ExtensionHost* host) {}
50
51 // Called immediately after a popup is created, but before the hosted
52 // extension has loaded and before the popup has been displayed. Use to
53 // finalize configuration of |popup|.
54 virtual void ExtensionPopupCreated(ExtensionPopup* popup) {}
55
56 // Called when the ExtensionPopup is resized. Note that the popup may have
57 // an empty bounds, if a popup is repositioned before the hosted content
58 // has loaded.
59 virtual void ExtensionPopupResized(ExtensionPopup* popup) {}
60 };
61
62 enum PopupChrome {
63 BUBBLE_CHROME,
64 RECTANGLE_CHROME
65 }; 39 };
66 40
67 virtual ~ExtensionPopup(); 41 virtual ~ExtensionPopup();
68 42
69 // Create and show a popup with |url| positioned adjacent to |relative_to| in 43 // Create and show a popup with |url| positioned adjacent to |relative_to| in
70 // screen coordinates. 44 // screen coordinates.
71 // |browser| is the browser to which the pop-up will be attached. NULL is a 45 // |browser| is the browser to which the pop-up will be attached. NULL is a
72 // valid parameter for pop-ups not associated with a browser. 46 // valid parameter for pop-ups not associated with a browser.
73 // |profile| is the user profile instance associated with the popup. A 47 // |profile| is the user profile instance associated with the popup. A
rafaelw 2011/02/10 20:22:00 remove
Jeff Timanus 2011/02/10 21:51:29 Done.
74 // non NULL value must be given. 48 // non NULL value must be given.
75 // |frame_window| is the native window that hosts the view inside which the
76 // popup will be anchored.
77 // The positioning of the pop-up is determined by |arrow_location| according 49 // The positioning of the pop-up is determined by |arrow_location| according
78 // to the following logic: The popup is anchored so that the corner indicated 50 // to the following logic: The popup is anchored so that the corner indicated
79 // by value of |arrow_location| remains fixed during popup resizes. 51 // by value of |arrow_location| remains fixed during popup resizes.
80 // If |arrow_location| is BOTTOM_*, then the popup 'pops up', otherwise 52 // If |arrow_location| is BOTTOM_*, then the popup 'pops up', otherwise
81 // the popup 'drops down'. 53 // the popup 'drops down'.
82 // Pass |activate_on_show| as true to activate the popup window.
83 // Pass |inspect_with_devtools| as true to pin the popup open and show the 54 // Pass |inspect_with_devtools| as true to pin the popup open and show the
84 // devtools window for it. 55 // devtools window for it.
85 // The |chrome| argument controls the chrome that surrounds the pop-up.
86 // Passing BUBBLE_CHROME will give the pop-up a bubble-like appearance,
87 // including the arrow mentioned above. Passing RECTANGLE_CHROME will give
88 // the popup a rectangular, black border with a drop-shadow with no arrow.
89 // The positioning of the popup is still governed by the arrow-location
90 // parameter.
91 //
92 // The actual display of the popup is delayed until the page contents 56 // The actual display of the popup is delayed until the page contents
93 // finish loading in order to minimize UI flashing and resizing. 57 // finish loading in order to minimize UI flashing and resizing.
94 static ExtensionPopup* Show(const GURL& url, Browser* browser, 58 static ExtensionPopup* Show(const GURL& url, Browser* browser,
95 Profile* profile,
96 gfx::NativeWindow frame_window,
97 const gfx::Rect& relative_to, 59 const gfx::Rect& relative_to,
98 BubbleBorder::ArrowLocation arrow_location, 60 BubbleBorder::ArrowLocation arrow_location,
99 bool activate_on_show,
100 bool inspect_with_devtools, 61 bool inspect_with_devtools,
101 PopupChrome chrome,
102 Observer* observer); 62 Observer* observer);
103 63
104 // Assigns the maximal width and height, respectively, to which the popup 64 // Closes the ExtensionPopup.
105 // may expand. If these routines are not called, the popup will resize to
106 // no larger than |kMaxWidth| x |kMaxHeight|. Note that the popup will
107 // never expand to larger than the dimensions of the screen.
108 void set_max_width(int width) { max_size_.set_width(width); }
109 void set_max_height(int height) { max_size_.set_height(height); }
110
111 // Closes the ExtensionPopup (this will cause the delegate
112 // ExtensionPopupIsClosing and ExtensionPopupClosed to fire.
113 void Close(); 65 void Close();
114 66
115 // Some clients wish to do their own custom focus change management. If this 67 // Some clients wish to do their own custom focus change management. If this
116 // is set to false, then the ExtensionPopup will not do anything in response 68 // is set to false, then the ExtensionPopup will not do anything in response
117 // to the BubbleLostFocus() calls it gets from the BrowserBubble. 69 // to the BubbleLostFocus() calls it gets from the BrowserBubble.
118 void set_close_on_lost_focus(bool close_on_lost_focus) { 70 void set_close_on_lost_focus(bool close_on_lost_focus) {
119 close_on_lost_focus_ = close_on_lost_focus; 71 close_on_lost_focus_ = close_on_lost_focus;
120 } 72 }
121 73
122 ExtensionHost* host() const { return extension_host_.get(); } 74 ExtensionHost* host() const { return extension_host_.get(); }
123 75
124 // Assigns the arrow location of the popup view, and updates the popup
125 // border widget, if necessary.
126 void SetArrowPosition(BubbleBorder::ArrowLocation arrow_location);
127 BubbleBorder::ArrowLocation arrow_position() const {
128 return anchor_position_;
129 }
130
131 // Gives the desired bounds (in screen coordinates) given the rect to point
132 // to and the size of the contained contents. Includes all of the
133 // border-chrome surrounding the pop-up as well.
134 gfx::Rect GetOuterBounds() const;
135
136 // BrowserBubble overrides. 76 // BrowserBubble overrides.
137 virtual void Hide(); 77 virtual void Hide();
138 virtual void Show(bool activate); 78 virtual void Show(bool activate);
139 virtual void ResizeToView(); 79 virtual void ResizeToView();
140 80
141 // BrowserBubble::Delegate methods. 81 // BrowserBubble::Delegate methods.
142 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); 82 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble);
143 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); 83 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble);
144 virtual void BubbleGotFocus(BrowserBubble* bubble); 84 virtual void BubbleGotFocus(BrowserBubble* bubble);
145 virtual void BubbleLostFocus(BrowserBubble* bubble, 85 virtual void BubbleLostFocus(BrowserBubble* bubble,
146 bool lost_focus_to_child); 86 bool lost_focus_to_child);
147 87
148 // NotificationObserver overrides. 88 // NotificationObserver overrides.
149 virtual void Observe(NotificationType type, 89 virtual void Observe(NotificationType type,
150 const NotificationSource& source, 90 const NotificationSource& source,
151 const NotificationDetails& details); 91 const NotificationDetails& details);
152 92
153 // ExtensionView::Container overrides. 93 // ExtensionView::Container overrides.
154 virtual void OnExtensionMouseMove(ExtensionView* view) { } 94 virtual void OnExtensionMouseMove(ExtensionView* view) { }
155 virtual void OnExtensionMouseLeave(ExtensionView* view) { } 95 virtual void OnExtensionMouseLeave(ExtensionView* view) { }
156 virtual void OnExtensionPreferredSizeChanged(ExtensionView* view); 96 virtual void OnExtensionPreferredSizeChanged(ExtensionView* view);
157 97
158 // Export the refrence-counted interface required for use as template
159 // arguments for RefCounted. ExtensionPopup does not inherit from RefCounted
160 // because it must override the behaviour of Release.
161 void AddRef() { instance_lifetime_->AddRef(); }
162 static bool ImplementsThreadSafeReferenceCounting() {
163 return InternalRefCounter::ImplementsThreadSafeReferenceCounting();
164 }
165
166 // Implements the standard RefCounted<T>::Release behaviour, except
167 // signals Observer::ExtensionPopupClosed after final release.
168 void Release();
169
170 // The min/max height of popups. 98 // The min/max height of popups.
171 static const int kMinWidth; 99 static const int kMinWidth;
172 static const int kMinHeight; 100 static const int kMinHeight;
173 static const int kMaxWidth; 101 static const int kMaxWidth;
174 static const int kMaxHeight; 102 static const int kMaxHeight;
175 103
176 private: 104 private:
177 ExtensionPopup(ExtensionHost* host, 105 ExtensionPopup(ExtensionHost* host,
178 views::Widget* frame, 106 views::Widget* frame,
179 const gfx::Rect& relative_to, 107 const gfx::Rect& relative_to,
180 BubbleBorder::ArrowLocation arrow_location, 108 BubbleBorder::ArrowLocation arrow_location,
181 bool activate_on_show,
182 bool inspect_with_devtools, 109 bool inspect_with_devtools,
183 PopupChrome chrome,
184 Observer* observer); 110 Observer* observer);
185 111
186 // The area on the screen that the popup should be positioned relative to. 112 // The area on the screen that the popup should be positioned relative to.
187 gfx::Rect relative_to_; 113 gfx::Rect relative_to_;
188 114
189 // The contained host for the view. 115 // The contained host for the view.
190 scoped_ptr<ExtensionHost> extension_host_; 116 scoped_ptr<ExtensionHost> extension_host_;
191 117
192 // Flag used to indicate if the pop-up should be activated upon first display.
193 bool activate_on_show_;
194
195 // Flag used to indicate if the pop-up should open a devtools window once 118 // Flag used to indicate if the pop-up should open a devtools window once
196 // it is shown inspecting it. 119 // it is shown inspecting it.
197 bool inspect_with_devtools_; 120 bool inspect_with_devtools_;
198 121
199 // If false, ignore BrowserBubble::Delegate::BubbleLostFocus() calls. 122 // If false, ignore BrowserBubble::Delegate::BubbleLostFocus() calls.
200 bool close_on_lost_focus_; 123 bool close_on_lost_focus_;
201 124
202 // Whether the ExtensionPopup is current going about closing itself. 125 // Whether the ExtensionPopup is current going about closing itself.
203 bool closing_; 126 bool closing_;
204 127
205 NotificationRegistrar registrar_; 128 NotificationRegistrar registrar_;
206 129
207 // A separate widget and associated pieces to draw a border behind the 130 // A separate widget and associated pieces to draw a border behind the
208 // popup. This has to be a separate window in order to support transparency. 131 // popup. This has to be a separate window in order to support transparency.
209 // Layered windows can't contain native child windows, so we wouldn't be 132 // Layered windows can't contain native child windows, so we wouldn't be
210 // able to have the ExtensionView child. 133 // able to have the ExtensionView child.
211 views::Widget* border_widget_; 134 views::Widget* border_widget_;
212 BubbleBorder* border_; 135 BubbleBorder* border_;
213 views::View* border_view_; 136 views::View* border_view_;
214 137
215 // The type of chrome associated with the popup window.
216 PopupChrome popup_chrome_;
217
218 // The maximal size to which the popup may expand.
219 gfx::Size max_size_;
220
221 // The observer of this popup. 138 // The observer of this popup.
222 Observer* observer_; 139 Observer* observer_;
223 140
224 // A cached copy of the arrow-position for the bubble chrome. 141 // A cached copy of the arrow-position for the bubble chrome.
225 // If a black-border was requested, we still need this value to determine 142 // If a black-border was requested, we still need this value to determine
226 // the position of the pop-up in relation to |relative_to_|. 143 // the position of the pop-up in relation to |relative_to_|.
227 BubbleBorder::ArrowLocation anchor_position_; 144 BubbleBorder::ArrowLocation anchor_position_;
rafaelw 2011/02/10 20:22:00 remove
Jeff Timanus 2011/02/10 21:51:29 Done.
228 145
229 // ExtensionPopup's lifetime is managed via reference counting, but it does
230 // not expose the RefCounted interface. Instead, the lifetime is tied to
231 // this member variable.
232 class InternalRefCounter : public base::RefCounted<InternalRefCounter> {
233 };
234 InternalRefCounter* instance_lifetime_;
235
236 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup); 146 DISALLOW_COPY_AND_ASSIGN(ExtensionPopup);
237 }; 147 };
238 148
239 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_ 149 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_POPUP_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/browser_bubble_win.cc ('k') | chrome/browser/ui/views/extensions/extension_popup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698