Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: ui/views/cocoa/bridged_native_widget.mm

Issue 1109493002: [MacViews] Fix behavior of non-resizable windows in fullscreen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't build nswindow_fullscreen_notification_waiter.mm on IOS. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 in_fullscreen_transition_ = true; 379 in_fullscreen_transition_ = true;
380 380
381 // If going into fullscreen, store an answer for GetRestoredBounds(). 381 // If going into fullscreen, store an answer for GetRestoredBounds().
382 if (target_fullscreen_state) 382 if (target_fullscreen_state)
383 bounds_before_fullscreen_ = gfx::ScreenRectFromNSRect([window_ frame]); 383 bounds_before_fullscreen_ = gfx::ScreenRectFromNSRect([window_ frame]);
384 } 384 }
385 385
386 void BridgedNativeWidget::OnFullscreenTransitionComplete( 386 void BridgedNativeWidget::OnFullscreenTransitionComplete(
387 bool actual_fullscreen_state) { 387 bool actual_fullscreen_state) {
388 in_fullscreen_transition_ = false; 388 in_fullscreen_transition_ = false;
389 if (target_fullscreen_state_ == actual_fullscreen_state) 389
390 if (target_fullscreen_state_ == actual_fullscreen_state) {
391 // Ensure constraints are re-applied when completing a transition.
392 OnSizeConstraintsChanged();
390 return; 393 return;
394 }
391 395
392 // First update to reflect reality so that OnTargetFullscreenStateChanged() 396 // First update to reflect reality so that OnTargetFullscreenStateChanged()
393 // expects the change. 397 // expects the change.
394 target_fullscreen_state_ = actual_fullscreen_state; 398 target_fullscreen_state_ = actual_fullscreen_state;
395 ToggleDesiredFullscreenState(); 399 ToggleDesiredFullscreenState();
396 400
397 // Usually ToggleDesiredFullscreenState() sets |in_fullscreen_transition_| via 401 // Usually ToggleDesiredFullscreenState() sets |in_fullscreen_transition_| via
398 // OnFullscreenTransitionStart(). When it does not, it means Cocoa ignored the 402 // OnFullscreenTransitionStart(). When it does not, it means Cocoa ignored the
399 // toggleFullScreen: request. This can occur when the fullscreen transition 403 // toggleFullScreen: request. This can occur when the fullscreen transition
400 // fails and Cocoa is *about* to send windowDidFailToEnterFullScreen:. 404 // fails and Cocoa is *about* to send windowDidFailToEnterFullScreen:.
(...skipping 22 matching lines...) Expand all
423 // of relying on AppKit to do it, and not worry that OnVisibilityChanged() 427 // of relying on AppKit to do it, and not worry that OnVisibilityChanged()
424 // won't be called for externally triggered fullscreen requests. 428 // won't be called for externally triggered fullscreen requests.
425 if (!window_visible_) 429 if (!window_visible_)
426 SetVisibilityState(SHOW_INACTIVE); 430 SetVisibilityState(SHOW_INACTIVE);
427 431
428 if (base::mac::IsOSSnowLeopard()) { 432 if (base::mac::IsOSSnowLeopard()) {
429 NOTIMPLEMENTED(); 433 NOTIMPLEMENTED();
430 return; // TODO(tapted): Implement this for Snow Leopard. 434 return; // TODO(tapted): Implement this for Snow Leopard.
431 } 435 }
432 436
433 // Since fullscreen requests are ignored if the collection behavior does not 437 // Enable fullscreen collection behavior because:
434 // allow it, save the collection behavior and restore it after. 438 // 1: -[NSWindow toggleFullscreen:] would otherwise be ignored,
435 NSWindowCollectionBehavior behavior = [window_ collectionBehavior]; 439 // 2: the fullscreen button must be enabled so the user can leave fullscreen.
436 [window_ setCollectionBehavior:behavior | 440 // This will be reset when a transition out of fullscreen completes.
437 NSWindowCollectionBehaviorFullScreenPrimary]; 441 gfx::SetNSWindowCanFullscreen(window_, true);
442
438 [window_ toggleFullScreen:nil]; 443 [window_ toggleFullScreen:nil];
439 [window_ setCollectionBehavior:behavior];
440 } 444 }
441 445
442 void BridgedNativeWidget::OnSizeChanged() { 446 void BridgedNativeWidget::OnSizeChanged() {
443 gfx::Size new_size = GetClientAreaSize(); 447 gfx::Size new_size = GetClientAreaSize();
444 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size); 448 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size);
445 if (layer()) 449 if (layer())
446 UpdateLayerProperties(); 450 UpdateLayerProperties();
447 } 451 }
448 452
449 void BridgedNativeWidget::OnVisibilityChanged() { 453 void BridgedNativeWidget::OnVisibilityChanged() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 widget->OnNativeFocus(); 518 widget->OnNativeFocus();
515 widget->GetFocusManager()->RestoreFocusedView(); 519 widget->GetFocusManager()->RestoreFocusedView();
516 } else { 520 } else {
517 widget->OnNativeBlur(); 521 widget->OnNativeBlur();
518 widget->GetFocusManager()->StoreFocusedView(true); 522 widget->GetFocusManager()->StoreFocusedView(true);
519 } 523 }
520 } 524 }
521 } 525 }
522 526
523 void BridgedNativeWidget::OnSizeConstraintsChanged() { 527 void BridgedNativeWidget::OnSizeConstraintsChanged() {
524 NSWindow* window = ns_window(); 528 // Don't modify the size constraints or fullscreen collection behavior while
529 // in fullscreen or during a transition. OnFullscreenTransitionComplete will
530 // reset these after leaving fullscreen.
531 if (target_fullscreen_state_ || in_fullscreen_transition_)
532 return;
533
525 Widget* widget = native_widget_mac()->GetWidget(); 534 Widget* widget = native_widget_mac()->GetWidget();
526 gfx::Size min_size = widget->GetMinimumSize(); 535 gfx::Size min_size = widget->GetMinimumSize();
527 gfx::Size max_size = widget->GetMaximumSize(); 536 gfx::Size max_size = widget->GetMaximumSize();
528 bool is_resizable = widget->widget_delegate()->CanResize(); 537 bool is_resizable = widget->widget_delegate()->CanResize();
529 bool shows_resize_controls = 538 bool shows_resize_controls =
530 is_resizable && (min_size.IsEmpty() || min_size != max_size); 539 is_resizable && (min_size.IsEmpty() || min_size != max_size);
531 bool shows_fullscreen_controls = 540 bool shows_fullscreen_controls =
532 is_resizable && widget->widget_delegate()->CanMaximize(); 541 is_resizable && widget->widget_delegate()->CanMaximize();
533 542
534 gfx::ApplyNSWindowSizeConstraints(window, min_size, max_size, 543 gfx::ApplyNSWindowSizeConstraints(window_, min_size, max_size,
535 shows_resize_controls, 544 shows_resize_controls,
536 shows_fullscreen_controls); 545 shows_fullscreen_controls);
537 } 546 }
538 547
539 InputMethod* BridgedNativeWidget::CreateInputMethod() { 548 InputMethod* BridgedNativeWidget::CreateInputMethod() {
540 if (switches::IsTextInputFocusManagerEnabled()) 549 if (switches::IsTextInputFocusManagerEnabled())
541 return new NullInputMethod(); 550 return new NullInputMethod();
542 551
543 return new InputMethodBridge(this, GetHostInputMethod(), true); 552 return new InputMethodBridge(this, GetHostInputMethod(), true);
544 } 553 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 window_, &kWindowPropertiesKey); 841 window_, &kWindowPropertiesKey);
833 if (!properties) { 842 if (!properties) {
834 properties = [NSMutableDictionary dictionary]; 843 properties = [NSMutableDictionary dictionary];
835 objc_setAssociatedObject(window_, &kWindowPropertiesKey, 844 objc_setAssociatedObject(window_, &kWindowPropertiesKey,
836 properties, OBJC_ASSOCIATION_RETAIN); 845 properties, OBJC_ASSOCIATION_RETAIN);
837 } 846 }
838 return properties; 847 return properties;
839 } 848 }
840 849
841 } // namespace views 850 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698