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