Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / host / ash_window_tree_host_unified.cc
blobf94d1e277ed1a92baeb3add43a9dea36ad36214c
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();
51 OnAcceleratedWidgetAvailable();
52 transformer_helper_.Init();
55 AshWindowTreeHostUnified::~AshWindowTreeHostUnified() {
56 for (auto* ash_host : mirroring_hosts_)
57 ash_host->AsWindowTreeHost()->window()->RemoveObserver(this);
59 DestroyCompositor();
60 DestroyDispatcher();
63 void AshWindowTreeHostUnified::PrepareForShutdown() {
64 window()->SetEventTargeter(
65 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter));
67 for (auto host : mirroring_hosts_)
68 host->PrepareForShutdown();
71 void AshWindowTreeHostUnified::RegisterMirroringHost(
72 AshWindowTreeHost* mirroring_ash_host) {
73 aura::Window* src_root = mirroring_ash_host->AsWindowTreeHost()->window();
74 src_root->SetEventTargeter(
75 make_scoped_ptr(new UnifiedEventTargeter(src_root, window())));
76 DCHECK(std::find(mirroring_hosts_.begin(), mirroring_hosts_.end(),
77 mirroring_ash_host) == mirroring_hosts_.end());
78 mirroring_hosts_.push_back(mirroring_ash_host);
79 mirroring_ash_host->AsWindowTreeHost()->window()->AddObserver(this);
82 void AshWindowTreeHostUnified::ToggleFullScreen() {
85 bool AshWindowTreeHostUnified::ConfineCursorToRootWindow() {
86 return true;
89 void AshWindowTreeHostUnified::UnConfineCursor() {
92 void AshWindowTreeHostUnified::SetRootWindowTransformer(
93 scoped_ptr<RootWindowTransformer> transformer) {
94 transformer_helper_.SetRootWindowTransformer(transformer.Pass());
97 gfx::Insets AshWindowTreeHostUnified::GetHostInsets() const {
98 return transformer_helper_.GetHostInsets();
101 aura::WindowTreeHost* AshWindowTreeHostUnified::AsWindowTreeHost() {
102 return this;
105 ui::EventSource* AshWindowTreeHostUnified::GetEventSource() {
106 return this;
109 gfx::AcceleratedWidget AshWindowTreeHostUnified::GetAcceleratedWidget() {
110 return gfx::kNullAcceleratedWidget;
113 void AshWindowTreeHostUnified::ShowImpl() {
116 void AshWindowTreeHostUnified::HideImpl() {
119 gfx::Rect AshWindowTreeHostUnified::GetBounds() const {
120 return bounds_;
123 void AshWindowTreeHostUnified::SetBounds(const gfx::Rect& bounds) {
124 bounds_.set_size(bounds.size());
125 OnHostResized(bounds_.size());
128 gfx::Transform AshWindowTreeHostUnified::GetRootTransform() const {
129 return transformer_helper_.GetTransform();
132 void AshWindowTreeHostUnified::SetRootTransform(
133 const gfx::Transform& transform) {
134 transformer_helper_.SetTransform(transform);
137 gfx::Transform AshWindowTreeHostUnified::GetInverseRootTransform() const {
138 return transformer_helper_.GetInverseTransform();
141 void AshWindowTreeHostUnified::UpdateRootWindowSize(
142 const gfx::Size& host_size) {
143 transformer_helper_.UpdateWindowSize(host_size);
146 void AshWindowTreeHostUnified::SetCapture() {
149 void AshWindowTreeHostUnified::ReleaseCapture() {
152 gfx::Point AshWindowTreeHostUnified::GetLocationOnNativeScreen() const {
153 return gfx::Point();
156 void AshWindowTreeHostUnified::SetCursorNative(gfx::NativeCursor cursor) {
157 for (auto host : mirroring_hosts_)
158 host->AsWindowTreeHost()->SetCursor(cursor);
161 void AshWindowTreeHostUnified::MoveCursorToNative(const gfx::Point& location) {
162 // No native cursor in offscreen surface.
165 void AshWindowTreeHostUnified::OnCursorVisibilityChangedNative(bool show) {
166 for (auto host : mirroring_hosts_)
167 host->AsWindowTreeHost()->OnCursorVisibilityChanged(show);
170 void AshWindowTreeHostUnified::OnWindowDestroying(aura::Window* window) {
171 auto iter =
172 std::find_if(mirroring_hosts_.begin(), mirroring_hosts_.end(),
173 [window](AshWindowTreeHost* ash_host) {
174 return ash_host->AsWindowTreeHost()->window() == window;
176 DCHECK(iter != mirroring_hosts_.end());
177 window->RemoveObserver(this);
178 mirroring_hosts_.erase(iter);
181 ui::EventDispatchDetails AshWindowTreeHostUnified::DispatchKeyEventPostIME(
182 ui::KeyEvent* event) {
183 input_method_handler()->SetPostIME(true);
184 ui::EventDispatchDetails details =
185 event_processor()->OnEventFromSource(event);
186 if (!details.dispatcher_destroyed)
187 input_method_handler()->SetPostIME(false);
188 return details;
191 } // namespace ash