| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 ~FocusRulesImpl() override {} | 27 ~FocusRulesImpl() override {} |
| 28 | 28 |
| 29 bool SupportsChildActivation(aura::Window* window) const override { | 29 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 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 | 37 } // namespace |
| 85 | 38 |
| 86 NativeWidgetViewManager::NativeWidgetViewManager( | 39 NativeWidgetViewManager::NativeWidgetViewManager( |
| 87 views::internal::NativeWidgetDelegate* delegate, | 40 views::internal::NativeWidgetDelegate* delegate, |
| 88 mojo::Shell* shell, | 41 mojo::Shell* shell, |
| 89 mojo::View* view) | 42 mojo::View* view) |
| 90 : NativeWidgetAura(delegate), view_(view) { | 43 : NativeWidgetAura(delegate), view_(view) { |
| 91 view_->AddObserver(this); | 44 view_->AddObserver(this); |
| 92 window_tree_host_.reset(new WindowTreeHostMojo(shell, view_)); | 45 window_tree_host_.reset(new WindowTreeHostMojo(shell, view_)); |
| 93 window_tree_host_->InitHost(); | 46 window_tree_host_->InitHost(); |
| 94 | 47 |
| 95 ime_filter_.reset( | |
| 96 new MinimalInputEventFilter(window_tree_host_->window())); | |
| 97 | |
| 98 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); | 48 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); |
| 99 | 49 |
| 100 aura::client::SetFocusClient(window_tree_host_->window(), | 50 aura::client::SetFocusClient(window_tree_host_->window(), |
| 101 focus_client_.get()); | 51 focus_client_.get()); |
| 102 aura::client::SetActivationClient(window_tree_host_->window(), | 52 aura::client::SetActivationClient(window_tree_host_->window(), |
| 103 focus_client_.get()); | 53 focus_client_.get()); |
| 104 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); | 54 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); |
| 105 | 55 |
| 106 capture_client_.reset( | 56 capture_client_.reset( |
| 107 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 57 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 94 } |
| 145 | 95 |
| 146 void NativeWidgetViewManager::OnViewInputEvent(mojo::View* view, | 96 void NativeWidgetViewManager::OnViewInputEvent(mojo::View* view, |
| 147 const mojo::EventPtr& event) { | 97 const mojo::EventPtr& event) { |
| 148 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >()); | 98 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event> >()); |
| 149 if (ui_event) | 99 if (ui_event) |
| 150 window_tree_host_->SendEventToProcessor(ui_event.get()); | 100 window_tree_host_->SendEventToProcessor(ui_event.get()); |
| 151 } | 101 } |
| 152 | 102 |
| 153 } // namespace mandoline | 103 } // namespace mandoline |
| OLD | NEW |