1 // Copyright 2014 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 "ash/host/ash_window_tree_host.h"
7 #include "ash/host/ash_window_tree_host_init_params.h"
8 #include "ash/host/ash_window_tree_host_unified.h"
9 #include "ash/host/root_window_transformer.h"
10 #include "ash/host/transformer_helper.h"
11 #include "base/command_line.h"
12 #include "base/trace_event/trace_event.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_tree_host_ozone.h"
15 #include "ui/events/null_event_targeter.h"
16 #include "ui/gfx/geometry/insets.h"
17 #include "ui/gfx/transform.h"
18 #include "ui/ozone/public/input_controller.h"
19 #include "ui/ozone/public/ozone_platform.h"
20 #include "ui/platform_window/platform_window.h"
25 class AshWindowTreeHostOzone
: public AshWindowTreeHost
,
26 public aura::WindowTreeHostOzone
{
28 explicit AshWindowTreeHostOzone(const gfx::Rect
& initial_bounds
);
29 ~AshWindowTreeHostOzone() override
;
33 void ToggleFullScreen() override
;
34 bool ConfineCursorToRootWindow() override
;
35 void UnConfineCursor() override
;
36 void SetRootWindowTransformer(
37 scoped_ptr
<RootWindowTransformer
> transformer
) override
;
38 gfx::Insets
GetHostInsets() const override
;
39 aura::WindowTreeHost
* AsWindowTreeHost() override
;
40 void PrepareForShutdown() override
;
41 void SetRootTransform(const gfx::Transform
& transform
) override
;
42 gfx::Transform
GetRootTransform() const override
;
43 gfx::Transform
GetInverseRootTransform() const override
;
44 void UpdateRootWindowSize(const gfx::Size
& host_size
) override
;
45 void OnCursorVisibilityChangedNative(bool show
) override
;
46 void SetBounds(const gfx::Rect
& bounds
) override
;
47 void DispatchEvent(ui::Event
* event
) override
;
49 // Temporarily disable the tap-to-click feature. Used on CrOS.
50 void SetTapToClickPaused(bool state
);
52 TransformerHelper transformer_helper_
;
54 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone
);
57 AshWindowTreeHostOzone::AshWindowTreeHostOzone(const gfx::Rect
& initial_bounds
)
58 : aura::WindowTreeHostOzone(initial_bounds
), transformer_helper_(this) {
61 AshWindowTreeHostOzone::~AshWindowTreeHostOzone() {
64 void AshWindowTreeHostOzone::ToggleFullScreen() {
68 bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() {
69 gfx::Rect
confined_bounds(GetBounds().size());
70 confined_bounds
.Inset(transformer_helper_
.GetHostInsets());
71 platform_window()->ConfineCursorToBounds(confined_bounds
);
75 void AshWindowTreeHostOzone::UnConfineCursor() {
79 void AshWindowTreeHostOzone::SetRootWindowTransformer(
80 scoped_ptr
<RootWindowTransformer
> transformer
) {
81 transformer_helper_
.SetRootWindowTransformer(transformer
.Pass());
82 ConfineCursorToRootWindow();
85 gfx::Insets
AshWindowTreeHostOzone::GetHostInsets() const {
86 return transformer_helper_
.GetHostInsets();
89 aura::WindowTreeHost
* AshWindowTreeHostOzone::AsWindowTreeHost() {
93 void AshWindowTreeHostOzone::PrepareForShutdown() {
94 // Block the root window from dispatching events because it is weird for a
95 // ScreenPositionClient not to be attached to the root window and for
96 // ui::EventHandlers to be unable to convert the event's location to screen
98 window()->SetEventTargeter(
99 scoped_ptr
<ui::EventTargeter
>(new ui::NullEventTargeter
));
102 void AshWindowTreeHostOzone::SetRootTransform(const gfx::Transform
& transform
) {
103 transformer_helper_
.SetTransform(transform
);
106 gfx::Transform
AshWindowTreeHostOzone::GetRootTransform() const {
107 return transformer_helper_
.GetTransform();
110 gfx::Transform
AshWindowTreeHostOzone::GetInverseRootTransform() const {
111 return transformer_helper_
.GetInverseTransform();
114 void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size
& host_size
) {
115 transformer_helper_
.UpdateWindowSize(host_size
);
118 void AshWindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show
) {
119 SetTapToClickPaused(!show
);
122 void AshWindowTreeHostOzone::SetBounds(const gfx::Rect
& bounds
) {
123 WindowTreeHostOzone::SetBounds(bounds
);
124 ConfineCursorToRootWindow();
127 void AshWindowTreeHostOzone::DispatchEvent(ui::Event
* event
) {
128 TRACE_EVENT0("input", "AshWindowTreeHostOzone::DispatchEvent");
129 if (event
->IsLocatedEvent())
130 TranslateLocatedEvent(static_cast<ui::LocatedEvent
*>(event
));
131 SendEventToProcessor(event
);
134 void AshWindowTreeHostOzone::SetTapToClickPaused(bool state
) {
135 #if defined(OS_CHROMEOS)
136 DCHECK(ui::OzonePlatform::GetInstance()->GetInputController());
138 // Temporarily pause tap-to-click when the cursor is hidden.
139 ui::OzonePlatform::GetInstance()->GetInputController()->SetTapToClickPaused(
146 AshWindowTreeHost
* AshWindowTreeHost::Create(
147 const AshWindowTreeHostInitParams
& init_params
) {
148 if (init_params
.offscreen
)
149 return new AshWindowTreeHostUnified(init_params
.initial_bounds
);
150 return new AshWindowTreeHostOzone(init_params
.initial_bounds
);