Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: mojo/views/native_widget_view_manager.cc

Issue 329803002: Fix text input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h"
13 #include "ui/base/ime/input_method_delegate.h" 14 #include "ui/base/ime/input_method_delegate.h"
14 #include "ui/base/ime/input_method_factory.h" 15 #include "ui/base/ime/input_method_factory.h"
15 #include "ui/base/ime/mock_input_method.h"
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(); 44 ui::InitializeInputMethodForTesting();
81 input_method_->Init(true); 45 input_method_->Init(true);
82 root_->AddPreTargetHandler(this); 46 root_->AddPreTargetHandler(this);
83 root_->SetProperty(aura::client::kRootWindowInputMethodKey, 47 root_->SetProperty(aura::client::kRootWindowInputMethodKey,
84 input_method_.get()); 48 input_method_.get());
85 } 49 }
86 50
87 virtual ~MinimalInputEventFilter() { 51 virtual ~MinimalInputEventFilter() {
88 root_->RemovePreTargetHandler(this); 52 root_->RemovePreTargetHandler(this);
89 root_->SetProperty(aura::client::kRootWindowInputMethodKey, 53 root_->SetProperty(aura::client::kRootWindowInputMethodKey,
90 static_cast<ui::InputMethod*>(NULL)); 54 static_cast<ui::InputMethod*>(NULL));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 122 }
159 123
160 void NativeWidgetViewManager::OnViewInputEvent(view_manager::View* view, 124 void NativeWidgetViewManager::OnViewInputEvent(view_manager::View* view,
161 const EventPtr& event) { 125 const EventPtr& event) {
162 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >()); 126 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >());
163 if (ui_event.get()) 127 if (ui_event.get())
164 window_tree_host_->SendEventToProcessor(ui_event.get()); 128 window_tree_host_->SendEventToProcessor(ui_event.get());
165 } 129 }
166 130
167 } // namespace mojo 131 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698