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 #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 Loading... | |
356 // called and the window is still open. Usually, -[NSWindow close] would | 356 // called and the window is still open. Usually, -[NSWindow close] would |
357 // synchronously call OnWindowWillClose() which removes the delegate and | 357 // synchronously call OnWindowWillClose() which removes the delegate and |
358 // notifies NativeWidgetMac, which then calls this with a nil delegate. | 358 // notifies NativeWidgetMac, which then calls this with a nil delegate. |
359 // For other teardown flows (e.g. Widget::WIDGET_OWNS_NATIVE_WIDGET or | 359 // For other teardown flows (e.g. Widget::WIDGET_OWNS_NATIVE_WIDGET or |
360 // Widget::CloseNow()) the delegate must first be cleared to avoid AppKit | 360 // Widget::CloseNow()) the delegate must first be cleared to avoid AppKit |
361 // calling back into the bridge. This means OnWindowWillClose() needs to be | 361 // calling back into the bridge. This means OnWindowWillClose() needs to be |
362 // invoked manually, which is done below. | 362 // invoked manually, which is done below. |
363 // Note that if the window has children it can't be closed until the | 363 // Note that if the window has children it can't be closed until the |
364 // children are gone, but removing child windows calls into AppKit for the | 364 // children are gone, but removing child windows calls into AppKit for the |
365 // parent window, so the delegate must be cleared first. | 365 // parent window, so the delegate must be cleared first. |
366 [window_ setDelegate:nil]; | 366 [window_ setDelegate:nil]; |
karandeepb
2016/06/24 05:34:36
Is setting the delegate to nil so early really nec
| |
367 close_window = true; | 367 close_window = true; |
368 } | 368 } |
369 | 369 |
370 RemoveOrDestroyChildren(); | 370 RemoveOrDestroyChildren(); |
371 DCHECK(child_windows_.empty()); | 371 DCHECK(child_windows_.empty()); |
372 SetFocusManager(nullptr); | 372 SetFocusManager(nullptr); |
373 SetRootView(nullptr); | 373 SetRootView(nullptr); |
374 DestroyCompositor(); | 374 DestroyCompositor(); |
375 | 375 |
376 if (close_window) { | 376 if (close_window) { |
377 OnWindowWillClose(); | 377 OnWindowWillClose(); |
378 [window_ close]; | 378 [window_ close]; |
karandeepb
2016/06/24 05:34:36
This does not do a [window_ orderOut:nil] like in
| |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window, | 382 void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window, |
383 const Widget::InitParams& params) { | 383 const Widget::InitParams& params) { |
384 widget_type_ = params.type; | 384 widget_type_ = params.type; |
385 | 385 |
386 DCHECK(!window_); | 386 DCHECK(!window_); |
387 window_.swap(window); | 387 window_.swap(window); |
388 [window_ setDelegate:window_delegate_]; | 388 [window_ setDelegate:window_delegate_]; |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 void* BridgedNativeWidget::GetNativeWindowProperty(const char* name) const { | 667 void* BridgedNativeWidget::GetNativeWindowProperty(const char* name) const { |
668 NSString* key = [NSString stringWithUTF8String:name]; | 668 NSString* key = [NSString stringWithUTF8String:name]; |
669 return [[GetWindowProperties() objectForKey:key] pointerValue]; | 669 return [[GetWindowProperties() objectForKey:key] pointerValue]; |
670 } | 670 } |
671 | 671 |
672 void BridgedNativeWidget::SetCursor(NSCursor* cursor) { | 672 void BridgedNativeWidget::SetCursor(NSCursor* cursor) { |
673 [window_delegate_ setCursor:cursor]; | 673 [window_delegate_ setCursor:cursor]; |
674 } | 674 } |
675 | 675 |
676 void BridgedNativeWidget::OnWindowWillClose() { | 676 void BridgedNativeWidget::OnWindowWillClose() { |
677 // Ensure BridgedNativeWidget does not have capture, otherwise | |
678 // OnMouseCaptureLost() may reference a deleted |native_widget_mac_| when | |
679 // called via ~CocoaMouseCapture() upon the destruction of |mouse_capture_|. | |
680 // See crbug.com/622201. Also we do this before setting the delegate to nil, | |
681 // because this may lead to callbacks to bridge which rely on a valid | |
682 // delegate. | |
683 ReleaseCapture(); | |
684 | |
677 if (parent_) { | 685 if (parent_) { |
678 parent_->RemoveChildWindow(this); | 686 parent_->RemoveChildWindow(this); |
679 parent_ = nullptr; | 687 parent_ = nullptr; |
680 } | 688 } |
681 [window_ setDelegate:nil]; | 689 [window_ setDelegate:nil]; |
682 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; | 690 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; |
683 native_widget_mac_->OnWindowWillClose(); | 691 native_widget_mac_->OnWindowWillClose(); |
684 } | 692 } |
685 | 693 |
686 void BridgedNativeWidget::OnFullscreenTransitionStart( | 694 void BridgedNativeWidget::OnFullscreenTransitionStart( |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 // If arriving via SetVisible(), |wants_to_be_visible_| should already be set. | 796 // If arriving via SetVisible(), |wants_to_be_visible_| should already be set. |
789 // If made visible externally (e.g. Cmd+H), just roll with it. Don't try (yet) | 797 // If made visible externally (e.g. Cmd+H), just roll with it. Don't try (yet) |
790 // to distinguish being *hidden* externally from being hidden by a parent | 798 // to distinguish being *hidden* externally from being hidden by a parent |
791 // window - we might not need that. | 799 // window - we might not need that. |
792 if (window_visible_) { | 800 if (window_visible_) { |
793 wants_to_be_visible_ = true; | 801 wants_to_be_visible_ = true; |
794 | 802 |
795 if (parent_) | 803 if (parent_) |
796 [parent_->GetNSWindow() addChildWindow:window_ ordered:NSWindowAbove]; | 804 [parent_->GetNSWindow() addChildWindow:window_ ordered:NSWindowAbove]; |
797 } else { | 805 } else { |
798 mouse_capture_.reset(); // Capture on hidden windows is not permitted. | 806 ReleaseCapture(); // Capture on hidden windows is not permitted. |
799 | 807 |
800 // When becoming invisible, remove the entry in any parent's childWindow | 808 // When becoming invisible, remove the entry in any parent's childWindow |
801 // list. Cocoa's childWindow management breaks down when child windows are | 809 // list. Cocoa's childWindow management breaks down when child windows are |
802 // hidden. | 810 // hidden. |
803 if (parent_) | 811 if (parent_) |
804 [parent_->GetNSWindow() removeChildWindow:window_]; | 812 [parent_->GetNSWindow() removeChildWindow:window_]; |
805 } | 813 } |
806 | 814 |
807 // TODO(tapted): Investigate whether we want this for Mac. This is what Aura | 815 // TODO(tapted): Investigate whether we want this for Mac. This is what Aura |
808 // does, and it is what tests expect. However, because layer drawing is | 816 // does, and it is what tests expect. However, because layer drawing is |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1345 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1353 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
1346 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1354 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
1347 // changes. Previously we tried adding an NSView and removing it, but for some | 1355 // changes. Previously we tried adding an NSView and removing it, but for some |
1348 // reason it required reposting the mouse-down event, and didn't always work. | 1356 // reason it required reposting the mouse-down event, and didn't always work. |
1349 // Calling the below seems to be an effective solution. | 1357 // Calling the below seems to be an effective solution. |
1350 [window_ setMovableByWindowBackground:NO]; | 1358 [window_ setMovableByWindowBackground:NO]; |
1351 [window_ setMovableByWindowBackground:YES]; | 1359 [window_ setMovableByWindowBackground:YES]; |
1352 } | 1360 } |
1353 | 1361 |
1354 } // namespace views | 1362 } // namespace views |
OLD | NEW |