| 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 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/base/ime/input_method.h" | 8 #include "ui/base/ime/input_method.h" |
| 9 #include "ui/base/ime/input_method_factory.h" | 9 #include "ui/base/ime/input_method_factory.h" |
| 10 #include "ui/base/ui_base_switches_util.h" | 10 #include "ui/base/ui_base_switches_util.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 if (view == [bridged_view_ hostedView]) | 32 if (view == [bridged_view_ hostedView]) |
| 33 return; | 33 return; |
| 34 | 34 |
| 35 [bridged_view_ clearView]; | 35 [bridged_view_ clearView]; |
| 36 bridged_view_.reset(); | 36 bridged_view_.reset(); |
| 37 // Note that there can still be references to the old |bridged_view_| | 37 // Note that there can still be references to the old |bridged_view_| |
| 38 // floating around in Cocoa libraries at this point. However, references to | 38 // floating around in Cocoa libraries at this point. However, references to |
| 39 // the old views::View will be gone, so any method calls will become no-ops. | 39 // the old views::View will be gone, so any method calls will become no-ops. |
| 40 | 40 |
| 41 if (view) { | 41 if (view) { |
| 42 bridged_view_.reset([[BridgedContentView alloc] initWithView:view]); | 42 bridged_view_.reset( |
| 43 [[BridgedContentView alloc] initWithView:view parent:this]); |
| 43 // Objective C initializers can return nil. However, if |view| is non-NULL | 44 // Objective C initializers can return nil. However, if |view| is non-NULL |
| 44 // this should be treated as an error and caught early. | 45 // this should be treated as an error and caught early. |
| 45 CHECK(bridged_view_); | 46 CHECK(bridged_view_); |
| 46 } | 47 } |
| 47 [window_ setContentView:bridged_view_]; | 48 [window_ setContentView:bridged_view_]; |
| 48 [window_ makeFirstResponder:bridged_view_]; | 49 [window_ makeFirstResponder:bridged_view_]; |
| 49 } | 50 } |
| 50 | 51 |
| 51 InputMethod* BridgedNativeWidget::CreateInputMethod() { | 52 InputMethod* BridgedNativeWidget::CreateInputMethod() { |
| 52 if (switches::IsTextInputFocusManagerEnabled()) | 53 if (switches::IsTextInputFocusManagerEnabled()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 69 | 70 |
| 70 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | 71 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { |
| 71 // Mac key events don't go through this, but some unit tests that use | 72 // Mac key events don't go through this, but some unit tests that use |
| 72 // MockInputMethod do. | 73 // MockInputMethod do. |
| 73 Widget* widget = [bridged_view_ hostedView]->GetWidget(); | 74 Widget* widget = [bridged_view_ hostedView]->GetWidget(); |
| 74 widget->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); | 75 widget->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); |
| 75 if (!key.handled() && widget->GetFocusManager()) | 76 if (!key.handled() && widget->GetFocusManager()) |
| 76 widget->GetFocusManager()->OnKeyEvent(key); | 77 widget->GetFocusManager()->OnKeyEvent(key); |
| 77 } | 78 } |
| 78 | 79 |
| 80 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before, |
| 81 View* focused_now) { |
| 82 } |
| 83 |
| 84 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before, |
| 85 View* focused_now) { |
| 86 ui::TextInputClient* input_client = |
| 87 focused_now ? focused_now->GetTextInputClient() : NULL; |
| 88 [bridged_view_ setTextInputClient:input_client]; |
| 89 } |
| 90 |
| 79 } // namespace views | 91 } // namespace views |
| OLD | NEW |