Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / ash / host / ash_window_tree_host_unified.cc
blobccc04428c7931e22aa947a46884b7339d85ef2d3
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 "base/logging.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_event_dispatcher.h"
10 #include "ui/aura/window_targeter.h"
11 #include "ui/compositor/compositor.h"
12 #include "ui/events/event_processor.h"
13 #include "ui/events/null_event_targeter.h"
14 #include "ui/gfx/geometry/insets.h"
16 namespace ash {
18 class UnifiedEventTargeter : public aura::WindowTargeter {
19 public:
20 UnifiedEventTargeter(aura::Window* src_root, aura::Window* dst_root)
21 : src_root_(src_root), dst_root_(dst_root) {}
23 ui::EventTarget* FindTargetForEvent(ui::EventTarget* root,
24 ui::Event* event) override {
25 if (root == src_root_ && !event->target()) {
26 if (event->IsLocatedEvent()) {
27 ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event);
28 located_event->ConvertLocationToTarget(
29 static_cast<aura::Window*>(nullptr), dst_root_);
30 located_event->UpdateForRootTransform(
31 dst_root_->GetHost()->GetRootTransform());
33 ignore_result(
34 dst_root_->GetHost()->event_processor()->OnEventFromSource(event));
35 return nullptr;
36 } else {
37 NOTREACHED() << "event type:" << event->type();
38 return aura::WindowTargeter::FindTargetForEvent(root, event);
42 aura::Window* src_root_;
43 aura::Window* dst_root_;
45 DISALLOW_COPY_AND_ASSIGN(UnifiedEventTargeter);
48 AshWindowTreeHostUnified::AshWindowTreeHostUnified(
49 const gfx::Rect& initial_bounds)
50 : bounds_(gfx::Rect(initial_bounds.size())) {
51 CreateCompositor(GetAcceleratedWidget());
54 AshWindowTreeHostUnified::~AshWindowTreeHostUnified() {
55 DestroyCompositor();
56 DestroyDispatcher();
59 void AshWindowTreeHostUnified::PrepareForShutdown() {
60 window()->SetEventTargeter(
61 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter));
63 for (auto host : mirroring_hosts_)
64 host->PrepareForShutdown();
67 void AshWindowTreeHostUnified::RegisterMirroringHost(
68 AshWindowTreeHost* mirroring_ash_host) {
69 aura::Window* src_root = mirroring_ash_host->AsWindowTreeHost()->window();
70 src_root->SetEventTargeter(
71 make_scoped_ptr(new UnifiedEventTargeter(src_root, window())));
72 DCHECK(std::find(mirroring_hosts_.begin(), mirroring_hosts_.end(),
73 mirroring_ash_host) == mirroring_hosts_.end());
74 mirroring_hosts_.push_back(mirroring_ash_host);
75 mirroring_ash_host->AsWindowTreeHost()->window()->AddObserver(this);
78 void AshWindowTreeHostUnified::ToggleFullScreen() {
81 bool AshWindowTreeHostUnified::ConfineCursorToRootWindow() {
82 return true;
85 void AshWindowTreeHostUnified::UnConfineCursor() {
88 void AshWindowTreeHostUnified::SetRootWindowTransformer(
89 scoped_ptr<RootWindowTransformer> transformer) {
90 // TODO(oshima): Find out if this is neceessary.
91 NOTIMPLEMENTED();
94 gfx::Insets AshWindowTreeHostUnified::GetHostInsets() const {
95 return gfx::Insets();
98 aura::WindowTreeHost* AshWindowTreeHostUnified::AsWindowTreeHost() {
99 return this;
102 ui::EventSource* AshWindowTreeHostUnified::GetEventSource() {
103 return this;
106 gfx::AcceleratedWidget AshWindowTreeHostUnified::GetAcceleratedWidget() {
107 return gfx::kNullAcceleratedWidget;
110 void AshWindowTreeHostUnified::Show() {
113 void AshWindowTreeHostUnified::Hide() {
116 gfx::Rect AshWindowTreeHostUnified::GetBounds() const {
117 return bounds_;
120 void AshWindowTreeHostUnified::SetBounds(const gfx::Rect& bounds) {
121 if (bounds_.size() == bounds.size())
122 return;
123 bounds_.set_size(bounds.size());
124 OnHostResized(bounds_.size());
127 void AshWindowTreeHostUnified::SetCapture() {
130 void AshWindowTreeHostUnified::ReleaseCapture() {
133 gfx::Point AshWindowTreeHostUnified::GetLocationOnNativeScreen() const {
134 return gfx::Point();
137 void AshWindowTreeHostUnified::SetCursorNative(gfx::NativeCursor cursor) {
138 for (auto host : mirroring_hosts_)
139 host->AsWindowTreeHost()->SetCursor(cursor);
142 void AshWindowTreeHostUnified::MoveCursorToNative(const gfx::Point& location) {
143 // TODO(oshima): Find out if this is neceessary.
144 NOTIMPLEMENTED();
147 void AshWindowTreeHostUnified::OnCursorVisibilityChangedNative(bool show) {
148 for (auto host : mirroring_hosts_)
149 host->AsWindowTreeHost()->OnCursorVisibilityChanged(show);
152 void AshWindowTreeHostUnified::OnWindowDestroying(aura::Window* window) {
153 auto iter =
154 std::find_if(mirroring_hosts_.begin(), mirroring_hosts_.end(),
155 [window](AshWindowTreeHost* ash_host) {
156 return ash_host->AsWindowTreeHost()->window() == window;
158 DCHECK(iter != mirroring_hosts_.end());
159 window->RemoveObserver(this);
160 mirroring_hosts_.erase(iter);
163 ui::EventProcessor* AshWindowTreeHostUnified::GetEventProcessor() {
164 return dispatcher();
167 } // namespace ash