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

Unified Diff: ui/views/cocoa/bridged_native_widget.mm

Issue 1747803003: MacViews: Implement Tab Dragging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove crbug.com/518740-fixing code, remove DragAndDrop helpers that are no longer required without… 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/cocoa/bridged_native_widget.mm
diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm
index 1c9560f2e8834aeb19225abd760819145854b361..8d5518c6358f5744c1a58debcb396542482132f4 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -25,6 +25,7 @@
#import "ui/gfx/mac/nswindow_frame_controls.h"
#import "ui/views/cocoa/bridged_content_view.h"
#import "ui/views/cocoa/cocoa_mouse_capture.h"
+#import "ui/views/cocoa/cocoa_window_move_loop.h"
#include "ui/views/cocoa/tooltip_manager_mac.h"
#import "ui/views/cocoa/views_nswindow_delegate.h"
#import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
@@ -615,6 +616,39 @@ bool BridgedNativeWidget::HasCapture() {
return mouse_capture_ && mouse_capture_->IsActive();
}
+Widget::MoveLoopResult BridgedNativeWidget::RunMoveLoop(
+ const gfx::Vector2d& drag_offset) {
+ DCHECK(!HasCapture());
+ DCHECK(!window_move_loop_);
+
+ // RunMoveLoop caller is responsible for updating the window to be under the
+ // mouse, but it does this using possibly outdated coordinate from the mouse
+ // event, and mouse is very likely moved beyound that point.
+
+ // Compensate for mouse drift by shifting the initial mouse position we pass
+ // to CocoaWindowMoveLoop, so as it handles incoming move events the window's
+ // top left corner will be |drag_offset| from the current mouse position.
+
+ const gfx::Rect frame = gfx::ScreenRectFromNSRect([window_ frame]);
+ const gfx::Point mouse_in_screen(frame.x() + drag_offset.x(),
+ frame.y() + drag_offset.y());
+ window_move_loop_.reset(new CocoaWindowMoveLoop(
+ this, gfx::ScreenPointToNSPoint(mouse_in_screen)));
+
+ return window_move_loop_->Run();
+
+ // |this| may be destroyed during the RunLoop, causing it to exit early.
+ // Even if that doesn't happen, CocoaWindowMoveLoop will clean itself up by
+ // calling EndMoveLoop(). So window_move_loop_ will always be null before the
+ // function returns. But don't DCHECK since |this| might not be valid.
+}
+
+void BridgedNativeWidget::EndMoveLoop() {
+ DCHECK(window_move_loop_);
+ window_move_loop_->End();
+ window_move_loop_.reset();
+}
+
void BridgedNativeWidget::SetNativeWindowProperty(const char* name,
void* value) {
NSString* key = [NSString stringWithUTF8String:name];
@@ -733,6 +767,10 @@ void BridgedNativeWidget::OnSizeChanged() {
[bridged_view_ updateWindowMask];
}
+void BridgedNativeWidget::OnPositionChanged() {
+ native_widget_mac_->GetWidget()->OnNativeWidgetMove();
+}
+
void BridgedNativeWidget::OnVisibilityChanged() {
OnVisibilityChangedTo([window_ isVisible]);
}

Powered by Google App Engine
This is Rietveld 408576698