Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ash / host / ash_window_tree_host_unified.cc
blob0fcb4b3ef2e7dd818075f9854e8e85cd5ea27298
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_);
31 located_event->UpdateForRootTransform(
32 dst_root_->GetHost()->GetRootTransform());
34 ignore_result(
35 dst_root_->GetHost()->event_processor()->OnEventFromSource(event));
36 return nullptr;
37 } else {
38 NOTREACHED() << "event type:" << event->type();
39 return aura::WindowTargeter::FindTargetForEvent(root, event);
43 aura::Window* src_root_;
44 aura::Window* dst_root_;
46 DISALLOW_COPY_AND_ASSIGN(UnifiedEventTargeter);
49 AshWindowTreeHostUnified::AshWindowTreeHostUnified(
50 const gfx::Rect& initial_bounds)
51 : bounds_(gfx::Rect(initial_bounds.size())), transformer_helper_(this) {
52 CreateCompositor(GetAcceleratedWidget());
53 transformer_helper_.Init();
56 AshWindowTreeHostUnified::~AshWindowTreeHostUnified() {
57 for (auto* ash_host : mirroring_hosts_)
58 ash_host->AsWindowTreeHost()->window()->RemoveObserver(this);
60 DestroyCompositor();
61 DestroyDispatcher();
64 void AshWindowTreeHostUnified::PrepareForShutdown() {
65 window()->SetEventTargeter(
66 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter));
68 for (auto host : mirroring_hosts_)
69 host->PrepareForShutdown();
72 void AshWindowTreeHostUnified::RegisterMirroringHost(
73 AshWindowTreeHost* mirroring_ash_host) {
74 aura::Window* src_root = mirroring_ash_host->AsWindowTreeHost()->window();
75 src_root->SetEventTargeter(
76 make_scoped_ptr(new UnifiedEventTargeter(src_root, window())));
77 DCHECK(std::find(mirroring_hosts_.begin(), mirroring_hosts_.end(),
78 mirroring_ash_host) == mirroring_hosts_.end());
79 mirroring_hosts_.push_back(mirroring_ash_host);
80 mirroring_ash_host->AsWindowTreeHost()->window()->AddObserver(this);
83 void AshWindowTreeHostUnified::ToggleFullScreen() {
86 bool AshWindowTreeHostUnified::ConfineCursorToRootWindow() {
87 return true;
90 void AshWindowTreeHostUnified::UnConfineCursor() {
93 void AshWindowTreeHostUnified::SetRootWindowTransformer(
94 scoped_ptr<RootWindowTransformer> transformer) {
95 transformer_helper_.SetRootWindowTransformer(transformer.Pass());
98 gfx::Insets AshWindowTreeHostUnified::GetHostInsets() const {
99 return transformer_helper_.GetHostInsets();
102 aura::WindowTreeHost* AshWindowTreeHostUnified::AsWindowTreeHost() {
103 return this;
106 ui::EventSource* AshWindowTreeHostUnified::GetEventSource() {
107 return this;
110 gfx::AcceleratedWidget AshWindowTreeHostUnified::GetAcceleratedWidget() {
111 return gfx::kNullAcceleratedWidget;
114 void AshWindowTreeHostUnified::ShowImpl() {
117 void AshWindowTreeHostUnified::HideImpl() {
120 gfx::Rect AshWindowTreeHostUnified::GetBounds() const {
121 return bounds_;
124 void AshWindowTreeHostUnified::SetBounds(const gfx::Rect& bounds) {
125 if (bounds_.size() == bounds.size())
126 return;
127 bounds_.set_size(bounds.size());
128 OnHostResized(bounds_.size());
131 gfx::Transform AshWindowTreeHostUnified::GetRootTransform() const {
132 return transformer_helper_.GetTransform();
135 void AshWindowTreeHostUnified::SetRootTransform(
136 const gfx::Transform& transform) {
137 transformer_helper_.SetTransform(transform);
140 gfx::Transform AshWindowTreeHostUnified::GetInverseRootTransform() const {
141 return transformer_helper_.GetInverseTransform();
144 void AshWindowTreeHostUnified::UpdateRootWindowSize(
145 const gfx::Size& host_size) {
146 transformer_helper_.UpdateWindowSize(host_size);
149 void AshWindowTreeHostUnified::SetCapture() {
152 void AshWindowTreeHostUnified::ReleaseCapture() {
155 gfx::Point AshWindowTreeHostUnified::GetLocationOnNativeScreen() const {
156 return gfx::Point();
159 void AshWindowTreeHostUnified::SetCursorNative(gfx::NativeCursor cursor) {
160 for (auto host : mirroring_hosts_)
161 host->AsWindowTreeHost()->SetCursor(cursor);
164 void AshWindowTreeHostUnified::MoveCursorToNative(const gfx::Point& location) {
165 // TODO(oshima): Find out if this is neceessary.
166 NOTIMPLEMENTED();
169 void AshWindowTreeHostUnified::OnCursorVisibilityChangedNative(bool show) {
170 for (auto host : mirroring_hosts_)
171 host->AsWindowTreeHost()->OnCursorVisibilityChanged(show);
174 void AshWindowTreeHostUnified::OnWindowDestroying(aura::Window* window) {
175 auto iter =
176 std::find_if(mirroring_hosts_.begin(), mirroring_hosts_.end(),
177 [window](AshWindowTreeHost* ash_host) {
178 return ash_host->AsWindowTreeHost()->window() == window;
180 DCHECK(iter != mirroring_hosts_.end());
181 window->RemoveObserver(this);
182 mirroring_hosts_.erase(iter);
185 bool AshWindowTreeHostUnified::DispatchKeyEventPostIME(
186 const ui::KeyEvent& event) {
187 ui::KeyEvent event_copy(event);
188 input_method_handler()->SetPostIME(true);
189 ui::EventDispatchDetails details =
190 event_processor()->OnEventFromSource(&event_copy);
191 if (details.dispatcher_destroyed)
192 return true;
193 input_method_handler()->SetPostIME(false);
194 return event_copy.stopped_propagation();
197 } // namespace ash