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/window_tree_host_mojo.h"
7 #include "components/view_manager/public/cpp/view_manager.h"
8 #include "mandoline/ui/aura/surface_context_factory.h"
9 #include "mojo/application/public/interfaces/shell.mojom.h"
10 #include "mojo/converters/geometry/geometry_type_converters.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/events/event.h"
15 #include "ui/events/event_constants.h"
19 ////////////////////////////////////////////////////////////////////////////////
20 // WindowTreeHostMojo, public:
22 WindowTreeHostMojo::WindowTreeHostMojo(mojo::Shell
* shell
, mojo::View
* view
)
23 : view_(view
), bounds_(view
->bounds().To
<gfx::Rect
>()) {
24 view_
->AddObserver(this);
26 context_factory_
.reset(new SurfaceContextFactory(shell
, view_
));
27 // WindowTreeHost creates the compositor using the ContextFactory from
28 // aura::Env. Install |context_factory_| there so that |context_factory_| is
30 ui::ContextFactory
* default_context_factory
=
31 aura::Env::GetInstance()->context_factory();
32 aura::Env::GetInstance()->set_context_factory(context_factory_
.get());
33 CreateCompositor(GetAcceleratedWidget());
34 aura::Env::GetInstance()->set_context_factory(default_context_factory
);
35 DCHECK_EQ(context_factory_
.get(), compositor()->context_factory());
38 WindowTreeHostMojo::~WindowTreeHostMojo() {
39 view_
->RemoveObserver(this);
44 ////////////////////////////////////////////////////////////////////////////////
45 // WindowTreeHostMojo, aura::WindowTreeHost implementation:
47 ui::EventSource
* WindowTreeHostMojo::GetEventSource() {
51 gfx::AcceleratedWidget
WindowTreeHostMojo::GetAcceleratedWidget() {
52 return gfx::kNullAcceleratedWidget
;
55 void WindowTreeHostMojo::ShowImpl() {
59 void WindowTreeHostMojo::HideImpl() {
62 gfx::Rect
WindowTreeHostMojo::GetBounds() const {
66 void WindowTreeHostMojo::SetBounds(const gfx::Rect
& bounds
) {
67 window()->SetBounds(gfx::Rect(bounds
.size()));
70 gfx::Point
WindowTreeHostMojo::GetLocationOnNativeScreen() const {
71 return gfx::Point(0, 0);
74 void WindowTreeHostMojo::SetCapture() {
78 void WindowTreeHostMojo::ReleaseCapture() {
82 void WindowTreeHostMojo::SetCursorNative(gfx::NativeCursor cursor
) {
86 void WindowTreeHostMojo::MoveCursorToNative(const gfx::Point
& location
) {
90 void WindowTreeHostMojo::OnCursorVisibilityChangedNative(bool show
) {
94 ////////////////////////////////////////////////////////////////////////////////
95 // WindowTreeHostMojo, ViewObserver implementation:
97 void WindowTreeHostMojo::OnViewBoundsChanged(
99 const mojo::Rect
& old_bounds
,
100 const mojo::Rect
& new_bounds
) {
101 gfx::Rect old_bounds2
= old_bounds
.To
<gfx::Rect
>();
102 gfx::Rect new_bounds2
= new_bounds
.To
<gfx::Rect
>();
103 bounds_
= new_bounds2
;
104 if (old_bounds2
.origin() != new_bounds2
.origin())
105 OnHostMoved(bounds_
.origin());
106 if (old_bounds2
.size() != new_bounds2
.size())
107 OnHostResized(bounds_
.size());
110 } // namespace mandoline