OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mandoline/ui/aura/native_widget_view_manager.h" | 5 #include "mandoline/ui/aura/native_widget_view_manager.h" |
6 | 6 |
7 #include "mandoline/ui/aura/input_method_mandoline.h" | 7 #include "mandoline/ui/aura/input_method_mandoline.h" |
8 #include "mandoline/ui/aura/window_tree_host_mojo.h" | 8 #include "mandoline/ui/aura/window_tree_host_mojo.h" |
9 #include "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
10 #include "mojo/converters/input_events/input_events_type_converters.h" | 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
11 #include "ui/aura/client/aura_constants.h" | |
12 #include "ui/aura/client/default_capture_client.h" | 11 #include "ui/aura/client/default_capture_client.h" |
13 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
14 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
15 #include "ui/base/ime/input_method_delegate.h" | 14 #include "ui/base/ime/input_method_delegate.h" |
16 #include "ui/wm/core/base_focus_rules.h" | 15 #include "ui/wm/core/base_focus_rules.h" |
17 #include "ui/wm/core/capture_controller.h" | 16 #include "ui/wm/core/capture_controller.h" |
18 #include "ui/wm/core/focus_controller.h" | 17 #include "ui/wm/core/focus_controller.h" |
19 | 18 |
20 namespace mandoline { | 19 namespace mandoline { |
21 namespace { | 20 namespace { |
22 | 21 |
23 // TODO: figure out what this should be. | 22 // TODO: figure out what this should be. |
24 class FocusRulesImpl : public wm::BaseFocusRules { | 23 class FocusRulesImpl : public wm::BaseFocusRules { |
25 public: | 24 public: |
26 FocusRulesImpl() {} | 25 FocusRulesImpl() {} |
27 ~FocusRulesImpl() override {} | 26 ~FocusRulesImpl() override {} |
28 | 27 |
29 bool SupportsChildActivation(aura::Window* window) const override { | 28 bool SupportsChildActivation(aura::Window* window) const override { |
30 return true; | 29 return true; |
31 } | 30 } |
32 | 31 |
33 private: | 32 private: |
34 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); | 33 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); |
35 }; | 34 }; |
36 | 35 |
37 class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, | |
38 public ui::EventHandler { | |
39 public: | |
40 explicit MinimalInputEventFilter(aura::Window* root) | |
41 : root_(root) { | |
42 input_method_.reset(new InputMethodMandoline(this)); | |
43 input_method_->OnFocus(); | |
44 root_->AddPreTargetHandler(this); | |
45 root_->SetProperty(aura::client::kRootWindowInputMethodKey, | |
46 input_method_.get()); | |
47 } | |
48 | |
49 ~MinimalInputEventFilter() override { | |
50 root_->RemovePreTargetHandler(this); | |
51 root_->SetProperty(aura::client::kRootWindowInputMethodKey, | |
52 static_cast<ui::InputMethod*>(NULL)); | |
53 } | |
54 | |
55 private: | |
56 // ui::EventHandler: | |
57 void OnKeyEvent(ui::KeyEvent* event) override { | |
58 // See the comment in InputMethodEventFilter::OnKeyEvent() for details. | |
59 if (event->IsTranslated()) { | |
60 event->SetTranslated(false); | |
61 } else { | |
62 if (input_method_->DispatchKeyEvent(*event)) | |
63 event->StopPropagation(); | |
64 } | |
65 } | |
66 | |
67 // ui::internal::InputMethodDelegate: | |
68 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { | |
69 // See the comment in InputMethodEventFilter::DispatchKeyEventPostIME() for | |
70 // details. | |
71 ui::KeyEvent aura_event(event); | |
72 aura_event.SetTranslated(true); | |
73 ui::EventDispatchDetails details = | |
74 root_->GetHost()->dispatcher()->OnEventFromSource(&aura_event); | |
75 return aura_event.handled() || details.dispatcher_destroyed; | |
76 } | |
77 | |
78 aura::Window* root_; | |
79 scoped_ptr<ui::InputMethod> input_method_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter); | |
82 }; | |
83 | |
84 } // namespace | 36 } // namespace |
85 | 37 |
86 NativeWidgetViewManager::NativeWidgetViewManager( | 38 NativeWidgetViewManager::NativeWidgetViewManager( |
87 views::internal::NativeWidgetDelegate* delegate, | 39 views::internal::NativeWidgetDelegate* delegate, |
88 mojo::Shell* shell, | 40 mojo::Shell* shell, |
89 mojo::View* view) | 41 mojo::View* view) |
90 : NativeWidgetAura(delegate), view_(view) { | 42 : NativeWidgetAura(delegate), view_(view) { |
91 view_->AddObserver(this); | 43 view_->AddObserver(this); |
92 window_tree_host_.reset(new WindowTreeHostMojo(shell, view_)); | 44 window_tree_host_.reset(new WindowTreeHostMojo(shell, view_)); |
93 window_tree_host_->InitHost(); | 45 window_tree_host_->InitHost(); |
94 | 46 |
95 ime_filter_.reset( | |
96 new MinimalInputEventFilter(window_tree_host_->window())); | |
97 | |
98 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); | 47 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); |
99 | 48 |
100 aura::client::SetFocusClient(window_tree_host_->window(), | 49 aura::client::SetFocusClient(window_tree_host_->window(), |
101 focus_client_.get()); | 50 focus_client_.get()); |
102 aura::client::SetActivationClient(window_tree_host_->window(), | 51 aura::client::SetActivationClient(window_tree_host_->window(), |
103 focus_client_.get()); | 52 focus_client_.get()); |
104 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); | 53 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); |
105 | 54 |
106 capture_client_.reset( | 55 capture_client_.reset( |
107 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 56 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 93 } |
145 | 94 |
146 void NativeWidgetViewManager::OnViewInputEvent(mojo::View* view, | 95 void NativeWidgetViewManager::OnViewInputEvent(mojo::View* view, |
147 const mojo::EventPtr& event) { | 96 const mojo::EventPtr& event) { |
148 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >()); | 97 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >()); |
149 if (ui_event) | 98 if (ui_event) |
150 window_tree_host_->SendEventToProcessor(ui_event.get()); | 99 window_tree_host_->SendEventToProcessor(ui_event.get()); |
151 } | 100 } |
152 | 101 |
153 } // namespace mandoline | 102 } // namespace mandoline |
OLD | NEW |