| 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" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 - (BOOL)handledByExtensionCommand:(NSEvent*)event { | 81 - (BOOL)handledByExtensionCommand:(NSEvent*)event { |
| 82 if (shellWindow_) | 82 if (shellWindow_) |
| 83 return shellWindow_->HandledByExtensionCommand(event); | 83 return shellWindow_->HandledByExtensionCommand(event); |
| 84 return NO; | 84 return NO; |
| 85 } | 85 } |
| 86 | 86 |
| 87 @end | 87 @end |
| 88 | 88 |
| 89 @interface ShellNSWindow : ChromeEventProcessingWindow | |
| 90 | |
| 91 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; | |
| 92 | |
| 93 @end | |
| 94 | |
| 95 // This is really a method on NSGrayFrame, so it should only be called on the | 89 // This is really a method on NSGrayFrame, so it should only be called on the |
| 96 // view passed into -[NSWindow drawCustomFrameRect:forView:]. | 90 // view passed into -[NSWindow drawCustomFrameRect:forView:]. |
| 97 @interface NSView (PrivateMethods) | 91 @interface NSView (PrivateMethods) |
| 98 - (CGFloat)roundedCornerRadius; | 92 - (CGFloat)roundedCornerRadius; |
| 99 @end | 93 @end |
| 100 | 94 |
| 95 @interface ShellNSWindow : ChromeEventProcessingWindow |
| 96 |
| 97 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; |
| 98 |
| 99 @end |
| 100 |
| 101 @implementation ShellNSWindow | 101 @implementation ShellNSWindow |
| 102 | 102 |
| 103 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { | 103 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { |
| 104 [[NSBezierPath bezierPathWithRect:rect] addClip]; | 104 [[NSBezierPath bezierPathWithRect:rect] addClip]; |
| 105 [[NSColor clearColor] set]; | 105 [[NSColor clearColor] set]; |
| 106 NSRectFill(rect); | 106 NSRectFill(rect); |
| 107 | 107 |
| 108 // Set up our clip. | 108 // Set up our clip. |
| 109 CGFloat cornerRadius = 4.0; | 109 CGFloat cornerRadius = 4.0; |
| 110 if ([view respondsToSelector:@selector(roundedCornerRadius)]) | 110 if ([view respondsToSelector:@selector(roundedCornerRadius)]) |
| 111 cornerRadius = [view roundedCornerRadius]; | 111 cornerRadius = [view roundedCornerRadius]; |
| 112 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] | 112 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] |
| 113 xRadius:cornerRadius | 113 xRadius:cornerRadius |
| 114 yRadius:cornerRadius] addClip]; | 114 yRadius:cornerRadius] addClip]; |
| 115 [[NSColor whiteColor] set]; | 115 [[NSColor whiteColor] set]; |
| 116 NSRectFill(rect); | 116 NSRectFill(rect); |
| 117 } | 117 } |
| 118 | 118 |
| 119 @end |
| 120 |
| 121 @interface ShellFramelessNSWindow : ShellNSWindow |
| 122 |
| 123 @end |
| 124 |
| 125 @implementation ShellFramelessNSWindow |
| 126 |
| 119 + (NSRect)frameRectForContentRect:(NSRect)contentRect | 127 + (NSRect)frameRectForContentRect:(NSRect)contentRect |
| 120 styleMask:(NSUInteger)mask { | 128 styleMask:(NSUInteger)mask { |
| 121 return contentRect; | 129 return contentRect; |
| 122 } | 130 } |
| 123 | 131 |
| 124 + (NSRect)contentRectForFrameRect:(NSRect)frameRect | 132 + (NSRect)contentRectForFrameRect:(NSRect)frameRect |
| 125 styleMask:(NSUInteger)mask { | 133 styleMask:(NSUInteger)mask { |
| 126 return frameRect; | 134 return frameRect; |
| 127 } | 135 } |
| 128 | 136 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 (NSWidth(main_screen_rect) - NSWidth(cocoa_bounds)) / 2; | 176 (NSWidth(main_screen_rect) - NSWidth(cocoa_bounds)) / 2; |
| 169 } | 177 } |
| 170 if (params.bounds.y() < 0) { | 178 if (params.bounds.y() < 0) { |
| 171 cocoa_bounds.origin.y = | 179 cocoa_bounds.origin.y = |
| 172 (NSHeight(main_screen_rect) - NSHeight(cocoa_bounds)) / 2; | 180 (NSHeight(main_screen_rect) - NSHeight(cocoa_bounds)) / 2; |
| 173 } | 181 } |
| 174 | 182 |
| 175 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | | 183 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
| 176 NSMiniaturizableWindowMask | NSResizableWindowMask | | 184 NSMiniaturizableWindowMask | NSResizableWindowMask | |
| 177 NSTexturedBackgroundWindowMask; | 185 NSTexturedBackgroundWindowMask; |
| 178 scoped_nsobject<NSWindow> window([[ShellNSWindow alloc] | 186 scoped_nsobject<NSWindow> window; |
| 179 initWithContentRect:cocoa_bounds | 187 if (has_frame_) { |
| 180 styleMask:style_mask | 188 window.reset([[ShellNSWindow alloc] |
| 181 backing:NSBackingStoreBuffered | 189 initWithContentRect:cocoa_bounds |
| 182 defer:NO]); | 190 styleMask:style_mask |
| 191 backing:NSBackingStoreBuffered |
| 192 defer:NO]); |
| 193 } else { |
| 194 window.reset([[ShellFramelessNSWindow alloc] |
| 195 initWithContentRect:cocoa_bounds |
| 196 styleMask:style_mask |
| 197 backing:NSBackingStoreBuffered |
| 198 defer:NO]); |
| 199 } |
| 183 [window setTitle:base::SysUTF8ToNSString(extension()->name())]; | 200 [window setTitle:base::SysUTF8ToNSString(extension()->name())]; |
| 184 gfx::Size min_size = params.minimum_size; | 201 gfx::Size min_size = params.minimum_size; |
| 185 if (min_size.width() || min_size.height()) { | 202 if (min_size.width() || min_size.height()) { |
| 186 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; | 203 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; |
| 187 } | 204 } |
| 188 gfx::Size max_size = params.maximum_size; | 205 gfx::Size max_size = params.maximum_size; |
| 189 if (max_size.width() || max_size.height()) { | 206 if (max_size.width() || max_size.height()) { |
| 190 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX; | 207 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX; |
| 191 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; | 208 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; |
| 192 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; | 209 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 NSWindow* window = [window_controller_ window]; | 535 NSWindow* window = [window_controller_ window]; |
| 519 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); | 536 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); |
| 520 return static_cast<ShellNSWindow*>(window); | 537 return static_cast<ShellNSWindow*>(window); |
| 521 } | 538 } |
| 522 | 539 |
| 523 // static | 540 // static |
| 524 NativeShellWindow* NativeShellWindow::Create( | 541 NativeShellWindow* NativeShellWindow::Create( |
| 525 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 542 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
| 526 return new ShellWindowCocoa(shell_window, params); | 543 return new ShellWindowCocoa(shell_window, params); |
| 527 } | 544 } |
| OLD | NEW |