Chromium Code Reviews| OLD | NEW |
|---|---|
| (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) { | |
|
Jun Mukai
2015/04/27 18:23:40
ui::Event has IsLocatedEvent() method.
oshima
2015/04/27 20:30:55
thanks, done.
| |
| 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 AshWindowTreeHostVirtual::AshWindowTreeHostVirtual( | |
| 53 const gfx::Rect& initial_bounds) | |
| 54 : bounds_(gfx::Rect(initial_bounds.size())) { | |
| 55 CreateCompositor(GetAcceleratedWidget()); | |
| 56 } | |
| 57 | |
| 58 AshWindowTreeHostVirtual::~AshWindowTreeHostVirtual() { | |
| 59 DestroyCompositor(); | |
| 60 DestroyDispatcher(); | |
| 61 } | |
| 62 | |
| 63 void AshWindowTreeHostVirtual::PrepareForShutdown() { | |
| 64 for (auto host : mirroring_hosts_) | |
| 65 host->PrepareForShutdown(); | |
| 66 } | |
| 67 | |
| 68 void AshWindowTreeHostVirtual::RegisterMirroringHost( | |
| 69 AshWindowTreeHost* mirroring_ash_host) { | |
| 70 aura::Window* src_root = mirroring_ash_host->AsWindowTreeHost()->window(); | |
| 71 src_root->SetEventTargeter( | |
| 72 make_scoped_ptr(new VirtualEventTargeter(src_root, window()))); | |
| 73 DCHECK(std::find(mirroring_hosts_.begin(), mirroring_hosts_.end(), | |
| 74 mirroring_ash_host) == mirroring_hosts_.end()); | |
| 75 mirroring_hosts_.push_back(mirroring_ash_host); | |
| 76 mirroring_ash_host->AsWindowTreeHost()->window()->AddObserver(this); | |
| 77 } | |
| 78 | |
| 79 void AshWindowTreeHostVirtual::ToggleFullScreen() { | |
| 80 } | |
| 81 | |
| 82 bool AshWindowTreeHostVirtual::ConfineCursorToRootWindow() { | |
| 83 return true; | |
| 84 } | |
| 85 | |
| 86 void AshWindowTreeHostVirtual::UnConfineCursor() { | |
| 87 } | |
| 88 | |
| 89 void AshWindowTreeHostVirtual::SetRootWindowTransformer( | |
| 90 scoped_ptr<RootWindowTransformer> transformer) { | |
| 91 // TODO(oshima): Find out if this is neceessary. | |
| 92 NOTIMPLEMENTED(); | |
| 93 } | |
| 94 | |
| 95 gfx::Insets AshWindowTreeHostVirtual::GetHostInsets() const { | |
| 96 return gfx::Insets(); | |
| 97 } | |
| 98 | |
| 99 aura::WindowTreeHost* AshWindowTreeHostVirtual::AsWindowTreeHost() { | |
| 100 return this; | |
| 101 } | |
| 102 | |
| 103 ui::EventSource* AshWindowTreeHostVirtual::GetEventSource() { | |
| 104 return this; | |
| 105 } | |
| 106 | |
| 107 gfx::AcceleratedWidget AshWindowTreeHostVirtual::GetAcceleratedWidget() { | |
| 108 // TODO(oshima): Enable offscreen compositor. | |
| 109 return gfx::kNullAcceleratedWidget; | |
| 110 } | |
| 111 | |
| 112 void AshWindowTreeHostVirtual::Show() { | |
| 113 } | |
| 114 | |
| 115 void AshWindowTreeHostVirtual::Hide() { | |
| 116 } | |
| 117 | |
| 118 gfx::Rect AshWindowTreeHostVirtual::GetBounds() const { | |
| 119 return bounds_; | |
| 120 } | |
| 121 | |
| 122 void AshWindowTreeHostVirtual::SetBounds(const gfx::Rect& bounds) { | |
| 123 if (bounds_.size() == bounds.size()) | |
| 124 return; | |
| 125 bounds_.set_size(bounds.size()); | |
| 126 OnHostResized(bounds_.size()); | |
| 127 } | |
| 128 | |
| 129 void AshWindowTreeHostVirtual::SetCapture() { | |
| 130 } | |
| 131 | |
| 132 void AshWindowTreeHostVirtual::ReleaseCapture() { | |
| 133 } | |
| 134 | |
| 135 gfx::Point AshWindowTreeHostVirtual::GetLocationOnNativeScreen() const { | |
| 136 return gfx::Point(); | |
| 137 } | |
| 138 | |
| 139 void AshWindowTreeHostVirtual::SetCursorNative(gfx::NativeCursor cursor) { | |
| 140 for (auto host : mirroring_hosts_) | |
| 141 host->AsWindowTreeHost()->SetCursor(cursor); | |
| 142 } | |
| 143 | |
| 144 void AshWindowTreeHostVirtual::MoveCursorToNative(const gfx::Point& location) { | |
| 145 // TODO(oshima): Find out if this is neceessary. | |
| 146 NOTIMPLEMENTED(); | |
| 147 } | |
| 148 | |
| 149 void AshWindowTreeHostVirtual::OnCursorVisibilityChangedNative(bool show) { | |
| 150 for (auto host : mirroring_hosts_) | |
| 151 host->AsWindowTreeHost()->OnCursorVisibilityChanged(show); | |
| 152 } | |
| 153 | |
| 154 void AshWindowTreeHostVirtual::OnWindowDestroying(aura::Window* window) { | |
| 155 auto iter = | |
| 156 std::find_if(mirroring_hosts_.begin(), mirroring_hosts_.end(), | |
| 157 [window](AshWindowTreeHost* ash_host) { | |
| 158 return ash_host->AsWindowTreeHost()->window() == window; | |
| 159 }); | |
| 160 DCHECK(iter != mirroring_hosts_.end()); | |
| 161 window->RemoveObserver(this); | |
| 162 mirroring_hosts_.erase(iter); | |
| 163 } | |
| 164 | |
| 165 ui::EventProcessor* AshWindowTreeHostVirtual::GetEventProcessor() { | |
| 166 return dispatcher(); | |
| 167 } | |
| 168 | |
| 169 } // namespace ash | |
| OLD | NEW |