Add ICU message format support
[chromium-blink-merge.git] / ash / host / ash_window_tree_host_unified.cc
blob2759af6d1332e6fbc73cfe989cd27011b2c7c3ff
1 // 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.
5 #include "ash/host/ash_window_tree_host_unified.h"
6 #include "ash/host/root_window_transformer.h"
7 #include "ash/ime/input_method_event_handler.h"
8 #include "base/logging.h"
9 #include "ui/aura/window.h"
10 #include "ui/aura/window_event_dispatcher.h"
11 #include "ui/aura/window_targeter.h"
12 #include "ui/compositor/compositor.h"
13 #include "ui/events/event_processor.h"
14 #include "ui/events/null_event_targeter.h"
15 #include "ui/gfx/geometry/insets.h"
17 namespace ash {
19 class UnifiedEventTargeter : public aura::WindowTargeter {
20 public:
21 UnifiedEventTargeter(aura::Window* src_root, aura::Window* dst_root)
22 : src_root_(src_root), dst_root_(dst_root) {}
24 ui::EventTarget* FindTargetForEvent(ui::EventTarget* root,
25 ui::Event* event) override {
26 if (root == src_root_ && !event->target()) {
27 if (event->IsLocatedEvent()) {
28 ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event);
29 located_event->ConvertLocationToTarget(
30 static_cast<aura::Window*>(nullptr), dst_root_);
32 ignore_result(
33 dst_root_->GetHost()->event_processor()->OnEventFromSource(event));
34 return nullptr;
35 } else {
36 NOTREACHED() << "event type:" << event->type();
37 return aura::WindowTargeter::FindTargetForEvent(root, event);
41 aura::Window* src_root_;
42 aura::Window* dst_root_;
44 DISALLOW_COPY_AND_ASSIGN(UnifiedEventTargeter);
47 AshWindowTreeHostUnified::AshWindowTreeHostUnified(
48 const gfx::Rect& initial_bounds)
49 : bounds_(gfx::Rect(initial_bounds.size())), transformer_helper_(this) {
50 CreateCompositor(GetAcceleratedWidget());
51 transformer_helper_.Init();
54 AshWindowTreeHostUnified::~AshWindowTreeHostUnified() {
55 for (auto* ash_host : mirroring_hosts_)
56 ash_host->AsWindowTreeHost()->window()->RemoveObserver(this);
58 DestroyCompositor();
59 DestroyDispatcher();
62 void AshWindowTreeHostUnified::PrepareForShutdown() {
63 window()->SetEventTargeter(
64 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter));
66 for (auto host : mirroring_hosts_)
67 host->PrepareForShutdown();
70 void AshWindowTreeHostUnified::RegisterMirroringHost(
71 AshWindowTreeHost* mirroring_ash_host) {
72 aura::Window* src_root = mirroring_ash_host->AsWindowTreeHost()->window();
73 src_root->SetEventTargeter(
74 make_scoped_ptr(new UnifiedEventTargeter(src_root, window())));
75 DCHECK(std::find(mirroring_hosts_.begin(), mirroring_hosts_.end(),
76 mirroring_ash_host) == mirroring_hosts_.end());
77 mirroring_hosts_.push_back(mirroring_ash_host);
78 mirroring_ash_host->AsWindowTreeHost()->window()->AddObserver(this);
81 void AshWindowTreeHostUnified::ToggleFullScreen() {
84 bool AshWindowTreeHostUnified::ConfineCursorToRootWindow() {
85 return true;
88 void AshWindowTreeHostUnified::UnConfineCursor() {
91 void AshWindowTreeHostUnified::SetRootWindowTransformer(
92 scoped_ptr<RootWindowTransformer> transformer) {
93 transformer_helper_.SetRootWindowTransformer(transformer.Pass());
96 gfx::Insets AshWindowTreeHostUnified::GetHostInsets() const {
97 return transformer_helper_.GetHostInsets();
100 aura::WindowTreeHost* AshWindowTreeHostUnified::AsWindowTreeHost() {
101 return this;
104 ui::EventSource* AshWindowTreeHostUnified::GetEventSource() {
105 return this;
108 gfx::AcceleratedWidget AshWindowTreeHostUnified::GetAcceleratedWidget() {
109 return gfx::kNullAcceleratedWidget;
112 void AshWindowTreeHostUnified::ShowImpl() {
115 void AshWindowTreeHostUnified::HideImpl() {
118 gfx::Rect AshWindowTreeHostUnified::GetBounds() const {
119 return bounds_;
122 void AshWindowTreeHostUnified::SetBounds(const gfx::Rect& bounds) {
123 bounds_.set_size(bounds.size());
124 OnHostResized(bounds_.size());
127 gfx::Transform AshWindowTreeHostUnified::GetRootTransform() const {
128 return transformer_helper_.GetTransform();
131 void AshWindowTreeHostUnified::SetRootTransform(
132 const gfx::Transform& transform) {
133 transformer_helper_.SetTransform(transform);
136 gfx::Transform AshWindowTreeHostUnified::GetInverseRootTransform() const {
137 return transformer_helper_.GetInverseTransform();
140 void AshWindowTreeHostUnified::UpdateRootWindowSize(
141 const gfx::Size& host_size) {
142 transformer_helper_.UpdateWindowSize(host_size);
145 void AshWindowTreeHostUnified::SetCapture() {
148 void AshWindowTreeHostUnified::ReleaseCapture() {
151 gfx::Point AshWindowTreeHostUnified::GetLocationOnNativeScreen() const {
152 return gfx::Point();
155 void AshWindowTreeHostUnified::SetCursorNative(gfx::NativeCursor cursor) {
156 for (auto host : mirroring_hosts_)
157 host->AsWindowTreeHost()->SetCursor(cursor);
160 void AshWindowTreeHostUnified::MoveCursorToNative(const gfx::Point& location) {
161 // No native cursor in offscreen surface.
164 void AshWindowTreeHostUnified::OnCursorVisibilityChangedNative(bool show) {
165 for (auto host : mirroring_hosts_)
166 host->AsWindowTreeHost()->OnCursorVisibilityChanged(show);
169 void AshWindowTreeHostUnified::OnWindowDestroying(aura::Window* window) {
170 auto iter =
171 std::find_if(mirroring_hosts_.begin(), mirroring_hosts_.end(),
172 [window](AshWindowTreeHost* ash_host) {
173 return ash_host->AsWindowTreeHost()->window() == window;
175 DCHECK(iter != mirroring_hosts_.end());
176 window->RemoveObserver(this);
177 mirroring_hosts_.erase(iter);
180 ui::EventDispatchDetails AshWindowTreeHostUnified::DispatchKeyEventPostIME(
181 ui::KeyEvent* event) {
182 input_method_handler()->SetPostIME(true);
183 ui::EventDispatchDetails details =
184 event_processor()->OnEventFromSource(event);
185 if (!details.dispatcher_destroyed)
186 input_method_handler()->SetPostIME(false);
187 return details;
190 } // namespace ash