Preserve viewport scrolling layer when a fling starts
[chromium-blink-merge.git] / ash / host / ash_window_tree_host_ozone.cc
blob3926fdff12425cf19e57a6def2fa79834016e7de
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/null_event_targeter.h"
17 #include "ui/gfx/geometry/insets.h"
18 #include "ui/gfx/transform.h"
19 #include "ui/ozone/public/input_controller.h"
20 #include "ui/ozone/public/ozone_platform.h"
21 #include "ui/platform_window/platform_window.h"
23 namespace ash {
24 namespace {
26 class AshWindowTreeHostOzone : public AshWindowTreeHost,
27 public aura::WindowTreeHostOzone {
28 public:
29 explicit AshWindowTreeHostOzone(const gfx::Rect& initial_bounds);
30 ~AshWindowTreeHostOzone() override;
32 private:
33 // AshWindowTreeHost:
34 void ToggleFullScreen() override;
35 bool ConfineCursorToRootWindow() override;
36 void UnConfineCursor() override;
37 void SetRootWindowTransformer(
38 scoped_ptr<RootWindowTransformer> transformer) override;
39 gfx::Insets GetHostInsets() const override;
40 aura::WindowTreeHost* AsWindowTreeHost() override;
41 void PrepareForShutdown() override;
42 void SetRootTransform(const gfx::Transform& transform) override;
43 gfx::Transform GetRootTransform() const override;
44 gfx::Transform GetInverseRootTransform() const override;
45 void UpdateRootWindowSize(const gfx::Size& host_size) override;
46 void OnCursorVisibilityChangedNative(bool show) override;
47 void SetBounds(const gfx::Rect& bounds) override;
48 void DispatchEvent(ui::Event* event) override;
50 // ui::internal::InputMethodDelegate:
51 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override;
53 // ui::EventSource:
54 ui::EventDispatchDetails DeliverEventToProcessor(ui::Event* event) override {
55 return ui::EventSource::DeliverEventToProcessor(event);
58 // Temporarily disable the tap-to-click feature. Used on CrOS.
59 void SetTapToClickPaused(bool state);
61 TransformerHelper transformer_helper_;
63 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone);
66 AshWindowTreeHostOzone::AshWindowTreeHostOzone(const gfx::Rect& initial_bounds)
67 : aura::WindowTreeHostOzone(initial_bounds), transformer_helper_(this) {
68 transformer_helper_.Init();
71 AshWindowTreeHostOzone::~AshWindowTreeHostOzone() {
74 void AshWindowTreeHostOzone::ToggleFullScreen() {
75 NOTIMPLEMENTED();
78 bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() {
79 gfx::Rect confined_bounds(GetBounds().size());
80 confined_bounds.Inset(transformer_helper_.GetHostInsets());
81 platform_window()->ConfineCursorToBounds(confined_bounds);
82 return true;
85 void AshWindowTreeHostOzone::UnConfineCursor() {
86 NOTIMPLEMENTED();
89 void AshWindowTreeHostOzone::SetRootWindowTransformer(
90 scoped_ptr<RootWindowTransformer> transformer) {
91 transformer_helper_.SetRootWindowTransformer(transformer.Pass());
92 ConfineCursorToRootWindow();
95 gfx::Insets AshWindowTreeHostOzone::GetHostInsets() const {
96 return transformer_helper_.GetHostInsets();
99 aura::WindowTreeHost* AshWindowTreeHostOzone::AsWindowTreeHost() {
100 return this;
103 void AshWindowTreeHostOzone::PrepareForShutdown() {
104 // Block the root window from dispatching events because it is weird for a
105 // ScreenPositionClient not to be attached to the root window and for
106 // ui::EventHandlers to be unable to convert the event's location to screen
107 // coordinates.
108 window()->SetEventTargeter(
109 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter));
112 void AshWindowTreeHostOzone::SetRootTransform(const gfx::Transform& transform) {
113 transformer_helper_.SetTransform(transform);
116 gfx::Transform AshWindowTreeHostOzone::GetRootTransform() const {
117 return transformer_helper_.GetTransform();
120 gfx::Transform AshWindowTreeHostOzone::GetInverseRootTransform() const {
121 return transformer_helper_.GetInverseTransform();
124 void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size& host_size) {
125 transformer_helper_.UpdateWindowSize(host_size);
128 void AshWindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show) {
129 SetTapToClickPaused(!show);
132 void AshWindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) {
133 WindowTreeHostOzone::SetBounds(bounds);
134 ConfineCursorToRootWindow();
137 void AshWindowTreeHostOzone::DispatchEvent(ui::Event* event) {
138 TRACE_EVENT0("input", "AshWindowTreeHostOzone::DispatchEvent");
139 if (event->IsLocatedEvent())
140 TranslateLocatedEvent(static_cast<ui::LocatedEvent*>(event));
141 SendEventToProcessor(event);
144 bool AshWindowTreeHostOzone::DispatchKeyEventPostIME(
145 const ui::KeyEvent& event) {
146 ui::KeyEvent event_copy(event);
147 input_method_handler()->SetPostIME(true);
148 ui::EventSource::DeliverEventToProcessor(&event_copy);
149 input_method_handler()->SetPostIME(false);
150 return event_copy.handled();
153 void AshWindowTreeHostOzone::SetTapToClickPaused(bool state) {
154 #if defined(OS_CHROMEOS)
155 DCHECK(ui::OzonePlatform::GetInstance()->GetInputController());
157 // Temporarily pause tap-to-click when the cursor is hidden.
158 ui::OzonePlatform::GetInstance()->GetInputController()->SetTapToClickPaused(
159 state);
160 #endif
163 } // namespace
165 AshWindowTreeHost* AshWindowTreeHost::Create(
166 const AshWindowTreeHostInitParams& init_params) {
167 if (init_params.offscreen)
168 return new AshWindowTreeHostUnified(init_params.initial_bounds);
169 return new AshWindowTreeHostOzone(init_params.initial_bounds);
172 } // namespace ash