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 "ash/ime/input_method_event_handler.h"
12 #include "base/command_line.h"
13 #include "base/trace_event/trace_event.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_tree_host_ozone.h"
16 #include "ui/events/event_processor.h"
17 #include "ui/events/null_event_targeter.h"
18 #include "ui/gfx/geometry/insets.h"
19 #include "ui/gfx/transform.h"
20 #include "ui/ozone/public/input_controller.h"
21 #include "ui/ozone/public/ozone_platform.h"
22 #include "ui/platform_window/platform_window.h"
27 class AshWindowTreeHostOzone
: public AshWindowTreeHost
,
28 public aura::WindowTreeHostOzone
{
30 explicit AshWindowTreeHostOzone(const gfx::Rect
& initial_bounds
);
31 ~AshWindowTreeHostOzone() override
;
35 void ToggleFullScreen() override
;
36 bool ConfineCursorToRootWindow() override
;
37 void UnConfineCursor() override
;
38 void SetRootWindowTransformer(
39 scoped_ptr
<RootWindowTransformer
> transformer
) override
;
40 gfx::Insets
GetHostInsets() const override
;
41 aura::WindowTreeHost
* AsWindowTreeHost() override
;
42 void PrepareForShutdown() override
;
43 void SetRootTransform(const gfx::Transform
& transform
) override
;
44 gfx::Transform
GetRootTransform() const override
;
45 gfx::Transform
GetInverseRootTransform() const override
;
46 void UpdateRootWindowSize(const gfx::Size
& host_size
) override
;
47 void OnCursorVisibilityChangedNative(bool show
) override
;
48 void SetBounds(const gfx::Rect
& bounds
) override
;
49 void DispatchEvent(ui::Event
* event
) override
;
51 // ui::internal::InputMethodDelegate:
52 bool DispatchKeyEventPostIME(const ui::KeyEvent
& event
) override
;
54 // Temporarily disable the tap-to-click feature. Used on CrOS.
55 void SetTapToClickPaused(bool state
);
57 TransformerHelper transformer_helper_
;
59 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone
);
62 AshWindowTreeHostOzone::AshWindowTreeHostOzone(const gfx::Rect
& initial_bounds
)
63 : aura::WindowTreeHostOzone(initial_bounds
), transformer_helper_(this) {
64 transformer_helper_
.Init();
67 AshWindowTreeHostOzone::~AshWindowTreeHostOzone() {
70 void AshWindowTreeHostOzone::ToggleFullScreen() {
74 bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() {
75 gfx::Rect
confined_bounds(GetBounds().size());
76 confined_bounds
.Inset(transformer_helper_
.GetHostInsets());
77 platform_window()->ConfineCursorToBounds(confined_bounds
);
81 void AshWindowTreeHostOzone::UnConfineCursor() {
85 void AshWindowTreeHostOzone::SetRootWindowTransformer(
86 scoped_ptr
<RootWindowTransformer
> transformer
) {
87 transformer_helper_
.SetRootWindowTransformer(transformer
.Pass());
88 ConfineCursorToRootWindow();
91 gfx::Insets
AshWindowTreeHostOzone::GetHostInsets() const {
92 return transformer_helper_
.GetHostInsets();
95 aura::WindowTreeHost
* AshWindowTreeHostOzone::AsWindowTreeHost() {
99 void AshWindowTreeHostOzone::PrepareForShutdown() {
100 // Block the root window from dispatching events because it is weird for a
101 // ScreenPositionClient not to be attached to the root window and for
102 // ui::EventHandlers to be unable to convert the event's location to screen
104 window()->SetEventTargeter(
105 scoped_ptr
<ui::EventTargeter
>(new ui::NullEventTargeter
));
108 void AshWindowTreeHostOzone::SetRootTransform(const gfx::Transform
& transform
) {
109 transformer_helper_
.SetTransform(transform
);
112 gfx::Transform
AshWindowTreeHostOzone::GetRootTransform() const {
113 return transformer_helper_
.GetTransform();
116 gfx::Transform
AshWindowTreeHostOzone::GetInverseRootTransform() const {
117 return transformer_helper_
.GetInverseTransform();
120 void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size
& host_size
) {
121 transformer_helper_
.UpdateWindowSize(host_size
);
124 void AshWindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show
) {
125 SetTapToClickPaused(!show
);
128 void AshWindowTreeHostOzone::SetBounds(const gfx::Rect
& bounds
) {
129 WindowTreeHostOzone::SetBounds(bounds
);
130 ConfineCursorToRootWindow();
133 void AshWindowTreeHostOzone::DispatchEvent(ui::Event
* event
) {
134 TRACE_EVENT0("input", "AshWindowTreeHostOzone::DispatchEvent");
135 if (event
->IsLocatedEvent())
136 TranslateLocatedEvent(static_cast<ui::LocatedEvent
*>(event
));
137 SendEventToProcessor(event
);
140 bool AshWindowTreeHostOzone::DispatchKeyEventPostIME(
141 const ui::KeyEvent
& event
) {
142 ui::KeyEvent
event_copy(event
);
143 input_method_handler()->SetPostIME(true);
144 ui::EventDispatchDetails details
=
145 event_processor()->OnEventFromSource(&event_copy
);
146 if (details
.dispatcher_destroyed
)
148 input_method_handler()->SetPostIME(false);
149 return event_copy
.stopped_propagation();
152 void AshWindowTreeHostOzone::SetTapToClickPaused(bool state
) {
153 #if defined(OS_CHROMEOS)
154 DCHECK(ui::OzonePlatform::GetInstance()->GetInputController());
156 // Temporarily pause tap-to-click when the cursor is hidden.
157 ui::OzonePlatform::GetInstance()->GetInputController()->SetTapToClickPaused(
164 AshWindowTreeHost
* AshWindowTreeHost::Create(
165 const AshWindowTreeHostInitParams
& init_params
) {
166 if (init_params
.offscreen
)
167 return new AshWindowTreeHostUnified(init_params
.initial_bounds
);
168 return new AshWindowTreeHostOzone(init_params
.initial_bounds
);