| OLD | NEW |
| 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 "chrome/browser/debugger/devtools_window.h" | 9 #include "chrome/browser/debugger/devtools_window.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 10 #include "chrome/browser/extensions/extension_host.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // NOTE: This takes ownership of |host|. | 41 // NOTE: This takes ownership of |host|. |
| 42 - (id)initWithHost:(ExtensionHost*)host | 42 - (id)initWithHost:(ExtensionHost*)host |
| 43 parentWindow:(NSWindow*)parentWindow | 43 parentWindow:(NSWindow*)parentWindow |
| 44 anchoredAt:(NSPoint)anchoredAt | 44 anchoredAt:(NSPoint)anchoredAt |
| 45 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation | 45 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation |
| 46 devMode:(BOOL)devMode; | 46 devMode:(BOOL)devMode; |
| 47 | 47 |
| 48 // Called when the extension's hosted NSView has been resized. | 48 // Called when the extension's hosted NSView has been resized. |
| 49 - (void)extensionViewFrameChanged; | 49 - (void)extensionViewFrameChanged; |
| 50 | 50 |
| 51 // Called when the extension's preferred size changes. | 51 // Called when the extension's size changes. |
| 52 - (void)onPreferredSizeChanged:(NSSize)newSize; | 52 - (void)onSizeChanged:(NSSize)newSize; |
| 53 | 53 |
| 54 // Called when the extension view is shown. | 54 // Called when the extension view is shown. |
| 55 - (void)onViewDidShow; | 55 - (void)onViewDidShow; |
| 56 @end | 56 @end |
| 57 | 57 |
| 58 class ExtensionPopupContainer : public ExtensionViewMac::Container { | 58 class ExtensionPopupContainer : public ExtensionViewMac::Container { |
| 59 public: | 59 public: |
| 60 explicit ExtensionPopupContainer(ExtensionPopupController* controller) | 60 explicit ExtensionPopupContainer(ExtensionPopupController* controller) |
| 61 : controller_(controller) { | 61 : controller_(controller) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void OnExtensionPreferredSizeChanged( | 64 virtual void OnExtensionSizeChanged( |
| 65 ExtensionViewMac* view, | 65 ExtensionViewMac* view, |
| 66 const gfx::Size& new_size) OVERRIDE { | 66 const gfx::Size& new_size) OVERRIDE { |
| 67 [controller_ onPreferredSizeChanged: | 67 [controller_ onSizeChanged: |
| 68 NSMakeSize(new_size.width(), new_size.height())]; | 68 NSMakeSize(new_size.width(), new_size.height())]; |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual void OnExtensionViewDidShow(ExtensionViewMac* view) OVERRIDE { | 71 virtual void OnExtensionViewDidShow(ExtensionViewMac* view) OVERRIDE { |
| 72 [controller_ onViewDidShow]; | 72 [controller_ onViewDidShow]; |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 ExtensionPopupController* controller_; // Weak; owns this. | 76 ExtensionPopupController* controller_; // Weak; owns this. |
| 77 }; | 77 }; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 293 } |
| 294 | 294 |
| 295 // A NSViewFrameDidChangeNotification won't be sent until the extension view | 295 // A NSViewFrameDidChangeNotification won't be sent until the extension view |
| 296 // content is loaded. The window is hidden on init, so show it the first time | 296 // content is loaded. The window is hidden on init, so show it the first time |
| 297 // the notification is fired (and consequently the view contents have loaded). | 297 // the notification is fired (and consequently the view contents have loaded). |
| 298 if (![window isVisible]) { | 298 if (![window isVisible]) { |
| 299 [self showWindow:self]; | 299 [self showWindow:self]; |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| 303 - (void)onPreferredSizeChanged:(NSSize)newSize { | 303 - (void)onSizeChanged:(NSSize)newSize { |
| 304 // When we update the size, the window will become visible. Stay hidden until | 304 // When we update the size, the window will become visible. Stay hidden until |
| 305 // the host is loaded. | 305 // the host is loaded. |
| 306 pendingPreferredSize_ = newSize; | 306 pendingSize_ = newSize; |
| 307 if (!host_->did_stop_loading()) | 307 if (!host_->did_stop_loading()) |
| 308 return; | 308 return; |
| 309 | 309 |
| 310 // No need to use CA here, our caller calls us repeatedly to animate the | 310 // No need to use CA here, our caller calls us repeatedly to animate the |
| 311 // resizing. | 311 // resizing. |
| 312 NSRect frame = [extensionView_ frame]; | 312 NSRect frame = [extensionView_ frame]; |
| 313 frame.size = newSize; | 313 frame.size = newSize; |
| 314 | 314 |
| 315 // |new_size| is in pixels. Convert to view units. | 315 // |new_size| is in pixels. Convert to view units. |
| 316 frame.size = [extensionView_ convertSize:frame.size fromView:nil]; | 316 frame.size = [extensionView_ convertSize:frame.size fromView:nil]; |
| 317 | 317 |
| 318 // On first display of some extensions, this function is called with zero | |
| 319 // width after the correct size has been set. Bail if zero is seen, assuming | |
| 320 // that an extension's view doesn't want any dimensions to ever be zero. | |
| 321 // http://crbug.com/112810 - Verify this assumption and look into WebCore's | |
| 322 // |contentsPreferredWidth| to see why this is occurring. | |
| 323 if (NSIsEmptyRect(frame)) | |
| 324 return; | |
| 325 | |
| 326 [extensionView_ setFrame:frame]; | 318 [extensionView_ setFrame:frame]; |
| 327 [extensionView_ setNeedsDisplay:YES]; | 319 [extensionView_ setNeedsDisplay:YES]; |
| 328 } | 320 } |
| 329 | 321 |
| 330 - (void)onViewDidShow { | 322 - (void)onViewDidShow { |
| 331 [self onPreferredSizeChanged:pendingPreferredSize_]; | 323 [self onSizeChanged:pendingSize_]; |
| 332 } | 324 } |
| 333 | 325 |
| 334 - (void)windowDidResize:(NSNotification*)notification { | 326 - (void)windowDidResize:(NSNotification*)notification { |
| 335 // Let the extension view know, so that it can tell plugins. | 327 // Let the extension view know, so that it can tell plugins. |
| 336 if (host_->view()) | 328 if (host_->view()) |
| 337 host_->view()->WindowFrameChanged(); | 329 host_->view()->WindowFrameChanged(); |
| 338 } | 330 } |
| 339 | 331 |
| 340 - (void)windowDidMove:(NSNotification*)notification { | 332 - (void)windowDidMove:(NSNotification*)notification { |
| 341 // Let the extension view know, so that it can tell plugins. | 333 // Let the extension view know, so that it can tell plugins. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 354 return minSize; | 346 return minSize; |
| 355 } | 347 } |
| 356 | 348 |
| 357 // Private (TestingAPI) | 349 // Private (TestingAPI) |
| 358 + (NSSize)maxPopupSize { | 350 + (NSSize)maxPopupSize { |
| 359 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 351 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
| 360 return maxSize; | 352 return maxSize; |
| 361 } | 353 } |
| 362 | 354 |
| 363 @end | 355 @end |
| OLD | NEW |