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

Unified 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 side-by-side diff with in-line comments
Download patch
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..13042c2cda95f3ca19651e8e96d6009ea0253015
--- /dev/null
+++ b/ash/host/ash_window_tree_host_virtual.cc
@@ -0,0 +1,169 @@
+// 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) {
Jun Mukai 2015/04/27 18:23:40 ui::Event has IsLocatedEvent() method.
oshima 2015/04/27 20:30:55 thanks, done.
+ 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);
+};
+
+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

Powered by Google App Engine
This is Rietveld 408576698