Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: ash/host/ash_window_tree_host_virtual.cc

Issue 1107733006: Unified Desktop: hook up ash to allow unified desktop mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ash/host/ash_window_tree_host_virtual.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/gfx/geometry/insets.h"
14
15 namespace ash {
16
17 bool IsLocatedEvent(const ui::Event& event) {
18 return event.IsMouseEvent() || event.IsTouchEvent() ||
19 event.IsScrollEvent() || event.IsGestureEvent();
20 }
21
22 class VirtualEventTargeter : public aura::WindowTargeter {
23 public:
24 VirtualEventTargeter(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 (IsLocatedEvent(*event)) {
31 ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event);
32 located_event->ConvertLocationToTarget(
33 static_cast<aura::Window*>(nullptr), dst_root_);
34 located_event->UpdateForRootTransform(
35 dst_root_->GetHost()->GetRootTransform());
36 }
37 ignore_result(
38 dst_root_->GetHost()->event_processor()->OnEventFromSource(event));
39 return nullptr;
40 } else {
41 LOG(ERROR) << "Handling Event:" << event->type();
42 return aura::WindowTargeter::FindTargetForEvent(root, event);
43 }
44 }
45
46 aura::Window* src_root_;
47 aura::Window* dst_root_;
48
49 DISALLOW_COPY_AND_ASSIGN(VirtualEventTargeter);
50 };
51
52 struct AshWindowTreeHostVirtual::PerDisplayData {
Jun Mukai 2015/04/26 23:45:08 I am not sure if PerDisplayData is worthwhile. If
oshima 2015/04/27 17:48:38 Forgot to remove it. thank you for the catch.
53 scoped_ptr<AshWindowTreeHost> ash_host;
54 PerDisplayData(scoped_ptr<AshWindowTreeHost> ash_host)
55 : ash_host(ash_host.Pass()) {}
56 ~PerDisplayData() {}
57 };
58
59 AshWindowTreeHostVirtual::AshWindowTreeHostVirtual(
60 const gfx::Rect& initial_bounds)
61 : bounds_(gfx::Rect(initial_bounds.size())) {
62 CreateCompositor(GetAcceleratedWidget());
63 }
64
65 AshWindowTreeHostVirtual::~AshWindowTreeHostVirtual() {
66 DestroyCompositor();
67 DestroyDispatcher();
68 }
69
70 void AshWindowTreeHostVirtual::PrepareForShutdown() {
71 for (auto host : mirroring_hosts_)
72 host->PrepareForShutdown();
73 }
74
75 void AshWindowTreeHostVirtual::RegisterMirroringHost(
76 AshWindowTreeHost* mirroring_ash_host) {
77 aura::Window* src_root = mirroring_ash_host->AsWindowTreeHost()->window();
78 src_root->SetEventTargeter(
79 make_scoped_ptr(new VirtualEventTargeter(src_root, window())));
80 DCHECK(std::find(mirroring_hosts_.begin(), mirroring_hosts_.end(),
81 mirroring_ash_host) == mirroring_hosts_.end());
82 mirroring_hosts_.push_back(mirroring_ash_host);
83 mirroring_ash_host->AsWindowTreeHost()->window()->AddObserver(this);
84 }
85
86 void AshWindowTreeHostVirtual::ToggleFullScreen() {
87 }
88
89 bool AshWindowTreeHostVirtual::ConfineCursorToRootWindow() {
90 return true;
91 }
92
93 void AshWindowTreeHostVirtual::UnConfineCursor() {
94 }
95
96 void AshWindowTreeHostVirtual::SetRootWindowTransformer(
97 scoped_ptr<RootWindowTransformer> transformer) {
98 // TODO(oshima): Find out if this is neceessary.
99 NOTIMPLEMENTED();
100 }
101
102 gfx::Insets AshWindowTreeHostVirtual::GetHostInsets() const {
103 return gfx::Insets();
104 }
105
106 aura::WindowTreeHost* AshWindowTreeHostVirtual::AsWindowTreeHost() {
107 return this;
108 }
109
110 ui::EventSource* AshWindowTreeHostVirtual::GetEventSource() {
111 return this;
112 }
113
114 gfx::AcceleratedWidget AshWindowTreeHostVirtual::GetAcceleratedWidget() {
115 // TODO(oshima): Enable offscreen compositor.
116 return gfx::kNullAcceleratedWidget;
117 }
118
119 void AshWindowTreeHostVirtual::Show() {
120 }
121
122 void AshWindowTreeHostVirtual::Hide() {
123 }
124
125 gfx::Rect AshWindowTreeHostVirtual::GetBounds() const {
126 return bounds_;
127 }
128
129 void AshWindowTreeHostVirtual::SetBounds(const gfx::Rect& bounds) {
130 if (bounds_.size() == bounds.size())
131 return;
132 bounds_.set_size(bounds.size());
133 OnHostResized(bounds_.size());
134 }
135
136 void AshWindowTreeHostVirtual::SetCapture() {
137 }
138
139 void AshWindowTreeHostVirtual::ReleaseCapture() {
140 }
141
142 gfx::Point AshWindowTreeHostVirtual::GetLocationOnNativeScreen() const {
143 return gfx::Point();
144 }
145
146 void AshWindowTreeHostVirtual::SetCursorNative(gfx::NativeCursor cursor) {
147 for (auto host : mirroring_hosts_)
148 host->AsWindowTreeHost()->SetCursor(cursor);
149 }
150
151 void AshWindowTreeHostVirtual::MoveCursorToNative(const gfx::Point& location) {
152 // TODO(oshima): Find out if this is neceessary.
153 NOTIMPLEMENTED();
154 }
155
156 void AshWindowTreeHostVirtual::OnCursorVisibilityChangedNative(bool show) {
157 for (auto host : mirroring_hosts_)
158 host->AsWindowTreeHost()->OnCursorVisibilityChanged(show);
159 }
160
161 void AshWindowTreeHostVirtual::OnWindowDestroying(aura::Window* window) {
162 auto iter =
163 std::find_if(mirroring_hosts_.begin(), mirroring_hosts_.end(),
164 [window](AshWindowTreeHost* ash_host) {
165 return ash_host->AsWindowTreeHost()->window() == window;
166 });
167 DCHECK(iter != mirroring_hosts_.end());
168 window->RemoveObserver(this);
169 mirroring_hosts_.erase(iter);
170 }
171
172 ui::EventProcessor* AshWindowTreeHostVirtual::GetEventProcessor() {
173 return dispatcher();
174 }
175
176 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698