| 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 | 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 Loading... |
| 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()), |
| 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 Loading... |
| 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 bool was_draggable = draggable_; |
| 531 gfx::Point point(location_in_window.x, |
| 532 NSHeight([window_ frame]) - location_in_window.y); |
| 533 draggable_ = native_widget_mac()->GetWidget()->GetNonClientComponent(point) == |
| 534 HTCAPTION; |
| 535 LOG(INFO) << "OnWindowWillReceiveLeftMouseDown " << location_in_window.x |
| 536 << ", " << location_in_window.y << " " << was_draggable << " " |
| 537 << draggable_; |
| 538 //////////////////////////////////////////////////////////////////////////////// |
| 539 // Behavior when using CGEventTap. |
| 540 /* |
| 541 // If draggability has not changed, do nothing. |
| 542 if (was_draggable == draggable_) |
| 543 return false; |
| 544 |
| 545 // Otherwise, either make the window draggable or non-draggable, then return |
| 546 // true to repost the event. |
| 547 NSView* content_view = [window_ contentView]; |
| 548 if (draggable_) { |
| 549 NSView* mask_view = nil; |
| 550 for (NSView* view in [content_view subviews]) { |
| 551 if ([view isKindOfClass:[CocoaNonClientDragMaskView class]]) |
| 552 mask_view = view; |
| 553 } |
| 554 [mask_view removeFromSuperview]; |
| 555 } else { |
| 556 base::scoped_nsobject<CocoaNonClientDragMaskView> mask_view( |
| 557 [[CocoaNonClientDragMaskView alloc] |
| 558 initWithFrame:[content_view bounds]]); |
| 559 [content_view addSubview:mask_view]; |
| 560 } |
| 561 return true; |
| 562 */ |
| 563 // |
| 564 //////////////////////////////////////////////////////////////////////////////// |
| 565 // Behavior when using NSEvent local monitor. |
| 566 NSView* content_view = [window_ contentView]; |
| 567 if (was_draggable) { |
| 568 // This is a re-post, the movement has already completed, so we can make the |
| 569 // window non-draggable again. |
| 570 draggable_ = false; |
| 571 base::scoped_nsobject<CocoaNonClientDragMaskView> mask_view( |
| 572 [[CocoaNonClientDragMaskView alloc] |
| 573 initWithFrame:[content_view bounds]]); |
| 574 [content_view addSubview:mask_view]; |
| 575 return false; |
| 576 } |
| 577 |
| 578 if (draggable_) { |
| 579 // Make the window draggable, then return true to repost the event. |
| 580 NSView* mask_view = nil; |
| 581 for (NSView* view in [content_view subviews]) { |
| 582 if ([view isKindOfClass:[CocoaNonClientDragMaskView class]]) |
| 583 mask_view = view; |
| 584 } |
| 585 [mask_view removeFromSuperview]; |
| 586 return true; |
| 587 } |
| 588 return false; |
| 589 // |
| 590 //////////////////////////////////////////////////////////////////////////////// |
| 591 } |
| 592 |
| 525 void BridgedNativeWidget::OnSizeConstraintsChanged() { | 593 void BridgedNativeWidget::OnSizeConstraintsChanged() { |
| 526 NSWindow* window = ns_window(); | 594 NSWindow* window = ns_window(); |
| 527 Widget* widget = native_widget_mac()->GetWidget(); | 595 Widget* widget = native_widget_mac()->GetWidget(); |
| 528 gfx::Size min_size = widget->GetMinimumSize(); | 596 gfx::Size min_size = widget->GetMinimumSize(); |
| 529 gfx::Size max_size = widget->GetMaximumSize(); | 597 gfx::Size max_size = widget->GetMaximumSize(); |
| 530 bool is_resizable = widget->widget_delegate()->CanResize(); | 598 bool is_resizable = widget->widget_delegate()->CanResize(); |
| 531 bool shows_resize_controls = | 599 bool shows_resize_controls = |
| 532 is_resizable && (min_size.IsEmpty() || min_size != max_size); | 600 is_resizable && (min_size.IsEmpty() || min_size != max_size); |
| 533 bool shows_fullscreen_controls = | 601 bool shows_fullscreen_controls = |
| 534 is_resizable && widget->widget_delegate()->CanMaximize(); | 602 is_resizable && widget->widget_delegate()->CanMaximize(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 window_, &kWindowPropertiesKey); | 917 window_, &kWindowPropertiesKey); |
| 850 if (!properties) { | 918 if (!properties) { |
| 851 properties = [NSMutableDictionary dictionary]; | 919 properties = [NSMutableDictionary dictionary]; |
| 852 objc_setAssociatedObject(window_, &kWindowPropertiesKey, | 920 objc_setAssociatedObject(window_, &kWindowPropertiesKey, |
| 853 properties, OBJC_ASSOCIATION_RETAIN); | 921 properties, OBJC_ASSOCIATION_RETAIN); |
| 854 } | 922 } |
| 855 return properties; | 923 return properties; |
| 856 } | 924 } |
| 857 | 925 |
| 858 } // namespace views | 926 } // namespace views |
| OLD | NEW |