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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_popup_controller.mm

Issue 1105713002: [Extension Toolbar] Slide out overflowed actions for popups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 5 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 10 matching lines...) Expand all
21 #include "components/web_modal/popup_manager.h" 21 #include "components/web_modal/popup_manager.h"
22 #include "content/public/browser/devtools_agent_host.h" 22 #include "content/public/browser/devtools_agent_host.h"
23 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_registrar.h" 24 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_source.h" 25 #include "content/public/browser/notification_source.h"
26 #include "ui/base/cocoa/window_size_constants.h" 26 #include "ui/base/cocoa/window_size_constants.h"
27 27
28 using content::BrowserContext; 28 using content::BrowserContext;
29 using content::RenderViewHost; 29 using content::RenderViewHost;
30 using content::WebContents; 30 using content::WebContents;
31 using extensions::ExtensionViewHost;
31 32
32 namespace { 33 namespace {
33 // The duration for any animations that might be invoked by this controller. 34 // The duration for any animations that might be invoked by this controller.
34 const NSTimeInterval kAnimationDuration = 0.2; 35 const NSTimeInterval kAnimationDuration = 0.2;
35 36
36 // There should only be one extension popup showing at one time. Keep a 37 // There should only be one extension popup showing at one time. Keep a
37 // reference to it here. 38 // reference to it here.
38 static ExtensionPopupController* gPopup; 39 static ExtensionPopupController* gPopup;
39 40
40 // Given a value and a rage, clamp the value into the range. 41 // Given a value and a rage, clamp the value into the range.
41 CGFloat Clamp(CGFloat value, CGFloat min, CGFloat max) { 42 CGFloat Clamp(CGFloat value, CGFloat min, CGFloat max) {
42 return std::max(min, std::min(max, value)); 43 return std::max(min, std::min(max, value));
43 } 44 }
44 45
45 } // namespace 46 } // namespace
46 47
47 @interface ExtensionPopupController (Private) 48 @interface ExtensionPopupController (Private)
48 // Callers should be using the public static method for initialization. 49 // Callers should be using the public static method for initialization.
49 - (id)initWithParentWindow:(NSWindow*)parentWindow 50 - (id)initWithParentWindow:(NSWindow*)parentWindow
50 anchoredAt:(NSPoint)anchoredAt 51 anchoredAt:(NSPoint)anchoredAt
51 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation 52 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation
52 devMode:(BOOL)devMode; 53 devMode:(BOOL)devMode;
53 54
54 // Set the ExtensionViewHost, taking ownership. 55 // Set the ExtensionViewHost, taking ownership.
55 - (void)setExtensionViewHost:(scoped_ptr<extensions::ExtensionViewHost>)host; 56 - (void)setExtensionViewHost:(scoped_ptr<ExtensionViewHost>)host;
56 57
57 // Called when the extension's hosted NSView has been resized. 58 // Called when the extension's hosted NSView has been resized.
58 - (void)extensionViewFrameChanged; 59 - (void)extensionViewFrameChanged;
59 60
60 // Called when the extension's size changes. 61 // Called when the extension's size changes.
61 - (void)onSizeChanged:(NSSize)newSize; 62 - (void)onSizeChanged:(NSSize)newSize;
62 63
63 // Called when the extension view is shown. 64 // Called when the extension view is shown.
64 - (void)onViewDidShow; 65 - (void)onViewDidShow;
65 66
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 withObject:nil 119 withObject:nil
119 afterDelay:0.0]; 120 afterDelay:0.0];
120 } 121 }
121 } 122 }
122 123
123 void Observe(int type, 124 void Observe(int type,
124 const content::NotificationSource& source, 125 const content::NotificationSource& source,
125 const content::NotificationDetails& details) override { 126 const content::NotificationDetails& details) override {
126 switch (type) { 127 switch (type) {
127 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD: { 128 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD: {
128 if (content::Details<extensions::ExtensionViewHost>( 129 if (content::Details<ExtensionViewHost>(
129 [controller_ extensionViewHost]) == details) { 130 [controller_ extensionViewHost]) == details) {
130 [controller_ showDevTools]; 131 [controller_ showDevTools];
131 } 132 }
132 break; 133 break;
133 } 134 }
134 default: { 135 default: {
135 NOTREACHED() << "Received unexpected notification"; 136 NOTREACHED() << "Received unexpected notification";
136 break; 137 break;
137 } 138 }
138 }; 139 };
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 229 }
229 } 230 }
230 if (!beingInspected_) 231 if (!beingInspected_)
231 [super windowDidResignKey:notification]; 232 [super windowDidResignKey:notification];
232 } 233 }
233 234
234 - (BOOL)isClosing { 235 - (BOOL)isClosing {
235 return [static_cast<InfoBubbleWindow*>([self window]) isClosing]; 236 return [static_cast<InfoBubbleWindow*>([self window]) isClosing];
236 } 237 }
237 238
238 - (extensions::ExtensionViewHost*)extensionViewHost { 239 - (ExtensionViewHost*)extensionViewHost {
239 return host_.get(); 240 return host_.get();
240 } 241 }
241 242
242 - (void)setBeingInspected:(BOOL)beingInspected { 243 - (void)setBeingInspected:(BOOL)beingInspected {
243 beingInspected_ = beingInspected; 244 beingInspected_ = beingInspected;
244 } 245 }
245 246
246 + (ExtensionPopupController*)showURL:(GURL)url 247 + (ExtensionPopupController*)host:(scoped_ptr<ExtensionViewHost>)host
247 inBrowser:(Browser*)browser 248 inBrowser:(Browser*)browser
248 anchoredAt:(NSPoint)anchoredAt 249 anchoredAt:(NSPoint)anchoredAt
249 arrowLocation:(info_bubble::BubbleArrowLocation) 250 arrowLocation:(info_bubble::BubbleArrowLocation)
250 arrowLocation 251 arrowLocation
251 devMode:(BOOL)devMode { 252 devMode:(BOOL)devMode {
252 DCHECK([NSThread isMainThread]); 253 DCHECK([NSThread isMainThread]);
253 DCHECK(browser); 254 DCHECK(browser);
254 if (!browser) 255 DCHECK(host);
255 return nil;
256 256
257 // If we click the browser/page action again, we should close the popup. 257 if (gPopup)
258 // Make Mac behavior the same with Windows and others.
259 if (gPopup) {
260 std::string extension_id = url.host();
261 std::string old_extension_id = [gPopup extensionViewHost]->extension_id();
262 [gPopup close]; // Starts the animation to fade out the popup. 258 [gPopup close]; // Starts the animation to fade out the popup.
263 if (extension_id == old_extension_id)
264 return nil;
265 }
266 259
267 // Create the popup first. This establishes an initially hidden NSWindow so 260 // Create the popup first. This establishes an initially hidden NSWindow so
268 // that the renderer is able to gather correct screen metrics for the initial 261 // that the renderer is able to gather correct screen metrics for the initial
269 // paint. 262 // paint.
270 gPopup = [[ExtensionPopupController alloc] 263 gPopup = [[ExtensionPopupController alloc]
271 initWithParentWindow:browser->window()->GetNativeWindow() 264 initWithParentWindow:browser->window()->GetNativeWindow()
272 anchoredAt:anchoredAt 265 anchoredAt:anchoredAt
273 arrowLocation:arrowLocation 266 arrowLocation:arrowLocation
274 devMode:devMode]; 267 devMode:devMode];
275
276 scoped_ptr<extensions::ExtensionViewHost> host(
277 extensions::ExtensionViewHostFactory::CreatePopupHost(url, browser));
278 DCHECK(host);
279 [gPopup setExtensionViewHost:host.Pass()]; 268 [gPopup setExtensionViewHost:host.Pass()];
280 return gPopup; 269 return gPopup;
281 } 270 }
282 271
283 + (ExtensionPopupController*)popup { 272 + (ExtensionPopupController*)popup {
284 return gPopup; 273 return gPopup;
285 } 274 }
286 275
287 - (void)setExtensionViewHost:(scoped_ptr<extensions::ExtensionViewHost>)host { 276 - (void)setExtensionViewHost:(scoped_ptr<ExtensionViewHost>)host {
288 DCHECK(!host_); 277 DCHECK(!host_);
289 DCHECK(host); 278 DCHECK(host);
290 host_.swap(host); 279 host_.swap(host);
291 280
292 extensionId_ = host_->extension_id(); 281 extensionId_ = host_->extension_id();
293 container_.reset(new ExtensionPopupContainer(self)); 282 container_.reset(new ExtensionPopupContainer(self));
294 ExtensionViewMac* hostView = static_cast<ExtensionViewMac*>(host_->view()); 283 ExtensionViewMac* hostView = static_cast<ExtensionViewMac*>(host_->view());
295 hostView->set_container(container_.get()); 284 hostView->set_container(container_.get());
296 hostView->CreateWidgetHostViewIn([self bubble]); 285 hostView->CreateWidgetHostViewIn([self bubble]);
297 286
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return minSize; 421 return minSize;
433 } 422 }
434 423
435 // Private (TestingAPI) 424 // Private (TestingAPI)
436 + (NSSize)maxPopupSize { 425 + (NSSize)maxPopupSize {
437 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; 426 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight};
438 return maxSize; 427 return maxSize;
439 } 428 }
440 429
441 @end 430 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698