Chromium Code Reviews| 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 input_method_->OnFocus(); |
|
tapted
2015/06/29 04:57:21
Can you add a comment about this line?
It seems o
Shu Chen
2015/06/29 06:05:57
ui::InputMethod::OnBlur() only gets called in Desk
tapted
2015/06/29 06:34:48
Acknowledged. (we discussed this out of band - "al
| |
| 718 input_method_ = ui::CreateInputMethod(NULL, nil); | |
| 719 } | 712 } |
| 720 return input_method_.get(); | 713 return input_method_.get(); |
| 721 } | 714 } |
| 722 | 715 |
| 723 gfx::Rect BridgedNativeWidget::GetRestoredBounds() const { | 716 gfx::Rect BridgedNativeWidget::GetRestoredBounds() const { |
| 724 if (target_fullscreen_state_ || in_fullscreen_transition_) | 717 if (target_fullscreen_state_ || in_fullscreen_transition_) |
| 725 return bounds_before_fullscreen_; | 718 return bounds_before_fullscreen_; |
| 726 | 719 |
| 727 return gfx::ScreenRectFromNSRect([window_ frame]); | 720 return gfx::ScreenRectFromNSRect([window_ frame]); |
| 728 } | 721 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 750 [window_ setOpaque:NO]; | 743 [window_ setOpaque:NO]; |
| 751 [window_ setBackgroundColor:[NSColor clearColor]]; | 744 [window_ setBackgroundColor:[NSColor clearColor]]; |
| 752 } | 745 } |
| 753 | 746 |
| 754 UpdateLayerProperties(); | 747 UpdateLayerProperties(); |
| 755 } | 748 } |
| 756 | 749 |
| 757 //////////////////////////////////////////////////////////////////////////////// | 750 //////////////////////////////////////////////////////////////////////////////// |
| 758 // BridgedNativeWidget, internal::InputMethodDelegate: | 751 // BridgedNativeWidget, internal::InputMethodDelegate: |
| 759 | 752 |
| 760 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | 753 bool BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { |
| 761 DCHECK(focus_manager_); | 754 DCHECK(focus_manager_); |
| 762 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); | 755 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); |
| 763 if (!key.handled()) | 756 if (!key.handled()) |
| 764 focus_manager_->OnKeyEvent(key); | 757 focus_manager_->OnKeyEvent(key); |
|
tapted
2015/06/29 04:57:21
BridgedContentView currently ignores the return va
Shu Chen
2015/06/29 06:05:57
Done.
| |
| 758 return key.handled(); | |
| 765 } | 759 } |
| 766 | 760 |
| 767 //////////////////////////////////////////////////////////////////////////////// | 761 //////////////////////////////////////////////////////////////////////////////// |
| 768 // BridgedNativeWidget, CocoaMouseCaptureDelegate: | 762 // BridgedNativeWidget, CocoaMouseCaptureDelegate: |
| 769 | 763 |
| 770 void BridgedNativeWidget::PostCapturedEvent(NSEvent* event) { | 764 void BridgedNativeWidget::PostCapturedEvent(NSEvent* event) { |
| 771 [bridged_view_ processCapturedMouseEvent:event]; | 765 [bridged_view_ processCapturedMouseEvent:event]; |
| 772 } | 766 } |
| 773 | 767 |
| 774 void BridgedNativeWidget::OnMouseCaptureLost() { | 768 void BridgedNativeWidget::OnMouseCaptureLost() { |
| 775 native_widget_mac_->GetWidget()->OnMouseCaptureLost(); | 769 native_widget_mac_->GetWidget()->OnMouseCaptureLost(); |
| 776 } | 770 } |
| 777 | 771 |
| 778 //////////////////////////////////////////////////////////////////////////////// | 772 //////////////////////////////////////////////////////////////////////////////// |
| 779 // BridgedNativeWidget, FocusChangeListener: | 773 // BridgedNativeWidget, FocusChangeListener: |
| 780 | 774 |
| 781 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before, | 775 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before, |
| 782 View* focused_now) { | 776 View* focused_now) { |
| 783 } | 777 } |
| 784 | 778 |
| 785 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before, | 779 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before, |
| 786 View* focused_now) { | 780 View* focused_now) { |
| 787 ui::TextInputClient* input_client = | 781 ui::InputMethod* input_method = |
| 788 focused_now ? focused_now->GetTextInputClient() : NULL; | 782 native_widget_mac_->GetWidget()->GetInputMethod(); |
| 789 [bridged_view_ setTextInputClient:input_client]; | 783 if (input_method) { |
| 784 ui::TextInputClient* input_client = input_method->GetTextInputClient(); | |
| 785 [bridged_view_ setTextInputClient:input_client]; | |
| 786 } | |
| 790 } | 787 } |
| 791 | 788 |
| 792 //////////////////////////////////////////////////////////////////////////////// | 789 //////////////////////////////////////////////////////////////////////////////// |
| 793 // BridgedNativeWidget, LayerDelegate: | 790 // BridgedNativeWidget, LayerDelegate: |
| 794 | 791 |
| 795 void BridgedNativeWidget::OnPaintLayer(const ui::PaintContext& context) { | 792 void BridgedNativeWidget::OnPaintLayer(const ui::PaintContext& context) { |
| 796 DCHECK(window_visible_); | 793 DCHECK(window_visible_); |
| 797 native_widget_mac_->GetWidget()->OnNativeWidgetPaint(context); | 794 native_widget_mac_->GetWidget()->OnNativeWidgetPaint(context); |
| 798 } | 795 } |
| 799 | 796 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1022 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
| 1026 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1023 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
| 1027 // changes. Previously we tried adding an NSView and removing it, but for some | 1024 // 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. | 1025 // reason it required reposting the mouse-down event, and didn't always work. |
| 1029 // Calling the below seems to be an effective solution. | 1026 // Calling the below seems to be an effective solution. |
| 1030 [window_ setMovableByWindowBackground:NO]; | 1027 [window_ setMovableByWindowBackground:NO]; |
| 1031 [window_ setMovableByWindowBackground:YES]; | 1028 [window_ setMovableByWindowBackground:YES]; |
| 1032 } | 1029 } |
| 1033 | 1030 |
| 1034 } // namespace views | 1031 } // namespace views |
| OLD | NEW |