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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 in_fullscreen_transition_ = true; | 381 in_fullscreen_transition_ = true; |
382 | 382 |
383 // If going into fullscreen, store an answer for GetRestoredBounds(). | 383 // If going into fullscreen, store an answer for GetRestoredBounds(). |
384 if (target_fullscreen_state) | 384 if (target_fullscreen_state) |
385 bounds_before_fullscreen_ = gfx::ScreenRectFromNSRect([window_ frame]); | 385 bounds_before_fullscreen_ = gfx::ScreenRectFromNSRect([window_ frame]); |
386 } | 386 } |
387 | 387 |
388 void BridgedNativeWidget::OnFullscreenTransitionComplete( | 388 void BridgedNativeWidget::OnFullscreenTransitionComplete( |
389 bool actual_fullscreen_state) { | 389 bool actual_fullscreen_state) { |
390 in_fullscreen_transition_ = false; | 390 in_fullscreen_transition_ = false; |
391 if (target_fullscreen_state_ == actual_fullscreen_state) | 391 |
| 392 if (target_fullscreen_state_ == actual_fullscreen_state) { |
| 393 // Ensure constraints are re-applied when completing a transition. |
| 394 OnSizeConstraintsChanged(); |
392 return; | 395 return; |
| 396 } |
393 | 397 |
394 // First update to reflect reality so that OnTargetFullscreenStateChanged() | 398 // First update to reflect reality so that OnTargetFullscreenStateChanged() |
395 // expects the change. | 399 // expects the change. |
396 target_fullscreen_state_ = actual_fullscreen_state; | 400 target_fullscreen_state_ = actual_fullscreen_state; |
397 ToggleDesiredFullscreenState(); | 401 ToggleDesiredFullscreenState(); |
398 | 402 |
399 // Usually ToggleDesiredFullscreenState() sets |in_fullscreen_transition_| via | 403 // Usually ToggleDesiredFullscreenState() sets |in_fullscreen_transition_| via |
400 // OnFullscreenTransitionStart(). When it does not, it means Cocoa ignored the | 404 // OnFullscreenTransitionStart(). When it does not, it means Cocoa ignored the |
401 // toggleFullScreen: request. This can occur when the fullscreen transition | 405 // toggleFullScreen: request. This can occur when the fullscreen transition |
402 // fails and Cocoa is *about* to send windowDidFailToEnterFullScreen:. | 406 // fails and Cocoa is *about* to send windowDidFailToEnterFullScreen:. |
(...skipping 22 matching lines...) Expand all Loading... |
425 // of relying on AppKit to do it, and not worry that OnVisibilityChanged() | 429 // of relying on AppKit to do it, and not worry that OnVisibilityChanged() |
426 // won't be called for externally triggered fullscreen requests. | 430 // won't be called for externally triggered fullscreen requests. |
427 if (!window_visible_) | 431 if (!window_visible_) |
428 SetVisibilityState(SHOW_INACTIVE); | 432 SetVisibilityState(SHOW_INACTIVE); |
429 | 433 |
430 if (base::mac::IsOSSnowLeopard()) { | 434 if (base::mac::IsOSSnowLeopard()) { |
431 NOTIMPLEMENTED(); | 435 NOTIMPLEMENTED(); |
432 return; // TODO(tapted): Implement this for Snow Leopard. | 436 return; // TODO(tapted): Implement this for Snow Leopard. |
433 } | 437 } |
434 | 438 |
435 // Since fullscreen requests are ignored if the collection behavior does not | 439 // Enable fullscreen collection behavior because: |
436 // allow it, save the collection behavior and restore it after. | 440 // 1: -[NSWindow toggleFullscreen:] would otherwise be ignored, |
437 NSWindowCollectionBehavior behavior = [window_ collectionBehavior]; | 441 // 2: the fullscreen button must be enabled so the user can leave fullscreen. |
438 [window_ setCollectionBehavior:behavior | | 442 // This will be reset when a transition out of fullscreen completes. |
439 NSWindowCollectionBehaviorFullScreenPrimary]; | 443 gfx::SetNSWindowCanFullscreen(window_, true); |
| 444 |
440 [window_ toggleFullScreen:nil]; | 445 [window_ toggleFullScreen:nil]; |
441 [window_ setCollectionBehavior:behavior]; | |
442 } | 446 } |
443 | 447 |
444 void BridgedNativeWidget::OnSizeChanged() { | 448 void BridgedNativeWidget::OnSizeChanged() { |
445 gfx::Size new_size = GetClientAreaSize(); | 449 gfx::Size new_size = GetClientAreaSize(); |
446 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size); | 450 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size); |
447 if (layer()) | 451 if (layer()) |
448 UpdateLayerProperties(); | 452 UpdateLayerProperties(); |
449 } | 453 } |
450 | 454 |
451 void BridgedNativeWidget::OnVisibilityChanged() { | 455 void BridgedNativeWidget::OnVisibilityChanged() { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 widget->OnNativeFocus(); | 520 widget->OnNativeFocus(); |
517 widget->GetFocusManager()->RestoreFocusedView(); | 521 widget->GetFocusManager()->RestoreFocusedView(); |
518 } else { | 522 } else { |
519 widget->OnNativeBlur(); | 523 widget->OnNativeBlur(); |
520 widget->GetFocusManager()->StoreFocusedView(true); | 524 widget->GetFocusManager()->StoreFocusedView(true); |
521 } | 525 } |
522 } | 526 } |
523 } | 527 } |
524 | 528 |
525 void BridgedNativeWidget::OnSizeConstraintsChanged() { | 529 void BridgedNativeWidget::OnSizeConstraintsChanged() { |
526 NSWindow* window = ns_window(); | 530 // Don't modify the size constraints or fullscreen collection behavior while |
| 531 // in fullscreen or during a transition. OnFullscreenTransitionComplete will |
| 532 // reset these after leaving fullscreen. |
| 533 if (target_fullscreen_state_ || in_fullscreen_transition_) |
| 534 return; |
| 535 |
527 Widget* widget = native_widget_mac()->GetWidget(); | 536 Widget* widget = native_widget_mac()->GetWidget(); |
528 gfx::Size min_size = widget->GetMinimumSize(); | 537 gfx::Size min_size = widget->GetMinimumSize(); |
529 gfx::Size max_size = widget->GetMaximumSize(); | 538 gfx::Size max_size = widget->GetMaximumSize(); |
530 bool is_resizable = widget->widget_delegate()->CanResize(); | 539 bool is_resizable = widget->widget_delegate()->CanResize(); |
531 bool shows_resize_controls = | 540 bool shows_resize_controls = |
532 is_resizable && (min_size.IsEmpty() || min_size != max_size); | 541 is_resizable && (min_size.IsEmpty() || min_size != max_size); |
533 bool shows_fullscreen_controls = | 542 bool shows_fullscreen_controls = |
534 is_resizable && widget->widget_delegate()->CanMaximize(); | 543 is_resizable && widget->widget_delegate()->CanMaximize(); |
535 | 544 |
536 gfx::ApplyNSWindowSizeConstraints(window, min_size, max_size, | 545 gfx::ApplyNSWindowSizeConstraints(window_, min_size, max_size, |
537 shows_resize_controls, | 546 shows_resize_controls, |
538 shows_fullscreen_controls); | 547 shows_fullscreen_controls); |
539 } | 548 } |
540 | 549 |
541 InputMethod* BridgedNativeWidget::CreateInputMethod() { | 550 InputMethod* BridgedNativeWidget::CreateInputMethod() { |
542 if (switches::IsTextInputFocusManagerEnabled()) | 551 if (switches::IsTextInputFocusManagerEnabled()) |
543 return new NullInputMethod(); | 552 return new NullInputMethod(); |
544 | 553 |
545 return new InputMethodBridge(this, GetHostInputMethod(), true); | 554 return new InputMethodBridge(this, GetHostInputMethod(), true); |
546 } | 555 } |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 window_, &kWindowPropertiesKey); | 858 window_, &kWindowPropertiesKey); |
850 if (!properties) { | 859 if (!properties) { |
851 properties = [NSMutableDictionary dictionary]; | 860 properties = [NSMutableDictionary dictionary]; |
852 objc_setAssociatedObject(window_, &kWindowPropertiesKey, | 861 objc_setAssociatedObject(window_, &kWindowPropertiesKey, |
853 properties, OBJC_ASSOCIATION_RETAIN); | 862 properties, OBJC_ASSOCIATION_RETAIN); |
854 } | 863 } |
855 return properties; | 864 return properties; |
856 } | 865 } |
857 | 866 |
858 } // namespace views | 867 } // namespace views |
OLD | NEW |