| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 - (void)windowDidEndLiveResize:(NSNotification*)notification { | 155 - (void)windowDidEndLiveResize:(NSNotification*)notification { |
| 156 if (appWindow_) | 156 if (appWindow_) |
| 157 appWindow_->WindowDidFinishResize(); | 157 appWindow_->WindowDidFinishResize(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 160 - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
| 161 if (appWindow_) | 161 if (appWindow_) |
| 162 appWindow_->WindowDidEnterFullscreen(); | 162 appWindow_->WindowDidEnterFullscreen(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 - (void)windowWillExitFullScreen:(NSNotification*)notification { |
| 166 if (appWindow_) |
| 167 appWindow_->WindowWillExitFullscreen(); |
| 168 } |
| 169 |
| 165 - (void)windowDidExitFullScreen:(NSNotification*)notification { | 170 - (void)windowDidExitFullScreen:(NSNotification*)notification { |
| 166 if (appWindow_) | 171 if (appWindow_) |
| 167 appWindow_->WindowDidExitFullscreen(); | 172 appWindow_->WindowDidExitFullscreen(); |
| 168 } | 173 } |
| 169 | 174 |
| 170 - (void)windowDidMove:(NSNotification*)notification { | 175 - (void)windowDidMove:(NSNotification*)notification { |
| 171 if (appWindow_) | 176 if (appWindow_) |
| 172 appWindow_->WindowDidMove(); | 177 appWindow_->WindowDidMove(); |
| 173 } | 178 } |
| 174 | 179 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 234 } |
| 230 | 235 |
| 231 - (void)setColor:(NSColor*)color | 236 - (void)setColor:(NSColor*)color |
| 232 inactiveColor:(NSColor*)inactiveColor { | 237 inactiveColor:(NSColor*)inactiveColor { |
| 233 color_.reset([color retain]); | 238 color_.reset([color retain]); |
| 234 inactiveColor_.reset([inactiveColor retain]); | 239 inactiveColor_.reset([inactiveColor retain]); |
| 235 } | 240 } |
| 236 | 241 |
| 237 @end | 242 @end |
| 238 | 243 |
| 244 @interface NSViewController () |
| 245 @property NSInteger layoutAttribute; |
| 246 @end |
| 247 |
| 239 // TODO(jamescook): Should these be AppNSWindow to match AppWindow? | 248 // TODO(jamescook): Should these be AppNSWindow to match AppWindow? |
| 240 // http://crbug.com/344082 | 249 // http://crbug.com/344082 |
| 241 @interface ShellNSWindow : ChromeEventProcessingWindow | 250 @interface ShellNSWindow : ChromeEventProcessingWindow |
| 242 @end | 251 @end |
| 243 | 252 |
| 244 @implementation ShellNSWindow | 253 @implementation ShellNSWindow |
| 245 | 254 |
| 246 // Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen | 255 // Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen |
| 247 // in menus, Expose, etc. | 256 // in menus, Expose, etc. |
| 248 - (BOOL)_isTitleHidden { | 257 - (BOOL)_isTitleHidden { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 - (NSView*)hitTest:(NSPoint)aPoint { | 297 - (NSView*)hitTest:(NSPoint)aPoint { |
| 289 return nil; | 298 return nil; |
| 290 } | 299 } |
| 291 | 300 |
| 292 @end | 301 @end |
| 293 | 302 |
| 294 @interface NSView (WebContentsView) | 303 @interface NSView (WebContentsView) |
| 295 - (void)setMouseDownCanMoveWindow:(BOOL)can_move; | 304 - (void)setMouseDownCanMoveWindow:(BOOL)can_move; |
| 296 @end | 305 @end |
| 297 | 306 |
| 307 @interface WindowControlView : NSView |
| 308 - (void)setupTrackingArea; |
| 309 @end |
| 310 |
| 311 @implementation WindowControlView |
| 312 |
| 313 - (void)setupTrackingArea { |
| 314 base::scoped_nsobject<NSTrackingArea> trackingArea([[NSTrackingArea alloc] |
| 315 initWithRect:[self bounds] |
| 316 options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) |
| 317 owner:self |
| 318 userInfo:nil]); |
| 319 [self addTrackingArea:trackingArea]; |
| 320 } |
| 321 |
| 322 - (void)mouseEntered:(NSEvent *)theEvent { |
| 323 // Show window control button icons. |
| 324 } |
| 325 |
| 326 - (void)mouseExited:(NSEvent *)theEvent { |
| 327 // Hide window control button icons. |
| 328 } |
| 329 |
| 330 @end |
| 331 |
| 298 NativeAppWindowCocoa::NativeAppWindowCocoa( | 332 NativeAppWindowCocoa::NativeAppWindowCocoa( |
| 299 AppWindow* app_window, | 333 AppWindow* app_window, |
| 300 const AppWindow::CreateParams& params) | 334 const AppWindow::CreateParams& params) |
| 301 : app_window_(app_window), | 335 : app_window_(app_window), |
| 302 has_frame_(params.frame == AppWindow::FRAME_CHROME), | 336 has_frame_(params.frame == AppWindow::FRAME_CHROME), |
| 303 is_hidden_with_app_(false), | 337 is_hidden_with_app_(false), |
| 304 is_maximized_(false), | 338 is_maximized_(false), |
| 305 is_fullscreen_(false), | 339 is_fullscreen_(false), |
| 306 is_resizable_(params.resizable), | 340 is_resizable_(params.resizable), |
| 307 shows_resize_controls_(true), | 341 shows_resize_controls_(true), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 334 if (has_frame_ && has_frame_color_) { | 368 if (has_frame_ && has_frame_color_) { |
| 335 NSView* window_view = [[window contentView] superview]; | 369 NSView* window_view = [[window contentView] superview]; |
| 336 titlebar_background_view_.reset([[TitlebarBackgroundView alloc] | 370 titlebar_background_view_.reset([[TitlebarBackgroundView alloc] |
| 337 initWithFrame:NSMakeRect(0, | 371 initWithFrame:NSMakeRect(0, |
| 338 NSMaxY([window_view bounds]) - | 372 NSMaxY([window_view bounds]) - |
| 339 kTitlebarBackgroundViewPaintHeight, | 373 kTitlebarBackgroundViewPaintHeight, |
| 340 NSWidth([window_view bounds]), | 374 NSWidth([window_view bounds]), |
| 341 kTitlebarBackgroundViewPaintHeight)]); | 375 kTitlebarBackgroundViewPaintHeight)]); |
| 342 [titlebar_background_view_ | 376 [titlebar_background_view_ |
| 343 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; | 377 setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; |
| 344 [window_view addSubview:titlebar_background_view_ | |
| 345 positioned:NSWindowBelow | |
| 346 relativeTo:nil]; | |
| 347 [titlebar_background_view_ | 378 [titlebar_background_view_ |
| 348 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) | 379 setColor:gfx::SkColorToSRGBNSColor(active_frame_color_) |
| 349 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; | 380 inactiveColor:gfx::SkColorToSRGBNSColor(inactive_frame_color_)]; |
| 381 |
| 382 Class titlebar_class = NSClassFromString(@"NSTitlebarAccessoryViewController
"); |
| 383 if (titlebar_class) { |
| 384 CGFloat height = 30; |
| 385 base::scoped_nsobject<NSView> container_view( |
| 386 [[NSView alloc] initWithFrame:NSMakeRect(0, NSMaxY([window_view bounds
]) - height, NSWidth([window_view bounds]), height)]); |
| 387 [titlebar_background_view_ setFrameOrigin:NSMakePoint(0, 0)]; |
| 388 [container_view addSubview: titlebar_background_view_]; |
| 389 titlebar_accessory_view_controller_.reset([[titlebar_class alloc] init]); |
| 390 [titlebar_accessory_view_controller_ setView:container_view]; |
| 391 [titlebar_accessory_view_controller_ setLayoutAttribute:2]; |
| 392 |
| 393 CGFloat window_control_view_y = floor(height - 20) / 2; |
| 394 base::scoped_nsobject<WindowControlView> window_control_view( |
| 395 [[WindowControlView alloc] initWithFrame:NSMakeRect(1, window_control_
view_y, 60, 20)]); |
| 396 [container_view addSubview:window_control_view]; |
| 397 [window_control_view setupTrackingArea]; |
| 398 |
| 399 CGFloat closeButtonX = 5; |
| 400 CGFloat miniButtonX = 25; |
| 401 CGFloat zoomButtonX = 45; |
| 402 |
| 403 NSUInteger styleMask = GetWindowStyleMask(); |
| 404 NSButton* closeButton = [NSWindow standardWindowButton:NSWindowCloseButton |
| 405 forStyleMask:styleMask]; |
| 406 // Vertically center the buttons in the tab strip. |
| 407 CGFloat buttonY = floor((20 - NSHeight([closeButton bounds])) / 2); |
| 408 [closeButton setFrameOrigin:NSMakePoint(closeButtonX, buttonY)]; |
| 409 [window_control_view addSubview:closeButton]; |
| 410 |
| 411 NSButton* miniaturizeButton = |
| 412 [NSWindow standardWindowButton:NSWindowMiniaturizeButton |
| 413 forStyleMask:styleMask]; |
| 414 [miniaturizeButton setFrameOrigin:NSMakePoint(miniButtonX, buttonY)]; |
| 415 [window_control_view addSubview:miniaturizeButton]; |
| 416 |
| 417 NSButton* zoomButton = |
| 418 [NSWindow standardWindowButton:NSWindowZoomButton |
| 419 forStyleMask:styleMask]; |
| 420 [window_control_view addSubview:zoomButton]; |
| 421 [zoomButton setFrameOrigin:NSMakePoint(zoomButtonX, buttonY)]; |
| 422 |
| 423 [window addTitlebarAccessoryViewController:titlebar_accessory_view_control
ler_]; |
| 424 } else { |
| 425 [window_view addSubview:titlebar_background_view_ |
| 426 positioned:NSWindowBelow |
| 427 relativeTo:nil]; |
| 428 } |
| 350 } | 429 } |
| 351 | 430 |
| 352 if (base::mac::IsOSSnowLeopard() && | 431 if (base::mac::IsOSSnowLeopard() && |
| 353 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 432 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
| 354 [window setBottomCornerRounded:NO]; | 433 [window setBottomCornerRounded:NO]; |
| 355 | 434 |
| 356 if (params.always_on_top) | 435 if (params.always_on_top) |
| 357 [window setLevel:AlwaysOnTopWindowLevel()]; | 436 [window setLevel:AlwaysOnTopWindowLevel()]; |
| 358 InitCollectionBehavior(window); | 437 InitCollectionBehavior(window); |
| 359 | 438 |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 923 |
| 845 void NativeAppWindowCocoa::WindowDidMiniaturize() { | 924 void NativeAppWindowCocoa::WindowDidMiniaturize() { |
| 846 app_window_->OnNativeWindowChanged(); | 925 app_window_->OnNativeWindowChanged(); |
| 847 } | 926 } |
| 848 | 927 |
| 849 void NativeAppWindowCocoa::WindowDidDeminiaturize() { | 928 void NativeAppWindowCocoa::WindowDidDeminiaturize() { |
| 850 app_window_->OnNativeWindowChanged(); | 929 app_window_->OnNativeWindowChanged(); |
| 851 } | 930 } |
| 852 | 931 |
| 853 void NativeAppWindowCocoa::WindowDidEnterFullscreen() { | 932 void NativeAppWindowCocoa::WindowDidEnterFullscreen() { |
| 933 if (titlebar_accessory_view_controller_) |
| 934 [window() removeTitlebarAccessoryViewControllerAtIndex:0]; |
| 854 is_fullscreen_ = true; | 935 is_fullscreen_ = true; |
| 855 app_window_->OSFullscreen(); | 936 app_window_->OSFullscreen(); |
| 856 app_window_->OnNativeWindowChanged(); | 937 app_window_->OnNativeWindowChanged(); |
| 857 } | 938 } |
| 858 | 939 |
| 940 void NativeAppWindowCocoa::WindowWillExitFullscreen() { |
| 941 if (titlebar_accessory_view_controller_) |
| 942 [window() addTitlebarAccessoryViewController:titlebar_accessory_view_control
ler_]; |
| 943 } |
| 944 |
| 859 void NativeAppWindowCocoa::WindowDidExitFullscreen() { | 945 void NativeAppWindowCocoa::WindowDidExitFullscreen() { |
| 860 is_fullscreen_ = false; | 946 is_fullscreen_ = false; |
| 861 if (!shows_fullscreen_controls_) | 947 if (!shows_fullscreen_controls_) |
| 862 SetFullScreenCollectionBehavior(window(), false); | 948 SetFullScreenCollectionBehavior(window(), false); |
| 863 | 949 |
| 864 app_window_->Restore(); | 950 app_window_->Restore(); |
| 865 app_window_->OnNativeWindowChanged(); | 951 app_window_->OnNativeWindowChanged(); |
| 866 } | 952 } |
| 867 | 953 |
| 868 void NativeAppWindowCocoa::WindowWillZoom() { | 954 void NativeAppWindowCocoa::WindowWillZoom() { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 } | 1059 } |
| 974 | 1060 |
| 975 void NativeAppWindowCocoa::UpdateRestoredBounds() { | 1061 void NativeAppWindowCocoa::UpdateRestoredBounds() { |
| 976 if (IsRestored(*this)) | 1062 if (IsRestored(*this)) |
| 977 restored_bounds_ = [window() frame]; | 1063 restored_bounds_ = [window() frame]; |
| 978 } | 1064 } |
| 979 | 1065 |
| 980 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { | 1066 void NativeAppWindowCocoa::HideWithoutMarkingHidden() { |
| 981 [window() orderOut:window_controller_]; | 1067 [window() orderOut:window_controller_]; |
| 982 } | 1068 } |
| OLD | NEW |