Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / ash / host / ash_window_tree_host_ozone.cc
blobcb2ec66e33dc4e08f0b2924c5a14473b2c71dac1
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 "base/trace_event/trace_event.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_tree_host_ozone.h"
14 #include "ui/events/null_event_targeter.h"
15 #include "ui/gfx/geometry/insets.h"
16 #include "ui/gfx/transform.h"
17 #include "ui/ozone/public/input_controller.h"
18 #include "ui/ozone/public/ozone_platform.h"
19 #include "ui/platform_window/platform_window.h"
21 namespace ash {
22 namespace {
24 class AshWindowTreeHostOzone : public AshWindowTreeHost,
25 public aura::WindowTreeHostOzone {
26 public:
27 explicit AshWindowTreeHostOzone(const gfx::Rect& initial_bounds);
28 ~AshWindowTreeHostOzone() override;
30 private:
31 // AshWindowTreeHost:
32 void ToggleFullScreen() override;
33 bool ConfineCursorToRootWindow() override;
34 void UnConfineCursor() override;
35 void SetRootWindowTransformer(
36 scoped_ptr<RootWindowTransformer> transformer) override;
37 gfx::Insets GetHostInsets() const override;
38 aura::WindowTreeHost* AsWindowTreeHost() override;
39 void PrepareForShutdown() override;
40 void SetRootTransform(const gfx::Transform& transform) override;
41 gfx::Transform GetRootTransform() const override;
42 gfx::Transform GetInverseRootTransform() const override;
43 void UpdateRootWindowSize(const gfx::Size& host_size) override;
44 void OnCursorVisibilityChangedNative(bool show) override;
45 void SetBounds(const gfx::Rect& bounds) override;
46 void DispatchEvent(ui::Event* event) override;
48 // Temporarily disable the tap-to-click feature. Used on CrOS.
49 void SetTapToClickPaused(bool state);
51 TransformerHelper transformer_helper_;
53 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone);
56 AshWindowTreeHostOzone::AshWindowTreeHostOzone(const gfx::Rect& initial_bounds)
57 : aura::WindowTreeHostOzone(initial_bounds), transformer_helper_(this) {
60 AshWindowTreeHostOzone::~AshWindowTreeHostOzone() {
63 void AshWindowTreeHostOzone::ToggleFullScreen() {
64 NOTIMPLEMENTED();
67 bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() {
68 gfx::Rect confined_bounds(GetBounds().size());
69 confined_bounds.Inset(transformer_helper_.GetHostInsets());
70 platform_window()->ConfineCursorToBounds(confined_bounds);
71 return true;
74 void AshWindowTreeHostOzone::UnConfineCursor() {
75 NOTIMPLEMENTED();
78 void AshWindowTreeHostOzone::SetRootWindowTransformer(
79 scoped_ptr<RootWindowTransformer> transformer) {
80 transformer_helper_.SetRootWindowTransformer(transformer.Pass());
81 ConfineCursorToRootWindow();
84 gfx::Insets AshWindowTreeHostOzone::GetHostInsets() const {
85 return transformer_helper_.GetHostInsets();
88 aura::WindowTreeHost* AshWindowTreeHostOzone::AsWindowTreeHost() {
89 return this;
92 void AshWindowTreeHostOzone::PrepareForShutdown() {
93 // Block the root window from dispatching events because it is weird for a
94 // ScreenPositionClient not to be attached to the root window and for
95 // ui::EventHandlers to be unable to convert the event's location to screen
96 // coordinates.
97 window()->SetEventTargeter(
98 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter));
101 void AshWindowTreeHostOzone::SetRootTransform(const gfx::Transform& transform) {
102 transformer_helper_.SetTransform(transform);
105 gfx::Transform AshWindowTreeHostOzone::GetRootTransform() const {
106 return transformer_helper_.GetTransform();
109 gfx::Transform AshWindowTreeHostOzone::GetInverseRootTransform() const {
110 return transformer_helper_.GetInverseTransform();
113 void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size& host_size) {
114 transformer_helper_.UpdateWindowSize(host_size);
117 void AshWindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show) {
118 SetTapToClickPaused(!show);
121 void AshWindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) {
122 WindowTreeHostOzone::SetBounds(bounds);
123 ConfineCursorToRootWindow();
126 void AshWindowTreeHostOzone::DispatchEvent(ui::Event* event) {
127 TRACE_EVENT0("input", "AshWindowTreeHostOzone::DispatchEvent");
128 if (event->IsLocatedEvent())
129 TranslateLocatedEvent(static_cast<ui::LocatedEvent*>(event));
130 SendEventToProcessor(event);
133 void AshWindowTreeHostOzone::SetTapToClickPaused(bool state) {
134 #if defined(OS_CHROMEOS)
135 DCHECK(ui::OzonePlatform::GetInstance()->GetInputController());
137 // Temporarily pause tap-to-click when the cursor is hidden.
138 ui::OzonePlatform::GetInstance()->GetInputController()->SetTapToClickPaused(
139 state);
140 #endif
143 } // namespace
145 AshWindowTreeHost* AshWindowTreeHost::Create(
146 const AshWindowTreeHostInitParams& init_params) {
147 return new AshWindowTreeHostOzone(init_params.initial_bounds);
150 } // namespace ash