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/gfx/display.h" | 18 #include "ui/gfx/display.h" |
19 #include "ui/gfx/geometry/dip_util.h" | 19 #include "ui/gfx/geometry/dip_util.h" |
20 #import "ui/gfx/mac/coordinate_conversion.h" | 20 #import "ui/gfx/mac/coordinate_conversion.h" |
21 #import "ui/gfx/mac/nswindow_frame_controls.h" | 21 #import "ui/gfx/mac/nswindow_frame_controls.h" |
22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
23 #import "ui/views/cocoa/bridged_content_view.h" | 23 #import "ui/views/cocoa/bridged_content_view.h" |
24 #import "ui/views/cocoa/cocoa_mouse_capture.h" | 24 #import "ui/views/cocoa/cocoa_mouse_capture.h" |
25 #include "ui/views/cocoa/tooltip_manager_mac.h" | 25 #include "ui/views/cocoa/tooltip_manager_mac.h" |
26 #import "ui/views/cocoa/views_nswindow_delegate.h" | 26 #import "ui/views/cocoa/views_nswindow_delegate.h" |
27 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" | 27 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" |
28 #include "ui/views/ime/input_method_bridge.h" | |
29 #include "ui/views/ime/null_input_method.h" | |
30 #include "ui/views/view.h" | 28 #include "ui/views/view.h" |
31 #include "ui/views/views_delegate.h" | 29 #include "ui/views/views_delegate.h" |
32 #include "ui/views/widget/native_widget_mac.h" | 30 #include "ui/views/widget/native_widget_mac.h" |
33 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
34 #include "ui/views/widget/widget_aura_utils.h" | 32 #include "ui/views/widget/widget_aura_utils.h" |
35 #include "ui/views/widget/widget_delegate.h" | 33 #include "ui/views/widget/widget_delegate.h" |
36 | 34 |
37 // The NSView that hosts the composited CALayer drawing the UI. It fills the | 35 // The NSView that hosts the composited CALayer drawing the UI. It fills the |
38 // window but is not hittable so that accessibility hit tests always go to the | 36 // window but is not hittable so that accessibility hit tests always go to the |
39 // BridgedContentView. | 37 // BridgedContentView. |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 bool shows_resize_controls = | 698 bool shows_resize_controls = |
701 is_resizable && (min_size.IsEmpty() || min_size != max_size); | 699 is_resizable && (min_size.IsEmpty() || min_size != max_size); |
702 bool shows_fullscreen_controls = | 700 bool shows_fullscreen_controls = |
703 is_resizable && widget->widget_delegate()->CanMaximize(); | 701 is_resizable && widget->widget_delegate()->CanMaximize(); |
704 | 702 |
705 gfx::ApplyNSWindowSizeConstraints(window_, min_size, max_size, | 703 gfx::ApplyNSWindowSizeConstraints(window_, min_size, max_size, |
706 shows_resize_controls, | 704 shows_resize_controls, |
707 shows_fullscreen_controls); | 705 shows_fullscreen_controls); |
708 } | 706 } |
709 | 707 |
710 InputMethod* BridgedNativeWidget::CreateInputMethod() { | 708 ui::InputMethod* BridgedNativeWidget::GetInputMethod() { |
711 return new InputMethodBridge(this, GetHostInputMethod(), true); | |
712 } | |
713 | |
714 ui::InputMethod* BridgedNativeWidget::GetHostInputMethod() { | |
715 if (!input_method_) { | 709 if (!input_method_) { |
716 // Delegate is NULL because Mac IME does not need DispatchKeyEventPostIME | 710 input_method_ = ui::CreateInputMethod(this, nil); |
717 // callbacks. | 711 // For now, use always-focused mode on Mac for the input method. |
718 input_method_ = ui::CreateInputMethod(NULL, nil); | 712 // TODO(tapted): Move this to OnWindowKeyStatusChangedTo() and balance. |
| 713 input_method_->OnFocus(); |
719 } | 714 } |
720 return input_method_.get(); | 715 return input_method_.get(); |
721 } | 716 } |
722 | 717 |
723 gfx::Rect BridgedNativeWidget::GetRestoredBounds() const { | 718 gfx::Rect BridgedNativeWidget::GetRestoredBounds() const { |
724 if (target_fullscreen_state_ || in_fullscreen_transition_) | 719 if (target_fullscreen_state_ || in_fullscreen_transition_) |
725 return bounds_before_fullscreen_; | 720 return bounds_before_fullscreen_; |
726 | 721 |
727 return gfx::ScreenRectFromNSRect([window_ frame]); | 722 return gfx::ScreenRectFromNSRect([window_ frame]); |
728 } | 723 } |
(...skipping 21 matching lines...) Expand all Loading... |
750 [window_ setOpaque:NO]; | 745 [window_ setOpaque:NO]; |
751 [window_ setBackgroundColor:[NSColor clearColor]]; | 746 [window_ setBackgroundColor:[NSColor clearColor]]; |
752 } | 747 } |
753 | 748 |
754 UpdateLayerProperties(); | 749 UpdateLayerProperties(); |
755 } | 750 } |
756 | 751 |
757 //////////////////////////////////////////////////////////////////////////////// | 752 //////////////////////////////////////////////////////////////////////////////// |
758 // BridgedNativeWidget, internal::InputMethodDelegate: | 753 // BridgedNativeWidget, internal::InputMethodDelegate: |
759 | 754 |
760 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | 755 bool BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { |
761 DCHECK(focus_manager_); | 756 DCHECK(focus_manager_); |
762 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); | 757 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); |
763 if (!key.handled()) | 758 if (!key.handled()) |
764 focus_manager_->OnKeyEvent(key); | 759 return !focus_manager_->OnKeyEvent(key); |
| 760 return key.handled(); |
765 } | 761 } |
766 | 762 |
767 //////////////////////////////////////////////////////////////////////////////// | 763 //////////////////////////////////////////////////////////////////////////////// |
768 // BridgedNativeWidget, CocoaMouseCaptureDelegate: | 764 // BridgedNativeWidget, CocoaMouseCaptureDelegate: |
769 | 765 |
770 void BridgedNativeWidget::PostCapturedEvent(NSEvent* event) { | 766 void BridgedNativeWidget::PostCapturedEvent(NSEvent* event) { |
771 [bridged_view_ processCapturedMouseEvent:event]; | 767 [bridged_view_ processCapturedMouseEvent:event]; |
772 } | 768 } |
773 | 769 |
774 void BridgedNativeWidget::OnMouseCaptureLost() { | 770 void BridgedNativeWidget::OnMouseCaptureLost() { |
775 native_widget_mac_->GetWidget()->OnMouseCaptureLost(); | 771 native_widget_mac_->GetWidget()->OnMouseCaptureLost(); |
776 } | 772 } |
777 | 773 |
778 //////////////////////////////////////////////////////////////////////////////// | 774 //////////////////////////////////////////////////////////////////////////////// |
779 // BridgedNativeWidget, FocusChangeListener: | 775 // BridgedNativeWidget, FocusChangeListener: |
780 | 776 |
781 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before, | 777 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before, |
782 View* focused_now) { | 778 View* focused_now) { |
783 } | 779 } |
784 | 780 |
785 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before, | 781 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before, |
786 View* focused_now) { | 782 View* focused_now) { |
787 ui::TextInputClient* input_client = | 783 ui::InputMethod* input_method = |
788 focused_now ? focused_now->GetTextInputClient() : NULL; | 784 native_widget_mac_->GetWidget()->GetInputMethod(); |
789 [bridged_view_ setTextInputClient:input_client]; | 785 if (input_method) { |
| 786 ui::TextInputClient* input_client = input_method->GetTextInputClient(); |
| 787 [bridged_view_ setTextInputClient:input_client]; |
| 788 } |
790 } | 789 } |
791 | 790 |
792 //////////////////////////////////////////////////////////////////////////////// | 791 //////////////////////////////////////////////////////////////////////////////// |
793 // BridgedNativeWidget, LayerDelegate: | 792 // BridgedNativeWidget, LayerDelegate: |
794 | 793 |
795 void BridgedNativeWidget::OnPaintLayer(const ui::PaintContext& context) { | 794 void BridgedNativeWidget::OnPaintLayer(const ui::PaintContext& context) { |
796 DCHECK(window_visible_); | 795 DCHECK(window_visible_); |
797 native_widget_mac_->GetWidget()->OnNativeWidgetPaint(context); | 796 native_widget_mac_->GetWidget()->OnNativeWidgetPaint(context); |
798 } | 797 } |
799 | 798 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1024 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
1026 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1025 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
1027 // changes. Previously we tried adding an NSView and removing it, but for some | 1026 // changes. Previously we tried adding an NSView and removing it, but for some |
1028 // reason it required reposting the mouse-down event, and didn't always work. | 1027 // reason it required reposting the mouse-down event, and didn't always work. |
1029 // Calling the below seems to be an effective solution. | 1028 // Calling the below seems to be an effective solution. |
1030 [window_ setMovableByWindowBackground:NO]; | 1029 [window_ setMovableByWindowBackground:NO]; |
1031 [window_ setMovableByWindowBackground:YES]; | 1030 [window_ setMovableByWindowBackground:YES]; |
1032 } | 1031 } |
1033 | 1032 |
1034 } // namespace views | 1033 } // namespace views |
OLD | NEW |