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

Side by Side 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 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 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
11 #import "base/mac/sdk_forward_declarations.h" 11 #import "base/mac/sdk_forward_declarations.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "ui/base/hit_test.h"
13 #include "ui/base/ime/input_method.h" 14 #include "ui/base/ime/input_method.h"
14 #include "ui/base/ime/input_method_factory.h" 15 #include "ui/base/ime/input_method_factory.h"
15 #include "ui/base/ui_base_switches_util.h" 16 #include "ui/base/ui_base_switches_util.h"
16 #include "ui/gfx/display.h" 17 #include "ui/gfx/display.h"
17 #include "ui/gfx/geometry/dip_util.h" 18 #include "ui/gfx/geometry/dip_util.h"
18 #import "ui/gfx/mac/coordinate_conversion.h" 19 #import "ui/gfx/mac/coordinate_conversion.h"
19 #import "ui/gfx/mac/nswindow_frame_controls.h" 20 #import "ui/gfx/mac/nswindow_frame_controls.h"
20 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
21 #import "ui/views/cocoa/cocoa_mouse_capture.h" 22 #import "ui/views/cocoa/cocoa_mouse_capture.h"
23 #import "ui/views/cocoa/cocoa_non_client_drag.h"
22 #import "ui/views/cocoa/bridged_content_view.h" 24 #import "ui/views/cocoa/bridged_content_view.h"
23 #import "ui/views/cocoa/views_nswindow_delegate.h" 25 #import "ui/views/cocoa/views_nswindow_delegate.h"
24 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" 26 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
25 #include "ui/views/widget/native_widget_mac.h" 27 #include "ui/views/widget/native_widget_mac.h"
26 #include "ui/views/ime/input_method_bridge.h" 28 #include "ui/views/ime/input_method_bridge.h"
27 #include "ui/views/ime/null_input_method.h" 29 #include "ui/views/ime/null_input_method.h"
28 #include "ui/views/view.h" 30 #include "ui/views/view.h"
29 #include "ui/views/views_delegate.h" 31 #include "ui/views/views_delegate.h"
30 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
31 #include "ui/views/widget/widget_aura_utils.h" 33 #include "ui/views/widget/widget_aura_utils.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 NSWindow* window, 87 NSWindow* window,
86 const gfx::Size& content_size) { 88 const gfx::Size& content_size) {
87 NSRect content_rect = 89 NSRect content_rect =
88 NSMakeRect(0, 0, content_size.width(), content_size.height()); 90 NSMakeRect(0, 0, content_size.width(), content_size.height());
89 NSRect frame_rect = [window frameRectForContentRect:content_rect]; 91 NSRect frame_rect = [window frameRectForContentRect:content_rect];
90 return gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect)); 92 return gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect));
91 } 93 }
92 94
93 BridgedNativeWidget::BridgedNativeWidget(NativeWidgetMac* parent) 95 BridgedNativeWidget::BridgedNativeWidget(NativeWidgetMac* parent)
94 : native_widget_mac_(parent), 96 : native_widget_mac_(parent),
97 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.
95 focus_manager_(nullptr), 98 focus_manager_(nullptr),
96 widget_type_(Widget::InitParams::TYPE_WINDOW), // Updated in Init(). 99 widget_type_(Widget::InitParams::TYPE_WINDOW), // Updated in Init().
97 parent_(nullptr), 100 parent_(nullptr),
98 target_fullscreen_state_(false), 101 target_fullscreen_state_(false),
99 in_fullscreen_transition_(false), 102 in_fullscreen_transition_(false),
100 window_visible_(false), 103 window_visible_(false),
101 wants_to_be_visible_(false) { 104 wants_to_be_visible_(false) {
102 DCHECK(parent); 105 DCHECK(parent);
103 window_delegate_.reset( 106 window_delegate_.reset(
104 [[ViewsNSWindowDelegate alloc] initWithBridgedNativeWidget:this]); 107 [[ViewsNSWindowDelegate alloc] initWithBridgedNativeWidget:this]);
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 if (is_key) { 518 if (is_key) {
516 widget->OnNativeFocus(); 519 widget->OnNativeFocus();
517 widget->GetFocusManager()->RestoreFocusedView(); 520 widget->GetFocusManager()->RestoreFocusedView();
518 } else { 521 } else {
519 widget->OnNativeBlur(); 522 widget->OnNativeBlur();
520 widget->GetFocusManager()->StoreFocusedView(true); 523 widget->GetFocusManager()->StoreFocusedView(true);
521 } 524 }
522 } 525 }
523 } 526 }
524 527
528 bool BridgedNativeWidget::OnWindowWillReceiveLeftMouseDown(
529 NSPoint location_in_window) {
530 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.
531 bool was_draggable = [content_view mouseDownCanMoveWindow];
532 gfx::Point point(location_in_window.x,
533 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
534 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.
535 point) == HTCAPTION;
536 LOG(INFO) << "OnWindowWillReceiveLeftMouseDown " << location_in_window.x
537 << ", " << location_in_window.y << " " << was_draggable << " "
538 << draggable;
539
540 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.
541 // 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.
542 // window non-draggable again.
543 [content_view setMouseDownCanMoveWindow:NO];
544 // AppKit will not update it's cache of mouseDownCanMoveWindow unless
545 // 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
546 base::scoped_nsobject<NSView> temp_view(
547 [[NSView alloc] initWithFrame:[content_view bounds]]);
548 [content_view addSubview:temp_view];
549 [temp_view removeFromSuperview];
550 return false;
551 }
552
553 if (draggable) {
554 // Make the window draggable, then return true to repost the event.
555 [content_view setMouseDownCanMoveWindow:YES];
556 // AppKit will not update it's cache of mouseDownCanMoveWindow unless
557 // something changes.
558 base::scoped_nsobject<NSView> temp_view(
559 [[NSView alloc] initWithFrame:[content_view bounds]]);
560 [content_view addSubview:temp_view];
561 [temp_view removeFromSuperview];
562 return true;
563 }
564
565 return false;
566 }
567
525 void BridgedNativeWidget::OnSizeConstraintsChanged() { 568 void BridgedNativeWidget::OnSizeConstraintsChanged() {
526 NSWindow* window = ns_window(); 569 NSWindow* window = ns_window();
527 Widget* widget = native_widget_mac()->GetWidget(); 570 Widget* widget = native_widget_mac()->GetWidget();
528 gfx::Size min_size = widget->GetMinimumSize(); 571 gfx::Size min_size = widget->GetMinimumSize();
529 gfx::Size max_size = widget->GetMaximumSize(); 572 gfx::Size max_size = widget->GetMaximumSize();
530 bool is_resizable = widget->widget_delegate()->CanResize(); 573 bool is_resizable = widget->widget_delegate()->CanResize();
531 bool shows_resize_controls = 574 bool shows_resize_controls =
532 is_resizable && (min_size.IsEmpty() || min_size != max_size); 575 is_resizable && (min_size.IsEmpty() || min_size != max_size);
533 bool shows_fullscreen_controls = 576 bool shows_fullscreen_controls =
534 is_resizable && widget->widget_delegate()->CanMaximize(); 577 is_resizable && widget->widget_delegate()->CanMaximize();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 window_, &kWindowPropertiesKey); 892 window_, &kWindowPropertiesKey);
850 if (!properties) { 893 if (!properties) {
851 properties = [NSMutableDictionary dictionary]; 894 properties = [NSMutableDictionary dictionary];
852 objc_setAssociatedObject(window_, &kWindowPropertiesKey, 895 objc_setAssociatedObject(window_, &kWindowPropertiesKey,
853 properties, OBJC_ASSOCIATION_RETAIN); 896 properties, OBJC_ASSOCIATION_RETAIN);
854 } 897 }
855 return properties; 898 return properties;
856 } 899 }
857 900
858 } // namespace views 901 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698