| 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/thread_task_runner_handle.h" | 15 #include "base/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/cocoa_mouse_capture.h" | 28 #import "ui/views/cocoa/cocoa_mouse_capture.h" |
| 28 #include "ui/views/cocoa/tooltip_manager_mac.h" | 29 #include "ui/views/cocoa/tooltip_manager_mac.h" |
| 29 #import "ui/views/cocoa/views_nswindow_delegate.h" | 30 #import "ui/views/cocoa/views_nswindow_delegate.h" |
| 30 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" | 31 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" |
| 31 #include "ui/views/view.h" | 32 #include "ui/views/view.h" |
| 32 #include "ui/views/views_delegate.h" | 33 #include "ui/views/views_delegate.h" |
| 33 #include "ui/views/widget/native_widget_mac.h" | 34 #include "ui/views/widget/native_widget_mac.h" |
| 34 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 35 #include "ui/views/widget/widget_aura_utils.h" | 36 #include "ui/views/widget/widget_aura_utils.h" |
| 36 #include "ui/views/widget/widget_delegate.h" | 37 #include "ui/views/widget/widget_delegate.h" |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 457 } |
| 457 | 458 |
| 458 // Widgets for UI controls (usually layered above web contents) start visible. | 459 // Widgets for UI controls (usually layered above web contents) start visible. |
| 459 if (params.type == Widget::InitParams::TYPE_CONTROL) | 460 if (params.type == Widget::InitParams::TYPE_CONTROL) |
| 460 SetVisibilityState(SHOW_INACTIVE); | 461 SetVisibilityState(SHOW_INACTIVE); |
| 461 | 462 |
| 462 // Tooltip Widgets shouldn't have their own tooltip manager, but tooltips are | 463 // Tooltip Widgets shouldn't have their own tooltip manager, but tooltips are |
| 463 // native on Mac, so nothing should ever want one in Widget form. | 464 // native on Mac, so nothing should ever want one in Widget form. |
| 464 DCHECK_NE(params.type, Widget::InitParams::TYPE_TOOLTIP); | 465 DCHECK_NE(params.type, Widget::InitParams::TYPE_TOOLTIP); |
| 465 tooltip_manager_.reset(new TooltipManagerMac(this)); | 466 tooltip_manager_.reset(new TooltipManagerMac(this)); |
| 467 drag_drop_client_.reset(new DragDropClientMac(this)); |
| 466 } | 468 } |
| 467 | 469 |
| 468 void BridgedNativeWidget::SetFocusManager(FocusManager* focus_manager) { | 470 void BridgedNativeWidget::SetFocusManager(FocusManager* focus_manager) { |
| 469 if (focus_manager_ == focus_manager) | 471 if (focus_manager_ == focus_manager) |
| 470 return; | 472 return; |
| 471 | 473 |
| 472 if (focus_manager_) | 474 if (focus_manager_) |
| 473 focus_manager_->RemoveFocusChangeListener(this); | 475 focus_manager_->RemoveFocusChangeListener(this); |
| 474 | 476 |
| 475 if (focus_manager) | 477 if (focus_manager) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 DCHECK(!view || !compositor_widget_); | 522 DCHECK(!view || !compositor_widget_); |
| 521 | 523 |
| 522 [bridged_view_ clearView]; | 524 [bridged_view_ clearView]; |
| 523 bridged_view_.reset(); | 525 bridged_view_.reset(); |
| 524 // Note that there can still be references to the old |bridged_view_| | 526 // Note that there can still be references to the old |bridged_view_| |
| 525 // floating around in Cocoa libraries at this point. However, references to | 527 // floating around in Cocoa libraries at this point. However, references to |
| 526 // the old views::View will be gone, so any method calls will become no-ops. | 528 // the old views::View will be gone, so any method calls will become no-ops. |
| 527 | 529 |
| 528 if (view) { | 530 if (view) { |
| 529 bridged_view_.reset([[BridgedContentView alloc] initWithView:view]); | 531 bridged_view_.reset([[BridgedContentView alloc] initWithView:view]); |
| 532 drag_drop_client_->SetRootView(view); |
| 533 |
| 530 // Objective C initializers can return nil. However, if |view| is non-NULL | 534 // Objective C initializers can return nil. However, if |view| is non-NULL |
| 531 // this should be treated as an error and caught early. | 535 // this should be treated as an error and caught early. |
| 532 CHECK(bridged_view_); | 536 CHECK(bridged_view_); |
| 533 } | 537 } |
| 534 [window_ setContentView:bridged_view_]; | 538 [window_ setContentView:bridged_view_]; |
| 535 } | 539 } |
| 536 | 540 |
| 537 void BridgedNativeWidget::SetVisibilityState(WindowVisibilityState new_state) { | 541 void BridgedNativeWidget::SetVisibilityState(WindowVisibilityState new_state) { |
| 538 // Ensure that: | 542 // Ensure that: |
| 539 // - A window with an invisible parent is not made visible. | 543 // - A window with an invisible parent is not made visible. |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1307 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
| 1304 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1308 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
| 1305 // changes. Previously we tried adding an NSView and removing it, but for some | 1309 // changes. Previously we tried adding an NSView and removing it, but for some |
| 1306 // reason it required reposting the mouse-down event, and didn't always work. | 1310 // reason it required reposting the mouse-down event, and didn't always work. |
| 1307 // Calling the below seems to be an effective solution. | 1311 // Calling the below seems to be an effective solution. |
| 1308 [window_ setMovableByWindowBackground:NO]; | 1312 [window_ setMovableByWindowBackground:NO]; |
| 1309 [window_ setMovableByWindowBackground:YES]; | 1313 [window_ setMovableByWindowBackground:YES]; |
| 1310 } | 1314 } |
| 1311 | 1315 |
| 1312 } // namespace views | 1316 } // namespace views |
| OLD | NEW |