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 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #import "base/mac/sdk_forward_declarations.h" | 12 #import "base/mac/sdk_forward_declarations.h" |
13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" | 14 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" |
15 #include "ui/base/hit_test.h" | 15 #include "ui/base/hit_test.h" |
16 #include "ui/base/ime/input_method.h" | 16 #include "ui/base/ime/input_method.h" |
17 #include "ui/base/ime/input_method_factory.h" | 17 #include "ui/base/ime/input_method_factory.h" |
18 #include "ui/base/ui_base_switches_util.h" | 18 #include "ui/base/ui_base_switches_util.h" |
19 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
20 #include "ui/gfx/geometry/dip_util.h" | 20 #include "ui/gfx/geometry/dip_util.h" |
21 #import "ui/gfx/mac/coordinate_conversion.h" | 21 #import "ui/gfx/mac/coordinate_conversion.h" |
22 #import "ui/gfx/mac/nswindow_frame_controls.h" | 22 #import "ui/gfx/mac/nswindow_frame_controls.h" |
23 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
24 #import "ui/views/cocoa/bridged_content_view.h" | 24 #import "ui/views/cocoa/bridged_content_view.h" |
25 #import "ui/views/cocoa/cocoa_mouse_capture.h" | 25 #import "ui/views/cocoa/cocoa_mouse_capture.h" |
26 #include "ui/views/cocoa/tooltip_manager_mac.h" | 26 #include "ui/views/cocoa/tooltip_manager_mac.h" |
27 #import "ui/views/cocoa/views_nswindow_delegate.h" | 27 #import "ui/views/cocoa/views_nswindow_delegate.h" |
28 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" | 28 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" |
29 #include "ui/views/ime/input_method_bridge.h" | |
30 #include "ui/views/ime/null_input_method.h" | |
31 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
32 #include "ui/views/views_delegate.h" | 30 #include "ui/views/views_delegate.h" |
33 #include "ui/views/widget/native_widget_mac.h" | 31 #include "ui/views/widget/native_widget_mac.h" |
34 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
35 #include "ui/views/widget/widget_aura_utils.h" | 33 #include "ui/views/widget/widget_aura_utils.h" |
36 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
37 | 35 |
38 // The NSView that hosts the composited CALayer drawing the UI. It fills the | 36 // The NSView that hosts the composited CALayer drawing the UI. It fills the |
39 // window but is not hittable so that accessibility hit tests always go to the | 37 // window but is not hittable so that accessibility hit tests always go to the |
40 // BridgedContentView. | 38 // BridgedContentView. |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 bool shows_resize_controls = | 699 bool shows_resize_controls = |
702 is_resizable && (min_size.IsEmpty() || min_size != max_size); | 700 is_resizable && (min_size.IsEmpty() || min_size != max_size); |
703 bool shows_fullscreen_controls = | 701 bool shows_fullscreen_controls = |
704 is_resizable && widget->widget_delegate()->CanMaximize(); | 702 is_resizable && widget->widget_delegate()->CanMaximize(); |
705 | 703 |
706 gfx::ApplyNSWindowSizeConstraints(window_, min_size, max_size, | 704 gfx::ApplyNSWindowSizeConstraints(window_, min_size, max_size, |
707 shows_resize_controls, | 705 shows_resize_controls, |
708 shows_fullscreen_controls); | 706 shows_fullscreen_controls); |
709 } | 707 } |
710 | 708 |
711 InputMethod* BridgedNativeWidget::CreateInputMethod() { | 709 ui::InputMethod* BridgedNativeWidget::GetInputMethod() { |
712 if (switches::IsTextInputFocusManagerEnabled()) | |
713 return new NullInputMethod(); | |
714 | |
715 return new InputMethodBridge(this, GetHostInputMethod(), true); | |
716 } | |
717 | |
718 ui::InputMethod* BridgedNativeWidget::GetHostInputMethod() { | |
719 if (!input_method_) { | 710 if (!input_method_) { |
720 // Delegate is NULL because Mac IME does not need DispatchKeyEventPostIME | 711 // Delegate is NULL because Mac IME does not need DispatchKeyEventPostIME |
721 // callbacks. | 712 // callbacks. |
722 input_method_ = ui::CreateInputMethod(NULL, nil); | 713 input_method_ = ui::CreateInputMethod(NULL, nil); |
yukawa
2015/06/11 21:48:42
Well if we almost always need to call |OnFocus()|
Shu Chen
2015/06/12 03:34:38
I will do a CL soon to avoid such default-focused
| |
714 input_method_->OnFocus(); | |
723 } | 715 } |
724 return input_method_.get(); | 716 return input_method_.get(); |
725 } | 717 } |
726 | 718 |
727 gfx::Rect BridgedNativeWidget::GetRestoredBounds() const { | 719 gfx::Rect BridgedNativeWidget::GetRestoredBounds() const { |
728 if (target_fullscreen_state_ || in_fullscreen_transition_) | 720 if (target_fullscreen_state_ || in_fullscreen_transition_) |
729 return bounds_before_fullscreen_; | 721 return bounds_before_fullscreen_; |
730 | 722 |
731 return gfx::ScreenRectFromNSRect([window_ frame]); | 723 return gfx::ScreenRectFromNSRect([window_ frame]); |
732 } | 724 } |
(...skipping 19 matching lines...) Expand all Loading... | |
752 layer()->SetFillsBoundsOpaquely(!translucent); | 744 layer()->SetFillsBoundsOpaquely(!translucent); |
753 if (translucent) { | 745 if (translucent) { |
754 [window_ setOpaque:NO]; | 746 [window_ setOpaque:NO]; |
755 [window_ setBackgroundColor:[NSColor clearColor]]; | 747 [window_ setBackgroundColor:[NSColor clearColor]]; |
756 } | 748 } |
757 | 749 |
758 UpdateLayerProperties(); | 750 UpdateLayerProperties(); |
759 } | 751 } |
760 | 752 |
761 //////////////////////////////////////////////////////////////////////////////// | 753 //////////////////////////////////////////////////////////////////////////////// |
762 // BridgedNativeWidget, internal::InputMethodDelegate: | |
763 | |
764 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | |
765 DCHECK(focus_manager_); | |
766 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); | |
767 if (!key.handled()) | |
768 focus_manager_->OnKeyEvent(key); | |
769 } | |
770 | |
771 //////////////////////////////////////////////////////////////////////////////// | |
772 // BridgedNativeWidget, CocoaMouseCaptureDelegate: | 754 // BridgedNativeWidget, CocoaMouseCaptureDelegate: |
773 | 755 |
774 void BridgedNativeWidget::PostCapturedEvent(NSEvent* event) { | 756 void BridgedNativeWidget::PostCapturedEvent(NSEvent* event) { |
775 [bridged_view_ processCapturedMouseEvent:event]; | 757 [bridged_view_ processCapturedMouseEvent:event]; |
776 } | 758 } |
777 | 759 |
778 void BridgedNativeWidget::OnMouseCaptureLost() { | 760 void BridgedNativeWidget::OnMouseCaptureLost() { |
779 native_widget_mac_->GetWidget()->OnMouseCaptureLost(); | 761 native_widget_mac_->GetWidget()->OnMouseCaptureLost(); |
780 } | 762 } |
781 | 763 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1011 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
1030 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1012 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
1031 // changes. Previously we tried adding an NSView and removing it, but for some | 1013 // changes. Previously we tried adding an NSView and removing it, but for some |
1032 // reason it required reposting the mouse-down event, and didn't always work. | 1014 // reason it required reposting the mouse-down event, and didn't always work. |
1033 // Calling the below seems to be an effective solution. | 1015 // Calling the below seems to be an effective solution. |
1034 [window_ setMovableByWindowBackground:NO]; | 1016 [window_ setMovableByWindowBackground:NO]; |
1035 [window_ setMovableByWindowBackground:YES]; | 1017 [window_ setMovableByWindowBackground:YES]; |
1036 } | 1018 } |
1037 | 1019 |
1038 } // namespace views | 1020 } // namespace views |
OLD | NEW |