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

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

Issue 1146873002: [MacViews] Enable dragging a window by its caption/draggable areas. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove CocoaNonClientDragMaskView, change BridgedContentView instead. Remove CGEventTap implementat… Created 5 years, 7 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 107896f931f200368571f936db5dd58cc4eebeb7..2360d70cce40f40e7d46a162da51ab302120b5ec 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -10,6 +10,7 @@
#include "base/mac/mac_util.h"
#import "base/mac/sdk_forward_declarations.h"
#include "base/thread_task_runner_handle.h"
+#include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/base/ui_base_switches_util.h"
@@ -19,6 +20,7 @@
#import "ui/gfx/mac/nswindow_frame_controls.h"
#include "ui/gfx/screen.h"
#import "ui/views/cocoa/cocoa_mouse_capture.h"
+#import "ui/views/cocoa/cocoa_non_client_drag.h"
#import "ui/views/cocoa/bridged_content_view.h"
#import "ui/views/cocoa/views_nswindow_delegate.h"
#import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
@@ -92,6 +94,7 @@ gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize(
BridgedNativeWidget::BridgedNativeWidget(NativeWidgetMac* parent)
: native_widget_mac_(parent),
+ non_client_drag_(new CocoaNonClientDrag()),
tapted 2015/05/20 07:18:15 My suggestion: ditch the reference counting and in
jackhou1 2015/05/22 02:49:16 Moved all code to bridged_native_widget.mm.
focus_manager_(nullptr),
widget_type_(Widget::InitParams::TYPE_WINDOW), // Updated in Init().
parent_(nullptr),
@@ -522,6 +525,46 @@ void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) {
}
}
+bool BridgedNativeWidget::OnWindowWillReceiveLeftMouseDown(
+ NSPoint location_in_window) {
+ BridgedContentView* content_view = [window_ contentView];
tapted 2015/05/20 07:18:15 nit: can just use bridged_view_. I think this will
jackhou1 2015/05/22 02:49:16 Done.
+ bool was_draggable = [content_view mouseDownCanMoveWindow];
+ gfx::Point point(location_in_window.x,
+ NSHeight([window_ frame]) - location_in_window.y);
tapted 2015/05/20 07:18:17 is this the right thing to flip in? Normally Widge
jackhou1 2015/05/22 02:49:16 We want to first flip this to a gfx::Point in the
tapted 2015/05/22 04:03:11 I guess so long as it's not out by the size of the
+ bool draggable = native_widget_mac()->GetWidget()->GetNonClientComponent(
tapted 2015/05/20 07:18:15 nit: maybe draggable -> should_move_window (I thin
jackhou1 2015/05/22 02:49:16 Done.
+ point) == HTCAPTION;
+ LOG(INFO) << "OnWindowWillReceiveLeftMouseDown " << location_in_window.x
+ << ", " << location_in_window.y << " " << was_draggable << " "
+ << draggable;
+
+ if (was_draggable) {
tapted 2015/05/20 07:18:15 nit: move to the top of the function? i.e. if (!b
jackhou1 2015/05/22 02:49:16 Done.
+ // This is a re-post, the movement has already completed, so we can make the
tapted 2015/05/20 07:18:16 completed -> started? (i.e. I think we are still
jackhou1 2015/05/22 02:49:16 Done.
+ // window non-draggable again.
+ [content_view setMouseDownCanMoveWindow:NO];
+ // AppKit will not update it's cache of mouseDownCanMoveWindow unless
+ // something changes.
tapted 2015/05/20 07:18:17 is there a private method we could poke to trigger
jackhou1 2015/05/22 02:49:16 [NSThemeFrame _resetDragMargins] does something bu
+ base::scoped_nsobject<NSView> temp_view(
+ [[NSView alloc] initWithFrame:[content_view bounds]]);
+ [content_view addSubview:temp_view];
+ [temp_view removeFromSuperview];
+ return false;
+ }
+
+ if (draggable) {
+ // Make the window draggable, then return true to repost the event.
+ [content_view setMouseDownCanMoveWindow:YES];
+ // AppKit will not update it's cache of mouseDownCanMoveWindow unless
+ // something changes.
+ base::scoped_nsobject<NSView> temp_view(
+ [[NSView alloc] initWithFrame:[content_view bounds]]);
+ [content_view addSubview:temp_view];
+ [temp_view removeFromSuperview];
+ return true;
+ }
+
+ return false;
+}
+
void BridgedNativeWidget::OnSizeConstraintsChanged() {
NSWindow* window = ns_window();
Widget* widget = native_widget_mac()->GetWidget();

Powered by Google App Engine
This is Rietveld 408576698