Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 } | 72 } |
| 73 return sheetController_; | 73 return sheetController_; |
| 74 } | 74 } |
| 75 | 75 |
| 76 - (void)executeCommand:(int)command { | 76 - (void)executeCommand:(int)command { |
| 77 // No-op, swallow the event. | 77 // No-op, swallow the event. |
| 78 } | 78 } |
| 79 | 79 |
| 80 @end | 80 @end |
| 81 | 81 |
| 82 @interface ShellNSWindow : ChromeEventProcessingWindow | |
| 83 | |
| 84 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; | |
| 85 | |
| 86 @end | |
| 87 | |
| 88 // This is really a method on NSGrayFrame, so it should only be called on the | 82 // This is really a method on NSGrayFrame, so it should only be called on the |
| 89 // view passed into -[NSWindow drawCustomFrameRect:forView:]. | 83 // view passed into -[NSWindow drawCustomFrameRect:forView:]. |
| 90 @interface NSView (PrivateMethods) | 84 @interface NSView (PrivateMethods) |
| 91 - (CGFloat)roundedCornerRadius; | 85 - (CGFloat)roundedCornerRadius; |
| 92 @end | 86 @end |
| 93 | 87 |
| 88 @interface ShellNSWindow : ChromeEventProcessingWindow | |
| 89 | |
| 90 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view; | |
| 91 | |
| 92 @end | |
| 93 | |
| 94 @implementation ShellNSWindow | 94 @implementation ShellNSWindow |
| 95 | 95 |
| 96 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { | 96 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { |
| 97 [[NSBezierPath bezierPathWithRect:rect] addClip]; | 97 [[NSBezierPath bezierPathWithRect:rect] addClip]; |
| 98 [[NSColor clearColor] set]; | 98 [[NSColor clearColor] set]; |
| 99 NSRectFill(rect); | 99 NSRectFill(rect); |
| 100 | 100 |
| 101 // Set up our clip. | 101 // Set up our clip. |
| 102 CGFloat cornerRadius = 4.0; | 102 CGFloat cornerRadius = 4.0; |
| 103 if ([view respondsToSelector:@selector(roundedCornerRadius)]) | 103 if ([view respondsToSelector:@selector(roundedCornerRadius)]) |
| 104 cornerRadius = [view roundedCornerRadius]; | 104 cornerRadius = [view roundedCornerRadius]; |
| 105 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] | 105 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] |
| 106 xRadius:cornerRadius | 106 xRadius:cornerRadius |
| 107 yRadius:cornerRadius] addClip]; | 107 yRadius:cornerRadius] addClip]; |
| 108 [[NSColor whiteColor] set]; | 108 [[NSColor whiteColor] set]; |
| 109 NSRectFill(rect); | 109 NSRectFill(rect); |
| 110 } | 110 } |
| 111 | 111 |
| 112 @end | |
| 113 | |
| 114 @interface ShellFramelessNSWindow : ShellNSWindow | |
| 115 | |
| 116 @end | |
| 117 | |
| 118 @implementation ShellFramelessNSWindow | |
| 119 | |
| 112 + (NSRect)frameRectForContentRect:(NSRect)contentRect | 120 + (NSRect)frameRectForContentRect:(NSRect)contentRect |
| 113 styleMask:(NSUInteger)mask { | 121 styleMask:(NSUInteger)mask { |
| 114 return contentRect; | 122 return contentRect; |
| 115 } | 123 } |
| 116 | 124 |
| 117 + (NSRect)contentRectForFrameRect:(NSRect)frameRect | 125 + (NSRect)contentRectForFrameRect:(NSRect)frameRect |
| 118 styleMask:(NSUInteger)mask { | 126 styleMask:(NSUInteger)mask { |
| 119 return frameRect; | 127 return frameRect; |
| 120 } | 128 } |
| 121 | 129 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 (NSWidth(main_screen_rect) - NSWidth(cocoa_bounds)) / 2; | 169 (NSWidth(main_screen_rect) - NSWidth(cocoa_bounds)) / 2; |
| 162 } | 170 } |
| 163 if (params.bounds.y() < 0) { | 171 if (params.bounds.y() < 0) { |
| 164 cocoa_bounds.origin.y = | 172 cocoa_bounds.origin.y = |
| 165 (NSHeight(main_screen_rect) - NSHeight(cocoa_bounds)) / 2; | 173 (NSHeight(main_screen_rect) - NSHeight(cocoa_bounds)) / 2; |
| 166 } | 174 } |
| 167 | 175 |
| 168 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | | 176 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
| 169 NSMiniaturizableWindowMask | NSResizableWindowMask | | 177 NSMiniaturizableWindowMask | NSResizableWindowMask | |
| 170 NSTexturedBackgroundWindowMask; | 178 NSTexturedBackgroundWindowMask; |
| 171 scoped_nsobject<NSWindow> window([[ShellNSWindow alloc] | 179 scoped_nsobject<NSWindow> window; |
| 180 if (has_frame_) | |
|
Robert Sesek
2012/09/17 18:50:45
Multi-line bodies need {} braces.
| |
| 181 window.reset([[ShellNSWindow alloc] | |
| 172 initWithContentRect:cocoa_bounds | 182 initWithContentRect:cocoa_bounds |
|
Robert Sesek
2012/09/17 18:50:45
nit: continuations need to be indented 4 spaces fr
| |
| 173 styleMask:style_mask | 183 styleMask:style_mask |
| 174 backing:NSBackingStoreBuffered | 184 backing:NSBackingStoreBuffered |
| 185 defer:NO]); | |
| 186 else | |
| 187 window.reset([[ShellFramelessNSWindow alloc] | |
| 188 initWithContentRect:cocoa_bounds | |
| 189 styleMask:style_mask | |
| 190 backing:NSBackingStoreBuffered | |
| 175 defer:NO]); | 191 defer:NO]); |
| 176 [window setTitle:base::SysUTF8ToNSString(extension()->name())]; | 192 [window setTitle:base::SysUTF8ToNSString(extension()->name())]; |
| 177 gfx::Size min_size = params.minimum_size; | 193 gfx::Size min_size = params.minimum_size; |
| 178 if (min_size.width() || min_size.height()) { | 194 if (min_size.width() || min_size.height()) { |
| 179 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; | 195 [window setContentMinSize:NSMakeSize(min_size.width(), min_size.height())]; |
| 180 } | 196 } |
| 181 gfx::Size max_size = params.maximum_size; | 197 gfx::Size max_size = params.maximum_size; |
| 182 if (max_size.width() || max_size.height()) { | 198 if (max_size.width() || max_size.height()) { |
| 183 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX; | 199 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX; |
| 184 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; | 200 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |