| 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 "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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 devMode:(BOOL)devMode; | 53 devMode:(BOOL)devMode; |
| 54 | 54 |
| 55 // Called when the extension's hosted NSView has been resized. | 55 // Called when the extension's hosted NSView has been resized. |
| 56 - (void)extensionViewFrameChanged; | 56 - (void)extensionViewFrameChanged; |
| 57 | 57 |
| 58 // Called when the extension's size changes. | 58 // Called when the extension's size changes. |
| 59 - (void)onSizeChanged:(NSSize)newSize; | 59 - (void)onSizeChanged:(NSSize)newSize; |
| 60 | 60 |
| 61 // Called when the extension view is shown. | 61 // Called when the extension view is shown. |
| 62 - (void)onViewDidShow; | 62 - (void)onViewDidShow; |
| 63 |
| 64 // Called when the window moves or resizes. Notifies the extension. |
| 65 - (void)onWindowChanged; |
| 66 |
| 63 @end | 67 @end |
| 64 | 68 |
| 65 class ExtensionPopupContainer : public ExtensionViewMac::Container { | 69 class ExtensionPopupContainer : public ExtensionViewMac::Container { |
| 66 public: | 70 public: |
| 67 explicit ExtensionPopupContainer(ExtensionPopupController* controller) | 71 explicit ExtensionPopupContainer(ExtensionPopupController* controller) |
| 68 : controller_(controller) { | 72 : controller_(controller) { |
| 69 } | 73 } |
| 70 | 74 |
| 71 virtual void OnExtensionSizeChanged( | 75 virtual void OnExtensionSizeChanged( |
| 72 ExtensionViewMac* view, | 76 ExtensionViewMac* view, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if ((self = [super initWithWindow:window | 168 if ((self = [super initWithWindow:window |
| 165 parentWindow:parentWindow | 169 parentWindow:parentWindow |
| 166 anchoredAt:anchoredAt])) { | 170 anchoredAt:anchoredAt])) { |
| 167 host_.reset(host); | 171 host_.reset(host); |
| 168 beingInspected_ = devMode; | 172 beingInspected_ = devMode; |
| 169 ignoreWindowDidResignKey_ = NO; | 173 ignoreWindowDidResignKey_ = NO; |
| 170 | 174 |
| 171 InfoBubbleView* view = self.bubble; | 175 InfoBubbleView* view = self.bubble; |
| 172 [view setArrowLocation:arrowLocation]; | 176 [view setArrowLocation:arrowLocation]; |
| 173 | 177 |
| 174 extensionView_ = host->view()->native_view(); | 178 extensionView_ = host->view()->GetNativeView(); |
| 175 container_.reset(new ExtensionPopupContainer(self)); | 179 container_.reset(new ExtensionPopupContainer(self)); |
| 176 host->view()->set_container(container_.get()); | 180 static_cast<ExtensionViewMac*>(host->view()) |
| 181 ->set_container(container_.get()); |
| 177 | 182 |
| 178 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 183 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 179 [center addObserver:self | 184 [center addObserver:self |
| 180 selector:@selector(extensionViewFrameChanged) | 185 selector:@selector(extensionViewFrameChanged) |
| 181 name:NSViewFrameDidChangeNotification | 186 name:NSViewFrameDidChangeNotification |
| 182 object:extensionView_]; | 187 object:extensionView_]; |
| 183 | 188 |
| 184 [view addSubview:extensionView_]; | 189 [view addSubview:extensionView_]; |
| 185 | 190 |
| 186 notificationBridge_.reset(new DevtoolsNotificationBridge(self)); | 191 notificationBridge_.reset(new DevtoolsNotificationBridge(self)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 217 } | 222 } |
| 218 } | 223 } |
| 219 [super close]; | 224 [super close]; |
| 220 } | 225 } |
| 221 | 226 |
| 222 - (void)windowWillClose:(NSNotification *)notification { | 227 - (void)windowWillClose:(NSNotification *)notification { |
| 223 [super windowWillClose:notification]; | 228 [super windowWillClose:notification]; |
| 224 if (gPopup == self) | 229 if (gPopup == self) |
| 225 gPopup = nil; | 230 gPopup = nil; |
| 226 if (host_->view()) | 231 if (host_->view()) |
| 227 host_->view()->set_container(NULL); | 232 static_cast<ExtensionViewMac*>(host_->view())->set_container(NULL); |
| 228 host_.reset(); | 233 host_.reset(); |
| 229 } | 234 } |
| 230 | 235 |
| 231 - (void)windowDidResignKey:(NSNotification*)notification { | 236 - (void)windowDidResignKey:(NSNotification*)notification { |
| 232 // |windowWillClose:| could have already been called. http://crbug.com/279505 | 237 // |windowWillClose:| could have already been called. http://crbug.com/279505 |
| 233 if (host_) { | 238 if (host_) { |
| 234 // When a modal dialog is opened on top of the popup and when it's closed, | 239 // When a modal dialog is opened on top of the popup and when it's closed, |
| 235 // it steals key-ness from the popup. Don't close the popup when this | 240 // it steals key-ness from the popup. Don't close the popup when this |
| 236 // happens. There's an extra windowDidResignKey: notification after the | 241 // happens. There's an extra windowDidResignKey: notification after the |
| 237 // modal dialog closes that should also be ignored. | 242 // modal dialog closes that should also be ignored. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 frame.size = [extensionView_ convertSize:frame.size fromView:nil]; | 395 frame.size = [extensionView_ convertSize:frame.size fromView:nil]; |
| 391 | 396 |
| 392 [extensionView_ setFrame:frame]; | 397 [extensionView_ setFrame:frame]; |
| 393 [extensionView_ setNeedsDisplay:YES]; | 398 [extensionView_ setNeedsDisplay:YES]; |
| 394 } | 399 } |
| 395 | 400 |
| 396 - (void)onViewDidShow { | 401 - (void)onViewDidShow { |
| 397 [self onSizeChanged:pendingSize_]; | 402 [self onSizeChanged:pendingSize_]; |
| 398 } | 403 } |
| 399 | 404 |
| 405 - (void)onWindowChanged { |
| 406 ExtensionViewMac* extensionView = |
| 407 static_cast<ExtensionViewMac*>(host_->view()); |
| 408 // Let the extension view know, so that it can tell plugins. |
| 409 if (extensionView) |
| 410 extensionView->WindowFrameChanged(); |
| 411 } |
| 412 |
| 400 - (void)windowDidResize:(NSNotification*)notification { | 413 - (void)windowDidResize:(NSNotification*)notification { |
| 401 // Let the extension view know, so that it can tell plugins. | 414 [self onWindowChanged]; |
| 402 if (host_->view()) | |
| 403 host_->view()->WindowFrameChanged(); | |
| 404 } | 415 } |
| 405 | 416 |
| 406 - (void)windowDidMove:(NSNotification*)notification { | 417 - (void)windowDidMove:(NSNotification*)notification { |
| 407 // Let the extension view know, so that it can tell plugins. | 418 [self onWindowChanged]; |
| 408 if (host_->view()) | |
| 409 host_->view()->WindowFrameChanged(); | |
| 410 } | 419 } |
| 411 | 420 |
| 412 // Private (TestingAPI) | 421 // Private (TestingAPI) |
| 413 - (NSView*)view { | 422 - (NSView*)view { |
| 414 return extensionView_; | 423 return extensionView_; |
| 415 } | 424 } |
| 416 | 425 |
| 417 // Private (TestingAPI) | 426 // Private (TestingAPI) |
| 418 + (NSSize)minPopupSize { | 427 + (NSSize)minPopupSize { |
| 419 NSSize minSize = {ExtensionViewMac::kMinWidth, ExtensionViewMac::kMinHeight}; | 428 NSSize minSize = {ExtensionViewMac::kMinWidth, ExtensionViewMac::kMinHeight}; |
| 420 return minSize; | 429 return minSize; |
| 421 } | 430 } |
| 422 | 431 |
| 423 // Private (TestingAPI) | 432 // Private (TestingAPI) |
| 424 + (NSSize)maxPopupSize { | 433 + (NSSize)maxPopupSize { |
| 425 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; | 434 NSSize maxSize = {ExtensionViewMac::kMaxWidth, ExtensionViewMac::kMaxHeight}; |
| 426 return maxSize; | 435 return maxSize; |
| 427 } | 436 } |
| 428 | 437 |
| 429 @end | 438 @end |
| OLD | NEW |