Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "extensions/shell/browser/shell_native_app_window_mac.h" | |
|
tapted
2014/12/17 08:05:16
nit: import
Yoyo Zhou
2014/12/18 02:38:34
Done.
| |
| 6 | |
| 7 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/strings/sys_string_conversions.h" | |
| 11 #include "content/public/browser/web_contents.h" | |
| 12 | |
| 13 @implementation ShellNativeAppWindowController | |
| 14 | |
| 15 @synthesize appWindow = appWindow_; | |
| 16 | |
| 17 - (void)windowWillClose:(NSNotification*)notification { | |
| 18 if (appWindow_) | |
| 19 appWindow_->WindowWillClose(); | |
| 20 } | |
| 21 | |
| 22 @end | |
| 23 | |
| 24 // TODO(yoz): Do we need to handle commands (keyboard shortcuts)? | |
| 25 // Do we need need ChromeEventProcessingWindow or UnderlayOpenGLHostingWindow? | |
| 26 @interface ShellNSWindow : NSWindow | |
| 27 @end | |
| 28 | |
| 29 @implementation ShellNSWindow | |
| 30 | |
| 31 - (BOOL)_isTitleHidden { | |
| 32 return YES; | |
| 33 } | |
| 34 | |
| 35 @end | |
| 36 | |
| 37 namespace extensions { | |
| 38 | |
| 39 ShellNativeAppWindowMac::ShellNativeAppWindowMac( | |
| 40 AppWindow* app_window, | |
| 41 const AppWindow::CreateParams& params) | |
| 42 : ShellNativeAppWindow(app_window, params) { | |
| 43 base::scoped_nsobject<NSWindow> shell_window; | |
| 44 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask; | |
| 45 | |
| 46 NSRect cocoa_bounds = params.GetInitialWindowBounds(gfx::Insets()).ToCGRect(); | |
| 47 // TODO(yoz): Flip coordinates here? | |
|
tapted
2014/12/17 08:05:16
you could use gfx::ScreenRectToNSRect from #import
Yoyo Zhou
2014/12/18 02:38:34
Done.
| |
| 48 | |
| 49 shell_window.reset( | |
| 50 [[ShellNSWindow alloc] initWithContentRect:cocoa_bounds | |
| 51 styleMask:style_mask | |
| 52 backing:NSBackingStoreBuffered | |
| 53 defer:NO]); | |
| 54 | |
| 55 window_controller_.reset([[ShellNativeAppWindowController alloc] | |
| 56 initWithWindow:shell_window.release()]); | |
|
tapted
2014/12/17 08:05:16
The release() looks a bit like a leak, but it's ne
Yoyo Zhou
2014/12/18 02:38:34
This looks more complicated right now; I was hopin
tapted
2014/12/18 03:30:55
Corect - the releases are not the same. But NSWind
| |
| 57 | |
| 58 [[window_controller_ window] setDelegate:window_controller_]; | |
| 59 [window_controller_ setAppWindow:this]; | |
| 60 | |
| 61 NSView* view = app_window->web_contents()->GetNativeView(); | |
| 62 NSView* frameView = [window() contentView]; | |
| 63 [view setFrame:[frameView bounds]]; | |
| 64 [frameView addSubview:view]; | |
| 65 } | |
| 66 | |
| 67 ShellNativeAppWindowMac::~ShellNativeAppWindowMac() { | |
| 68 } | |
|
tapted
2014/12/17 08:05:16
this should call [window() setDelegate:nil]; (the
Yoyo Zhou
2014/12/18 02:38:34
Done.
| |
| 69 | |
| 70 bool ShellNativeAppWindowMac::IsActive() const { | |
| 71 NOTIMPLEMENTED(); | |
|
tapted
2014/12/17 08:05:16
if you feel like it now.. [window() isKeyWindow] s
Yoyo Zhou
2014/12/18 02:38:34
Done.
| |
| 72 return false; | |
| 73 } | |
| 74 | |
| 75 gfx::NativeWindow ShellNativeAppWindowMac::GetNativeWindow() const { | |
| 76 return window(); | |
| 77 } | |
| 78 | |
| 79 gfx::Rect ShellNativeAppWindowMac::GetBounds() const { | |
| 80 // Flip coordinates based on the primary screen. | |
|
tapted
2014/12/17 08:05:16
return gfx::ScreenRectFromNSRect([window() frame])
Yoyo Zhou
2014/12/18 02:38:34
Done.
| |
| 81 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | |
| 82 NSRect frame = [[window_controller_ window] frame]; | |
| 83 return gfx::Rect(frame.origin.x, NSHeight([screen frame]) - NSMaxY(frame), | |
| 84 NSWidth(frame), NSHeight(frame)); | |
| 85 } | |
| 86 | |
| 87 void ShellNativeAppWindowMac::Show() { | |
| 88 [window_controller_ showWindow:nil]; | |
| 89 } | |
| 90 | |
| 91 void ShellNativeAppWindowMac::Hide() { | |
| 92 NOTIMPLEMENTED(); | |
| 93 } | |
| 94 | |
| 95 void ShellNativeAppWindowMac::Activate() { | |
| 96 // TODO(yoz): Activate in front of other applications. | |
| 97 [[window_controller_ window] makeKeyAndOrderFront:window_controller_]; | |
| 98 } | |
| 99 | |
| 100 void ShellNativeAppWindowMac::Deactivate() { | |
| 101 // See crbug.com/51364. | |
| 102 NOTIMPLEMENTED(); | |
| 103 } | |
| 104 | |
| 105 void ShellNativeAppWindowMac::SetBounds(const gfx::Rect& bounds) { | |
| 106 // TODO(yoz): Windows should be fullscreen. | |
| 107 NOTIMPLEMENTED(); | |
| 108 } | |
| 109 | |
| 110 void ShellNativeAppWindowMac::WindowWillClose() { | |
| 111 [window_controller_ setAppWindow:NULL]; | |
| 112 app_window()->OnNativeWindowChanged(); | |
| 113 app_window()->OnNativeClose(); | |
| 114 } | |
| 115 | |
| 116 ShellNSWindow* ShellNativeAppWindowMac::window() const { | |
| 117 NSWindow* window = [window_controller_ window]; | |
| 118 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); | |
|
tapted
2014/12/17 08:05:16
maybe, from base/mac/foundation_util.h
return b
Yoyo Zhou
2014/12/18 02:38:34
Done.
| |
| 119 return static_cast<ShellNSWindow*>(window); | |
| 120 } | |
| 121 | |
| 122 } // namespace extensions | |
| OLD | NEW |