Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #import "ui/views/cocoa/bridged_native_widget.h" | 5 #import "ui/views/cocoa/bridged_native_widget.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; | 367 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; |
| 368 native_widget_mac_->OnWindowWillClose(); | 368 native_widget_mac_->OnWindowWillClose(); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void BridgedNativeWidget::OnFullscreenTransitionStart( | 371 void BridgedNativeWidget::OnFullscreenTransitionStart( |
| 372 bool target_fullscreen_state) { | 372 bool target_fullscreen_state) { |
| 373 // Note: This can fail for fullscreen changes started externally, but a user | 373 // Note: This can fail for fullscreen changes started externally, but a user |
| 374 // shouldn't be able to do that if the window is invisible to begin with. | 374 // shouldn't be able to do that if the window is invisible to begin with. |
| 375 DCHECK(window_visible_); | 375 DCHECK(window_visible_); |
| 376 | 376 |
| 377 DCHECK_NE(target_fullscreen_state, target_fullscreen_state_); | |
|
tapted
2015/05/13 06:12:42
I think we can keep this.... see below
jackhou1
2015/05/13 06:53:10
Done.
| |
| 378 target_fullscreen_state_ = target_fullscreen_state; | 377 target_fullscreen_state_ = target_fullscreen_state; |
| 379 in_fullscreen_transition_ = true; | 378 in_fullscreen_transition_ = true; |
| 380 | 379 |
| 381 // If going into fullscreen, store an answer for GetRestoredBounds(). | 380 // If going into fullscreen, store an answer for GetRestoredBounds(). |
| 382 if (target_fullscreen_state) | 381 if (target_fullscreen_state) |
| 383 bounds_before_fullscreen_ = gfx::ScreenRectFromNSRect([window_ frame]); | 382 bounds_before_fullscreen_ = gfx::ScreenRectFromNSRect([window_ frame]); |
| 384 } | 383 } |
| 385 | 384 |
| 386 void BridgedNativeWidget::OnFullscreenTransitionComplete( | 385 void BridgedNativeWidget::OnFullscreenTransitionComplete( |
| 387 bool actual_fullscreen_state) { | 386 bool actual_fullscreen_state) { |
| 388 in_fullscreen_transition_ = false; | 387 in_fullscreen_transition_ = false; |
| 388 | |
| 389 // If window did leave fullscreen, reset the size constraints and collection | |
| 390 // behavior. | |
| 391 if (!actual_fullscreen_state) | |
| 392 OnSizeConstraintsChanged(); | |
|
tapted
2015/05/13 06:12:42
This should only happen if we're staying in this s
jackhou1
2015/05/13 06:53:10
Done.
| |
| 393 | |
| 389 if (target_fullscreen_state_ == actual_fullscreen_state) | 394 if (target_fullscreen_state_ == actual_fullscreen_state) |
| 390 return; | 395 return; |
| 391 | 396 |
| 392 // First update to reflect reality so that OnTargetFullscreenStateChanged() | 397 // First update to reflect reality so that OnTargetFullscreenStateChanged() |
| 393 // expects the change. | 398 // expects the change. |
| 394 target_fullscreen_state_ = actual_fullscreen_state; | 399 target_fullscreen_state_ = actual_fullscreen_state; |
| 395 ToggleDesiredFullscreenState(); | 400 ToggleDesiredFullscreenState(); |
| 396 | 401 |
| 397 // Usually ToggleDesiredFullscreenState() sets |in_fullscreen_transition_| via | 402 // Usually ToggleDesiredFullscreenState() sets |in_fullscreen_transition_| via |
| 398 // OnFullscreenTransitionStart(). When it does not, it means Cocoa ignored the | 403 // OnFullscreenTransitionStart(). When it does not, it means Cocoa ignored the |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 423 // of relying on AppKit to do it, and not worry that OnVisibilityChanged() | 428 // of relying on AppKit to do it, and not worry that OnVisibilityChanged() |
| 424 // won't be called for externally triggered fullscreen requests. | 429 // won't be called for externally triggered fullscreen requests. |
| 425 if (!window_visible_) | 430 if (!window_visible_) |
| 426 SetVisibilityState(SHOW_INACTIVE); | 431 SetVisibilityState(SHOW_INACTIVE); |
| 427 | 432 |
| 428 if (base::mac::IsOSSnowLeopard()) { | 433 if (base::mac::IsOSSnowLeopard()) { |
| 429 NOTIMPLEMENTED(); | 434 NOTIMPLEMENTED(); |
| 430 return; // TODO(tapted): Implement this for Snow Leopard. | 435 return; // TODO(tapted): Implement this for Snow Leopard. |
| 431 } | 436 } |
| 432 | 437 |
| 433 // Since fullscreen requests are ignored if the collection behavior does not | 438 // Before entering fullscreen, and during fullscreen: |
| 434 // allow it, save the collection behavior and restore it after. | 439 // 1: Size constraints must be removed so that the window takes up the entire |
| 435 NSWindowCollectionBehavior behavior = [window_ collectionBehavior]; | 440 // screen. |
| 436 [window_ setCollectionBehavior:behavior | | 441 // 2: Fullscreen collection behavior must be enabled because: |
| 437 NSWindowCollectionBehaviorFullScreenPrimary]; | 442 // a: -[NSWindow toggleFullscreen:] would otherwise be ignored, |
| 443 // b: it enables the fullscreen button so the user can leave fullscreen. | |
| 444 // These will be reset after leaving fullscreen. | |
| 445 if (!([ns_window() styleMask] & NSFullScreenWindowMask)) { | |
| 446 target_fullscreen_state_ = true; | |
|
tapted
2015/05/13 06:12:42
it feels fragile to update target_fullscreen_state
jackhou1
2015/05/13 06:53:10
By bringing back the willUseFullScreenContentSize,
| |
| 447 OnSizeConstraintsChanged(); | |
| 448 } | |
| 438 [window_ toggleFullScreen:nil]; | 449 [window_ toggleFullScreen:nil]; |
| 439 [window_ setCollectionBehavior:behavior]; | |
| 440 } | 450 } |
| 441 | 451 |
| 442 void BridgedNativeWidget::OnSizeChanged() { | 452 void BridgedNativeWidget::OnSizeChanged() { |
| 443 gfx::Size new_size = GetClientAreaSize(); | 453 gfx::Size new_size = GetClientAreaSize(); |
| 444 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size); | 454 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size); |
| 445 if (layer()) | 455 if (layer()) |
| 446 UpdateLayerProperties(); | 456 UpdateLayerProperties(); |
| 447 } | 457 } |
| 448 | 458 |
| 449 void BridgedNativeWidget::OnVisibilityChanged() { | 459 void BridgedNativeWidget::OnVisibilityChanged() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 widget->GetFocusManager()->RestoreFocusedView(); | 525 widget->GetFocusManager()->RestoreFocusedView(); |
| 516 } else { | 526 } else { |
| 517 widget->OnNativeBlur(); | 527 widget->OnNativeBlur(); |
| 518 widget->GetFocusManager()->StoreFocusedView(true); | 528 widget->GetFocusManager()->StoreFocusedView(true); |
| 519 } | 529 } |
| 520 } | 530 } |
| 521 } | 531 } |
| 522 | 532 |
| 523 void BridgedNativeWidget::OnSizeConstraintsChanged() { | 533 void BridgedNativeWidget::OnSizeConstraintsChanged() { |
| 524 NSWindow* window = ns_window(); | 534 NSWindow* window = ns_window(); |
| 535 | |
| 536 // If entering or in fullscreen, remove size constraints so that the window | |
| 537 // fills the screen, and show fullscreen controls so the user can leave. | |
| 538 if (target_fullscreen_state_) { | |
|
tapted
2015/05/13 06:12:42
I think just (at the start, with an appropriate co
jackhou1
2015/05/13 06:53:10
Done.
| |
| 539 gfx::ApplyNSWindowSizeConstraints(window, gfx::Size(), gfx::Size(), true, | |
| 540 true); | |
| 541 return; | |
| 542 } | |
| 543 | |
| 525 Widget* widget = native_widget_mac()->GetWidget(); | 544 Widget* widget = native_widget_mac()->GetWidget(); |
| 526 gfx::Size min_size = widget->GetMinimumSize(); | 545 gfx::Size min_size = widget->GetMinimumSize(); |
| 527 gfx::Size max_size = widget->GetMaximumSize(); | 546 gfx::Size max_size = widget->GetMaximumSize(); |
| 528 bool is_resizable = widget->widget_delegate()->CanResize(); | 547 bool is_resizable = widget->widget_delegate()->CanResize(); |
| 529 bool shows_resize_controls = | 548 bool shows_resize_controls = |
| 530 is_resizable && (min_size.IsEmpty() || min_size != max_size); | 549 is_resizable && (min_size.IsEmpty() || min_size != max_size); |
| 531 bool shows_fullscreen_controls = | 550 bool shows_fullscreen_controls = |
| 532 is_resizable && widget->widget_delegate()->CanMaximize(); | 551 is_resizable && widget->widget_delegate()->CanMaximize(); |
| 533 | 552 |
| 534 gfx::ApplyNSWindowSizeConstraints(window, min_size, max_size, | 553 gfx::ApplyNSWindowSizeConstraints(window, min_size, max_size, |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 window_, &kWindowPropertiesKey); | 851 window_, &kWindowPropertiesKey); |
| 833 if (!properties) { | 852 if (!properties) { |
| 834 properties = [NSMutableDictionary dictionary]; | 853 properties = [NSMutableDictionary dictionary]; |
| 835 objc_setAssociatedObject(window_, &kWindowPropertiesKey, | 854 objc_setAssociatedObject(window_, &kWindowPropertiesKey, |
| 836 properties, OBJC_ASSOCIATION_RETAIN); | 855 properties, OBJC_ASSOCIATION_RETAIN); |
| 837 } | 856 } |
| 838 return properties; | 857 return properties; |
| 839 } | 858 } |
| 840 | 859 |
| 841 } // namespace views | 860 } // namespace views |
| OLD | NEW |