| 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 #include "chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/cocoa/browser_window_utils.h" | 10 #include "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 11 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 11 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 12 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
| 12 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 13 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 14 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 15 #include "content/public/browser/native_web_keyboard_event.h" | 16 #include "content/public/browser/native_web_keyboard_event.h" |
| 16 #include "content/public/browser/render_widget_host_view.h" | 17 #include "content/public/browser/render_widget_host_view.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
| 19 | 20 |
| 20 @interface NSWindow (NSPrivateApis) | 21 @interface NSWindow (NSPrivateApis) |
| 21 - (void)setBottomCornerRounded:(BOOL)rounded; | 22 - (void)setBottomCornerRounded:(BOOL)rounded; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 71 } |
| 71 | 72 |
| 72 - (BOOL)canAttachConstrainedWindow { | 73 - (BOOL)canAttachConstrainedWindow { |
| 73 return YES; | 74 return YES; |
| 74 } | 75 } |
| 75 | 76 |
| 76 - (void)executeCommand:(int)command { | 77 - (void)executeCommand:(int)command { |
| 77 // No-op, swallow the event. | 78 // No-op, swallow the event. |
| 78 } | 79 } |
| 79 | 80 |
| 81 - (BOOL)handledByExtensionCommand:(NSEvent*)event { |
| 82 if (shellWindow_) |
| 83 return shellWindow_->HandledByExtensionCommand(event); |
| 84 return NO; |
| 85 } |
| 86 |
| 80 @end | 87 @end |
| 81 | 88 |
| 82 @interface ShellNSWindow : ChromeEventProcessingWindow | 89 @interface ShellNSWindow : ChromeEventProcessingWindow |
| 83 | 90 |
| 84 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; | 91 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; |
| 85 | 92 |
| 86 @end | 93 @end |
| 87 | 94 |
| 88 // This is really a method on NSGrayFrame, so it should only be called on the | 95 // This is really a method on NSGrayFrame, so it should only be called on the |
| 89 // view passed into -[NSWindow drawCustomFrameRect:forView:]. | 96 // view passed into -[NSWindow drawCustomFrameRect:forView:]. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 window_controller_.reset( | 170 window_controller_.reset( |
| 164 [[ShellWindowController alloc] initWithWindow:window.release()]); | 171 [[ShellWindowController alloc] initWithWindow:window.release()]); |
| 165 | 172 |
| 166 NSView* view = web_contents()->GetView()->GetNativeView(); | 173 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 167 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 174 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 168 | 175 |
| 169 InstallView(); | 176 InstallView(); |
| 170 | 177 |
| 171 [[window_controller_ window] setDelegate:window_controller_]; | 178 [[window_controller_ window] setDelegate:window_controller_]; |
| 172 [window_controller_ setShellWindow:this]; | 179 [window_controller_ setShellWindow:this]; |
| 180 |
| 181 extension_keybinding_registry_.reset( |
| 182 new ExtensionKeybindingRegistryCocoa(shell_window_->profile(), window, |
| 183 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY)); |
| 173 } | 184 } |
| 174 | 185 |
| 175 void ShellWindowCocoa::InstallView() { | 186 void ShellWindowCocoa::InstallView() { |
| 176 NSView* view = web_contents()->GetView()->GetNativeView(); | 187 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 177 if (has_frame_) { | 188 if (has_frame_) { |
| 178 [view setFrame:[[window() contentView] bounds]]; | 189 [view setFrame:[[window() contentView] bounds]]; |
| 179 [[window() contentView] addSubview:view]; | 190 [[window() contentView] addSubview:view]; |
| 180 } else { | 191 } else { |
| 181 // TODO(jeremya): find a cleaner way to send this information to the | 192 // TODO(jeremya): find a cleaner way to send this information to the |
| 182 // WebContentsViewCocoa view. | 193 // WebContentsViewCocoa view. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 // lose key window status. | 456 // lose key window status. |
| 446 if ([NSApp isActive] && ([NSApp keyWindow] == window())) | 457 if ([NSApp isActive] && ([NSApp keyWindow] == window())) |
| 447 return; | 458 return; |
| 448 | 459 |
| 449 content::RenderWidgetHostView* rwhv = | 460 content::RenderWidgetHostView* rwhv = |
| 450 web_contents()->GetRenderWidgetHostView(); | 461 web_contents()->GetRenderWidgetHostView(); |
| 451 if (rwhv) | 462 if (rwhv) |
| 452 rwhv->SetActive(false); | 463 rwhv->SetActive(false); |
| 453 } | 464 } |
| 454 | 465 |
| 466 bool ShellWindowCocoa::HandledByExtensionCommand(NSEvent* event) { |
| 467 return extension_keybinding_registry_->ProcessKeyEvent( |
| 468 content::NativeWebKeyboardEvent(event)); |
| 469 } |
| 470 |
| 455 ShellWindowCocoa::~ShellWindowCocoa() { | 471 ShellWindowCocoa::~ShellWindowCocoa() { |
| 456 } | 472 } |
| 457 | 473 |
| 458 ShellNSWindow* ShellWindowCocoa::window() const { | 474 ShellNSWindow* ShellWindowCocoa::window() const { |
| 459 NSWindow* window = [window_controller_ window]; | 475 NSWindow* window = [window_controller_ window]; |
| 460 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); | 476 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); |
| 461 return static_cast<ShellNSWindow*>(window); | 477 return static_cast<ShellNSWindow*>(window); |
| 462 } | 478 } |
| 463 | 479 |
| 464 // static | 480 // static |
| 465 NativeShellWindow* NativeShellWindow::Create( | 481 NativeShellWindow* NativeShellWindow::Create( |
| 466 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 482 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
| 467 return new ShellWindowCocoa(shell_window, params); | 483 return new ShellWindowCocoa(shell_window, params); |
| 468 } | 484 } |
| OLD | NEW |