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 #include "mojo/views/native_widget_view_manager.h" | 5 #include "mojo/views/native_widget_view_manager.h" |
| 6 | 6 |
| 7 #include "mojo/aura/window_tree_host_mojo.h" | 7 #include "mojo/aura/window_tree_host_mojo.h" |
| 8 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 8 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 9 #include "mojo/services/public/cpp/view_manager/view.h" | 9 #include "mojo/services/public/cpp/view_manager/view.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
| 13 #include "ui/base/ime/input_method_delegate.h" | 13 #include "ui/base/ime/input_method_delegate.h" |
| 14 #include "ui/base/ime/input_method_factory.h" | 14 #include "ui/base/ime/input_method_factory.h" |
| 15 #include "ui/base/ime/mock_input_method.h" | 15 #include "ui/base/ime/mock_input_method.h" |
|
sky
2014/06/11 20:00:37
nit: I think you can remove this now.
| |
| 16 #include "ui/base/ime/text_input_client.h" | 16 #include "ui/base/ime/text_input_client.h" |
| 17 #include "ui/wm/core/base_focus_rules.h" | 17 #include "ui/wm/core/base_focus_rules.h" |
| 18 #include "ui/wm/core/focus_controller.h" | 18 #include "ui/wm/core/focus_controller.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // TODO: figure out what this should be. | 23 // TODO: figure out what this should be. |
| 24 class FocusRulesImpl : public wm::BaseFocusRules { | 24 class FocusRulesImpl : public wm::BaseFocusRules { |
| 25 public: | 25 public: |
| 26 FocusRulesImpl() {} | 26 FocusRulesImpl() {} |
| 27 virtual ~FocusRulesImpl() {} | 27 virtual ~FocusRulesImpl() {} |
| 28 | 28 |
| 29 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { | 29 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { |
| 30 return true; | 30 return true; |
| 31 } | 31 } |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); | 34 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 class InputMethodImpl : public ui::MockInputMethod { | |
| 38 public: | |
| 39 explicit InputMethodImpl(ui::internal::InputMethodDelegate* delegate) | |
| 40 : MockInputMethod(delegate), | |
| 41 delegate_(delegate) { | |
| 42 } | |
| 43 virtual ~InputMethodImpl() { | |
| 44 } | |
| 45 | |
| 46 // MockInputMethod: | |
| 47 virtual bool DispatchKeyEvent(const ui::KeyEvent& event) OVERRIDE { | |
| 48 // If no text input client, do nothing. | |
| 49 if (!GetTextInputClient()) | |
| 50 return DispatchKeyEventPostIME(event); | |
| 51 | |
| 52 const bool handled = DispatchKeyEventPostIME(event); | |
| 53 if (event.type() == ui::ET_KEY_PRESSED && GetTextInputClient()) { | |
| 54 const uint16 ch = event.GetCharacter(); | |
| 55 if (ch) { | |
| 56 GetTextInputClient()->InsertChar(ch, event.flags()); | |
| 57 return true; | |
| 58 } | |
| 59 } | |
| 60 return handled; | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) const { | |
| 65 return delegate_ && delegate_->DispatchKeyEventPostIME(event); | |
| 66 } | |
| 67 | |
| 68 ui::internal::InputMethodDelegate* delegate_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(InputMethodImpl); | |
| 71 }; | |
| 72 | |
| 73 class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, | 37 class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, |
| 74 public ui::EventHandler { | 38 public ui::EventHandler { |
| 75 public: | 39 public: |
| 76 explicit MinimalInputEventFilter(aura::Window* root) | 40 explicit MinimalInputEventFilter(aura::Window* root) |
| 77 : root_(root) { | 41 : root_(root), |
| 78 ui::SetUpInputMethodFactoryForTesting(); | 42 input_method_( |
| 79 input_method_.reset(new InputMethodImpl(this)); | 43 ui::CreateInputMethod(this, gfx::kNullAcceleratedWidget).Pass()) { |
| 80 ui::InitializeInputMethod(); | |
| 81 input_method_->Init(true); | 44 input_method_->Init(true); |
| 82 root_->AddPreTargetHandler(this); | 45 root_->AddPreTargetHandler(this); |
| 83 root_->SetProperty(aura::client::kRootWindowInputMethodKey, | 46 root_->SetProperty(aura::client::kRootWindowInputMethodKey, |
| 84 input_method_.get()); | 47 input_method_.get()); |
| 85 } | 48 } |
| 86 | 49 |
| 87 virtual ~MinimalInputEventFilter() { | 50 virtual ~MinimalInputEventFilter() { |
| 88 root_->RemovePreTargetHandler(this); | 51 root_->RemovePreTargetHandler(this); |
| 89 root_->SetProperty(aura::client::kRootWindowInputMethodKey, | 52 root_->SetProperty(aura::client::kRootWindowInputMethodKey, |
| 90 static_cast<ui::InputMethod*>(NULL)); | 53 static_cast<ui::InputMethod*>(NULL)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 } | 121 } |
| 159 | 122 |
| 160 void NativeWidgetViewManager::OnViewInputEvent(view_manager::View* view, | 123 void NativeWidgetViewManager::OnViewInputEvent(view_manager::View* view, |
| 161 const EventPtr& event) { | 124 const EventPtr& event) { |
| 162 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >()); | 125 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >()); |
| 163 if (ui_event.get()) | 126 if (ui_event.get()) |
| 164 window_tree_host_->SendEventToProcessor(ui_event.get()); | 127 window_tree_host_->SendEventToProcessor(ui_event.get()); |
| 165 } | 128 } |
| 166 | 129 |
| 167 } // namespace mojo | 130 } // namespace mojo |
| OLD | NEW |