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/native_app_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/extensions/native_app_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_keybinding_registry_cocoa .h" |
13 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 13 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
15 #include "content/public/browser/native_web_keyboard_event.h" | 15 #include "content/public/browser/native_web_keyboard_event.h" |
16 #include "content/public/browser/notification_source.h" | |
17 #include "content/public/browser/notification_types.h" | |
16 #include "content/public/browser/render_widget_host_view.h" | 18 #include "content/public/browser/render_widget_host_view.h" |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_contents_view.h" | 20 #include "content/public/browser/web_contents_view.h" |
19 #include "third_party/skia/include/core/SkRegion.h" | 21 #include "third_party/skia/include/core/SkRegion.h" |
20 | 22 |
21 @interface NSWindow (NSPrivateApis) | 23 @interface NSWindow (NSPrivateApis) |
22 - (void)setBottomCornerRounded:(BOOL)rounded; | 24 - (void)setBottomCornerRounded:(BOOL)rounded; |
23 @end | 25 @end |
24 | 26 |
25 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 27 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 InstallView(); | 257 InstallView(); |
256 | 258 |
257 [[window_controller_ window] setDelegate:window_controller_]; | 259 [[window_controller_ window] setDelegate:window_controller_]; |
258 [window_controller_ setAppWindow:this]; | 260 [window_controller_ setAppWindow:this]; |
259 | 261 |
260 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa( | 262 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa( |
261 shell_window_->profile(), | 263 shell_window_->profile(), |
262 window, | 264 window, |
263 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 265 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
264 shell_window)); | 266 shell_window)); |
267 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | |
268 content::Source<content::NavigationController>( | |
269 &web_contents()->GetController())); | |
265 } | 270 } |
266 | 271 |
267 void NativeAppWindowCocoa::InstallView() { | 272 void NativeAppWindowCocoa::InstallView() { |
268 NSView* view = web_contents()->GetView()->GetNativeView(); | 273 NSView* view = web_contents()->GetView()->GetNativeView(); |
269 if (has_frame_) { | 274 if (has_frame_) { |
270 [view setFrame:[[window() contentView] bounds]]; | 275 [view setFrame:[[window() contentView] bounds]]; |
271 [[window() contentView] addSubview:view]; | 276 [[window() contentView] addSubview:view]; |
272 if (!max_size_.IsEmpty() && min_size_ == max_size_) { | 277 if (!max_size_.IsEmpty() && min_size_ == max_size_) { |
273 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; | 278 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; |
274 [window() setShowsResizeIndicator:NO]; | 279 [window() setShowsResizeIndicator:NO]; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 scoped_nsobject<NSView> controlRegion( | 636 scoped_nsobject<NSView> controlRegion( |
632 [[ControlRegionView alloc] initWithAppWindow:this]); | 637 [[ControlRegionView alloc] initWithAppWindow:this]); |
633 [controlRegion setFrame:NSMakeRect(iter->x(), | 638 [controlRegion setFrame:NSMakeRect(iter->x(), |
634 webViewHeight - iter->bottom(), | 639 webViewHeight - iter->bottom(), |
635 iter->width(), | 640 iter->width(), |
636 iter->height())]; | 641 iter->height())]; |
637 [webView addSubview:controlRegion]; | 642 [webView addSubview:controlRegion]; |
638 } | 643 } |
639 } | 644 } |
640 | 645 |
646 void NativeAppWindowCocoa::Observe(int type, | |
647 const content::NotificationSource& source, | |
648 const content::NotificationDetails& details) { | |
Avi (use Gerrit)
2013/01/14 17:10:03
bad indentation
| |
649 if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) { | |
650 if (content::RenderWidgetHostView* rwhv = | |
651 web_contents()->GetRenderWidgetHostView()) { | |
652 rwhv->Focus(); | |
Avi (use Gerrit)
2013/01/14 17:10:03
I'm not clear on why this wouldn't be working. Is
jeremya
2013/01/15 05:49:52
The bug happens even for non-frameless windows.
I
| |
653 } | |
654 return; | |
655 } | |
656 NOTREACHED(); | |
657 } | |
658 | |
641 void NativeAppWindowCocoa::FlashFrame(bool flash) { | 659 void NativeAppWindowCocoa::FlashFrame(bool flash) { |
642 if (flash) { | 660 if (flash) { |
643 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; | 661 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; |
644 } else { | 662 } else { |
645 [NSApp cancelUserAttentionRequest:attention_request_id_]; | 663 [NSApp cancelUserAttentionRequest:attention_request_id_]; |
646 attention_request_id_ = 0; | 664 attention_request_id_ = 0; |
647 } | 665 } |
648 } | 666 } |
649 | 667 |
650 bool NativeAppWindowCocoa::IsAlwaysOnTop() const { | 668 bool NativeAppWindowCocoa::IsAlwaysOnTop() const { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); | 760 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); |
743 return static_cast<ShellNSWindow*>(window); | 761 return static_cast<ShellNSWindow*>(window); |
744 } | 762 } |
745 | 763 |
746 // static | 764 // static |
747 NativeAppWindow* NativeAppWindow::Create( | 765 NativeAppWindow* NativeAppWindow::Create( |
748 ShellWindow* shell_window, | 766 ShellWindow* shell_window, |
749 const ShellWindow::CreateParams& params) { | 767 const ShellWindow::CreateParams& params) { |
750 return new NativeAppWindowCocoa(shell_window, params); | 768 return new NativeAppWindowCocoa(shell_window, params); |
751 } | 769 } |
OLD | NEW |