blob: ab9a954e8931e6cc9b055835916935e62039cd46 [file] [log] [blame]
oshima55ef9212015-04-27 23:27:031// Copyright 2015 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.
4
5#include "ash/host/ash_window_tree_host_unified.h"
dchengcbf0d9d2015-12-27 22:49:236
7#include <utility>
8
oshima55ef9212015-04-27 23:27:039#include "ash/host/root_window_transformer.h"
oshima5e0fff82015-06-27 01:31:3010#include "ash/ime/input_method_event_handler.h"
oshima55ef9212015-04-27 23:27:0311#include "base/logging.h"
12#include "ui/aura/window.h"
13#include "ui/aura/window_event_dispatcher.h"
14#include "ui/aura/window_targeter.h"
15#include "ui/compositor/compositor.h"
16#include "ui/events/event_processor.h"
oshimab8fb0b72015-04-28 18:25:1017#include "ui/events/null_event_targeter.h"
oshima55ef9212015-04-27 23:27:0318#include "ui/gfx/geometry/insets.h"
19
20namespace ash {
21
22class UnifiedEventTargeter : public aura::WindowTargeter {
23 public:
24 UnifiedEventTargeter(aura::Window* src_root, aura::Window* dst_root)
25 : src_root_(src_root), dst_root_(dst_root) {}
26
27 ui::EventTarget* FindTargetForEvent(ui::EventTarget* root,
28 ui::Event* event) override {
29 if (root == src_root_ && !event->target()) {
30 if (event->IsLocatedEvent()) {
31 ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event);
32 located_event->ConvertLocationToTarget(
33 static_cast<aura::Window*>(nullptr), dst_root_);
oshima55ef9212015-04-27 23:27:0334 }
35 ignore_result(
36 dst_root_->GetHost()->event_processor()->OnEventFromSource(event));
37 return nullptr;
38 } else {
oshimaf8b27692015-04-30 07:23:0039 NOTREACHED() << "event type:" << event->type();
oshima55ef9212015-04-27 23:27:0340 return aura::WindowTargeter::FindTargetForEvent(root, event);
41 }
42 }
43
44 aura::Window* src_root_;
45 aura::Window* dst_root_;
46
47 DISALLOW_COPY_AND_ASSIGN(UnifiedEventTargeter);
48};
49
50AshWindowTreeHostUnified::AshWindowTreeHostUnified(
51 const gfx::Rect& initial_bounds)
oshima38dffad2015-05-05 17:22:5652 : bounds_(gfx::Rect(initial_bounds.size())), transformer_helper_(this) {
sieversb2a31d3372015-08-25 19:27:1353 CreateCompositor();
54 OnAcceleratedWidgetAvailable();
oshima38dffad2015-05-05 17:22:5655 transformer_helper_.Init();
oshima55ef9212015-04-27 23:27:0356}
57
58AshWindowTreeHostUnified::~AshWindowTreeHostUnified() {
oshimac2f69582015-05-20 22:04:5459 for (auto* ash_host : mirroring_hosts_)
60 ash_host->AsWindowTreeHost()->window()->RemoveObserver(this);
61
oshima55ef9212015-04-27 23:27:0362 DestroyCompositor();
63 DestroyDispatcher();
64}
65
66void AshWindowTreeHostUnified::PrepareForShutdown() {
oshimab8fb0b72015-04-28 18:25:1067 window()->SetEventTargeter(
68 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter));
69
oshima55ef9212015-04-27 23:27:0370 for (auto host : mirroring_hosts_)
71 host->PrepareForShutdown();
72}
73
74void AshWindowTreeHostUnified::RegisterMirroringHost(
75 AshWindowTreeHost* mirroring_ash_host) {
76 aura::Window* src_root = mirroring_ash_host->AsWindowTreeHost()->window();
77 src_root->SetEventTargeter(
78 make_scoped_ptr(new UnifiedEventTargeter(src_root, window())));
79 DCHECK(std::find(mirroring_hosts_.begin(), mirroring_hosts_.end(),
80 mirroring_ash_host) == mirroring_hosts_.end());
81 mirroring_hosts_.push_back(mirroring_ash_host);
82 mirroring_ash_host->AsWindowTreeHost()->window()->AddObserver(this);
83}
84
85void AshWindowTreeHostUnified::ToggleFullScreen() {
86}
87
88bool AshWindowTreeHostUnified::ConfineCursorToRootWindow() {
89 return true;
90}
91
92void AshWindowTreeHostUnified::UnConfineCursor() {
93}
94
95void AshWindowTreeHostUnified::SetRootWindowTransformer(
96 scoped_ptr<RootWindowTransformer> transformer) {
dchengcbf0d9d2015-12-27 22:49:2397 transformer_helper_.SetRootWindowTransformer(std::move(transformer));
oshima55ef9212015-04-27 23:27:0398}
99
100gfx::Insets AshWindowTreeHostUnified::GetHostInsets() const {
oshima38dffad2015-05-05 17:22:56101 return transformer_helper_.GetHostInsets();
oshima55ef9212015-04-27 23:27:03102}
103
104aura::WindowTreeHost* AshWindowTreeHostUnified::AsWindowTreeHost() {
105 return this;
106}
107
108ui::EventSource* AshWindowTreeHostUnified::GetEventSource() {
109 return this;
110}
111
112gfx::AcceleratedWidget AshWindowTreeHostUnified::GetAcceleratedWidget() {
oshima55ef9212015-04-27 23:27:03113 return gfx::kNullAcceleratedWidget;
114}
115
jbauman8da589a2015-06-04 02:23:12116void AshWindowTreeHostUnified::ShowImpl() {
oshima55ef9212015-04-27 23:27:03117}
118
jbauman8da589a2015-06-04 02:23:12119void AshWindowTreeHostUnified::HideImpl() {
oshima55ef9212015-04-27 23:27:03120}
121
122gfx::Rect AshWindowTreeHostUnified::GetBounds() const {
123 return bounds_;
124}
125
126void AshWindowTreeHostUnified::SetBounds(const gfx::Rect& bounds) {
oshima55ef9212015-04-27 23:27:03127 bounds_.set_size(bounds.size());
128 OnHostResized(bounds_.size());
129}
130
oshima38dffad2015-05-05 17:22:56131gfx::Transform AshWindowTreeHostUnified::GetRootTransform() const {
132 return transformer_helper_.GetTransform();
133}
134
135void AshWindowTreeHostUnified::SetRootTransform(
136 const gfx::Transform& transform) {
137 transformer_helper_.SetTransform(transform);
138}
139
140gfx::Transform AshWindowTreeHostUnified::GetInverseRootTransform() const {
141 return transformer_helper_.GetInverseTransform();
142}
143
144void AshWindowTreeHostUnified::UpdateRootWindowSize(
145 const gfx::Size& host_size) {
146 transformer_helper_.UpdateWindowSize(host_size);
147}
148
oshima55ef9212015-04-27 23:27:03149void AshWindowTreeHostUnified::SetCapture() {
150}
151
152void AshWindowTreeHostUnified::ReleaseCapture() {
153}
154
155gfx::Point AshWindowTreeHostUnified::GetLocationOnNativeScreen() const {
156 return gfx::Point();
157}
158
159void AshWindowTreeHostUnified::SetCursorNative(gfx::NativeCursor cursor) {
160 for (auto host : mirroring_hosts_)
161 host->AsWindowTreeHost()->SetCursor(cursor);
162}
163
164void AshWindowTreeHostUnified::MoveCursorToNative(const gfx::Point& location) {
oshimaaf6e8572015-07-30 19:41:57165 // No native cursor in offscreen surface.
oshima55ef9212015-04-27 23:27:03166}
167
168void AshWindowTreeHostUnified::OnCursorVisibilityChangedNative(bool show) {
169 for (auto host : mirroring_hosts_)
170 host->AsWindowTreeHost()->OnCursorVisibilityChanged(show);
171}
172
173void AshWindowTreeHostUnified::OnWindowDestroying(aura::Window* window) {
174 auto iter =
175 std::find_if(mirroring_hosts_.begin(), mirroring_hosts_.end(),
176 [window](AshWindowTreeHost* ash_host) {
177 return ash_host->AsWindowTreeHost()->window() == window;
178 });
179 DCHECK(iter != mirroring_hosts_.end());
180 window->RemoveObserver(this);
181 mirroring_hosts_.erase(iter);
182}
183
shuchen59c2a2cf2015-08-04 09:47:50184ui::EventDispatchDetails AshWindowTreeHostUnified::DispatchKeyEventPostIME(
185 ui::KeyEvent* event) {
oshima5e0fff82015-06-27 01:31:30186 input_method_handler()->SetPostIME(true);
shuchen2bfd5db2015-07-23 01:28:38187 ui::EventDispatchDetails details =
shuchen59c2a2cf2015-08-04 09:47:50188 event_processor()->OnEventFromSource(event);
189 if (!details.dispatcher_destroyed)
190 input_method_handler()->SetPostIME(false);
191 return details;
oshima5e0fff82015-06-27 01:31:30192}
193
oshima55ef9212015-04-27 23:27:03194} // namespace ash