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