Mandoline UI Process: Update namespaces and file names
[chromium-blink-merge.git] / mandoline / ui / aura / native_widget_view_manager.cc
blobba863711ba6062955c51478bba767f32c5741abf
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
3 // found in the LICENSE file.
5 #include "mandoline/ui/aura/native_widget_view_manager.h"
7 #include "mandoline/ui/aura/input_method_mandoline.h"
8 #include "mandoline/ui/aura/window_tree_host_mojo.h"
9 #include "mojo/converters/geometry/geometry_type_converters.h"
10 #include "mojo/converters/input_events/input_events_type_converters.h"
11 #include "ui/aura/client/default_capture_client.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/base/ime/input_method_delegate.h"
15 #include "ui/wm/core/base_focus_rules.h"
16 #include "ui/wm/core/capture_controller.h"
17 #include "ui/wm/core/focus_controller.h"
19 namespace mandoline {
20 namespace {
22 // TODO: figure out what this should be.
23 class FocusRulesImpl : public wm::BaseFocusRules {
24 public:
25 FocusRulesImpl() {}
26 ~FocusRulesImpl() override {}
28 bool SupportsChildActivation(aura::Window* window) const override {
29 return true;
32 private:
33 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl);
36 } // namespace
38 NativeWidgetViewManager::NativeWidgetViewManager(
39 views::internal::NativeWidgetDelegate* delegate,
40 mojo::Shell* shell,
41 mus::View* view)
42 : NativeWidgetAura(delegate), view_(view) {
43 view_->AddObserver(this);
44 window_tree_host_.reset(new WindowTreeHostMojo(shell, view_));
45 window_tree_host_->InitHost();
47 focus_client_.reset(new wm::FocusController(new FocusRulesImpl));
49 aura::client::SetFocusClient(window_tree_host_->window(),
50 focus_client_.get());
51 aura::client::SetActivationClient(window_tree_host_->window(),
52 focus_client_.get());
53 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get());
55 capture_client_.reset(
56 new aura::client::DefaultCaptureClient(window_tree_host_->window()));
59 NativeWidgetViewManager::~NativeWidgetViewManager() {
60 if (view_)
61 view_->RemoveObserver(this);
64 void NativeWidgetViewManager::InitNativeWidget(
65 const views::Widget::InitParams& in_params) {
66 views::Widget::InitParams params(in_params);
67 params.parent = window_tree_host_->window();
68 NativeWidgetAura::InitNativeWidget(params);
71 void NativeWidgetViewManager::OnWindowVisibilityChanged(aura::Window* window,
72 bool visible) {
73 view_->SetVisible(visible);
74 // NOTE: We could also update aura::Window's visibility when the View's
75 // visibilty changes, but this code isn't going to be around for very long so
76 // I'm not bothering.
79 void NativeWidgetViewManager::OnViewDestroyed(mus::View* view) {
80 DCHECK_EQ(view, view_);
81 view->RemoveObserver(this);
82 view_ = NULL;
83 // TODO(sky): WindowTreeHostMojo assumes the View outlives it.
84 // NativeWidgetViewManager needs to deal, likely by deleting this.
87 void NativeWidgetViewManager::OnViewBoundsChanged(
88 mus::View* view,
89 const mojo::Rect& old_bounds,
90 const mojo::Rect& new_bounds) {
91 gfx::Rect view_rect = view->bounds().To<gfx::Rect>();
92 GetWidget()->SetBounds(gfx::Rect(view_rect.size()));
95 void NativeWidgetViewManager::OnViewFocusChanged(mus::View* gained_focus,
96 mus::View* lost_focus) {
97 if (gained_focus == view_)
98 window_tree_host_->GetInputMethod()->OnFocus();
99 else if (lost_focus == view_)
100 window_tree_host_->GetInputMethod()->OnBlur();
103 void NativeWidgetViewManager::OnViewInputEvent(mus::View* view,
104 const mojo::EventPtr& event) {
105 scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event>>());
106 if (!ui_event)
107 return;
109 if (ui_event->IsKeyEvent()) {
110 window_tree_host_->GetInputMethod()->DispatchKeyEvent(
111 static_cast<ui::KeyEvent*>(ui_event.get()));
112 } else {
113 window_tree_host_->SendEventToProcessor(ui_event.get());
117 } // namespace mandoline