Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/apps/native_app_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 10 #include "base/mac/sdk_forward_declarations.h" | 10 #include "base/mac/sdk_forward_declarations.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 non_draggable->op(*draggable, SkRegion::kDifference_Op); | 120 non_draggable->op(*draggable, SkRegion::kDifference_Op); |
| 121 for (SkRegion::Iterator it(*non_draggable); !it.done(); it.next()) { | 121 for (SkRegion::Iterator it(*non_draggable); !it.done(); it.next()) { |
| 122 result.push_back(gfx::SkIRectToRect(it.rect())); | 122 result.push_back(gfx::SkIRectToRect(it.rect())); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 return result; | 125 return result; |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace | 128 } // namespace |
| 129 | 129 |
| 130 @interface NativeAppWindowController (Private) | |
|
tapted
2015/02/12 05:56:04
(Private) -> ()
jackhou1
2015/02/13 00:04:33
Done.
| |
| 131 - (void)didChangeActive; | |
| 132 @end | |
| 133 | |
| 130 @implementation NativeAppWindowController | 134 @implementation NativeAppWindowController |
| 131 | 135 |
| 132 @synthesize appWindow = appWindow_; | 136 @synthesize appWindow = appWindow_; |
| 133 | 137 |
| 138 - (void)didChangeActive { | |
| 139 [base::mac::ObjCCastStrict<ShellNSWindow>([self window]) | |
| 140 didChangeActive]; | |
| 141 } | |
| 142 | |
| 134 - (void)windowWillClose:(NSNotification*)notification { | 143 - (void)windowWillClose:(NSNotification*)notification { |
| 135 if (appWindow_) | 144 if (appWindow_) |
| 136 appWindow_->WindowWillClose(); | 145 appWindow_->WindowWillClose(); |
| 137 } | 146 } |
| 138 | 147 |
| 148 - (void)windowDidBecomeMain:(NSNotification*)notification { | |
|
tapted
2015/02/12 05:56:04
the FooMain methods should be able to be removed -
jackhou1
2015/02/13 00:04:33
Done.
| |
| 149 [self didChangeActive]; | |
| 150 } | |
| 151 | |
| 152 - (void)windowDidResignMain:(NSNotification*)notification { | |
| 153 [self didChangeActive]; | |
| 154 } | |
| 155 | |
| 139 - (void)windowDidBecomeKey:(NSNotification*)notification { | 156 - (void)windowDidBecomeKey:(NSNotification*)notification { |
| 157 [self didChangeActive]; | |
| 140 if (appWindow_) | 158 if (appWindow_) |
| 141 appWindow_->WindowDidBecomeKey(); | 159 appWindow_->WindowDidBecomeKey(); |
| 142 } | 160 } |
| 143 | 161 |
| 144 - (void)windowDidResignKey:(NSNotification*)notification { | 162 - (void)windowDidResignKey:(NSNotification*)notification { |
| 163 [self didChangeActive]; | |
| 145 if (appWindow_) | 164 if (appWindow_) |
| 146 appWindow_->WindowDidResignKey(); | 165 appWindow_->WindowDidResignKey(); |
| 147 } | 166 } |
| 148 | 167 |
| 149 - (void)windowDidResize:(NSNotification*)notification { | 168 - (void)windowDidResize:(NSNotification*)notification { |
| 150 if (appWindow_) | 169 if (appWindow_) |
| 151 appWindow_->WindowDidResize(); | 170 appWindow_->WindowDidResize(); |
| 152 } | 171 } |
| 153 | 172 |
| 154 - (void)windowDidEndLiveResize:(NSNotification*)notification { | 173 - (void)windowDidEndLiveResize:(NSNotification*)notification { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 | 220 |
| 202 - (BOOL)handledByExtensionCommand:(NSEvent*)event | 221 - (BOOL)handledByExtensionCommand:(NSEvent*)event |
| 203 priority:(ui::AcceleratorManager::HandlerPriority)priority { | 222 priority:(ui::AcceleratorManager::HandlerPriority)priority { |
| 204 if (appWindow_) | 223 if (appWindow_) |
| 205 return appWindow_->HandledByExtensionCommand(event, priority); | 224 return appWindow_->HandledByExtensionCommand(event, priority); |
| 206 return NO; | 225 return NO; |
| 207 } | 226 } |
| 208 | 227 |
| 209 @end | 228 @end |
| 210 | 229 |
| 211 // This is really a method on NSGrayFrame, so it should only be called on the | 230 @interface TitleBarBackgroundView : NSView { |
| 212 // view passed into -[NSWindow drawCustomFrameRect:forView:]. | |
| 213 @interface NSView (PrivateMethods) | |
| 214 - (CGFloat)roundedCornerRadius; | |
| 215 @end | |
| 216 | |
| 217 // TODO(jamescook): Should these be AppNSWindow to match AppWindow? | |
| 218 // http://crbug.com/344082 | |
| 219 @interface ShellNSWindow : ChromeEventProcessingWindow | |
| 220 @end | |
| 221 @implementation ShellNSWindow | |
| 222 | |
| 223 // Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen | |
| 224 // in menus, Expose, etc. | |
| 225 - (BOOL)_isTitleHidden { | |
| 226 return YES; | |
| 227 } | |
| 228 | |
| 229 - (void)drawCustomFrameRect:(NSRect)frameRect forView:(NSView*)view { | |
| 230 // Make the background color of the content area white. We can't just call | |
| 231 // -setBackgroundColor as that causes the title bar to be drawn in a solid | |
| 232 // color. | |
| 233 NSRect rect = [self contentRectForFrameRect:frameRect]; | |
| 234 [[NSColor whiteColor] set]; | |
| 235 NSRectFill(rect); | |
| 236 | |
| 237 // Draw the native title bar. We remove the content area since the native | |
| 238 // implementation draws a gray background. | |
| 239 rect.origin.y = NSMaxY(rect); | |
| 240 rect.size.height = CGFLOAT_MAX; | |
| 241 rect = NSIntersectionRect(rect, frameRect); | |
| 242 | |
| 243 [NSBezierPath clipRect:rect]; | |
| 244 [super drawCustomFrameRect:frameRect | |
| 245 forView:view]; | |
| 246 } | |
| 247 | |
| 248 @end | |
| 249 | |
| 250 @interface ShellCustomFrameNSWindow : ShellNSWindow { | |
| 251 @private | 231 @private |
| 252 base::scoped_nsobject<NSColor> color_; | 232 base::scoped_nsobject<NSColor> color_; |
| 253 base::scoped_nsobject<NSColor> inactiveColor_; | 233 base::scoped_nsobject<NSColor> inactiveColor_; |
| 254 } | 234 } |
| 255 | |
| 256 - (void)setColor:(NSColor*)color | 235 - (void)setColor:(NSColor*)color |
| 257 inactiveColor:(NSColor*)inactiveColor; | 236 inactiveColor:(NSColor*)inactiveColor; |
| 258 | |
| 259 @end | 237 @end |
| 260 | 238 |
| 261 @implementation ShellCustomFrameNSWindow | 239 @implementation TitleBarBackgroundView |
| 262 | 240 |
| 263 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view { | 241 - (void)drawRect:(NSRect)rect { |
| 264 [[NSBezierPath bezierPathWithRect:rect] addClip]; | 242 [[NSBezierPath bezierPathWithRect:rect] addClip]; |
| 265 [[NSColor clearColor] set]; | 243 [[NSColor clearColor] set]; |
| 266 NSRectFill(rect); | 244 NSRectFill(rect); |
| 267 | 245 |
| 268 // Set up our clip. | 246 // Set up our clip. |
| 269 CGFloat cornerRadius = 4.0; | 247 CGFloat cornerRadius = 4.0; |
| 270 if ([view respondsToSelector:@selector(roundedCornerRadius)]) | 248 [[NSBezierPath bezierPathWithRoundedRect:[self bounds] |
| 271 cornerRadius = [view roundedCornerRadius]; | |
| 272 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] | |
| 273 xRadius:cornerRadius | 249 xRadius:cornerRadius |
| 274 yRadius:cornerRadius] addClip]; | 250 yRadius:cornerRadius] addClip]; |
| 275 if ([self isMainWindow] || [self isKeyWindow]) | 251 if ([[self window] isMainWindow] || [[self window] isKeyWindow]) |
| 276 [color_ set]; | 252 [color_ set]; |
| 277 else | 253 else |
| 278 [inactiveColor_ set]; | 254 [inactiveColor_ set]; |
| 279 NSRectFill(rect); | 255 NSRectFill(rect); |
| 280 } | 256 } |
| 281 | 257 |
| 282 - (void)setColor:(NSColor*)color | 258 - (void)setColor:(NSColor*)color |
| 283 inactiveColor:(NSColor*)inactiveColor { | 259 inactiveColor:(NSColor*)inactiveColor { |
| 284 color_.reset([color retain]); | 260 color_.reset([color retain]); |
| 285 inactiveColor_.reset([inactiveColor retain]); | 261 inactiveColor_.reset([inactiveColor retain]); |
| 286 } | 262 } |
| 287 | 263 |
| 288 @end | 264 @end |
| 289 | 265 |
| 266 // TODO(jamescook): Should these be AppNSWindow to match AppWindow? | |
| 267 // http://crbug.com/344082 | |
| 268 @interface ShellNSWindow : ChromeEventProcessingWindow { | |
| 269 @private | |
| 270 base::scoped_nsobject<TitleBarBackgroundView> titleBarBackgroundView_; | |
| 271 } | |
| 272 - (void)didChangeActive; | |
| 273 - (void)setColor:(NSColor*)color | |
| 274 inactiveColor:(NSColor*)inactiveColor; | |
| 275 @end | |
| 276 | |
| 277 @implementation ShellNSWindow | |
| 278 | |
| 279 // Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen | |
| 280 // in menus, Expose, etc. | |
| 281 - (BOOL)_isTitleHidden { | |
| 282 return YES; | |
| 283 } | |
| 284 | |
| 285 - (void)didChangeActive { | |
| 286 [titleBarBackgroundView_ setNeedsDisplay:YES]; | |
| 287 } | |
| 288 | |
| 289 - (void)setColor:(NSColor*)color | |
| 290 inactiveColor:(NSColor*)inactiveColor { | |
| 291 if (!titleBarBackgroundView_) { | |
| 292 NSView* windowView = [[self contentView] superview]; | |
|
tapted
2015/02/12 05:56:04
Mavericks has (officially) banned the practice of
jackhou1
2015/02/13 00:04:33
Yes, and looking around forums it seems like addin
jackhou1
2015/02/18 04:35:09
Tested this out on 10.10 linking with both 10.6 an
| |
| 293 titleBarBackgroundView_.reset([[TitleBarBackgroundView alloc] | |
| 294 initWithFrame:NSMakeRect(0, | |
| 295 NSMaxY([windowView bounds]) - | |
| 296 60.0, | |
| 297 NSWidth([windowView bounds]), | |
| 298 60.0)]); | |
| 299 [titleBarBackgroundView_ | |
| 300 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; | |
| 301 [windowView addSubview:titleBarBackgroundView_ | |
| 302 positioned:NSWindowBelow | |
| 303 relativeTo:nil]; | |
| 304 } | |
| 305 | |
| 306 [titleBarBackgroundView_ setColor:color | |
| 307 inactiveColor:inactiveColor]; | |
| 308 } | |
| 309 | |
| 310 @end | |
| 311 | |
| 290 @interface ShellFramelessNSWindow : ShellNSWindow | 312 @interface ShellFramelessNSWindow : ShellNSWindow |
| 291 @end | 313 @end |
| 292 | 314 |
| 293 @implementation ShellFramelessNSWindow | 315 @implementation ShellFramelessNSWindow |
| 294 | 316 |
| 295 - (void)drawCustomFrameRect:(NSRect)rect forView:(NSView*)view {} | |
| 296 | |
| 297 + (NSRect)frameRectForContentRect:(NSRect)contentRect | 317 + (NSRect)frameRectForContentRect:(NSRect)contentRect |
| 298 styleMask:(NSUInteger)mask { | 318 styleMask:(NSUInteger)mask { |
| 299 return contentRect; | 319 return contentRect; |
| 300 } | 320 } |
| 301 | 321 |
| 302 + (NSRect)contentRectForFrameRect:(NSRect)frameRect | 322 + (NSRect)contentRectForFrameRect:(NSRect)frameRect |
| 303 styleMask:(NSUInteger)mask { | 323 styleMask:(NSUInteger)mask { |
| 304 return frameRect; | 324 return frameRect; |
| 305 } | 325 } |
| 306 | 326 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 is_fullscreen_(false), | 363 is_fullscreen_(false), |
| 344 is_resizable_(params.resizable), | 364 is_resizable_(params.resizable), |
| 345 shows_resize_controls_(true), | 365 shows_resize_controls_(true), |
| 346 shows_fullscreen_controls_(true), | 366 shows_fullscreen_controls_(true), |
| 347 has_frame_color_(params.has_frame_color), | 367 has_frame_color_(params.has_frame_color), |
| 348 active_frame_color_(params.active_frame_color), | 368 active_frame_color_(params.active_frame_color), |
| 349 inactive_frame_color_(params.inactive_frame_color) { | 369 inactive_frame_color_(params.inactive_frame_color) { |
| 350 Observe(WebContents()); | 370 Observe(WebContents()); |
| 351 | 371 |
| 352 base::scoped_nsobject<NSWindow> window; | 372 base::scoped_nsobject<NSWindow> window; |
| 353 Class window_class; | 373 Class window_class = has_frame_ ? |
| 354 if (has_frame_) { | 374 [ShellNSWindow class] : [ShellFramelessNSWindow class]; |
| 355 window_class = has_frame_color_ ? | |
| 356 [ShellCustomFrameNSWindow class] : [ShellNSWindow class]; | |
| 357 } else { | |
| 358 window_class = [ShellFramelessNSWindow class]; | |
| 359 } | |
| 360 | 375 |
| 361 // Estimate the initial bounds of the window. Once the frame insets are known, | 376 // Estimate the initial bounds of the window. Once the frame insets are known, |
| 362 // the window bounds and constraints can be set precisely. | 377 // the window bounds and constraints can be set precisely. |
| 363 NSRect cocoa_bounds = GfxToCocoaBounds( | 378 NSRect cocoa_bounds = GfxToCocoaBounds( |
| 364 params.GetInitialWindowBounds(gfx::Insets())); | 379 params.GetInitialWindowBounds(gfx::Insets())); |
| 365 window.reset([[window_class alloc] | 380 window.reset([[window_class alloc] |
| 366 initWithContentRect:cocoa_bounds | 381 initWithContentRect:cocoa_bounds |
| 367 styleMask:GetWindowStyleMask() | 382 styleMask:GetWindowStyleMask() |
| 368 backing:NSBackingStoreBuffered | 383 backing:NSBackingStoreBuffered |
| 369 defer:NO]); | 384 defer:NO]); |
| 370 | 385 |
| 371 std::string name; | 386 std::string name; |
| 372 const extensions::Extension* extension = app_window_->GetExtension(); | 387 const extensions::Extension* extension = app_window_->GetExtension(); |
| 373 if (extension) | 388 if (extension) |
| 374 name = extension->name(); | 389 name = extension->name(); |
| 375 [window setTitle:base::SysUTF8ToNSString(name)]; | 390 [window setTitle:base::SysUTF8ToNSString(name)]; |
| 376 [[window contentView] setWantsLayer:YES]; | 391 [[window contentView] setWantsLayer:YES]; |
| 377 if (has_frame_ && has_frame_color_) { | 392 if (has_frame_ && has_frame_color_) { |
| 378 [base::mac::ObjCCastStrict<ShellCustomFrameNSWindow>(window) | 393 [base::mac::ObjCCastStrict<ShellNSWindow>(window) |
| 379 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) | 394 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) |
| 380 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; | 395 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; |
| 381 } | 396 } |
| 382 | 397 |
| 383 if (base::mac::IsOSSnowLeopard() && | 398 if (base::mac::IsOSSnowLeopard() && |
| 384 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 399 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
| 385 [window setBottomCornerRounded:NO]; | 400 [window setBottomCornerRounded:NO]; |
| 386 | 401 |
| 387 if (params.always_on_top) | 402 if (params.always_on_top) |
| 388 [window setLevel:AlwaysOnTopWindowLevel()]; | 403 [window setLevel:AlwaysOnTopWindowLevel()]; |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 } | 1016 } |
| 1002 | 1017 |
| 1003 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 1018 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
| 1004 if (IsRestored(*this)) | 1019 if (IsRestored(*this)) |
| 1005 restored_bounds_ = [window() frame]; | 1020 restored_bounds_ = [window() frame]; |
| 1006 } | 1021 } |
| 1007 | 1022 |
| 1008 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 1023 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
| 1009 [window() orderOut:window_controller_]; | 1024 [window() orderOut:window_controller_]; |
| 1010 } | 1025 } |
| OLD | NEW |