Add shadow to contextual search panel.
[chromium-blink-merge.git] / mandoline / ui / aura / native_widget_view_manager.cc
blob0af2b370f78dc3f8908605623ecec45023fd5906
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 mojo::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(mojo::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 mojo::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(mojo::View* gained_focus,
96 mojo::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(mojo::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 window_tree_host_->SendEventToProcessor(ui_event.get());
110 } // namespace mandoline