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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #import "base/mac/foundation_util.h" | 12 #import "base/mac/foundation_util.h" |
13 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
14 #import "base/mac/sdk_forward_declarations.h" | 14 #import "base/mac/sdk_forward_declarations.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" | 16 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" |
17 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" | 17 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" |
18 #include "ui/base/hit_test.h" | 18 #include "ui/base/hit_test.h" |
19 #include "ui/base/ime/input_method.h" | 19 #include "ui/base/ime/input_method.h" |
20 #include "ui/base/ime/input_method_factory.h" | 20 #include "ui/base/ime/input_method_factory.h" |
21 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
22 #include "ui/display/screen.h" | 22 #include "ui/display/screen.h" |
23 #include "ui/gfx/geometry/dip_util.h" | 23 #include "ui/gfx/geometry/dip_util.h" |
24 #import "ui/gfx/mac/coordinate_conversion.h" | 24 #import "ui/gfx/mac/coordinate_conversion.h" |
25 #import "ui/gfx/mac/nswindow_frame_controls.h" | 25 #import "ui/gfx/mac/nswindow_frame_controls.h" |
26 #import "ui/views/cocoa/bridged_content_view.h" | 26 #import "ui/views/cocoa/bridged_content_view.h" |
27 #import "ui/views/cocoa/cocoa_mouse_capture.h" | 27 #import "ui/views/cocoa/cocoa_mouse_capture.h" |
| 28 #import "ui/views/cocoa/cocoa_window_move_loop.h" |
28 #include "ui/views/cocoa/tooltip_manager_mac.h" | 29 #include "ui/views/cocoa/tooltip_manager_mac.h" |
29 #import "ui/views/cocoa/views_nswindow_delegate.h" | 30 #import "ui/views/cocoa/views_nswindow_delegate.h" |
30 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" | 31 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" |
31 #include "ui/views/view.h" | 32 #include "ui/views/view.h" |
32 #include "ui/views/views_delegate.h" | 33 #include "ui/views/views_delegate.h" |
33 #include "ui/views/widget/native_widget_mac.h" | 34 #include "ui/views/widget/native_widget_mac.h" |
34 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
35 #include "ui/views/widget/widget_aura_utils.h" | 36 #include "ui/views/widget/widget_aura_utils.h" |
36 #include "ui/views/widget/widget_delegate.h" | 37 #include "ui/views/widget/widget_delegate.h" |
37 | 38 |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 } | 609 } |
609 | 610 |
610 void BridgedNativeWidget::ReleaseCapture() { | 611 void BridgedNativeWidget::ReleaseCapture() { |
611 mouse_capture_.reset(); | 612 mouse_capture_.reset(); |
612 } | 613 } |
613 | 614 |
614 bool BridgedNativeWidget::HasCapture() { | 615 bool BridgedNativeWidget::HasCapture() { |
615 return mouse_capture_ && mouse_capture_->IsActive(); | 616 return mouse_capture_ && mouse_capture_->IsActive(); |
616 } | 617 } |
617 | 618 |
| 619 Widget::MoveLoopResult BridgedNativeWidget::RunMoveLoop( |
| 620 const gfx::Vector2d& drag_offset) { |
| 621 DCHECK(!HasCapture()); |
| 622 DCHECK(!window_move_loop_); |
| 623 |
| 624 // RunMoveLoop caller is responsible for updating the window to be under the |
| 625 // mouse, but it does this using possibly outdated coordinate from the mouse |
| 626 // event, and mouse is very likely moved beyound that point. |
| 627 |
| 628 // Compensate for mouse drift by shifting the initial mouse position we pass |
| 629 // to CocoaWindowMoveLoop, so as it handles incoming move events the window's |
| 630 // top left corner will be |drag_offset| from the current mouse position. |
| 631 |
| 632 const gfx::Rect frame = gfx::ScreenRectFromNSRect([window_ frame]); |
| 633 const gfx::Point mouse_in_screen(frame.x() + drag_offset.x(), |
| 634 frame.y() + drag_offset.y()); |
| 635 window_move_loop_.reset(new CocoaWindowMoveLoop( |
| 636 this, gfx::ScreenPointToNSPoint(mouse_in_screen))); |
| 637 |
| 638 return window_move_loop_->Run(); |
| 639 |
| 640 // |this| may be destroyed during the RunLoop, causing it to exit early. |
| 641 // Even if that doesn't happen, CocoaWindowMoveLoop will clean itself up by |
| 642 // calling EndMoveLoop(). So window_move_loop_ will always be null before the |
| 643 // function returns. But don't DCHECK since |this| might not be valid. |
| 644 } |
| 645 |
| 646 void BridgedNativeWidget::EndMoveLoop() { |
| 647 DCHECK(window_move_loop_); |
| 648 window_move_loop_->End(); |
| 649 window_move_loop_.reset(); |
| 650 } |
| 651 |
618 void BridgedNativeWidget::SetNativeWindowProperty(const char* name, | 652 void BridgedNativeWidget::SetNativeWindowProperty(const char* name, |
619 void* value) { | 653 void* value) { |
620 NSString* key = [NSString stringWithUTF8String:name]; | 654 NSString* key = [NSString stringWithUTF8String:name]; |
621 if (value) { | 655 if (value) { |
622 [GetWindowProperties() setObject:[NSValue valueWithPointer:value] | 656 [GetWindowProperties() setObject:[NSValue valueWithPointer:value] |
623 forKey:key]; | 657 forKey:key]; |
624 } else { | 658 } else { |
625 [GetWindowProperties() removeObjectForKey:key]; | 659 [GetWindowProperties() removeObjectForKey:key]; |
626 } | 660 } |
627 } | 661 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 | 760 |
727 // 10.9 is unable to generate a window shadow from the composited CALayer, so | 761 // 10.9 is unable to generate a window shadow from the composited CALayer, so |
728 // use Quartz. | 762 // use Quartz. |
729 // We don't update the window mask during a live resize, instead it is done | 763 // We don't update the window mask during a live resize, instead it is done |
730 // after the resize is completed in viewDidEndLiveResize: in | 764 // after the resize is completed in viewDidEndLiveResize: in |
731 // BridgedContentView. | 765 // BridgedContentView. |
732 if (base::mac::IsOSMavericksOrEarlier() && ![window_ inLiveResize]) | 766 if (base::mac::IsOSMavericksOrEarlier() && ![window_ inLiveResize]) |
733 [bridged_view_ updateWindowMask]; | 767 [bridged_view_ updateWindowMask]; |
734 } | 768 } |
735 | 769 |
| 770 void BridgedNativeWidget::OnPositionChanged() { |
| 771 native_widget_mac_->GetWidget()->OnNativeWidgetMove(); |
| 772 } |
| 773 |
736 void BridgedNativeWidget::OnVisibilityChanged() { | 774 void BridgedNativeWidget::OnVisibilityChanged() { |
737 OnVisibilityChangedTo([window_ isVisible]); | 775 OnVisibilityChangedTo([window_ isVisible]); |
738 } | 776 } |
739 | 777 |
740 void BridgedNativeWidget::OnVisibilityChangedTo(bool new_visibility) { | 778 void BridgedNativeWidget::OnVisibilityChangedTo(bool new_visibility) { |
741 if (window_visible_ == new_visibility) | 779 if (window_visible_ == new_visibility) |
742 return; | 780 return; |
743 | 781 |
744 window_visible_ = new_visibility; | 782 window_visible_ = new_visibility; |
745 | 783 |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1341 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
1304 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1342 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
1305 // changes. Previously we tried adding an NSView and removing it, but for some | 1343 // changes. Previously we tried adding an NSView and removing it, but for some |
1306 // reason it required reposting the mouse-down event, and didn't always work. | 1344 // reason it required reposting the mouse-down event, and didn't always work. |
1307 // Calling the below seems to be an effective solution. | 1345 // Calling the below seems to be an effective solution. |
1308 [window_ setMovableByWindowBackground:NO]; | 1346 [window_ setMovableByWindowBackground:NO]; |
1309 [window_ setMovableByWindowBackground:YES]; | 1347 [window_ setMovableByWindowBackground:YES]; |
1310 } | 1348 } |
1311 | 1349 |
1312 } // namespace views | 1350 } // namespace views |
OLD | NEW |