Chromium Code Reviews| Index: ash/host/ash_window_tree_host_virtual.cc |
| diff --git a/ash/host/ash_window_tree_host_virtual.cc b/ash/host/ash_window_tree_host_virtual.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..32a5ce42ba87a0adbeaff608344691dd63f72dee |
| --- /dev/null |
| +++ b/ash/host/ash_window_tree_host_virtual.cc |
| @@ -0,0 +1,176 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/host/ash_window_tree_host_virtual.h" |
| +#include "ash/host/root_window_transformer.h" |
| +#include "base/logging.h" |
| +#include "ui/aura/window.h" |
| +#include "ui/aura/window_event_dispatcher.h" |
| +#include "ui/aura/window_targeter.h" |
| +#include "ui/compositor/compositor.h" |
| +#include "ui/events/event_processor.h" |
| +#include "ui/gfx/geometry/insets.h" |
| + |
| +namespace ash { |
| + |
| +bool IsLocatedEvent(const ui::Event& event) { |
| + return event.IsMouseEvent() || event.IsTouchEvent() || |
| + event.IsScrollEvent() || event.IsGestureEvent(); |
| +} |
| + |
| +class VirtualEventTargeter : public aura::WindowTargeter { |
| + public: |
| + VirtualEventTargeter(aura::Window* src_root, aura::Window* dst_root) |
| + : src_root_(src_root), dst_root_(dst_root) {} |
| + |
| + ui::EventTarget* FindTargetForEvent(ui::EventTarget* root, |
| + ui::Event* event) override { |
| + if (root == src_root_ && !event->target()) { |
| + if (IsLocatedEvent(*event)) { |
| + ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event); |
| + located_event->ConvertLocationToTarget( |
| + static_cast<aura::Window*>(nullptr), dst_root_); |
| + located_event->UpdateForRootTransform( |
| + dst_root_->GetHost()->GetRootTransform()); |
| + } |
| + ignore_result( |
| + dst_root_->GetHost()->event_processor()->OnEventFromSource(event)); |
| + return nullptr; |
| + } else { |
| + LOG(ERROR) << "Handling Event:" << event->type(); |
| + return aura::WindowTargeter::FindTargetForEvent(root, event); |
| + } |
| + } |
| + |
| + aura::Window* src_root_; |
| + aura::Window* dst_root_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(VirtualEventTargeter); |
| +}; |
| + |
| +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.
|
| + scoped_ptr<AshWindowTreeHost> ash_host; |
| + PerDisplayData(scoped_ptr<AshWindowTreeHost> ash_host) |
| + : ash_host(ash_host.Pass()) {} |
| + ~PerDisplayData() {} |
| +}; |
| + |
| +AshWindowTreeHostVirtual::AshWindowTreeHostVirtual( |
| + const gfx::Rect& initial_bounds) |
| + : bounds_(gfx::Rect(initial_bounds.size())) { |
| + CreateCompositor(GetAcceleratedWidget()); |
| +} |
| + |
| +AshWindowTreeHostVirtual::~AshWindowTreeHostVirtual() { |
| + DestroyCompositor(); |
| + DestroyDispatcher(); |
| +} |
| + |
| +void AshWindowTreeHostVirtual::PrepareForShutdown() { |
| + for (auto host : mirroring_hosts_) |
| + host->PrepareForShutdown(); |
| +} |
| + |
| +void AshWindowTreeHostVirtual::RegisterMirroringHost( |
| + AshWindowTreeHost* mirroring_ash_host) { |
| + aura::Window* src_root = mirroring_ash_host->AsWindowTreeHost()->window(); |
| + src_root->SetEventTargeter( |
| + make_scoped_ptr(new VirtualEventTargeter(src_root, window()))); |
| + DCHECK(std::find(mirroring_hosts_.begin(), mirroring_hosts_.end(), |
| + mirroring_ash_host) == mirroring_hosts_.end()); |
| + mirroring_hosts_.push_back(mirroring_ash_host); |
| + mirroring_ash_host->AsWindowTreeHost()->window()->AddObserver(this); |
| +} |
| + |
| +void AshWindowTreeHostVirtual::ToggleFullScreen() { |
| +} |
| + |
| +bool AshWindowTreeHostVirtual::ConfineCursorToRootWindow() { |
| + return true; |
| +} |
| + |
| +void AshWindowTreeHostVirtual::UnConfineCursor() { |
| +} |
| + |
| +void AshWindowTreeHostVirtual::SetRootWindowTransformer( |
| + scoped_ptr<RootWindowTransformer> transformer) { |
| + // TODO(oshima): Find out if this is neceessary. |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +gfx::Insets AshWindowTreeHostVirtual::GetHostInsets() const { |
| + return gfx::Insets(); |
| +} |
| + |
| +aura::WindowTreeHost* AshWindowTreeHostVirtual::AsWindowTreeHost() { |
| + return this; |
| +} |
| + |
| +ui::EventSource* AshWindowTreeHostVirtual::GetEventSource() { |
| + return this; |
| +} |
| + |
| +gfx::AcceleratedWidget AshWindowTreeHostVirtual::GetAcceleratedWidget() { |
| + // TODO(oshima): Enable offscreen compositor. |
| + return gfx::kNullAcceleratedWidget; |
| +} |
| + |
| +void AshWindowTreeHostVirtual::Show() { |
| +} |
| + |
| +void AshWindowTreeHostVirtual::Hide() { |
| +} |
| + |
| +gfx::Rect AshWindowTreeHostVirtual::GetBounds() const { |
| + return bounds_; |
| +} |
| + |
| +void AshWindowTreeHostVirtual::SetBounds(const gfx::Rect& bounds) { |
| + if (bounds_.size() == bounds.size()) |
| + return; |
| + bounds_.set_size(bounds.size()); |
| + OnHostResized(bounds_.size()); |
| +} |
| + |
| +void AshWindowTreeHostVirtual::SetCapture() { |
| +} |
| + |
| +void AshWindowTreeHostVirtual::ReleaseCapture() { |
| +} |
| + |
| +gfx::Point AshWindowTreeHostVirtual::GetLocationOnNativeScreen() const { |
| + return gfx::Point(); |
| +} |
| + |
| +void AshWindowTreeHostVirtual::SetCursorNative(gfx::NativeCursor cursor) { |
| + for (auto host : mirroring_hosts_) |
| + host->AsWindowTreeHost()->SetCursor(cursor); |
| +} |
| + |
| +void AshWindowTreeHostVirtual::MoveCursorToNative(const gfx::Point& location) { |
| + // TODO(oshima): Find out if this is neceessary. |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void AshWindowTreeHostVirtual::OnCursorVisibilityChangedNative(bool show) { |
| + for (auto host : mirroring_hosts_) |
| + host->AsWindowTreeHost()->OnCursorVisibilityChanged(show); |
| +} |
| + |
| +void AshWindowTreeHostVirtual::OnWindowDestroying(aura::Window* window) { |
| + auto iter = |
| + std::find_if(mirroring_hosts_.begin(), mirroring_hosts_.end(), |
| + [window](AshWindowTreeHost* ash_host) { |
| + return ash_host->AsWindowTreeHost()->window() == window; |
| + }); |
| + DCHECK(iter != mirroring_hosts_.end()); |
| + window->RemoveObserver(this); |
| + mirroring_hosts_.erase(iter); |
| +} |
| + |
| +ui::EventProcessor* AshWindowTreeHostVirtual::GetEventProcessor() { |
| + return dispatcher(); |
| +} |
| + |
| +} // namespace ash |