| 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 initWithWindow:[self window] | 71 initWithWindow:[self window] |
| 71 delegate:self]); | 72 delegate:self]); |
| 72 } | 73 } |
| 73 return sheetController_; | 74 return sheetController_; |
| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 window_controller_.reset( | 199 window_controller_.reset( |
| 193 [[ShellWindowController alloc] initWithWindow:window.release()]); | 200 [[ShellWindowController alloc] initWithWindow:window.release()]); |
| 194 | 201 |
| 195 NSView* view = web_contents()->GetView()->GetNativeView(); | 202 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 196 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 203 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 197 | 204 |
| 198 InstallView(); | 205 InstallView(); |
| 199 | 206 |
| 200 [[window_controller_ window] setDelegate:window_controller_]; | 207 [[window_controller_ window] setDelegate:window_controller_]; |
| 201 [window_controller_ setShellWindow:this]; | 208 [window_controller_ setShellWindow:this]; |
| 209 |
| 210 extension_keybinding_registry_.reset( |
| 211 new ExtensionKeybindingRegistryCocoa(shell_window_->profile(), window, |
| 212 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY)); |
| 202 } | 213 } |
| 203 | 214 |
| 204 void ShellWindowCocoa::InstallView() { | 215 void ShellWindowCocoa::InstallView() { |
| 205 NSView* view = web_contents()->GetView()->GetNativeView(); | 216 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 206 if (has_frame_) { | 217 if (has_frame_) { |
| 207 [view setFrame:[[window() contentView] bounds]]; | 218 [view setFrame:[[window() contentView] bounds]]; |
| 208 [[window() contentView] addSubview:view]; | 219 [[window() contentView] addSubview:view]; |
| 209 } else { | 220 } else { |
| 210 // TODO(jeremya): find a cleaner way to send this information to the | 221 // TODO(jeremya): find a cleaner way to send this information to the |
| 211 // WebContentsViewCocoa view. | 222 // WebContentsViewCocoa view. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 } | 499 } |
| 489 | 500 |
| 490 void ShellWindowCocoa::WindowDidResize() { | 501 void ShellWindowCocoa::WindowDidResize() { |
| 491 shell_window_->SaveWindowPosition(); | 502 shell_window_->SaveWindowPosition(); |
| 492 } | 503 } |
| 493 | 504 |
| 494 void ShellWindowCocoa::WindowDidMove() { | 505 void ShellWindowCocoa::WindowDidMove() { |
| 495 shell_window_->SaveWindowPosition(); | 506 shell_window_->SaveWindowPosition(); |
| 496 } | 507 } |
| 497 | 508 |
| 509 bool ShellWindowCocoa::HandledByExtensionCommand(NSEvent* event) { |
| 510 return extension_keybinding_registry_->ProcessKeyEvent( |
| 511 content::NativeWebKeyboardEvent(event)); |
| 512 } |
| 513 |
| 498 ShellWindowCocoa::~ShellWindowCocoa() { | 514 ShellWindowCocoa::~ShellWindowCocoa() { |
| 499 } | 515 } |
| 500 | 516 |
| 501 ShellNSWindow* ShellWindowCocoa::window() const { | 517 ShellNSWindow* ShellWindowCocoa::window() const { |
| 502 NSWindow* window = [window_controller_ window]; | 518 NSWindow* window = [window_controller_ window]; |
| 503 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); | 519 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); |
| 504 return static_cast<ShellNSWindow*>(window); | 520 return static_cast<ShellNSWindow*>(window); |
| 505 } | 521 } |
| 506 | 522 |
| 507 // static | 523 // static |
| 508 NativeShellWindow* NativeShellWindow::Create( | 524 NativeShellWindow* NativeShellWindow::Create( |
| 509 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 525 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
| 510 return new ShellWindowCocoa(shell_window, params); | 526 return new ShellWindowCocoa(shell_window, params); |
| 511 } | 527 } |
| OLD | NEW |