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 ui::EventDispatchDetails
DispatchKeyEventPostIME(
53 ui::KeyEvent
* event
) override
;
55 // Temporarily disable the tap-to-click feature. Used on CrOS.
56 void SetTapToClickPaused(bool state
);
58 TransformerHelper transformer_helper_
;
60 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone
);
63 AshWindowTreeHostOzone::AshWindowTreeHostOzone(const gfx::Rect
& initial_bounds
)
64 : aura::WindowTreeHostOzone(initial_bounds
), transformer_helper_(this) {
65 transformer_helper_
.Init();
68 AshWindowTreeHostOzone::~AshWindowTreeHostOzone() {
71 void AshWindowTreeHostOzone::ToggleFullScreen() {
75 bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() {
76 gfx::Rect
confined_bounds(GetBounds().size());
77 confined_bounds
.Inset(transformer_helper_
.GetHostInsets());
78 platform_window()->ConfineCursorToBounds(confined_bounds
);
82 void AshWindowTreeHostOzone::UnConfineCursor() {
86 void AshWindowTreeHostOzone::SetRootWindowTransformer(
87 scoped_ptr
<RootWindowTransformer
> transformer
) {
88 transformer_helper_
.SetRootWindowTransformer(transformer
.Pass());
89 ConfineCursorToRootWindow();
92 gfx::Insets
AshWindowTreeHostOzone::GetHostInsets() const {
93 return transformer_helper_
.GetHostInsets();
96 aura::WindowTreeHost
* AshWindowTreeHostOzone::AsWindowTreeHost() {
100 void AshWindowTreeHostOzone::PrepareForShutdown() {
101 // Block the root window from dispatching events because it is weird for a
102 // ScreenPositionClient not to be attached to the root window and for
103 // ui::EventHandlers to be unable to convert the event's location to screen
105 window()->SetEventTargeter(
106 scoped_ptr
<ui::EventTargeter
>(new ui::NullEventTargeter
));
109 void AshWindowTreeHostOzone::SetRootTransform(const gfx::Transform
& transform
) {
110 transformer_helper_
.SetTransform(transform
);
113 gfx::Transform
AshWindowTreeHostOzone::GetRootTransform() const {
114 return transformer_helper_
.GetTransform();
117 gfx::Transform
AshWindowTreeHostOzone::GetInverseRootTransform() const {
118 return transformer_helper_
.GetInverseTransform();
121 void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size
& host_size
) {
122 transformer_helper_
.UpdateWindowSize(host_size
);
125 void AshWindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show
) {
126 SetTapToClickPaused(!show
);
129 void AshWindowTreeHostOzone::SetBounds(const gfx::Rect
& bounds
) {
130 WindowTreeHostOzone::SetBounds(bounds
);
131 ConfineCursorToRootWindow();
134 void AshWindowTreeHostOzone::DispatchEvent(ui::Event
* event
) {
135 TRACE_EVENT0("input", "AshWindowTreeHostOzone::DispatchEvent");
136 if (event
->IsLocatedEvent())
137 TranslateLocatedEvent(static_cast<ui::LocatedEvent
*>(event
));
138 SendEventToProcessor(event
);
141 ui::EventDispatchDetails
AshWindowTreeHostOzone::DispatchKeyEventPostIME(
142 ui::KeyEvent
* event
) {
143 input_method_handler()->SetPostIME(true);
144 ui::EventDispatchDetails details
=
145 event_processor()->OnEventFromSource(event
);
146 if (!details
.dispatcher_destroyed
)
147 input_method_handler()->SetPostIME(false);
151 void AshWindowTreeHostOzone::SetTapToClickPaused(bool state
) {
152 #if defined(OS_CHROMEOS)
153 DCHECK(ui::OzonePlatform::GetInstance()->GetInputController());
155 // Temporarily pause tap-to-click when the cursor is hidden.
156 ui::OzonePlatform::GetInstance()->GetInputController()->SetTapToClickPaused(
163 AshWindowTreeHost
* AshWindowTreeHost::Create(
164 const AshWindowTreeHostInitParams
& init_params
) {
165 if (init_params
.offscreen
)
166 return new AshWindowTreeHostUnified(init_params
.initial_bounds
);
167 return new AshWindowTreeHostOzone(init_params
.initial_bounds
);