ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / ash / host / ash_window_tree_host_ozone.cc
blob7c23cd9e12a3786824e69f3ec23aec4760d3f081
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/root_window_transformer.h"
9 #include "ash/host/transformer_helper.h"
10 #include "base/command_line.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_tree_host_ozone.h"
13 #include "ui/events/null_event_targeter.h"
14 #include "ui/gfx/geometry/insets.h"
15 #include "ui/gfx/transform.h"
16 #include "ui/ozone/public/input_controller.h"
17 #include "ui/ozone/public/ozone_platform.h"
18 #include "ui/platform_window/platform_window.h"
20 namespace ash {
21 namespace {
23 class AshWindowTreeHostOzone : public AshWindowTreeHost,
24 public aura::WindowTreeHostOzone {
25 public:
26 explicit AshWindowTreeHostOzone(const gfx::Rect& initial_bounds);
27 ~AshWindowTreeHostOzone() override;
29 private:
30 // AshWindowTreeHost:
31 void ToggleFullScreen() override;
32 bool ConfineCursorToRootWindow() override;
33 void UnConfineCursor() override;
34 void SetRootWindowTransformer(
35 scoped_ptr<RootWindowTransformer> transformer) override;
36 gfx::Insets GetHostInsets() const override;
37 aura::WindowTreeHost* AsWindowTreeHost() override;
38 void PrepareForShutdown() override;
39 void SetRootTransform(const gfx::Transform& transform) override;
40 gfx::Transform GetRootTransform() const override;
41 gfx::Transform GetInverseRootTransform() const override;
42 void UpdateRootWindowSize(const gfx::Size& host_size) override;
43 void OnCursorVisibilityChangedNative(bool show) override;
44 void SetBounds(const gfx::Rect& bounds) override;
45 void DispatchEvent(ui::Event* event) override;
47 // Temporarily disable the tap-to-click feature. Used on CrOS.
48 void SetTapToClickPaused(bool state);
50 TransformerHelper transformer_helper_;
52 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone);
55 AshWindowTreeHostOzone::AshWindowTreeHostOzone(const gfx::Rect& initial_bounds)
56 : aura::WindowTreeHostOzone(initial_bounds), transformer_helper_(this) {
59 AshWindowTreeHostOzone::~AshWindowTreeHostOzone() {
62 void AshWindowTreeHostOzone::ToggleFullScreen() {
63 NOTIMPLEMENTED();
66 bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() {
67 gfx::Rect confined_bounds(GetBounds().size());
68 confined_bounds.Inset(transformer_helper_.GetHostInsets());
69 platform_window()->ConfineCursorToBounds(confined_bounds);
70 return true;
73 void AshWindowTreeHostOzone::UnConfineCursor() {
74 NOTIMPLEMENTED();
77 void AshWindowTreeHostOzone::SetRootWindowTransformer(
78 scoped_ptr<RootWindowTransformer> transformer) {
79 transformer_helper_.SetRootWindowTransformer(transformer.Pass());
80 ConfineCursorToRootWindow();
83 gfx::Insets AshWindowTreeHostOzone::GetHostInsets() const {
84 return transformer_helper_.GetHostInsets();
87 aura::WindowTreeHost* AshWindowTreeHostOzone::AsWindowTreeHost() {
88 return this;
91 void AshWindowTreeHostOzone::PrepareForShutdown() {
92 // Block the root window from dispatching events because it is weird for a
93 // ScreenPositionClient not to be attached to the root window and for
94 // ui::EventHandlers to be unable to convert the event's location to screen
95 // coordinates.
96 window()->SetEventTargeter(
97 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter));
100 void AshWindowTreeHostOzone::SetRootTransform(const gfx::Transform& transform) {
101 transformer_helper_.SetTransform(transform);
104 gfx::Transform AshWindowTreeHostOzone::GetRootTransform() const {
105 return transformer_helper_.GetTransform();
108 gfx::Transform AshWindowTreeHostOzone::GetInverseRootTransform() const {
109 return transformer_helper_.GetInverseTransform();
112 void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size& host_size) {
113 transformer_helper_.UpdateWindowSize(host_size);
116 void AshWindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show) {
117 SetTapToClickPaused(!show);
120 void AshWindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) {
121 WindowTreeHostOzone::SetBounds(bounds);
122 ConfineCursorToRootWindow();
125 void AshWindowTreeHostOzone::DispatchEvent(ui::Event* event) {
126 if (event->IsLocatedEvent())
127 TranslateLocatedEvent(static_cast<ui::LocatedEvent*>(event));
128 SendEventToProcessor(event);
131 void AshWindowTreeHostOzone::SetTapToClickPaused(bool state) {
132 #if defined(OS_CHROMEOS)
133 DCHECK(ui::OzonePlatform::GetInstance()->GetInputController());
135 // Temporarily pause tap-to-click when the cursor is hidden.
136 ui::OzonePlatform::GetInstance()->GetInputController()->SetTapToClickPaused(
137 state);
138 #endif
141 } // namespace
143 AshWindowTreeHost* AshWindowTreeHost::Create(
144 const AshWindowTreeHostInitParams& init_params) {
145 return new AshWindowTreeHostOzone(init_params.initial_bounds);
148 } // namespace ash