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

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

Issue 2090003002: MacViews: Explicitly release mouse capture in BridgedNativeWidget::OnWindowWillClose(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix trybots. Don't run tests on Mus. Created 4 years, 6 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 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
OLDNEW
« no previous file with comments | « no previous file | ui/views/widget/widget_interactive_uitest.cc » ('j') | ui/views/widget/widget_interactive_uitest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698