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

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

Issue 2454283002: MacViews: Hide windows before closing. (Closed)
Patch Set: Fix tests. Created 4 years, 1 month 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 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 BridgedNativeWidget::~BridgedNativeWidget() { 356 BridgedNativeWidget::~BridgedNativeWidget() {
357 // The delegate should be cleared already. Note this enforces the precondition 357 // The delegate should be cleared already. Note this enforces the precondition
358 // that -[NSWindow close] is invoked on the hosted window before the 358 // that -[NSWindow close] is invoked on the hosted window before the
359 // destructor is called. 359 // destructor is called.
360 DCHECK(![window_ delegate]); 360 DCHECK(![window_ delegate]);
361 361
362 RemoveOrDestroyChildren(); 362 RemoveOrDestroyChildren();
363 DCHECK(child_windows_.empty()); 363 DCHECK(child_windows_.empty());
364 SetFocusManager(nullptr); 364 SetFocusManager(nullptr);
365 SetRootView(nullptr); 365 SetRootView(nullptr);
366
367 DCHECK(![window_ isVisible]);
366 DestroyCompositor(); 368 DestroyCompositor();
367 } 369 }
368 370
369 void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window, 371 void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window,
370 const Widget::InitParams& params) { 372 const Widget::InitParams& params) {
371 widget_type_ = params.type; 373 widget_type_ = params.type;
372 374
373 DCHECK(!window_); 375 DCHECK(!window_);
374 window_.swap(window); 376 window_.swap(window);
375 [window_ setDelegate:window_delegate_]; 377 [window_ setDelegate:window_delegate_];
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 void* BridgedNativeWidget::GetNativeWindowProperty(const char* name) const { 676 void* BridgedNativeWidget::GetNativeWindowProperty(const char* name) const {
675 NSString* key = [NSString stringWithUTF8String:name]; 677 NSString* key = [NSString stringWithUTF8String:name];
676 return [[GetWindowProperties() objectForKey:key] pointerValue]; 678 return [[GetWindowProperties() objectForKey:key] pointerValue];
677 } 679 }
678 680
679 void BridgedNativeWidget::SetCursor(NSCursor* cursor) { 681 void BridgedNativeWidget::SetCursor(NSCursor* cursor) {
680 [window_delegate_ setCursor:cursor]; 682 [window_delegate_ setCursor:cursor];
681 } 683 }
682 684
683 void BridgedNativeWidget::OnWindowWillClose() { 685 void BridgedNativeWidget::OnWindowWillClose() {
686 // Hide the window before closing. This ensures that destroying the compositor
687 // during the close does not cause a flash, which would be the case if the
688 // window was still visible.
689 SetVisibilityState(HIDE_WINDOW);
690
684 native_widget_mac_->GetWidget()->OnNativeWidgetDestroying(); 691 native_widget_mac_->GetWidget()->OnNativeWidgetDestroying();
685 692
686 // Ensure BridgedNativeWidget does not have capture, otherwise 693 // Ensure BridgedNativeWidget does not have capture, otherwise
687 // OnMouseCaptureLost() may reference a deleted |native_widget_mac_| when 694 // OnMouseCaptureLost() may reference a deleted |native_widget_mac_| when
688 // called via ~CocoaMouseCapture() upon the destruction of |mouse_capture_|. 695 // called via ~CocoaMouseCapture() upon the destruction of |mouse_capture_|.
689 // See crbug.com/622201. Also we do this before setting the delegate to nil, 696 // See crbug.com/622201. Also we do this before setting the delegate to nil,
690 // because this may lead to callbacks to bridge which rely on a valid 697 // because this may lead to callbacks to bridge which rely on a valid
691 // delegate. 698 // delegate.
692 ReleaseCapture(); 699 ReleaseCapture();
693 700
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 [bridged_view_ setMouseDownCanMoveWindow:draggable]; 1385 [bridged_view_ setMouseDownCanMoveWindow:draggable];
1379 // AppKit will not update its cache of mouseDownCanMoveWindow unless something 1386 // AppKit will not update its cache of mouseDownCanMoveWindow unless something
1380 // changes. Previously we tried adding an NSView and removing it, but for some 1387 // changes. Previously we tried adding an NSView and removing it, but for some
1381 // reason it required reposting the mouse-down event, and didn't always work. 1388 // reason it required reposting the mouse-down event, and didn't always work.
1382 // Calling the below seems to be an effective solution. 1389 // Calling the below seems to be an effective solution.
1383 [window_ setMovableByWindowBackground:NO]; 1390 [window_ setMovableByWindowBackground:NO];
1384 [window_ setMovableByWindowBackground:YES]; 1391 [window_ setMovableByWindowBackground:YES];
1385 } 1392 }
1386 1393
1387 } // namespace views 1394 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/widget/native_widget_mac_unittest.mm » ('j') | ui/views/widget/native_widget_mac_unittest.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698