removes ws1
It's been replaced by ws2.
BUG=865689
TEST=none
Change-Id: I86310a113750d350d24f7d11180b4411a5346d48
Reviewed-on: https://chromium-review.googlesource.com/1145052
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576945}
diff --git a/BUILD.gn b/BUILD.gn
index 9d06746..f445ca9 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -630,7 +630,6 @@
"//mash:all",
"//media/mojo/services:media_service_unittests",
"//mojo",
- "//services/ui/ws:tests",
"//ui/views/mus:views_mus_interactive_ui_tests",
"//ui/views/mus:views_mus_unittests",
]
diff --git a/ash/BUILD.gn b/ash/BUILD.gn
index 804508c..259f5c6 100644
--- a/ash/BUILD.gn
+++ b/ash/BUILD.gn
@@ -1389,9 +1389,6 @@
"//services/preferences/public/cpp",
"//services/service_manager/public/cpp",
"//services/ui/gpu_host",
-
- # TODO(sky): this should not be necessary once --mash goes away.
- "//services/ui:lib",
"//services/ui/public/cpp/input_devices:input_device_controller",
"//services/ui/public/interfaces/input_devices",
diff --git a/chrome/utility/BUILD.gn b/chrome/utility/BUILD.gn
index f31a91a..20b78f06 100644
--- a/chrome/utility/BUILD.gn
+++ b/chrome/utility/BUILD.gn
@@ -153,7 +153,6 @@
"//ash/components/tap_visualizer:lib",
"//ash/components/tap_visualizer/public/mojom",
"//chrome/services/file_util:lib",
- "//services/ui:lib",
"//services/ui/public/interfaces",
]
}
diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
index abaa573..d33f24a 100644
--- a/content/browser/BUILD.gn
+++ b/content/browser/BUILD.gn
@@ -2302,7 +2302,6 @@
if (use_aura) {
deps += [
- "//services/ui:lib",
"//services/ui/public/cpp",
"//services/ui/public/interfaces",
"//ui/aura",
diff --git a/mash/BUILD.gn b/mash/BUILD.gn
index 0116125..3d6f3f4 100644
--- a/mash/BUILD.gn
+++ b/mash/BUILD.gn
@@ -19,7 +19,6 @@
"//mash/example",
"//mash/runner",
"//mash/session",
- "//mash/simple_wm",
"//mash/task_viewer",
]
diff --git a/mash/example/BUILD.gn b/mash/example/BUILD.gn
index f18ad9b..a210a3c 100644
--- a/mash/example/BUILD.gn
+++ b/mash/example/BUILD.gn
@@ -12,7 +12,6 @@
"//mash/example/views_examples",
"//mash/example/window_type_launcher",
"//mash/runner",
- "//mash/simple_wm",
]
if (is_chromeos) {
@@ -24,6 +23,5 @@
standalone_services = [
"//mash/example/views_examples:manifest",
"//mash/example/window_type_launcher:manifest",
- "//mash/simple_wm:manifest",
]
}
diff --git a/mash/simple_wm/BUILD.gn b/mash/simple_wm/BUILD.gn
deleted file mode 100644
index b1fb47a..0000000
--- a/mash/simple_wm/BUILD.gn
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright 2016 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.
-
-import("//build/config/ui.gni")
-import("//services/service_manager/public/cpp/service.gni")
-import("//services/service_manager/public/service_manifest.gni")
-import("//tools/grit/repack.gni")
-
-service("simple_wm") {
- testonly = true
-
- sources = [
- "main.cc",
- ]
-
- deps = [
- ":lib",
- "//base",
- "//services/service_manager/public/cpp",
- "//ui/views/mus:for_mojo_application",
- ]
-
- resources = [ "$root_out_dir/views_mus_resources.pak" ]
-}
-
-source_set("lib") {
- testonly = true
- sources = [
- "move_event_handler.cc",
- "move_event_handler.h",
- "move_loop.cc",
- "move_loop.h",
- "simple_wm.cc",
- "simple_wm.h",
- ]
-
- deps = [
- "//base",
- "//services/service_manager/public/cpp",
- "//services/ui/public/cpp",
- "//services/ui/public/interfaces",
- "//ui/aura",
- "//ui/aura:test_support",
- "//ui/display",
- "//ui/display:test_support",
- "//ui/gfx/geometry/mojo",
- "//ui/views",
- "//ui/views/mus:mus",
- "//ui/wm",
- "//ui/wm/public",
- ]
-
- public_deps = [
- "//skia", # Due to use of Sk types in service header.
- ]
-
- data_deps = [
- "//services/ui",
- ]
-}
-
-service_manifest("manifest") {
- name = "simple_wm"
- source = "manifest.json"
-}
diff --git a/mash/simple_wm/OWNERS b/mash/simple_wm/OWNERS
deleted file mode 100644
index 59dfd4b3..0000000
--- a/mash/simple_wm/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-per-file manifest.json=set noparent
-per-file manifest.json=file://ipc/SECURITY_OWNERS
diff --git a/mash/simple_wm/main.cc b/mash/simple_wm/main.cc
deleted file mode 100644
index 42311306..0000000
--- a/mash/simple_wm/main.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2016 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 "mash/simple_wm/simple_wm.h"
-#include "services/service_manager/public/c/main.h"
-#include "services/service_manager/public/cpp/service_runner.h"
-
-MojoResult ServiceMain(MojoHandle service_request_handle) {
- service_manager::ServiceRunner runner(new simple_wm::SimpleWM);
- return runner.Run(service_request_handle);
-}
diff --git a/mash/simple_wm/manifest.json b/mash/simple_wm/manifest.json
deleted file mode 100644
index d0f38b6..0000000
--- a/mash/simple_wm/manifest.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "name": "simple_wm",
- "display_name": "Simple Window Manager",
- "interface_provider_specs": {
- "service_manager:connector": {
- "requires": {
- "*": [ "app" ],
- "ui": [ "window_manager" ]
- }
- }
- }
-}
diff --git a/mash/simple_wm/move_event_handler.cc b/mash/simple_wm/move_event_handler.cc
deleted file mode 100644
index 4e1d58aa..0000000
--- a/mash/simple_wm/move_event_handler.cc
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2016 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 "mash/simple_wm/move_event_handler.h"
-
-#include "mash/simple_wm/move_loop.h"
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "ui/aura/mus/window_port_mus.h"
-#include "ui/aura/window.h"
-#include "ui/aura/window_delegate.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/base/hit_test.h"
-#include "ui/events/event.h"
-
-namespace simple_wm {
-namespace {
-
-ui::CursorType CursorForWindowComponent(int window_component) {
- switch (window_component) {
- case HTBOTTOM:
- return ui::CursorType::kSouthResize;
- case HTBOTTOMLEFT:
- return ui::CursorType::kSouthWestResize;
- case HTBOTTOMRIGHT:
- return ui::CursorType::kSouthEastResize;
- case HTLEFT:
- return ui::CursorType::kWestResize;
- case HTRIGHT:
- return ui::CursorType::kEastResize;
- case HTTOP:
- return ui::CursorType::kNorthResize;
- case HTTOPLEFT:
- return ui::CursorType::kNorthWestResize;
- case HTTOPRIGHT:
- return ui::CursorType::kNorthEastResize;
- default:
- return ui::CursorType::kNull;
- }
-}
-
-} // namespace
-
-MoveEventHandler::MoveEventHandler(aura::Window* window)
- : window_(window) {
- window_->AddObserver(this);
- window_->AddPreTargetHandler(this);
-}
-
-MoveEventHandler::~MoveEventHandler() {
- Detach();
-}
-
-void MoveEventHandler::ProcessLocatedEvent(ui::LocatedEvent* event) {
- const bool had_move_loop = move_loop_.get() != nullptr;
- DCHECK(event->IsMouseEvent() || event->IsTouchEvent());
-
- // This event handler can receive mouse events like ET_MOUSE_CAPTURE_CHANGED
- // that cannot be converted to PointerEvents. Ignore them because they aren't
- // needed for move handling.
- if (!ui::PointerEvent::CanConvertFrom(*event))
- return;
-
- // TODO(moshayedi): no need for this once MoveEventHandler directly receives
- // pointer events.
- std::unique_ptr<ui::PointerEvent> pointer_event;
- if (event->IsMouseEvent())
- pointer_event.reset(new ui::PointerEvent(*event->AsMouseEvent()));
- else
- pointer_event.reset(new ui::PointerEvent(*event->AsTouchEvent()));
-
- if (move_loop_) {
- if (move_loop_->Move(*pointer_event.get()) == MoveLoop::DONE)
- move_loop_.reset();
- } else if (pointer_event->type() == ui::ET_POINTER_DOWN) {
- const int ht_location =
- GetNonClientComponentForEvent(pointer_event.get());
- if (ht_location != HTNOWHERE)
- move_loop_ = MoveLoop::Create(window_, ht_location, *pointer_event.get());
- } else if (pointer_event->type() == ui::ET_POINTER_MOVED) {
- const int ht_location = GetNonClientComponentForEvent(pointer_event.get());
- aura::WindowPortMus::Get(window_)->SetCursor(
- ui::CursorData(CursorForWindowComponent(ht_location)));
- }
- if (had_move_loop || move_loop_)
- event->SetHandled();
-}
-
-int MoveEventHandler::GetNonClientComponentForEvent(
- const ui::LocatedEvent* event) {
- return window_->delegate()->GetNonClientComponent(event->location());
-}
-
-void MoveEventHandler::Detach() {
- window_->RemoveObserver(this);
- window_->RemovePreTargetHandler(this);
- window_ = nullptr;
-}
-
-void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) {
- ProcessLocatedEvent(event);
-}
-
-void MoveEventHandler::OnTouchEvent(ui::TouchEvent* event) {
- ProcessLocatedEvent(event);
-}
-
-void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) {
- if (!move_loop_)
- return;
-
- move_loop_->Revert();
- move_loop_.reset();
- event->SetHandled();
-}
-
-void MoveEventHandler::OnWindowDestroying(aura::Window* window) {
- DCHECK_EQ(window_, window);
- Detach();
-}
-
-} // namespace simple_wm
diff --git a/mash/simple_wm/move_event_handler.h b/mash/simple_wm/move_event_handler.h
deleted file mode 100644
index c6638bb..0000000
--- a/mash/simple_wm/move_event_handler.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef MASH_SIMPLE_WM_MOVE_EVENT_HANDLER_H_
-#define MASH_SIMPLE_WM_MOVE_EVENT_HANDLER_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "ui/aura/window_observer.h"
-#include "ui/events/event_handler.h"
-
-namespace aura {
-class Window;
-}
-
-namespace ui {
-class LocatedEvent;
-}
-
-namespace simple_wm {
-
-class MoveLoop;
-
-// EventHandler attached to the root. Starts a MoveLoop as necessary.
-class MoveEventHandler : public ui::EventHandler, public aura::WindowObserver {
- public:
- explicit MoveEventHandler(aura::Window* window);
- ~MoveEventHandler() override;
-
- private:
- void ProcessLocatedEvent(ui::LocatedEvent* event);
- int GetNonClientComponentForEvent(const ui::LocatedEvent* event);
-
- // Removes observer and EventHandler installed on |window_|.
- void Detach();
-
- // Overridden from ui::EventHandler:
- void OnMouseEvent(ui::MouseEvent* event) override;
- void OnTouchEvent(ui::TouchEvent* event) override;
- void OnCancelMode(ui::CancelModeEvent* event) override;
-
- // Overridden from aura::WindowObserver:
- void OnWindowDestroying(aura::Window* window) override;
-
- aura::Window* window_;
- std::unique_ptr<MoveLoop> move_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(MoveEventHandler);
-};
-
-} // namespace simple_wm
-
-#endif // MASH_SIMPLE_WM_MOVE_EVENT_HANDLER_H_
diff --git a/mash/simple_wm/move_loop.cc b/mash/simple_wm/move_loop.cc
deleted file mode 100644
index 1336e34..0000000
--- a/mash/simple_wm/move_loop.cc
+++ /dev/null
@@ -1,238 +0,0 @@
-// Copyright 2016 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 "mash/simple_wm/move_loop.h"
-
-#include "base/auto_reset.h"
-#include "base/memory/ptr_util.h"
-#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/window.h"
-#include "ui/base/hit_test.h"
-#include "ui/base/ui_base_types.h"
-#include "ui/events/event.h"
-#include "ui/gfx/geometry/point_conversions.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace simple_wm {
-namespace {
-
-int MouseOnlyEventFlags(int flags) {
- return flags & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON |
- ui::EF_RIGHT_MOUSE_BUTTON);
-}
-
-} // namespace
-
-MoveLoop::~MoveLoop() {
- if (target_)
- target_->RemoveObserver(this);
-}
-
-// static
-std::unique_ptr<MoveLoop> MoveLoop::Create(aura::Window* target,
- int ht_location,
- const ui::PointerEvent& event) {
- DCHECK_EQ(event.type(), ui::ET_POINTER_DOWN);
- // Start a move on left mouse, or any other type of pointer.
- if (event.IsMousePointerEvent() &&
- MouseOnlyEventFlags(event.flags()) != ui::EF_LEFT_MOUSE_BUTTON) {
- return nullptr;
- }
-
- Type type;
- HorizontalLocation h_loc;
- VerticalLocation v_loc;
- if (!DetermineType(ht_location, &type, &h_loc, &v_loc))
- return nullptr;
-
- return base::WrapUnique(new MoveLoop(target, event, type, h_loc, v_loc));
-}
-
-MoveLoop::MoveResult MoveLoop::Move(const ui::PointerEvent& event) {
- switch (event.type()) {
- case ui::ET_POINTER_CANCELLED:
- if (event.pointer_details().id == pointer_id_) {
- if (target_)
- Revert();
- return MoveResult::DONE;
- }
- return MoveResult::CONTINUE;
-
- case ui::ET_POINTER_MOVED:
- if (target_ && event.pointer_details().id == pointer_id_)
- MoveImpl(event);
- return MoveResult::CONTINUE;
-
- case ui::ET_POINTER_UP:
- if (event.pointer_details().id == pointer_id_) {
- // TODO(sky): need to support changed_flags.
- if (target_)
- MoveImpl(event);
- return MoveResult::DONE;
- }
- return MoveResult::CONTINUE;
-
- default:
- break;
- }
- return MoveResult::CONTINUE;
-}
-
-void MoveLoop::Revert() {
- if (!target_)
- return;
-
- base::AutoReset<bool> resetter(&changing_bounds_, true);
- target_->SetBounds(initial_window_bounds_);
-}
-
-MoveLoop::MoveLoop(aura::Window* target,
- const ui::PointerEvent& event,
- Type type,
- HorizontalLocation h_loc,
- VerticalLocation v_loc)
- : target_(target),
- type_(type),
- h_loc_(h_loc),
- v_loc_(v_loc),
- pointer_id_(event.pointer_details().id),
- initial_event_screen_location_(event.root_location()),
- initial_window_bounds_(target->bounds()),
- initial_user_set_bounds_(target->bounds()),
- changing_bounds_(false) {
- target->AddObserver(this);
-}
-
-// static
-bool MoveLoop::DetermineType(int ht_location,
- Type* type,
- HorizontalLocation* h_loc,
- VerticalLocation* v_loc) {
- *h_loc = HorizontalLocation::OTHER;
- *v_loc = VerticalLocation::OTHER;
- switch (ht_location) {
- case HTCAPTION:
- *type = Type::MOVE;
- *v_loc = VerticalLocation::TOP;
- return true;
- case HTTOPLEFT:
- *type = Type::RESIZE;
- *v_loc = VerticalLocation::TOP;
- *h_loc = HorizontalLocation::LEFT;
- return true;
- case HTTOP:
- *type = Type::RESIZE;
- *v_loc = VerticalLocation::TOP;
- return true;
- case HTTOPRIGHT:
- *type = Type::RESIZE;
- *v_loc = VerticalLocation::TOP;
- *h_loc = HorizontalLocation::RIGHT;
- return true;
- case HTRIGHT:
- *type = Type::RESIZE;
- *h_loc = HorizontalLocation::RIGHT;
- return true;
- case HTBOTTOMRIGHT:
- *type = Type::RESIZE;
- *v_loc = VerticalLocation::BOTTOM;
- *h_loc = HorizontalLocation::RIGHT;
- return true;
- case HTBOTTOM:
- *type = Type::RESIZE;
- *v_loc = VerticalLocation::BOTTOM;
- return true;
- case HTBOTTOMLEFT:
- *type = Type::RESIZE;
- *v_loc = VerticalLocation::BOTTOM;
- *h_loc = HorizontalLocation::LEFT;
- return true;
- case HTLEFT:
- *type = Type::RESIZE;
- *h_loc = HorizontalLocation::LEFT;
- return true;
- default:
- break;
- }
- return false;
-}
-
-void MoveLoop::MoveImpl(const ui::PointerEvent& event) {
- ui::WindowShowState show_state =
- target_->GetProperty(aura::client::kShowStateKey);
- // TODO(beng): figure out if there might not be another place to put this,
- // perhaps prior to move loop creation.
- if (show_state == ui::SHOW_STATE_MAXIMIZED) {
- base::AutoReset<bool> resetter(&changing_bounds_, true);
- target_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
- gfx::Rect restored_bounds =
- *target_->GetProperty(aura::client::kRestoreBoundsKey);
- // TODO(beng): Not just enough to adjust width and height, probably also
- // need to take some action to recenter the window relative to
- // the pointer position within the titlebar.
- initial_window_bounds_.set_width(restored_bounds.width());
- initial_window_bounds_.set_height(restored_bounds.height());
- }
- const gfx::Vector2d delta =
- event.root_location() - initial_event_screen_location_;
- const gfx::Rect new_bounds(DetermineBoundsFromDelta(delta));
- base::AutoReset<bool> resetter(&changing_bounds_, true);
- target_->SetBounds(new_bounds);
-}
-
-void MoveLoop::Cancel() {
- target_->RemoveObserver(this);
- target_ = nullptr;
-}
-
-gfx::Rect MoveLoop::DetermineBoundsFromDelta(const gfx::Vector2d& delta) {
- if (type_ == Type::MOVE) {
- return gfx::Rect(initial_window_bounds_.origin() + delta,
- initial_window_bounds_.size());
- }
-
- // TODO(sky): support better min sizes, make sure doesn't get bigger than
- // screen and max. Also make sure keep some portion on screen.
- gfx::Rect bounds(initial_window_bounds_);
- if (h_loc_ == HorizontalLocation::LEFT) {
- const int x = std::min(bounds.right() - 1, bounds.x() + delta.x());
- const int width = bounds.right() - x;
- bounds.set_x(x);
- bounds.set_width(width);
- } else if (h_loc_ == HorizontalLocation::RIGHT) {
- bounds.set_width(std::max(1, bounds.width() + delta.x()));
- }
-
- if (v_loc_ == VerticalLocation::TOP) {
- const int y = std::min(bounds.bottom() - 1, bounds.y() + delta.y());
- const int height = bounds.bottom() - y;
- bounds.set_y(y);
- bounds.set_height(height);
- } else if (v_loc_ == VerticalLocation::BOTTOM) {
- bounds.set_height(std::max(1, bounds.height() + delta.y()));
- }
-
- return bounds;
-}
-
-void MoveLoop::OnWindowHierarchyChanged(const HierarchyChangeParams& params) {
- if (params.target == target_)
- Cancel();
-}
-
-void MoveLoop::OnWindowBoundsChanged(aura::Window* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- ui::PropertyChangeReason reason) {
- DCHECK_EQ(window, target_);
- if (!changing_bounds_)
- Cancel();
-}
-
-void MoveLoop::OnWindowVisibilityChanged(aura::Window* window, bool visible) {
- DCHECK_EQ(window, target_);
- Cancel();
-}
-
-} // namespace simple_wm
diff --git a/mash/simple_wm/move_loop.h b/mash/simple_wm/move_loop.h
deleted file mode 100644
index dd115bd..0000000
--- a/mash/simple_wm/move_loop.h
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef MASH_SIMPLE_WM_MOVE_LOOP_H_
-#define MASH_SIMPLE_WM_MOVE_LOOP_H_
-
-#include <stdint.h>
-#include <memory>
-
-#include "base/macros.h"
-#include "ui/aura/window_observer.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace ui {
-class PointerEvent;
-}
-
-namespace simple_wm {
-
-// MoveLoop is responsible for moving/resizing windows.
-class MoveLoop : public aura::WindowObserver {
- public:
- enum MoveResult {
- // The move is still ongoing.
- CONTINUE,
- // The move is done and the MoveLoop should be destroyed.
- DONE,
- };
-
- enum class HorizontalLocation {
- LEFT,
- RIGHT,
- OTHER,
- };
-
- enum class VerticalLocation {
- TOP,
- BOTTOM,
- OTHER,
- };
-
- ~MoveLoop() override;
-
- // If a move/resize loop should occur for the specified parameters creates
- // and returns a new MoveLoop. All events should be funneled to the MoveLoop
- // until done (Move()). |ht_location| is one of the constants defined by
- // HitTestCompat.
- static std::unique_ptr<MoveLoop> Create(aura::Window* target,
- int ht_location,
- const ui::PointerEvent& event);
-
- // Processes an event for a move/resize loop.
- MoveResult Move(const ui::PointerEvent& event);
-
- // If possible reverts any changes made during the move loop.
- void Revert();
-
- private:
- enum class Type {
- MOVE,
- RESIZE,
- };
-
- MoveLoop(aura::Window* target,
- const ui::PointerEvent& event,
- Type type,
- HorizontalLocation h_loc,
- VerticalLocation v_loc);
-
- // Determines the type of move from the specified HitTestCompat value.
- // Returns true if a move/resize should occur.
- static bool DetermineType(int ht_location,
- Type* type,
- HorizontalLocation* h_loc,
- VerticalLocation* v_loc);
-
- // Does the actual move/resize.
- void MoveImpl(const ui::PointerEvent& event);
-
- // Cancels the loop. This sets |target_| to null and removes the observer.
- // After this the MoveLoop is still ongoing and won't stop until the
- // appropriate event is received.
- void Cancel();
-
- gfx::Rect DetermineBoundsFromDelta(const gfx::Vector2d& delta);
-
- // aura::WindowObserver:
- void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
- void OnWindowBoundsChanged(aura::Window* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- ui::PropertyChangeReason reason) override;
- void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
-
- // The window this MoveLoop is acting on. |target_| is set to null if the
- // window unexpectedly changes while the move is in progress.
- aura::Window* target_;
-
- const Type type_;
- const HorizontalLocation h_loc_;
- const VerticalLocation v_loc_;
-
- // The id of the pointer that triggered the move.
- const int32_t pointer_id_;
-
- // Location of the event (in screen coordinates) that triggered the move.
- const gfx::Point initial_event_screen_location_;
-
- // Original bounds of the window.
- gfx::Rect initial_window_bounds_;
- const gfx::Rect initial_user_set_bounds_;
-
- // Set to true when MoveLoop changes the bounds of |target_|. The move is
- // canceled if the bounds change unexpectedly during the move.
- bool changing_bounds_;
-
- DISALLOW_COPY_AND_ASSIGN(MoveLoop);
-};
-
-} // namespace simple_wm
-
-#endif // MASH_SIMPLE_WM_MOVE_LOOP_H_
diff --git a/mash/simple_wm/simple_wm.cc b/mash/simple_wm/simple_wm.cc
deleted file mode 100644
index 6370eac..0000000
--- a/mash/simple_wm/simple_wm.cc
+++ /dev/null
@@ -1,610 +0,0 @@
-// Copyright 2016 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 "mash/simple_wm/simple_wm.h"
-
-#include <memory>
-
-#include "base/observer_list.h"
-#include "base/strings/utf_string_conversions.h"
-#include "mash/simple_wm/move_event_handler.h"
-#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/layout_manager.h"
-#include "ui/display/screen_base.h"
-#include "ui/gfx/canvas.h"
-#include "ui/gfx/geometry/mojo/geometry.mojom.h"
-#include "ui/views/controls/button/md_text_button.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/mus/aura_init.h"
-#include "ui/views/mus/mus_client.h"
-#include "ui/views/widget/native_widget_aura.h"
-#include "ui/views/widget/widget.h"
-#include "ui/views/widget/widget_delegate.h"
-#include "ui/wm/core/focus_controller.h"
-
-namespace simple_wm {
-
-namespace {
-
-const int kNonClientTopHeight = 24;
-const int kNonClientSize = 5;
-const int kNonClientMaximizedTopOverlap = 4;
-
-} // namespace
-
-class SimpleWM::WindowListModelObserver {
- public:
- virtual void OnWindowAddedOrRemoved() = 0;
- virtual void OnWindowTitleChanged(size_t index,
- const base::string16& title) = 0;
-};
-
-class SimpleWM::WindowListModel : public aura::WindowObserver {
- public:
- explicit WindowListModel(aura::Window* window_container)
- : window_container_(window_container) {
- window_container_->AddObserver(this);
- }
- ~WindowListModel() override {
- window_container_->RemoveObserver(this);
- for (auto* window : windows_)
- window->RemoveObserver(this);
- }
-
- size_t GetSize() const {
- return windows_.size();
- }
- base::string16 GetTitle(size_t index) const {
- return windows_.at(index)->GetTitle();
- }
- aura::Window* GetWindow(size_t index) const {
- return windows_.at(index);
- }
-
- void AddObserver(WindowListModelObserver* observer) {
- observers_.AddObserver(observer);
- }
- void RemoveObserver(WindowListModelObserver* observer) {
- observers_.RemoveObserver(observer);
- }
-
- private:
- // aura::WindowObserver:
- void OnWindowAdded(aura::Window* window) override {
- if (window->parent() == window_container_)
- AddWindow(window);
- for (auto& observer : observers_)
- observer.OnWindowAddedOrRemoved();
- }
- void OnWillRemoveWindow(aura::Window* window) override {
- window->RemoveObserver(this);
- for (auto& observer : observers_)
- observer.OnWindowAddedOrRemoved();
- auto it = std::find(windows_.begin(), windows_.end(), window);
- DCHECK(it != windows_.end());
- windows_.erase(it);
- }
- void OnWindowTitleChanged(aura::Window* window) override {
- auto it = std::find(windows_.begin(), windows_.end(), window);
- size_t index = it - windows_.begin();
- for (auto& observer : observers_)
- observer.OnWindowTitleChanged(index, window->GetTitle());
- }
-
- void AddWindow(aura::Window* window) {
- window->AddObserver(this);
- auto it = std::find(windows_.begin(), windows_.end(), window);
- DCHECK(it == windows_.end());
- windows_.push_back(window);
- }
-
- aura::Window* window_container_;
- std::vector<aura::Window*> windows_;
- base::ObserverList<WindowListModelObserver> observers_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowListModel);
-};
-
-class SimpleWM::WindowListView : public views::WidgetDelegateView,
- public views::ButtonListener,
- public SimpleWM::WindowListModelObserver {
- public:
- using ActivateCallback = base::Callback<void(aura::Window*)>;
-
- WindowListView(WindowListModel* model, ActivateCallback activate_callback)
- : model_(model), activate_callback_(activate_callback) {
- model_->AddObserver(this);
- Rebuild();
- }
- ~WindowListView() override {
- model_->RemoveObserver(this);
- }
-
- static const int kButtonSpacing = 5;
-
- // views::View
- void Layout() override {
- int x_offset = kButtonSpacing;
- for (int i = 0; i < child_count(); ++i) {
- View* v = child_at(i);
- gfx::Size ps = v->GetPreferredSize();
- gfx::Rect bounds(x_offset, kButtonSpacing, ps.width(), ps.height());
- v->SetBoundsRect(bounds);
- x_offset = bounds.right() + kButtonSpacing;
- }
- }
- void OnPaint(gfx::Canvas* canvas) override {
- canvas->DrawColor(SK_ColorLTGRAY);
- gfx::Rect stroke_bounds = GetLocalBounds();
- stroke_bounds.set_height(1);
- canvas->FillRect(stroke_bounds, SK_ColorDKGRAY);
- }
- gfx::Size CalculatePreferredSize() const override {
- std::unique_ptr<views::MdTextButton> measure_button(
- views::MdTextButton::Create(nullptr, base::UTF8ToUTF16("Sample")));
- int height =
- measure_button->GetPreferredSize().height() + 2 * kButtonSpacing;
- return gfx::Size(0, height);
- }
-
- private:
- // views::ButtonListener:
- void ButtonPressed(views::Button* sender, const ui::Event& event) override {
- activate_callback_.Run(
- model_->GetWindow(static_cast<size_t>(sender->tag())));
- }
-
- // WindowListModelObserver:
- void OnWindowAddedOrRemoved() override {
- Rebuild();
- }
- void OnWindowTitleChanged(size_t index,
- const base::string16& new_title) override {
- views::MdTextButton* label =
- static_cast<views::MdTextButton*>(child_at(static_cast<int>(index)));
- label->SetText(new_title);
- Layout();
- }
-
- void Rebuild() {
- RemoveAllChildViews(true);
-
- size_t size = model_->GetSize();
- for (size_t i = 0; i < size; ++i) {
- base::string16 title = model_->GetTitle(i);
- if (title.empty())
- title = base::UTF8ToUTF16("Untitled");
- views::MdTextButton* button = views::MdTextButton::Create(this, title);
- button->set_tag(static_cast<int>(i));
- AddChildView(button);
- }
- Layout();
- }
-
- WindowListModel* model_;
- ActivateCallback activate_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowListView);
-};
-
-class SimpleWM::FrameView : public views::WidgetDelegateView,
- public aura::WindowObserver {
- public:
- explicit FrameView(aura::Window* client_window)
- : client_window_(client_window) {
- client_window_->AddObserver(this);
- }
- ~FrameView() override = default;
-
- void Init() {
- move_event_handler_ =
- std::make_unique<MoveEventHandler>(GetWidget()->GetNativeWindow());
- }
-
- private:
- // views::WidgetDelegateView:
- base::string16 GetWindowTitle() const override {
- base::string16* title_from_property =
- client_window_->GetProperty(aura::client::kTitleKey);
- base::string16 title = title_from_property ? *title_from_property
- : base::UTF8ToUTF16("(Window)");
- // TODO(beng): quick hack to cause WindowObserver::OnWindowTitleChanged to
- // fire.
- GetWidget()->GetNativeWindow()->SetTitle(title);
- return title;
- }
- void Layout() override {
- // Client offsets are applied automatically by the window service.
- gfx::Rect parent_bounds = GetWidget()->GetNativeWindow()->bounds();
- parent_bounds.set_origin(gfx::Point());
-
- if (GetWidget()->IsMaximized()) {
- parent_bounds.Inset(-kNonClientSize, -kNonClientMaximizedTopOverlap,
- -kNonClientSize, -kNonClientSize);
- }
-
- client_window_->SetBounds(parent_bounds);
- }
- bool CanMaximize() const override {
- return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) &
- ui::mojom::kResizeBehaviorCanMaximize) != 0;
- }
-
- bool CanMinimize() const override {
- return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) &
- ui::mojom::kResizeBehaviorCanMinimize) != 0;
- }
-
- bool CanResize() const override {
- return (client_window_->GetProperty(aura::client::kResizeBehaviorKey) &
- ui::mojom::kResizeBehaviorCanResize) != 0;
- }
-
- // aura::WindowObserver:
- void OnWindowPropertyChanged(aura::Window* window, const void* key,
- intptr_t old) override {
- if (key == aura::client::kTitleKey)
- GetWidget()->UpdateWindowTitle();
- else if (key == aura::client::kResizeBehaviorKey)
- GetWidget()->non_client_view()->frame_view()->Layout();
- }
-
- aura::Window* client_window_;
- std::unique_ptr<MoveEventHandler> move_event_handler_;
-
- DISALLOW_COPY_AND_ASSIGN(FrameView);
-};
-
-class SimpleWM::WorkspaceLayoutManager : public aura::WindowObserver {
- public:
- explicit WorkspaceLayoutManager(aura::Window* window_root)
- : window_root_(window_root) {}
- ~WorkspaceLayoutManager() override = default;
-
- private:
- // aura::WindowObserver:
- void OnWindowPropertyChanged(aura::Window* window, const void* key,
- intptr_t old) override {
- if (key == aura::client::kShowStateKey) {
- ui::WindowShowState show_state =
- window->GetProperty(aura::client::kShowStateKey);
- switch (show_state) {
- case ui::SHOW_STATE_NORMAL:
- window->Show();
- window->SetBounds(
- *window->GetProperty(aura::client::kRestoreBoundsKey));
- break;
- case ui::SHOW_STATE_MINIMIZED:
- window->Hide();
- break;
- case ui::SHOW_STATE_MAXIMIZED:
- window->Show();
- window->SetProperty(aura::client::kRestoreBoundsKey,
- new gfx::Rect(window->bounds()));
- window->SetBounds(gfx::Rect(window_root_->bounds().size()));
- break;
- default:
- NOTREACHED();
- break;
- }
- }
- }
- void OnWindowDestroying(aura::Window* window) override {
- window->RemoveObserver(this);
- }
-
- aura::Window* window_root_;
-
- DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager);
-};
-
-class SimpleWM::DisplayLayoutManager : public aura::LayoutManager {
- public:
- DisplayLayoutManager(aura::Window* display_root,
- aura::Window* window_root,
- SimpleWM::WindowListView* window_list_view)
- : display_root_(display_root),
- window_root_(window_root),
- window_list_view_(window_list_view) {}
- ~DisplayLayoutManager() override = default;
-
- private:
- // aura::LayoutManager:
- void OnWindowResized() override {}
- void OnWindowAddedToLayout(aura::Window* child) override {
- Layout();
- }
- void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
- void OnWindowRemovedFromLayout(aura::Window* child) override {}
- void OnChildWindowVisibilityChanged(aura::Window* child,
- bool visible) override {}
- void SetChildBounds(aura::Window* child,
- const gfx::Rect& requested_bounds) override {
- SetChildBoundsDirect(child, requested_bounds);
- }
-
- void Layout() {
- gfx::Size ps = window_list_view_->GetPreferredSize();
- gfx::Rect bounds = display_root_->bounds();
- gfx::Rect window_root_bounds = bounds;
- window_root_bounds.set_height(window_root_bounds.height() - ps.height());
- window_root_->SetBounds(window_root_bounds);
- gfx::Rect window_list_view_bounds = bounds;
- window_list_view_bounds.set_height(ps.height());
- window_list_view_bounds.set_y(window_root_bounds.bottom());
- window_list_view_->GetWidget()->SetBounds(window_list_view_bounds);
- }
-
- aura::Window* display_root_;
- aura::Window* window_root_;
- SimpleWM::WindowListView* window_list_view_;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayLayoutManager);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// SimpleWM, public:
-
-SimpleWM::SimpleWM() = default;
-
-SimpleWM::~SimpleWM() {
- // WindowTreeHost uses state from WindowTreeClient, so destroy it first.
- window_tree_host_.reset();
-
- // WindowTreeClient destruction may callback to us.
- window_tree_client_.reset();
-
- display::Screen::SetScreenInstance(nullptr);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// SimpleWM, service_manager::Service implementation:
-
-void SimpleWM::OnStart() {
- CHECK(!started_);
- started_ = true;
- screen_ = std::make_unique<display::ScreenBase>();
- display::Screen::SetScreenInstance(screen_.get());
- views::AuraInit::InitParams params;
- params.connector = context()->connector();
- params.identity = context()->identity();
- params.mode = views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER;
- aura_init_ = views::AuraInit::Create(params);
- if (!aura_init_) {
- context()->QuitNow();
- return;
- }
- window_tree_client_ = aura::WindowTreeClient::CreateForWindowManager(
- context()->connector(), this, this);
- aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client_.get());
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// SimpleWM, aura::WindowTreeClientDelegate implementation:
-
-void SimpleWM::OnEmbed(
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
- // WindowTreeClients configured as the window manager should never get
- // OnEmbed().
- NOTREACHED();
-}
-
-void SimpleWM::OnLostConnection(aura::WindowTreeClient* client) {
- window_tree_host_.reset();
- window_tree_client_.reset();
-}
-
-void SimpleWM::OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) {
- // WindowTreeClients configured as the window manager should never get
- // OnEmbedRootDestroyed().
- NOTREACHED();
-}
-
-void SimpleWM::OnPointerEventObserved(const ui::PointerEvent& event,
- int64_t display_id,
- aura::Window* target) {
- // Don't care.
-}
-
-aura::PropertyConverter* SimpleWM::GetPropertyConverter() {
- return &property_converter_;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// SimpleWM, aura::WindowManagerDelegate implementation:
-
-void SimpleWM::SetWindowManagerClient(
- aura::WindowManagerClient* client) {
- window_manager_client_ = client;
-}
-
-void SimpleWM::OnWmConnected() {}
-
-void SimpleWM::OnWmSetBounds(aura::Window* window, const gfx::Rect& bounds) {
- FrameView* frame_view = GetFrameViewForClientWindow(window);
- frame_view->GetWidget()->SetBounds(bounds);
-}
-
-bool SimpleWM::OnWmSetProperty(
- aura::Window* window,
- const std::string& name,
- std::unique_ptr<std::vector<uint8_t>>* new_data) {
- return true;
-}
-
-void SimpleWM::OnWmSetModalType(aura::Window* window, ui::ModalType type) {}
-
-void SimpleWM::OnWmSetCanFocus(aura::Window* window, bool can_focus) {}
-
-aura::Window* SimpleWM::OnWmCreateTopLevelWindow(
- ui::mojom::WindowType window_type,
- std::map<std::string, std::vector<uint8_t>>* properties) {
- aura::Window* client_window = new aura::Window(nullptr);
- SetWindowType(client_window, window_type);
- client_window->Init(ui::LAYER_NOT_DRAWN);
-
- views::Widget* frame_widget = new views::Widget;
- views::NativeWidgetAura* frame_native_widget =
- new views::NativeWidgetAura(frame_widget, true);
- views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
- FrameView* frame_view = new FrameView(client_window);
- params.delegate = frame_view;
- params.native_widget = frame_native_widget;
- params.parent = window_root_;
- params.bounds = gfx::Rect(10, 10, 500, 500);
- frame_widget->Init(params);
- frame_widget->Show();
- frame_view->Init();
-
- frame_widget->GetNativeWindow()->AddChild(client_window);
- frame_widget->GetNativeWindow()->AddObserver(workspace_layout_manager_.get());
-
- client_window_to_frame_view_[client_window] = frame_view;
- // TODO(beng): probably need to observe client_window from now on so we can
- // clean up this map.
-
- return client_window;
-}
-
-void SimpleWM::OnWmClientJankinessChanged(
- const std::set<aura::Window*>& client_windows,
- bool janky) {
- // Don't care.
-}
-
-void SimpleWM::OnWmBuildDragImage(const gfx::Point& screen_location,
- const gfx::ImageSkia& drag_image,
- const gfx::Vector2d& drag_image_offset,
- ui::mojom::PointerKind source) {}
-
-void SimpleWM::OnWmMoveDragImage(const gfx::Point& screen_location) {}
-
-void SimpleWM::OnWmDestroyDragImage() {}
-
-void SimpleWM::OnWmWillCreateDisplay(const display::Display& display) {
- screen_->display_list().AddDisplay(display,
- display::DisplayList::Type::PRIMARY);
-}
-
-void SimpleWM::OnWmNewDisplay(
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
- const display::Display& display) {
- // Only handles a single root.
- DCHECK(!window_root_);
- window_tree_host_ = std::move(window_tree_host);
- window_tree_host_->InitHost();
- window_tree_host_->window()->Show();
- display_root_ = window_tree_host_->window();
- window_root_ = new aura::Window(nullptr);
- window_root_->Init(ui::LAYER_SOLID_COLOR);
- window_root_->layer()->SetColor(SK_ColorWHITE);
- display_root_->AddChild(window_root_);
- window_root_->Show();
- workspace_layout_manager_ =
- std::make_unique<WorkspaceLayoutManager>(window_root_);
-
- window_list_model_ = std::make_unique<WindowListModel>(window_root_);
-
- views::Widget* window_list_widget = new views::Widget;
- views::NativeWidgetAura* window_list_widget_native_widget =
- new views::NativeWidgetAura(window_list_widget, true);
- views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
- WindowListView* window_list_view =
- new WindowListView(window_list_model_.get(),
- base::Bind(&SimpleWM::OnWindowListViewItemActivated,
- base::Unretained(this)));
- params.delegate = window_list_view;
- params.native_widget = window_list_widget_native_widget;
- params.parent = display_root_;
- window_list_widget->Init(params);
- window_list_widget->Show();
-
- display_root_->SetLayoutManager(new DisplayLayoutManager(
- display_root_, window_root_, window_list_view));
-
- DCHECK(window_manager_client_);
- window_manager_client_->AddActivationParent(window_root_);
- ui::mojom::FrameDecorationValuesPtr frame_decoration_values =
- ui::mojom::FrameDecorationValues::New();
- frame_decoration_values->normal_client_area_insets.Set(
- kNonClientTopHeight, kNonClientSize, kNonClientSize, kNonClientSize);
- frame_decoration_values->max_title_bar_button_width = 0;
- window_manager_client_->SetFrameDecorationValues(
- std::move(frame_decoration_values));
- focus_controller_ = std::make_unique<wm::FocusController>(this);
- aura::client::SetFocusClient(display_root_, focus_controller_.get());
- wm::SetActivationClient(display_root_, focus_controller_.get());
- display_root_->AddPreTargetHandler(focus_controller_.get());
-}
-
-void SimpleWM::OnWmDisplayRemoved(
- aura::WindowTreeHostMus* window_tree_host) {
- DCHECK_EQ(window_tree_host, window_tree_host_.get());
- window_root_ = nullptr;
- window_tree_host_.reset();
-}
-
-void SimpleWM::OnWmDisplayModified(const display::Display& display) {}
-
-void SimpleWM::OnWmPerformMoveLoop(
- aura::Window* window,
- ui::mojom::MoveLoopSource source,
- const gfx::Point& cursor_location,
- const base::Callback<void(bool)>& on_done) {
- // Don't care.
-}
-
-void SimpleWM::OnWmCancelMoveLoop(aura::Window* window) {}
-
-void SimpleWM::OnCursorTouchVisibleChanged(bool enabled) {}
-
-void SimpleWM::OnWmSetClientArea(
- aura::Window* window,
- const gfx::Insets& insets,
- const std::vector<gfx::Rect>& additional_client_areas) {}
-
-bool SimpleWM::IsWindowActive(aura::Window* window) { return false; }
-
-void SimpleWM::OnWmDeactivateWindow(aura::Window* window) {}
-
-void SimpleWM::OnWmPerformAction(aura::Window* window,
- const std::string& action) {}
-
-////////////////////////////////////////////////////////////////////////////////
-// SimpleWM, wm::BaseFocusRules implementation:
-
-bool SimpleWM::SupportsChildActivation(aura::Window* window) const {
- return window == window_root_;
-}
-
-bool SimpleWM::IsWindowConsideredVisibleForActivation(
- aura::Window* window) const {
- if (window->IsVisible())
- return true;
-
- ui::WindowShowState show_state =
- window->GetProperty(aura::client::kShowStateKey);
- if (show_state == ui::SHOW_STATE_MINIMIZED)
- return true;
-
- return window->TargetVisibility();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// SimpleWM, private:
-
-SimpleWM::FrameView* SimpleWM::GetFrameViewForClientWindow(
- aura::Window* client_window) {
- auto it = client_window_to_frame_view_.find(client_window);
- return it != client_window_to_frame_view_.end() ? it->second : nullptr;
-}
-
-void SimpleWM::OnWindowListViewItemActivated(aura::Window* window) {
- window->Show();
- wm::ActivationClient* activation_client =
- wm::GetActivationClient(window->GetRootWindow());
- activation_client->ActivateWindow(window);
-}
-
-} // namespace simple_wm
diff --git a/mash/simple_wm/simple_wm.h b/mash/simple_wm/simple_wm.h
deleted file mode 100644
index 2bc758d..0000000
--- a/mash/simple_wm/simple_wm.h
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef MASH_SIMPLE_WM_SIMPLE_WM_H_
-#define MASH_SIMPLE_WM_SIMPLE_WM_H_
-
-#include <memory>
-#include <utility>
-
-#include "base/memory/ptr_util.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/service_manager/public/cpp/connector.h"
-#include "services/service_manager/public/cpp/service.h"
-#include "services/service_manager/public/cpp/service_context.h"
-#include "ui/aura/env.h"
-#include "ui/aura/mus/property_converter.h"
-#include "ui/aura/mus/property_utils.h"
-#include "ui/aura/mus/window_manager_delegate.h"
-#include "ui/aura/mus/window_tree_client.h"
-#include "ui/aura/mus/window_tree_client_delegate.h"
-#include "ui/aura/mus/window_tree_host_mus.h"
-#include "ui/aura/window.h"
-#include "ui/display/display.h"
-#include "ui/wm/core/base_focus_rules.h"
-#include "ui/wm/core/capture_controller.h"
-#include "ui/wm/core/wm_state.h"
-
-namespace display {
-class ScreenBase;
-}
-
-namespace views {
-class AuraInit;
-}
-
-namespace wm {
-class FocusController;
-}
-
-namespace simple_wm {
-
-class SimpleWM : public service_manager::Service,
- public aura::WindowTreeClientDelegate,
- public aura::WindowManagerDelegate,
- public wm::BaseFocusRules {
- public:
- SimpleWM();
- ~SimpleWM() override;
-
- private:
- class DisplayLayoutManager;
- class FrameView;
- class WindowListModel;
- class WindowListModelObserver;
- class WindowListView;
- class WorkspaceLayoutManager;
-
- // service_manager::Service:
- void OnStart() override;
-
- // aura::WindowTreeClientDelegate:
- void OnEmbed(
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override;
- void OnLostConnection(aura::WindowTreeClient* client) override;
- void OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) override;
- void OnPointerEventObserved(const ui::PointerEvent& event,
- int64_t display_id,
- aura::Window* target) override;
- aura::PropertyConverter* GetPropertyConverter() override;
-
- // aura::WindowManagerDelegate:
- void SetWindowManagerClient(aura::WindowManagerClient* client) override;
- void OnWmConnected() override;
- void OnWmAcceleratedWidgetAvailableForDisplay(
- int64_t display_id,
- gfx::AcceleratedWidget widget) override {}
- void OnWmSetBounds(aura::Window* window, const gfx::Rect& bounds) override;
- bool OnWmSetProperty(
- aura::Window* window,
- const std::string& name,
- std::unique_ptr<std::vector<uint8_t>>* new_data) override;
- void OnWmSetModalType(aura::Window* window, ui::ModalType type) override;
- void OnWmSetCanFocus(aura::Window* window, bool can_focus) override;
- aura::Window* OnWmCreateTopLevelWindow(
- ui::mojom::WindowType window_type,
- std::map<std::string, std::vector<uint8_t>>* properties) override;
- void OnWmClientJankinessChanged(const std::set<aura::Window*>& client_windows,
- bool janky) override;
- void OnWmBuildDragImage(const gfx::Point& screen_location,
- const gfx::ImageSkia& drag_image,
- const gfx::Vector2d& drag_image_offset,
- ui::mojom::PointerKind source) override;
- void OnWmMoveDragImage(const gfx::Point& screen_location) override;
- void OnWmDestroyDragImage() override;
- void OnWmWillCreateDisplay(const display::Display& display) override;
- void OnWmNewDisplay(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
- const display::Display& display) override;
- void OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) override;
- void OnWmDisplayModified(const display::Display& display) override;
- void OnWmPerformMoveLoop(aura::Window* window,
- ui::mojom::MoveLoopSource source,
- const gfx::Point& cursor_location,
- const base::Callback<void(bool)>& on_done) override;
- void OnWmCancelMoveLoop(aura::Window* window) override;
- void OnCursorTouchVisibleChanged(bool enabled) override;
- void OnWmSetClientArea(
- aura::Window* window,
- const gfx::Insets& insets,
- const std::vector<gfx::Rect>& additional_client_areas) override;
- bool IsWindowActive(aura::Window* window) override;
- void OnWmDeactivateWindow(aura::Window* window) override;
- void OnWmPerformAction(aura::Window* window,
- const std::string& action) override;
-
- // wm::BaseFocusRules:
- bool SupportsChildActivation(aura::Window* window) const override;
- bool IsWindowConsideredVisibleForActivation(
- aura::Window* window) const override;
-
- FrameView* GetFrameViewForClientWindow(aura::Window* client_window);
-
- void OnWindowListViewItemActivated(aura::Window* index);
-
- std::unique_ptr<views::AuraInit> aura_init_;
- wm::WMState wm_state_;
- std::unique_ptr<display::ScreenBase> screen_;
- aura::PropertyConverter property_converter_;
- std::unique_ptr<wm::FocusController> focus_controller_;
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_;
- aura::Window* display_root_ = nullptr;
- aura::Window* window_root_ = nullptr;
- aura::WindowManagerClient* window_manager_client_ = nullptr;
- std::unique_ptr<aura::WindowTreeClient> window_tree_client_;
- std::map<aura::Window*, FrameView*> client_window_to_frame_view_;
- std::unique_ptr<WindowListModel> window_list_model_;
- std::unique_ptr<WorkspaceLayoutManager> workspace_layout_manager_;
-
- bool started_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(SimpleWM);
-};
-
-} // namespace simple_wm
-
-#endif // MASH_SIMPLE_WM_SIMPLE_WM_H_
diff --git a/services/ui/BUILD.gn b/services/ui/BUILD.gn
index aea14eac..f2b12d28 100644
--- a/services/ui/BUILD.gn
+++ b/services/ui/BUILD.gn
@@ -2,118 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import("//build/config/ui.gni")
-import("//testing/test.gni")
-import("//services/service_manager/public/cpp/service.gni")
import("//services/service_manager/public/service_manifest.gni")
-import("//tools/grit/repack.gni")
-
-group("all") {
- testonly = true
- deps = [
- ":ui",
- "//services/ui/ime/test_ime_driver",
- "//services/viz",
- ]
-}
-
-service("ui") {
- sources = [
- "main.cc",
- ]
-
- deps = [
- ":lib",
- "//services/service_manager/public/cpp",
- ]
-
- data_deps = [
- ":resources_100",
- ":resources_200",
- ":resources_strings",
- "//services/viz",
- ]
-}
service_manifest("manifest") {
name = "ui"
source = "manifest.json"
}
-
-source_set("lib") {
- sources = [
- "service.cc",
- "service.h",
- ]
-
- public_deps = [
- "//services/ui/common:mus_common",
- ]
- deps = [
- "//base",
- "//cc",
- "//components/discardable_memory/public/interfaces",
- "//components/discardable_memory/service",
- "//components/viz/service",
- "//mojo/public/cpp/system",
- "//services/catalog/public/cpp",
- "//services/catalog/public/mojom:constants",
- "//services/service_manager/public/cpp",
- "//services/ui/gpu_host",
- "//services/ui/ime:lib",
- "//services/ui/input_devices",
- "//services/ui/public/interfaces",
- "//services/ui/ws:lib",
- "//services/ui/ws:test_interface",
- "//ui/base/mojo:lib",
- "//ui/events",
- "//ui/events/ozone:events_ozone_layout",
- "//ui/gl:gl",
- "//ui/platform_window:platform_impls",
- "//ui/platform_window:platform_window",
- ]
-
- if (use_x11) {
- public_configs = [ "//build/config/linux:x11" ]
- public_deps += [ "//ui/events/platform/x11" ]
- }
-
- if (use_ozone) {
- deps += [ "//ui/ozone:ozone" ]
- }
-
- if (is_chromeos) {
- deps += [ "//services/ui/public/cpp/input_devices:input_device_controller" ]
- }
-}
-
-repack("resources_strings") {
- sources = [
- "$root_gen_dir/ui/strings/app_locale_settings_en-US.pak",
- "$root_gen_dir/ui/strings/ui_strings_en-US.pak",
- ]
- output = "$root_out_dir/mus_app_resources_strings.pak"
- deps = [
- "//ui/strings",
- ]
-}
-
-repack("resources_100") {
- sources = [
- "$root_gen_dir/ui/resources/ui_resources_100_percent.pak",
- ]
- output = "$root_out_dir/mus_app_resources_100.pak"
- deps = [
- "//ui/resources",
- ]
-}
-
-repack("resources_200") {
- sources = [
- "$root_gen_dir/ui/resources/ui_resources_200_percent.pak",
- ]
- output = "$root_out_dir/mus_app_resources_200.pak"
- deps = [
- "//ui/resources",
- ]
-}
diff --git a/services/ui/ime/BUILD.gn b/services/ui/ime/BUILD.gn
index 8f82b69..93b70a4 100644
--- a/services/ui/ime/BUILD.gn
+++ b/services/ui/ime/BUILD.gn
@@ -41,7 +41,6 @@
data_deps = [
":lib",
- "//services/ui",
"//services/ui/ime/test_ime_driver",
]
}
diff --git a/services/ui/main.cc b/services/ui/main.cc
deleted file mode 100644
index 2f3f812..0000000
--- a/services/ui/main.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2014 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 "services/service_manager/public/c/main.h"
-#include "base/message_loop/message_loop.h"
-#include "services/service_manager/public/cpp/service_runner.h"
-#include "services/ui/service.h"
-
-MojoResult ServiceMain(MojoHandle service_request_handle) {
- ui::Service::InitParams params;
- params.running_standalone = true;
- ui::Service* ui_service = new ui::Service(params);
- service_manager::ServiceRunner runner(ui_service);
- runner.set_message_loop_type(base::MessageLoop::TYPE_UI);
- return runner.Run(service_request_handle);
-}
diff --git a/services/ui/service.cc b/services/ui/service.cc
deleted file mode 100644
index 5011695..0000000
--- a/services/ui/service.cc
+++ /dev/null
@@ -1,546 +0,0 @@
-// Copyright 2014 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 "services/ui/service.h"
-
-#include <set>
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/run_loop.h"
-#include "base/threading/platform_thread.h"
-#include "base/trace_event/trace_event.h"
-#include "build/build_config.h"
-#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
-#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "services/catalog/public/cpp/resource_loader.h"
-#include "services/catalog/public/mojom/constants.mojom.h"
-#include "services/service_manager/public/c/main.h"
-#include "services/service_manager/public/cpp/connector.h"
-#include "services/service_manager/public/cpp/service_context.h"
-#include "services/ui/common/image_cursors_set.h"
-#include "services/ui/common/switches.h"
-#include "services/ui/display/screen_manager.h"
-#include "services/ui/gpu_host/gpu_host.h"
-#include "services/ui/ime/ime_driver_bridge.h"
-#include "services/ui/ime/ime_registrar_impl.h"
-#include "services/ui/ws/accessibility_manager.h"
-#include "services/ui/ws/display_binding.h"
-#include "services/ui/ws/display_creation_config.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/event_injector.h"
-#include "services/ui/ws/threaded_image_cursors.h"
-#include "services/ui/ws/threaded_image_cursors_factory.h"
-#include "services/ui/ws/user_activity_monitor.h"
-#include "services/ui/ws/user_display_manager.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_server_test_impl.h"
-#include "services/ui/ws/window_tree.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "services/ui/ws/window_tree_factory.h"
-#include "services/ui/ws/window_tree_host_factory.h"
-#include "ui/base/cursor/image_cursors.h"
-#include "ui/base/mojo/clipboard_host.h"
-#include "ui/base/platform_window_defaults.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/base/ui_base_features.h"
-#include "ui/base/ui_base_paths.h"
-#include "ui/events/event_switches.h"
-#include "ui/events/platform/platform_event_source.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gl/gl_surface.h"
-
-#if defined(USE_X11)
-#include "ui/base/x/x11_util.h" // nogncheck
-#include "ui/gfx/x/x11.h"
-#include "ui/platform_window/x11/x11_window.h"
-#elif defined(USE_OZONE)
-#include "services/ui/display/screen_manager_forwarding.h"
-#include "ui/events/ozone/layout/keyboard_layout_engine.h"
-#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
-#include "ui/ozone/public/ozone_platform.h"
-#endif
-
-#if defined(OS_CHROMEOS)
-#include "services/ui/public/cpp/input_devices/input_device_controller.h"
-#endif
-
-using mojo::InterfaceRequest;
-using ui::mojom::WindowServerTest;
-using ui::mojom::WindowTreeHostFactory;
-
-namespace ui {
-
-namespace {
-
-const char kResourceFileStrings[] = "mus_app_resources_strings.pak";
-const char kResourceFile100[] = "mus_app_resources_100.pak";
-const char kResourceFile200[] = "mus_app_resources_200.pak";
-
-class ThreadedImageCursorsFactoryImpl : public ws::ThreadedImageCursorsFactory {
- public:
- explicit ThreadedImageCursorsFactoryImpl(const Service::InitParams& params) {
- // When running in-process use |resource_runner_| to load cursors.
- if (params.resource_runner) {
- resource_runner_ = params.resource_runner;
- // |params.image_cursors_set_weak_ptr| must be set, but don't DCHECK
- // because it can only be dereferenced on |resource_runner_|.
- image_cursors_set_weak_ptr_ = params.image_cursors_set_weak_ptr;
- }
- }
-
- ~ThreadedImageCursorsFactoryImpl() override = default;
-
- // ws::ThreadedImageCursorsFactory:
- std::unique_ptr<ws::ThreadedImageCursors> CreateCursors() override {
- // When running out-of-process lazily initialize the resource runner to the
- // UI service's thread.
- if (!resource_runner_) {
- resource_runner_ = base::ThreadTaskRunnerHandle::Get();
- image_cursors_set_ = std::make_unique<ui::ImageCursorsSet>();
- image_cursors_set_weak_ptr_ = image_cursors_set_->GetWeakPtr();
- }
- return std::make_unique<ws::ThreadedImageCursors>(
- resource_runner_, image_cursors_set_weak_ptr_);
- }
-
- private:
- scoped_refptr<base::SingleThreadTaskRunner> resource_runner_;
- base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr_;
-
- // Used when UI Service doesn't run inside WM's process.
- std::unique_ptr<ui::ImageCursorsSet> image_cursors_set_;
-
- DISALLOW_COPY_AND_ASSIGN(ThreadedImageCursorsFactoryImpl);
-};
-
-} // namespace
-
-// TODO(sky): this is a pretty typical pattern, make it easier to do.
-struct Service::PendingRequest {
- service_manager::BindSourceInfo source_info;
- std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request;
- std::unique_ptr<mojom::ScreenProviderRequest> screen_request;
-};
-
-Service::InitParams::InitParams() = default;
-
-Service::InitParams::~InitParams() = default;
-
-Service::Service(const InitParams& params)
- : running_standalone_(params.running_standalone),
- threaded_image_cursors_factory_(
- std::make_unique<ThreadedImageCursorsFactoryImpl>(params)),
- test_config_(false),
- ime_registrar_(&ime_driver_),
- discardable_shared_memory_manager_(params.memory_manager),
- should_host_viz_(params.should_host_viz) {
- // UI service must host viz when running in its own process.
- DCHECK(!running_standalone_ || should_host_viz_);
-}
-
-Service::~Service() {
- in_destructor_ = true;
-
- // Destroy |window_server_| first, since it depends on |event_source_|.
- // WindowServer (or more correctly its Displays) may have state that needs to
- // be destroyed before GpuState as well.
- window_server_.reset();
-
- // Must be destroyed before calling OzonePlatform::Shutdown().
- threaded_image_cursors_factory_.reset();
-
-#if defined(OS_CHROMEOS)
- // InputDeviceController uses ozone.
- input_device_controller_.reset();
-#endif
-
-#if defined(USE_OZONE)
- OzonePlatform::Shutdown();
-#endif
-}
-
-bool Service::InitializeResources(service_manager::Connector* connector) {
- if (!running_standalone_ || ui::ResourceBundle::HasSharedInstance())
- return true;
-
- std::set<std::string> resource_paths;
- resource_paths.insert(kResourceFileStrings);
- resource_paths.insert(kResourceFile100);
- resource_paths.insert(kResourceFile200);
-
- catalog::ResourceLoader loader;
- filesystem::mojom::DirectoryPtr directory;
- connector->BindInterface(catalog::mojom::kServiceName, &directory);
- if (!loader.OpenFiles(std::move(directory), resource_paths)) {
- LOG(ERROR) << "Service failed to open resource files.";
- return false;
- }
-
- ui::RegisterPathProvider();
-
- // Initialize resource bundle with 1x and 2x cursor bitmaps.
- ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(
- loader.TakeFile(kResourceFileStrings),
- base::MemoryMappedFile::Region::kWholeFile);
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100),
- ui::SCALE_FACTOR_100P);
- rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200),
- ui::SCALE_FACTOR_200P);
- return true;
-}
-
-void Service::OnStart() {
- base::PlatformThread::SetName("mus");
- TRACE_EVENT0("mus", "Service::Initialize started");
-
- test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kUseTestConfig);
-#if defined(USE_X11)
- XInitThreads();
- ui::SetDefaultX11ErrorHandlers();
-#endif
-
- if (test_config_)
- ui::test::EnableTestConfigForPlatformWindows();
-
- // If resources are unavailable do not complete start-up.
- if (!InitializeResources(context()->connector())) {
- context()->QuitNow();
- return;
- }
-
-#if defined(USE_OZONE)
- // The ozone platform can provide its own event source. So initialize the
- // platform before creating the default event source.
- // Because GL libraries need to be initialized before entering the sandbox,
- // in MUS, |InitializeForUI| will load the GL libraries.
- ui::OzonePlatform::InitParams params;
- if (should_host_viz_) {
- // If mus is hosting viz, then it needs to set up ozone so that it can
- // connect to the gpu service through the connector.
- // Currently mus hosting viz (i.e. mash mode) only runs single-process.
- params.connector = context()->connector();
- params.single_process = true;
- params.using_mojo = true;
- } else {
- params.using_mojo = features::IsOzoneDrmMojo();
- }
- ui::OzonePlatform::InitializeForUI(params);
-
- // Assume a client will change the layout to an appropriate configuration.
- ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()
- ->SetCurrentLayoutByName("us");
-#endif
-
-#if defined(OS_CHROMEOS)
- input_device_controller_ = std::make_unique<InputDeviceController>();
- input_device_controller_->AddInterface(®istry_);
-#endif
-
-#if !defined(OS_ANDROID)
- event_source_ = ui::PlatformEventSource::CreateDefault();
-#endif
-
- // This needs to happen after DeviceDataManager has been constructed. That
- // happens either during OzonePlatform or PlatformEventSource initialization,
- // so keep this line below both of those.
- input_device_server_.RegisterAsObserver();
-
- if (!discardable_shared_memory_manager_) {
- owned_discardable_shared_memory_manager_ =
- std::make_unique<discardable_memory::DiscardableSharedMemoryManager>();
- discardable_shared_memory_manager_ =
- owned_discardable_shared_memory_manager_.get();
- }
-
- window_server_ = std::make_unique<ws::WindowServer>(this, should_host_viz_);
- if (should_host_viz_) {
- std::unique_ptr<gpu_host::GpuHost> gpu_host =
- std::make_unique<gpu_host::DefaultGpuHost>(
- window_server_.get(), context()->connector(),
- discardable_shared_memory_manager_);
- window_server_->SetGpuHost(std::move(gpu_host));
-
- registry_.AddInterface<mojom::Gpu>(
- base::BindRepeating(&Service::BindGpuRequest, base::Unretained(this)));
-#if defined(OS_CHROMEOS)
- registry_.AddInterface<mojom::Arc>(
- base::BindRepeating(&Service::BindArcRequest, base::Unretained(this)));
-#endif // defined(OS_CHROMEOS)
- }
- registry_.AddInterface<mojom::VideoDetector>(base::BindRepeating(
- &Service::BindVideoDetectorRequest, base::Unretained(this)));
-
- ime_driver_.Init(context()->connector(), test_config_);
-
- registry_with_source_info_.AddInterface<mojom::AccessibilityManager>(
- base::BindRepeating(&Service::BindAccessibilityManagerRequest,
- base::Unretained(this)));
- registry_with_source_info_.AddInterface<mojom::ClipboardHost>(
- base::BindRepeating(&Service::BindClipboardHostRequest,
- base::Unretained(this)));
- registry_with_source_info_.AddInterface<mojom::ScreenProvider>(
- base::BindRepeating(&Service::BindScreenProviderRequest,
- base::Unretained(this)));
- registry_.AddInterface<mojom::IMERegistrar>(base::BindRepeating(
- &Service::BindIMERegistrarRequest, base::Unretained(this)));
- registry_.AddInterface<mojom::IMEDriver>(base::BindRepeating(
- &Service::BindIMEDriverRequest, base::Unretained(this)));
- registry_with_source_info_.AddInterface<mojom::UserActivityMonitor>(
- base::BindRepeating(&Service::BindUserActivityMonitorRequest,
- base::Unretained(this)));
- registry_with_source_info_.AddInterface<WindowTreeHostFactory>(
- base::BindRepeating(&Service::BindWindowTreeHostFactoryRequest,
- base::Unretained(this)));
- registry_with_source_info_
- .AddInterface<mojom::WindowManagerWindowTreeFactory>(base::BindRepeating(
- &Service::BindWindowManagerWindowTreeFactoryRequest,
- base::Unretained(this)));
- registry_with_source_info_.AddInterface<mojom::WindowTreeFactory>(
- base::BindRepeating(&Service::BindWindowTreeFactoryRequest,
- base::Unretained(this)));
- registry_with_source_info_
- .AddInterface<discardable_memory::mojom::DiscardableSharedMemoryManager>(
- base::BindRepeating(
- &Service::BindDiscardableSharedMemoryManagerRequest,
- base::Unretained(this)));
- if (test_config_) {
- registry_.AddInterface<WindowServerTest>(base::BindRepeating(
- &Service::BindWindowServerTestRequest, base::Unretained(this)));
- }
- registry_.AddInterface<mojom::EventInjector>(base::BindRepeating(
- &Service::BindEventInjectorRequest, base::Unretained(this)));
-
- // On non-Linux platforms there will be no DeviceDataManager instance and no
- // purpose in adding the Mojo interface to connect to.
- if (input_device_server_.IsRegisteredAsObserver()) {
- registry_.AddInterface<mojom::InputDeviceServer>(base::BindRepeating(
- &Service::BindInputDeviceServerRequest, base::Unretained(this)));
- }
-
-#if defined(OS_CHROMEOS)
- registry_.AddInterface<mojom::TouchDeviceServer>(base::BindRepeating(
- &Service::BindTouchDeviceServerRequest, base::Unretained(this)));
-#endif // defined(OS_CHROMEOS)
-
-#if defined(USE_OZONE)
- ui::OzonePlatform::GetInstance()->AddInterfaces(®istry_);
-#endif
-}
-
-void Service::OnBindInterface(
- const service_manager::BindSourceInfo& source_info,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) {
- if (!registry_with_source_info_.TryBindInterface(
- interface_name, &interface_pipe, source_info)) {
- registry_.BindInterface(interface_name, std::move(interface_pipe));
- }
-}
-
-void Service::StartDisplayInit() {
- DCHECK(!is_gpu_ready_); // This should only be called once.
- is_gpu_ready_ = true;
- if (screen_manager_)
- screen_manager_->Init(window_server_->display_manager());
-}
-
-void Service::OnFirstDisplayReady() {
- PendingRequests requests;
- requests.swap(pending_requests_);
- for (auto& request : requests) {
- if (request->wtf_request) {
- BindWindowTreeFactoryRequest(std::move(*request->wtf_request),
- request->source_info);
- } else {
- BindScreenProviderRequest(std::move(*request->screen_request),
- request->source_info);
- }
- }
-}
-
-void Service::OnNoMoreDisplays() {
- // We may get here from the destructor. Don't try to use RequestQuit() when
- // that happens as ServiceContext DCHECKs in this case.
- if (in_destructor_)
- return;
-
- DCHECK(context());
- context()->CreateQuitClosure().Run();
-}
-
-bool Service::IsTestConfig() const {
- return test_config_;
-}
-
-void Service::OnWillCreateTreeForWindowManager(
- bool automatically_create_display_roots) {
- if (window_server_->display_creation_config() !=
- ws::DisplayCreationConfig::UNKNOWN) {
- return;
- }
-
- DVLOG(3) << "OnWillCreateTreeForWindowManager "
- << automatically_create_display_roots;
- ws::DisplayCreationConfig config = automatically_create_display_roots
- ? ws::DisplayCreationConfig::AUTOMATIC
- : ws::DisplayCreationConfig::MANUAL;
- window_server_->SetDisplayCreationConfig(config);
- if (window_server_->display_creation_config() ==
- ws::DisplayCreationConfig::MANUAL) {
-#if defined(OS_CHROMEOS)
- display::ScreenManagerForwarding::Mode mode =
- running_standalone_
- ? display::ScreenManagerForwarding::Mode::OWN_PROCESS
- : display::ScreenManagerForwarding::Mode::IN_WM_PROCESS;
- screen_manager_ = std::make_unique<display::ScreenManagerForwarding>(mode);
-#else
- CHECK(false);
-#endif
- } else {
- screen_manager_ = display::ScreenManager::Create();
- }
- screen_manager_->AddInterfaces(®istry_with_source_info_);
- if (is_gpu_ready_)
- screen_manager_->Init(window_server_->display_manager());
-}
-
-ws::ThreadedImageCursorsFactory* Service::GetThreadedImageCursorsFactory() {
- return threaded_image_cursors_factory_.get();
-}
-
-void Service::BindAccessibilityManagerRequest(
- mojom::AccessibilityManagerRequest request,
- const service_manager::BindSourceInfo& source_info) {
- if (!accessibility_) {
- accessibility_ =
- std::make_unique<ws::AccessibilityManager>(window_server_.get());
- }
- accessibility_->Bind(std::move(request));
-}
-
-void Service::BindClipboardHostRequest(
- mojom::ClipboardHostRequest request,
- const service_manager::BindSourceInfo& source_info) {
- if (!clipboard_host_)
- clipboard_host_ = std::make_unique<ClipboardHost>();
- clipboard_host_->AddBinding(std::move(request));
-}
-
-void Service::BindScreenProviderRequest(
- mojom::ScreenProviderRequest request,
- const service_manager::BindSourceInfo& source_info) {
- // Wait for the DisplayManager to be configured before binding display
- // requests. Otherwise the client sees no displays.
- if (!window_server_->display_manager()->IsReady()) {
- std::unique_ptr<PendingRequest> pending_request(new PendingRequest);
- pending_request->source_info = source_info;
- pending_request->screen_request =
- std::make_unique<mojom::ScreenProviderRequest>(std::move(request));
- pending_requests_.push_back(std::move(pending_request));
- return;
- }
- window_server_->display_manager()
- ->GetUserDisplayManager()
- ->AddDisplayManagerBinding(std::move(request));
-}
-
-void Service::BindGpuRequest(mojom::GpuRequest request) {
- window_server_->gpu_host()->Add(std::move(request));
-}
-
-void Service::BindIMERegistrarRequest(mojom::IMERegistrarRequest request) {
- ime_registrar_.AddBinding(std::move(request));
-}
-
-void Service::BindIMEDriverRequest(mojom::IMEDriverRequest request) {
- ime_driver_.AddBinding(std::move(request));
-}
-
-void Service::BindInputDeviceServerRequest(
- mojom::InputDeviceServerRequest request) {
- input_device_server_.AddBinding(std::move(request));
-}
-
-void Service::BindUserActivityMonitorRequest(
- mojom::UserActivityMonitorRequest request,
- const service_manager::BindSourceInfo& source_info) {
- window_server_->user_activity_monitor()->Add(std::move(request));
-}
-
-void Service::BindWindowManagerWindowTreeFactoryRequest(
- mojom::WindowManagerWindowTreeFactoryRequest request,
- const service_manager::BindSourceInfo& source_info) {
- window_server_->BindWindowManagerWindowTreeFactory(std::move(request));
-}
-
-void Service::BindWindowTreeFactoryRequest(
- mojom::WindowTreeFactoryRequest request,
- const service_manager::BindSourceInfo& source_info) {
- if (!window_server_->display_manager()->IsReady()) {
- std::unique_ptr<PendingRequest> pending_request(new PendingRequest);
- pending_request->source_info = source_info;
- pending_request->wtf_request.reset(
- new mojom::WindowTreeFactoryRequest(std::move(request)));
- pending_requests_.push_back(std::move(pending_request));
- return;
- }
- mojo::MakeStrongBinding(
- std::make_unique<ws::WindowTreeFactory>(window_server_.get(),
- source_info.identity.name()),
- std::move(request));
-}
-
-void Service::BindWindowTreeHostFactoryRequest(
- mojom::WindowTreeHostFactoryRequest request,
- const service_manager::BindSourceInfo& source_info) {
- if (!window_tree_host_factory_) {
- window_tree_host_factory_ =
- std::make_unique<ws::WindowTreeHostFactory>(window_server_.get());
- }
- window_tree_host_factory_->AddBinding(std::move(request));
-}
-
-void Service::BindDiscardableSharedMemoryManagerRequest(
- discardable_memory::mojom::DiscardableSharedMemoryManagerRequest request,
- const service_manager::BindSourceInfo& source_info) {
- discardable_shared_memory_manager_->Bind(std::move(request), source_info);
-}
-
-void Service::BindWindowServerTestRequest(
- mojom::WindowServerTestRequest request) {
- if (!test_config_)
- return;
- mojo::MakeStrongBinding(
- std::make_unique<ws::WindowServerTestImpl>(window_server_.get()),
- std::move(request));
-}
-
-void Service::BindEventInjectorRequest(mojom::EventInjectorRequest request) {
- mojo::MakeStrongBinding(
- std::make_unique<ws::EventInjector>(window_server_.get()),
- std::move(request));
-}
-
-void Service::BindVideoDetectorRequest(mojom::VideoDetectorRequest request) {
- if (!should_host_viz_)
- return;
- window_server_->video_detector()->AddBinding(std::move(request));
-}
-
-#if defined(OS_CHROMEOS)
-void Service::BindArcRequest(mojom::ArcRequest request) {
- window_server_->gpu_host()->AddArc(std::move(request));
-}
-
-void Service::BindTouchDeviceServerRequest(
- mojom::TouchDeviceServerRequest request) {
- touch_device_server_.AddBinding(std::move(request));
-}
-
-#endif // defined(OS_CHROMEOS)
-
-} // namespace ui
diff --git a/services/ui/service.h b/services/ui/service.h
deleted file mode 100644
index 59bae85..0000000
--- a/services/ui/service.h
+++ /dev/null
@@ -1,242 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_SERVICE_H_
-#define SERVICES_UI_SERVICE_H_
-
-#include <stdint.h>
-
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/memory/weak_ptr.h"
-#include "base/single_thread_task_runner.h"
-#include "components/discardable_memory/public/interfaces/discardable_shared_memory_manager.mojom.h"
-#include "services/service_manager/public/cpp/binder_registry.h"
-#include "services/service_manager/public/cpp/connector.h"
-#include "services/service_manager/public/cpp/service.h"
-#include "services/service_manager/public/cpp/service_runner.h"
-#include "services/ui/ime/ime_driver_bridge.h"
-#include "services/ui/ime/ime_registrar_impl.h"
-#include "services/ui/input_devices/input_device_server.h"
-#include "services/ui/public/interfaces/accessibility_manager.mojom.h"
-#include "services/ui/public/interfaces/event_injector.mojom.h"
-#include "services/ui/public/interfaces/gpu.mojom.h"
-#include "services/ui/public/interfaces/ime/ime.mojom.h"
-#include "services/ui/public/interfaces/screen_provider.mojom.h"
-#include "services/ui/public/interfaces/user_activity_monitor.mojom.h"
-#include "services/ui/public/interfaces/video_detector.mojom.h"
-#include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom.h"
-#include "services/ui/public/interfaces/window_server_test.mojom.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/public/interfaces/window_tree_host_factory.mojom.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "ui/base/mojo/clipboard.mojom.h"
-
-#if defined(OS_CHROMEOS)
-#include "services/ui/input_devices/touch_device_server.h"
-#include "services/ui/public/interfaces/arc.mojom.h"
-#endif // defined(OS_CHROMEOS)
-
-namespace discardable_memory {
-class DiscardableSharedMemoryManager;
-}
-
-namespace display {
-class ScreenManager;
-}
-
-namespace service_manager {
-class Connector;
-class Identity;
-}
-
-namespace ui {
-
-class ClipboardHost;
-class ImageCursorsSet;
-class InputDeviceController;
-class PlatformEventSource;
-
-namespace ws {
-class AccessibilityManager;
-class ThreadedImageCursorsFactory;
-class WindowServer;
-class WindowTreeHostFactory;
-}
-
-class Service : public service_manager::Service,
- public ws::WindowServerDelegate {
- public:
- // TODO(jamescook): Audit these. Some may be unused after the elimination of
- // "mus" mode.
- struct InitParams {
- InitParams();
- ~InitParams();
-
- // UI service runs in its own process (i.e. not embedded in browser or ash).
- bool running_standalone = false;
-
- // Can be used to load resources.
- scoped_refptr<base::SingleThreadTaskRunner> resource_runner = nullptr;
-
- // Can only be de-referenced on |resource_runner_|.
- base::WeakPtr<ImageCursorsSet> image_cursors_set_weak_ptr = nullptr;
-
- // If null Service creates a DiscardableSharedMemoryManager.
- discardable_memory::DiscardableSharedMemoryManager* memory_manager =
- nullptr;
-
- // Whether mus should host viz, or whether an external client (e.g. the
- // window manager) would be responsible for hosting viz.
- bool should_host_viz = true;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(InitParams);
- };
-
- explicit Service(const InitParams& params);
- ~Service() override;
-
- private:
- // Holds InterfaceRequests received before the first WindowTreeHost Display
- // has been established.
- struct PendingRequest;
-
- // Attempts to initialize the resource bundle. Returns true if successful,
- // otherwise false if resources cannot be loaded.
- bool InitializeResources(service_manager::Connector* connector);
-
- void AddUserIfNecessary(const service_manager::Identity& remote_identity);
-
- // service_manager::Service:
- void OnStart() override;
- void OnBindInterface(const service_manager::BindSourceInfo& source_info,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) override;
-
- // WindowServerDelegate:
- void StartDisplayInit() override;
- void OnFirstDisplayReady() override;
- void OnNoMoreDisplays() override;
- bool IsTestConfig() const override;
- void OnWillCreateTreeForWindowManager(
- bool automatically_create_display_roots) override;
- ws::ThreadedImageCursorsFactory* GetThreadedImageCursorsFactory() override;
-
- void BindAccessibilityManagerRequest(
- mojom::AccessibilityManagerRequest request,
- const service_manager::BindSourceInfo& source_info);
-
- void BindClipboardHostRequest(
- mojom::ClipboardHostRequest request,
- const service_manager::BindSourceInfo& source_info);
-
- void BindScreenProviderRequest(
- mojom::ScreenProviderRequest request,
- const service_manager::BindSourceInfo& source_info);
-
- void BindGpuRequest(mojom::GpuRequest request);
-
- void BindIMERegistrarRequest(mojom::IMERegistrarRequest request);
-
- void BindIMEDriverRequest(mojom::IMEDriverRequest request);
-
- void BindInputDeviceServerRequest(mojom::InputDeviceServerRequest request);
-
- void BindUserActivityMonitorRequest(
- mojom::UserActivityMonitorRequest request,
- const service_manager::BindSourceInfo& source_info);
-
- void BindWindowManagerWindowTreeFactoryRequest(
- mojom::WindowManagerWindowTreeFactoryRequest request,
- const service_manager::BindSourceInfo& source_info);
-
- void BindWindowTreeFactoryRequest(
- mojom::WindowTreeFactoryRequest request,
- const service_manager::BindSourceInfo& source_info);
-
- void BindWindowTreeHostFactoryRequest(
- mojom::WindowTreeHostFactoryRequest request,
- const service_manager::BindSourceInfo& source_info);
-
- void BindDiscardableSharedMemoryManagerRequest(
- discardable_memory::mojom::DiscardableSharedMemoryManagerRequest request,
- const service_manager::BindSourceInfo& source_info);
-
- void BindWindowServerTestRequest(mojom::WindowServerTestRequest request);
-
- void BindEventInjectorRequest(mojom::EventInjectorRequest request);
-
- void BindVideoDetectorRequest(mojom::VideoDetectorRequest request);
-
-#if defined(OS_CHROMEOS)
- void BindArcRequest(mojom::ArcRequest request);
- void BindTouchDeviceServerRequest(mojom::TouchDeviceServerRequest request);
-#endif // defined(OS_CHROMEOS)
-
- std::unique_ptr<ws::WindowServer> window_server_;
- std::unique_ptr<PlatformEventSource> event_source_;
- using PendingRequests = std::vector<std::unique_ptr<PendingRequest>>;
- PendingRequests pending_requests_;
-
- // Provides input-device information via Mojo IPC. Registers Mojo interfaces
- // and must outlive |registry_|.
- InputDeviceServer input_device_server_;
-
- // True if the UI Service runs runs inside its own process, false if it is
- // embedded in another process.
- const bool running_standalone_;
-
- std::unique_ptr<ws::ThreadedImageCursorsFactory>
- threaded_image_cursors_factory_;
-
- bool test_config_;
-
-#if defined(OS_CHROMEOS)
- std::unique_ptr<InputDeviceController> input_device_controller_;
- TouchDeviceServer touch_device_server_;
-#endif
-
- // Manages display hardware and handles display management. May register Mojo
- // interfaces and must outlive |registry_|.
- std::unique_ptr<display::ScreenManager> screen_manager_;
-
- IMERegistrarImpl ime_registrar_;
- IMEDriverBridge ime_driver_;
-
- discardable_memory::DiscardableSharedMemoryManager*
- discardable_shared_memory_manager_;
-
- // non-null if this created the DiscardableSharedMemoryManager. Null when
- // running in-process.
- std::unique_ptr<discardable_memory::DiscardableSharedMemoryManager>
- owned_discardable_shared_memory_manager_;
-
- const bool should_host_viz_;
-
- service_manager::BinderRegistryWithArgs<
- const service_manager::BindSourceInfo&>
- registry_with_source_info_;
- service_manager::BinderRegistry registry_;
-
- // Set to true in StartDisplayInit().
- bool is_gpu_ready_ = false;
-
- bool in_destructor_ = false;
-
- std::unique_ptr<ClipboardHost> clipboard_host_;
- std::unique_ptr<ws::AccessibilityManager> accessibility_;
- std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(Service);
-};
-
-} // namespace ui
-
-#endif // SERVICES_UI_SERVICE_H_
diff --git a/services/ui/ws/BUILD.gn b/services/ui/ws/BUILD.gn
deleted file mode 100644
index cb54a12..0000000
--- a/services/ui/ws/BUILD.gn
+++ /dev/null
@@ -1,335 +0,0 @@
-# Copyright 2014 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.
-
-import("//build/config/ui.gni")
-import("//testing/test.gni")
-import("//services/catalog/public/tools/catalog.gni")
-import("//services/service_manager/public/cpp/service.gni")
-import("//services/service_manager/public/service_manifest.gni")
-import("//services/service_manager/public/tools/test/service_test.gni")
-
-# In external window mode, top-level windows are native platform windows i.e.
-# not children of a Chrome OS window manager's root window.
-is_external_mode = use_ozone && !is_chromeos
-
-static_library("lib") {
- sources = [
- "accelerator.cc",
- "accelerator.h",
- "access_policy.h",
- "access_policy_delegate.h",
- "accessibility_manager.cc",
- "accessibility_manager.h",
- "async_event_dispatcher.h",
- "async_event_dispatcher_lookup.h",
- "compositor_frame_sink_client_binding.cc",
- "compositor_frame_sink_client_binding.h",
- "cursor_location_manager.cc",
- "cursor_location_manager.h",
- "cursor_state.cc",
- "cursor_state.h",
- "cursor_state_delegate.h",
- "debug_utils.cc",
- "debug_utils.h",
- "default_access_policy.cc",
- "default_access_policy.h",
- "display.cc",
- "display.h",
- "display_binding.cc",
- "display_binding.h",
- "display_creation_config.h",
- "display_manager.cc",
- "display_manager.h",
- "drag_controller.cc",
- "drag_controller.h",
- "drag_cursor_updater.h",
- "drag_source.h",
- "drag_target_connection.h",
- "event_dispatcher.h",
- "event_dispatcher_delegate.h",
- "event_dispatcher_impl.cc",
- "event_dispatcher_impl.h",
- "event_injector.cc",
- "event_injector.h",
- "event_location.h",
- "event_matcher.cc",
- "event_matcher.h",
- "event_processor.cc",
- "event_processor.h",
- "event_processor_delegate.h",
- "event_targeter.cc",
- "event_targeter.h",
- "event_targeter_delegate.h",
- "focus_controller.cc",
- "focus_controller.h",
- "focus_controller_observer.h",
- "frame_generator.cc",
- "frame_generator.h",
- "modal_window_controller.cc",
- "modal_window_controller.h",
- "operation.cc",
- "operation.h",
- "platform_display.cc",
- "platform_display.h",
- "platform_display_default.cc",
- "platform_display_default.h",
- "platform_display_delegate.h",
- "platform_display_factory.h",
- "platform_display_mirror.cc",
- "platform_display_mirror.h",
- "server_window.cc",
- "server_window.h",
- "server_window_delegate.h",
- "server_window_drawn_tracker.cc",
- "server_window_drawn_tracker.h",
- "server_window_drawn_tracker_observer.h",
- "server_window_observer.h",
- "server_window_tracker.h",
- "threaded_image_cursors.cc",
- "threaded_image_cursors.h",
- "threaded_image_cursors_factory.h",
- "user_activity_monitor.cc",
- "user_activity_monitor.h",
- "user_display_manager.cc",
- "user_display_manager.h",
- "user_display_manager_delegate.h",
- "video_detector_impl.cc",
- "video_detector_impl.h",
- "window_coordinate_conversions.cc",
- "window_coordinate_conversions.h",
- "window_finder.cc",
- "window_finder.h",
- "window_manager_access_policy.cc",
- "window_manager_access_policy.h",
- "window_manager_display_root.cc",
- "window_manager_display_root.h",
- "window_manager_state.cc",
- "window_manager_state.h",
- "window_manager_window_tree_factory.cc",
- "window_manager_window_tree_factory.h",
- "window_manager_window_tree_factory_observer.h",
- "window_server.cc",
- "window_server.h",
- "window_server_delegate.cc",
- "window_server_delegate.h",
- "window_tree.cc",
- "window_tree.h",
- "window_tree_binding.cc",
- "window_tree_binding.h",
- "window_tree_factory.cc",
- "window_tree_factory.h",
- "window_tree_host_factory.cc",
- "window_tree_host_factory.h",
- ]
-
- deps = [
- "//components/discardable_memory/service",
- "//components/viz/service/main", # TODO(sad): Temporary until GPU process split.
- "//gpu/command_buffer/client",
- "//gpu/command_buffer/client:gles2_interface",
- "//gpu/ipc/client",
- "//gpu/ipc/common",
- "//services/ui/gpu_host",
- "//services/viz/privileged/interfaces",
- ]
-
- public_deps = [
- "//base",
- "//cc",
- "//components/viz/common",
- "//components/viz/host",
- "//components/viz/service",
- "//mojo/public/cpp/bindings",
- "//mojo/public/cpp/system",
- "//services/service_manager/public/cpp",
- "//services/service_manager/public/mojom",
- "//services/ui/common:mus_common",
- "//services/ui/display",
- "//services/ui/public/interfaces",
- "//services/viz/privileged/interfaces/compositing",
- "//ui/base",
- "//ui/display",
- "//ui/events",
- "//ui/events/devices",
- "//ui/events/platform",
- "//ui/gfx",
- "//ui/gfx/geometry",
- "//ui/gfx/geometry/mojo",
- "//ui/gl",
- "//ui/platform_window",
- "//ui/platform_window:platform_impls",
- "//ui/platform_window/mojo",
- ]
-
- if (use_ozone) {
- public_deps += [ "//ui/ozone" ]
- }
- if (is_chromeos) {
- public_deps += [ "//ui/chromeos/events" ]
- if (use_ozone) {
- public_deps += [ "//ui/events/ozone:events_ozone" ]
- }
- }
-
- # ui service should not depend on below components.
- assert_no_deps = [
- "//ash",
- "//content/public/browser",
- "//content/public/common",
- "//ui/aura",
- "//ui/views",
- ]
-}
-
-static_library("test_interface") {
- sources = [
- "window_server_test_impl.cc",
- "window_server_test_impl.h",
- ]
-
- deps = [
- ":lib",
- "//mojo/public/cpp/bindings:bindings",
- "//services/ui/public/interfaces",
- "//ui/gfx",
- ]
-}
-
-static_library("test_support") {
- testonly = true
-
- sources = [
- "test_change_tracker.cc",
- "test_change_tracker.h",
- "window_server_service_test_base.cc",
- "window_server_service_test_base.h",
- ]
-
- if (!is_external_mode) {
- # WindowServerTestBase assumes an initial display (and root) is provided
- # at startup, which is not the case on platforms running external window
- # mode.
- sources += [
- "window_server_test_base.cc",
- "window_server_test_base.h",
- ]
- }
-
- deps = [
- "//base",
- "//base/test:test_config",
- "//base/test:test_support",
- "//components/viz/test:test_support",
- "//mojo/public/cpp/bindings:bindings",
- "//services/service_manager/public/cpp",
- "//services/service_manager/public/cpp:service_test_support",
- "//services/ui/common:mus_common",
- "//services/ui/public/cpp",
- "//services/ui/public/interfaces",
- "//testing/gtest",
- "//ui/aura",
- "//ui/display:test_support",
- "//ui/gfx/geometry/mojo",
- "//ui/gl",
- "//ui/wm",
- ]
-
- data_deps = [
- "//services/ui/ime/test_ime_driver",
- ]
-}
-
-source_set("tests") {
- testonly = true
-
- sources = [
- "cursor_location_manager_unittest.cc",
- "cursor_state_unittest.cc",
- "cursor_unittest.cc",
- "display_unittest.cc",
- "drag_controller_unittest.cc",
- "event_dispatcher_impl_test_api.cc",
- "event_dispatcher_impl_test_api.h",
- "event_matcher_unittest.cc",
- "event_processor_unittest.cc",
- "focus_controller_unittest.cc",
- "frame_generator_unittest.cc",
- "modal_window_controller_unittest.cc",
- "server_window_drawn_tracker_unittest.cc",
- "test_server_window_delegate.cc",
- "test_server_window_delegate.h",
- "test_utils.cc",
- "test_utils.h",
- "transient_windows_unittest.cc",
- "user_activity_monitor_unittest.cc",
- "user_display_manager_unittest.cc",
- "window_coordinate_conversions_unittest.cc",
- "window_finder_unittest.cc",
- "window_manager_state_unittest.cc",
- "window_tree_client_unittest.cc",
- "window_tree_unittest.cc",
- ]
-
- if (!is_external_mode) {
- # A window manager client is not needed on platforms running external
- # window mode, since the host system is always the window manager.
- sources += [ "window_manager_client_unittest.cc" ]
- }
-
- # TODO(jamescook): Run this test on non-ozone platforms. This will require
- # initializing all the platform-specific windowing support.
- if (use_ozone) {
- sources += [ "platform_display_default_unittest.cc" ]
- }
-
- deps = [
- ":lib",
- ":test_support",
- "//base",
- "//base/test:test_config",
- "//base/test:test_support",
- "//cc:cc",
- "//cc:test_support",
- "//components/discardable_memory/service",
- "//components/viz/service/main",
- "//components/viz/test:test_support",
- "//gpu/ipc/client",
- "//mojo/public/cpp/bindings:bindings",
- "//services/service_manager/public/cpp",
- "//services/service_manager/public/cpp:service_test_support",
- "//services/service_manager/public/mojom",
- "//services/ui/common:mus_common",
- "//services/ui/common:task_runner_test_base",
- "//services/ui/gpu_host",
- "//services/ui/gpu_host:test_support",
- "//services/ui/public/cpp",
- "//services/ui/public/interfaces",
- "//testing/gtest",
- "//third_party/mesa:osmesa",
- "//ui/aura",
- "//ui/aura:test_support",
- "//ui/events",
- "//ui/gfx",
- "//ui/gfx:test_support",
- "//ui/gfx/geometry",
- "//ui/gfx/geometry/mojo",
- "//ui/gl",
- "//ui/gl/init",
- ]
-
- data_deps = [
- "//services/ui",
- ]
-}
-
-service_manifest("unittests_manifest") {
- name = "ui_service_unittests"
- source = "test_manifest.json"
-}
-
-catalog("tests_catalog") {
- testonly = true
- embedded_services = [ ":unittests_manifest" ]
- standalone_services = [ "//services/ui:manifest" ]
-}
diff --git a/services/ui/ws/DEPS b/services/ui/ws/DEPS
deleted file mode 100644
index 67bb2c7..0000000
--- a/services/ui/ws/DEPS
+++ /dev/null
@@ -1,16 +0,0 @@
-include_rules = [
- "+components/viz/common",
- "+components/viz/host",
- "+gpu/command_buffer/client",
- "+gpu/config",
- "+gpu/ipc/client",
- "+gpu/ipc/common",
- "+services/viz/privileged/interfaces",
- "+services/viz/public/interfaces",
-]
-
-specific_include_rules = {
- ".*_(unit|pixel|perf)test.*\.cc": [
- "+components/viz/test",
- ],
-}
diff --git a/services/ui/ws/OWNERS b/services/ui/ws/OWNERS
deleted file mode 100644
index c47f9de..0000000
--- a/services/ui/ws/OWNERS
+++ /dev/null
@@ -1,8 +0,0 @@
-per-file *gpu*=fsamuel@chromium.org
-per-file *gpu*=sadrul@chromium.org
-per-file *compositor_frame*=fsamuel@chromium.org
-per-file *compositor_frame*=rjkroege@chromium.org
-per-file *frame_generator*=fsamuel@chromium.org
-
-per-file test_manifest.json=set noparent
-per-file test_manifest.json=file://ipc/SECURITY_OWNERS
diff --git a/services/ui/ws/README.md b/services/ui/ws/README.md
deleted file mode 100644
index 35688fe5..0000000
--- a/services/ui/ws/README.md
+++ /dev/null
@@ -1,113 +0,0 @@
-This directory contains the Window Service implementation.
-
-## Ids
-
-Each client connected to the Window Service is assigned a unique id inside the
-Window Service. This id is a monotonically increasing uint32_t. This is often
-referred to as the client_id.
-
-The Window Service uses a client_id of 1 for itself; 0 is not a valid client_id
-in the Window Service.
-
-As clients do not know their id, they always supply 0 as the client id in the
-mojom related functions. Internally the Window Service maps 0 to the real client
-id.
-
-Windows have a couple of different (related) ids.
-
-### ClientWindowId
-
-ClientWindowId is a uint64_t pairing of a client_id and a window_id. The
-window_id is a uint32_t assigned by the client, and should be unique within that
-client's scope. When communicating with the Window Service, clients may use 0 as
-the client_id to refer to their own windows. The Window Service maps 0 to the
-real client_id. In Window Service code the id from the client is typically
-referred to as the transport_window_id. Mojom functions that receive the
-transport_window_id map it to a ClientWindowId. ClientWindowId is a real class
-that provides type safety.
-
-When a client is embedded in an existing window, the embedded client is given
-visibility to a Window created by the embedder. In this case the Window Service
-supplies the ClientWindowId to the embedded client and uses the ClientWindowId
-at the time the Window was created (the ClientWindowId actually comes from the
-FrameSinkId, see below for details on FrameSinkId). In other words, both the
-embedder and embedded client use the same ClientWindowId for the Window. See
-discussion on FrameSinkId for more details.
-
-For a client to establish an embed root, it first calls
-ScheduleEmbedForExistingClient(), so it can provide a window_id that is unique
-within its own scope. That client then passes the returned token to what will
-become its embedder to call EmbedUsingToken(). In this case, the embedder and
-embedded client do not use the same ClientWindowId for the Window.
-
-ClientWindowId is globally unique, but a Window may have multiple
-ClientWindowIds associated with it.
-
-TODO(sky): See http://crbug.com/817850 for making it so there is only one
-ClientWindowId per Window.
-
-### FrameSinkId
-
-Each Window has a FrameSinkId that is needed for both hit-testing and
-embedding. The FrameSinkId is initialized to the ClientWindowId of the client
-creating the Window, but it changes during an embedding. In particular, when a
-client calls Embed() the FrameSinkId of the Window changes such that the
-client_id of the FrameSinkId matches the client_id of the client being
-embedded and the sink_id is set to 0. The embedder is informed of this by way of
-OnFrameSinkIdAllocated(). The embedded client is informed of the original
-FrameSinkId (the client_id of the FrameSinkId matches the embedder's client_id).
-In client code the embedded client ends up *always* using a client_id of 0 for
-the FrameSinkId. This works because Viz knows the real client_id and handles
-mapping 0 to the real client_id.
-
-The FrameSinkId of top-level windows is set to the ClientWindowId from the
-client requesting the top-level (top-levels are created and owned by the Window
-Manager). The Window Manager is told the updated FrameSinkId when it is asked
-to create the top-level (WmCreateTopLevelWindow()).
-
-The FrameSinkId of an embed root's Window is set to the ClientWindowId of the
-embed root's Window from the embedded client.
-
-### LocalSurfaceId
-
-The LocalSurfaceId (which contains unguessable) is necessary if the client wants
-to submit a compositor-frame for the Window (it wants to show something on
-screen), and not needed if the client only wants to submit a hit-test region.
-The LocalSurfaceId may be assigned when the bounds and/or device-scale-factor
-changes. The LocalSurfaceId can change at other times as well (perhaps to
-synchronize an effect with the embedded client). The LocalSurfaceId is intended
-to allow for smooth resizes and ensures at embed points the CompositorFrame from
-both clients match. Client code supplies a LocalSurfaceId for windows that have
-another client embedded in them as well as windows with a LayerTreeFrameSink.
-The LocalSurfaceId comes from the owner of the window. The embedded client is
-told of changes to the LocalSurfaceId by way of OnWindowBoundsChanged(). This is
-still very much a work in progress.
-
-FrameSinkId is derived from the embedded client, where as LocalSurfaceId
-comes from the embedder.
-
-### Event Processing
-
-One of the key operations of the Window Service is event processing. This
-includes maintaining state associated with the current input devices (such
-as the location of the mouse cursor) as well dispatching to the appropriate
-client. Event processing includes the following classes, see each for more
-details:
-. EventDispatcherImpl: events received from the platform are sent here first.
- If not already processing an event EventDispatcherImpl forwards the event to
- EventProcessor. If EventDispatcherImpl is processing an event it queues the
- event for later processing.
-. EventProcessor: maintains state related to event processing, passing the
- appropriate events and targets to EventDispatcher for dispatch.
-. AsyncEventDispatcher: dispatches an event to the client, notifying a callback
- when done. This interface is largely for testing with WindowTree providing
- the implementation.
-. EventTargeter: used by EventProcessor to determine the ServerWindow to send an
- event to. Targetting is potentially asynchronous.
-
-EventDispatcherImpl and EventProcessor both have delegates that can impact
-targetting, as well as being notified during the lifecycle of processing.
-
-EventInjector is not a core part of event processing. It allows remote clients
-to inject events for testing, remoting and similar use cases. Events injected
-via EventInjector end up going to EventProcessor.
diff --git a/services/ui/ws/accelerator.cc b/services/ui/ws/accelerator.cc
deleted file mode 100644
index ede15dd9..0000000
--- a/services/ui/ws/accelerator.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/accelerator.h"
-
-namespace ui {
-namespace ws {
-
-Accelerator::Accelerator(uint32_t id, const mojom::EventMatcher& matcher)
- : id_(id),
- accelerator_phase_(matcher.accelerator_phase),
- event_matcher_(matcher),
- weak_factory_(this) {}
-
-Accelerator::~Accelerator() {}
-
-bool Accelerator::MatchesEvent(const ui::Event& event,
- const ui::mojom::AcceleratorPhase phase) const {
- if (accelerator_phase_ != phase)
- return false;
- if (!event_matcher_.MatchesEvent(event))
- return false;
- return true;
-}
-
-bool Accelerator::EqualEventMatcher(const Accelerator* other) const {
- return accelerator_phase_ == other->accelerator_phase_ &&
- event_matcher_.Equals(other->event_matcher_);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/accelerator.h b/services/ui/ws/accelerator.h
deleted file mode 100644
index 03bd535e..0000000
--- a/services/ui/ws/accelerator.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_ACCELERATOR_H_
-#define SERVICES_UI_WS_ACCELERATOR_H_
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "services/ui/public/interfaces/event_matcher.mojom.h"
-#include "services/ui/ws/event_matcher.h"
-
-namespace ui {
-class Event;
-}
-
-namespace ui {
-namespace ws {
-
-// An Accelerator encompasses an id defined by the client, along with a unique
-// mojom::EventMatcher. See WindowManagerClient.
-//
-// This provides a WeakPtr, as the client might delete the accelerator between
-// an event having been matched and the dispatch of the accelerator to the
-// client.
-class Accelerator {
- public:
- Accelerator(uint32_t id, const mojom::EventMatcher& matcher);
- ~Accelerator();
-
- // Returns true if |event| and |phase | matches the definition in the
- // mojom::EventMatcher used for initialization.
- bool MatchesEvent(const ui::Event& event,
- const ui::mojom::AcceleratorPhase phase) const;
-
- // Returns true if |other| was created with an identical mojom::EventMatcher.
- bool EqualEventMatcher(const Accelerator* other) const;
-
- base::WeakPtr<Accelerator> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
-
- uint32_t id() const { return id_; }
-
- private:
- uint32_t id_;
- ui::mojom::AcceleratorPhase accelerator_phase_;
- EventMatcher event_matcher_;
- base::WeakPtrFactory<Accelerator> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(Accelerator);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_ACCELERATOR_H_
diff --git a/services/ui/ws/access_policy.h b/services/ui/ws/access_policy.h
deleted file mode 100644
index 2184e71..0000000
--- a/services/ui/ws/access_policy.h
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_ACCESS_POLICY_H_
-#define SERVICES_UI_WS_ACCESS_POLICY_H_
-
-#include <stdint.h>
-
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/ui/ws/ids.h"
-
-namespace ui {
-namespace ws {
-
-class AccessPolicyDelegate;
-class ServerWindow;
-
-// AccessPolicy is used by WindowTree to determine what the WindowTree is
-// allowed to do.
-class AccessPolicy {
- public:
- virtual ~AccessPolicy() {}
-
- virtual void Init(ClientSpecificId client_id,
- AccessPolicyDelegate* delegate) = 0;
-
- // Unless otherwise mentioned all arguments have been validated. That is the
- // |window| arguments are non-null unless otherwise stated (eg CanSetWindow()
- // is allowed to take a NULL window).
- virtual bool CanRemoveWindowFromParent(const ServerWindow* window) const = 0;
- virtual bool CanAddWindow(const ServerWindow* parent,
- const ServerWindow* child) const = 0;
- virtual bool CanAddTransientWindow(const ServerWindow* parent,
- const ServerWindow* child) const = 0;
- virtual bool CanRemoveTransientWindowFromParent(
- const ServerWindow* window) const = 0;
- virtual bool CanSetModal(const ServerWindow* window) const = 0;
- virtual bool CanSetChildModalParent(
- const ServerWindow* window,
- const ServerWindow* modal_parent) const = 0;
- virtual bool CanReorderWindow(const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction) const = 0;
- virtual bool CanDeleteWindow(const ServerWindow* window) const = 0;
- virtual bool CanGetWindowTree(const ServerWindow* window) const = 0;
- // Used when building a window tree (GetWindowTree()) to decide if we should
- // descend into |window|.
- virtual bool CanDescendIntoWindowForWindowTree(
- const ServerWindow* window) const = 0;
- virtual bool CanEmbed(const ServerWindow* window) const = 0;
- virtual bool CanChangeWindowVisibility(const ServerWindow* window) const = 0;
- virtual bool CanChangeWindowOpacity(const ServerWindow* window) const = 0;
- virtual bool CanSetWindowCompositorFrameSink(
- const ServerWindow* window) const = 0;
- virtual bool CanSetWindowBounds(const ServerWindow* window) const = 0;
- virtual bool CanSetWindowTransform(const ServerWindow* window) const = 0;
- virtual bool CanSetWindowProperties(const ServerWindow* window) const = 0;
- virtual bool CanSetWindowTextInputState(const ServerWindow* window) const = 0;
- virtual bool CanSetCapture(const ServerWindow* window) const = 0;
- virtual bool CanSetFocus(const ServerWindow* window) const = 0;
- virtual bool CanSetClientArea(const ServerWindow* window) const = 0;
- virtual bool CanSetHitTestMask(const ServerWindow* window) const = 0;
- virtual bool CanSetAcceptDrops(const ServerWindow* window) const = 0;
- virtual bool CanSetEventTargetingPolicy(const ServerWindow* window) const = 0;
- virtual bool CanStackAbove(const ServerWindow* above,
- const ServerWindow* below) const = 0;
- virtual bool CanStackAtTop(const ServerWindow* window) const = 0;
- virtual bool CanPerformWmAction(const ServerWindow* window) const = 0;
- // Used for all client controllable cursor properties; which cursor should be
- // displayed, visibility, locking, etc.
- virtual bool CanSetCursorProperties(const ServerWindow* window) const = 0;
- virtual bool CanInitiateDragLoop(const ServerWindow* window) const = 0;
- virtual bool CanInitiateMoveLoop(const ServerWindow* window) const = 0;
-
- // Returns whether the client should notify on a hierarchy change.
- // |new_parent| and |old_parent| are initially set to the new and old parents
- // but may be altered so that the client only sees a certain set of windows.
- virtual bool ShouldNotifyOnHierarchyChange(
- const ServerWindow* window,
- const ServerWindow** new_parent,
- const ServerWindow** old_parent) const = 0;
- virtual bool CanSetWindowManager() const = 0;
-
- // Returns the window to supply to the client when focus changes to |focused|.
- virtual const ServerWindow* GetWindowForFocusChange(
- const ServerWindow* focused) = 0;
-
- virtual bool IsValidIdForNewWindow(const ClientWindowId& id) const = 0;
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_ACCESS_POLICY_H_
diff --git a/services/ui/ws/access_policy_delegate.h b/services/ui/ws/access_policy_delegate.h
deleted file mode 100644
index 378995dc4..0000000
--- a/services/ui/ws/access_policy_delegate.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_ACCESS_POLICY_DELEGATE_H_
-#define SERVICES_UI_WS_ACCESS_POLICY_DELEGATE_H_
-
-namespace ui {
-namespace ws {
-
-class ServerWindow;
-
-// Delegate used by the AccessPolicy implementations to get state.
-class AccessPolicyDelegate {
- public:
- // Returns true if the tree has |window| as one of its roots.
- virtual bool HasRootForAccessPolicy(const ServerWindow* window) const = 0;
-
- // Returns true if |window| has been exposed to the client.
- virtual bool IsWindowKnownForAccessPolicy(
- const ServerWindow* window) const = 0;
-
- // Returns true if Embed(window) has been invoked on |window|.
- virtual bool IsWindowRootOfAnotherTreeForAccessPolicy(
- const ServerWindow* window) const = 0;
-
- // Returns true if |window| was created by the window manager.
- virtual bool IsWindowCreatedByWindowManager(
- const ServerWindow* window) const = 0;
-
- // Returns true if the tree intercepts events targetted at |window|.
- virtual bool ShouldInterceptEventsForAccessPolicy(
- const ServerWindow* window) const = 0;
-
- protected:
- virtual ~AccessPolicyDelegate() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_ACCESS_POLICY_DELEGATE_H_
diff --git a/services/ui/ws/accessibility_manager.cc b/services/ui/ws/accessibility_manager.cc
deleted file mode 100644
index 02d8781..0000000
--- a/services/ui/ws/accessibility_manager.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/accessibility_manager.h"
-
-#include "services/ui/ws/window_server.h"
-
-namespace ui {
-namespace ws {
-
-AccessibilityManager::AccessibilityManager(WindowServer* window_server)
- : window_server_(window_server), binding_(this) {
- DCHECK(window_server_);
-}
-
-AccessibilityManager::~AccessibilityManager() {}
-
-void AccessibilityManager::Bind(mojom::AccessibilityManagerRequest request) {
- binding_.Close();
- binding_.Bind(std::move(request));
-}
-
-void AccessibilityManager::SetHighContrastMode(bool enabled) {
- window_server_->SetHighContrastMode(enabled);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/accessibility_manager.h b/services/ui/ws/accessibility_manager.h
deleted file mode 100644
index a4d65b3..0000000
--- a/services/ui/ws/accessibility_manager.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_ACCESSIBILITY_MANAGER_H_
-#define SERVICES_UI_WS_ACCESSIBILITY_MANAGER_H_
-
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/ui/public/interfaces/accessibility_manager.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class WindowServer;
-
-class AccessibilityManager : public mojom::AccessibilityManager {
- public:
- explicit AccessibilityManager(WindowServer* window_server);
- ~AccessibilityManager() override;
-
- void Bind(mojom::AccessibilityManagerRequest request);
-
- private:
- // mojom::AccessibilityManager:
- void SetHighContrastMode(bool enabled) override;
-
- WindowServer* window_server_;
- mojo::Binding<mojom::AccessibilityManager> binding_;
-
- DISALLOW_COPY_AND_ASSIGN(AccessibilityManager);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_ACCESSIBILITY_MANAGER_H_
diff --git a/services/ui/ws/async_event_dispatcher.h b/services/ui/ws/async_event_dispatcher.h
deleted file mode 100644
index a4d889e..0000000
--- a/services/ui/ws/async_event_dispatcher.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef SERVICES_UI_WS_ASYNC_EVENT_DISPATCHER_H_
-#define SERVICES_UI_WS_ASYNC_EVENT_DISPATCHER_H_
-
-#include <stdint.h>
-
-#include <string>
-
-#include "base/callback_forward.h"
-#include "base/containers/flat_map.h"
-
-namespace ui {
-class Event;
-}
-
-namespace ui {
-namespace mojom {
-enum class EventReslut;
-}
-namespace ws {
-
-class ServerWindow;
-
-struct EventLocation;
-
-// AsyncEventDispatchers dispatch events asynchronously. A callback is run once
-// the accelerator or event is dispatched. This class allows the event
-// dispatching code to be independent of WindowTree (for testing and
-// modularity).
-//
-// If an AsyncEventDispatcher does not run the callback in a reasonable amount
-// of time, Dispatch* may be called again.
-class AsyncEventDispatcher {
- public:
- using DispatchEventCallback = base::OnceCallback<void(mojom::EventResult)>;
- // Dispatches |event| to |target|, running |callback| with the result.
- // |event_location| is only useful for located events.
- virtual void DispatchEvent(ServerWindow* target,
- const Event& event,
- const EventLocation& event_location,
- DispatchEventCallback callback) = 0;
-
- // In addition to the result of the accelerator, AcceleratorCallback is
- // supplied arbitrary key-value pairs that are added to the event if
- // further processing is necessary (EventResult::UNHANDLED is supplied to the
- // callback). The intepretation of the key-value pairs is left to clients (see
- // ash/public/interfaces/event_properties.mojom for examples).
- using AcceleratorCallback = base::OnceCallback<void(
- mojom::EventResult,
- const base::flat_map<std::string, std::vector<uint8_t>>&)>;
-
- // Dispatches an accelerator that matches |event|, running the callback with
- // the result and key-value pairs. |accelerator_id| identifies the
- // accelerator.
- virtual void DispatchAccelerator(uint32_t accelerator_id,
- const Event& event,
- AcceleratorCallback callback) = 0;
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_ASYNC_EVENT_DISPATCHER_H_
diff --git a/services/ui/ws/async_event_dispatcher_lookup.h b/services/ui/ws/async_event_dispatcher_lookup.h
deleted file mode 100644
index e4ee1eab..0000000
--- a/services/ui/ws/async_event_dispatcher_lookup.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef SERVICES_UI_WS_ASYNC_EVENT_DISPATCHER_LOOKUP_H_
-#define SERVICES_UI_WS_ASYNC_EVENT_DISPATCHER_LOOKUP_H_
-
-#include "services/ui/common/types.h"
-
-namespace ui {
-namespace ws {
-
-class AsyncEventDispatcher;
-
-// Looks up an AsyncEventDispatcher by id. This is used so that event processing
-// related code does not have a dependency on WindowTree or WindowService.
-class AsyncEventDispatcherLookup {
- public:
- virtual AsyncEventDispatcher* GetAsyncEventDispatcherById(
- ClientSpecificId id) = 0;
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_ASYNC_EVENT_DISPATCHER_LOOKUP_H_
diff --git a/services/ui/ws/compositor_frame_sink_client_binding.cc b/services/ui/ws/compositor_frame_sink_client_binding.cc
deleted file mode 100644
index 95626cfd..0000000
--- a/services/ui/ws/compositor_frame_sink_client_binding.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/compositor_frame_sink_client_binding.h"
-
-namespace ui {
-namespace ws {
-
-CompositorFrameSinkClientBinding::CompositorFrameSinkClientBinding(
- viz::mojom::CompositorFrameSinkClient* sink_client,
- viz::mojom::CompositorFrameSinkClientRequest sink_client_request,
- viz::mojom::CompositorFrameSinkAssociatedPtr compositor_frame_sink)
- : binding_(sink_client, std::move(sink_client_request)),
- compositor_frame_sink_(std::move(compositor_frame_sink)) {}
-
-CompositorFrameSinkClientBinding::~CompositorFrameSinkClientBinding() = default;
-
-void CompositorFrameSinkClientBinding::SetWantsAnimateOnlyBeginFrames() {
- compositor_frame_sink_->SetWantsAnimateOnlyBeginFrames();
-}
-
-void CompositorFrameSinkClientBinding::SetNeedsBeginFrame(
- bool needs_begin_frame) {
- compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frame);
-}
-
-void CompositorFrameSinkClientBinding::SubmitCompositorFrame(
- const viz::LocalSurfaceId& local_surface_id,
- viz::CompositorFrame frame,
- base::Optional<viz::HitTestRegionList> hit_test_region_list,
- uint64_t submit_time) {
- compositor_frame_sink_->SubmitCompositorFrame(
- local_surface_id, std::move(frame), std::move(hit_test_region_list),
- submit_time);
-}
-
-void CompositorFrameSinkClientBinding::SubmitCompositorFrameSync(
- const viz::LocalSurfaceId& local_surface_id,
- viz::CompositorFrame frame,
- base::Optional<viz::HitTestRegionList> hit_test_region_list,
- uint64_t submit_time,
- const SubmitCompositorFrameSyncCallback callback) {
- NOTIMPLEMENTED();
-}
-
-void CompositorFrameSinkClientBinding::DidNotProduceFrame(
- const viz::BeginFrameAck& ack) {
- compositor_frame_sink_->DidNotProduceFrame(ack);
-}
-
-void CompositorFrameSinkClientBinding::DidAllocateSharedBitmap(
- mojo::ScopedSharedBufferHandle buffer,
- const viz::SharedBitmapId& id) {
- compositor_frame_sink_->DidAllocateSharedBitmap(std::move(buffer), id);
-}
-
-void CompositorFrameSinkClientBinding::DidDeleteSharedBitmap(
- const viz::SharedBitmapId& id) {
- compositor_frame_sink_->DidDeleteSharedBitmap(id);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/compositor_frame_sink_client_binding.h b/services/ui/ws/compositor_frame_sink_client_binding.h
deleted file mode 100644
index c9f48485..0000000
--- a/services/ui/ws/compositor_frame_sink_client_binding.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_COMPOSITOR_FRAME_SINK_CLIENT_BINDING_H_
-#define SERVICES_UI_WS_COMPOSITOR_FRAME_SINK_CLIENT_BINDING_H_
-
-#include "base/macros.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/viz/privileged/interfaces/compositing/frame_sink_manager.mojom.h"
-#include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom.h"
-
-namespace ui {
-namespace ws {
-
-// CompositorFrameSinkClientBinding manages the binding between a FrameGenerator
-// and its CompositorFrameSink. CompositorFrameSinkClientBinding exists so
-// that a mock implementation of CompositorFrameSink can be injected for
-// tests. FrameGenerator owns its associated CompositorFrameSinkClientBinding.
-class CompositorFrameSinkClientBinding
- : public viz::mojom::CompositorFrameSink {
- public:
- CompositorFrameSinkClientBinding(
- viz::mojom::CompositorFrameSinkClient* sink_client,
- viz::mojom::CompositorFrameSinkClientRequest sink_client_request,
- viz::mojom::CompositorFrameSinkAssociatedPtr compositor_frame_sink);
- ~CompositorFrameSinkClientBinding() override;
-
- private:
- // viz::mojom::CompositorFrameSink implementation:
- void SubmitCompositorFrame(
- const viz::LocalSurfaceId& local_surface_id,
- viz::CompositorFrame frame,
- base::Optional<viz::HitTestRegionList> hit_test_region_list,
- uint64_t submit_time) override;
- void SubmitCompositorFrameSync(
- const viz::LocalSurfaceId& local_surface_id,
- viz::CompositorFrame frame,
- base::Optional<viz::HitTestRegionList> hit_test_region_list,
- uint64_t submit_time,
- const SubmitCompositorFrameSyncCallback callback) override;
- void SetNeedsBeginFrame(bool needs_begin_frame) override;
- void SetWantsAnimateOnlyBeginFrames() override;
- void DidNotProduceFrame(const viz::BeginFrameAck& ack) override;
- void DidAllocateSharedBitmap(mojo::ScopedSharedBufferHandle buffer,
- const viz::SharedBitmapId& id) override;
- void DidDeleteSharedBitmap(const viz::SharedBitmapId& id) override;
-
- mojo::Binding<viz::mojom::CompositorFrameSinkClient> binding_;
- viz::mojom::CompositorFrameSinkAssociatedPtr compositor_frame_sink_;
-
- DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkClientBinding);
-};
-}
-}
-
-#endif // SERVICES_UI_WS_COMPOSITOR_FRAME_SINK_CLIENT_BINDING_H_
diff --git a/services/ui/ws/cursor_location_manager.cc b/services/ui/ws/cursor_location_manager.cc
deleted file mode 100644
index a958716..0000000
--- a/services/ui/ws/cursor_location_manager.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/cursor_location_manager.h"
-
-#include "ui/gfx/geometry/point.h"
-
-namespace ui {
-namespace ws {
-
-CursorLocationManager::CursorLocationManager() {}
-
-CursorLocationManager::~CursorLocationManager() {}
-
-void CursorLocationManager::OnMouseCursorLocationChanged(
- const gfx::Point& point_in_dip) {
- current_cursor_location_ = static_cast<base::subtle::Atomic32>(
- (point_in_dip.x() & 0xFFFF) << 16 | (point_in_dip.y() & 0xFFFF));
- if (cursor_location_memory()) {
- base::subtle::NoBarrier_Store(cursor_location_memory(),
- current_cursor_location_);
- }
-}
-
-mojo::ScopedSharedBufferHandle
-CursorLocationManager::GetCursorLocationMemory() {
- if (!cursor_location_handle_.is_valid()) {
- // Create our shared memory segment to share the cursor state with our
- // window clients.
- cursor_location_handle_ =
- mojo::SharedBufferHandle::Create(sizeof(base::subtle::Atomic32));
-
- if (!cursor_location_handle_.is_valid())
- return mojo::ScopedSharedBufferHandle();
-
- cursor_location_mapping_ =
- cursor_location_handle_->Map(sizeof(base::subtle::Atomic32));
- if (!cursor_location_mapping_)
- return mojo::ScopedSharedBufferHandle();
- base::subtle::NoBarrier_Store(cursor_location_memory(),
- current_cursor_location_);
- }
-
- return cursor_location_handle_->Clone(
- mojo::SharedBufferHandle::AccessMode::READ_ONLY);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/cursor_location_manager.h b/services/ui/ws/cursor_location_manager.h
deleted file mode 100644
index 348ee43..0000000
--- a/services/ui/ws/cursor_location_manager.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_
-#define SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_
-
-#include "base/atomicops.h"
-#include "base/macros.h"
-#include "mojo/public/cpp/system/buffer.h"
-
-namespace gfx {
-class Point;
-}
-
-namespace ui {
-namespace ws {
-namespace test {
-class CursorLocationManagerTestApi;
-}
-
-// Manages a shared memory buffer that stores the cursor location.
-class CursorLocationManager {
- public:
- CursorLocationManager();
- ~CursorLocationManager();
-
- // Sets the current cursor location to |point|. Atomically writes the location
- // to shared memory. |point| should be in screen-coord and DIP.
- void OnMouseCursorLocationChanged(const gfx::Point& point_in_dip);
-
- // Returns a read-only handle to the shared memory which contains the global
- // mouse cursor position. Each call returns a new handle.
- mojo::ScopedSharedBufferHandle GetCursorLocationMemory();
-
- private:
- friend test::CursorLocationManagerTestApi;
-
- base::subtle::Atomic32* cursor_location_memory() {
- return reinterpret_cast<base::subtle::Atomic32*>(
- cursor_location_mapping_.get());
- }
-
- // The current location of the cursor. This is always kept up to date so we
- // can atomically write this to |cursor_location_memory()| once it is created.
- base::subtle::Atomic32 current_cursor_location_ = 0;
-
- // A handle to a shared memory buffer that is one 32 bit integer long. We
- // share this with any client as the same user. This buffer is lazily
- // created on the first access.
- mojo::ScopedSharedBufferHandle cursor_location_handle_;
-
- // The one int32 in |cursor_location_handle_|. When we write to this
- // location, we must always write to it atomically. (On the other side of the
- // mojo connection, this data must be read atomically.)
- mojo::ScopedSharedBufferMapping cursor_location_mapping_;
-
- DISALLOW_COPY_AND_ASSIGN(CursorLocationManager);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_CURSOR_LOCATION_MANAGER_H_
diff --git a/services/ui/ws/cursor_location_manager_unittest.cc b/services/ui/ws/cursor_location_manager_unittest.cc
deleted file mode 100644
index 6548a40..0000000
--- a/services/ui/ws/cursor_location_manager_unittest.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/cursor_location_manager.h"
-
-#include "base/atomicops.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/geometry/point.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-
-TEST(CursorLocationManagerTest, PositiveCoordinates) {
- const gfx::Point point(100, 150);
-
- CursorLocationManager cursor_location_manager;
- cursor_location_manager.OnMouseCursorLocationChanged(point);
-
- base::subtle::Atomic32* cursor_location_memory = nullptr;
- mojo::ScopedSharedBufferHandle handle =
- cursor_location_manager.GetCursorLocationMemory();
- mojo::ScopedSharedBufferMapping cursor_location_mapping =
- handle->Map(sizeof(base::subtle::Atomic32));
- ASSERT_TRUE(cursor_location_mapping);
- cursor_location_memory =
- reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get());
-
- base::subtle::Atomic32 location =
- base::subtle::NoBarrier_Load(cursor_location_memory);
- EXPECT_EQ(point, Atomic32ToPoint(location));
-}
-
-TEST(CursorLocationManagerTest, NegativeCoordinates) {
- const gfx::Point point(-10, -11);
-
- CursorLocationManager cursor_location_manager;
- cursor_location_manager.OnMouseCursorLocationChanged(point);
-
- base::subtle::Atomic32* cursor_location_memory = nullptr;
- mojo::ScopedSharedBufferHandle handle =
- cursor_location_manager.GetCursorLocationMemory();
- mojo::ScopedSharedBufferMapping cursor_location_mapping =
- handle->Map(sizeof(base::subtle::Atomic32));
- ASSERT_TRUE(cursor_location_mapping);
- cursor_location_memory =
- reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get());
-
- base::subtle::Atomic32 location =
- base::subtle::NoBarrier_Load(cursor_location_memory);
- EXPECT_EQ(point, Atomic32ToPoint(location));
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/cursor_state.cc b/services/ui/ws/cursor_state.cc
deleted file mode 100644
index a921378..0000000
--- a/services/ui/ws/cursor_state.cc
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/cursor_state.h"
-
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_manager.h"
-#include "ui/base/cursor/cursor.h"
-
-namespace ui {
-namespace ws {
-
-class CursorState::StateSnapshot {
- public:
- StateSnapshot() = default;
- StateSnapshot(const StateSnapshot& rhs) = default;
- ~StateSnapshot() = default;
-
- const base::Optional<ui::CursorData>& global_override_cursor() const {
- return global_override_cursor_;
- }
- void SetGlobalOverrideCursor(const base::Optional<ui::CursorData>& cursor) {
- global_override_cursor_ = cursor;
- }
-
- const ui::CursorData& cursor_data() const { return cursor_data_; }
- void SetCursorData(const ui::CursorData& data) { cursor_data_ = data; }
-
- bool visible() const { return visible_; }
- void set_visible(bool visible) { visible_ = visible; }
-
- ui::CursorSize cursor_size() const { return cursor_size_; }
- void set_cursor_size(ui::CursorSize cursor_size) {
- cursor_size_ = cursor_size;
- }
-
- bool cursor_touch_visible() const { return cursor_touch_visible_; }
- void set_cursor_touch_visible(bool enabled) {
- cursor_touch_visible_ = enabled;
- }
-
- private:
- // An optional cursor set by the window manager which overrides per-window
- // requests.
- base::Optional<ui::CursorData> global_override_cursor_;
-
- // The last cursor set. Used to track whether we need to change the cursor.
- ui::CursorData cursor_data_ = ui::CursorData(ui::CursorType::kNull);
-
- // Which cursor set to use.
- ui::CursorSize cursor_size_ = CursorSize::kNormal;
-
- // Whether the cursor is visible.
- bool visible_ = true;
-
- // An extra visibility check separate from user control which shows/hides
- // based on whether the last event was a touch or a mouse event.
- bool cursor_touch_visible_ = true;
-};
-
-CursorState::CursorState(DisplayManager* display_manager,
- CursorStateDelegate* delegate)
- : display_manager_(display_manager),
- delegate_(delegate),
- current_state_(std::make_unique<StateSnapshot>()),
- state_on_unlock_(std::make_unique<StateSnapshot>()) {}
-
-CursorState::~CursorState() {}
-
-void CursorState::SetCurrentWindowCursor(const ui::CursorData& cursor) {
- if (!state_on_unlock_->cursor_data().IsSameAs(cursor))
- state_on_unlock_->SetCursorData(cursor);
-
- if (cursor_lock_count_ == 0 &&
- !current_state_->cursor_data().IsSameAs(cursor)) {
- current_state_->SetCursorData(cursor);
- SetPlatformCursor();
- }
-}
-
-void CursorState::LockCursor() {
- cursor_lock_count_++;
-}
-
-void CursorState::UnlockCursor() {
- cursor_lock_count_--;
- DCHECK_GE(cursor_lock_count_, 0);
- if (cursor_lock_count_ > 0)
- return;
-
- if (current_state_->cursor_touch_visible() !=
- state_on_unlock_->cursor_touch_visible()) {
- NotifyCursorTouchVisibleChanged(state_on_unlock_->cursor_touch_visible());
- }
-
- *current_state_ = *state_on_unlock_;
- SetPlatformCursorSize();
- SetPlatformCursor();
-}
-
-void CursorState::SetCursorVisible(bool visible) {
- state_on_unlock_->set_visible(visible);
- if (cursor_lock_count_ == 0 &&
- current_state_->visible() != state_on_unlock_->visible()) {
- current_state_->set_visible(visible);
- SetPlatformCursor();
- }
-}
-
-void CursorState::SetGlobalOverrideCursor(
- const base::Optional<ui::CursorData>& cursor) {
- state_on_unlock_->SetGlobalOverrideCursor(cursor);
- if (cursor_lock_count_ == 0) {
- current_state_->SetGlobalOverrideCursor(cursor);
- SetPlatformCursor();
- }
-}
-
-void CursorState::SetCursorSize(ui::CursorSize cursor_size) {
- state_on_unlock_->set_cursor_size(cursor_size);
- if (cursor_lock_count_ == 0 &&
- current_state_->cursor_size() != state_on_unlock_->cursor_size()) {
- current_state_->set_cursor_size(cursor_size);
- SetPlatformCursorSize();
- SetPlatformCursor();
- }
-}
-
-void CursorState::SetCursorTouchVisible(bool enabled) {
- state_on_unlock_->set_cursor_touch_visible(enabled);
- if (cursor_lock_count_ == 0 && current_state_->cursor_touch_visible() !=
- state_on_unlock_->cursor_touch_visible()) {
- current_state_->set_cursor_touch_visible(enabled);
- NotifyCursorTouchVisibleChanged(enabled);
- SetPlatformCursor();
- }
-}
-
-void CursorState::NotifyCursorTouchVisibleChanged(bool enabled) {
- delegate_->OnCursorTouchVisibleChanged(enabled);
-}
-
-void CursorState::SetPlatformCursorSize() {
- DisplayManager* manager = display_manager_;
- for (Display* display : manager->displays())
- display->SetNativeCursorSize(current_state_->cursor_size());
-}
-
-void CursorState::SetPlatformCursor() {
- DisplayManager* manager = display_manager_;
- auto set_on_all = [manager](const ui::CursorData& cursor) {
- for (Display* display : manager->displays())
- display->SetNativeCursor(cursor);
- };
-
- if (current_state_->visible() && current_state_->cursor_touch_visible()) {
- if (current_state_->global_override_cursor().has_value())
- set_on_all(current_state_->global_override_cursor().value());
- else
- set_on_all(current_state_->cursor_data());
- } else {
- set_on_all(ui::CursorData(ui::CursorType::kNone));
- }
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/cursor_state.h b/services/ui/ws/cursor_state.h
deleted file mode 100644
index 5db99e3..0000000
--- a/services/ui/ws/cursor_state.h
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_CURSOR_STATE_H_
-#define SERVICES_UI_WS_CURSOR_STATE_H_
-
-#include <memory>
-
-#include "base/optional.h"
-#include "services/ui/ws/cursor_state_delegate.h"
-#include "ui/base/cursor/cursor_data.h"
-
-namespace ui {
-
-enum class CursorSize;
-
-namespace ws {
-
-class DisplayManager;
-
-// Owns all the state about if and how the cursor is displayed in mus.
-class CursorState {
- public:
- CursorState(DisplayManager* display_manager, CursorStateDelegate* delegate);
- ~CursorState();
-
- // Sets the normal cursor which would be used if the window manager hasn't
- // set an override cursor.
- void SetCurrentWindowCursor(const ui::CursorData& cursor);
-
- // When the cursor is locked, changes to the cursor are queued up. Queued
- // changes are performed atomically when the cursor is unlocked.
- void LockCursor();
- void UnlockCursor();
-
- // Whether the cursor is visible on the display.
- void SetCursorVisible(bool visible);
-
- // Sets a cursor globally, which overrides the per-window cursors.
- void SetGlobalOverrideCursor(const base::Optional<ui::CursorData>& cursor);
-
- // Sets the cursor size.
- void SetCursorSize(ui::CursorSize cursor_size);
-
- // Sets whether the cursor is hidden because the user is interacting with the
- // touch screen.
- void SetCursorTouchVisible(bool enabled);
-
- private:
- // A snapshot of the cursor state at a specific time.
- class StateSnapshot;
-
- // Notifies the window manager when the value of mouse events enabled changes.
- void NotifyCursorTouchVisibleChanged(bool enabled);
-
- // Synchronizes cursor set data with all platform displays.
- void SetPlatformCursorSize();
-
- // Synchronizes the current cursor state with all the platform displays.
- void SetPlatformCursor();
-
- // Contains are the displays we notify on cursor changes.
- DisplayManager* display_manager_;
-
- // Receives messages when mouse events enabled changes.
- CursorStateDelegate* delegate_;
-
- // Number of times LockCursor() has been invoked without a corresponding
- // UnlockCursor().
- int cursor_lock_count_ = 0;
-
- // The current state of the cursor.
- std::unique_ptr<StateSnapshot> current_state_;
-
- // The cursor state to restore when the cursor is unlocked.
- std::unique_ptr<StateSnapshot> state_on_unlock_;
-
- DISALLOW_COPY_AND_ASSIGN(CursorState);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_CURSOR_STATE_H_
diff --git a/services/ui/ws/cursor_state_delegate.h b/services/ui/ws/cursor_state_delegate.h
deleted file mode 100644
index 2b70974..0000000
--- a/services/ui/ws/cursor_state_delegate.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_CURSOR_STATE_DELEGATE_H_
-#define SERVICES_UI_WS_CURSOR_STATE_DELEGATE_H_
-
-namespace ui {
-
-namespace ws {
-
-// Interface used for the CursorState object to message back to the window
-// manager.
-class CursorStateDelegate {
- public:
- virtual void OnCursorTouchVisibleChanged(bool enabled) = 0;
-
- protected:
- virtual ~CursorStateDelegate() {}
-};
-
-} // namespace ws
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_CURSOR_STATE_DELEGATE_H_
diff --git a/services/ui/ws/cursor_state_unittest.cc b/services/ui/ws/cursor_state_unittest.cc
deleted file mode 100644
index 3f8f076..0000000
--- a/services/ui/ws/cursor_state_unittest.cc
+++ /dev/null
@@ -1,173 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/cursor_state.h"
-
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/test_utils.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/cursor/cursor.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-
-class CursorStateTest : public testing::Test, public CursorStateDelegate {
- public:
- CursorStateTest() {}
- ~CursorStateTest() override {}
-
- WindowServer* window_server() { return ws_test_helper_.window_server(); }
- DisplayManager* display_manager() {
- return window_server()->display_manager();
- }
- TestScreenManager& screen_manager() { return screen_manager_; }
- const base::Optional<bool>& last_mouse_events_enabled_send() {
- return last_mouse_events_enabled_send_;
- }
- CursorState* cursor_state() { return cursor_state_.get(); }
- const ui::CursorData& cursor() { return ws_test_helper_.cursor(); }
-
- protected:
- // testing::Test:
- void SetUp() override {
- screen_manager_.Init(window_server()->display_manager());
- cursor_state_ = std::make_unique<CursorState>(display_manager(), this);
-
- AddWindowManager(window_server());
- screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
- ASSERT_EQ(1u, display_manager()->displays().size());
- }
-
- // CursorStateDelegate:
- void OnCursorTouchVisibleChanged(bool enabled) override {
- last_mouse_events_enabled_send_ = enabled;
- }
-
- private:
- WindowServerTestHelper ws_test_helper_;
- TestScreenManager screen_manager_;
-
- base::Optional<bool> last_mouse_events_enabled_send_;
-
- std::unique_ptr<CursorState> cursor_state_;
-
- DISALLOW_COPY_AND_ASSIGN(CursorStateTest);
-};
-
-TEST_F(CursorStateTest, CursorLockTest) {
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->LockCursor();
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kCell));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->UnlockCursor();
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
-
- EXPECT_FALSE(last_mouse_events_enabled_send().has_value());
-}
-
-TEST_F(CursorStateTest, CursorVisibilityTest) {
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->SetCursorVisible(false);
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
-
- cursor_state()->SetCursorVisible(true);
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->SetCursorVisible(false);
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kCell));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
-
- cursor_state()->SetCursorVisible(true);
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
-
- EXPECT_FALSE(last_mouse_events_enabled_send().has_value());
-}
-
-TEST_F(CursorStateTest, CursorOverrideTest) {
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->SetGlobalOverrideCursor(
- ui::CursorData(ui::CursorType::kCell));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kCell));
-
- cursor_state()->SetGlobalOverrideCursor(base::nullopt);
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- EXPECT_FALSE(last_mouse_events_enabled_send().has_value());
-}
-
-TEST_F(CursorStateTest, CursorOverrideLockTest) {
- // This test is meant to mimic the calls in ScreenshotController when it sets
- // a cursor.
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->SetGlobalOverrideCursor(
- ui::CursorData(ui::CursorType::kCross));
- cursor_state()->LockCursor();
- cursor_state()->SetGlobalOverrideCursor(base::nullopt);
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kCross));
-
- cursor_state()->UnlockCursor();
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- EXPECT_FALSE(last_mouse_events_enabled_send().has_value());
-}
-
-TEST_F(CursorStateTest, CursorOverrideVisibilityTest) {
- // This test is meant to mimic the calls in ScreenshotController when it
- // hides the cursor.
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->SetCursorVisible(false);
- cursor_state()->LockCursor();
- cursor_state()->SetGlobalOverrideCursor(base::nullopt);
- cursor_state()->SetCursorVisible(true);
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
-
- cursor_state()->UnlockCursor();
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- EXPECT_FALSE(last_mouse_events_enabled_send().has_value());
-}
-
-TEST_F(CursorStateTest, SetCursorTouchVisibleWhileUnlock) {
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->SetCursorTouchVisible(false);
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
- EXPECT_EQ(false, last_mouse_events_enabled_send());
-
- cursor_state()->SetCursorTouchVisible(true);
- EXPECT_EQ(true, last_mouse_events_enabled_send());
-}
-
-TEST_F(CursorStateTest, SetCursorTouchVisibleWhileLocked) {
- cursor_state()->SetCurrentWindowCursor(ui::CursorData(ui::CursorType::kWait));
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
-
- cursor_state()->LockCursor();
- cursor_state()->SetCursorTouchVisible(false);
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kWait));
- EXPECT_FALSE(last_mouse_events_enabled_send().has_value());
-
- cursor_state()->UnlockCursor();
- EXPECT_TRUE(cursor().IsType(ui::CursorType::kNone));
- EXPECT_EQ(false, last_mouse_events_enabled_send());
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/cursor_unittest.cc b/services/ui/ws/cursor_unittest.cc
deleted file mode 100644
index 010c1c74..0000000
--- a/services/ui/ws/cursor_unittest.cc
+++ /dev/null
@@ -1,190 +0,0 @@
-// Copyright 2016 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 <stdint.h>
-
-#include <string>
-
-#include "base/macros.h"
-#include "services/ui/common/types.h"
-#include "services/ui/common/util.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/platform_display_factory.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_utils.h"
-#include "services/ui/ws/window_manager_display_root.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/events/event.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-
-class CursorTest : public testing::Test {
- public:
- CursorTest() {}
- ~CursorTest() override {}
-
- WindowServer* window_server() { return ws_test_helper_.window_server(); }
- TestWindowServerDelegate* window_server_delegate() {
- return ws_test_helper_.window_server_delegate();
- }
- ui::CursorType cursor_type() const {
- return ws_test_helper_.cursor().cursor_type();
- }
-
- protected:
- // testing::Test:
- void SetUp() override {
- screen_manager_.Init(window_server()->display_manager());
- screen_manager_.AddDisplay();
- AddWindowManager(window_server());
- }
-
- ServerWindow* GetRoot() {
- DisplayManager* display_manager = window_server()->display_manager();
- Display* display = *display_manager->displays().begin();
- return display->window_manager_display_root()->GetClientVisibleRoot();
- }
-
- // Create a 30x30 window where the outer 10 pixels is non-client.
- ServerWindow* BuildServerWindow() {
- DisplayManager* display_manager = window_server()->display_manager();
- Display* display = *display_manager->displays().begin();
- WindowManagerDisplayRoot* active_display_root =
- display->window_manager_display_root();
- WindowTree* tree =
- active_display_root->window_manager_state()->window_tree();
- ClientWindowId child_window_id;
- if (!NewWindowInTree(tree, &child_window_id))
- return nullptr;
-
- ServerWindow* w = tree->GetWindowByClientId(child_window_id);
- w->SetBounds(gfx::Rect(10, 10, 30, 30));
- w->SetClientArea(gfx::Insets(10, 10), std::vector<gfx::Rect>());
- w->SetVisible(true);
-
- return w;
- }
-
- void MoveCursorTo(const gfx::Point& p) {
- DisplayManager* display_manager = window_server()->display_manager();
- ASSERT_EQ(1u, display_manager->displays().size());
- Display* display = *display_manager->displays().begin();
- WindowManagerDisplayRoot* active_display_root =
- display->window_manager_display_root();
- ASSERT_TRUE(active_display_root);
- PointerEvent event(
- MouseEvent(ET_MOUSE_MOVED, p, p, base::TimeTicks(), 0, 0));
- ignore_result(static_cast<PlatformDisplayDelegate*>(display)
- ->GetEventSink()
- ->OnEventFromSource(&event));
- WindowManagerState* wms = active_display_root->window_manager_state();
- ASSERT_TRUE(WindowManagerStateTestApi(wms).AckInFlightEvent(
- mojom::EventResult::HANDLED));
- }
-
- private:
- WindowServerTestHelper ws_test_helper_;
- TestScreenManager screen_manager_;
- DISALLOW_COPY_AND_ASSIGN(CursorTest);
-};
-
-TEST_F(CursorTest, ChangeByMouseMove) {
- ServerWindow* win = BuildServerWindow();
- win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- win->parent()->SetCursor(ui::CursorData(ui::CursorType::kCell));
- EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
- win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
- EXPECT_EQ(ui::CursorType::kEastResize,
- win->non_client_cursor().cursor_type());
-
- // Non client area
- MoveCursorTo(gfx::Point(15, 15));
- EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
-
- // Client area, which comes from win->parent().
- MoveCursorTo(gfx::Point(25, 25));
- EXPECT_EQ(ui::CursorType::kCell, cursor_type());
-}
-
-TEST_F(CursorTest, ChangeByClientAreaChange) {
- ServerWindow* win = BuildServerWindow();
- win->parent()->SetCursor(ui::CursorData(ui::CursorType::kCross));
- win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
- win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
- EXPECT_EQ(ui::CursorType::kEastResize,
- win->non_client_cursor().cursor_type());
-
- // Non client area before we move.
- MoveCursorTo(gfx::Point(15, 15));
- EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
-
- // Changing the client area should cause a change. The cursor for the client
- // area comes from root ancestor, which is win->parent().
- win->SetClientArea(gfx::Insets(1, 1), std::vector<gfx::Rect>());
- EXPECT_EQ(ui::CursorType::kCross, cursor_type());
-}
-
-TEST_F(CursorTest, NonClientCursorChange) {
- ServerWindow* win = BuildServerWindow();
- win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
- win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
- EXPECT_EQ(ui::CursorType::kEastResize,
- win->non_client_cursor().cursor_type());
-
- MoveCursorTo(gfx::Point(15, 15));
- EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
-
- win->SetNonClientCursor(ui::CursorData(ui::CursorType::kWestResize));
- EXPECT_EQ(ui::CursorType::kWestResize, cursor_type());
-}
-
-TEST_F(CursorTest, IgnoreClientCursorChangeInNonClientArea) {
- ServerWindow* win = BuildServerWindow();
- win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
- win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
- EXPECT_EQ(ui::CursorType::kEastResize,
- win->non_client_cursor().cursor_type());
-
- MoveCursorTo(gfx::Point(15, 15));
- EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
-
- win->SetCursor(ui::CursorData(ui::CursorType::kHelp));
- EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
-}
-
-TEST_F(CursorTest, NonClientToClientByBoundsChange) {
- ServerWindow* win = BuildServerWindow();
- win->parent()->SetCursor(ui::CursorData(ui::CursorType::kCopy));
- win->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- EXPECT_EQ(ui::CursorType::kIBeam, win->cursor().cursor_type());
- win->SetNonClientCursor(ui::CursorData(ui::CursorType::kEastResize));
- EXPECT_EQ(ui::CursorType::kEastResize,
- win->non_client_cursor().cursor_type());
-
- // Non client area before we move.
- MoveCursorTo(gfx::Point(15, 15));
- EXPECT_EQ(ui::CursorType::kEastResize, cursor_type());
-
- win->SetBounds(gfx::Rect(0, 0, 30, 30));
- EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/debug_utils.cc b/services/ui/ws/debug_utils.cc
deleted file mode 100644
index a617aaf..0000000
--- a/services/ui/ws/debug_utils.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/debug_utils.h"
-
-#include "services/ui/ws/server_window.h"
-
-namespace ui {
-namespace ws {
-
-std::string DebugWindowId(const ServerWindow* window) {
- return window ? window->frame_sink_id().ToString() : "null";
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/debug_utils.h b/services/ui/ws/debug_utils.h
deleted file mode 100644
index dbac1c6..0000000
--- a/services/ui/ws/debug_utils.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_DEBUG_UTILS_H_
-#define SERVICES_UI_WS_DEBUG_UTILS_H_
-
-#include <string>
-
-namespace ui {
-namespace ws {
-
-class ServerWindow;
-
-// Returns a debug string for |window|, returns "null" if |window| is null.
-std::string DebugWindowId(const ServerWindow* window);
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DEBUG_UTILS_H_
diff --git a/services/ui/ws/default_access_policy.cc b/services/ui/ws/default_access_policy.cc
deleted file mode 100644
index 9d0c7a9..0000000
--- a/services/ui/ws/default_access_policy.cc
+++ /dev/null
@@ -1,281 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/default_access_policy.h"
-
-#include "services/ui/ws/access_policy_delegate.h"
-#include "services/ui/ws/server_window.h"
-
-namespace ui {
-namespace ws {
-
-DefaultAccessPolicy::DefaultAccessPolicy() {}
-
-DefaultAccessPolicy::~DefaultAccessPolicy() {}
-
-void DefaultAccessPolicy::Init(ClientSpecificId client_id,
- AccessPolicyDelegate* delegate) {
- client_id_ = client_id;
- delegate_ = delegate;
-}
-
-bool DefaultAccessPolicy::CanRemoveWindowFromParent(
- const ServerWindow* window) const {
- if (!WasCreatedByThisClient(window))
- return false; // Can only unparent windows we created.
-
- return delegate_->HasRootForAccessPolicy(window->parent()) ||
- WasCreatedByThisClient(window->parent());
-}
-
-bool DefaultAccessPolicy::CanAddWindow(const ServerWindow* parent,
- const ServerWindow* child) const {
- return WasCreatedByThisClient(child) &&
- (delegate_->HasRootForAccessPolicy(parent) ||
- (WasCreatedByThisClient(parent) &&
- !delegate_->IsWindowRootOfAnotherTreeForAccessPolicy(parent)));
-}
-
-bool DefaultAccessPolicy::CanAddTransientWindow(
- const ServerWindow* parent,
- const ServerWindow* child) const {
- return (delegate_->HasRootForAccessPolicy(child) ||
- WasCreatedByThisClient(child)) &&
- (delegate_->HasRootForAccessPolicy(parent) ||
- WasCreatedByThisClient(parent));
-}
-
-bool DefaultAccessPolicy::CanRemoveTransientWindowFromParent(
- const ServerWindow* window) const {
- return (delegate_->HasRootForAccessPolicy(window) ||
- WasCreatedByThisClient(window)) &&
- (delegate_->HasRootForAccessPolicy(window->transient_parent()) ||
- WasCreatedByThisClient(window->transient_parent()));
-}
-
-bool DefaultAccessPolicy::CanSetModal(const ServerWindow* window) const {
- return delegate_->HasRootForAccessPolicy(window) ||
- WasCreatedByThisClient(window);
-}
-
-bool DefaultAccessPolicy::CanSetChildModalParent(
- const ServerWindow* window,
- const ServerWindow* modal_parent) const {
- return (delegate_->HasRootForAccessPolicy(window) ||
- WasCreatedByThisClient(window)) &&
- (!modal_parent || delegate_->HasRootForAccessPolicy(modal_parent) ||
- WasCreatedByThisClient(modal_parent));
-}
-
-bool DefaultAccessPolicy::CanReorderWindow(
- const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction) const {
- return WasCreatedByThisClient(window) &&
- WasCreatedByThisClient(relative_window);
-}
-
-bool DefaultAccessPolicy::CanDeleteWindow(const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool DefaultAccessPolicy::CanGetWindowTree(const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window) ||
- delegate_->ShouldInterceptEventsForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanDescendIntoWindowForWindowTree(
- const ServerWindow* window) const {
- return (WasCreatedByThisClient(window) &&
- !delegate_->IsWindowRootOfAnotherTreeForAccessPolicy(window)) ||
- delegate_->HasRootForAccessPolicy(window) ||
- delegate_->ShouldInterceptEventsForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanEmbed(const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool DefaultAccessPolicy::CanChangeWindowVisibility(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanChangeWindowOpacity(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetWindowCompositorFrameSink(
- const ServerWindow* window) const {
- // Once a window embeds another app, the embedder app is no longer able to
- // call SetWindowSurfaceId() - this ability is transferred to the embedded
- // app.
- if (delegate_->IsWindowRootOfAnotherTreeForAccessPolicy(window))
- return false;
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetWindowBounds(const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool DefaultAccessPolicy::CanSetWindowTransform(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool DefaultAccessPolicy::CanSetWindowProperties(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool DefaultAccessPolicy::CanSetWindowTextInputState(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetCapture(const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetFocus(const ServerWindow* window) const {
- return !window || WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetClientArea(const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetHitTestMask(const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetAcceptDrops(const ServerWindow* window) const {
- return (WasCreatedByThisClient(window) &&
- !delegate_->IsWindowRootOfAnotherTreeForAccessPolicy(window)) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetEventTargetingPolicy(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanStackAbove(const ServerWindow* above,
- const ServerWindow* below) const {
- return delegate_->HasRootForAccessPolicy(above) &&
- delegate_->IsWindowCreatedByWindowManager(above) &&
- delegate_->HasRootForAccessPolicy(below) &&
- delegate_->IsWindowCreatedByWindowManager(below);
-}
-
-bool DefaultAccessPolicy::CanStackAtTop(const ServerWindow* window) const {
- return delegate_->HasRootForAccessPolicy(window) &&
- delegate_->IsWindowCreatedByWindowManager(window);
-}
-
-bool DefaultAccessPolicy::CanPerformWmAction(const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanSetCursorProperties(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanInitiateDragLoop(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::CanInitiateMoveLoop(
- const ServerWindow* window) const {
- return delegate_->HasRootForAccessPolicy(window);
-}
-
-bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange(
- const ServerWindow* window,
- const ServerWindow** new_parent,
- const ServerWindow** old_parent) const {
- if (!WasCreatedByThisClient(window)) {
- // The window may have been exposed to the client because of
- // ShouldInterceptEventsForAccessPolicy(). Notify the parent in this case,
- // but the |old_parent| and/or |new_parent| may need to be updated.
- if (delegate_->IsWindowKnownForAccessPolicy(window)) {
- if (*old_parent && !delegate_->IsWindowKnownForAccessPolicy(*old_parent))
- *old_parent = nullptr;
- if (*new_parent &&
- (!delegate_->IsWindowKnownForAccessPolicy(*new_parent) &&
- delegate_->ShouldInterceptEventsForAccessPolicy(*new_parent))) {
- *new_parent = nullptr;
- }
- return true;
- }
-
- // Let the client know about |window| if the client intercepts events for
- // |new_parent|.
- if (*new_parent &&
- delegate_->ShouldInterceptEventsForAccessPolicy(*new_parent)) {
- if (*old_parent &&
- !delegate_->ShouldInterceptEventsForAccessPolicy(*old_parent)) {
- *old_parent = nullptr;
- }
- return true;
- }
- return false;
- }
-
- if (*new_parent && !WasCreatedByThisClient(*new_parent) &&
- !delegate_->HasRootForAccessPolicy((*new_parent))) {
- *new_parent = nullptr;
- }
-
- if (*old_parent && !WasCreatedByThisClient(*old_parent) &&
- !delegate_->HasRootForAccessPolicy((*old_parent))) {
- *old_parent = nullptr;
- }
- return true;
-}
-
-const ServerWindow* DefaultAccessPolicy::GetWindowForFocusChange(
- const ServerWindow* focused) {
- if (WasCreatedByThisClient(focused) ||
- delegate_->HasRootForAccessPolicy(focused))
- return focused;
- return nullptr;
-}
-
-bool DefaultAccessPolicy::CanSetWindowManager() const {
- return false;
-}
-
-bool DefaultAccessPolicy::WasCreatedByThisClient(
- const ServerWindow* window) const {
- return window->owning_tree_id() == client_id_;
-}
-
-bool DefaultAccessPolicy::IsValidIdForNewWindow(
- const ClientWindowId& id) const {
- // Clients using DefaultAccessPolicy only see windows they have created (for
- // the embed point they choose the id), which should have the same client_id
- // as the client_id_ since we should have already filled in the real one.
- return base::checked_cast<ClientSpecificId>(id.client_id()) == client_id_;
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/default_access_policy.h b/services/ui/ws/default_access_policy.h
deleted file mode 100644
index 9a8a974..0000000
--- a/services/ui/ws/default_access_policy.h
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_DEFAULT_ACCESS_POLICY_H_
-#define SERVICES_UI_WS_DEFAULT_ACCESS_POLICY_H_
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "services/ui/ws/access_policy.h"
-
-namespace ui {
-namespace ws {
-
-class AccessPolicyDelegate;
-
-// AccessPolicy for all clients, except the window manager.
-class DefaultAccessPolicy : public AccessPolicy {
- public:
- DefaultAccessPolicy();
- ~DefaultAccessPolicy() override;
-
- // AccessPolicy:
- void Init(ClientSpecificId client_id,
- AccessPolicyDelegate* delegate) override;
- bool CanRemoveWindowFromParent(const ServerWindow* window) const override;
- bool CanAddWindow(const ServerWindow* parent,
- const ServerWindow* child) const override;
- bool CanAddTransientWindow(const ServerWindow* parent,
- const ServerWindow* child) const override;
- bool CanRemoveTransientWindowFromParent(
- const ServerWindow* window) const override;
- bool CanSetModal(const ServerWindow* window) const override;
- bool CanSetChildModalParent(const ServerWindow* window,
- const ServerWindow* modal_parent) const override;
- bool CanReorderWindow(const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction) const override;
- bool CanDeleteWindow(const ServerWindow* window) const override;
- bool CanGetWindowTree(const ServerWindow* window) const override;
- bool CanDescendIntoWindowForWindowTree(
- const ServerWindow* window) const override;
- bool CanEmbed(const ServerWindow* window) const override;
- bool CanChangeWindowVisibility(const ServerWindow* window) const override;
- bool CanChangeWindowOpacity(const ServerWindow* window) const override;
- bool CanSetWindowCompositorFrameSink(
- const ServerWindow* window) const override;
- bool CanSetWindowBounds(const ServerWindow* window) const override;
- bool CanSetWindowTransform(const ServerWindow* window) const override;
- bool CanSetWindowProperties(const ServerWindow* window) const override;
- bool CanSetWindowTextInputState(const ServerWindow* window) const override;
- bool CanSetCapture(const ServerWindow* window) const override;
- bool CanSetFocus(const ServerWindow* window) const override;
- bool CanSetClientArea(const ServerWindow* window) const override;
- bool CanSetHitTestMask(const ServerWindow* window) const override;
- bool CanSetAcceptDrops(const ServerWindow* window) const override;
- bool CanSetEventTargetingPolicy(const ServerWindow* window) const override;
- bool CanStackAbove(const ServerWindow* above,
- const ServerWindow* below) const override;
- bool CanStackAtTop(const ServerWindow* window) const override;
- bool CanPerformWmAction(const ServerWindow* window) const override;
- bool CanSetCursorProperties(const ServerWindow* window) const override;
- bool CanInitiateDragLoop(const ServerWindow* window) const override;
- bool CanInitiateMoveLoop(const ServerWindow* window) const override;
- bool ShouldNotifyOnHierarchyChange(
- const ServerWindow* window,
- const ServerWindow** new_parent,
- const ServerWindow** old_parent) const override;
- const ServerWindow* GetWindowForFocusChange(
- const ServerWindow* focused) override;
- bool CanSetWindowManager() const override;
- bool IsValidIdForNewWindow(const ClientWindowId& id) const override;
-
- private:
- bool WasCreatedByThisClient(const ServerWindow* window) const;
-
- ClientSpecificId client_id_ = 0u;
- AccessPolicyDelegate* delegate_ = nullptr;
-
- DISALLOW_COPY_AND_ASSIGN(DefaultAccessPolicy);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DEFAULT_ACCESS_POLICY_H_
diff --git a/services/ui/ws/display.cc b/services/ui/ws/display.cc
deleted file mode 100644
index ae0f8df..0000000
--- a/services/ui/ws/display.cc
+++ /dev/null
@@ -1,383 +0,0 @@
-// 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 "services/ui/ws/display.h"
-
-#include <set>
-#include <utility>
-#include <vector>
-
-#include "base/strings/utf_string_conversions.h"
-#include "services/service_manager/public/mojom/connector.mojom.h"
-#include "services/ui/common/types.h"
-#include "services/ui/display/viewport_metrics.h"
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "services/ui/ws/debug_utils.h"
-#include "services/ui/ws/display_binding.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/focus_controller.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/user_activity_monitor.h"
-#include "services/ui/ws/window_manager_display_root.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_manager_window_tree_factory.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/display/screen.h"
-
-namespace ui {
-namespace ws {
-
-Display::Display(WindowServer* window_server) : window_server_(window_server) {
- window_server_->window_manager_window_tree_factory()->AddObserver(this);
-}
-
-Display::~Display() {
- window_server_->window_manager_window_tree_factory()->RemoveObserver(this);
-
- if (focus_controller_) {
- focus_controller_->RemoveObserver(this);
- focus_controller_.reset();
- }
-
- if (!binding_) {
- if (window_manager_display_root_) {
- window_manager_display_root_->window_manager_state()->OnDisplayDestroying(
- this);
- }
- } else if (window_manager_display_root_) {
- // If there is a |binding_| then the tree was created specifically for this
- // display (which corresponds to a WindowTreeHost).
- window_server_->DestroyTree(
- window_manager_display_root_->window_manager_state()->window_tree());
- }
-}
-
-void Display::Init(const display::ViewportMetrics& metrics,
- std::unique_ptr<DisplayBinding> binding) {
- binding_ = std::move(binding);
- display_manager()->AddDisplay(this);
-
- CreateRootWindow(metrics.bounds_in_pixels.size());
-
- platform_display_ = PlatformDisplay::Create(
- root_.get(), metrics, window_server_->GetThreadedImageCursorsFactory());
- platform_display_->Init(this);
- UpdateCursorConfig();
-}
-
-void Display::InitWindowManagerDisplayRoots() {
- if (binding_) {
- std::unique_ptr<WindowManagerDisplayRoot> display_root_ptr(
- new WindowManagerDisplayRoot(this));
- window_manager_display_root_ = display_root_ptr.get();
- WindowManagerDisplayRoot* display_root = display_root_ptr.get();
- WindowTree* window_tree = binding_->CreateWindowTree(display_root->root());
- display_root->window_manager_state_ = window_tree->window_manager_state();
- window_tree->window_manager_state()->AddWindowManagerDisplayRoot(
- std::move(display_root_ptr));
- } else {
- CreateWindowManagerDisplayRootFromFactory();
- }
- display_manager()->OnDisplayUpdated(display_);
-}
-
-int64_t Display::GetId() const {
- // TODO(tonikitoo): Implement a different ID for external window mode.
- return display_.id();
-}
-
-void Display::SetDisplay(const display::Display& display) {
- display_ = display;
-
- UpdateCursorConfig();
-}
-
-const display::Display& Display::GetDisplay() {
- return display_;
-}
-
-const display::ViewportMetrics& Display::GetViewportMetrics() const {
- return platform_display_->GetViewportMetrics();
-}
-
-DisplayManager* Display::display_manager() {
- return window_server_->display_manager();
-}
-
-const DisplayManager* Display::display_manager() const {
- return window_server_->display_manager();
-}
-
-gfx::Size Display::GetSize() const {
- DCHECK(root_);
- return root_->bounds().size();
-}
-
-WindowManagerDisplayRoot* Display::GetWindowManagerDisplayRootWithRoot(
- const ServerWindow* window) {
- return (window_manager_display_root_ &&
- window_manager_display_root_->root() == window)
- ? window_manager_display_root_
- : nullptr;
-}
-
-bool Display::SetFocusedWindow(ServerWindow* new_focused_window) {
- DVLOG(3) << "Display::SetFocusedWindow id="
- << DebugWindowId(new_focused_window);
- ServerWindow* old_focused_window = focus_controller_->GetFocusedWindow();
- if (old_focused_window == new_focused_window)
- return true;
- DCHECK(!new_focused_window || root_->Contains(new_focused_window));
- return focus_controller_->SetFocusedWindow(new_focused_window);
-}
-
-ServerWindow* Display::GetFocusedWindow() {
- return focus_controller_->GetFocusedWindow();
-}
-
-void Display::UpdateTextInputState(ServerWindow* window,
- const ui::TextInputState& state) {
- // Do not need to update text input for unfocused windows.
- if (!platform_display_ || focus_controller_->GetFocusedWindow() != window)
- return;
- platform_display_->UpdateTextInputState(state);
-}
-
-void Display::SetImeVisibility(ServerWindow* window, bool visible) {
- // Do not need to show or hide IME for unfocused window.
- if (focus_controller_->GetFocusedWindow() != window)
- return;
- platform_display_->SetImeVisibility(visible);
-}
-
-void Display::OnWillDestroyTree(WindowTree* tree) {
- if (window_manager_display_root_ &&
- window_manager_display_root_->window_manager_state()->window_tree() ==
- tree) {
- window_manager_display_root_ = nullptr;
- }
-}
-
-void Display::RemoveWindowManagerDisplayRoot(
- WindowManagerDisplayRoot* display_root) {
- DCHECK_EQ(window_manager_display_root_, display_root);
- window_manager_display_root_ = nullptr;
- display_manager()->DestroyDisplay(this);
-}
-
-void Display::SetNativeCursor(const ui::CursorData& cursor) {
- platform_display_->SetCursor(cursor);
-}
-
-void Display::SetNativeCursorSize(ui::CursorSize cursor_size) {
- platform_display_->SetCursorSize(cursor_size);
-}
-
-void Display::SetSize(const gfx::Size& size) {
- platform_display_->SetViewportSize(size);
-}
-
-void Display::SetTitle(const std::string& title) {
- platform_display_->SetTitle(base::UTF8ToUTF16(title));
-}
-
-void Display::CreateWindowManagerDisplayRootFromFactory() {
- WindowManagerWindowTreeFactory* factory =
- window_server_->window_manager_window_tree_factory();
- if (!factory->window_tree())
- return;
-
- std::unique_ptr<WindowManagerDisplayRoot> display_root_ptr =
- std::make_unique<WindowManagerDisplayRoot>(this);
- window_manager_display_root_ = display_root_ptr.get();
- WindowManagerState* window_manager_state =
- factory->window_tree()->window_manager_state();
- window_manager_display_root_->window_manager_state_ = window_manager_state;
- window_manager_display_root_->root()->SetVisible(true);
- window_manager_state->window_tree()->AddRootForWindowManager(
- window_manager_display_root_->root());
- window_manager_state->AddWindowManagerDisplayRoot(
- std::move(display_root_ptr));
-}
-
-void Display::CreateRootWindow(const gfx::Size& size) {
- DCHECK(!root_);
-
- const ClientWindowId client_window_id =
- display_manager()->GetAndAdvanceNextRootId();
- root_.reset(window_server_->CreateServerWindow(client_window_id,
- ServerWindow::Properties()));
- root_->set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- root_->SetBounds(gfx::Rect(size), allocator_.GenerateId());
- root_->SetVisible(true);
- focus_controller_ = std::make_unique<FocusController>(root_.get());
- focus_controller_->AddObserver(this);
-}
-
-void Display::UpdateCursorConfig() {
- float scale = display_.device_scale_factor();
-
- if (!display_manager()->IsInternalDisplay(display_))
- scale *= ui::mojom::kCursorMultiplierForExternalDisplays;
-
- if (platform_display_)
- platform_display_->SetCursorConfig(display_.rotation(), scale);
-}
-
-ServerWindow* Display::GetRootWindow() {
- return root_.get();
-}
-
-EventSink* Display::GetEventSink() {
- return this;
-}
-
-void Display::OnAcceleratedWidgetAvailable() {
- display_manager()->OnDisplayAcceleratedWidgetAvailable(this);
- InitWindowManagerDisplayRoots();
-}
-
-void Display::OnNativeCaptureLost() {
- if (window_manager_display_root_) {
- window_manager_display_root_->window_manager_state()->SetCapture(
- nullptr, kInvalidClientId);
- }
-}
-
-bool Display::IsHostingViz() const {
- return window_server_->is_hosting_viz();
-}
-
-void Display::OnViewportMetricsChanged(
- const display::ViewportMetrics& metrics) {
- platform_display_->UpdateViewportMetrics(metrics);
-
- SetBoundsInPixels(metrics.bounds_in_pixels);
-}
-
-void Display::SetBoundsInPixels(const gfx::Rect& bounds_in_pixels) {
- if (root_->bounds().size() == bounds_in_pixels.size())
- return;
-
- gfx::Rect new_bounds(bounds_in_pixels.size());
- root_->SetBounds(new_bounds, allocator_.GenerateId());
- if (window_manager_display_root_) {
- window_manager_display_root_->root()->SetBounds(new_bounds,
- allocator_.GenerateId());
- }
-}
-
-ServerWindow* Display::GetActiveRootWindow() {
- if (window_manager_display_root_)
- return window_manager_display_root_->root();
- return nullptr;
-}
-
-void Display::ProcessEvent(ui::Event* event,
- base::OnceClosure event_processed_callback) {
- if (window_manager_display_root_) {
- WindowManagerState* wm_state =
- window_manager_display_root_->window_manager_state();
- wm_state->ProcessEvent(event, GetId());
- if (event_processed_callback) {
- wm_state->ScheduleCallbackWhenDoneProcessingEvents(
- std::move(event_processed_callback));
- }
- } else if (event_processed_callback) {
- std::move(event_processed_callback).Run();
- }
-
- window_server_->user_activity_monitor()->OnUserActivity();
-}
-
-void Display::OnActivationChanged(ServerWindow* old_active_window,
- ServerWindow* new_active_window) {
- // Don't do anything here. We assume the window manager handles restacking. If
- // we did attempt to restack then we would be reordering windows owned by
- // the window-manager, which breaks the assumption that only the owner of a
- // window reorders the children.
-}
-
-void Display::OnFocusChanged(FocusControllerChangeSource change_source,
- ServerWindow* old_focused_window,
- ServerWindow* new_focused_window) {
- // TODO(sky): focus is global, not per windowtreehost. Move.
-
- // There are up to four clients that need to be notified:
- // . the client containing |old_focused_window|.
- // . the client with |old_focused_window| as its root.
- // . the client containing |new_focused_window|.
- // . the client with |new_focused_window| as its root.
- // Some of these client may be the same. The following takes care to notify
- // each only once.
- WindowTree* owning_tree_old = nullptr;
- WindowTree* embedded_tree_old = nullptr;
-
- if (old_focused_window) {
- owning_tree_old =
- window_server_->GetTreeWithId(old_focused_window->owning_tree_id());
- if (owning_tree_old) {
- owning_tree_old->ProcessFocusChanged(old_focused_window,
- new_focused_window);
- }
- embedded_tree_old = window_server_->GetTreeWithRoot(old_focused_window);
- if (embedded_tree_old) {
- DCHECK_NE(owning_tree_old, embedded_tree_old);
- embedded_tree_old->ProcessFocusChanged(old_focused_window,
- new_focused_window);
- }
- }
- WindowTree* owning_tree_new = nullptr;
- WindowTree* embedded_tree_new = nullptr;
- if (new_focused_window) {
- owning_tree_new =
- window_server_->GetTreeWithId(new_focused_window->owning_tree_id());
- if (owning_tree_new && owning_tree_new != owning_tree_old &&
- owning_tree_new != embedded_tree_old) {
- owning_tree_new->ProcessFocusChanged(old_focused_window,
- new_focused_window);
- }
- embedded_tree_new = window_server_->GetTreeWithRoot(new_focused_window);
- if (embedded_tree_new && embedded_tree_new != owning_tree_old &&
- embedded_tree_new != embedded_tree_old) {
- DCHECK_NE(owning_tree_new, embedded_tree_new);
- embedded_tree_new->ProcessFocusChanged(old_focused_window,
- new_focused_window);
- }
- }
-
- // WindowManagers are always notified of focus changes.
- if (window_manager_display_root_) {
- WindowTree* wm_tree =
- window_manager_display_root_->window_manager_state()->window_tree();
- if (wm_tree != owning_tree_old && wm_tree != embedded_tree_old &&
- wm_tree != owning_tree_new && wm_tree != embedded_tree_new) {
- wm_tree->ProcessFocusChanged(old_focused_window, new_focused_window);
- }
- }
-
- if (new_focused_window) {
- UpdateTextInputState(new_focused_window,
- new_focused_window->text_input_state());
- }
-}
-
-void Display::OnWindowManagerWindowTreeFactoryReady(
- WindowManagerWindowTreeFactory* factory) {
- if (!binding_)
- CreateWindowManagerDisplayRootFromFactory();
-}
-
-EventDispatchDetails Display::OnEventFromSource(Event* event) {
- ProcessEvent(event);
- return EventDispatchDetails();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/display.h b/services/ui/ws/display.h
deleted file mode 100644
index 3a19b1a..0000000
--- a/services/ui/ws/display.h
+++ /dev/null
@@ -1,214 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_DISPLAY_H_
-#define SERVICES_UI_WS_DISPLAY_H_
-
-#include <stdint.h>
-
-#include <memory>
-#include <queue>
-#include <set>
-
-#include "base/callback_forward.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
-#include "services/ui/common/types.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/ui/public/interfaces/window_tree_host.mojom.h"
-#include "services/ui/ws/focus_controller_observer.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/platform_display_delegate.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_observer.h"
-#include "services/ui/ws/window_manager_window_tree_factory_observer.h"
-#include "ui/display/display.h"
-#include "ui/events/event_sink.h"
-
-namespace display {
-struct ViewportMetrics;
-}
-
-namespace ui {
-namespace ws {
-
-class DisplayBinding;
-class DisplayManager;
-class FocusController;
-class WindowManagerDisplayRoot;
-class WindowServer;
-class WindowTree;
-
-namespace test {
-class DisplayTestApi;
-}
-
-// Displays manages the state associated with a single display. Display has a
-// single root window whose children are the roots for a per-user
-// WindowManager. Display is configured in two distinct ways:
-// . with a DisplayBinding. In this mode there is only ever one WindowManager
-// for the display, which comes from the client that created the
-// Display.
-// . without a DisplayBinding. In this mode a WindowManager is automatically
-// created per user.
-class Display : public PlatformDisplayDelegate,
- public mojom::WindowTreeHost,
- public FocusControllerObserver,
- public WindowManagerWindowTreeFactoryObserver,
- public EventSink {
- public:
- explicit Display(WindowServer* window_server);
- ~Display() override;
-
- // Initializes the display root ServerWindow and PlatformDisplay. Adds this to
- // DisplayManager as a pending display, until accelerated widget is available.
- void Init(const display::ViewportMetrics& metrics,
- std::unique_ptr<DisplayBinding> binding);
-
- // Initialize the display's root window to host window manager content.
- void InitWindowManagerDisplayRoots();
-
- // Returns the ID for this display. In internal mode this is the
- // display::Display ID. In external mode this hasn't been defined yet.
- int64_t GetId() const;
-
- // Sets the display::Display corresponding to this ws::Display.
- void SetDisplay(const display::Display& display);
-
- // PlatformDisplayDelegate:
- const display::Display& GetDisplay() override;
-
- const display::ViewportMetrics& GetViewportMetrics() const;
-
- DisplayManager* display_manager();
- const DisplayManager* display_manager() const;
-
- PlatformDisplay* platform_display() { return platform_display_.get(); }
-
- // Returns the size of the display in physical pixels.
- gfx::Size GetSize() const;
-
- WindowServer* window_server() { return window_server_; }
-
- // Returns the root of the Display. The root's children are the roots
- // of the corresponding WindowManagers.
- ServerWindow* root_window() { return root_.get(); }
- const ServerWindow* root_window() const { return root_.get(); }
-
- WindowManagerDisplayRoot* GetWindowManagerDisplayRootWithRoot(
- const ServerWindow* window);
-
- WindowManagerDisplayRoot* window_manager_display_root() {
- return window_manager_display_root_;
- }
-
- const WindowManagerDisplayRoot* window_manager_display_root() const {
- return window_manager_display_root_;
- }
-
- // TODO(sky): this should only be called by WindowServer, move to interface
- // used by WindowServer.
- // See description of WindowServer::SetFocusedWindow() for details on return
- // value.
- bool SetFocusedWindow(ServerWindow* window);
- // NOTE: this returns the focused window only if the focused window is in this
- // display. If this returns null focus may be in another display.
- ServerWindow* GetFocusedWindow();
-
- void UpdateTextInputState(ServerWindow* window,
- const ui::TextInputState& state);
- void SetImeVisibility(ServerWindow* window, bool visible);
-
- // Called just before |tree| is destroyed.
- void OnWillDestroyTree(WindowTree* tree);
-
- // Called prior to |display_root| being destroyed.
- void RemoveWindowManagerDisplayRoot(WindowManagerDisplayRoot* display_root);
-
- // Sets the native cursor to |cursor|.
- void SetNativeCursor(const ui::CursorData& curosor);
-
- // Sets the native cursor size to |cursor_size|.
- void SetNativeCursorSize(ui::CursorSize cursor_size);
-
- // mojom::WindowTreeHost:
- void SetSize(const gfx::Size& size) override;
- void SetTitle(const std::string& title) override;
-
- // Updates the size of display root ServerWindow and WM root ServerWindow(s).
- void OnViewportMetricsChanged(const display::ViewportMetrics& metrics);
-
- void SetBoundsInPixels(const gfx::Rect& bounds_in_pixels);
-
- // Returns the root window of the active user.
- ServerWindow* GetActiveRootWindow();
-
- // Processes an event. |event_processed_callback| is run once the appropriate
- // client processes the event.
- // TODO(sky): move event processing code into standalone classes. Display
- // shouldn't have logic like this.
- void ProcessEvent(
- ui::Event* event,
- base::OnceClosure event_processed_callback = base::OnceClosure());
-
- private:
- friend class test::DisplayTestApi;
-
- class CursorState;
-
- // Creates a WindowManagerDisplayRoot from the
- // WindowManagerWindowTreeFactory.
- void CreateWindowManagerDisplayRootFromFactory();
-
- // Creates the root ServerWindow for this display, where |size| is in physical
- // pixels.
- void CreateRootWindow(const gfx::Size& size);
-
- // Applyes the cursor scale and rotation to the PlatformDisplay.
- void UpdateCursorConfig();
-
- // PlatformDisplayDelegate:
- ServerWindow* GetRootWindow() override;
- EventSink* GetEventSink() override;
- void OnAcceleratedWidgetAvailable() override;
- void OnNativeCaptureLost() override;
- bool IsHostingViz() const override;
-
- // FocusControllerObserver:
- void OnActivationChanged(ServerWindow* old_active_window,
- ServerWindow* new_active_window) override;
- void OnFocusChanged(FocusControllerChangeSource change_source,
- ServerWindow* old_focused_window,
- ServerWindow* new_focused_window) override;
-
- // WindowManagerWindowTreeFactoryObserver:
- void OnWindowManagerWindowTreeFactoryReady(
- WindowManagerWindowTreeFactory* factory) override;
-
- // EventSink:
- EventDispatchDetails OnEventFromSource(Event* event) override;
-
- std::unique_ptr<DisplayBinding> binding_;
- WindowServer* const window_server_;
- std::unique_ptr<ServerWindow> root_;
- std::unique_ptr<PlatformDisplay> platform_display_;
- std::unique_ptr<FocusController> focus_controller_;
-
- // In internal window mode this contains information about the display. In
- // external window mode this will be invalid.
- display::Display display_;
-
- viz::ParentLocalSurfaceIdAllocator allocator_;
-
- // This is owned by WindowManagerState.
- WindowManagerDisplayRoot* window_manager_display_root_ = nullptr;
-
- DISALLOW_COPY_AND_ASSIGN(Display);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DISPLAY_H_
diff --git a/services/ui/ws/display_binding.cc b/services/ui/ws/display_binding.cc
deleted file mode 100644
index 476b946..0000000
--- a/services/ui/ws/display_binding.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-// 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 "services/ui/ws/display_binding.h"
-
-#include "base/memory/ptr_util.h"
-#include "services/service_manager/public/mojom/connector.mojom.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/window_manager_access_policy.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree.h"
-
-namespace ui {
-namespace ws {
-
-DisplayBindingImpl::DisplayBindingImpl(mojom::WindowTreeHostRequest request,
- Display* display,
- mojom::WindowTreeClientPtr client,
- WindowServer* window_server)
- : window_server_(window_server),
- binding_(display, std::move(request)),
- client_(std::move(client)) {}
-
-DisplayBindingImpl::~DisplayBindingImpl() {}
-
-WindowTree* DisplayBindingImpl::CreateWindowTree(ServerWindow* root) {
- const uint32_t embed_flags = 0;
- WindowTree* tree = window_server_->EmbedAtWindow(
- root, std::move(client_), embed_flags,
- base::WrapUnique(new WindowManagerAccessPolicy));
- const bool automatically_create_display_roots = true;
- tree->ConfigureWindowManager(automatically_create_display_roots);
- return tree;
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/display_binding.h b/services/ui/ws/display_binding.h
deleted file mode 100644
index 3b88965..0000000
--- a/services/ui/ws/display_binding.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_DISPLAY_BINDING_H_
-#define SERVICES_UI_WS_DISPLAY_BINDING_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/public/interfaces/window_tree_host.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class Display;
-class ServerWindow;
-class WindowServer;
-class WindowTree;
-
-// DisplayBinding manages the binding between a Display and it's mojo clients.
-// DisplayBinding is used when a Display is created via a
-// WindowTreeHostFactory.
-//
-// DisplayBinding is owned by Display.
-class DisplayBinding {
- public:
- virtual ~DisplayBinding() {}
-
- virtual WindowTree* CreateWindowTree(ServerWindow* root) = 0;
-};
-
-// Live implementation of DisplayBinding.
-class DisplayBindingImpl : public DisplayBinding {
- public:
- DisplayBindingImpl(mojom::WindowTreeHostRequest request,
- Display* display,
- mojom::WindowTreeClientPtr client,
- WindowServer* window_server);
- ~DisplayBindingImpl() override;
-
- private:
- // DisplayBinding:
- WindowTree* CreateWindowTree(ServerWindow* root) override;
-
- WindowServer* window_server_;
- mojo::Binding<mojom::WindowTreeHost> binding_;
- mojom::WindowTreeClientPtr client_;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayBindingImpl);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DISPLAY_BINDING_H_
diff --git a/services/ui/ws/display_creation_config.h b/services/ui/ws/display_creation_config.h
deleted file mode 100644
index 65b1f52..0000000
--- a/services/ui/ws/display_creation_config.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_DISPLAY_CREATION_CONFIG_H_
-#define SERVICES_UI_WS_DISPLAY_CREATION_CONFIG_H_
-
-namespace ui {
-namespace ws {
-
-enum class DisplayCreationConfig {
- // Initial state.
- UNKNOWN,
-
- // Displays are created automatically based on the system.
- AUTOMATIC,
-
- // Used when the window manager manually creates displays.
- MANUAL,
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DISPLAY_CREATION_CONFIG_H_
diff --git a/services/ui/ws/display_manager.cc b/services/ui/ws/display_manager.cc
deleted file mode 100644
index f40f244..0000000
--- a/services/ui/ws/display_manager.cc
+++ /dev/null
@@ -1,453 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/display_manager.h"
-
-#include <vector>
-
-#include "base/containers/flat_set.h"
-#include "base/trace_event/trace_event.h"
-#include "services/ui/display/screen_manager.h"
-#include "services/ui/display/viewport_metrics.h"
-#include "services/ui/ws/cursor_location_manager.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_binding.h"
-#include "services/ui/ws/display_creation_config.h"
-#include "services/ui/ws/event_processor.h"
-#include "services/ui/ws/frame_generator.h"
-#include "services/ui/ws/platform_display_mirror.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/user_display_manager.h"
-#include "services/ui/ws/user_display_manager_delegate.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_manager_window_tree_factory.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree.h"
-#include "ui/display/display_list.h"
-#include "ui/display/screen_base.h"
-#include "ui/display/types/display_constants.h"
-#include "ui/events/event_rewriter.h"
-#include "ui/gfx/geometry/point_conversions.h"
-
-#if defined(OS_CHROMEOS)
-#include "ui/chromeos/events/event_rewriter_chromeos.h"
-#endif
-
-namespace ui {
-namespace ws {
-
-DisplayManager::DisplayManager(WindowServer* window_server, bool is_hosting_viz)
- : window_server_(window_server),
- cursor_location_manager_(std::make_unique<CursorLocationManager>()) {
-#if defined(OS_CHROMEOS)
- if (is_hosting_viz) {
- // TODO: http://crbug.com/701468 fix function key preferences and sticky
- // keys.
- ui::EventRewriterChromeOS::Delegate* delegate = nullptr;
- ui::EventRewriter* sticky_keys_controller = nullptr;
- event_rewriter_ = std::make_unique<ui::EventRewriterChromeOS>(
- delegate, sticky_keys_controller);
- }
-#endif
-}
-
-DisplayManager::~DisplayManager() {
- DestroyAllDisplays();
-}
-
-void DisplayManager::OnDisplayCreationConfigSet() {
- if (window_server_->display_creation_config() ==
- DisplayCreationConfig::MANUAL) {
- if (user_display_manager_)
- user_display_manager_->DisableAutomaticNotification();
- } else {
- // In AUTOMATIC mode SetDisplayConfiguration() is never called.
- got_initial_config_from_window_manager_ = true;
- }
-}
-
-bool DisplayManager::SetDisplayConfiguration(
- const std::vector<display::Display>& displays,
- const std::vector<display::ViewportMetrics>& viewport_metrics,
- int64_t primary_display_id,
- int64_t internal_display_id,
- const std::vector<display::Display>& mirrors) {
- DCHECK_NE(display::kUnifiedDisplayId, internal_display_id);
- if (window_server_->display_creation_config() !=
- DisplayCreationConfig::MANUAL) {
- LOG(ERROR) << "SetDisplayConfiguration is only valid when roots manually "
- "created";
- return false;
- }
- if (displays.size() + mirrors.size() != viewport_metrics.size()) {
- LOG(ERROR) << "SetDisplayConfiguration called with mismatch in sizes";
- return false;
- }
-
- size_t primary_display_index = std::numeric_limits<size_t>::max();
-
- // Check the mirrors before potentially passing them to a unified display.
- base::flat_set<int64_t> mirror_ids;
- for (const auto& mirror : mirrors) {
- if (mirror.id() == display::kInvalidDisplayId) {
- LOG(ERROR) << "SetDisplayConfiguration passed invalid display id";
- return false;
- }
- if (mirror.id() == display::kUnifiedDisplayId) {
- LOG(ERROR) << "SetDisplayConfiguration passed unified display in mirrors";
- return false;
- }
- if (!mirror_ids.insert(mirror.id()).second) {
- LOG(ERROR) << "SetDisplayConfiguration passed duplicate display id";
- return false;
- }
- if (mirror.id() == primary_display_id) {
- LOG(ERROR) << "SetDisplayConfiguration passed primary display in mirrors";
- return false;
- }
- }
-
- base::flat_set<int64_t> display_ids;
- for (size_t i = 0; i < displays.size(); ++i) {
- const display::Display& display = displays[i];
- if (display.id() == display::kInvalidDisplayId) {
- LOG(ERROR) << "SetDisplayConfiguration passed invalid display id";
- return false;
- }
- if (!display_ids.insert(display.id()).second) {
- LOG(ERROR) << "SetDisplayConfiguration passed duplicate display id";
- return false;
- }
- if (display.id() == primary_display_id)
- primary_display_index = i;
- Display* ws_display = GetDisplayById(display.id());
- if (!ws_display && display.id() != display::kUnifiedDisplayId) {
- LOG(ERROR) << "SetDisplayConfiguration passed unknown display id "
- << display.id();
- return false;
- }
- }
- if (primary_display_index == std::numeric_limits<size_t>::max()) {
- LOG(ERROR) << "SetDisplayConfiguration primary id not in displays";
- return false;
- }
-
- // See comment in header as to why this doesn't use Display::SetInternalId().
- // NOTE: the internal display might not be listed in |displays| or |mirrors|.
- internal_display_id_ = internal_display_id;
-
- display::DisplayList& display_list =
- display::ScreenManager::GetInstance()->GetScreen()->display_list();
- // Update the primary display first, in case the old primary has been removed.
- display_list.AddOrUpdateDisplay(displays[primary_display_index],
- display::DisplayList::Type::PRIMARY);
-
- // Remove any existing displays that are not included in the configuration.
- for (int i = display_list.displays().size() - 1; i >= 0; --i) {
- const int64_t id = display_list.displays()[i].id();
- if (display_ids.count(id) == 0) {
- // The display list also contains mirrors, which do not have ws::Displays.
- // If the destroyed display still has a root window, it is orphaned here.
- // Root windows are destroyed by explicit window manager instruction.
- if (Display* ws_display = GetDisplayById(id))
- DestroyDisplay(ws_display);
- // Do not remove display::Display entries for mirroring displays.
- if (mirror_ids.count(id) == 0)
- display_list.RemoveDisplay(id);
- }
- }
-
- // Remove any existing mirrors that are not included in the configuration.
- for (int i = mirrors_.size() - 1; i >= 0; --i) {
- if (mirror_ids.count(mirrors_[i]->display().id()) == 0) {
- // Do not remove display::Display entries for extended displays.
- if (display_ids.count(mirrors_[i]->display().id()) == 0)
- display_list.RemoveDisplay(mirrors_[i]->display().id());
- mirrors_.erase(mirrors_.begin() + i);
- }
- }
-
- // Add or update any displays that are included in the configuration.
- for (size_t i = 0; i < displays.size(); ++i) {
- Display* ws_display = GetDisplayById(displays[i].id());
- DCHECK(ws_display);
- ws_display->SetDisplay(displays[i]);
- ws_display->OnViewportMetricsChanged(viewport_metrics[i]);
- if (i != primary_display_index) {
- display_list.AddOrUpdateDisplay(displays[i],
- display::DisplayList::Type::NOT_PRIMARY);
- }
- }
-
- // Add or update any mirrors that are included in the configuration.
- for (size_t i = 0; i < mirrors.size(); ++i) {
- DCHECK(!GetDisplayById(mirrors[i].id()));
- Display* ws_display_to_mirror = GetDisplayById(displays[0].id());
-
- const auto& metrics = viewport_metrics[displays.size() + i];
- PlatformDisplayMirror* mirror = nullptr;
- for (size_t i = 0; i < mirrors_.size(); ++i) {
- if (mirrors_[i]->display().id() == mirrors[i].id()) {
- mirror = mirrors_[i].get();
- break;
- }
- }
- if (mirror) {
- mirror->set_display(mirrors[i]);
- mirror->UpdateViewportMetrics(metrics);
- } else {
- mirrors_.push_back(std::make_unique<PlatformDisplayMirror>(
- mirrors[i], metrics, window_server_, ws_display_to_mirror));
- }
- }
-
- std::set<int64_t> existing_display_ids;
- for (const display::Display& display : display_list.displays())
- existing_display_ids.insert(display.id());
- std::set<int64_t> removed_display_ids =
- base::STLSetDifference<std::set<int64_t>>(existing_display_ids,
- display_ids);
- for (int64_t display_id : removed_display_ids)
- display_list.RemoveDisplay(display_id);
-
- if (user_display_manager_)
- user_display_manager_->CallOnDisplaysChanged();
-
- if (!got_initial_config_from_window_manager_) {
- got_initial_config_from_window_manager_ = true;
- window_server_->delegate()->OnFirstDisplayReady();
- }
-
- return true;
-}
-
-UserDisplayManager* DisplayManager::GetUserDisplayManager() {
- if (!user_display_manager_) {
- user_display_manager_ =
- std::make_unique<UserDisplayManager>(window_server_);
- if (window_server_->display_creation_config() ==
- DisplayCreationConfig::MANUAL) {
- user_display_manager_->DisableAutomaticNotification();
- }
- }
- return user_display_manager_.get();
-}
-
-void DisplayManager::AddDisplay(Display* display) {
- DCHECK_EQ(0u, pending_displays_.count(display));
- pending_displays_.insert(display);
-}
-
-Display* DisplayManager::AddDisplayForWindowManager(
- bool is_primary_display,
- const display::Display& display,
- const display::ViewportMetrics& metrics) {
- DCHECK_EQ(DisplayCreationConfig::MANUAL,
- window_server_->display_creation_config());
- const display::DisplayList::Type display_type =
- is_primary_display ? display::DisplayList::Type::PRIMARY
- : display::DisplayList::Type::NOT_PRIMARY;
- display::DisplayList& display_list =
- display::ScreenManager::GetInstance()->GetScreen()->display_list();
- // The display may already be listed as a mirror destination display.
- display_list.AddOrUpdateDisplay(display, display_type);
- OnDisplayAdded(display, metrics);
- return GetDisplayById(display.id());
-}
-
-void DisplayManager::DestroyDisplay(Display* display) {
- const bool is_pending = pending_displays_.count(display) > 0;
- if (is_pending) {
- pending_displays_.erase(display);
- } else {
- DCHECK(displays_.count(display));
- displays_.erase(display);
- window_server_->OnDisplayDestroyed(display);
- }
- const int64_t display_id = display->GetId();
- delete display;
-
- // If we have no more roots left, let the app know so it can terminate.
- // TODO(sky): move to delegate/observer.
- if (displays_.empty() && pending_displays_.empty())
- window_server_->OnNoMoreDisplays();
- else if (user_display_manager_)
- user_display_manager_->OnDisplayDestroyed(display_id);
-}
-
-void DisplayManager::DestroyAllDisplays() {
- while (!pending_displays_.empty())
- DestroyDisplay(*pending_displays_.begin());
- DCHECK(pending_displays_.empty());
-
- while (!displays_.empty())
- DestroyDisplay(*displays_.begin());
- DCHECK(displays_.empty());
-}
-
-std::set<const Display*> DisplayManager::displays() const {
- std::set<const Display*> ret_value(displays_.begin(), displays_.end());
- return ret_value;
-}
-
-void DisplayManager::OnDisplayUpdated(const display::Display& display) {
- if (user_display_manager_)
- user_display_manager_->OnDisplayUpdated(display);
-}
-
-Display* DisplayManager::GetDisplayContaining(const ServerWindow* window) {
- return const_cast<Display*>(
- static_cast<const DisplayManager*>(this)->GetDisplayContaining(window));
-}
-
-const Display* DisplayManager::GetDisplayContaining(
- const ServerWindow* window) const {
- while (window && window->parent())
- window = window->parent();
- for (Display* display : displays_) {
- if (window == display->root_window())
- return display;
- }
- return nullptr;
-}
-
-const Display* DisplayManager::GetDisplayById(int64_t display_id) const {
- for (Display* display : displays_) {
- if (display->GetId() == display_id)
- return display;
- }
- return nullptr;
-}
-
-const WindowManagerDisplayRoot* DisplayManager::GetWindowManagerDisplayRoot(
- const ServerWindow* window) const {
- const ServerWindow* last = window;
- while (window && window->parent()) {
- last = window;
- window = window->parent();
- }
- for (Display* display : displays_) {
- if (window == display->root_window())
- return display->GetWindowManagerDisplayRootWithRoot(last);
- }
- return nullptr;
-}
-
-WindowManagerDisplayRoot* DisplayManager::GetWindowManagerDisplayRoot(
- const ServerWindow* window) {
- return const_cast<WindowManagerDisplayRoot*>(
- const_cast<const DisplayManager*>(this)->GetWindowManagerDisplayRoot(
- window));
-}
-
-bool DisplayManager::InUnifiedDisplayMode() const {
- return GetDisplayById(display::kUnifiedDisplayId) != nullptr;
-}
-
-ClientWindowId DisplayManager::GetAndAdvanceNextRootId() {
- const ClientSpecificId id = next_root_id_++;
- CHECK_NE(0u, next_root_id_);
- return ClientWindowId(kWindowServerClientId, id);
-}
-
-void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) {
- DCHECK_NE(0u, pending_displays_.count(display));
- DCHECK_EQ(0u, displays_.count(display));
- const bool is_first_display =
- displays_.empty() && got_initial_config_from_window_manager_;
- displays_.insert(display);
- pending_displays_.erase(display);
- if (event_rewriter_)
- display->platform_display()->AddEventRewriter(event_rewriter_.get());
- window_server_->OnDisplayReady(display, is_first_display);
-}
-
-void DisplayManager::OnWindowManagerSurfaceActivation(
- Display* display,
- const viz::SurfaceInfo& surface_info) {
- display->platform_display()->GetFrameGenerator()->SetEmbeddedSurface(
- surface_info);
- // Also pass the surface info to any displays mirroring the given display.
- for (const auto& mirror : mirrors_) {
- if (mirror->display_to_mirror() == display)
- mirror->GetFrameGenerator()->SetEmbeddedSurface(surface_info);
- }
-}
-
-void DisplayManager::SetHighContrastMode(bool enabled) {
- for (Display* display : displays_) {
- display->platform_display()->GetFrameGenerator()->SetHighContrastMode(
- enabled);
- }
-}
-
-bool DisplayManager::IsInternalDisplay(const display::Display& display) const {
- return display.id() == GetInternalDisplayId();
-}
-
-int64_t DisplayManager::GetInternalDisplayId() const {
- if (window_server_->display_creation_config() ==
- DisplayCreationConfig::MANUAL) {
- return internal_display_id_;
- }
- return display::Display::HasInternalDisplay()
- ? display::Display::InternalDisplayId()
- : display::kInvalidDisplayId;
-}
-
-void DisplayManager::CreateDisplay(const display::Display& display,
- const display::ViewportMetrics& metrics) {
- ws::Display* ws_display = new ws::Display(window_server_);
- ws_display->SetDisplay(display);
- ws_display->Init(metrics, nullptr);
-}
-
-void DisplayManager::OnDisplayAdded(const display::Display& display,
- const display::ViewportMetrics& metrics) {
- DVLOG(3) << "OnDisplayAdded: " << display.ToString();
- CreateDisplay(display, metrics);
-}
-
-void DisplayManager::OnDisplayRemoved(int64_t display_id) {
- DVLOG(3) << "OnDisplayRemoved: " << display_id;
- Display* display = GetDisplayById(display_id);
- if (display)
- DestroyDisplay(display);
-}
-
-void DisplayManager::OnDisplayModified(
- const display::Display& display,
- const display::ViewportMetrics& metrics) {
- DVLOG(3) << "OnDisplayModified: " << display.ToString();
-
- Display* ws_display = GetDisplayById(display.id());
- DCHECK(ws_display);
-
- // Update the cached display information.
- ws_display->SetDisplay(display);
-
- // Send IPC to WMs with new display information.
- WindowManagerWindowTreeFactory* factory =
- window_server_->window_manager_window_tree_factory();
- if (factory->window_tree())
- factory->window_tree()->OnWmDisplayModified(display);
-
- // Update the PlatformWindow and ServerWindow size. This must happen after
- // OnWmDisplayModified() so the WM has updated the display size.
- ws_display->OnViewportMetricsChanged(metrics);
-
- OnDisplayUpdated(display);
-}
-
-void DisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) {
- DVLOG(3) << "OnPrimaryDisplayChanged: " << primary_display_id;
- // TODO(kylechar): Send IPCs to WM clients first.
-
- // Send IPCs to any DisplayManagerObservers.
- if (user_display_manager_)
- user_display_manager_->OnPrimaryDisplayChanged(primary_display_id);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/display_manager.h b/services/ui/ws/display_manager.h
deleted file mode 100644
index e5d2caf..0000000
--- a/services/ui/ws/display_manager.h
+++ /dev/null
@@ -1,179 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_DISPLAY_MANAGER_H_
-#define SERVICES_UI_WS_DISPLAY_MANAGER_H_
-
-#include <map>
-#include <memory>
-#include <set>
-
-#include "base/macros.h"
-#include "components/viz/common/surfaces/surface_info.h"
-#include "services/ui/display/screen_manager_delegate.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/ui/ws/ids.h"
-#include "ui/display/display.h"
-
-namespace display {
-struct ViewportMetrics;
-}
-namespace ui {
-class EventRewriter;
-namespace ws {
-
-class CursorLocationManager;
-class Display;
-class PlatformDisplayMirror;
-class ServerWindow;
-class UserDisplayManager;
-class WindowManagerDisplayRoot;
-class WindowServer;
-
-// DisplayManager manages the set of Displays. DisplayManager distinguishes
-// between displays that do not yet have an accelerated widget (pending), vs
-// those that do.
-class DisplayManager : public display::ScreenManagerDelegate {
- public:
- DisplayManager(WindowServer* window_server, bool is_hosting_viz);
- ~DisplayManager() override;
-
- // Called once WindowServer::display_creation_config() has been determined.
- void OnDisplayCreationConfigSet();
-
- // Indicates the display configuration is valid. Set to true when the
- // display_creation_config() has been determined and the config is
- // AUTOMATIC, or MANUAL and the SetDisplayConfiguration() has been called.
- bool got_initial_config_from_window_manager() const {
- return got_initial_config_from_window_manager_;
- }
-
- // Sets the display configuration from the window manager. Returns true
- // on success, false if the arguments aren't valid.
- bool SetDisplayConfiguration(
- const std::vector<display::Display>& displays,
- const std::vector<display::ViewportMetrics>& viewport_metrics,
- int64_t primary_display_id,
- int64_t internal_display_id,
- const std::vector<display::Display>& mirrors);
-
- // Returns the UserDisplayManager. DisplayManager owns the return value.
- UserDisplayManager* GetUserDisplayManager();
-
- // Returns the CursorLocationManager.
- CursorLocationManager* cursor_location_manager() {
- return cursor_location_manager_.get();
- }
-
- // Adds/removes a Display. DisplayManager owns the Displays.
- // TODO(sky): make add take a scoped_ptr.
- void AddDisplay(Display* display);
- // Called when the window manager explicitly adds a new display.
- Display* AddDisplayForWindowManager(bool is_primary_display,
- const display::Display& display,
- const display::ViewportMetrics& metrics);
- void DestroyDisplay(Display* display);
- void DestroyAllDisplays();
- const std::set<Display*>& displays() { return displays_; }
- std::set<const Display*> displays() const;
-
- // Notifies when something about the Display changes.
- void OnDisplayUpdated(const display::Display& display);
-
- // Returns the Display that contains |window|, or null if |window| is not
- // attached to a display.
- Display* GetDisplayContaining(const ServerWindow* window);
- const Display* GetDisplayContaining(const ServerWindow* window) const;
-
- // Returns the display with the specified display id, or null if there is no
- // display with that id.
- const Display* GetDisplayById(int64_t display_id) const;
- Display* GetDisplayById(int64_t display_id) {
- return const_cast<Display*>(
- const_cast<const DisplayManager*>(this)->GetDisplayById(display_id));
- }
-
- const WindowManagerDisplayRoot* GetWindowManagerDisplayRoot(
- const ServerWindow* window) const;
- // TODO(sky): constness here is wrong! fix!
- WindowManagerDisplayRoot* GetWindowManagerDisplayRoot(
- const ServerWindow* window);
-
- bool IsReady() const {
- return !displays_.empty() && got_initial_config_from_window_manager_;
- }
- bool has_active_or_pending_displays() const {
- return !displays_.empty() || !pending_displays_.empty();
- }
-
- bool InUnifiedDisplayMode() const;
-
- // Returns the id for the next root window (both for the root of a Display
- // as well as the root of WindowManagers).
- ClientWindowId GetAndAdvanceNextRootId();
-
- // Called when the AcceleratedWidget is available for |display|.
- void OnDisplayAcceleratedWidgetAvailable(Display* display);
-
- // Called when a new surface for a WindowManager root has been created.
- void OnWindowManagerSurfaceActivation(Display* display,
- const viz::SurfaceInfo& surface_info);
-
- // Switch the high contrast mode of all Displays to |enabled|.
- void SetHighContrastMode(bool enabled);
-
- bool IsInternalDisplay(const display::Display& display) const;
- int64_t GetInternalDisplayId() const;
-
- private:
- void CreateDisplay(const display::Display& display,
- const display::ViewportMetrics& metrics);
-
- // NOTE: these functions are *not* called when the WindowManager manually
- // creates roots.
- // display::ScreenManagerDelegate:
- void OnDisplayAdded(const display::Display& display,
- const display::ViewportMetrics& metrics) override;
- void OnDisplayRemoved(int64_t id) override;
- void OnDisplayModified(const display::Display& display,
- const display::ViewportMetrics& metrics) override;
- void OnPrimaryDisplayChanged(int64_t primary_display_id) override;
-
- WindowServer* window_server_;
-
- // For rewriting ChromeOS function keys.
- std::unique_ptr<ui::EventRewriter> event_rewriter_;
-
- // Displays are initially added to |pending_displays_|. When the display is
- // initialized it is moved to |displays_|. WindowServer owns the Displays.
- std::set<Display*> pending_displays_;
- std::set<Display*> displays_;
-
- // Displays that mirror the contents of another display in |displays_|.
- std::vector<std::unique_ptr<PlatformDisplayMirror>> mirrors_;
-
- std::unique_ptr<UserDisplayManager> user_display_manager_;
-
- std::unique_ptr<CursorLocationManager> cursor_location_manager_;
-
- // ID to use for next root node.
- // TODO(sky): figure out why this starts at 2.
- ClientSpecificId next_root_id_ = 2;
-
- bool got_initial_config_from_window_manager_ = false;
-
- // Id of the internal display, or kInvalidDisplayId. This is only set when
- // WindowManager is configured to manually create display roots. This is
- // not mirrored in Display::SetInternalId() as mus may be running in the
- // same process as the window-manager, so that if this did set the value in
- // Display there could be race conditions.
- int64_t internal_display_id_ = display::kInvalidDisplayId;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayManager);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DISPLAY_MANAGER_H_
diff --git a/services/ui/ws/display_unittest.cc b/services/ui/ws/display_unittest.cc
deleted file mode 100644
index c500f46f..0000000
--- a/services/ui/ws/display_unittest.cc
+++ /dev/null
@@ -1,261 +0,0 @@
-// Copyright 2016 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 <stdint.h>
-
-#include <string>
-
-#include "base/macros.h"
-#include "services/ui/common/types.h"
-#include "services/ui/common/util.h"
-#include "services/ui/display/viewport_metrics.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/platform_display_factory.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_utils.h"
-#include "services/ui/ws/window_manager_display_root.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/display/display.h"
-#include "ui/events/event.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-namespace {
-
-// Returns the root ServerWindow for the specified Display.
-ServerWindow* GetRootOnDisplay(WindowTree* tree, Display* display) {
- for (const ServerWindow* root : tree->roots()) {
- if (tree->GetDisplay(root) == display)
- return const_cast<ServerWindow*>(root);
- }
- return nullptr;
-}
-
-// Tracks destruction of a ServerWindow, setting a bool* to true when
-// OnWindowDestroyed() is called
-class ServerWindowDestructionObserver : public ServerWindowObserver {
- public:
- ServerWindowDestructionObserver(ServerWindow* window, bool* destroyed)
- : window_(window), destroyed_(destroyed) {
- window_->AddObserver(this);
- }
- ~ServerWindowDestructionObserver() override {
- if (window_)
- window_->RemoveObserver(this);
- }
-
- // ServerWindowObserver:
- void OnWindowDestroyed(ServerWindow* window) override {
- *destroyed_ = true;
- window_->RemoveObserver(this);
- window_ = nullptr;
- }
-
- private:
- ServerWindow* window_;
- bool* destroyed_;
-
- DISALLOW_COPY_AND_ASSIGN(ServerWindowDestructionObserver);
-};
-
-} // namespace
-
-// -----------------------------------------------------------------------------
-
-class DisplayTest : public testing::Test {
- public:
- DisplayTest() {}
- ~DisplayTest() override {}
-
- WindowServer* window_server() { return ws_test_helper_.window_server(); }
- DisplayManager* display_manager() {
- return window_server()->display_manager();
- }
- TestWindowServerDelegate* window_server_delegate() {
- return ws_test_helper_.window_server_delegate();
- }
- TestScreenManager& screen_manager() { return screen_manager_; }
- const ui::CursorData& cursor() { return ws_test_helper_.cursor(); }
-
- protected:
- // testing::Test:
- void SetUp() override {
- screen_manager_.Init(window_server()->display_manager());
- }
-
- private:
- WindowServerTestHelper ws_test_helper_;
- TestScreenManager screen_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayTest);
-};
-
-TEST_F(DisplayTest, CreateDisplay) {
- AddWindowManager(window_server());
- const int64_t display_id =
- screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
-
- ASSERT_EQ(1u, display_manager()->displays().size());
- Display* display = display_manager()->GetDisplayById(display_id);
-
- // Display should have root window with correct size.
- ASSERT_NE(nullptr, display->root_window());
- EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString());
-
- // Display should have a WM root window with the correct size too.
- WindowManagerDisplayRoot* root1 = display->window_manager_display_root();
- ASSERT_NE(nullptr, root1);
- ASSERT_NE(nullptr, root1->root());
- EXPECT_EQ("0,0 1024x768", root1->root()->bounds().ToString());
-}
-
-TEST_F(DisplayTest, CreateDisplayBeforeWM) {
- // Add one display, no WM exists yet.
- const int64_t display_id =
- screen_manager().AddDisplay(MakeDisplay(0, 0, 1024, 768, 1.0f));
- EXPECT_EQ(1u, display_manager()->displays().size());
-
- Display* display = display_manager()->GetDisplayById(display_id);
-
- // Display should have root window with correct size.
- ASSERT_NE(nullptr, display->root_window());
- EXPECT_EQ("0,0 1024x768", display->root_window()->bounds().ToString());
-
- // There should be no WM state for display yet.
- EXPECT_EQ(nullptr, display->window_manager_display_root());
-
- AddWindowManager(window_server());
-
- // After adding a WM display should have WM state and WM root for the display.
- WindowManagerDisplayRoot* root1 = display->window_manager_display_root();
- ASSERT_NE(nullptr, root1);
- ASSERT_NE(nullptr, root1->root());
- EXPECT_EQ("0,0 1024x768", root1->root()->bounds().ToString());
-}
-
-TEST_F(DisplayTest, CreateDisplayWithDeviceScaleFactor) {
- // The display bounds should be the pixel_size / device_scale_factor.
- display::Display display = MakeDisplay(0, 0, 1024, 768, 2.0f);
- EXPECT_EQ("0,0 512x384", display.bounds().ToString());
-
- const int64_t display_id = screen_manager().AddDisplay(display);
- display.set_id(display_id);
- Display* ws_display = display_manager()->GetDisplayById(display_id);
-
- // The root ServerWindow bounds should be in PP.
- EXPECT_EQ("0,0 1024x768", ws_display->root_window()->bounds().ToString());
-
- // Modify the display work area to be 48 DIPs smaller.
- display::Display modified_display = display;
- gfx::Rect modified_work_area = display.work_area();
- modified_work_area.set_height(modified_work_area.height() - 48);
- modified_display.set_work_area(modified_work_area);
- screen_manager().ModifyDisplay(modified_display);
-
- // The display work area should have changed.
- EXPECT_EQ("0,0 512x336", ws_display->GetDisplay().work_area().ToString());
-
- // The root ServerWindow should still be in PP after updating the work area.
- EXPECT_EQ("0,0 1024x768", ws_display->root_window()->bounds().ToString());
-}
-
-TEST_F(DisplayTest, Destruction) {
- AddWindowManager(window_server());
-
- int64_t display_id = screen_manager().AddDisplay();
-
- ASSERT_EQ(1u, display_manager()->displays().size());
- EXPECT_EQ(1u, window_server()->num_trees());
-
- WindowManagerState* state = window_server()->GetWindowManagerState();
- // Destroy the tree associated with |state|. Should result in deleting
- // |state|.
- window_server()->DestroyTree(state->window_tree());
- EXPECT_EQ(1u, display_manager()->displays().size());
- EXPECT_EQ(0u, window_server()->num_trees());
- EXPECT_FALSE(window_server_delegate()->got_on_no_more_displays());
- screen_manager().RemoveDisplay(display_id);
- EXPECT_TRUE(window_server_delegate()->got_on_no_more_displays());
-}
-
-// Verifies a single tree is used for multiple displays.
-TEST_F(DisplayTest, MultipleDisplays) {
- screen_manager().AddDisplay();
- screen_manager().AddDisplay();
- AddWindowManager(window_server());
- ASSERT_EQ(1u, window_server_delegate()->bindings()->size());
- TestWindowTreeBinding* window_tree_binding =
- (*window_server_delegate()->bindings())[0];
- WindowTree* tree = window_tree_binding->tree();
- ASSERT_EQ(2u, tree->roots().size());
- std::set<const ServerWindow*> roots = tree->roots();
- auto it = roots.begin();
- ServerWindow* root1 = const_cast<ServerWindow*>(*it);
- ++it;
- ServerWindow* root2 = const_cast<ServerWindow*>(*it);
- ASSERT_NE(root1, root2);
- Display* display1 = tree->GetDisplay(root1);
- WindowManagerState* display1_wms =
- display1->window_manager_display_root()->window_manager_state();
- Display* display2 = tree->GetDisplay(root2);
- WindowManagerState* display2_wms =
- display2->window_manager_display_root()->window_manager_state();
- EXPECT_EQ(display1_wms->window_tree(), display2_wms->window_tree());
-}
-
-// Assertions around destroying a secondary display.
-TEST_F(DisplayTest, DestroyingDisplayDoesntDelete) {
- AddWindowManager(window_server());
- screen_manager().AddDisplay();
- const int64_t secondary_display_id = screen_manager().AddDisplay();
- ASSERT_EQ(1u, window_server_delegate()->bindings()->size());
- WindowTree* tree = (*window_server_delegate()->bindings())[0]->tree();
- ASSERT_EQ(2u, tree->roots().size());
- Display* secondary_display =
- display_manager()->GetDisplayById(secondary_display_id);
- ASSERT_TRUE(secondary_display);
- bool secondary_root_destroyed = false;
- ServerWindow* secondary_root = GetRootOnDisplay(tree, secondary_display);
- ASSERT_TRUE(secondary_root);
- ServerWindowDestructionObserver observer(secondary_root,
- &secondary_root_destroyed);
- ClientWindowId secondary_root_id =
- ClientWindowIdForWindow(tree, secondary_root);
- TestWindowTreeClient* tree_client =
- static_cast<TestWindowTreeClient*>(tree->client());
- tree_client->tracker()->changes()->clear();
- TestWindowManager* test_window_manager =
- window_server_delegate()->last_binding()->window_manager();
- EXPECT_FALSE(test_window_manager->got_display_removed());
- screen_manager().RemoveDisplay(secondary_display_id);
-
- // Destroying the display should result in the following:
- // . The WindowManager should be told it was removed with the right id.
- EXPECT_TRUE(test_window_manager->got_display_removed());
- EXPECT_EQ(secondary_display_id, test_window_manager->display_removed_id());
- EXPECT_FALSE(secondary_root_destroyed);
- // The window should still be valid on the server side.
- ASSERT_TRUE(tree->GetWindowByClientId(secondary_root_id));
- // No changes.
- ASSERT_EQ(0u, tree_client->tracker()->changes()->size());
-
- // The window should be destroyed when the client says so.
- ASSERT_TRUE(tree->DeleteWindow(secondary_root_id));
- EXPECT_TRUE(secondary_root_destroyed);
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/drag_controller.cc b/services/ui/ws/drag_controller.cc
deleted file mode 100644
index 2e3b332..0000000
--- a/services/ui/ws/drag_controller.cc
+++ /dev/null
@@ -1,376 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/drag_controller.h"
-
-#include <utility>
-
-#include "base/logging.h"
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "services/ui/ws/drag_cursor_updater.h"
-#include "services/ui/ws/drag_source.h"
-#include "services/ui/ws/drag_target_connection.h"
-#include "services/ui/ws/server_window.h"
-#include "ui/base/cursor/cursor.h"
-
-namespace ui {
-namespace ws {
-
-struct DragController::Operation {
- OperationType type;
- uint32_t event_flags;
- gfx::Point screen_position;
-};
-
-struct DragController::WindowState {
- // Set to true once we've observed the ServerWindow* that is the key to this
- // instance in |window_state_|.
- bool observed = false;
-
- // If we're waiting for a response, this is the type of message. NONE means
- // there's no outstanding
- OperationType waiting_on_reply = OperationType::NONE;
-
- // The operation that we'll send off if |waiting_on_reply| isn't NONE.
- Operation queued_operation = {OperationType::NONE, 0, gfx::Point()};
-
- // The current set of operations that this window accepts. This gets updated
- // on each return message.
- DropEffectBitmask bitmask = 0u;
-};
-
-DragController::DragController(
- DragCursorUpdater* cursor_updater,
- DragSource* source,
- ServerWindow* source_window,
- DragTargetConnection* source_connection,
- int32_t drag_pointer,
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data,
- DropEffectBitmask drag_operations)
- : source_(source),
- cursor_updater_(cursor_updater),
- drag_operations_(drag_operations),
- drag_pointer_id_(drag_pointer),
- current_cursor_(ui::CursorType::kNoDrop),
- source_window_(source_window),
- source_connection_(source_connection),
- mime_data_(mime_data),
- weak_factory_(this) {
- SetCurrentTargetWindow(nullptr);
- EnsureWindowObserved(source_window_);
-}
-
-DragController::~DragController() {
- for (auto& pair : window_state_) {
- if (pair.second.observed)
- pair.first->RemoveObserver(this);
- }
-}
-
-void DragController::Cancel() {
- MessageDragCompleted(false, ui::mojom::kDropEffectNone);
- // |this| may be deleted now.
-}
-
-bool DragController::DispatchPointerEvent(const ui::PointerEvent& event,
- ServerWindow* current_target) {
- DVLOG(2) << "DragController dispatching pointer event at "
- << event.location().ToString();
- uint32_t event_flags =
- event.flags() &
- (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN);
- gfx::Point screen_position = event.location();
-
- if (waiting_for_final_drop_response_) {
- // If we're waiting on a target window to respond to the final drag drop
- // call, don't process any more pointer events.
- DVLOG(1) << "Ignoring event because we're waiting for final drop response";
- return false;
- }
-
- if (event.pointer_details().id != drag_pointer_id_) {
- DVLOG(1) << "Ignoring event from different pointer "
- << event.pointer_details().id;
- return false;
- }
-
- // If |current_target| doesn't accept drags, walk its hierarchy up until we
- // find one that does (or set to nullptr at the top of the tree).
- while (current_target && !current_target->can_accept_drops())
- current_target = current_target->parent();
-
- if (current_target) {
- // If we're non-null, we're about to use |current_target| in some
- // way. Ensure that we receive notifications that this window has gone
- // away.
- EnsureWindowObserved(current_target);
- }
-
- source_->OnDragMoved(screen_position);
-
- if (current_target && current_target == current_target_window_ &&
- event.type() != ET_POINTER_UP) {
- QueueOperation(current_target, OperationType::OVER, event_flags,
- screen_position);
- } else if (current_target != current_target_window_) {
- if (current_target_window_) {
- QueueOperation(current_target_window_, OperationType::LEAVE, event_flags,
- screen_position);
- }
-
- if (current_target) {
- // TODO(erg): If we have a queued LEAVE operation, does this turn into a
- // noop?
- QueueOperation(current_target, OperationType::ENTER, event_flags,
- screen_position);
- }
-
- SetCurrentTargetWindow(current_target);
- } else if (event.type() != ET_POINTER_UP) {
- DVLOG(1) << "Performing no action for pointer event at "
- << screen_position.ToString()
- << "! current_target=" << current_target;
- }
-
- if (event.type() == ET_POINTER_UP) {
- if (current_target) {
- QueueOperation(current_target, OperationType::DROP, event_flags,
- screen_position);
- waiting_for_final_drop_response_ = true;
- } else {
- // The pointer was released over no window or a window that doesn't
- // accept drags.
- MessageDragCompleted(false, ui::mojom::kDropEffectNone);
- }
- }
-
- return true;
-}
-
-void DragController::OnWillDestroyDragTargetConnection(
- DragTargetConnection* connection) {
- called_on_drag_mime_types_.erase(connection);
-}
-
-void DragController::MessageDragCompleted(bool success,
- DropEffect action_taken) {
- DVLOG(1) << "Drag Completed: success=" << success
- << ", action_taken=" << action_taken;
- for (DragTargetConnection* connection : called_on_drag_mime_types_)
- connection->PerformOnDragDropDone();
- called_on_drag_mime_types_.clear();
-
- source_->OnDragCompleted(success, action_taken);
- // |this| may be deleted now.
-}
-
-size_t DragController::GetSizeOfQueueForWindow(ServerWindow* window) {
- auto it = window_state_.find(window);
- if (it == window_state_.end())
- return 0u;
- if (it->second.waiting_on_reply == OperationType::NONE)
- return 0u;
- if (it->second.queued_operation.type == OperationType::NONE)
- return 1u;
- return 2u;
-}
-
-void DragController::SetWindowDropOperations(ServerWindow* window,
- DropEffectBitmask bitmask) {
- WindowState& state = window_state_[window];
- state.bitmask = bitmask;
-
- if (current_target_window_ == window) {
- current_cursor_ = CursorForEffectBitmask(bitmask);
- cursor_updater_->OnDragCursorUpdated();
- }
-}
-
-ui::CursorData DragController::CursorForEffectBitmask(
- DropEffectBitmask bitmask) {
- DropEffectBitmask combined = bitmask & drag_operations_;
- return combined == ui::mojom::kDropEffectNone
- ? ui::CursorData(ui::CursorType::kNoDrop)
- : ui::CursorData(ui::CursorType::kCopy);
-}
-
-void DragController::SetCurrentTargetWindow(ServerWindow* current_target) {
- current_target_window_ = current_target;
-
- if (current_target_window_) {
- // Immediately set the cursor to the last known set of operations (which
- // could be none).
- WindowState& state = window_state_[current_target_window_];
- current_cursor_ = CursorForEffectBitmask(state.bitmask);
- } else {
- // Can't drop in empty areas.
- current_cursor_ = ui::CursorData(ui::CursorType::kNoDrop);
- }
-
- cursor_updater_->OnDragCursorUpdated();
-}
-
-void DragController::EnsureWindowObserved(ServerWindow* window) {
- if (!window)
- return;
-
- WindowState& state = window_state_[window];
- if (!state.observed) {
- state.observed = true;
- window->AddObserver(this);
- }
-}
-
-void DragController::QueueOperation(ServerWindow* window,
- OperationType type,
- uint32_t event_flags,
- const gfx::Point& screen_position) {
- DVLOG(2) << "Queueing operation " << ToString(type) << " to " << window;
-
- // If this window doesn't have the mime data, send it.
- DragTargetConnection* connection = source_->GetDragTargetForWindow(window);
- if (connection != source_connection_ &&
- !base::ContainsKey(called_on_drag_mime_types_, connection)) {
- connection->PerformOnDragDropStart(mime_data_);
- called_on_drag_mime_types_.insert(connection);
- }
-
- WindowState& state = window_state_[window];
- // Set the queued operation to the incoming.
- state.queued_operation = {type, event_flags, screen_position};
-
- if (state.waiting_on_reply == OperationType::NONE) {
- // Send the operation immediately.
- DispatchOperation(window, &state);
- }
-}
-
-void DragController::DispatchOperation(ServerWindow* target,
- WindowState* state) {
- DragTargetConnection* connection = source_->GetDragTargetForWindow(target);
-
- DCHECK_EQ(OperationType::NONE, state->waiting_on_reply);
- Operation& op = state->queued_operation;
- switch (op.type) {
- case OperationType::NONE: {
- // NONE case to silence the compiler.
- NOTREACHED();
- break;
- }
- case OperationType::ENTER: {
- std::unique_ptr<ServerWindowTracker> tracker =
- std::make_unique<ServerWindowTracker>();
- tracker->Add(target);
- connection->PerformOnDragEnter(
- target, op.event_flags, op.screen_position, drag_operations_,
- base::Bind(&DragController::OnDragStatusCompleted,
- weak_factory_.GetWeakPtr(), base::Passed(&tracker)));
- state->waiting_on_reply = OperationType::ENTER;
- break;
- }
- case OperationType::OVER: {
- std::unique_ptr<ServerWindowTracker> tracker =
- std::make_unique<ServerWindowTracker>();
- tracker->Add(target);
- connection->PerformOnDragOver(
- target, op.event_flags, op.screen_position, drag_operations_,
- base::Bind(&DragController::OnDragStatusCompleted,
- weak_factory_.GetWeakPtr(), base::Passed(&tracker)));
- state->waiting_on_reply = OperationType::OVER;
- break;
- }
- case OperationType::LEAVE: {
- connection->PerformOnDragLeave(target);
- state->waiting_on_reply = OperationType::NONE;
- break;
- }
- case OperationType::DROP: {
- std::unique_ptr<ServerWindowTracker> tracker =
- std::make_unique<ServerWindowTracker>();
- tracker->Add(target);
- connection->PerformOnCompleteDrop(
- target, op.event_flags, op.screen_position, drag_operations_,
- base::Bind(&DragController::OnDragDropCompleted,
- weak_factory_.GetWeakPtr(), base::Passed(&tracker)));
- state->waiting_on_reply = OperationType::DROP;
- break;
- }
- }
-
- state->queued_operation = {OperationType::NONE, 0, gfx::Point()};
-}
-
-void DragController::OnRespondToOperation(ServerWindow* window) {
- WindowState& state = window_state_[window];
- DCHECK_NE(OperationType::NONE, state.waiting_on_reply);
- state.waiting_on_reply = OperationType::NONE;
- if (state.queued_operation.type != OperationType::NONE)
- DispatchOperation(window, &state);
-}
-
-void DragController::OnDragStatusCompleted(
- std::unique_ptr<ServerWindowTracker> tracker,
- DropEffectBitmask bitmask) {
- if (tracker->windows().empty()) {
- // The window has been deleted and its queue is empty.
- return;
- }
-
- // We must remove the completed item.
- OnRespondToOperation(*(tracker->windows().begin()));
- SetWindowDropOperations(*(tracker->windows().begin()), bitmask);
-}
-
-void DragController::OnDragDropCompleted(
- std::unique_ptr<ServerWindowTracker> tracker,
- DropEffect action) {
- if (tracker->windows().empty()) {
- // The window has been deleted after we sent the drop message. It's really
- // hard to recover from this so just signal to the source that our drag
- // failed.
- MessageDragCompleted(false, ui::mojom::kDropEffectNone);
- return;
- }
-
- OnRespondToOperation(*(tracker->windows().begin()));
- MessageDragCompleted(action != 0u, action);
-}
-
-void DragController::OnWindowDestroying(ServerWindow* window) {
- auto it = window_state_.find(window);
- if (it != window_state_.end()) {
- window->RemoveObserver(this);
- window_state_.erase(it);
- }
-
- if (current_target_window_ == window)
- SetCurrentTargetWindow(nullptr);
-
- if (source_window_ == window) {
- source_window_ = nullptr;
- // Our source window is being deleted, fail the drag.
- MessageDragCompleted(false, ui::mojom::kDropEffectNone);
- }
-}
-
-// static
-std::string DragController::ToString(OperationType type) {
- switch (type) {
- case OperationType::NONE:
- return "NONE";
- case OperationType::ENTER:
- return "ENTER";
- case OperationType::OVER:
- return "OVER";
- case OperationType::LEAVE:
- return "LEAVE";
- case OperationType::DROP:
- return "DROP";
- }
- NOTREACHED();
- return std::string();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/drag_controller.h b/services/ui/ws/drag_controller.h
deleted file mode 100644
index 25a5a4d..0000000
--- a/services/ui/ws/drag_controller.h
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_DRAG_CONTROLLER_H_
-#define SERVICES_UI_WS_DRAG_CONTROLLER_H_
-
-#include <map>
-#include <memory>
-#include <set>
-
-#include "base/containers/flat_map.h"
-#include "base/memory/weak_ptr.h"
-#include "services/ui/common/types.h"
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/server_window_observer.h"
-#include "services/ui/ws/server_window_tracker.h"
-
-namespace gfx {
-class Point;
-}
-
-namespace ui {
-class PointerEvent;
-
-namespace ws {
-
-namespace test {
-class DragControllerTestApi;
-}
-
-class DragCursorUpdater;
-class DragSource;
-class DragTargetConnection;
-
-// A single ui::mojom::kDropEffect operation.
-using DropEffect = uint32_t;
-
-// A bitmask of ui::mojom::kDropEffect operations.
-using DropEffectBitmask = uint32_t;
-
-// Represents all the data around the current ongoing drag operation.
-//
-// There should only be one instance of this class per userid. The
-// WindowManagerState's EventDispatcher creates and owns this instance.
-class DragController : public ServerWindowObserver {
- public:
- DragController(
- DragCursorUpdater* cursor_updater,
- DragSource* source,
- ServerWindow* source_window,
- DragTargetConnection* source_connection,
- int32_t drag_pointer,
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data,
- DropEffectBitmask drag_operations);
- ~DragController() override;
-
- const ui::CursorData& current_cursor() const { return current_cursor_; }
-
- // Cancels the current drag, ie, due to the user pressing Escape.
- void Cancel();
-
- // Responds to a pointer move/release event. Returns true if the event was
- // handled by the drag.
- bool DispatchPointerEvent(const ui::PointerEvent& event,
- ServerWindow* current_target);
-
- void OnWillDestroyDragTargetConnection(DragTargetConnection* connection);
-
- private:
- friend class test::DragControllerTestApi;
- enum class OperationType { NONE, ENTER, OVER, LEAVE, DROP };
- struct Operation;
- struct WindowState;
-
- // Notifies all windows we messaged that the drag is finished, and then tell
- // |source| the result.
- void MessageDragCompleted(bool success, DropEffect action_taken);
-
- // Returns the number of events on |window|. A value of 1 means that there's
- // a single event outstanding that we're waiting for a response from the
- // client, all values over 1 are queued and will be dispatched when the event
- // in the front of the queue gets a response.
- size_t GetSizeOfQueueForWindow(ServerWindow* window);
-
- // Sets |current_target_window_| to |current_target|, making sure that we add
- // and release ServerWindow observers correctly.
- void SetCurrentTargetWindow(ServerWindow* current_target);
-
- // Updates the possible cursor effects for |window|. |bitmask| is a
- // bitmask of the current valid drag operations.
- void SetWindowDropOperations(ServerWindow* window, DropEffectBitmask bitmask);
-
- // Returns the cursor for the window |bitmask|, adjusted for types that the
- // drag source allows.
- ui::CursorData CursorForEffectBitmask(DropEffectBitmask bitmask);
-
- // Ensure that |window| has an entry in |window_state_| and that we're an
- // observer.
- void EnsureWindowObserved(ServerWindow* window);
-
- void QueueOperation(ServerWindow* window,
- OperationType type,
- uint32_t event_flags,
- const gfx::Point& screen_position);
- void DispatchOperation(ServerWindow* window, WindowState* state);
- void OnRespondToOperation(ServerWindow* window);
-
- // Callback methods. |tracker| contains the window being queried and is null
- // if the window was destroyed while waiting for client.
- void OnDragStatusCompleted(std::unique_ptr<ServerWindowTracker> tracker,
- DropEffectBitmask bitmask);
- void OnDragDropCompleted(std::unique_ptr<ServerWindowTracker> tracker,
- DropEffect action);
-
- // ServerWindowObserver:
- void OnWindowDestroying(ServerWindow* window) override;
-
- static std::string ToString(OperationType type);
-
- // Our owner.
- DragSource* source_;
-
- // Object to notify about all cursor changes.
- DragCursorUpdater* cursor_updater_;
-
- // A bit-field of acceptable drag operations offered by the source.
- const DropEffectBitmask drag_operations_;
-
- // Only act on pointer events that meet this id.
- const int32_t drag_pointer_id_;
-
- // The current mouse cursor during the drag.
- ui::CursorData current_cursor_;
-
- // Sending OnDragOver() to our |source_| destroys us; there is a period where
- // we have to continue to exist, but not process any more pointer events.
- bool waiting_for_final_drop_response_ = false;
-
- ServerWindow* source_window_;
- ServerWindow* current_target_window_ = nullptr;
-
- // The target connection that |source_window_| is part of.
- DragTargetConnection* source_connection_;
-
- // A list of the offered mime types.
- base::flat_map<std::string, std::vector<uint8_t>> mime_data_;
-
- // We need to keep track of state on a per window basis. A window being in
- // this map means that we're observing it. WindowState also keeps track of
- // what type of operation we're waiting for a response from the window's
- // client, along with a queued operation to send when we get a reply.
- std::map<ServerWindow*, WindowState> window_state_;
-
- // A set of DragTargetConnections* which have received the
- // PerformOnDragMimeTypes() call.
- std::set<DragTargetConnection*> called_on_drag_mime_types_;
-
- base::WeakPtrFactory<DragController> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(DragController);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DRAG_CONTROLLER_H_
diff --git a/services/ui/ws/drag_controller_unittest.cc b/services/ui/ws/drag_controller_unittest.cc
deleted file mode 100644
index cdd5944..0000000
--- a/services/ui/ws/drag_controller_unittest.cc
+++ /dev/null
@@ -1,684 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/drag_controller.h"
-
-#include <map>
-#include <memory>
-#include <utility>
-
-#include "base/containers/queue.h"
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "services/ui/ws/drag_source.h"
-#include "services/ui/ws/drag_target_connection.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/events/base_event_utils.h"
-
-namespace ui {
-namespace ws {
-
-enum class QueuedType { NONE, ENTER, OVER, LEAVE, DROP };
-
-class DragControllerTest;
-
-// All the classes to represent a window.
-class DragTestWindow : public DragTargetConnection {
- public:
- struct DragEvent {
- QueuedType type;
- uint32_t key_state;
- gfx::Point cursor_offset;
- uint32_t effect_bitmask;
- base::Callback<void(uint32_t)> callback;
- };
-
- DragTestWindow(DragControllerTest* parent,
- TestServerWindowDelegate* window_delegate,
- const viz::FrameSinkId& id)
- : parent_(parent),
- window_delegate_(window_delegate),
- window_(window_delegate_, id) {
- window_.SetCanAcceptDrops(true);
- }
- ~DragTestWindow() override;
-
- TestServerWindowDelegate* delegate() { return window_delegate_; }
- ServerWindow* window() { return &window_; }
-
- QueuedType queue_response_type() {
- if (queued_callbacks_.empty())
- return QueuedType::NONE;
- return queued_callbacks_.front().type;
- }
-
- const DragEvent& queue_front() { return queued_callbacks_.front(); }
-
- size_t queue_size() { return queued_callbacks_.size(); }
-
- uint32_t times_received_drag_drop_start() {
- return times_received_drag_drop_start_;
- }
-
- void SetParent(DragTestWindow* p) { p->window_.Add(&window_); }
-
- void OptOutOfDrag() { window_.SetCanAcceptDrops(false); }
-
- // Calls the callback at the front of the queue.
- void Respond(bool respond_with_effect) {
- if (queued_callbacks_.size()) {
- if (!queued_callbacks_.front().callback.is_null()) {
- queued_callbacks_.front().callback.Run(
- respond_with_effect ? queued_callbacks_.front().effect_bitmask : 0);
- }
-
- queued_callbacks_.pop();
- }
- }
-
- // Overridden from DragTestConnection:
- void PerformOnDragDropStart(
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data)
- override {
- times_received_drag_drop_start_++;
- mime_data_ = mime_data;
- }
-
- void PerformOnDragEnter(
- const ServerWindow* window,
- uint32_t key_state,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) override {
- DCHECK_EQ(window, &window_);
- queued_callbacks_.push({QueuedType::ENTER, key_state, cursor_offset,
- effect_bitmask, callback});
- }
-
- void PerformOnDragOver(
- const ServerWindow* window,
- uint32_t key_state,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) override {
- DCHECK_EQ(window, &window_);
- queued_callbacks_.push(
- {QueuedType::OVER, key_state, cursor_offset, effect_bitmask, callback});
- }
-
- void PerformOnDragLeave(const ServerWindow* window) override {
- DCHECK_EQ(window, &window_);
- queued_callbacks_.push({QueuedType::LEAVE, 0, gfx::Point(), 0,
- base::Callback<void(uint32_t)>()});
- }
-
- void PerformOnCompleteDrop(
- const ServerWindow* window,
- uint32_t key_state,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) override {
- DCHECK_EQ(window, &window_);
- queued_callbacks_.push(
- {QueuedType::DROP, key_state, cursor_offset, effect_bitmask, callback});
- }
-
- void PerformOnDragDropDone() override { mime_data_.clear(); }
-
- private:
- DragControllerTest* parent_;
- TestServerWindowDelegate* window_delegate_;
- ServerWindow window_;
- base::flat_map<std::string, std::vector<uint8_t>> mime_data_;
- uint32_t times_received_drag_drop_start_ = 0;
-
- base::queue<DragEvent> queued_callbacks_;
-};
-
-class DragControllerTest : public testing::Test,
- public DragCursorUpdater,
- public DragSource {
- public:
- std::unique_ptr<DragTestWindow> BuildWindow() {
- viz::FrameSinkId id(1, ++window_id_);
- std::unique_ptr<DragTestWindow> p =
- std::make_unique<DragTestWindow>(this, window_delegate_.get(), id);
- connection_by_window_[p->window()] = p.get();
- return p;
- }
-
- void StartDragOperation(
- DragTestWindow* window,
- uint32_t drag_operations) {
- window->PerformOnDragDropStart(
- base::flat_map<std::string, std::vector<uint8_t>>());
- drag_operation_ = std::make_unique<DragController>(
- this, this, window->window(), window, MouseEvent::kMousePointerId,
- base::flat_map<std::string, std::vector<uint8_t>>(), drag_operations);
-
- // It would be nice if we could just let the observer method fire, but it
- // fires during the constructor when we haven't assigned the unique_ptr
- // yet.
- cursor_ = drag_operation_->current_cursor().cursor_type();
- }
-
- void DispatchDrag(DragTestWindow* window,
- bool mouse_released,
- uint32_t flags,
- const gfx::Point& position) {
- ui::PointerEvent event(
- ui::MouseEvent(mouse_released ? ET_MOUSE_RELEASED : ET_MOUSE_PRESSED,
- position, position, ui::EventTimeForNow(), flags, 0));
- drag_operation_->DispatchPointerEvent(event,
- window ? window->window() : nullptr);
- }
-
- void DispatchDragWithPointer(DragTestWindow* window,
- int32_t drag_pointer,
- bool mouse_released,
- uint32_t flags,
- const gfx::Point& position) {
- ui::PointerEvent event(
- ET_POINTER_DOWN, position, position, flags, 0,
- PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE, drag_pointer),
- base::TimeTicks());
- drag_operation_->DispatchPointerEvent(event,
- window ? window->window() : nullptr);
- }
-
- void OnTestWindowDestroyed(DragTestWindow* test_window) {
- drag_operation_->OnWillDestroyDragTargetConnection(test_window);
- connection_by_window_.erase(test_window->window());
- }
-
- DragController* drag_operation() const { return drag_operation_.get(); }
-
- const base::Optional<uint32_t>& drag_completed_action() {
- return drag_completed_action_;
- }
- const base::Optional<bool>& drag_completed_value() {
- return drag_completed_value_;
- }
-
- ui::CursorType cursor_type() const { return cursor_; }
-
- private:
- // Overridden from testing::Test:
- void SetUp() override {
- testing::Test::SetUp();
-
- window_delegate_ = std::make_unique<TestServerWindowDelegate>(
- ws_test_helper_.window_server()->GetVizHostProxy());
- root_window_ = std::make_unique<ServerWindow>(window_delegate_.get(),
- viz::FrameSinkId(1, 2));
- window_delegate_->set_root_window(root_window_.get());
- root_window_->SetVisible(true);
- }
-
- void TearDown() override {
- drag_operation_.reset();
- root_window_.reset();
- window_delegate_.reset();
-
- DCHECK(connection_by_window_.empty());
-
- testing::Test::TearDown();
- }
-
- // Overridden from DragCursorUpdater:
- void OnDragCursorUpdated() override {
- if (drag_operation_)
- cursor_ = drag_operation_->current_cursor().cursor_type();
- }
-
- // Overridden from DragControllerSource:
- void OnDragMoved(const gfx::Point& location) override {}
-
- void OnDragCompleted(bool success, uint32_t action_taken) override {
- drag_completed_action_ = action_taken;
- drag_completed_value_ = success;
- }
-
- DragTargetConnection* GetDragTargetForWindow(
- const ServerWindow* window) override {
- auto it = connection_by_window_.find(const_cast<ServerWindow*>(window));
- if (it == connection_by_window_.end())
- return nullptr;
- return it->second;
- }
-
- int window_id_ = 3;
-
- test::WindowServerTestHelper ws_test_helper_;
-
- ui::CursorType cursor_;
-
- std::map<ServerWindow*, DragTargetConnection*> connection_by_window_;
-
- std::unique_ptr<TestServerWindowDelegate> window_delegate_;
- std::unique_ptr<ServerWindow> root_window_;
-
- std::unique_ptr<DragController> drag_operation_;
-
- base::Optional<uint32_t> drag_completed_action_;
- base::Optional<bool> drag_completed_value_;
-};
-
-DragTestWindow::~DragTestWindow() {
- parent_->OnTestWindowDestroyed(this);
-}
-
-TEST_F(DragControllerTest, SimpleDragDrop) {
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- EXPECT_EQ(ui::CursorType::kNoDrop, cursor_type());
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
- window->Respond(true);
-
- // (Even though we're doing a move, the cursor name is COPY.)
- EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
- window->Respond(true);
-
- DispatchDrag(window.get(), true, 0, gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::DROP, window->queue_response_type());
- window->Respond(true);
-
- EXPECT_EQ(ui::mojom::kDropEffectMove,
- drag_completed_action().value_or(ui::mojom::kDropEffectNone));
- EXPECT_TRUE(drag_completed_value().value_or(false));
-}
-
-TEST_F(DragControllerTest, FailsOnWindowSayingNo) {
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
- window->Respond(true);
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
- window->Respond(true);
-
- DispatchDrag(window.get(), true, 0, gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::DROP, window->queue_response_type());
-
- // Unlike SimpleDragDrop, respond with kDropEffectNone, which should make the
- // drag fail.
- window->Respond(false);
-
- EXPECT_EQ(ui::mojom::kDropEffectNone,
- drag_completed_action().value_or(ui::mojom::kDropEffectCopy));
- EXPECT_FALSE(drag_completed_value().value_or(true));
-}
-
-TEST_F(DragControllerTest, OnlyDeliverMimeDataOnce) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
-
- // The client lib is responsible for sending the data to the window that's
- // the drag source to minimize IPC.
- EXPECT_EQ(0u, window1->times_received_drag_drop_start());
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
- EXPECT_EQ(1u, window1->times_received_drag_drop_start());
- DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(1u, window1->times_received_drag_drop_start());
- window1->Respond(true);
-
- // Window2 doesn't receive the drag data until mouse is over it.
- EXPECT_EQ(0u, window2->times_received_drag_drop_start());
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(2, 2));
- EXPECT_EQ(1u, window2->times_received_drag_drop_start());
-
- // Moving back to the source window doesn't send an additional start message.
- DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(1u, window1->times_received_drag_drop_start());
-
- // Moving back to window2 doesn't send an additional start message.
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(1u, window2->times_received_drag_drop_start());
-}
-
-TEST_F(DragControllerTest, DeliverMessageToParent) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
- std::unique_ptr<DragTestWindow> window3 = BuildWindow();
-
- window3->SetParent(window2.get());
- window3->OptOutOfDrag();
-
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
-
- // Dispatching a drag to window3 (which has can accept drags off) redirects
- // to window2, which is its parent.
- DispatchDrag(window3.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(1u, window2->times_received_drag_drop_start());
-}
-
-TEST_F(DragControllerTest, FailWhenDropOverNoWindow) {
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
- window->Respond(true);
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
- window->Respond(true);
-
- DispatchDrag(nullptr, true, 0, gfx::Point(2, 2));
- // Moving outside of |window| should result in |window| getting a leave.
- EXPECT_EQ(QueuedType::LEAVE, window->queue_response_type());
- window->Respond(true);
-
- EXPECT_FALSE(drag_completed_value().value_or(true));
-}
-
-TEST_F(DragControllerTest, EnterLeaveWhenMovingBetweenTwoWindows) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
-
- DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type());
- window1->Respond(true);
-
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
- EXPECT_EQ(QueuedType::LEAVE, window1->queue_response_type());
- window1->Respond(true);
- window2->Respond(true);
-}
-
-TEST_F(DragControllerTest, DeadWindowDoesntBlock) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
-
- test::DragControllerTestApi api(drag_operation());
-
- // Simulate a dead window by giving it a few messages, but don't respond to
- // them.
- DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(2, 2));
- EXPECT_EQ(1u, window1->queue_size());
- EXPECT_EQ(2u, api.GetSizeOfQueueForWindow(window1->window()));
-
- // Moving to window2 should dispatch the enter event to it immediately.
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(3, 3));
- EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
- EXPECT_EQ(1u, window1->queue_size());
-}
-
-TEST_F(DragControllerTest, EnterToOverQueued) {
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
- ASSERT_EQ(1u, window->queue_size());
- EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
- // Don't respond.
-
- // We don't receive another message since we haven't acknowledged the first.
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 2));
- ASSERT_EQ(1u, window->queue_size());
-
- // Responding causes us to receive our next event.
- window->Respond(true);
- ASSERT_EQ(1u, window->queue_size());
- EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
-}
-
-TEST_F(DragControllerTest, CoalesceMouseOverEvents) {
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 2));
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 3));
-
- // Responding to the first delivers us the last mouse over event's position.
- window->Respond(true);
- ASSERT_EQ(1u, window->queue_size());
- EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
- EXPECT_EQ(gfx::Point(2, 3), window->queue_front().cursor_offset);
-
- // There are no queued events because they were coalesced.
- window->Respond(true);
- EXPECT_EQ(0u, window->queue_size());
-}
-
-TEST_F(DragControllerTest, RemovePendingMouseOversOnLeave) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
-
- // Enter
- DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type());
-
- // Over
- DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
-
- // Leave
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
-
- // The window finally responds to the enter message; we should not receive
- // any over messages since we didn't respond to the enter message in time.
- window1->Respond(true);
- ASSERT_EQ(1u, window1->queue_size());
- EXPECT_EQ(QueuedType::LEAVE, window1->queue_response_type());
-}
-
-TEST_F(DragControllerTest, TargetWindowClosedWhileDrag) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
-
- test::DragControllerTestApi api(drag_operation());
-
- // Send some events to |window|.
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
-
- ServerWindow* server_window = window2->window();
-
- // Ensure that DragController is waiting for a response from |window|.
- EXPECT_EQ(2u, api.GetSizeOfQueueForWindow(server_window));
- EXPECT_EQ(server_window, api.GetCurrentTarget());
-
- // Force the destruction of |window.window|.
- window2.reset();
-
- // DragController doesn't know anything about the server window now.
- EXPECT_EQ(0u, api.GetSizeOfQueueForWindow(server_window));
- EXPECT_EQ(nullptr, api.GetCurrentTarget());
-
- // But a target window closing out from under us doesn't fail the drag.
- EXPECT_FALSE(drag_completed_value().has_value());
-}
-
-TEST_F(DragControllerTest, TargetWindowClosedResetsCursor) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
- EXPECT_EQ(ui::CursorType::kNoDrop, cursor_type());
-
- // Send some events to |window|.
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
- window2->Respond(true);
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- window2->Respond(true);
- EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
-
- // Force the destruction of |window.window|.
- window2.reset();
-
- // The cursor no loner indicates that it can drop on |window2|.
- EXPECT_EQ(ui::CursorType::kNoDrop, cursor_type());
-}
-
-TEST_F(DragControllerTest, SourceWindowClosedWhileDrag) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
-
- test::DragControllerTestApi api(drag_operation());
-
- // Send some events to |windoww|.
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
-
- ServerWindow* server_window = window2->window();
-
- // Ensure that DragController is waiting for a response from |window2|.
- EXPECT_EQ(2u, api.GetSizeOfQueueForWindow(server_window));
- EXPECT_EQ(server_window, api.GetCurrentTarget());
-
- // Force the destruction of the source window.
- window1.reset();
-
- // The source window going away fails the drag.
- EXPECT_FALSE(drag_completed_value().value_or(true));
-}
-
-TEST_F(DragControllerTest, DontQueueEventsAfterDrop) {
- // The DragController needs to stick around to coordinate the drop, but
- // it should ignore further mouse events during this time.
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- test::DragControllerTestApi api(drag_operation());
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
- window->Respond(true);
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
- window->Respond(true);
-
- DispatchDrag(window.get(), true, 0, gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::DROP, window->queue_response_type());
- EXPECT_EQ(1u, api.GetSizeOfQueueForWindow(window->window()));
-
- // Further located events don't result in additional drag messages.
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
- EXPECT_EQ(1u, api.GetSizeOfQueueForWindow(window->window()));
-}
-
-TEST_F(DragControllerTest, CancelDrag) {
- // The DragController needs to stick around to coordinate the drop, but
- // it should ignore further mouse events during this time.
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
- window->Respond(true);
-
- drag_operation()->Cancel();
-
- EXPECT_FALSE(drag_completed_value().value_or(true));
-}
-
-TEST_F(DragControllerTest, IgnoreEventsFromOtherPointers) {
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- // This starts the operation with MouseEvent::kMousePointerId.
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- // Ignore events from pointer 5.
- DispatchDragWithPointer(window.get(), 5, false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- ASSERT_EQ(0u, window->queue_size());
-}
-
-TEST_F(DragControllerTest, RejectingWindowHasProperCursor) {
- std::unique_ptr<DragTestWindow> window = BuildWindow();
- StartDragOperation(window.get(), ui::mojom::kDropEffectMove);
-
- EXPECT_EQ(ui::CursorType::kNoDrop, cursor_type());
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window->queue_response_type());
- window->Respond(true);
-
- EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
-
- DispatchDrag(window.get(), false, ui::EF_LEFT_MOUSE_BUTTON, gfx::Point(2, 2));
- EXPECT_EQ(QueuedType::OVER, window->queue_response_type());
-
- // At this point, we respond with no available drag actions at this pixel.
- window->Respond(false);
- EXPECT_EQ(ui::CursorType::kNoDrop, cursor_type());
-}
-
-TEST_F(DragControllerTest, ResopnseFromOtherWindowDoesntChangeCursor) {
- std::unique_ptr<DragTestWindow> window1 = BuildWindow();
- std::unique_ptr<DragTestWindow> window2 = BuildWindow();
- StartDragOperation(window1.get(), ui::mojom::kDropEffectMove);
-
- // Send some events to |window2|.
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
- EXPECT_EQ(QueuedType::ENTER, window2->queue_response_type());
- DispatchDrag(window2.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(1, 1));
-
- EXPECT_EQ(ui::CursorType::kNoDrop, cursor_type());
-
- // Now enter |window1|, and respond.
- DispatchDrag(window1.get(), false, ui::EF_LEFT_MOUSE_BUTTON,
- gfx::Point(5, 5));
- EXPECT_EQ(QueuedType::ENTER, window1->queue_response_type());
- window1->Respond(true);
-
- EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
-
- // Window 2 responding negatively to its queued messages shouldn't change the
- // cursor.
- window2->Respond(false);
-
- EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/drag_cursor_updater.h b/services/ui/ws/drag_cursor_updater.h
deleted file mode 100644
index dcc945a..0000000
--- a/services/ui/ws/drag_cursor_updater.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_DRAG_CURSOR_UPDATER_H_
-#define SERVICES_UI_WS_DRAG_CURSOR_UPDATER_H_
-
-namespace ui {
-namespace ws {
-
-// An interface for the DragController to signal that the cursor has changed.
-class DragCursorUpdater {
- public:
- virtual void OnDragCursorUpdated() = 0;
-
- protected:
- virtual ~DragCursorUpdater() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DRAG_CURSOR_UPDATER_H_
diff --git a/services/ui/ws/drag_source.h b/services/ui/ws/drag_source.h
deleted file mode 100644
index cb45039..0000000
--- a/services/ui/ws/drag_source.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_DRAG_SOURCE_H_
-#define SERVICES_UI_WS_DRAG_SOURCE_H_
-
-namespace ui {
-namespace ws {
-
-class DragTargetConnection;
-class ServerWindow;
-
-// An interface implemented by the object that caused a DragController to
-// exist, and which acts as a delegate to it.
-class DragSource {
- public:
- virtual ~DragSource() {}
-
- // Called during a drag operation when the mouse cursor moves.
- virtual void OnDragMoved(const gfx::Point& location) = 0;
-
- // Called when a drag operation is completed. |success| is true when a target
- // window signaled the successful completion of the drag, false in all other
- // cases where a drag was aborted at any step in the process. |action_taken|
- // is one of the kDropEffect constants in window_tree_constants.mojom.
- virtual void OnDragCompleted(bool success, uint32_t action_taken) = 0;
-
- // Returns the client connection that created |window|.
- virtual DragTargetConnection* GetDragTargetForWindow(
- const ServerWindow* window) = 0;
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DRAG_SOURCE_H_
diff --git a/services/ui/ws/drag_target_connection.h b/services/ui/ws/drag_target_connection.h
deleted file mode 100644
index 06d3887..0000000
--- a/services/ui/ws/drag_target_connection.h
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_DRAG_TARGET_CONNECTION_H_
-#define SERVICES_UI_WS_DRAG_TARGET_CONNECTION_H_
-
-#include <string>
-
-#include "base/bind.h"
-#include "base/containers/flat_map.h"
-#include "ui/gfx/geometry/point.h"
-
-namespace ui {
-namespace ws {
-
-class ServerWindow;
-
-// An abstract connection which can respond to drag/drop target requests.
-//
-// The methods in this class send drag and drop messages to the client and
-// return their results through the passed in callback. From the point of view
-// of the client, the lifecycle of receiving messages are in the following
-// order:
-class DragTargetConnection {
- public:
- virtual ~DragTargetConnection() {}
-
- // On the first time that the pointer enters a window offered by this
- // connection, we send this start message with the |mime_data| of the
- // drag so that we only send this data over the connection once. We send the
- // mime data first because clients may read the payload at any time,
- // including during the enter message.
- //
- // (As an optimization, on the server side, we don't send this message to the
- // source window of the drag; the client library has already done the
- // equivalent in ui::WindowDropTarget to minimize the load of inter-process
- // communication.)
- virtual void PerformOnDragDropStart(
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data) = 0;
-
- // Next, on each time that the mouse cursor moves from one |window| to
- // another, we send a DragEnter message. The value returned by |callback| is
- // a bitmask of drop operations that can be performed at this location, in
- // terms of the ui::mojom::kDropEffect{None,Move,Copy,Link} constants.
- virtual void PerformOnDragEnter(
- const ServerWindow* window,
- uint32_t key_state,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) = 0;
-
- // For each mouse move after the initial DragEnter message, we call DragOver
- // to change the mouse location and to update what drop operations can be
- // performed.
- virtual void PerformOnDragOver(
- const ServerWindow* window,
- uint32_t key_state,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) = 0;
-
- // If the mouse cursor leaves |window|, send an DragLeave message.
- virtual void PerformOnDragLeave(const ServerWindow* window) = 0;
-
- // If the user releases the pointer over a window, send a DragDrop message,
- // which signals that the client should complete the drag. The return value
- // is which operation was performed; a non-zero callback value means the drag
- // was accepted and completed.
- virtual void PerformOnCompleteDrop(
- const ServerWindow* window,
- uint32_t key_state,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) = 0;
-
- // Finally, regardless of which window accepted (or rejected) the drop, we
- // send a done message to each connection that we sent a start message
- // to. This message is used to clear cached data from the drag.
- //
- // (Again, we don't send this message to the source window as we didn't send
- // a DragStart message; the client library handles the equivalent at its
- // layer.)
- virtual void PerformOnDragDropDone() = 0;
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_DRAG_TARGET_CONNECTION_H_
diff --git a/services/ui/ws/event_dispatcher.h b/services/ui/ws/event_dispatcher.h
deleted file mode 100644
index 200a81c..0000000
--- a/services/ui/ws/event_dispatcher.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef SERVICES_UI_WS_EVENT_DISPATCHER_H_
-#define SERVICES_UI_WS_EVENT_DISPATCHER_H_
-
-#include <stdint.h>
-
-#include "services/ui/common/types.h"
-
-namespace ui {
-
-class Event;
-
-namespace ws {
-
-class Accelerator;
-class ServerWindow;
-
-struct EventLocation;
-
-// EventDispatcher is called from EventProcessor once it determines the target
-// for events as well as accelerators.
-class EventDispatcher {
- public:
- enum class AcceleratorPhase {
- kPre,
- kPost,
- };
-
- // Called when the target Window is found for |event|.
- // |post_target_accelerator| is the accelerator to run if the target doesn't
- // handle the event. See EventProcessor for details on event processing
- // phases. |client_id| is the id of tree the event should be sent to. See
- // EventLocation for details on |event_location|. |event_location| is only
- // useful for located events.
- virtual void DispatchInputEventToWindow(
- ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const ui::Event& event,
- Accelerator* post_target_accelerator) = 0;
-
- // A matching accelerator was found for the specified phase of processing.
- // |event| is the event that the accelerator matches and |display_id|
- // identifies the display the event came in on.
- virtual void OnAccelerator(uint32_t accelerator,
- int64_t display_id,
- const ui::Event& event,
- AcceleratorPhase phase) = 0;
-
- protected:
- virtual ~EventDispatcher() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_
diff --git a/services/ui/ws/event_dispatcher_delegate.h b/services/ui/ws/event_dispatcher_delegate.h
deleted file mode 100644
index 2eea409..0000000
--- a/services/ui/ws/event_dispatcher_delegate.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef SERVICES_UI_WS_EVENT_DISPATCHER_DELEGATE_H_
-#define SERVICES_UI_WS_EVENT_DISPATCHER_DELEGATE_H_
-
-#include <stdint.h>
-
-#include "services/ui/ws/ids.h"
-
-namespace ui {
-
-class Event;
-
-namespace ws {
-
-class AsyncEventDispatcher;
-class ServerWindow;
-
-struct EventLocation;
-
-// Called at interesting stages during event dispatch.
-class EventDispatcherDelegate {
- public:
- // Called immediately before |event| is handed to EventProcessor for
- // processing
- virtual void OnWillProcessEvent(const ui::Event& event,
- const EventLocation& event_location) = 0;
-
- // Called before dispatching an event to an AsyncEventDispatcher. The delegate
- // may return a different ServerWindow to send the event to. Typically the
- // delegate will return |target|.
- virtual ServerWindow* OnWillDispatchInputEvent(
- ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const Event& event) = 0;
-
- // Called when |async_event_dispatcher| did not complete processing in a
- // reasonable amount of time.
- virtual void OnEventDispatchTimedOut(
- AsyncEventDispatcher* async_event_dispatcher) = 0;
-
- // Called when an AsyncEventDispatcher handles an event that mapped to an
- // accelerator.
- virtual void OnAsyncEventDispatcherHandledAccelerator(const Event& event,
- int64_t display_id) = 0;
-
- protected:
- virtual ~EventDispatcherDelegate() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_DISPATCHER_DELEGATE_H_
diff --git a/services/ui/ws/event_dispatcher_impl.cc b/services/ui/ws/event_dispatcher_impl.cc
deleted file mode 100644
index dd7ddd0..0000000
--- a/services/ui/ws/event_dispatcher_impl.cc
+++ /dev/null
@@ -1,411 +0,0 @@
-// Copyright 2018 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 "services/ui/ws/event_dispatcher_impl.h"
-
-#include "base/debug/debugger.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/ui/ws/accelerator.h"
-#include "services/ui/ws/async_event_dispatcher.h"
-#include "services/ui/ws/async_event_dispatcher_lookup.h"
-#include "services/ui/ws/event_dispatcher_delegate.h"
-#include "services/ui/ws/event_location.h"
-#include "services/ui/ws/event_processor.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_tracker.h"
-#include "ui/events/event.h"
-
-namespace ui {
-namespace ws {
-namespace {
-
-bool CanEventsBeCoalesced(const ui::Event& one, const ui::Event& two) {
- if (one.type() != two.type() || one.flags() != two.flags())
- return false;
-
- // TODO(sad): wheel events can also be merged.
- if (one.type() != ui::ET_POINTER_MOVED)
- return false;
-
- return one.AsPointerEvent()->pointer_details().id ==
- two.AsPointerEvent()->pointer_details().id;
-}
-
-std::unique_ptr<ui::Event> CoalesceEvents(std::unique_ptr<ui::Event> first,
- std::unique_ptr<ui::Event> second) {
- DCHECK(first->type() == ui::ET_POINTER_MOVED)
- << " Non-move events cannot be merged yet.";
- // For mouse moves, the new event just replaces the old event, but we need to
- // use the latency from the old event.
- second->set_latency(*first->latency());
- second->latency()->set_coalesced();
- return second;
-}
-
-base::TimeDelta GetDefaultAckTimerDelay() {
-#if defined(NDEBUG)
- return base::TimeDelta::FromMilliseconds(100);
-#else
- return base::TimeDelta::FromMilliseconds(1000);
-#endif
-}
-
-} // namespace
-
-// See EventDispatcherImpl::EventTask::Type::kProcessedEvent for details on
-// this.
-class EventDispatcherImpl::ProcessedEventTarget {
- public:
- ProcessedEventTarget(
- AsyncEventDispatcherLookup* async_event_dispatcher_lookup,
- ServerWindow* window,
- ClientSpecificId client_id,
- Accelerator* accelerator)
- : async_event_dispatcher_lookup_(async_event_dispatcher_lookup),
- client_id_(client_id) {
- DCHECK(async_event_dispatcher_lookup_);
- DCHECK(window);
- tracker_.Add(window);
- if (accelerator)
- accelerator_ = accelerator->GetWeakPtr();
- }
-
- ~ProcessedEventTarget() {}
-
- // Return true if the event is still valid. The event becomes invalid if
- // the window is destroyed while waiting to dispatch.
- bool IsValid() {
- return window() &&
- async_event_dispatcher_lookup_->GetAsyncEventDispatcherById(
- client_id_);
- }
-
- ServerWindow* window() {
- return tracker_.windows().empty() ? nullptr : tracker_.windows().front();
- }
-
- ClientSpecificId client_id() const { return client_id_; }
-
- base::WeakPtr<Accelerator> accelerator() { return accelerator_; }
-
- private:
- AsyncEventDispatcherLookup* async_event_dispatcher_lookup_;
- ServerWindowTracker tracker_;
- const ClientSpecificId client_id_;
- base::WeakPtr<Accelerator> accelerator_;
-
- DISALLOW_COPY_AND_ASSIGN(ProcessedEventTarget);
-};
-
-EventDispatcherImpl::InFlightEventDispatchDetails::InFlightEventDispatchDetails(
- EventDispatcherImpl* event_dispatcher,
- AsyncEventDispatcher* async_event_dispatcher,
- int64_t display_id,
- const Event& event,
- EventDispatchPhase phase)
- : async_event_dispatcher(async_event_dispatcher),
- display_id(display_id),
- event(Event::Clone(event)),
- phase(phase),
- weak_factory_(event_dispatcher) {}
-
-EventDispatcherImpl::InFlightEventDispatchDetails::
- ~InFlightEventDispatchDetails() {}
-
-// Contains data used for event processing that needs to happen. See enum for
-// details.
-struct EventDispatcherImpl::EventTask {
- enum class Type {
- // ProcessEvent() was called while waiting on a client or EventProcessor
- // to complete processing. |event| is non-null and |processed_target| is
- // null.
- kEvent,
-
- // In certain situations EventProcessor::ProcessEvent() generates more than
- // one event. When that happens, |kProcessedEvent| is used for all events
- // after the first. For example, a move may result in an exit for one
- // Window and and an enter for another Window. The event generated for the
- // enter results in an EventTask of type |kProcessedEvent|. In this case
- // both |event| and |processed_target| are valid.
- kProcessedEvent,
-
- // ScheduleCallbackWhenDoneProcessingEvents() is called while waiting on
- // a client or EventProcessor. |event| and |processed_target| are null.
- kClosure
- };
-
- EventTask() = default;
- ~EventTask() = default;
-
- Type type() const {
- if (done_closure)
- return Type::kClosure;
- if (processed_target) {
- DCHECK(event);
- return Type::kProcessedEvent;
- }
- DCHECK(event);
- return Type::kEvent;
- }
-
- std::unique_ptr<Event> event;
- std::unique_ptr<ProcessedEventTarget> processed_target;
- EventLocation event_location;
- base::OnceClosure done_closure;
-};
-
-EventDispatcherImpl::EventDispatcherImpl(
- AsyncEventDispatcherLookup* async_event_dispatcher_lookup,
- AsyncEventDispatcher* accelerator_dispatcher,
- EventDispatcherDelegate* delegate)
- : async_event_dispatcher_lookup_(async_event_dispatcher_lookup),
- accelerator_dispatcher_(accelerator_dispatcher),
- delegate_(delegate) {
- DCHECK(async_event_dispatcher_lookup_);
-}
-
-EventDispatcherImpl::~EventDispatcherImpl() = default;
-
-void EventDispatcherImpl::Init(EventProcessor* event_processor) {
- DCHECK(event_processor);
- DCHECK(!event_processor_);
- event_processor_ = event_processor;
-}
-
-void EventDispatcherImpl::ProcessEvent(ui::Event* event,
- const EventLocation& event_location) {
- // If this is still waiting for an ack from a previously sent event, then
- // queue the event so it's dispatched once the ack is received.
- if (IsProcessingEvent()) {
- if (!event_tasks_.empty() &&
- event_tasks_.back()->type() == EventTask::Type::kEvent &&
- CanEventsBeCoalesced(*event_tasks_.back()->event, *event)) {
- event_tasks_.back()->event = CoalesceEvents(
- std::move(event_tasks_.back()->event), ui::Event::Clone(*event));
- event_tasks_.back()->event_location = event_location;
- return;
- }
- QueueEvent(*event, nullptr, event_location);
- return;
- }
-
- QueueEvent(*event, nullptr, event_location);
- ProcessEventTasks();
-}
-
-bool EventDispatcherImpl::IsProcessingEvent() const {
- return in_flight_event_dispatch_details_ ||
- event_processor_->IsProcessingEvent();
-}
-
-const ui::Event* EventDispatcherImpl::GetInFlightEvent() const {
- return in_flight_event_dispatch_details_
- ? in_flight_event_dispatch_details_->event.get()
- : nullptr;
-}
-
-void EventDispatcherImpl::ScheduleCallbackWhenDoneProcessingEvents(
- base::OnceClosure closure) {
- DCHECK(closure);
- if (!IsProcessingEvent()) {
- std::move(closure).Run();
- return;
- }
-
- // TODO(sky): use make_unique (presubmit check fails on make_unique).
- std::unique_ptr<EventTask> event_task(new EventTask());
- event_task->done_closure = std::move(closure);
- event_tasks_.push(std::move(event_task));
-}
-
-void EventDispatcherImpl::OnWillDestroyAsyncEventDispatcher(
- AsyncEventDispatcher* target) {
- if (!in_flight_event_dispatch_details_ ||
- in_flight_event_dispatch_details_->async_event_dispatcher != target) {
- return;
- }
-
- // The target is going to be deleted and won't ack the event, simulate an ack
- // so we don't wait for the timer to fire.
- OnDispatchInputEventDone(mojom::EventResult::UNHANDLED);
-}
-
-void EventDispatcherImpl::ScheduleInputEventTimeout(
- AsyncEventDispatcher* async_event_dispatcher,
- int64_t display_id,
- const Event& event,
- EventDispatchPhase phase) {
- DCHECK(!in_flight_event_dispatch_details_);
- std::unique_ptr<InFlightEventDispatchDetails> details =
- std::make_unique<InFlightEventDispatchDetails>(
- this, async_event_dispatcher, display_id, event, phase);
-
- // TODO(sad): Adjust this delay, possibly make this dynamic.
- const base::TimeDelta max_delay = base::debug::BeingDebugged()
- ? base::TimeDelta::FromDays(1)
- : GetDefaultAckTimerDelay();
- details->timer.Start(
- FROM_HERE, max_delay,
- base::Bind(&EventDispatcherImpl::OnDispatchInputEventTimeout,
- details->weak_factory_.GetWeakPtr()));
- in_flight_event_dispatch_details_ = std::move(details);
-}
-
-void EventDispatcherImpl::ProcessEventTasks() {
- // Loop through |event_tasks_| stopping after dispatching the first valid
- // event.
- while (!event_tasks_.empty() && !IsProcessingEvent()) {
- std::unique_ptr<EventTask> task = std::move(event_tasks_.front());
- event_tasks_.pop();
-
- switch (task->type()) {
- case EventTask::Type::kClosure:
- std::move(task->done_closure).Run();
- break;
- case EventTask::Type::kEvent:
- delegate_->OnWillProcessEvent(*task->event, task->event_location);
- event_processor_->ProcessEvent(
- *task->event, task->event_location,
- EventProcessor::AcceleratorMatchPhase::ANY);
- break;
- case EventTask::Type::kProcessedEvent:
- if (task->processed_target->IsValid()) {
- DispatchInputEventToWindowImpl(task->processed_target->window(),
- task->processed_target->client_id(),
- task->event_location, *task->event,
- task->processed_target->accelerator());
- }
- break;
- }
- }
-}
-
-// TODO(riajiang): We might want to do event targeting for the next event while
-// waiting for the current event to be dispatched. https://crbug.com/724521
-void EventDispatcherImpl::DispatchInputEventToWindowImpl(
- ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const ui::Event& event,
- base::WeakPtr<Accelerator> accelerator) {
- DCHECK(!in_flight_event_dispatch_details_);
- DCHECK(target);
- target = delegate_->OnWillDispatchInputEvent(target, client_id,
- event_location, event);
- AsyncEventDispatcher* async_event_dispatcher =
- async_event_dispatcher_lookup_->GetAsyncEventDispatcherById(client_id);
- DCHECK(async_event_dispatcher);
- ScheduleInputEventTimeout(async_event_dispatcher, event_location.display_id,
- event, EventDispatchPhase::TARGET);
- in_flight_event_dispatch_details_->post_target_accelerator = accelerator;
-
- async_event_dispatcher->DispatchEvent(
- target, event, event_location,
- base::BindOnce(
- &EventDispatcherImpl::OnDispatchInputEventDone,
- in_flight_event_dispatch_details_->weak_factory_.GetWeakPtr()));
-}
-
-void EventDispatcherImpl::OnDispatchInputEventTimeout() {
- DCHECK(in_flight_event_dispatch_details_);
- delegate_->OnEventDispatchTimedOut(
- in_flight_event_dispatch_details_->async_event_dispatcher);
- if (in_flight_event_dispatch_details_->phase ==
- EventDispatchPhase::PRE_TARGET_ACCELERATOR) {
- OnAcceleratorDone(mojom::EventResult::UNHANDLED, {});
- } else {
- OnDispatchInputEventDone(mojom::EventResult::UNHANDLED);
- }
-}
-
-void EventDispatcherImpl::OnDispatchInputEventDone(mojom::EventResult result) {
- DCHECK(in_flight_event_dispatch_details_);
- std::unique_ptr<InFlightEventDispatchDetails> details =
- std::move(in_flight_event_dispatch_details_);
-
- if (result == mojom::EventResult::UNHANDLED &&
- details->post_target_accelerator) {
- OnAccelerator(details->post_target_accelerator->id(), details->display_id,
- *details->event, AcceleratorPhase::kPost);
- }
-
- ProcessEventTasks();
-}
-
-void EventDispatcherImpl::OnAcceleratorDone(
- mojom::EventResult result,
- const base::flat_map<std::string, std::vector<uint8_t>>& properties) {
- DCHECK(in_flight_event_dispatch_details_);
- DCHECK_EQ(EventDispatchPhase::PRE_TARGET_ACCELERATOR,
- in_flight_event_dispatch_details_->phase);
-
- std::unique_ptr<InFlightEventDispatchDetails> details =
- std::move(in_flight_event_dispatch_details_);
-
- if (result == mojom::EventResult::UNHANDLED) {
- DCHECK(details->event->IsKeyEvent());
- if (!properties.empty())
- details->event->AsKeyEvent()->SetProperties(properties);
- event_processor_->ProcessEvent(
- *details->event, EventLocation(details->display_id),
- EventProcessor::AcceleratorMatchPhase::POST_ONLY);
- } else {
- // We're not going to process the event any further, notify the delegate.
- delegate_->OnAsyncEventDispatcherHandledAccelerator(*details->event,
- details->display_id);
- ProcessEventTasks();
- }
-}
-
-void EventDispatcherImpl::QueueEvent(
- const ui::Event& event,
- std::unique_ptr<ProcessedEventTarget> processed_event_target,
- const EventLocation& event_location) {
- std::unique_ptr<EventTask> queued_event(new EventTask);
- queued_event->event = ui::Event::Clone(event);
- queued_event->processed_target = std::move(processed_event_target);
- queued_event->event_location = event_location;
- event_tasks_.push(std::move(queued_event));
-}
-
-void EventDispatcherImpl::DispatchInputEventToWindow(
- ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const Event& event,
- Accelerator* accelerator) {
- if (in_flight_event_dispatch_details_) {
- std::unique_ptr<ProcessedEventTarget> processed_event_target =
- std::make_unique<ProcessedEventTarget>(async_event_dispatcher_lookup_,
- target, client_id, accelerator);
- QueueEvent(event, std::move(processed_event_target), event_location);
- return;
- }
-
- base::WeakPtr<Accelerator> weak_accelerator;
- if (accelerator)
- weak_accelerator = accelerator->GetWeakPtr();
- DispatchInputEventToWindowImpl(target, client_id, event_location, event,
- weak_accelerator);
-}
-
-void EventDispatcherImpl::OnAccelerator(uint32_t accelerator_id,
- int64_t display_id,
- const ui::Event& event,
- AcceleratorPhase phase) {
- const bool needs_ack = phase == AcceleratorPhase::kPre;
- AsyncEventDispatcher::AcceleratorCallback ack_callback;
- if (needs_ack) {
- ScheduleInputEventTimeout(accelerator_dispatcher_, display_id, event,
- EventDispatchPhase::PRE_TARGET_ACCELERATOR);
- ack_callback = base::BindOnce(
- &EventDispatcherImpl::OnAcceleratorDone,
- in_flight_event_dispatch_details_->weak_factory_.GetWeakPtr());
- }
- accelerator_dispatcher_->DispatchAccelerator(accelerator_id, event,
- std::move(ack_callback));
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/event_dispatcher_impl.h b/services/ui/ws/event_dispatcher_impl.h
deleted file mode 100644
index 26ec81fd..0000000
--- a/services/ui/ws/event_dispatcher_impl.h
+++ /dev/null
@@ -1,195 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef SERVICES_UI_WS_EVENT_DISPATCHER_IMPL_H_
-#define SERVICES_UI_WS_EVENT_DISPATCHER_IMPL_H_
-
-#include <stdint.h>
-
-#include <string>
-#include <vector>
-
-#include "base/containers/flat_map.h"
-#include "base/containers/queue.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "base/timer/timer.h"
-#include "services/ui/ws/event_dispatcher.h"
-#include "services/ui/ws/event_processor_delegate.h"
-
-namespace ui {
-
-class Event;
-
-namespace mojom {
-enum class EventResult;
-}
-
-namespace ws {
-
-class EventDispatcherDelegate;
-class EventProcessor;
-class AsyncEventDispatcher;
-class AsyncEventDispatcherLookup;
-
-struct EventLocation;
-
-// EventDispatcherImpl is the entry point for event related processing done by
-// the Window Service. Events received from the platform are forwarded to
-// ProcessEvent(). ProcessEvent() may queue the event for later processing (if
-// waiting for an event to be dispatched, or waiting on EventProcessor to
-// complete processing). EventDispatcherImpl ultimately calls to EventProcessor
-// for processing. EventDispatcherImpl uses AsyncEventDispatcher for dispatch
-// to clients.
-class EventDispatcherImpl : public EventDispatcher {
- public:
- // |accelerator_dispatcher| must outlive this class.
- EventDispatcherImpl(AsyncEventDispatcherLookup* async_event_dispatcher_lookup,
- AsyncEventDispatcher* accelerator_dispatcher,
- EventDispatcherDelegate* delegate);
- ~EventDispatcherImpl() override;
-
- void Init(EventProcessor* processor);
-
- // Processes an event. If IsProcessingEvent() is true, this queues up the
- // event for later processing. This doesn't take ownership of |event|, but it
- // may modify it.
- void ProcessEvent(ui::Event* event, const EventLocation& event_location);
-
- // Returns true if actively processing an event. This includes waiting for an
- // AsyncEventDispatcher to respond to an event.
- bool IsProcessingEvent() const;
-
- // Returns the event this EventDispatcherImpl is waiting on a response for, or
- // null if not waiting on an AsyncEventDispatcher.
- const ui::Event* GetInFlightEvent() const;
-
- // Notifies |closure| once done processing currently queued events. This
- // notifies |closure| immediately if IsProcessingEvent() returns false.
- void ScheduleCallbackWhenDoneProcessingEvents(base::OnceClosure closure);
-
- // Called when an AsyncEventDispatcher is destroyed.
- // TODO(sky): AsyncEventDispatcher should support observers.
- void OnWillDestroyAsyncEventDispatcher(AsyncEventDispatcher* target);
-
- private:
- friend class EventDispatcherImplTestApi;
- class ProcessedEventTarget;
- struct EventTask;
-
- enum class EventDispatchPhase {
- // Not actively dispatching.
- NONE,
-
- // A PRE_TARGET accelerator has been encountered and we're awaiting the ack.
- PRE_TARGET_ACCELERATOR,
-
- // Dispatching to the target, awaiting the ack.
- TARGET,
- };
-
- // Tracks state associated with an event being dispatched to an
- // AsyncEventDispatcher.
- struct InFlightEventDispatchDetails {
- InFlightEventDispatchDetails(EventDispatcherImpl* dispatcher,
- AsyncEventDispatcher* async_event_dispatcher,
- int64_t display_id,
- const Event& event,
- EventDispatchPhase phase);
- ~InFlightEventDispatchDetails();
-
- // Timer used to know when the AsyncEventDispatcher has taken too long.
- base::OneShotTimer timer;
- AsyncEventDispatcher* async_event_dispatcher;
- int64_t display_id;
- std::unique_ptr<Event> event;
- EventDispatchPhase phase;
- base::WeakPtr<Accelerator> post_target_accelerator;
-
- // Used for callbacks associated with the processing (such as |timer|). This
- // is used rather than a WeakPtrFactory on EventDispatcherImpl itself so
- // that it's scoped to the life of waiting for the AsyncEventDispatcher to
- // respond.
- base::WeakPtrFactory<EventDispatcherImpl> weak_factory_;
- };
-
- // Creates an InFlightEventDispatchDetails and schedules a timer that calls
- // OnDispatchInputEventTimeout() when done. This is used prior to asking
- // an AsyncEventDispatcher to dispatch an event or accelerator.
- void ScheduleInputEventTimeout(AsyncEventDispatcher* async_event_dispatcher,
- int64_t display_id,
- const Event& event,
- EventDispatchPhase phase);
-
- // Processes all pending events until there are no more, or this class is
- // waiting on on a result from either EventProcessor of AsyncEventDispatcher.
- void ProcessEventTasks();
-
- // Actual implementation of DispatchInputEventToWindow(). Schedules a timeout
- // and calls DispatchEvent() on the appropriate AsyncEventDispatcher.
- void DispatchInputEventToWindowImpl(ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const ui::Event& event,
- base::WeakPtr<Accelerator> accelerator);
-
- // The AsyncEventDispatcher has not completed processing in an appropriate
- // amount of time.
- void OnDispatchInputEventTimeout();
-
- // The AsyncEventDispatcher has completed processing the current event.
- void OnDispatchInputEventDone(mojom::EventResult result);
-
- // Called when |accelerator_dispatcher_| has completed processing the
- // accelerator.
- void OnAcceleratorDone(
- mojom::EventResult result,
- const base::flat_map<std::string, std::vector<uint8_t>>& properties);
-
- // Schedules an event to be processed later.
- void QueueEvent(const Event& event,
- std::unique_ptr<ProcessedEventTarget> processed_event_target,
- const EventLocation& event_location);
-
- // EventDispatcher:
- void DispatchInputEventToWindow(ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const Event& event,
- Accelerator* accelerator) override;
- void OnAccelerator(uint32_t accelerator_id,
- int64_t display_id,
- const ui::Event& event,
- AcceleratorPhase phase) override;
-
- EventProcessor* event_processor_ = nullptr;
-
- // Used to map a ClientId to an AsyncEventDispatcher.
- AsyncEventDispatcherLookup* const async_event_dispatcher_lookup_;
-
- // Processes accelerators. This AsyncEventDispatcher corresponds to the
- // AsyncEventDispatcher accelerators originate from, which is typically the
- // WindowManager.
- AsyncEventDispatcher* const accelerator_dispatcher_;
-
- EventDispatcherDelegate* delegate_;
-
- // Used for any event related tasks that need to be processed. Tasks are added
- // to the queue anytime work comes in while waiting for an
- // AsyncEventDispatcher to respond, or waiting for async hit-testing
- // processing to complete.
- base::queue<std::unique_ptr<EventTask>> event_tasks_;
-
- // If non-null we're actively waiting for a response from an
- // AsyncEventDispatcher.
- std::unique_ptr<InFlightEventDispatchDetails>
- in_flight_event_dispatch_details_;
-
- DISALLOW_COPY_AND_ASSIGN(EventDispatcherImpl);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_DISPATCHER_IMPL_H_
diff --git a/services/ui/ws/event_dispatcher_impl_test_api.cc b/services/ui/ws/event_dispatcher_impl_test_api.cc
deleted file mode 100644
index 8f64e70..0000000
--- a/services/ui/ws/event_dispatcher_impl_test_api.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2018 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 "services/ui/ws/event_dispatcher_impl_test_api.h"
-
-#include "services/ui/ws/event_dispatcher_impl.h"
-#include "services/ui/ws/window_tree.h"
-
-namespace ui {
-namespace ws {
-
-EventDispatcherImplTestApi::EventDispatcherImplTestApi(
- EventDispatcherImpl* event_dispatcher)
- : event_dispatcher_(event_dispatcher) {}
-
-EventDispatcherImplTestApi::~EventDispatcherImplTestApi() = default;
-
-void EventDispatcherImplTestApi::DispatchInputEventToWindow(
- ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const Event& event,
- Accelerator* accelerator) {
- event_dispatcher_->DispatchInputEventToWindow(
- target, client_id, event_location, event, accelerator);
-}
-
-WindowTree* EventDispatcherImplTestApi::GetTreeThatWillAckEvent() {
- return event_dispatcher_->in_flight_event_dispatch_details_
- ? static_cast<WindowTree*>(
- event_dispatcher_->in_flight_event_dispatch_details_
- ->async_event_dispatcher)
- : nullptr;
-}
-
-bool EventDispatcherImplTestApi::is_event_tasks_empty() {
- return event_dispatcher_->event_tasks_.empty();
-}
-
-bool EventDispatcherImplTestApi::OnDispatchInputEventDone(
- mojom::EventResult result) {
- if (!event_dispatcher_->GetInFlightEvent())
- return false;
- event_dispatcher_->OnDispatchInputEventDone(result);
- return true;
-}
-
-void EventDispatcherImplTestApi::OnDispatchInputEventTimeout() {
- if (event_dispatcher_->GetInFlightEvent())
- event_dispatcher_->OnDispatchInputEventTimeout();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/event_dispatcher_impl_test_api.h b/services/ui/ws/event_dispatcher_impl_test_api.h
deleted file mode 100644
index bdd0b4fc..0000000
--- a/services/ui/ws/event_dispatcher_impl_test_api.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef SERVICES_UI_WS_EVENT_DISPATCHER_IMPL_TEST_API_H_
-#define SERVICES_UI_WS_EVENT_DISPATCHER_IMPL_TEST_API_H_
-
-#include "base/macros.h"
-#include "services/ui/common/types.h"
-
-namespace ui {
-
-class Event;
-
-namespace mojom {
-enum class EventResult;
-}
-
-namespace ws {
-
-class Accelerator;
-class EventDispatcherImpl;
-class ServerWindow;
-class WindowTree;
-
-struct EventLocation;
-
-// Allows accessing internal functions of EventDispatcherImpl for testing. Most
-// functions call through to a function of the same name on EventDispatcherImpl,
-// see EventDispatcherImpl for details.
-class EventDispatcherImplTestApi {
- public:
- explicit EventDispatcherImplTestApi(EventDispatcherImpl* event_dispatcher);
- ~EventDispatcherImplTestApi();
-
- void DispatchInputEventToWindow(ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const Event& event,
- Accelerator* accelerator);
-
- // Convenience for returning
- // |in_flight_event_dispatch_details_->async_event_dispatcher_| as a
- // WindowTree.
- WindowTree* GetTreeThatWillAckEvent();
-
- bool is_event_tasks_empty();
-
- bool OnDispatchInputEventDone(mojom::EventResult result);
-
- void OnDispatchInputEventTimeout();
-
- private:
- EventDispatcherImpl* event_dispatcher_;
-
- DISALLOW_COPY_AND_ASSIGN(EventDispatcherImplTestApi);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_DISPATCHER_IMPL_TEST_API_H_
diff --git a/services/ui/ws/event_injector.cc b/services/ui/ws/event_injector.cc
deleted file mode 100644
index faad73cc..0000000
--- a/services/ui/ws/event_injector.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/event_injector.h"
-
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_server.h"
-
-namespace ui {
-namespace ws {
-
-EventInjector::EventInjector(WindowServer* server) : window_server_(server) {}
-
-EventInjector::~EventInjector() {}
-
-void EventInjector::AdjustEventLocationForPixelLayout(Display* display,
- ui::LocatedEvent* event) {
- WindowManagerState* window_manager_state =
- window_server_->GetWindowManagerState();
- if (!window_manager_state)
- return;
-
- // Only need to adjust the location of events when there is capture.
- PlatformDisplay* platform_display_with_capture =
- window_manager_state->platform_display_with_capture();
- if (!platform_display_with_capture ||
- display->platform_display() == platform_display_with_capture) {
- return;
- }
-
- // The event is from a display other than the display with capture. On device
- // events originate from the display with capture and are in terms of the
- // pixel layout (see comments in EventLocation). Convert the location to be
- // relative to the display with capture in terms of the pixel layout to match
- // what happens on device.
- gfx::PointF capture_relative_location = event->location_f();
- capture_relative_location += display->GetViewportMetrics()
- .bounds_in_pixels.origin()
- .OffsetFromOrigin();
- capture_relative_location -=
- platform_display_with_capture->GetViewportMetrics()
- .bounds_in_pixels.origin()
- .OffsetFromOrigin();
- event->set_location_f(capture_relative_location);
- event->set_root_location_f(capture_relative_location);
-}
-
-void EventInjector::InjectEvent(int64_t display_id,
- std::unique_ptr<ui::Event> event,
- InjectEventCallback cb) {
- DisplayManager* manager = window_server_->display_manager();
- if (!manager) {
- DVLOG(1) << "No display manager in InjectEvent.";
- std::move(cb).Run(false);
- return;
- }
-
- Display* display = manager->GetDisplayById(display_id);
- if (!display) {
- DVLOG(1) << "Invalid display_id in InjectEvent.";
- std::move(cb).Run(false);
- return;
- }
-
- if (event->IsLocatedEvent()) {
- LocatedEvent* located_event = event->AsLocatedEvent();
- if (located_event->root_location_f() != located_event->location_f()) {
- DVLOG(1) << "EventInjector::InjectEvent locations must match";
- std::move(cb).Run(false);
- return;
- }
-
- AdjustEventLocationForPixelLayout(display, located_event);
-
- // If this is a mouse pointer event, then we have to also update the
- // location of the cursor on the screen.
- if (event->IsMousePointerEvent())
- display->platform_display()->MoveCursorTo(located_event->location());
- }
- display->ProcessEvent(event.get(), base::BindOnce(std::move(cb), true));
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/event_injector.h b/services/ui/ws/event_injector.h
deleted file mode 100644
index f8108db9..0000000
--- a/services/ui/ws/event_injector.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_EVENT_INJECTOR_H_
-#define SERVICES_UI_WS_EVENT_INJECTOR_H_
-
-#include "services/ui/public/interfaces/event_injector.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class Display;
-class WindowServer;
-
-// See description in mojom for details on this.
-class EventInjector : public mojom::EventInjector {
- public:
- explicit EventInjector(WindowServer* server);
- ~EventInjector() override;
-
- private:
- // Adjusts the location as necessary of |event|. |display| is the display
- // the event is targetted at.
- void AdjustEventLocationForPixelLayout(Display* display,
- ui::LocatedEvent* event);
-
- // mojom::EventInjector:
- void InjectEvent(int64_t display_id,
- std::unique_ptr<ui::Event> event,
- InjectEventCallback cb) override;
-
- WindowServer* window_server_;
-
- DISALLOW_COPY_AND_ASSIGN(EventInjector);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_INJECTOR_H_
diff --git a/services/ui/ws/event_location.h b/services/ui/ws/event_location.h
deleted file mode 100644
index f51d7f0..0000000
--- a/services/ui/ws/event_location.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_EVENT_LOCATION_H_
-#define SERVICES_UI_WS_EVENT_LOCATION_H_
-
-#include <stdint.h>
-
-#include "ui/display/types/display_constants.h"
-#include "ui/gfx/geometry/point_f.h"
-
-namespace ui {
-namespace ws {
-
-// Contains a location relative to a particular display in two different
-// coordinate systems. The location the event is received at is |raw_location|.
-// |raw_location| is in terms of the pixel display layout. |location| is derived
-// from |raw_location| and in terms of the DIP display layout (but in pixels).
-// Typically |raw_location| is on a single display, in which case |location| is
-// exactly the same value. If there is a grab then the events are still
-// generated for the display the grab was initiated on, even if the mouse moves
-// to another display. As the pixel layout of displays differs from the DIP
-// layout |location| is converted to follow the DIP layout (but in pixels).
-//
-// For example, two displays might have pixels bounds of:
-// 0,0 1000x1000 and 0,1060 1000x1000
-// where as the DIP bounds might be:
-// 0,0 500x500 and 500,0 1000x1000
-// Notice the pixel bounds are staggered along the y-axis and the DIP bounds
-// along the x-axis.
-// If there is a grab on the first display and the mouse moves into the second
-// display then |raw_location| would be 0,1060 which is converted to a
-// |location| of 1000,0 (|display_id| remains the same regardless of the display
-// the mouse is on.
-struct EventLocation {
- EventLocation() : display_id(display::kInvalidDisplayId) {}
- explicit EventLocation(int64_t display_id) : display_id(display_id) {}
- EventLocation(const gfx::PointF& raw_location,
- const gfx::PointF& location,
- int64_t display_id)
- : raw_location(raw_location),
- location(location),
- display_id(display_id) {}
-
- // Location of event in terms of pixel display layout.
- gfx::PointF raw_location;
-
- // Location of event in terms of DIP display layout (but in pixels).
- gfx::PointF location;
-
- // Id of the display the event was generated from.
- int64_t display_id;
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_LOCATION_H_
diff --git a/services/ui/ws/event_matcher.cc b/services/ui/ws/event_matcher.cc
deleted file mode 100644
index f1f14c1..0000000
--- a/services/ui/ws/event_matcher.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/event_matcher.h"
-
-#include "ui/events/mojo/event_struct_traits.h"
-
-namespace ui {
-namespace ws {
-
-EventMatcher::EventMatcher(const mojom::EventMatcher& matcher)
- : fields_to_match_(NONE),
- event_type_(ui::ET_UNKNOWN),
- event_flags_(ui::EF_NONE),
- ignore_event_flags_(ui::EF_NONE),
- keyboard_code_(ui::VKEY_UNKNOWN),
- pointer_type_(ui::EventPointerType::POINTER_TYPE_UNKNOWN) {
- if (matcher.type_matcher) {
- fields_to_match_ |= TYPE;
- event_type_ = mojo::ConvertTo<ui::EventType>(matcher.type_matcher->type);
- }
- if (matcher.flags_matcher) {
- fields_to_match_ |= FLAGS;
- event_flags_ = matcher.flags_matcher->flags;
- if (matcher.ignore_flags_matcher)
- ignore_event_flags_ = matcher.ignore_flags_matcher->flags;
- }
- if (matcher.key_matcher) {
- fields_to_match_ |= KEYBOARD_CODE;
- keyboard_code_ = static_cast<uint16_t>(matcher.key_matcher->keyboard_code);
- }
- if (matcher.pointer_kind_matcher) {
- fields_to_match_ |= POINTER_KIND;
- switch (matcher.pointer_kind_matcher->pointer_kind) {
- case ui::mojom::PointerKind::MOUSE:
- pointer_type_ = ui::EventPointerType::POINTER_TYPE_MOUSE;
- break;
- case ui::mojom::PointerKind::TOUCH:
- pointer_type_ = ui::EventPointerType::POINTER_TYPE_TOUCH;
- break;
- default:
- NOTREACHED();
- }
- }
- if (matcher.pointer_location_matcher) {
- fields_to_match_ |= POINTER_LOCATION;
- pointer_region_ = matcher.pointer_location_matcher->region;
- }
-}
-
-EventMatcher::EventMatcher(EventMatcher&& rhs) = default;
-
-EventMatcher::~EventMatcher() {}
-
-bool EventMatcher::HasFields(int fields) {
- return (fields_to_match_ & fields) != 0;
-}
-
-bool EventMatcher::MatchesEvent(const ui::Event& event) const {
- if ((fields_to_match_ & TYPE) && event.type() != event_type_)
- return false;
- // Synthetic flags should never be matched against.
- constexpr int kSyntheticFlags = EF_IS_SYNTHESIZED | EF_IS_REPEAT;
- int flags = event.flags() & ~(ignore_event_flags_ | kSyntheticFlags);
- if ((fields_to_match_ & FLAGS) && flags != event_flags_)
- return false;
- if (fields_to_match_ & KEYBOARD_CODE) {
- if (!event.IsKeyEvent())
- return false;
- if (keyboard_code_ != event.AsKeyEvent()->GetConflatedWindowsKeyCode())
- return false;
- }
- if (fields_to_match_ & POINTER_KIND) {
- if (!event.IsPointerEvent() ||
- pointer_type_ != event.AsPointerEvent()->pointer_details().pointer_type)
- return false;
- }
- if (fields_to_match_ & POINTER_LOCATION) {
- // TODO(sad): The tricky part here is to make sure the same coord-space is
- // used for the location-region and the event-location.
- NOTIMPLEMENTED();
- return false;
- }
- return true;
-}
-
-bool EventMatcher::Equals(const EventMatcher& other) const {
- return fields_to_match_ == other.fields_to_match_ &&
- event_type_ == other.event_type_ &&
- event_flags_ == other.event_flags_ &&
- ignore_event_flags_ == other.ignore_event_flags_ &&
- keyboard_code_ == other.keyboard_code_ &&
- pointer_type_ == other.pointer_type_ &&
- pointer_region_ == other.pointer_region_;
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/event_matcher.h b/services/ui/ws/event_matcher.h
deleted file mode 100644
index d0bb7e7..0000000
--- a/services/ui/ws/event_matcher.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_EVENT_MATCHER_H_
-#define SERVICES_UI_WS_EVENT_MATCHER_H_
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "services/ui/public/interfaces/event_matcher.mojom.h"
-#include "ui/events/event.h"
-#include "ui/events/mojo/event_constants.mojom.h"
-#include "ui/events/mojo/keyboard_codes.mojom.h"
-#include "ui/gfx/geometry/rect_f.h"
-
-namespace ui {
-namespace ws {
-
-// Wraps a mojom::EventMatcher and allows events to be tested against it.
-class EventMatcher {
- public:
- enum MatchFields {
- NONE = 0,
- TYPE = 1 << 0,
- FLAGS = 1 << 1,
- KEYBOARD_CODE = 1 << 2,
- POINTER_KIND = 1 << 3,
- POINTER_LOCATION = 1 << 4,
- };
-
- explicit EventMatcher(const mojom::EventMatcher& matcher);
- EventMatcher(EventMatcher&& rhs);
- ~EventMatcher();
-
- // Returns true if this matcher would match any of types in the |fields|
- // bitarray.
- bool HasFields(int fields);
-
- bool MatchesEvent(const ui::Event& event) const;
-
- bool Equals(const EventMatcher& other) const;
-
- private:
- uint32_t fields_to_match_;
- ui::EventType event_type_;
- // Bitfields of kEventFlag* and kMouseEventFlag* values in
- // input_event_constants.mojom.
- int event_flags_;
- int ignore_event_flags_;
- uint16_t keyboard_code_;
- ui::EventPointerType pointer_type_;
- gfx::RectF pointer_region_;
-
- DISALLOW_COPY_AND_ASSIGN(EventMatcher);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_MATCHER_H_
diff --git a/services/ui/ws/event_matcher_unittest.cc b/services/ui/ws/event_matcher_unittest.cc
deleted file mode 100644
index 29db65b..0000000
--- a/services/ui/ws/event_matcher_unittest.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/event_matcher.h"
-
-#include "base/time/time.h"
-#include "services/ui/public/interfaces/event_matcher.mojom.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/events/event.h"
-#include "ui/events/mojo/event_constants.mojom.h"
-#include "ui/gfx/geometry/point.h"
-
-namespace ui {
-namespace ws {
-
-// NOTE: Most of the matching functionality is exercised by tests of Accelerator
-// handling in the EventDispatcher and WindowTree tests. These are just basic
-// sanity checks.
-
-using EventTesterTest = testing::Test;
-
-TEST_F(EventTesterTest, MatchesEventByType) {
- mojom::EventMatcherPtr matcher = mojom::EventMatcher::New();
- matcher->type_matcher = mojom::EventTypeMatcher::New();
- matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN;
- EventMatcher pointer_down_matcher(*matcher);
-
- ui::PointerEvent pointer_down(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- EXPECT_TRUE(pointer_down_matcher.MatchesEvent(pointer_down));
-
- ui::PointerEvent pointer_up(ui::TouchEvent(
- ui::ET_TOUCH_RELEASED, gfx::Point(), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- EXPECT_FALSE(pointer_down_matcher.MatchesEvent(pointer_up));
-}
-
-TEST_F(EventTesterTest, MatchesEventByKeyCode) {
- mojom::EventMatcherPtr matcher(mojom::EventMatcher::New());
- matcher->type_matcher = mojom::EventTypeMatcher::New();
- matcher->type_matcher->type = ui::mojom::EventType::KEY_PRESSED;
- matcher->key_matcher = mojom::KeyEventMatcher::New();
- matcher->key_matcher->keyboard_code = ui::mojom::KeyboardCode::Z;
- EventMatcher z_matcher(*matcher);
-
- ui::KeyEvent z_key(ui::ET_KEY_PRESSED, ui::VKEY_Z, ui::EF_NONE);
- EXPECT_TRUE(z_matcher.MatchesEvent(z_key));
-
- ui::KeyEvent y_key(ui::ET_KEY_PRESSED, ui::VKEY_Y, ui::EF_NONE);
- EXPECT_FALSE(z_matcher.MatchesEvent(y_key));
-}
-
-TEST_F(EventTesterTest, MatchesEventByKeyFlags) {
- mojom::EventMatcherPtr matcher(mojom::EventMatcher::New());
- matcher->type_matcher = mojom::EventTypeMatcher::New();
- matcher->type_matcher->type = ui::mojom::EventType::KEY_PRESSED;
- matcher->flags_matcher = mojom::EventFlagsMatcher::New();
- matcher->flags_matcher->flags = ui::mojom::kEventFlagControlDown;
- matcher->key_matcher = mojom::KeyEventMatcher::New();
- matcher->key_matcher->keyboard_code = ui::mojom::KeyboardCode::N;
- EventMatcher control_n_matcher(*matcher);
-
- ui::KeyEvent control_n(ui::ET_KEY_PRESSED, ui::VKEY_N, ui::EF_CONTROL_DOWN);
- EXPECT_TRUE(control_n_matcher.MatchesEvent(control_n));
-
- ui::KeyEvent shift_n(ui::ET_KEY_PRESSED, ui::VKEY_N, ui::EF_SHIFT_DOWN);
- EXPECT_FALSE(control_n_matcher.MatchesEvent(shift_n));
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/event_processor.cc b/services/ui/ws/event_processor.cc
deleted file mode 100644
index 144b09ce..0000000
--- a/services/ui/ws/event_processor.cc
+++ /dev/null
@@ -1,859 +0,0 @@
-// 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 "services/ui/ws/event_processor.h"
-
-#include <algorithm>
-
-#include "base/time/time.h"
-#include "services/ui/ws/accelerator.h"
-#include "services/ui/ws/drag_controller.h"
-#include "services/ui/ws/drag_source.h"
-#include "services/ui/ws/event_dispatcher.h"
-#include "services/ui/ws/event_location.h"
-#include "services/ui/ws/event_processor_delegate.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_delegate.h"
-#include "services/ui/ws/server_window_drawn_tracker.h"
-#include "services/ui/ws/window_coordinate_conversions.h"
-#include "services/ui/ws/window_finder.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/events/event_utils.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/point_conversions.h"
-
-namespace ui {
-namespace ws {
-
-using Entry = std::pair<uint32_t, std::unique_ptr<Accelerator>>;
-
-namespace {
-
-bool IsOnlyOneMouseButtonDown(int flags) {
- const uint32_t button_only_flags =
- flags & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON |
- ui::EF_RIGHT_MOUSE_BUTTON);
- return button_only_flags == ui::EF_LEFT_MOUSE_BUTTON ||
- button_only_flags == ui::EF_MIDDLE_MOUSE_BUTTON ||
- button_only_flags == ui::EF_RIGHT_MOUSE_BUTTON;
-}
-
-// This is meant to mirror when implicit capture stops. Specifically non-mouse
-// pointer up, or mouse and no more buttons down.
-bool IsPointerGoingUp(const Event& event) {
- return event.IsPointerEvent() &&
- (event.type() == ui::ET_POINTER_UP ||
- event.type() == ui::ET_POINTER_CANCELLED) &&
- (!event.IsMousePointerEvent() ||
- IsOnlyOneMouseButtonDown(event.flags()));
-}
-
-// Get the pointer id from an event, only supports PointerEvents for now.
-int32_t GetPointerId(const Event& event) {
- if (event.IsPointerEvent())
- return event.AsPointerEvent()->pointer_details().id;
- return PointerDetails::kUnknownPointerId;
-}
-
-} // namespace
-
-////////////////////////////////////////////////////////////////////////////////
-
-EventProcessor::ObservedWindow::ObservedWindow() = default;
-EventProcessor::ObservedWindow::~ObservedWindow() = default;
-
-EventProcessor::EventProcessor(EventProcessorDelegate* delegate,
- EventDispatcher* event_dispatcher)
- : delegate_(delegate),
- event_dispatcher_(event_dispatcher),
- capture_window_(nullptr),
- capture_window_client_id_(kInvalidClientId),
- event_targeter_(std::make_unique<EventTargeter>(this)),
- mouse_button_down_(false),
- mouse_cursor_source_window_(nullptr),
- mouse_cursor_in_non_client_area_(false) {}
-
-EventProcessor::~EventProcessor() {
- SetMouseCursorSourceWindow(nullptr);
- if (capture_window_) {
- UnobserveWindow(capture_window_);
- capture_window_ = nullptr;
- capture_window_client_id_ = kInvalidClientId;
- }
- for (const auto& pair : pointer_targets_) {
- if (pair.second.window)
- UnobserveWindow(pair.second.window);
- }
- pointer_targets_.clear();
-}
-
-void EventProcessor::Reset() {
- if (capture_window_) {
- CancelPointerEventsToTarget(capture_window_);
- DCHECK(capture_window_ == nullptr);
- }
-
- while (!pointer_targets_.empty())
- StopTrackingPointer(pointer_targets_.begin()->first);
-
- mouse_button_down_ = false;
-}
-
-ui::CursorData EventProcessor::GetCurrentMouseCursor() const {
- if (drag_controller_)
- return drag_controller_->current_cursor();
-
- if (!mouse_cursor_source_window_)
- return ui::CursorData(ui::CursorType::kPointer);
-
- if (mouse_cursor_in_non_client_area_)
- return mouse_cursor_source_window_->non_client_cursor();
-
- const ServerWindow* window = GetWindowForMouseCursor();
- return window ? window->cursor() : ui::CursorData(ui::CursorType::kPointer);
-}
-
-bool EventProcessor::SetCaptureWindow(ServerWindow* window,
- ClientSpecificId client_id) {
- if (!window)
- client_id = kInvalidClientId;
-
- if (window == capture_window_ && client_id == capture_window_client_id_)
- return true;
-
- // A window that is blocked by a modal window cannot gain capture.
- if (window && modal_window_controller_.IsWindowBlocked(window))
- return false;
-
- // If we're currently performing a drag and drop, reject setting the capture
- // window.
- if (drag_controller_)
- return false;
-
- if (capture_window_) {
- // Stop observing old capture window. |pointer_targets_| are cleared on
- // initial setting of a capture window.
- UnobserveWindow(capture_window_);
- } else {
- CancelImplicitCaptureExcept(window, client_id);
- }
-
- // Set the capture before changing native capture; otherwise, the callback
- // from native platform might try to set the capture again.
- const bool had_capture_window = capture_window_ != nullptr;
- ServerWindow* old_capture_window = capture_window_;
- capture_window_ = window;
- capture_window_client_id_ = client_id;
-
- delegate_->OnCaptureChanged(capture_window_, old_capture_window);
-
- // Begin tracking the capture window if it is not yet being observed.
- if (window) {
- ObserveWindow(window);
- // TODO(sky): this conditional is problematic for the case of capture moving
- // to a different display.
- if (!had_capture_window)
- delegate_->SetNativeCapture(window);
- } else {
- delegate_->ReleaseNativeCapture();
- if (!mouse_button_down_)
- UpdateCursorProviderByLastKnownLocation();
- }
- return true;
-}
-
-void EventProcessor::SetDragDropSourceWindow(
- DragSource* drag_source,
- ServerWindow* window,
- DragTargetConnection* source_connection,
- int32_t drag_pointer,
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data,
- uint32_t drag_operations) {
- CancelImplicitCaptureExcept(nullptr, kInvalidClientId);
- drag_controller_ = std::make_unique<DragController>(
- this, drag_source, window, source_connection, drag_pointer, mime_data,
- drag_operations);
-}
-
-void EventProcessor::CancelDragDrop() {
- if (drag_controller_)
- drag_controller_->Cancel();
-}
-
-void EventProcessor::EndDragDrop() {
- drag_controller_.reset();
-}
-
-void EventProcessor::OnWillDestroyDragTargetConnection(
- DragTargetConnection* connection) {
- if (drag_controller_)
- drag_controller_->OnWillDestroyDragTargetConnection(connection);
-}
-
-void EventProcessor::AddSystemModalWindow(ServerWindow* window) {
- modal_window_controller_.AddSystemModalWindow(window);
- ReleaseCaptureBlockedByAnyModalWindow();
-}
-
-void EventProcessor::ReleaseCaptureBlockedByAnyModalWindow() {
- if (!capture_window_)
- return;
-
- if (modal_window_controller_.IsWindowBlocked(capture_window_))
- SetCaptureWindow(nullptr, kInvalidClientId);
-}
-
-const ServerWindow* EventProcessor::GetWindowForMouseCursor() const {
- if (mouse_cursor_in_non_client_area_ || !mouse_cursor_source_window_)
- return mouse_cursor_source_window_;
-
- // Return the ancestor (starting at |mouse_cursor_source_window_|) whose
- // client id differs. In other words, return the first window ancestor that is
- // an embed root. This is done to match the behavior of aura, which sets the
- // cursor on the root.
- const ClientSpecificId target_client_id = delegate_->GetEventTargetClientId(
- mouse_cursor_source_window_, mouse_cursor_in_non_client_area_);
- const ServerWindow* window = mouse_cursor_source_window_;
- while (window && window->owning_tree_id() == target_client_id)
- window = window->parent();
- return window;
-}
-
-void EventProcessor::UpdateNonClientAreaForCurrentWindow() {
- if (!mouse_button_down_ && mouse_cursor_source_window_) {
- event_targeter_->FindTargetForLocation(
- EventSource::MOUSE,
- {mouse_pointer_last_location_, mouse_pointer_last_location_,
- mouse_pointer_display_id_},
- base::BindOnce(
- &EventProcessor::UpdateNonClientAreaForCurrentWindowOnFoundWindow,
- base::Unretained(this)));
- }
-}
-
-void EventProcessor::UpdateCursorProviderByLastKnownLocation() {
- if (!mouse_button_down_) {
- event_targeter_->FindTargetForLocation(
- EventSource::MOUSE,
- {mouse_pointer_last_location_, mouse_pointer_last_location_,
- mouse_pointer_display_id_},
- base::BindOnce(&EventProcessor::
- UpdateCursorProviderByLastKnownLocationOnFoundWindow,
- base::Unretained(this)));
- }
-}
-
-bool EventProcessor::AddAccelerator(uint32_t id,
- mojom::EventMatcherPtr event_matcher) {
- std::unique_ptr<Accelerator> accelerator(new Accelerator(id, *event_matcher));
- // If an accelerator with the same id or matcher already exists, then abort.
- for (const auto& pair : accelerators_) {
- if (pair.first == id) {
- DVLOG(1) << "duplicate accelerator. Accelerator id=" << accelerator->id()
- << " type=" << event_matcher->type_matcher->type
- << " flags=" << event_matcher->flags_matcher->flags;
- return false;
- } else if (accelerator->EqualEventMatcher(pair.second.get())) {
- DVLOG(1) << "duplicate matcher. Accelerator id=" << accelerator->id()
- << " type=" << event_matcher->type_matcher->type
- << " flags=" << event_matcher->flags_matcher->flags;
- return false;
- }
- }
- accelerators_.insert(Entry(id, std::move(accelerator)));
- return true;
-}
-
-void EventProcessor::RemoveAccelerator(uint32_t id) {
- auto it = accelerators_.find(id);
- // Clients may pass bogus ids.
- if (it != accelerators_.end())
- accelerators_.erase(it);
-}
-
-void EventProcessor::SetKeyEventsThatDontHideCursor(
- std::vector<::ui::mojom::EventMatcherPtr> dont_hide_cursor_list) {
- dont_hide_cursor_matchers_.clear();
- for (auto& matcher_ptr : dont_hide_cursor_list) {
- EventMatcher matcher(*matcher_ptr);
- // Ensure we don't have pointer matchers in our key only list.
- DCHECK(!matcher.HasFields(EventMatcher::POINTER_KIND |
- EventMatcher::POINTER_LOCATION));
- dont_hide_cursor_matchers_.push_back(std::move(matcher));
- }
-}
-
-bool EventProcessor::IsProcessingEvent() const {
- return waiting_on_event_targeter_;
-}
-
-void EventProcessor::ProcessEvent(const ui::Event& event,
- const EventLocation& event_location,
- AcceleratorMatchPhase match_phase) {
-#if !defined(NDEBUG)
- if (match_phase == AcceleratorMatchPhase::POST_ONLY) {
- // POST_ONLY should always be preceeded by ANY with the same event.
- DCHECK(previous_event_);
- // Event doesn't define ==, so this compares the key fields.
- DCHECK(event.type() == previous_event_->type() &&
- event.time_stamp() == previous_event_->time_stamp() &&
- event.flags() == previous_event_->flags());
- DCHECK_EQ(previous_accelerator_match_phase_, AcceleratorMatchPhase::ANY);
- }
- previous_event_ = Event::Clone(event);
- previous_accelerator_match_phase_ = match_phase;
-#endif
-
- if (event.IsKeyEvent()) {
- const ui::KeyEvent* key_event = event.AsKeyEvent();
- if (!key_event->is_char() && match_phase == AcceleratorMatchPhase::ANY) {
- Accelerator* pre_target =
- FindAccelerator(*key_event, ui::mojom::AcceleratorPhase::PRE_TARGET);
- if (pre_target) {
- event_dispatcher_->OnAccelerator(
- pre_target->id(), event_location.display_id, event,
- EventDispatcher::AcceleratorPhase::kPre);
- return;
- }
- }
- ProcessKeyEvent(*key_event, event_location.display_id, match_phase);
- return;
- }
-
- DCHECK(event.IsPointerEvent() || event.IsScrollEvent());
- DCHECK(event_location.location == event.AsLocatedEvent()->root_location_f());
- DCHECK(event_location.location == event.AsLocatedEvent()->location_f());
- DCHECK(!waiting_on_event_targeter_);
- if (ShouldUseEventTargeter(event)) {
- waiting_on_event_targeter_ = true;
- const EventSource event_source =
- event.IsMousePointerEvent() ? EventSource::MOUSE : EventSource::TOUCH;
- event_targeter_->FindTargetForLocation(
- event_source, event_location,
- base::BindOnce(&EventProcessor::ProcessEventOnFoundTarget,
- base::Unretained(this), ui::Event::Clone(event)));
- } else {
- ProcessEventOnFoundTargetImpl(ui::Event::Clone(event), event_location,
- nullptr);
- }
-}
-
-ServerWindow* EventProcessor::GetRootWindowForDisplay(int64_t display_id) {
- return delegate_->GetRootWindowForDisplay(display_id);
-}
-
-viz::HitTestQuery* EventProcessor::GetHitTestQueryForDisplay(
- int64_t display_id) {
- return delegate_->GetHitTestQueryForDisplay(display_id);
-}
-
-ServerWindow* EventProcessor::GetWindowFromFrameSinkId(
- const viz::FrameSinkId& frame_sink_id) {
- return delegate_->GetWindowFromFrameSinkId(frame_sink_id);
-}
-
-DeepestWindow EventProcessor::AdjustTargetForModal(
- const DeepestWindow& target) const {
- const ServerWindow* modal_transient =
- modal_window_controller_.GetModalTransient(target.window);
- if (!modal_transient &&
- !modal_window_controller_.IsWindowBlocked(target.window)) {
- return target;
- }
-
- DeepestWindow updated_target = target;
- updated_target.in_non_client_area = true;
- updated_target.window =
- target.window ? delegate_->GetFallbackTargetForEventBlockedByModal(
- target.window->GetRootForDrawn())
- : nullptr;
- return updated_target;
-}
-
-void EventProcessor::SetMouseCursorSourceWindow(ServerWindow* window) {
- if (mouse_cursor_source_window_ == window)
- return;
-
- if (mouse_cursor_source_window_)
- UnobserveWindow(mouse_cursor_source_window_);
- mouse_cursor_source_window_ = window;
- if (mouse_cursor_source_window_)
- ObserveWindow(mouse_cursor_source_window_);
-}
-
-void EventProcessor::SetMousePointerLocation(
- const gfx::PointF& new_mouse_location,
- int64_t new_mouse_display_id) {
- // TODO: this needs to account for grab and a different display. By that I
- // mean during a grab |mouse_pointer_last_location_| may actually be in a
- // different display.
- mouse_pointer_last_location_ = new_mouse_location;
- mouse_pointer_display_id_ = new_mouse_display_id;
-}
-
-void EventProcessor::ProcessKeyEvent(const ui::KeyEvent& event,
- int64_t display_id,
- AcceleratorMatchPhase match_phase) {
- Accelerator* post_target =
- FindAccelerator(event, ui::mojom::AcceleratorPhase::POST_TARGET);
- if (drag_controller_ && event.type() == ui::ET_KEY_PRESSED &&
- event.key_code() == ui::VKEY_ESCAPE) {
- drag_controller_->Cancel();
- return;
- }
- ServerWindow* focused_window =
- delegate_->GetFocusedWindowForEventProcessor(display_id);
- if (focused_window) {
- // We only hide the cursor when there's a window to receive the key
- // event. We want to hide the cursor when the user is entering text
- // somewhere so if the user is at the desktop with no window to react to
- // the key press, there's no reason to hide the cursor.
- HideCursorOnMatchedKeyEvent(event);
-
- // Assume key events are for the client area.
- const bool in_nonclient_area = false;
- const ClientSpecificId client_id =
- delegate_->GetEventTargetClientId(focused_window, in_nonclient_area);
- event_dispatcher_->DispatchInputEventToWindow(focused_window, client_id,
- EventLocation(display_id),
- event, post_target);
- return;
- }
- delegate_->OnEventTargetNotFound(event, display_id);
- if (post_target)
- event_dispatcher_->OnAccelerator(post_target->id(), display_id, event,
- EventDispatcher::AcceleratorPhase::kPost);
-}
-
-void EventProcessor::HideCursorOnMatchedKeyEvent(const ui::KeyEvent& event) {
- if (event.IsSynthesized()) {
- // Don't bother performing the matching; it will be rejected anyway.
- return;
- }
-
- bool hide_cursor = !dont_hide_cursor_matchers_.empty();
- for (auto& matcher : dont_hide_cursor_matchers_) {
- if (matcher.MatchesEvent(event)) {
- hide_cursor = false;
- break;
- }
- }
-
- if (hide_cursor)
- delegate_->OnEventChangesCursorVisibility(event, false);
-}
-
-bool EventProcessor::ShouldUseEventTargeter(const Event& event) const {
- if (drag_controller_)
- return true;
-
- if (capture_window_)
- return false;
-
- auto iter = pointer_targets_.find(GetPointerId(event));
- if (iter == pointer_targets_.end() || !iter->second.is_pointer_down)
- return true;
-
- return (event.IsMousePointerEvent() && IsPointerGoingUp(event)) ||
- event.type() == ET_POINTER_DOWN;
-}
-
-void EventProcessor::ProcessEventOnFoundTarget(
- std::unique_ptr<ui::Event> event,
- const EventLocation& event_location,
- const DeepestWindow& target) {
- DCHECK(waiting_on_event_targeter_);
- waiting_on_event_targeter_ = false;
- ProcessEventOnFoundTargetImpl(std::move(event), event_location, &target);
-}
-
-void EventProcessor::ProcessEventOnFoundTargetImpl(
- std::unique_ptr<ui::Event> event,
- const EventLocation& event_location,
- const DeepestWindow* found_target) {
- // WARNING: |found_target| may be null!
- DCHECK(!waiting_on_event_targeter_);
-
- UpdateCursorRelatedProperties(*event, event_location);
-
- const bool is_mouse_event = event->IsMousePointerEvent();
- const bool is_pointer_going_up = IsPointerGoingUp(*event);
-
- // Update mouse down state upon events which change it.
- if (is_mouse_event) {
- if (event->type() == ui::ET_POINTER_DOWN)
- mouse_button_down_ = true;
- else if (is_pointer_going_up)
- mouse_button_down_ = false;
- }
-
- if (drag_controller_ && event->IsPointerEvent()) {
- DCHECK(found_target);
- if (drag_controller_->DispatchPointerEvent(
- *event->AsPointerEvent(),
- AdjustTargetForModal(*found_target).window)) {
- return;
- }
- }
-
- if (capture_window_) {
- SetMouseCursorSourceWindow(capture_window_);
- DispatchToClient(capture_window_, capture_window_client_id_,
- *event->AsLocatedEvent(), event_location);
- return;
- }
-
- std::unique_ptr<DeepestWindowAndTarget> result;
- if (found_target) {
- result = std::make_unique<DeepestWindowAndTarget>();
- result->deepest_window = AdjustTargetForModal(*found_target);
- result->pointer_target.is_mouse_event = is_mouse_event;
- result->pointer_target.window = result->deepest_window.window;
- result->pointer_target.in_nonclient_area =
- result->deepest_window.in_non_client_area;
- result->pointer_target.is_pointer_down =
- event->type() == ui::ET_POINTER_DOWN;
- result->pointer_target.display_id = event_location.display_id;
- }
-
- const int32_t pointer_id = GetPointerId(*event);
- if (!IsTrackingPointer(pointer_id) ||
- !pointer_targets_[pointer_id].is_pointer_down) {
- DCHECK(result);
- const bool any_pointers_down = AreAnyPointersDown();
- UpdateTargetForPointer(pointer_id, *event->AsLocatedEvent(),
- result->pointer_target, event_location);
- if (is_mouse_event)
- SetMouseCursorSourceWindow(pointer_targets_[pointer_id].window);
-
- PointerTarget& pointer_target = pointer_targets_[pointer_id];
- if (pointer_target.is_pointer_down) {
- if (!any_pointers_down) {
- // Don't attempt to change focus on pointer down. We assume client code
- // will do that.
- ServerWindow* capture_window = pointer_target.window;
- if (!capture_window) {
- capture_window =
- delegate_->GetRootWindowForDisplay(event_location.display_id);
- }
- delegate_->SetNativeCapture(capture_window);
- }
- }
- }
-
- // When we release the mouse button, we want the cursor to be sourced from
- // the window under the mouse pointer, even though we're sending the button
- // up event to the window that had implicit capture. We have to set this
- // before we perform dispatch because the Delegate is going to read this
- // information from us.
- if (is_pointer_going_up && is_mouse_event) {
- DCHECK(result);
- UpdateCursorProvider(result->deepest_window);
- }
-
- DispatchToPointerTarget(pointer_targets_[pointer_id],
- *event->AsLocatedEvent(), event_location);
-
- if (is_pointer_going_up) {
- if (is_mouse_event)
- pointer_targets_[pointer_id].is_pointer_down = false;
- else
- StopTrackingPointer(pointer_id);
- if (!AreAnyPointersDown())
- delegate_->ReleaseNativeCapture();
- }
-
- if (event->type() == ET_POINTER_DOWN) {
- // Use |found_target| as |result| has already been adjusted for the
- // modal window.
- DCHECK(found_target);
- if (found_target->window)
- HandleClickOnBlockedWindow(*found_target);
- }
-}
-
-void EventProcessor::UpdateCursorRelatedProperties(
- const ui::Event& event,
- const EventLocation& event_location) {
- if (event.IsMousePointerEvent()) {
- // This corresponds to the code in CompoundEventFilter which updates
- // visibility on each mouse event. Here, we're sure that we're a non-exit
- // mouse event and FROM_TOUCH doesn't exist in mus so we shouldn't need
- // further filtering.
- delegate_->OnEventChangesCursorTouchVisibility(event, true);
- delegate_->OnEventChangesCursorVisibility(event, true);
-
- SetMousePointerLocation(event_location.raw_location,
- event_location.display_id);
- delegate_->OnMouseCursorLocationChanged(event_location.raw_location,
- event_location.display_id);
- } else if (event.IsPointerEvent()) {
- // When we have a non-touch event that wasn't synthesized, hide the mouse
- // cursor until the next non-synthesized mouse event.
- delegate_->OnEventChangesCursorTouchVisibility(event, false);
- }
-}
-
-void EventProcessor::UpdateNonClientAreaForCurrentWindowOnFoundWindow(
- const EventLocation& event_location,
- const DeepestWindow& target) {
- if (!mouse_cursor_source_window_)
- return;
-
- const DeepestWindow updated_target = AdjustTargetForModal(target);
- if (updated_target.window == mouse_cursor_source_window_) {
- mouse_cursor_in_non_client_area_ =
- mouse_cursor_source_window_ ? updated_target.in_non_client_area : false;
- }
- delegate_->UpdateNativeCursorFromEventProcessor();
-}
-
-void EventProcessor::UpdateCursorProviderByLastKnownLocationOnFoundWindow(
- const EventLocation& event_location,
- const DeepestWindow& target) {
- UpdateCursorProvider(AdjustTargetForModal(target));
-}
-
-void EventProcessor::UpdateCursorProvider(const DeepestWindow& target) {
- if (mouse_button_down_)
- return;
-
- SetMouseCursorSourceWindow(target.window);
- if (mouse_cursor_source_window_) {
- mouse_cursor_in_non_client_area_ = target.in_non_client_area;
- } else {
- SetMouseCursorSourceWindow(
- delegate_->GetRootWindowForDisplay(mouse_pointer_display_id_));
- mouse_cursor_in_non_client_area_ = true;
- }
- delegate_->UpdateNativeCursorFromEventProcessor();
-}
-
-void EventProcessor::HandleClickOnBlockedWindow(const DeepestWindow& target) {
- ServerWindow* modal_transient =
- modal_window_controller_.GetModalTransient(target.window);
- if (modal_transient) {
- ServerWindow* toplevel =
- modal_window_controller_.GetToplevelWindow(target.window);
- DCHECK(toplevel);
- delegate_->SetFocusedWindowFromEventProcessor(toplevel);
- delegate_->OnEventOccurredOutsideOfModalWindow(modal_transient);
- } else if (target.window->IsDrawn() &&
- modal_window_controller_.IsWindowBlocked(target.window) &&
- modal_window_controller_.GetActiveSystemModalWindow()) {
- delegate_->OnEventOccurredOutsideOfModalWindow(
- modal_window_controller_.GetActiveSystemModalWindow());
- }
-}
-
-void EventProcessor::StartTrackingPointer(int32_t pointer_id,
- const PointerTarget& pointer_target) {
- DCHECK(!IsTrackingPointer(pointer_id));
- if (pointer_target.window)
- ObserveWindow(pointer_target.window);
- pointer_targets_[pointer_id] = pointer_target;
-}
-
-void EventProcessor::StopTrackingPointer(int32_t pointer_id) {
- DCHECK(IsTrackingPointer(pointer_id));
- ServerWindow* window = pointer_targets_[pointer_id].window;
- pointer_targets_.erase(pointer_id);
- if (window)
- UnobserveWindow(window);
-}
-
-void EventProcessor::UpdateTargetForPointer(
- int32_t pointer_id,
- const ui::LocatedEvent& event,
- const PointerTarget& pointer_target,
- const EventLocation& event_location) {
- if (!IsTrackingPointer(pointer_id)) {
- StartTrackingPointer(pointer_id, pointer_target);
- return;
- }
-
- if (pointer_target.window == pointer_targets_[pointer_id].window &&
- pointer_target.in_nonclient_area ==
- pointer_targets_[pointer_id].in_nonclient_area) {
- // The targets are the same, only set the down state to true if necessary.
- // Down going to up is handled by ProcessLocatedEvent().
- if (pointer_target.is_pointer_down)
- pointer_targets_[pointer_id].is_pointer_down = true;
- return;
- }
-
- // The targets are changing. Send an exit if appropriate.
- if (event.IsMousePointerEvent()) {
- ui::PointerEvent exit_event(
- ui::ET_POINTER_EXITED, event.location(), event.root_location(),
- event.flags(), 0 /* changed_button_flags */,
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE,
- ui::MouseEvent::kMousePointerId),
- event.time_stamp());
- DispatchToPointerTarget(pointer_targets_[pointer_id], exit_event,
- event_location);
- }
-
- // Technically we're updating in place, but calling start then stop makes for
- // simpler code.
- StopTrackingPointer(pointer_id);
- StartTrackingPointer(pointer_id, pointer_target);
-}
-
-bool EventProcessor::AreAnyPointersDown() const {
- for (const auto& pair : pointer_targets_) {
- if (pair.second.is_pointer_down)
- return true;
- }
- return false;
-}
-
-void EventProcessor::DispatchToPointerTarget(
- const PointerTarget& target,
- const ui::LocatedEvent& event,
- const EventLocation& event_location) {
- if (!target.window) {
- delegate_->OnEventTargetNotFound(event, target.display_id);
- return;
- }
-
- if (target.is_mouse_event)
- mouse_cursor_in_non_client_area_ = target.in_nonclient_area;
-
- DispatchToClient(target.window,
- delegate_->GetEventTargetClientId(target.window,
- target.in_nonclient_area),
- event, event_location);
-}
-
-void EventProcessor::DispatchToClient(ServerWindow* window,
- ClientSpecificId client_id,
- const ui::LocatedEvent& event,
- const EventLocation& event_location) {
- gfx::Point location = ConvertPointFromRootForEventDispatch(
- delegate_->GetRootWindowForEventDispatch(window), window,
- event.location());
- std::unique_ptr<ui::Event> clone = ui::Event::Clone(event);
- clone->AsLocatedEvent()->set_location(location);
- // TODO(jonross): add post-target accelerator support once accelerators
- // support pointer events.
- event_dispatcher_->DispatchInputEventToWindow(
- window, client_id, event_location, *clone, nullptr);
-}
-
-void EventProcessor::CancelPointerEventsToTarget(ServerWindow* window) {
- if (capture_window_ == window) {
- UnobserveWindow(window);
- capture_window_ = nullptr;
- capture_window_client_id_ = kInvalidClientId;
- mouse_button_down_ = false;
- // A window only cares to be informed that it lost capture if it explicitly
- // requested capture. A window can lose capture if another window gains
- // explicit capture.
- delegate_->OnCaptureChanged(nullptr, window);
- delegate_->ReleaseNativeCapture();
- UpdateCursorProviderByLastKnownLocation();
- return;
- }
-
- for (auto& pair : pointer_targets_) {
- if (pair.second.window == window) {
- UnobserveWindow(window);
- pair.second.window = nullptr;
- }
- }
-}
-
-void EventProcessor::ObserveWindow(ServerWindow* window) {
- auto iter = observed_windows_.find(window);
- if (iter != observed_windows_.end()) {
- iter->second->num_observers++;
- return;
- }
- std::unique_ptr<ObservedWindow> observed_window =
- std::make_unique<ObservedWindow>();
- observed_window->num_observers = 1;
- observed_window->drawn_tracker =
- std::make_unique<ServerWindowDrawnTracker>(window, this);
- observed_windows_[window] = std::move(observed_window);
-}
-
-void EventProcessor::UnobserveWindow(ServerWindow* window) {
- auto it = observed_windows_.find(window);
- DCHECK(it != observed_windows_.end());
- DCHECK_LT(0u, it->second->num_observers);
- if (--it->second->num_observers == 0u)
- observed_windows_.erase(it);
-}
-
-Accelerator* EventProcessor::FindAccelerator(
- const ui::KeyEvent& event,
- const ui::mojom::AcceleratorPhase phase) {
- for (const auto& pair : accelerators_) {
- if (pair.second->MatchesEvent(event, phase))
- return pair.second.get();
- }
- return nullptr;
-}
-
-void EventProcessor::CancelImplicitCaptureExcept(ServerWindow* window,
- ClientSpecificId client_id) {
- for (const auto& pair : pointer_targets_) {
- ServerWindow* target = pair.second.window;
- if (!target)
- continue;
- UnobserveWindow(target);
- if (target == window)
- continue;
-
- // Don't send cancel events to the same client requesting capture,
- // otherwise the client can easily get confused.
- if (window && client_id == delegate_->GetEventTargetClientId(
- target, pair.second.in_nonclient_area)) {
- continue;
- }
-
- ui::EventType event_type = pair.second.is_mouse_event
- ? ui::ET_POINTER_EXITED
- : ui::ET_POINTER_CANCELLED;
- ui::EventPointerType pointer_type =
- pair.second.is_mouse_event ? ui::EventPointerType::POINTER_TYPE_MOUSE
- : ui::EventPointerType::POINTER_TYPE_TOUCH;
- // TODO(jonross): Track previous location in PointerTarget for sending
- // cancels.
- ui::PointerEvent event(event_type, gfx::Point(), gfx::Point(), ui::EF_NONE,
- 0 /* changed_button_flags */,
- ui::PointerDetails(pointer_type, pair.first),
- ui::EventTimeForNow());
- DispatchToPointerTarget(pair.second, event,
- EventLocation(pair.second.display_id));
- }
- pointer_targets_.clear();
-}
-
-void EventProcessor::WindowNoLongerValidTarget(ServerWindow* window) {
- CancelPointerEventsToTarget(window);
- if (mouse_cursor_source_window_ == window)
- SetMouseCursorSourceWindow(nullptr);
-}
-
-void EventProcessor::OnDrawnStateChanged(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) {
- if (!is_drawn)
- WindowNoLongerValidTarget(window);
-}
-
-void EventProcessor::OnRootDidChange(ServerWindow* ancestor,
- ServerWindow* window) {
- if (!delegate_->GetRootWindowForEventDispatch(window))
- WindowNoLongerValidTarget(window);
-}
-
-void EventProcessor::OnDragCursorUpdated() {
- delegate_->UpdateNativeCursorFromEventProcessor();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/event_processor.h b/services/ui/ws/event_processor.h
deleted file mode 100644
index df6269e..0000000
--- a/services/ui/ws/event_processor.h
+++ /dev/null
@@ -1,421 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_EVENT_PROCESSOR_H_
-#define SERVICES_UI_WS_EVENT_PROCESSOR_H_
-
-#include <stdint.h>
-
-#include <map>
-#include <memory>
-#include <utility>
-
-#include "base/containers/flat_map.h"
-#include "base/macros.h"
-#include "services/ui/common/types.h"
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "services/ui/public/interfaces/window_manager.mojom.h"
-#include "services/ui/ws/drag_cursor_updater.h"
-#include "services/ui/ws/event_matcher.h"
-#include "services/ui/ws/event_targeter.h"
-#include "services/ui/ws/event_targeter_delegate.h"
-#include "services/ui/ws/modal_window_controller.h"
-#include "services/ui/ws/server_window_drawn_tracker_observer.h"
-#include "ui/display/types/display_constants.h"
-#include "ui/gfx/geometry/point_f.h"
-#include "ui/gfx/geometry/rect_f.h"
-
-namespace viz {
-class HitTestQuery;
-}
-
-namespace ui {
-class Event;
-class KeyEvent;
-class LocatedEvent;
-
-namespace ws {
-
-class Accelerator;
-class DragController;
-class DragSource;
-class DragTargetConnection;
-class EventDispatcher;
-class EventProcessorDelegate;
-class ServerWindow;
-class ServerWindowDrawnTracker;
-
-struct EventLocation;
-
-namespace test {
-class EventProcessorTestApi;
-}
-
-// EventProcessor is responsible for processing events and maintaining event
-// related state: capture, cursor, last mouse location... EventProcessor informs
-// EventProcessorDelegate of interesting state changes and uses an
-// EventDispatcher for the actual dispatch. EventProcessor uses EventTargeter
-// to determine the actual target. EventProcessor handles a single event at a
-// time, and it may asynchronously process the event (EventTargeter may work
-// asynchronously). A single event may result in multiple calls to
-// EventDispatcher::DispatchEvent().
-class EventProcessor : public ServerWindowDrawnTrackerObserver,
- public DragCursorUpdater,
- public EventTargeterDelegate {
- public:
- enum class AcceleratorMatchPhase {
- // Both pre and post should be considered.
- ANY,
-
- // PRE_TARGETs are not considered, only the actual target and any
- // accelerators registered with POST_TARGET.
- POST_ONLY,
- };
-
- EventProcessor(EventProcessorDelegate* delegate,
- EventDispatcher* event_dispatcher);
- ~EventProcessor() override;
-
- ModalWindowController* modal_window_controller() {
- return &modal_window_controller_;
- }
-
- // Cancels capture and stops tracking any pointer events. This does not send
- // any events to the delegate.
- void Reset();
-
- const gfx::PointF& mouse_pointer_last_location() const {
- return mouse_pointer_last_location_;
- }
- int64_t mouse_pointer_display_id() const { return mouse_pointer_display_id_; }
-
- // Returns the cursor for the current target, or POINTER if the mouse is not
- // over a valid target.
- ui::CursorData GetCurrentMouseCursor() const;
-
- // |capture_window_| will receive all input. See window_tree.mojom for
- // details.
- ServerWindow* capture_window() { return capture_window_; }
- const ServerWindow* capture_window() const { return capture_window_; }
- // Setting capture can fail if the window is blocked by a modal window
- // (indicated by returning |false|).
- bool SetCaptureWindow(ServerWindow* capture_window,
- ClientSpecificId client_id);
-
- // Id of the client that capture events are sent to.
- ClientSpecificId capture_window_client_id() const {
- return capture_window_client_id_;
- }
-
- void SetDragDropSourceWindow(
- DragSource* drag_source,
- ServerWindow* window,
- DragTargetConnection* source_connection,
- int32_t drag_pointer,
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data,
- uint32_t drag_operations);
- void CancelDragDrop();
- void EndDragDrop();
-
- void OnWillDestroyDragTargetConnection(DragTargetConnection* connection);
-
- // Adds a system modal window. The window remains modal to system until it is
- // destroyed. There can exist multiple system modal windows, in which case the
- // one that is visible and added most recently or shown most recently would be
- // the active one.
- void AddSystemModalWindow(ServerWindow* window);
-
- // Checks if the current capture window is blocked by any visible modal window
- // and if that's the case, releases the capture.
- void ReleaseCaptureBlockedByAnyModalWindow();
-
- // Retrieves the ServerWindow of the last mouse move. If there is no valid
- // window event target this falls back to the root of the display. In general
- // this is not null, but may be null during shutdown.
- ServerWindow* mouse_cursor_source_window() const {
- return mouse_cursor_source_window_;
- }
-
- // Returns the window the mouse cursor is taken from. This does not take
- // into account drags. In other words if there is a drag on going the mouse
- // comes comes from a different window.
- const ServerWindow* GetWindowForMouseCursor() const;
-
- // If the mouse cursor is still over |mouse_cursor_source_window_|, updates
- // whether we are in the non-client area. Used when
- // |mouse_cursor_source_window_| has changed its properties.
- void UpdateNonClientAreaForCurrentWindow();
-
- // Possibly updates the cursor. If we aren't in an implicit capture, we take
- // the last known location of the mouse pointer, and look for the
- // ServerWindow* under it.
- void UpdateCursorProviderByLastKnownLocation();
-
- // Adds an accelerator with the given id and event-matcher. If an accelerator
- // already exists with the same id or the same matcher, then the accelerator
- // is not added. Returns whether adding the accelerator was successful or not.
- bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher);
-
- void RemoveAccelerator(uint32_t id);
-
- void SetKeyEventsThatDontHideCursor(
- std::vector<::ui::mojom::EventMatcherPtr> dont_hide_cursor_list);
-
- // True if we are actively finding a target for an event, false otherwise.
- bool IsProcessingEvent() const;
-
- // Processes the supplied event, informing the delegate as approriate. This
- // may result in generating any number of events. If |match_phase| is
- // ANY and there is a matching accelerator with PRE_TARGET found, than only
- // OnAccelerator() is called. The expectation is after the PRE_TARGET has been
- // handled this is again called with an AcceleratorMatchPhase of POST_ONLY.
- // This may be asynchronous if we need to find the target window for |event|
- // asynchronously.
- // NOTE: if |event| is a LocatedEvent, then |event_location.location| is the
- // same as the location (and root_location) of |event|.
- void ProcessEvent(const ui::Event& event,
- const EventLocation& event_location,
- AcceleratorMatchPhase match_phase);
-
- // EventTargeterDelegate:
- ServerWindow* GetRootWindowForDisplay(int64_t display_id) override;
- viz::HitTestQuery* GetHitTestQueryForDisplay(int64_t display_id) override;
- ServerWindow* GetWindowFromFrameSinkId(
- const viz::FrameSinkId& frame_sink_id) override;
-
- private:
- friend class test::EventProcessorTestApi;
-
- // Keeps track of state associated with an active pointer.
- struct PointerTarget {
- // The target window, which may be null. null is used in two situations:
- // when there is no valid window target, or there was a target but the
- // window is destroyed before a corresponding release/cancel.
- ServerWindow* window = nullptr;
-
- bool is_mouse_event = false;
-
- // Did the pointer event start in the non-client area.
- bool in_nonclient_area = false;
-
- bool is_pointer_down = false;
-
- int64_t display_id = display::kInvalidDisplayId;
- };
-
- struct DeepestWindowAndTarget {
- PointerTarget pointer_target;
- DeepestWindow deepest_window;
- };
-
- struct ObservedWindow {
- ObservedWindow();
- ~ObservedWindow();
-
- // Number of times ObserveWindow() has been called.
- uint8_t num_observers = 0;
-
- std::unique_ptr<ServerWindowDrawnTracker> drawn_tracker;
- };
-
- // EventTargeter returns the deepest window based on hit-test data. If the
- // target is blocked by a modal window this returns a different target,
- // otherwise the supplied target is returned.
- DeepestWindow AdjustTargetForModal(const DeepestWindow& target) const;
-
- void SetMouseCursorSourceWindow(ServerWindow* window);
-
- // Called after we found the target for the current mouse cursor to see if
- // |mouse_pointer_last_location_| and |mouse_pointer_display_id_| need to be
- // updated based on the new target we found. No need to call delegate's
- // OnMouseCursorLocationChanged since mouse location is the same in
- // screen-coord.
- // TODO(riajiang): No need to update mouse location after ozone drm can tell
- // us the right display the cursor is on for drag-n-drop events.
- // crbug.com/726470
- void SetMousePointerLocation(const gfx::PointF& new_mouse_location,
- int64_t new_mouse_display_id);
-
- void ProcessKeyEvent(const ui::KeyEvent& event,
- int64_t display_id,
- AcceleratorMatchPhase match_phase);
-
- // When the user presses a key, we want to hide the cursor if it doesn't
- // match a list of window manager supplied keys.
- void HideCursorOnMatchedKeyEvent(const ui::KeyEvent& event);
-
- bool IsTrackingPointer(int32_t pointer_id) const {
- return pointer_targets_.count(pointer_id) > 0;
- }
-
- // Returns true if EventTargeter needs to be queried for the specified event.
- bool ShouldUseEventTargeter(const Event& event) const;
-
- // Callback from EventTargeter once the target has been found. Calls
- // ProcessEventOnFoundTargetImpl().
- void ProcessEventOnFoundTarget(std::unique_ptr<ui::Event> event,
- const EventLocation& event_location,
- const DeepestWindow& target);
-
- // EventProcessor provides the following logic for events:
- // . wheel events go to the current target of the associated pointer. If
- // there is no target, they go to the deepest window.
- // . move (not drag) events go to the deepest window.
- // . when a pointer goes down all events until the corresponding up or
- // cancel go to the deepest target. For mouse events the up only occurs
- // when no buttons on the mouse are down.
- // This also generates exit events as appropriate. For example, if the mouse
- // moves between one window to another an exit is generated on the first.
- //
- // NOTE: |found_target| is null if ShouldUseEventTargeter() returned false.
- // If ShouldUseEventTargeter() returned false it means this function should
- // not need |found_target| and has enough information to process the event
- // without a DeepestWindow.
- void ProcessEventOnFoundTargetImpl(std::unique_ptr<ui::Event> event,
- const EventLocation& event_location,
- const DeepestWindow* found_target);
-
- // Called when processing a event to updated cursor related properties.
- void UpdateCursorRelatedProperties(const ui::Event& event,
- const EventLocation& event_location);
-
- void UpdateNonClientAreaForCurrentWindowOnFoundWindow(
- const EventLocation& event_location,
- const DeepestWindow& target);
-
- // This callback is triggered by UpdateCursorProviderByLastKnownLocation().
- // It calls UpdateCursorProvider() as appropriate.
- void UpdateCursorProviderByLastKnownLocationOnFoundWindow(
- const EventLocation& event_location,
- const DeepestWindow& target);
-
- // Immediatley updates the cursor provider (|mouse_cursor_source_window_|)
- // as appropriate.
- void UpdateCursorProvider(const DeepestWindow& target);
-
- // Called during a click to nodify if the click was blocked by a modal.
- void HandleClickOnBlockedWindow(const DeepestWindow& target);
-
- // Adds |pointer_target| to |pointer_targets_|.
- void StartTrackingPointer(int32_t pointer_id,
- const PointerTarget& pointer_target);
-
- // Removes a PointerTarget from |pointer_targets_|.
- void StopTrackingPointer(int32_t pointer_id);
-
- // Starts tracking the pointer for |event|, or if already tracking the
- // pointer sends the appropriate event to the delegate and updates the
- // currently tracked PointerTarget appropriately.
- void UpdateTargetForPointer(int32_t pointer_id,
- const ui::LocatedEvent& event,
- const PointerTarget& pointer_target,
- const EventLocation& event_location);
-
- // Returns true if any pointers are in the pressed/down state.
- bool AreAnyPointersDown() const;
-
- // If |target->window| is valid, then passes the event to the delegate.
- void DispatchToPointerTarget(const PointerTarget& target,
- const ui::LocatedEvent& event,
- const EventLocation& event_location);
-
- // Dispatch |event| to the delegate.
- void DispatchToClient(ServerWindow* window,
- ClientSpecificId client_id,
- const ui::LocatedEvent& event,
- const EventLocation& event_location);
-
- // Stops sending pointer events to |window|. This does not remove the entry
- // for |window| from |pointer_targets_|, rather it nulls out the window. This
- // way we continue to eat events until the up/cancel is received.
- void CancelPointerEventsToTarget(ServerWindow* window);
-
- // Used to observe a window. Can be called multiple times on a window. To
- // unobserve a window, UnobserveWindow() should be called the same number of
- // times.
- void ObserveWindow(ServerWindow* winodw);
- void UnobserveWindow(ServerWindow* winodw);
-
- // Returns an Accelerator bound to the specified code/flags, and of the
- // matching |phase|. Otherwise returns null.
- Accelerator* FindAccelerator(const ui::KeyEvent& event,
- const ui::mojom::AcceleratorPhase phase);
-
- // Clears the implicit captures in |pointer_targets_|, with the exception of
- // |window|. |window| may be null. |client_id| is the target client of
- // |window|.
- void CancelImplicitCaptureExcept(ServerWindow* window,
- ClientSpecificId client_id);
-
- // Called when |window| is no longer a valid target for events, for example,
- // the window was removed from the hierarchy.
- void WindowNoLongerValidTarget(ServerWindow* window);
-
- // ServerWindowDrawnTrackerObserver:
- void OnDrawnStateChanged(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) override;
- void OnRootDidChange(ServerWindow* ancestor, ServerWindow* window) override;
-
- // DragCursorUpdater:
- void OnDragCursorUpdated() override;
-
- EventProcessorDelegate* delegate_;
- EventDispatcher* event_dispatcher_;
-
- ServerWindow* capture_window_;
- ClientSpecificId capture_window_client_id_;
-
- std::unique_ptr<DragController> drag_controller_;
-
- ModalWindowController modal_window_controller_;
-
- std::unique_ptr<EventTargeter> event_targeter_;
-
- bool mouse_button_down_;
- ServerWindow* mouse_cursor_source_window_;
- bool mouse_cursor_in_non_client_area_;
-
- // The location of the mouse pointer in display coordinates. This can be
- // outside the bounds of |mouse_cursor_source_window_|, which can capture the
- // cursor.
- gfx::PointF mouse_pointer_last_location_;
- // Id of the display |mouse_pointer_last_location_| is on.
- int64_t mouse_pointer_display_id_ = display::kInvalidDisplayId;
-
- std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_;
-
- // A list of EventMatchers provided by the window manager. When this list is
- // empty, we perform no processing. When it contains EventMatchers, we run
- // each post-targeted key event through this list and if there's a match, we
- // don't hide the cursor (otherwise we hide the cursor).
- std::vector<EventMatcher> dont_hide_cursor_matchers_;
-
- using PointerIdToTargetMap = std::map<int32_t, PointerTarget>;
- // |pointer_targets_| contains the active pointers. For a mouse based pointer
- // a PointerTarget is always active (and present in |pointer_targets_|). For
- // touch based pointers the pointer is active while down and removed on
- // cancel or up.
- PointerIdToTargetMap pointer_targets_;
-
- // Keeps track of number of observe requests for each observed window.
- std::map<const ServerWindow*, std::unique_ptr<ObservedWindow>>
- observed_windows_;
-
- // Set to true when querying EventTargeter for the target.
- bool waiting_on_event_targeter_ = false;
-
-#if !defined(NDEBUG)
- std::unique_ptr<ui::Event> previous_event_;
- AcceleratorMatchPhase previous_accelerator_match_phase_ =
- AcceleratorMatchPhase::ANY;
-#endif
-
- DISALLOW_COPY_AND_ASSIGN(EventProcessor);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_PROCESSOR_H_
diff --git a/services/ui/ws/event_processor_delegate.h b/services/ui/ws/event_processor_delegate.h
deleted file mode 100644
index f0408f7..0000000
--- a/services/ui/ws/event_processor_delegate.h
+++ /dev/null
@@ -1,116 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_EVENT_PROCESSOR_DELEGATE_H_
-#define SERVICES_UI_WS_EVENT_PROCESSOR_DELEGATE_H_
-
-#include <stdint.h>
-
-#include "services/ui/common/types.h"
-
-namespace gfx {
-class PointF;
-}
-
-namespace viz {
-class FrameSinkId;
-class HitTestQuery;
-}
-
-namespace ui {
-
-class Event;
-
-namespace ws {
-
-class ServerWindow;
-
-// Notified of various state changes to EventProcessor. This is also used to
-// obtain ServerWindows matching certain criteria (such as the ServerWindow for
-// a display).
-class EventProcessorDelegate {
- public:
- virtual void SetFocusedWindowFromEventProcessor(ServerWindow* window) = 0;
- virtual ServerWindow* GetFocusedWindowForEventProcessor(
- int64_t display_id) = 0;
-
- // Called when capture should be set on the native display. |window| is the
- // window capture is being set on.
- virtual void SetNativeCapture(ServerWindow* window) = 0;
-
- // Called when the native display is having capture released. There is no
- // longer a ServerWindow holding capture.
- virtual void ReleaseNativeCapture() = 0;
-
- // Called when EventProcessor has a new value for the cursor and our
- // delegate should perform the native updates.
- virtual void UpdateNativeCursorFromEventProcessor() = 0;
-
- // Called when |window| has lost capture. The native display may still be
- // holding capture. The delegate should not change native display capture.
- // ReleaseNativeCapture() is invoked if appropriate.
- virtual void OnCaptureChanged(ServerWindow* new_capture,
- ServerWindow* old_capture) = 0;
-
- virtual void OnMouseCursorLocationChanged(const gfx::PointF& point,
- int64_t display_id) = 0;
-
- virtual void OnEventChangesCursorVisibility(const ui::Event& event,
- bool visible) = 0;
-
- virtual void OnEventChangesCursorTouchVisibility(const ui::Event& event,
- bool visible) = 0;
-
- // Returns the id of the client to send events to. |in_nonclient_area| is
- // true if the event occurred in the non-client area of the window.
- virtual ClientSpecificId GetEventTargetClientId(const ServerWindow* window,
- bool in_nonclient_area) = 0;
-
- // Returns the window to start searching from at the specified location, or
- // null if there is a no window containing |location_in_display|.
- // |location_in_display| is in display coordinates and in pixels.
- // |location_in_display| and |display_id| are updated if the window we
- // found is on a different display than the originated display.
- // TODO(riajiang): No need to update |location_in_display| and |display_id|
- // after ozone drm can tell us the right display the cursor is on for
- // drag-n-drop events. crbug.com/726470
- virtual ServerWindow* GetRootWindowForDisplay(int64_t display_id) = 0;
-
- // Returns the root of |window| that is used for event dispatch. The returned
- // value is used for coordinate conversion. Returns null if |window| is not
- // in a hierarchy that events should be dispatched to (typically not
- // associated with a display).
- virtual ServerWindow* GetRootWindowForEventDispatch(ServerWindow* window) = 0;
-
- // Called when event dispatch could not find a target. OnAccelerator may still
- // be called.
- virtual void OnEventTargetNotFound(const ui::Event& event,
- int64_t display_id) = 0;
-
- // If an event is blocked by a modal window this function is used to determine
- // which window the event should be dispatched to. Return null to indicate no
- // window. |window| is the window the event would be targetted at if there was
- // no modal window open.
- virtual ServerWindow* GetFallbackTargetForEventBlockedByModal(
- ServerWindow* window) = 0;
-
- // Called when an event occurs that targets a window that should be blocked
- // by a modal window. |modal_window| is the modal window that blocked the
- // event.
- virtual void OnEventOccurredOutsideOfModalWindow(
- ServerWindow* modal_window) = 0;
-
- virtual viz::HitTestQuery* GetHitTestQueryForDisplay(int64_t display_id) = 0;
-
- virtual ServerWindow* GetWindowFromFrameSinkId(
- const viz::FrameSinkId& frame_sink_id) = 0;
-
- protected:
- virtual ~EventProcessorDelegate() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_PROCESSOR_DELEGATE_H_
diff --git a/services/ui/ws/event_processor_unittest.cc b/services/ui/ws/event_processor_unittest.cc
deleted file mode 100644
index 135ddea..0000000
--- a/services/ui/ws/event_processor_unittest.cc
+++ /dev/null
@@ -1,2337 +0,0 @@
-// 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 "services/ui/ws/event_processor.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "base/command_line.h"
-#include "base/containers/queue.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "base/run_loop.h"
-#include "base/test/scoped_feature_list.h"
-#include "base/test/scoped_task_environment.h"
-#include "components/viz/common/features.h"
-#include "components/viz/host/hit_test/hit_test_query.h"
-#include "services/ui/common/accelerator_util.h"
-#include "services/ui/common/switches.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/ui/ws/accelerator.h"
-#include "services/ui/ws/event_dispatcher.h"
-#include "services/ui/ws/event_location.h"
-#include "services/ui/ws/event_processor_delegate.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/events/event.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-namespace {
-
-// Client ids used to indicate the client area and non-client area.
-const ClientSpecificId kClientAreaId = 11;
-const ClientSpecificId kNonclientAreaId = 111;
-
-// Identifies a generated event.
-struct DispatchedEventDetails {
- DispatchedEventDetails()
- : window(nullptr), client_id(kInvalidClientId), accelerator(nullptr) {}
-
- bool IsNonclientArea() const { return client_id == kNonclientAreaId; }
- bool IsClientArea() const { return client_id == kClientAreaId; }
-
- ServerWindow* window;
- ClientSpecificId client_id;
- std::unique_ptr<ui::Event> event;
- Accelerator* accelerator;
-};
-
-// Serves as both the EventProcessorDelegate and EventDispatcher
-// implementation. Records interesting calls for various assertions.
-class TestEventProcessorDelegate : public EventProcessorDelegate,
- public EventDispatcher {
- public:
- // Delegate interface used by this class to release capture on event
- // dispatcher.
- class Delegate {
- public:
- virtual void ReleaseCapture() = 0;
- };
-
- explicit TestEventProcessorDelegate(Delegate* delegate)
- : delegate_(delegate),
- focused_window_(nullptr),
- lost_capture_window_(nullptr),
- last_accelerator_(0) {}
- ~TestEventProcessorDelegate() override {}
-
- void EnableFallbackToRoot() { fallback_to_root_ = true; }
-
- void set_is_window_in_display_root(bool value) {
- is_window_in_display_root_ = value;
- }
-
- ui::Event* last_event_target_not_found() {
- return last_event_target_not_found_.get();
- }
-
- uint32_t GetAndClearLastAccelerator() {
- uint32_t return_value = last_accelerator_;
- last_accelerator_ = 0;
- last_accelerator_phase_ = AcceleratorPhase::kPost;
- return return_value;
- }
-
- AcceleratorPhase last_accelerator_phase() const {
- return last_accelerator_phase_;
- }
-
- void set_root(ServerWindow* root) { root_ = root; }
-
- ServerWindow* window_that_blocked_event() {
- return window_that_blocked_event_;
- }
- void ClearWindowThatBlockedEvent() { window_that_blocked_event_ = nullptr; }
-
- // Returns the last dispatched event, or null if there are no more.
- std::unique_ptr<DispatchedEventDetails>
- GetAndAdvanceDispatchedEventDetails() {
- if (dispatched_event_queue_.empty())
- return nullptr;
-
- std::unique_ptr<DispatchedEventDetails> details =
- std::move(dispatched_event_queue_.front());
- dispatched_event_queue_.pop();
- return details;
- }
-
- ServerWindow* GetAndClearLastFocusedWindow() {
- ServerWindow* result = focused_window_;
- focused_window_ = nullptr;
- return result;
- }
-
- bool has_queued_events() const { return !dispatched_event_queue_.empty(); }
- ServerWindow* lost_capture_window() { return lost_capture_window_; }
-
- base::Optional<bool> last_cursor_visibility() {
- return last_cursor_visibility_;
- }
-
- viz::HitTestQuery* hit_test_query() { return &hit_test_query_; }
-
- void AddWindow(ServerWindow* window) { windows_.push_back(window); }
-
- // EventProcessorDelegate:
- void SetFocusedWindowFromEventProcessor(ServerWindow* window) override {
- focused_window_ = window;
- }
-
- private:
- // EventDispatcher:
- void DispatchInputEventToWindow(ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const ui::Event& event,
- Accelerator* accelerator) override {
- std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails);
- details->window = target;
- details->client_id = client_id;
- details->event = ui::Event::Clone(event);
- details->accelerator = accelerator;
- dispatched_event_queue_.push(std::move(details));
- }
- void OnAccelerator(uint32_t accelerator,
- int64_t display_id,
- const ui::Event& event,
- AcceleratorPhase phase) override {
- EXPECT_EQ(0u, last_accelerator_);
- last_accelerator_ = accelerator;
- last_accelerator_phase_ = phase;
- }
-
- // EventProcessorDelegate:
- ServerWindow* GetFocusedWindowForEventProcessor(int64_t display_id) override {
- return focused_window_;
- }
- void SetNativeCapture(ServerWindow* window) override {}
- void ReleaseNativeCapture() override {
- if (delegate_)
- delegate_->ReleaseCapture();
- }
- void UpdateNativeCursorFromEventProcessor() override {}
- void OnCaptureChanged(ServerWindow* new_capture_window,
- ServerWindow* old_capture_window) override {
- lost_capture_window_ = old_capture_window;
- }
- void OnMouseCursorLocationChanged(const gfx::PointF& point,
- int64_t display_id) override {}
- void OnEventChangesCursorVisibility(const ui::Event& event,
- bool visible) override {
- last_cursor_visibility_ = visible;
- }
- void OnEventChangesCursorTouchVisibility(const ui::Event& event,
- bool visible) override {}
- ClientSpecificId GetEventTargetClientId(const ServerWindow* window,
- bool in_nonclient_area) override {
- return in_nonclient_area ? kNonclientAreaId : kClientAreaId;
- }
- ServerWindow* GetRootWindowForDisplay(int64_t display_id) override {
- return root_;
- }
- void OnEventTargetNotFound(const ui::Event& event,
- int64_t display_id) override {
- last_event_target_not_found_ = ui::Event::Clone(event);
- }
- ServerWindow* GetFallbackTargetForEventBlockedByModal(
- ServerWindow* window) override {
- return fallback_to_root_ ? root_ : nullptr;
- }
- void OnEventOccurredOutsideOfModalWindow(
- ServerWindow* modal_transient) override {
- window_that_blocked_event_ = modal_transient;
- }
- viz::HitTestQuery* GetHitTestQueryForDisplay(int64_t display_id) override {
- return &hit_test_query_;
- }
- ServerWindow* GetWindowFromFrameSinkId(
- const viz::FrameSinkId& frame_sink_id) override {
- for (ServerWindow* window : windows_) {
- if (window->frame_sink_id() == frame_sink_id)
- return window;
- }
- return nullptr;
- }
- ServerWindow* GetRootWindowForEventDispatch(ServerWindow* window) override {
- return is_window_in_display_root_ ? window->GetRootForDrawn() : nullptr;
- }
-
- Delegate* delegate_;
- ServerWindow* focused_window_;
- ServerWindow* lost_capture_window_;
- uint32_t last_accelerator_;
- AcceleratorPhase last_accelerator_phase_ = AcceleratorPhase::kPost;
- base::queue<std::unique_ptr<DispatchedEventDetails>> dispatched_event_queue_;
- ServerWindow* root_ = nullptr;
- std::unique_ptr<ui::Event> last_event_target_not_found_;
- base::Optional<bool> last_cursor_visibility_;
- ServerWindow* window_that_blocked_event_ = nullptr;
- viz::HitTestQuery hit_test_query_;
- std::vector<ServerWindow*> windows_;
-
- // If true events blocked by a modal window are sent to |root_|.
- bool fallback_to_root_ = false;
-
- bool is_window_in_display_root_ = true;
-
- DISALLOW_COPY_AND_ASSIGN(TestEventProcessorDelegate);
-};
-
-// Used by RunMouseEventTests(). Can identify up to two generated events. The
-// first ServerWindow and two points identify the first event, the second
-// ServerWindow and points identify the second event. If only one event is
-// generated set the second window to null.
-struct MouseEventTest {
- std::unique_ptr<ui::MouseEvent> input_event;
- ServerWindow* expected_target_window1;
- gfx::Point expected_root_location1;
- gfx::Point expected_location1;
- ServerWindow* expected_target_window2;
- gfx::Point expected_root_location2;
- gfx::Point expected_location2;
-};
-
-// Verifies |details| matches the supplied ServerWindow and points.
-void ExpectDispatchedEventDetailsMatches(const DispatchedEventDetails* details,
- ServerWindow* target,
- const gfx::Point& root_location,
- const gfx::Point& location) {
- if (!target) {
- ASSERT_FALSE(details);
- return;
- }
- ASSERT_TRUE(details);
- ASSERT_EQ(target, details->window);
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsLocatedEvent());
- ASSERT_TRUE(details->IsClientArea());
- ASSERT_EQ(root_location, details->event->AsLocatedEvent()->root_location());
- ASSERT_EQ(location, details->event->AsLocatedEvent()->location());
-}
-
-ui::mojom::EventMatcherPtr BuildKeyMatcher(ui::mojom::KeyboardCode code) {
- ui::mojom::EventMatcherPtr matcher(ui::mojom::EventMatcher::New());
- matcher->key_matcher = ui::mojom::KeyEventMatcher::New();
- matcher->key_matcher->keyboard_code = code;
- return matcher;
-}
-
-EventLocation EventLocationFromEvent(const Event& event) {
- EventLocation event_location(0);
- if (event.IsLocatedEvent()) {
- event_location.raw_location = event_location.location =
- event.AsLocatedEvent()->root_location_f();
- }
- return event_location;
-}
-
-} // namespace
-
-// Test fixture for EventProcessor with friend access to verify the internal
-// state. Setup creates a TestServerWindowDelegate, a visible root ServerWindow,
-// a TestEventProcessor and the EventProcessor for testing.
-class EventProcessorTest : public testing::TestWithParam<bool>,
- public TestEventProcessorDelegate::Delegate {
- public:
- EventProcessorTest() {}
- ~EventProcessorTest() override {}
-
- ServerWindow* root_window() { return root_window_.get(); }
- TestEventProcessorDelegate* test_event_dispatcher_delegate() {
- return test_event_dispatcher_delegate_.get();
- }
- EventProcessor* event_dispatcher() { return event_dispatcher_.get(); }
- VizHostProxy* viz_host_proxy() {
- return ws_test_helper_.window_server()->GetVizHostProxy();
- }
- TestServerWindowDelegate* window_delegate() { return window_delegate_.get(); }
-
- void DispatchEvent(EventProcessor* dispatcher,
- const ui::Event& event,
- EventProcessor::AcceleratorMatchPhase match_phase);
- void RunMouseEventTests(EventProcessor* dispatcher,
- TestEventProcessorDelegate* dispatcher_delegate,
- MouseEventTest* tests,
- size_t test_count);
- bool AreAnyPointersDown() const;
- // Deletes everything created during SetUp()
- void ClearSetup();
- std::unique_ptr<ServerWindow> CreateChildWindowWithParent(
- const viz::FrameSinkId& id,
- ServerWindow* parent);
- // Creates a window which is a child of |root_window_|.
- std::unique_ptr<ServerWindow> CreateChildWindow(const viz::FrameSinkId& id);
- bool IsMouseButtonDown() const;
- bool IsWindowPointerTarget(const ServerWindow* window) const;
- int NumberPointerTargetsForWindow(ServerWindow* window) const;
- const ServerWindow* GetActiveSystemModalWindow() const;
-
- protected:
- bool is_event_processing_async() const { return GetParam(); }
-
- // testing::TestWithParam<bool>:
- void SetUp() override;
-
- void RunTasks();
-
- private:
- // TestEventProcessorDelegate::Delegate:
- void ReleaseCapture() override {
- event_dispatcher_->SetCaptureWindow(nullptr, kInvalidClientId);
- }
-
- WindowServerTestHelper ws_test_helper_;
-
- std::unique_ptr<TestServerWindowDelegate> window_delegate_;
- std::unique_ptr<ServerWindow> root_window_;
- std::unique_ptr<TestEventProcessorDelegate> test_event_dispatcher_delegate_;
- std::unique_ptr<EventProcessor> event_dispatcher_;
-
- DISALLOW_COPY_AND_ASSIGN(EventProcessorTest);
-};
-
-void EventProcessorTest::DispatchEvent(
- EventProcessor* dispatcher,
- const ui::Event& event,
- EventProcessor::AcceleratorMatchPhase match_phase) {
- dispatcher->ProcessEvent(event, EventLocationFromEvent(event), match_phase);
- RunTasks();
-}
-
-void EventProcessorTest::RunMouseEventTests(
- EventProcessor* dispatcher,
- TestEventProcessorDelegate* dispatcher_delegate,
- MouseEventTest* tests,
- size_t test_count) {
- for (size_t i = 0; i < test_count; ++i) {
- const MouseEventTest& test = tests[i];
- ASSERT_FALSE(dispatcher_delegate->has_queued_events())
- << " unexpected queued events before running " << i;
- DispatchEvent(dispatcher, ui::PointerEvent(*test.input_event),
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches(
- details.get(), test.expected_target_window1,
- test.expected_root_location1, test.expected_location1))
- << " details don't match " << i;
- details = dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches(
- details.get(), test.expected_target_window2,
- test.expected_root_location2, test.expected_location2))
- << " details2 don't match " << i;
- ASSERT_FALSE(dispatcher_delegate->has_queued_events())
- << " unexpected queued events after running " << i;
- }
-}
-
-bool EventProcessorTest::AreAnyPointersDown() const {
- return EventProcessorTestApi(event_dispatcher_.get()).AreAnyPointersDown();
-}
-
-void EventProcessorTest::ClearSetup() {
- // ServerWindowDelegate should outlive ServerWindow.
- root_window_.reset();
- window_delegate_.reset();
- test_event_dispatcher_delegate_.reset();
- event_dispatcher_.reset();
-}
-
-std::unique_ptr<ServerWindow> EventProcessorTest::CreateChildWindowWithParent(
- const viz::FrameSinkId& id,
- ServerWindow* parent) {
- std::unique_ptr<ServerWindow> child(
- new ServerWindow(window_delegate_.get(), id));
- parent->Add(child.get());
- child->SetVisible(true);
- return child;
-}
-
-std::unique_ptr<ServerWindow> EventProcessorTest::CreateChildWindow(
- const viz::FrameSinkId& id) {
- return CreateChildWindowWithParent(id, root_window_.get());
-}
-
-bool EventProcessorTest::IsMouseButtonDown() const {
- return EventProcessorTestApi(event_dispatcher_.get()).is_mouse_button_down();
-}
-
-bool EventProcessorTest::IsWindowPointerTarget(
- const ServerWindow* window) const {
- return EventProcessorTestApi(event_dispatcher_.get())
- .IsWindowPointerTarget(window);
-}
-
-int EventProcessorTest::NumberPointerTargetsForWindow(
- ServerWindow* window) const {
- return EventProcessorTestApi(event_dispatcher_.get())
- .NumberPointerTargetsForWindow(window);
-}
-
-const ServerWindow* EventProcessorTest::GetActiveSystemModalWindow() const {
- ModalWindowController* mwc =
- EventProcessorTestApi(event_dispatcher_.get()).modal_window_controller();
- return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow();
-}
-
-void EventProcessorTest::RunTasks() {
- if (!is_event_processing_async())
- return;
-
- base::RunLoop runloop;
- runloop.RunUntilIdle();
-}
-
-void EventProcessorTest::SetUp() {
- if (is_event_processing_async()) {
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- switches::kUseAsyncEventTargeting);
- }
- testing::TestWithParam<bool>::SetUp();
-
- window_delegate_ =
- std::make_unique<TestServerWindowDelegate>(viz_host_proxy());
- root_window_ = std::make_unique<ServerWindow>(window_delegate_.get(),
- viz::FrameSinkId(1, 2));
- root_window_->set_is_activation_parent(true);
- window_delegate_->set_root_window(root_window_.get());
- root_window_->SetVisible(true);
-
- test_event_dispatcher_delegate_ =
- std::make_unique<TestEventProcessorDelegate>(this);
- event_dispatcher_ =
- std::make_unique<EventProcessor>(test_event_dispatcher_delegate_.get(),
- test_event_dispatcher_delegate_.get());
- test_event_dispatcher_delegate_->set_root(root_window_.get());
-}
-
-TEST_P(EventProcessorTest, ProcessEvent) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- // Send event that is over child.
- const ui::PointerEvent ui_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), ui_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- ASSERT_EQ(child.get(), details->window);
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location());
-}
-
-TEST_P(EventProcessorTest, ProcessEventNoTarget) {
- // Send event without a target.
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
- DispatchEvent(event_dispatcher(), key,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Event wasn't dispatched to a target.
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(details);
-
- // Delegate was informed that there wasn't a target.
- ui::Event* event_out =
- test_event_dispatcher_delegate()->last_event_target_not_found();
- ASSERT_TRUE(event_out);
- EXPECT_TRUE(event_out->IsKeyEvent());
- EXPECT_EQ(ui::VKEY_A, event_out->AsKeyEvent()->key_code());
-}
-
-TEST_P(EventProcessorTest, AcceleratorBasic) {
- ClearSetup();
- TestEventProcessorDelegate event_dispatcher_delegate(nullptr);
- EventProcessor dispatcher(&event_dispatcher_delegate,
- &event_dispatcher_delegate);
-
- uint32_t accelerator_1 = 1;
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
- EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher)));
-
- uint32_t accelerator_2 = 2;
- matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::N,
- ui::mojom::kEventFlagNone);
- EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher)));
-
- // Attempting to add a new accelerator with the same id should fail.
- matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T,
- ui::mojom::kEventFlagNone);
- EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher)));
-
- // Adding the accelerator with the same id should succeed once the existing
- // accelerator is removed.
- dispatcher.RemoveAccelerator(accelerator_2);
- matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T,
- ui::mojom::kEventFlagNone);
- EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher)));
-
- // Attempting to add an accelerator with the same matcher should fail.
- uint32_t accelerator_3 = 3;
- matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T,
- ui::mojom::kEventFlagNone);
- EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher)));
-
- matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T,
- ui::mojom::kEventFlagControlDown);
- EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher)));
-}
-
-TEST_P(EventProcessorTest, EventMatching) {
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
- uint32_t accelerator_1 = 1;
- dispatcher->AddAccelerator(accelerator_1, std::move(matcher));
-
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(accelerator_1,
- event_dispatcher_delegate->GetAndClearLastAccelerator());
-
- // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to
- // ignoring.
- key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W,
- ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON);
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(accelerator_1,
- event_dispatcher_delegate->GetAndClearLastAccelerator());
-
- key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE);
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
-
- uint32_t accelerator_2 = 2;
- matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::W,
- ui::mojom::kEventFlagNone);
- dispatcher->AddAccelerator(accelerator_2, std::move(matcher));
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(accelerator_2,
- event_dispatcher_delegate->GetAndClearLastAccelerator());
-
- dispatcher->RemoveAccelerator(accelerator_2);
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
-}
-
-// Tests that a post-target accelerator is not triggered by ProcessEvent.
-TEST_P(EventProcessorTest, PostTargetAccelerator) {
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
- matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET;
- uint32_t accelerator_1 = 1;
- dispatcher->AddAccelerator(accelerator_1, std::move(matcher));
-
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- // The post-target accelerator should be fired if there is no focused window.
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(accelerator_1,
- event_dispatcher_delegate->GetAndClearLastAccelerator());
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(details);
-
- // Set focused window for EventProcessor dispatches key events.
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- event_dispatcher_delegate->SetFocusedWindowFromEventProcessor(child.get());
-
- // With a focused window the event should be dispatched.
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_TRUE(details);
- EXPECT_TRUE(details->accelerator);
-
- base::WeakPtr<Accelerator> accelerator_weak_ptr =
- details->accelerator->GetWeakPtr();
- dispatcher->RemoveAccelerator(accelerator_1);
- EXPECT_FALSE(accelerator_weak_ptr);
-
- // Post deletion there should be no accelerator
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator());
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_TRUE(details);
- EXPECT_FALSE(details->accelerator);
-}
-
-TEST_P(EventProcessorTest, ProcessPost) {
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- uint32_t pre_id = 1;
- {
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
- matcher->accelerator_phase = ui::mojom::AcceleratorPhase::PRE_TARGET;
- dispatcher->AddAccelerator(pre_id, std::move(matcher));
- }
-
- uint32_t post_id = 2;
- {
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
- matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET;
- dispatcher->AddAccelerator(post_id, std::move(matcher));
- }
-
- // Set focused window for EventProcessor dispatches key events.
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- event_dispatcher_delegate->SetFocusedWindowFromEventProcessor(child.get());
-
- // Dispatch for ANY, which should trigger PRE and not call
- // DispatchInputEventToWindow().
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- DispatchEvent(dispatcher, key, EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_EQ(EventDispatcher::AcceleratorPhase::kPre,
- event_dispatcher_delegate->last_accelerator_phase());
- EXPECT_EQ(pre_id, event_dispatcher_delegate->GetAndClearLastAccelerator());
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
-
- // Dispatch for POST, which should trigger POST.
- DispatchEvent(dispatcher, key,
- EventProcessor::AcceleratorMatchPhase::POST_ONLY);
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- ASSERT_TRUE(details->accelerator);
- EXPECT_EQ(post_id, details->accelerator->id());
-}
-
-TEST_P(EventProcessorTest, Capture) {
- ServerWindow* root = root_window();
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- MouseEventTest tests[] = {
- // Send a mouse down event over child.
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr,
- gfx::Point(), gfx::Point()},
-
- // Capture should be activated. Let's send a mouse move outside the bounds
- // of the child.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
- gfx::Point(50, 50), base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
- gfx::Point(), gfx::Point()},
- // Release the mouse and verify that the mouse up event goes to the child.
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), gfx::Point(50, 50),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
- gfx::Point(), gfx::Point()},
-
- // A mouse move at (50, 50) should now go to the root window. As the
- // move crosses between |child| and |root| |child| gets an exit, and
- // |root| the move.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
- gfx::Point(50, 50), base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root,
- gfx::Point(50, 50), gfx::Point(50, 50)},
-
- };
- RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
- tests, arraysize(tests));
-}
-
-TEST_P(EventProcessorTest, CaptureMultipleMouseButtons) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- MouseEventTest tests[] = {
- // Send a mouse down event over child with a left mouse button
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr,
- gfx::Point(), gfx::Point()},
-
- // Capture should be activated. Let's send a mouse move outside the bounds
- // of the child and press the right mouse button too.
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_MOVED, gfx::Point(50, 50), gfx::Point(50, 50),
- base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 0),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
- gfx::Point(), gfx::Point()},
-
- // Release the left mouse button and verify that the mouse up event goes
- // to the child.
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), gfx::Point(50, 50),
- base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
- ui::EF_RIGHT_MOUSE_BUTTON),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
- gfx::Point(), gfx::Point()},
-
- // A mouse move at (50, 50) should still go to the child.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
- gfx::Point(50, 50), base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON, 0),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
- gfx::Point(), gfx::Point()},
-
- };
- RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
- tests, arraysize(tests));
-}
-
-TEST_P(EventProcessorTest, ClientAreaGoesToOwner) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>());
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- // Start move loop by sending mouse event over non-client area.
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Events should target child and be in the non-client area.
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- ASSERT_TRUE(details);
- ASSERT_EQ(child.get(), details->window);
- EXPECT_TRUE(details->IsNonclientArea());
-
- // Move the mouse 5,6 pixels and target is the same.
- const ui::PointerEvent move_event(
- ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(17, 18), gfx::Point(17, 18),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
- DispatchEvent(dispatcher, move_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Still same target.
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- ASSERT_EQ(child.get(), details->window);
- EXPECT_TRUE(details->IsNonclientArea());
-
- // Release the mouse.
- const ui::PointerEvent release_event(ui::MouseEvent(
- ui::ET_MOUSE_RELEASED, gfx::Point(17, 18), gfx::Point(17, 18),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, release_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // The event should not have been dispatched to the delegate.
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- ASSERT_EQ(child.get(), details->window);
- EXPECT_TRUE(details->IsNonclientArea());
-
- // Press in the client area and verify target/client area. The non-client area
- // should get an exit first.
- const ui::PointerEvent press_event2(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(21, 22), gfx::Point(21, 22),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, press_event2,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_TRUE(event_dispatcher_delegate->has_queued_events());
- ASSERT_EQ(child.get(), details->window);
- EXPECT_TRUE(details->IsNonclientArea());
- EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type());
-
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- ASSERT_EQ(child.get(), details->window);
- EXPECT_TRUE(details->IsClientArea());
- EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type());
-}
-
-TEST_P(EventProcessorTest, AdditionalClientArea) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- std::vector<gfx::Rect> additional_client_areas;
- additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2));
- child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas);
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- // Press in the additional client area, it should go to the child.
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Events should target child and be in the client area.
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- ASSERT_EQ(child.get(), details->window);
- EXPECT_TRUE(details->IsClientArea());
-}
-
-TEST_P(EventProcessorTest, HitTestMask) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
- child->SetHitTestMask(gfx::Rect(2, 2, 16, 16));
-
- // Move in the masked area.
- const ui::PointerEvent move1(
- ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(11, 11), gfx::Point(11, 11),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
- DispatchEvent(event_dispatcher(), move1,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Event went through the child window and hit the root.
- std::unique_ptr<DispatchedEventDetails> details1 =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(root_window(), details1->window);
- EXPECT_TRUE(details1->IsClientArea());
-
- child->ClearHitTestMask();
-
- // Move right in the same part of the window.
- const ui::PointerEvent move2(
- ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(11, 12), gfx::Point(11, 12),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
- DispatchEvent(event_dispatcher(), move2,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Mouse exits the root.
- std::unique_ptr<DispatchedEventDetails> details2 =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(ui::ET_POINTER_EXITED, details2->event->type());
-
- // Mouse hits the child.
- std::unique_ptr<DispatchedEventDetails> details3 =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(child.get(), details3->window);
- EXPECT_TRUE(details3->IsClientArea());
-}
-
-TEST_P(EventProcessorTest, DontFocusOnSecondDown) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- // Press on |child|. Press should not change focus.
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- EXPECT_EQ(child.get(), details->window);
- EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow());
-}
-
-TEST_P(EventProcessorTest, TwoPointersActive) {
- std::unique_ptr<ServerWindow> child1 =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> child2 =
- CreateChildWindow(viz::FrameSinkId(1, 4));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child1->SetBounds(gfx::Rect(10, 10, 20, 20));
- child2->SetBounds(gfx::Rect(50, 51, 11, 12));
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- // Press on child1.
- const ui::PointerEvent touch_event1(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- DispatchEvent(dispatcher, touch_event1,
- EventProcessor::AcceleratorMatchPhase::ANY);
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(child1.get(), details->window);
-
- // Drag over child2, child1 should get the drag.
- const ui::PointerEvent drag_event1(ui::TouchEvent(
- ui::ET_TOUCH_MOVED, gfx::Point(53, 54), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- DispatchEvent(dispatcher, drag_event1,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(child1.get(), details->window);
-
- // Press on child2 with a different touch id.
- const ui::PointerEvent touch_event2(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2)));
- DispatchEvent(dispatcher, touch_event2,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(child2.get(), details->window);
-
- // Drag over child1 with id 2, child2 should continue to get the drag.
- const ui::PointerEvent drag_event2(ui::TouchEvent(
- ui::ET_TOUCH_MOVED, gfx::Point(13, 14), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2)));
- DispatchEvent(dispatcher, drag_event2,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(child2.get(), details->window);
-
- // Drag again with id 1, child1 should continue to get it.
- DispatchEvent(dispatcher, drag_event1,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(child1.get(), details->window);
-
- // Release touch id 1, and click on 2. 2 should get it.
- const ui::PointerEvent touch_release(ui::TouchEvent(
- ui::ET_TOUCH_RELEASED, gfx::Point(54, 55), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- DispatchEvent(dispatcher, touch_release,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(child1.get(), details->window);
- const ui::PointerEvent touch_event3(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2)));
- DispatchEvent(dispatcher, touch_event3,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(child2.get(), details->window);
-}
-
-TEST_P(EventProcessorTest, DestroyWindowWhileGettingEvents) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- // Press on child.
- const ui::PointerEvent touch_event1(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- DispatchEvent(dispatcher, touch_event1,
- EventProcessor::AcceleratorMatchPhase::ANY);
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- EXPECT_EQ(child.get(), details->window);
-
- // Delete child, and continue the drag. Event should not be dispatched.
- child.reset();
-
- const ui::PointerEvent drag_event1(ui::TouchEvent(
- ui::ET_TOUCH_MOVED, gfx::Point(53, 54), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- DispatchEvent(dispatcher, drag_event1,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(nullptr, details.get());
-}
-
-TEST_P(EventProcessorTest, MouseInExtendedHitTestRegion) {
- ServerWindow* root = root_window();
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- // Send event that is not over child.
- const ui::PointerEvent ui_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(8, 9), gfx::Point(8, 9),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, ui_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- ASSERT_EQ(root, details->window);
-
- // Release the mouse.
- const ui::PointerEvent release_event(ui::MouseEvent(
- ui::ET_MOUSE_RELEASED, gfx::Point(8, 9), gfx::Point(8, 9),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, release_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- ASSERT_EQ(root, details->window);
- EXPECT_TRUE(details->IsClientArea());
-
- // Change the extended hit test region and send event in extended hit test
- // region. Should result in exit for root, followed by press for child.
- root->set_extended_hit_test_regions_for_children(gfx::Insets(-5, -5, -5, -5),
- gfx::Insets(-5, -5, -5, -5));
- DispatchEvent(dispatcher, ui_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_EQ(root, details->window);
- EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type());
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
-
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- EXPECT_TRUE(details->IsNonclientArea());
- ASSERT_EQ(child.get(), details->window);
- EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type());
- ASSERT_TRUE(details->event.get());
- ASSERT_TRUE(details->event->IsPointerEvent());
- EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location());
-}
-
-TEST_P(EventProcessorTest, WheelWhileDown) {
- std::unique_ptr<ServerWindow> child1 =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> child2 =
- CreateChildWindow(viz::FrameSinkId(1, 4));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child1->SetBounds(gfx::Rect(10, 10, 20, 20));
- child2->SetBounds(gfx::Rect(50, 51, 11, 12));
-
- MouseEventTest tests[] = {
- // Send a mouse down event over child1.
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr,
- gfx::Point(), gfx::Point()},
- // Send mouse wheel over child2, should go to child1 as it has capture.
- {std::make_unique<ui::MouseWheelEvent>(
- gfx::Vector2d(1, 0), gfx::Point(53, 54), gfx::Point(53, 54),
- base::TimeTicks(), ui::EF_NONE, ui::EF_NONE),
- child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr,
- gfx::Point(), gfx::Point()},
- };
- RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
- tests, arraysize(tests));
-}
-
-// Tests that when explicit capture has been set that all events go to the
-// designated window, and that when capture is cleared, events find the
-// appropriate target window.
-TEST_P(EventProcessorTest, SetExplicitCapture) {
- ServerWindow* root = root_window();
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- {
- // Send all pointer events to the child.
- dispatcher->SetCaptureWindow(child.get(), kClientAreaId);
-
- // The mouse press should go to the child even though its outside its
- // bounds.
- const ui::PointerEvent left_press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, left_press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Events should target child.
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
-
- ASSERT_TRUE(details);
- ASSERT_EQ(child.get(), details->window);
- EXPECT_TRUE(details->IsClientArea());
- EXPECT_TRUE(IsMouseButtonDown());
-
- // The mouse down state should update while capture is set.
- const ui::PointerEvent right_press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
- ui::EF_RIGHT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, right_press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_TRUE(IsMouseButtonDown());
-
- // One button released should not clear mouse down
- const ui::PointerEvent left_release_event(ui::MouseEvent(
- ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), gfx::Point(5, 5),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, left_release_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_TRUE(IsMouseButtonDown());
-
- // Touch Event while mouse is down should not affect state.
- const ui::PointerEvent touch_event(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(15, 15), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2)));
- DispatchEvent(dispatcher, touch_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_TRUE(IsMouseButtonDown());
-
- // Move event should not affect down
- const ui::PointerEvent move_event(
- ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(15, 5), gfx::Point(15, 5),
- base::TimeTicks(), ui::EF_RIGHT_MOUSE_BUTTON,
- ui::EF_RIGHT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, move_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_TRUE(IsMouseButtonDown());
-
- // All mouse buttons up should clear mouse down.
- const ui::PointerEvent right_release_event(
- ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(5, 5),
- gfx::Point(5, 5), base::TimeTicks(),
- ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, right_release_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(IsMouseButtonDown());
- }
-
- {
- // Releasing capture and sending the same event will go to the root.
- dispatcher->SetCaptureWindow(nullptr, kClientAreaId);
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Events should target the root.
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
-
- ASSERT_TRUE(details);
- ASSERT_EQ(root, details->window);
- }
-}
-
-// This test verifies that explicit capture overrides and resets implicit
-// capture.
-TEST_P(EventProcessorTest, ExplicitCaptureOverridesImplicitCapture) {
- ServerWindow* root = root_window();
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EventProcessor* dispatcher = event_dispatcher();
-
- // Run some implicit capture tests.
- MouseEventTest tests[] = {
- // Send a mouse down event over child with a left mouse button
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- child.get(), gfx::Point(20, 25), gfx::Point(10, 15)},
- // Capture should be activated. Let's send a mouse move outside the bounds
- // of the child and press the right mouse button too.
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_MOVED, gfx::Point(50, 50), gfx::Point(50, 50),
- base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 0),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40)},
- // Release the left mouse button and verify that the mouse up event goes
- // to the child.
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), gfx::Point(50, 50),
- base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
- ui::EF_RIGHT_MOUSE_BUTTON),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40)},
- // A mouse move at (50, 50) should still go to the child.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
- gfx::Point(50, 50), base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON, 0),
- child.get(), gfx::Point(50, 50), gfx::Point(40, 40)},
-
- };
- RunMouseEventTests(dispatcher, event_dispatcher_delegate, tests,
- arraysize(tests));
-
- // Add a second pointer target to the child.
- {
- const ui::PointerEvent touch_event(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- DispatchEvent(dispatcher, touch_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- }
-
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- EXPECT_EQ(child.get(), details->window);
-
- // Verify that no window has explicit capture and hence we did indeed do
- // implicit capture.
- ASSERT_EQ(nullptr, dispatcher->capture_window());
-
- // Give the root window explicit capture and verify input events over the
- // child go to the root instead.
- dispatcher->SetCaptureWindow(root, kNonclientAreaId);
-
- // The implicit target should receive a cancel event for each pointer target.
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_TRUE(event_dispatcher_delegate->has_queued_events());
- EXPECT_EQ(child.get(), details->window);
- EXPECT_EQ(ui::ET_POINTER_CANCELLED, details->event->type());
-
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- EXPECT_EQ(child.get(), details->window);
- EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type());
-
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Events should target the root.
- details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- ASSERT_EQ(root, details->window);
- ASSERT_TRUE(details->IsNonclientArea());
-}
-
-// Tests that setting capture does delete active pointer targets for the capture
-// window.
-TEST_P(EventProcessorTest, CaptureUpdatesActivePointerTargets) {
- ServerWindow* root = root_window();
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
-
- EventProcessor* dispatcher = event_dispatcher();
- {
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(dispatcher, press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- ASSERT_EQ(root, details->window);
- }
- {
- const ui::PointerEvent touch_event(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
- DispatchEvent(dispatcher, touch_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- }
-
- ASSERT_TRUE(AreAnyPointersDown());
- ASSERT_TRUE(IsWindowPointerTarget(root));
- EXPECT_EQ(2, NumberPointerTargetsForWindow(root));
-
- // Setting the capture should clear the implicit pointers for the specified
- // window.
- dispatcher->SetCaptureWindow(root, kNonclientAreaId);
- EXPECT_FALSE(AreAnyPointersDown());
- EXPECT_FALSE(IsWindowPointerTarget(root));
-}
-
-// Tests that when explicit capture is changed, that the previous window with
-// capture is no longer being observed.
-TEST_P(EventProcessorTest, UpdatingCaptureStopsObservingPreviousCapture) {
- std::unique_ptr<ServerWindow> child1 =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> child2 =
- CreateChildWindow(viz::FrameSinkId(1, 4));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child1->SetBounds(gfx::Rect(10, 10, 20, 20));
- child2->SetBounds(gfx::Rect(50, 51, 11, 12));
-
- EventProcessor* dispatcher = event_dispatcher();
- ASSERT_FALSE(AreAnyPointersDown());
- ASSERT_FALSE(IsWindowPointerTarget(child1.get()));
- ASSERT_FALSE(IsWindowPointerTarget(child2.get()));
- dispatcher->SetCaptureWindow(child1.get(), kClientAreaId);
- dispatcher->SetCaptureWindow(child2.get(), kClientAreaId);
- EXPECT_EQ(child1.get(),
- test_event_dispatcher_delegate()->lost_capture_window());
-
- EXPECT_FALSE(
- EventProcessorTestApi(dispatcher).IsObservingWindow(child1.get()));
-}
-
-// Tests that destroying a window with explicit capture clears the capture
-// state.
-TEST_P(EventProcessorTest, DestroyingCaptureWindowRemovesExplicitCapture) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- EventProcessor* dispatcher = event_dispatcher();
- dispatcher->SetCaptureWindow(child.get(), kClientAreaId);
- EXPECT_EQ(child.get(), dispatcher->capture_window());
-
- ServerWindow* lost_capture_window = child.get();
- child.reset();
- EXPECT_EQ(nullptr, dispatcher->capture_window());
- EXPECT_EQ(lost_capture_window,
- test_event_dispatcher_delegate()->lost_capture_window());
-}
-
-// Tests that when |client_id| is set for a window performing capture, that this
-// preference is used regardless of whether an event targets the client region.
-TEST_P(EventProcessorTest, CaptureInNonClientAreaOverridesActualPoint) {
- ServerWindow* root = root_window();
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
-
- root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>());
- EventProcessor* dispatcher = event_dispatcher();
- dispatcher->SetCaptureWindow(root, kNonclientAreaId);
-
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- // Press in the client area, it should be marked as non client.
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(6, 6), gfx::Point(6, 6),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // Events should target child and be in the client area.
- std::unique_ptr<DispatchedEventDetails> details =
- event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails();
- EXPECT_FALSE(event_dispatcher_delegate->has_queued_events());
- ASSERT_EQ(root, details->window);
- EXPECT_TRUE(details->IsNonclientArea());
-}
-
-TEST_P(EventProcessorTest, ProcessPointerEvents) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- {
- const ui::PointerEvent pointer_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), pointer_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- ASSERT_EQ(child.get(), details->window);
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location());
- }
-
- {
- const int touch_id = 3;
- const ui::PointerEvent pointer_event(ui::TouchEvent(
- ui::ET_TOUCH_RELEASED, gfx::Point(25, 20), base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH,
- touch_id)));
- DispatchEvent(event_dispatcher(), pointer_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- ASSERT_EQ(child.get(), details->window);
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location());
- EXPECT_EQ(touch_id, dispatched_event->pointer_details().id);
- }
-}
-
-TEST_P(EventProcessorTest, ResetClearsPointerDown) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- // Send event that is over child.
- const ui::PointerEvent ui_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), ui_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- ASSERT_EQ(child.get(), details->window);
-
- EXPECT_TRUE(AreAnyPointersDown());
-
- event_dispatcher()->Reset();
- EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
- EXPECT_FALSE(AreAnyPointersDown());
-}
-
-TEST_P(EventProcessorTest, ResetClearsCapture) {
- ServerWindow* root = root_window();
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
-
- root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>());
- EventProcessor* dispatcher = event_dispatcher();
- dispatcher->SetCaptureWindow(root, kNonclientAreaId);
-
- event_dispatcher()->Reset();
- EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
- EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
-}
-
-// Tests that events on a parent of a modal window are blocked.
-TEST_P(EventProcessorTest, ModalWindowEventOnModalParent) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 5));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
-
- w1->AddTransientWindow(w2.get());
- w2->SetModalType(MODAL_TYPE_WINDOW);
-
- // Send event that is over |w1|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
- // As |w2| is modal and the event is over |w1|, no events should be queued,
- // and the delegate should be informed of this.
- ASSERT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
- EXPECT_EQ(w2.get(),
- test_event_dispatcher_delegate()->window_that_blocked_event());
- test_event_dispatcher_delegate()->ClearWindowThatBlockedEvent();
-
- const ui::PointerEvent mouse_released(ui::MouseEvent(
- ui::ET_MOUSE_RELEASED, gfx::Point(15, 15), gfx::Point(15, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_released,
- EventProcessor::AcceleratorMatchPhase::ANY);
- ASSERT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
- EXPECT_FALSE(test_event_dispatcher_delegate()->window_that_blocked_event());
-
- // Send event over |w2|.
- const ui::PointerEvent mouse_pressed2(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed2,
- EventProcessor::AcceleratorMatchPhase::ANY);
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_EQ(w2.get(), details->window);
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(55, 15), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
- EXPECT_FALSE(test_event_dispatcher_delegate()->window_that_blocked_event());
-}
-
-// Tests that events on a modal child target the modal child itself.
-TEST_P(EventProcessorTest, ModalWindowEventOnModalChild) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 5));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
-
- w1->AddTransientWindow(w2.get());
- w2->SetModalType(MODAL_TYPE_WINDOW);
-
- // Send event that is over |w2|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_EQ(w2.get(), details->window);
- EXPECT_TRUE(details->IsClientArea());
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(55, 15), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
-}
-
-// Tests that events on an unrelated window are not affected by the modal
-// window.
-TEST_P(EventProcessorTest, ModalWindowEventOnUnrelatedWindow) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 5));
- std::unique_ptr<ServerWindow> w3 = CreateChildWindow(viz::FrameSinkId(1, 6));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
- w3->SetBounds(gfx::Rect(70, 10, 10, 10));
-
- w1->AddTransientWindow(w2.get());
- w2->SetModalType(MODAL_TYPE_WINDOW);
-
- // Send event that is over |w3|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_EQ(w3.get(), details->window);
- EXPECT_TRUE(details->IsClientArea());
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(75, 15), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
-}
-
-// Tests that events on a descendant of a modal parent target the modal child.
-TEST_P(EventProcessorTest, ModalWindowEventOnDescendantOfModalParent) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w11 =
- CreateChildWindowWithParent(viz::FrameSinkId(1, 4), w1.get());
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 5));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w11->SetBounds(gfx::Rect(10, 10, 10, 10));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
-
- w1->AddTransientWindow(w2.get());
- w2->SetModalType(MODAL_TYPE_WINDOW);
-
- // Send event that is over |w11|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // The event is targeted at |w11|, but is blocked by the modal window |w2|.
- ASSERT_TRUE(test_event_dispatcher_delegate()->last_event_target_not_found());
- ASSERT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
-}
-
-// Same as ModalWindowEventOnDescendantOfModalParent but with fallback to root
-// enabled.
-TEST_P(EventProcessorTest,
- ModalWindowEventOnDescendantOfModalParentWithFallback) {
- test_event_dispatcher_delegate()->EnableFallbackToRoot();
-
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w11 =
- CreateChildWindowWithParent(viz::FrameSinkId(1, 4), w1.get());
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 5));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w11->SetBounds(gfx::Rect(10, 10, 10, 10));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
-
- w1->AddTransientWindow(w2.get());
- w2->SetModalType(MODAL_TYPE_WINDOW);
-
- // Send event that is over |w11|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_EQ(root_window(), details->window);
- EXPECT_TRUE(details->IsNonclientArea());
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(25, 25), dispatched_event->location());
-}
-
-// Tests that events on a system modal window target the modal window itself.
-TEST_P(EventProcessorTest, ModalWindowEventOnSystemModal) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w1->SetModalType(MODAL_TYPE_SYSTEM);
-
- // Send event that is over |w1|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_EQ(w1.get(), details->window);
- EXPECT_TRUE(details->IsClientArea());
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location());
-}
-
-// Tests that events outside of system modal window target the modal window.
-TEST_P(EventProcessorTest, ModalWindowEventOutsideSystemModal) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w1->SetModalType(MODAL_TYPE_SYSTEM);
- event_dispatcher()->AddSystemModalWindow(w1.get());
-
- // Send event that is outside of |w1|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- ASSERT_TRUE(test_event_dispatcher_delegate()->last_event_target_not_found());
- ASSERT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
- EXPECT_EQ(w1.get(),
- test_event_dispatcher_delegate()->window_that_blocked_event());
-}
-
-// Variant of ModalWindowEventOutsideSystemModal with
-// EnableFallbackToRoot().
-TEST_P(EventProcessorTest, ModalWindowEventOutsideSystemModalWithFallback) {
- test_event_dispatcher_delegate()->EnableFallbackToRoot();
-
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w1->SetModalType(MODAL_TYPE_SYSTEM);
- event_dispatcher()->AddSystemModalWindow(w1.get());
-
- // Send event that is outside of |w1|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_EQ(root_window(), details->window);
- EXPECT_TRUE(details->IsNonclientArea());
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(45, 15), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(45, 15), dispatched_event->location());
-}
-
-// Tests events on a sub-window of system modal window target the window itself.
-TEST_P(EventProcessorTest, ModalWindowEventSubWindowSystemModal) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- w1->SetModalType(MODAL_TYPE_SYSTEM);
- event_dispatcher()->AddSystemModalWindow(w1.get());
-
- std::unique_ptr<ServerWindow> w2 =
- CreateChildWindowWithParent(viz::FrameSinkId(1, 4), w1.get());
- std::unique_ptr<ServerWindow> w3 = CreateChildWindow(viz::FrameSinkId(1, 5));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w2->SetBounds(gfx::Rect(10, 10, 10, 10));
- w3->SetBounds(gfx::Rect(50, 10, 10, 10));
-
- struct {
- gfx::Point location;
- ServerWindow* expected_target;
- } kTouchData[] = {
- // Touch on |w1| should go to |w1|.
- {gfx::Point(11, 11), w1.get()},
- // Touch on |w2| should go to |w2|.
- {gfx::Point(25, 25), w2.get()},
- // Touch on |w3| should go to |w1|.
- {gfx::Point(11, 31), w1.get()},
- };
-
- for (size_t i = 0; i < arraysize(kTouchData); i++) {
- // Send touch press and check that the expected target receives it.
- DispatchEvent(
- event_dispatcher(),
- ui::PointerEvent(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, kTouchData[i].location, base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0))),
- EventProcessor::AcceleratorMatchPhase::ANY);
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details) << " details is nullptr " << i;
- EXPECT_EQ(kTouchData[i].expected_target, details->window) << i;
-
- // Release touch.
- DispatchEvent(
- event_dispatcher(),
- ui::PointerEvent(ui::TouchEvent(
- ui::ET_TOUCH_RELEASED, kTouchData[i].location, base::TimeTicks(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0))),
- EventProcessor::AcceleratorMatchPhase::ANY);
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- }
-}
-
-// Tests that setting capture to a descendant of a modal parent fails.
-TEST_P(EventProcessorTest, ModalWindowSetCaptureDescendantOfModalParent) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w11 =
- CreateChildWindowWithParent(viz::FrameSinkId(1, 4), w1.get());
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 5));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w11->SetBounds(gfx::Rect(10, 10, 10, 10));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
-
- w1->AddTransientWindow(w2.get());
- w2->SetModalType(MODAL_TYPE_WINDOW);
-
- EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), kClientAreaId));
- EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
-}
-
-// Tests that setting capture to a window unrelated to a modal parent works.
-TEST_P(EventProcessorTest, ModalWindowSetCaptureUnrelatedWindow) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 4));
- std::unique_ptr<ServerWindow> w3 = CreateChildWindow(viz::FrameSinkId(1, 5));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
- w3->SetBounds(gfx::Rect(70, 10, 10, 10));
-
- w1->AddTransientWindow(w2.get());
- w2->SetModalType(MODAL_TYPE_WINDOW);
-
- EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), kClientAreaId));
- EXPECT_EQ(w3.get(), event_dispatcher()->capture_window());
-}
-
-// Tests that setting capture fails when there is a system modal window.
-TEST_P(EventProcessorTest, ModalWindowSystemSetCapture) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 4));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
-
- w2->SetModalType(MODAL_TYPE_SYSTEM);
- event_dispatcher()->AddSystemModalWindow(w2.get());
-
- EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w1.get(), kClientAreaId));
- EXPECT_EQ(nullptr, event_dispatcher()->capture_window());
-}
-
-// Tests having multiple system modal windows.
-TEST_P(EventProcessorTest, ModalWindowMultipleSystemModals) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 4));
- std::unique_ptr<ServerWindow> w3 = CreateChildWindow(viz::FrameSinkId(1, 5));
-
- w2->SetVisible(false);
-
- // In the beginning, there should be no active system modal window.
- EXPECT_EQ(nullptr, GetActiveSystemModalWindow());
-
- // Add a visible system modal window. It should become the active one.
- w1->SetModalType(MODAL_TYPE_SYSTEM);
- event_dispatcher()->AddSystemModalWindow(w1.get());
- EXPECT_EQ(w1.get(), GetActiveSystemModalWindow());
-
- // Add an invisible system modal window. It should not change the active one.
- w2->SetModalType(MODAL_TYPE_SYSTEM);
- event_dispatcher()->AddSystemModalWindow(w2.get());
- EXPECT_EQ(w1.get(), GetActiveSystemModalWindow());
-
- // Add another visible system modal window. It should become the active one.
- w3->SetModalType(MODAL_TYPE_SYSTEM);
- event_dispatcher()->AddSystemModalWindow(w3.get());
- EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
-
- // Make an existing system modal window visible. It should become the active
- // one.
- w2->SetVisible(true);
- EXPECT_EQ(w2.get(), GetActiveSystemModalWindow());
-
- // Remove the active system modal window. Next one should become active.
- w2.reset();
- EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
-
- // Remove an inactive system modal window. It should not change the active
- // one.
- w1.reset();
- EXPECT_EQ(w3.get(), GetActiveSystemModalWindow());
-
- // Remove the last remaining system modal window. There should be no active
- // one anymore.
- w3.reset();
- EXPECT_EQ(nullptr, GetActiveSystemModalWindow());
-}
-
-TEST_P(EventProcessorTest, CaptureNotResetOnParentChange) {
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- w1->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- std::unique_ptr<ServerWindow> w11 =
- CreateChildWindowWithParent(viz::FrameSinkId(1, 4), w1.get());
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 5));
- w2->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- w1->SetBounds(gfx::Rect(0, 0, 100, 100));
- w11->SetBounds(gfx::Rect(10, 10, 10, 10));
- w2->SetBounds(gfx::Rect(0, 0, 100, 100));
-
- // Send event that is over |w11|.
- const ui::PointerEvent mouse_pressed(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), mouse_pressed,
- EventProcessor::AcceleratorMatchPhase::ANY);
- event_dispatcher()->SetCaptureWindow(w11.get(), kClientAreaId);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- EXPECT_EQ(w11.get(), details->window);
- EXPECT_TRUE(details->IsClientArea());
-
- // Move |w11| to |w2| and verify the mouse is still down, and |w11| has
- // capture.
- w2->Add(w11.get());
- EXPECT_TRUE(IsMouseButtonDown());
- EXPECT_EQ(w11.get(),
- EventProcessorTestApi(event_dispatcher()).capture_window());
-}
-
-TEST_P(EventProcessorTest, ChangeCaptureFromClientToNonclient) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- event_dispatcher()->SetCaptureWindow(child.get(), kNonclientAreaId);
- EXPECT_EQ(kNonclientAreaId, event_dispatcher()->capture_window_client_id());
- EXPECT_EQ(nullptr, test_event_dispatcher_delegate()->lost_capture_window());
- event_dispatcher()->SetCaptureWindow(child.get(), kClientAreaId);
- // Changing capture from client to non-client should notify the delegate.
- // The delegate can decide if it really wants to forward the event or not.
- EXPECT_EQ(child.get(),
- test_event_dispatcher_delegate()->lost_capture_window());
- EXPECT_EQ(child.get(), event_dispatcher()->capture_window());
- EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id());
-}
-
-TEST_P(EventProcessorTest, MoveMouseFromNoTargetToValidTarget) {
- ServerWindow* root = root_window();
- root->set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- MouseEventTest tests[] = {
- // Send a mouse down over the root, but not the child. No event should
- // be generated.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(5, 5),
- gfx::Point(5, 5), base::TimeTicks(), 0,
- 0),
- nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
- gfx::Point()},
-
- // Move into child.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(12, 12),
- gfx::Point(12, 12), base::TimeTicks(),
- 0, 0),
- child.get(), gfx::Point(12, 12), gfx::Point(2, 2), nullptr, gfx::Point(),
- gfx::Point()}};
- RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
- tests, arraysize(tests));
-}
-
-TEST_P(EventProcessorTest, NoTargetToTargetWithMouseDown) {
- ServerWindow* root = root_window();
- root->set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- MouseEventTest tests[] = {
- // Mouse over the root, but not the child. No event should be generated.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(5, 5),
- gfx::Point(5, 5), base::TimeTicks(), 0,
- 0),
- nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
- gfx::Point()},
-
- // Press in same location, still no target.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_PRESSED, gfx::Point(5, 5),
- gfx::Point(5, 5), base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
- gfx::Point()},
-
- // Move into child, still no target.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(12, 12),
- gfx::Point(12, 12), base::TimeTicks(),
- ui::EF_LEFT_MOUSE_BUTTON, 0),
- nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
- gfx::Point()}};
- RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
- tests, arraysize(tests));
-}
-
-TEST_P(EventProcessorTest, DontSendExitToSameClientWhenCaptureChanges) {
- ServerWindow* root = root_window();
- root->set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- std::unique_ptr<ServerWindow> c1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> c2 = CreateChildWindow(viz::FrameSinkId(1, 4));
-
- root->SetBounds(gfx::Rect(0, 0, 100, 100));
- c1->SetBounds(gfx::Rect(10, 10, 20, 20));
- c2->SetBounds(gfx::Rect(15, 15, 20, 20));
-
- MouseEventTest tests[] = {
- // Mouse over |c2|.
- {std::make_unique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(16, 16),
- gfx::Point(16, 16), base::TimeTicks(),
- 0, 0),
- c2.get(), gfx::Point(16, 16), gfx::Point(1, 1), nullptr, gfx::Point(),
- gfx::Point()},
-
- // Press in same location.
- {std::make_unique<ui::MouseEvent>(
- ui::ET_MOUSE_PRESSED, gfx::Point(16, 16), gfx::Point(16, 16),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON),
- c2.get(), gfx::Point(16, 16), gfx::Point(1, 1), nullptr, gfx::Point(),
- gfx::Point()}};
- RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
- tests, arraysize(tests));
-
- // Set capture on |c1|. No events should be sent as |c1| is in the same
- // client.
- event_dispatcher()->SetCaptureWindow(c1.get(), kClientAreaId);
- EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
-}
-
-TEST_P(EventProcessorTest, MousePointerClearedOnDestroy) {
- root_window()->set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- std::unique_ptr<ServerWindow> c1 = CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- c1->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- const ui::PointerEvent move_event(
- ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), gfx::Point(15, 15),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
- DispatchEvent(event_dispatcher(), move_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- EXPECT_EQ(c1.get(), event_dispatcher()->mouse_cursor_source_window());
- c1.reset();
- EXPECT_EQ(nullptr, event_dispatcher()->mouse_cursor_source_window());
-}
-
-TEST_P(EventProcessorTest, LocationHonorsTransform) {
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- gfx::Transform transform;
- transform.Scale(SkIntToMScalar(2), SkIntToMScalar(2));
- child->SetTransform(transform);
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- // Send event that is over child.
- const ui::PointerEvent ui_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), ui_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- std::unique_ptr<DispatchedEventDetails> details =
- test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails();
- ASSERT_TRUE(details);
- ASSERT_EQ(child.get(), details->window);
-
- ASSERT_TRUE(details->event);
- ASSERT_TRUE(details->event->IsPointerEvent());
-
- ui::PointerEvent* dispatched_event = details->event->AsPointerEvent();
- EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location());
- EXPECT_EQ(gfx::Point(5, 7), dispatched_event->location());
-}
-
-TEST_P(EventProcessorTest, MouseMovementsShowCursor) {
- EXPECT_EQ(base::Optional<bool>(),
- test_event_dispatcher_delegate()->last_cursor_visibility());
-
- const ui::PointerEvent move1(
- ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(11, 11), gfx::Point(11, 11),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
- DispatchEvent(event_dispatcher(), move1,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- EXPECT_EQ(base::Optional<bool>(true),
- test_event_dispatcher_delegate()->last_cursor_visibility());
-}
-
-TEST_P(EventProcessorTest, KeyDoesntHideCursorWithNoList) {
- // In the case of mus, we don't send a list to the window server so ensure we
- // don't hide the cursor in this mode.
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- EXPECT_EQ(base::Optional<bool>(),
- event_dispatcher_delegate->last_cursor_visibility());
-
- // Set focused window for EventProcessor dispatches key events.
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- event_dispatcher_delegate->SetFocusedWindowFromEventProcessor(child.get());
-
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
- DispatchEvent(event_dispatcher(), key,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- EXPECT_EQ(base::Optional<bool>(),
- event_dispatcher_delegate->last_cursor_visibility());
-}
-
-TEST_P(EventProcessorTest, KeyDoesntHideCursorOnMatch) {
- // In the case of mash, we send a list of keys which don't hide the cursor.
- std::vector<ui::mojom::EventMatcherPtr> matchers;
- matchers.push_back(BuildKeyMatcher(ui::mojom::KeyboardCode::A));
- event_dispatcher()->SetKeyEventsThatDontHideCursor(std::move(matchers));
-
- // Set focused window for EventProcessor dispatches key events.
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- event_dispatcher_delegate->SetFocusedWindowFromEventProcessor(child.get());
-
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
- DispatchEvent(event_dispatcher(), key,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- EXPECT_EQ(base::Optional<bool>(),
- event_dispatcher_delegate->last_cursor_visibility());
-}
-
-TEST_P(EventProcessorTest, KeyHidesCursorOnNoMatch) {
- // In the case of mash, we send a list of keys which don't hide the cursor.
- std::vector<ui::mojom::EventMatcherPtr> matchers;
- matchers.push_back(BuildKeyMatcher(ui::mojom::KeyboardCode::B));
- event_dispatcher()->SetKeyEventsThatDontHideCursor(std::move(matchers));
-
- // Set focused window for EventProcessor dispatches key events.
- TestEventProcessorDelegate* event_dispatcher_delegate =
- test_event_dispatcher_delegate();
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- event_dispatcher_delegate->SetFocusedWindowFromEventProcessor(child.get());
-
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
- DispatchEvent(event_dispatcher(), key,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- EXPECT_EQ(base::Optional<bool>(false),
- event_dispatcher_delegate->last_cursor_visibility());
-}
-
-TEST_P(EventProcessorTest, ChildModal) {
- std::unique_ptr<ServerWindow> modal_parent =
- CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> child_modal_window =
- CreateChildWindow(viz::FrameSinkId(1, 4));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- modal_parent->SetBounds(gfx::Rect(10, 10, 30, 30));
- child_modal_window->SetBounds(gfx::Rect(50, 10, 10, 10));
- modal_parent->AddTransientWindow(child_modal_window.get());
- child_modal_window->SetModalType(MODAL_TYPE_CHILD);
- child_modal_window->SetChildModalParent(modal_parent.get());
-
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- // As the event falls over |modal_parent|, but there is a CHILD_MODAL window,
- // the event is blocked and the delegate notified.
- EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events());
- EXPECT_EQ(child_modal_window.get(),
- test_event_dispatcher_delegate()->window_that_blocked_event());
-}
-
-TEST_P(EventProcessorTest, DontCancelWhenMovedToSeparateDisplay) {
- TestServerWindowDelegate window_delegate2(viz_host_proxy());
- ServerWindow root2(&window_delegate2, viz::FrameSinkId(1, 100));
- root2.set_is_activation_parent(true);
- window_delegate2.set_root_window(&root2);
- root2.SetVisible(true);
-
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- event_dispatcher()->SetCaptureWindow(w1.get(), kClientAreaId);
- ASSERT_EQ(w1.get(), event_dispatcher()->capture_window());
- test_event_dispatcher_delegate()->set_root(&root2);
- window_delegate()->AddRootWindow(&root2);
- root2.Add(w1.get());
- EXPECT_EQ(w1.get(), event_dispatcher()->capture_window());
-}
-
-// Tests that setting capture to a window unrelated to a modal parent works.
-TEST_P(EventProcessorTest, MouseCursorSourceWindowChangesWithSystemModal) {
- BlockingContainers blocking_containers;
- blocking_containers.system_modal_container = root_window();
- event_dispatcher()->modal_window_controller()->SetBlockingContainers(
- {blocking_containers});
-
- std::unique_ptr<ServerWindow> w1 = CreateChildWindow(viz::FrameSinkId(1, 3));
- std::unique_ptr<ServerWindow> w2 = CreateChildWindow(viz::FrameSinkId(1, 4));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- root_window()->set_is_activation_parent(true);
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
- w2->SetModalType(MODAL_TYPE_SYSTEM);
- event_dispatcher()->modal_window_controller()->AddSystemModalWindow(w2.get());
-
- // Move the mouse over |w1|.
- const ui::PointerEvent move(
- ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(11, 11), gfx::Point(11, 11),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0));
- DispatchEvent(event_dispatcher(), move,
- EventProcessor::AcceleratorMatchPhase::ANY);
-
- EXPECT_EQ(nullptr, event_dispatcher()->mouse_cursor_source_window());
-
- event_dispatcher()->UpdateCursorProviderByLastKnownLocation();
- RunTasks();
- // EventProcessor fallsback to the root incase of invalid window.
- EXPECT_EQ(root_window(), event_dispatcher()->mouse_cursor_source_window());
-}
-
-TEST_P(EventProcessorTest, DontQueryWhileMouseIsDown) {
- // This test is easier to write with async event processing.
- if (!is_event_processing_async())
- return;
-
- std::unique_ptr<ServerWindow> child =
- CreateChildWindow(viz::FrameSinkId(1, 3));
-
- root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- child->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- const ui::PointerEvent press_event(ui::MouseEvent(
- ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- DispatchEvent(event_dispatcher(), press_event,
- EventProcessor::AcceleratorMatchPhase::ANY);
- ASSERT_FALSE(event_dispatcher()->IsProcessingEvent());
-
- const ui::PointerEvent move_event(ui::MouseEvent(
- ui::ET_MOUSE_MOVED, gfx::Point(20, 25), gfx::Point(20, 25),
- base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON));
- event_dispatcher()->ProcessEvent(move_event,
- EventLocationFromEvent(move_event),
- EventProcessor::AcceleratorMatchPhase::ANY);
- EXPECT_FALSE(event_dispatcher()->IsProcessingEvent());
-}
-
-INSTANTIATE_TEST_CASE_P(/* no prefix */, EventProcessorTest, testing::Bool());
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/event_targeter.cc b/services/ui/ws/event_targeter.cc
deleted file mode 100644
index 789c315..0000000
--- a/services/ui/ws/event_targeter.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/event_targeter.h"
-
-#include "base/command_line.h"
-#include "base/metrics/user_metrics.h"
-#include "base/task_scheduler/post_task.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "components/viz/common/features.h"
-#include "components/viz/host/hit_test/hit_test_query.h"
-#include "services/ui/common/switches.h"
-#include "services/ui/ws/event_location.h"
-#include "services/ui/ws/event_targeter_delegate.h"
-#include "ui/gfx/geometry/point_conversions.h"
-
-namespace ui {
-namespace ws {
-
-EventTargeter::EventTargeter(EventTargeterDelegate* event_targeter_delegate)
- : event_targeter_delegate_(event_targeter_delegate),
- weak_ptr_factory_(this) {}
-
-EventTargeter::~EventTargeter() {}
-
-void EventTargeter::FindTargetForLocation(EventSource event_source,
- const EventLocation& event_location,
- HitTestCallback callback) {
- // TODO(riajiang): After the async ask-client part is implemented, the async
- // part should be moved to after sync viz-hit-test call.
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kUseAsyncEventTargeting)) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::BindOnce(&EventTargeter::FindTargetForLocationNow,
- weak_ptr_factory_.GetWeakPtr(), event_source,
- event_location, base::Passed(&callback)));
- } else {
- FindTargetForLocationNow(event_source, event_location, std::move(callback));
- }
-}
-
-void EventTargeter::FindTargetForLocationNow(
- EventSource event_source,
- const EventLocation& event_location,
- HitTestCallback callback) {
- ServerWindow* root = event_targeter_delegate_->GetRootWindowForDisplay(
- event_location.display_id);
- DeepestWindow deepest_window;
- if (root) {
- deepest_window = ui::ws::FindDeepestVisibleWindowForLocation(
- root, event_source, gfx::ToFlooredPoint(event_location.raw_location));
- }
- std::move(callback).Run(event_location, deepest_window);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/event_targeter.h b/services/ui/ws/event_targeter.h
deleted file mode 100644
index 56935f9..0000000
--- a/services/ui/ws/event_targeter.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_EVENT_TARGETER_H_
-#define SERVICES_UI_WS_EVENT_TARGETER_H_
-
-#include <stdint.h>
-
-#include "base/callback_forward.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "services/ui/ws/window_finder.h"
-#include "ui/gfx/geometry/point.h"
-
-namespace ui {
-namespace ws {
-
-class EventTargeterDelegate;
-struct EventLocation;
-
-namespace test {
-class EventTargeterTestApi;
-}
-
-using HitTestCallback =
- base::OnceCallback<void(const EventLocation&, const DeepestWindow&)>;
-
-// Finds the target window for a location.
-class EventTargeter {
- public:
- explicit EventTargeter(EventTargeterDelegate* event_targeter_delegate);
- ~EventTargeter();
-
- // Calls WindowFinder to find the target for |display_location|. |callback| is
- // called with the found target.
- void FindTargetForLocation(EventSource event_source,
- const EventLocation& event_location,
- HitTestCallback callback);
-
- private:
- friend class test::EventTargeterTestApi;
-
- void FindTargetForLocationNow(EventSource event_source,
- const EventLocation& display_location,
- HitTestCallback callback);
-
- EventTargeterDelegate* event_targeter_delegate_;
-
- base::WeakPtrFactory<EventTargeter> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(EventTargeter);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_TARGETER_H_
diff --git a/services/ui/ws/event_targeter_delegate.h b/services/ui/ws/event_targeter_delegate.h
deleted file mode 100644
index f37627f..0000000
--- a/services/ui/ws/event_targeter_delegate.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_EVENT_TARGETER_DELEGATE_H_
-#define SERVICES_UI_WS_EVENT_TARGETER_DELEGATE_H_
-
-#include <stdint.h>
-
-namespace viz {
-class HitTestQuery;
-}
-
-namespace ui {
-namespace ws {
-class ServerWindow;
-
-// Used by EventTargeter to talk to WindowManagerState.
-class EventTargeterDelegate {
- public:
- // Calls EventDispatcherDelegate::GetRootWindowForDisplay(), see
- // event_dispatcher_delegate.h for details.
- virtual ServerWindow* GetRootWindowForDisplay(int64_t display_id) = 0;
-
- // Returns null if there's no display with |display_id|.
- virtual viz::HitTestQuery* GetHitTestQueryForDisplay(int64_t display_id) = 0;
-
- // |frame_sink_id| must be valid. Returns null if there's no window
- // associated with |frame_sink_id|.
- virtual ServerWindow* GetWindowFromFrameSinkId(
- const viz::FrameSinkId& frame_sink_id) = 0;
-
- protected:
- virtual ~EventTargeterDelegate() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_EVENT_TARGETER_DELEGATE_H_
diff --git a/services/ui/ws/focus_controller.cc b/services/ui/ws/focus_controller.cc
deleted file mode 100644
index 06a862c..0000000
--- a/services/ui/ws/focus_controller.cc
+++ /dev/null
@@ -1,261 +0,0 @@
-// 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 "services/ui/ws/focus_controller.h"
-
-#include "base/macros.h"
-#include "services/ui/public/interfaces/window_manager.mojom.h"
-#include "services/ui/ws/focus_controller_observer.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_drawn_tracker.h"
-
-namespace ui {
-namespace ws {
-
-namespace {
-
-ServerWindow* GetDeepestLastDescendant(ServerWindow* window) {
- while (!window->children().empty())
- window = window->children().back();
- return window;
-}
-
-// This can be used to iterate over each node in a rooted tree for the purpose
-// of shifting focus/activation.
-class WindowTreeIterator {
- public:
- explicit WindowTreeIterator(ServerWindow* root) : root_(root) {}
- ~WindowTreeIterator() {}
-
- ServerWindow* GetNext(ServerWindow* window) const {
- if (window == root_ || window == nullptr)
- return GetDeepestLastDescendant(root_);
-
- // Return the next sibling.
- ServerWindow* parent = window->parent();
- if (parent) {
- const ServerWindow::Windows& siblings = parent->children();
- ServerWindow::Windows::const_reverse_iterator iter =
- std::find(siblings.rbegin(), siblings.rend(), window);
- DCHECK(iter != siblings.rend());
- ++iter;
- if (iter != siblings.rend())
- return GetDeepestLastDescendant(*iter);
- }
-
- // All children and siblings have been explored. Next is the parent.
- return parent;
- }
-
- private:
- ServerWindow* root_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTreeIterator);
-};
-
-} // namespace
-
-FocusController::FocusController(ServerWindow* root)
- : root_(root),
- focused_window_(nullptr),
- active_window_(nullptr),
- activation_reason_(ActivationChangeReason::UNKNOWN) {
- DCHECK(root_);
-}
-
-FocusController::~FocusController() {
-}
-
-bool FocusController::SetFocusedWindow(ServerWindow* window) {
- if (GetFocusedWindow() == window)
- return true;
-
- return SetFocusedWindowImpl(FocusControllerChangeSource::EXPLICIT, window);
-}
-
-ServerWindow* FocusController::GetFocusedWindow() {
- return focused_window_;
-}
-
-void FocusController::AddObserver(FocusControllerObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void FocusController::RemoveObserver(FocusControllerObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-void FocusController::SetActiveWindow(ServerWindow* window,
- ActivationChangeReason reason) {
- DCHECK(!window || CanBeActivated(window));
- if (active_window_ == window)
- return;
-
- ServerWindow* old_active = active_window_;
- active_window_ = window;
- activation_reason_ = reason;
- for (auto& observer : observers_)
- observer.OnActivationChanged(old_active, active_window_);
-}
-
-bool FocusController::CanBeFocused(ServerWindow* window) const {
- // All ancestors of |window| must be drawn, and be focusable.
- for (ServerWindow* w = window; w; w = w->parent()) {
- if (!w->IsDrawn())
- return false;
- if (!w->can_focus())
- return false;
- }
-
- // |window| must be a descendent of an activatable window.
- return GetActivatableAncestorOf(window) != nullptr;
-}
-
-bool FocusController::CanBeActivated(ServerWindow* window) const {
- DCHECK(window);
- // A detached window cannot be activated.
- if (!root_->Contains(window))
- return false;
-
- // The parent window must be allowed to have active children.
- if (!window->parent() || !window->parent()->is_activation_parent())
- return false;
-
- if (!window->can_focus())
- return false;
-
- // The window must be drawn, or if it's not drawn, it must be minimized.
- if (!window->IsDrawn() &&
- window->GetShowState() != mojom::ShowState::MINIMIZED) {
- return false;
- }
-
- // TODO(sad): If there's a transient modal window, then this cannot be
- // activated.
- return true;
-}
-
-ServerWindow* FocusController::GetActivatableAncestorOf(
- ServerWindow* window) const {
- for (ServerWindow* w = window; w; w = w->parent()) {
- if (CanBeActivated(w))
- return w;
- }
- return nullptr;
-}
-
-bool FocusController::SetFocusedWindowImpl(
- FocusControllerChangeSource change_source,
- ServerWindow* window) {
- if (window && !CanBeFocused(window))
- return false;
-
- ServerWindow* old_focused = GetFocusedWindow();
-
- DCHECK(!window || window->IsDrawn());
-
- // Activate the closest activatable ancestor window.
- // TODO(sad): The window to activate doesn't necessarily have to be a direct
- // ancestor (e.g. could be a transient parent).
- SetActiveWindow(GetActivatableAncestorOf(window),
- ActivationChangeReason::FOCUS);
-
- for (auto& observer : observers_)
- observer.OnFocusChanged(change_source, old_focused, window);
-
- focused_window_ = window;
- // We can currently use only a single ServerWindowDrawnTracker since focused
- // window is expected to be a direct descendant of the active window.
- if (focused_window_ && active_window_) {
- DCHECK(active_window_->Contains(focused_window_));
- }
- ServerWindow* track_window = focused_window_;
- if (!track_window)
- track_window = active_window_;
- if (track_window) {
- drawn_tracker_ =
- std::make_unique<ServerWindowDrawnTracker>(track_window, this);
- } else {
- drawn_tracker_.reset();
- }
- return true;
-}
-
-void FocusController::ProcessDrawnOrRootChange(ServerWindow* ancestor,
- ServerWindow* window) {
- drawn_tracker_.reset();
-
- // Find the window that triggered this state-change notification.
- ServerWindow* trigger = window;
- while (trigger->parent() != ancestor)
- trigger = trigger->parent();
- DCHECK(trigger);
- auto will_be_hidden = [trigger](ServerWindow* w) {
- return trigger->Contains(w);
- };
-
- // If |window| is |active_window_|, then activate the next activatable window
- // that does not belong to the subtree which is getting hidden.
- if (window == active_window_) {
- WindowTreeIterator iter(root_);
- ServerWindow* activate = active_window_;
- do {
- activate = iter.GetNext(activate);
- } while (activate != active_window_ &&
- (will_be_hidden(activate) || !CanBeActivated(activate)));
- if (activate == window)
- activate = nullptr;
- SetActiveWindow(activate, ActivationChangeReason::DRAWN_STATE_CHANGED);
-
- // Now make sure focus is in the active window.
- ServerWindow* focus = nullptr;
- if (active_window_) {
- WindowTreeIterator iter(active_window_);
- focus = nullptr;
- do {
- focus = iter.GetNext(focus);
- } while (focus != active_window_ &&
- (will_be_hidden(focus) || !CanBeFocused(focus)));
- DCHECK(focus && CanBeFocused(focus));
- }
- SetFocusedWindowImpl(FocusControllerChangeSource::DRAWN_STATE_CHANGED,
- focus);
- return;
- }
-
- // Move focus to the next focusable window in |active_window_|.
- DCHECK_EQ(focused_window_, window);
- WindowTreeIterator iter(active_window_);
- ServerWindow* focus = focused_window_;
- do {
- focus = iter.GetNext(focus);
- } while (focus != focused_window_ &&
- (will_be_hidden(focus) || !CanBeFocused(focus)));
- if (focus == window)
- focus = nullptr;
- SetFocusedWindowImpl(FocusControllerChangeSource::DRAWN_STATE_CHANGED, focus);
-}
-
-void FocusController::OnDrawnStateWillChange(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) {
- DCHECK(!is_drawn);
- DCHECK_NE(ancestor, window);
- DCHECK(root_->Contains(window));
- ProcessDrawnOrRootChange(ancestor, window);
-}
-
-void FocusController::OnDrawnStateChanged(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) {
- // DCHECK(false); TODO(sadrul):
-}
-
-void FocusController::OnRootWillChange(ServerWindow* ancestor,
- ServerWindow* window) {
- ProcessDrawnOrRootChange(ancestor, window);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/focus_controller.h b/services/ui/ws/focus_controller.h
deleted file mode 100644
index 80e5beb..0000000
--- a/services/ui/ws/focus_controller.h
+++ /dev/null
@@ -1,96 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_FOCUS_CONTROLLER_H_
-#define SERVICES_UI_WS_FOCUS_CONTROLLER_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "base/observer_list.h"
-#include "services/ui/ws/server_window_drawn_tracker_observer.h"
-#include "services/ui/ws/server_window_tracker.h"
-
-namespace ui {
-
-namespace ws {
-
-class FocusControllerObserver;
-class ServerWindow;
-class ServerWindowDrawnTracker;
-
-// Describes the source of the change.
-enum class FocusControllerChangeSource {
- EXPLICIT,
- DRAWN_STATE_CHANGED,
-};
-
-// Tracks the focused window. Focus is moved to another window when the drawn
-// state of the focused window changes.
-class FocusController : public ServerWindowDrawnTrackerObserver {
- public:
- explicit FocusController(ServerWindow* root);
- ~FocusController() override;
-
- // Sets the focused window. Does nothing if |window| is currently focused.
- // This does not notify the delegate. See ServerWindow::SetFocusedWindow()
- // for details on return value.
- bool SetFocusedWindow(ServerWindow* window);
- ServerWindow* GetFocusedWindow();
-
- void AddObserver(FocusControllerObserver* observer);
- void RemoveObserver(FocusControllerObserver* observer);
-
- private:
- enum class ActivationChangeReason {
- UNKNOWN,
- FOCUS, // Focus change required a different window to be activated.
- DRAWN_STATE_CHANGED, // Active window was hidden or destroyed.
- };
- void SetActiveWindow(ServerWindow* window, ActivationChangeReason reason);
-
- // Returns whether |window| can be focused or activated.
- bool CanBeFocused(ServerWindow* window) const;
- bool CanBeActivated(ServerWindow* window) const;
-
- // Returns the closest activatable ancestor of |window|. Returns nullptr if
- // there is no such ancestor.
- ServerWindow* GetActivatableAncestorOf(ServerWindow* window) const;
-
- // Implementation of SetFocusedWindow().
- bool SetFocusedWindowImpl(FocusControllerChangeSource change_source,
- ServerWindow* window);
-
- // Called internally when the drawn state or root changes. |ancestor| is
- // the |ancestor| argument from those two functions, see them for details.
- void ProcessDrawnOrRootChange(ServerWindow* ancestor, ServerWindow* window);
-
- // ServerWindowDrawnTrackerObserver:
- void OnDrawnStateWillChange(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) override;
- void OnDrawnStateChanged(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) override;
- void OnRootWillChange(ServerWindow* ancestor, ServerWindow* window) override;
-
- ServerWindow* root_;
- ServerWindow* focused_window_;
- ServerWindow* active_window_;
- // Tracks what caused |active_window_| to be activated.
- ActivationChangeReason activation_reason_;
-
- base::ObserverList<FocusControllerObserver> observers_;
-
- // Keeps track of the visibility of the focused and active window.
- std::unique_ptr<ServerWindowDrawnTracker> drawn_tracker_;
-
- DISALLOW_COPY_AND_ASSIGN(FocusController);
-};
-
-} // namespace ws
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_FOCUS_CONTROLLER_H_
diff --git a/services/ui/ws/focus_controller_observer.h b/services/ui/ws/focus_controller_observer.h
deleted file mode 100644
index ab49b42..0000000
--- a/services/ui/ws/focus_controller_observer.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_FOCUS_CONTROLLER_OBSERVER_H_
-#define SERVICES_UI_WS_FOCUS_CONTROLLER_OBSERVER_H_
-
-namespace ui {
-namespace ws {
-
-enum class FocusControllerChangeSource;
-class ServerWindow;
-
-class FocusControllerObserver {
- public:
- virtual void OnActivationChanged(ServerWindow* old_active_window,
- ServerWindow* new_active_window) = 0;
- virtual void OnFocusChanged(FocusControllerChangeSource change_source,
- ServerWindow* old_focused_window,
- ServerWindow* new_focused_window) = 0;
-
- protected:
- ~FocusControllerObserver() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_FOCUS_CONTROLLER_OBSERVER_H_
diff --git a/services/ui/ws/focus_controller_unittest.cc b/services/ui/ws/focus_controller_unittest.cc
deleted file mode 100644
index 4b8498f..0000000
--- a/services/ui/ws/focus_controller_unittest.cc
+++ /dev/null
@@ -1,225 +0,0 @@
-// 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 "services/ui/ws/focus_controller.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "services/ui/ws/focus_controller_observer.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-
-namespace ws {
-namespace {
-
-class TestFocusControllerObserver : public FocusControllerObserver {
- public:
- TestFocusControllerObserver()
- : ignore_explicit_(true),
- focus_change_count_(0u),
- old_focused_window_(nullptr),
- new_focused_window_(nullptr),
- old_active_window_(nullptr),
- new_active_window_(nullptr) {}
-
- void ClearAll() {
- focus_change_count_ = 0u;
- old_focused_window_ = nullptr;
- new_focused_window_ = nullptr;
- old_active_window_ = nullptr;
- new_active_window_ = nullptr;
- }
- size_t focus_change_count() const { return focus_change_count_; }
- ServerWindow* old_focused_window() { return old_focused_window_; }
- ServerWindow* new_focused_window() { return new_focused_window_; }
-
- ServerWindow* old_active_window() { return old_active_window_; }
- ServerWindow* new_active_window() { return new_active_window_; }
-
- void set_ignore_explicit(bool ignore) { ignore_explicit_ = ignore; }
-
- private:
- // FocusControllerObserver:
- void OnActivationChanged(ServerWindow* old_active_window,
- ServerWindow* new_active_window) override {
- old_active_window_ = old_active_window;
- new_active_window_ = new_active_window;
- }
- void OnFocusChanged(FocusControllerChangeSource source,
- ServerWindow* old_focused_window,
- ServerWindow* new_focused_window) override {
- if (ignore_explicit_ && source == FocusControllerChangeSource::EXPLICIT)
- return;
-
- focus_change_count_++;
- old_focused_window_ = old_focused_window;
- new_focused_window_ = new_focused_window;
- }
-
- bool ignore_explicit_;
- size_t focus_change_count_;
- ServerWindow* old_focused_window_;
- ServerWindow* new_focused_window_;
- ServerWindow* old_active_window_;
- ServerWindow* new_active_window_;
-
- DISALLOW_COPY_AND_ASSIGN(TestFocusControllerObserver);
-};
-
-} // namespace
-
-class FocusControllerTest : public testing::Test {
- public:
- FocusControllerTest() {}
- ~FocusControllerTest() override {}
-
- VizHostProxy* viz_host_proxy() {
- return ws_test_helper_.window_server()->GetVizHostProxy();
- }
-
- private:
- test::WindowServerTestHelper ws_test_helper_;
-
- DISALLOW_COPY_AND_ASSIGN(FocusControllerTest);
-};
-
-TEST_F(FocusControllerTest, Basic) {
- TestServerWindowDelegate server_window_delegate(viz_host_proxy());
- ServerWindow root(&server_window_delegate, viz::FrameSinkId(1, 1));
- server_window_delegate.set_root_window(&root);
- root.SetVisible(true);
- root.set_is_activation_parent(true);
- ServerWindow child(&server_window_delegate, viz::FrameSinkId(1, 2));
- child.SetVisible(true);
- child.set_is_activation_parent(true);
- root.Add(&child);
- ServerWindow child_child(&server_window_delegate, viz::FrameSinkId(1, 3));
- child_child.SetVisible(true);
- child.Add(&child_child);
- child_child.set_is_activation_parent(true);
-
- // Sibling of |child|.
- ServerWindow child2(&server_window_delegate, viz::FrameSinkId(1, 4));
- child2.SetVisible(true);
- root.Add(&child2);
-
- TestFocusControllerObserver focus_observer;
- FocusController focus_controller(&root);
- focus_controller.AddObserver(&focus_observer);
-
- focus_controller.SetFocusedWindow(&child_child);
- EXPECT_EQ(0u, focus_observer.focus_change_count());
-
- // Remove the ancestor of the focused window, focus should go to |child2|.
- root.Remove(&child);
- EXPECT_EQ(1u, focus_observer.focus_change_count());
- EXPECT_EQ(&child2, focus_observer.new_focused_window());
- EXPECT_EQ(&child_child, focus_observer.old_focused_window());
- focus_observer.ClearAll();
-
- // Make the focused window invisible. Focus is lost in this case (as no one
- // to give focus to).
- child2.SetVisible(false);
- EXPECT_EQ(1u, focus_observer.focus_change_count());
- EXPECT_EQ(nullptr, focus_observer.new_focused_window());
- EXPECT_EQ(&child2, focus_observer.old_focused_window());
- focus_observer.ClearAll();
-
- // Go back to initial state and focus |child_child|.
- child2.SetVisible(false);
- root.Add(&child);
- focus_controller.SetFocusedWindow(&child_child);
- EXPECT_EQ(0u, focus_observer.focus_change_count());
-
- // Hide the focused window, focus should go to parent.
- child_child.SetVisible(false);
- EXPECT_EQ(1u, focus_observer.focus_change_count());
- EXPECT_EQ(&child, focus_observer.new_focused_window());
- EXPECT_EQ(&child_child, focus_observer.old_focused_window());
- focus_observer.ClearAll();
-
- child_child.SetVisible(true);
- focus_controller.SetFocusedWindow(&child_child);
- EXPECT_EQ(0u, focus_observer.focus_change_count());
-
- // Hide the parent of the focused window, focus is lost as there no visible
- // windows to move focus to.
- child.SetVisible(false);
- EXPECT_EQ(1u, focus_observer.focus_change_count());
- EXPECT_EQ(nullptr, focus_observer.new_focused_window());
- EXPECT_EQ(&child_child, focus_observer.old_focused_window());
- focus_observer.ClearAll();
- focus_controller.RemoveObserver(&focus_observer);
-}
-
-namespace {
-
-// ServerWindowDelegate implementation whose GetRootWindow() implementation
-// returns the last ancestor as the root of a window.
-class TestServerWindowDelegate2 : public ServerWindowDelegate {
- public:
- explicit TestServerWindowDelegate2(VizHostProxy* viz_host_proxy)
- : viz_host_proxy_(viz_host_proxy) {}
- ~TestServerWindowDelegate2() override = default;
-
- // ServerWindowDelegate:
- VizHostProxy* GetVizHostProxy() override { return viz_host_proxy_; }
- ServerWindow* GetRootWindowForDrawn(const ServerWindow* window) override {
- const ServerWindow* root = window;
- while (root && root->parent())
- root = root->parent();
- // TODO(sky): this cast shouldn't be necessary!
- return const_cast<ServerWindow*>(root);
- }
- void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info,
- ServerWindow* window) override {}
-
- private:
- VizHostProxy* viz_host_proxy_ = nullptr;
-
- DISALLOW_COPY_AND_ASSIGN(TestServerWindowDelegate2);
-};
-
-} // namespace
-
-TEST_F(FocusControllerTest, ActiveWindowMovesToDifferentDisplay) {
- TestServerWindowDelegate2 server_window_delegate(viz_host_proxy());
- ServerWindow root1(&server_window_delegate, viz::FrameSinkId(1, 1));
- root1.SetVisible(true);
- root1.set_is_activation_parent(true);
- ServerWindow root2(&server_window_delegate, viz::FrameSinkId(1, 2));
- root2.SetVisible(true);
- root2.set_is_activation_parent(true);
-
- ServerWindow child(&server_window_delegate, viz::FrameSinkId(1, 3));
- root1.Add(&child);
- child.SetVisible(true);
- child.set_is_activation_parent(true);
-
- ServerWindow child_child(&server_window_delegate, viz::FrameSinkId(1, 4));
- child.Add(&child_child);
- child_child.SetVisible(true);
-
- TestFocusControllerObserver focus_observer;
- focus_observer.set_ignore_explicit(false);
- FocusController focus_controller(&root1);
- focus_controller.AddObserver(&focus_observer);
-
- focus_controller.SetFocusedWindow(&child_child);
- EXPECT_EQ(&child_child, focus_controller.GetFocusedWindow());
-
- root2.Add(&child_child);
- // As the focused window is moving to a different root focus should move
- // to the parent of the old focused window.
- EXPECT_EQ(&child, focus_controller.GetFocusedWindow());
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/frame_generator.cc b/services/ui/ws/frame_generator.cc
deleted file mode 100644
index bf0bee4..0000000
--- a/services/ui/ws/frame_generator.cc
+++ /dev/null
@@ -1,247 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/frame_generator.h"
-
-#include <utility>
-#include <vector>
-
-#include "components/viz/common/quads/compositor_frame.h"
-#include "components/viz/common/quads/render_pass.h"
-#include "components/viz/common/quads/render_pass_draw_quad.h"
-#include "components/viz/common/quads/shared_quad_state.h"
-#include "components/viz/common/quads/surface_draw_quad.h"
-#include "ui/gfx/geometry/size_f.h"
-
-namespace ui {
-namespace ws {
-
-FrameGenerator::FrameGenerator() = default;
-
-FrameGenerator::~FrameGenerator() = default;
-
-void FrameGenerator::SetDeviceScaleFactor(float device_scale_factor) {
- if (device_scale_factor_ == device_scale_factor)
- return;
- device_scale_factor_ = device_scale_factor;
- SetNeedsBeginFrame(true);
-}
-
-void FrameGenerator::SetHighContrastMode(bool enabled) {
- if (high_contrast_mode_enabled_ == enabled)
- return;
-
- high_contrast_mode_enabled_ = enabled;
- SetNeedsBeginFrame(true);
-}
-
-void FrameGenerator::SetEmbeddedSurface(const viz::SurfaceInfo& surface_info) {
- DCHECK(surface_info.is_valid());
-
- // Only handle embedded surfaces changing here. The display root surface
- // changing is handled immediately after the CompositorFrame is submitted.
- if (surface_info != window_manager_surface_info_) {
- window_manager_surface_info_ = surface_info;
- SetNeedsBeginFrame(true);
- }
-}
-
-void FrameGenerator::SwapSurfaceWith(FrameGenerator* other) {
- viz::SurfaceInfo window_manager_surface_info = window_manager_surface_info_;
- window_manager_surface_info_ = other->window_manager_surface_info_;
- other->window_manager_surface_info_ = window_manager_surface_info;
- if (window_manager_surface_info_.is_valid())
- SetNeedsBeginFrame(true);
- if (other->window_manager_surface_info_.is_valid())
- other->SetNeedsBeginFrame(true);
-}
-
-void FrameGenerator::OnWindowDamaged() {
- SetNeedsBeginFrame(true);
-}
-
-void FrameGenerator::OnWindowSizeChanged(const gfx::Size& pixel_size) {
- if (pixel_size_ == pixel_size)
- return;
-
- pixel_size_ = pixel_size;
- SetNeedsBeginFrame(true);
- display_private_->Resize(pixel_size);
-}
-
-void FrameGenerator::Bind(
- std::unique_ptr<viz::mojom::CompositorFrameSink> compositor_frame_sink,
- viz::mojom::DisplayPrivateAssociatedPtr display_private) {
- DCHECK(!compositor_frame_sink_);
- compositor_frame_sink_ = std::move(compositor_frame_sink);
- display_private_ = std::move(display_private);
-}
-
-void FrameGenerator::ReclaimResources(
- const std::vector<viz::ReturnedResource>& resources) {
- // Nothing to do here because FrameGenerator CompositorFrames don't reference
- // any resources.
- DCHECK(resources.empty());
-}
-
-void FrameGenerator::DidReceiveCompositorFrameAck(
- const std::vector<viz::ReturnedResource>& resources) {}
-
-void FrameGenerator::DidPresentCompositorFrame(
- uint32_t presentation_token,
- const gfx::PresentationFeedback& feedback) {
- NOTIMPLEMENTED();
-}
-
-void FrameGenerator::OnBeginFrame(const viz::BeginFrameArgs& begin_frame_args) {
- DCHECK(compositor_frame_sink_);
- current_begin_frame_ack_ = viz::BeginFrameAck(begin_frame_args, false);
- if (begin_frame_args.type == viz::BeginFrameArgs::MISSED) {
- compositor_frame_sink_->DidNotProduceFrame(current_begin_frame_ack_);
- return;
- }
-
- current_begin_frame_ack_.has_damage = true;
- last_begin_frame_args_ = begin_frame_args;
-
- // TODO(fsamuel): We should add a trace for generating a top level frame.
- viz::CompositorFrame frame(GenerateCompositorFrame());
- if (!id_allocator_.GetCurrentLocalSurfaceId().is_valid() ||
- frame.size_in_pixels() != last_submitted_frame_size_ ||
- frame.device_scale_factor() != last_device_scale_factor_) {
- last_device_scale_factor_ = frame.device_scale_factor();
- last_submitted_frame_size_ = frame.size_in_pixels();
- id_allocator_.GenerateId();
- }
-
- compositor_frame_sink_->SubmitCompositorFrame(
- id_allocator_.GetCurrentLocalSurfaceId(), std::move(frame),
- GenerateHitTestRegionList(), 0);
-
- SetNeedsBeginFrame(false);
-}
-
-viz::CompositorFrame FrameGenerator::GenerateCompositorFrame() {
- const int render_pass_id = 1;
- const gfx::Rect bounds(pixel_size_);
- std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
- render_pass->SetNew(render_pass_id, bounds, bounds, gfx::Transform());
-
- DrawWindow(render_pass.get());
-
- viz::CompositorFrame frame;
- frame.render_pass_list.push_back(std::move(render_pass));
- if (high_contrast_mode_enabled_) {
- std::unique_ptr<viz::RenderPass> invert_pass = viz::RenderPass::Create();
- invert_pass->SetNew(2, bounds, bounds, gfx::Transform());
- viz::SharedQuadState* shared_state =
- invert_pass->CreateAndAppendSharedQuadState();
- gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(
- pixel_size_, window_manager_surface_info_.device_scale_factor(),
- window_manager_surface_info_.device_scale_factor());
- bool is_clipped = false;
- bool are_contents_opaque = false;
- shared_state->SetAll(gfx::Transform(), gfx::Rect(scaled_bounds), bounds,
- bounds, is_clipped, are_contents_opaque, 1.f,
- SkBlendMode::kSrcOver, 0);
- auto* quad =
- invert_pass->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
- frame.render_pass_list.back()->filters.Append(
- cc::FilterOperation::CreateInvertFilter(1.f));
- quad->SetNew(
- shared_state, bounds, bounds, render_pass_id, 0 /* mask_resource_id */,
- gfx::RectF() /* mask_uv_rect */, gfx::Size() /* mask_texture_size */,
- gfx::Vector2dF() /* filters_scale */,
- gfx::PointF() /* filters_origin */, gfx::RectF() /* tex_coord_rect */,
- false /* force_anti_aliasing_off */);
- frame.render_pass_list.push_back(std::move(invert_pass));
- }
- frame.metadata.device_scale_factor = device_scale_factor_;
- frame.metadata.begin_frame_ack = current_begin_frame_ack_;
-
- if (window_manager_surface_info_.is_valid()) {
- frame.metadata.referenced_surfaces.push_back(
- viz::SurfaceRange(window_manager_surface_info_.id()));
- }
-
- return frame;
-}
-
-viz::HitTestRegionList FrameGenerator::GenerateHitTestRegionList() const {
- viz::HitTestRegionList hit_test_region_list;
- hit_test_region_list.flags = viz::HitTestRegionFlags::kHitTestMine;
- hit_test_region_list.bounds.set_size(pixel_size_);
-
- viz::HitTestRegion hit_test_region;
- hit_test_region.frame_sink_id =
- window_manager_surface_info_.id().frame_sink_id();
- hit_test_region.flags = viz::HitTestRegionFlags::kHitTestChildSurface;
- hit_test_region.rect = gfx::Rect(pixel_size_);
-
- hit_test_region_list.regions.push_back(std::move(hit_test_region));
-
- return hit_test_region_list;
-}
-
-void FrameGenerator::DrawWindow(viz::RenderPass* pass) {
- DCHECK(window_manager_surface_info_.is_valid());
-
- const gfx::Rect bounds_at_origin(
- window_manager_surface_info_.size_in_pixels());
-
- gfx::Transform quad_to_target_transform;
-
- if (scale_and_center_) {
- // Determine the scaling to fit the source within the target.
- gfx::SizeF source(window_manager_surface_info_.size_in_pixels());
- const gfx::SizeF target(pixel_size_);
- const float scale = std::min(target.width() / source.width(),
- target.height() / source.height());
-
- // Apply the transform to center the source within the output.
- source.Scale(scale);
- DCHECK(source.width() <= target.width() ||
- source.height() <= target.height());
- if (source.width() < target.width()) {
- quad_to_target_transform.Translate(
- (target.width() - source.width()) / 2.0f, 0);
- } else if (source.height() < target.height()) {
- quad_to_target_transform.Translate(
- 0, (target.height() - source.height()) / 2.0f);
- }
-
- // Apply the scaling after the transform.
- quad_to_target_transform.Scale(scale, scale);
- }
-
- viz::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
-
- gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(
- bounds_at_origin.size(),
- window_manager_surface_info_.device_scale_factor(),
- window_manager_surface_info_.device_scale_factor());
-
- // TODO(fsamuel): These clipping and visible rects are incorrect. They need
- // to be populated from CompositorFrame structs.
- sqs->SetAll(quad_to_target_transform,
- gfx::Rect(scaled_bounds) /* layer_rect */,
- bounds_at_origin /* visible_layer_bounds */,
- bounds_at_origin /* clip_rect */, false /* is_clipped */,
- false /* are_contents_opaque */, 1.0f /* opacity */,
- SkBlendMode::kSrcOver, 0 /* sorting-context_id */);
- auto* quad = pass->CreateAndAppendDrawQuad<viz::SurfaceDrawQuad>();
- quad->SetAll(sqs, bounds_at_origin /* rect */,
- bounds_at_origin /* visible_rect */, true /* needs_blending*/,
- viz::SurfaceRange(window_manager_surface_info_.id()),
- SK_ColorWHITE /* default_background_color */,
- false /* stretch_content_to_fill_bounds */);
-}
-
-void FrameGenerator::SetNeedsBeginFrame(bool needs_begin_frame) {
- needs_begin_frame &= window_manager_surface_info_.is_valid();
- compositor_frame_sink_->SetNeedsBeginFrame(needs_begin_frame);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/frame_generator.h b/services/ui/ws/frame_generator.h
deleted file mode 100644
index 998f2a3..0000000
--- a/services/ui/ws/frame_generator.h
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_FRAME_GENERATOR_H_
-#define SERVICES_UI_WS_FRAME_GENERATOR_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "components/viz/common/frame_sinks/begin_frame_source.h"
-#include "components/viz/common/hit_test/hit_test_region_list.h"
-#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
-#include "components/viz/common/surfaces/surface_id.h"
-#include "components/viz/common/surfaces/surface_info.h"
-#include "services/ui/ws/compositor_frame_sink_client_binding.h"
-#include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace cc {
-class RenderPass;
-}
-
-namespace ui {
-namespace ws {
-
-// Responsible for redrawing the display in response to the redraw requests by
-// submitting CompositorFrames to the owned CompositorFrameSink.
-class FrameGenerator : public viz::mojom::CompositorFrameSinkClient {
- public:
- FrameGenerator();
- ~FrameGenerator() override;
-
- void SetDeviceScaleFactor(float device_scale_factor);
- void SetHighContrastMode(bool enabled);
-
- // Updates the WindowManager's SurfaceInfo.
- void SetEmbeddedSurface(const viz::SurfaceInfo& surface_info);
-
- // Swaps the |window_manager_surface_info_| with that of |other|.
- void SwapSurfaceWith(FrameGenerator* other);
-
- void OnWindowDamaged();
- void OnWindowSizeChanged(const gfx::Size& pixel_size);
- void Bind(
- std::unique_ptr<viz::mojom::CompositorFrameSink> compositor_frame_sink,
- viz::mojom::DisplayPrivateAssociatedPtr display_private);
-
- const viz::SurfaceInfo& window_manager_surface_info() const {
- return window_manager_surface_info_;
- }
-
- void set_scale_and_center(bool value) { scale_and_center_ = value; }
-
- private:
- // viz::mojom::CompositorFrameSinkClient implementation:
- void DidReceiveCompositorFrameAck(
- const std::vector<viz::ReturnedResource>& resources) override;
- void DidPresentCompositorFrame(
- uint32_t presentation_token,
- const gfx::PresentationFeedback& feedback) override;
- void OnBeginFrame(const viz::BeginFrameArgs& args) override;
- void OnBeginFramePausedChanged(bool paused) override {}
- void ReclaimResources(
- const std::vector<viz::ReturnedResource>& resources) override;
-
- viz::CompositorFrame GenerateCompositorFrame();
-
- viz::HitTestRegionList GenerateHitTestRegionList() const;
-
- // DrawWindow creates SurfaceDrawQuad for the window manager and appends it to
- // the provided viz::RenderPass.
- void DrawWindow(viz::RenderPass* pass);
-
- void SetNeedsBeginFrame(bool needs_begin_frame);
-
- float device_scale_factor_ = 1.f;
- gfx::Size pixel_size_;
-
- std::unique_ptr<viz::mojom::CompositorFrameSink> compositor_frame_sink_;
- viz::mojom::DisplayPrivateAssociatedPtr display_private_;
- viz::BeginFrameArgs last_begin_frame_args_;
- viz::BeginFrameAck current_begin_frame_ack_;
- bool high_contrast_mode_enabled_ = false;
- gfx::Size last_submitted_frame_size_;
- viz::ParentLocalSurfaceIdAllocator id_allocator_;
- float last_device_scale_factor_ = 0.0f;
-
- viz::SurfaceInfo window_manager_surface_info_;
-
- // Whether the window manager surface should be scaled and centered.
- bool scale_and_center_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(FrameGenerator);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_FRAME_GENERATOR_H_
diff --git a/services/ui/ws/frame_generator_unittest.cc b/services/ui/ws/frame_generator_unittest.cc
deleted file mode 100644
index c50f5900..0000000
--- a/services/ui/ws/frame_generator_unittest.cc
+++ /dev/null
@@ -1,311 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/frame_generator.h"
-
-#include "base/macros.h"
-#include "base/test/scoped_task_environment.h"
-#include "components/viz/common/frame_sinks/begin_frame_source.h"
-#include "components/viz/common/quads/render_pass.h"
-#include "components/viz/test/begin_frame_args_test.h"
-#include "components/viz/test/fake_external_begin_frame_source.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-
-namespace {
-
-constexpr float kRefreshRate = 0.f;
-constexpr bool kTickAutomatically = false;
-constexpr float kDefaultScaleFactor = 1.0f;
-constexpr float kArbitraryScaleFactor = 0.5f;
-constexpr gfx::Size kArbitrarySize(3, 4);
-constexpr gfx::Size kAnotherArbitrarySize(5, 6);
-const viz::SurfaceId kArbitrarySurfaceId(
- viz::FrameSinkId(1, 1),
- viz::LocalSurfaceId(1, base::UnguessableToken::Create()));
-const viz::SurfaceInfo kArbitrarySurfaceInfo(kArbitrarySurfaceId,
- 1.0f,
- gfx::Size(100, 100));
-}
-
-// TestClientBinding Observes a BeginFrame and accepts CompositorFrame submitted
-// from FrameGenerator. It provides a way to inspect CompositorFrames.
-class TestClientBinding : public viz::mojom::CompositorFrameSink,
- public viz::BeginFrameObserver {
- public:
- explicit TestClientBinding(viz::mojom::CompositorFrameSinkClient* sink_client)
- : sink_client_(sink_client) {}
- ~TestClientBinding() override = default;
-
- // viz::mojom::CompositorFrameSink implementation:
- void SubmitCompositorFrame(
- const viz::LocalSurfaceId& local_surface_id,
- viz::CompositorFrame frame,
- base::Optional<viz::HitTestRegionList> hit_test_region_list,
- uint64_t submit_time) override {
- ++frames_submitted_;
- last_frame_ = std::move(frame);
- last_begin_frame_ack_ = last_frame_.metadata.begin_frame_ack;
- }
-
- void SubmitCompositorFrameSync(
- const viz::LocalSurfaceId& local_surface_id,
- viz::CompositorFrame frame,
- base::Optional<viz::HitTestRegionList> hit_test_region_list,
- uint64_t submit_time,
- SubmitCompositorFrameSyncCallback callback) override {}
-
- void DidNotProduceFrame(const viz::BeginFrameAck& ack) override {
- last_begin_frame_ack_ = ack;
- }
-
- void DidAllocateSharedBitmap(mojo::ScopedSharedBufferHandle buffer,
- const viz::SharedBitmapId& id) override {}
-
- void DidDeleteSharedBitmap(const viz::SharedBitmapId& id) override {}
-
- void SetNeedsBeginFrame(bool needs_begin_frame) override {
- if (needs_begin_frame == observing_begin_frames_)
- return;
-
- observing_begin_frames_ = needs_begin_frame;
- if (needs_begin_frame) {
- begin_frame_source_->AddObserver(this);
- } else {
- begin_frame_source_->RemoveObserver(this);
- }
- }
-
- void SetWantsAnimateOnlyBeginFrames() override {}
-
- // viz::BeginFrameObserver implementation.
- void OnBeginFrame(const viz::BeginFrameArgs& args) override {
- sink_client_->OnBeginFrame(args);
- last_begin_frame_args_ = args;
- }
-
- const viz::BeginFrameArgs& LastUsedBeginFrameArgs() const override {
- return last_begin_frame_args_;
- }
-
- bool WantsAnimateOnlyBeginFrames() const override { return false; }
-
- void OnBeginFrameSourcePausedChanged(bool paused) override {}
-
- void SetBeginFrameSource(viz::BeginFrameSource* begin_frame_source) {
- begin_frame_source_ = begin_frame_source;
- }
-
- const viz::RenderPassList& last_render_pass_list() const {
- return last_frame_.render_pass_list;
- }
-
- const viz::CompositorFrameMetadata& last_metadata() const {
- return last_frame_.metadata;
- }
-
- int frames_submitted() const { return frames_submitted_; }
-
- const viz::BeginFrameAck& last_begin_frame_ack() const {
- return last_begin_frame_ack_;
- }
-
- private:
- viz::mojom::CompositorFrameSinkClient* sink_client_;
- viz::BeginFrameArgs last_begin_frame_args_;
- viz::CompositorFrame last_frame_;
- viz::BeginFrameSource* begin_frame_source_ = nullptr;
- bool observing_begin_frames_ = false;
- int frames_submitted_ = 0;
- viz::BeginFrameAck last_begin_frame_ack_;
-};
-
-class FrameGeneratorTest : public testing::Test {
- public:
- FrameGeneratorTest() = default;
- ~FrameGeneratorTest() override = default;
-
- // testing::Test overrides:
- void SetUp() override {
- testing::Test::SetUp();
-
- frame_generator_ = std::make_unique<FrameGenerator>();
- begin_frame_source_ = std::make_unique<viz::FakeExternalBeginFrameSource>(
- kRefreshRate, kTickAutomatically);
-
- // FrameGenerator requires a valid SurfaceInfo before generating
- // CompositorFrames.
- std::unique_ptr<TestClientBinding> client_binding =
- std::make_unique<TestClientBinding>(frame_generator_.get());
- binding_ = client_binding.get();
- IssueBeginFrame();
-
- // FrameGenerator does not request BeginFrames right after creation.
- EXPECT_EQ(0, NumberOfFramesReceived());
- client_binding->SetBeginFrameSource(begin_frame_source_.get());
- viz::mojom::DisplayPrivateAssociatedPtr display_private;
- mojo::MakeRequestAssociatedWithDedicatedPipe(&display_private);
- frame_generator_->Bind(std::move(client_binding),
- std::move(display_private));
- };
-
- // InitWithSurfaceInfo creates a TestClientBinding and binds it to
- // |frame_generator_|. After InitWithSurfaceInfo finishes, |frame_generator_|
- // has a valid SurfaceInfo and does not request BeginFrames.
- void InitWithSurfaceInfo() {
- frame_generator_->SetEmbeddedSurface(kArbitrarySurfaceInfo);
-
- // Issue a BeginFrame so that frame_generator_ stops requesting BeginFrames
- // after submitting a CompositorFrame.
- IssueBeginFrame();
- EXPECT_EQ(1, NumberOfFramesReceived());
- }
-
- void IssueBeginFrame() {
- begin_frame_source_->TestOnBeginFrame(viz::CreateBeginFrameArgsForTesting(
- BEGINFRAME_FROM_HERE, 0, next_sequence_number_));
- ++next_sequence_number_;
- }
-
- int NumberOfFramesReceived() const { return binding_->frames_submitted(); }
-
- const viz::BeginFrameAck& LastBeginFrameAck() const {
- return binding_->last_begin_frame_ack();
- }
-
- const viz::CompositorFrameMetadata& LastMetadata() const {
- return binding_->last_metadata();
- }
-
- const viz::RenderPassList& LastRenderPassList() const {
- return binding_->last_render_pass_list();
- }
-
- FrameGenerator* frame_generator() { return frame_generator_.get(); }
- viz::BeginFrameSource* begin_frame_source() {
- return begin_frame_source_.get();
- }
-
- TestClientBinding* binding() { return binding_; }
-
- private:
- base::test::ScopedTaskEnvironment scoped_task_environment_;
- std::unique_ptr<viz::FakeExternalBeginFrameSource> begin_frame_source_;
- std::unique_ptr<FrameGenerator> frame_generator_;
- TestClientBinding* binding_ = nullptr;
- int next_sequence_number_ = 1;
-
- DISALLOW_COPY_AND_ASSIGN(FrameGeneratorTest);
-};
-
-// FrameGenerator has an invalid SurfaceInfo as default. FrameGenerator does not
-// submit CompositorFrames when its SurfaceInfo is invalid.
-TEST_F(FrameGeneratorTest, InvalidSurfaceInfo) {
- IssueBeginFrame();
- EXPECT_EQ(0, NumberOfFramesReceived());
- EXPECT_EQ(viz::BeginFrameAck(), LastBeginFrameAck());
-}
-
-TEST_F(FrameGeneratorTest, OnFirstSurfaceActivation) {
- InitWithSurfaceInfo();
-
- // Verify that the CompositorFrame refers to the window manager's surface via
- // referenced_surfaces.
- const viz::CompositorFrameMetadata& last_metadata = LastMetadata();
- const std::vector<viz::SurfaceRange>& referenced_surfaces =
- last_metadata.referenced_surfaces;
- EXPECT_EQ(1lu, referenced_surfaces.size());
- EXPECT_EQ(viz::SurfaceRange(kArbitrarySurfaceId),
- referenced_surfaces.front());
-
- viz::BeginFrameAck expected_ack(0, 2, true);
- EXPECT_EQ(expected_ack, LastBeginFrameAck());
- EXPECT_EQ(expected_ack, last_metadata.begin_frame_ack);
-
- // FrameGenerator stops requesting BeginFrames after submitting a
- // CompositorFrame.
- IssueBeginFrame();
- EXPECT_EQ(expected_ack, LastBeginFrameAck());
-}
-
-TEST_F(FrameGeneratorTest, SetDeviceScaleFactor) {
- InitWithSurfaceInfo();
-
- // FrameGenerator does not request BeginFrames if its device scale factor
- // remains unchanged.
- frame_generator()->SetDeviceScaleFactor(kDefaultScaleFactor);
- IssueBeginFrame();
- EXPECT_EQ(1, NumberOfFramesReceived());
- const viz::CompositorFrameMetadata& last_metadata = LastMetadata();
- EXPECT_EQ(kDefaultScaleFactor, last_metadata.device_scale_factor);
-
- frame_generator()->SetDeviceScaleFactor(kArbitraryScaleFactor);
- IssueBeginFrame();
- EXPECT_EQ(2, NumberOfFramesReceived());
- const viz::CompositorFrameMetadata& second_last_metadata = LastMetadata();
- EXPECT_EQ(kArbitraryScaleFactor, second_last_metadata.device_scale_factor);
-}
-
-TEST_F(FrameGeneratorTest, SetHighContrastMode) {
- InitWithSurfaceInfo();
-
- // Changing high contrast mode should trigger a BeginFrame.
- frame_generator()->SetHighContrastMode(true);
- IssueBeginFrame();
- EXPECT_EQ(2, NumberOfFramesReceived());
-
- // Verify that the last frame has an invert filter.
- const viz::RenderPassList& render_pass_list = LastRenderPassList();
- const cc::FilterOperations expected_filters(
- {cc::FilterOperation::CreateInvertFilter(1.f)});
- EXPECT_EQ(expected_filters, render_pass_list.front()->filters);
-}
-
-TEST_F(FrameGeneratorTest, WindowBoundsChanged) {
- InitWithSurfaceInfo();
-
- // Window bounds change triggers a BeginFrame.
- constexpr viz::RenderPassId expected_render_pass_id = 1u;
- frame_generator()->OnWindowSizeChanged(kArbitrarySize);
- IssueBeginFrame();
- EXPECT_EQ(2, NumberOfFramesReceived());
- viz::RenderPass* received_render_pass = LastRenderPassList().front().get();
- EXPECT_EQ(expected_render_pass_id, received_render_pass->id);
- EXPECT_EQ(kArbitrarySize, received_render_pass->output_rect.size());
- EXPECT_EQ(kArbitrarySize, received_render_pass->damage_rect.size());
- EXPECT_EQ(gfx::Transform(), received_render_pass->transform_to_root_target);
-}
-
-// Change window bounds twice before issuing a BeginFrame. The CompositorFrame
-// submitted by frame_generator() should only has the second bounds.
-TEST_F(FrameGeneratorTest, WindowBoundsChangedTwice) {
- InitWithSurfaceInfo();
-
- frame_generator()->OnWindowSizeChanged(kArbitrarySize);
- frame_generator()->OnWindowSizeChanged(kAnotherArbitrarySize);
- IssueBeginFrame();
- EXPECT_EQ(2, NumberOfFramesReceived());
- viz::RenderPass* received_render_pass = LastRenderPassList().front().get();
- EXPECT_EQ(kAnotherArbitrarySize, received_render_pass->output_rect.size());
- EXPECT_EQ(kAnotherArbitrarySize, received_render_pass->damage_rect.size());
-
- // frame_generator() stops requesting BeginFrames after getting one.
- IssueBeginFrame();
- EXPECT_EQ(2, NumberOfFramesReceived());
-}
-
-TEST_F(FrameGeneratorTest, WindowDamaged) {
- InitWithSurfaceInfo();
-
- frame_generator()->OnWindowDamaged();
- IssueBeginFrame();
- EXPECT_EQ(2, NumberOfFramesReceived());
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/ids.h b/services/ui/ws/ids.h
deleted file mode 100644
index 87a0b10..0000000
--- a/services/ui/ws/ids.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_IDS_H_
-#define SERVICES_UI_WS_IDS_H_
-
-#include <stdint.h>
-
-#include "components/viz/common/surfaces/frame_sink_id.h"
-#include "services/ui/common/types.h"
-
-namespace ui {
-namespace ws {
-
-// See comments in README.md (services/ui/ws/README.md) for details on ids.
-
-// A client id used to indicate no client. That is, no WindowTree ever gets this
-// id.
-const ClientSpecificId kInvalidClientId = 0;
-
-const Id kInvalidTransportId = 0;
-
-// Client id used to indicate the window was created by the WindowServer.
-const ClientSpecificId kWindowServerClientId = 1;
-
-// Used for ids assigned by the client.
-using ClientWindowId = viz::FrameSinkId;
-
-using ClientWindowIdHash = viz::FrameSinkIdHash;
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_IDS_H_
diff --git a/services/ui/ws/modal_window_controller.cc b/services/ui/ws/modal_window_controller.cc
deleted file mode 100644
index 5e986abe..0000000
--- a/services/ui/ws/modal_window_controller.cc
+++ /dev/null
@@ -1,338 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/modal_window_controller.h"
-
-#include "base/stl_util.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_drawn_tracker.h"
-
-namespace ui {
-namespace ws {
-namespace {
-
-// This mirrors that of RootWindowController.
-bool IsWindowAboveContainer(const ServerWindow* window,
- const ServerWindow* blocking_container) {
- std::vector<const ServerWindow*> target_path;
- std::vector<const ServerWindow*> blocking_path;
-
- while (window) {
- target_path.push_back(window);
- window = window->parent();
- }
-
- while (blocking_container) {
- blocking_path.push_back(blocking_container);
- blocking_container = blocking_container->parent();
- }
-
- // The root window is put at the end so that we compare windows at
- // the same depth.
- while (!blocking_path.empty()) {
- if (target_path.empty())
- return false;
-
- const ServerWindow* target = target_path.back();
- target_path.pop_back();
- const ServerWindow* blocking = blocking_path.back();
- blocking_path.pop_back();
-
- // Still on the same path, continue.
- if (target == blocking)
- continue;
-
- // This can happen only if unparented window is passed because
- // first element must be the same root.
- if (!target->parent() || !blocking->parent())
- return false;
-
- const ServerWindow* common_parent = target->parent();
- DCHECK_EQ(common_parent, blocking->parent());
- const ServerWindow::Windows& windows = common_parent->children();
- auto blocking_iter = std::find(windows.begin(), windows.end(), blocking);
- // If the target window is above blocking window, the window can handle
- // events.
- return std::find(blocking_iter, windows.end(), target) != windows.end();
- }
-
- return true;
-}
-
-const ServerWindow* GetModalChildForWindowAncestor(const ServerWindow* window) {
- for (const ServerWindow* ancestor = window; ancestor;
- ancestor = ancestor->parent()) {
- for (auto* transient_child : ancestor->transient_children()) {
- if (transient_child->modal_type() != MODAL_TYPE_NONE &&
- transient_child->IsDrawn())
- return transient_child;
- }
- }
- return nullptr;
-}
-
-const ServerWindow* GetWindowModalTargetForWindow(const ServerWindow* window) {
- const ServerWindow* modal_window = GetModalChildForWindowAncestor(window);
- if (!modal_window)
- return window;
- return GetWindowModalTargetForWindow(modal_window);
-}
-
-// Returns true if |transient| is a valid modal window. |target_window| is
-// the window being considered.
-bool IsModalTransientChild(const ServerWindow* transient,
- const ServerWindow* target_window) {
- return transient->IsDrawn() &&
- (transient->modal_type() == MODAL_TYPE_WINDOW ||
- transient->modal_type() == MODAL_TYPE_SYSTEM ||
- (transient->modal_type() == MODAL_TYPE_CHILD &&
- (transient->GetChildModalParent() &&
- transient->GetChildModalParent()->Contains(target_window))));
-}
-
-// Returns the deepest modal window starting at |activatable|. |target_window|
-// is the window being considered.
-const ServerWindow* GetModalTransientChild(const ServerWindow* activatable,
- const ServerWindow* target_window) {
- for (const ServerWindow* transient : activatable->transient_children()) {
- if (IsModalTransientChild(transient, target_window)) {
- if (transient->transient_children().empty())
- return transient;
-
- const ServerWindow* modal_child =
- GetModalTransientChild(transient, target_window);
- return modal_child ? modal_child : transient;
- }
- }
- return nullptr;
-}
-
-} // namespace
-
-class ModalWindowController::TrackedBlockingContainers
- : public ServerWindowObserver {
- public:
- TrackedBlockingContainers(ModalWindowController* modal_window_controller,
- ServerWindow* system_modal_container,
- ServerWindow* min_container)
- : modal_window_controller_(modal_window_controller),
- system_modal_container_(system_modal_container),
- min_container_(min_container) {
- DCHECK(system_modal_container_);
- system_modal_container_->AddObserver(this);
- if (min_container_)
- min_container_->AddObserver(this);
- }
-
- ~TrackedBlockingContainers() override {
- if (system_modal_container_)
- system_modal_container_->RemoveObserver(this);
- if (min_container_)
- min_container_->RemoveObserver(this);
- }
-
- bool IsInDisplayWithRoot(const ServerWindow* root) const {
- return root->Contains(system_modal_container_);
- }
-
- ServerWindow* system_modal_container() { return system_modal_container_; }
-
- ServerWindow* min_container() { return min_container_; }
-
- private:
- void Destroy() {
- modal_window_controller_->DestroyTrackedBlockingContainers(this);
- }
-
- // ServerWindowObserver:
- void OnWindowDestroying(ServerWindow* window) override {
- if (window == min_container_) {
- min_container_->RemoveObserver(this);
- min_container_ = nullptr;
- if (!system_modal_container_)
- Destroy();
- } else if (window == system_modal_container_) {
- system_modal_container_->RemoveObserver(this);
- system_modal_container_ = nullptr;
- // The |system_modal_container_| should always be valid.
- Destroy();
- }
- }
-
- ModalWindowController* modal_window_controller_;
- ServerWindow* system_modal_container_;
- ServerWindow* min_container_;
-
- DISALLOW_COPY_AND_ASSIGN(TrackedBlockingContainers);
-};
-
-ModalWindowController::ModalWindowController() {}
-
-ModalWindowController::~ModalWindowController() {
- for (auto it = system_modal_windows_.begin();
- it != system_modal_windows_.end(); it++) {
- (*it)->RemoveObserver(this);
- }
-}
-
-void ModalWindowController::SetBlockingContainers(
- const std::vector<BlockingContainers>& all_blocking_containers) {
- all_blocking_containers_.clear();
-
- for (const BlockingContainers& containers : all_blocking_containers) {
- all_blocking_containers_.push_back(
- std::make_unique<TrackedBlockingContainers>(
- this, containers.system_modal_container, containers.min_container));
- }
-}
-
-void ModalWindowController::AddSystemModalWindow(ServerWindow* window) {
- DCHECK(window);
- DCHECK(!base::ContainsValue(system_modal_windows_, window));
- DCHECK_EQ(MODAL_TYPE_SYSTEM, window->modal_type());
-
- system_modal_windows_.push_back(window);
- window_drawn_trackers_.insert(make_pair(
- window, std::make_unique<ServerWindowDrawnTracker>(window, this)));
- window->AddObserver(this);
-}
-
-void ModalWindowController::DestroyTrackedBlockingContainers(
- TrackedBlockingContainers* containers) {
- for (auto iter = all_blocking_containers_.begin();
- iter != all_blocking_containers_.end(); ++iter) {
- if (iter->get() == containers) {
- all_blocking_containers_.erase(iter);
- return;
- }
- }
- NOTREACHED();
-}
-
-bool ModalWindowController::IsWindowBlocked(const ServerWindow* window) const {
- if (!window || !window->IsDrawn())
- return true;
-
- return GetModalTransient(window) ||
- IsWindowBlockedBySystemModalOrMinContainer(window);
-}
-
-const ServerWindow* ModalWindowController::GetModalTransient(
- const ServerWindow* window) const {
- if (!window)
- return nullptr;
-
- // We always want to check the for the transient child of the toplevel window.
- const ServerWindow* toplevel = GetToplevelWindow(window);
- if (!toplevel)
- return nullptr;
-
- return GetModalTransientChild(toplevel, window);
-}
-
-const ServerWindow* ModalWindowController::GetToplevelWindow(
- const ServerWindow* window) const {
- const ServerWindow* last = nullptr;
- for (const ServerWindow *w = window; w; last = w, w = w->parent()) {
- if (w->is_activation_parent())
- return last;
- }
- return nullptr;
-}
-
-const ServerWindow* ModalWindowController::GetActiveSystemModalWindow() const {
- for (auto it = system_modal_windows_.rbegin();
- it != system_modal_windows_.rend(); it++) {
- ServerWindow* modal = *it;
- if (modal->IsDrawn() && IsWindowInSystemModalContainer(modal))
- return modal;
- }
- return nullptr;
-}
-
-bool ModalWindowController::IsWindowBlockedBySystemModalOrMinContainer(
- const ServerWindow* window) const {
- const ServerWindow* system_modal_window = GetActiveSystemModalWindow();
- const ServerWindow* min_container = nullptr;
- if (system_modal_window) {
- // If there is a system modal window, then |window| must be part of the
- // system modal window.
- const bool is_part_of_active_modal =
- system_modal_window->Contains(window) ||
- window->HasTransientAncestor(system_modal_window);
- if (!is_part_of_active_modal)
- return true;
-
- // When there is a system modal window the |min_container| becomes the
- // system modal container.
- min_container = system_modal_window->parent();
- } else {
- min_container = GetMinContainer(window);
- }
- return min_container && !IsWindowAboveContainer(window, min_container);
-}
-
-bool ModalWindowController::IsWindowInSystemModalContainer(
- const ServerWindow* window) const {
- DCHECK(window->IsDrawn());
- const ServerWindow* root = window->GetRootForDrawn();
- DCHECK(root);
- for (auto& blocking_containers : all_blocking_containers_) {
- if (blocking_containers->IsInDisplayWithRoot(root))
- return window->parent() == blocking_containers->system_modal_container();
- }
- // This means the window manager didn't set the blocking containers, assume
- // the window is in a valid system modal container.
- return true;
-}
-
-const ServerWindow* ModalWindowController::GetMinContainer(
- const ServerWindow* window) const {
- DCHECK(window->IsDrawn());
- const ServerWindow* root = window->GetRootForDrawn();
- DCHECK(root);
- for (auto& blocking_containers : all_blocking_containers_) {
- if (blocking_containers->IsInDisplayWithRoot(root))
- return blocking_containers->min_container();
- }
- return nullptr;
-}
-
-void ModalWindowController::RemoveWindow(ServerWindow* window) {
- window->RemoveObserver(this);
- auto it = std::find(system_modal_windows_.begin(),
- system_modal_windows_.end(), window);
- DCHECK(it != system_modal_windows_.end());
- system_modal_windows_.erase(it);
- window_drawn_trackers_.erase(window);
-}
-
-void ModalWindowController::OnWindowDestroyed(ServerWindow* window) {
- RemoveWindow(window);
-}
-
-void ModalWindowController::OnWindowModalTypeChanged(ServerWindow* window,
- ModalType old_modal_type) {
- DCHECK_EQ(MODAL_TYPE_SYSTEM, old_modal_type);
- DCHECK_NE(MODAL_TYPE_SYSTEM, window->modal_type());
- RemoveWindow(window);
-}
-
-void ModalWindowController::OnDrawnStateChanged(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) {
- if (!is_drawn)
- return;
-
- // Move the most recently shown window to the end of the list.
- auto it = std::find(system_modal_windows_.begin(),
- system_modal_windows_.end(), window);
- DCHECK(it != system_modal_windows_.end());
- system_modal_windows_.splice(system_modal_windows_.end(),
- system_modal_windows_, it);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/modal_window_controller.h b/services/ui/ws/modal_window_controller.h
deleted file mode 100644
index af2b8a20..0000000
--- a/services/ui/ws/modal_window_controller.h
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_MODAL_WINDOW_CONTROLLER_H_
-#define SERVICES_UI_WS_MODAL_WINDOW_CONTROLLER_H_
-
-#include <list>
-#include <map>
-#include <vector>
-
-#include "services/ui/ws/server_window_drawn_tracker_observer.h"
-#include "services/ui/ws/server_window_observer.h"
-
-namespace ui {
-namespace ws {
-
-class ServerWindow;
-class ServerWindowDrawnTracker;
-
-namespace test {
-class ModalWindowControllerTestApi;
-}
-
-// See mojom::BlockingContainers for details on this. |min_container| may
-// be null.
-struct BlockingContainers {
- ServerWindow* system_modal_container = nullptr;
- ServerWindow* min_container = nullptr;
-};
-
-// Used to keeps track of system modal windows and check whether windows are
-// blocked by modal windows or not to do appropriate retargetting of events.
-class ModalWindowController : public ServerWindowObserver,
- public ServerWindowDrawnTrackerObserver {
- public:
- ModalWindowController();
- ~ModalWindowController() override;
-
- // See description in mojom::WindowManager::SetBlockingContainers() for
- // details on this.
- void SetBlockingContainers(
- const std::vector<BlockingContainers>& all_containers);
-
- // Adds a system modal window. The window remains modal to system until it is
- // destroyed. There can exist multiple system modal windows, in which case the
- // one that is visible and added most recently or shown most recently would be
- // the active one.
- void AddSystemModalWindow(ServerWindow* window);
-
- // Checks whether |window| is blocked by any visible modal window.
- bool IsWindowBlocked(const ServerWindow* window) const;
-
- // Returns the deepest modal window that is a transient descendants of the
- // top-level window for |window|.
- ServerWindow* GetModalTransient(ServerWindow* window) {
- return const_cast<ServerWindow*>(
- GetModalTransient(static_cast<const ServerWindow*>(window)));
- }
- const ServerWindow* GetModalTransient(const ServerWindow* window) const;
-
- ServerWindow* GetToplevelWindow(ServerWindow* window) {
- return const_cast<ServerWindow*>(
- GetToplevelWindow(static_cast<const ServerWindow*>(window)));
- }
- const ServerWindow* GetToplevelWindow(const ServerWindow* window) const;
-
- // Returns the system modal window that is visible and added/shown most
- // recently, if any.
- ServerWindow* GetActiveSystemModalWindow() {
- return const_cast<ServerWindow*>(
- const_cast<const ModalWindowController*>(this)
- ->GetActiveSystemModalWindow());
- }
- const ServerWindow* GetActiveSystemModalWindow() const;
-
- private:
- friend class test::ModalWindowControllerTestApi;
- class TrackedBlockingContainers;
-
- // Called when the window associated with a TrackedBlockingContainers is
- // destroyed.
- void DestroyTrackedBlockingContainers(TrackedBlockingContainers* containers);
-
- // Returns true if the there is a system modal window and |window| is not
- // associated with it, or |window| is not above the minimum container (if one
- // has been set).
- bool IsWindowBlockedBySystemModalOrMinContainer(
- const ServerWindow* window) const;
-
- // Returns true if |window| is in a container marked for system models.
- bool IsWindowInSystemModalContainer(const ServerWindow* window) const;
-
- const ServerWindow* GetMinContainer(const ServerWindow* window) const;
-
- // Removes |window| from the data structures used by this class.
- void RemoveWindow(ServerWindow* window);
-
- // ServerWindowObserver:
- void OnWindowDestroyed(ServerWindow* window) override;
- void OnWindowModalTypeChanged(ServerWindow* window,
- ModalType old_modal_type) override;
-
- // ServerWindowDrawnTrackerObserver:
- void OnDrawnStateChanged(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) override;
-
- // List of system modal windows in order they are added/shown.
- std::list<ServerWindow*> system_modal_windows_;
-
- // Drawn trackers for system modal windows.
- std::map<ServerWindow*, std::unique_ptr<ServerWindowDrawnTracker>>
- window_drawn_trackers_;
-
- std::vector<std::unique_ptr<TrackedBlockingContainers>>
- all_blocking_containers_;
-
- DISALLOW_COPY_AND_ASSIGN(ModalWindowController);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_MODAL_WINDOW_CONTROLLER_H_
diff --git a/services/ui/ws/modal_window_controller_unittest.cc b/services/ui/ws/modal_window_controller_unittest.cc
deleted file mode 100644
index 9eb1dbe1..0000000
--- a/services/ui/ws/modal_window_controller_unittest.cc
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/modal_window_controller.h"
-
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-namespace ws {
-
-class ModalWindowControllerTest : public testing::Test {
- public:
- ModalWindowControllerTest() {}
- ~ModalWindowControllerTest() override {}
-
- VizHostProxy* viz_host_proxy() {
- return ws_test_helper_.window_server()->GetVizHostProxy();
- }
-
- private:
- test::WindowServerTestHelper ws_test_helper_;
-
- DISALLOW_COPY_AND_ASSIGN(ModalWindowControllerTest);
-};
-
-TEST_F(ModalWindowControllerTest, MinContainer) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root_window(&window_delegate, viz::FrameSinkId(1, 1));
- window_delegate.set_root_window(&root_window);
- ServerWindow container1(&window_delegate, viz::FrameSinkId(1, 2));
- ServerWindow container2(&window_delegate, viz::FrameSinkId(1, 3));
- ServerWindow container3(&window_delegate, viz::FrameSinkId(1, 4));
-
- root_window.SetVisible(true);
- container1.SetVisible(true);
- container2.SetVisible(true);
- container3.SetVisible(true);
-
- ModalWindowController modal_window_controller;
-
- std::vector<BlockingContainers> blocking_containers(1);
- blocking_containers[0].system_modal_container = &container3;
- blocking_containers[0].min_container = &container2;
- modal_window_controller.SetBlockingContainers(blocking_containers);
-
- ServerWindow window(&window_delegate, viz::FrameSinkId(1, 5));
- window.SetVisible(true);
-
- // Window should be blocked when not attached to hierarchy.
- EXPECT_TRUE(modal_window_controller.IsWindowBlocked(&window));
-
- container1.Add(&window);
- // Still blocked as still not drawn.
- EXPECT_TRUE(modal_window_controller.IsWindowBlocked(&window));
-
- root_window.Add(&container1);
- root_window.Add(&container2);
- root_window.Add(&container3);
-
- // Still blocked as window beneath min container.
- EXPECT_TRUE(modal_window_controller.IsWindowBlocked(&window));
-
- // container2 (and 3) are above min container, so shouldn't be blocked in
- // either of them.
- container2.Add(&window);
- EXPECT_FALSE(modal_window_controller.IsWindowBlocked(&window));
-
- container3.Add(&window);
- EXPECT_FALSE(modal_window_controller.IsWindowBlocked(&window));
-}
-
-TEST_F(ModalWindowControllerTest, SystemModalContainer) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root_window(&window_delegate, viz::FrameSinkId(1, 1));
- window_delegate.set_root_window(&root_window);
- ServerWindow container1(&window_delegate, viz::FrameSinkId(1, 2));
- ServerWindow container2(&window_delegate, viz::FrameSinkId(1, 3));
- ServerWindow container3(&window_delegate, viz::FrameSinkId(1, 4));
-
- root_window.SetVisible(true);
- container1.SetVisible(true);
- container2.SetVisible(true);
- container3.SetVisible(true);
-
- root_window.Add(&container1);
- root_window.Add(&container2);
- root_window.Add(&container3);
-
- ModalWindowController modal_window_controller;
-
- std::vector<BlockingContainers> blocking_containers(1);
- blocking_containers[0].system_modal_container = &container3;
- blocking_containers[0].min_container = &container2;
- modal_window_controller.SetBlockingContainers(blocking_containers);
-
- ServerWindow window(&window_delegate, viz::FrameSinkId(1, 5));
- window.SetVisible(true);
-
- container2.Add(&window);
- EXPECT_FALSE(modal_window_controller.IsWindowBlocked(&window));
-
- ServerWindow modal_window(&window_delegate, viz::FrameSinkId(1, 6));
- modal_window.SetModalType(MODAL_TYPE_SYSTEM);
- modal_window_controller.AddSystemModalWindow(&modal_window);
-
- // |window| should still not be blocked as the system modal window isn't
- // drawn.
- EXPECT_FALSE(modal_window_controller.IsWindowBlocked(&window));
-
- container3.Add(&modal_window);
- EXPECT_FALSE(modal_window_controller.IsWindowBlocked(&window));
-
- modal_window.SetVisible(true);
- EXPECT_TRUE(modal_window_controller.IsWindowBlocked(&window));
-
- // Move the window to container3, it should still be blocked by the sytem
- // modal.
- container3.Add(&window);
- EXPECT_TRUE(modal_window_controller.IsWindowBlocked(&window));
-
- // Make window a child of the modal window.
- modal_window.Add(&window);
- EXPECT_FALSE(modal_window_controller.IsWindowBlocked(&window));
-
- container3.Add(&window);
- modal_window.AddTransientWindow(&window);
- EXPECT_FALSE(modal_window_controller.IsWindowBlocked(&window));
-
- container2.Add(&window);
- EXPECT_TRUE(modal_window_controller.IsWindowBlocked(&window));
-
- modal_window.RemoveTransientWindow(&window);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/operation.cc b/services/ui/ws/operation.cc
deleted file mode 100644
index 34e28d4d..0000000
--- a/services/ui/ws/operation.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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 "services/ui/ws/operation.h"
-
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree.h"
-
-namespace ui {
-namespace ws {
-
-Operation::Operation(WindowTree* tree,
- WindowServer* window_server,
- OperationType operation_type)
- : window_server_(window_server),
- source_tree_id_(tree->id()),
- operation_type_(operation_type) {
- DCHECK(operation_type != OperationType::NONE);
- // Tell the window server about the operation currently in flight. The window
- // server uses this information to suppress certain calls out to clients.
- window_server_->PrepareForOperation(this);
-}
-
-Operation::~Operation() {
- window_server_->FinishOperation();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/operation.h b/services/ui/ws/operation.h
deleted file mode 100644
index 88fe8c1..0000000
--- a/services/ui/ws/operation.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_OPERATION_H_
-#define SERVICES_UI_WS_OPERATION_H_
-
-#include <set>
-
-#include "base/macros.h"
-#include "services/ui/common/types.h"
-
-namespace ui {
-namespace ws {
-
-class WindowServer;
-class WindowTree;
-
-enum class OperationType {
- NONE,
- ADD_TRANSIENT_WINDOW,
- ADD_WINDOW,
- DELETE_WINDOW,
- EMBED,
- RELEASE_CAPTURE,
- REMOVE_TRANSIENT_WINDOW_FROM_PARENT,
- REMOVE_WINDOW_FROM_PARENT,
- REORDER_WINDOW,
- SET_CAPTURE,
- SET_CLIENT_AREA,
- SET_FOCUS,
- SET_WINDOW_BOUNDS,
- SET_WINDOW_OPACITY,
- SET_WINDOW_PREDEFINED_CURSOR,
- SET_WINDOW_PROPERTY,
- SET_WINDOW_TRANSFORM,
- SET_WINDOW_VISIBILITY,
-};
-
-// This class tracks the currently pending client-initiated operation.
-// This is typically used to suppress superfluous notifications generated
-// by suboperations in the window server.
-class Operation {
- public:
- Operation(WindowTree* tree,
- WindowServer* window_server,
- OperationType operation_type);
- ~Operation();
-
- ClientSpecificId source_tree_id() const { return source_tree_id_; }
-
- const OperationType& type() const { return operation_type_; }
-
- // Marks the tree with the specified id as having been sent a message
- // during the course of |this| operation.
- void MarkTreeAsMessaged(ClientSpecificId tree_id) {
- message_ids_.insert(tree_id);
- }
-
- // Returns true if MarkTreeAsMessaged(tree_id) was invoked.
- bool DidMessageTree(ClientSpecificId tree_id) const {
- return message_ids_.count(tree_id) > 0;
- }
-
- private:
- WindowServer* const window_server_;
- const ClientSpecificId source_tree_id_;
- const OperationType operation_type_;
-
- // See description of MarkTreeAsMessaged/DidMessageTree.
- std::set<ClientSpecificId> message_ids_;
-
- DISALLOW_COPY_AND_ASSIGN(Operation);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_OPERATION_H_
diff --git a/services/ui/ws/platform_display.cc b/services/ui/ws/platform_display.cc
deleted file mode 100644
index 9da4993e..0000000
--- a/services/ui/ws/platform_display.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/platform_display.h"
-
-#include "build/build_config.h"
-#include "services/ui/ws/platform_display_default.h"
-#include "services/ui/ws/platform_display_factory.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/threaded_image_cursors.h"
-#include "services/ui/ws/threaded_image_cursors_factory.h"
-#include "ui/platform_window/platform_window.h"
-
-#if defined(OS_WIN)
-#include "ui/platform_window/win/win_window.h"
-#elif defined(USE_X11)
-#include "ui/platform_window/x11/x11_window.h"
-#elif defined(OS_ANDROID)
-#include "ui/platform_window/android/platform_window_android.h"
-#elif defined(USE_OZONE)
-#include "ui/ozone/public/ozone_platform.h"
-#include "ui/platform_window/platform_window_delegate.h"
-#include "ui/platform_window/platform_window_init_properties.h"
-#endif
-
-namespace ui {
-namespace ws {
-
-// static
-PlatformDisplayFactory* PlatformDisplay::factory_ = nullptr;
-
-// static
-std::unique_ptr<PlatformDisplay> PlatformDisplay::Create(
- ServerWindow* root,
- const display::ViewportMetrics& metrics,
- ThreadedImageCursorsFactory* threaded_image_cursors_factory) {
- if (factory_)
- return factory_->CreatePlatformDisplay(root, metrics);
-
-#if defined(OS_ANDROID)
- return std::make_unique<PlatformDisplayDefault>(root, metrics,
- nullptr /* image_cursors */);
-#else
- return std::make_unique<PlatformDisplayDefault>(
- root, metrics, threaded_image_cursors_factory->CreateCursors());
-#endif
-}
-
-// static
-std::unique_ptr<PlatformWindow> PlatformDisplay::CreatePlatformWindow(
- PlatformWindowDelegate* delegate,
- const gfx::Rect& bounds) {
- DCHECK(!bounds.size().IsEmpty());
- std::unique_ptr<PlatformWindow> platform_window;
-#if defined(OS_WIN)
- platform_window = std::make_unique<ui::WinWindow>(delegate, bounds);
-#elif defined(USE_X11)
- platform_window = std::make_unique<ui::X11Window>(delegate, bounds);
-#elif defined(OS_ANDROID)
- platform_window = std::make_unique<ui::PlatformWindowAndroid>(delegate);
- platform_window->SetBounds(bounds);
-#elif defined(USE_OZONE)
- ui::PlatformWindowInitProperties properties;
- properties.bounds = bounds;
- platform_window = OzonePlatform::GetInstance()->CreatePlatformWindow(
- delegate, std::move(properties));
-#else
- NOTREACHED() << "Unsupported platform";
-#endif
- return platform_window;
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/platform_display.h b/services/ui/ws/platform_display.h
deleted file mode 100644
index b9c1210..0000000
--- a/services/ui/ws/platform_display.h
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_PLATFORM_DISPLAY_H_
-#define SERVICES_UI_WS_PLATFORM_DISPLAY_H_
-
-#include <stdint.h>
-
-#include <memory>
-
-#include "base/memory/ref_counted.h"
-#include "base/strings/string16.h"
-#include "services/ui/display/viewport_metrics.h"
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "ui/display/display.h"
-#include "ui/events/event_source.h"
-#include "ui/gfx/native_widget_types.h"
-
-namespace ui {
-
-enum class CursorSize;
-class PlatformWindow;
-class PlatformWindowDelegate;
-struct TextInputState;
-
-namespace ws {
-
-class FrameGenerator;
-class PlatformDisplayDelegate;
-class PlatformDisplayFactory;
-class ServerWindow;
-class ThreadedImageCursorsFactory;
-
-// PlatformDisplay is used to connect the root ServerWindow to a display.
-class PlatformDisplay : public ui::EventSource {
- public:
- ~PlatformDisplay() override {}
-
- static std::unique_ptr<PlatformDisplay> Create(
- ServerWindow* root_window,
- const display::ViewportMetrics& metrics,
- ThreadedImageCursorsFactory* threaded_image_cursors_factory);
-
- virtual void Init(PlatformDisplayDelegate* delegate) = 0;
-
- virtual void SetViewportSize(const gfx::Size& size) = 0;
-
- virtual void SetTitle(const base::string16& title) = 0;
-
- virtual void SetCapture() = 0;
-
- virtual void ReleaseCapture() = 0;
-
- virtual void SetCursor(const ui::CursorData& cursor) = 0;
-
- virtual void MoveCursorTo(const gfx::Point& window_pixel_location) = 0;
-
- virtual void SetCursorSize(const ui::CursorSize& cursor_size) = 0;
-
- virtual void ConfineCursorToBounds(const gfx::Rect& pixel_bounds) = 0;
-
- virtual void UpdateTextInputState(const ui::TextInputState& state) = 0;
- virtual void SetImeVisibility(bool visible) = 0;
-
- // Updates the viewport metrics for the display.
- virtual void UpdateViewportMetrics(
- const display::ViewportMetrics& metrics) = 0;
-
- virtual const display::ViewportMetrics& GetViewportMetrics() = 0;
-
- // Returns the AcceleratedWidget associated with the Display. It can return
- // kNullAcceleratedWidget if the accelerated widget is not available yet.
- virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;
-
- virtual FrameGenerator* GetFrameGenerator() = 0;
-
- virtual void SetCursorConfig(display::Display::Rotation rotation,
- float scale) = 0;
-
- // Overrides factory for testing. Default (NULL) value indicates regular
- // (non-test) environment.
- static void set_factory_for_testing(PlatformDisplayFactory* factory) {
- PlatformDisplay::factory_ = factory;
- }
-
- protected:
- // Create a platform window with the given delegate and bounds.
- static std::unique_ptr<PlatformWindow> CreatePlatformWindow(
- PlatformWindowDelegate* delegate,
- const gfx::Rect& bounds);
-
- private:
- // Static factory instance (always NULL for non-test).
- static PlatformDisplayFactory* factory_;
-};
-
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_PLATFORM_DISPLAY_H_
diff --git a/services/ui/ws/platform_display_default.cc b/services/ui/ws/platform_display_default.cc
deleted file mode 100644
index f75910d..0000000
--- a/services/ui/ws/platform_display_default.cc
+++ /dev/null
@@ -1,270 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/platform_display_default.h"
-
-#include <utility>
-
-#include "build/build_config.h"
-#include "gpu/ipc/client/gpu_channel_host.h"
-#include "services/ui/display/screen_manager.h"
-#include "services/ui/public/interfaces/cursor/cursor_struct_traits.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/threaded_image_cursors.h"
-#include "services/viz/privileged/interfaces/compositing/display_private.mojom.h"
-#include "ui/display/display.h"
-#include "ui/events/event.h"
-#include "ui/events/event_utils.h"
-#include "ui/platform_window/platform_ime_controller.h"
-#include "ui/platform_window/platform_window.h"
-#include "ui/platform_window/stub/stub_window.h"
-
-#if defined(USE_OZONE)
-#include "ui/events/ozone/chromeos/cursor_controller.h"
-#endif
-
-namespace ui {
-namespace ws {
-
-PlatformDisplayDefault::PlatformDisplayDefault(
- ServerWindow* root_window,
- const display::ViewportMetrics& metrics,
- std::unique_ptr<ThreadedImageCursors> image_cursors)
- : root_window_(root_window),
- image_cursors_(std::move(image_cursors)),
- metrics_(metrics),
- widget_(gfx::kNullAcceleratedWidget) {}
-
-PlatformDisplayDefault::~PlatformDisplayDefault() {
-#if defined(OS_CHROMEOS)
- ui::CursorController::GetInstance()->ClearCursorConfigForWindow(
- GetAcceleratedWidget());
-#endif
-
- // Don't notify the delegate from the destructor.
- delegate_ = nullptr;
-
- frame_generator_.reset();
- image_cursors_.reset();
- // Destroy the PlatformWindow early on as it may call us back during
- // destruction and we want to be in a known state. But destroy the surface
- // and ThreadedImageCursors first because they can still be using the platform
- // window.
- platform_window_.reset();
-}
-
-EventSink* PlatformDisplayDefault::GetEventSink() {
- return delegate_->GetEventSink();
-}
-
-void PlatformDisplayDefault::Init(PlatformDisplayDelegate* delegate) {
- DCHECK(delegate);
- delegate_ = delegate;
-
- const gfx::Rect& bounds = metrics_.bounds_in_pixels;
- DCHECK(!bounds.size().IsEmpty());
-
- if (delegate_->GetDisplay().id() == display::kUnifiedDisplayId) {
- // Virtual unified displays use a StubWindow; see AshWindowTreeHostUnified.
- platform_window_ = std::make_unique<ui::StubWindow>(this, true, bounds);
- } else if (delegate_->GetDisplay().id() == display::kInvalidDisplayId) {
- // Unit tests may use kInvalidDisplayId to request a StubWindow for testing.
- platform_window_ = std::make_unique<ui::StubWindow>(this, false);
- } else {
- platform_window_ = CreatePlatformWindow(this, metrics_.bounds_in_pixels);
- }
-
- platform_window_->Show();
-
- if (image_cursors_) {
- image_cursors_->SetDisplay(delegate_->GetDisplay(),
- metrics_.device_scale_factor);
- }
-}
-
-void PlatformDisplayDefault::SetViewportSize(const gfx::Size& size) {
- platform_window_->SetBounds(gfx::Rect(size));
-}
-
-void PlatformDisplayDefault::SetTitle(const base::string16& title) {
- platform_window_->SetTitle(title);
-}
-
-void PlatformDisplayDefault::SetCapture() {
- platform_window_->SetCapture();
-}
-
-void PlatformDisplayDefault::ReleaseCapture() {
- platform_window_->ReleaseCapture();
-}
-
-void PlatformDisplayDefault::SetCursor(const ui::CursorData& cursor_data) {
- if (!image_cursors_)
- return;
-
- image_cursors_->SetCursor(cursor_data, platform_window_.get());
-}
-
-void PlatformDisplayDefault::MoveCursorTo(
- const gfx::Point& window_pixel_location) {
- platform_window_->MoveCursorTo(window_pixel_location);
-}
-
-void PlatformDisplayDefault::SetCursorSize(const ui::CursorSize& cursor_size) {
- image_cursors_->SetCursorSize(cursor_size);
-}
-
-void PlatformDisplayDefault::ConfineCursorToBounds(
- const gfx::Rect& pixel_bounds) {
- platform_window_->ConfineCursorToBounds(pixel_bounds);
-}
-
-void PlatformDisplayDefault::UpdateTextInputState(
- const ui::TextInputState& state) {
- ui::PlatformImeController* ime = platform_window_->GetPlatformImeController();
- if (ime)
- ime->UpdateTextInputState(state);
-}
-
-void PlatformDisplayDefault::SetImeVisibility(bool visible) {
- ui::PlatformImeController* ime = platform_window_->GetPlatformImeController();
- if (ime)
- ime->SetImeVisibility(visible);
-}
-
-FrameGenerator* PlatformDisplayDefault::GetFrameGenerator() {
- return frame_generator_.get();
-}
-
-void PlatformDisplayDefault::UpdateViewportMetrics(
- const display::ViewportMetrics& metrics) {
- if (metrics_ == metrics)
- return;
-
- gfx::Rect bounds = platform_window_->GetBounds();
- if (bounds.size() != metrics.bounds_in_pixels.size()) {
- bounds.set_size(metrics.bounds_in_pixels.size());
- platform_window_->SetBounds(bounds);
- }
-
- metrics_ = metrics;
- if (frame_generator_) {
- frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor);
- frame_generator_->OnWindowSizeChanged(metrics_.bounds_in_pixels.size());
- }
-}
-
-const display::ViewportMetrics& PlatformDisplayDefault::GetViewportMetrics() {
- return metrics_;
-}
-
-gfx::AcceleratedWidget PlatformDisplayDefault::GetAcceleratedWidget() const {
- return widget_;
-}
-
-void PlatformDisplayDefault::SetCursorConfig(
- display::Display::Rotation rotation,
- float scale) {
-#if defined(OS_CHROMEOS)
- ui::CursorController::GetInstance()->SetCursorConfigForWindow(
- GetAcceleratedWidget(), rotation, scale);
-#endif
-}
-
-void PlatformDisplayDefault::OnBoundsChanged(const gfx::Rect& new_bounds) {
- // We only care if the window size has changed.
- if (new_bounds.size() == metrics_.bounds_in_pixels.size())
- return;
-
- // TODO(tonikitoo): Handle the bounds changing in external window mode. The
- // window should be resized by the WS and it shouldn't involve ScreenManager.
-}
-
-void PlatformDisplayDefault::OnDamageRect(const gfx::Rect& damaged_region) {
- if (frame_generator_)
- frame_generator_->OnWindowDamaged();
-}
-
-void PlatformDisplayDefault::DispatchEvent(ui::Event* event) {
- // Mojo requires conversion of mouse and touch events to pointer events.
- if (event->IsMouseEvent()) {
- ui::PointerEvent pointer_event(*event->AsMouseEvent());
- SendEventToSink(&pointer_event);
- } else if (event->IsTouchEvent()) {
- ui::PointerEvent pointer_event(*event->AsTouchEvent());
- SendEventToSink(&pointer_event);
- } else {
- SendEventToSink(event);
- }
-}
-
-void PlatformDisplayDefault::OnCloseRequest() {
- // TODO(tonikitoo): Handle a close request in external window mode. The window
- // should be closed by the WS and it shouldn't involve ScreenManager.
- const int64_t display_id = delegate_->GetDisplay().id();
- display::ScreenManager::GetInstance()->RequestCloseDisplay(display_id);
-}
-
-void PlatformDisplayDefault::OnClosed() {}
-
-void PlatformDisplayDefault::OnWindowStateChanged(
- ui::PlatformWindowState new_state) {}
-
-void PlatformDisplayDefault::OnLostCapture() {
- delegate_->OnNativeCaptureLost();
-}
-
-void PlatformDisplayDefault::OnAcceleratedWidgetAvailable(
- gfx::AcceleratedWidget widget,
- float device_scale_factor) {
- // This will get called after Init() is called, either synchronously as part
- // of the Init() callstack or async after Init() has returned, depending on
- // the platform.
- DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_);
- widget_ = widget;
- delegate_->OnAcceleratedWidgetAvailable();
-
- if (!delegate_->IsHostingViz())
- return;
-
- viz::mojom::CompositorFrameSinkAssociatedPtr compositor_frame_sink;
- viz::mojom::CompositorFrameSinkClientPtr compositor_frame_sink_client;
- viz::mojom::CompositorFrameSinkClientRequest
- compositor_frame_sink_client_request =
- mojo::MakeRequest(&compositor_frame_sink_client);
-
- // TODO(ccameron): |display_client| is not bound. This will need to
- // change to support macOS.
- viz::mojom::DisplayPrivateAssociatedPtr display_private;
- viz::mojom::DisplayClientPtr display_client;
- viz::mojom::DisplayClientRequest display_client_request =
- mojo::MakeRequest(&display_client);
-
- root_window_->CreateRootCompositorFrameSink(
- widget_, mojo::MakeRequest(&compositor_frame_sink),
- std::move(compositor_frame_sink_client),
- mojo::MakeRequest(&display_private), std::move(display_client));
-
- display_private->SetDisplayVisible(true);
- frame_generator_ = std::make_unique<FrameGenerator>();
- auto frame_sink_client_binding =
- std::make_unique<CompositorFrameSinkClientBinding>(
- frame_generator_.get(),
- std::move(compositor_frame_sink_client_request),
- std::move(compositor_frame_sink));
- frame_generator_->Bind(std::move(frame_sink_client_binding),
- std::move(display_private));
- frame_generator_->OnWindowSizeChanged(root_window_->bounds().size());
- frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor);
-}
-
-void PlatformDisplayDefault::OnAcceleratedWidgetDestroying() {}
-
-void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() {
-}
-
-void PlatformDisplayDefault::OnActivationChanged(bool active) {}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/platform_display_default.h b/services/ui/ws/platform_display_default.h
deleted file mode 100644
index 9b5be0a..0000000
--- a/services/ui/ws/platform_display_default.h
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_PLATFORM_DISPLAY_DEFAULT_H_
-#define SERVICES_UI_WS_PLATFORM_DISPLAY_DEFAULT_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "services/ui/display/viewport_metrics.h"
-#include "services/ui/ws/frame_generator.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/platform_display_delegate.h"
-#include "services/ui/ws/server_window.h"
-#include "ui/platform_window/platform_window_delegate.h"
-
-namespace ui {
-
-class EventSink;
-class PlatformWindow;
-
-namespace ws {
-
-class ThreadedImageCursors;
-
-// PlatformDisplay implementation that connects to a PlatformWindow and
-// FrameGenerator for Chrome OS.
-class PlatformDisplayDefault : public PlatformDisplay,
- public ui::PlatformWindowDelegate {
- public:
- // |image_cursors| may be null, for example on Android or in tests.
- PlatformDisplayDefault(ServerWindow* root_window,
- const display::ViewportMetrics& metrics,
- std::unique_ptr<ThreadedImageCursors> image_cursors);
- ~PlatformDisplayDefault() override;
-
- // EventSource::
- EventSink* GetEventSink() override;
-
- // PlatformDisplay:
- void Init(PlatformDisplayDelegate* delegate) override;
- void SetViewportSize(const gfx::Size& size) override;
- void SetTitle(const base::string16& title) override;
- void SetCapture() override;
- void ReleaseCapture() override;
- void SetCursor(const ui::CursorData& cursor) override;
- void MoveCursorTo(const gfx::Point& window_pixel_location) override;
- void SetCursorSize(const ui::CursorSize& cursor_size) override;
- void ConfineCursorToBounds(const gfx::Rect& pixel_bounds) override;
- void UpdateTextInputState(const ui::TextInputState& state) override;
- void SetImeVisibility(bool visible) override;
- void UpdateViewportMetrics(const display::ViewportMetrics& metrics) override;
- const display::ViewportMetrics& GetViewportMetrics() override;
- gfx::AcceleratedWidget GetAcceleratedWidget() const override;
- FrameGenerator* GetFrameGenerator() override;
- void SetCursorConfig(display::Display::Rotation rotation,
- float scale) override;
-
- private:
- // ui::PlatformWindowDelegate:
- void OnBoundsChanged(const gfx::Rect& new_bounds) override;
- void OnDamageRect(const gfx::Rect& damaged_region) override;
- void DispatchEvent(ui::Event* event) override;
- void OnCloseRequest() override;
- void OnClosed() override;
- void OnWindowStateChanged(ui::PlatformWindowState new_state) override;
- void OnLostCapture() override;
- void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
- float device_scale_factor) override;
- void OnAcceleratedWidgetDestroying() override;
- void OnAcceleratedWidgetDestroyed() override;
- void OnActivationChanged(bool active) override;
-
- ServerWindow* root_window_;
-
- std::unique_ptr<ThreadedImageCursors> image_cursors_;
-
- PlatformDisplayDelegate* delegate_ = nullptr;
- std::unique_ptr<FrameGenerator> frame_generator_;
-
- display::ViewportMetrics metrics_;
- std::unique_ptr<ui::PlatformWindow> platform_window_;
- gfx::AcceleratedWidget widget_;
-
- DISALLOW_COPY_AND_ASSIGN(PlatformDisplayDefault);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_PLATFORM_DISPLAY_DEFAULT_H_
diff --git a/services/ui/ws/platform_display_default_unittest.cc b/services/ui/ws/platform_display_default_unittest.cc
deleted file mode 100644
index 04bac1c..0000000
--- a/services/ui/ws/platform_display_default_unittest.cc
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/platform_display_default.h"
-
-#include "base/message_loop/message_loop.h"
-#include "base/time/time.h"
-#include "services/ui/common/image_cursors_set.h"
-#include "services/ui/ws/threaded_image_cursors.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/display/types/native_display_delegate.h"
-#include "ui/events/event.h"
-#include "ui/events/event_sink.h"
-#include "ui/events/system_input_injector.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/ozone/public/cursor_factory_ozone.h"
-#include "ui/ozone/public/ozone_platform.h"
-#include "ui/platform_window/platform_window.h"
-#include "ui/platform_window/stub/stub_window.h"
-
-namespace ui {
-namespace ws {
-namespace {
-
-// An EventSink that records events sent to it.
-class TestEventSink : public EventSink {
- public:
- TestEventSink() { Reset(); }
- ~TestEventSink() override = default;
-
- void Reset() {
- count_ = 0;
- last_event_type_ = ET_UNKNOWN;
- }
-
- // EventSink:
- EventDispatchDetails OnEventFromSource(Event* event) override {
- count_++;
- last_event_type_ = event->type();
- return EventDispatchDetails();
- }
-
- int count_;
- EventType last_event_type_;
-};
-
-// A PlatformDisplayDelegate to connect the PlatformDisplay to a TestEventSink.
-class TestPlatformDisplayDelegate : public PlatformDisplayDelegate {
- public:
- explicit TestPlatformDisplayDelegate(TestEventSink* sink) : sink_(sink) {}
- ~TestPlatformDisplayDelegate() override = default;
-
- // PlatformDisplayDelegate:
- const display::Display& GetDisplay() override { return stub_display_; }
- ServerWindow* GetRootWindow() override { return nullptr; }
- EventSink* GetEventSink() override { return sink_; }
- void OnAcceleratedWidgetAvailable() override {}
- void OnNativeCaptureLost() override {}
- bool IsHostingViz() const override { return true; }
-
- private:
- TestEventSink* sink_;
- display::Display stub_display_;
-
- DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplayDelegate);
-};
-
-TEST(PlatformDisplayDefaultTest, EventDispatch) {
- // ThreadTaskRunnerHandle needed required by ThreadedImageCursors.
- base::MessageLoop loop;
-
- // Create the display.
- display::ViewportMetrics metrics;
- metrics.bounds_in_pixels = gfx::Rect(1024, 768);
- metrics.device_scale_factor = 1.f;
- metrics.ui_scale_factor = 1.f;
- scoped_refptr<base::SingleThreadTaskRunner> task_runner =
- base::ThreadTaskRunnerHandle::Get();
- ImageCursorsSet image_cursors_set;
- CursorFactoryOzone cursor_factory_ozone;
- std::unique_ptr<ThreadedImageCursors> threaded_image_cursors =
- std::make_unique<ThreadedImageCursors>(task_runner,
- image_cursors_set.GetWeakPtr());
- PlatformDisplayDefault display(nullptr, metrics,
- std::move(threaded_image_cursors));
-
- // Initialize the display with a test EventSink so we can sense events.
- TestEventSink event_sink;
- TestPlatformDisplayDelegate delegate(&event_sink);
- // kInvalidDisplayId causes the display to be initialized with a StubWindow.
- EXPECT_EQ(display::kInvalidDisplayId, delegate.GetDisplay().id());
- display.Init(&delegate);
-
- // Event dispatch is handled at the PlatformWindowDelegate level.
- PlatformWindowDelegate* display_for_dispatch =
- static_cast<PlatformWindowDelegate*>(&display);
-
- // Mouse events are converted to pointer events.
- MouseEvent mouse(ET_MOUSE_PRESSED, gfx::Point(1, 2), gfx::Point(1, 2),
- base::TimeTicks(), EF_NONE, 0);
- display_for_dispatch->DispatchEvent(&mouse);
- EXPECT_EQ(ET_POINTER_DOWN, event_sink.last_event_type_);
- event_sink.Reset();
-
- // Touch events are converted to pointer events.
- TouchEvent touch(ET_TOUCH_PRESSED, gfx::Point(3, 4), base::TimeTicks(),
- PointerDetails(EventPointerType::POINTER_TYPE_TOUCH, 0));
- display_for_dispatch->DispatchEvent(&touch);
- EXPECT_EQ(ET_POINTER_DOWN, event_sink.last_event_type_);
- event_sink.Reset();
-
- // Pressing a key dispatches exactly one event.
- KeyEvent key_pressed(ET_KEY_PRESSED, VKEY_A, EF_NONE);
- display_for_dispatch->DispatchEvent(&key_pressed);
- EXPECT_EQ(1, event_sink.count_);
- EXPECT_EQ(ET_KEY_PRESSED, event_sink.last_event_type_);
- event_sink.Reset();
-
- // Releasing the key dispatches exactly one event.
- KeyEvent key_released(ET_KEY_RELEASED, VKEY_A, EF_NONE);
- display_for_dispatch->DispatchEvent(&key_released);
- EXPECT_EQ(1, event_sink.count_);
- EXPECT_EQ(ET_KEY_RELEASED, event_sink.last_event_type_);
-}
-
-} // namespace
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/platform_display_delegate.h b/services/ui/ws/platform_display_delegate.h
deleted file mode 100644
index 41bbb95..0000000
--- a/services/ui/ws/platform_display_delegate.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_PLATFORM_DISPLAY_DELEGATE_H_
-#define SERVICES_UI_WS_PLATFORM_DISPLAY_DELEGATE_H_
-
-namespace display {
-class Display;
-}
-
-namespace ui {
-
-class EventSink;
-
-namespace ws {
-
-class ServerWindow;
-
-// PlatformDisplayDelegate is implemented by an object that manages the
-// lifetime of a PlatformDisplay, forwards events to the appropriate windows,
-/// and responses to changes in viewport size.
-class PlatformDisplayDelegate {
- public:
- // Returns a display::Display for this display.
- virtual const display::Display& GetDisplay() = 0;
-
- // Returns the root window of this display.
- virtual ServerWindow* GetRootWindow() = 0;
-
- // Returns the event sink of this display;
- virtual EventSink* GetEventSink() = 0;
-
- // Called once when the AcceleratedWidget is available for drawing.
- virtual void OnAcceleratedWidgetAvailable() = 0;
-
- // Called when the Display loses capture.
- virtual void OnNativeCaptureLost() = 0;
-
- virtual bool IsHostingViz() const = 0;
-
- protected:
- virtual ~PlatformDisplayDelegate() {}
-};
-
-} // namespace ws
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_PLATFORM_DISPLAY_DELEGATE_H_
diff --git a/services/ui/ws/platform_display_factory.h b/services/ui/ws/platform_display_factory.h
deleted file mode 100644
index 99e17af..0000000
--- a/services/ui/ws/platform_display_factory.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_PLATFORM_DISPLAY_FACTORY_H_
-#define SERVICES_UI_WS_PLATFORM_DISPLAY_FACTORY_H_
-
-#include <memory>
-
-namespace display {
-struct ViewportMetrics;
-}
-
-namespace ui {
-namespace ws {
-
-class PlatformDisplay;
-class ServerWindow;
-
-// Abstract factory for PlatformDisplays. Used by tests to construct test
-// PlatformDisplays.
-class PlatformDisplayFactory {
- public:
- virtual std::unique_ptr<PlatformDisplay> CreatePlatformDisplay(
- ServerWindow* root_window,
- const display::ViewportMetrics& metrics) = 0;
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_PLATFORM_DISPLAY_FACTORY_H_
diff --git a/services/ui/ws/platform_display_mirror.cc b/services/ui/ws/platform_display_mirror.cc
deleted file mode 100644
index ef8bf65..0000000
--- a/services/ui/ws/platform_display_mirror.cc
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/platform_display_mirror.h"
-
-#include "components/viz/common/surfaces/surface_id.h"
-#include "components/viz/common/surfaces/surface_info.h"
-#include "components/viz/host/renderer_settings_creation.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/frame_generator.h"
-#include "services/ui/ws/window_server.h"
-#include "ui/platform_window/platform_window.h"
-
-namespace ui {
-namespace ws {
-
-PlatformDisplayMirror::PlatformDisplayMirror(
- const display::Display& display,
- const display::ViewportMetrics& metrics,
- WindowServer* window_server,
- Display* display_to_mirror)
- : display_(display),
- metrics_(metrics),
- window_server_(window_server),
- display_to_mirror_(display_to_mirror) {
- DCHECK(display_to_mirror_);
- frame_sink_id_ = window_server->display_manager()->GetAndAdvanceNextRootId();
-
- // Create a new platform window to display the mirror destination content.
- platform_window_ = CreatePlatformWindow(this, metrics_.bounds_in_pixels);
- platform_window_->Show();
-}
-
-PlatformDisplayMirror::~PlatformDisplayMirror() = default;
-
-void PlatformDisplayMirror::Init(PlatformDisplayDelegate* delegate) {}
-
-void PlatformDisplayMirror::SetViewportSize(const gfx::Size& size) {}
-
-void PlatformDisplayMirror::SetTitle(const base::string16& title) {}
-
-void PlatformDisplayMirror::SetCapture() {}
-
-void PlatformDisplayMirror::ReleaseCapture() {}
-
-void PlatformDisplayMirror::SetCursor(const ui::CursorData& cursor) {}
-
-void PlatformDisplayMirror::MoveCursorTo(
- const gfx::Point& window_pixel_location) {}
-
-void PlatformDisplayMirror::SetCursorSize(const ui::CursorSize& cursor_size) {}
-
-void PlatformDisplayMirror::ConfineCursorToBounds(
- const gfx::Rect& pixel_bounds) {}
-
-void PlatformDisplayMirror::UpdateTextInputState(
- const ui::TextInputState& state) {}
-
-void PlatformDisplayMirror::SetImeVisibility(bool visible) {}
-
-void PlatformDisplayMirror::UpdateViewportMetrics(
- const display::ViewportMetrics& metrics) {
- metrics_ = metrics;
-}
-
-const display::ViewportMetrics& PlatformDisplayMirror::GetViewportMetrics() {
- return metrics_;
-}
-
-gfx::AcceleratedWidget PlatformDisplayMirror::GetAcceleratedWidget() const {
- return widget_;
-}
-
-FrameGenerator* PlatformDisplayMirror::GetFrameGenerator() {
- return frame_generator_.get();
-}
-
-EventSink* PlatformDisplayMirror::GetEventSink() {
- return nullptr;
-}
-
-void PlatformDisplayMirror::SetCursorConfig(display::Display::Rotation rotation,
- float scale) {}
-
-void PlatformDisplayMirror::OnBoundsChanged(const gfx::Rect& new_bounds) {}
-
-void PlatformDisplayMirror::OnDamageRect(const gfx::Rect& damaged_region) {}
-
-void PlatformDisplayMirror::DispatchEvent(ui::Event* event) {}
-
-void PlatformDisplayMirror::OnCloseRequest() {}
-
-void PlatformDisplayMirror::OnClosed() {}
-
-void PlatformDisplayMirror::OnWindowStateChanged(
- ui::PlatformWindowState new_state) {}
-
-void PlatformDisplayMirror::OnLostCapture() {}
-
-void PlatformDisplayMirror::OnAcceleratedWidgetAvailable(
- gfx::AcceleratedWidget widget,
- float device_scale_factor) {
- DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_);
- widget_ = widget;
-
- // Create a CompositorFrameSink for this display, using the widget's surface.
- viz::mojom::CompositorFrameSinkAssociatedPtr compositor_frame_sink;
- viz::mojom::CompositorFrameSinkClientPtr compositor_frame_sink_client;
- viz::mojom::CompositorFrameSinkClientRequest
- compositor_frame_sink_client_request =
- mojo::MakeRequest(&compositor_frame_sink_client);
- window_server_->GetVizHostProxy()->RegisterFrameSinkId(frame_sink_id_, this);
-
- // TODO(ccameron): Bind |display_client| to support macOS? (maybe not needed)
- viz::mojom::DisplayPrivateAssociatedPtr display_private;
- viz::mojom::DisplayClientPtr display_client;
- viz::mojom::DisplayClientRequest display_client_request =
- mojo::MakeRequest(&display_client);
-
- auto params = viz::mojom::RootCompositorFrameSinkParams::New();
- params->frame_sink_id = frame_sink_id_;
- params->widget = widget_;
- params->renderer_settings = viz::CreateRendererSettings();
- params->compositor_frame_sink = mojo::MakeRequest(&compositor_frame_sink);
- params->compositor_frame_sink_client =
- compositor_frame_sink_client.PassInterface();
- params->display_private = mojo::MakeRequest(&display_private);
- params->display_client = display_client.PassInterface();
- window_server_->GetVizHostProxy()->CreateRootCompositorFrameSink(
- std::move(params));
-
- // Make a FrameGenerator that references |display_to_mirror_|'s surface id.
- display_private->SetDisplayVisible(true);
- frame_generator_ = std::make_unique<FrameGenerator>();
- auto frame_sink_client_binding =
- std::make_unique<CompositorFrameSinkClientBinding>(
- frame_generator_.get(),
- std::move(compositor_frame_sink_client_request),
- std::move(compositor_frame_sink));
- frame_generator_->Bind(std::move(frame_sink_client_binding),
- std::move(display_private));
-
- frame_generator_->OnWindowSizeChanged(metrics_.bounds_in_pixels.size());
- frame_generator_->SetDeviceScaleFactor(metrics_.device_scale_factor);
- frame_generator_->set_scale_and_center(true);
-
- // Pass the surface info for the mirror source display to the frame generator,
- // the id is not available if the source display init is not yet complete.
- const viz::SurfaceInfo& info = display_to_mirror_->platform_display()
- ->GetFrameGenerator()
- ->window_manager_surface_info();
- if (info.id().is_valid())
- frame_generator_->SetEmbeddedSurface(info);
-}
-
-void PlatformDisplayMirror::OnAcceleratedWidgetDestroying() {}
-
-void PlatformDisplayMirror::OnAcceleratedWidgetDestroyed() {}
-
-void PlatformDisplayMirror::OnActivationChanged(bool active) {}
-
-void PlatformDisplayMirror::OnFirstSurfaceActivation(
- const viz::SurfaceInfo& surface_info) {}
-
-void PlatformDisplayMirror::OnFrameTokenChanged(uint32_t frame_token) {}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/platform_display_mirror.h b/services/ui/ws/platform_display_mirror.h
deleted file mode 100644
index 7cc712b..0000000
--- a/services/ui/ws/platform_display_mirror.h
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_PLATFORM_DISPLAY_MIRROR_H_
-#define SERVICES_UI_WS_PLATFORM_DISPLAY_MIRROR_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "components/viz/common/surfaces/frame_sink_id.h"
-#include "components/viz/host/host_frame_sink_client.h"
-#include "services/ui/ws/platform_display.h"
-#include "ui/display/display.h"
-#include "ui/platform_window/platform_window.h"
-#include "ui/platform_window/platform_window_delegate.h"
-
-namespace ui {
-namespace ws {
-
-class Display;
-class WindowServer;
-
-// PlatformDisplay implementation that mirrors another display.
-class PlatformDisplayMirror : public PlatformDisplay,
- public ui::PlatformWindowDelegate,
- public viz::HostFrameSinkClient {
- public:
- PlatformDisplayMirror(const display::Display& display,
- const display::ViewportMetrics& metrics,
- WindowServer* window_server,
- Display* display_to_mirror);
- ~PlatformDisplayMirror() override;
-
- const display::Display& display() const { return display_; }
- void set_display(const display::Display& display) { display_ = display; }
-
- Display* display_to_mirror() const { return display_to_mirror_; }
-
- // PlatformDisplay:
- void Init(PlatformDisplayDelegate* delegate) override;
- void SetViewportSize(const gfx::Size& size) override;
- void SetTitle(const base::string16& title) override;
- void SetCapture() override;
- void ReleaseCapture() override;
- void SetCursor(const ui::CursorData& cursor) override;
- void MoveCursorTo(const gfx::Point& window_pixel_location) override;
- void SetCursorSize(const ui::CursorSize& cursor_size) override;
- void ConfineCursorToBounds(const gfx::Rect& pixel_bounds) override;
- void UpdateTextInputState(const ui::TextInputState& state) override;
- void SetImeVisibility(bool visible) override;
- void UpdateViewportMetrics(const display::ViewportMetrics& metrics) override;
- const display::ViewportMetrics& GetViewportMetrics() override;
- gfx::AcceleratedWidget GetAcceleratedWidget() const override;
- FrameGenerator* GetFrameGenerator() override;
- EventSink* GetEventSink() override;
- void SetCursorConfig(display::Display::Rotation rotation,
- float scale) override;
-
- // ui::PlatformWindowDelegate:
- void OnBoundsChanged(const gfx::Rect& new_bounds) override;
- void OnDamageRect(const gfx::Rect& damaged_region) override;
- void DispatchEvent(ui::Event* event) override;
- void OnCloseRequest() override;
- void OnClosed() override;
- void OnWindowStateChanged(ui::PlatformWindowState new_state) override;
- void OnLostCapture() override;
- void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
- float device_scale_factor) override;
- void OnAcceleratedWidgetDestroying() override;
- void OnAcceleratedWidgetDestroyed() override;
- void OnActivationChanged(bool active) override;
-
- // viz::HostFrameSinkClient:
- void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override;
- void OnFrameTokenChanged(uint32_t frame_token) override;
-
- private:
- // The basic info and metrics about this mirroring destination display.
- display::Display display_;
- display::ViewportMetrics metrics_;
-
- // The WindowServer that owns this object, via DisplayManager.
- WindowServer* window_server_;
-
- // The source ws::Display that this display mirrors.
- Display* display_to_mirror_;
-
- // The frame sink id assigned to this display.
- viz::FrameSinkId frame_sink_id_;
-
- // The window in the underlying platform windowing system (i.e. Wayland/X11).
- std::unique_ptr<ui::PlatformWindow> platform_window_;
-
- // The accelerated widget that provides a surface to paint pixels.
- gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
-
- // The generator that submits frames copied from the source display's surface
- // to this destination display's frame sink.
- std::unique_ptr<FrameGenerator> frame_generator_;
-
- DISALLOW_COPY_AND_ASSIGN(PlatformDisplayMirror);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_PLATFORM_DISPLAY_MIRROR_H_
diff --git a/services/ui/ws/server_window.cc b/services/ui/ws/server_window.cc
deleted file mode 100644
index 35c7a20d..0000000
--- a/services/ui/ws/server_window.cc
+++ /dev/null
@@ -1,500 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/server_window.h"
-
-#include <inttypes.h>
-#include <stddef.h>
-
-#include "base/strings/stringprintf.h"
-#include "components/viz/host/host_frame_sink_manager.h"
-#include "components/viz/host/renderer_settings_creation.h"
-#include "services/ui/public/interfaces/window_manager.mojom.h"
-#include "services/ui/ws/server_window_delegate.h"
-#include "services/ui/ws/server_window_observer.h"
-#include "services/ui/ws/server_window_tracker.h"
-#include "ui/base/cursor/cursor.h"
-
-namespace ui {
-namespace ws {
-
-ServerWindow::ServerWindow(ServerWindowDelegate* delegate,
- const viz::FrameSinkId& frame_sink_id,
- const Properties& properties)
- : delegate_(delegate),
- owning_tree_id_(frame_sink_id.client_id()),
- // Default to kPointer as kNull doesn't change the cursor, it leaves
- // the last non-null cursor.
- cursor_(ui::CursorType::kPointer),
- non_client_cursor_(ui::CursorType::kPointer),
- properties_(properties),
- // Don't notify newly added observers during notification. This causes
- // problems for code that adds an observer as part of an observer
- // notification (such as ServerWindowDrawTracker).
- observers_(base::ObserverListPolicy::EXISTING_ONLY) {
- DCHECK(delegate); // Must provide a delegate.
- UpdateFrameSinkId(frame_sink_id);
-}
-
-ServerWindow::~ServerWindow() {
- for (auto& observer : observers_)
- observer.OnWindowDestroying(this);
-
- if (transient_parent_)
- transient_parent_->RemoveTransientWindow(this);
-
- // Destroy transient children, only after we've removed ourselves from our
- // parent, as destroying an active transient child may otherwise attempt to
- // refocus us.
- Windows transient_children(transient_children_);
- for (auto* window : transient_children)
- delete window;
- DCHECK(transient_children_.empty());
-
- while (!children_.empty())
- children_.front()->parent()->Remove(children_.front());
-
- if (parent_)
- parent_->Remove(this);
-
- for (auto& observer : observers_)
- observer.OnWindowDestroyed(this);
-
- auto* host_frame_sink_manager = delegate_->GetVizHostProxy();
- if (host_frame_sink_manager)
- host_frame_sink_manager->InvalidateFrameSinkId(frame_sink_id_);
-}
-
-void ServerWindow::AddObserver(ServerWindowObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void ServerWindow::RemoveObserver(ServerWindowObserver* observer) {
- DCHECK(observers_.HasObserver(observer));
- observers_.RemoveObserver(observer);
-}
-
-bool ServerWindow::HasObserver(ServerWindowObserver* observer) {
- return observers_.HasObserver(observer);
-}
-
-void ServerWindow::CreateRootCompositorFrameSink(
- gfx::AcceleratedWidget widget,
- viz::mojom::CompositorFrameSinkAssociatedRequest sink_request,
- viz::mojom::CompositorFrameSinkClientPtr client,
- viz::mojom::DisplayPrivateAssociatedRequest display_request,
- viz::mojom::DisplayClientPtr display_client) {
- has_created_compositor_frame_sink_ = true;
- // TODO(fsamuel): AcceleratedWidget cannot be transported over IPC for Mac
- // or Android. We should instead use GpuSurfaceTracker here on those
- // platforms.
-
- auto params = viz::mojom::RootCompositorFrameSinkParams::New();
- params->frame_sink_id = frame_sink_id_;
- params->widget = widget;
- params->renderer_settings = viz::CreateRendererSettings();
- params->compositor_frame_sink = std::move(sink_request);
- params->compositor_frame_sink_client = client.PassInterface();
- params->display_private = std::move(display_request);
- params->display_client = display_client.PassInterface();
-
- delegate_->GetVizHostProxy()->CreateRootCompositorFrameSink(
- std::move(params));
-}
-
-void ServerWindow::CreateCompositorFrameSink(
- viz::mojom::CompositorFrameSinkRequest request,
- viz::mojom::CompositorFrameSinkClientPtr client) {
- has_created_compositor_frame_sink_ = true;
- delegate_->GetVizHostProxy()->CreateCompositorFrameSink(
- frame_sink_id_, std::move(request), std::move(client));
-}
-
-void ServerWindow::UpdateFrameSinkId(const viz::FrameSinkId& frame_sink_id) {
- DCHECK(frame_sink_id.is_valid());
- auto* host_frame_sink_manager = delegate_->GetVizHostProxy();
- DCHECK(host_frame_sink_manager);
- host_frame_sink_manager->RegisterFrameSinkId(frame_sink_id, this);
- host_frame_sink_manager->SetFrameSinkDebugLabel(frame_sink_id, GetName());
- if (frame_sink_id_.is_valid()) {
- if (parent()) {
- host_frame_sink_manager->UnregisterFrameSinkHierarchy(
- parent()->frame_sink_id(), frame_sink_id_);
- host_frame_sink_manager->RegisterFrameSinkHierarchy(
- parent()->frame_sink_id(), frame_sink_id);
- }
- host_frame_sink_manager->InvalidateFrameSinkId(frame_sink_id_);
- }
- frame_sink_id_ = frame_sink_id;
-}
-
-void ServerWindow::Add(ServerWindow* child) {
- // We assume validation checks happened already.
- DCHECK(child);
- DCHECK(child != this);
- DCHECK(!child->Contains(this));
- if (child->parent() == this) {
- if (children_.size() == 1)
- return; // Already in the right position.
- child->Reorder(children_.back(), mojom::OrderDirection::ABOVE);
- return;
- }
-
- ServerWindow* old_parent = child->parent();
- for (auto& observer : child->observers_)
- observer.OnWillChangeWindowHierarchy(child, this, old_parent);
-
- if (child->parent())
- child->parent()->RemoveImpl(child);
-
- child->parent_ = this;
- children_.push_back(child);
-
- for (auto& observer : child->observers_)
- observer.OnWindowHierarchyChanged(child, this, old_parent);
-}
-
-void ServerWindow::Remove(ServerWindow* child) {
- // We assume validation checks happened else where.
- DCHECK(child);
- DCHECK(child != this);
- DCHECK(child->parent() == this);
-
- for (auto& observer : child->observers_)
- observer.OnWillChangeWindowHierarchy(child, nullptr, this);
-
- RemoveImpl(child);
-
- for (auto& observer : child->observers_)
- observer.OnWindowHierarchyChanged(child, nullptr, this);
-}
-
-void ServerWindow::RemoveAllChildren() {
- while (!children_.empty())
- Remove(children_[0]);
-}
-
-void ServerWindow::Reorder(ServerWindow* relative,
- mojom::OrderDirection direction) {
- parent_->children_.erase(
- std::find(parent_->children_.begin(), parent_->children_.end(), this));
- Windows::iterator i =
- std::find(parent_->children_.begin(), parent_->children_.end(), relative);
- if (direction == mojom::OrderDirection::ABOVE) {
- DCHECK(i != parent_->children_.end());
- parent_->children_.insert(++i, this);
- } else if (direction == mojom::OrderDirection::BELOW) {
- DCHECK(i != parent_->children_.end());
- parent_->children_.insert(i, this);
- }
- for (auto& observer : observers_)
- observer.OnWindowReordered(this, relative, direction);
- OnStackingChanged();
-}
-
-void ServerWindow::StackChildAtBottom(ServerWindow* child) {
- // There's nothing to do if the child is already at the bottom.
- if (children_.size() <= 1 || child == children_.front())
- return;
- child->Reorder(children_.front(), mojom::OrderDirection::BELOW);
-}
-
-void ServerWindow::StackChildAtTop(ServerWindow* child) {
- // There's nothing to do if the child is already at the top.
- if (children_.size() <= 1 || child == children_.back())
- return;
- child->Reorder(children_.back(), mojom::OrderDirection::ABOVE);
-}
-
-void ServerWindow::SetBounds(
- const gfx::Rect& bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- if (bounds_ == bounds && current_local_surface_id_ == local_surface_id)
- return;
-
- const gfx::Rect old_bounds = bounds_;
-
- current_local_surface_id_ = local_surface_id;
-
- bounds_ = bounds;
- for (auto& observer : observers_)
- observer.OnWindowBoundsChanged(this, old_bounds, bounds);
-}
-
-void ServerWindow::SetClientArea(
- const gfx::Insets& insets,
- const std::vector<gfx::Rect>& additional_client_areas) {
- if (client_area_ == insets &&
- additional_client_areas == additional_client_areas_) {
- return;
- }
-
- additional_client_areas_ = additional_client_areas;
- client_area_ = insets;
- for (auto& observer : observers_)
- observer.OnWindowClientAreaChanged(this, insets, additional_client_areas);
-}
-
-void ServerWindow::SetHitTestMask(const gfx::Rect& mask) {
- hit_test_mask_ = std::make_unique<gfx::Rect>(mask);
-}
-
-void ServerWindow::ClearHitTestMask() {
- hit_test_mask_.reset();
-}
-
-void ServerWindow::SetCanAcceptDrops(bool accepts_drops) {
- accepts_drops_ = accepts_drops;
-}
-
-const ServerWindow* ServerWindow::GetRootForDrawn() const {
- return delegate_->GetRootWindowForDrawn(this);
-}
-
-bool ServerWindow::AddTransientWindow(ServerWindow* child) {
- if (child->transient_parent())
- child->transient_parent()->RemoveTransientWindow(child);
-
- DCHECK(std::find(transient_children_.begin(), transient_children_.end(),
- child) == transient_children_.end());
- transient_children_.push_back(child);
- child->transient_parent_ = this;
-
- for (auto& observer : observers_)
- observer.OnTransientWindowAdded(this, child);
- return true;
-}
-
-void ServerWindow::RemoveTransientWindow(ServerWindow* child) {
- Windows::iterator i =
- std::find(transient_children_.begin(), transient_children_.end(), child);
- DCHECK(i != transient_children_.end());
- transient_children_.erase(i);
- DCHECK_EQ(this, child->transient_parent());
- child->transient_parent_ = nullptr;
-
- for (auto& observer : observers_)
- observer.OnTransientWindowRemoved(this, child);
-}
-
-bool ServerWindow::HasTransientAncestor(const ServerWindow* window) const {
- const ServerWindow* transient_ancestor = this;
- while (transient_ancestor && transient_ancestor != window)
- transient_ancestor = transient_ancestor->transient_parent_;
- return transient_ancestor == window;
-}
-
-void ServerWindow::SetModalType(ModalType modal_type) {
- if (modal_type_ == modal_type)
- return;
-
- const ModalType old_modal_type = modal_type_;
- modal_type_ = modal_type;
- for (auto& observer : observers_)
- observer.OnWindowModalTypeChanged(this, old_modal_type);
-}
-
-void ServerWindow::SetChildModalParent(ServerWindow* modal_parent) {
- if (modal_parent) {
- child_modal_parent_tracker_ = std::make_unique<ServerWindowTracker>();
- child_modal_parent_tracker_->Add(modal_parent);
- } else {
- child_modal_parent_tracker_.reset();
- }
-}
-
-const ServerWindow* ServerWindow::GetChildModalParent() const {
- return child_modal_parent_tracker_ &&
- !child_modal_parent_tracker_->windows().empty()
- ? *child_modal_parent_tracker_->windows().begin()
- : nullptr;
-}
-
-bool ServerWindow::Contains(const ServerWindow* window) const {
- for (const ServerWindow* parent = window; parent; parent = parent->parent_) {
- if (parent == this)
- return true;
- }
- return false;
-}
-
-void ServerWindow::SetVisible(bool value) {
- if (visible_ == value)
- return;
-
- for (auto& observer : observers_)
- observer.OnWillChangeWindowVisibility(this);
- visible_ = value;
- for (auto& observer : observers_)
- observer.OnWindowVisibilityChanged(this);
-}
-
-void ServerWindow::SetOpacity(float value) {
- if (value == opacity_)
- return;
- float old_opacity = opacity_;
- opacity_ = value;
- for (auto& observer : observers_)
- observer.OnWindowOpacityChanged(this, old_opacity, opacity_);
-}
-
-void ServerWindow::SetCursor(ui::CursorData value) {
- if (cursor_.IsSameAs(value))
- return;
- cursor_ = std::move(value);
- for (auto& observer : observers_)
- observer.OnWindowCursorChanged(this, cursor_);
-}
-
-void ServerWindow::SetNonClientCursor(ui::CursorData value) {
- if (non_client_cursor_.IsSameAs(value))
- return;
- non_client_cursor_ = std::move(value);
- for (auto& observer : observers_)
- observer.OnWindowNonClientCursorChanged(this, non_client_cursor_);
-}
-
-void ServerWindow::SetTransform(const gfx::Transform& transform) {
- if (transform_ == transform)
- return;
-
- const gfx::Transform old_transform = transform_;
- transform_ = transform;
- for (auto& observer : observers_)
- observer.OnWindowTransformChanged(this, old_transform, transform);
-}
-
-void ServerWindow::SetProperty(const std::string& name,
- const std::vector<uint8_t>* value) {
- auto it = properties_.find(name);
- if (it != properties_.end()) {
- if (value && it->second == *value)
- return;
- } else if (!value) {
- // This property isn't set in |properties_| and |value| is nullptr, so
- // there's
- // no change.
- return;
- }
-
- if (value) {
- properties_[name] = *value;
- } else if (it != properties_.end()) {
- properties_.erase(it);
- }
- auto* host_frame_sink_manager = delegate_->GetVizHostProxy();
- if (host_frame_sink_manager && name == mojom::WindowManager::kName_Property)
- host_frame_sink_manager->SetFrameSinkDebugLabel(frame_sink_id_, GetName());
-
- for (auto& observer : observers_)
- observer.OnWindowSharedPropertyChanged(this, name, value);
-}
-
-std::string ServerWindow::GetName() const {
- auto it = properties_.find(mojom::WindowManager::kName_Property);
- if (it == properties_.end())
- return std::string();
- return std::string(it->second.begin(), it->second.end());
-}
-
-void ServerWindow::SetTextInputState(const ui::TextInputState& state) {
- const bool changed = !(text_input_state_ == state);
- if (changed) {
- text_input_state_ = state;
- // keyboard even if the state is not changed. So we have to notify
- // |observers_|.
- for (auto& observer : observers_)
- observer.OnWindowTextInputStateChanged(this, state);
- }
-}
-
-bool ServerWindow::IsDrawn() const {
- const ServerWindow* root = delegate_->GetRootWindowForDrawn(this);
- if (!root || !root->visible())
- return false;
- const ServerWindow* window = this;
- while (window && window != root && window->visible())
- window = window->parent();
- return root == window;
-}
-
-mojom::ShowState ServerWindow::GetShowState() const {
- auto iter = properties_.find(mojom::WindowManager::kShowState_Property);
- if (iter == properties_.end() || iter->second.empty())
- return mojom::ShowState::DEFAULT;
-
- return static_cast<mojom::ShowState>(iter->second[0]);
-}
-
-void ServerWindow::SetUnderlayOffset(const gfx::Vector2d& offset) {
- if (offset == underlay_offset_)
- return;
-
- underlay_offset_ = offset;
-}
-
-void ServerWindow::OnEmbeddedAppDisconnected() {
- for (auto& observer : observers_)
- observer.OnWindowEmbeddedAppDisconnected(this);
-}
-
-#if DCHECK_IS_ON()
-std::string ServerWindow::GetDebugWindowHierarchy() const {
- std::string result;
- BuildDebugInfo(std::string(), &result);
- return result;
-}
-
-std::string ServerWindow::GetDebugWindowInfo() const {
- std::string name = GetName();
- if (name.empty())
- name = "(no name)";
-
- std::string frame_sink;
- if (has_created_compositor_frame_sink_)
- frame_sink = " [" + frame_sink_id_.ToString() + "]";
-
- return base::StringPrintf(
- "visible=%s bounds=%s name=%s%s", visible_ ? "true" : "false",
- bounds_.ToString().c_str(), name.c_str(), frame_sink.c_str());
-}
-
-void ServerWindow::BuildDebugInfo(const std::string& depth,
- std::string* result) const {
- *result +=
- base::StringPrintf("%s%s\n", depth.c_str(), GetDebugWindowInfo().c_str());
- for (const ServerWindow* child : children_)
- child->BuildDebugInfo(depth + " ", result);
-}
-#endif // DCHECK_IS_ON()
-
-void ServerWindow::OnFirstSurfaceActivation(
- const viz::SurfaceInfo& surface_info) {
- delegate_->OnFirstSurfaceActivation(surface_info, this);
-}
-
-void ServerWindow::OnFrameTokenChanged(uint32_t frame_token) {
- // TODO(yiyix, fsamuel): Implement frame token propagation for Mus. See
- // crbug.com/771331
-}
-
-void ServerWindow::RemoveImpl(ServerWindow* window) {
- window->parent_ = nullptr;
- children_.erase(std::find(children_.begin(), children_.end(), window));
-}
-
-void ServerWindow::OnStackingChanged() {
- if (stacking_target_) {
- Windows::const_iterator window_i = std::find(
- parent()->children().begin(), parent()->children().end(), this);
- DCHECK(window_i != parent()->children().end());
- if (window_i != parent()->children().begin() &&
- (*(window_i - 1) == stacking_target_)) {
- return;
- }
- }
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/server_window.h b/services/ui/ws/server_window.h
deleted file mode 100644
index 845c7ae1..0000000
--- a/services/ui/ws/server_window.h
+++ /dev/null
@@ -1,324 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_SERVER_WINDOW_H_
-#define SERVICES_UI_WS_SERVER_WINDOW_H_
-
-#include <stdint.h>
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/observer_list.h"
-#include "components/viz/common/surfaces/frame_sink_id.h"
-#include "components/viz/host/host_frame_sink_client.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/ui/ws/ids.h"
-#include "services/viz/privileged/interfaces/compositing/display_private.mojom.h"
-#include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom.h"
-#include "ui/base/window_tracker_template.h"
-#include "ui/gfx/geometry/insets.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/geometry/vector2d.h"
-#include "ui/gfx/native_widget_types.h"
-#include "ui/gfx/transform.h"
-#include "ui/platform_window/text_input_state.h"
-
-namespace ui {
-namespace ws {
-
-class ServerWindowDelegate;
-class ServerWindowObserver;
-
-// Server side representation of a window. Delegate is informed of interesting
-// events.
-//
-// It is assumed that all functions that mutate the tree have validated the
-// mutation is possible before hand. For example, Reorder() assumes the supplied
-// window is a child and not already in position.
-//
-// ServerWindows do not own their children. If you delete a window that has
-// children the children are implicitly removed. Similarly if a window has a
-// parent and the window is deleted the deleted window is implicitly removed
-// from the parent.
-class ServerWindow : public viz::HostFrameSinkClient {
- public:
- using Properties = std::map<std::string, std::vector<uint8_t>>;
- using Windows = std::vector<ServerWindow*>;
-
- // |frame_sink_id| needs to be an input here as we are creating frame_sink_id_
- // based on the ClientWindowId clients provided.
- ServerWindow(ServerWindowDelegate* delegate,
- const viz::FrameSinkId& frame_sink_id,
- const Properties& properties = Properties());
- ~ServerWindow() override;
-
- void AddObserver(ServerWindowObserver* observer);
- void RemoveObserver(ServerWindowObserver* observer);
- bool HasObserver(ServerWindowObserver* observer);
-
- // Creates a new CompositorFrameSink of the specified type, replacing the
- // existing.
- void CreateRootCompositorFrameSink(
- gfx::AcceleratedWidget widget,
- viz::mojom::CompositorFrameSinkAssociatedRequest sink_request,
- viz::mojom::CompositorFrameSinkClientPtr client,
- viz::mojom::DisplayPrivateAssociatedRequest display_request,
- viz::mojom::DisplayClientPtr display_client);
-
- void CreateCompositorFrameSink(
- viz::mojom::CompositorFrameSinkRequest request,
- viz::mojom::CompositorFrameSinkClientPtr client);
-
- // Id of the tree that owns and created this window.
- ClientSpecificId owning_tree_id() const { return owning_tree_id_; }
-
- const viz::FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
- void UpdateFrameSinkId(const viz::FrameSinkId& frame_sink_id);
-
- const base::Optional<viz::LocalSurfaceId>& current_local_surface_id() const {
- return current_local_surface_id_;
- }
-
- // Add the child to this window.
- void Add(ServerWindow* child);
-
- // Removes the child window, but does not delete it.
- void Remove(ServerWindow* child);
-
- // Removes all child windows from this window, but does not delete them.
- void RemoveAllChildren();
-
- void Reorder(ServerWindow* relative, mojom::OrderDirection diretion);
- void StackChildAtBottom(ServerWindow* child);
- void StackChildAtTop(ServerWindow* child);
-
- const gfx::Rect& bounds() const { return bounds_; }
- // Sets the bounds. If the size changes this implicitly resets the client
- // area to fill the whole bounds.
- void SetBounds(const gfx::Rect& bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id =
- base::nullopt);
-
- const std::vector<gfx::Rect>& additional_client_areas() const {
- return additional_client_areas_;
- }
- const gfx::Insets& client_area() const { return client_area_; }
- void SetClientArea(const gfx::Insets& insets,
- const std::vector<gfx::Rect>& additional_client_areas);
-
- const gfx::Rect* hit_test_mask() const { return hit_test_mask_.get(); }
- void SetHitTestMask(const gfx::Rect& mask);
- void ClearHitTestMask();
-
- bool can_accept_drops() const { return accepts_drops_; }
- void SetCanAcceptDrops(bool accepts_drags);
-
- const ui::CursorData& cursor() const { return cursor_; }
- const ui::CursorData& non_client_cursor() const { return non_client_cursor_; }
-
- const ServerWindow* parent() const { return parent_; }
- ServerWindow* parent() { return parent_; }
-
- // Returns the root window used in checking drawn status. This is not
- // necessarily the same as the root window used in event dispatch.
- // NOTE: this returns null if the window does not have an ancestor associated
- // with a display.
- const ServerWindow* GetRootForDrawn() const;
- ServerWindow* GetRootForDrawn() {
- return const_cast<ServerWindow*>(
- const_cast<const ServerWindow*>(this)->GetRootForDrawn());
- }
-
- const Windows& children() const { return children_; }
-
- // Transient window management.
- // Adding transient child fails if the child window is modal to system.
- bool AddTransientWindow(ServerWindow* child);
- void RemoveTransientWindow(ServerWindow* child);
-
- ServerWindow* transient_parent() { return transient_parent_; }
- const ServerWindow* transient_parent() const { return transient_parent_; }
-
- const Windows& transient_children() const { return transient_children_; }
-
- // Returns true if |this| is a transient descendant of |window|.
- bool HasTransientAncestor(const ServerWindow* window) const;
-
- ModalType modal_type() const { return modal_type_; }
- void SetModalType(ModalType modal_type);
-
- void SetChildModalParent(ServerWindow* modal_parent);
- const ServerWindow* GetChildModalParent() const;
- ServerWindow* GetChildModalParent() {
- return const_cast<ServerWindow*>(
- const_cast<const ServerWindow*>(this)->GetChildModalParent());
- }
-
- // Returns true if this contains |window| or is |window|.
- bool Contains(const ServerWindow* window) const;
-
- // Returns the visibility requested by this window. IsDrawn() returns whether
- // the window is actually visible on screen.
- bool visible() const { return visible_; }
- void SetVisible(bool value);
-
- float opacity() const { return opacity_; }
- void SetOpacity(float value);
-
- void SetCursor(ui::CursorData cursor);
- void SetNonClientCursor(ui::CursorData cursor);
-
- const gfx::Transform& transform() const { return transform_; }
- void SetTransform(const gfx::Transform& transform);
-
- const std::map<std::string, std::vector<uint8_t>>& properties() const {
- return properties_;
- }
- void SetProperty(const std::string& name, const std::vector<uint8_t>* value);
-
- std::string GetName() const;
-
- void SetTextInputState(const ui::TextInputState& state);
- const ui::TextInputState& text_input_state() const {
- return text_input_state_;
- }
-
- void set_can_focus(bool can_focus) { can_focus_ = can_focus; }
- bool can_focus() const { return can_focus_; }
-
- void set_is_activation_parent(bool value) { is_activation_parent_ = value; }
- bool is_activation_parent() const { return is_activation_parent_; }
-
- bool has_created_compositor_frame_sink() const {
- return has_created_compositor_frame_sink_;
- }
-
- void set_event_targeting_policy(mojom::EventTargetingPolicy policy) {
- event_targeting_policy_ = policy;
- }
- mojom::EventTargetingPolicy event_targeting_policy() const {
- return event_targeting_policy_;
- }
-
- // Returns true if this window is attached to a root and all ancestors are
- // visible.
- bool IsDrawn() const;
-
- mojom::ShowState GetShowState() const;
-
- const gfx::Insets& extended_mouse_hit_test_region() const {
- return extended_mouse_hit_test_region_;
- }
- const gfx::Insets& extended_touch_hit_test_region() const {
- return extended_touch_hit_test_region_;
- }
- void set_extended_hit_test_regions_for_children(
- const gfx::Insets& mouse_insets,
- const gfx::Insets& touch_insets) {
- extended_mouse_hit_test_region_ = mouse_insets;
- extended_touch_hit_test_region_ = touch_insets;
- }
-
- // Offset of the underlay from the the window bounds (used for shadows).
- const gfx::Vector2d& underlay_offset() const { return underlay_offset_; }
- void SetUnderlayOffset(const gfx::Vector2d& offset);
-
- ServerWindowDelegate* delegate() { return delegate_; }
-
- // Called when the window is no longer an embed root.
- void OnEmbeddedAppDisconnected();
-
-#if DCHECK_IS_ON()
- std::string GetDebugWindowHierarchy() const;
- std::string GetDebugWindowInfo() const;
- void BuildDebugInfo(const std::string& depth, std::string* result) const;
-#endif
-
- private:
- // viz::HostFrameSinkClient implementation.
- void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override;
- void OnFrameTokenChanged(uint32_t frame_token) override;
-
- // Implementation of removing a window. Doesn't send any notification.
- void RemoveImpl(ServerWindow* window);
-
- // Called when this window's stacking order among its siblings is changed.
- void OnStackingChanged();
-
- ServerWindowDelegate* const delegate_;
- // This is the client id of the WindowTree that owns this window. This is
- // cached as the |frame_sink_id_| may change.
- const ClientSpecificId owning_tree_id_;
- // This may change for embed windows.
- viz::FrameSinkId frame_sink_id_;
- base::Optional<viz::LocalSurfaceId> current_local_surface_id_;
-
- ServerWindow* parent_ = nullptr;
- Windows children_;
-
- // Transient window management.
- // If non-null we're actively restacking transient as the result of a
- // transient ancestor changing.
- ServerWindow* stacking_target_ = nullptr;
- ServerWindow* transient_parent_ = nullptr;
- Windows transient_children_;
-
- ModalType modal_type_ = MODAL_TYPE_NONE;
- bool visible_ = false;
- gfx::Rect bounds_;
- gfx::Insets client_area_;
- std::vector<gfx::Rect> additional_client_areas_;
- ui::CursorData cursor_;
- ui::CursorData non_client_cursor_;
- float opacity_ = 1.0f;
- bool can_focus_ = true;
- mojom::EventTargetingPolicy event_targeting_policy_ =
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS;
- gfx::Transform transform_;
- ui::TextInputState text_input_state_;
-
- Properties properties_;
-
- gfx::Vector2d underlay_offset_;
-
- // The hit test for windows extends outside the bounds of the window by this
- // amount.
- gfx::Insets extended_mouse_hit_test_region_;
- gfx::Insets extended_touch_hit_test_region_;
-
- // Mouse events outside the hit test mask don't hit the window. An empty mask
- // means all events miss the window. If null there is no mask.
- std::unique_ptr<gfx::Rect> hit_test_mask_;
-
- // Whether this window can be the target in a drag and drop
- // operation. Clients must opt-in to this.
- bool accepts_drops_ = false;
-
- base::ObserverList<ServerWindowObserver> observers_;
-
- // Used to track the modal parent of a child modal window.
- std::unique_ptr<WindowTrackerTemplate<ServerWindow, ServerWindowObserver>>
- child_modal_parent_tracker_;
-
- // Whether the children of this window can be active. Also used to determine
- // when a window is considered top level. That is, if true the children of
- // this window are considered top level windows.
- bool is_activation_parent_ = false;
-
- // Used by tests to know whether clients have already drawn this window.
- bool has_created_compositor_frame_sink_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(ServerWindow);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_SERVER_WINDOW_H_
diff --git a/services/ui/ws/server_window_delegate.h b/services/ui/ws/server_window_delegate.h
deleted file mode 100644
index ad74d98c..0000000
--- a/services/ui/ws/server_window_delegate.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_SERVER_WINDOW_DELEGATE_H_
-#define SERVICES_UI_WS_SERVER_WINDOW_DELEGATE_H_
-
-#include <memory>
-
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/viz/privileged/interfaces/compositing/frame_sink_manager.mojom.h"
-
-namespace viz {
-class HitTestQuery;
-class HostFrameSinkClient;
-}
-
-namespace ui {
-
-namespace ws {
-
-class ServerWindow;
-
-// A proxy to communicate to the viz host (usually viz::HostFrameSinkManager).
-// If mus is hosting viz, then it forwards all the calls to the appropriate viz
-// host. If mus is not hosting viz, then it drops all calls. It is always safe
-// to call any method on this proxy. See documentation in
-// viz::HostFrameSinkManager for the documentation for the methods.
-class VizHostProxy {
- public:
- virtual ~VizHostProxy() {}
-
- virtual void RegisterFrameSinkId(const viz::FrameSinkId& frame_sink_id,
- viz::HostFrameSinkClient* client) = 0;
-
- virtual void SetFrameSinkDebugLabel(const viz::FrameSinkId& frame_sink_id,
- const std::string& name) = 0;
-
- virtual void InvalidateFrameSinkId(const viz::FrameSinkId& frame_sink_id) = 0;
-
- virtual void RegisterFrameSinkHierarchy(const viz::FrameSinkId& new_parent,
- const viz::FrameSinkId& child) = 0;
- virtual void UnregisterFrameSinkHierarchy(const viz::FrameSinkId& old_parent,
- const viz::FrameSinkId& child) = 0;
-
- virtual void CreateRootCompositorFrameSink(
- viz::mojom::RootCompositorFrameSinkParamsPtr params) = 0;
-
- virtual void CreateCompositorFrameSink(
- const viz::FrameSinkId& frame_sink_id,
- viz::mojom::CompositorFrameSinkRequest request,
- viz::mojom::CompositorFrameSinkClientPtr client) = 0;
-
- virtual viz::HitTestQuery* GetHitTestQuery(
- const viz::FrameSinkId& frame_sink_id) = 0;
-};
-
-class ServerWindowDelegate {
- public:
- // Returns a proxy to communicate to the viz host. This must always return
- // non-null.
- virtual VizHostProxy* GetVizHostProxy() = 0;
-
- // Returns the root of the window tree to which this |window| is attached.
- // Returns null if this window is not attached up through to a root window.
- // The returned root is used for drawn checks and may differ from that used
- // for event dispatch purposes.
- virtual ServerWindow* GetRootWindowForDrawn(const ServerWindow* window) = 0;
-
- // Called when a CompositorFrame with a new SurfaceId activates for the first
- // time for |window|.
- virtual void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info,
- ServerWindow* window) = 0;
-
- protected:
- virtual ~ServerWindowDelegate() {}
-};
-
-} // namespace ws
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_SERVER_WINDOW_DELEGATE_H_
diff --git a/services/ui/ws/server_window_drawn_tracker.cc b/services/ui/ws/server_window_drawn_tracker.cc
deleted file mode 100644
index 29d01c7..0000000
--- a/services/ui/ws/server_window_drawn_tracker.cc
+++ /dev/null
@@ -1,159 +0,0 @@
-// 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 "services/ui/ws/server_window_drawn_tracker.h"
-
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_drawn_tracker_observer.h"
-
-namespace ui {
-
-namespace ws {
-
-ServerWindowDrawnTracker::ServerWindowDrawnTracker(
- ServerWindow* window,
- ServerWindowDrawnTrackerObserver* observer)
- : window_(window),
- observer_(observer),
- drawn_(window->IsDrawn()),
- weak_factory_(this) {
- AddObservers();
-}
-
-ServerWindowDrawnTracker::~ServerWindowDrawnTracker() {
- RemoveObservers();
-}
-
-void ServerWindowDrawnTracker::SetDrawn(ServerWindow* ancestor, bool drawn) {
- // If |windows_| is empty when this code runs, that means |window_| has been
- // destroyed. So set |window_| to nullptr, but make sure the right value is
- // sent to OnDrawnStateChanged().
- ServerWindow* window = window_;
- if (windows_.empty())
- window_ = nullptr;
-
- if (drawn == drawn_)
- return;
-
- drawn_ = drawn;
- observer_->OnDrawnStateChanged(ancestor, window, drawn);
-}
-
-void ServerWindowDrawnTracker::AddObservers() {
- if (!window_) {
- root_ = nullptr;
- return;
- }
-
- ServerWindow* last = window_;
- for (ServerWindow* v = window_; v; v = v->parent()) {
- v->AddObserver(this);
- windows_.insert(v);
- last = v;
- }
- DCHECK(last);
- root_ = last;
-}
-
-void ServerWindowDrawnTracker::RemoveObservers() {
- for (ServerWindow* window : windows_)
- window->RemoveObserver(this);
-
- windows_.clear();
-}
-
-void ServerWindowDrawnTracker::OnWindowDestroying(ServerWindow* window) {
- if (!drawn_)
- return;
- observer_->OnDrawnStateWillChange(window->parent(), window_, false);
-}
-
-void ServerWindowDrawnTracker::OnWindowDestroyed(ServerWindow* window) {
- // As windows are removed before being destroyed, resulting in
- // OnWindowHierarchyChanged() and us removing ourself as an observer, the only
- // window we should ever get notified of destruction on is |window_|.
- DCHECK_EQ(window, window_);
- RemoveObservers();
- SetDrawn(nullptr, false);
-}
-
-void ServerWindowDrawnTracker::OnWillChangeWindowHierarchy(
- ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) {
- bool new_is_drawn = new_parent && new_parent->IsDrawn();
- if (new_is_drawn) {
- for (ServerWindow* w = window_; new_is_drawn && w != old_parent;
- w = w->parent()) {
- new_is_drawn = w->visible();
- }
- }
- if (drawn_ != new_is_drawn) {
- auto ref = weak_factory_.GetWeakPtr();
- observer_->OnDrawnStateWillChange(new_is_drawn ? nullptr : old_parent,
- window_, new_is_drawn);
- // Allow for the |observer_| to delete |this|.
- if (!ref)
- return;
- }
-
- if (!root_->Contains(new_parent))
- observer_->OnRootWillChange(old_parent, window_);
-}
-
-void ServerWindowDrawnTracker::OnWindowHierarchyChanged(
- ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) {
- ServerWindow* old_root = root_;
- RemoveObservers();
- AddObservers();
- const bool is_drawn = window_->IsDrawn();
- auto ref = weak_factory_.GetWeakPtr();
- SetDrawn(is_drawn ? nullptr : old_parent, is_drawn);
- // Allow for the |observer_| to delete |this|.
- if (!ref)
- return;
- if (old_root != root_)
- observer_->OnRootDidChange(old_parent, window);
-}
-
-void ServerWindowDrawnTracker::OnWillChangeWindowVisibility(
- ServerWindow* window) {
- bool will_change = false;
- if (drawn_) {
- // If |window_| is currently drawn, then any change of visibility of the
- // windows will toggle the drawn status.
- will_change = true;
- } else {
- // If |window| is currently visible, then it's becoming invisible, and so
- // |window_| will remain not drawn.
- if (window->visible()) {
- will_change = false;
- } else {
- bool is_drawn = (window->GetRootForDrawn() == window) ||
- (window->parent() && window->parent()->IsDrawn());
- if (is_drawn) {
- for (ServerWindow* w = window_; is_drawn && w != window;
- w = w->parent())
- is_drawn = w->visible();
- }
- will_change = drawn_ != is_drawn;
- }
- }
- if (will_change) {
- bool new_is_drawn = !drawn_;
- observer_->OnDrawnStateWillChange(new_is_drawn ? nullptr : window->parent(),
- window_, new_is_drawn);
- }
-}
-
-void ServerWindowDrawnTracker::OnWindowVisibilityChanged(ServerWindow* window) {
- const bool is_drawn = window_->IsDrawn();
- SetDrawn(is_drawn ? nullptr : window->parent(), is_drawn);
-}
-
-} // namespace ws
-
-} // namespace ui
diff --git a/services/ui/ws/server_window_drawn_tracker.h b/services/ui/ws/server_window_drawn_tracker.h
deleted file mode 100644
index 9ae7d07..0000000
--- a/services/ui/ws/server_window_drawn_tracker.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_SERVER_WINDOW_DRAWN_TRACKER_H_
-#define SERVICES_UI_WS_SERVER_WINDOW_DRAWN_TRACKER_H_
-
-#include <set>
-
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "services/ui/ws/server_window_observer.h"
-
-namespace ui {
-
-namespace ws {
-
-class ServerWindowDrawnTrackerObserver;
-
-// ServerWindowDrawnTracker notifies its observer any time the drawn state of
-// the supplied window changes.
-//
-// NOTE: you must ensure this class is destroyed before the root.
-class ServerWindowDrawnTracker : public ServerWindowObserver {
- public:
- ServerWindowDrawnTracker(ServerWindow* window,
- ServerWindowDrawnTrackerObserver* observer);
- ~ServerWindowDrawnTracker() override;
-
- ServerWindow* window() { return window_; }
-
- private:
- void SetDrawn(ServerWindow* ancestor, bool drawn);
-
- // Adds |this| as an observer to |window_| and its ancestors.
- void AddObservers();
-
- // Stops observerving any windows we added as an observer in AddObservers().
- void RemoveObservers();
-
- // ServerWindowObserver:
- void OnWindowDestroying(ServerWindow* window) override;
- void OnWindowDestroyed(ServerWindow* window) override;
- void OnWillChangeWindowHierarchy(ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) override;
- void OnWindowHierarchyChanged(ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) override;
- void OnWillChangeWindowVisibility(ServerWindow* window) override;
- void OnWindowVisibilityChanged(ServerWindow* window) override;
-
- ServerWindow* root_ = nullptr;
- ServerWindow* window_;
- ServerWindowDrawnTrackerObserver* observer_;
- bool drawn_;
- // Set of windows we're observing. This is |window_| and all its ancestors.
- std::set<ServerWindow*> windows_;
-
- base::WeakPtrFactory<ServerWindowDrawnTracker> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(ServerWindowDrawnTracker);
-};
-
-} // namespace ws
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_SERVER_WINDOW_DRAWN_TRACKER_H_
diff --git a/services/ui/ws/server_window_drawn_tracker_observer.h b/services/ui/ws/server_window_drawn_tracker_observer.h
deleted file mode 100644
index 773a0de..0000000
--- a/services/ui/ws/server_window_drawn_tracker_observer.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_SERVER_WINDOW_DRAWN_TRACKER_OBSERVER_H_
-#define SERVICES_UI_WS_SERVER_WINDOW_DRAWN_TRACKER_OBSERVER_H_
-
-namespace ui {
-
-namespace ws {
-
-class ServerWindow;
-
-class ServerWindowDrawnTrackerObserver {
- public:
- // Invoked right before the drawn state changes. If |is_drawn| is false,
- // |ancestor| identifies where the change will occur. In the case of a remove,
- // |ancestor| is the parent of the window that will be removed (causing the
- // drawn state to change). In the case of visibility change, |ancestor| is the
- // parent of the window whose visibility will change.
- virtual void OnDrawnStateWillChange(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) {}
-
- // Invoked when the drawn state changes. If |is_drawn| is false |ancestor|
- // identifies where the change occurred. In the case of a remove |ancestor| is
- // the parent of the window that was removed. In the case of a visibility
- // change |ancestor| is the parent of the window whose visibility changed.
- virtual void OnDrawnStateChanged(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) {}
-
- // Invoked if the root will change as the result of a child of |ancestor|
- // being moved to a new root.
- virtual void OnRootWillChange(ServerWindow* ancestor, ServerWindow* window) {}
-
- // Invoked after the root changed. |ancestor| is the old ancestor that was the
- // old parent of the window (not necessarily |window|) that was moved.
- virtual void OnRootDidChange(ServerWindow* ancestor, ServerWindow* window) {}
-
- protected:
- virtual ~ServerWindowDrawnTrackerObserver() {}
-};
-
-} // namespace ws
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_SERVER_WINDOW_DRAWN_TRACKER_OBSERVER_H_
diff --git a/services/ui/ws/server_window_drawn_tracker_unittest.cc b/services/ui/ws/server_window_drawn_tracker_unittest.cc
deleted file mode 100644
index 290d8111..0000000
--- a/services/ui/ws/server_window_drawn_tracker_unittest.cc
+++ /dev/null
@@ -1,291 +0,0 @@
-// 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 "services/ui/ws/server_window_drawn_tracker.h"
-
-#include <stddef.h>
-
-#include "base/macros.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_drawn_tracker_observer.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-
-namespace ws {
-namespace {
-
-class TestServerWindowDrawnTrackerObserver
- : public ServerWindowDrawnTrackerObserver {
- public:
- TestServerWindowDrawnTrackerObserver() = default;
-
- void clear_change_count() {
- change_count_ = 0u;
- root_will_change_count_ = 0u;
- root_did_change_count_ = 0u;
- }
- size_t change_count() const { return change_count_; }
- const ServerWindow* ancestor() const { return ancestor_; }
- const ServerWindow* window() const { return window_; }
- bool is_drawn() const { return is_drawn_; }
- size_t root_will_change_count() const { return root_will_change_count_; }
- size_t root_did_change_count() const { return root_did_change_count_; }
-
- private:
- // ServerWindowDrawnTrackerObserver:
- void OnDrawnStateWillChange(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) override {
- change_count_++;
- ancestor_ = ancestor;
- window_ = window;
- is_drawn_ = is_drawn;
- }
-
- void OnDrawnStateChanged(ServerWindow* ancestor,
- ServerWindow* window,
- bool is_drawn) override {
- EXPECT_EQ(ancestor_, ancestor);
- EXPECT_EQ(window_, window);
- EXPECT_EQ(is_drawn_, is_drawn);
- }
- void OnRootWillChange(ServerWindow* ancestor, ServerWindow* window) override {
- root_will_change_count_++;
- }
- void OnRootDidChange(ServerWindow* ancestor, ServerWindow* window) override {
- root_did_change_count_++;
- }
-
- size_t change_count_ = 0u;
- size_t root_will_change_count_ = 0u;
- size_t root_did_change_count_ = 0u;
- const ServerWindow* ancestor_ = nullptr;
- const ServerWindow* window_ = nullptr;
- bool is_drawn_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(TestServerWindowDrawnTrackerObserver);
-};
-
-viz::FrameSinkId MakeFrameSinkId() {
- constexpr int client_id = 1;
- static int window_id = 0;
- return viz::FrameSinkId(client_id, ++window_id);
-}
-
-} // namespace
-
-class ServerWindowDrawnTrackerTest : public testing::Test {
- public:
- ServerWindowDrawnTrackerTest() {}
- ~ServerWindowDrawnTrackerTest() override {}
-
- VizHostProxy* viz_host_proxy() {
- return ws_test_helper_.window_server()->GetVizHostProxy();
- }
-
- private:
- test::WindowServerTestHelper ws_test_helper_;
-
- DISALLOW_COPY_AND_ASSIGN(ServerWindowDrawnTrackerTest);
-};
-
-TEST_F(ServerWindowDrawnTrackerTest, ChangeBecauseOfDeletionAndVisibility) {
- TestServerWindowDelegate server_window_delegate(viz_host_proxy());
- std::unique_ptr<ServerWindow> window(
- new ServerWindow(&server_window_delegate, MakeFrameSinkId()));
- server_window_delegate.set_root_window(window.get());
- TestServerWindowDrawnTrackerObserver drawn_observer;
- ServerWindowDrawnTracker tracker(window.get(), &drawn_observer);
- window->SetVisible(true);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(0u, drawn_observer.root_will_change_count());
- EXPECT_EQ(0u, drawn_observer.root_did_change_count());
- EXPECT_EQ(window.get(), drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_TRUE(drawn_observer.is_drawn());
- drawn_observer.clear_change_count();
-
- window->SetVisible(false);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(0u, drawn_observer.root_will_change_count());
- EXPECT_EQ(0u, drawn_observer.root_did_change_count());
- EXPECT_EQ(window.get(), drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_FALSE(drawn_observer.is_drawn());
- drawn_observer.clear_change_count();
-
- window->SetVisible(true);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(0u, drawn_observer.root_will_change_count());
- EXPECT_EQ(0u, drawn_observer.root_did_change_count());
- EXPECT_EQ(window.get(), drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_TRUE(drawn_observer.is_drawn());
- drawn_observer.clear_change_count();
-
- ServerWindow* old_window = window.get();
- window.reset();
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(0u, drawn_observer.root_will_change_count());
- EXPECT_EQ(0u, drawn_observer.root_did_change_count());
- EXPECT_EQ(old_window, drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_FALSE(drawn_observer.is_drawn());
-}
-
-TEST_F(ServerWindowDrawnTrackerTest, ChangeBecauseOfRemovingFromRoot) {
- TestServerWindowDelegate server_window_delegate(viz_host_proxy());
- ServerWindow root(&server_window_delegate, MakeFrameSinkId());
- server_window_delegate.set_root_window(&root);
- root.SetVisible(true);
- ServerWindow child(&server_window_delegate, MakeFrameSinkId());
- child.SetVisible(true);
- root.Add(&child);
-
- TestServerWindowDrawnTrackerObserver drawn_observer;
- ServerWindowDrawnTracker tracker(&child, &drawn_observer);
- root.Remove(&child);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(1u, drawn_observer.root_will_change_count());
- EXPECT_EQ(1u, drawn_observer.root_did_change_count());
- EXPECT_EQ(&child, drawn_observer.window());
- EXPECT_EQ(&root, drawn_observer.ancestor());
- EXPECT_FALSE(drawn_observer.is_drawn());
- drawn_observer.clear_change_count();
-
- root.Add(&child);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(1u, drawn_observer.root_will_change_count());
- EXPECT_EQ(1u, drawn_observer.root_did_change_count());
- EXPECT_EQ(&child, drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_TRUE(drawn_observer.is_drawn());
-}
-
-TEST_F(ServerWindowDrawnTrackerTest, ChangeBecauseOfRemovingAncestorFromRoot) {
- TestServerWindowDelegate server_window_delegate(viz_host_proxy());
- ServerWindow root(&server_window_delegate, MakeFrameSinkId());
- server_window_delegate.set_root_window(&root);
- root.SetVisible(true);
- ServerWindow child(&server_window_delegate, MakeFrameSinkId());
- child.SetVisible(true);
- root.Add(&child);
-
- ServerWindow child_child(&server_window_delegate, MakeFrameSinkId());
- child_child.SetVisible(true);
- child.Add(&child_child);
-
- TestServerWindowDrawnTrackerObserver drawn_observer;
- ServerWindowDrawnTracker tracker(&child_child, &drawn_observer);
- root.Remove(&child);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(1u, drawn_observer.root_will_change_count());
- EXPECT_EQ(1u, drawn_observer.root_did_change_count());
- EXPECT_EQ(&child_child, drawn_observer.window());
- EXPECT_EQ(&root, drawn_observer.ancestor());
- EXPECT_FALSE(drawn_observer.is_drawn());
- drawn_observer.clear_change_count();
-
- root.Add(&child_child);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(1u, drawn_observer.root_will_change_count());
- EXPECT_EQ(1u, drawn_observer.root_did_change_count());
- EXPECT_EQ(&child_child, drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_TRUE(drawn_observer.is_drawn());
-}
-
-TEST_F(ServerWindowDrawnTrackerTest, VisibilityChangeFromNonParentAncestor) {
- TestServerWindowDelegate server_window_delegate(viz_host_proxy());
- ServerWindow root(&server_window_delegate, MakeFrameSinkId());
- ServerWindow child1(&server_window_delegate, MakeFrameSinkId());
- ServerWindow child2(&server_window_delegate, MakeFrameSinkId());
- ServerWindow child3(&server_window_delegate, MakeFrameSinkId());
- server_window_delegate.set_root_window(&root);
-
- root.Add(&child1);
- child1.Add(&child2);
- child2.Add(&child3);
-
- root.SetVisible(true);
- child1.SetVisible(false);
- child2.SetVisible(false);
- child3.SetVisible(true);
-
- TestServerWindowDrawnTrackerObserver drawn_observer;
- ServerWindowDrawnTracker tracker(&child3, &drawn_observer);
-
- EXPECT_FALSE(child3.IsDrawn());
-
- // Make |child1| visible. |child3| should still be not drawn, since |child2|
- // is still invisible.
- child1.SetVisible(true);
- EXPECT_EQ(0u, drawn_observer.change_count());
- EXPECT_EQ(0u, drawn_observer.root_will_change_count());
- EXPECT_EQ(0u, drawn_observer.root_did_change_count());
- EXPECT_EQ(nullptr, drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_FALSE(drawn_observer.is_drawn());
- EXPECT_FALSE(child3.IsDrawn());
-
- child2.SetVisible(true);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(0u, drawn_observer.root_will_change_count());
- EXPECT_EQ(0u, drawn_observer.root_did_change_count());
- EXPECT_EQ(&child3, drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_TRUE(drawn_observer.is_drawn());
- EXPECT_TRUE(child3.IsDrawn());
-}
-
-TEST_F(ServerWindowDrawnTrackerTest, TreeHierarchyChangeFromNonParentAncestor) {
- TestServerWindowDelegate server_window_delegate(viz_host_proxy());
- ServerWindow root(&server_window_delegate, MakeFrameSinkId());
- ServerWindow child1(&server_window_delegate, MakeFrameSinkId());
- ServerWindow child2(&server_window_delegate, MakeFrameSinkId());
- ServerWindow child11(&server_window_delegate, MakeFrameSinkId());
- ServerWindow child111(&server_window_delegate, MakeFrameSinkId());
- server_window_delegate.set_root_window(&root);
-
- root.Add(&child1);
- root.Add(&child2);
- child1.Add(&child11);
- child11.Add(&child111);
-
- root.SetVisible(true);
- child1.SetVisible(false);
- child2.SetVisible(true);
- child11.SetVisible(false);
- child111.SetVisible(true);
-
- TestServerWindowDrawnTrackerObserver drawn_observer;
- ServerWindowDrawnTracker tracker(&child111, &drawn_observer);
- EXPECT_FALSE(child111.IsDrawn());
-
- // Move |child11| as a child of |child2|. |child111| should remain not drawn.
- child2.Add(&child11);
- EXPECT_EQ(0u, drawn_observer.change_count());
- EXPECT_EQ(0u, drawn_observer.root_will_change_count());
- EXPECT_EQ(0u, drawn_observer.root_did_change_count());
- EXPECT_EQ(nullptr, drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_FALSE(drawn_observer.is_drawn());
- EXPECT_FALSE(child111.IsDrawn());
-
- child11.SetVisible(true);
- EXPECT_EQ(1u, drawn_observer.change_count());
- EXPECT_EQ(0u, drawn_observer.root_will_change_count());
- EXPECT_EQ(0u, drawn_observer.root_did_change_count());
- EXPECT_EQ(&child111, drawn_observer.window());
- EXPECT_EQ(nullptr, drawn_observer.ancestor());
- EXPECT_TRUE(drawn_observer.is_drawn());
- EXPECT_TRUE(child111.IsDrawn());
-}
-
-} // namespace ws
-
-} // namespace ui
diff --git a/services/ui/ws/server_window_observer.h b/services/ui/ws/server_window_observer.h
deleted file mode 100644
index ac54498..0000000
--- a/services/ui/ws/server_window_observer.h
+++ /dev/null
@@ -1,108 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_SERVER_WINDOW_OBSERVER_H_
-#define SERVICES_UI_WS_SERVER_WINDOW_OBSERVER_H_
-
-#include <stdint.h>
-
-#include <string>
-#include <vector>
-
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "ui/base/ui_base_types.h"
-
-namespace gfx {
-class Insets;
-class Rect;
-class Transform;
-}
-
-namespace ui {
-
-struct TextInputState;
-
-namespace ws {
-
-class ServerWindow;
-
-// TODO(sky): rename to OnDid and OnWill everywhere.
-class ServerWindowObserver {
- public:
- // Invoked when a window is about to be destroyed; before any of the children
- // have been removed and before the window has been removed from its parent.
- virtual void OnWindowDestroying(ServerWindow* window) {}
-
- // Invoked at the end of the window's destructor (after it has been removed
- // from the hierarchy.
- virtual void OnWindowDestroyed(ServerWindow* window) {}
-
- virtual void OnWillChangeWindowHierarchy(ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) {}
-
- virtual void OnWindowHierarchyChanged(ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) {}
-
- virtual void OnWindowBoundsChanged(ServerWindow* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {}
-
- virtual void OnWindowTransformChanged(ServerWindow* window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform) {}
-
- virtual void OnWindowClientAreaChanged(
- ServerWindow* window,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas) {}
-
- virtual void OnWindowReordered(ServerWindow* window,
- ServerWindow* relative,
- mojom::OrderDirection direction) {}
-
- virtual void OnWillChangeWindowVisibility(ServerWindow* window) {}
- virtual void OnWindowVisibilityChanged(ServerWindow* window) {}
- virtual void OnWindowOpacityChanged(ServerWindow* window,
- float old_opacity,
- float new_opacity) {}
-
- virtual void OnWindowCursorChanged(ServerWindow* window,
- const ui::CursorData& cursor_data) {}
- virtual void OnWindowNonClientCursorChanged(
- ServerWindow* window,
- const ui::CursorData& cursor_data) {}
-
- virtual void OnWindowTextInputStateChanged(ServerWindow* window,
- const ui::TextInputState& state) {}
-
- virtual void OnWindowSharedPropertyChanged(
- ServerWindow* window,
- const std::string& name,
- const std::vector<uint8_t>* new_data) {}
-
- // Called when the window is no longer an embed root.
- virtual void OnWindowEmbeddedAppDisconnected(ServerWindow* window) {}
-
- // Called when a transient child is added to |window|.
- virtual void OnTransientWindowAdded(ServerWindow* window,
- ServerWindow* transient_child) {}
-
- // Called when a transient child is removed from |window|.
- virtual void OnTransientWindowRemoved(ServerWindow* window,
- ServerWindow* transient_child) {}
-
- virtual void OnWindowModalTypeChanged(ServerWindow* window,
- ModalType old_modal_type) {}
-
- protected:
- virtual ~ServerWindowObserver() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_SERVER_WINDOW_OBSERVER_H_
diff --git a/services/ui/ws/server_window_tracker.h b/services/ui/ws/server_window_tracker.h
deleted file mode 100644
index b611a72..0000000
--- a/services/ui/ws/server_window_tracker.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_SERVER_WINDOW_TRACKER_H_
-#define SERVICES_UI_WS_SERVER_WINDOW_TRACKER_H_
-
-#include <stdint.h>
-#include <set>
-
-#include "base/macros.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_observer.h"
-#include "ui/base/window_tracker_template.h"
-
-namespace ui {
-namespace ws {
-
-using ServerWindowTracker =
- ui::WindowTrackerTemplate<ServerWindow, ServerWindowObserver>;
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_SERVER_WINDOW_TRACKER_H_
diff --git a/services/ui/ws/test_change_tracker.cc b/services/ui/ws/test_change_tracker.cc
deleted file mode 100644
index 5d110d6..0000000
--- a/services/ui/ws/test_change_tracker.cc
+++ /dev/null
@@ -1,504 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/test_change_tracker.h"
-
-#include <stddef.h>
-
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
-#include "mojo/public/cpp/bindings/map.h"
-#include "services/ui/common/util.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/gfx/geometry/point_conversions.h"
-
-namespace ui {
-
-namespace ws {
-
-std::string WindowIdToString(Id id) {
- return (id == 0) ? "null"
- : base::StringPrintf("%d,%d", ClientIdFromTransportId(id),
- ClientWindowIdFromTransportId(id));
-}
-
-namespace {
-
-std::string DirectionToString(mojom::OrderDirection direction) {
- return direction == mojom::OrderDirection::ABOVE ? "above" : "below";
-}
-
-enum class ChangeDescriptionType {
- ONE,
- TWO,
- // Includes display id and location of events.
- THREE,
-};
-
-std::string ChangeToDescription(const Change& change,
- ChangeDescriptionType type) {
- switch (change.type) {
- case CHANGE_TYPE_EMBED:
- if (type == ChangeDescriptionType::ONE)
- return "OnEmbed";
- return base::StringPrintf("OnEmbed drawn=%s",
- change.bool_value ? "true" : "false");
-
- case CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED:
- return base::StringPrintf("OnEmbeddedAppDisconnected window=%s",
- WindowIdToString(change.window_id).c_str());
-
- case CHANGE_TYPE_UNEMBED:
- return base::StringPrintf("OnUnembed window=%s",
- WindowIdToString(change.window_id).c_str());
-
- case CHANGE_TYPE_CAPTURE_CHANGED:
- return base::StringPrintf("OnCaptureChanged new_window=%s old_window=%s",
- WindowIdToString(change.window_id).c_str(),
- WindowIdToString(change.window_id2).c_str());
-
- case CHANGE_TYPE_FRAME_SINK_ID_ALLOCATED:
- return base::StringPrintf("OnFrameSinkIdAllocated window=%s %s",
- WindowIdToString(change.window_id).c_str(),
- change.frame_sink_id.ToString().c_str());
-
- case CHANGE_TYPE_NODE_ADD_TRANSIENT_WINDOW:
- return base::StringPrintf("AddTransientWindow parent = %s child = %s",
- WindowIdToString(change.window_id).c_str(),
- WindowIdToString(change.window_id2).c_str());
-
- case CHANGE_TYPE_NODE_BOUNDS_CHANGED:
- return base::StringPrintf(
- "BoundsChanged window=%s old_bounds=%s new_bounds=%s "
- "local_surface_id=%s",
- WindowIdToString(change.window_id).c_str(),
- change.bounds.ToString().c_str(), change.bounds2.ToString().c_str(),
- change.local_surface_id ? change.local_surface_id->ToString().c_str()
- : "(none)");
-
- case CHANGE_TYPE_NODE_HIERARCHY_CHANGED:
- return base::StringPrintf(
- "HierarchyChanged window=%s old_parent=%s new_parent=%s",
- WindowIdToString(change.window_id).c_str(),
- WindowIdToString(change.window_id2).c_str(),
- WindowIdToString(change.window_id3).c_str());
-
- case CHANGE_TYPE_NODE_REMOVE_TRANSIENT_WINDOW_FROM_PARENT:
- return base::StringPrintf(
- "RemoveTransientWindowFromParent parent = %s child = %s",
- WindowIdToString(change.window_id).c_str(),
- WindowIdToString(change.window_id2).c_str());
-
- case CHANGE_TYPE_NODE_REORDERED:
- return base::StringPrintf("Reordered window=%s relative=%s direction=%s",
- WindowIdToString(change.window_id).c_str(),
- WindowIdToString(change.window_id2).c_str(),
- DirectionToString(change.direction).c_str());
-
- case CHANGE_TYPE_NODE_DELETED:
- return base::StringPrintf("WindowDeleted window=%s",
- WindowIdToString(change.window_id).c_str());
-
- case CHANGE_TYPE_NODE_VISIBILITY_CHANGED:
- return base::StringPrintf("VisibilityChanged window=%s visible=%s",
- WindowIdToString(change.window_id).c_str(),
- change.bool_value ? "true" : "false");
-
- case CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED:
- return base::StringPrintf("DrawnStateChanged window=%s drawn=%s",
- WindowIdToString(change.window_id).c_str(),
- change.bool_value ? "true" : "false");
-
- case CHANGE_TYPE_INPUT_EVENT: {
- std::string result = base::StringPrintf(
- "InputEvent window=%s event_action=%d",
- WindowIdToString(change.window_id).c_str(), change.event_action);
- if (change.matches_pointer_watcher)
- result += " matches_pointer_watcher";
- return result;
- }
-
- case CHANGE_TYPE_POINTER_WATCHER_EVENT:
- return base::StringPrintf("PointerWatcherEvent event_action=%d window=%s",
- change.event_action,
- WindowIdToString(change.window_id).c_str());
-
- case CHANGE_TYPE_PROPERTY_CHANGED:
- return base::StringPrintf("PropertyChanged window=%s key=%s value=%s",
- WindowIdToString(change.window_id).c_str(),
- change.property_key.c_str(),
- change.property_value.c_str());
-
- case CHANGE_TYPE_FOCUSED:
- return base::StringPrintf("Focused id=%s",
- WindowIdToString(change.window_id).c_str());
-
- case CHANGE_TYPE_CURSOR_CHANGED:
- return base::StringPrintf("CursorChanged id=%s cursor_type=%d",
- WindowIdToString(change.window_id).c_str(),
- static_cast<int>(change.cursor_type));
- case CHANGE_TYPE_ON_CHANGE_COMPLETED:
- return base::StringPrintf("ChangeCompleted id=%d sucess=%s",
- change.change_id,
- change.bool_value ? "true" : "false");
-
- case CHANGE_TYPE_ON_TOP_LEVEL_CREATED:
- return base::StringPrintf("TopLevelCreated id=%d window_id=%s drawn=%s",
- change.change_id,
- WindowIdToString(change.window_id).c_str(),
- change.bool_value ? "true" : "false");
- case CHANGE_TYPE_OPACITY:
- return base::StringPrintf("OpacityChanged window_id=%s opacity=%.2f",
- WindowIdToString(change.window_id).c_str(),
- change.float_value);
- case CHANGE_TYPE_SURFACE_CHANGED:
- return base::StringPrintf("SurfaceCreated window_id=%s surface_id=%s",
- WindowIdToString(change.window_id).c_str(),
- change.surface_id.ToString().c_str());
- case CHANGE_TYPE_TRANSFORM_CHANGED:
- return base::StringPrintf("TransformChanged window_id=%s",
- WindowIdToString(change.window_id).c_str());
- }
- return std::string();
-}
-
-std::string SingleChangeToDescriptionImpl(const std::vector<Change>& changes,
- ChangeDescriptionType change_type) {
- std::string result;
- for (auto& change : changes) {
- if (!result.empty())
- result += "\n";
- result += ChangeToDescription(change, change_type);
- }
- return result;
-}
-
-} // namespace
-
-std::vector<std::string> ChangesToDescription1(
- const std::vector<Change>& changes) {
- std::vector<std::string> strings(changes.size());
- for (size_t i = 0; i < changes.size(); ++i)
- strings[i] = ChangeToDescription(changes[i], ChangeDescriptionType::ONE);
- return strings;
-}
-
-std::string SingleChangeToDescription(const std::vector<Change>& changes) {
- return SingleChangeToDescriptionImpl(changes, ChangeDescriptionType::ONE);
-}
-
-std::string SingleChangeToDescription2(const std::vector<Change>& changes) {
- return SingleChangeToDescriptionImpl(changes, ChangeDescriptionType::TWO);
-}
-
-std::string SingleWindowDescription(const std::vector<TestWindow>& windows) {
- if (windows.empty())
- return "no windows";
- std::string result;
- for (const TestWindow& window : windows)
- result += window.ToString();
- return result;
-}
-
-std::string ChangeWindowDescription(const std::vector<Change>& changes) {
- if (changes.size() != 1)
- return std::string();
- std::vector<std::string> window_strings(changes[0].windows.size());
- for (size_t i = 0; i < changes[0].windows.size(); ++i)
- window_strings[i] = "[" + changes[0].windows[i].ToString() + "]";
- return base::JoinString(window_strings, ",");
-}
-
-TestWindow WindowDataToTestWindow(const mojom::WindowDataPtr& data) {
- TestWindow window;
- window.parent_id = data->parent_id;
- window.window_id = data->window_id;
- window.visible = data->visible;
- window.properties = mojo::FlatMapToMap(data->properties);
- return window;
-}
-
-void WindowDatasToTestWindows(const std::vector<mojom::WindowDataPtr>& data,
- std::vector<TestWindow>* test_windows) {
- for (size_t i = 0; i < data.size(); ++i)
- test_windows->push_back(WindowDataToTestWindow(data[i]));
-}
-
-Change::Change()
- : type(CHANGE_TYPE_EMBED),
- window_id(0),
- window_id2(0),
- window_id3(0),
- event_action(0),
- matches_pointer_watcher(false),
- direction(mojom::OrderDirection::ABOVE),
- bool_value(false),
- float_value(0.f),
- cursor_type(ui::CursorType::kNull),
- change_id(0u),
- display_id(0) {}
-
-Change::Change(const Change& other) = default;
-
-Change::~Change() {}
-
-TestChangeTracker::TestChangeTracker() : delegate_(NULL) {}
-
-TestChangeTracker::~TestChangeTracker() {}
-
-void TestChangeTracker::OnEmbed(mojom::WindowDataPtr root, bool drawn) {
- Change change;
- change.type = CHANGE_TYPE_EMBED;
- change.bool_value = drawn;
- change.windows.push_back(WindowDataToTestWindow(root));
- AddChange(change);
-}
-
-void TestChangeTracker::OnEmbeddedAppDisconnected(Id window_id) {
- Change change;
- change.type = CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED;
- change.window_id = window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowBoundsChanged(
- Id window_id,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- Change change;
- change.type = CHANGE_TYPE_NODE_BOUNDS_CHANGED;
- change.window_id = window_id;
- change.bounds = old_bounds;
- change.bounds2 = new_bounds;
- change.local_surface_id = local_surface_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowTransformChanged(Id window_id) {
- Change change;
- change.type = CHANGE_TYPE_TRANSFORM_CHANGED;
- change.window_id = window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnUnembed(Id window_id) {
- Change change;
- change.type = CHANGE_TYPE_UNEMBED;
- change.window_id = window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnTransientWindowAdded(Id window_id,
- Id transient_window_id) {
- Change change;
- change.type = CHANGE_TYPE_NODE_ADD_TRANSIENT_WINDOW;
- change.window_id = window_id;
- change.window_id2 = transient_window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnTransientWindowRemoved(Id window_id,
- Id transient_window_id) {
- Change change;
- change.type = CHANGE_TYPE_NODE_REMOVE_TRANSIENT_WINDOW_FROM_PARENT;
- change.window_id = window_id;
- change.window_id2 = transient_window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnCaptureChanged(Id new_capture_window_id,
- Id old_capture_window_id) {
- Change change;
- change.type = CHANGE_TYPE_CAPTURE_CHANGED;
- change.window_id = new_capture_window_id;
- change.window_id2 = old_capture_window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnFrameSinkIdAllocated(
- Id window_id,
- const viz::FrameSinkId& frame_sink_id) {
- Change change;
- change.type = CHANGE_TYPE_FRAME_SINK_ID_ALLOCATED;
- change.window_id = window_id;
- change.frame_sink_id = frame_sink_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowHierarchyChanged(
- Id window_id,
- Id old_parent_id,
- Id new_parent_id,
- std::vector<mojom::WindowDataPtr> windows) {
- Change change;
- change.type = CHANGE_TYPE_NODE_HIERARCHY_CHANGED;
- change.window_id = window_id;
- change.window_id2 = old_parent_id;
- change.window_id3 = new_parent_id;
- WindowDatasToTestWindows(windows, &change.windows);
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowReordered(Id window_id,
- Id relative_window_id,
- mojom::OrderDirection direction) {
- Change change;
- change.type = CHANGE_TYPE_NODE_REORDERED;
- change.window_id = window_id;
- change.window_id2 = relative_window_id;
- change.direction = direction;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowDeleted(Id window_id) {
- Change change;
- change.type = CHANGE_TYPE_NODE_DELETED;
- change.window_id = window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowVisibilityChanged(Id window_id, bool visible) {
- Change change;
- change.type = CHANGE_TYPE_NODE_VISIBILITY_CHANGED;
- change.window_id = window_id;
- change.bool_value = visible;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowOpacityChanged(Id window_id, float opacity) {
- Change change;
- change.type = CHANGE_TYPE_OPACITY;
- change.window_id = window_id;
- change.float_value = opacity;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowParentDrawnStateChanged(Id window_id,
- bool drawn) {
- Change change;
- change.type = CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED;
- change.window_id = window_id;
- change.bool_value = drawn;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowInputEvent(
- Id window_id,
- const ui::Event& event,
- int64_t display_id,
- const gfx::PointF& event_location_in_screen_pixel_layout,
- bool matches_pointer_watcher) {
- Change change;
- change.type = CHANGE_TYPE_INPUT_EVENT;
- change.window_id = window_id;
- change.event_action = static_cast<int32_t>(event.type());
- change.matches_pointer_watcher = matches_pointer_watcher;
- change.display_id = display_id;
- if (event.IsLocatedEvent())
- change.location1 = event.AsLocatedEvent()->root_location();
- change.location2 = event_location_in_screen_pixel_layout;
- if (event.IsKeyEvent() && event.AsKeyEvent()->properties())
- change.key_event_properties = *event.AsKeyEvent()->properties();
- AddChange(change);
-}
-
-void TestChangeTracker::OnPointerEventObserved(const ui::Event& event,
- Id window_id) {
- Change change;
- change.type = CHANGE_TYPE_POINTER_WATCHER_EVENT;
- change.event_action = static_cast<int32_t>(event.type());
- change.window_id = window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowSharedPropertyChanged(
- Id window_id,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& data) {
- Change change;
- change.type = CHANGE_TYPE_PROPERTY_CHANGED;
- change.window_id = window_id;
- change.property_key = name;
- if (!data)
- change.property_value = "NULL";
- else
- change.property_value.assign(data->begin(), data->end());
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowFocused(Id window_id) {
- Change change;
- change.type = CHANGE_TYPE_FOCUSED;
- change.window_id = window_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowCursorChanged(Id window_id,
- const ui::CursorData& cursor) {
- Change change;
- change.type = CHANGE_TYPE_CURSOR_CHANGED;
- change.window_id = window_id;
- change.cursor_type = cursor.cursor_type();
- AddChange(change);
-}
-
-void TestChangeTracker::OnChangeCompleted(uint32_t change_id, bool success) {
- Change change;
- change.type = CHANGE_TYPE_ON_CHANGE_COMPLETED;
- change.change_id = change_id;
- change.bool_value = success;
- AddChange(change);
-}
-
-void TestChangeTracker::OnTopLevelCreated(uint32_t change_id,
- mojom::WindowDataPtr window_data,
- bool drawn) {
- Change change;
- change.type = CHANGE_TYPE_ON_TOP_LEVEL_CREATED;
- change.change_id = change_id;
- change.window_id = window_data->window_id;
- change.bool_value = drawn;
- AddChange(change);
-}
-
-void TestChangeTracker::OnWindowSurfaceChanged(
- Id window_id,
- const viz::SurfaceInfo& surface_info) {
- Change change;
- change.type = CHANGE_TYPE_SURFACE_CHANGED;
- change.window_id = window_id;
- change.surface_id = surface_info.id();
- change.frame_size = surface_info.size_in_pixels();
- change.device_scale_factor = surface_info.device_scale_factor();
- AddChange(change);
-}
-
-void TestChangeTracker::AddChange(const Change& change) {
- changes_.push_back(change);
- if (delegate_)
- delegate_->OnChangeAdded();
-}
-
-TestWindow::TestWindow() {}
-
-TestWindow::TestWindow(const TestWindow& other) = default;
-
-TestWindow::~TestWindow() {}
-
-std::string TestWindow::ToString() const {
- return base::StringPrintf("window=%s parent=%s",
- WindowIdToString(window_id).c_str(),
- WindowIdToString(parent_id).c_str());
-}
-
-std::string TestWindow::ToString2() const {
- return base::StringPrintf(
- "window=%s parent=%s visible=%s", WindowIdToString(window_id).c_str(),
- WindowIdToString(parent_id).c_str(), visible ? "true" : "false");
-}
-
-} // namespace ws
-
-} // namespace ui
diff --git a/services/ui/ws/test_change_tracker.h b/services/ui/ws/test_change_tracker.h
deleted file mode 100644
index 8bf9f1d..0000000
--- a/services/ui/ws/test_change_tracker.h
+++ /dev/null
@@ -1,210 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_TEST_CHANGE_TRACKER_H_
-#define SERVICES_UI_WS_TEST_CHANGE_TRACKER_H_
-
-#include <stdint.h>
-
-#include <string>
-#include <vector>
-
-#include "base/containers/flat_map.h"
-#include "base/macros.h"
-#include "services/ui/common/types.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "ui/gfx/geometry/mojo/geometry.mojom.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/point_f.h"
-
-namespace ui {
-
-namespace ws {
-
-enum ChangeType {
- CHANGE_TYPE_CAPTURE_CHANGED,
- CHANGE_TYPE_FRAME_SINK_ID_ALLOCATED,
- CHANGE_TYPE_EMBED,
- CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED,
- CHANGE_TYPE_UNEMBED,
- // TODO(sky): nuke NODE.
- CHANGE_TYPE_NODE_ADD_TRANSIENT_WINDOW,
- CHANGE_TYPE_NODE_BOUNDS_CHANGED,
- CHANGE_TYPE_NODE_HIERARCHY_CHANGED,
- CHANGE_TYPE_NODE_REMOVE_TRANSIENT_WINDOW_FROM_PARENT,
- CHANGE_TYPE_NODE_REORDERED,
- CHANGE_TYPE_NODE_VISIBILITY_CHANGED,
- CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED,
- CHANGE_TYPE_NODE_DELETED,
- CHANGE_TYPE_INPUT_EVENT,
- CHANGE_TYPE_POINTER_WATCHER_EVENT,
- CHANGE_TYPE_PROPERTY_CHANGED,
- CHANGE_TYPE_FOCUSED,
- CHANGE_TYPE_CURSOR_CHANGED,
- CHANGE_TYPE_ON_CHANGE_COMPLETED,
- CHANGE_TYPE_ON_TOP_LEVEL_CREATED,
- CHANGE_TYPE_OPACITY,
- CHANGE_TYPE_SURFACE_CHANGED,
- CHANGE_TYPE_TRANSFORM_CHANGED,
-};
-
-// TODO(sky): consider nuking and converting directly to WindowData.
-struct TestWindow {
- TestWindow();
- TestWindow(const TestWindow& other);
- ~TestWindow();
-
- // Returns a string description of this.
- std::string ToString() const;
-
- // Returns a string description that includes visible and drawn.
- std::string ToString2() const;
-
- Id parent_id;
- Id window_id;
- bool visible;
- std::map<std::string, std::vector<uint8_t>> properties;
-};
-
-// Tracks a call to WindowTreeClient. See the individual functions for the
-// fields that are used.
-struct Change {
- Change();
- Change(const Change& other);
- ~Change();
-
- ChangeType type;
- std::vector<TestWindow> windows;
- Id window_id;
- Id window_id2;
- Id window_id3;
- gfx::Rect bounds;
- gfx::Rect bounds2;
- viz::FrameSinkId frame_sink_id;
- base::Optional<viz::LocalSurfaceId> local_surface_id;
- // TODO(sky): rename, this is Event::event_type.
- int32_t event_action;
- bool matches_pointer_watcher;
- std::string embed_url;
- mojom::OrderDirection direction;
- bool bool_value;
- float float_value;
- std::string property_key;
- std::string property_value;
- ui::CursorType cursor_type;
- uint32_t change_id;
- viz::SurfaceId surface_id;
- gfx::Size frame_size;
- float device_scale_factor;
- gfx::Transform transform;
- // Set in OnWindowInputEvent() if the event is a KeyEvent.
- base::flat_map<std::string, std::vector<uint8_t>> key_event_properties;
- int64_t display_id;
- gfx::Point location1;
- gfx::PointF location2;
-};
-
-// Converts Changes to string descriptions.
-std::vector<std::string> ChangesToDescription1(
- const std::vector<Change>& changes);
-
-// Convenience for returning the description of the first item in |changes|.
-// Returns an empty string if |changes| has something other than one entry.
-std::string SingleChangeToDescription(const std::vector<Change>& changes);
-std::string SingleChangeToDescription2(const std::vector<Change>& changes);
-
-// Convenience for returning the description of the first item in |windows|.
-// Returns an empty string if |windows| has something other than one entry.
-std::string SingleWindowDescription(const std::vector<TestWindow>& windows);
-
-// Returns a string description of |changes[0].windows|. Returns an empty string
-// if change.size() != 1.
-std::string ChangeWindowDescription(const std::vector<Change>& changes);
-
-// Converts WindowDatas to TestWindows.
-void WindowDatasToTestWindows(const std::vector<mojom::WindowDataPtr>& data,
- std::vector<TestWindow>* test_windows);
-
-// TestChangeTracker is used to record WindowTreeClient functions. It notifies
-// a delegate any time a change is added.
-class TestChangeTracker {
- public:
- // Used to notify the delegate when a change is added. A change corresponds to
- // a single WindowTreeClient function.
- class Delegate {
- public:
- virtual void OnChangeAdded() = 0;
-
- protected:
- virtual ~Delegate() {}
- };
-
- TestChangeTracker();
- ~TestChangeTracker();
-
- void set_delegate(Delegate* delegate) { delegate_ = delegate; }
-
- std::vector<Change>* changes() { return &changes_; }
-
- // Each of these functions generate a Change. There is one per
- // WindowTreeClient function.
- void OnEmbed(mojom::WindowDataPtr root, bool drawn);
- void OnEmbeddedAppDisconnected(Id window_id);
- void OnUnembed(Id window_id);
- void OnCaptureChanged(Id new_capture_window_id, Id old_capture_window_id);
- void OnFrameSinkIdAllocated(Id window_id,
- const viz::FrameSinkId& frame_sink_id);
- void OnTransientWindowAdded(Id window_id, Id transient_window_id);
- void OnTransientWindowRemoved(Id window_id, Id transient_window_id);
- void OnWindowBoundsChanged(
- Id window_id,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id);
- void OnWindowTransformChanged(Id window_id);
- void OnWindowHierarchyChanged(Id window_id,
- Id old_parent_id,
- Id new_parent_id,
- std::vector<mojom::WindowDataPtr> windows);
- void OnWindowReordered(Id window_id,
- Id relative_window_id,
- mojom::OrderDirection direction);
- void OnWindowDeleted(Id window_id);
- void OnWindowVisibilityChanged(Id window_id, bool visible);
- void OnWindowOpacityChanged(Id window_id, float opacity);
- void OnWindowParentDrawnStateChanged(Id window_id, bool drawn);
- void OnWindowInputEvent(
- Id window_id,
- const ui::Event& event,
- int64_t display_id,
- const gfx::PointF& event_location_in_screen_pixel_layout,
- bool matches_pointer_watcher);
- void OnPointerEventObserved(const ui::Event& event, Id window_id);
- void OnWindowSharedPropertyChanged(
- Id window_id,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& data);
- void OnWindowFocused(Id window_id);
- void OnWindowCursorChanged(Id window_id, const ui::CursorData& cursor);
- void OnChangeCompleted(uint32_t change_id, bool success);
- void OnTopLevelCreated(uint32_t change_id,
- mojom::WindowDataPtr window_data,
- bool drawn);
- void OnWindowSurfaceChanged(Id window_id,
- const viz::SurfaceInfo& surface_info);
-
- private:
- void AddChange(const Change& change);
-
- Delegate* delegate_;
- std::vector<Change> changes_;
-
- DISALLOW_COPY_AND_ASSIGN(TestChangeTracker);
-};
-
-} // namespace ws
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_TEST_CHANGE_TRACKER_H_
diff --git a/services/ui/ws/test_manifest.json b/services/ui/ws/test_manifest.json
deleted file mode 100644
index ae155484..0000000
--- a/services/ui/ws/test_manifest.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "name": "ui_service_unittests",
- "display_name": "Mus Window Server Unittests",
- "interface_provider_specs": {
- "service_manager:connector": {
- "provides": {
- "ui:window_tree_client": [
- "ui.mojom.WindowTreeClient"
- ]
- },
- "requires": {
- "*": [ "app" ],
- "ui_service_unittests": [ "ui:window_tree_client" ],
- "ui": [
- "window_manager",
- "window_tree_host_factory"
- ],
- "viz": [ "viz_host" ]
- }
- }
- }
-}
diff --git a/services/ui/ws/test_server_window_delegate.cc b/services/ui/ws/test_server_window_delegate.cc
deleted file mode 100644
index 87a8ae3..0000000
--- a/services/ui/ws/test_server_window_delegate.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/test_server_window_delegate.h"
-
-#include "services/ui/ws/server_window.h"
-
-namespace ui {
-namespace ws {
-
-TestServerWindowDelegate::TestServerWindowDelegate(VizHostProxy* viz_host_proxy)
- : viz_host_proxy_(viz_host_proxy) {}
-
-TestServerWindowDelegate::~TestServerWindowDelegate() {}
-
-void TestServerWindowDelegate::AddRootWindow(ServerWindow* window) {
- roots_.insert(window);
-}
-
-VizHostProxy* TestServerWindowDelegate::GetVizHostProxy() {
- return viz_host_proxy_;
-}
-
-ServerWindow* TestServerWindowDelegate::GetRootWindowForDrawn(
- const ServerWindow* window) {
- for (ServerWindow* root : roots_) {
- if (root->Contains(window))
- return root;
- }
- return root_window_;
-}
-
-void TestServerWindowDelegate::OnFirstSurfaceActivation(
- const viz::SurfaceInfo& surface_info,
- ServerWindow* window) {}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/test_server_window_delegate.h b/services/ui/ws/test_server_window_delegate.h
deleted file mode 100644
index f0e6fc2..0000000
--- a/services/ui/ws/test_server_window_delegate.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_TEST_SERVER_WINDOW_DELEGATE_H_
-#define SERVICES_UI_WS_TEST_SERVER_WINDOW_DELEGATE_H_
-
-#include <set>
-
-#include "base/macros.h"
-#include "services/ui/ws/server_window_delegate.h"
-
-namespace ui {
-namespace ws {
-
-class TestServerWindowDelegate : public ServerWindowDelegate {
- public:
- explicit TestServerWindowDelegate(VizHostProxy* viz_host_proxy);
- ~TestServerWindowDelegate() override;
-
- // GetRootWindowForDrawn() returns the first ServerWindow added by way of
- // AddRootWindow() that contains the supplied window. If none of the
- // ServerWindows added by way of AddRootWindow() contain the supplied window,
- // then the value passed to set_root_window() is returned.
- void set_root_window(ServerWindow* window) { root_window_ = window; }
- void AddRootWindow(ServerWindow* window);
-
- private:
- // ServerWindowDelegate:
- VizHostProxy* GetVizHostProxy() override;
- ServerWindow* GetRootWindowForDrawn(const ServerWindow* window) override;
- void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info,
- ServerWindow* window) override;
-
- ServerWindow* root_window_ = nullptr;
- VizHostProxy* viz_host_proxy_ = nullptr;
- std::set<ServerWindow*> roots_;
-
- DISALLOW_COPY_AND_ASSIGN(TestServerWindowDelegate);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_TEST_SERVER_WINDOW_DELEGATE_H_
diff --git a/services/ui/ws/test_utils.cc b/services/ui/ws/test_utils.cc
deleted file mode 100644
index 93ec69d..0000000
--- a/services/ui/ws/test_utils.cc
+++ /dev/null
@@ -1,859 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/test_utils.h"
-
-#include <utility>
-
-#include "base/memory/ptr_util.h"
-#include "base/message_loop/message_loop_current.h"
-#include "base/strings/string_number_conversions.h"
-#include "components/viz/common/frame_sinks/copy_output_request.h"
-#include "gpu/ipc/client/gpu_channel_host.h"
-#include "services/service_manager/public/mojom/connector.mojom.h"
-#include "services/ui/common/image_cursors_set.h"
-#include "services/ui/gpu_host/test_gpu_host.h"
-#include "services/ui/public/interfaces/cursor/cursor.mojom.h"
-#include "services/ui/ws/cursor_location_manager.h"
-#include "services/ui/ws/display_binding.h"
-#include "services/ui/ws/display_creation_config.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/threaded_image_cursors.h"
-#include "services/ui/ws/threaded_image_cursors_factory.h"
-#include "services/ui/ws/window_manager_access_policy.h"
-#include "services/ui/ws/window_manager_window_tree_factory.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/gfx/geometry/dip_util.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-namespace {
-
-ClientWindowId NextUnusedClientWindowId(WindowTree* tree) {
- for (ClientSpecificId id = kEmbedTreeWindowId;; ++id) {
- // Used the id of the client in the upper bits to simplify things.
- const ClientWindowId client_id = ClientWindowId(tree->id(), id);
- if (!tree->GetWindowByClientId(client_id))
- return client_id;
- }
-}
-
-display::ViewportMetrics MakeViewportMetrics(const display::Display& display) {
- gfx::Size pixel_size = gfx::ConvertSizeToPixel(display.device_scale_factor(),
- display.bounds().size());
-
- display::ViewportMetrics metrics;
- metrics.bounds_in_pixels.set_size(pixel_size);
- metrics.device_scale_factor = display.device_scale_factor();
- metrics.ui_scale_factor = 1;
- return metrics;
-}
-
-class TestThreadedImageCursorsFactory : public ThreadedImageCursorsFactory {
- public:
- TestThreadedImageCursorsFactory() {}
- ~TestThreadedImageCursorsFactory() override {}
-
- // ThreadedImageCursorsFactory:
- std::unique_ptr<ThreadedImageCursors> CreateCursors() override {
- if (!resource_runner_) {
- resource_runner_ = base::ThreadTaskRunnerHandle::Get();
- image_cursors_set_ = std::make_unique<ui::ImageCursorsSet>();
- }
- return std::make_unique<ws::ThreadedImageCursors>(
- resource_runner_, image_cursors_set_->GetWeakPtr());
- }
-
- private:
- scoped_refptr<base::SingleThreadTaskRunner> resource_runner_;
- std::unique_ptr<ui::ImageCursorsSet> image_cursors_set_;
-
- DISALLOW_COPY_AND_ASSIGN(TestThreadedImageCursorsFactory);
-};
-
-} // namespace
-
-// TestScreenManager -------------------------------------------------
-
-TestScreenManager::TestScreenManager() {}
-
-TestScreenManager::~TestScreenManager() {
- display::Screen::SetScreenInstance(nullptr);
-}
-
-int64_t TestScreenManager::AddDisplay() {
- return AddDisplay(
- display::Display(display::kInvalidDisplayId, gfx::Rect(100, 100)));
-}
-
-int64_t TestScreenManager::AddDisplay(const display::Display& input_display) {
- // Generate a unique display id.
- int64_t display_id = display_ids_.empty() ? 1 : *display_ids_.rbegin() + 1;
- display_ids_.insert(display_id);
-
- display::Display display = input_display;
- display.set_id(display_id);
-
- // First display added will be the primary display.
- display::DisplayList::Type type = display::DisplayList::Type::NOT_PRIMARY;
- if (display_ids_.size() == 1)
- type = display::DisplayList::Type::PRIMARY;
-
- screen_->display_list().AddDisplay(display, type);
- delegate_->OnDisplayAdded(display, MakeViewportMetrics(display));
-
- if (type == display::DisplayList::Type::PRIMARY)
- delegate_->OnPrimaryDisplayChanged(display_id);
-
- return display_id;
-}
-
-void TestScreenManager::ModifyDisplay(
- const display::Display& display,
- const base::Optional<display::ViewportMetrics>& metrics) {
- DCHECK(display_ids_.count(display.id()) == 1);
- screen_->display_list().UpdateDisplay(display);
- if (metrics)
- delegate_->OnDisplayModified(display, *metrics);
- else
- delegate_->OnDisplayModified(display, MakeViewportMetrics(display));
-}
-
-void TestScreenManager::RemoveDisplay(int64_t display_id) {
- DCHECK(display_ids_.count(display_id) == 1);
- screen_->display_list().RemoveDisplay(display_id);
- delegate_->OnDisplayRemoved(display_id);
- display_ids_.erase(display_id);
-}
-
-void TestScreenManager::Init(display::ScreenManagerDelegate* delegate) {
- delegate_ = delegate;
-
- // Reset everything.
- display_ids_.clear();
- display::Screen::SetScreenInstance(nullptr);
- screen_ = std::make_unique<display::ScreenBase>();
- display::Screen::SetScreenInstance(screen_.get());
-}
-
-display::ScreenBase* TestScreenManager::GetScreen() {
- return screen_.get();
-}
-
-// TestPlatformDisplayFactory -------------------------------------------------
-
-TestPlatformDisplayFactory::TestPlatformDisplayFactory(
- ui::CursorData* cursor_storage)
- : cursor_storage_(cursor_storage) {}
-
-TestPlatformDisplayFactory::~TestPlatformDisplayFactory() {}
-
-std::unique_ptr<PlatformDisplay>
-TestPlatformDisplayFactory::CreatePlatformDisplay(
- ServerWindow* root_window,
- const display::ViewportMetrics& metrics) {
- return std::make_unique<TestPlatformDisplay>(metrics, cursor_storage_);
-}
-
-// WindowTreeTestApi ---------------------------------------------------------
-
-WindowTreeTestApi::WindowTreeTestApi(WindowTree* tree) : tree_(tree) {}
-WindowTreeTestApi::~WindowTreeTestApi() {}
-
-void WindowTreeTestApi::StartPointerWatcher(bool want_moves) {
- tree_->StartPointerWatcher(want_moves);
-}
-
-void WindowTreeTestApi::StopPointerWatcher() {
- tree_->StopPointerWatcher();
-}
-
-// EventProcessorTestApi ----------------------------------------------------
-
-bool EventProcessorTestApi::IsWindowPointerTarget(
- const ServerWindow* window) const {
- for (const auto& pair : ep_->pointer_targets_) {
- if (pair.second.window == window)
- return true;
- }
- return false;
-}
-
-int EventProcessorTestApi::NumberPointerTargetsForWindow(ServerWindow* window) {
- int count = 0;
- for (const auto& pair : ep_->pointer_targets_)
- if (pair.second.window == window)
- count++;
- return count;
-}
-
-bool EventProcessorTestApi::IsObservingWindow(ServerWindow* window) {
- return ep_->observed_windows_.count(window) > 0;
-}
-
-// TestDisplayBinding ---------------------------------------------------------
-
-WindowTree* TestDisplayBinding::CreateWindowTree(ServerWindow* root) {
- const uint32_t embed_flags = 0;
- WindowTree* tree = window_server_->EmbedAtWindow(
- root, ui::mojom::WindowTreeClientPtr(), embed_flags,
- base::WrapUnique(new WindowManagerAccessPolicy));
- WindowTreeTestApi(tree).set_is_for_embedding(false);
- tree->ConfigureWindowManager(automatically_create_display_roots_);
- return tree;
-}
-
-// TestWindowManager ----------------------------------------------------------
-
-TestWindowManager::TestWindowManager() {}
-
-TestWindowManager::~TestWindowManager() {}
-
-void TestWindowManager::OnConnect() {
- connect_count_++;
-}
-
-void TestWindowManager::WmOnAcceleratedWidgetForDisplay(
- int64_t display,
- gpu::SurfaceHandle surface_handle) {}
-
-void TestWindowManager::WmNewDisplayAdded(
- const display::Display& display,
- ui::mojom::WindowDataPtr root,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- display_added_count_++;
-}
-
-void TestWindowManager::WmDisplayRemoved(int64_t display_id) {
- got_display_removed_ = true;
- display_removed_id_ = display_id;
-}
-
-void TestWindowManager::WmSetModalType(Id window_id, ui::ModalType type) {
- on_set_modal_type_called_ = true;
-}
-
-void TestWindowManager::WmCreateTopLevelWindow(
- uint32_t change_id,
- const viz::FrameSinkId& frame_sink_id,
- const base::flat_map<std::string, std::vector<uint8_t>>& properties) {
- got_create_top_level_window_ = true;
- change_id_ = change_id;
-}
-
-void TestWindowManager::WmClientJankinessChanged(ClientSpecificId client_id,
- bool janky) {}
-
-void TestWindowManager::WmBuildDragImage(const gfx::Point& screen_location,
- const gfx::ImageSkia& drag_image,
- const gfx::Vector2d& drag_image_offset,
- ui::mojom::PointerKind source) {}
-
-void TestWindowManager::WmMoveDragImage(const gfx::Point& screen_location,
- WmMoveDragImageCallback callback) {
- std::move(callback).Run();
-}
-
-void TestWindowManager::WmDestroyDragImage() {}
-
-void TestWindowManager::WmPerformMoveLoop(uint32_t change_id,
- Id window_id,
- mojom::MoveLoopSource source,
- const gfx::Point& cursor_location) {
- on_perform_move_loop_called_ = true;
-}
-
-void TestWindowManager::WmCancelMoveLoop(uint32_t change_id) {}
-
-void TestWindowManager::WmDeactivateWindow(Id window_id) {}
-
-void TestWindowManager::WmStackAbove(uint32_t change_id,
- Id above_id,
- Id below_id) {}
-
-void TestWindowManager::WmStackAtTop(uint32_t change_id, Id window_id) {}
-
-void TestWindowManager::WmPerformWmAction(Id window_id,
- const std::string& action) {
- last_wm_action_ = action;
-}
-
-void TestWindowManager::OnAccelerator(uint32_t ack_id,
- uint32_t accelerator_id,
- std::unique_ptr<ui::Event> event) {
- on_accelerator_called_ = true;
- on_accelerator_id_ = accelerator_id;
-}
-
-void TestWindowManager::OnCursorTouchVisibleChanged(bool enabled) {}
-
-void TestWindowManager::OnEventBlockedByModalWindow(Id window_id) {}
-
-// TestWindowTreeClient -------------------------------------------------------
-
-TestWindowTreeClient::TestWindowTreeClient()
- : binding_(this), record_on_change_completed_(false) {}
-TestWindowTreeClient::~TestWindowTreeClient() {}
-
-void TestWindowTreeClient::Bind(
- mojo::InterfaceRequest<mojom::WindowTreeClient> request) {
- binding_.Bind(std::move(request));
-}
-
-void TestWindowTreeClient::OnEmbed(
- mojom::WindowDataPtr root,
- ui::mojom::WindowTreePtr tree,
- int64_t display_id,
- Id focused_window_id,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- // TODO(sky): add test coverage of |focused_window_id|.
- tracker_.OnEmbed(std::move(root), drawn);
-}
-
-void TestWindowTreeClient::OnEmbedFromToken(
- const base::UnguessableToken& token,
- ::ui::mojom::WindowDataPtr root,
- int64_t display_id,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {}
-
-void TestWindowTreeClient::OnEmbeddedAppDisconnected(Id window) {
- tracker_.OnEmbeddedAppDisconnected(window);
-}
-
-void TestWindowTreeClient::OnUnembed(Id window_id) {
- tracker_.OnUnembed(window_id);
-}
-
-void TestWindowTreeClient::OnCaptureChanged(Id new_capture_window_id,
- Id old_capture_window_id) {
- tracker_.OnCaptureChanged(new_capture_window_id, old_capture_window_id);
-}
-
-void TestWindowTreeClient::OnFrameSinkIdAllocated(
- Id window_id,
- const viz::FrameSinkId& frame_sink_id) {
- tracker_.OnFrameSinkIdAllocated(window_id, frame_sink_id);
-}
-
-void TestWindowTreeClient::OnTopLevelCreated(
- uint32_t change_id,
- mojom::WindowDataPtr data,
- int64_t display_id,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- tracker_.OnTopLevelCreated(change_id, std::move(data), drawn);
-}
-
-void TestWindowTreeClient::OnWindowBoundsChanged(
- Id window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- tracker_.OnWindowBoundsChanged(window, std::move(old_bounds),
- std::move(new_bounds), local_surface_id);
-}
-
-void TestWindowTreeClient::OnWindowTransformChanged(
- Id window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform) {}
-
-void TestWindowTreeClient::OnClientAreaChanged(
- Id window_id,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas) {}
-
-void TestWindowTreeClient::OnTransientWindowAdded(Id window_id,
- Id transient_window_id) {}
-
-void TestWindowTreeClient::OnTransientWindowRemoved(Id window_id,
- Id transient_window_id) {}
-
-void TestWindowTreeClient::OnWindowHierarchyChanged(
- Id window,
- Id old_parent,
- Id new_parent,
- std::vector<mojom::WindowDataPtr> windows) {
- tracker_.OnWindowHierarchyChanged(window, old_parent, new_parent,
- std::move(windows));
-}
-
-void TestWindowTreeClient::OnWindowReordered(Id window_id,
- Id relative_window_id,
- mojom::OrderDirection direction) {
- tracker_.OnWindowReordered(window_id, relative_window_id, direction);
-}
-
-void TestWindowTreeClient::OnWindowDeleted(Id window) {
- tracker_.OnWindowDeleted(window);
-}
-
-void TestWindowTreeClient::OnWindowVisibilityChanged(Id window, bool visible) {
- tracker_.OnWindowVisibilityChanged(window, visible);
-}
-
-void TestWindowTreeClient::OnWindowOpacityChanged(Id window,
- float old_opacity,
- float new_opacity) {
- tracker_.OnWindowOpacityChanged(window, new_opacity);
-}
-
-void TestWindowTreeClient::OnWindowParentDrawnStateChanged(Id window,
- bool drawn) {
- tracker_.OnWindowParentDrawnStateChanged(window, drawn);
-}
-
-void TestWindowTreeClient::OnWindowSharedPropertyChanged(
- Id window,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& new_data) {
- tracker_.OnWindowSharedPropertyChanged(window, name, new_data);
-}
-
-void TestWindowTreeClient::OnWindowInputEvent(
- uint32_t event_id,
- Id window,
- int64_t display_id,
- Id display_root_window,
- const gfx::PointF& event_location_in_screen_pixel_layout,
- std::unique_ptr<ui::Event> event,
- bool matches_pointer_watcher) {
- tracker_.OnWindowInputEvent(window, *event.get(), display_id,
- event_location_in_screen_pixel_layout,
- matches_pointer_watcher);
-}
-
-void TestWindowTreeClient::OnPointerEventObserved(
- std::unique_ptr<ui::Event> event,
- Id window_id,
- int64_t display_id) {
- tracker_.OnPointerEventObserved(*event.get(), window_id);
-}
-
-void TestWindowTreeClient::OnWindowFocused(Id focused_window_id) {
- tracker_.OnWindowFocused(focused_window_id);
-}
-
-void TestWindowTreeClient::OnWindowCursorChanged(Id window_id,
- ui::CursorData cursor) {
- tracker_.OnWindowCursorChanged(window_id, cursor);
-}
-
-void TestWindowTreeClient::OnWindowSurfaceChanged(
- Id window_id,
- const viz::SurfaceInfo& surface_info) {}
-
-void TestWindowTreeClient::OnDragDropStart(
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data) {}
-
-void TestWindowTreeClient::OnDragEnter(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnDragEnterCallback callback) {}
-
-void TestWindowTreeClient::OnDragOver(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnDragOverCallback callback) {}
-
-void TestWindowTreeClient::OnDragLeave(Id window) {}
-
-void TestWindowTreeClient::OnCompleteDrop(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnCompleteDropCallback callback) {}
-
-void TestWindowTreeClient::OnPerformDragDropCompleted(uint32_t change_id,
- bool success,
- uint32_t action_taken) {}
-
-void TestWindowTreeClient::OnDragDropDone() {}
-
-void TestWindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) {
- if (record_on_change_completed_)
- tracker_.OnChangeCompleted(change_id, success);
-}
-
-void TestWindowTreeClient::RequestClose(Id window_id) {}
-
-void TestWindowTreeClient::GetWindowManager(
- mojo::AssociatedInterfaceRequest<mojom::WindowManager> internal) {}
-
-void TestWindowTreeClient::GetScreenProviderObserver(
- mojom::ScreenProviderObserverAssociatedRequest observer) {}
-
-// TestWindowTreeBinding ------------------------------------------------------
-
-TestWindowTreeBinding::TestWindowTreeBinding(
- WindowTree* tree,
- std::unique_ptr<TestWindowTreeClient> client)
- : WindowTreeBinding(client.get()),
- tree_(tree),
- client_(std::move(client)) {}
-
-TestWindowTreeBinding::~TestWindowTreeBinding() {}
-
-mojom::WindowManager* TestWindowTreeBinding::GetWindowManager() {
- if (!window_manager_.get())
- window_manager_ = std::make_unique<TestWindowManager>();
- return window_manager_.get();
-}
-void TestWindowTreeBinding::SetIncomingMethodCallProcessingPaused(bool paused) {
- is_paused_ = paused;
-}
-
-mojom::WindowTreeClient* TestWindowTreeBinding::CreateClientForShutdown() {
- DCHECK(!client_after_reset_);
- client_after_reset_ = std::make_unique<TestWindowTreeClient>();
- return client_after_reset_.get();
-}
-
-// TestWindowServerDelegate ----------------------------------------------
-
-TestWindowServerDelegate::TestWindowServerDelegate()
- : threaded_image_cursors_factory_(
- std::make_unique<TestThreadedImageCursorsFactory>()) {}
-TestWindowServerDelegate::~TestWindowServerDelegate() {}
-
-TestWindowTreeBinding* TestWindowServerDelegate::Embed(WindowTree* tree,
- ServerWindow* window,
- int flags) {
- mojom::WindowTreeClientPtr client;
- mojom::WindowTreeClientRequest client_request = mojo::MakeRequest(&client);
- ClientWindowId client_window_id;
- if (!tree->IsWindowKnown(window, &client_window_id))
- return nullptr;
-
- tree->Embed(client_window_id, std::move(client), flags);
- last_client()->Bind(std::move(client_request));
- return last_binding();
-}
-
-void TestWindowServerDelegate::StartDisplayInit() {}
-
-void TestWindowServerDelegate::OnNoMoreDisplays() {
- got_on_no_more_displays_ = true;
-}
-
-std::unique_ptr<WindowTreeBinding>
-TestWindowServerDelegate::CreateWindowTreeBinding(
- BindingType type,
- ws::WindowServer* window_server,
- ws::WindowTree* tree,
- mojom::WindowTreeRequest* tree_request,
- mojom::WindowTreeClientPtr* client) {
- std::unique_ptr<TestWindowTreeBinding> binding =
- std::make_unique<TestWindowTreeBinding>(tree);
- bindings_.push_back(binding.get());
- return std::move(binding);
-}
-
-bool TestWindowServerDelegate::IsTestConfig() const {
- return true;
-}
-
-void TestWindowServerDelegate::OnWillCreateTreeForWindowManager(
- bool automatically_create_display_roots) {
- if (window_server_->display_creation_config() !=
- DisplayCreationConfig::UNKNOWN) {
- return;
- }
- window_server_->SetDisplayCreationConfig(
- automatically_create_display_roots ? DisplayCreationConfig::AUTOMATIC
- : DisplayCreationConfig::MANUAL);
-}
-
-ThreadedImageCursorsFactory*
-TestWindowServerDelegate::GetThreadedImageCursorsFactory() {
- return threaded_image_cursors_factory_.get();
-}
-
-// WindowServerTestHelper ---------------------------------------------------
-
-WindowServerTestHelper::WindowServerTestHelper()
- : cursor_(ui::CursorType::kNull), platform_display_factory_(&cursor_) {
- // Some tests create their own message loop, for example to add a task runner.
- if (!base::MessageLoopCurrent::Get())
- message_loop_ = std::make_unique<base::MessageLoop>();
- PlatformDisplay::set_factory_for_testing(&platform_display_factory_);
- window_server_ = std::make_unique<WindowServer>(&window_server_delegate_,
- true /* should_host_viz */);
- std::unique_ptr<gpu_host::GpuHost> gpu_host =
- std::make_unique<gpu_host::TestGpuHost>();
- window_server_->SetGpuHost(std::move(gpu_host));
- window_server_delegate_.set_window_server(window_server_.get());
-}
-
-WindowServerTestHelper::~WindowServerTestHelper() {
- // Destroy |window_server_| while the message-loop is still alive.
- window_server_.reset();
-}
-
-// WindowEventTargetingHelper ------------------------------------------------
-
-WindowEventTargetingHelper::WindowEventTargetingHelper(
- bool automatically_create_display_roots) {
- display_ = new Display(window_server());
- display_binding_ = new TestDisplayBinding(window_server(),
- automatically_create_display_roots);
- display_->Init(display::ViewportMetrics(),
- base::WrapUnique(display_binding_));
- wm_client_ = ws_test_helper_.window_server_delegate()->last_client();
- wm_client_->tracker()->changes()->clear();
-}
-
-WindowEventTargetingHelper::~WindowEventTargetingHelper() {}
-
-ServerWindow* WindowEventTargetingHelper::CreatePrimaryTree(
- const gfx::Rect& root_window_bounds,
- const gfx::Rect& window_bounds) {
- WindowTree* wm_tree = window_server()->GetTreeWithId(kWindowManagerClientId);
- const ClientWindowId embed_window_id(wm_tree->id(),
- next_primary_tree_window_id_++);
- EXPECT_TRUE(wm_tree->NewWindow(embed_window_id, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree->SetWindowVisibility(embed_window_id, true));
- EXPECT_TRUE(wm_tree->AddWindow(FirstRootId(wm_tree), embed_window_id));
- display_->root_window()->SetBounds(root_window_bounds, base::nullopt);
- mojom::WindowTreeClientPtr client;
- ws_test_helper_.window_server_delegate()->last_client()->Bind(
- mojo::MakeRequest(&client));
- const uint32_t embed_flags = 0;
- wm_tree->Embed(embed_window_id, std::move(client), embed_flags);
- ServerWindow* embed_window = wm_tree->GetWindowByClientId(embed_window_id);
- embed_window->set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window);
- WindowTreeTestApi(tree1).set_is_for_embedding(false);
- EXPECT_NE(nullptr, tree1);
- EXPECT_NE(tree1, wm_tree);
-
- embed_window->SetBounds(window_bounds, base::nullopt);
-
- return embed_window;
-}
-
-void WindowEventTargetingHelper::CreateSecondaryTree(
- ServerWindow* embed_window,
- const gfx::Rect& window_bounds,
- TestWindowTreeClient** out_client,
- WindowTree** window_tree,
- ServerWindow** window) {
- WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window);
- ASSERT_TRUE(tree1 != nullptr);
- const ClientWindowId child1_id(tree1->id(), kEmbedTreeWindowId);
- ASSERT_TRUE(tree1->NewWindow(child1_id, ServerWindow::Properties()));
- ServerWindow* child1 = tree1->GetWindowByClientId(child1_id);
- ASSERT_TRUE(child1);
- EXPECT_TRUE(tree1->AddWindow(ClientWindowIdForWindow(tree1, embed_window),
- child1_id));
- embed_window->set_is_activation_parent(true);
-
- child1->SetVisible(true);
- child1->SetBounds(window_bounds, base::nullopt);
-
- TestWindowTreeClient* embed_client =
- ws_test_helper_.window_server_delegate()->last_client();
- embed_client->tracker()->changes()->clear();
- wm_client_->tracker()->changes()->clear();
-
- *out_client = embed_client;
- *window_tree = tree1;
- *window = child1;
-}
-
-void WindowEventTargetingHelper::SetTaskRunner(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
- base::MessageLoopCurrent::Get()->SetTaskRunner(task_runner);
-}
-
-// ----------------------------------------------------------------------------
-
-TestScreenProviderObserver::TestScreenProviderObserver() : binding_(this) {}
-
-TestScreenProviderObserver::~TestScreenProviderObserver() = default;
-
-mojom::ScreenProviderObserverPtr TestScreenProviderObserver::GetPtr() {
- mojom::ScreenProviderObserverPtr ptr;
- binding_.Bind(mojo::MakeRequest(&ptr));
- return ptr;
-}
-
-std::string TestScreenProviderObserver::GetAndClearObserverCalls() {
- std::string result;
- std::swap(observer_calls_, result);
- return result;
-}
-
-std::string TestScreenProviderObserver::DisplayIdsToString(
- const std::vector<mojom::WsDisplayPtr>& wm_displays) {
- std::string display_ids;
- for (const auto& wm_display : wm_displays) {
- if (!display_ids.empty())
- display_ids += " ";
- display_ids += base::Int64ToString(wm_display->display.id());
- }
- return display_ids;
-}
-
-void TestScreenProviderObserver::OnDisplaysChanged(
- std::vector<mojom::WsDisplayPtr> displays,
- int64_t primary_display_id,
- int64_t internal_display_id) {
- if (!observer_calls_.empty())
- observer_calls_ += "\n";
- observer_calls_ += "OnDisplaysChanged " + DisplayIdsToString(displays);
- observer_calls_ += " " + base::Int64ToString(internal_display_id);
-}
-
-// -----------------------------------------------------------------------------
-TestPlatformDisplay::TestPlatformDisplay(
- const display::ViewportMetrics& metrics,
- ui::CursorData* cursor_storage)
- : metrics_(metrics), cursor_storage_(cursor_storage) {}
-
-TestPlatformDisplay::~TestPlatformDisplay() = default;
-
-// PlatformDisplay:
-void TestPlatformDisplay::Init(PlatformDisplayDelegate* delegate) {
- delegate->OnAcceleratedWidgetAvailable();
-}
-void TestPlatformDisplay::SetViewportSize(const gfx::Size& size) {}
-void TestPlatformDisplay::SetTitle(const base::string16& title) {}
-void TestPlatformDisplay::SetCapture() {
- has_capture_ = true;
-}
-void TestPlatformDisplay::ReleaseCapture() {
- has_capture_ = false;
-}
-void TestPlatformDisplay::SetCursor(const ui::CursorData& cursor) {
- *cursor_storage_ = cursor;
-}
-void TestPlatformDisplay::SetCursorSize(const ui::CursorSize& cursor_size) {}
-void TestPlatformDisplay::ConfineCursorToBounds(const gfx::Rect& pixel_bounds) {
- confine_cursor_bounds_ = pixel_bounds;
-}
-void TestPlatformDisplay::MoveCursorTo(
- const gfx::Point& window_pixel_location) {}
-void TestPlatformDisplay::UpdateTextInputState(
- const ui::TextInputState& state) {}
-void TestPlatformDisplay::SetImeVisibility(bool visible) {}
-void TestPlatformDisplay::UpdateViewportMetrics(
- const display::ViewportMetrics& metrics) {
- metrics_ = metrics;
-}
-const display::ViewportMetrics& TestPlatformDisplay::GetViewportMetrics() {
- return metrics_;
-}
-gfx::AcceleratedWidget TestPlatformDisplay::GetAcceleratedWidget() const {
- return gfx::kNullAcceleratedWidget;
-}
-FrameGenerator* TestPlatformDisplay::GetFrameGenerator() {
- return nullptr;
-}
-EventSink* TestPlatformDisplay::GetEventSink() {
- return nullptr;
-}
-void TestPlatformDisplay::SetCursorConfig(display::Display::Rotation rotation,
- float scale) {
- cursor_scale_ = scale;
-}
-
-// -----------------------------------------------------------------------------
-
-CursorLocationManagerTestApi::CursorLocationManagerTestApi(
- CursorLocationManager* cursor_location_manager)
- : cursor_location_manager_(cursor_location_manager) {}
-
-CursorLocationManagerTestApi::~CursorLocationManagerTestApi() = default;
-
-base::subtle::Atomic32 CursorLocationManagerTestApi::current_cursor_location() {
- return cursor_location_manager_->current_cursor_location_;
-}
-
-// -----------------------------------------------------------------------------
-
-void AddWindowManager(WindowServer* window_server,
- bool automatically_create_display_roots) {
- window_server->window_manager_window_tree_factory()->CreateWindowTree(
- nullptr, nullptr, automatically_create_display_roots);
-}
-
-display::Display MakeDisplay(int origin_x,
- int origin_y,
- int width_pixels,
- int height_pixels,
- float scale_factor) {
- gfx::Size scaled_size = gfx::ConvertSizeToDIP(
- scale_factor, gfx::Size(width_pixels, height_pixels));
- gfx::Rect bounds(gfx::Point(origin_x, origin_y), scaled_size);
-
- display::Display display;
- display.set_bounds(bounds);
- display.set_work_area(bounds);
- display.set_device_scale_factor(scale_factor);
- return display;
-}
-
-ServerWindow* FirstRoot(WindowTree* tree) {
- return tree->roots().size() == 1u
- ? const_cast<ServerWindow*>(*(tree->roots().begin()))
- : nullptr;
-}
-
-ClientWindowId FirstRootId(WindowTree* tree) {
- ServerWindow* first_root = FirstRoot(tree);
- return first_root ? ClientWindowIdForWindow(tree, first_root)
- : ClientWindowId();
-}
-
-ClientWindowId ClientWindowIdForWindow(WindowTree* tree,
- const ServerWindow* window) {
- ClientWindowId client_window_id;
- // If window isn't known we'll return 0, which should then error out.
- tree->IsWindowKnown(window, &client_window_id);
- return client_window_id;
-}
-
-ServerWindow* NewWindowInTree(WindowTree* tree, ClientWindowId* client_id) {
- return NewWindowInTreeWithParent(tree, FirstRoot(tree), client_id);
-}
-
-ServerWindow* NewWindowInTreeWithParent(WindowTree* tree,
- ServerWindow* parent,
- ClientWindowId* client_id,
- const gfx::Rect& bounds) {
- if (!parent)
- return nullptr;
- ClientWindowId parent_client_id;
- if (!tree->IsWindowKnown(parent, &parent_client_id))
- return nullptr;
- ClientWindowId client_window_id = NextUnusedClientWindowId(tree);
- if (!tree->NewWindow(client_window_id, ServerWindow::Properties()))
- return nullptr;
- if (!tree->SetWindowVisibility(client_window_id, true))
- return nullptr;
- if (!tree->AddWindow(parent_client_id, client_window_id))
- return nullptr;
- ServerWindow* window = tree->GetWindowByClientId(client_window_id);
- window->SetBounds(bounds);
- if (client_id)
- *client_id = client_window_id;
- return window;
-}
-
-gfx::Point Atomic32ToPoint(base::subtle::Atomic32 atomic) {
- return gfx::Point(static_cast<int16_t>(atomic >> 16),
- static_cast<int16_t>(atomic & 0xFFFF));
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/test_utils.h b/services/ui/ws/test_utils.h
deleted file mode 100644
index 846fd73..0000000
--- a/services/ui/ws/test_utils.h
+++ /dev/null
@@ -1,891 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_TEST_UTILS_H_
-#define SERVICES_UI_WS_TEST_UTILS_H_
-
-#include <stdint.h>
-
-#include <memory>
-#include <set>
-#include <vector>
-
-#include "base/atomicops.h"
-#include "base/containers/flat_map.h"
-#include "base/message_loop/message_loop.h"
-#include "base/optional.h"
-#include "base/single_thread_task_runner.h"
-#include "services/service_manager/public/cpp/bind_source_info.h"
-#include "services/ui/display/screen_manager.h"
-#include "services/ui/display/viewport_metrics.h"
-#include "services/ui/gpu_host/gpu_host.h"
-#include "services/ui/public/interfaces/screen_provider.mojom.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_binding.h"
-#include "services/ui/ws/drag_controller.h"
-#include "services/ui/ws/event_dispatcher_impl_test_api.h"
-#include "services/ui/ws/event_processor.h"
-#include "services/ui/ws/event_targeter.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/platform_display_factory.h"
-#include "services/ui/ws/test_change_tracker.h"
-#include "services/ui/ws/user_activity_monitor.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "ui/display/display.h"
-#include "ui/display/screen_base.h"
-#include "ui/display/types/display_constants.h"
-
-namespace ui {
-namespace ws {
-
-class CursorLocationManager;
-
-namespace test {
-
-const ClientSpecificId kWindowManagerClientId = kWindowServerClientId + 1;
-const std::string kWindowManagerClientIdString =
- std::to_string(kWindowManagerClientId);
-const ClientSpecificId kEmbedTreeWindowId = 1;
-
-// Collection of utilities useful in creating mus tests.
-
-// Test ScreenManager instance that allows adding/modifying/removing displays.
-// Tracks display ids to perform some basic verification that no duplicates are
-// added and display was added before being modified or removed. Display ids
-// reset when Init() is called.
-class TestScreenManager : public display::ScreenManager {
- public:
- TestScreenManager();
- ~TestScreenManager() override;
-
- // Adds a new display with default metrics, generates a unique display id and
- // returns it. Calls OnDisplayAdded() on delegate.
- int64_t AddDisplay();
-
- // Adds a new display with provided |display|, generates a unique display id
- // and returns it. Calls OnDisplayAdded() on delegate.
- int64_t AddDisplay(const display::Display& display);
-
- // Calls OnDisplayModified() on delegate.
- void ModifyDisplay(const display::Display& display,
- const base::Optional<display::ViewportMetrics>& metrics =
- base::Optional<display::ViewportMetrics>());
-
- // Calls OnDisplayRemoved() on delegate.
- void RemoveDisplay(int64_t id);
-
- // display::ScreenManager:
- void AddInterfaces(
- service_manager::BinderRegistryWithArgs<
- const service_manager::BindSourceInfo&>* registry) override {}
- void Init(display::ScreenManagerDelegate* delegate) override;
- void RequestCloseDisplay(int64_t display_id) override {}
- display::ScreenBase* GetScreen() override;
-
- private:
- display::ScreenManagerDelegate* delegate_ = nullptr;
- std::unique_ptr<display::ScreenBase> screen_;
- std::set<int64_t> display_ids_;
-
- DISALLOW_COPY_AND_ASSIGN(TestScreenManager);
-};
-
-// -----------------------------------------------------------------------------
-
-class UserActivityMonitorTestApi {
- public:
- explicit UserActivityMonitorTestApi(UserActivityMonitor* monitor)
- : monitor_(monitor) {}
-
- void SetTimerTaskRunner(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
- monitor_->idle_timer_.SetTaskRunner(task_runner);
- }
-
- private:
- UserActivityMonitor* monitor_;
- DISALLOW_COPY_AND_ASSIGN(UserActivityMonitorTestApi);
-};
-
-// -----------------------------------------------------------------------------
-
-class WindowTreeTestApi {
- public:
- explicit WindowTreeTestApi(WindowTree* tree);
- ~WindowTreeTestApi();
-
- void set_is_for_embedding(bool value) { tree_->is_for_embedding_ = value; }
- void set_window_manager_internal(mojom::WindowManager* wm_internal) {
- tree_->window_manager_internal_ = wm_internal;
- }
- void SetEventTargetingPolicy(Id transport_window_id,
- mojom::EventTargetingPolicy policy) {
- tree_->SetEventTargetingPolicy(transport_window_id, policy);
- }
- void AckOldestEvent(
- mojom::EventResult result = mojom::EventResult::UNHANDLED) {
- tree_->OnWindowInputEventAck(tree_->event_ack_id_, result);
- }
- void EnableCapture() { tree_->event_ack_id_ = 1u; }
- void AckLastEvent(mojom::EventResult result) {
- tree_->OnWindowInputEventAck(tree_->event_ack_id_, result);
- }
- void AckLastAccelerator(
- mojom::EventResult result,
- const base::flat_map<std::string, std::vector<uint8_t>>& properties =
- base::flat_map<std::string, std::vector<uint8_t>>()) {
- tree_->OnAcceleratorAck(tree_->event_ack_id_, result, properties);
- }
-
- void StartPointerWatcher(bool want_moves);
- void StopPointerWatcher();
-
- bool ProcessSetDisplayRoot(const display::Display& display_to_create,
- const display::ViewportMetrics& viewport_metrics,
- bool is_primary_display,
- const ClientWindowId& client_window_id) {
- return tree_->ProcessSetDisplayRoot(display_to_create, viewport_metrics,
- is_primary_display, client_window_id,
- std::vector<display::Display>());
- }
-
- bool ProcessSwapDisplayRoots(int64_t display_id1, int64_t display_id2) {
- return tree_->ProcessSwapDisplayRoots(display_id1, display_id2);
- }
- size_t event_queue_size() const { return tree_->event_queue_.size(); }
- bool HasEventInFlight() const { return tree_->event_ack_id_ != 0u; }
-
- private:
- WindowTree* tree_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTreeTestApi);
-};
-
-// -----------------------------------------------------------------------------
-
-class EventProcessorTestApi {
- public:
- explicit EventProcessorTestApi(EventProcessor* ep) : ep_(ep) {}
- ~EventProcessorTestApi() {}
-
- bool AreAnyPointersDown() const { return ep_->AreAnyPointersDown(); }
- bool is_mouse_button_down() const { return ep_->mouse_button_down_; }
- bool IsWindowPointerTarget(const ServerWindow* window) const;
- int NumberPointerTargetsForWindow(ServerWindow* window);
- ModalWindowController* modal_window_controller() const {
- return &ep_->modal_window_controller_;
- }
- ServerWindow* capture_window() { return ep_->capture_window_; }
- EventTargeter* event_targeter() { return ep_->event_targeter_.get(); }
- bool IsObservingWindow(ServerWindow* window);
-
- private:
- EventProcessor* ep_;
-
- DISALLOW_COPY_AND_ASSIGN(EventProcessorTestApi);
-};
-
-// -----------------------------------------------------------------------------
-
-class EventTargeterTestApi {
- public:
- explicit EventTargeterTestApi(EventTargeter* event_targeter)
- : event_targeter_(event_targeter) {}
- ~EventTargeterTestApi() {}
-
- bool HasPendingQueries() const {
- return event_targeter_->weak_ptr_factory_.HasWeakPtrs();
- }
-
- private:
- EventTargeter* event_targeter_;
-
- DISALLOW_COPY_AND_ASSIGN(EventTargeterTestApi);
-};
-
-// -----------------------------------------------------------------------------
-
-class ModalWindowControllerTestApi {
- public:
- explicit ModalWindowControllerTestApi(ModalWindowController* mwc)
- : mwc_(mwc) {}
- ~ModalWindowControllerTestApi() {}
-
- const ServerWindow* GetActiveSystemModalWindow() const {
- return mwc_->GetActiveSystemModalWindow();
- }
-
- private:
- ModalWindowController* mwc_;
-
- DISALLOW_COPY_AND_ASSIGN(ModalWindowControllerTestApi);
-};
-
-// -----------------------------------------------------------------------------
-
-class WindowManagerStateTestApi {
- public:
- explicit WindowManagerStateTestApi(WindowManagerState* wms) : wms_(wms) {}
- ~WindowManagerStateTestApi() {}
-
- ClientSpecificId GetEventTargetClientId(ServerWindow* window,
- bool in_nonclient_area) {
- return wms_->GetEventTargetClientId(window, in_nonclient_area);
- }
-
- void ProcessEvent(ui::Event* event, int64_t display_id = 0) {
- wms_->ProcessEvent(event, display_id);
- }
-
- ClientSpecificId GetEventTargetClientId(const ServerWindow* window,
- bool in_nonclient_area) {
- return wms_->GetEventTargetClientId(window, in_nonclient_area);
- }
-
- void OnEventAckTimeout(ClientSpecificId client_id) {
- EventDispatcherImplTestApi(&wms_->event_dispatcher_)
- .OnDispatchInputEventTimeout();
- }
-
- const std::vector<std::unique_ptr<WindowManagerDisplayRoot>>&
- window_manager_display_roots() const {
- return wms_->window_manager_display_roots_;
- }
-
- // TODO(sky): convert calling code to use EventDispatcherImplTestApi directly.
- void DispatchInputEventToWindow(ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const ui::Event& event,
- Accelerator* accelerator) {
- EventDispatcherImplTestApi(&wms_->event_dispatcher_)
- .DispatchInputEventToWindow(target, client_id, event_location, event,
- accelerator);
- }
- WindowTree* tree_awaiting_input_ack() {
- return EventDispatcherImplTestApi(&wms_->event_dispatcher_)
- .GetTreeThatWillAckEvent();
- }
- bool is_event_tasks_empty() const {
- return EventDispatcherImplTestApi(&wms_->event_dispatcher_)
- .is_event_tasks_empty();
- }
- bool AckInFlightEvent(mojom::EventResult result) {
- return EventDispatcherImplTestApi(&wms_->event_dispatcher_)
- .OnDispatchInputEventDone(result);
- }
-
- private:
- WindowManagerState* wms_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTestApi);
-};
-
-// -----------------------------------------------------------------------------
-
-class DragControllerTestApi {
- public:
- explicit DragControllerTestApi(DragController* op) : op_(op) {}
- ~DragControllerTestApi() {}
-
- size_t GetSizeOfQueueForWindow(ServerWindow* window) {
- return op_->GetSizeOfQueueForWindow(window);
- }
-
- ServerWindow* GetCurrentTarget() { return op_->current_target_window_; }
-
- private:
- DragController* op_;
-
- DISALLOW_COPY_AND_ASSIGN(DragControllerTestApi);
-};
-
-// -----------------------------------------------------------------------------
-
-// Factory that always embeds the new WindowTree as the root user id.
-class TestDisplayBinding : public DisplayBinding {
- public:
- explicit TestDisplayBinding(WindowServer* window_server,
- bool automatically_create_display_roots = true)
- : window_server_(window_server),
- automatically_create_display_roots_(
- automatically_create_display_roots) {}
- ~TestDisplayBinding() override {}
-
- private:
- // DisplayBinding:
- WindowTree* CreateWindowTree(ServerWindow* root) override;
-
- WindowServer* window_server_;
- const bool automatically_create_display_roots_;
-
- DISALLOW_COPY_AND_ASSIGN(TestDisplayBinding);
-};
-
-// -----------------------------------------------------------------------------
-
-// Factory that dispenses TestPlatformDisplays.
-class TestPlatformDisplayFactory : public PlatformDisplayFactory {
- public:
- explicit TestPlatformDisplayFactory(ui::CursorData* cursor_storage);
- ~TestPlatformDisplayFactory();
-
- // PlatformDisplayFactory:
- std::unique_ptr<PlatformDisplay> CreatePlatformDisplay(
- ServerWindow* root_window,
- const display::ViewportMetrics& metrics) override;
-
- private:
- ui::CursorData* cursor_storage_;
-
- DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplayFactory);
-};
-
-// -----------------------------------------------------------------------------
-
-class TestWindowManager : public mojom::WindowManager {
- public:
- TestWindowManager();
- ~TestWindowManager() override;
-
- bool did_call_create_top_level_window(uint32_t* change_id) {
- if (!got_create_top_level_window_)
- return false;
-
- got_create_top_level_window_ = false;
- *change_id = change_id_;
- return true;
- }
-
- void ClearAcceleratorCalled() {
- on_accelerator_id_ = 0u;
- on_accelerator_called_ = false;
- }
-
- const std::string& last_wm_action() const { return last_wm_action_; }
- bool on_perform_move_loop_called() { return on_perform_move_loop_called_; }
- bool on_accelerator_called() { return on_accelerator_called_; }
- uint32_t on_accelerator_id() { return on_accelerator_id_; }
- bool got_display_removed() const { return got_display_removed_; }
- int64_t display_removed_id() const { return display_removed_id_; }
- bool on_set_modal_type_called() { return on_set_modal_type_called_; }
- int connect_count() const { return connect_count_; }
- int display_added_count() const { return display_added_count_; }
-
- private:
- // WindowManager:
- void OnConnect() override;
- void WmOnAcceleratedWidgetForDisplay(
- int64_t display,
- gpu::SurfaceHandle surface_handle) override;
- void WmNewDisplayAdded(
- const display::Display& display,
- ui::mojom::WindowDataPtr root,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override;
- void WmDisplayRemoved(int64_t display_id) override;
- void WmDisplayModified(const display::Display& display) override {}
- void WmSetBounds(uint32_t change_id,
- Id window_id,
- const gfx::Rect& bounds) override {}
- void WmSetProperty(
- uint32_t change_id,
- Id window_id,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& value) override {}
- void WmSetModalType(Id window_id, ui::ModalType type) override;
- void WmSetCanFocus(Id window_id, bool can_focus) override {}
- void WmCreateTopLevelWindow(
- uint32_t change_id,
- const viz::FrameSinkId& frame_sink_id,
- const base::flat_map<std::string, std::vector<uint8_t>>& properties)
- override;
- void WmClientJankinessChanged(ClientSpecificId client_id,
- bool janky) override;
- void WmBuildDragImage(const gfx::Point& screen_location,
- const gfx::ImageSkia& drag_image,
- const gfx::Vector2d& drag_image_offset,
- ui::mojom::PointerKind source) override;
- void WmMoveDragImage(const gfx::Point& screen_location,
- WmMoveDragImageCallback callback) override;
- void WmDestroyDragImage() override;
- void WmPerformMoveLoop(uint32_t change_id,
- Id window_id,
- mojom::MoveLoopSource source,
- const gfx::Point& cursor_location) override;
- void WmCancelMoveLoop(uint32_t change_id) override;
- void WmDeactivateWindow(Id window_id) override;
- void WmStackAbove(uint32_t change_id, Id above_id, Id below_id) override;
- void WmStackAtTop(uint32_t change_id, Id window_id) override;
- void WmPerformWmAction(Id window_id, const std::string& action) override;
- void OnAccelerator(uint32_t ack_id,
- uint32_t accelerator_id,
- std::unique_ptr<ui::Event> event) override;
- void OnCursorTouchVisibleChanged(bool enabled) override;
- void OnEventBlockedByModalWindow(Id window_id) override;
-
- std::string last_wm_action_;
-
- bool on_perform_move_loop_called_ = false;
- bool on_set_modal_type_called_ = false;
-
- bool got_create_top_level_window_ = false;
- uint32_t change_id_ = 0u;
-
- bool on_accelerator_called_ = false;
- uint32_t on_accelerator_id_ = 0u;
-
- bool got_display_removed_ = false;
- int64_t display_removed_id_ = 0;
-
- int connect_count_ = 0;
- int display_added_count_ = 0;
-
- DISALLOW_COPY_AND_ASSIGN(TestWindowManager);
-};
-
-// -----------------------------------------------------------------------------
-
-// WindowTreeClient implementation that logs all calls to a TestChangeTracker.
-class TestWindowTreeClient : public ui::mojom::WindowTreeClient {
- public:
- TestWindowTreeClient();
- ~TestWindowTreeClient() override;
-
- TestChangeTracker* tracker() { return &tracker_; }
-
- void Bind(mojo::InterfaceRequest<mojom::WindowTreeClient> request);
-
- void set_record_on_change_completed(bool value) {
- record_on_change_completed_ = value;
- }
-
- private:
- // WindowTreeClient:
- void OnEmbed(
- mojom::WindowDataPtr root,
- ui::mojom::WindowTreePtr tree,
- int64_t display_id,
- Id focused_window_id,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override;
- void OnEmbedFromToken(
- const base::UnguessableToken& token,
- mojom::WindowDataPtr root,
- int64_t display_id,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override;
- void OnEmbeddedAppDisconnected(Id window) override;
- void OnUnembed(Id window_id) override;
- void OnCaptureChanged(Id new_capture_window_id,
- Id old_capture_window_id) override;
- void OnFrameSinkIdAllocated(Id window_id,
- const viz::FrameSinkId& frame_sink_id) override;
- void OnTopLevelCreated(
- uint32_t change_id,
- mojom::WindowDataPtr data,
- int64_t display_id,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override;
- void OnWindowBoundsChanged(
- Id window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override;
- void OnWindowTransformChanged(Id window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform) override;
- void OnClientAreaChanged(
- Id window_id,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas) override;
- void OnTransientWindowAdded(Id window_id, Id transient_window_id) override;
- void OnTransientWindowRemoved(Id window_id, Id transient_window_id) override;
- void OnWindowHierarchyChanged(
- Id window,
- Id old_parent,
- Id new_parent,
- std::vector<mojom::WindowDataPtr> windows) override;
- void OnWindowReordered(Id window_id,
- Id relative_window_id,
- mojom::OrderDirection direction) override;
- void OnWindowDeleted(Id window) override;
- void OnWindowVisibilityChanged(Id window, bool visible) override;
- void OnWindowOpacityChanged(Id window,
- float old_opacity,
- float new_opacity) override;
- void OnWindowParentDrawnStateChanged(Id window, bool drawn) override;
- void OnWindowSharedPropertyChanged(
- Id window,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& new_data) override;
- void OnWindowInputEvent(
- uint32_t event_id,
- Id window,
- int64_t display_id,
- Id display_root_window,
- const gfx::PointF& event_location_in_screen_pixel_layout,
- std::unique_ptr<ui::Event> event,
- bool matches_pointer_watcher) override;
- void OnPointerEventObserved(std::unique_ptr<ui::Event> event,
- Id window_id,
- int64_t display_id) override;
- void OnWindowFocused(Id focused_window_id) override;
- void OnWindowCursorChanged(Id window_id, ui::CursorData cursor) override;
- void OnWindowSurfaceChanged(Id window_id,
- const viz::SurfaceInfo& surface_info) override;
- void OnDragDropStart(const base::flat_map<std::string, std::vector<uint8_t>>&
- mime_data) override;
- void OnDragEnter(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnDragEnterCallback callback) override;
- void OnDragOver(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnDragOverCallback callback) override;
- void OnDragLeave(Id window) override;
- void OnCompleteDrop(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnCompleteDropCallback callback) override;
- void OnPerformDragDropCompleted(uint32_t change_id,
- bool success,
- uint32_t action_taken) override;
- void OnDragDropDone() override;
- void OnChangeCompleted(uint32_t change_id, bool success) override;
- void RequestClose(Id window_id) override;
- void GetWindowManager(
- mojo::AssociatedInterfaceRequest<mojom::WindowManager> internal) override;
- void GetScreenProviderObserver(
- mojom::ScreenProviderObserverAssociatedRequest observer) override;
-
- TestChangeTracker tracker_;
- mojo::Binding<mojom::WindowTreeClient> binding_;
- bool record_on_change_completed_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClient);
-};
-
-// -----------------------------------------------------------------------------
-
-// WindowTreeBinding implementation that vends TestWindowTreeBinding.
-class TestWindowTreeBinding : public WindowTreeBinding {
- public:
- TestWindowTreeBinding(WindowTree* tree,
- std::unique_ptr<TestWindowTreeClient> client =
- std::make_unique<TestWindowTreeClient>());
- ~TestWindowTreeBinding() override;
-
- std::unique_ptr<TestWindowTreeClient> ReleaseClient() {
- return std::move(client_);
- }
-
- WindowTree* tree() { return tree_; }
- TestWindowTreeClient* client() { return client_.get(); }
- TestWindowManager* window_manager() { return window_manager_.get(); }
-
- bool is_paused() const { return is_paused_; }
-
- // WindowTreeBinding:
- mojom::WindowManager* GetWindowManager() override;
- void SetIncomingMethodCallProcessingPaused(bool paused) override;
-
- protected:
- // WindowTreeBinding:
- mojom::WindowTreeClient* CreateClientForShutdown() override;
-
- private:
- WindowTree* tree_;
- std::unique_ptr<TestWindowTreeClient> client_;
- // This is the client created once ResetClientForShutdown() is called.
- std::unique_ptr<TestWindowTreeClient> client_after_reset_;
- bool is_paused_ = false;
- std::unique_ptr<TestWindowManager> window_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(TestWindowTreeBinding);
-};
-
-// -----------------------------------------------------------------------------
-
-// WindowServerDelegate that creates TestWindowTreeClients.
-class TestWindowServerDelegate : public WindowServerDelegate {
- public:
- TestWindowServerDelegate();
- ~TestWindowServerDelegate() override;
-
- void set_window_server(WindowServer* window_server) {
- window_server_ = window_server;
- }
-
- TestWindowTreeClient* last_client() {
- return last_binding() ? last_binding()->client() : nullptr;
- }
- TestWindowTreeBinding* last_binding() {
- return bindings_.empty() ? nullptr : bindings_.back();
- }
-
- std::vector<TestWindowTreeBinding*>* bindings() { return &bindings_; }
-
- bool got_on_no_more_displays() const { return got_on_no_more_displays_; }
-
- // Does an Embed() in |tree| at |window| returning the TestWindowTreeBinding
- // that resulred (null on failure).
- TestWindowTreeBinding* Embed(WindowTree* tree,
- ServerWindow* window,
- int flags = 0);
-
- // WindowServerDelegate:
- void StartDisplayInit() override;
- void OnNoMoreDisplays() override;
- std::unique_ptr<WindowTreeBinding> CreateWindowTreeBinding(
- BindingType type,
- ws::WindowServer* window_server,
- ws::WindowTree* tree,
- mojom::WindowTreeRequest* tree_request,
- mojom::WindowTreeClientPtr* client) override;
- bool IsTestConfig() const override;
- void OnWillCreateTreeForWindowManager(
- bool automatically_create_display_roots) override;
- ThreadedImageCursorsFactory* GetThreadedImageCursorsFactory() override;
-
- private:
- WindowServer* window_server_ = nullptr;
- bool got_on_no_more_displays_ = false;
- // All TestWindowTreeBinding objects created via CreateWindowTreeBinding.
- // These are owned by the corresponding WindowTree.
- std::vector<TestWindowTreeBinding*> bindings_;
- std::unique_ptr<ThreadedImageCursorsFactory> threaded_image_cursors_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(TestWindowServerDelegate);
-};
-
-// -----------------------------------------------------------------------------
-
-// Helper class which creates and sets up the necessary objects for tests that
-// use the WindowServer.
-class WindowServerTestHelper {
- public:
- WindowServerTestHelper();
- ~WindowServerTestHelper();
-
- WindowServer* window_server() { return window_server_.get(); }
- const ui::CursorData& cursor() const { return cursor_; }
-
- TestWindowServerDelegate* window_server_delegate() {
- return &window_server_delegate_;
- }
-
- private:
- ui::CursorData cursor_;
- TestPlatformDisplayFactory platform_display_factory_;
- TestWindowServerDelegate window_server_delegate_;
- std::unique_ptr<WindowServer> window_server_;
- std::unique_ptr<base::MessageLoop> message_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowServerTestHelper);
-};
-
-// -----------------------------------------------------------------------------
-
-// Helper class which owns all of the necessary objects to test event targeting
-// of ServerWindow objects.
-class WindowEventTargetingHelper {
- public:
- explicit WindowEventTargetingHelper(
- bool automatically_create_display_roots = true);
- ~WindowEventTargetingHelper();
-
- // Creates |window| as an embeded window of the primary tree. This window is a
- // root window of its own tree, with bounds |window_bounds|. The bounds of the
- // root window of |display_| are defined by |root_window_bounds|.
- ServerWindow* CreatePrimaryTree(const gfx::Rect& root_window_bounds,
- const gfx::Rect& window_bounds);
- // Creates a secondary tree, embedded as a child of |embed_window|. The
- // resulting |window| is setup for event targeting, with bounds
- // |window_bounds|.
- // TODO(sky): rename and cleanup. This doesn't really create a new tree.
- void CreateSecondaryTree(ServerWindow* embed_window,
- const gfx::Rect& window_bounds,
- TestWindowTreeClient** out_client,
- WindowTree** window_tree,
- ServerWindow** window);
- // Sets the task runner for |message_loop_|
- void SetTaskRunner(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
-
- ui::CursorType cursor_type() const {
- return ws_test_helper_.cursor().cursor_type();
- }
- Display* display() { return display_; }
- TestWindowTreeBinding* last_binding() {
- return ws_test_helper_.window_server_delegate()->last_binding();
- }
- TestWindowTreeClient* last_window_tree_client() {
- return ws_test_helper_.window_server_delegate()->last_client();
- }
- TestWindowTreeClient* wm_client() { return wm_client_; }
- WindowServer* window_server() { return ws_test_helper_.window_server(); }
-
- TestWindowServerDelegate* test_window_server_delegate() {
- return ws_test_helper_.window_server_delegate();
- }
-
- private:
- WindowServerTestHelper ws_test_helper_;
- // TestWindowTreeClient that is used for the WM client. Owned by
- // |window_server_delegate_|
- TestWindowTreeClient* wm_client_ = nullptr;
- // Owned by WindowServer
- TestDisplayBinding* display_binding_ = nullptr;
- // Owned by WindowServer's DisplayManager.
- Display* display_ = nullptr;
- ClientSpecificId next_primary_tree_window_id_ = kEmbedTreeWindowId;
-
- DISALLOW_COPY_AND_ASSIGN(WindowEventTargetingHelper);
-};
-
-// -----------------------------------------------------------------------------
-
-class TestScreenProviderObserver : public mojom::ScreenProviderObserver {
- public:
- TestScreenProviderObserver();
- ~TestScreenProviderObserver() override;
-
- mojom::ScreenProviderObserverPtr GetPtr();
-
- std::string GetAndClearObserverCalls();
-
- private:
- std::string DisplayIdsToString(
- const std::vector<mojom::WsDisplayPtr>& wm_displays);
-
- // mojom::ScreenProviderObserver:
- void OnDisplaysChanged(std::vector<mojom::WsDisplayPtr> displays,
- int64_t primary_display_id,
- int64_t internal_display_id) override;
-
- mojo::Binding<mojom::ScreenProviderObserver> binding_;
- std::string observer_calls_;
-
- DISALLOW_COPY_AND_ASSIGN(TestScreenProviderObserver);
-};
-
-// -----------------------------------------------------------------------------
-// Empty implementation of PlatformDisplay.
-class TestPlatformDisplay : public PlatformDisplay {
- public:
- TestPlatformDisplay(const display::ViewportMetrics& metrics,
- ui::CursorData* cursor_storage);
- ~TestPlatformDisplay() override;
-
- display::Display::Rotation cursor_rotation() const {
- return cursor_rotation_;
- }
- float cursor_scale() const { return cursor_scale_; }
-
- gfx::Rect confine_cursor_bounds() const { return confine_cursor_bounds_; }
-
- const display::ViewportMetrics& metrics() const { return metrics_; }
-
- bool has_capture() const { return has_capture_; }
-
- // PlatformDisplay:
- void Init(PlatformDisplayDelegate* delegate) override;
- void SetViewportSize(const gfx::Size& size) override;
- void SetTitle(const base::string16& title) override;
- void SetCapture() override;
- void ReleaseCapture() override;
- void SetCursor(const ui::CursorData& cursor) override;
- void SetCursorSize(const ui::CursorSize& cursor_size) override;
- void ConfineCursorToBounds(const gfx::Rect& pixel_bounds) override;
- void MoveCursorTo(const gfx::Point& window_pixel_location) override;
- void UpdateTextInputState(const ui::TextInputState& state) override;
- void SetImeVisibility(bool visible) override;
- void UpdateViewportMetrics(const display::ViewportMetrics& metrics) override;
- const display::ViewportMetrics& GetViewportMetrics() override;
- gfx::AcceleratedWidget GetAcceleratedWidget() const override;
- FrameGenerator* GetFrameGenerator() override;
- EventSink* GetEventSink() override;
- void SetCursorConfig(display::Display::Rotation rotation,
- float scale) override;
-
- private:
- display::ViewportMetrics metrics_;
- ui::CursorData* cursor_storage_;
- display::Display::Rotation cursor_rotation_ =
- display::Display::Rotation::ROTATE_0;
- float cursor_scale_ = 1.0f;
- gfx::Rect confine_cursor_bounds_;
- bool has_capture_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplay);
-};
-
-// -----------------------------------------------------------------------------
-
-class CursorLocationManagerTestApi {
- public:
- CursorLocationManagerTestApi(CursorLocationManager* cursor_location_manager);
- ~CursorLocationManagerTestApi();
-
- base::subtle::Atomic32 current_cursor_location();
-
- private:
- CursorLocationManager* cursor_location_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(CursorLocationManagerTestApi);
-};
-
-// -----------------------------------------------------------------------------
-
-// Adds a WM to |window_server|. Creates WindowManagerWindowTreeFactory and
-// associated WindowTree for the WM.
-void AddWindowManager(WindowServer* window_server,
- bool automatically_create_display_roots = true);
-
-// Create a new Display object with specified origin, pixel size and device
-// scale factor. The bounds size is computed based on the pixel size and device
-// scale factor.
-display::Display MakeDisplay(int origin_x,
- int origin_y,
- int width_pixels,
- int height_pixels,
- float scale_factor);
-
-// Returns the first and only root of |tree|. If |tree| has zero or more than
-// one root returns null.
-ServerWindow* FirstRoot(WindowTree* tree);
-
-// Returns the ClientWindowId of the first root of |tree|, or an empty
-// ClientWindowId if |tree| has zero or more than one root.
-ClientWindowId FirstRootId(WindowTree* tree);
-
-// Returns |tree|s ClientWindowId for |window|.
-ClientWindowId ClientWindowIdForWindow(WindowTree* tree,
- const ServerWindow* window);
-
-// Creates a new visible window as a child of the single root of |tree|.
-// |client_id| is set to the ClientWindowId of the new window.
-ServerWindow* NewWindowInTree(WindowTree* tree,
- ClientWindowId* client_id = nullptr);
-ServerWindow* NewWindowInTreeWithParent(WindowTree* tree,
- ServerWindow* parent,
- ClientWindowId* client_id = nullptr,
- const gfx::Rect& bounds = gfx::Rect());
-
-// Converts an atomic 32 to a point. The cursor location is represented as an
-// atomic 32.
-gfx::Point Atomic32ToPoint(base::subtle::Atomic32 atomic);
-
-} // namespace test
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_TEST_UTILS_H_
diff --git a/services/ui/ws/threaded_image_cursors.cc b/services/ui/ws/threaded_image_cursors.cc
deleted file mode 100644
index f5178d7..0000000
--- a/services/ui/ws/threaded_image_cursors.cc
+++ /dev/null
@@ -1,230 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/threaded_image_cursors.h"
-
-#include "base/bind.h"
-#include "base/single_thread_task_runner.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "services/ui/common/image_cursors_set.h"
-#include "ui/base/cursor/cursor_data.h"
-#include "ui/base/cursor/image_cursors.h"
-#include "ui/platform_window/platform_window.h"
-
-#if defined(USE_OZONE)
-#include "ui/ozone/public/cursor_factory_ozone.h"
-#include "ui/ozone/public/ozone_platform.h"
-#endif
-
-namespace ui {
-namespace ws {
-namespace {
-
-void AddImageCursorsOnResourceThread(
- base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr,
- std::unique_ptr<ui::ImageCursors> image_cursors) {
- if (image_cursors_set_weak_ptr)
- image_cursors_set_weak_ptr->AddImageCursors(std::move(image_cursors));
-}
-
-void RemoveImageCursorsOnResourceThread(
- base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr,
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr) {
- if (image_cursors_set_weak_ptr && image_cursors_weak_ptr) {
- image_cursors_set_weak_ptr->DeleteImageCursors(
- image_cursors_weak_ptr.get());
- }
-}
-
-void SetDisplayOnResourceThread(
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
- const display::Display& display,
- float scale_factor) {
- if (image_cursors_weak_ptr)
- image_cursors_weak_ptr->SetDisplay(display, scale_factor);
-}
-
-void SetCursorSizeOnResourceThread(
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
- CursorSize cursor_size) {
- if (image_cursors_weak_ptr)
- image_cursors_weak_ptr->SetCursorSize(cursor_size);
-}
-
-// Executed on |resource_task_runner_|. Sets cursor type on
-// |image_cursors_set_weak_ptr_|, and then schedules a task on
-// |ui_service_task_runner_| to set the corresponding PlatformCursor on the
-// provided |platform_window|.
-// |platform_window| pointer needs to be valid while
-// |threaded_image_cursors_weak_ptr| is not invalidated.
-void SetCursorOnResourceThread(
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
- ui::CursorType cursor_type,
- ui::PlatformWindow* platform_window,
- scoped_refptr<base::SingleThreadTaskRunner> ui_service_task_runner_,
- base::WeakPtr<ThreadedImageCursors> threaded_image_cursors_weak_ptr) {
- if (image_cursors_weak_ptr) {
- ui::Cursor native_cursor(cursor_type);
- image_cursors_weak_ptr->SetPlatformCursor(&native_cursor);
- // |platform_window| is owned by the UI Service thread, so setting the
- // cursor on it also needs to happen on that thread.
- ui_service_task_runner_->PostTask(
- FROM_HERE, base::Bind(&ThreadedImageCursors::SetCursorOnPlatformWindow,
- threaded_image_cursors_weak_ptr,
- native_cursor.platform(), platform_window));
- }
-}
-
-#if defined(USE_OZONE)
-// Executed on |resource_task_runner_|. Creates a PlatformCursor using the
-// Ozone |cursor_factory| passed to it, and then schedules a task on
-// |ui_service_task_runner_| to set that cursor on the provided
-// |platform_window|.
-// |platform_window| pointer needs to be valid while
-// |threaded_image_cursors_weak_ptr| is not invalidated.
-void SetCustomCursorOnResourceThread(
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr,
- std::unique_ptr<ui::CursorData> cursor_data,
- ui::CursorFactoryOzone* cursor_factory,
- ui::PlatformWindow* platform_window,
- scoped_refptr<base::SingleThreadTaskRunner> ui_service_task_runner_,
- base::WeakPtr<ThreadedImageCursors> threaded_image_cursors_weak_ptr) {
- if (image_cursors_weak_ptr) {
- ui::PlatformCursor platform_cursor =
- cursor_data->ToNativeCursor().platform();
- // |platform_window| is owned by the UI Service thread, so setting the
- // cursor on it also needs to happen on that thread.
- ui_service_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&ThreadedImageCursors::SetCursorOnPlatformWindowAndUnref,
- threaded_image_cursors_weak_ptr, platform_cursor,
- platform_window));
- }
-}
-#endif // defined(USE_OZONE)
-
-} // namespace
-
-ThreadedImageCursors::ThreadedImageCursors(
- scoped_refptr<base::SingleThreadTaskRunner>& resource_task_runner,
- base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr)
- : resource_task_runner_(resource_task_runner),
- image_cursors_set_weak_ptr_(image_cursors_set_weak_ptr),
- weak_ptr_factory_(this) {
- DCHECK(resource_task_runner_);
- ui_service_task_runner_ = base::ThreadTaskRunnerHandle::Get();
-
- // Create and initialize the ImageCursors object here and then set it on
- // |image_cursors_set_weak_ptr_|. Note that it is essential to initialize
- // the ImageCursors object on the UI Service's thread if we are using Ozone,
- // so that it uses the right (thread-local) CursorFactoryOzone instance.
- std::unique_ptr<ui::ImageCursors> image_cursors =
- std::make_unique<ui::ImageCursors>();
- image_cursors->Initialize();
- image_cursors_weak_ptr_ = image_cursors->GetWeakPtr();
- resource_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&AddImageCursorsOnResourceThread, image_cursors_set_weak_ptr_,
- base::Passed(std::move(image_cursors))));
-}
-
-ThreadedImageCursors::~ThreadedImageCursors() {
- resource_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&RemoveImageCursorsOnResourceThread,
- image_cursors_set_weak_ptr_, image_cursors_weak_ptr_));
-}
-
-void ThreadedImageCursors::SetDisplay(const display::Display& display,
- float scale_factor) {
- resource_task_runner_->PostTask(
- FROM_HERE, base::Bind(&SetDisplayOnResourceThread,
- image_cursors_weak_ptr_, display, scale_factor));
-}
-
-void ThreadedImageCursors::SetCursorSize(CursorSize cursor_size) {
- resource_task_runner_->PostTask(
- FROM_HERE, base::Bind(&SetCursorSizeOnResourceThread,
- image_cursors_weak_ptr_, cursor_size));
-}
-
-void ThreadedImageCursors::SetCursor(const ui::CursorData& cursor_data,
- ui::PlatformWindow* platform_window) {
- ui::CursorType cursor_type = cursor_data.cursor_type();
-
-#if !defined(USE_OZONE)
- // Outside of ozone builds, there isn't a single interface for creating
- // PlatformCursors. The closest thing to one is in //content/ instead of
- // //ui/ which means we can't use it from here. For now, just don't handle
- // custom image cursors.
- //
- // TODO(erg): Once blink speaks directly to mus, make blink perform its own
- // cursor management on its own mus windows so we can remove Webcursor from
- // //content/ and do this in way that's safe cross-platform, instead of as an
- // ozone-specific hack.
- if (cursor_type == ui::CursorType::kCustom) {
- NOTIMPLEMENTED() << "No custom cursor support on non-ozone yet.";
- cursor_type = ui::CursorType::kPointer;
- }
-#else
- // In Ozone builds, we have an interface available which turns bitmap data
- // into platform cursors.
- if (cursor_type == ui::CursorType::kCustom) {
- std::unique_ptr<ui::CursorData> cursor_data_copy =
- std::make_unique<ui::CursorData>(cursor_data);
- ui::CursorFactoryOzone* cursor_factory =
- ui::CursorFactoryOzone::GetInstance();
- // CursorFactoryOzone is a thread-local singleton (crbug.com/741106).
- // However the instance that belongs to the UI Service thread is used
- // on the resource thread. (This happens via ImageCursors when we call
- // SetCursorOnResourceThread.) Since CursorFactoryOzone is not thread-safe,
- // we should only use it on the UI Service thread, which is why this
- // PostTask is needed.
- resource_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&SetCustomCursorOnResourceThread, image_cursors_weak_ptr_,
- base::Passed(&cursor_data_copy),
- base::Unretained(cursor_factory), platform_window,
- ui_service_task_runner_, weak_ptr_factory_.GetWeakPtr()));
- }
-#endif // !defined(USE_OZONE)
-
- // Handle the non-custom cursor case for both Ozone and non-Ozone builds.
- if (cursor_type != ui::CursorType::kCustom) {
- resource_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&SetCursorOnResourceThread, image_cursors_weak_ptr_,
- cursor_type, platform_window, ui_service_task_runner_,
- weak_ptr_factory_.GetWeakPtr()));
- }
-}
-
-void ThreadedImageCursors::SetCursorOnPlatformWindow(
- ui::PlatformCursor platform_cursor,
- ui::PlatformWindow* platform_window) {
- platform_window->SetCursor(platform_cursor);
-}
-
-#if defined(USE_OZONE)
-void ThreadedImageCursors::SetCursorOnPlatformWindowAndUnref(
- ui::PlatformCursor platform_cursor,
- ui::PlatformWindow* platform_window) {
- SetCursorOnPlatformWindow(platform_cursor, platform_window);
-
- // The PlatformCursor returned by CreateAnimatedCursor() has a single
- // refcount which is owned by the caller. If we were returned a valid
- // |platform_cursor|, we must unref it here. All implementations of
- // PlatformWindow::SetCursor() which need to keep the PlatformCursor have
- // increased the refcount for their self.
- //
- // Note: Cursors returned by SetPlatformCursor() do not return custom bitmap
- // cursors. The refcount of such a cursor is owned by the caller and
- // shouldn't be refed/unrefed by the caller.
- if (platform_cursor)
- ui::CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor);
-}
-#endif
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/threaded_image_cursors.h b/services/ui/ws/threaded_image_cursors.h
deleted file mode 100644
index b9ce89f..0000000
--- a/services/ui/ws/threaded_image_cursors.h
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_THREADED_IMAGE_CURSORS_H_
-#define SERVICES_UI_WS_THREADED_IMAGE_CURSORS_H_
-
-#include "base/memory/weak_ptr.h"
-#include "ui/base/cursor/cursor.h"
-
-namespace base {
-class SingleThreadTaskRunner;
-}
-
-namespace display {
-class Display;
-}
-
-namespace ui {
-class CursorData;
-class ImageCursors;
-class ImageCursorsSet;
-class PlatformWindow;
-
-namespace ws {
-
-// Wrapper around ui::ImageCursors, which executes its methods asynchronously
-// via the provided task runner. This is needed because ui::ImageCursors needs
-// to load resources when executing some of its methods, which cannot happen on
-// the UI Service's thread when it runs inside the Window Manager process.
-//
-// Unlike ImageCursors, this class can also handle CursorType::kCustom cursors,
-// which is also done asynchronously.
-//
-// Note: We could execute the methods synchronously when UI Service runs in its
-// own process (and thus the provided task runner matches the task runner of the
-// UI Service's thread), but we don't do that in the interest of sharing code.
-class ThreadedImageCursors {
- public:
- // |resource_runner| is the task runner for the thread which can be used to
- // load resources; |image_cursors_set_weak_ptr_| points to an object that
- // lives on |resource_runner|'s thread.
- // We create an ImageCursors object here and then pass the ownership to
- // |image_cursors_set_weak_ptr_|. All operations on the ImageCursors object
- // happen on |resource_runner|, which is why we need the owner to live on
- // |resource_runner|'s thread.
- ThreadedImageCursors(
- scoped_refptr<base::SingleThreadTaskRunner>& resource_task_runner,
- base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr_);
- ~ThreadedImageCursors();
-
- // Executes ui::ImageCursors::SetDisplay asynchronously.
- // Sets the display the cursors are loaded for. |scale_factor| determines the
- // size of the image to load. Returns true if the cursor image is reloaded.
- void SetDisplay(const display::Display& display, float scale_factor);
-
- // Asynchronously sets the size of the mouse cursor icon.
- void SetCursorSize(CursorSize cursor_size);
-
- // Asynchronously loads the cursor and then sets the corresponding
- // PlatformCursor on the provided |platform_window|.
- // |platform_window| pointer needs to be valid while this object is alive.
- void SetCursor(const ui::CursorData& cursor_data,
- ui::PlatformWindow* platform_window);
-
- // Helper method. Sets |platform_cursor| on the |platform_window|.
- void SetCursorOnPlatformWindow(ui::PlatformCursor platform_cursor,
- ui::PlatformWindow* platform_window);
-#if defined(USE_OZONE)
- void SetCursorOnPlatformWindowAndUnref(ui::PlatformCursor platform_cursor,
- ui::PlatformWindow* platform_window);
-#endif
-
- private:
- // The object used for performing the actual cursor operations.
- // Created on UI Service's thread, but is used on the
- // |resource_task_runner_|'s thread, because it needs to load resources.
- base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr_;
-
- // Task runner for the thread which owns the cursor resources.
- // |image_cursors_set_weak_ptr__| and |image_cursors_weak_ptr_| should only
- // be dereferenced on this task runner.
- scoped_refptr<base::SingleThreadTaskRunner> resource_task_runner_;
-
- // Task runner of the UI Service thread (where this object is created and
- // destroyed).
- scoped_refptr<base::SingleThreadTaskRunner> ui_service_task_runner_;
-
- // Lives on |resource_runner_|'s thread, used to own the object behind
- // |image_cursors_weak_ptr_|.
- base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr_;
-
- base::WeakPtrFactory<ThreadedImageCursors> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(ThreadedImageCursors);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_THREADED_IMAGE_CURSORS_H_
diff --git a/services/ui/ws/threaded_image_cursors_factory.h b/services/ui/ws/threaded_image_cursors_factory.h
deleted file mode 100644
index 1deab54..0000000
--- a/services/ui/ws/threaded_image_cursors_factory.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_THREADED_IMAGE_CURSORS_FACTORY_H_
-#define SERVICES_UI_WS_THREADED_IMAGE_CURSORS_FACTORY_H_
-
-#include <memory>
-
-namespace ui {
-namespace ws {
-class ThreadedImageCursors;
-
-class ThreadedImageCursorsFactory {
- public:
- virtual ~ThreadedImageCursorsFactory() {}
- virtual std::unique_ptr<ThreadedImageCursors> CreateCursors() = 0;
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_THREADED_IMAGE_CURSORS_FACTORY_H_
diff --git a/services/ui/ws/transient_windows_unittest.cc b/services/ui/ws/transient_windows_unittest.cc
deleted file mode 100644
index 19dca6b..0000000
--- a/services/ui/ws/transient_windows_unittest.cc
+++ /dev/null
@@ -1,191 +0,0 @@
-// 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 "base/macros.h"
-#include "base/strings/string_number_conversions.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_observer.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-namespace ws {
-
-namespace {
-
-class TestTransientWindowObserver : public ServerWindowObserver {
- public:
- TestTransientWindowObserver() : add_count_(0), remove_count_(0) {}
-
- ~TestTransientWindowObserver() override {}
-
- int add_count() const { return add_count_; }
- int remove_count() const { return remove_count_; }
-
- // TransientWindowObserver overrides:
- void OnTransientWindowAdded(ServerWindow* window,
- ServerWindow* transient) override {
- add_count_++;
- }
- void OnTransientWindowRemoved(ServerWindow* window,
- ServerWindow* transient) override {
- remove_count_++;
- }
-
- private:
- int add_count_;
- int remove_count_;
-
- DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver);
-};
-
-ServerWindow* CreateTestWindow(TestServerWindowDelegate* delegate,
- const viz::FrameSinkId& frame_sink_id,
- ServerWindow* parent) {
- ServerWindow* window = new ServerWindow(delegate, frame_sink_id);
- window->SetVisible(true);
- if (parent)
- parent->Add(window);
- else
- delegate->set_root_window(window);
- return window;
-}
-
-std::string ChildWindowIDsAsString(ServerWindow* parent) {
- std::string result;
- for (auto i = parent->children().begin(); i != parent->children().end();
- ++i) {
- if (!result.empty())
- result += " ";
- const viz::FrameSinkId& id = (*i)->frame_sink_id();
- if (id.client_id() != 0) {
- // All use cases of this expect the client_id to be 0.
- return "unexpected-client-id";
- }
- result += base::IntToString(id.sink_id());
- }
- return result;
-}
-
-} // namespace
-
-class TransientWindowsTest : public testing::Test {
- public:
- TransientWindowsTest() {}
- ~TransientWindowsTest() override {}
-
- VizHostProxy* viz_host_proxy() {
- return ws_test_helper_.window_server()->GetVizHostProxy();
- }
-
- private:
- test::WindowServerTestHelper ws_test_helper_;
-
- DISALLOW_COPY_AND_ASSIGN(TransientWindowsTest);
-};
-
-TEST_F(TransientWindowsTest, TransientChildren) {
- TestServerWindowDelegate server_window_delegate(viz_host_proxy());
-
- std::unique_ptr<ServerWindow> parent(CreateTestWindow(
- &server_window_delegate, viz::FrameSinkId(1, 0), nullptr));
- std::unique_ptr<ServerWindow> w1(CreateTestWindow(
- &server_window_delegate, viz::FrameSinkId(1, 1), parent.get()));
- std::unique_ptr<ServerWindow> w3(CreateTestWindow(
- &server_window_delegate, viz::FrameSinkId(1, 2), parent.get()));
-
- ServerWindow* w2 = CreateTestWindow(&server_window_delegate,
- viz::FrameSinkId(1, 3), parent.get());
-
- // w2 is now owned by w1.
- w1->AddTransientWindow(w2);
- // Stack w1 at the top (end), this should force w2 to be last (on top of w1).
- parent->StackChildAtTop(w1.get());
-
- // Destroy w1, which should also destroy w3 (since it's a transient child).
- w1.reset();
- w2 = nullptr;
- ASSERT_EQ(1u, parent->children().size());
- EXPECT_EQ(w3.get(), parent->children()[0]);
-}
-
-// Verifies adding doesn't restack at all.
-TEST_F(TransientWindowsTest, DontStackUponCreation) {
- TestServerWindowDelegate delegate(viz_host_proxy());
- std::unique_ptr<ServerWindow> parent(
- CreateTestWindow(&delegate, viz::FrameSinkId(0, 1), nullptr));
- std::unique_ptr<ServerWindow> window0(
- CreateTestWindow(&delegate, viz::FrameSinkId(0, 2), parent.get()));
- std::unique_ptr<ServerWindow> window1(
- CreateTestWindow(&delegate, viz::FrameSinkId(0, 3), parent.get()));
-
- ServerWindow* window2 =
- CreateTestWindow(&delegate, viz::FrameSinkId(0, 4), parent.get());
- window0->AddTransientWindow(window2);
- EXPECT_EQ("2 3 4", ChildWindowIDsAsString(parent.get()));
-}
-
-// More variations around verifying ordering doesn't change when
-// adding/removing transients.
-TEST_F(TransientWindowsTest, RestackUponAddOrRemoveTransientWindow) {
- TestServerWindowDelegate delegate(viz_host_proxy());
- std::unique_ptr<ServerWindow> parent(
- CreateTestWindow(&delegate, viz::FrameSinkId(0, 1), nullptr));
- std::unique_ptr<ServerWindow> windows[4];
- for (int i = 0; i < 4; i++)
- windows[i].reset(
- CreateTestWindow(&delegate, viz::FrameSinkId(0, i + 2), parent.get()));
-
- EXPECT_EQ("2 3 4 5", ChildWindowIDsAsString(parent.get()));
-
- windows[0]->AddTransientWindow(windows[2].get());
- EXPECT_EQ(windows[0].get(), windows[2]->transient_parent());
- ASSERT_EQ(1u, windows[0]->transient_children().size());
- EXPECT_EQ(windows[2].get(), windows[0]->transient_children()[0]);
- EXPECT_EQ("2 3 4 5", ChildWindowIDsAsString(parent.get()));
-
- windows[0]->AddTransientWindow(windows[3].get());
- EXPECT_EQ(windows[0].get(), windows[3]->transient_parent());
- ASSERT_EQ(2u, windows[0]->transient_children().size());
- EXPECT_EQ(windows[2].get(), windows[0]->transient_children()[0]);
- EXPECT_EQ(windows[3].get(), windows[0]->transient_children()[1]);
- EXPECT_EQ("2 3 4 5", ChildWindowIDsAsString(parent.get()));
-
- windows[0]->RemoveTransientWindow(windows[2].get());
- EXPECT_EQ(nullptr, windows[2]->transient_parent());
- ASSERT_EQ(1u, windows[0]->transient_children().size());
- EXPECT_EQ(windows[3].get(), windows[0]->transient_children()[0]);
- EXPECT_EQ("2 3 4 5", ChildWindowIDsAsString(parent.get()));
-
- windows[0]->RemoveTransientWindow(windows[3].get());
- EXPECT_EQ(nullptr, windows[3]->transient_parent());
- ASSERT_EQ(0u, windows[0]->transient_children().size());
- EXPECT_EQ("2 3 4 5", ChildWindowIDsAsString(parent.get()));
-}
-
-// Verifies TransientWindowObserver is notified appropriately.
-TEST_F(TransientWindowsTest, TransientWindowObserverNotified) {
- TestServerWindowDelegate delegate(viz_host_proxy());
- std::unique_ptr<ServerWindow> parent(
- CreateTestWindow(&delegate, viz::FrameSinkId(0, 1), nullptr));
- std::unique_ptr<ServerWindow> w1(
- CreateTestWindow(&delegate, viz::FrameSinkId(0, 2), parent.get()));
-
- TestTransientWindowObserver test_observer;
- parent->AddObserver(&test_observer);
-
- parent->AddTransientWindow(w1.get());
- EXPECT_EQ(1, test_observer.add_count());
- EXPECT_EQ(0, test_observer.remove_count());
-
- parent->RemoveTransientWindow(w1.get());
- EXPECT_EQ(1, test_observer.add_count());
- EXPECT_EQ(1, test_observer.remove_count());
-
- parent->RemoveObserver(&test_observer);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/user_activity_monitor.cc b/services/ui/ws/user_activity_monitor.cc
deleted file mode 100644
index 8e22d44..0000000
--- a/services/ui/ws/user_activity_monitor.cc
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/user_activity_monitor.h"
-
-#include "base/bind.h"
-#include "base/memory/ptr_util.h"
-#include "base/time/default_tick_clock.h"
-
-namespace ui {
-namespace ws {
-
-UserActivityMonitor::UserActivityMonitor(
- std::unique_ptr<const base::TickClock> clock)
- : now_clock_(std::move(clock)) {
- if (!now_clock_)
- now_clock_ = base::WrapUnique(new base::DefaultTickClock);
- last_activity_ = now_clock_->NowTicks();
-}
-
-UserActivityMonitor::~UserActivityMonitor() {}
-
-void UserActivityMonitor::OnUserActivity() {
- base::TimeTicks now = now_clock_->NowTicks();
- for (auto& pair : activity_observers_) {
- ActivityObserverInfo* info = &(pair.first);
- if (info->last_activity_notification.is_null() ||
- (now - info->last_activity_notification) > info->delay) {
- pair.second->OnUserActivity();
- info->last_activity_notification = now;
- }
- }
-
- // Wake up all the 'idle' observers.
- for (auto& pair : idle_observers_) {
- IdleObserverInfo* info = &(pair.first);
- if (info->idle_state == mojom::UserIdleObserver::IdleState::ACTIVE)
- continue;
- info->last_idle_state_notification = now;
- info->idle_state = mojom::UserIdleObserver::IdleState::ACTIVE;
- pair.second->OnUserIdleStateChanged(info->idle_state);
- }
-
- last_activity_ = now;
-
- // Start the timer if there are some idle observers.
- if (idle_timer_.IsRunning())
- idle_timer_.Reset();
-}
-
-void UserActivityMonitor::Add(mojom::UserActivityMonitorRequest request) {
- bindings_.AddBinding(this, std::move(request));
-}
-
-void UserActivityMonitor::AddUserActivityObserver(
- uint32_t delay_between_notify_secs,
- mojom::UserActivityObserverPtr observer) {
- ActivityObserverInfo info;
- info.delay = base::TimeDelta::FromSeconds(delay_between_notify_secs);
- observer.set_connection_error_handler(
- base::Bind(&UserActivityMonitor::OnActivityObserverDisconnected,
- base::Unretained(this), observer.get()));
- activity_observers_.push_back(std::make_pair(info, std::move(observer)));
-}
-
-void UserActivityMonitor::AddUserIdleObserver(
- uint32_t idleness_in_minutes,
- mojom::UserIdleObserverPtr observer) {
- IdleObserverInfo info;
- info.idle_duration = base::TimeDelta::FromMinutes(idleness_in_minutes);
- base::TimeTicks now = now_clock_->NowTicks();
- DCHECK(!last_activity_.is_null());
- bool user_is_active = (now - last_activity_ < info.idle_duration);
- info.idle_state = user_is_active ? mojom::UserIdleObserver::IdleState::ACTIVE
- : mojom::UserIdleObserver::IdleState::IDLE;
- info.last_idle_state_notification = now;
- observer->OnUserIdleStateChanged(info.idle_state);
- observer.set_connection_error_handler(
- base::Bind(&UserActivityMonitor::OnIdleObserverDisconnected,
- base::Unretained(this), observer.get()));
- idle_observers_.push_back(std::make_pair(info, std::move(observer)));
- if (user_is_active)
- ActivateIdleTimer();
-}
-
-void UserActivityMonitor::ActivateIdleTimer() {
- if (idle_timer_.IsRunning())
- return;
- idle_timer_.Start(FROM_HERE, base::TimeDelta::FromMinutes(1), this,
- &UserActivityMonitor::OnMinuteTimer);
-}
-
-void UserActivityMonitor::OnMinuteTimer() {
- base::TimeTicks now = now_clock_->NowTicks();
- bool active_observer = false;
- for (auto& pair : idle_observers_) {
- IdleObserverInfo* info = &(pair.first);
- if (info->idle_state == mojom::UserIdleObserver::IdleState::IDLE)
- continue;
- if (now - info->last_idle_state_notification < info->idle_duration) {
- active_observer = true;
- continue;
- }
- info->last_idle_state_notification = now;
- info->idle_state = mojom::UserIdleObserver::IdleState::IDLE;
- pair.second->OnUserIdleStateChanged(info->idle_state);
- }
- // All observers are already notified of IDLE. No point running the timer
- // anymore.
- if (!active_observer)
- idle_timer_.Stop();
-}
-
-void UserActivityMonitor::OnActivityObserverDisconnected(
- mojom::UserActivityObserver* observer) {
- activity_observers_.erase(std::remove_if(
- activity_observers_.begin(), activity_observers_.end(),
- [observer](const std::pair<ActivityObserverInfo,
- mojom::UserActivityObserverPtr>& pair) {
- return pair.second.get() == observer;
- }));
-}
-
-void UserActivityMonitor::OnIdleObserverDisconnected(
- mojom::UserIdleObserver* observer) {
- idle_observers_.erase(std::remove_if(
- idle_observers_.begin(), idle_observers_.end(),
- [observer](
- const std::pair<IdleObserverInfo, mojom::UserIdleObserverPtr>& pair) {
- return pair.second.get() == observer;
- }));
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/user_activity_monitor.h b/services/ui/ws/user_activity_monitor.h
deleted file mode 100644
index c892af2..0000000
--- a/services/ui/ws/user_activity_monitor.h
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_USER_ACTIVITY_MONITOR_H_
-#define SERVICES_UI_WS_USER_ACTIVITY_MONITOR_H_
-
-#include "base/time/tick_clock.h"
-#include "base/time/time.h"
-#include "base/timer/timer.h"
-#include "mojo/public/cpp/bindings/binding_set.h"
-#include "mojo/public/cpp/bindings/interface_ptr_set.h"
-#include "services/ui/public/interfaces/user_activity_monitor.mojom.h"
-
-namespace ui {
-namespace ws {
-
-namespace test {
-class UserActivityMonitorTestApi;
-}
-
-class UserActivityMonitor : public mojom::UserActivityMonitor {
- public:
- // |now_clock| is used to get the timestamp. If |now_clock| is nullptr, then
- // DefaultTickClock is used.
- explicit UserActivityMonitor(
- std::unique_ptr<const base::TickClock> now_clock);
- ~UserActivityMonitor() override;
-
- // Should be called whenever some input event is received from the user.
- void OnUserActivity();
-
- // Provides an implementation for the remote request.
- void Add(mojom::UserActivityMonitorRequest request);
-
- // mojom::UserActivityMonitor:
- void AddUserActivityObserver(
- uint32_t delay_between_notify_secs,
- mojom::UserActivityObserverPtr observer) override;
- void AddUserIdleObserver(uint32_t idleness_in_minutes,
- mojom::UserIdleObserverPtr observer) override;
-
- private:
- friend class test::UserActivityMonitorTestApi;
-
- // Makes sure the idle timer is running.
- void ActivateIdleTimer();
-
- // Called every minute when |idle_timer_| is active.
- void OnMinuteTimer();
-
- void OnActivityObserverDisconnected(mojom::UserActivityObserver* observer);
- void OnIdleObserverDisconnected(mojom::UserIdleObserver* observer);
-
- mojo::BindingSet<mojom::UserActivityMonitor> bindings_;
- std::unique_ptr<const base::TickClock> now_clock_;
-
- struct ActivityObserverInfo {
- base::TimeTicks last_activity_notification;
- base::TimeDelta delay;
- };
- std::vector<std::pair<ActivityObserverInfo, mojom::UserActivityObserverPtr>>
- activity_observers_;
-
- struct IdleObserverInfo {
- base::TimeTicks last_idle_state_notification;
- base::TimeDelta idle_duration;
- mojom::UserIdleObserver::IdleState idle_state;
- };
- std::vector<std::pair<IdleObserverInfo, mojom::UserIdleObserverPtr>>
- idle_observers_;
- // Timer used to determine user's idleness. The timer is run only when at
- // least one of the idle-observers are notified ACTIVE.
- base::RepeatingTimer idle_timer_;
- base::TimeTicks last_activity_;
-
- DISALLOW_COPY_AND_ASSIGN(UserActivityMonitor);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_USER_ACTIVITY_MONITOR_H_
diff --git a/services/ui/ws/user_activity_monitor_unittest.cc b/services/ui/ws/user_activity_monitor_unittest.cc
deleted file mode 100644
index 6ef67ba..0000000
--- a/services/ui/ws/user_activity_monitor_unittest.cc
+++ /dev/null
@@ -1,214 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/user_activity_monitor.h"
-
-#include "base/run_loop.h"
-#include "base/test/simple_test_tick_clock.h"
-#include "base/test/test_mock_time_task_runner.h"
-#include "mojo/public/cpp/bindings/interface_request.h"
-#include "services/ui/common/task_runner_test_base.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using ui::mojom::UserIdleObserver;
-
-namespace ui {
-namespace ws {
-namespace test {
-
-class TestUserActivityObserver : public mojom::UserActivityObserver {
- public:
- TestUserActivityObserver() : binding_(this) {}
- ~TestUserActivityObserver() override {}
-
- mojom::UserActivityObserverPtr GetPtr() {
- mojom::UserActivityObserverPtr ptr;
- binding_.Bind(mojo::MakeRequest(&ptr));
- return ptr;
- }
-
- bool GetAndResetReceivedUserActivity() {
- bool val = received_user_activity_;
- received_user_activity_ = false;
- return val;
- }
-
- private:
- // mojom::UserActivityObserver:
- void OnUserActivity() override { received_user_activity_ = true; }
-
- mojo::Binding<mojom::UserActivityObserver> binding_;
- bool received_user_activity_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(TestUserActivityObserver);
-};
-
-class TestUserIdleObserver : public mojom::UserIdleObserver {
- public:
- TestUserIdleObserver() : binding_(this) {}
- ~TestUserIdleObserver() override {}
-
- mojom::UserIdleObserverPtr GetPtr() {
- mojom::UserIdleObserverPtr ptr;
- binding_.Bind(mojo::MakeRequest(&ptr));
- return ptr;
- }
-
- bool GetAndResetIdleState(UserIdleObserver::IdleState* state) {
- if (!received_idle_state_)
- return false;
- received_idle_state_ = false;
- *state = idle_state_;
- return true;
- }
-
- private:
- // mojom::UserIdleObserver:
- void OnUserIdleStateChanged(UserIdleObserver::IdleState new_state) override {
- received_idle_state_ = true;
- idle_state_ = new_state;
- }
-
- mojo::Binding<mojom::UserIdleObserver> binding_;
- bool received_idle_state_ = false;
- UserIdleObserver::IdleState idle_state_ = UserIdleObserver::IdleState::ACTIVE;
-
- DISALLOW_COPY_AND_ASSIGN(TestUserIdleObserver);
-};
-
-class UserActivityMonitorTest : public TaskRunnerTestBase {
- public:
- UserActivityMonitorTest() {}
- ~UserActivityMonitorTest() override {}
-
- UserActivityMonitor* monitor() { return monitor_.get(); }
-
- private:
- // testing::Test:
- void SetUp() override {
- TaskRunnerTestBase::SetUp();
- monitor_ = std::make_unique<UserActivityMonitor>(
- task_runner()->DeprecatedGetMockTickClock());
- }
-
- std::unique_ptr<UserActivityMonitor> monitor_;
-
- DISALLOW_COPY_AND_ASSIGN(UserActivityMonitorTest);
-};
-
-TEST_F(UserActivityMonitorTest, UserActivityObserver) {
- TestUserActivityObserver first_observer, second_observer;
- monitor()->AddUserActivityObserver(3, first_observer.GetPtr());
- monitor()->AddUserActivityObserver(4, second_observer.GetPtr());
-
- // The first activity should notify both observers.
- monitor()->OnUserActivity();
- RunUntilIdle();
- EXPECT_TRUE(first_observer.GetAndResetReceivedUserActivity());
- EXPECT_TRUE(second_observer.GetAndResetReceivedUserActivity());
-
- // The next activity after just one second should not notify either observer.
- RunTasksForNext(base::TimeDelta::FromSeconds(1));
- monitor()->OnUserActivity();
- RunUntilIdle();
- EXPECT_FALSE(first_observer.GetAndResetReceivedUserActivity());
- EXPECT_FALSE(second_observer.GetAndResetReceivedUserActivity());
-
- RunTasksForNext(base::TimeDelta::FromMilliseconds(2001));
- monitor()->OnUserActivity();
- RunUntilIdle();
- EXPECT_TRUE(first_observer.GetAndResetReceivedUserActivity());
- EXPECT_FALSE(second_observer.GetAndResetReceivedUserActivity());
-
- RunTasksForNext(base::TimeDelta::FromSeconds(1));
- monitor()->OnUserActivity();
- RunUntilIdle();
- EXPECT_FALSE(first_observer.GetAndResetReceivedUserActivity());
- EXPECT_TRUE(second_observer.GetAndResetReceivedUserActivity());
-}
-
-// Tests that idleness observers receive the correct notification upon
-// connection.
-TEST_F(UserActivityMonitorTest, UserIdleObserverConnectNotification) {
- UserIdleObserver::IdleState idle_state;
-
- // If an observer is added without any user activity, then it still receives
- // an ACTIVE notification immediately.
- TestUserIdleObserver first_observer;
- monitor()->AddUserIdleObserver(1, first_observer.GetPtr());
- RunUntilIdle();
- EXPECT_TRUE(first_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::ACTIVE, idle_state);
-
- // If an observer is added without any user activity and the system has been
- // idle, then the observer receives an IDLE notification immediately.
- RunTasksForNext(base::TimeDelta::FromMinutes(5));
- TestUserIdleObserver second_observer;
- monitor()->AddUserIdleObserver(4, second_observer.GetPtr());
- RunUntilIdle();
- EXPECT_TRUE(second_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::IDLE, idle_state);
- EXPECT_TRUE(first_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::IDLE, idle_state);
-
- // If an observer is added after some user activity, then it receives an
- // immediate ACTIVE notification.
- monitor()->OnUserActivity();
- TestUserIdleObserver third_observer;
- monitor()->AddUserIdleObserver(1, third_observer.GetPtr());
- RunUntilIdle();
- EXPECT_TRUE(third_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::ACTIVE, idle_state);
- EXPECT_TRUE(second_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::ACTIVE, idle_state);
- EXPECT_TRUE(first_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::ACTIVE, idle_state);
-
- RunTasksForNext(base::TimeDelta::FromMinutes(10));
- TestUserIdleObserver fourth_observer;
- monitor()->AddUserIdleObserver(1, fourth_observer.GetPtr());
- RunUntilIdle();
- EXPECT_TRUE(fourth_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::IDLE, idle_state);
- EXPECT_TRUE(third_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::IDLE, idle_state);
- EXPECT_TRUE(second_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::IDLE, idle_state);
- EXPECT_TRUE(first_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::IDLE, idle_state);
-
- // All observers are idle. These should not receive any IDLE notifications as
- // more time passes by.
- RunTasksForNext(base::TimeDelta::FromMinutes(100));
- RunUntilIdle();
- EXPECT_FALSE(first_observer.GetAndResetIdleState(&idle_state));
- EXPECT_FALSE(second_observer.GetAndResetIdleState(&idle_state));
- EXPECT_FALSE(third_observer.GetAndResetIdleState(&idle_state));
- EXPECT_FALSE(fourth_observer.GetAndResetIdleState(&idle_state));
-
- // Some activity would notify ACTIVE to all observers.
- monitor()->OnUserActivity();
- RunUntilIdle();
- EXPECT_TRUE(fourth_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::ACTIVE, idle_state);
- EXPECT_TRUE(third_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::ACTIVE, idle_state);
- EXPECT_TRUE(second_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::ACTIVE, idle_state);
- EXPECT_TRUE(first_observer.GetAndResetIdleState(&idle_state));
- EXPECT_EQ(UserIdleObserver::IdleState::ACTIVE, idle_state);
-
- // Yet more activity should not send any notifications.
- monitor()->OnUserActivity();
- RunUntilIdle();
- EXPECT_FALSE(first_observer.GetAndResetIdleState(&idle_state));
- EXPECT_FALSE(second_observer.GetAndResetIdleState(&idle_state));
- EXPECT_FALSE(third_observer.GetAndResetIdleState(&idle_state));
- EXPECT_FALSE(fourth_observer.GetAndResetIdleState(&idle_state));
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/user_display_manager.cc b/services/ui/ws/user_display_manager.cc
deleted file mode 100644
index 1fb692d..0000000
--- a/services/ui/ws/user_display_manager.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/user_display_manager.h"
-
-#include <utility>
-
-#include "services/ui/display/screen_manager.h"
-#include "services/ui/ws/user_display_manager_delegate.h"
-#include "ui/display/display.h"
-#include "ui/display/screen_base.h"
-#include "ui/display/types/display_constants.h"
-
-namespace ui {
-namespace ws {
-
-UserDisplayManager::UserDisplayManager(UserDisplayManagerDelegate* delegate)
- : delegate_(delegate),
- got_valid_frame_decorations_(delegate->GetFrameDecorations(nullptr)) {}
-
-UserDisplayManager::~UserDisplayManager() {}
-
-void UserDisplayManager::DisableAutomaticNotification() {
- DCHECK(notify_automatically_);
- notify_automatically_ = false;
-}
-
-void UserDisplayManager::CallOnDisplaysChanged() {
- observers_.ForAllPtrs([this](mojom::ScreenProviderObserver* observer) {
- CallOnDisplaysChanged(observer);
- });
-}
-
-void UserDisplayManager::OnFrameDecorationValuesChanged() {
- got_valid_frame_decorations_ = true;
- CallOnDisplaysChangedIfNecessary();
-}
-
-void UserDisplayManager::AddDisplayManagerBinding(
- mojo::InterfaceRequest<mojom::ScreenProvider> request) {
- bindings_.AddBinding(this, std::move(request));
-}
-
-void UserDisplayManager::OnDisplayUpdated(const display::Display& display) {
- CallOnDisplaysChangedIfNecessary();
-}
-
-void UserDisplayManager::OnDisplayDestroyed(int64_t display_id) {
- CallOnDisplaysChangedIfNecessary();
-}
-
-void UserDisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) {
- CallOnDisplaysChangedIfNecessary();
-}
-
-void UserDisplayManager::AddObserver(
- mojom::ScreenProviderObserverPtr observer) {
- mojom::ScreenProviderObserver* observer_impl = observer.get();
- observers_.AddPtr(std::move(observer));
- OnObserverAdded(observer_impl);
-}
-
-void UserDisplayManager::OnObserverAdded(
- mojom::ScreenProviderObserver* observer) {
- // Many clients key off the frame decorations to size widgets. Wait for frame
- // decorations before notifying so that we don't have to worry about clients
- // resizing appropriately.
- if (!ShouldCallOnDisplaysChanged())
- return;
-
- CallOnDisplaysChanged(observer);
-}
-
-mojom::WsDisplayPtr UserDisplayManager::ToWsDisplayPtr(
- const display::Display& display) {
- mojom::WsDisplayPtr ws_display = mojom::WsDisplay::New();
- ws_display->display = display;
- delegate_->GetFrameDecorations(&ws_display->frame_decoration_values);
- return ws_display;
-}
-
-std::vector<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() {
- const auto& displays =
- display::ScreenManager::GetInstance()->GetScreen()->GetAllDisplays();
-
- std::vector<mojom::WsDisplayPtr> ws_display;
- ws_display.reserve(displays.size());
-
- for (const auto& display : displays)
- ws_display.push_back(ToWsDisplayPtr(display));
-
- return ws_display;
-}
-
-bool UserDisplayManager::ShouldCallOnDisplaysChanged() const {
- return got_valid_frame_decorations_ && !display::ScreenManager::GetInstance()
- ->GetScreen()
- ->GetAllDisplays()
- .empty();
-}
-
-void UserDisplayManager::CallOnDisplaysChangedIfNecessary() {
- if (!notify_automatically_ || !ShouldCallOnDisplaysChanged())
- return;
-
- CallOnDisplaysChanged();
-}
-
-void UserDisplayManager::CallOnDisplaysChanged(
- mojom::ScreenProviderObserver* observer) {
- observer->OnDisplaysChanged(GetAllDisplays(),
- display::ScreenManager::GetInstance()
- ->GetScreen()
- ->GetPrimaryDisplay()
- .id(),
- delegate_->GetInternalDisplayId());
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/user_display_manager.h b/services/ui/ws/user_display_manager.h
deleted file mode 100644
index e0205466..0000000
--- a/services/ui/ws/user_display_manager.h
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_USER_DISPLAY_MANAGER_H_
-#define SERVICES_UI_WS_USER_DISPLAY_MANAGER_H_
-
-#include <vector>
-
-#include "base/macros.h"
-#include "mojo/public/cpp/bindings/binding_set.h"
-#include "mojo/public/cpp/bindings/interface_ptr_set.h"
-#include "services/ui/public/interfaces/screen_provider.mojom.h"
-
-namespace display {
-class Display;
-}
-
-namespace ui {
-namespace ws {
-
-class UserDisplayManagerDelegate;
-
-// Provides per user display state.
-// TODO(sky): merge this with ui::ws::DisplayManager (and rename).
-class UserDisplayManager : public mojom::ScreenProvider {
- public:
- UserDisplayManager(UserDisplayManagerDelegate* delegate);
- ~UserDisplayManager() override;
-
- void DisableAutomaticNotification();
-
- // Unconditionally calls OnDisplayChanged() on observers.
- void CallOnDisplaysChanged();
-
- // Called when the frame decorations for this user change.
- void OnFrameDecorationValuesChanged();
-
- void AddDisplayManagerBinding(
- mojo::InterfaceRequest<mojom::ScreenProvider> request);
-
- // Called when something about the display (e.g. pixel-ratio, size) changes.
- void OnDisplayUpdated(const display::Display& display);
-
- // Called when the display with |display_id| was removed.
- void OnDisplayDestroyed(int64_t display_id);
-
- // Called when the primary display changes.
- void OnPrimaryDisplayChanged(int64_t primary_display_id);
-
- // mojom::ScreenProvider:
- void AddObserver(mojom::ScreenProviderObserverPtr observer) override;
-
- private:
- // Called when a new observer is added. If frame decorations are available
- // notifies the observer immediately.
- void OnObserverAdded(mojom::ScreenProviderObserver* observer);
-
- // Fills in a WsDisplayPtr for |display|.
- mojom::WsDisplayPtr ToWsDisplayPtr(const display::Display& display);
-
- std::vector<mojom::WsDisplayPtr> GetAllDisplays();
-
- bool ShouldCallOnDisplaysChanged() const;
-
- // Calls OnDisplaysChanged() on all observers.
- void CallOnDisplaysChangedIfNecessary();
-
- // Calls OnDisplaysChanged() on |observer|.
- void CallOnDisplaysChanged(mojom::ScreenProviderObserver* observer);
-
- UserDisplayManagerDelegate* delegate_;
-
- // Set to true the first time at least one Display has valid frame values.
- bool got_valid_frame_decorations_;
-
- mojo::BindingSet<mojom::ScreenProvider> bindings_;
-
- // WARNING: only use these once |got_valid_frame_decorations_| is true.
- mojo::InterfacePtrSet<mojom::ScreenProviderObserver> observers_;
-
- // If true DisplayManagerObservers are notified any time there is a display
- // change. If false, observers are only notified when CallOnDisplaysChanged()
- // is explicitly called. This value is true in automatic display creation and
- // false when in manual mode.
- bool notify_automatically_ = true;
-
- DISALLOW_COPY_AND_ASSIGN(UserDisplayManager);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_USER_DISPLAY_MANAGER_H_
diff --git a/services/ui/ws/user_display_manager_delegate.h b/services/ui/ws/user_display_manager_delegate.h
deleted file mode 100644
index 70bb641..0000000
--- a/services/ui/ws/user_display_manager_delegate.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_USER_DISPLAY_MANAGER_DELEGATE_H_
-#define SERVICES_UI_WS_USER_DISPLAY_MANAGER_DELEGATE_H_
-
-#include <stdint.h>
-
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class UserDisplayManagerDelegate {
- public:
- // Gets the frame decorations. Returns true if the decorations have been set,
- // false otherwise. |values| may be null.
- virtual bool GetFrameDecorations(mojom::FrameDecorationValuesPtr* values) = 0;
-
- virtual int64_t GetInternalDisplayId() = 0;
-
- protected:
- virtual ~UserDisplayManagerDelegate() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_USER_DISPLAY_MANAGER_DELEGATE_H_
diff --git a/services/ui/ws/user_display_manager_unittest.cc b/services/ui/ws/user_display_manager_unittest.cc
deleted file mode 100644
index b57f11dd..0000000
--- a/services/ui/ws/user_display_manager_unittest.cc
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/user_display_manager.h"
-
-#include <stdint.h>
-
-#include <string>
-
-#include "base/macros.h"
-#include "base/strings/string_number_conversions.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "mojo/public/cpp/bindings/interface_request.h"
-#include "services/ui/common/task_runner_test_base.h"
-#include "services/ui/common/types.h"
-#include "services/ui/common/util.h"
-#include "services/ui/display/screen_manager.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_utils.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_manager_window_tree_factory.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-namespace {
-
-mojom::FrameDecorationValuesPtr CreateDefaultFrameDecorationValues() {
- return mojom::FrameDecorationValues::New();
-}
-
-} // namespace
-
-// -----------------------------------------------------------------------------
-
-class UserDisplayManagerTest : public TaskRunnerTestBase {
- public:
- UserDisplayManagerTest() {}
- ~UserDisplayManagerTest() override {}
-
- WindowServer* window_server() { return ws_test_helper_.window_server(); }
- TestWindowServerDelegate* window_server_delegate() {
- return ws_test_helper_.window_server_delegate();
- }
-
- TestScreenManager& screen_manager() { return screen_manager_; }
-
- private:
- // testing::Test:
- void SetUp() override {
- TaskRunnerTestBase::SetUp();
- screen_manager_.Init(window_server()->display_manager());
- }
-
- WindowServerTestHelper ws_test_helper_;
- TestScreenManager screen_manager_;
- DISALLOW_COPY_AND_ASSIGN(UserDisplayManagerTest);
-};
-
-TEST_F(UserDisplayManagerTest, OnlyNotifyWhenFrameDecorationsSet) {
- screen_manager().AddDisplay();
-
- TestScreenProviderObserver screen_provider_observer;
- DisplayManager* display_manager = window_server()->display_manager();
- AddWindowManager(window_server());
- UserDisplayManager* user_display_manager =
- display_manager->GetUserDisplayManager();
- ASSERT_TRUE(user_display_manager);
- user_display_manager->AddObserver(screen_provider_observer.GetPtr());
- RunUntilIdle();
-
- // Observer should not have been notified yet.
- EXPECT_EQ(std::string(), screen_provider_observer.GetAndClearObserverCalls());
-
- // Set the frame decoration values, which should trigger sending immediately.
- ASSERT_EQ(1u, display_manager->displays().size());
- window_server()->GetWindowManagerState()->SetFrameDecorationValues(
- CreateDefaultFrameDecorationValues());
- RunUntilIdle();
-
- EXPECT_EQ("OnDisplaysChanged 1 -1",
- screen_provider_observer.GetAndClearObserverCalls());
-}
-
-TEST_F(UserDisplayManagerTest, AddObserverAfterFrameDecorationsSet) {
- screen_manager().AddDisplay();
-
- TestScreenProviderObserver screen_provider_observer;
- DisplayManager* display_manager = window_server()->display_manager();
- AddWindowManager(window_server());
- UserDisplayManager* user_display_manager =
- display_manager->GetUserDisplayManager();
- ASSERT_TRUE(user_display_manager);
- ASSERT_EQ(1u, display_manager->displays().size());
- window_server()->GetWindowManagerState()->SetFrameDecorationValues(
- CreateDefaultFrameDecorationValues());
-
- user_display_manager->AddObserver(screen_provider_observer.GetPtr());
- RunUntilIdle();
-
- EXPECT_EQ("OnDisplaysChanged 1 -1",
- screen_provider_observer.GetAndClearObserverCalls());
-}
-
-TEST_F(UserDisplayManagerTest, AddRemoveDisplay) {
- screen_manager().AddDisplay();
-
- TestScreenProviderObserver screen_provider_observer;
- DisplayManager* display_manager = window_server()->display_manager();
- AddWindowManager(window_server());
- UserDisplayManager* user_display_manager =
- display_manager->GetUserDisplayManager();
- ASSERT_TRUE(user_display_manager);
- ASSERT_EQ(1u, display_manager->displays().size());
- window_server()->GetWindowManagerState()->SetFrameDecorationValues(
- CreateDefaultFrameDecorationValues());
- user_display_manager->AddObserver(screen_provider_observer.GetPtr());
- RunUntilIdle();
-
- EXPECT_EQ("OnDisplaysChanged 1 -1",
- screen_provider_observer.GetAndClearObserverCalls());
-
- // Add another display.
- const int64_t second_display_id = screen_manager().AddDisplay();
- RunUntilIdle();
-
- // Observer should be notified immediately as frame decorations were set.
- EXPECT_EQ("OnDisplaysChanged 1 2 -1",
- screen_provider_observer.GetAndClearObserverCalls());
-
- // Remove the display and verify observer is notified.
- screen_manager().RemoveDisplay(second_display_id);
- RunUntilIdle();
-
- EXPECT_EQ("OnDisplaysChanged 1 -1",
- screen_provider_observer.GetAndClearObserverCalls());
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/video_detector_impl.cc b/services/ui/ws/video_detector_impl.cc
deleted file mode 100644
index e74d2e1..0000000
--- a/services/ui/ws/video_detector_impl.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/video_detector_impl.h"
-
-#include "components/viz/host/host_frame_sink_manager.h"
-
-namespace ui {
-namespace ws {
-
-VideoDetectorImpl::VideoDetectorImpl(
- viz::HostFrameSinkManager* host_frame_sink_manager)
- : host_frame_sink_manager_(host_frame_sink_manager) {}
-
-VideoDetectorImpl::~VideoDetectorImpl() = default;
-
-void VideoDetectorImpl::AddBinding(mojom::VideoDetectorRequest request) {
- binding_set_.AddBinding(this, std::move(request));
-}
-
-void VideoDetectorImpl::AddObserver(
- viz::mojom::VideoDetectorObserverPtr observer) {
- host_frame_sink_manager_->AddVideoDetectorObserver(std::move(observer));
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/video_detector_impl.h b/services/ui/ws/video_detector_impl.h
deleted file mode 100644
index 77170fd71..0000000
--- a/services/ui/ws/video_detector_impl.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef SERVICES_UI_WS_VIDEO_DETECTOR_IMPL_H_
-#define SERVICES_UI_WS_VIDEO_DETECTOR_IMPL_H_
-
-#include "mojo/public/cpp/bindings/binding_set.h"
-#include "services/ui/public/interfaces/video_detector.mojom.h"
-#include "services/viz/public/interfaces/compositing/video_detector_observer.mojom.h"
-
-namespace viz {
-class HostFrameSinkManager;
-}
-
-namespace ui {
-namespace ws {
-
-// WS-side representation of viz::VideoDetector. Internally forwards observer
-// requests to viz.
-// TODO(crbug.com/780514): If we restart viz the observers won't receive
-// notifications anymore. This needs to be fixed.
-class VideoDetectorImpl : public mojom::VideoDetector {
- public:
- explicit VideoDetectorImpl(
- viz::HostFrameSinkManager* host_frame_sink_manager);
- ~VideoDetectorImpl() override;
-
- void AddBinding(mojom::VideoDetectorRequest request);
-
- // mojom::VideoDetector implementation.
- void AddObserver(viz::mojom::VideoDetectorObserverPtr observer) override;
-
- private:
- viz::HostFrameSinkManager* host_frame_sink_manager_;
- mojo::BindingSet<mojom::VideoDetector> binding_set_;
-
- DISALLOW_COPY_AND_ASSIGN(VideoDetectorImpl);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_VIDEO_DETECTOR_IMPL_H_
diff --git a/services/ui/ws/window_coordinate_conversions.cc b/services/ui/ws/window_coordinate_conversions.cc
deleted file mode 100644
index 264b7c1..0000000
--- a/services/ui/ws/window_coordinate_conversions.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/window_coordinate_conversions.h"
-
-#include "services/ui/ws/server_window.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/point3_f.h"
-#include "ui/gfx/geometry/point_f.h"
-#include "ui/gfx/transform.h"
-
-namespace ui {
-namespace ws {
-namespace {
-
-gfx::Transform GetTransformToRoot(const ServerWindow* root,
- const ServerWindow* window) {
- gfx::Transform transform;
- const ServerWindow* w = window;
- for (; w && w != root; w = w->parent()) {
- gfx::Transform translation;
- translation.Translate(static_cast<float>(w->bounds().x()),
- static_cast<float>(w->bounds().y()));
- if (!w->transform().IsIdentity())
- transform.ConcatTransform(w->transform());
- transform.ConcatTransform(translation);
- }
- // Allow the root to also have a transform. This mirrors how
- // WindowManagerDisplayRoot works. Ash sets the transform for rotation as well
- // as ui scale.
- if (w == root && !w->transform().IsIdentity())
- transform.ConcatTransform(w->transform());
- return transform;
-}
-
-} // namespace
-
-gfx::Point ConvertPointFromRootForEventDispatch(
- const ServerWindow* root,
- const ServerWindow* window,
- const gfx::Point& location_in_root) {
- // This code should only be called when |window| is connected to a display.
- DCHECK(root);
-
- if (root == window)
- return location_in_root;
-
- const gfx::Transform transform = GetTransformToRoot(root, window);
- gfx::Point3F location_in_root3(gfx::PointF{location_in_root});
- transform.TransformPointReverse(&location_in_root3);
-
- return gfx::ToFlooredPoint(location_in_root3.AsPointF());
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_coordinate_conversions.h b/services/ui/ws/window_coordinate_conversions.h
deleted file mode 100644
index f871bb6..0000000
--- a/services/ui/ws/window_coordinate_conversions.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_COORDINATE_CONVERSIONS_H_
-#define SERVICES_UI_WS_WINDOW_COORDINATE_CONVERSIONS_H_
-
-namespace gfx {
-class Point;
-}
-
-namespace ui {
-namespace ws {
-
-class ServerWindow;
-
-// Converts |point|, in the coordinates of the root, to that of |window|.
-gfx::Point ConvertPointFromRootForEventDispatch(const ServerWindow* root,
- const ServerWindow* window,
- const gfx::Point& point);
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_COORDINATE_CONVERSIONS_H_
diff --git a/services/ui/ws/window_coordinate_conversions_unittest.cc b/services/ui/ws/window_coordinate_conversions_unittest.cc
deleted file mode 100644
index 5e25ec80..0000000
--- a/services/ui/ws/window_coordinate_conversions_unittest.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2017 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 "services/ui/ws/window_coordinate_conversions.h"
-
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-namespace ws {
-
-class WindowCoordinateConversions : public testing::Test {
- public:
- WindowCoordinateConversions() {}
- ~WindowCoordinateConversions() override {}
-
- VizHostProxy* viz_host_proxy() {
- return ws_test_helper_.window_server()->GetVizHostProxy();
- }
-
- private:
- test::WindowServerTestHelper ws_test_helper_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowCoordinateConversions);
-};
-
-TEST_F(WindowCoordinateConversions, Transform) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- root.set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
- ServerWindow child(&window_delegate, viz::FrameSinkId(1, 3));
- root.Add(&child);
- child.SetVisible(true);
- child.SetBounds(gfx::Rect(0, 0, 20, 20), base::nullopt);
- // Make the root |child|, and set a transform on |child|, which mirrors
- // how WindowManagerState and EventDispatcher work together.
- window_delegate.set_root_window(&child);
- gfx::Transform transform;
- transform.Scale(SkIntToMScalar(2), SkIntToMScalar(2));
- child.SetTransform(transform);
-
- ServerWindow child_child(&window_delegate, viz::FrameSinkId(1, 4));
- child.Add(&child_child);
- child_child.SetVisible(true);
- child_child.SetBounds(gfx::Rect(4, 6, 12, 24), base::nullopt);
-
- const gfx::Point converted_point = ConvertPointFromRootForEventDispatch(
- &child, &child_child, gfx::Point(14, 20));
- EXPECT_EQ(gfx::Point(3, 4), converted_point);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_finder.cc b/services/ui/ws/window_finder.cc
deleted file mode 100644
index 1f99e99..0000000
--- a/services/ui/ws/window_finder.cc
+++ /dev/null
@@ -1,180 +0,0 @@
-// 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 "services/ui/ws/window_finder.h"
-
-#include "base/containers/adapters.h"
-#include "services/ui/ws/server_window.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/point3_f.h"
-#include "ui/gfx/geometry/point_f.h"
-#include "ui/gfx/transform.h"
-
-namespace ui {
-namespace ws {
-namespace {
-
-bool IsLocationInNonclientArea(const ServerWindow* target,
- const gfx::Point& location) {
- if (!target->parent() || target->bounds().size().IsEmpty())
- return false;
-
- gfx::Rect client_area(target->bounds().size());
- client_area.Inset(target->client_area());
- if (client_area.Contains(location))
- return false;
-
- for (const auto& rect : target->additional_client_areas()) {
- if (rect.Contains(location))
- return false;
- }
-
- return true;
-}
-
-bool ShouldUseExtendedHitRegion(const ServerWindow* window) {
- if (!window->parent())
- return false;
-
- const mojom::ShowState show_state = window->GetShowState();
- if (show_state == mojom::ShowState::MAXIMIZED ||
- show_state == mojom::ShowState::FULLSCREEN) {
- return false;
- }
- // This matches the logic of EasyResizeWindowTargeter.
- return !window->transient_parent() ||
- window->transient_parent() == window->parent();
-}
-
-// Returns true if |location_in_window| is in the extended hit region and not
-// in the normal bounds of |window|.
-bool IsLocationInExtendedHitRegion(EventSource event_source,
- const ServerWindow* window,
- const gfx::Point& location_in_window) {
- if (!ShouldUseExtendedHitRegion(window))
- return false;
-
- const gfx::Insets& extended_hit_insets =
- event_source == EventSource::MOUSE
- ? window->parent()->extended_mouse_hit_test_region()
- : window->parent()->extended_touch_hit_test_region();
- if (extended_hit_insets.IsEmpty())
- return false;
-
- gfx::Rect child_bounds(window->bounds().size());
- if (child_bounds.Contains(location_in_window))
- return false;
-
- child_bounds.Inset(extended_hit_insets);
- return child_bounds.Contains(location_in_window);
-}
-
-gfx::Transform TransformFromParent(const ServerWindow* window,
- const gfx::Transform& current_transform) {
- gfx::Transform result = current_transform;
- if (window->bounds().origin() != gfx::Point()) {
- gfx::Transform translation;
- translation.Translate(static_cast<float>(window->bounds().x()),
- static_cast<float>(window->bounds().y()));
- result.PreconcatTransform(translation);
- }
- if (!window->transform().IsIdentity())
- result.PreconcatTransform(window->transform());
- return result;
-}
-
-bool FindDeepestVisibleWindowForLocationImpl(
- ServerWindow* window,
- bool is_root_window,
- EventSource event_source,
- const gfx::Point& location_in_root,
- const gfx::Point& location_in_window,
- const gfx::Transform& transform_from_parent,
- DeepestWindow* deepest_window) {
- // The non-client area takes precedence over descendants, as otherwise the
- // user would likely not be able to hit the non-client area as it's common
- // for descendants to go into the non-client area.
- //
- // Display roots aren't allowed to have non-client areas. This is important
- // as roots may have a transform, which causes problem in comparing sizes.
- if (!is_root_window &&
- IsLocationInNonclientArea(window, location_in_window)) {
- deepest_window->window = window;
- deepest_window->in_non_client_area = true;
- return true;
- }
- const mojom::EventTargetingPolicy event_targeting_policy =
- window->event_targeting_policy();
-
- if (event_targeting_policy == ui::mojom::EventTargetingPolicy::NONE)
- return false;
-
- if (event_targeting_policy ==
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS ||
- event_targeting_policy == mojom::EventTargetingPolicy::DESCENDANTS_ONLY) {
- const ServerWindow::Windows& children = window->children();
- for (ServerWindow* child : base::Reversed(children)) {
- if (!child->visible())
- continue;
-
- const gfx::Transform child_transform =
- TransformFromParent(child, transform_from_parent);
- gfx::Point3F location_in_child3(gfx::PointF{location_in_root});
- child_transform.TransformPointReverse(&location_in_child3);
- const gfx::Point location_in_child =
- gfx::ToFlooredPoint(location_in_child3.AsPointF());
- if (IsLocationInExtendedHitRegion(event_source, child,
- location_in_child)) {
- deepest_window->window = child;
- deepest_window->in_non_client_area = true;
- return true;
- }
- gfx::Rect child_bounds(child->bounds().size());
- if (!child_bounds.Contains(location_in_child) ||
- (child->hit_test_mask() &&
- !child->hit_test_mask()->Contains(location_in_child))) {
- continue;
- }
-
- const bool child_is_root = false;
- if (FindDeepestVisibleWindowForLocationImpl(
- child, child_is_root, event_source, location_in_root,
- location_in_child, child_transform, deepest_window)) {
- return true;
- }
- }
- }
-
- if (event_targeting_policy == mojom::EventTargetingPolicy::DESCENDANTS_ONLY)
- return false;
-
- deepest_window->window = window;
- deepest_window->in_non_client_area = false;
- return true;
-}
-
-} // namespace
-
-DeepestWindow FindDeepestVisibleWindowForLocation(ServerWindow* root_window,
- EventSource event_source,
- const gfx::Point& location) {
- gfx::Point initial_location = location;
- gfx::Transform root_transform = root_window->transform();
- if (!root_transform.IsIdentity()) {
- gfx::Point3F transformed_location(gfx::PointF{initial_location});
- root_transform.TransformPointReverse(&transformed_location);
- initial_location = gfx::ToFlooredPoint(transformed_location.AsPointF());
- }
- DeepestWindow result;
- // Allow the root to have a transform, which mirrors what happens with
- // WindowManagerDisplayRoot.
- const bool is_root_window = true;
- FindDeepestVisibleWindowForLocationImpl(
- root_window, is_root_window, event_source, location, initial_location,
- root_transform, &result);
- return result;
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_finder.h b/services/ui/ws/window_finder.h
deleted file mode 100644
index 5a461d2..0000000
--- a/services/ui/ws/window_finder.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_FINDER_H_
-#define SERVICES_UI_WS_WINDOW_FINDER_H_
-
-#include "components/viz/host/hit_test/hit_test_query.h"
-
-namespace gfx {
-class Point;
-}
-
-namespace ui {
-namespace ws {
-
-class ServerWindow;
-
-struct DeepestWindow {
- ServerWindow* window = nullptr;
- bool in_non_client_area = false;
-};
-
-using EventSource = viz::EventSource;
-
-// Finds the deepest visible child of |root| that should receive an event at
-// |location|. |location| is in the coordinate space of |root_window|. The
-// |window| field in the returned structure is set to the child window. If no
-// valid child window is found |window| is set to null.
-DeepestWindow FindDeepestVisibleWindowForLocation(ServerWindow* root_window,
- EventSource event_source,
- const gfx::Point& location);
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_FINDER_H_
diff --git a/services/ui/ws/window_finder_unittest.cc b/services/ui/ws/window_finder_unittest.cc
deleted file mode 100644
index f6a28af..0000000
--- a/services/ui/ws/window_finder_unittest.cc
+++ /dev/null
@@ -1,319 +0,0 @@
-// 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 "services/ui/ws/window_finder.h"
-
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-namespace ws {
-
-class WindowFinderTest : public testing::Test {
- public:
- WindowFinderTest() {}
- ~WindowFinderTest() override {}
-
- VizHostProxy* viz_host_proxy() {
- return ws_test_helper_.window_server()->GetVizHostProxy();
- }
-
- private:
- test::WindowServerTestHelper ws_test_helper_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowFinderTest);
-};
-
-TEST_F(WindowFinderTest, FindDeepestVisibleWindow) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- root.set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- window_delegate.set_root_window(&root);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
-
- ServerWindow child1(&window_delegate, viz::FrameSinkId(1, 3));
- root.Add(&child1);
- child1.SetVisible(true);
- child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt);
-
- ServerWindow child2(&window_delegate, viz::FrameSinkId(1, 4));
- root.Add(&child2);
- child2.SetVisible(true);
- child2.SetBounds(gfx::Rect(15, 15, 20, 20), base::nullopt);
-
- EXPECT_EQ(&child2, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(16, 16))
- .window);
-
- EXPECT_EQ(&child1, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(13, 14))
- .window);
-
- child1.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE);
- EXPECT_EQ(nullptr, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(13, 14))
- .window);
-
- root.set_extended_hit_test_regions_for_children(gfx::Insets(-1, -1, -1, -1),
- gfx::Insets(-2, -2, -2, -2));
- EXPECT_EQ(&child2, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(14, 14))
- .window);
- EXPECT_EQ(nullptr, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(13, 13))
- .window);
- EXPECT_EQ(&child2, FindDeepestVisibleWindowForLocation(
- &root, EventSource::TOUCH, gfx::Point(13, 13))
- .window);
-}
-
-TEST_F(WindowFinderTest, FindDeepestVisibleWindowNonClientArea) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- window_delegate.set_root_window(&root);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
-
- ServerWindow child1(&window_delegate, viz::FrameSinkId(1, 3));
- root.Add(&child1);
- child1.SetVisible(true);
- child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt);
-
- DeepestWindow result = FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(13, 14));
- EXPECT_EQ(&child1, result.window);
- EXPECT_FALSE(result.in_non_client_area);
-
- result = FindDeepestVisibleWindowForLocation(&root, EventSource::MOUSE,
- gfx::Point(11, 11));
- EXPECT_EQ(&child1, result.window);
- EXPECT_FALSE(result.in_non_client_area);
-
- // 11, 11 is over the non-client area.
- child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>());
- result = FindDeepestVisibleWindowForLocation(&root, EventSource::MOUSE,
- gfx::Point(11, 11));
- EXPECT_EQ(&child1, result.window);
- EXPECT_TRUE(result.in_non_client_area);
-
- // 15, 15 is over the client area.
- result = FindDeepestVisibleWindowForLocation(&root, EventSource::MOUSE,
- gfx::Point(15, 15));
- EXPECT_EQ(&child1, result.window);
- EXPECT_FALSE(result.in_non_client_area);
-
- // EventTargetingPolicy::NONE should not impact the result for the
- // non-client area.
- child1.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE);
- result = FindDeepestVisibleWindowForLocation(&root, EventSource::MOUSE,
- gfx::Point(11, 11));
- child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>());
- EXPECT_EQ(&child1, result.window);
- EXPECT_TRUE(result.in_non_client_area);
-
- // EventTargetingPolicy::NONE means the client area won't be matched though.
- result = FindDeepestVisibleWindowForLocation(&root, EventSource::MOUSE,
- gfx::Point(15, 15));
- EXPECT_EQ(&root, result.window);
- EXPECT_FALSE(result.in_non_client_area);
-}
-
-TEST_F(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- window_delegate.set_root_window(&root);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
-
- ServerWindow child_with_mask(&window_delegate, viz::FrameSinkId(1, 4));
- root.Add(&child_with_mask);
- child_with_mask.SetVisible(true);
- child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt);
- child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16));
-
- // Test a point inside the window but outside the mask.
- EXPECT_EQ(&root, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(11, 11))
- .window);
-
- // Test a point inside the window and inside the mask.
- EXPECT_EQ(&child_with_mask, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(15, 15))
- .window);
-}
-
-TEST_F(WindowFinderTest, FindDeepestVisibleWindowOverNonTarget) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- window_delegate.set_root_window(&root);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
-
- // Create two windows, |child1| and |child2|. The two overlap but |child2| is
- // not a valid event target.
- ServerWindow child1(&window_delegate, viz::FrameSinkId(1, 3));
- root.Add(&child1);
- child1.SetVisible(true);
- child1.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt);
-
- ServerWindow child2(&window_delegate, viz::FrameSinkId(1, 4));
- root.Add(&child2);
- child2.set_event_targeting_policy(mojom::EventTargetingPolicy::NONE);
- child2.SetVisible(true);
- child2.SetBounds(gfx::Rect(15, 15, 20, 20), base::nullopt);
-
- // 16, 16 is over |child2| and |child1|, but as |child2| isn't a valid event
- // target |child1| should be picked.
- EXPECT_EQ(&child1, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(16, 16))
- .window);
-}
-
-TEST_F(WindowFinderTest, NonClientPreferredOverChild) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- window_delegate.set_root_window(&root);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
-
- // Create two windows, |child| and |child_child|; |child| is a child of the
- // root and |child_child| and child of |child|. All share the same size with
- // |child| having a non-client area.
- ServerWindow child(&window_delegate, viz::FrameSinkId(1, 3));
- root.Add(&child);
- child.SetVisible(true);
- child.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
- child.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>());
-
- ServerWindow child_child(&window_delegate, viz::FrameSinkId(1, 4));
- child.Add(&child_child);
- child_child.SetVisible(true);
- child_child.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
-
- // |child| was should be returned as the event is over the non-client area.
- EXPECT_EQ(&child, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(1, 1))
- .window);
-}
-
-TEST_F(WindowFinderTest, FindDeepestVisibleWindowWithTransform) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- root.set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- window_delegate.set_root_window(&root);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
- ServerWindow child(&window_delegate, viz::FrameSinkId(1, 3));
- root.Add(&child);
- child.SetVisible(true);
- child.SetBounds(gfx::Rect(10, 10, 20, 20), base::nullopt);
- gfx::Transform transform;
- transform.Scale(SkIntToMScalar(2), SkIntToMScalar(2));
- child.SetTransform(transform);
-
- EXPECT_EQ(&child, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(49, 49))
- .window);
- EXPECT_EQ(nullptr, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(9, 9))
- .window);
-
- ServerWindow child_child(&window_delegate, viz::FrameSinkId(1, 4));
- child.Add(&child_child);
- child_child.SetVisible(true);
- child_child.SetBounds(gfx::Rect(12, 12, 4, 4), base::nullopt);
-
- EXPECT_EQ(&child, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(30, 30))
- .window);
- EXPECT_EQ(&child_child, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(35, 35))
- .window);
-
- // Verify extended hit test with transform is picked up.
- root.set_extended_hit_test_regions_for_children(gfx::Insets(-2, -2, -2, -2),
- gfx::Insets(-2, -2, -2, -2));
- EXPECT_EQ(&child, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(7, 7))
- .window);
- EXPECT_EQ(nullptr, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(4, 4))
- .window);
-}
-
-TEST_F(WindowFinderTest, FindDeepestVisibleWindowWithTransformOnParent) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- root.set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
- ServerWindow child(&window_delegate, viz::FrameSinkId(1, 3));
- root.Add(&child);
- child.SetVisible(true);
- child.SetBounds(gfx::Rect(10, 10, 10, 10), base::nullopt);
- // Make the root child, but the transform is set on the parent. This mirrors
- // how WindowManagerState and EventDispatcher work together.
- window_delegate.set_root_window(&child);
- gfx::Transform transform;
- transform.Scale(SkIntToMScalar(2), SkIntToMScalar(2));
- root.SetTransform(transform);
-
- EXPECT_EQ(&child, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(25, 25))
- .window);
- EXPECT_EQ(nullptr, FindDeepestVisibleWindowForLocation(
- &root, EventSource::MOUSE, gfx::Point(52, 52))
- .window);
-}
-
-// Creates the following window hierarchy:
-// root
-// |- c1 (has .5x transform, and is used as the root in
-// FindDeepestVisibleWindowForLocation).
-// |- c2
-// |- c3
-// With various assertions around hit testing.
-TEST_F(WindowFinderTest,
- FindDeepestVisibleWindowWithTransformOnParentMagnified) {
- TestServerWindowDelegate window_delegate(viz_host_proxy());
- ServerWindow root(&window_delegate, viz::FrameSinkId(1, 2));
- root.set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- root.SetVisible(true);
- root.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
- window_delegate.set_root_window(&root);
- ServerWindow c1(&window_delegate, viz::FrameSinkId(1, 3));
- root.Add(&c1);
- c1.SetVisible(true);
- c1.SetBounds(gfx::Rect(0, 0, 100, 100), base::nullopt);
- gfx::Transform transform;
- transform.Scale(SkFloatToMScalar(.5f), SkFloatToMScalar(.5f));
- c1.SetTransform(transform);
-
- ServerWindow c2(&window_delegate, viz::FrameSinkId(1, 4));
- c1.Add(&c2);
- c2.SetVisible(true);
- c2.SetBounds(gfx::Rect(0, 0, 200, 200), base::nullopt);
-
- ServerWindow c3(&window_delegate, viz::FrameSinkId(1, 5));
- c2.Add(&c3);
- c3.SetVisible(true);
- c3.SetBounds(gfx::Rect(0, 190, 200, 10), base::nullopt);
-
- EXPECT_EQ(&c2, FindDeepestVisibleWindowForLocation(&c1, EventSource::MOUSE,
- gfx::Point(55, 55))
- .window);
- EXPECT_EQ(&c3, FindDeepestVisibleWindowForLocation(&c1, EventSource::MOUSE,
- gfx::Point(0, 99))
- .window);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_manager_access_policy.cc b/services/ui/ws/window_manager_access_policy.cc
deleted file mode 100644
index fe53b8e..0000000
--- a/services/ui/ws/window_manager_access_policy.cc
+++ /dev/null
@@ -1,238 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/window_manager_access_policy.h"
-
-#include "services/ui/ws/access_policy_delegate.h"
-#include "services/ui/ws/server_window.h"
-
-namespace ui {
-namespace ws {
-
-WindowManagerAccessPolicy::WindowManagerAccessPolicy() {}
-
-WindowManagerAccessPolicy::~WindowManagerAccessPolicy() {}
-
-void WindowManagerAccessPolicy::Init(ClientSpecificId client_id,
- AccessPolicyDelegate* delegate) {
- client_id_ = client_id;
- delegate_ = delegate;
-}
-
-bool WindowManagerAccessPolicy::CanRemoveWindowFromParent(
- const ServerWindow* window) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanAddWindow(const ServerWindow* parent,
- const ServerWindow* child) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanAddTransientWindow(
- const ServerWindow* parent,
- const ServerWindow* child) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanRemoveTransientWindowFromParent(
- const ServerWindow* window) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanSetModal(
- const ServerWindow* window) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanSetChildModalParent(
- const ServerWindow* window,
- const ServerWindow* modal_parent) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanReorderWindow(
- const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanDeleteWindow(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool WindowManagerAccessPolicy::CanGetWindowTree(
- const ServerWindow* window) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanDescendIntoWindowForWindowTree(
- const ServerWindow* window) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanEmbed(const ServerWindow* window) const {
- return !delegate_->HasRootForAccessPolicy(window);
-}
-
-bool WindowManagerAccessPolicy::CanChangeWindowVisibility(
- const ServerWindow* window) const {
- if (WasCreatedByThisClient(window))
- return true;
- // The WindowManager can change the visibility of the WindowManager root.
- const ServerWindow* root = window->GetRootForDrawn();
- return root && window->parent() == root;
-}
-
-bool WindowManagerAccessPolicy::CanChangeWindowOpacity(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool WindowManagerAccessPolicy::CanSetWindowCompositorFrameSink(
- const ServerWindow* window) const {
- if (delegate_->IsWindowRootOfAnotherTreeForAccessPolicy(window))
- return false;
-
- return WasCreatedByThisClient(window) ||
- (delegate_->HasRootForAccessPolicy(window));
-}
-
-bool WindowManagerAccessPolicy::CanSetWindowBounds(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool WindowManagerAccessPolicy::CanSetWindowTransform(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool WindowManagerAccessPolicy::CanSetWindowProperties(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool WindowManagerAccessPolicy::CanSetWindowTextInputState(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool WindowManagerAccessPolicy::CanSetCapture(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window);
-}
-
-bool WindowManagerAccessPolicy::CanSetFocus(const ServerWindow* window) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanSetClientArea(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool WindowManagerAccessPolicy::CanSetHitTestMask(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool WindowManagerAccessPolicy::CanSetAcceptDrops(
- const ServerWindow* window) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanSetEventTargetingPolicy(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool WindowManagerAccessPolicy::CanStackAbove(
- const ServerWindow* above,
- const ServerWindow* below) const {
- // This API is for clients. Window managers can perform any arbitrary
- // reordering of the windows and don't need to go through this constrained
- // API.
- return false;
-}
-
-bool WindowManagerAccessPolicy::CanStackAtTop(
- const ServerWindow* window) const {
- // This API is for clients. Window managers can perform any arbitrary
- // reordering of the windows and don't need to go through this constrained
- // API.
- return false;
-}
-
-bool WindowManagerAccessPolicy::CanPerformWmAction(
- const ServerWindow* window) const {
- // This API is for clients. Window managers don't need to tell themselves to
- // do things.
- return false;
-}
-
-bool WindowManagerAccessPolicy::CanSetCursorProperties(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool WindowManagerAccessPolicy::CanInitiateDragLoop(
- const ServerWindow* window) const {
- return WasCreatedByThisClient(window) ||
- delegate_->HasRootForAccessPolicy(window);
-}
-
-bool WindowManagerAccessPolicy::CanInitiateMoveLoop(
- const ServerWindow* window) const {
- return false;
-}
-
-bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
- const ServerWindow* window,
- const ServerWindow** new_parent,
- const ServerWindow** old_parent) const {
- // Notify if we've already told the window manager about the window, or if
- // we've
- // already told the window manager about the parent. The later handles the
- // case of a window that wasn't parented to the root getting added to the
- // root.
- return IsWindowKnown(window) || (*new_parent && IsWindowKnown(*new_parent));
-}
-
-bool WindowManagerAccessPolicy::CanSetWindowManager() const {
- return true;
-}
-
-const ServerWindow* WindowManagerAccessPolicy::GetWindowForFocusChange(
- const ServerWindow* focused) {
- return focused;
-}
-
-bool WindowManagerAccessPolicy::IsWindowKnown(
- const ServerWindow* window) const {
- return delegate_->IsWindowKnownForAccessPolicy(window);
-}
-
-bool WindowManagerAccessPolicy::IsValidIdForNewWindow(
- const ClientWindowId& id) const {
- // The WindowManager see windows created from other clients. If the WM doesn't
- // use the client id when creating windows the WM could end up with two
- // windows with the same id. Because of this the wm must use the same
- // client id for all windows it creates.
- return base::checked_cast<ClientSpecificId>(id.client_id()) == client_id_;
-}
-
-bool WindowManagerAccessPolicy::WasCreatedByThisClient(
- const ServerWindow* window) const {
- return window->owning_tree_id() == client_id_;
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_manager_access_policy.h b/services/ui/ws/window_manager_access_policy.h
deleted file mode 100644
index ab2d475..0000000
--- a/services/ui/ws/window_manager_access_policy.h
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_MANAGER_ACCESS_POLICY_H_
-#define SERVICES_UI_WS_WINDOW_MANAGER_ACCESS_POLICY_H_
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "services/ui/ws/access_policy.h"
-
-namespace ui {
-namespace ws {
-
-class AccessPolicyDelegate;
-
-class WindowManagerAccessPolicy : public AccessPolicy {
- public:
- WindowManagerAccessPolicy();
- ~WindowManagerAccessPolicy() override;
-
- // AccessPolicy:
- void Init(ClientSpecificId client_id,
- AccessPolicyDelegate* delegate) override;
- bool CanRemoveWindowFromParent(const ServerWindow* window) const override;
- bool CanAddWindow(const ServerWindow* parent,
- const ServerWindow* child) const override;
- bool CanAddTransientWindow(const ServerWindow* parent,
- const ServerWindow* child) const override;
- bool CanRemoveTransientWindowFromParent(
- const ServerWindow* window) const override;
- bool CanSetModal(const ServerWindow* window) const override;
- bool CanSetChildModalParent(const ServerWindow* window,
- const ServerWindow* modal_parent) const override;
- bool CanReorderWindow(const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction) const override;
- bool CanDeleteWindow(const ServerWindow* window) const override;
- bool CanGetWindowTree(const ServerWindow* window) const override;
- bool CanDescendIntoWindowForWindowTree(
- const ServerWindow* window) const override;
- bool CanEmbed(const ServerWindow* window) const override;
- bool CanChangeWindowVisibility(const ServerWindow* window) const override;
- bool CanChangeWindowOpacity(const ServerWindow* window) const override;
- bool CanSetWindowCompositorFrameSink(
- const ServerWindow* window) const override;
- bool CanSetWindowBounds(const ServerWindow* window) const override;
- bool CanSetWindowTransform(const ServerWindow* window) const override;
- bool CanSetWindowProperties(const ServerWindow* window) const override;
- bool CanSetWindowTextInputState(const ServerWindow* window) const override;
- bool CanSetCapture(const ServerWindow* window) const override;
- bool CanSetFocus(const ServerWindow* window) const override;
- bool CanSetClientArea(const ServerWindow* window) const override;
- bool CanSetHitTestMask(const ServerWindow* window) const override;
- bool CanSetAcceptDrops(const ServerWindow* window) const override;
- bool CanSetEventTargetingPolicy(const ServerWindow* window) const override;
- bool CanStackAbove(const ServerWindow* above,
- const ServerWindow* below) const override;
- bool CanStackAtTop(const ServerWindow* window) const override;
- bool CanPerformWmAction(const ServerWindow* window) const override;
- bool CanSetCursorProperties(const ServerWindow* window) const override;
- bool CanInitiateDragLoop(const ServerWindow* window) const override;
- bool CanInitiateMoveLoop(const ServerWindow* window) const override;
- bool ShouldNotifyOnHierarchyChange(
- const ServerWindow* window,
- const ServerWindow** new_parent,
- const ServerWindow** old_parent) const override;
- const ServerWindow* GetWindowForFocusChange(
- const ServerWindow* focused) override;
- bool CanSetWindowManager() const override;
- bool IsValidIdForNewWindow(const ClientWindowId& id) const override;
-
- private:
- bool IsWindowKnown(const ServerWindow* window) const;
- bool WasCreatedByThisClient(const ServerWindow* window) const;
-
- ClientSpecificId client_id_ = 0u;
- AccessPolicyDelegate* delegate_ = nullptr;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerAccessPolicy);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_MANAGER_ACCESS_POLICY_H_
diff --git a/services/ui/ws/window_manager_client_unittest.cc b/services/ui/ws/window_manager_client_unittest.cc
deleted file mode 100644
index b0c0217..0000000
--- a/services/ui/ws/window_manager_client_unittest.cc
+++ /dev/null
@@ -1,874 +0,0 @@
-// Copyright 2014 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 <stddef.h>
-#include <stdint.h>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/run_loop.h"
-#include "services/ui/common/util.h"
-#include "services/ui/ws/test_utils.h"
-#include "services/ui/ws/window_server_test_base.h"
-#include "ui/aura/client/transient_window_client.h"
-#include "ui/aura/env.h"
-#include "ui/aura/mus/embed_root.h"
-#include "ui/aura/mus/embed_root_delegate.h"
-#include "ui/aura/mus/window_port_mus.h"
-#include "ui/aura/mus/window_tree_client.h"
-#include "ui/aura/mus/window_tree_client_delegate.h"
-#include "ui/aura/mus/window_tree_host_mus.h"
-#include "ui/aura/mus/window_tree_host_mus_init_params.h"
-#include "ui/aura/test/mus/change_completion_waiter.h"
-#include "ui/aura/test/mus/test_window_manager_delegate.h"
-#include "ui/aura/test/mus/window_tree_client_private.h"
-#include "ui/aura/window.h"
-#include "ui/aura/window_observer.h"
-#include "ui/aura/window_tracker.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace ui {
-namespace ws {
-
-namespace {
-
-Id server_id(aura::Window* window) {
- return aura::WindowMus::Get(window)->server_id();
-}
-
-aura::Window* GetChildWindowByServerId(aura::WindowTreeClient* client, Id id) {
- return aura::WindowTreeClientPrivate(client).GetWindowByServerId(id);
-}
-
-class BoundsChangeObserver : public aura::WindowObserver {
- public:
- explicit BoundsChangeObserver(aura::Window* window) : window_(window) {
- window_->AddObserver(this);
- }
- ~BoundsChangeObserver() override { window_->RemoveObserver(this); }
-
- private:
- // Overridden from WindowObserver:
- void OnWindowBoundsChanged(aura::Window* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- ui::PropertyChangeReason reason) override {
- DCHECK_EQ(window, window_);
- EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
- }
-
- aura::Window* window_;
-
- DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver);
-};
-
-// Wait until the bounds of the supplied window change; returns false on
-// timeout.
-bool WaitForBoundsToChange(aura::Window* window) {
- BoundsChangeObserver observer(window);
- return WindowServerTestBase::DoRunLoopWithTimeout();
-}
-
-// Spins a run loop until the tree beginning at |root| has |tree_size| windows
-// (including |root|).
-class TreeSizeMatchesObserver : public aura::WindowObserver {
- public:
- TreeSizeMatchesObserver(aura::Window* tree, size_t tree_size)
- : tree_(tree), tree_size_(tree_size) {
- tree_->AddObserver(this);
- }
- ~TreeSizeMatchesObserver() override { tree_->RemoveObserver(this); }
-
- bool IsTreeCorrectSize() { return CountWindows(tree_) == tree_size_; }
-
- private:
- // Overridden from WindowObserver:
- void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override {
- if (IsTreeCorrectSize())
- EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
- }
-
- size_t CountWindows(const aura::Window* window) const {
- size_t count = 1;
- for (const aura::Window* child : window->children())
- count += CountWindows(child);
- return count;
- }
-
- aura::Window* tree_;
- size_t tree_size_;
-
- DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver);
-};
-
-// Wait until |window| has |tree_size| descendants; returns false on timeout.
-// The count includes |window|. For example, if you want to wait for |window| to
-// have a single child, use a |tree_size| of 2.
-bool WaitForTreeSizeToMatch(aura::Window* window, size_t tree_size) {
- TreeSizeMatchesObserver observer(window, tree_size);
- return observer.IsTreeCorrectSize() ||
- WindowServerTestBase::DoRunLoopWithTimeout();
-}
-
-class StackingOrderChangeObserver : public aura::WindowObserver {
- public:
- StackingOrderChangeObserver(aura::Window* window) : window_(window) {
- window_->AddObserver(this);
- }
- ~StackingOrderChangeObserver() override { window_->RemoveObserver(this); }
-
- private:
- // Overridden from aura::WindowObserver:
- void OnWindowStackingChanged(aura::Window* window) override {
- DCHECK_EQ(window, window_);
- EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
- }
-
- aura::Window* window_;
-
- DISALLOW_COPY_AND_ASSIGN(StackingOrderChangeObserver);
-};
-
-// Wait until |window|'s tree size matches |tree_size|; returns false on
-// timeout.
-bool WaitForStackingOrderChange(aura::Window* window) {
- StackingOrderChangeObserver observer(window);
- return WindowServerTestBase::DoRunLoopWithTimeout();
-}
-
-// Tracks a window's destruction. Query is_valid() for current state.
-class WindowTracker : public aura::WindowObserver {
- public:
- explicit WindowTracker(aura::Window* window) : window_(window) {
- window_->AddObserver(this);
- }
- ~WindowTracker() override {
- if (window_)
- window_->RemoveObserver(this);
- }
-
- bool is_valid() const { return !!window_; }
-
- private:
- // Overridden from WindowObserver:
- void OnWindowDestroyed(aura::Window* window) override {
- DCHECK_EQ(window, window_);
- window_ = nullptr;
- }
-
- aura::Window* window_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTracker);
-};
-
-// Creates a new visible Window. If |parent| is non-null the newly created
-// window is added to it.
-aura::Window* NewVisibleWindow(
- aura::Window* parent,
- aura::WindowTreeClient* client,
- aura::WindowMusType type = aura::WindowMusType::LOCAL) {
- std::unique_ptr<aura::WindowPortMus> window_port_mus =
- std::make_unique<aura::WindowPortMus>(client, type);
- aura::Window* window = new aura::Window(nullptr, std::move(window_port_mus));
- window->Init(ui::LAYER_NOT_DRAWN);
- window->Show();
- if (parent)
- parent->AddChild(window);
- return window;
-}
-
-} // namespace
-
-// WindowServer
-// -----------------------------------------------------------------
-
-struct EmbedResult {
- bool IsValid() const {
- return window_tree_client.get() != nullptr &&
- window_tree_host.get() != nullptr;
- }
-
- std::unique_ptr<aura::WindowTreeClient> window_tree_client;
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host;
-};
-
-aura::Window* GetFirstRoot(aura::WindowTreeClient* client) {
- return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin();
-}
-
-// These tests model synchronization of two peer clients of the window server,
-// that are given access to some root window.
-
-class WindowServerTest : public WindowServerTestBase {
- public:
- struct ClientAreaChange {
- aura::Window* window = nullptr;
- gfx::Insets insets;
- };
-
- WindowServerTest() {}
-
- aura::Window* GetFirstWMRoot() { return GetFirstRoot(window_manager()); }
-
- // Embeds another version of the test app @ window. This runs a run loop until
- // a response is received, or a timeout. The return value is always non-null,
- // but if there is an error there is no WindowTreeClient. Always use
- // ASSERT_EQ(result->IsValid()) on the return value.
- std::unique_ptr<EmbedResult> Embed(aura::WindowTreeClient* window_tree_client,
- aura::Window* window) {
- DCHECK(!embed_details_);
- embed_details_ = std::make_unique<EmbedDetails>();
- window_tree_client->Embed(window, ConnectAndGetWindowServerClient(), 0,
- base::Bind(&WindowServerTest::EmbedCallbackImpl,
- base::Unretained(this)));
- if (embed_details_->callback_run) {
- // The callback was run immediately, this indicates an immediate failure,
- // such as |window| has children.
- EXPECT_FALSE(embed_details_->embed_result);
- embed_details_.reset();
- return std::make_unique<EmbedResult>();
- }
- // Wait for EmbedCallbackImpl() to be called with the result.
- embed_details_->waiting = true;
- if (!WindowServerTestBase::DoRunLoopWithTimeout()) {
- embed_details_.reset();
- return std::make_unique<EmbedResult>();
- }
- std::unique_ptr<EmbedResult> result = std::move(embed_details_->result);
- embed_details_.reset();
- return result;
- }
-
- // Establishes a connection to this application and asks for a
- // WindowTreeClient.
- ui::mojom::WindowTreeClientPtr ConnectAndGetWindowServerClient() {
- ui::mojom::WindowTreeClientPtr client;
- connector()->BindInterface(test_name(), &client);
- return client;
- }
-
- std::unique_ptr<ClientAreaChange> WaitForClientAreaToChange() {
- client_area_change_ = std::make_unique<ClientAreaChange>();
- // The nested run loop is quit in OnWmSetClientArea(). Client area
- // changes don't route through the window, only the WindowManagerDelegate.
- if (!WindowServerTestBase::DoRunLoopWithTimeout()) {
- client_area_change_.reset();
- return nullptr;
- }
- return std::move(client_area_change_);
- }
-
- // WindowServerTestBase:
- void OnEmbed(
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override {
- if (!embed_details_) {
- WindowServerTestBase::OnEmbed(std::move(window_tree_host));
- return;
- }
-
- embed_details_->result->window_tree_host = std::move(window_tree_host);
- embed_details_->result->window_tree_client = ReleaseMostRecentClient();
- if (embed_details_->callback_run)
- EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
- }
- void OnWmSetClientArea(
- aura::Window* window,
- const gfx::Insets& insets,
- const std::vector<gfx::Rect>& additional_client_areas) override {
- if (!client_area_change_.get())
- return;
-
- client_area_change_->window = window;
- client_area_change_->insets = insets;
- EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
- }
-
- private:
- // Used to track the state of a call to window->Embed().
- struct EmbedDetails {
- EmbedDetails() : result(std::make_unique<EmbedResult>()) {}
-
- // The callback function supplied to Embed() was called.
- bool callback_run = false;
-
- // The boolean supplied to the Embed() callback.
- bool embed_result = false;
-
- // Whether a MessageLoop is running.
- bool waiting = false;
-
- std::unique_ptr<EmbedResult> result;
- };
-
- void EmbedCallbackImpl(bool result) {
- embed_details_->callback_run = true;
- embed_details_->embed_result = result;
- if (embed_details_->waiting &&
- (!result || embed_details_->result->window_tree_client))
- EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
- }
-
- std::unique_ptr<EmbedDetails> embed_details_;
-
- std::unique_ptr<ClientAreaChange> client_area_change_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowServerTest);
-};
-
-TEST_F(WindowServerTest, RootWindow) {
- ASSERT_NE(nullptr, window_manager());
- EXPECT_EQ(1u, window_manager()->GetRoots().size());
-}
-
-TEST_F(WindowServerTest, Embed) {
- aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
- ASSERT_TRUE(embed_result->IsValid());
-
- aura::Window* embed_root = embed_result->window_tree_host->window();
- // WindowTreeHost::window() is the single root of the embed.
- EXPECT_EQ(1u, embed_result->window_tree_client->GetRoots().size());
- EXPECT_EQ(embed_root, GetFirstRoot(embed_result->window_tree_client.get()));
- EXPECT_EQ(ClientWindowIdFromTransportId(server_id(window)),
- ClientWindowIdFromTransportId(server_id(embed_root)));
- EXPECT_NE(0u, ClientIdFromTransportId(server_id(embed_root)));
- EXPECT_EQ(nullptr, embed_root->parent());
- EXPECT_TRUE(embed_root->children().empty());
-}
-
-// Window manager has two windows, N1 and N11. Embeds A at N1. A should not see
-// N11.
-TEST_F(WindowServerTest, EmbeddedDoesntSeeChild) {
- aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
- ASSERT_TRUE(embed_result->IsValid());
- aura::Window* embed_root = embed_result->window_tree_host->window();
- EXPECT_EQ(ClientWindowIdFromTransportId(server_id(window)),
- ClientWindowIdFromTransportId(server_id(embed_root)));
- EXPECT_NE(0u, ClientIdFromTransportId(server_id(embed_root)));
- EXPECT_EQ(nullptr, embed_root->parent());
- EXPECT_TRUE(embed_root->children().empty());
-}
-
-// TODO(beng): write a replacement test for the one that once existed here:
-// This test validates the following scenario:
-// - a window originating from one client
-// - a window originating from a second client
-// + the client originating the window is destroyed
-// -> the window should still exist (since the second client is live) but
-// should be disconnected from any windows.
-// http://crbug.com/396300
-//
-// TODO(beng): The new test should validate the scenario as described above
-// except that the second client still has a valid tree.
-
-// Verifies that bounds changes applied to a window hierarchy in one client
-// are reflected to another.
-TEST_F(WindowServerTest, SetBounds) {
- aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
-
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
- ASSERT_TRUE(embed_result->IsValid());
- aura::Window* embed_root = embed_result->window_tree_host->window();
- EXPECT_EQ(window->bounds(), embed_root->bounds());
-
- window->SetBounds(gfx::Rect(0, 0, 100, 100));
- ASSERT_TRUE(WaitForBoundsToChange(embed_root));
- EXPECT_EQ(window->bounds(), embed_root->bounds());
-}
-
-// Verifies that bounds changes applied to a window owned by a different
-// client can be refused.
-TEST_F(WindowServerTest, SetBoundsSecurity) {
- aura::TestWindowManagerDelegate wm_delegate;
- set_window_manager_delegate(&wm_delegate);
-
- aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
-
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
- ASSERT_TRUE(embed_result->IsValid());
- aura::Window* embed_root = embed_result->window_tree_host->window();
- window->SetBounds(gfx::Rect(0, 0, 800, 600));
- ASSERT_TRUE(WaitForBoundsToChange(embed_root));
-
- embed_result->window_tree_host->SetBoundsInPixels(gfx::Rect(0, 0, 1024, 768));
- // Bounds change is initially accepted, but the server declines the request.
- EXPECT_NE(window->bounds(), embed_root->bounds());
-
- // The client is notified when the requested is declined, and updates the
- // local bounds accordingly.
- ASSERT_TRUE(WaitForBoundsToChange(embed_root));
- EXPECT_EQ(window->bounds(), embed_root->bounds());
- set_window_manager_delegate(nullptr);
-}
-
-// Verifies that a root window can always be destroyed.
-TEST_F(WindowServerTest, DestroySecurity) {
- aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
-
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
- ASSERT_TRUE(embed_result->IsValid());
- aura::Window* embed_root = embed_result->window_tree_host->window();
-
- // The root can be destroyed, even though it was not created by the client.
- aura::WindowTracker tracker;
- tracker.Add(window);
- tracker.Add(embed_root);
- embed_result->window_tree_host.reset();
- EXPECT_FALSE(tracker.Contains(embed_root));
- EXPECT_TRUE(tracker.Contains(window));
-
- delete window;
- EXPECT_FALSE(tracker.Contains(window));
-}
-
-TEST_F(WindowServerTest, MultiRoots) {
- aura::Window* window1 = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
- aura::Window* window2 = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
- std::unique_ptr<EmbedResult> embed_result1 = Embed(window_manager(), window1);
- ASSERT_TRUE(embed_result1->IsValid());
- std::unique_ptr<EmbedResult> embed_result2 = Embed(window_manager(), window2);
- ASSERT_TRUE(embed_result2->IsValid());
-}
-
-TEST_F(WindowServerTest, Reorder) {
- aura::Window* window1 = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
-
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window1);
- ASSERT_TRUE(embed_result->IsValid());
- aura::WindowTreeClient* embedded = embed_result->window_tree_client.get();
- aura::Window* embed_root = embed_result->window_tree_host->window();
-
- aura::Window* window11 = NewVisibleWindow(embed_root, embedded);
- aura::Window* window12 = NewVisibleWindow(embed_root, embedded);
- ASSERT_TRUE(WaitForTreeSizeToMatch(window1, 3u));
-
- // |embedded|'s WindowTree has an id_ of embedded_client_id, so window11's
- // client_id part should be embedded_client_id in the WindowTree for
- // window_manager(). Similar for window12.
- Id embedded_client_id = test::kWindowManagerClientId + 1;
- Id window11_in_wm = embedded_client_id << 32 |
- ClientWindowIdFromTransportId(server_id(window11));
- Id window12_in_wm = embedded_client_id << 32 |
- ClientWindowIdFromTransportId(server_id(window12));
-
- {
- window11->parent()->StackChildAtTop(window11);
- // The |embedded| tree should be updated immediately.
- EXPECT_EQ(embed_root->children().front(),
- GetChildWindowByServerId(embedded, server_id(window12)));
- EXPECT_EQ(embed_root->children().back(),
- GetChildWindowByServerId(embedded, server_id(window11)));
-
- // The window_manager() tree is still not updated.
- EXPECT_EQ(window1->children().back(),
- GetChildWindowByServerId(window_manager(), window12_in_wm));
-
- // Wait until window_manager() tree is updated.
- ASSERT_TRUE(WaitForStackingOrderChange(
- GetChildWindowByServerId(window_manager(), window11_in_wm)));
- EXPECT_EQ(window1->children().front(),
- GetChildWindowByServerId(window_manager(), window12_in_wm));
- EXPECT_EQ(window1->children().back(),
- GetChildWindowByServerId(window_manager(), window11_in_wm));
- }
-
- {
- window11->parent()->StackChildAtBottom(window11);
- // |embedded| should be updated immediately.
- EXPECT_EQ(embed_root->children().front(),
- GetChildWindowByServerId(embedded, server_id(window11)));
- EXPECT_EQ(embed_root->children().back(),
- GetChildWindowByServerId(embedded, server_id(window12)));
-
- // |window_manager()| is also eventually updated.
- EXPECT_EQ(window1->children().back(),
- GetChildWindowByServerId(window_manager(), window11_in_wm));
- ASSERT_TRUE(WaitForStackingOrderChange(
- GetChildWindowByServerId(window_manager(), window11_in_wm)));
- EXPECT_EQ(window1->children().front(),
- GetChildWindowByServerId(window_manager(), window11_in_wm));
- EXPECT_EQ(window1->children().back(),
- GetChildWindowByServerId(window_manager(), window12_in_wm));
- }
-}
-
-namespace {
-
-class VisibilityChangeObserver : public aura::WindowObserver {
- public:
- explicit VisibilityChangeObserver(aura::Window* window) : window_(window) {
- window_->AddObserver(this);
- }
- ~VisibilityChangeObserver() override { window_->RemoveObserver(this); }
-
- private:
- // Overridden from WindowObserver:
- void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
- EXPECT_EQ(window, window_);
- EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
- }
-
- aura::Window* window_;
-
- DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver);
-};
-
-} // namespace
-
-TEST_F(WindowServerTest, Visible) {
- aura::Window* window1 = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
-
- // Embed another app and verify initial state.
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window1);
- ASSERT_TRUE(embed_result->IsValid());
- aura::Window* embed_root = embed_result->window_tree_host->window();
- EXPECT_TRUE(embed_root->TargetVisibility());
- EXPECT_TRUE(embed_root->IsVisible());
-
- // Change the visible state from the first client and verify its mirrored
- // correctly to the embedded app.
- {
- VisibilityChangeObserver observer(embed_root);
- window1->Hide();
- ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout());
- }
-
- EXPECT_FALSE(window1->TargetVisibility());
- EXPECT_FALSE(window1->IsVisible());
-
- EXPECT_FALSE(embed_root->TargetVisibility());
- EXPECT_FALSE(embed_root->IsVisible());
-
- // Make the node visible again.
- {
- VisibilityChangeObserver observer(embed_root);
- window1->Show();
- ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout());
- }
-
- EXPECT_TRUE(window1->TargetVisibility());
- EXPECT_TRUE(window1->IsVisible());
-
- EXPECT_TRUE(embed_root->TargetVisibility());
- EXPECT_TRUE(embed_root->IsVisible());
-}
-
-// TODO(beng): tests for window event dispatcher.
-// - verify that we see events for all windows.
-
-TEST_F(WindowServerTest, EmbedFailsWithChildren) {
- aura::Window* window1 = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
- ASSERT_TRUE(NewVisibleWindow(window1, window_manager()));
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window1);
- // Embed() should fail as |window1| has a child.
- EXPECT_FALSE(embed_result->IsValid());
-}
-
-namespace {
-
-class DestroyObserver : public aura::WindowObserver {
- public:
- DestroyObserver(aura::WindowTreeClient* client, bool* got_destroy)
- : got_destroy_(got_destroy) {
- GetFirstRoot(client)->AddObserver(this);
- }
- ~DestroyObserver() override {}
-
- private:
- // Overridden from aura::WindowObserver:
- void OnWindowDestroyed(aura::Window* window) override {
- *got_destroy_ = true;
- window->RemoveObserver(this);
-
- EXPECT_TRUE(WindowServerTestBase::QuitRunLoop());
- }
-
- bool* got_destroy_;
-
- DISALLOW_COPY_AND_ASSIGN(DestroyObserver);
-};
-
-} // namespace
-
-// Verifies deleting a Window that is the root of another client notifies
-// observers in the right order (OnWindowDestroyed() before
-// OnWindowManagerDestroyed()).
-TEST_F(WindowServerTest, WindowServerDestroyedAfterRootObserver) {
- aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
-
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
- ASSERT_TRUE(embed_result->IsValid());
- aura::WindowTreeClient* embedded_client =
- embed_result->window_tree_client.get();
-
- bool got_destroy = false;
- DestroyObserver observer(embedded_client, &got_destroy);
- // Delete the window |embedded_client| is embedded in. |embedded_client| is
- // asynchronously notified and cleans up.
- delete window;
- EXPECT_TRUE(DoRunLoopWithTimeout());
- ASSERT_TRUE(got_destroy);
- // The WindowTreeHost was destroyed as well (by
- // WindowServerTestBase::OnEmbedRootDestroyed()).
- embed_result->window_tree_host.release();
- EXPECT_EQ(0u, embed_result->window_tree_client->GetRoots().size());
-}
-
-TEST_F(WindowServerTest, ClientAreaChanged) {
- aura::Window* window = NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
-
- std::unique_ptr<EmbedResult> embed_result = Embed(window_manager(), window);
- ASSERT_TRUE(embed_result->IsValid());
-
- // Verify change from embedded makes it to parent.
- const gfx::Insets insets(1, 2, 3, 4);
- embed_result->window_tree_host->SetClientArea(insets,
- std::vector<gfx::Rect>());
- std::unique_ptr<ClientAreaChange> client_area_change =
- WaitForClientAreaToChange();
- ASSERT_TRUE(client_area_change);
- EXPECT_EQ(window, client_area_change->window);
- EXPECT_EQ(insets, client_area_change->insets);
-}
-
-class EstablishConnectionViaFactoryDelegate
- : public aura::TestWindowManagerDelegate {
- public:
- explicit EstablishConnectionViaFactoryDelegate(aura::WindowTreeClient* client)
- : client_(client), run_loop_(nullptr), created_window_(nullptr) {}
- ~EstablishConnectionViaFactoryDelegate() override {}
-
- bool QuitOnCreate() {
- if (run_loop_)
- return false;
-
- created_window_ = nullptr;
- run_loop_ = std::make_unique<base::RunLoop>();
- run_loop_->Run();
- run_loop_.reset();
- return created_window_ != nullptr;
- }
-
- aura::Window* created_window() { return created_window_; }
-
- // WindowManagerDelegate:
- aura::Window* OnWmCreateTopLevelWindow(
- ui::mojom::WindowType window_type,
- std::map<std::string, std::vector<uint8_t>>* properties) override {
- created_window_ = NewVisibleWindow((*client_->GetRoots().begin()), client_,
- aura::WindowMusType::TOP_LEVEL_IN_WM);
- if (run_loop_)
- run_loop_->Quit();
- return created_window_;
- }
-
- private:
- aura::WindowTreeClient* client_;
- std::unique_ptr<base::RunLoop> run_loop_;
- aura::Window* created_window_;
-
- DISALLOW_COPY_AND_ASSIGN(EstablishConnectionViaFactoryDelegate);
-};
-
-TEST_F(WindowServerTest, EstablishConnectionViaFactory) {
- EstablishConnectionViaFactoryDelegate delegate(window_manager());
- set_window_manager_delegate(&delegate);
- std::unique_ptr<aura::WindowTreeClient> second_client =
- aura::WindowTreeClient::CreateForWindowTreeFactory(connector(), this,
- false);
- aura::WindowTreeHostMus window_tree_host_in_second_client(
- aura::CreateInitParamsForTopLevel(second_client.get()));
- window_tree_host_in_second_client.InitHost();
- window_tree_host_in_second_client.window()->Show();
- ASSERT_TRUE(second_client->GetRoots().count(
- window_tree_host_in_second_client.window()) > 0);
- // Wait for the window to appear in the wm.
- ASSERT_TRUE(delegate.QuitOnCreate());
-
- aura::Window* window_in_wm = delegate.created_window();
- ASSERT_TRUE(window_in_wm);
-
- // Change the bounds in the wm, and make sure the child sees it.
- const gfx::Rect window_bounds(1, 11, 12, 101);
- window_in_wm->SetBounds(window_bounds);
- ASSERT_TRUE(
- WaitForBoundsToChange(window_tree_host_in_second_client.window()));
- EXPECT_EQ(window_bounds,
- window_tree_host_in_second_client.GetBoundsInPixels());
-}
-
-TEST_F(WindowServerTest, OnWindowHierarchyChangedIncludesTransientParent) {
- // Create a second connection. In the second connection create a window,
- // parent it to the root, create another window, mark it as a transient parent
- // of the first window and then add it.
- EstablishConnectionViaFactoryDelegate delegate(window_manager());
- set_window_manager_delegate(&delegate);
- std::unique_ptr<aura::WindowTreeClient> second_client =
- aura::WindowTreeClient::CreateForWindowTreeFactory(connector(), this,
- false);
- aura::WindowTreeHostMus window_tree_host_in_second_client(
- aura::CreateInitParamsForTopLevel(second_client.get()));
- window_tree_host_in_second_client.InitHost();
- window_tree_host_in_second_client.window()->Show();
- aura::Window* second_client_child = NewVisibleWindow(
- window_tree_host_in_second_client.window(), second_client.get());
- // Create the transient without a parent, set transient parent, then add.
- aura::Window* transient = NewVisibleWindow(nullptr, second_client.get());
- aura::client::TransientWindowClient* transient_window_client =
- aura::client::GetTransientWindowClient();
- transient_window_client->AddTransientChild(second_client_child, transient);
- second_client_child->AddChild(transient);
-
- // Wait for the top-level to appear in the window manager.
- ASSERT_TRUE(delegate.QuitOnCreate());
- aura::Window* top_level_in_wm = delegate.created_window();
-
- // Makes sure the window manager sees the same structure and the transient
- // parent is connected correctly.
- ASSERT_TRUE(WaitForTreeSizeToMatch(top_level_in_wm, 3u));
- ASSERT_EQ(1u, top_level_in_wm->children().size());
- aura::Window* second_client_child_in_wm = top_level_in_wm->children()[0];
- ASSERT_EQ(1u, second_client_child_in_wm->children().size());
- aura::Window* transient_in_wm = second_client_child_in_wm->children()[0];
- ASSERT_EQ(second_client_child_in_wm,
- transient_window_client->GetTransientParent(transient_in_wm));
-}
-
-class TestEmbedRootDelegate : public aura::EmbedRootDelegate {
- public:
- TestEmbedRootDelegate() {}
-
- void SetQuitClosure(base::Closure closure) { quit_closure_ = closure; }
-
- const base::UnguessableToken& token() const { return token_; }
- aura::Window* embed_window() { return embed_window_; }
- bool got_unembed() const { return got_unembed_; }
-
- // EmbedRootDelegate:
- void OnEmbedTokenAvailable(const base::UnguessableToken& token) override {
- token_ = token;
- quit_closure_.Run();
- }
- void OnEmbed(aura::Window* window) override {
- embed_window_ = window;
- quit_closure_.Run();
- }
- void OnUnembed() override {
- got_unembed_ = true;
- quit_closure_.Run();
- }
-
- private:
- base::Closure quit_closure_;
- aura::Window* embed_window_ = nullptr;
- bool got_unembed_ = false;
-
- base::UnguessableToken token_;
-
- DISALLOW_COPY_AND_ASSIGN(TestEmbedRootDelegate);
-};
-
-// This test exercises multiple EmbedRoots for a single client.
-TEST_F(WindowServerTest, EmbedRoot) {
- EstablishConnectionViaFactoryDelegate delegate(window_manager());
- set_window_manager_delegate(&delegate);
- std::unique_ptr<aura::WindowTreeClient> second_client =
- aura::WindowTreeClient::CreateForWindowTreeFactory(connector(), this,
- false);
-
- // Create a visible window so that the window-manager has a different number
- // of initial windows than the client.
- NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
- std::vector<std::unique_ptr<aura::EmbedRoot>> embed_roots;
- for (int i = 0; i < 2; ++i) {
- // Create a new EmbedRoot and wait for the token from the server.
- TestEmbedRootDelegate test_embed_root_delegate;
- std::unique_ptr<aura::EmbedRoot> embed_root =
- second_client->CreateEmbedRoot(&test_embed_root_delegate);
- base::RunLoop run_loop1;
- test_embed_root_delegate.SetQuitClosure(run_loop1.QuitClosure());
- run_loop1.Run();
- ASSERT_TRUE(test_embed_root_delegate.token());
-
- // Embed the token from the window manager's connection and wait for
- // OnEmbed().
- aura::Window* embed_window_in_wm =
- NewVisibleWindow(GetFirstWMRoot(), window_manager(),
- aura::WindowMusType::EMBED_IN_OWNER);
- window_manager()->EmbedUsingToken(embed_window_in_wm,
- test_embed_root_delegate.token(), 0u,
- base::DoNothing());
-
- base::RunLoop run_loop2;
- test_embed_root_delegate.SetQuitClosure(run_loop2.QuitClosure());
- run_loop2.Run();
- ASSERT_TRUE(test_embed_root_delegate.embed_window());
- EXPECT_NE(test_embed_root_delegate.embed_window(), embed_window_in_wm);
- // Create a child of the embed root's window in |second_client|. Then wait
- // for completion to ensure all is well.
- NewVisibleWindow(test_embed_root_delegate.embed_window(),
- second_client.get());
- aura::test::WaitForAllChangesToComplete(second_client.get());
- embed_roots.push_back(std::move(embed_root));
- }
-}
-
-TEST_F(WindowServerTest, DeleteEmbedRoot) {
- EstablishConnectionViaFactoryDelegate delegate(window_manager());
- set_window_manager_delegate(&delegate);
- std::unique_ptr<aura::WindowTreeClient> second_client =
- aura::WindowTreeClient::CreateForWindowTreeFactory(connector(), this,
- false);
-
- // Create a new EmbedRoot and wait for the token from the server.
- TestEmbedRootDelegate test_embed_root_delegate;
- std::unique_ptr<aura::EmbedRoot> embed_root =
- second_client->CreateEmbedRoot(&test_embed_root_delegate);
- base::RunLoop run_loop1;
- test_embed_root_delegate.SetQuitClosure(run_loop1.QuitClosure());
- run_loop1.Run();
- ASSERT_TRUE(test_embed_root_delegate.token());
-
- // Embed the token from the window manager's connection and wait for
- // OnEmbed().
- aura::Window* embed_window_in_wm = NewVisibleWindow(
- GetFirstWMRoot(), window_manager(), aura::WindowMusType::EMBED_IN_OWNER);
- window_manager()->EmbedUsingToken(embed_window_in_wm,
- test_embed_root_delegate.token(), 0u,
- base::DoNothing());
-
- base::RunLoop run_loop2;
- test_embed_root_delegate.SetQuitClosure(run_loop2.QuitClosure());
- run_loop2.Run();
- ASSERT_TRUE(test_embed_root_delegate.embed_window());
- aura::WindowTracker embed_root_window_tracker;
- embed_root_window_tracker.Add(test_embed_root_delegate.embed_window());
-
- // Delete the embed root (from the window-manager).
- delete embed_window_in_wm;
- base::RunLoop run_loop3;
- test_embed_root_delegate.SetQuitClosure(run_loop3.QuitClosure());
- run_loop3.Run();
- EXPECT_TRUE(test_embed_root_delegate.got_unembed());
- // The EmbedRoot's window should still exist in the embedded client.
- EXPECT_FALSE(embed_root_window_tracker.windows().empty());
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_manager_display_root.cc b/services/ui/ws/window_manager_display_root.cc
deleted file mode 100644
index 0e41987..0000000
--- a/services/ui/ws/window_manager_display_root.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/window_manager_display_root.h"
-
-#include <string>
-#include <vector>
-
-#include "services/ui/public/interfaces/window_manager.mojom.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree.h"
-
-namespace ui {
-namespace ws {
-
-WindowManagerDisplayRoot::WindowManagerDisplayRoot(Display* display)
- : display_(display) {
- std::string name = "WindowManagerRoot";
- ServerWindow::Properties properties;
- properties[mojom::WindowManager::kName_Property] =
- std::vector<uint8_t>(name.begin(), name.end());
-
- const ClientWindowId client_window_id =
- window_server()->display_manager()->GetAndAdvanceNextRootId();
- root_.reset(
- window_server()->CreateServerWindow(client_window_id, properties));
- root_->set_event_targeting_policy(
- mojom::EventTargetingPolicy::DESCENDANTS_ONLY);
- // Our root is always a child of the Display's root. Do this
- // before the WindowTree has been created so that the client doesn't get
- // notified of the add, bounds change and visibility change.
- root_->SetBounds(gfx::Rect(display->root_window()->bounds().size()),
- allocator_.GenerateId());
- root_->SetVisible(true);
- display->root_window()->Add(root_.get());
-}
-
-WindowManagerDisplayRoot::~WindowManagerDisplayRoot() {}
-
-const ServerWindow* WindowManagerDisplayRoot::GetClientVisibleRoot() const {
- if (window_manager_state_->window_tree()
- ->automatically_create_display_roots()) {
- return root_.get();
- }
-
- return root_->children().empty() ? nullptr : root_->children()[0];
-}
-
-WindowServer* WindowManagerDisplayRoot::window_server() {
- return display_->window_server();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_manager_display_root.h b/services/ui/ws/window_manager_display_root.h
deleted file mode 100644
index c6962e42..0000000
--- a/services/ui/ws/window_manager_display_root.h
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_MANAGER_DISPLAY_ROOT_H_
-#define SERVICES_UI_WS_WINDOW_MANAGER_DISPLAY_ROOT_H_
-
-#include <stdint.h>
-
-#include <memory>
-
-#include "base/macros.h"
-#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
-
-namespace ui {
-namespace ws {
-
-class Display;
-class ServerWindow;
-class WindowManagerState;
-class WindowServer;
-
-// Owns the root window of a window manager for one display. Each window manager
-// has one WindowManagerDisplayRoot for each Display. The root window is
-// parented to the root of a Display.
-class WindowManagerDisplayRoot {
- public:
- explicit WindowManagerDisplayRoot(Display* display);
- ~WindowManagerDisplayRoot();
-
- // NOTE: this window is not necessarily visible to the window manager. When
- // the display roots are automatically created this root is visible to the
- // window manager. When the display roots are not automatically created this
- // root has a single child that is created by the client. Use
- // GetClientVisibleRoot() to get the root that is visible to the client.
- ServerWindow* root() { return root_.get(); }
- const ServerWindow* root() const { return root_.get(); }
-
- // See root() for details of this. This returns null until the client creates
- // the root.
- ServerWindow* GetClientVisibleRoot() {
- return const_cast<ServerWindow*>(
- const_cast<const WindowManagerDisplayRoot*>(this)
- ->GetClientVisibleRoot());
- }
- const ServerWindow* GetClientVisibleRoot() const;
-
- Display* display() { return display_; }
- const Display* display() const { return display_; }
-
- WindowManagerState* window_manager_state() { return window_manager_state_; }
- const WindowManagerState* window_manager_state() const {
- return window_manager_state_;
- }
-
- private:
- friend class Display;
- friend class WindowManagerState;
-
- WindowServer* window_server();
-
- Display* display_;
- // Root ServerWindow of this WindowManagerDisplayRoot. |root_| has a parent,
- // the root ServerWindow of the Display.
- std::unique_ptr<ServerWindow> root_;
- WindowManagerState* window_manager_state_ = nullptr;
- viz::ParentLocalSurfaceIdAllocator allocator_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerDisplayRoot);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_MANAGER_DISPLAY_ROOT_H_
diff --git a/services/ui/ws/window_manager_state.cc b/services/ui/ws/window_manager_state.cc
deleted file mode 100644
index fcf2b00f..0000000
--- a/services/ui/ws/window_manager_state.cc
+++ /dev/null
@@ -1,642 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/window_manager_state.h"
-
-#include <utility>
-
-#include "base/containers/queue.h"
-#include "base/logging.h"
-#include "base/memory/weak_ptr.h"
-#include "components/viz/host/host_frame_sink_manager.h"
-#include "services/service_manager/public/mojom/connector.mojom.h"
-#include "services/ui/common/accelerator_util.h"
-#include "services/ui/ws/accelerator.h"
-#include "services/ui/ws/cursor_location_manager.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_creation_config.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/event_location.h"
-#include "services/ui/ws/event_targeter.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_tracker.h"
-#include "services/ui/ws/user_display_manager.h"
-#include "services/ui/ws/window_manager_display_root.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree.h"
-#include "ui/events/event.h"
-#include "ui/gfx/geometry/dip_util.h"
-#include "ui/gfx/geometry/point3_f.h"
-#include "ui/gfx/geometry/point_conversions.h"
-
-namespace ui {
-namespace ws {
-namespace {
-
-// Flags that matter when checking if a key event matches an accelerator.
-const int kAcceleratorEventFlags =
- EF_SHIFT_DOWN | EF_CONTROL_DOWN | EF_ALT_DOWN | EF_COMMAND_DOWN;
-
-const ServerWindow* GetEmbedRoot(const ServerWindow* window) {
- DCHECK(window);
- const ServerWindow* embed_root = window->parent();
- while (embed_root &&
- embed_root->owning_tree_id() == window->owning_tree_id()) {
- embed_root = embed_root->parent();
- }
- return embed_root;
-}
-
-const gfx::Rect& GetDisplayBoundsInPixels(Display* display) {
- return display->GetViewportMetrics().bounds_in_pixels;
-}
-
-gfx::Point PixelsToDips(Display* display, const gfx::Point& location) {
- return gfx::ConvertPointToDIP(
- display->GetDisplay().device_scale_factor() /
- display->GetViewportMetrics().ui_scale_factor,
- location);
-}
-
-gfx::Point DipsToPixels(Display* display, const gfx::Point& location) {
- return gfx::ConvertPointToPixel(
- display->GetDisplay().device_scale_factor() /
- display->GetViewportMetrics().ui_scale_factor,
- location);
-}
-
-} // namespace
-
-bool WindowManagerState::DebugAccelerator::Matches(
- const ui::KeyEvent& event) const {
- return key_code == event.key_code() &&
- event_flags == (kAcceleratorEventFlags & event.flags()) &&
- !event.is_char();
-}
-
-WindowManagerState::WindowManagerState(WindowTree* window_tree)
- : window_tree_(window_tree),
- event_dispatcher_(window_server(), window_tree_, this),
- event_processor_(this, &event_dispatcher_),
- cursor_state_(window_tree_->display_manager(), this) {
- event_dispatcher_.Init(&event_processor_);
- frame_decoration_values_ = mojom::FrameDecorationValues::New();
- frame_decoration_values_->max_title_bar_button_width = 0u;
-
- AddDebugAccelerators();
-}
-
-WindowManagerState::~WindowManagerState() {
- for (auto& display_root : window_manager_display_roots_)
- display_root->display()->OnWillDestroyTree(window_tree_);
-
- if (window_tree_->automatically_create_display_roots()) {
- for (auto& display_root : orphaned_window_manager_display_roots_)
- display_root->root()->RemoveObserver(this);
- }
-}
-
-void WindowManagerState::SetFrameDecorationValues(
- mojom::FrameDecorationValuesPtr values) {
- got_frame_decoration_values_ = true;
- frame_decoration_values_ = values.Clone();
- UserDisplayManager* user_display_manager =
- display_manager()->GetUserDisplayManager();
- user_display_manager->OnFrameDecorationValuesChanged();
- if (window_server()->display_creation_config() ==
- DisplayCreationConfig::MANUAL &&
- display_manager()->got_initial_config_from_window_manager()) {
- user_display_manager->CallOnDisplaysChanged();
- }
-}
-
-bool WindowManagerState::SetCapture(ServerWindow* window,
- ClientSpecificId client_id) {
- if (capture_window() == window &&
- client_id == event_processor_.capture_window_client_id()) {
- return true;
- }
-#if DCHECK_IS_ON()
- if (window) {
- WindowManagerDisplayRoot* display_root =
- display_manager()->GetWindowManagerDisplayRoot(window);
- DCHECK(display_root && display_root->window_manager_state() == this);
- }
-#endif
- return event_processor_.SetCaptureWindow(window, client_id);
-}
-
-void WindowManagerState::ReleaseCaptureBlockedByAnyModalWindow() {
- event_processor_.ReleaseCaptureBlockedByAnyModalWindow();
-}
-
-void WindowManagerState::SetCursorLocation(const gfx::Point& display_pixels,
- int64_t display_id) {
- Display* display = display_manager()->GetDisplayById(display_id);
- if (!display) {
- NOTIMPLEMENTED() << "Window manager sent invalid display_id!";
- return;
- }
-
- // MoveCursorTo() implicitly generates a mouse event.
- display->platform_display()->MoveCursorTo(display_pixels);
-}
-
-void WindowManagerState::SetKeyEventsThatDontHideCursor(
- std::vector<::ui::mojom::EventMatcherPtr> dont_hide_cursor_list) {
- event_processor()->SetKeyEventsThatDontHideCursor(
- std::move(dont_hide_cursor_list));
-}
-
-void WindowManagerState::SetCursorTouchVisible(bool enabled) {
- cursor_state_.SetCursorTouchVisible(enabled);
-}
-
-void WindowManagerState::SetDragDropSourceWindow(
- DragSource* drag_source,
- ServerWindow* window,
- DragTargetConnection* source_connection,
- const base::flat_map<std::string, std::vector<uint8_t>>& drag_data,
- uint32_t drag_operation) {
- PointerId drag_pointer = MouseEvent::kMousePointerId;
- const ui::Event* in_flight_event = event_dispatcher_.GetInFlightEvent();
- if (in_flight_event && in_flight_event->IsPointerEvent()) {
- drag_pointer = in_flight_event->AsPointerEvent()->pointer_details().id;
- } else {
- NOTIMPLEMENTED() << "Set drag drop set up during something other than a "
- << "pointer event; rejecting drag.";
- drag_source->OnDragCompleted(false, ui::mojom::kDropEffectNone);
- return;
- }
-
- event_processor_.SetDragDropSourceWindow(drag_source, window,
- source_connection, drag_pointer,
- drag_data, drag_operation);
-}
-
-void WindowManagerState::CancelDragDrop() {
- event_processor_.CancelDragDrop();
-}
-
-void WindowManagerState::EndDragDrop() {
- event_processor_.EndDragDrop();
- UpdateNativeCursorFromEventProcessor();
-}
-
-void WindowManagerState::AddSystemModalWindow(ServerWindow* window) {
- event_processor_.AddSystemModalWindow(window);
-}
-
-void WindowManagerState::DeleteWindowManagerDisplayRoot(
- ServerWindow* display_root) {
- for (auto iter = orphaned_window_manager_display_roots_.begin();
- iter != orphaned_window_manager_display_roots_.end(); ++iter) {
- if ((*iter)->root() == display_root) {
- orphaned_window_manager_display_roots_.erase(iter);
- return;
- }
- }
-
- for (auto iter = window_manager_display_roots_.begin();
- iter != window_manager_display_roots_.end(); ++iter) {
- if ((*iter)->root() == display_root) {
- (*iter)->display()->RemoveWindowManagerDisplayRoot((*iter).get());
- window_manager_display_roots_.erase(iter);
- return;
- }
- }
-}
-
-void WindowManagerState::OnWillDestroyTree(WindowTree* tree) {
- event_processor_.OnWillDestroyDragTargetConnection(tree);
-
- event_dispatcher_.OnWillDestroyAsyncEventDispatcher(tree);
-}
-
-void WindowManagerState::ProcessEvent(ui::Event* event, int64_t display_id) {
- EventLocation event_location(display_id);
- if (event->IsLocatedEvent()) {
- event_location.raw_location = event->AsLocatedEvent()->location_f();
- AdjustEventLocation(display_id, event->AsLocatedEvent());
- event_location.location = event->AsLocatedEvent()->root_location_f();
- }
- event_dispatcher_.ProcessEvent(event, event_location);
-}
-
-void WindowManagerState::ScheduleCallbackWhenDoneProcessingEvents(
- base::OnceClosure closure) {
- event_dispatcher_.ScheduleCallbackWhenDoneProcessingEvents(
- std::move(closure));
-}
-
-const WindowServer* WindowManagerState::window_server() const {
- return window_tree_->window_server();
-}
-
-WindowServer* WindowManagerState::window_server() {
- return window_tree_->window_server();
-}
-
-DisplayManager* WindowManagerState::display_manager() {
- return window_tree_->display_manager();
-}
-
-const DisplayManager* WindowManagerState::display_manager() const {
- return window_tree_->display_manager();
-}
-
-void WindowManagerState::AddWindowManagerDisplayRoot(
- std::unique_ptr<WindowManagerDisplayRoot> display_root) {
- window_manager_display_roots_.push_back(std::move(display_root));
-}
-
-void WindowManagerState::OnDisplayDestroying(Display* display) {
- if (display->platform_display() == platform_display_with_capture_)
- platform_display_with_capture_ = nullptr;
-
- for (auto iter = window_manager_display_roots_.begin();
- iter != window_manager_display_roots_.end(); ++iter) {
- if ((*iter)->display() == display) {
- if (window_tree_->automatically_create_display_roots())
- (*iter)->root()->AddObserver(this);
- orphaned_window_manager_display_roots_.push_back(std::move(*iter));
- window_manager_display_roots_.erase(iter);
- window_tree_->OnDisplayDestroying(display->GetId());
- orphaned_window_manager_display_roots_.back()->display_ = nullptr;
- return;
- }
- }
-}
-
-ServerWindow* WindowManagerState::GetWindowManagerRootForDisplayRoot(
- ServerWindow* window) {
- for (auto& display_root_ptr : window_manager_display_roots_) {
- if (display_root_ptr->root()->parent() == window)
- return display_root_ptr->GetClientVisibleRoot();
- }
- NOTREACHED();
- return nullptr;
-}
-
-void WindowManagerState::AddDebugAccelerators() {
- const DebugAccelerator accelerator = {
- DebugAcceleratorType::PRINT_WINDOWS, ui::VKEY_S,
- ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN};
- debug_accelerators_.push_back(accelerator);
-}
-
-void WindowManagerState::ProcessDebugAccelerator(const ui::Event& event,
- int64_t display_id) {
- if (event.type() != ui::ET_KEY_PRESSED)
- return;
-
- const ui::KeyEvent& key_event = *event.AsKeyEvent();
- for (const DebugAccelerator& accelerator : debug_accelerators_) {
- if (accelerator.Matches(key_event)) {
- HandleDebugAccelerator(accelerator.type, display_id);
- break;
- }
- }
-}
-
-void WindowManagerState::HandleDebugAccelerator(DebugAcceleratorType type,
- int64_t display_id) {
-#if DCHECK_IS_ON()
- // Error so it will be collected in system logs.
- for (Display* display : display_manager()->displays()) {
- WindowManagerDisplayRoot* display_root =
- display->window_manager_display_root();
- if (display_root) {
- LOG(ERROR) << "ServerWindow hierarchy:\n"
- << display_root->root()->GetDebugWindowHierarchy();
- }
- }
- ServerWindow* focused_window = GetFocusedWindowForEventProcessor(display_id);
- LOG(ERROR) << "Focused window: "
- << (focused_window ? focused_window->frame_sink_id().ToString()
- : "(null)");
-#endif
-}
-
-bool WindowManagerState::ConvertPointToScreen(int64_t display_id,
- gfx::Point* point) {
- Display* display = display_manager()->GetDisplayById(display_id);
- if (!display)
- return false;
-
- WindowManagerDisplayRoot* root = display->window_manager_display_root();
- if (!root)
- return false;
-
- const display::Display& originated_display = display->GetDisplay();
- gfx::Transform transform;
- transform.Scale(originated_display.device_scale_factor(),
- originated_display.device_scale_factor());
- transform *= display->window_manager_display_root()
- ->GetClientVisibleRoot()
- ->transform();
- gfx::Transform invert;
- if (!transform.GetInverse(&invert))
- invert = transform;
- auto point_3f = gfx::Point3F(gfx::PointF(*point));
- invert.TransformPoint(&point_3f);
- *point = gfx::ToFlooredPoint(point_3f.AsPointF()) +
- originated_display.bounds().origin().OffsetFromOrigin();
- return true;
-}
-
-Display* WindowManagerState::FindDisplayContainingPixelLocation(
- const gfx::Point& screen_pixels) {
- for (auto& display_root_ptr : window_manager_display_roots_) {
- if (GetDisplayBoundsInPixels(display_root_ptr->display())
- .Contains(screen_pixels)) {
- return display_root_ptr->display();
- }
- }
- return nullptr;
-}
-
-void WindowManagerState::AdjustEventLocation(int64_t display_id,
- LocatedEvent* event) {
- if (window_manager_display_roots_.empty())
- return;
-
- Display* display = display_manager()->GetDisplayById(display_id);
- if (!display)
- return;
-
- const gfx::Rect& display_bounds_in_pixels = GetDisplayBoundsInPixels(display);
- // Typical case is the display contains the location.
- if (gfx::Rect(display_bounds_in_pixels.size()).Contains(event->location()))
- return;
-
- // The location is outside the bounds of the specified display. This generally
- // happens when there is a grab and the mouse is moved to another display.
- // When this happens the location of the event is in terms of the pixel
- // display layout. Find the display using the pixel display layout.
- const gfx::Point screen_pixels =
- event->location() + display_bounds_in_pixels.origin().OffsetFromOrigin();
- Display* containing_display =
- FindDisplayContainingPixelLocation(screen_pixels);
- if (!containing_display) {
- DVLOG(1) << "Invalid event location " << event->location().ToString()
- << " / display id " << display_id;
- return;
- }
-
- // Adjust the location of the event to be in terms of the DIP display layout
- // (but in pixels). See EventLocation for details on this.
- const gfx::Point location_in_containing_display =
- screen_pixels -
- GetDisplayBoundsInPixels(containing_display).origin().OffsetFromOrigin();
- const gfx::Point screen_dip_location =
- containing_display->GetDisplay().bounds().origin() +
- PixelsToDips(containing_display, location_in_containing_display)
- .OffsetFromOrigin();
- const gfx::Point pixel_relative_location = DipsToPixels(
- display, screen_dip_location -
- display->GetDisplay().bounds().origin().OffsetFromOrigin());
- event->set_location(pixel_relative_location);
- event->set_root_location(pixel_relative_location);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// EventProcessorDelegate:
-
-void WindowManagerState::SetFocusedWindowFromEventProcessor(
- ServerWindow* new_focused_window) {
- window_server()->SetFocusedWindow(new_focused_window);
-}
-
-ServerWindow* WindowManagerState::GetFocusedWindowForEventProcessor(
- int64_t display_id) {
- ServerWindow* focused_window = window_server()->GetFocusedWindow();
- if (focused_window)
- return focused_window;
-
- // When none of the windows have focus return the window manager's root.
- for (auto& display_root_ptr : window_manager_display_roots_) {
- if (display_root_ptr->display()->GetId() == display_id)
- return display_root_ptr->GetClientVisibleRoot();
- }
- if (!window_manager_display_roots_.empty())
- return (*window_manager_display_roots_.begin())->GetClientVisibleRoot();
- return nullptr;
-}
-
-void WindowManagerState::SetNativeCapture(ServerWindow* window) {
- DCHECK(window);
-
- // Classic ash expects no native grab when in unified display.
- // See http://crbug.com/773348 for details.
- if (display_manager()->InUnifiedDisplayMode())
- return;
-
- WindowManagerDisplayRoot* display_root =
- display_manager()->GetWindowManagerDisplayRoot(window);
- DCHECK(display_root);
- platform_display_with_capture_ = display_root->display()->platform_display();
- platform_display_with_capture_->SetCapture();
-}
-
-void WindowManagerState::ReleaseNativeCapture() {
- // Classic ash expects no native grab when in unified display.
- // See http://crbug.com/773348 for details.
- if (display_manager()->InUnifiedDisplayMode())
- return;
-
- // Tests trigger calling this without a corresponding SetNativeCapture().
- // TODO(sky): maybe abstract this away so that DCHECK can be added?
- if (!platform_display_with_capture_)
- return;
-
- platform_display_with_capture_->ReleaseCapture();
- platform_display_with_capture_ = nullptr;
-}
-
-void WindowManagerState::UpdateNativeCursorFromEventProcessor() {
- const ui::CursorData cursor = event_processor_.GetCurrentMouseCursor();
- cursor_state_.SetCurrentWindowCursor(cursor);
-}
-
-void WindowManagerState::OnCaptureChanged(ServerWindow* new_capture,
- ServerWindow* old_capture) {
- window_server()->ProcessCaptureChanged(new_capture, old_capture);
-}
-
-void WindowManagerState::OnMouseCursorLocationChanged(
- const gfx::PointF& point_in_display,
- int64_t display_id) {
- gfx::Point point_in_screen = gfx::ToFlooredPoint(point_in_display);
- if (ConvertPointToScreen(display_id, &point_in_screen)) {
- window_server()
- ->display_manager()
- ->cursor_location_manager()
- ->OnMouseCursorLocationChanged(point_in_screen);
- }
- // If the display the |point_in_display| is on has been deleted, keep the old
- // cursor location.
-}
-
-void WindowManagerState::OnEventChangesCursorVisibility(const ui::Event& event,
- bool visible) {
- if (event.IsSynthesized())
- return;
- cursor_state_.SetCursorVisible(visible);
-}
-
-void WindowManagerState::OnEventChangesCursorTouchVisibility(
- const ui::Event& event,
- bool visible) {
- if (event.IsSynthesized())
- return;
-
- // Setting cursor touch visibility needs to cause a callback which notifies a
- // caller so we can dispatch the state change to the window manager.
- cursor_state_.SetCursorTouchVisible(visible);
-}
-
-ClientSpecificId WindowManagerState::GetEventTargetClientId(
- const ServerWindow* window,
- bool in_nonclient_area) {
- if (in_nonclient_area) {
- // Events in the non-client area always go to the window manager.
- return window_tree_->id();
- }
-
- // If the window is an embed root, it goes to the tree embedded in the window.
- WindowTree* tree = window_server()->GetTreeWithRoot(window);
- if (!tree) {
- // Window is not an embed root, event goes to owner of the window.
- tree = window_server()->GetTreeWithId(window->owning_tree_id());
- }
- DCHECK(tree);
-
- // Ascend to the first tree marked as not embedder_intercepts_events().
- const ServerWindow* embed_root =
- tree->HasRoot(window) ? window : GetEmbedRoot(window);
- while (tree && tree->embedder_intercepts_events()) {
- DCHECK(tree->HasRoot(embed_root));
- tree = window_server()->GetTreeWithId(embed_root->owning_tree_id());
- embed_root = GetEmbedRoot(embed_root);
- }
- DCHECK(tree);
- return tree->id();
-}
-
-ServerWindow* WindowManagerState::GetRootWindowForDisplay(int64_t display_id) {
- Display* display = display_manager()->GetDisplayById(display_id);
- if (!display)
- return nullptr;
-
- return display->window_manager_display_root()->GetClientVisibleRoot();
-}
-
-ServerWindow* WindowManagerState::GetRootWindowForEventDispatch(
- ServerWindow* window) {
- for (auto& display_root_ptr : window_manager_display_roots_) {
- ServerWindow* client_visible_root =
- display_root_ptr->GetClientVisibleRoot();
- if (client_visible_root->Contains(window))
- return client_visible_root;
- }
- return nullptr;
-}
-
-void WindowManagerState::OnEventTargetNotFound(const ui::Event& event,
- int64_t display_id) {
- window_server()->SendToPointerWatchers(event, nullptr, /* window */
- nullptr /* ignore_tree */, display_id);
- if (event.IsMousePointerEvent())
- UpdateNativeCursorFromEventProcessor();
-}
-
-ServerWindow* WindowManagerState::GetFallbackTargetForEventBlockedByModal(
- ServerWindow* window) {
- DCHECK(window);
- // TODO(sky): reevaluate when http://crbug.com/646998 is fixed.
- return GetWindowManagerRootForDisplayRoot(window);
-}
-
-void WindowManagerState::OnEventOccurredOutsideOfModalWindow(
- ServerWindow* modal_window) {
- window_tree_->OnEventOccurredOutsideOfModalWindow(modal_window);
-}
-
-viz::HitTestQuery* WindowManagerState::GetHitTestQueryForDisplay(
- int64_t display_id) {
- Display* display = display_manager()->GetDisplayById(display_id);
- if (!display)
- return nullptr;
-
- return window_server()->GetVizHostProxy()->GetHitTestQuery(
- display->root_window()->frame_sink_id());
-}
-
-ServerWindow* WindowManagerState::GetWindowFromFrameSinkId(
- const viz::FrameSinkId& frame_sink_id) {
- DCHECK(frame_sink_id.is_valid());
- return window_tree()->GetWindowByClientId(frame_sink_id);
-}
-
-void WindowManagerState::OnWindowEmbeddedAppDisconnected(ServerWindow* window) {
- for (auto iter = orphaned_window_manager_display_roots_.begin();
- iter != orphaned_window_manager_display_roots_.end(); ++iter) {
- if ((*iter)->root() == window) {
- window->RemoveObserver(this);
- orphaned_window_manager_display_roots_.erase(iter);
- return;
- }
- }
- NOTREACHED();
-}
-
-void WindowManagerState::OnCursorTouchVisibleChanged(bool enabled) {
- window_tree_->OnCursorTouchVisibleChanged(enabled);
-}
-
-ServerWindow* WindowManagerState::OnWillDispatchInputEvent(
- ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const Event& event) {
- if (target->parent() == nullptr) {
- // The target is a display root, redirect to the WindowManager's root so
- // that the WindowManager is passed a window it knows.
- target = GetWindowManagerRootForDisplayRoot(target);
- }
- if (event.IsMousePointerEvent())
- UpdateNativeCursorFromEventProcessor();
- WindowTree* tree = window_server()->GetTreeWithId(client_id);
- DCHECK(tree);
- // Ignore |tree| because it will receive the event via normal dispatch.
- window_server()->SendToPointerWatchers(event, target, tree,
- event_location.display_id);
- return target;
-}
-
-void WindowManagerState::OnEventDispatchTimedOut(
- AsyncEventDispatcher* async_event_dispatcher) {
- DCHECK(async_event_dispatcher);
- WindowTree* hung_tree = static_cast<WindowTree*>(async_event_dispatcher);
- if (!hung_tree->janky())
- window_tree_->ClientJankinessChanged(hung_tree);
-}
-
-void WindowManagerState::OnAsyncEventDispatcherHandledAccelerator(
- const Event& event,
- int64_t display_id) {
- window_server()->SendToPointerWatchers(event, nullptr, nullptr, display_id);
-}
-
-void WindowManagerState::OnWillProcessEvent(
- const ui::Event& event,
- const EventLocation& event_location) {
- // Debug accelerators are always checked and don't interfere with processing.
- ProcessDebugAccelerator(event, event_location.display_id);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_manager_state.h b/services/ui/ws/window_manager_state.h
deleted file mode 100644
index b012826..0000000
--- a/services/ui/ws/window_manager_state.h
+++ /dev/null
@@ -1,275 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_
-#define SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_
-
-#include <stdint.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "base/containers/flat_map.h"
-#include "base/memory/weak_ptr.h"
-#include "base/timer/timer.h"
-#include "services/ui/public/interfaces/screen_provider.mojom.h"
-#include "services/ui/ws/cursor_state.h"
-#include "services/ui/ws/cursor_state_delegate.h"
-#include "services/ui/ws/event_dispatcher_delegate.h"
-#include "services/ui/ws/event_dispatcher_impl.h"
-#include "services/ui/ws/event_processor.h"
-#include "services/ui/ws/event_processor_delegate.h"
-#include "services/ui/ws/server_window_observer.h"
-#include "services/ui/ws/window_server.h"
-
-namespace viz {
-class HitTestQuery;
-}
-
-namespace ui {
-namespace ws {
-
-class DisplayManager;
-class EventDispatcherImpl;
-class PlatformDisplay;
-class WindowManagerDisplayRoot;
-class WindowTree;
-
-namespace test {
-class WindowManagerStateTestApi;
-}
-
-// Manages state specific to a WindowManager that is shared across displays.
-// WindowManagerState is owned by the WindowTree the window manager is
-// associated with.
-class WindowManagerState : public EventProcessorDelegate,
- public ServerWindowObserver,
- public CursorStateDelegate,
- public EventDispatcherDelegate {
- public:
- explicit WindowManagerState(WindowTree* window_tree);
- ~WindowManagerState() override;
-
- WindowTree* window_tree() { return window_tree_; }
- const WindowTree* window_tree() const { return window_tree_; }
-
- void OnWillDestroyTree(WindowTree* tree);
-
- void SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values);
- const mojom::FrameDecorationValues& frame_decoration_values() const {
- return *frame_decoration_values_;
- }
- bool got_frame_decoration_values() const {
- return got_frame_decoration_values_;
- }
-
- bool SetCapture(ServerWindow* window, ClientSpecificId client_id);
- ServerWindow* capture_window() { return event_processor_.capture_window(); }
- const ServerWindow* capture_window() const {
- return event_processor_.capture_window();
- }
-
- void ReleaseCaptureBlockedByAnyModalWindow();
-
- // Sets the location of the cursor to a location on display |display_id|.
- void SetCursorLocation(const gfx::Point& display_pixels, int64_t display_id);
-
- void SetKeyEventsThatDontHideCursor(
- std::vector<::ui::mojom::EventMatcherPtr> dont_hide_cursor_list);
-
- void SetCursorTouchVisible(bool enabled);
-
- void SetDragDropSourceWindow(
- DragSource* drag_source,
- ServerWindow* window,
- DragTargetConnection* source_connection,
- const base::flat_map<std::string, std::vector<uint8_t>>& drag_data,
- uint32_t drag_operation);
- void CancelDragDrop();
- void EndDragDrop();
-
- void AddSystemModalWindow(ServerWindow* window);
-
- // Deletes the WindowManagerDisplayRoot whose root is |display_root|.
- void DeleteWindowManagerDisplayRoot(ServerWindow* display_root);
-
- // TODO(sky): EventProcessor is really an implementation detail and should
- // not be exposed.
- EventProcessor* event_processor() { return &event_processor_; }
-
- CursorState& cursor_state() { return cursor_state_; }
-
- // Processes an event from PlatformDisplay. This doesn't take ownership of
- // |event|, but it may modify it.
- void ProcessEvent(ui::Event* event, int64_t display_id);
-
- // Notifies |closure| once done processing currently queued events. This
- // notifies |closure| immediately if IsProcessingEvent() returns false.
- void ScheduleCallbackWhenDoneProcessingEvents(base::OnceClosure closure);
-
- PlatformDisplay* platform_display_with_capture() {
- return platform_display_with_capture_;
- }
-
- private:
- friend class Display;
- friend class test::WindowManagerStateTestApi;
-
- // Set of display roots. This is a vector rather than a set to support removal
- // without deleting.
- using WindowManagerDisplayRoots =
- std::vector<std::unique_ptr<WindowManagerDisplayRoot>>;
-
- enum class DebugAcceleratorType {
- PRINT_WINDOWS,
- };
-
- struct DebugAccelerator {
- bool Matches(const KeyEvent& event) const;
-
- DebugAcceleratorType type;
- KeyboardCode key_code;
- int event_flags;
- };
-
- const WindowServer* window_server() const;
- WindowServer* window_server();
-
- DisplayManager* display_manager();
- const DisplayManager* display_manager() const;
-
- // Adds |display_root| to the set of WindowManagerDisplayRoots owned by this
- // WindowManagerState.
- void AddWindowManagerDisplayRoot(
- std::unique_ptr<WindowManagerDisplayRoot> display_root);
-
- // Called when a Display is deleted.
- void OnDisplayDestroying(Display* display);
-
- // Returns the ServerWindow that is the root of the WindowManager for
- // |window|. |window| corresponds to the root of a Display.
- ServerWindow* GetWindowManagerRootForDisplayRoot(ServerWindow* window);
-
- // Called if the client doesn't ack an event in the appropriate amount of
- // time.
- void OnEventAckTimeout(ClientSpecificId client_id);
-
- // Implemenation of processing an event with a match phase of all. This
- // handles debug accelerators and forwards to EventProcessor.
- void ProcessEventImpl(const Event& event,
- const EventLocation& event_location);
-
- // Dispatches the event to the appropriate client and starts the ack timer.
- void DispatchInputEventToWindowImpl(ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const Event& event,
- base::WeakPtr<Accelerator> accelerator);
-
- // Registers accelerators used internally for debugging.
- void AddDebugAccelerators();
-
- // Finds the debug accelerator for |event| and if one is found calls
- // HandleDebugAccelerator().
- void ProcessDebugAccelerator(const Event& event, int64_t display_id);
-
- // Runs the specified debug accelerator.
- void HandleDebugAccelerator(DebugAcceleratorType type, int64_t display_id);
-
- // Processes queued event tasks until there are no more, or we're waiting on
- // a client or the EventDisptacher to complete processing.
- void ProcessEventTasks();
-
- // Helper function to convert |point| to be in screen coordinates. |point| as
- // the input should be in display-physical-pixel space, and the output is in
- // screen-dip space. Returns true if the |point| is successfully converted,
- // false otherwise.
- bool ConvertPointToScreen(int64_t display_id, gfx::Point* point);
-
- Display* FindDisplayContainingPixelLocation(const gfx::Point& screen_pixels);
-
- void AdjustEventLocation(int64_t display_id, LocatedEvent* event);
-
- // EventProcessorDelegate:
- void SetFocusedWindowFromEventProcessor(ServerWindow* window) override;
- ServerWindow* GetFocusedWindowForEventProcessor(int64_t display_id) override;
- void SetNativeCapture(ServerWindow* window) override;
- void ReleaseNativeCapture() override;
- void UpdateNativeCursorFromEventProcessor() override;
- void OnCaptureChanged(ServerWindow* new_capture,
- ServerWindow* old_capture) override;
- void OnMouseCursorLocationChanged(const gfx::PointF& point,
- int64_t display_id) override;
- void OnEventChangesCursorVisibility(const ui::Event& event,
- bool visible) override;
- void OnEventChangesCursorTouchVisibility(const ui::Event& event,
- bool visible) override;
- ClientSpecificId GetEventTargetClientId(const ServerWindow* window,
- bool in_nonclient_area) override;
- ServerWindow* GetRootWindowForDisplay(int64_t display_id) override;
- ServerWindow* GetRootWindowForEventDispatch(ServerWindow* window) override;
- void OnEventTargetNotFound(const Event& event, int64_t display_id) override;
- ServerWindow* GetFallbackTargetForEventBlockedByModal(
- ServerWindow* window) override;
- void OnEventOccurredOutsideOfModalWindow(ServerWindow* modal_window) override;
- viz::HitTestQuery* GetHitTestQueryForDisplay(int64_t display_id) override;
- ServerWindow* GetWindowFromFrameSinkId(
- const viz::FrameSinkId& frame_sink_id) override;
-
- // ServerWindowObserver:
- void OnWindowEmbeddedAppDisconnected(ServerWindow* window) override;
-
- // CursorStateDelegate:
- void OnCursorTouchVisibleChanged(bool enabled) override;
-
- // EventDispatcherDelegate:
- ServerWindow* OnWillDispatchInputEvent(ServerWindow* target,
- ClientSpecificId client_id,
- const EventLocation& event_location,
- const Event& event) override;
- void OnEventDispatchTimedOut(
- AsyncEventDispatcher* async_event_dipsatcher) override;
- void OnAsyncEventDispatcherHandledAccelerator(const Event& event,
- int64_t display_id) override;
- void OnWillProcessEvent(const ui::Event& event,
- const EventLocation& event_location) override;
-
- // The single WindowTree this WindowManagerState is associated with.
- // |window_tree_| owns this.
- WindowTree* window_tree_;
-
- // Set to true the first time SetFrameDecorationValues() is called.
- bool got_frame_decoration_values_ = false;
- mojom::FrameDecorationValuesPtr frame_decoration_values_;
-
- std::vector<DebugAccelerator> debug_accelerators_;
-
- EventDispatcherImpl event_dispatcher_;
-
- EventProcessor event_processor_;
-
- // PlatformDisplay that currently has capture.
- PlatformDisplay* platform_display_with_capture_ = nullptr;
-
- // All the active WindowManagerDisplayRoots.
- WindowManagerDisplayRoots window_manager_display_roots_;
-
- // Set of WindowManagerDisplayRoots corresponding to Displays that have been
- // destroyed. WindowManagerDisplayRoots are not destroyed immediately when
- // the Display is destroyed to allow the client to destroy the window when it
- // wants to. Once the client destroys the window WindowManagerDisplayRoots is
- // destroyed.
- WindowManagerDisplayRoots orphaned_window_manager_display_roots_;
-
- // All state regarding what the current cursor is.
- CursorState cursor_state_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerState);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_
diff --git a/services/ui/ws/window_manager_state_unittest.cc b/services/ui/ws/window_manager_state_unittest.cc
deleted file mode 100644
index 0ba2715..0000000
--- a/services/ui/ws/window_manager_state_unittest.cc
+++ /dev/null
@@ -1,1004 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/window_manager_state.h"
-
-#include <memory>
-
-#include "base/command_line.h"
-#include "base/containers/flat_map.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/test/test_simple_task_runner.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "services/service_manager/public/mojom/connector.mojom.h"
-#include "services/ui/common/accelerator_util.h"
-#include "services/ui/common/switches.h"
-#include "services/ui/ws/accelerator.h"
-#include "services/ui/ws/cursor_location_manager.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/event_location.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/test_change_tracker.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "services/ui/ws/window_manager_access_policy.h"
-#include "services/ui/ws/window_manager_display_root.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/events/event.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-
-// Used in checking if an event was processed. See usage for examples.
-void SetBoolToTrue(bool* value) {
- *value = true;
-}
-
-class WindowManagerStateTest : public testing::Test {
- public:
- WindowManagerStateTest();
- ~WindowManagerStateTest() override {}
-
- std::unique_ptr<Accelerator> CreateAccelerator();
-
- // Creates a child |server_window| with associataed |window_tree| and
- // |test_client|. The window is setup for processing input.
- void CreateSecondaryTree(TestWindowTreeClient** test_client,
- WindowTree** window_tree,
- ServerWindow** server_window);
-
- void DispatchInputEventToWindow(ServerWindow* target,
- const EventLocation& event_location,
- const ui::Event& event,
- Accelerator* accelerator);
- void OnEventAckTimeout(ClientSpecificId client_id);
-
- // This is the tree associated with the WindowManagerState. That is, this is
- // the WindowTree of the WindowManager.
- WindowTree* tree() {
- return window_event_targeting_helper_.window_server()->GetTreeWithId(
- kWindowManagerClientId);
- }
- // This is *not* the tree associated with the WindowManagerState, use tree()
- // if you need the window manager tree.
- WindowTree* window_tree() { return window_tree_; }
- TestWindowTreeClient* window_tree_client() { return window_tree_client_; }
- ServerWindow* window() { return window_; }
- TestWindowManager* window_manager() { return &window_manager_; }
- TestWindowTreeClient* wm_client() {
- return window_event_targeting_helper_.wm_client();
- }
- WindowManagerState* window_manager_state() { return window_manager_state_; }
- WindowServer* window_server() {
- return window_event_targeting_helper_.window_server();
- }
- ui::CursorType cursor_type() const {
- return window_event_targeting_helper_.cursor_type();
- }
-
- void EmbedAt(WindowTree* tree,
- const ClientWindowId& embed_window_id,
- uint32_t embed_flags,
- WindowTree** embed_tree,
- TestWindowTreeClient** embed_client_proxy) {
- mojom::WindowTreeClientPtr embed_client;
- auto client_request = mojo::MakeRequest(&embed_client);
- ASSERT_TRUE(
- tree->Embed(embed_window_id, std::move(embed_client), embed_flags));
- TestWindowTreeClient* client =
- window_event_targeting_helper_.last_window_tree_client();
- ASSERT_EQ(1u, client->tracker()->changes()->size());
- EXPECT_EQ(CHANGE_TYPE_EMBED, (*client->tracker()->changes())[0].type);
- client->tracker()->changes()->clear();
- *embed_client_proxy = client;
- *embed_tree = window_event_targeting_helper_.last_binding()->tree();
- }
-
- void DestroyWindowTree() {
- window_event_targeting_helper_.window_server()->DestroyTree(window_tree_);
- window_tree_ = nullptr;
- }
-
- // testing::Test:
- void SetUp() override;
-
- protected:
- // Handles WindowStateManager ack timeouts.
- scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
-
- private:
- WindowEventTargetingHelper window_event_targeting_helper_;
-
- WindowManagerState* window_manager_state_;
-
- TestWindowManager window_manager_;
- ServerWindow* window_ = nullptr;
- WindowTree* window_tree_ = nullptr;
- TestWindowTreeClient* window_tree_client_ = nullptr;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTest);
-};
-
-WindowManagerStateTest::WindowManagerStateTest()
- : task_runner_(new base::TestSimpleTaskRunner) {}
-
-std::unique_ptr<Accelerator> WindowManagerStateTest::CreateAccelerator() {
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
- matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET;
- uint32_t accelerator_id = 1;
- std::unique_ptr<Accelerator> accelerator(
- new Accelerator(accelerator_id, *matcher));
- return accelerator;
-}
-
-void WindowManagerStateTest::CreateSecondaryTree(
- TestWindowTreeClient** test_client,
- WindowTree** window_tree,
- ServerWindow** server_window) {
- window_event_targeting_helper_.CreateSecondaryTree(
- window_, gfx::Rect(20, 20, 20, 20), test_client, window_tree,
- server_window);
-}
-
-void WindowManagerStateTest::DispatchInputEventToWindow(
- ServerWindow* target,
- const EventLocation& event_location,
- const ui::Event& event,
- Accelerator* accelerator) {
- WindowManagerStateTestApi test_api(window_manager_state_);
- ClientSpecificId client_id = test_api.GetEventTargetClientId(target, false);
- test_api.DispatchInputEventToWindow(target, client_id, event_location, event,
- accelerator);
-}
-
-void WindowManagerStateTest::OnEventAckTimeout(
- ClientSpecificId client_id) {
- WindowManagerStateTestApi test_api(window_manager_state_);
- test_api.OnEventAckTimeout(client_id);
-}
-
-void WindowManagerStateTest::SetUp() {
- window_event_targeting_helper_.SetTaskRunner(task_runner_);
- window_manager_state_ = window_event_targeting_helper_.display()
- ->window_manager_display_root()
- ->window_manager_state();
- window_ = window_event_targeting_helper_.CreatePrimaryTree(
- gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 50, 50));
- window_tree_ = window_event_targeting_helper_.last_binding()->tree();
- window_tree_client_ =
- window_event_targeting_helper_.last_window_tree_client();
- ASSERT_TRUE(window_tree_->HasRoot(window_));
-
- WindowTreeTestApi(tree()).set_window_manager_internal(&window_manager_);
- wm_client()->tracker()->changes()->clear();
- window_tree_client_->tracker()->changes()->clear();
-}
-
-void SetCanFocusUp(ServerWindow* window) {
- while (window) {
- window->set_can_focus(true);
- window = window->parent();
- }
-}
-
-class WindowManagerStateTestAsync : public WindowManagerStateTest {
- public:
- WindowManagerStateTestAsync() {}
- ~WindowManagerStateTestAsync() override {}
-
- // WindowManagerStateTest:
- void SetUp() override {
- base::CommandLine::ForCurrentProcess()->AppendSwitch(
- switches::kUseAsyncEventTargeting);
- WindowManagerStateTest::SetUp();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTestAsync);
-};
-
-EventLocation EventLocationFromEvent(const Event& event,
- const Display& display) {
- EventLocation event_location(display.GetId());
- if (event.IsLocatedEvent()) {
- event_location.raw_location = event_location.location =
- event.AsLocatedEvent()->root_location_f();
- }
- return event_location;
-}
-
-// Tests that when an event is dispatched with no accelerator, that post target
-// accelerator is not triggered.
-TEST_F(WindowManagerStateTest, NullAccelerator) {
- WindowManagerState* state = window_manager_state();
- EXPECT_TRUE(state);
-
- ServerWindow* target = window();
- const Display* display = window_tree()->GetDisplay(target);
- ASSERT_TRUE(display);
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- DispatchInputEventToWindow(target, EventLocationFromEvent(key, *display), key,
- nullptr);
- WindowTree* target_tree = window_tree();
- TestChangeTracker* tracker = window_tree_client()->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
-
- WindowTreeTestApi(target_tree).AckOldestEvent();
- EXPECT_FALSE(window_manager()->on_accelerator_called());
-}
-
-// Tests that when a post target accelerator is provided on an event, that it is
-// called on ack.
-TEST_F(WindowManagerStateTest, PostTargetAccelerator) {
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
-
- ServerWindow* target = window();
- const Display* display = window_tree()->GetDisplay(target);
- ASSERT_TRUE(display);
- DispatchInputEventToWindow(target, EventLocationFromEvent(key, *display), key,
- accelerator.get());
- TestChangeTracker* tracker = window_tree_client()->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
-
- WindowTreeTestApi(window_tree()).AckOldestEvent();
- EXPECT_TRUE(window_manager()->on_accelerator_called());
- EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
-}
-
-// Tests that if a pre target accelerator consumes the event no other processing
-// is done.
-TEST_F(WindowManagerStateTest, PreTargetConsumed) {
- // Set up two trees with focus on a child in the second.
- const ClientWindowId child_window_id(window_tree()->id(), 11);
- window_tree()->NewWindow(child_window_id, ServerWindow::Properties());
- ServerWindow* child_window =
- window_tree()->GetWindowByClientId(child_window_id);
- window_tree()->AddWindow(FirstRootId(window_tree()), child_window_id);
- child_window->SetVisible(true);
- SetCanFocusUp(child_window);
- child_window->parent()->set_is_activation_parent(true);
- ASSERT_TRUE(window_tree()->SetFocus(child_window_id));
-
- // Register a pre-accelerator.
- uint32_t accelerator_id = 11;
- {
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
-
- ASSERT_TRUE(window_manager_state()->event_processor()->AddAccelerator(
- accelerator_id, std::move(matcher)));
- }
- TestChangeTracker* tracker = wm_client()->tracker();
- tracker->changes()->clear();
- TestChangeTracker* tracker2 = window_tree_client()->tracker();
- tracker2->changes()->clear();
-
- // Send and ensure only the pre accelerator is called.
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- bool was_event_processed = false;
- window_manager_state()->ProcessEvent(&key, 0);
- window_manager_state()->ScheduleCallbackWhenDoneProcessingEvents(
- base::BindOnce(&SetBoolToTrue, &was_event_processed));
- EXPECT_TRUE(window_manager()->on_accelerator_called());
- EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id());
- EXPECT_TRUE(tracker->changes()->empty());
- EXPECT_TRUE(tracker2->changes()->empty());
- EXPECT_FALSE(was_event_processed);
-
- // Ack the accelerator, saying we consumed it.
- WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::HANDLED);
- EXPECT_TRUE(was_event_processed);
- // Nothing should change.
- EXPECT_TRUE(tracker->changes()->empty());
- EXPECT_TRUE(tracker2->changes()->empty());
-
- was_event_processed = false;
- window_manager()->ClearAcceleratorCalled();
-
- // Repeat, but respond with UNHANDLED.
- window_manager_state()->ProcessEvent(&key, 0);
- window_manager_state()->ScheduleCallbackWhenDoneProcessingEvents(
- base::BindOnce(&SetBoolToTrue, &was_event_processed));
- EXPECT_FALSE(was_event_processed);
- EXPECT_TRUE(window_manager()->on_accelerator_called());
- EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id());
- EXPECT_TRUE(tracker->changes()->empty());
- EXPECT_TRUE(tracker2->changes()->empty());
- WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::UNHANDLED);
- // |was_event_processed| is false because the accelerator wasn't completely
- // handled yet.
- EXPECT_FALSE(was_event_processed);
-
- EXPECT_TRUE(tracker->changes()->empty());
- // The focused window should get the event.
- EXPECT_EQ("InputEvent window=0,11 event_action=7",
- SingleChangeToDescription(*tracker2->changes()));
- WindowTreeTestApi(window_tree()).AckLastEvent(mojom::EventResult::HANDLED);
- EXPECT_TRUE(was_event_processed);
-}
-
-TEST_F(WindowManagerStateTest, AckWithProperties) {
- // Set up two trees with focus on a child in the second.
- const ClientWindowId child_window_id(window_tree()->id(), 11);
- window_tree()->NewWindow(child_window_id, ServerWindow::Properties());
- ServerWindow* child_window =
- window_tree()->GetWindowByClientId(child_window_id);
- window_tree()->AddWindow(FirstRootId(window_tree()), child_window_id);
- child_window->SetVisible(true);
- SetCanFocusUp(child_window);
- child_window->parent()->set_is_activation_parent(true);
- ASSERT_TRUE(window_tree()->SetFocus(child_window_id));
-
- // Register a pre-accelerator.
- uint32_t accelerator_id = 11;
- {
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown);
-
- ASSERT_TRUE(window_manager_state()->event_processor()->AddAccelerator(
- accelerator_id, std::move(matcher)));
- }
- TestChangeTracker* tracker = wm_client()->tracker();
- tracker->changes()->clear();
- TestChangeTracker* tracker2 = window_tree_client()->tracker();
- tracker2->changes()->clear();
-
- // Send and ensure only the pre accelerator is called.
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- window_manager_state()->ProcessEvent(&key, 0);
- EXPECT_TRUE(window_manager()->on_accelerator_called());
- EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id());
- EXPECT_TRUE(tracker->changes()->empty());
- EXPECT_TRUE(tracker2->changes()->empty());
-
- // Ack the accelerator, with unhandled.
- base::flat_map<std::string, std::vector<uint8_t>> event_properties;
- const std::string property_key = "x";
- const std::vector<uint8_t> property_value(2, 0xAB);
- event_properties[property_key] = property_value;
- EXPECT_TRUE(tracker->changes()->empty());
- EXPECT_TRUE(tracker2->changes()->empty());
- WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::UNHANDLED,
- event_properties);
-
- // The focused window should get the event.
- EXPECT_EQ("InputEvent window=0,11 event_action=7",
- SingleChangeToDescription(*tracker2->changes()));
- ASSERT_EQ(1u, tracker2->changes()->size());
- EXPECT_EQ(1u, (*tracker2->changes())[0].key_event_properties.size());
- EXPECT_EQ(event_properties, (*tracker2->changes())[0].key_event_properties);
-
- WindowTreeTestApi(window_tree()).AckLastEvent(mojom::EventResult::HANDLED);
- tracker2->changes()->clear();
-
- // Send the event again, and ack with no properties. Ensure client gets no
- // properties.
- window_manager()->ClearAcceleratorCalled();
- window_manager_state()->ProcessEvent(&key, 0);
- EXPECT_TRUE(window_manager()->on_accelerator_called());
- EXPECT_EQ(accelerator_id, window_manager()->on_accelerator_id());
- EXPECT_TRUE(tracker->changes()->empty());
- EXPECT_TRUE(tracker2->changes()->empty());
-
- // Ack the accelerator with unhandled.
- WindowTreeTestApi(tree()).AckLastAccelerator(mojom::EventResult::UNHANDLED);
-
- // The focused window should get the event.
- EXPECT_EQ("InputEvent window=0,11 event_action=7",
- SingleChangeToDescription(*tracker2->changes()));
- ASSERT_EQ(1u, tracker2->changes()->size());
- EXPECT_TRUE((*tracker2->changes())[0].key_event_properties.empty());
-}
-
-// Tests that when a client handles an event that post target accelerators are
-// not called.
-TEST_F(WindowManagerStateTest, ClientHandlesEvent) {
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
-
- ServerWindow* target = window();
- const Display* display = window_tree()->GetDisplay(target);
- ASSERT_TRUE(display);
- DispatchInputEventToWindow(target, EventLocationFromEvent(key, *display), key,
- accelerator.get());
- TestChangeTracker* tracker = window_tree_client()->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
-
- EXPECT_TRUE(WindowManagerStateTestApi(window_manager_state())
- .AckInFlightEvent(mojom::EventResult::HANDLED));
- EXPECT_FALSE(window_manager()->on_accelerator_called());
-}
-
-// Tests that when an accelerator is deleted before an ack, that it is not
-// called.
-TEST_F(WindowManagerStateTest, AcceleratorDeleted) {
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- std::unique_ptr<Accelerator> accelerator(CreateAccelerator());
-
- ServerWindow* target = window();
- const Display* display = window_tree()->GetDisplay(target);
- ASSERT_TRUE(display);
- DispatchInputEventToWindow(target, EventLocationFromEvent(key, *display), key,
- accelerator.get());
- TestChangeTracker* tracker = window_tree_client()->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
-
- accelerator.reset();
- EXPECT_TRUE(WindowManagerStateTestApi(window_manager_state())
- .AckInFlightEvent(mojom::EventResult::UNHANDLED));
- EXPECT_FALSE(window_manager()->on_accelerator_called());
-}
-
-// Tests that a events arriving before an ack don't notify the tree until the
-// ack arrives, and that the correct accelerator is called.
-TEST_F(WindowManagerStateTest, EnqueuedAccelerators) {
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- std::unique_ptr<Accelerator> accelerator(CreateAccelerator());
-
- ServerWindow* target = window();
- const Display* display = window_tree()->GetDisplay(target);
- ASSERT_TRUE(display);
- DispatchInputEventToWindow(target, EventLocationFromEvent(key, *display), key,
- accelerator.get());
- TestChangeTracker* tracker = window_tree_client()->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
-
- tracker->changes()->clear();
- ui::KeyEvent key2(ui::ET_KEY_PRESSED, ui::VKEY_Y, ui::EF_CONTROL_DOWN);
- mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher(
- ui::mojom::KeyboardCode::Y, ui::mojom::kEventFlagControlDown);
- matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET;
- uint32_t accelerator_id = 2;
- std::unique_ptr<Accelerator> accelerator2(
- new Accelerator(accelerator_id, *matcher));
- DispatchInputEventToWindow(target, EventLocationFromEvent(key2, *display),
- key2, accelerator2.get());
- EXPECT_TRUE(tracker->changes()->empty());
-
- WindowTreeTestApi(window_tree()).AckOldestEvent();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
- EXPECT_TRUE(window_manager()->on_accelerator_called());
- EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
-}
-
-// Tests that the accelerator is not sent when the tree is dying.
-TEST_F(WindowManagerStateTest, DeleteTree) {
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
-
- ServerWindow* target = window();
- const Display* display = window_tree()->GetDisplay(target);
- ASSERT_TRUE(display);
- DispatchInputEventToWindow(target, EventLocationFromEvent(key, *display), key,
- accelerator.get());
- TestChangeTracker* tracker = window_tree_client()->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
-
- window_manager_state()->OnWillDestroyTree(tree());
- EXPECT_FALSE(window_manager()->on_accelerator_called());
-}
-
-// Tests that if a tree is destroyed before acking, that the accelerator is
-// still sent if it is not the root tree.
-TEST_F(WindowManagerStateTest, DeleteNonRootTree) {
- TestWindowTreeClient* embed_connection = nullptr;
- WindowTree* target_tree = nullptr;
- ServerWindow* target = nullptr;
- CreateSecondaryTree(&embed_connection, &target_tree, &target);
- TestWindowManager target_window_manager;
- WindowTreeTestApi(target_tree)
- .set_window_manager_internal(&target_window_manager);
-
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
- const Display* display = target_tree->GetDisplay(target);
- ASSERT_TRUE(display);
- DispatchInputEventToWindow(target, EventLocationFromEvent(key, *display), key,
- accelerator.get());
- TestChangeTracker* tracker = embed_connection->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- // clients that created this window is receiving the event, so client_id part
- // would be reset to 0 before sending back to clients.
- EXPECT_EQ("InputEvent window=0," + std::to_string(kEmbedTreeWindowId) +
- " event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
- EXPECT_TRUE(wm_client()->tracker()->changes()->empty());
-
- window_manager_state()->OnWillDestroyTree(target_tree);
- EXPECT_FALSE(target_window_manager.on_accelerator_called());
- EXPECT_TRUE(window_manager()->on_accelerator_called());
-}
-
-// Tests that if a tree is destroyed before acking an event, that mus won't
-// then try to send any queued events.
-TEST_F(WindowManagerStateTest, DontSendQueuedEventsToADeadTree) {
- ServerWindow* target = window();
- TestChangeTracker* tracker = window_tree_client()->tracker();
-
- const Display* display = window_tree()->GetDisplay(target);
- ASSERT_TRUE(display);
- ui::MouseEvent press(ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
- base::TimeTicks(), EF_LEFT_MOUSE_BUTTON,
- EF_LEFT_MOUSE_BUTTON);
- DispatchInputEventToWindow(target, EventLocationFromEvent(press, *display),
- press, nullptr);
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=1",
- ChangesToDescription1(*tracker->changes())[0]);
- tracker->changes()->clear();
- // The above is not setting TreeAwaitingInputAck.
-
- // Queue the key release event; it should not be immediately dispatched
- // because there's no ACK for the last one.
- ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(5, 5),
- gfx::Point(5, 5), base::TimeTicks(),
- EF_LEFT_MOUSE_BUTTON, EF_LEFT_MOUSE_BUTTON);
- DispatchInputEventToWindow(target, EventLocationFromEvent(release, *display),
- release, nullptr);
- EXPECT_EQ(0u, tracker->changes()->size());
-
- // Destroying a window tree with an event in queue shouldn't crash.
- DestroyWindowTree();
-}
-
-// Tests that when an ack times out that the accelerator is notified.
-TEST_F(WindowManagerStateTest, AckTimeout) {
- ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
- std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
- const Display* display = window_tree()->GetDisplay(window());
- ASSERT_TRUE(display);
- DispatchInputEventToWindow(window(), EventLocationFromEvent(key, *display),
- key, accelerator.get());
- TestChangeTracker* tracker = window_tree_client()->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
-
- OnEventAckTimeout(window()->owning_tree_id());
- EXPECT_TRUE(window_manager()->on_accelerator_called());
- EXPECT_EQ(accelerator->id(), window_manager()->on_accelerator_id());
-}
-
-TEST_F(WindowManagerStateTest, InterceptingEmbedderReceivesEvents) {
- WindowTree* embedder_tree = tree();
- const ClientWindowId embed_window_id(embedder_tree->id(), 12);
- embedder_tree->NewWindow(embed_window_id, ServerWindow::Properties());
- ServerWindow* embedder_window =
- embedder_tree->GetWindowByClientId(embed_window_id);
- ASSERT_TRUE(
- embedder_tree->AddWindow(FirstRootId(embedder_tree), embed_window_id));
-
- TestWindowTreeClient* embedder_client = wm_client();
-
- {
- // Do a normal embed.
- const uint32_t embed_flags = 0;
- WindowTree* embed_tree = nullptr;
- TestWindowTreeClient* embed_client_proxy = nullptr;
- EmbedAt(embedder_tree, embed_window_id, embed_flags, &embed_tree,
- &embed_client_proxy);
- ASSERT_TRUE(embed_client_proxy);
-
- // Send an event to the embed window. It should go to the embedded client.
- const Display* display = embed_tree->GetDisplay(embedder_window);
- ASSERT_TRUE(display);
- ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
- base::TimeTicks(), 0, 0);
- DispatchInputEventToWindow(embedder_window,
- EventLocationFromEvent(mouse, *display), mouse,
- nullptr);
- ASSERT_EQ(1u, embed_client_proxy->tracker()->changes()->size());
- EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT,
- (*embed_client_proxy->tracker()->changes())[0].type);
- WindowTreeTestApi(embed_tree).AckLastEvent(mojom::EventResult::UNHANDLED);
- embed_client_proxy->tracker()->changes()->clear();
- }
-
- {
- // Do an embed where the embedder wants to intercept events to the embedded
- // tree.
- const uint32_t embed_flags = mojom::kEmbedFlagEmbedderInterceptsEvents;
- WindowTree* embed_tree = nullptr;
- TestWindowTreeClient* embed_client_proxy = nullptr;
- const ClientWindowId embed_client_window_id =
- embedder_window->frame_sink_id();
- EmbedAt(embedder_tree, embed_window_id, embed_flags, &embed_tree,
- &embed_client_proxy);
- ASSERT_TRUE(embed_client_proxy);
- embedder_client->tracker()->changes()->clear();
-
- // Send an event to the embed window. But this time, it should reach the
- // embedder.
- const Display* display = embed_tree->GetDisplay(embedder_window);
- ASSERT_TRUE(display);
- ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
- base::TimeTicks(), 0, 0);
- DispatchInputEventToWindow(embedder_window,
- EventLocationFromEvent(mouse, *display), mouse,
- nullptr);
- ASSERT_EQ(0u, embed_client_proxy->tracker()->changes()->size());
- ASSERT_EQ(1u, embedder_client->tracker()->changes()->size());
- EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT,
- (*embedder_client->tracker()->changes())[0].type);
- WindowTreeTestApi(embedder_tree)
- .AckLastEvent(mojom::EventResult::UNHANDLED);
- embedder_client->tracker()->changes()->clear();
-
- // Embed another tree in the embedded tree.
- const ClientWindowId nested_embed_window_id(embed_tree->id(), 23);
- embed_tree->NewWindow(nested_embed_window_id, ServerWindow::Properties());
- ASSERT_TRUE(
- embed_tree->AddWindow(embed_client_window_id, nested_embed_window_id));
-
- WindowTree* nested_embed_tree = nullptr;
- TestWindowTreeClient* nested_embed_client_proxy = nullptr;
- // Intercept events (kEmbedFlagEmbedderInterceptsEvents) is inherited, so
- // even though this doesn't explicitly specify
- // kEmbedFlagEmbedderInterceptsEvents it gets
- // kEmbedFlagEmbedderInterceptsEvents from the parent embedding.
- EmbedAt(embed_tree, nested_embed_window_id, 0, &nested_embed_tree,
- &nested_embed_client_proxy);
- ASSERT_TRUE(nested_embed_client_proxy);
- embed_client_proxy->tracker()->changes()->clear();
- embedder_client->tracker()->changes()->clear();
-
- // Send an event to the nested embed window. The event should still reach
- // the outermost embedder.
- ServerWindow* nested_embed_window =
- embed_tree->GetWindowByClientId(nested_embed_window_id);
- ASSERT_TRUE(nested_embed_window->parent());
- mouse = ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
- base::TimeTicks(), 0, 0);
- DispatchInputEventToWindow(nested_embed_window,
- EventLocationFromEvent(mouse, *display), mouse,
- nullptr);
- ASSERT_EQ(0u, nested_embed_client_proxy->tracker()->changes()->size());
- ASSERT_EQ(0u, embed_client_proxy->tracker()->changes()->size());
-
- ASSERT_EQ(1u, embedder_client->tracker()->changes()->size());
- EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT,
- (*embedder_client->tracker()->changes())[0].type);
- WindowTreeTestApi(embedder_tree)
- .AckLastEvent(mojom::EventResult::UNHANDLED);
- }
-}
-
-// Ensures accelerators are forgotten between events.
-TEST_F(WindowManagerStateTest, PostAcceleratorForgotten) {
- // Send an event that matches the accelerator and have the target respond
- // that it handled the event so that the accelerator isn't called.
- ui::KeyEvent accelerator_key(ui::ET_KEY_PRESSED, ui::VKEY_W,
- ui::EF_CONTROL_DOWN);
- std::unique_ptr<Accelerator> accelerator = CreateAccelerator();
- ServerWindow* target = window();
- const Display* display = window_tree()->GetDisplay(target);
- ASSERT_TRUE(display);
- DispatchInputEventToWindow(target,
- EventLocationFromEvent(accelerator_key, *display),
- accelerator_key, accelerator.get());
- TestChangeTracker* tracker = window_tree_client()->tracker();
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
- tracker->changes()->clear();
- WindowTreeTestApi(window_tree()).AckLastEvent(mojom::EventResult::HANDLED);
- EXPECT_FALSE(window_manager()->on_accelerator_called());
-
- // Send another event that doesn't match the accelerator, the accelerator
- // shouldn't be called.
- ui::KeyEvent non_accelerator_key(ui::ET_KEY_PRESSED, ui::VKEY_T,
- ui::EF_CONTROL_DOWN);
- DispatchInputEventToWindow(
- target, EventLocationFromEvent(non_accelerator_key, *display),
- non_accelerator_key, nullptr);
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(
- "InputEvent window=" + kWindowManagerClientIdString + ",1 event_action=7",
- ChangesToDescription1(*tracker->changes())[0]);
- WindowTreeTestApi(window_tree()).AckLastEvent(mojom::EventResult::UNHANDLED);
- EXPECT_FALSE(window_manager()->on_accelerator_called());
-}
-
-// Verifies there is no crash if the WindowTree of a window manager is destroyed
-// with no roots.
-TEST(WindowManagerStateShutdownTest, DestroyTreeBeforeDisplay) {
- WindowServerTestHelper ws_test_helper;
- WindowServer* window_server = ws_test_helper.window_server();
- TestScreenManager screen_manager;
- screen_manager.Init(window_server->display_manager());
- screen_manager.AddDisplay();
- AddWindowManager(window_server);
- ASSERT_EQ(1u, window_server->display_manager()->displays().size());
- Display* display = *(window_server->display_manager()->displays().begin());
- WindowManagerDisplayRoot* window_manager_display_root =
- display->window_manager_display_root();
- ASSERT_TRUE(window_manager_display_root);
- WindowTree* tree =
- window_manager_display_root->window_manager_state()->window_tree();
- ASSERT_EQ(1u, tree->roots().size());
- ClientWindowId root_client_id;
- ASSERT_TRUE(tree->IsWindowKnown(*(tree->roots().begin()), &root_client_id));
- EXPECT_TRUE(tree->DeleteWindow(root_client_id));
- window_server->DestroyTree(tree);
-}
-
-TEST_F(WindowManagerStateTest, CursorResetOverNoTarget) {
- ASSERT_EQ(1u, window_server()->display_manager()->displays().size());
- const ClientWindowId child_window_id(window_tree()->id(), 11);
- window_tree()->NewWindow(child_window_id, ServerWindow::Properties());
- ServerWindow* child_window =
- window_tree()->GetWindowByClientId(child_window_id);
- window_tree()->AddWindow(FirstRootId(window_tree()), child_window_id);
- child_window->SetVisible(true);
- child_window->SetBounds(gfx::Rect(0, 0, 20, 20));
- child_window->parent()->SetCursor(ui::CursorData(ui::CursorType::kCopy));
- EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
- // Move the mouse outside the bounds of the child, so that the mouse is not
- // over any valid windows. Cursor should change to POINTER.
- ui::PointerEvent move(
- ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0,
- ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0),
- base::TimeTicks());
- window_manager_state()->ProcessEvent(&move, 0);
- // The event isn't over a valid target, which should trigger resetting the
- // cursor to POINTER.
- EXPECT_EQ(ui::CursorType::kPointer, cursor_type());
-}
-
-TEST(WindowManagerStateEventTest, AdjustEventLocation) {
- WindowServerTestHelper ws_test_helper;
- WindowServer* window_server = ws_test_helper.window_server();
- TestScreenManager screen_manager;
- screen_manager.Init(window_server->display_manager());
- AddWindowManager(window_server);
- const int64_t first_display_id = screen_manager.AddDisplay();
- const int64_t second_display_id = screen_manager.AddDisplay();
- Display* first_display =
- window_server->display_manager()->GetDisplayById(first_display_id);
- // As there are no child windows make sure the root is a valid target.
- first_display->window_manager_display_root()
- ->GetClientVisibleRoot()
- ->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- Display* second_display =
- window_server->display_manager()->GetDisplayById(second_display_id);
- ASSERT_TRUE(second_display);
- display::Display second_display_display = second_display->GetDisplay();
- second_display_display.set_bounds(gfx::Rect(100, 0, 100, 100));
- display::ViewportMetrics second_metrics;
- // The DIP display layout is horizontal and the pixel layout vertical.
- second_metrics.device_scale_factor = 1.0f;
- second_metrics.bounds_in_pixels = gfx::Rect(0, 200, 100, 100);
- second_metrics.ui_scale_factor = 1.0f;
- screen_manager.ModifyDisplay(second_display_display, second_metrics);
- const gfx::Point move_location(5, 210);
- ui::PointerEvent move(
- ui::ET_POINTER_MOVED, move_location, move_location, 0, 0,
- ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0),
- base::TimeTicks());
- WindowManagerDisplayRoot* window_manager_display_root =
- second_display->window_manager_display_root();
- TestChangeTracker* tracker =
- ws_test_helper.window_server_delegate()->last_client()->tracker();
- tracker->changes()->clear();
- window_manager_display_root->window_manager_state()->ProcessEvent(
- &move, first_display_id);
- ASSERT_EQ(1u, tracker->changes()->size());
- // |location2| is the location supplied in terms of the pixel display layout.
- EXPECT_EQ(gfx::PointF(move_location), (*tracker->changes())[0].location2);
- // |location1| is the location in DIP display layout.
- EXPECT_EQ(gfx::Point(105, 10), (*tracker->changes())[0].location1);
-}
-
-TEST_F(WindowManagerStateTest, CursorLocationManagerUpdatedOnMouseMove) {
- WindowManagerStateTestApi test_api(window_manager_state());
- ASSERT_EQ(1u, test_api.window_manager_display_roots().size());
- WindowManagerDisplayRoot* window_manager_display_root =
- test_api.window_manager_display_roots().begin()->get();
- ASSERT_TRUE(window_manager_display_root->GetClientVisibleRoot());
- // Install a transform on the root, which impacts the location reported to
- // clients.
- gfx::Transform transform;
- transform.Translate(6, 7);
- window_manager_display_root->GetClientVisibleRoot()->SetTransform(transform);
- ui::PointerEvent move(
- ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0,
- ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0),
- base::TimeTicks());
- // Tests add display with kInvalidDisplayId.
- window_manager_state()->ProcessEvent(&move, display::kInvalidDisplayId);
- CursorLocationManager* cursor_location_manager =
- window_server()->display_manager()->cursor_location_manager();
- // The location reported to clients is offset by the root transform.
- EXPECT_EQ(
- gfx::Point(19, 18),
- Atomic32ToPoint(CursorLocationManagerTestApi(cursor_location_manager)
- .current_cursor_location()));
-}
-
-TEST_F(WindowManagerStateTest, SetCapture) {
- ASSERT_EQ(1u, window_server()->display_manager()->displays().size());
- Display* display = *(window_server()->display_manager()->displays().begin());
- TestPlatformDisplay* platform_display =
- static_cast<TestPlatformDisplay*>(display->platform_display());
- EXPECT_TRUE(window_tree()->SetCapture(FirstRootId(window_tree())));
- EXPECT_EQ(FirstRoot(window_tree()), window_manager_state()->capture_window());
- EXPECT_TRUE(platform_display->has_capture());
- EXPECT_TRUE(window_tree()->ReleaseCapture(FirstRootId(window_tree())));
- EXPECT_FALSE(platform_display->has_capture());
-
- // In unified mode capture should not propagate to the PlatformDisplay. This
- // is for compatibility with classic ash. See http://crbug.com/773348.
- display->SetDisplay(display::Display(display::kUnifiedDisplayId));
- EXPECT_TRUE(window_tree()->SetCapture(FirstRootId(window_tree())));
- EXPECT_EQ(FirstRoot(window_tree()), window_manager_state()->capture_window());
- EXPECT_FALSE(platform_display->has_capture());
- EXPECT_TRUE(window_tree()->ReleaseCapture(FirstRootId(window_tree())));
- EXPECT_FALSE(platform_display->has_capture());
-}
-
-TEST_F(WindowManagerStateTestAsync, CursorResetOverNoTargetAsync) {
- ASSERT_EQ(1u, window_server()->display_manager()->displays().size());
- const ClientWindowId child_window_id(window_tree()->id(), 11);
- window_tree()->NewWindow(child_window_id, ServerWindow::Properties());
- ServerWindow* child_window =
- window_tree()->GetWindowByClientId(child_window_id);
- window_tree()->AddWindow(FirstRootId(window_tree()), child_window_id);
- // Setup steps already do hit-test for mouse cursor update so this should go
- // to the queue in EventTargeter.
- EventTargeterTestApi event_targeter_test_api(
- EventProcessorTestApi(window_manager_state()->event_processor())
- .event_targeter());
- EXPECT_TRUE(event_targeter_test_api.HasPendingQueries());
- // But no events have been generated, so IsProcessingEvent() should be false.
- EXPECT_FALSE(window_manager_state()->event_processor()->IsProcessingEvent());
- child_window->SetVisible(true);
- child_window->SetBounds(gfx::Rect(0, 0, 20, 20));
- child_window->parent()->SetCursor(ui::CursorData(ui::CursorType::kCopy));
- // Move the mouse outside the bounds of the child, so that the mouse is not
- // over any valid windows. Cursor should change to POINTER.
- ui::PointerEvent move(
- ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0,
- ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0),
- base::TimeTicks());
- WindowManagerStateTestApi test_api(window_manager_state());
- EXPECT_TRUE(test_api.is_event_tasks_empty());
- window_manager_state()->ProcessEvent(&move, 0);
- EXPECT_FALSE(test_api.tree_awaiting_input_ack());
- EXPECT_TRUE(window_manager_state()->event_processor()->IsProcessingEvent());
- EXPECT_TRUE(test_api.is_event_tasks_empty());
- task_runner_->RunUntilIdle();
- EXPECT_TRUE(test_api.is_event_tasks_empty());
- // The event isn't over a valid target, which should trigger resetting the
- // cursor to POINTER.
- EXPECT_EQ(ui::CursorType::kPointer, cursor_type());
-}
-
-TEST_F(WindowManagerStateTest, DeleteTreeWithPendingEventAck) {
- ASSERT_EQ(1u, window_server()->display_manager()->displays().size());
- Display* display = *(window_server()->display_manager()->displays().begin());
-
- TestWindowTreeClient* embed_connection = nullptr;
- WindowTree* target_tree = nullptr;
- ServerWindow* target = nullptr;
- CreateSecondaryTree(&embed_connection, &target_tree, &target);
- target->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
-
- bool was_event_processed = false;
- ui::PointerEvent move(
- ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0,
- ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0),
- base::TimeTicks());
- window_manager_state()->ProcessEvent(&move, display->GetId());
- window_manager_state()->ScheduleCallbackWhenDoneProcessingEvents(
- base::BindOnce(&SetBoolToTrue, &was_event_processed));
- EXPECT_FALSE(was_event_processed);
- EXPECT_TRUE(WindowTreeTestApi(target_tree).HasEventInFlight());
- window_server()->DestroyTree(target_tree);
- // Destroying the tree triggers the event to be considered processed.
- EXPECT_TRUE(was_event_processed);
-}
-
-TEST_F(WindowManagerStateTest, EventProcessedCallbackNotRunForGeneratedEvents) {
- ASSERT_EQ(1u, window_server()->display_manager()->displays().size());
- Display* display = *(window_server()->display_manager()->displays().begin());
-
- // Create two children of the root.
- ServerWindow* wm_root = FirstRoot(window_tree());
- wm_root->SetBounds(gfx::Rect(0, 0, 100, 100));
- wm_root->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- ServerWindow* child_window1 = NewWindowInTreeWithParent(
- window_tree(), wm_root, nullptr, gfx::Rect(0, 0, 20, 20));
- child_window1->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- ServerWindow* child_window2 = NewWindowInTreeWithParent(
- window_tree(), wm_root, nullptr, gfx::Rect(50, 0, 20, 20));
- child_window2->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
-
- TestChangeTracker* tracker = window_tree_client()->tracker();
- tracker->changes()->clear();
-
- bool was_event_processed = false;
- ui::PointerEvent move1(
- ui::ET_POINTER_MOVED, gfx::Point(15, 15), gfx::Point(15, 15), 0, 0,
- ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0),
- base::TimeTicks());
- window_manager_state()->ProcessEvent(&move1, display->GetId());
- window_manager_state()->ScheduleCallbackWhenDoneProcessingEvents(
- base::BindOnce(&SetBoolToTrue, &was_event_processed));
- EXPECT_FALSE(was_event_processed);
- EXPECT_TRUE(WindowTreeTestApi(window_tree()).HasEventInFlight());
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, (*tracker->changes())[0].type);
- tracker->changes()->clear();
- WindowTreeTestApi(window_tree()).AckLastEvent(mojom::EventResult::HANDLED);
- EXPECT_TRUE(was_event_processed);
- was_event_processed = false;
-
- ui::PointerEvent move2(
- ui::ET_POINTER_MOVED, gfx::Point(65, 15), gfx::Point(65, 15), 0, 0,
- ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0),
- base::TimeTicks());
- window_manager_state()->ProcessEvent(&move2, display->GetId());
- window_manager_state()->ScheduleCallbackWhenDoneProcessingEvents(
- base::BindOnce(&SetBoolToTrue, &was_event_processed));
- EXPECT_FALSE(was_event_processed);
- EXPECT_TRUE(WindowTreeTestApi(window_tree()).HasEventInFlight());
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, (*tracker->changes())[0].type);
- EXPECT_EQ(ET_POINTER_EXITED, (*tracker->changes())[0].event_action);
- tracker->changes()->clear();
-
- WindowTreeTestApi(window_tree()).AckLastEvent(mojom::EventResult::HANDLED);
- // |was_event_processed| is false, because the exit was synthesized and will
- // be followed by a move.
- EXPECT_FALSE(was_event_processed);
- ASSERT_EQ(1u, tracker->changes()->size());
- EXPECT_EQ(CHANGE_TYPE_INPUT_EVENT, (*tracker->changes())[0].type);
- EXPECT_EQ(ET_POINTER_MOVED, (*tracker->changes())[0].event_action);
- tracker->changes()->clear();
- WindowTreeTestApi(window_tree()).AckLastEvent(mojom::EventResult::HANDLED);
- EXPECT_TRUE(was_event_processed);
- EXPECT_TRUE(tracker->changes()->empty());
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_manager_window_tree_factory.cc b/services/ui/ws/window_manager_window_tree_factory.cc
deleted file mode 100644
index 7e279889..0000000
--- a/services/ui/ws/window_manager_window_tree_factory.cc
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/window_manager_window_tree_factory.h"
-
-#include "base/bind.h"
-#include "services/ui/ws/display_creation_config.h"
-#include "services/ui/ws/window_manager_window_tree_factory_observer.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree.h"
-
-namespace ui {
-namespace ws {
-
-WindowManagerWindowTreeFactory::WindowManagerWindowTreeFactory(
- WindowServer* window_server)
- : window_server_(window_server), binding_(this) {}
-
-WindowManagerWindowTreeFactory::~WindowManagerWindowTreeFactory() {}
-
-void WindowManagerWindowTreeFactory::Bind(
- mojo::InterfaceRequest<mojom::WindowManagerWindowTreeFactory> request) {
- binding_.Bind(std::move(request));
-}
-
-void WindowManagerWindowTreeFactory::AddObserver(
- WindowManagerWindowTreeFactoryObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void WindowManagerWindowTreeFactory::RemoveObserver(
- WindowManagerWindowTreeFactoryObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-void WindowManagerWindowTreeFactory::OnTreeDestroyed() {
- window_tree_ = nullptr;
-}
-
-void WindowManagerWindowTreeFactory::CreateWindowTree(
- mojom::WindowTreeRequest window_tree_request,
- mojom::WindowTreeClientPtr window_tree_client,
- bool automatically_create_display_roots) {
- if (window_tree_) {
- DVLOG(1) << "CreateWindowTree() called more than once.";
- return;
- }
-
- // CreateWindowTree() can only be called once, so there is no reason to keep
- // the binding around.
- if (binding_.is_bound())
- binding_.Close();
-
- // If the config is MANUAL, then all WindowManagers must connect as MANUAL.
- if (!automatically_create_display_roots &&
- window_server_->display_creation_config() ==
- DisplayCreationConfig::AUTOMATIC) {
- DVLOG(1) << "CreateWindowTree() called with manual and automatic.";
- return;
- }
-
- SetWindowTree(window_server_->CreateTreeForWindowManager(
- std::move(window_tree_request), std::move(window_tree_client),
- automatically_create_display_roots));
-}
-
-void WindowManagerWindowTreeFactory::SetWindowTree(WindowTree* window_tree) {
- DCHECK(!window_tree_);
- window_tree_ = window_tree;
-
- for (WindowManagerWindowTreeFactoryObserver& observer : observers_)
- observer.OnWindowManagerWindowTreeFactoryReady(this);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_manager_window_tree_factory.h b/services/ui/ws/window_manager_window_tree_factory.h
deleted file mode 100644
index 7c2b2f1..0000000
--- a/services/ui/ws/window_manager_window_tree_factory.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_MANAGER_WINDOW_TREE_FACTORY_H_
-#define SERVICES_UI_WS_WINDOW_MANAGER_WINDOW_TREE_FACTORY_H_
-
-#include <stdint.h>
-
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class WindowManagerWindowTreeFactoryObserver;
-class WindowServer;
-class WindowTree;
-
-// Implementation of mojom::WindowManagerWindowTreeFactory.
-class WindowManagerWindowTreeFactory
- : public mojom::WindowManagerWindowTreeFactory {
- public:
- explicit WindowManagerWindowTreeFactory(WindowServer* window_server);
- ~WindowManagerWindowTreeFactory() override;
-
- WindowTree* window_tree() { return window_tree_; }
-
- bool is_bound() const { return binding_.is_bound(); }
-
- void Bind(
- mojo::InterfaceRequest<mojom::WindowManagerWindowTreeFactory> request);
-
- void AddObserver(WindowManagerWindowTreeFactoryObserver* observer);
- void RemoveObserver(WindowManagerWindowTreeFactoryObserver* observer);
-
- void OnTreeDestroyed();
-
- // mojom::WindowManagerWindowTreeFactory:
- void CreateWindowTree(mojom::WindowTreeRequest window_tree_request,
- mojom::WindowTreeClientPtr window_tree_client,
- bool window_manager_creates_roots) override;
-
- private:
- void SetWindowTree(WindowTree* window_tree);
-
- WindowServer* window_server_;
- mojo::Binding<mojom::WindowManagerWindowTreeFactory> binding_;
-
- // Owned by WindowServer.
- WindowTree* window_tree_ = nullptr;
-
- base::ObserverList<WindowManagerWindowTreeFactoryObserver> observers_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerWindowTreeFactory);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_MANAGER_WINDOW_TREE_FACTORY_H_
diff --git a/services/ui/ws/window_manager_window_tree_factory_observer.h b/services/ui/ws/window_manager_window_tree_factory_observer.h
deleted file mode 100644
index 70a0ff7..0000000
--- a/services/ui/ws/window_manager_window_tree_factory_observer.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_MANAGER_WINDOW_TREE_FACTORY_OBSERVER_H_
-#define SERVICES_UI_WS_WINDOW_MANAGER_WINDOW_TREE_FACTORY_OBSERVER_H_
-
-namespace ui {
-namespace ws {
-
-class WindowManagerWindowTreeFactory;
-
-class WindowManagerWindowTreeFactoryObserver {
- public:
- // Called when the WindowTree associated with |factory| has been set
- virtual void OnWindowManagerWindowTreeFactoryReady(
- WindowManagerWindowTreeFactory* factory) = 0;
-
- protected:
- virtual ~WindowManagerWindowTreeFactoryObserver() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_MANAGER_WINDOW_TREE_FACTORY_OBSERVER_H_
diff --git a/services/ui/ws/window_server.cc b/services/ui/ws/window_server.cc
deleted file mode 100644
index a362d6f9..0000000
--- a/services/ui/ws/window_server.cc
+++ /dev/null
@@ -1,1078 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/window_server.h"
-
-#include <set>
-#include <string>
-
-#include "base/logging.h"
-#include "base/memory/ptr_util.h"
-#include "base/stl_util.h"
-#include "components/viz/common/switches.h"
-#include "services/ui/gpu_host/gpu_host.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_creation_config.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/frame_generator.h"
-#include "services/ui/ws/operation.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/user_activity_monitor.h"
-#include "services/ui/ws/window_manager_access_policy.h"
-#include "services/ui/ws/window_manager_display_root.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_manager_window_tree_factory.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "ui/gfx/geometry/size_conversions.h"
-
-namespace ui {
-namespace ws {
-
-namespace {
-
-// Returns true if |window| is considered the active window manager for
-// |display|.
-bool IsWindowConsideredWindowManagerRoot(const Display* display,
- const ServerWindow* window) {
- if (!display)
- return false;
-
- const WindowManagerDisplayRoot* display_root =
- display->window_manager_display_root();
- return display_root && display_root->GetClientVisibleRoot() == window;
-}
-
-class VizHostProxyImpl : public VizHostProxy {
- public:
- explicit VizHostProxyImpl(viz::HostFrameSinkManager* manager)
- : manager_(manager) {}
-
- ~VizHostProxyImpl() override = default;
-
- // VizHostProxy:
- void RegisterFrameSinkId(const viz::FrameSinkId& frame_sink_id,
- viz::HostFrameSinkClient* client) override {
- if (manager_)
- manager_->RegisterFrameSinkId(frame_sink_id, client);
- }
-
- void SetFrameSinkDebugLabel(const viz::FrameSinkId& frame_sink_id,
- const std::string& name) override {
- if (manager_)
- manager_->SetFrameSinkDebugLabel(frame_sink_id, name);
- }
-
- void InvalidateFrameSinkId(const viz::FrameSinkId& frame_sink_id) override {
- if (manager_)
- manager_->InvalidateFrameSinkId(frame_sink_id);
- }
-
- void RegisterFrameSinkHierarchy(const viz::FrameSinkId& new_parent,
- const viz::FrameSinkId& child) override {
- if (manager_)
- manager_->RegisterFrameSinkHierarchy(new_parent, child);
- }
-
- void UnregisterFrameSinkHierarchy(const viz::FrameSinkId& old_parent,
- const viz::FrameSinkId& child) override {
- if (manager_)
- manager_->UnregisterFrameSinkHierarchy(old_parent, child);
- }
-
- void CreateRootCompositorFrameSink(
- viz::mojom::RootCompositorFrameSinkParamsPtr params) override {
- // No software compositing on ChromeOS.
- params->gpu_compositing = true;
-
- if (manager_)
- manager_->CreateRootCompositorFrameSink(std::move(params));
- }
-
- void CreateCompositorFrameSink(
- const viz::FrameSinkId& frame_sink_id,
- viz::mojom::CompositorFrameSinkRequest request,
- viz::mojom::CompositorFrameSinkClientPtr client) override {
- if (manager_) {
- manager_->CreateCompositorFrameSink(frame_sink_id, std::move(request),
- std::move(client));
- }
- }
-
- viz::HitTestQuery* GetHitTestQuery(
- const viz::FrameSinkId& frame_sink_id) override {
- if (!manager_)
- return nullptr;
- const auto& display_hit_test_query_map = manager_->display_hit_test_query();
- const auto iter = display_hit_test_query_map.find(frame_sink_id);
- return (iter != display_hit_test_query_map.end()) ? iter->second.get()
- : nullptr;
- }
-
- private:
- viz::HostFrameSinkManager* const manager_;
-
- DISALLOW_COPY_AND_ASSIGN(VizHostProxyImpl);
-};
-
-} // namespace
-
-struct WindowServer::CurrentMoveLoopState {
- uint32_t change_id;
- ServerWindow* window;
- WindowTree* initiator;
- gfx::Rect revert_bounds;
-};
-
-struct WindowServer::CurrentDragLoopState {
- uint32_t change_id;
- ServerWindow* window;
- WindowTree* initiator;
-};
-
-WindowServer::WindowServer(WindowServerDelegate* delegate, bool should_host_viz)
- : delegate_(delegate),
- next_client_id_(kWindowServerClientId + 1),
- display_manager_(std::make_unique<DisplayManager>(this, should_host_viz)),
- current_operation_(nullptr),
- in_destructor_(false),
- next_wm_change_id_(0),
- window_manager_window_tree_factory_(
- std::make_unique<WindowManagerWindowTreeFactory>(this)),
- host_frame_sink_manager_(
- should_host_viz ? std::make_unique<viz::HostFrameSinkManager>()
- : nullptr),
- viz_host_proxy_(
- std::make_unique<VizHostProxyImpl>(host_frame_sink_manager_.get())),
- video_detector_(host_frame_sink_manager_.get()),
- display_creation_config_(DisplayCreationConfig::UNKNOWN) {
- if (host_frame_sink_manager_)
- host_frame_sink_manager_->WillAssignTemporaryReferencesExternally();
- user_activity_monitor_ = std::make_unique<UserActivityMonitor>(nullptr);
-}
-
-WindowServer::~WindowServer() {
- in_destructor_ = true;
-
- for (auto& pair : tree_map_)
- pair.second->PrepareForWindowServerShutdown();
-
- // Destroys the window trees results in querying for the display. Tear down
- // the displays first so that the trees are notified of the display going
- // away while the display is still valid.
- display_manager_->DestroyAllDisplays();
-
- while (!tree_map_.empty())
- DestroyTree(tree_map_.begin()->second.get());
-
- display_manager_.reset();
-}
-
-void WindowServer::SetDisplayCreationConfig(DisplayCreationConfig config) {
- DCHECK(tree_map_.empty());
- DCHECK_EQ(DisplayCreationConfig::UNKNOWN, display_creation_config_);
- display_creation_config_ = config;
- display_manager_->OnDisplayCreationConfigSet();
-}
-
-void WindowServer::SetGpuHost(std::unique_ptr<gpu_host::GpuHost> gpu_host) {
- DCHECK(host_frame_sink_manager_);
- gpu_host_ = std::move(gpu_host);
- CreateFrameSinkManager();
-}
-
-ThreadedImageCursorsFactory* WindowServer::GetThreadedImageCursorsFactory() {
- return delegate()->GetThreadedImageCursorsFactory();
-}
-
-ServerWindow* WindowServer::CreateServerWindow(
- const viz::FrameSinkId& frame_sink_id,
- const std::map<std::string, std::vector<uint8_t>>& properties) {
- ServerWindow* window = new ServerWindow(this, frame_sink_id, properties);
- window->AddObserver(this);
- return window;
-}
-
-ClientSpecificId WindowServer::GetAndAdvanceNextClientId() {
- const ClientSpecificId id = next_client_id_++;
- CHECK_NE(0u, next_client_id_);
- return id;
-}
-
-WindowTree* WindowServer::EmbedAtWindow(
- ServerWindow* root,
- mojom::WindowTreeClientPtr client,
- uint32_t flags,
- std::unique_ptr<AccessPolicy> access_policy) {
- // TODO(sky): I suspect this code needs to reset the FrameSinkId to the
- // ClientWindowId that was used at the time the window was created. As
- // currently if there is a reembed the FrameSinkId from the last embedding
- // is incorrectly used.
- const bool is_for_embedding = true;
- std::unique_ptr<WindowTree> tree_ptr = std::make_unique<WindowTree>(
- this, is_for_embedding, root, std::move(access_policy));
- WindowTree* tree = tree_ptr.get();
- if (flags & mojom::kEmbedFlagEmbedderInterceptsEvents)
- tree->set_embedder_intercepts_events();
-
- if (flags & mojom::kEmbedFlagEmbedderControlsVisibility)
- tree->set_can_change_root_window_visibility(false);
-
- mojom::WindowTreePtr window_tree_ptr;
- auto window_tree_request = mojo::MakeRequest(&window_tree_ptr);
- std::unique_ptr<WindowTreeBinding> binding =
- delegate_->CreateWindowTreeBinding(
- WindowServerDelegate::BindingType::EMBED, this, tree,
- &window_tree_request, &client);
- if (!binding) {
- binding = std::make_unique<ws::DefaultWindowTreeBinding>(
- tree, this, std::move(window_tree_request), std::move(client));
- }
-
- AddTree(std::move(tree_ptr), std::move(binding), std::move(window_tree_ptr));
- OnTreeMessagedClient(tree->id());
- root->UpdateFrameSinkId(viz::FrameSinkId(tree->id(), 0));
- return tree;
-}
-
-void WindowServer::AddTree(std::unique_ptr<WindowTree> tree_impl_ptr,
- std::unique_ptr<WindowTreeBinding> binding,
- mojom::WindowTreePtr tree_ptr) {
- CHECK_EQ(0u, tree_map_.count(tree_impl_ptr->id()));
- WindowTree* tree = tree_impl_ptr.get();
- tree_map_[tree->id()] = std::move(tree_impl_ptr);
- tree->Init(std::move(binding), std::move(tree_ptr));
-}
-
-WindowTree* WindowServer::CreateTreeForWindowManager(
- mojom::WindowTreeRequest window_tree_request,
- mojom::WindowTreeClientPtr window_tree_client,
- bool automatically_create_display_roots) {
- delegate_->OnWillCreateTreeForWindowManager(
- automatically_create_display_roots);
-
- const bool is_for_embedding = false;
- std::unique_ptr<WindowTree> window_tree = std::make_unique<WindowTree>(
- this, is_for_embedding, nullptr,
- base::WrapUnique(new WindowManagerAccessPolicy));
- std::unique_ptr<WindowTreeBinding> window_tree_binding =
- delegate_->CreateWindowTreeBinding(
- WindowServerDelegate::BindingType::WINDOW_MANAGER, this,
- window_tree.get(), &window_tree_request, &window_tree_client);
- if (!window_tree_binding) {
- window_tree_binding = std::make_unique<DefaultWindowTreeBinding>(
- window_tree.get(), this, std::move(window_tree_request),
- std::move(window_tree_client));
- }
- WindowTree* window_tree_ptr = window_tree.get();
- AddTree(std::move(window_tree), std::move(window_tree_binding), nullptr);
- window_tree_ptr->ConfigureWindowManager(automatically_create_display_roots);
- return window_tree_ptr;
-}
-
-void WindowServer::DestroyTree(WindowTree* tree) {
- std::unique_ptr<WindowTree> tree_ptr;
- {
- auto iter = tree_map_.find(tree->id());
- DCHECK(iter != tree_map_.end());
- tree_ptr = std::move(iter->second);
- tree_map_.erase(iter);
- }
-
- base::EraseIf(scheduled_embeds_,
- [&tree](const std::pair<base::UnguessableToken,
- const WindowTreeAndWindowId&>& pair) {
- return (tree == pair.second.tree);
- });
-
- // Notify remaining connections so that they can cleanup.
- for (auto& pair : tree_map_)
- pair.second->OnWillDestroyTree(tree);
-
- if (window_manager_window_tree_factory_->window_tree() == tree)
- window_manager_window_tree_factory_->OnTreeDestroyed();
-
- // Remove any requests from the client that resulted in a call to the window
- // manager and we haven't gotten a response back yet.
- std::set<uint32_t> to_remove;
- for (auto& pair : in_flight_wm_change_map_) {
- if (pair.second.client_id == tree->id())
- to_remove.insert(pair.first);
- }
- for (uint32_t id : to_remove)
- in_flight_wm_change_map_.erase(id);
-}
-
-WindowTree* WindowServer::GetTreeWithId(ClientSpecificId client_id) {
- auto iter = tree_map_.find(client_id);
- return iter == tree_map_.end() ? nullptr : iter->second.get();
-}
-
-WindowTree* WindowServer::GetTreeWithClientName(
- const std::string& client_name) {
- for (const auto& entry : tree_map_) {
- if (entry.second->name() == client_name)
- return entry.second.get();
- }
- return nullptr;
-}
-
-base::UnguessableToken WindowServer::RegisterEmbedToken(
- WindowTree* tree,
- ClientSpecificId window_id) {
- const base::UnguessableToken token = base::UnguessableToken::Create();
- DCHECK(!scheduled_embeds_.count(token));
- scheduled_embeds_[token] = {tree, window_id};
- return token;
-}
-
-WindowTreeAndWindowId WindowServer::UnregisterEmbedToken(
- const base::UnguessableToken& token) {
- auto iter = scheduled_embeds_.find(token);
- if (iter == scheduled_embeds_.end())
- return {};
- WindowTreeAndWindowId result = iter->second;
- scheduled_embeds_.erase(iter);
- return result;
-}
-
-void WindowServer::OnTreeMessagedClient(ClientSpecificId id) {
- if (current_operation_)
- current_operation_->MarkTreeAsMessaged(id);
-}
-
-bool WindowServer::DidTreeMessageClient(ClientSpecificId id) const {
- return current_operation_ && current_operation_->DidMessageTree(id);
-}
-
-const WindowTree* WindowServer::GetTreeWithRoot(
- const ServerWindow* window) const {
- if (!window)
- return nullptr;
- for (auto& pair : tree_map_) {
- if (pair.second->HasRoot(window))
- return pair.second.get();
- }
- return nullptr;
-}
-
-void WindowServer::BindWindowManagerWindowTreeFactory(
- mojo::InterfaceRequest<mojom::WindowManagerWindowTreeFactory> request) {
- if (window_manager_window_tree_factory_->is_bound()) {
- DVLOG(1) << "Can only have one WindowManagerWindowTreeFactory";
- return;
- }
- window_manager_window_tree_factory_->Bind(std::move(request));
-}
-
-bool WindowServer::SetFocusedWindow(ServerWindow* window) {
- // TODO(sky): this should fail if there is modal dialog active and |window|
- // is outside that.
- ServerWindow* currently_focused = GetFocusedWindow();
- Display* focused_display =
- currently_focused
- ? display_manager_->GetDisplayContaining(currently_focused)
- : nullptr;
- if (!window)
- return focused_display ? focused_display->SetFocusedWindow(nullptr) : true;
-
- Display* display = display_manager_->GetDisplayContaining(window);
- DCHECK(display); // It's assumed callers do validation before calling this.
- const bool result = display->SetFocusedWindow(window);
- // If the focus actually changed, and focus was in another display, then we
- // need to notify the previously focused display so that it cleans up state
- // and notifies appropriately.
- if (result && display->GetFocusedWindow() && display != focused_display &&
- focused_display) {
- const bool cleared_focus = focused_display->SetFocusedWindow(nullptr);
- DCHECK(cleared_focus);
- }
- return result;
-}
-
-ServerWindow* WindowServer::GetFocusedWindow() {
- for (Display* display : display_manager_->displays()) {
- ServerWindow* focused_window = display->GetFocusedWindow();
- if (focused_window)
- return focused_window;
- }
- return nullptr;
-}
-
-void WindowServer::SetHighContrastMode(bool enabled) {
- // TODO(fsamuel): This doesn't really seem like it's a window server concept?
- if (high_contrast_mode_ == enabled)
- return;
- high_contrast_mode_ = enabled;
-
- // Propagate the change to all Displays so that FrameGenerators start
- // requesting BeginFrames.
- display_manager_->SetHighContrastMode(enabled);
-}
-
-uint32_t WindowServer::GenerateWindowManagerChangeId(
- WindowTree* source,
- uint32_t client_change_id) {
- const uint32_t wm_change_id = next_wm_change_id_++;
- in_flight_wm_change_map_[wm_change_id] = {source->id(), client_change_id};
- return wm_change_id;
-}
-
-void WindowServer::WindowManagerChangeCompleted(
- uint32_t window_manager_change_id,
- bool success) {
- InFlightWindowManagerChange change;
- if (!GetAndClearInFlightWindowManagerChange(window_manager_change_id,
- &change)) {
- return;
- }
-
- WindowTree* tree = GetTreeWithId(change.client_id);
- tree->OnChangeCompleted(change.client_change_id, success);
-}
-
-void WindowServer::WindowManagerCreatedTopLevelWindow(
- WindowTree* wm_tree,
- uint32_t window_manager_change_id,
- ServerWindow* window) {
- InFlightWindowManagerChange change;
- if (!GetAndClearInFlightWindowManagerChange(window_manager_change_id,
- &change)) {
- DVLOG(1) << "WindowManager responded with invalid change id; most "
- << "likely bug in WindowManager processing WmCreateTopLevelWindow "
- << "change_id=" << window_manager_change_id;
- return;
- }
-
- WindowTree* tree = GetTreeWithId(change.client_id);
- // The window manager should have created the window already, and it should
- // be ready for embedding.
- if (!tree->IsWaitingForNewTopLevelWindow(window_manager_change_id)) {
- DVLOG(1) << "WindowManager responded with valid change id, but client "
- << "is not waiting for top-level; possible bug in mus, change_id="
- << window_manager_change_id;
- WindowManagerSentBogusMessage();
- return;
- }
- if (window && (window->owning_tree_id() != wm_tree->id() ||
- !window->children().empty() || GetTreeWithRoot(window))) {
- DVLOG(1)
- << "WindowManager responded with invalid window; window should "
- << "not have any children, not be the root of a client and should be "
- << "created by the WindowManager, window_manager_change_id="
- << window_manager_change_id;
- WindowManagerSentBogusMessage();
- return;
- }
-
- viz::FrameSinkId updated_frame_sink_id =
- tree->OnWindowManagerCreatedTopLevelWindow(
- window_manager_change_id, change.client_change_id, window);
- if (window)
- window->UpdateFrameSinkId(updated_frame_sink_id);
-}
-
-void WindowServer::ProcessWindowBoundsChanged(
- const ServerWindow* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessWindowBoundsChanged(window, old_bounds, new_bounds,
- IsOperationSource(pair.first),
- local_surface_id);
- }
-}
-
-void WindowServer::ProcessWindowTransformChanged(
- const ServerWindow* window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessWindowTransformChanged(
- window, old_transform, new_transform, IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::ProcessClientAreaChanged(
- const ServerWindow* window,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessClientAreaChanged(window, new_client_area,
- new_additional_client_areas,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::ProcessCaptureChanged(const ServerWindow* new_capture,
- const ServerWindow* old_capture) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessCaptureChanged(new_capture, old_capture,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::ProcessWillChangeWindowHierarchy(
- const ServerWindow* window,
- const ServerWindow* new_parent,
- const ServerWindow* old_parent) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessWillChangeWindowHierarchy(
- window, new_parent, old_parent, IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::ProcessWindowHierarchyChanged(
- const ServerWindow* window,
- const ServerWindow* new_parent,
- const ServerWindow* old_parent) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessWindowHierarchyChanged(window, new_parent, old_parent,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::ProcessWindowReorder(const ServerWindow* window,
- const ServerWindow* relative_window,
- const mojom::OrderDirection direction) {
- // We'll probably do a bit of reshuffling when we add a transient window.
- if ((current_operation_type() == OperationType::ADD_TRANSIENT_WINDOW) ||
- (current_operation_type() ==
- OperationType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT)) {
- return;
- }
- for (auto& pair : tree_map_) {
- pair.second->ProcessWindowReorder(window, relative_window, direction,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::ProcessWindowDeleted(ServerWindow* window) {
- for (auto& pair : tree_map_)
- pair.second->ProcessWindowDeleted(window, IsOperationSource(pair.first));
-}
-
-void WindowServer::ProcessWillChangeWindowCursor(ServerWindow* window,
- const ui::CursorData& cursor) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessCursorChanged(window, cursor,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::SendToPointerWatchers(const ui::Event& event,
- ServerWindow* target_window,
- WindowTree* ignore_tree,
- int64_t display_id) {
- for (auto& pair : tree_map_) {
- WindowTree* tree = pair.second.get();
- if (tree != ignore_tree)
- tree->SendToPointerWatcher(event, target_window, display_id);
- }
-}
-
-void WindowServer::SetSurfaceActivationCallback(
- base::OnceCallback<void(ServerWindow*)> callback) {
- DCHECK(delegate_->IsTestConfig()) << "Surface activation callbacks are "
- << "expensive, and allowed only in tests.";
- DCHECK(surface_activation_callback_.is_null() || callback.is_null());
- surface_activation_callback_ = std::move(callback);
-}
-
-void WindowServer::StartMoveLoop(uint32_t change_id,
- ServerWindow* window,
- WindowTree* initiator,
- const gfx::Rect& revert_bounds) {
- current_move_loop_.reset(
- new CurrentMoveLoopState{change_id, window, initiator, revert_bounds});
-}
-
-void WindowServer::EndMoveLoop() {
- current_move_loop_.reset();
-}
-
-uint32_t WindowServer::GetCurrentMoveLoopChangeId() {
- if (current_move_loop_)
- return current_move_loop_->change_id;
- return 0;
-}
-
-ServerWindow* WindowServer::GetCurrentMoveLoopWindow() {
- if (current_move_loop_)
- return current_move_loop_->window;
- return nullptr;
-}
-
-WindowTree* WindowServer::GetCurrentMoveLoopInitiator() {
- if (current_move_loop_)
- return current_move_loop_->initiator;
- return nullptr;
-}
-
-gfx::Rect WindowServer::GetCurrentMoveLoopRevertBounds() {
- if (current_move_loop_)
- return current_move_loop_->revert_bounds;
- return gfx::Rect();
-}
-
-void WindowServer::StartDragLoop(uint32_t change_id,
- ServerWindow* window,
- WindowTree* initiator) {
- current_drag_loop_.reset(
- new CurrentDragLoopState{change_id, window, initiator});
-}
-
-void WindowServer::EndDragLoop() {
- current_drag_loop_.reset();
-}
-
-uint32_t WindowServer::GetCurrentDragLoopChangeId() {
- if (current_drag_loop_)
- return current_drag_loop_->change_id;
- return 0u;
-}
-
-ServerWindow* WindowServer::GetCurrentDragLoopWindow() {
- if (current_drag_loop_)
- return current_drag_loop_->window;
- return nullptr;
-}
-
-WindowTree* WindowServer::GetCurrentDragLoopInitiator() {
- if (current_drag_loop_)
- return current_drag_loop_->initiator;
- return nullptr;
-}
-
-void WindowServer::OnDisplayReady(Display* display, bool is_first) {
- if (is_first)
- delegate_->OnFirstDisplayReady();
- bool wm_is_hosting_viz = !gpu_host_;
- if (wm_is_hosting_viz) {
- // Notify WM about the AcceleratedWidget if it is hosting viz.
- for (auto& pair : tree_map_) {
- if (pair.second->window_manager_state()) {
- auto& wm_tree = pair.second;
- wm_tree->OnAcceleratedWidgetAvailableForDisplay(display);
- }
- }
- } else {
- gpu_host_->OnAcceleratedWidgetAvailable(
- display->platform_display()->GetAcceleratedWidget());
- }
-}
-
-void WindowServer::OnDisplayDestroyed(Display* display) {
- if (gpu_host_) {
- gpu_host_->OnAcceleratedWidgetDestroyed(
- display->platform_display()->GetAcceleratedWidget());
- }
-}
-
-void WindowServer::OnNoMoreDisplays() {
- delegate_->OnNoMoreDisplays();
-}
-
-WindowManagerState* WindowServer::GetWindowManagerState() {
- return window_manager_window_tree_factory_->window_tree()
- ? window_manager_window_tree_factory_->window_tree()
- ->window_manager_state()
- : nullptr;
-}
-
-VizHostProxy* WindowServer::GetVizHostProxy() {
- return viz_host_proxy_.get();
-}
-
-void WindowServer::OnFirstSurfaceActivation(
- const viz::SurfaceInfo& surface_info,
- ServerWindow* window) {
- DCHECK(host_frame_sink_manager_);
- // This is only used for testing to observe that a window has a
- // CompositorFrame.
- if (surface_activation_callback_)
- std::move(surface_activation_callback_).Run(window);
-
- Display* display = display_manager_->GetDisplayContaining(window);
- if (IsWindowConsideredWindowManagerRoot(display, window)) {
- // A new surface for a WindowManager root has been created. This is a
- // special case because ServerWindows created by the WindowServer are not
- // part of a WindowTree. Send the SurfaceId directly to FrameGenerator and
- // claim the temporary reference for the display root.
- display_manager_->OnWindowManagerSurfaceActivation(display, surface_info);
- host_frame_sink_manager_->AssignTemporaryReference(
- surface_info.id(), display->root_window()->frame_sink_id());
- return;
- }
-
- HandleTemporaryReferenceForNewSurface(surface_info.id(), window);
-
- // We always use the owner of the window's id (even for an embedded window),
- // because an embedded window's id is allocated by the parent's window tree.
- WindowTree* window_tree = GetTreeWithId(window->owning_tree_id());
- if (window_tree)
- window_tree->ProcessWindowSurfaceChanged(window, surface_info);
-}
-
-bool WindowServer::GetFrameDecorations(
- mojom::FrameDecorationValuesPtr* values) {
- WindowManagerState* window_manager_state = GetWindowManagerState();
- if (!window_manager_state)
- return false;
- if (values && window_manager_state->got_frame_decoration_values())
- *values = window_manager_state->frame_decoration_values().Clone();
- return window_manager_state->got_frame_decoration_values();
-}
-
-int64_t WindowServer::GetInternalDisplayId() {
- return display_manager_->GetInternalDisplayId();
-}
-
-bool WindowServer::GetAndClearInFlightWindowManagerChange(
- uint32_t window_manager_change_id,
- InFlightWindowManagerChange* change) {
- // There are valid reasons as to why we wouldn't know about the id. The
- // most likely is the client disconnected before the response from the window
- // manager came back.
- auto iter = in_flight_wm_change_map_.find(window_manager_change_id);
- if (iter == in_flight_wm_change_map_.end())
- return false;
-
- *change = iter->second;
- in_flight_wm_change_map_.erase(iter);
- return true;
-}
-
-void WindowServer::PrepareForOperation(Operation* op) {
- // Should only ever have one change in flight.
- CHECK(!current_operation_);
- current_operation_ = op;
-}
-
-void WindowServer::FinishOperation() {
- // PrepareForOperation/FinishOperation should be balanced.
- CHECK(current_operation_);
- current_operation_ = nullptr;
-}
-
-void WindowServer::UpdateNativeCursorFromMouseLocation(ServerWindow* window) {
- UpdateNativeCursorFromMouseLocation(
- display_manager_->GetWindowManagerDisplayRoot(window));
-}
-
-void WindowServer::UpdateNativeCursorFromMouseLocation(
- WindowManagerDisplayRoot* display_root) {
- if (!display_root)
- return;
-
- EventProcessor* event_processor =
- display_root->window_manager_state()->event_processor();
- event_processor->UpdateCursorProviderByLastKnownLocation();
-}
-
-void WindowServer::UpdateNativeCursorIfOver(ServerWindow* window) {
- WindowManagerDisplayRoot* display_root =
- display_manager_->GetWindowManagerDisplayRoot(window);
- if (!display_root)
- return;
-
- EventProcessor* event_processor =
- display_root->window_manager_state()->event_processor();
- if (window != event_processor->GetWindowForMouseCursor())
- return;
-
- event_processor->UpdateNonClientAreaForCurrentWindow();
-}
-
-void WindowServer::HandleTemporaryReferenceForNewSurface(
- const viz::SurfaceId& surface_id,
- ServerWindow* window) {
- DCHECK(host_frame_sink_manager_);
- // TODO(kylechar): Investigate adding tests for this.
- const ClientSpecificId window_client_id = window->owning_tree_id();
-
- // Find the root ServerWindow for the client that embeds |window|, which is
- // the root of the client that embeds |surface_id|. The client that embeds
- // |surface_id| created |window|, so |window| will have the client id of the
- // embedder. The root window of the embedder will have been created by it's
- // embedder, so the first ServerWindow with a different client id will be the
- // root of the embedder.
- ServerWindow* current = window->parent();
- while (current && current->owning_tree_id() == window_client_id)
- current = current->parent();
-
- // The client that embeds |window| is expected to submit a CompositorFrame
- // that references |surface_id|. Have the parent claim ownership of the
- // temporary reference to |surface_id|. If the parent client crashes before it
- // adds a surface reference then the GPU can cleanup temporary references. If
- // no parent client embeds |window| then tell the GPU to drop the temporary
- // reference immediately.
- if (current) {
- host_frame_sink_manager_->AssignTemporaryReference(
- surface_id, current->frame_sink_id());
- } else {
- host_frame_sink_manager_->DropTemporaryReference(surface_id);
- }
-}
-
-void WindowServer::CreateFrameSinkManager() {
- DCHECK(host_frame_sink_manager_);
- viz::mojom::FrameSinkManagerPtr frame_sink_manager;
- viz::mojom::FrameSinkManagerRequest frame_sink_manager_request =
- mojo::MakeRequest(&frame_sink_manager);
- viz::mojom::FrameSinkManagerClientPtr frame_sink_manager_client;
- viz::mojom::FrameSinkManagerClientRequest frame_sink_manager_client_request =
- mojo::MakeRequest(&frame_sink_manager_client);
-
- viz::mojom::FrameSinkManagerParamsPtr params =
- viz::mojom::FrameSinkManagerParams::New();
- params->restart_id = viz_restart_id_++;
- base::Optional<uint32_t> activation_deadline_in_frames =
- switches::GetDeadlineToSynchronizeSurfaces();
- params->use_activation_deadline = activation_deadline_in_frames.has_value();
- params->activation_deadline_in_frames =
- activation_deadline_in_frames.value_or(0u);
- params->frame_sink_manager = std::move(frame_sink_manager_request);
- params->frame_sink_manager_client = frame_sink_manager_client.PassInterface();
- gpu_host_->CreateFrameSinkManager(std::move(params));
-
- host_frame_sink_manager_->BindAndSetManager(
- std::move(frame_sink_manager_client_request), nullptr /* task_runner */,
- std::move(frame_sink_manager));
-}
-
-AsyncEventDispatcher* WindowServer::GetAsyncEventDispatcherById(
- ClientSpecificId id) {
- return GetTreeWithId(id);
-}
-
-ServerWindow* WindowServer::GetRootWindowForDrawn(const ServerWindow* window) {
- Display* display = display_manager_->GetDisplayContaining(window);
- return display ? display->root_window() : nullptr;
-}
-
-void WindowServer::OnWindowDestroyed(ServerWindow* window) {
- ProcessWindowDeleted(window);
-}
-
-void WindowServer::OnWillChangeWindowHierarchy(ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) {
- if (in_destructor_)
- return;
-
- ProcessWillChangeWindowHierarchy(window, new_parent, old_parent);
-}
-
-void WindowServer::OnWindowHierarchyChanged(ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) {
- if (in_destructor_)
- return;
-
- WindowManagerDisplayRoot* display_root =
- display_manager_->GetWindowManagerDisplayRoot(window);
- if (display_root) {
- display_root->window_manager_state()
- ->ReleaseCaptureBlockedByAnyModalWindow();
- }
-
- ProcessWindowHierarchyChanged(window, new_parent, old_parent);
-
- if (old_parent) {
- viz_host_proxy_->UnregisterFrameSinkHierarchy(old_parent->frame_sink_id(),
- window->frame_sink_id());
- }
- if (new_parent) {
- viz_host_proxy_->RegisterFrameSinkHierarchy(new_parent->frame_sink_id(),
- window->frame_sink_id());
- }
-
- if (!pending_system_modal_windows_.windows().empty()) {
- // Windows that are now in a display are put here, then removed. We do this
- // in two passes to avoid removing from a list we're iterating over.
- std::set<ServerWindow*> no_longer_pending;
- for (ServerWindow* system_modal_window :
- pending_system_modal_windows_.windows()) {
- DCHECK_EQ(MODAL_TYPE_SYSTEM, system_modal_window->modal_type());
- WindowManagerDisplayRoot* display_root =
- display_manager_->GetWindowManagerDisplayRoot(system_modal_window);
- if (display_root) {
- no_longer_pending.insert(system_modal_window);
- display_root->window_manager_state()->AddSystemModalWindow(window);
- }
- }
-
- for (ServerWindow* system_modal_window : no_longer_pending)
- pending_system_modal_windows_.Remove(system_modal_window);
- }
-
- WindowManagerDisplayRoot* old_display_root =
- old_parent ? display_manager_->GetWindowManagerDisplayRoot(old_parent)
- : nullptr;
- WindowManagerDisplayRoot* new_display_root =
- new_parent ? display_manager_->GetWindowManagerDisplayRoot(new_parent)
- : nullptr;
- UpdateNativeCursorFromMouseLocation(new_display_root);
- if (old_display_root != new_display_root)
- UpdateNativeCursorFromMouseLocation(old_display_root);
-}
-
-void WindowServer::OnWindowBoundsChanged(ServerWindow* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {
- if (in_destructor_)
- return;
-
- ProcessWindowBoundsChanged(window, old_bounds, new_bounds,
- window->current_local_surface_id());
- UpdateNativeCursorFromMouseLocation(window);
-}
-
-void WindowServer::OnWindowTransformChanged(
- ServerWindow* window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform) {
- if (in_destructor_)
- return;
-
- ProcessWindowTransformChanged(window, old_transform, new_transform);
- UpdateNativeCursorFromMouseLocation(window);
-}
-
-void WindowServer::OnWindowClientAreaChanged(
- ServerWindow* window,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas) {
- if (in_destructor_)
- return;
-
- ProcessClientAreaChanged(window, new_client_area,
- new_additional_client_areas);
-
- UpdateNativeCursorIfOver(window);
-}
-
-void WindowServer::OnWindowReordered(ServerWindow* window,
- ServerWindow* relative,
- mojom::OrderDirection direction) {
- ProcessWindowReorder(window, relative, direction);
- UpdateNativeCursorFromMouseLocation(window);
-}
-
-void WindowServer::OnWillChangeWindowVisibility(ServerWindow* window) {
- if (in_destructor_)
- return;
-
- for (auto& pair : tree_map_) {
- pair.second->ProcessWillChangeWindowVisibility(
- window, IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::OnWindowOpacityChanged(ServerWindow* window,
- float old_opacity,
- float new_opacity) {
- DCHECK(!in_destructor_);
-
- for (auto& pair : tree_map_) {
- pair.second->ProcessWindowOpacityChanged(window, old_opacity, new_opacity,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::OnWindowVisibilityChanged(ServerWindow* window) {
- if (in_destructor_)
- return;
-
- WindowManagerDisplayRoot* display_root =
- display_manager_->GetWindowManagerDisplayRoot(window);
- if (display_root) {
- display_root->window_manager_state()
- ->ReleaseCaptureBlockedByAnyModalWindow();
- }
-}
-
-void WindowServer::OnWindowCursorChanged(ServerWindow* window,
- const ui::CursorData& cursor) {
- if (in_destructor_)
- return;
-
- ProcessWillChangeWindowCursor(window, cursor);
-
- UpdateNativeCursorIfOver(window);
-}
-
-void WindowServer::OnWindowNonClientCursorChanged(
- ServerWindow* window,
- const ui::CursorData& cursor) {
- if (in_destructor_)
- return;
-
- UpdateNativeCursorIfOver(window);
-}
-
-void WindowServer::OnWindowSharedPropertyChanged(
- ServerWindow* window,
- const std::string& name,
- const std::vector<uint8_t>* new_data) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessWindowPropertyChanged(window, name, new_data,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::OnWindowTextInputStateChanged(
- ServerWindow* window,
- const ui::TextInputState& state) {
- Display* display = display_manager_->GetDisplayContaining(window);
- display->UpdateTextInputState(window, state);
-}
-
-void WindowServer::OnTransientWindowAdded(ServerWindow* window,
- ServerWindow* transient_child) {
- for (auto& pair : tree_map_) {
- pair.second->ProcessTransientWindowAdded(window, transient_child,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::OnTransientWindowRemoved(ServerWindow* window,
- ServerWindow* transient_child) {
- // If we're deleting a window, then this is a superfluous message.
- if (current_operation_type() == OperationType::DELETE_WINDOW)
- return;
- for (auto& pair : tree_map_) {
- pair.second->ProcessTransientWindowRemoved(window, transient_child,
- IsOperationSource(pair.first));
- }
-}
-
-void WindowServer::OnWindowModalTypeChanged(ServerWindow* window,
- ModalType old_modal_type) {
- WindowManagerDisplayRoot* display_root =
- display_manager_->GetWindowManagerDisplayRoot(window);
- if (window->modal_type() == MODAL_TYPE_SYSTEM) {
- if (display_root)
- display_root->window_manager_state()->AddSystemModalWindow(window);
- else
- pending_system_modal_windows_.Add(window);
- } else {
- pending_system_modal_windows_.Remove(window);
- }
-
- if (display_root && window->modal_type() != MODAL_TYPE_NONE) {
- display_root->window_manager_state()
- ->ReleaseCaptureBlockedByAnyModalWindow();
- }
-}
-
-void WindowServer::OnGpuServiceInitialized() {
- delegate_->StartDisplayInit();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_server.h b/services/ui/ws/window_server.h
deleted file mode 100644
index 80643d9..0000000
--- a/services/ui/ws/window_server.h
+++ /dev/null
@@ -1,452 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_SERVER_H_
-#define SERVICES_UI_WS_WINDOW_SERVER_H_
-
-#include <stdint.h>
-
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "base/containers/flat_map.h"
-#include "base/macros.h"
-#include "base/optional.h"
-#include "components/viz/common/frame_sinks/begin_frame_source.h"
-#include "components/viz/common/surfaces/frame_sink_id.h"
-#include "components/viz/host/host_frame_sink_manager.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/ui/gpu_host/gpu_host_delegate.h"
-#include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/ws/async_event_dispatcher_lookup.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/operation.h"
-#include "services/ui/ws/server_window_delegate.h"
-#include "services/ui/ws/server_window_observer.h"
-#include "services/ui/ws/server_window_tracker.h"
-#include "services/ui/ws/user_display_manager_delegate.h"
-#include "services/ui/ws/video_detector_impl.h"
-
-namespace ui {
-
-namespace gpu_host {
-class GpuHost;
-}
-
-namespace ws {
-
-class AccessPolicy;
-class Display;
-class DisplayManager;
-class ServerWindow;
-class ThreadedImageCursorsFactory;
-class UserActivityMonitor;
-class WindowManagerDisplayRoot;
-class WindowManagerState;
-class WindowManagerWindowTreeFactory;
-class WindowServerDelegate;
-class WindowTree;
-class WindowTreeBinding;
-
-enum class DisplayCreationConfig;
-
-struct WindowTreeAndWindowId {
- WindowTree* tree = nullptr;
- ClientSpecificId window_id = 0u;
-};
-
-// WindowServer manages the set of clients of the window server (all the
-// WindowTrees) as well as providing the root of the hierarchy.
-class WindowServer : public ServerWindowDelegate,
- public ServerWindowObserver,
- public gpu_host::GpuHostDelegate,
- public UserDisplayManagerDelegate,
- public AsyncEventDispatcherLookup {
- public:
- WindowServer(WindowServerDelegate* delegate, bool should_host_viz);
- ~WindowServer() override;
-
- WindowServerDelegate* delegate() { return delegate_; }
-
- DisplayManager* display_manager() { return display_manager_.get(); }
- const DisplayManager* display_manager() const {
- return display_manager_.get();
- }
-
- void SetDisplayCreationConfig(DisplayCreationConfig config);
- DisplayCreationConfig display_creation_config() const {
- return display_creation_config_;
- }
-
- void SetGpuHost(std::unique_ptr<gpu_host::GpuHost> gpu_host);
- gpu_host::GpuHost* gpu_host() { return gpu_host_.get(); }
-
- bool is_hosting_viz() const { return !!host_frame_sink_manager_; }
-
- ThreadedImageCursorsFactory* GetThreadedImageCursorsFactory();
-
- // Creates a new ServerWindow. The return value is owned by the caller, but
- // must be destroyed before WindowServer.
- ServerWindow* CreateServerWindow(
- const viz::FrameSinkId& frame_sink_id,
- const std::map<std::string, std::vector<uint8_t>>& properties);
-
- // Returns the id for the next WindowTree.
- ClientSpecificId GetAndAdvanceNextClientId();
-
- // See description of WindowTree::Embed() for details. This assumes
- // |transport_window_id| is valid.
- WindowTree* EmbedAtWindow(ServerWindow* root,
- mojom::WindowTreeClientPtr client,
- uint32_t flags,
- std::unique_ptr<AccessPolicy> access_policy);
-
- // Adds |tree_impl_ptr| to the set of known trees. Use DestroyTree() to
- // destroy the tree.
- void AddTree(std::unique_ptr<WindowTree> tree_impl_ptr,
- std::unique_ptr<WindowTreeBinding> binding,
- mojom::WindowTreePtr tree_ptr);
- WindowTree* CreateTreeForWindowManager(
- mojom::WindowTreeRequest window_tree_request,
- mojom::WindowTreeClientPtr window_tree_client,
- bool automatically_create_display_roots);
- // Invoked when a WindowTree's connection encounters an error.
- void DestroyTree(WindowTree* tree);
-
- // Returns the tree by client id.
- WindowTree* GetTreeWithId(ClientSpecificId client_id);
-
- WindowTree* GetTreeWithClientName(const std::string& client_name);
-
- size_t num_trees() const { return tree_map_.size(); }
-
- // Creates and registers a token for use in a future embedding. |window_id|
- // is the window_id portion of the ClientWindowId to use for the window in
- // |tree|. |window_id| is validated during actual embed.
- base::UnguessableToken RegisterEmbedToken(WindowTree* tree,
- ClientSpecificId window_id);
-
- // Unregisters the WindowTree associated with |token| and returns it. Returns
- // null if RegisterEmbedToken() was not previously called for |token|.
- WindowTreeAndWindowId UnregisterEmbedToken(
- const base::UnguessableToken& token);
-
- OperationType current_operation_type() const {
- return current_operation_ ? current_operation_->type()
- : OperationType::NONE;
- }
-
- // Returns true if the specified client issued the current operation.
- bool IsOperationSource(ClientSpecificId client_id) const {
- return current_operation_ &&
- current_operation_->source_tree_id() == client_id;
- }
-
- // Invoked when a client messages a client about the change. This is used
- // to avoid sending ServerChangeIdAdvanced() unnecessarily.
- void OnTreeMessagedClient(ClientSpecificId id);
-
- // Returns true if OnTreeMessagedClient() was invoked for id.
- bool DidTreeMessageClient(ClientSpecificId id) const;
-
- // Returns the WindowTree that has |window| as a root.
- WindowTree* GetTreeWithRoot(const ServerWindow* window) {
- return const_cast<WindowTree*>(
- const_cast<const WindowServer*>(this)->GetTreeWithRoot(window));
- }
- const WindowTree* GetTreeWithRoot(const ServerWindow* window) const;
-
- UserActivityMonitor* user_activity_monitor() {
- return user_activity_monitor_.get();
- }
-
- WindowManagerWindowTreeFactory* window_manager_window_tree_factory() {
- return window_manager_window_tree_factory_.get();
- }
- void BindWindowManagerWindowTreeFactory(
- mojo::InterfaceRequest<mojom::WindowManagerWindowTreeFactory> request);
-
- // Sets focus to |window|. Returns true if |window| already has focus, or
- // focus was successfully changed. Returns |false| if |window| is not a valid
- // window to receive focus.
- bool SetFocusedWindow(ServerWindow* window);
- ServerWindow* GetFocusedWindow();
-
- void SetHighContrastMode(bool enabled);
-
- // Returns a change id for the window manager that is associated with
- // |source| and |client_change_id|. When the window manager replies
- // WindowManagerChangeCompleted() is called to obtain the original source
- // and client supplied change_id that initiated the called.
- uint32_t GenerateWindowManagerChangeId(WindowTree* source,
- uint32_t client_change_id);
-
- // Called when a response from the window manager is obtained. Calls to
- // the client that initiated the change with the change id originally
- // supplied by the client.
- void WindowManagerChangeCompleted(uint32_t window_manager_change_id,
- bool success);
- void WindowManagerCreatedTopLevelWindow(WindowTree* wm_tree,
- uint32_t window_manager_change_id,
- ServerWindow* window);
-
- // Called when we get an unexpected message from the WindowManager.
- // TODO(sky): decide what we want to do here.
- void WindowManagerSentBogusMessage() {}
-
- // These functions trivially delegate to all WindowTrees, which in
- // term notify their clients.
- void ProcessWindowBoundsChanged(
- const ServerWindow* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id);
- void ProcessWindowTransformChanged(const ServerWindow* window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform);
- void ProcessClientAreaChanged(
- const ServerWindow* window,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas);
- void ProcessCaptureChanged(const ServerWindow* new_capture,
- const ServerWindow* old_capture);
- void ProcessWillChangeWindowHierarchy(const ServerWindow* window,
- const ServerWindow* new_parent,
- const ServerWindow* old_parent);
- void ProcessWindowHierarchyChanged(const ServerWindow* window,
- const ServerWindow* new_parent,
- const ServerWindow* old_parent);
- void ProcessWindowReorder(const ServerWindow* window,
- const ServerWindow* relative_window,
- const mojom::OrderDirection direction);
- void ProcessWindowDeleted(ServerWindow* window);
- void ProcessWillChangeWindowCursor(ServerWindow* window,
- const ui::CursorData& cursor);
-
- // Sends an |event| to all WindowTrees that might be observing events. Skips
- // |ignore_tree| if it is non-null. |target_window| is the target of the
- // event.
- void SendToPointerWatchers(const ui::Event& event,
- ServerWindow* target_window,
- WindowTree* ignore_tree,
- int64_t display_id);
-
- // Sets a callback to be called whenever a surface is activated. This
- // corresponds a client submitting a new CompositorFrame for a Window. This
- // should only be called in a test configuration.
- void SetSurfaceActivationCallback(
- base::OnceCallback<void(ServerWindow*)> callback);
-
- void StartMoveLoop(uint32_t change_id,
- ServerWindow* window,
- WindowTree* initiator,
- const gfx::Rect& revert_bounds);
- void EndMoveLoop();
- uint32_t GetCurrentMoveLoopChangeId();
- ServerWindow* GetCurrentMoveLoopWindow();
- WindowTree* GetCurrentMoveLoopInitiator();
- gfx::Rect GetCurrentMoveLoopRevertBounds();
- bool in_move_loop() const { return !!current_move_loop_; }
-
- void StartDragLoop(uint32_t change_id,
- ServerWindow* window,
- WindowTree* initiator);
- void EndDragLoop();
- uint32_t GetCurrentDragLoopChangeId();
- ServerWindow* GetCurrentDragLoopWindow();
- WindowTree* GetCurrentDragLoopInitiator();
- bool in_drag_loop() const { return !!current_drag_loop_; }
-
- void OnDisplayReady(Display* display, bool is_first);
- void OnDisplayDestroyed(Display* display);
- void OnNoMoreDisplays();
- WindowManagerState* GetWindowManagerState();
-
- VideoDetectorImpl* video_detector() { return &video_detector_; }
-
- // ServerWindowDelegate:
- VizHostProxy* GetVizHostProxy() override;
- void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info,
- ServerWindow* window) override;
-
- // UserDisplayManagerDelegate:
- bool GetFrameDecorations(mojom::FrameDecorationValuesPtr* values) override;
- int64_t GetInternalDisplayId() override;
-
- private:
- struct CurrentMoveLoopState;
- struct CurrentDragLoopState;
- friend class Operation;
-
- using WindowTreeMap =
- std::map<ClientSpecificId, std::unique_ptr<WindowTree>>;
-
- struct InFlightWindowManagerChange {
- // Identifies the client that initiated the change.
- ClientSpecificId client_id;
-
- // Change id supplied by the client.
- uint32_t client_change_id;
- };
-
- using InFlightWindowManagerChangeMap =
- std::map<uint32_t, InFlightWindowManagerChange>;
-
- bool GetAndClearInFlightWindowManagerChange(
- uint32_t window_manager_change_id,
- InFlightWindowManagerChange* change);
-
- // Invoked when a client is about to execute a window server operation.
- // Subsequently followed by FinishOperation() once the change is done.
- //
- // Changes should never nest, meaning each PrepareForOperation() must be
- // balanced with a call to FinishOperation() with no PrepareForOperation()
- // in between.
- void PrepareForOperation(Operation* op);
-
- // Balances a call to PrepareForOperation().
- void FinishOperation();
-
- // Updates the native cursor by figuring out what window is under the mouse
- // cursor. This is run in response to events that change the bounds or window
- // hierarchy.
- void UpdateNativeCursorFromMouseLocation(ServerWindow* window);
- void UpdateNativeCursorFromMouseLocation(
- WindowManagerDisplayRoot* display_root);
-
- // Updates the native cursor if the cursor is currently inside |window|. This
- // is run in response to events that change the mouse cursor properties of
- // |window|.
- void UpdateNativeCursorIfOver(ServerWindow* window);
-
- // Finds the parent client that will embed |surface_id| and claims ownership
- // of the temporary reference. If no parent client is found then tell GPU to
- // immediately drop the temporary reference. |window| is the ServerWindow
- // that corresponds to |surface_id|.
- void HandleTemporaryReferenceForNewSurface(const viz::SurfaceId& surface_id,
- ServerWindow* window);
-
- void CreateFrameSinkManager();
-
- // AsyncEventDispatcherLookup:
- AsyncEventDispatcher* GetAsyncEventDispatcherById(
- ClientSpecificId id) override;
-
- // Overridden from ServerWindowDelegate:
- ServerWindow* GetRootWindowForDrawn(const ServerWindow* window) override;
-
- // Overridden from ServerWindowObserver:
- void OnWindowDestroyed(ServerWindow* window) override;
- void OnWillChangeWindowHierarchy(ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) override;
- void OnWindowHierarchyChanged(ServerWindow* window,
- ServerWindow* new_parent,
- ServerWindow* old_parent) override;
- void OnWindowBoundsChanged(ServerWindow* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override;
- void OnWindowTransformChanged(ServerWindow* window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform) override;
- void OnWindowClientAreaChanged(
- ServerWindow* window,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas) override;
- void OnWindowReordered(ServerWindow* window,
- ServerWindow* relative,
- mojom::OrderDirection direction) override;
- void OnWillChangeWindowVisibility(ServerWindow* window) override;
- void OnWindowVisibilityChanged(ServerWindow* window) override;
- void OnWindowOpacityChanged(ServerWindow* window,
- float old_opacity,
- float new_opacity) override;
- void OnWindowSharedPropertyChanged(
- ServerWindow* window,
- const std::string& name,
- const std::vector<uint8_t>* new_data) override;
- void OnWindowCursorChanged(ServerWindow* window,
- const ui::CursorData& cursor) override;
- void OnWindowNonClientCursorChanged(ServerWindow* window,
- const ui::CursorData& cursor) override;
- void OnWindowTextInputStateChanged(ServerWindow* window,
- const ui::TextInputState& state) override;
- void OnTransientWindowAdded(ServerWindow* window,
- ServerWindow* transient_child) override;
- void OnTransientWindowRemoved(ServerWindow* window,
- ServerWindow* transient_child) override;
- void OnWindowModalTypeChanged(ServerWindow* window,
- ModalType old_modal_type) override;
-
- // GpuHostDelegate:
- void OnGpuServiceInitialized() override;
-
- WindowServerDelegate* delegate_;
-
- // ID to use for next WindowTree.
- ClientSpecificId next_client_id_;
-
- std::unique_ptr<DisplayManager> display_manager_;
-
- std::unique_ptr<CurrentDragLoopState> current_drag_loop_;
- std::unique_ptr<CurrentMoveLoopState> current_move_loop_;
-
- // Set of WindowTrees.
- WindowTreeMap tree_map_;
-
- // If non-null then we're processing a client operation. The Operation is
- // not owned by us (it's created on the stack by WindowTree).
- Operation* current_operation_;
-
- bool in_destructor_;
- bool high_contrast_mode_ = false;
-
- // Maps from window manager change id to the client that initiated the
- // request.
- InFlightWindowManagerChangeMap in_flight_wm_change_map_;
-
- // Next id supplied to the window manager.
- uint32_t next_wm_change_id_;
-
- std::unique_ptr<gpu_host::GpuHost> gpu_host_;
- base::OnceCallback<void(ServerWindow*)> surface_activation_callback_;
-
- std::unique_ptr<UserActivityMonitor> user_activity_monitor_;
-
- std::unique_ptr<WindowManagerWindowTreeFactory>
- window_manager_window_tree_factory_;
-
- viz::SurfaceId root_surface_id_;
-
- // Incremented when the viz process is restarted.
- uint32_t viz_restart_id_ = viz::BeginFrameSource::kNotRestartableId + 1;
-
- // Provides interfaces to create and manage FrameSinks.
- std::unique_ptr<viz::HostFrameSinkManager> host_frame_sink_manager_;
- std::unique_ptr<VizHostProxy> viz_host_proxy_;
-
- VideoDetectorImpl video_detector_;
-
- // System modal windows not attached to a display are added here. Once
- // attached to a display they are removed.
- ServerWindowTracker pending_system_modal_windows_;
-
- DisplayCreationConfig display_creation_config_;
-
- // Tokens registered by ScheduleEmbedForExistingClient() that are removed when
- // EmbedUsingToken() is called.
- using ScheduledEmbeds =
- base::flat_map<base::UnguessableToken, WindowTreeAndWindowId>;
- ScheduledEmbeds scheduled_embeds_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowServer);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_SERVER_H_
diff --git a/services/ui/ws/window_server_delegate.cc b/services/ui/ws/window_server_delegate.cc
deleted file mode 100644
index 6d1194b..0000000
--- a/services/ui/ws/window_server_delegate.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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 "services/ui/ws/window_server_delegate.h"
-
-#include "services/ui/ws/window_tree_binding.h"
-
-namespace ui {
-namespace ws {
-
-void WindowServerDelegate::OnFirstDisplayReady() {}
-
-std::unique_ptr<WindowTreeBinding>
-WindowServerDelegate::CreateWindowTreeBinding(
- BindingType type,
- ws::WindowServer* window_server,
- ws::WindowTree* tree,
- mojom::WindowTreeRequest* tree_request,
- mojom::WindowTreeClientPtr* client) {
- return nullptr;
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_server_delegate.h b/services/ui/ws/window_server_delegate.h
deleted file mode 100644
index 1539856..0000000
--- a/services/ui/ws/window_server_delegate.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_SERVER_DELEGATE_H_
-#define SERVICES_UI_WS_WINDOW_SERVER_DELEGATE_H_
-
-#include <stdint.h>
-
-#include <memory>
-#include <string>
-
-#include "mojo/public/cpp/bindings/interface_request.h"
-#include "services/ui/common/types.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-
-namespace ui {
-
-namespace mojom {
-class WindowTree;
-}
-
-namespace ws {
-
-class Display;
-class ThreadedImageCursorsFactory;
-class WindowServer;
-class WindowTree;
-class WindowTreeBinding;
-
-class WindowServerDelegate {
- public:
- enum BindingType {
- EMBED,
- WINDOW_MANAGER,
- };
-
- // WindowServer signal that display initialization can start.
- virtual void StartDisplayInit() = 0;
-
- // Called once when the AcceleratedWidget of a Display is available.
- virtual void OnFirstDisplayReady();
-
- virtual void OnNoMoreDisplays() = 0;
-
- virtual bool IsTestConfig() const = 0;
-
- // Creates a WindowTreeBinding. Default implementation returns null, which
- // creates DefaultBinding.
- virtual std::unique_ptr<WindowTreeBinding> CreateWindowTreeBinding(
- BindingType type,
- ws::WindowServer* window_server,
- ws::WindowTree* tree,
- mojom::WindowTreeRequest* tree_request,
- mojom::WindowTreeClientPtr* client);
-
- // Called prior to a new WindowTree being created for a
- // WindowManagerWindowTreeFactory. |automatically_create_display_roots|
- // mirrors that of CreateWindowTree(). See it for details.
- virtual void OnWillCreateTreeForWindowManager(
- bool automatically_create_display_roots) = 0;
-
- virtual ThreadedImageCursorsFactory* GetThreadedImageCursorsFactory() = 0;
-
- protected:
- virtual ~WindowServerDelegate() {}
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_SERVER_DELEGATE_H_
diff --git a/services/ui/ws/window_server_service_test_base.cc b/services/ui/ws/window_server_service_test_base.cc
deleted file mode 100644
index 5dfd12d..0000000
--- a/services/ui/ws/window_server_service_test_base.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/window_server_service_test_base.h"
-
-#include <memory>
-
-#include "base/command_line.h"
-#include "base/macros.h"
-#include "services/service_manager/public/cpp/service.h"
-#include "services/service_manager/public/cpp/service_test.h"
-#include "services/ui/common/switches.h"
-#include "ui/gl/gl_switches.h"
-
-namespace ui {
-
-namespace {
-
-const char kTestAppName[] = "ui_service_unittests";
-
-class WindowServerServiceTestClient
- : public service_manager::test::ServiceTestClient {
- public:
- explicit WindowServerServiceTestClient(WindowServerServiceTestBase* test)
- : ServiceTestClient(test), test_(test) {}
- ~WindowServerServiceTestClient() override {}
-
- private:
- // service_manager::test::ServiceTestClient:
- void OnBindInterface(const service_manager::BindSourceInfo& source_info,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) override {
- test_->OnBindInterface(source_info, interface_name,
- std::move(interface_pipe));
- }
-
- WindowServerServiceTestBase* test_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowServerServiceTestClient);
-};
-
-void EnsureCommandLineSwitch(const std::string& name) {
- base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
- if (!cmd_line->HasSwitch(name))
- cmd_line->AppendSwitch(name);
-}
-
-} // namespace
-
-WindowServerServiceTestBase::WindowServerServiceTestBase()
- : ServiceTest(kTestAppName) {
- EnsureCommandLineSwitch(switches::kUseTestConfig);
- EnsureCommandLineSwitch(::switches::kOverrideUseSoftwareGLForTests);
-}
-
-WindowServerServiceTestBase::~WindowServerServiceTestBase() {}
-
-std::unique_ptr<service_manager::Service>
-WindowServerServiceTestBase::CreateService() {
- return std::make_unique<WindowServerServiceTestClient>(this);
-}
-
-} // namespace ui
diff --git a/services/ui/ws/window_server_service_test_base.h b/services/ui/ws/window_server_service_test_base.h
deleted file mode 100644
index 882fb07..0000000
--- a/services/ui/ws/window_server_service_test_base.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_SERVER_SERVICE_TEST_BASE_H_
-#define SERVICES_UI_WS_WINDOW_SERVER_SERVICE_TEST_BASE_H_
-
-#include "base/macros.h"
-#include "services/service_manager/public/cpp/service_test.h"
-
-namespace ui {
-
-// Base class for all window manager ServiceTests to perform some common setup.
-class WindowServerServiceTestBase : public service_manager::test::ServiceTest {
- public:
- WindowServerServiceTestBase();
- ~WindowServerServiceTestBase() override;
-
- virtual void OnBindInterface(
- const service_manager::BindSourceInfo& source_info,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) = 0;
-
- private:
- // service_manager::test::ServiceTest:
- std::unique_ptr<service_manager::Service> CreateService() override;
-
- DISALLOW_COPY_AND_ASSIGN(WindowServerServiceTestBase);
-};
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_SERVER_SERVICE_TEST_BASE_H_
diff --git a/services/ui/ws/window_server_test_base.cc b/services/ui/ws/window_server_test_base.cc
deleted file mode 100644
index 241f8f38..0000000
--- a/services/ui/ws/window_server_test_base.cc
+++ /dev/null
@@ -1,310 +0,0 @@
-// 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 "services/ui/ws/window_server_test_base.h"
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/location.h"
-#include "base/run_loop.h"
-#include "base/single_thread_task_runner.h"
-#include "base/test/test_timeouts.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "services/service_manager/public/cpp/connector.h"
-#include "ui/aura/env.h"
-#include "ui/aura/mus/window_tree_client.h"
-#include "ui/aura/mus/window_tree_host_mus.h"
-#include "ui/base/ui_base_features.h"
-#include "ui/base/ui_base_switches.h"
-#include "ui/display/display.h"
-#include "ui/display/display_list.h"
-#include "ui/wm/core/capture_controller.h"
-
-namespace ui {
-namespace {
-
-base::RunLoop* current_run_loop = nullptr;
-
-void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) {
- CHECK(current_run_loop);
- *timeout = true;
- timeout_task.Run();
-}
-
-} // namespace
-
-WindowServerTestBase::WindowServerTestBase() {
- registry_.AddInterface<mojom::WindowTreeClient>(
- base::Bind(&WindowServerTestBase::BindWindowTreeClientRequest,
- base::Unretained(this)));
-}
-
-WindowServerTestBase::~WindowServerTestBase() {}
-
-// static
-bool WindowServerTestBase::DoRunLoopWithTimeout() {
- if (current_run_loop != nullptr)
- return false;
-
- bool timeout = false;
- base::RunLoop run_loop;
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout),
- TestTimeouts::action_timeout());
-
- current_run_loop = &run_loop;
- current_run_loop->Run();
- current_run_loop = nullptr;
- return !timeout;
-}
-
-// static
-bool WindowServerTestBase::QuitRunLoop() {
- if (!current_run_loop)
- return false;
-
- current_run_loop->Quit();
- current_run_loop = nullptr;
- return true;
-}
-
-void WindowServerTestBase::DeleteWindowTreeClient(
- aura::WindowTreeClient* client) {
- for (auto iter = window_tree_clients_.begin();
- iter != window_tree_clients_.end(); ++iter) {
- if (iter->get() == client) {
- window_tree_clients_.erase(iter);
- return;
- }
- }
- NOTREACHED();
-}
-
-std::unique_ptr<aura::WindowTreeClient>
-WindowServerTestBase::ReleaseMostRecentClient() {
- if (window_tree_clients_.empty())
- return nullptr;
-
- std::unique_ptr<aura::WindowTreeClient> result =
- std::move(window_tree_clients_.back());
- window_tree_clients_.pop_back();
- return result;
-}
-
-void WindowServerTestBase::SetUp() {
- feature_list_.InitAndEnableFeature(features::kMashDeprecated);
- WindowServerServiceTestBase::SetUp();
-
- env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS);
- display::Screen::SetScreenInstance(&screen_);
- std::unique_ptr<aura::WindowTreeClient> window_manager_window_tree_client =
- aura::WindowTreeClient::CreateForWindowManager(connector(), this, this);
- window_manager_ = window_manager_window_tree_client.get();
- window_tree_clients_.push_back(std::move(window_manager_window_tree_client));
-
- // Connecting as the WindowManager results in OnWmNewDisplay() being called
- // with the display (and root). Wait for it to be called so we have display
- // and root window information (otherwise we can't really do anything).
- ASSERT_TRUE(DoRunLoopWithTimeout());
-}
-
-void WindowServerTestBase::TearDown() {
- // WindowTreeHost depends on WindowTreeClient.
- window_tree_hosts_.clear();
- window_tree_clients_.clear();
- env_.reset();
- display::Screen::SetScreenInstance(nullptr);
-
- WindowServerServiceTestBase::TearDown();
-}
-
-void WindowServerTestBase::OnBindInterface(
- const service_manager::BindSourceInfo& source_info,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) {
- registry_.BindInterface(interface_name, std::move(interface_pipe));
-}
-
-void WindowServerTestBase::OnEmbed(
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
- EXPECT_TRUE(QuitRunLoop());
- window_tree_hosts_.push_back(std::move(window_tree_host));
-}
-
-void WindowServerTestBase::OnLostConnection(aura::WindowTreeClient* client) {
- window_tree_client_lost_connection_ = true;
- DeleteWindowTreeClient(client);
-}
-
-void WindowServerTestBase::OnEmbedRootDestroyed(
- aura::WindowTreeHostMus* window_tree_host) {
- if (!DeleteWindowTreeHost(window_tree_host)) {
- // Assume a subclass called Embed() and wants us to destroy it.
- delete window_tree_host;
- }
-}
-
-void WindowServerTestBase::OnPointerEventObserved(const ui::PointerEvent& event,
- int64_t display_id,
- aura::Window* target) {}
-
-aura::PropertyConverter* WindowServerTestBase::GetPropertyConverter() {
- return &property_converter_;
-}
-
-void WindowServerTestBase::SetWindowManagerClient(
- aura::WindowManagerClient* client) {
- window_manager_client_ = client;
-}
-
-void WindowServerTestBase::OnWmConnected() {}
-
-void WindowServerTestBase::OnWmSetBounds(aura::Window* window,
- const gfx::Rect& bounds) {
- if (!window_manager_delegate_)
- return;
- window_manager_delegate_->OnWmSetBounds(window, bounds);
-}
-
-bool WindowServerTestBase::OnWmSetProperty(
- aura::Window* window,
- const std::string& name,
- std::unique_ptr<std::vector<uint8_t>>* new_data) {
- return window_manager_delegate_
- ? window_manager_delegate_->OnWmSetProperty(window, name, new_data)
- : true;
-}
-
-void WindowServerTestBase::OnWmSetModalType(aura::Window* window,
- ui::ModalType type) {
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmSetModalType(window, type);
-}
-
-void WindowServerTestBase::OnWmSetCanFocus(aura::Window* window,
- bool can_focus) {
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmSetCanFocus(window, can_focus);
-}
-
-aura::Window* WindowServerTestBase::OnWmCreateTopLevelWindow(
- ui::mojom::WindowType window_type,
- std::map<std::string, std::vector<uint8_t>>* properties) {
- return window_manager_delegate_
- ? window_manager_delegate_->OnWmCreateTopLevelWindow(window_type,
- properties)
- : nullptr;
-}
-
-void WindowServerTestBase::OnWmClientJankinessChanged(
- const std::set<aura::Window*>& client_windows,
- bool janky) {
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmClientJankinessChanged(client_windows, janky);
-}
-
-void WindowServerTestBase::OnWmWillCreateDisplay(
- const display::Display& display) {
- screen_.display_list().AddDisplay(display,
- display::DisplayList::Type::PRIMARY);
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmWillCreateDisplay(display);
-}
-
-void WindowServerTestBase::OnWmNewDisplay(
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
- const display::Display& display) {
- EXPECT_TRUE(QuitRunLoop());
- ASSERT_TRUE(window_manager_client_);
- window_manager_client_->AddActivationParent(window_tree_host->window());
- window_tree_hosts_.push_back(std::move(window_tree_host));
-
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmNewDisplay(nullptr, display);
-}
-
-void WindowServerTestBase::OnWmDisplayRemoved(
- aura::WindowTreeHostMus* window_tree_host) {
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmDisplayRemoved(window_tree_host);
- ASSERT_TRUE(DeleteWindowTreeHost(window_tree_host));
-}
-
-void WindowServerTestBase::OnWmDisplayModified(
- const display::Display& display) {
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmDisplayModified(display);
-}
-
-ui::mojom::EventResult WindowServerTestBase::OnAccelerator(
- uint32_t accelerator_id,
- const ui::Event& event,
- base::flat_map<std::string, std::vector<uint8_t>>* properties) {
- return window_manager_delegate_ ? window_manager_delegate_->OnAccelerator(
- accelerator_id, event, properties)
- : ui::mojom::EventResult::UNHANDLED;
-}
-
-void WindowServerTestBase::OnCursorTouchVisibleChanged(bool enabled) {
- if (window_manager_delegate_)
- window_manager_delegate_->OnCursorTouchVisibleChanged(enabled);
-}
-
-void WindowServerTestBase::OnWmPerformMoveLoop(
- aura::Window* window,
- ui::mojom::MoveLoopSource source,
- const gfx::Point& cursor_location,
- const base::Callback<void(bool)>& on_done) {
- if (window_manager_delegate_) {
- window_manager_delegate_->OnWmPerformMoveLoop(window, source,
- cursor_location, on_done);
- }
-}
-
-void WindowServerTestBase::OnWmCancelMoveLoop(aura::Window* window) {
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmCancelMoveLoop(window);
-}
-
-void WindowServerTestBase::OnWmSetClientArea(
- aura::Window* window,
- const gfx::Insets& insets,
- const std::vector<gfx::Rect>& additional_client_areas) {
- if (window_manager_delegate_) {
- window_manager_delegate_->OnWmSetClientArea(window, insets,
- additional_client_areas);
- }
-}
-
-bool WindowServerTestBase::IsWindowActive(aura::Window* window) {
- if (window_manager_delegate_)
- window_manager_delegate_->IsWindowActive(window);
- return false;
-}
-
-void WindowServerTestBase::OnWmDeactivateWindow(aura::Window* window) {
- if (window_manager_delegate_)
- window_manager_delegate_->OnWmDeactivateWindow(window);
-}
-
-void WindowServerTestBase::BindWindowTreeClientRequest(
- ui::mojom::WindowTreeClientRequest request) {
- const bool create_discardable_memory = false;
- window_tree_clients_.push_back(aura::WindowTreeClient::CreateForEmbedding(
- connector(), this, std::move(request), create_discardable_memory));
-}
-
-bool WindowServerTestBase::DeleteWindowTreeHost(
- aura::WindowTreeHostMus* window_tree_host) {
- for (auto iter = window_tree_hosts_.begin(); iter != window_tree_hosts_.end();
- ++iter) {
- if ((*iter).get() == window_tree_host) {
- window_tree_hosts_.erase(iter);
- return true;
- }
- }
- return false;
-}
-
-} // namespace ui
diff --git a/services/ui/ws/window_server_test_base.h b/services/ui/ws/window_server_test_base.h
deleted file mode 100644
index 0d92c21a..0000000
--- a/services/ui/ws/window_server_test_base.h
+++ /dev/null
@@ -1,175 +0,0 @@
-// 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_SERVER_TEST_BASE_H_
-#define SERVICES_UI_WS_WINDOW_SERVER_TEST_BASE_H_
-
-#include <memory>
-#include <set>
-
-#include "base/macros.h"
-#include "base/test/scoped_feature_list.h"
-#include "services/service_manager/public/cpp/binder_registry.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/ws/window_server_service_test_base.h"
-#include "ui/aura/mus/property_converter.h"
-#include "ui/aura/mus/window_manager_delegate.h"
-#include "ui/aura/mus/window_tree_client_delegate.h"
-#include "ui/display/screen_base.h"
-#include "ui/wm/core/wm_state.h"
-
-namespace aura {
-class Env;
-}
-
-namespace ui {
-
-// WindowServerTestBase is a base class for use with shell tests that use
-// WindowServer. SetUp() connects to the WindowServer and blocks until OnEmbed()
-// has been invoked. window_manager() can be used to access the WindowServer
-// established as part of SetUp().
-class WindowServerTestBase : public WindowServerServiceTestBase,
- public aura::WindowTreeClientDelegate,
- public aura::WindowManagerDelegate {
- public:
- WindowServerTestBase();
- ~WindowServerTestBase() override;
-
- // True if WindowTreeClientDelegate::OnLostConnection() was called.
- bool window_tree_client_lost_connection() const {
- return window_tree_client_lost_connection_;
- }
-
- // Runs the MessageLoop until QuitRunLoop() is called, or a timeout occurs.
- // Returns true on success. Generally prefer running a RunLoop and
- // explicitly quiting that, but use this for times when that is not possible.
- static bool DoRunLoopWithTimeout() WARN_UNUSED_RESULT;
-
- // Quits a run loop started by DoRunLoopWithTimeout(). Returns true on
- // success, false if a RunLoop isn't running.
- static bool QuitRunLoop() WARN_UNUSED_RESULT;
-
- aura::WindowTreeClient* window_manager() { return window_manager_; }
- aura::WindowManagerClient* window_manager_client() {
- return window_manager_client_;
- }
-
- protected:
- void set_window_manager_delegate(aura::WindowManagerDelegate* delegate) {
- window_manager_delegate_ = delegate;
- }
-
- // Cleans up internal state then deletes |client|.
- void DeleteWindowTreeClient(aura::WindowTreeClient* client);
-
- // Returns the most recent WindowTreeClient that was created as the result of
- // InterfaceFactory<WindowTreeClient> being called. In other words the most
- // recent WindowTreeClient created as the result of a client embedding.
- std::unique_ptr<aura::WindowTreeClient> ReleaseMostRecentClient();
-
- // testing::Test:
- void SetUp() override;
- void TearDown() override;
-
- // WindowServerServiceTestBase:
- void OnBindInterface(const service_manager::BindSourceInfo& source_info,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) override;
-
- // WindowTreeClientDelegate:
- void OnEmbed(
- std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override;
- void OnLostConnection(aura::WindowTreeClient* client) override;
- void OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) override;
- void OnPointerEventObserved(const ui::PointerEvent& event,
- int64_t display_id,
- aura::Window* target) override;
- aura::PropertyConverter* GetPropertyConverter() override;
-
- // WindowManagerDelegate:
- void SetWindowManagerClient(aura::WindowManagerClient* client) override;
- void OnWmConnected() override;
- void OnWmAcceleratedWidgetAvailableForDisplay(
- int64_t display_id,
- gfx::AcceleratedWidget widget) override {}
- void OnWmSetBounds(aura::Window* window, const gfx::Rect& bounds) override;
- bool OnWmSetProperty(
- aura::Window* window,
- const std::string& name,
- std::unique_ptr<std::vector<uint8_t>>* new_data) override;
- void OnWmSetModalType(aura::Window* window, ui::ModalType type) override;
- void OnWmSetCanFocus(aura::Window* window, bool can_focus) override;
- aura::Window* OnWmCreateTopLevelWindow(
- ui::mojom::WindowType window_type,
- std::map<std::string, std::vector<uint8_t>>* properties) override;
- void OnWmClientJankinessChanged(const std::set<aura::Window*>& client_windows,
- bool not_responding) override;
- void OnWmBuildDragImage(const gfx::Point& screen_location,
- const gfx::ImageSkia& drag_image,
- const gfx::Vector2d& drag_image_offset,
- ui::mojom::PointerKind source) override {}
- void OnWmMoveDragImage(const gfx::Point& screen_location) override {}
- void OnWmDestroyDragImage() override {}
- void OnWmWillCreateDisplay(const display::Display& display) override;
- void OnWmNewDisplay(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
- const display::Display& display) override;
- void OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) override;
- void OnWmDisplayModified(const display::Display& display) override;
- mojom::EventResult OnAccelerator(
- uint32_t accelerator_id,
- const ui::Event& event,
- base::flat_map<std::string, std::vector<uint8_t>>* properties) override;
- void OnCursorTouchVisibleChanged(bool enabled) override;
- void OnWmPerformMoveLoop(aura::Window* window,
- mojom::MoveLoopSource source,
- const gfx::Point& cursor_location,
- const base::Callback<void(bool)>& on_done) override;
- void OnWmCancelMoveLoop(aura::Window* window) override;
- void OnWmSetClientArea(
- aura::Window* window,
- const gfx::Insets& insets,
- const std::vector<gfx::Rect>& additional_client_areas) override;
- bool IsWindowActive(aura::Window* window) override;
- void OnWmDeactivateWindow(aura::Window* window) override;
-
- void BindWindowTreeClientRequest(
- mojom::WindowTreeClientRequest request);
-
- private:
- // Removes |window_tree_host| from |window_tree_hosts_| and deletes it.
- // Returns true on success, and false if not found, in which case
- // |window_tree_host| is not deleted.
- bool DeleteWindowTreeHost(aura::WindowTreeHostMus* window_tree_host);
-
- base::test::ScopedFeatureList feature_list_;
-
- std::unique_ptr<aura::Env> env_;
- ::wm::WMState wm_state_;
- display::ScreenBase screen_;
- aura::PropertyConverter property_converter_;
-
- std::vector<std::unique_ptr<aura::WindowTreeClient>> window_tree_clients_;
-
- std::vector<std::unique_ptr<aura::WindowTreeHostMus>> window_tree_hosts_;
-
- // The window server connection held by the window manager (app running at
- // the root window).
- aura::WindowTreeClient* window_manager_ = nullptr;
-
- // A test can override the WM-related behaviour by installing its own
- // WindowManagerDelegate during the test.
- aura::WindowManagerDelegate* window_manager_delegate_ = nullptr;
-
- aura::WindowManagerClient* window_manager_client_ = nullptr;
-
- bool window_tree_client_lost_connection_ = false;
-
- service_manager::BinderRegistry registry_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowServerTestBase);
-};
-
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_SERVER_TEST_BASE_H_
diff --git a/services/ui/ws/window_server_test_impl.cc b/services/ui/ws/window_server_test_impl.cc
deleted file mode 100644
index 56028334..0000000
--- a/services/ui/ws/window_server_test_impl.cc
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/window_server_test_impl.h"
-
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree.h"
-
-namespace ui {
-namespace ws {
-
-WindowServerTestImpl::WindowServerTestImpl(WindowServer* window_server)
- : window_server_(window_server) {}
-
-WindowServerTestImpl::~WindowServerTestImpl() {}
-
-void WindowServerTestImpl::OnSurfaceActivated(
- const std::string& name,
- EnsureClientHasDrawnWindowCallback cb,
- ServerWindow* window) {
- // This api is used to detect when a client has painted once, which is
- // dictated by whether there is a CompositorFrameSink.
- WindowTree* tree = window_server_->GetTreeWithClientName(name);
- if (tree && tree->HasRoot(window) &&
- window->has_created_compositor_frame_sink()) {
- std::move(cb).Run(true);
- } else {
- // No tree with the given name, or it hasn't painted yet. Install a callback
- // for the next time a client creates a CompositorFramesink.
- InstallCallback(name, std::move(cb));
- }
-}
-
-void WindowServerTestImpl::InstallCallback(
- const std::string& client_name,
- EnsureClientHasDrawnWindowCallback cb) {
- window_server_->SetSurfaceActivationCallback(
- base::BindOnce(&WindowServerTestImpl::OnSurfaceActivated,
- base::Unretained(this), client_name, std::move(cb)));
-}
-
-void WindowServerTestImpl::EnsureClientHasDrawnWindow(
- const std::string& client_name,
- EnsureClientHasDrawnWindowCallback callback) {
- WindowTree* tree = window_server_->GetTreeWithClientName(client_name);
- if (tree) {
- for (const ServerWindow* window : tree->roots()) {
- if (window->has_created_compositor_frame_sink()) {
- std::move(callback).Run(true);
- return;
- }
- }
- }
- InstallCallback(client_name, std::move(callback));
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_server_test_impl.h b/services/ui/ws/window_server_test_impl.h
deleted file mode 100644
index 43c4d361..0000000
--- a/services/ui/ws/window_server_test_impl.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_SERVER_TEST_IMPL_H_
-#define SERVICES_UI_WS_WINDOW_SERVER_TEST_IMPL_H_
-
-#include "services/ui/public/interfaces/window_server_test.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class ServerWindow;
-class WindowServer;
-
-// Used to detect when a client (as identified by a name) has drawn at least
-// once to screen.
-class WindowServerTestImpl : public mojom::WindowServerTest {
- public:
- explicit WindowServerTestImpl(WindowServer* server);
- ~WindowServerTestImpl() override;
-
- private:
- void OnSurfaceActivated(const std::string& name,
- EnsureClientHasDrawnWindowCallback cb,
- ServerWindow* window);
-
- // Installs a callback that calls OnSurfaceActivated() the next time a client
- // creates a compositor frame.
- void InstallCallback(const std::string& name,
- EnsureClientHasDrawnWindowCallback cb);
-
- // mojom::WindowServerTest:
- void EnsureClientHasDrawnWindow(
- const std::string& client_name,
- EnsureClientHasDrawnWindowCallback callback) override;
-
- WindowServer* window_server_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowServerTestImpl);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_SERVER_TEST_IMPL_H_
diff --git a/services/ui/ws/window_tree.cc b/services/ui/ws/window_tree.cc
deleted file mode 100644
index 0b48d0a..0000000
--- a/services/ui/ws/window_tree.cc
+++ /dev/null
@@ -1,2898 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/window_tree.h"
-
-#include <stddef.h>
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/callback_helpers.h"
-#include "base/macros.h"
-#include "base/memory/ptr_util.h"
-#include "build/build_config.h"
-#include "mojo/public/cpp/bindings/map.h"
-#include "services/ui/common/util.h"
-#include "services/ui/display/screen_manager.h"
-#include "services/ui/ws/cursor_location_manager.h"
-#include "services/ui/ws/debug_utils.h"
-#include "services/ui/ws/default_access_policy.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/event_location.h"
-#include "services/ui/ws/event_matcher.h"
-#include "services/ui/ws/event_processor.h"
-#include "services/ui/ws/focus_controller.h"
-#include "services/ui/ws/frame_generator.h"
-#include "services/ui/ws/modal_window_controller.h"
-#include "services/ui/ws/operation.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/server_window_observer.h"
-#include "services/ui/ws/user_display_manager.h"
-#include "services/ui/ws/window_manager_display_root.h"
-#include "services/ui/ws/window_manager_state.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/display/display.h"
-#include "ui/display/display_list.h"
-#include "ui/display/screen_base.h"
-#include "ui/display/types/display_constants.h"
-#include "ui/platform_window/mojo/ime_type_converters.h"
-#include "ui/platform_window/text_input_state.h"
-
-using mojo::InterfaceRequest;
-
-using EventProperties = base::flat_map<std::string, std::vector<uint8_t>>;
-
-namespace ui {
-namespace ws {
-namespace {
-
-bool HasPositiveInset(const gfx::Insets& insets) {
- return insets.width() > 0 || insets.height() > 0 || insets.left() > 0 ||
- insets.right() > 0;
-}
-
-FrameGenerator* GetFrameGenerator(WindowManagerDisplayRoot* display_root) {
- return display_root->display()->platform_display()
- ? display_root->display()->platform_display()->GetFrameGenerator()
- : nullptr;
-}
-
-display::ViewportMetrics TransportMetricsToDisplayMetrics(
- const ui::mojom::WmViewportMetrics& transport_metrics) {
- display::ViewportMetrics viewport_metrics;
- viewport_metrics.bounds_in_pixels = transport_metrics.bounds_in_pixels;
- viewport_metrics.device_scale_factor = transport_metrics.device_scale_factor;
- viewport_metrics.ui_scale_factor = transport_metrics.ui_scale_factor;
- return viewport_metrics;
-}
-
-} // namespace
-
-class TargetedEvent : public ServerWindowObserver {
- public:
- TargetedEvent(ServerWindow* target,
- const ui::Event& event,
- const EventLocation& event_location,
- WindowTree::DispatchEventCallback callback)
- : target_(target),
- event_(ui::Event::Clone(event)),
- event_location_(event_location),
- callback_(std::move(callback)) {
- target_->AddObserver(this);
- }
- ~TargetedEvent() override {
- if (target_)
- target_->RemoveObserver(this);
- }
-
- ServerWindow* target() { return target_; }
- std::unique_ptr<ui::Event> TakeEvent() { return std::move(event_); }
- const EventLocation& event_location() const { return event_location_; }
- WindowTree::DispatchEventCallback TakeCallback() {
- return std::move(callback_);
- }
-
- private:
- // ServerWindowObserver:
- void OnWindowDestroyed(ServerWindow* window) override {
- DCHECK_EQ(target_, window);
- target_->RemoveObserver(this);
- target_ = nullptr;
- }
-
- ServerWindow* target_;
- std::unique_ptr<ui::Event> event_;
- const EventLocation event_location_;
- WindowTree::DispatchEventCallback callback_;
-
- DISALLOW_COPY_AND_ASSIGN(TargetedEvent);
-};
-
-struct WindowTree::DragMoveState {
- // Whether we've queued a move to |queued_cursor_location_| when we get an
- // ack from WmMoveDragImage.
- bool has_queued_drag_window_move = false;
-
- // When |has_queued_drag_window_move_| is true, this is a location which
- // should be sent to the window manager as soon as it acked the last one.
- gfx::Point queued_cursor_location;
-};
-
-WindowTree::WindowTree(WindowServer* window_server,
- bool is_for_embedding,
- ServerWindow* root,
- std::unique_ptr<AccessPolicy> access_policy)
- : window_server_(window_server),
- is_for_embedding_(is_for_embedding),
- id_(window_server_->GetAndAdvanceNextClientId()),
- access_policy_(std::move(access_policy)),
- event_ack_id_(0),
- window_manager_internal_(nullptr),
- drag_weak_factory_(this) {
- if (root)
- roots_.insert(root);
- access_policy_->Init(id_, this);
-}
-
-WindowTree::~WindowTree() {
- DestroyWindows();
-
- // We alert the WindowManagerState that we're destroying this state here
- // because WindowManagerState would attempt to use things that wouldn't have
- // been cleaned up by OnWindowDestroyingTreeImpl().
- if (window_manager_state_) {
- window_manager_state_->OnWillDestroyTree(this);
- window_manager_state_.reset();
- }
-}
-
-void WindowTree::Init(std::unique_ptr<WindowTreeBinding> binding,
- mojom::WindowTreePtr tree) {
- DCHECK(!binding_);
- binding_ = std::move(binding);
-
- if (roots_.empty())
- return;
-
- std::vector<const ServerWindow*> to_send;
- CHECK_EQ(1u, roots_.size());
- const ServerWindow* root = *roots_.begin();
- GetUnknownWindowsFrom(root, &to_send, nullptr);
-
- Display* display = GetDisplay(root);
- int64_t display_id = display ? display->GetId() : display::kInvalidDisplayId;
- const ServerWindow* focused_window =
- display ? display->GetFocusedWindow() : nullptr;
- if (focused_window)
- focused_window = access_policy_->GetWindowForFocusChange(focused_window);
- ClientWindowId focused_window_id;
- if (focused_window)
- IsWindowKnown(focused_window, &focused_window_id);
-
- const bool drawn = root->parent() && root->parent()->IsDrawn();
- client()->OnEmbed(WindowToWindowData(to_send.front()), std::move(tree),
- display_id, ClientWindowIdToTransportId(focused_window_id),
- drawn, root->current_local_surface_id());
-}
-
-void WindowTree::OnAcceleratedWidgetAvailableForDisplay(Display* display) {
- DCHECK(window_manager_internal_);
- // TODO(sad): Use GpuSurfaceTracker on platforms where a gpu::SurfaceHandle is
- // not the same as a gfx::AcceleratedWidget.
- window_manager_internal_->WmOnAcceleratedWidgetForDisplay(
- display->GetId(), display->platform_display()->GetAcceleratedWidget());
-}
-
-void WindowTree::ConfigureWindowManager(
- bool automatically_create_display_roots) {
- // ConfigureWindowManager() should be called early on, before anything
- // else. |waiting_for_top_level_window_info_| must be null as if
- // |waiting_for_top_level_window_info_| is non-null it means we're about to
- // create an associated interface, which doesn't work with pause/resume.
- // TODO(sky): DCHECK temporary until 626869 is sorted out.
- DCHECK(!waiting_for_top_level_window_info_);
- DCHECK(!window_manager_internal_);
- automatically_create_display_roots_ = automatically_create_display_roots;
- window_manager_internal_ = binding_->GetWindowManager();
- window_manager_internal_->OnConnect();
- window_manager_state_ = std::make_unique<WindowManagerState>(this);
-}
-
-bool WindowTree::IsWindowKnown(const ServerWindow* window,
- ClientWindowId* id) const {
- if (!window)
- return false;
- auto iter = window_to_client_id_map_.find(window);
- if (iter == window_to_client_id_map_.end())
- return false;
- if (id)
- *id = iter->second;
- return true;
-}
-
-bool WindowTree::HasRoot(const ServerWindow* window) const {
- return roots_.count(window) > 0;
-}
-
-const ServerWindow* WindowTree::GetWindowByClientId(
- const ClientWindowId& id) const {
- auto iter = client_id_to_window_map_.find(id);
- return iter == client_id_to_window_map_.end() ? nullptr : iter->second;
-}
-
-const Display* WindowTree::GetDisplay(const ServerWindow* window) const {
- return window ? display_manager()->GetDisplayContaining(window) : nullptr;
-}
-
-const WindowManagerDisplayRoot* WindowTree::GetWindowManagerDisplayRoot(
- const ServerWindow* window) const {
- return window ? display_manager()->GetWindowManagerDisplayRoot(window)
- : nullptr;
-}
-
-DisplayManager* WindowTree::display_manager() {
- return window_server_->display_manager();
-}
-
-const DisplayManager* WindowTree::display_manager() const {
- return window_server_->display_manager();
-}
-
-void WindowTree::PrepareForWindowServerShutdown() {
- window_manager_internal_client_binding_.reset();
- binding_->ResetClientForShutdown();
- if (window_manager_internal_)
- window_manager_internal_ = binding_->GetWindowManager();
-}
-
-void WindowTree::AddRootForWindowManager(const ServerWindow* root) {
- if (!automatically_create_display_roots_)
- return;
-
- DCHECK(automatically_create_display_roots_);
- DCHECK(window_manager_internal_);
- const ClientWindowId client_window_id = root->frame_sink_id();
- AddToMaps(root, client_window_id);
- roots_.insert(root);
-
- Display* ws_display = GetDisplay(root);
- DCHECK(ws_display);
-
- window_manager_internal_->WmNewDisplayAdded(
- ws_display->GetDisplay(), WindowToWindowData(root),
- root->parent()->IsDrawn(), root->current_local_surface_id());
-}
-
-void WindowTree::OnWillDestroyTree(WindowTree* tree) {
- DCHECK_NE(tree, this); // This function is not called for |this|.
-
- if (event_source_wms_ && event_source_wms_->window_tree() == tree)
- event_source_wms_ = nullptr;
-
- // Notify our client if |tree| was embedded in any of our windows.
- for (const auto* tree_root : tree->roots_) {
- const bool owns_tree_root = tree_root->owning_tree_id() == id_;
- if (owns_tree_root)
- client()->OnEmbeddedAppDisconnected(TransportIdForWindow(tree_root));
- }
-
- if (window_manager_state_)
- window_manager_state_->OnWillDestroyTree(tree);
-}
-
-void WindowTree::OnWmDisplayModified(const display::Display& display) {
- window_manager_internal_->WmDisplayModified(display);
-}
-
-void WindowTree::NotifyChangeCompleted(
- uint32_t change_id,
- mojom::WindowManagerErrorCode error_code) {
- client()->OnChangeCompleted(
- change_id, error_code == mojom::WindowManagerErrorCode::SUCCESS);
-}
-
-void WindowTree::OnWmMoveDragImageAck() {
- if (drag_move_state_->has_queued_drag_window_move) {
- gfx::Point queued_location = drag_move_state_->queued_cursor_location;
- drag_move_state_.reset();
- OnDragMoved(queued_location);
- } else {
- drag_move_state_.reset();
- }
-}
-
-ServerWindow* WindowTree::ProcessSetDisplayRoot(
- const display::Display& display_to_create,
- const display::ViewportMetrics& viewport_metrics,
- bool is_primary_display,
- const ClientWindowId& client_window_id,
- const std::vector<display::Display>& mirrors) {
- DCHECK(window_manager_state_); // Only called for window manager.
- DVLOG(3) << "SetDisplayRoot client=" << id_
- << " global window_id=" << client_window_id.ToString();
-
- if (automatically_create_display_roots_) {
- DVLOG(1) << "SetDisplayRoot is only applicable when "
- << "automatically_create_display_roots is false";
- return nullptr;
- }
-
- ServerWindow* window = GetWindowByClientId(client_window_id);
- const bool is_moving_to_new_display =
- window && window->parent() && base::ContainsKey(roots_, window);
- if (!window || (window->parent() && !is_moving_to_new_display)) {
- DVLOG(1) << "SetDisplayRoot called with invalid window id "
- << client_window_id.ToString();
- return nullptr;
- }
-
- if (base::ContainsKey(roots_, window) && !is_moving_to_new_display) {
- DVLOG(1) << "SetDisplayRoot called with existing root";
- return nullptr;
- }
-
- Display* display = display_manager()->GetDisplayById(display_to_create.id());
- const bool display_already_existed = display != nullptr;
- if (!display) {
- // Create a display if the window manager is extending onto a new display.
- display = display_manager()->AddDisplayForWindowManager(
- is_primary_display, display_to_create, viewport_metrics);
- } else if (!display->window_manager_display_root()) {
- // Init the root if the display already existed as a mirroring destination.
- display->InitWindowManagerDisplayRoots();
- }
-
- if (!mirrors.empty())
- NOTIMPLEMENTED() << "TODO(crbug.com/806318): Mus+Viz mirroring/unified";
-
- DCHECK(display);
- WindowManagerDisplayRoot* display_root =
- display->window_manager_display_root();
- DCHECK(display_root);
- display_root->root()->RemoveAllChildren();
-
- // NOTE: this doesn't resize the window in any way. We assume the client takes
- // care of any modifications it needs to do.
- roots_.insert(window);
- Operation op(this, window_server_, OperationType::ADD_WINDOW);
- ServerWindow* old_parent =
- is_moving_to_new_display ? window->parent() : nullptr;
- display_root->root()->Add(window);
- if (is_moving_to_new_display) {
- DCHECK(old_parent);
- window_manager_state_->DeleteWindowManagerDisplayRoot(old_parent);
- }
- if (display_already_existed &&
- display->platform_display()->GetAcceleratedWidget()) {
- // Notify the window manager that the dispay's accelerated widget is already
- // available, if the display is being reused for a new window tree host.
- window_manager_internal_->WmOnAcceleratedWidgetForDisplay(
- display->GetId(), display->platform_display()->GetAcceleratedWidget());
- }
- return window;
-}
-
-bool WindowTree::ProcessSwapDisplayRoots(int64_t display_id1,
- int64_t display_id2) {
- DCHECK(window_manager_state_); // Can only be called by the window manager.
- DVLOG(3) << "SwapDisplayRoots display_id1=" << display_id2
- << " display_id2=" << display_id2;
- if (automatically_create_display_roots_) {
- DVLOG(1) << "SwapDisplayRoots only applicable when window-manager creates "
- << "display roots";
- return false;
- }
- Display* display1 = display_manager()->GetDisplayById(display_id1);
- Display* display2 = display_manager()->GetDisplayById(display_id2);
- if (!display1 || !display2) {
- DVLOG(1) << "SwapDisplayRoots called with unknown display ids";
- return false;
- }
-
- WindowManagerDisplayRoot* display_root1 =
- display1->window_manager_display_root();
- WindowManagerDisplayRoot* display_root2 =
- display2->window_manager_display_root();
-
- if (!display_root1->GetClientVisibleRoot() ||
- !display_root2->GetClientVisibleRoot()) {
- DVLOG(1) << "SetDisplayRoot called with displays that have not been "
- << "configured";
- return false;
- }
-
- display_root1->root()->Add(display_root2->GetClientVisibleRoot());
- display_root2->root()->Add(display_root1->GetClientVisibleRoot());
-
- // TODO(sky): this is race condition here if one is valid and one null.
- FrameGenerator* frame_generator1 = GetFrameGenerator(display_root1);
- FrameGenerator* frame_generator2 = GetFrameGenerator(display_root2);
- if (frame_generator1 && frame_generator2)
- frame_generator1->SwapSurfaceWith(frame_generator2);
-
- return true;
-}
-
-bool WindowTree::ProcessSetBlockingContainers(
- std::vector<mojom::BlockingContainersPtr>
- transport_all_blocking_containers) {
- DCHECK(window_manager_state_); // Can only be called by the window manager.
-
- std::vector<BlockingContainers> all_containers;
- for (auto& transport_container : transport_all_blocking_containers) {
- BlockingContainers blocking_containers;
- blocking_containers.system_modal_container = GetWindowByClientId(
- MakeClientWindowId(transport_container->system_modal_container_id));
- if (!blocking_containers.system_modal_container) {
- DVLOG(1) << "SetBlockingContainers called with unknown modal container";
- return false;
- }
- blocking_containers.min_container = GetWindowByClientId(
- MakeClientWindowId(transport_container->min_container_id));
- all_containers.push_back(blocking_containers);
- }
- window_manager_state_->event_processor()
- ->modal_window_controller()
- ->SetBlockingContainers(all_containers);
- return true;
-}
-
-bool WindowTree::SetCapture(const ClientWindowId& client_window_id) {
- ServerWindow* window = GetWindowByClientId(client_window_id);
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- ServerWindow* current_capture_window =
- display_root ? display_root->window_manager_state()->capture_window()
- : nullptr;
- if (window && window->IsDrawn() && display_root &&
- access_policy_->CanSetCapture(window) &&
- (!current_capture_window ||
- access_policy_->CanSetCapture(current_capture_window))) {
- Operation op(this, window_server_, OperationType::SET_CAPTURE);
- return display_root->window_manager_state()->SetCapture(window, id_);
- }
- return false;
-}
-
-bool WindowTree::ReleaseCapture(const ClientWindowId& client_window_id) {
- ServerWindow* window = GetWindowByClientId(client_window_id);
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- ServerWindow* current_capture_window =
- display_root ? display_root->window_manager_state()->capture_window()
- : nullptr;
- if (!window || !display_root ||
- (current_capture_window &&
- !access_policy_->CanSetCapture(current_capture_window)) ||
- window != current_capture_window) {
- return false;
- }
- Operation op(this, window_server_, OperationType::RELEASE_CAPTURE);
- return display_root->window_manager_state()->SetCapture(nullptr,
- kInvalidClientId);
-}
-
-void WindowTree::DispatchEvent(ServerWindow* target,
- const ui::Event& event,
- const EventLocation& event_location,
- DispatchEventCallback callback) {
- if (event_ack_id_ || !event_queue_.empty()) {
- // Either awaiting an ack, or there are events in the queue. Store the event
- // for processing when the ack is received.
- event_queue_.push(std::make_unique<TargetedEvent>(
- target, event, event_location, std::move(callback)));
- // TODO(sad): If the |event_queue_| grows too large, then this should notify
- // Display, so that it can stop sending events.
- return;
- }
-
- DispatchEventImpl(target, event, event_location, std::move(callback));
-}
-
-void WindowTree::DispatchAccelerator(uint32_t accelerator_id,
- const ui::Event& event,
- AcceleratorCallback callback) {
- DVLOG(3) << "OnAccelerator client=" << id_;
- DCHECK(window_manager_internal_); // Only valid for the window manager.
- if (callback) {
- GenerateEventAckId();
- accelerator_ack_callback_ = std::move(callback);
- } else {
- DCHECK_EQ(0u, event_ack_id_);
- DCHECK(!accelerator_ack_callback_);
- }
- // TODO: https://crbug.com/617167. Don't clone event once we map mojom::Event
- // directly to ui::Event.
- window_manager_internal_->OnAccelerator(event_ack_id_, accelerator_id,
- ui::Event::Clone(event));
-}
-
-bool WindowTree::NewWindow(
- const ClientWindowId& client_window_id,
- const std::map<std::string, std::vector<uint8_t>>& properties) {
- DVLOG(3) << "new window client=" << id_
- << " window_id=" << client_window_id.ToString();
- if (!IsValidIdForNewWindow(client_window_id)) {
- DVLOG(1) << "NewWindow failed (id is not valid for client)";
- return false;
- }
- DCHECK(!GetWindowByClientId(client_window_id));
- DCHECK_EQ(id_, client_window_id.client_id());
- ServerWindow* window =
- window_server_->CreateServerWindow(client_window_id, properties);
- created_windows_.insert(window);
- AddToMaps(window, client_window_id);
- return true;
-}
-
-bool WindowTree::AddWindow(const ClientWindowId& parent_id,
- const ClientWindowId& child_id) {
- ServerWindow* parent = GetWindowByClientId(parent_id);
- ServerWindow* child = GetWindowByClientId(child_id);
- DVLOG(3) << "add window client=" << id_
- << " client parent window_id=" << parent_id.ToString()
- << " global window_id=" << DebugWindowId(parent)
- << " client child window_id= " << child_id.ToString()
- << " global window_id=" << DebugWindowId(child);
- if (!parent) {
- DVLOG(1) << "AddWindow failed (no parent)";
- return false;
- }
- if (!child) {
- DVLOG(1) << "AddWindow failed (no child)";
- return false;
- }
- if (child->parent() == parent) {
- DVLOG(1) << "AddWindow failed (already has parent)";
- return false;
- }
- if (child->Contains(parent)) {
- DVLOG(1) << "AddWindow failed (child contains parent)";
- return false;
- }
- if (!access_policy_->CanAddWindow(parent, child)) {
- DVLOG(1) << "AddWindow failed (access denied)";
- return false;
- }
- Operation op(this, window_server_, OperationType::ADD_WINDOW);
- parent->Add(child);
- return true;
-}
-
-bool WindowTree::AddTransientWindow(const ClientWindowId& window_id,
- const ClientWindowId& transient_window_id) {
- ServerWindow* window = GetWindowByClientId(window_id);
- ServerWindow* transient_window = GetWindowByClientId(transient_window_id);
- if (window && transient_window && !transient_window->Contains(window) &&
- access_policy_->CanAddTransientWindow(window, transient_window)) {
- Operation op(this, window_server_, OperationType::ADD_TRANSIENT_WINDOW);
- return window->AddTransientWindow(transient_window);
- }
- return false;
-}
-
-bool WindowTree::DeleteWindow(const ClientWindowId& window_id) {
- ServerWindow* window = GetWindowByClientId(window_id);
- DVLOG(3) << "removing window from parent client=" << id_
- << " client window_id= " << window_id.ToString()
- << " global window_id=" << DebugWindowId(window);
- if (!window)
- return false;
-
- if (roots_.count(window) > 0) {
- // Deleting a root behaves as an unembed.
- window_server_->OnTreeMessagedClient(id_);
- RemoveRoot(window, RemoveRootReason::UNEMBED);
- return true;
- }
-
- if (!access_policy_->CanDeleteWindow(window) &&
- !ShouldRouteToWindowManager(window)) {
- return false;
- }
-
- // Have the owner of the tree service the actual delete.
- WindowTree* tree = window_server_->GetTreeWithId(window->owning_tree_id());
- return tree && tree->DeleteWindowImpl(this, window);
-}
-
-bool WindowTree::SetModalType(const ClientWindowId& window_id,
- ModalType modal_type) {
- ServerWindow* window = GetWindowByClientId(window_id);
- if (!window) {
- DVLOG(1) << "SetModalType failed (invalid id)";
- return false;
- }
-
- if (is_for_embedding_ && modal_type == MODAL_TYPE_SYSTEM) {
- DVLOG(1) << "SetModalType failed (not allowed for embedded clients)";
- return false;
- }
-
- if (ShouldRouteToWindowManager(window)) {
- WindowTree* wm_tree = GetWindowManagerDisplayRoot(window)
- ->window_manager_state()
- ->window_tree();
- wm_tree->window_manager_internal_->WmSetModalType(
- wm_tree->TransportIdForWindow(window), modal_type);
- return true;
- }
-
- if (!access_policy_->CanSetModal(window)) {
- DVLOG(1) << "SetModalType failed (access denied)";
- return false;
- }
-
- if (window->modal_type() == modal_type)
- return true;
-
- window->SetModalType(modal_type);
- return true;
-}
-
-bool WindowTree::SetChildModalParent(
- const ClientWindowId& window_id,
- const ClientWindowId& modal_parent_window_id) {
- ServerWindow* window = GetWindowByClientId(window_id);
- ServerWindow* modal_parent_window =
- GetWindowByClientId(modal_parent_window_id);
- // A value of null for |modal_parent_window| resets the modal parent.
- if (!window) {
- DVLOG(1) << "SetChildModalParent failed (invalid id)";
- return false;
- }
-
- if (!access_policy_->CanSetChildModalParent(window, modal_parent_window)) {
- DVLOG(1) << "SetChildModalParent failed (access denied)";
- return false;
- }
-
- window->SetChildModalParent(modal_parent_window);
- return true;
-}
-
-std::vector<const ServerWindow*> WindowTree::GetWindowTree(
- const ClientWindowId& window_id) const {
- const ServerWindow* window = GetWindowByClientId(window_id);
- std::vector<const ServerWindow*> windows;
- if (window)
- GetWindowTreeImpl(window, &windows);
- return windows;
-}
-
-bool WindowTree::SetWindowVisibility(const ClientWindowId& window_id,
- bool visible) {
- ServerWindow* window = GetWindowByClientId(window_id);
- DVLOG(3) << "SetWindowVisibility client=" << id_
- << " client window_id= " << window_id.ToString()
- << " global window_id=" << DebugWindowId(window);
- if (!window) {
- DVLOG(1) << "SetWindowVisibility failed (no window)";
- return false;
- }
- if (!access_policy_->CanChangeWindowVisibility(window) ||
- (!can_change_root_window_visibility_ && HasRoot(window))) {
- DVLOG(1) << "SetWindowVisibility failed (access policy denied change)";
- return false;
- }
- if (window->visible() == visible)
- return true;
- Operation op(this, window_server_, OperationType::SET_WINDOW_VISIBILITY);
- window->SetVisible(visible);
- return true;
-}
-
-bool WindowTree::SetWindowOpacity(const ClientWindowId& window_id,
- float opacity) {
- ServerWindow* window = GetWindowByClientId(window_id);
- if (!window || !access_policy_->CanChangeWindowOpacity(window))
- return false;
- if (window->opacity() == opacity)
- return true;
- Operation op(this, window_server_, OperationType::SET_WINDOW_OPACITY);
- window->SetOpacity(opacity);
- return true;
-}
-
-bool WindowTree::SetFocus(const ClientWindowId& window_id) {
- ServerWindow* window = GetWindowByClientId(window_id);
- ServerWindow* currently_focused = window_server_->GetFocusedWindow();
- DVLOG(3) << "SetFocusedWindow client=" << id_
- << " client window_id=" << window_id.ToString()
- << " window=" << DebugWindowId(window);
- if (currently_focused == window)
- return true;
-
- Display* display = GetDisplay(window);
- if (window && (!display || !window->can_focus() || !window->IsDrawn())) {
- DVLOG(1) << "SetFocus failed (window cannot be focused)";
- return false;
- }
-
- if (!access_policy_->CanSetFocus(window)) {
- DVLOG(1) << "SetFocus failed (blocked by access policy)";
- return false;
- }
-
- Operation op(this, window_server_, OperationType::SET_FOCUS);
- bool success = window_server_->SetFocusedWindow(window);
- if (!success)
- DVLOG(1) << "SetFocus failed (could not SetFocusedWindow)";
- return success;
-}
-
-bool WindowTree::Embed(const ClientWindowId& window_id,
- mojom::WindowTreeClientPtr window_tree_client,
- uint32_t flags) {
- if (!window_tree_client || !CanEmbed(window_id))
- return false;
- ServerWindow* window = GetWindowByClientId(window_id);
- DCHECK(window); // CanEmbed() returns false if no window.
- PrepareForEmbed(window);
- // mojom::kEmbedFlagEmbedderInterceptsEvents is inherited, otherwise an
- // embedder could effectively circumvent it by embedding itself.
- if (embedder_intercepts_events_)
- flags = mojom::kEmbedFlagEmbedderInterceptsEvents;
- window_server_->EmbedAtWindow(window, std::move(window_tree_client), flags,
- base::WrapUnique(new DefaultAccessPolicy));
- client()->OnFrameSinkIdAllocated(ClientWindowIdToTransportId(window_id),
- window->frame_sink_id());
- return true;
-}
-
-bool WindowTree::EmbedExistingTree(
- const ClientWindowId& window_id,
- const WindowTreeAndWindowId& tree_and_window_id,
- const base::UnguessableToken& token) {
- const ClientWindowId window_id_in_embedded(tree_and_window_id.tree->id(),
- tree_and_window_id.window_id);
- if (!CanEmbed(window_id) ||
- !tree_and_window_id.tree->IsValidIdForNewWindow(window_id_in_embedded)) {
- return false;
- }
- ServerWindow* window = GetWindowByClientId(window_id);
- DCHECK(window); // CanEmbed() returns false if no window.
- PrepareForEmbed(window);
- tree_and_window_id.tree->AddRootForToken(token, window,
- window_id_in_embedded);
- window->UpdateFrameSinkId(window_id_in_embedded);
- client()->OnFrameSinkIdAllocated(ClientWindowIdToTransportId(window_id),
- window->frame_sink_id());
- return true;
-}
-
-bool WindowTree::IsWaitingForNewTopLevelWindow(uint32_t wm_change_id) {
- return waiting_for_top_level_window_info_ &&
- waiting_for_top_level_window_info_->wm_change_id == wm_change_id;
-}
-
-viz::FrameSinkId WindowTree::OnWindowManagerCreatedTopLevelWindow(
- uint32_t wm_change_id,
- uint32_t client_change_id,
- const ServerWindow* window) {
- DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id));
- std::unique_ptr<WaitingForTopLevelWindowInfo>
- waiting_for_top_level_window_info(
- std::move(waiting_for_top_level_window_info_));
- binding_->SetIncomingMethodCallProcessingPaused(false);
- // We were paused, so the id should still be valid.
- DCHECK(IsValidIdForNewWindow(
- waiting_for_top_level_window_info->client_window_id));
- if (!window) {
- client()->OnChangeCompleted(client_change_id, false);
- return viz::FrameSinkId();
- }
- AddToMaps(window, waiting_for_top_level_window_info->client_window_id);
- roots_.insert(window);
- Display* display = GetDisplay(window);
- int64_t display_id = display ? display->GetId() : display::kInvalidDisplayId;
- const bool drawn = window->parent() && window->parent()->IsDrawn();
- client()->OnTopLevelCreated(client_change_id, WindowToWindowData(window),
- display_id, drawn,
- window->current_local_surface_id());
- return waiting_for_top_level_window_info->client_window_id;
-}
-
-void WindowTree::AddActivationParent(const ClientWindowId& window_id) {
- ServerWindow* window = GetWindowByClientId(window_id);
- if (window)
- window->set_is_activation_parent(true);
- else
- DVLOG(1) << "AddActivationParent failed (invalid window id)";
-}
-
-void WindowTree::OnChangeCompleted(uint32_t change_id, bool success) {
- client()->OnChangeCompleted(change_id, success);
-}
-
-void WindowTree::OnEventOccurredOutsideOfModalWindow(
- const ServerWindow* modal_window) {
- DCHECK(window_manager_internal_);
- // Only tell the window manager about windows it created.
- if (modal_window->owning_tree_id() != id_)
- return;
-
- ClientWindowId client_window_id;
- const bool is_known = IsWindowKnown(modal_window, &client_window_id);
- // The window manager knows all windows.
- DCHECK(is_known);
- window_manager_internal_->OnEventBlockedByModalWindow(
- ClientWindowIdToTransportId(client_window_id));
-}
-
-void WindowTree::OnCursorTouchVisibleChanged(bool enabled) {
- DCHECK(window_manager_internal_);
- window_manager_internal_->OnCursorTouchVisibleChanged(enabled);
-}
-
-void WindowTree::OnDisplayDestroying(int64_t display_id) {
- DCHECK(window_manager_internal_);
- if (automatically_create_display_roots_)
- window_manager_internal_->WmDisplayRemoved(display_id);
- // For the else case the client should detect removal directly.
-}
-
-void WindowTree::ClientJankinessChanged(WindowTree* tree) {
- tree->janky_ = !tree->janky_;
- // Don't inform the client if it is the source of jank (which generally only
- // happens while debugging).
- if (window_manager_internal_ && tree != this) {
- window_manager_internal_->WmClientJankinessChanged(
- tree->id(), tree->janky());
- }
-}
-
-void WindowTree::ProcessWindowBoundsChanged(
- const ServerWindow* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- bool originated_change,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- ClientWindowId client_window_id;
- if (originated_change || !IsWindowKnown(window, &client_window_id))
- return;
- client()->OnWindowBoundsChanged(ClientWindowIdToTransportId(client_window_id),
- old_bounds, new_bounds, local_surface_id);
-}
-
-void WindowTree::ProcessWindowTransformChanged(
- const ServerWindow* window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform,
- bool originated_change) {
- ClientWindowId client_window_id;
- if (originated_change || !IsWindowKnown(window, &client_window_id))
- return;
- client()->OnWindowTransformChanged(
- ClientWindowIdToTransportId(client_window_id), old_transform,
- new_transform);
-}
-
-void WindowTree::ProcessClientAreaChanged(
- const ServerWindow* window,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas,
- bool originated_change) {
- ClientWindowId client_window_id;
- if (originated_change || !IsWindowKnown(window, &client_window_id))
- return;
- client()->OnClientAreaChanged(
- ClientWindowIdToTransportId(client_window_id), new_client_area,
- std::vector<gfx::Rect>(new_additional_client_areas));
-}
-
-void WindowTree::ProcessWillChangeWindowHierarchy(
- const ServerWindow* window,
- const ServerWindow* new_parent,
- const ServerWindow* old_parent,
- bool originated_change) {
- if (originated_change)
- return;
-
- const bool old_drawn = window->IsDrawn();
- const bool new_drawn =
- window->visible() && new_parent && new_parent->IsDrawn();
- if (old_drawn == new_drawn)
- return;
-
- NotifyDrawnStateChanged(window, new_drawn);
-}
-
-void WindowTree::ProcessWindowPropertyChanged(
- const ServerWindow* window,
- const std::string& name,
- const std::vector<uint8_t>* new_data,
- bool originated_change) {
- if (originated_change)
- return;
-
- ClientWindowId client_window_id;
- if (!IsWindowKnown(window, &client_window_id))
- return;
-
- base::Optional<std::vector<uint8_t>> data;
- if (new_data)
- data.emplace(*new_data);
-
- client()->OnWindowSharedPropertyChanged(
- ClientWindowIdToTransportId(client_window_id), name, data);
-}
-
-void WindowTree::ProcessWindowHierarchyChanged(const ServerWindow* window,
- const ServerWindow* new_parent,
- const ServerWindow* old_parent,
- bool originated_change) {
- const bool knows_new = new_parent && IsWindowKnown(new_parent);
- if (originated_change || (window_server_->current_operation_type() ==
- OperationType::DELETE_WINDOW) ||
- (window_server_->current_operation_type() == OperationType::EMBED) ||
- window_server_->DidTreeMessageClient(id_)) {
- return;
- }
-
- if (!access_policy_->ShouldNotifyOnHierarchyChange(window, &new_parent,
- &old_parent)) {
- return;
- }
- // Inform the client of any new windows and update the set of windows we know
- // about.
- std::vector<const ServerWindow*> to_send;
- if (!IsWindowKnown(window))
- GetUnknownWindowsFrom(window, &to_send, nullptr);
- const bool knows_old = old_parent && IsWindowKnown(old_parent);
- if (!knows_old && !knows_new)
- return;
-
- const Id new_parent_client_window_id =
- knows_new ? TransportIdForWindow(new_parent) : kInvalidTransportId;
- const Id old_parent_client_window_id =
- knows_old ? TransportIdForWindow(old_parent) : kInvalidTransportId;
- const Id client_window_id =
- window ? TransportIdForWindow(window) : kInvalidTransportId;
- client()->OnWindowHierarchyChanged(
- client_window_id, old_parent_client_window_id,
- new_parent_client_window_id, WindowsToWindowDatas(to_send));
- window_server_->OnTreeMessagedClient(id_);
-}
-
-void WindowTree::ProcessWindowReorder(const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction,
- bool originated_change) {
- DCHECK_EQ(window->parent(), relative_window->parent());
- ClientWindowId client_window_id, relative_client_window_id;
- if (originated_change || !IsWindowKnown(window, &client_window_id) ||
- !IsWindowKnown(relative_window, &relative_client_window_id) ||
- window_server_->DidTreeMessageClient(id_))
- return;
-
- // Do not notify ordering changes of the root windows, since the client
- // doesn't know about the ancestors of the roots, and so can't do anything
- // about this ordering change of the root.
- if (HasRoot(window) || HasRoot(relative_window))
- return;
-
- client()->OnWindowReordered(
- ClientWindowIdToTransportId(client_window_id),
- ClientWindowIdToTransportId(relative_client_window_id), direction);
- window_server_->OnTreeMessagedClient(id_);
-}
-
-void WindowTree::ProcessWindowDeleted(ServerWindow* window,
- bool originated_change) {
- created_windows_.erase(window);
-
- ClientWindowId client_window_id;
- if (!IsWindowKnown(window, &client_window_id))
- return;
-
- if (HasRoot(window))
- RemoveRoot(window, RemoveRootReason::DELETED);
- else
- RemoveFromMaps(window);
-
- if (originated_change)
- return;
-
- client()->OnWindowDeleted(ClientWindowIdToTransportId(client_window_id));
- window_server_->OnTreeMessagedClient(id_);
-}
-
-void WindowTree::ProcessWillChangeWindowVisibility(const ServerWindow* window,
- bool originated_change) {
- if (originated_change)
- return;
-
- ClientWindowId client_window_id;
- if (IsWindowKnown(window, &client_window_id)) {
- client()->OnWindowVisibilityChanged(
- ClientWindowIdToTransportId(client_window_id), !window->visible());
- return;
- }
-
- bool window_target_drawn_state;
- if (window->visible()) {
- // Window is being hidden, won't be drawn.
- window_target_drawn_state = false;
- } else {
- // Window is being shown. Window will be drawn if its parent is drawn.
- window_target_drawn_state = window->parent() && window->parent()->IsDrawn();
- }
-
- NotifyDrawnStateChanged(window, window_target_drawn_state);
-}
-
-void WindowTree::ProcessWindowOpacityChanged(const ServerWindow* window,
- float old_opacity,
- float new_opacity,
- bool originated_change) {
- if (originated_change)
- return;
-
- ClientWindowId client_window_id;
- if (IsWindowKnown(window, &client_window_id)) {
- client()->OnWindowOpacityChanged(
- ClientWindowIdToTransportId(client_window_id), old_opacity,
- new_opacity);
- }
-}
-
-void WindowTree::ProcessCursorChanged(const ServerWindow* window,
- const ui::CursorData& cursor,
- bool originated_change) {
- if (originated_change)
- return;
- ClientWindowId client_window_id;
- if (!IsWindowKnown(window, &client_window_id))
- return;
-
- client()->OnWindowCursorChanged(ClientWindowIdToTransportId(client_window_id),
- cursor);
-}
-
-void WindowTree::ProcessFocusChanged(const ServerWindow* old_focused_window,
- const ServerWindow* new_focused_window) {
- if (window_server_->current_operation_type() == OperationType::SET_FOCUS &&
- window_server_->IsOperationSource(id_)) {
- return;
- }
- const ServerWindow* window =
- new_focused_window
- ? access_policy_->GetWindowForFocusChange(new_focused_window)
- : nullptr;
- ClientWindowId client_window_id;
- // If the window isn't known we'll supply null, which is ok.
- IsWindowKnown(window, &client_window_id);
- client()->OnWindowFocused(ClientWindowIdToTransportId(client_window_id));
-}
-
-void WindowTree::ProcessTransientWindowAdded(
- const ServerWindow* window,
- const ServerWindow* transient_window,
- bool originated_change) {
- if (originated_change)
- return;
-
- ClientWindowId client_window_id, transient_client_window_id;
- if (!IsWindowKnown(window, &client_window_id) ||
- !IsWindowKnown(transient_window, &transient_client_window_id)) {
- return;
- }
- client()->OnTransientWindowAdded(
- ClientWindowIdToTransportId(client_window_id),
- ClientWindowIdToTransportId(transient_client_window_id));
-}
-
-void WindowTree::ProcessTransientWindowRemoved(
- const ServerWindow* window,
- const ServerWindow* transient_window,
- bool originated_change) {
- if (originated_change)
- return;
- ClientWindowId client_window_id, transient_client_window_id;
- if (!IsWindowKnown(window, &client_window_id) ||
- !IsWindowKnown(transient_window, &transient_client_window_id)) {
- return;
- }
- client()->OnTransientWindowRemoved(
- ClientWindowIdToTransportId(client_window_id),
- ClientWindowIdToTransportId(transient_client_window_id));
-}
-
-void WindowTree::ProcessWindowSurfaceChanged(
- ServerWindow* window,
- const viz::SurfaceInfo& surface_info) {
- ClientWindowId client_window_id;
- if (!IsWindowKnown(window, &client_window_id))
- return;
- client()->OnWindowSurfaceChanged(
- ClientWindowIdToTransportId(client_window_id), surface_info);
-}
-
-void WindowTree::SendToPointerWatcher(const ui::Event& event,
- ServerWindow* target_window,
- int64_t display_id) {
- if (!EventMatchesPointerWatcher(event))
- return;
-
- ClientWindowId client_window_id;
- // Ignore the return value from IsWindowKnown() as in the case of the client
- // not knowing the window we'll send 0, which corresponds to no window.
- IsWindowKnown(target_window, &client_window_id);
- client()->OnPointerEventObserved(
- ui::Event::Clone(event), ClientWindowIdToTransportId(client_window_id),
- display_id);
-}
-
-Id WindowTree::ClientWindowIdToTransportId(
- const ClientWindowId& client_window_id) const {
- if (client_window_id.client_id() == id_)
- return client_window_id.sink_id();
- const Id client_id = client_window_id.client_id();
- return (client_id << 32) | client_window_id.sink_id();
-}
-
-bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const {
- if (window_manager_state_)
- return false; // We are the window manager, don't route to ourself.
-
- // If the client created this window, then do not route it through the WM.
- if (window->owning_tree_id() == id_)
- return false;
-
- // If the client did not create the window, then it must be the root of the
- // client. If not, that means the client should not know about this window,
- // and so do not route the request to the WM.
- if (roots_.count(window) == 0)
- return false;
-
- return IsWindowCreatedByWindowManager(window);
-}
-
-void WindowTree::ProcessCaptureChanged(const ServerWindow* new_capture,
- const ServerWindow* old_capture,
- bool originated_change) {
- ClientWindowId new_capture_window_client_id;
- ClientWindowId old_capture_window_client_id;
- const bool new_capture_window_known =
- IsWindowKnown(new_capture, &new_capture_window_client_id);
- const bool old_capture_window_known =
- IsWindowKnown(old_capture, &old_capture_window_client_id);
- if (!new_capture_window_known && !old_capture_window_known)
- return;
-
- if (originated_change && ((window_server_->current_operation_type() ==
- OperationType::RELEASE_CAPTURE) ||
- (window_server_->current_operation_type() ==
- OperationType::SET_CAPTURE))) {
- return;
- }
-
- client()->OnCaptureChanged(
- ClientWindowIdToTransportId(new_capture_window_client_id),
- ClientWindowIdToTransportId(old_capture_window_client_id));
-}
-
-Id WindowTree::TransportIdForWindow(const ServerWindow* window) const {
- auto iter = window_to_client_id_map_.find(window);
- DCHECK(iter != window_to_client_id_map_.end());
- return ClientWindowIdToTransportId(iter->second);
-}
-
-bool WindowTree::IsValidIdForNewWindow(const ClientWindowId& id) const {
- // Reserve 0 (ClientWindowId() and sink_id) to indicate a null window.
- return client_id_to_window_map_.count(id) == 0u &&
- access_policy_->IsValidIdForNewWindow(id) && id != ClientWindowId() &&
- id.sink_id() != 0;
-}
-
-bool WindowTree::CanReorderWindow(const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction) const {
- if (!window) {
- DVLOG(1) << "CanReorderWindow failed (invalid window)";
- return false;
- }
- if (!relative_window) {
- DVLOG(1) << "CanReorderWindow failed (invalid relative window)";
- return false;
- }
-
- if (!window->parent()) {
- DVLOG(1) << "CanReorderWindow failed (no parent)";
- return false;
- }
-
- if (window->parent() != relative_window->parent()) {
- DVLOG(1) << "CanReorderWindow failed (parents differ)";
- return false;
- }
-
- if (!access_policy_->CanReorderWindow(window, relative_window, direction)) {
- DVLOG(1) << "CanReorderWindow failed (access policy denied)";
- return false;
- }
-
- const ServerWindow::Windows& children = window->parent()->children();
- const size_t child_i =
- std::find(children.begin(), children.end(), window) - children.begin();
- const size_t target_i =
- std::find(children.begin(), children.end(), relative_window) -
- children.begin();
- if ((direction == mojom::OrderDirection::ABOVE && child_i == target_i + 1) ||
- (direction == mojom::OrderDirection::BELOW && child_i + 1 == target_i)) {
- DVLOG(1) << "CanReorderWindow failed (already in position)";
- return false;
- }
-
- return true;
-}
-
-bool WindowTree::RemoveWindowFromParent(
- const ClientWindowId& client_window_id) {
- ServerWindow* window = GetWindowByClientId(client_window_id);
- DVLOG(3) << "removing window from parent client=" << id_
- << " client window_id= " << client_window_id
- << " global window_id=" << DebugWindowId(window);
- if (!window) {
- DVLOG(1) << "RemoveWindowFromParent failed (invalid window id="
- << client_window_id.ToString() << ")";
- return false;
- }
- if (!window->parent()) {
- DVLOG(1) << "RemoveWindowFromParent failed (no parent id="
- << client_window_id.ToString() << ")";
- return false;
- }
- if (!access_policy_->CanRemoveWindowFromParent(window)) {
- DVLOG(1) << "RemoveWindowFromParent failed (access policy disallowed id="
- << client_window_id.ToString() << ")";
- return false;
- }
- Operation op(this, window_server_, OperationType::REMOVE_WINDOW_FROM_PARENT);
- window->parent()->Remove(window);
- return true;
-}
-
-bool WindowTree::DeleteWindowImpl(WindowTree* source, ServerWindow* window) {
- DCHECK(window);
- DCHECK_EQ(window->owning_tree_id(), id_);
- Operation op(source, window_server_, OperationType::DELETE_WINDOW);
- delete window;
- return true;
-}
-
-void WindowTree::GetUnknownWindowsFrom(
- const ServerWindow* window,
- std::vector<const ServerWindow*>* windows,
- const ClientWindowId* id_for_window) {
- if (!access_policy_->CanGetWindowTree(window))
- return;
-
- // This function is called in the context of a hierarchy change when the
- // parent wasn't known. We need to tell the client about the window so that
- // it can set the parent correctly.
- if (windows)
- windows->push_back(window);
- if (IsWindowKnown(window))
- return;
-
- const ClientWindowId client_window_id =
- id_for_window ? *id_for_window : window->frame_sink_id();
- AddToMaps(window, client_window_id);
- if (!access_policy_->CanDescendIntoWindowForWindowTree(window))
- return;
- const ServerWindow::Windows& children = window->children();
- for (ServerWindow* child : children)
- GetUnknownWindowsFrom(child, windows, nullptr);
-}
-
-void WindowTree::AddToMaps(const ServerWindow* window,
- const ClientWindowId& client_window_id) {
- DCHECK_EQ(0u, client_id_to_window_map_.count(client_window_id));
- client_id_to_window_map_[client_window_id] = window;
- window_to_client_id_map_[window] = client_window_id;
-}
-
-void WindowTree::AddRootForToken(const base::UnguessableToken& token,
- ServerWindow* window,
- const ClientWindowId& client_window_id) {
- roots_.insert(window);
- Display* display = GetDisplay(window);
- int64_t display_id = display ? display->GetId() : display::kInvalidDisplayId;
- // Caller should have verified there is no window already registered for
- // |client_window_id|.
- DCHECK(!GetWindowByClientId(client_window_id));
- GetUnknownWindowsFrom(window, nullptr, &client_window_id);
- client()->OnEmbedFromToken(token, WindowToWindowData(window), display_id,
- window->current_local_surface_id());
-}
-
-bool WindowTree::RemoveFromMaps(const ServerWindow* window) {
- auto iter = window_to_client_id_map_.find(window);
- if (iter == window_to_client_id_map_.end())
- return false;
-
- client_id_to_window_map_.erase(iter->second);
- window_to_client_id_map_.erase(iter);
- return true;
-}
-
-void WindowTree::RemoveFromKnown(const ServerWindow* window,
- std::vector<ServerWindow*>* created_windows) {
- // TODO(sky): const_cast here is a bit ick.
- if (created_windows_.count(const_cast<ServerWindow*>(window))) {
- if (created_windows)
- created_windows->push_back(const_cast<ServerWindow*>(window));
- return;
- }
-
- RemoveFromMaps(window);
-
- for (ServerWindow* child : window->children())
- RemoveFromKnown(child, created_windows);
-}
-
-void WindowTree::RemoveRoot(ServerWindow* window, RemoveRootReason reason) {
- DCHECK(roots_.count(window) > 0);
- roots_.erase(window);
-
- if (window->owning_tree_id() == id_) {
- // This client created the window. If this client is the window manager and
- // display roots are manually created, then |window| is a display root and
- // needs be cleaned.
- if (window_manager_state_ && !automatically_create_display_roots_) {
- // The window manager is asking to delete the root it created.
- window_manager_state_->DeleteWindowManagerDisplayRoot(window->parent());
- DeleteWindowImpl(this, window);
- }
- return;
- }
-
- const Id client_window_id = TransportIdForWindow(window);
-
- if (reason == RemoveRootReason::EMBED) {
- client()->OnUnembed(client_window_id);
- client()->OnWindowDeleted(client_window_id);
- window_server_->OnTreeMessagedClient(id_);
- }
-
- // This client no longer knows about |window|. Unparent any windows created
- // by this client that were parented to descendants of |window|.
- std::vector<ServerWindow*> created_windows;
- RemoveFromKnown(window, &created_windows);
- for (ServerWindow* created_window : created_windows)
- created_window->parent()->Remove(created_window);
-
- if (reason == RemoveRootReason::UNEMBED) {
- // Notify the owner of the window it no longer has a client embedded in it.
- // Owner is null in the case of the windowmanager unembedding itself from
- // a root.
- WindowTree* owning_tree =
- window_server_->GetTreeWithId(window->owning_tree_id());
- if (owning_tree) {
- DCHECK(owning_tree && owning_tree != this);
- owning_tree->client()->OnEmbeddedAppDisconnected(
- owning_tree->TransportIdForWindow(window));
- }
-
- window->OnEmbeddedAppDisconnected();
- }
-}
-
-std::vector<mojom::WindowDataPtr> WindowTree::WindowsToWindowDatas(
- const std::vector<const ServerWindow*>& windows) {
- std::vector<mojom::WindowDataPtr> array(windows.size());
- for (size_t i = 0; i < windows.size(); ++i)
- array[i] = WindowToWindowData(windows[i]);
- return array;
-}
-
-mojom::WindowDataPtr WindowTree::WindowToWindowData(
- const ServerWindow* window) {
- DCHECK(IsWindowKnown(window));
- const ServerWindow* parent = window->parent();
- const ServerWindow* transient_parent = window->transient_parent();
- // If the parent or transient parent isn't known, it means it is not visible
- // to the client and should not be sent over.
- if (!IsWindowKnown(parent))
- parent = nullptr;
- if (!IsWindowKnown(transient_parent))
- transient_parent = nullptr;
- mojom::WindowDataPtr window_data(mojom::WindowData::New());
- window_data->parent_id =
- parent ? TransportIdForWindow(parent) : kInvalidTransportId;
- window_data->window_id =
- window ? TransportIdForWindow(window) : kInvalidTransportId;
- window_data->transient_parent_id =
- transient_parent ? TransportIdForWindow(transient_parent)
- : kInvalidTransportId;
- window_data->bounds = window->bounds();
- window_data->properties = mojo::MapToFlatMap(window->properties());
- window_data->visible = window->visible();
- return window_data;
-}
-
-void WindowTree::GetWindowTreeImpl(
- const ServerWindow* window,
- std::vector<const ServerWindow*>* windows) const {
- DCHECK(window);
-
- if (!access_policy_->CanGetWindowTree(window))
- return;
-
- windows->push_back(window);
-
- if (!access_policy_->CanDescendIntoWindowForWindowTree(window))
- return;
-
- const ServerWindow::Windows& children = window->children();
- for (ServerWindow* child : children)
- GetWindowTreeImpl(child, windows);
-}
-
-void WindowTree::NotifyDrawnStateChanged(const ServerWindow* window,
- bool new_drawn_value) {
- // Even though we don't know about window, it may be an ancestor of our root,
- // in which case the change may effect our roots drawn state.
- if (roots_.empty())
- return;
-
- for (auto* root : roots_) {
- if (window->Contains(root) && (new_drawn_value != root->IsDrawn())) {
- client()->OnWindowParentDrawnStateChanged(TransportIdForWindow(root),
- new_drawn_value);
- }
- }
-}
-
-void WindowTree::DestroyWindows() {
- if (created_windows_.empty())
- return;
-
- Operation op(this, window_server_, OperationType::DELETE_WINDOW);
- // If we get here from the destructor we're not going to get
- // ProcessWindowDeleted(). Copy the map and delete from the copy so that we
- // don't have to worry about whether |created_windows_| changes or not.
- std::set<ServerWindow*> created_windows_copy;
- created_windows_.swap(created_windows_copy);
- // A sibling can be a transient parent of another window so we detach windows
- // from their transient parents to avoid double deletes.
- for (ServerWindow* window : created_windows_copy) {
- ServerWindow* transient_parent = window->transient_parent();
- if (transient_parent)
- transient_parent->RemoveTransientWindow(window);
- }
-
- for (ServerWindow* window : created_windows_copy)
- delete window;
-}
-
-bool WindowTree::CanEmbed(const ClientWindowId& window_id) const {
- const ServerWindow* window = GetWindowByClientId(window_id);
- return window && access_policy_->CanEmbed(window);
-}
-
-void WindowTree::PrepareForEmbed(ServerWindow* window) {
- DCHECK(window);
-
- // Only allow a node to be the root for one client.
- WindowTree* existing_owner = window_server_->GetTreeWithRoot(window);
-
- Operation op(this, window_server_, OperationType::EMBED);
- RemoveChildrenAsPartOfEmbed(window);
- if (existing_owner) {
- // Never message the originating client.
- window_server_->OnTreeMessagedClient(id_);
- existing_owner->RemoveRoot(window, RemoveRootReason::EMBED);
- }
-}
-
-void WindowTree::RemoveChildrenAsPartOfEmbed(ServerWindow* window) {
- CHECK(window);
- while (!window->children().empty())
- window->Remove(window->children().front());
-}
-
-uint32_t WindowTree::GenerateEventAckId() {
- DCHECK(!event_ack_id_);
- // We do not want to create a sequential id for each event, because that can
- // leak some information to the client. So instead, manufacture the id
- // randomly.
- event_ack_id_ = 0x1000000 | (rand() & 0xffffff);
- return event_ack_id_;
-}
-
-void WindowTree::DispatchEventImpl(ServerWindow* target,
- const ui::Event& event,
- const EventLocation& event_location,
- DispatchEventCallback callback) {
- // DispatchEventImpl() is called so often that log level 4 is used.
- DVLOG(4) << "DispatchEventImpl client=" << id_;
- GenerateEventAckId();
- event_ack_callback_ = std::move(callback);
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target);
- DCHECK(display_root);
- event_source_wms_ = display_root->window_manager_state();
- // Should only get events from windows attached to a host.
- DCHECK(event_source_wms_);
- bool matched_pointer_watcher = EventMatchesPointerWatcher(event);
-
- // Pass the root window of the display supplying the event. This is necessary
- // for Ash to determine the event position in the unified desktop mode, where
- // each physical display mirrors part of a single virtual display.
- Display* display = window_server_->display_manager()->GetDisplayById(
- event_location.display_id);
- WindowManagerDisplayRoot* event_display_root = nullptr;
- if (display && window_manager_state_) {
- event_display_root = display->window_manager_display_root();
- }
- ServerWindow* display_root_window =
- event_display_root ? event_display_root->GetClientVisibleRoot() : nullptr;
-
- client()->OnWindowInputEvent(
- event_ack_id_, TransportIdForWindow(target), event_location.display_id,
- display_root_window ? TransportIdForWindow(display_root_window) : Id(),
- event_location.raw_location, ui::Event::Clone(event),
- matched_pointer_watcher);
-}
-
-bool WindowTree::EventMatchesPointerWatcher(const ui::Event& event) const {
- if (!has_pointer_watcher_)
- return false;
- if (!event.IsPointerEvent())
- return false;
- if (pointer_watcher_want_moves_ && event.type() == ui::ET_POINTER_MOVED)
- return true;
- return event.type() == ui::ET_POINTER_DOWN ||
- event.type() == ui::ET_POINTER_UP ||
- event.type() == ui::ET_POINTER_WHEEL_CHANGED;
-}
-
-ClientWindowId WindowTree::MakeClientWindowId(Id transport_window_id) const {
- // If the client didn't specify the id portion of the window_id use the id of
- // the client.
- if (!ClientIdFromTransportId(transport_window_id))
- return ClientWindowId(id_, transport_window_id);
- return ClientWindowId(ClientIdFromTransportId(transport_window_id),
- ClientWindowIdFromTransportId(transport_window_id));
-}
-
-mojom::WindowTreeClientPtr
-WindowTree::GetAndRemoveScheduledEmbedWindowTreeClient(
- const base::UnguessableToken& token) {
- auto iter = scheduled_embeds_.find(token);
- if (iter != scheduled_embeds_.end()) {
- mojom::WindowTreeClientPtr client = std::move(iter->second);
- scheduled_embeds_.erase(iter);
- return client;
- }
-
- // There are no clients above the window manager.
- if (window_manager_internal_)
- return nullptr;
-
- // Use the root to find the client that embedded this. For non-window manager
- // connections there should be only one root (a WindowTreeClient can only be
- // embedded once). During shutdown there may be no roots.
- if (roots_.size() != 1)
- return nullptr;
- const ServerWindow* root = *roots_.begin();
- WindowTree* owning_tree =
- window_server_->GetTreeWithId(root->owning_tree_id());
- if (!owning_tree)
- return nullptr;
- DCHECK_NE(this, owning_tree);
- return owning_tree->GetAndRemoveScheduledEmbedWindowTreeClient(token);
-}
-
-void WindowTree::NewWindow(
- uint32_t change_id,
- Id transport_window_id,
- const base::Optional<base::flat_map<std::string, std::vector<uint8_t>>>&
- transport_properties) {
- std::map<std::string, std::vector<uint8_t>> properties;
- if (transport_properties.has_value())
- properties = mojo::FlatMapToMap(transport_properties.value());
-
- client()->OnChangeCompleted(
- change_id,
- NewWindow(MakeClientWindowId(transport_window_id), properties));
-}
-
-void WindowTree::NewTopLevelWindow(
- uint32_t change_id,
- Id transport_window_id,
- const base::flat_map<std::string, std::vector<uint8_t>>&
- transport_properties) {
- // TODO(sky): rather than DCHECK, have this kill connection.
- DCHECK(!window_manager_internal_); // Not valid for the windowmanager.
- DCHECK(!waiting_for_top_level_window_info_);
- const ClientWindowId client_window_id =
- MakeClientWindowId(transport_window_id);
- // TODO(sky): need a way for client to provide context to figure out display.
- Display* display = display_manager()->displays().empty()
- ? nullptr
- : *(display_manager()->displays().begin());
- // TODO(sky): move checks to accesspolicy.
- WindowManagerDisplayRoot* display_root =
- display && !is_for_embedding_ ? display->window_manager_display_root()
- : nullptr;
- if (!display_root ||
- display_root->window_manager_state()->window_tree() == this ||
- !IsValidIdForNewWindow(client_window_id)) {
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- // The server creates the real window. Any further messages from the client
- // may try to alter the window. Pause incoming messages so that we know we
- // can't get a message for a window before the window is created. Once the
- // window is created we'll resume processing.
- binding_->SetIncomingMethodCallProcessingPaused(true);
-
- const uint32_t wm_change_id =
- window_server_->GenerateWindowManagerChangeId(this, change_id);
-
- waiting_for_top_level_window_info_.reset(
- new WaitingForTopLevelWindowInfo(client_window_id, wm_change_id));
-
- display_root->window_manager_state()
- ->window_tree()
- ->window_manager_internal_->WmCreateTopLevelWindow(
- wm_change_id, client_window_id, transport_properties);
-}
-
-void WindowTree::DeleteWindow(uint32_t change_id, Id transport_window_id) {
- client()->OnChangeCompleted(
- change_id, DeleteWindow(MakeClientWindowId(transport_window_id)));
-}
-
-void WindowTree::AddWindow(uint32_t change_id, Id parent_id, Id child_id) {
- client()->OnChangeCompleted(
- change_id,
- AddWindow(MakeClientWindowId(parent_id), MakeClientWindowId(child_id)));
-}
-
-void WindowTree::RemoveWindowFromParent(uint32_t change_id, Id window_id) {
- client()->OnChangeCompleted(
- change_id, RemoveWindowFromParent(MakeClientWindowId(window_id)));
-}
-
-void WindowTree::AddTransientWindow(uint32_t change_id,
- Id window,
- Id transient_window) {
- client()->OnChangeCompleted(
- change_id, AddTransientWindow(MakeClientWindowId(window),
- MakeClientWindowId(transient_window)));
-}
-
-void WindowTree::RemoveTransientWindowFromParent(uint32_t change_id,
- Id transient_window_id) {
- bool success = false;
- ServerWindow* transient_window =
- GetWindowByClientId(MakeClientWindowId(transient_window_id));
- if (transient_window && transient_window->transient_parent() &&
- access_policy_->CanRemoveTransientWindowFromParent(transient_window)) {
- success = true;
- Operation op(this, window_server_,
- OperationType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT);
- transient_window->transient_parent()->RemoveTransientWindow(
- transient_window);
- }
- client()->OnChangeCompleted(change_id, success);
-}
-
-void WindowTree::SetModalType(uint32_t change_id,
- Id window_id,
- ModalType modal_type) {
- client()->OnChangeCompleted(
- change_id, SetModalType(MakeClientWindowId(window_id), modal_type));
-}
-
-void WindowTree::SetChildModalParent(uint32_t change_id,
- Id window_id,
- Id parent_window_id) {
- client()->OnChangeCompleted(
- change_id, SetChildModalParent(MakeClientWindowId(window_id),
- MakeClientWindowId(parent_window_id)));
-}
-
-void WindowTree::ReorderWindow(uint32_t change_id,
- Id window_id,
- Id relative_window_id,
- mojom::OrderDirection direction) {
- // TODO(erg): This implementation allows reordering two windows that are
- // children of a parent window which the two implementations can't see. There
- // should be a security check to prevent this.
- bool success = false;
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- ServerWindow* relative_window =
- GetWindowByClientId(MakeClientWindowId(relative_window_id));
- DVLOG(3) << "reorder client=" << id_ << " client window_id=" << window_id
- << " global window_id=" << DebugWindowId(window)
- << " relative client window_id=" << relative_window_id
- << " relative global window_id=" << DebugWindowId(relative_window);
- if (CanReorderWindow(window, relative_window, direction)) {
- success = true;
- Operation op(this, window_server_, OperationType::REORDER_WINDOW);
- window->Reorder(relative_window, direction);
- window_server_->ProcessWindowReorder(window, relative_window, direction);
- }
- client()->OnChangeCompleted(change_id, success);
-}
-
-void WindowTree::GetWindowTree(Id window_id, GetWindowTreeCallback callback) {
- std::vector<const ServerWindow*> windows(
- GetWindowTree(MakeClientWindowId(window_id)));
- std::move(callback).Run(WindowsToWindowDatas(windows));
-}
-
-void WindowTree::SetCapture(uint32_t change_id, Id window_id) {
- client()->OnChangeCompleted(change_id,
- SetCapture(MakeClientWindowId(window_id)));
-}
-
-void WindowTree::ReleaseCapture(uint32_t change_id, Id window_id) {
- client()->OnChangeCompleted(change_id,
- ReleaseCapture(MakeClientWindowId(window_id)));
-}
-
-void WindowTree::StartPointerWatcher(bool want_moves) {
- has_pointer_watcher_ = true;
- pointer_watcher_want_moves_ = want_moves;
-}
-
-void WindowTree::StopPointerWatcher() {
- has_pointer_watcher_ = false;
- pointer_watcher_want_moves_ = false;
-}
-
-void WindowTree::SetWindowBounds(
- uint32_t change_id,
- Id window_id,
- const gfx::Rect& bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- if (window && ShouldRouteToWindowManager(window)) {
- DVLOG(3) << "Redirecting request to change bounds for "
- << DebugWindowId(window) << " to window manager...";
- const uint32_t wm_change_id =
- window_server_->GenerateWindowManagerChangeId(this, change_id);
- // |window_id| may be a client id, use the id from the window to ensure
- // the windowmanager doesn't get an id it doesn't know about.
- WindowManagerDisplayRoot* display_root =
- GetWindowManagerDisplayRoot(window);
- WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
- wm_tree->window_manager_internal_->WmSetBounds(
- wm_change_id, wm_tree->TransportIdForWindow(window), std::move(bounds));
- return;
- }
-
- DVLOG(3) << "SetWindowBounds window_id=" << window_id
- << " global window_id=" << DebugWindowId(window)
- << " bounds=" << bounds.ToString() << " local_surface_id="
- << (local_surface_id ? local_surface_id->ToString() : "null");
-
- if (!window) {
- DVLOG(1) << "SetWindowBounds failed (invalid window id)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- // Only the owner of the window can change the bounds.
- bool success = access_policy_->CanSetWindowBounds(window);
- if (success) {
- Operation op(this, window_server_, OperationType::SET_WINDOW_BOUNDS);
- window->SetBounds(bounds, local_surface_id);
- } else {
- DVLOG(1) << "SetWindowBounds failed (access denied)";
- }
- client()->OnChangeCompleted(change_id, success);
-}
-
-void WindowTree::SetWindowTransform(uint32_t change_id,
- Id window_id,
- const gfx::Transform& transform) {
- // Clients shouldn't have a need to set the transform of the embed root, so
- // we don't bother routing it to the window-manager.
-
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- DVLOG(3) << "SetWindowTransform client window_id=" << window_id
- << " global window_id=" << DebugWindowId(window)
- << " transform=" << transform.ToString();
-
- if (!window) {
- DVLOG(1) << "SetWindowTransform failed (invalid window id)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- // Only the owner of the window can change the bounds.
- const bool success = access_policy_->CanSetWindowTransform(window);
- if (success) {
- Operation op(this, window_server_, OperationType::SET_WINDOW_TRANSFORM);
- window->SetTransform(transform);
- } else {
- DVLOG(1) << "SetWindowTransform failed (access denied)";
- }
- client()->OnChangeCompleted(change_id, success);
-}
-
-void WindowTree::SetWindowVisibility(uint32_t change_id,
- Id transport_window_id,
- bool visible) {
- client()->OnChangeCompleted(
- change_id,
- SetWindowVisibility(MakeClientWindowId(transport_window_id), visible));
-}
-
-void WindowTree::SetWindowProperty(
- uint32_t change_id,
- Id transport_window_id,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& value) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- if (window && ShouldRouteToWindowManager(window)) {
- const uint32_t wm_change_id =
- window_server_->GenerateWindowManagerChangeId(this, change_id);
- WindowManagerDisplayRoot* display_root =
- GetWindowManagerDisplayRoot(window);
- WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
- wm_tree->window_manager_internal_->WmSetProperty(
- wm_change_id, wm_tree->TransportIdForWindow(window), name, value);
- return;
- }
- const bool success = window && access_policy_->CanSetWindowProperties(window);
- if (success) {
- Operation op(this, window_server_, OperationType::SET_WINDOW_PROPERTY);
- if (!value.has_value()) {
- window->SetProperty(name, nullptr);
- } else {
- window->SetProperty(name, &value.value());
- }
- }
- client()->OnChangeCompleted(change_id, success);
-}
-
-void WindowTree::SetWindowOpacity(uint32_t change_id,
- Id window_id,
- float opacity) {
- client()->OnChangeCompleted(
- change_id, SetWindowOpacity(MakeClientWindowId(window_id), opacity));
-}
-
-void WindowTree::AttachCompositorFrameSink(
- Id transport_window_id,
- viz::mojom::CompositorFrameSinkRequest compositor_frame_sink,
- viz::mojom::CompositorFrameSinkClientPtr client) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- if (!window) {
- DVLOG(1) << "AttachCompositorFrameSink failed (invalid window id)";
- return;
- }
-
- const bool success = access_policy_->CanSetWindowCompositorFrameSink(window);
- if (!success) {
- DVLOG(1) << "AttachCompositorFrameSink failed (access denied)";
- return;
- }
- window->CreateCompositorFrameSink(std::move(compositor_frame_sink),
- std::move(client));
-}
-
-void WindowTree::SetWindowTextInputState(Id transport_window_id,
- ui::mojom::TextInputStatePtr state) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- bool success = window && access_policy_->CanSetWindowTextInputState(window);
- if (success)
- window->SetTextInputState(state.To<ui::TextInputState>());
-}
-
-void WindowTree::SetImeVisibility(Id transport_window_id,
- bool visible,
- ui::mojom::TextInputStatePtr state) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- bool success = window && access_policy_->CanSetWindowTextInputState(window);
- if (success) {
- if (!state.is_null())
- window->SetTextInputState(state.To<ui::TextInputState>());
-
- Display* display = GetDisplay(window);
- if (display)
- display->SetImeVisibility(window, visible);
- }
-}
-
-void WindowTree::OnWindowInputEventAck(uint32_t event_id,
- mojom::EventResult result) {
- // DispatchEventImpl() is called so often that log level 4 is used.
- DVLOG(4) << "OnWindowInputEventAck client=" << id_;
- if (event_ack_id_ == 0 || event_id != event_ack_id_ || !event_ack_callback_) {
- // TODO(sad): Something bad happened. Kill the client?
- NOTIMPLEMENTED() << ": Wrong event acked. event_id=" << event_id
- << ", event_ack_id_=" << event_ack_id_;
- DVLOG(1) << "OnWindowInputEventAck supplied unexpected event_id";
- return;
- }
-
- event_ack_id_ = 0;
-
- if (janky_)
- event_source_wms_->window_tree()->ClientJankinessChanged(this);
-
- event_source_wms_ = nullptr;
- base::ResetAndReturn(&event_ack_callback_).Run(result);
-
- if (!event_queue_.empty()) {
- DCHECK(!event_ack_id_);
- ServerWindow* target = nullptr;
- std::unique_ptr<ui::Event> event;
- DispatchEventCallback callback;
- EventLocation event_location;
- do {
- std::unique_ptr<TargetedEvent> targeted_event =
- std::move(event_queue_.front());
- event_queue_.pop();
- target = targeted_event->target();
- event = targeted_event->TakeEvent();
- event_location = targeted_event->event_location();
- callback = targeted_event->TakeCallback();
- } while (!event_queue_.empty() && !GetDisplay(target));
- if (GetDisplay(target)) {
- DispatchEventImpl(target, *event, event_location, std::move(callback));
- } else {
- // If the window is no longer valid (or not in a display), then there is
- // no point in dispatching to the client, but we need to run the callback
- // so that WindowManagerState isn't still waiting for an ack. We only
- // need run the last callback as they should all target the same
- // WindowManagerState and WindowManagerState is at most waiting on one
- // ack.
- std::move(callback).Run(mojom::EventResult::UNHANDLED);
- }
- }
-}
-
-void WindowTree::SetClientArea(Id transport_window_id,
- const gfx::Insets& insets,
- const base::Optional<std::vector<gfx::Rect>>&
- transport_additional_client_areas) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- DVLOG(3) << "SetClientArea client window_id=" << transport_window_id
- << " global window_id=" << DebugWindowId(window)
- << " insets=" << insets.top() << " " << insets.left() << " "
- << insets.bottom() << " " << insets.right();
- if (!window) {
- DVLOG(1) << "SetClientArea failed (invalid window id)";
- return;
- }
- if (!access_policy_->CanSetClientArea(window)) {
- DVLOG(1) << "SetClientArea failed (access denied)";
- return;
- }
-
- Operation op(this, window_server_, OperationType::SET_CLIENT_AREA);
- window->SetClientArea(insets, transport_additional_client_areas.value_or(
- std::vector<gfx::Rect>()));
-}
-
-void WindowTree::SetHitTestMask(Id transport_window_id,
- const base::Optional<gfx::Rect>& mask) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- if (!window) {
- DVLOG(1) << "SetHitTestMask failed (invalid window id)";
- return;
- }
-
- if (!access_policy_->CanSetHitTestMask(window)) {
- DVLOG(1) << "SetHitTestMask failed (access denied)";
- return;
- }
-
- if (mask)
- window->SetHitTestMask(*mask);
- else
- window->ClearHitTestMask();
-}
-
-void WindowTree::SetCanAcceptDrops(Id window_id, bool accepts_drops) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- if (!window) {
- DVLOG(1) << "SetCanAcceptDrops failed (invalid window id)";
- return;
- }
-
- if (!access_policy_->CanSetAcceptDrops(window)) {
- DVLOG(1) << "SetAcceptsDrops failed (access denied)";
- return;
- }
-
- window->SetCanAcceptDrops(accepts_drops);
-}
-
-void WindowTree::Embed(Id transport_window_id,
- mojom::WindowTreeClientPtr client,
- uint32_t flags,
- EmbedCallback callback) {
- std::move(callback).Run(
- Embed(MakeClientWindowId(transport_window_id), std::move(client), flags));
-}
-
-void WindowTree::ScheduleEmbed(mojom::WindowTreeClientPtr client,
- ScheduleEmbedCallback callback) {
- const base::UnguessableToken token = base::UnguessableToken::Create();
- scheduled_embeds_[token] = std::move(client);
- std::move(callback).Run(token);
-}
-
-void WindowTree::EmbedUsingToken(Id transport_window_id,
- const base::UnguessableToken& token,
- uint32_t flags,
- EmbedUsingTokenCallback callback) {
- mojom::WindowTreeClientPtr client =
- GetAndRemoveScheduledEmbedWindowTreeClient(token);
- if (client) {
- Embed(transport_window_id, std::move(client), flags, std::move(callback));
- return;
- }
-
- WindowTreeAndWindowId tree_and_id =
- window_server()->UnregisterEmbedToken(token);
- if (!tree_and_id.tree) {
- DVLOG(1) << "EmbedUsingToken failed, no ScheduleEmbed(), token="
- << token.ToString();
- std::move(callback).Run(false);
- return;
- }
- if (tree_and_id.tree == this) {
- DVLOG(1) << "EmbedUsingToken failed, attempt to embed self, token="
- << token.ToString();
- std::move(callback).Run(false);
- return;
- }
- std::move(callback).Run(EmbedExistingTree(
- MakeClientWindowId(transport_window_id), tree_and_id, token));
-}
-
-void WindowTree::ScheduleEmbedForExistingClient(
- uint32_t window_id,
- ScheduleEmbedForExistingClientCallback callback) {
- std::move(callback).Run(window_server()->RegisterEmbedToken(this, window_id));
-}
-
-void WindowTree::SetFocus(uint32_t change_id, Id transport_window_id) {
- client()->OnChangeCompleted(
- change_id, SetFocus(MakeClientWindowId(transport_window_id)));
-}
-
-void WindowTree::SetCanFocus(Id transport_window_id, bool can_focus) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- if (!window) {
- DVLOG(1) << "SetCanFocus failed (invalid window id)";
- return;
- }
-
- if (ShouldRouteToWindowManager(window)) {
- WindowManagerDisplayRoot* display_root =
- GetWindowManagerDisplayRoot(window);
- WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
- wm_tree->window_manager_internal_->WmSetCanFocus(transport_window_id,
- can_focus);
- } else if (access_policy_->CanSetFocus(window)) {
- window->set_can_focus(can_focus);
- } else {
- DVLOG(1) << "SetCanFocus failed (access denied)";
- }
-}
-
-void WindowTree::SetEventTargetingPolicy(Id transport_window_id,
- mojom::EventTargetingPolicy policy) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- // TODO(riajiang): check |event_queue_| is empty for |window|.
- if (window && access_policy_->CanSetEventTargetingPolicy(window))
- window->set_event_targeting_policy(policy);
-}
-
-void WindowTree::SetCursor(uint32_t change_id,
- Id transport_window_id,
- ui::CursorData cursor) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- if (!window) {
- DVLOG(1) << "SetCursor failed (invalid id)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- // Only the owner of the window can change the bounds.
- bool success = access_policy_->CanSetCursorProperties(window);
- if (!success) {
- DVLOG(1) << "SetCursor failed (access denied)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- // If the cursor is custom, it must have valid frames.
- if (cursor.cursor_type() == ui::CursorType::kCustom) {
- if (cursor.cursor_frames().empty()) {
- DVLOG(1) << "SetCursor failed (no frames with custom cursor)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- for (const SkBitmap& bitmap : cursor.cursor_frames()) {
- if (bitmap.drawsNothing()) {
- DVLOG(1) << "SetCursor failed (cursor frame draws nothing)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
- }
- }
-
- Operation op(this, window_server_,
- OperationType::SET_WINDOW_PREDEFINED_CURSOR);
- window->SetCursor(std::move(cursor));
- client()->OnChangeCompleted(change_id, success);
-}
-
-void WindowTree::DeactivateWindow(Id window_id) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- if (!window) {
- DVLOG(1) << "DeactivateWindow failed (invalid id)";
- return;
- }
-
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root) {
- // The window isn't parented. There's nothing to do.
- DVLOG(1) << "DeactivateWindow failed (window unparented)";
- return;
- }
-
- WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
- wm_tree->window_manager_internal_->WmDeactivateWindow(
- wm_tree->TransportIdForWindow(window));
-}
-
-void WindowTree::StackAbove(uint32_t change_id, Id above_id, Id below_id) {
- ServerWindow* above = GetWindowByClientId(MakeClientWindowId(above_id));
- if (!above) {
- DVLOG(1) << "StackAbove failed (invalid above id)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- ServerWindow* below = GetWindowByClientId(MakeClientWindowId(below_id));
- if (!below) {
- DVLOG(1) << "StackAbove failed (invalid below id)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- if (!access_policy_->CanStackAbove(above, below)) {
- DVLOG(1) << "StackAbove failed (access denied)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- ServerWindow* parent = above->parent();
- ServerWindow* below_parent = below->parent();
- if (!parent) {
- DVLOG(1) << "StackAbove failed (above unparented)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
- if (!below_parent) {
- DVLOG(1) << "StackAbove failed (below unparented)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
- if (parent != below_parent) {
- DVLOG(1) << "StackAbove failed (windows have different parents)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(above);
- if (!display_root) {
- DVLOG(1) << "StackAbove (no display root)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- // Window reordering assumes that it is the owner of parent who is sending
- // the message, and does not deal gracefully with other clients reordering
- // their windows. So tell the window manager to send us a reorder message.
- WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
- const uint32_t wm_change_id =
- window_server_->GenerateWindowManagerChangeId(this, change_id);
- wm_tree->window_manager_internal_->WmStackAbove(
- wm_change_id, wm_tree->TransportIdForWindow(above),
- wm_tree->TransportIdForWindow(below));
-}
-
-void WindowTree::StackAtTop(uint32_t change_id, Id window_id) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- if (!window) {
- DVLOG(1) << "StackAtTop failed (invalid id)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- if (!access_policy_->CanStackAtTop(window)) {
- DVLOG(1) << "StackAtTop failed (access denied)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- ServerWindow* parent = window->parent();
- if (!parent) {
- DVLOG(1) << "StackAtTop failed (window unparented)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- DCHECK(!parent->children().empty());
- if (parent->children().back() == window) {
- // Ignore this call; the client didn't know they were already at the top.
- DVLOG(3) << "StackAtTop ignored (already at top)";
- client()->OnChangeCompleted(change_id, true);
- return;
- }
-
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root) {
- DVLOG(1) << "StackAtTop (no display root)";
- client()->OnChangeCompleted(change_id, false);
- return;
- }
-
- // Window reordering assumes that it is the owner of parent who is sending
- // the message, and does not deal gracefully with other clients reordering
- // their windows. So tell the window manager to send us a reorder message.
- WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
- const uint32_t wm_change_id =
- window_server_->GenerateWindowManagerChangeId(this, change_id);
- wm_tree->window_manager_internal_->WmStackAtTop(
- wm_change_id, wm_tree->TransportIdForWindow(window));
-}
-
-void WindowTree::PerformWmAction(Id window_id, const std::string& action) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- if (!window) {
- DVLOG(1) << "PerformWmAction(" << action << ") failed (invalid id)";
- return;
- }
-
- if (!access_policy_->CanPerformWmAction(window)) {
- DVLOG(1) << "PerformWmAction(" << action << ") failed (access denied)";
- return;
- }
-
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root) {
- DVLOG(1) << "PerformWmAction(" << action << ") failed (no display root)";
- return;
- }
-
- WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
- wm_tree->window_manager_internal_->WmPerformWmAction(
- wm_tree->TransportIdForWindow(window), action);
-}
-
-void WindowTree::GetWindowManagerClient(
- mojo::AssociatedInterfaceRequest<mojom::WindowManagerClient> internal) {
- if (!access_policy_->CanSetWindowManager() || !window_manager_internal_ ||
- window_manager_internal_client_binding_) {
- return;
- }
- window_manager_internal_client_binding_.reset(
- new mojo::AssociatedBinding<mojom::WindowManagerClient>(
- this, std::move(internal)));
-}
-
-void WindowTree::GetCursorLocationMemory(
- GetCursorLocationMemoryCallback callback) {
- std::move(callback).Run(
- display_manager()->cursor_location_manager()->GetCursorLocationMemory());
-}
-
-void WindowTree::PerformDragDrop(
- uint32_t change_id,
- Id source_window_id,
- const gfx::Point& screen_location,
- const base::flat_map<std::string, std::vector<uint8_t>>& drag_data,
- const gfx::ImageSkia& drag_image,
- const gfx::Vector2d& drag_image_offset,
- uint32_t drag_operation,
- ui::mojom::PointerKind source) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(source_window_id));
- bool success = window && access_policy_->CanInitiateDragLoop(window);
- if (!success || !ShouldRouteToWindowManager(window)) {
- // We need to fail this move loop change, otherwise the client will just be
- // waiting for |change_id|.
- DVLOG(1) << "PerformDragDrop failed (access denied)";
- client()->OnPerformDragDropCompleted(change_id, false,
- mojom::kDropEffectNone);
- return;
- }
-
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root) {
- // The window isn't parented. There's nothing to do.
- DVLOG(1) << "PerformDragDrop failed (window unparented)";
- client()->OnPerformDragDropCompleted(change_id, false,
- mojom::kDropEffectNone);
- return;
- }
-
- if (window_server_->in_move_loop() || window_server_->in_drag_loop()) {
- // Either the window manager is servicing a window drag or we're servicing
- // a drag and drop operation. We can't start a second drag.
- DVLOG(1) << "PerformDragDrop failed (already performing a drag)";
- client()->OnPerformDragDropCompleted(change_id, false,
- mojom::kDropEffectNone);
- return;
- }
-
- WindowManagerState* wms = display_root->window_manager_state();
-
- // Send the drag representation to the window manager.
- wms->window_tree()->window_manager_internal_->WmBuildDragImage(
- screen_location, drag_image, drag_image_offset, source);
-
- // Here, we need to dramatically change how the mouse pointer works. Once
- // we've started a drag drop operation, cursor events don't go to windows as
- // normal.
- window_server_->StartDragLoop(change_id, window, this);
- wms->SetDragDropSourceWindow(this, window, this, drag_data, drag_operation);
-}
-
-void WindowTree::CancelDragDrop(Id window_id) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- if (!window) {
- DVLOG(1) << "CancelDragDrop failed (no window)";
- return;
- }
-
- if (window != window_server_->GetCurrentDragLoopWindow()) {
- DVLOG(1) << "CancelDragDrop failed (not the drag loop window)";
- return;
- }
-
- if (window_server_->GetCurrentDragLoopInitiator() != this) {
- DVLOG(1) << "CancelDragDrop failed (not the drag initiator)";
- return;
- }
-
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root) {
- DVLOG(1) << "CancelDragDrop failed (no such window manager display root)";
- return;
- }
-
- WindowManagerState* wms = display_root->window_manager_state();
- wms->CancelDragDrop();
-}
-
-void WindowTree::PerformWindowMove(uint32_t change_id,
- Id window_id,
- ui::mojom::MoveLoopSource source,
- const gfx::Point& cursor) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- bool success = window && access_policy_->CanInitiateMoveLoop(window);
- if (!success || !ShouldRouteToWindowManager(window)) {
- // We need to fail this move loop change, otherwise the client will just be
- // waiting for |change_id|.
- DVLOG(1) << "PerformWindowMove failed (access denied)";
- OnChangeCompleted(change_id, false);
- return;
- }
-
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root) {
- // The window isn't parented. There's nothing to do.
- DVLOG(1) << "PerformWindowMove failed (window unparented)";
- OnChangeCompleted(change_id, false);
- return;
- }
-
- if (window_server_->in_move_loop() || window_server_->in_drag_loop()) {
- // Either the window manager is servicing a window drag or we're servicing
- // a drag and drop operation. We can't start a second drag.
- DVLOG(1) << "PerformWindowMove failed (already performing a drag)";
- OnChangeCompleted(change_id, false);
- return;
- }
-
- // When we perform a window move loop, we give the window manager non client
- // capture. Because of how the capture public interface currently works,
- // SetCapture() will check whether the mouse cursor is currently in the
- // non-client area and if so, will redirect messages to the window
- // manager. (And normal window movement relies on this behaviour.)
- WindowManagerState* wms = display_root->window_manager_state();
- wms->SetCapture(window, wms->window_tree()->id());
-
- const uint32_t wm_change_id =
- window_server_->GenerateWindowManagerChangeId(this, change_id);
- window_server_->StartMoveLoop(wm_change_id, window, this, window->bounds());
- wms->window_tree()->window_manager_internal_->WmPerformMoveLoop(
- wm_change_id, wms->window_tree()->TransportIdForWindow(window), source,
- cursor);
-}
-
-void WindowTree::CancelWindowMove(Id window_id) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- if (!window) {
- DVLOG(1) << "CancelWindowMove failed (invalid window id)";
- return;
- }
-
- bool success = access_policy_->CanInitiateMoveLoop(window);
- if (!success) {
- DVLOG(1) << "CancelWindowMove failed (access denied)";
- return;
- }
-
- if (window != window_server_->GetCurrentMoveLoopWindow()) {
- DVLOG(1) << "CancelWindowMove failed (not the move loop window)";
- return;
- }
-
- if (window_server_->GetCurrentMoveLoopInitiator() != this) {
- DVLOG(1) << "CancelWindowMove failed (not the move loop initiator)";
- return;
- }
-
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root) {
- DVLOG(1) << "CancelWindowMove failed (no such window manager display root)";
- return;
- }
-
- WindowManagerState* wms = display_root->window_manager_state();
- wms->window_tree()->window_manager_internal_->WmCancelMoveLoop(
- window_server_->GetCurrentMoveLoopChangeId());
-}
-
-void WindowTree::AddAccelerators(
- std::vector<mojom::WmAcceleratorPtr> accelerators,
- AddAcceleratorsCallback callback) {
- DCHECK(window_manager_state_);
-
- bool success = true;
- for (auto iter = accelerators.begin(); iter != accelerators.end(); ++iter) {
- if (!window_manager_state_->event_processor()->AddAccelerator(
- iter->get()->id, std::move(iter->get()->event_matcher)))
- success = false;
- }
- std::move(callback).Run(success);
-}
-
-void WindowTree::RemoveAccelerator(uint32_t id) {
- window_manager_state_->event_processor()->RemoveAccelerator(id);
-}
-
-void WindowTree::AddActivationParent(Id transport_window_id) {
- AddActivationParent(MakeClientWindowId(transport_window_id));
-}
-
-void WindowTree::RemoveActivationParent(Id transport_window_id) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- if (!window) {
- DVLOG(1) << "RemoveActivationParent failed (invalid window id)";
- return;
- }
- window->set_is_activation_parent(false);
-}
-
-void WindowTree::SetExtendedHitRegionForChildren(
- Id window_id,
- const gfx::Insets& mouse_insets,
- const gfx::Insets& touch_insets) {
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- // Extended hit test region should only be set by the owner of the window.
- if (!window) {
- DVLOG(1) << "SetExtendedHitRegionForChildren failed (invalid window id)";
- return;
- }
- if (window->owning_tree_id() != id_) {
- DVLOG(1) << "SetExtendedHitRegionForChildren failed (supplied window that "
- << "client does not own)";
- return;
- }
- if (HasPositiveInset(mouse_insets) || HasPositiveInset(touch_insets)) {
- DVLOG(1) << "SetExtendedHitRegionForChildren failed (insets must be "
- << "negative)";
- return;
- }
- window->set_extended_hit_test_regions_for_children(mouse_insets,
- touch_insets);
-}
-
-void WindowTree::SetKeyEventsThatDontHideCursor(
- std::vector<::ui::mojom::EventMatcherPtr> dont_hide_cursor_list) {
- DCHECK(window_manager_state_);
- window_manager_state_->SetKeyEventsThatDontHideCursor(
- std::move(dont_hide_cursor_list));
-}
-
-void WindowTree::SetDisplayRoot(const display::Display& display,
- mojom::WmViewportMetricsPtr viewport_metrics,
- bool is_primary_display,
- Id window_id,
- const std::vector<display::Display>& mirrors,
- SetDisplayRootCallback callback) {
- ServerWindow* display_root = ProcessSetDisplayRoot(
- display, TransportMetricsToDisplayMetrics(*viewport_metrics),
- is_primary_display, MakeClientWindowId(window_id), mirrors);
- if (!display_root) {
- std::move(callback).Run(false);
- return;
- }
- display_root->parent()->SetVisible(true);
- std::move(callback).Run(true);
-}
-
-void WindowTree::SetDisplayConfiguration(
- const std::vector<display::Display>& displays,
- std::vector<ui::mojom::WmViewportMetricsPtr> transport_metrics,
- int64_t primary_display_id,
- int64_t internal_display_id,
- const std::vector<display::Display>& mirrors,
- SetDisplayConfigurationCallback callback) {
- std::vector<display::ViewportMetrics> metrics;
- for (auto& transport_ptr : transport_metrics)
- metrics.push_back(TransportMetricsToDisplayMetrics(*transport_ptr));
- std::move(callback).Run(display_manager()->SetDisplayConfiguration(
- displays, metrics, primary_display_id, internal_display_id, mirrors));
-}
-
-void WindowTree::SwapDisplayRoots(int64_t display_id1,
- int64_t display_id2,
- SwapDisplayRootsCallback callback) {
- DCHECK(window_manager_state_); // Only applicable to the window manager.
- std::move(callback).Run(ProcessSwapDisplayRoots(display_id1, display_id2));
-}
-
-void WindowTree::SetBlockingContainers(
- std::vector<::ui::mojom::BlockingContainersPtr> blocking_containers,
- SetBlockingContainersCallback callback) {
- DCHECK(window_manager_state_); // Only applicable to the window manager.
- std::move(callback).Run(
- ProcessSetBlockingContainers(std::move(blocking_containers)));
-}
-
-void WindowTree::WmResponse(uint32_t change_id, bool response) {
- if (window_server_->in_move_loop() &&
- window_server_->GetCurrentMoveLoopChangeId() == change_id) {
- ServerWindow* window = window_server_->GetCurrentMoveLoopWindow();
-
- if (window->owning_tree_id() != id_) {
- window_server_->WindowManagerSentBogusMessage();
- window = nullptr;
- } else {
- WindowManagerDisplayRoot* display_root =
- GetWindowManagerDisplayRoot(window);
- if (display_root) {
- WindowManagerState* wms = display_root->window_manager_state();
- // Clear the implicit capture.
- wms->SetCapture(nullptr, false);
- }
- }
-
- if (!response && window) {
- // Our move loop didn't succeed, which means that we must restore the
- // original bounds of the window.
- window->SetBounds(window_server_->GetCurrentMoveLoopRevertBounds(),
- base::nullopt);
- }
-
- window_server_->EndMoveLoop();
- }
-
- window_server_->WindowManagerChangeCompleted(change_id, response);
-}
-
-void WindowTree::WmSetBoundsResponse(uint32_t change_id) {
- // The window manager will always give a response of false to the client
- // because it will always update the bounds of the top level window itself
- // which will overwrite the request made by the client.
- WmResponse(change_id, false);
-}
-
-void WindowTree::WmRequestClose(Id transport_window_id) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- WindowTree* tree = window_server_->GetTreeWithRoot(window);
- if (tree && tree != this) {
- tree->client()->RequestClose(tree->TransportIdForWindow(window));
- }
- // TODO(sky): think about what else case means.
-}
-
-void WindowTree::WmSetFrameDecorationValues(
- mojom::FrameDecorationValuesPtr values) {
- DCHECK(window_manager_state_);
- window_manager_state_->SetFrameDecorationValues(std::move(values));
-}
-
-void WindowTree::WmSetNonClientCursor(Id window_id, ui::CursorData cursor) {
- DCHECK(window_manager_state_);
- ServerWindow* window = GetWindowByClientId(MakeClientWindowId(window_id));
- if (!window) {
- DVLOG(1) << "WmSetNonClientCursor failed (invalid window id)";
- return;
- }
-
- window->SetNonClientCursor(std::move(cursor));
-}
-
-void WindowTree::WmLockCursor() {
- DCHECK(window_manager_state_);
- window_manager_state_->cursor_state().LockCursor();
-}
-
-void WindowTree::WmUnlockCursor() {
- DCHECK(window_manager_state_);
- window_manager_state_->cursor_state().UnlockCursor();
-}
-
-void WindowTree::WmSetCursorVisible(bool visible) {
- DCHECK(window_manager_state_);
- window_manager_state_->cursor_state().SetCursorVisible(visible);
-}
-
-void WindowTree::WmSetCursorSize(ui::CursorSize cursor_size) {
- DCHECK(window_manager_state_);
- window_manager_state_->cursor_state().SetCursorSize(cursor_size);
-}
-
-void WindowTree::WmSetGlobalOverrideCursor(
- base::Optional<ui::CursorData> cursor) {
- DCHECK(window_manager_state_);
- window_manager_state_->cursor_state().SetGlobalOverrideCursor(cursor);
-}
-
-void WindowTree::WmMoveCursorToDisplayLocation(const gfx::Point& display_pixels,
- int64_t display_id) {
- DCHECK(window_manager_state_);
- window_manager_state_->SetCursorLocation(display_pixels, display_id);
-}
-
-void WindowTree::WmConfineCursorToBounds(const gfx::Rect& bounds_in_pixels,
- int64_t display_id) {
- DCHECK(window_manager_state_);
- Display* display = display_manager()->GetDisplayById(display_id);
- if (!display) {
- DVLOG(1) << "WmConfineCursorToBounds failed (invalid display id)";
- return;
- }
-
- PlatformDisplay* platform_display = display->platform_display();
- if (!platform_display) {
- DVLOG(1) << "WmConfineCursorToBounds failed (no platform display)";
- return;
- }
-
- platform_display->ConfineCursorToBounds(bounds_in_pixels);
-}
-
-void WindowTree::WmSetCursorTouchVisible(bool enabled) {
- DCHECK(window_manager_state_);
- window_manager_state_->SetCursorTouchVisible(enabled);
-}
-
-void WindowTree::OnWmCreatedTopLevelWindow(uint32_t change_id,
- Id transport_window_id) {
- ServerWindow* window =
- GetWindowByClientId(MakeClientWindowId(transport_window_id));
- if (window && window->owning_tree_id() != id_) {
- DVLOG(1) << "OnWmCreatedTopLevelWindow failed (invalid window id)";
- window_server_->WindowManagerSentBogusMessage();
- window = nullptr;
- }
- window_server_->WindowManagerCreatedTopLevelWindow(this, change_id, window);
-}
-
-void WindowTree::OnAcceleratorAck(uint32_t event_id,
- mojom::EventResult result,
- const EventProperties& properties) {
- DVLOG(3) << "OnAcceleratorAck client=" << id_;
- if (event_ack_id_ == 0 || event_id != event_ack_id_ ||
- !accelerator_ack_callback_) {
- DVLOG(1) << "OnAcceleratorAck failed (invalid event id)";
- window_server_->WindowManagerSentBogusMessage();
- return;
- }
- event_ack_id_ = 0;
- DCHECK(window_manager_state_);
- base::ResetAndReturn(&accelerator_ack_callback_).Run(result, properties);
-}
-
-bool WindowTree::HasRootForAccessPolicy(const ServerWindow* window) const {
- return HasRoot(window);
-}
-
-bool WindowTree::IsWindowKnownForAccessPolicy(
- const ServerWindow* window) const {
- return IsWindowKnown(window);
-}
-
-bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy(
- const ServerWindow* window) const {
- WindowTree* tree = window_server_->GetTreeWithRoot(window);
- return tree && tree != this;
-}
-
-bool WindowTree::IsWindowCreatedByWindowManager(
- const ServerWindow* window) const {
- // The WindowManager is attached to the root of the Display, if there isn't a
- // WindowManager attached, the window manager didn't create this window.
- const WindowManagerDisplayRoot* display_root =
- GetWindowManagerDisplayRoot(window);
- if (!display_root)
- return false;
-
- return display_root->window_manager_state()->window_tree()->id() ==
- window->owning_tree_id();
-}
-
-bool WindowTree::ShouldInterceptEventsForAccessPolicy(
- const ServerWindow* window) const {
- if (is_for_embedding_)
- return false;
-
- while (window) {
- // Find the first window created by this client. If there is an embedding,
- // it'll be here.
- if (window->owning_tree_id() == id_) {
- // embedded_tree->embedder_intercepts_events() indicates Embed() was
- // called with kEmbedFlagEmbedderInterceptsEvents. In this case the
- // embedder needs to see the window so that it knows the event is
- // targetted at it.
- WindowTree* embedded_tree = window_server_->GetTreeWithRoot(window);
- if (embedded_tree && embedded_tree->embedder_intercepts_events())
- return true;
- return false;
- }
- window = window->parent();
- }
- return false;
-}
-
-void WindowTree::OnDragMoved(const gfx::Point& location) {
- DCHECK(window_server_->in_drag_loop());
- DCHECK_EQ(this, window_server_->GetCurrentDragLoopInitiator());
-
- ServerWindow* window = window_server_->GetCurrentDragLoopWindow();
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root)
- return;
-
- if (drag_move_state_) {
- drag_move_state_->has_queued_drag_window_move = true;
- drag_move_state_->queued_cursor_location = location;
- } else {
- WindowManagerState* wms = display_root->window_manager_state();
- drag_move_state_ = std::make_unique<DragMoveState>();
- wms->window_tree()->window_manager_internal_->WmMoveDragImage(
- location, base::Bind(&WindowTree::OnWmMoveDragImageAck,
- drag_weak_factory_.GetWeakPtr()));
- }
-}
-
-void WindowTree::OnDragCompleted(bool success, uint32_t action_taken) {
- DCHECK(window_server_->in_drag_loop());
-
- if (window_server_->GetCurrentDragLoopInitiator() != this)
- return;
-
- uint32_t change_id = window_server_->GetCurrentDragLoopChangeId();
- ServerWindow* window = window_server_->GetCurrentDragLoopWindow();
- WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
- if (!display_root)
- return;
-
- window_server_->EndDragLoop();
- WindowManagerState* wms = display_root->window_manager_state();
- wms->EndDragDrop();
- wms->window_tree()->window_manager_internal_->WmDestroyDragImage();
- drag_weak_factory_.InvalidateWeakPtrs();
-
- client()->OnPerformDragDropCompleted(change_id, success, action_taken);
-}
-
-DragTargetConnection* WindowTree::GetDragTargetForWindow(
- const ServerWindow* window) {
- if (!window)
- return nullptr;
- DragTargetConnection* connection = window_server_->GetTreeWithRoot(window);
- if (connection)
- return connection;
- return window_server_->GetTreeWithId(window->owning_tree_id());
-}
-
-void WindowTree::PerformOnDragDropStart(
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data) {
- client()->OnDragDropStart(mime_data);
-}
-
-void WindowTree::PerformOnDragEnter(
- const ServerWindow* window,
- uint32_t event_flags,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) {
- ClientWindowId client_window_id;
- if (!IsWindowKnown(window, &client_window_id)) {
- NOTREACHED();
- callback.Run(0);
- return;
- }
- client()->OnDragEnter(ClientWindowIdToTransportId(client_window_id),
- event_flags, cursor_offset, effect_bitmask, callback);
-}
-
-void WindowTree::PerformOnDragOver(
- const ServerWindow* window,
- uint32_t event_flags,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) {
- ClientWindowId client_window_id;
- if (!IsWindowKnown(window, &client_window_id)) {
- NOTREACHED();
- callback.Run(0);
- return;
- }
- client()->OnDragOver(ClientWindowIdToTransportId(client_window_id),
- event_flags, cursor_offset, effect_bitmask, callback);
-}
-
-void WindowTree::PerformOnDragLeave(const ServerWindow* window) {
- ClientWindowId client_window_id;
- if (!IsWindowKnown(window, &client_window_id)) {
- NOTREACHED();
- return;
- }
- client()->OnDragLeave(ClientWindowIdToTransportId(client_window_id));
-}
-
-void WindowTree::PerformOnCompleteDrop(
- const ServerWindow* window,
- uint32_t event_flags,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) {
- ClientWindowId client_window_id;
- if (!IsWindowKnown(window, &client_window_id)) {
- NOTREACHED();
- callback.Run(0);
- return;
- }
- client()->OnCompleteDrop(ClientWindowIdToTransportId(client_window_id),
- event_flags, cursor_offset, effect_bitmask,
- callback);
-}
-
-void WindowTree::PerformOnDragDropDone() {
- client()->OnDragDropDone();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_tree.h b/services/ui/ws/window_tree.h
deleted file mode 100644
index ae920d3..0000000
--- a/services/ui/ws/window_tree.h
+++ /dev/null
@@ -1,765 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_TREE_H_
-#define SERVICES_UI_WS_WINDOW_TREE_H_
-
-#include <stdint.h>
-
-#include <map>
-#include <memory>
-#include <set>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/containers/flat_map.h"
-#include "base/containers/queue.h"
-#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
-#include "mojo/public/cpp/bindings/associated_binding.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/ws/access_policy_delegate.h"
-#include "services/ui/ws/async_event_dispatcher.h"
-#include "services/ui/ws/drag_source.h"
-#include "services/ui/ws/drag_target_connection.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "services/viz/public/interfaces/compositing/surface_id.mojom.h"
-#include "ui/gfx/native_widget_types.h"
-
-namespace display {
-struct ViewportMetrics;
-}
-namespace gfx {
-class Insets;
-class Rect;
-}
-
-namespace ui {
-class Event;
-}
-
-namespace ui {
-namespace ws {
-
-class AccessPolicy;
-class DisplayManager;
-class Display;
-class DragTargetConnection;
-class ServerWindow;
-class TargetedEvent;
-class WindowManagerDisplayRoot;
-class WindowManagerState;
-class WindowServer;
-
-struct EventLocation;
-struct WindowTreeAndWindowId;
-
-namespace test {
-class WindowTreeTestApi;
-}
-
-// WindowTree represents a view onto portions of the window tree. The parts of
-// the tree exposed to the client start at the root windows. A WindowTree may
-// have any number of roots (including none). A WindowTree may not have
-// visibility of all the descendants of its roots.
-//
-// WindowTree notifies its client as changes happen to windows exposed to the
-// the client.
-//
-// See ids.h for details on how WindowTree handles identity of windows.
-class WindowTree : public mojom::WindowTree,
- public AccessPolicyDelegate,
- public mojom::WindowManagerClient,
- public DragSource,
- public DragTargetConnection,
- public AsyncEventDispatcher {
- public:
- WindowTree(WindowServer* window_server,
- bool is_for_embedding,
- ServerWindow* root,
- std::unique_ptr<AccessPolicy> access_policy);
- ~WindowTree() override;
-
- void Init(std::unique_ptr<WindowTreeBinding> binding,
- mojom::WindowTreePtr tree);
-
- // Called if this WindowTree hosts a WindowManager. See mojom for details
- // on |automatically_create_display_roots|.
- void ConfigureWindowManager(bool automatically_create_display_roots);
-
- bool automatically_create_display_roots() const {
- return automatically_create_display_roots_;
- }
-
- void OnAcceleratedWidgetAvailableForDisplay(Display* display);
-
- ClientSpecificId id() const { return id_; }
-
- void set_embedder_intercepts_events() { embedder_intercepts_events_ = true; }
- bool embedder_intercepts_events() const {
- return embedder_intercepts_events_;
- }
-
- void set_can_change_root_window_visibility(bool value) {
- can_change_root_window_visibility_ = value;
- }
-
- bool is_for_embedding() const { return is_for_embedding_; }
-
- mojom::WindowTreeClient* client() { return binding_->client(); }
-
- // Returns the Window with the specified client id *only* if known to this
- // client, returns null if not known.
- ServerWindow* GetWindowByClientId(const ClientWindowId& id) {
- return const_cast<ServerWindow*>(
- const_cast<const WindowTree*>(this)->GetWindowByClientId(id));
- }
- const ServerWindow* GetWindowByClientId(const ClientWindowId& id) const;
-
- bool IsWindowKnown(const ServerWindow* window) const {
- return IsWindowKnown(window, nullptr);
- }
- // Returns whether |window| is known to this tree. If |window| is known and
- // |client_window_id| is non-null |client_window_id| is set to the
- // ClientWindowId of the window.
- bool IsWindowKnown(const ServerWindow* window,
- ClientWindowId* client_window_id) const;
-
- // Returns true if |window| is one of this trees roots.
- bool HasRoot(const ServerWindow* window) const;
-
- std::set<const ServerWindow*> roots() { return roots_; }
-
- void set_name(const std::string& name) { name_ = name; }
- const std::string& name() const { return name_; }
-
- bool janky() const { return janky_; }
-
- const Display* GetDisplay(const ServerWindow* window) const;
- Display* GetDisplay(const ServerWindow* window) {
- return const_cast<Display*>(
- const_cast<const WindowTree*>(this)->GetDisplay(window));
- }
-
- const WindowManagerDisplayRoot* GetWindowManagerDisplayRoot(
- const ServerWindow* window) const;
- WindowManagerDisplayRoot* GetWindowManagerDisplayRoot(
- const ServerWindow* window) {
- return const_cast<WindowManagerDisplayRoot*>(
- const_cast<const WindowTree*>(this)->GetWindowManagerDisplayRoot(
- window));
- }
- WindowManagerState* window_manager_state() {
- return window_manager_state_.get();
- }
-
- DisplayManager* display_manager();
- const DisplayManager* display_manager() const;
-
- WindowServer* window_server() { return window_server_; }
- const WindowServer* window_server() const { return window_server_; }
-
- // Called from ~WindowServer. Reset WindowTreeClient so that it no longer gets
- // any messages.
- void PrepareForWindowServerShutdown();
-
- // Adds a new root to this tree. This is only valid for window managers.
- void AddRootForWindowManager(const ServerWindow* root);
-
- // Invoked when a tree is about to be destroyed.
- void OnWillDestroyTree(WindowTree* tree);
-
- // Sends updated display information.
- void OnWmDisplayModified(const display::Display& display);
-
- // These functions are synchronous variants of those defined in the mojom. The
- // WindowTree implementations all call into these. See the mojom for details.
- bool SetCapture(const ClientWindowId& client_window_id);
- bool ReleaseCapture(const ClientWindowId& client_window_id);
- bool NewWindow(const ClientWindowId& client_window_id,
- const std::map<std::string, std::vector<uint8_t>>& properties);
- bool AddWindow(const ClientWindowId& parent_id,
- const ClientWindowId& child_id);
- bool AddTransientWindow(const ClientWindowId& window_id,
- const ClientWindowId& transient_window_id);
- bool RemoveWindowFromParent(const ClientWindowId& window_id);
- bool DeleteWindow(const ClientWindowId& window_id);
- bool SetModalType(const ClientWindowId& window_id, ModalType modal_type);
- bool SetChildModalParent(const ClientWindowId& window_id,
- const ClientWindowId& modal_parent_window_id);
- std::vector<const ServerWindow*> GetWindowTree(
- const ClientWindowId& window_id) const;
- bool SetWindowVisibility(const ClientWindowId& window_id, bool visible);
- bool SetWindowOpacity(const ClientWindowId& window_id, float opacity);
- bool SetFocus(const ClientWindowId& window_id);
- bool Embed(const ClientWindowId& window_id,
- mojom::WindowTreeClientPtr window_tree_client,
- uint32_t flags);
-
- // Called from EmbedUsingToken() to embed an existing client that previously
- // called ScheduleEmbedForExistingClient(). |tree_and_window_id.tree| is the
- // client that previously called ScheduleEmbedForExistingClient() and
- // |token| is the token returned to the client.
- bool EmbedExistingTree(const ClientWindowId& window_id,
- const WindowTreeAndWindowId& tree_and_window_id,
- const base::UnguessableToken& token);
-
- bool IsWaitingForNewTopLevelWindow(uint32_t wm_change_id);
- viz::FrameSinkId OnWindowManagerCreatedTopLevelWindow(
- uint32_t wm_change_id,
- uint32_t client_change_id,
- const ServerWindow* window);
- void AddActivationParent(const ClientWindowId& window_id);
-
- // Calls through to the client.
- void OnChangeCompleted(uint32_t change_id, bool success);
-
- // If |callback| is valid then an ack is expected from the client. When the
- // ack from the client is received |callback| is Run().
- using AcceleratorCallback = base::OnceCallback<void(
- mojom::EventResult,
- const base::flat_map<std::string, std::vector<uint8_t>>&)>;
- void OnEventOccurredOutsideOfModalWindow(const ServerWindow* modal_window);
-
- // Called when the cursor touch visibility bit changes. This is only called
- // on the WindowTree associated with a WindowManager.
- void OnCursorTouchVisibleChanged(bool enabled);
-
- // Called when a display has been removed. This is only called on the
- // WindowTree associated with a WindowManager.
- void OnDisplayDestroying(int64_t display_id);
-
- // Called when |tree|'s jankiness changes (see janky_ for definition).
- // Notifies the window manager client so it can update UI for the affected
- // window(s).
- void ClientJankinessChanged(WindowTree* tree);
-
- // The following methods are invoked after the corresponding change has been
- // processed. They do the appropriate bookkeeping and update the client as
- // necessary.
- void ProcessWindowBoundsChanged(
- const ServerWindow* window,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- bool originated_change,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id);
- void ProcessWindowTransformChanged(const ServerWindow* window,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform,
- bool originated_change);
- void ProcessClientAreaChanged(
- const ServerWindow* window,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas,
- bool originated_change);
- void ProcessWillChangeWindowHierarchy(const ServerWindow* window,
- const ServerWindow* new_parent,
- const ServerWindow* old_parent,
- bool originated_change);
- void ProcessWindowPropertyChanged(const ServerWindow* window,
- const std::string& name,
- const std::vector<uint8_t>* new_data,
- bool originated_change);
- void ProcessWindowHierarchyChanged(const ServerWindow* window,
- const ServerWindow* new_parent,
- const ServerWindow* old_parent,
- bool originated_change);
- void ProcessWindowReorder(const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction,
- bool originated_change);
- void ProcessWindowDeleted(ServerWindow* window, bool originated_change);
- void ProcessWillChangeWindowVisibility(const ServerWindow* window,
- bool originated_change);
- void ProcessWindowOpacityChanged(const ServerWindow* window,
- float old_opacity,
- float new_opacity,
- bool originated_change);
- void ProcessCursorChanged(const ServerWindow* window,
- const ui::CursorData& cursor,
- bool originated_change);
- void ProcessFocusChanged(const ServerWindow* old_focused_window,
- const ServerWindow* new_focused_window);
- void ProcessCaptureChanged(const ServerWindow* new_capture,
- const ServerWindow* old_capture,
- bool originated_change);
- void ProcessTransientWindowAdded(const ServerWindow* window,
- const ServerWindow* transient_window,
- bool originated_change);
- void ProcessTransientWindowRemoved(const ServerWindow* window,
- const ServerWindow* transient_window,
- bool originated_change);
- void ProcessWindowSurfaceChanged(ServerWindow* window,
- const viz::SurfaceInfo& surface_info);
-
- // Sends this event to the client if it matches an active pointer watcher.
- // |target_window| is the target of the event, and may be null or not known
- // to this tree.
- void SendToPointerWatcher(const ui::Event& event,
- ServerWindow* target_window,
- int64_t display_id);
-
- // Before the ClientWindowId gets sent back to the client, making sure we
- // reset the high 16 bits back to 0 if it's being sent back to the client
- // that created the window.
- Id ClientWindowIdToTransportId(const ClientWindowId& client_window_id) const;
-
- private:
- friend class test::WindowTreeTestApi;
-
- struct WaitingForTopLevelWindowInfo {
- WaitingForTopLevelWindowInfo(const ClientWindowId& client_window_id,
- uint32_t wm_change_id)
- : client_window_id(client_window_id), wm_change_id(wm_change_id) {}
- ~WaitingForTopLevelWindowInfo() {}
-
- // Id supplied from the client.
- ClientWindowId client_window_id;
-
- // Change id we created for the window manager.
- uint32_t wm_change_id;
- };
-
- enum class RemoveRootReason {
- // The window is being removed.
- DELETED,
-
- // Another client is being embedded in the window.
- EMBED,
-
- // The embedded client explicitly asked to be unembedded.
- UNEMBED,
- };
-
- bool ShouldRouteToWindowManager(const ServerWindow* window) const;
-
- Id TransportIdForWindow(const ServerWindow* window) const;
-
- // Returns true if |id| is a valid WindowId for a new window.
- bool IsValidIdForNewWindow(const ClientWindowId& id) const;
-
- // These functions return true if the corresponding mojom function is allowed
- // for this tree.
- bool CanReorderWindow(const ServerWindow* window,
- const ServerWindow* relative_window,
- mojom::OrderDirection direction) const;
-
- // Deletes a window owned by this tree. Returns true on success. |source| is
- // the tree that originated the change.
- bool DeleteWindowImpl(WindowTree* source, ServerWindow* window);
-
- // If |window| is known does nothing. Otherwise adds |window| to |windows| (if
- // non-null) and marks |window| as known and recurses. If |window| is not
- // known it assigned the ClientWindowId |id_for_window|, if |id_for_window|
- // is null, then the FrameSinkId of |window| is used.
- void GetUnknownWindowsFrom(const ServerWindow* window,
- std::vector<const ServerWindow*>* windows,
- const ClientWindowId* id_for_window);
-
- // Called to add |window| as an embed root. This matches a call from the
- // client to ScheduleEmbedForExistingClient(). |client_window_id| is the
- // ClientWindowId to use for |window|.
- void AddRootForToken(const base::UnguessableToken& token,
- ServerWindow* window,
- const ClientWindowId& client_window_id);
-
- void AddToMaps(const ServerWindow* window,
- const ClientWindowId& client_window_id);
-
- // Removes |window| from the appropriate maps. If |window| is known to this
- // client true is returned.
- bool RemoveFromMaps(const ServerWindow* window);
-
- // Removes |window| and all its descendants from the necessary maps. This
- // does not recurse through windows that were created by this tree. All
- // windows created by this tree are added to |created_windows|.
- void RemoveFromKnown(const ServerWindow* window,
- std::vector<ServerWindow*>* created_windows);
-
- // Removes a root from set of roots of this tree. This does not remove
- // the window from the window tree, only from the set of roots.
- void RemoveRoot(ServerWindow* window, RemoveRootReason reason);
-
- // Converts Window(s) to WindowData(s) for transport. This assumes all the
- // windows are valid for the client. The parent of windows the client is not
- // allowed to see are set to NULL (in the returned WindowData(s)).
- std::vector<mojom::WindowDataPtr> WindowsToWindowDatas(
- const std::vector<const ServerWindow*>& windows);
- mojom::WindowDataPtr WindowToWindowData(const ServerWindow* window);
-
- // Implementation of GetWindowTree(). Adds |window| to |windows| and recurses
- // if CanDescendIntoWindowForWindowTree() returns true.
- void GetWindowTreeImpl(const ServerWindow* window,
- std::vector<const ServerWindow*>* windows) const;
-
- // Notify the client if the drawn state of any of the roots changes.
- // |window| is the window that is changing to the drawn state
- // |new_drawn_value|.
- void NotifyDrawnStateChanged(const ServerWindow* window,
- bool new_drawn_value);
-
- // Deletes all Windows we own.
- void DestroyWindows();
-
- bool CanEmbed(const ClientWindowId& window_id) const;
- void PrepareForEmbed(ServerWindow* window);
- void RemoveChildrenAsPartOfEmbed(ServerWindow* window);
-
- // Generates a new event id for an accelerator or event ack, sets it in
- // |event_ack_id_| and returns it.
- uint32_t GenerateEventAckId();
-
- void DispatchEventImpl(ServerWindow* target,
- const ui::Event& event,
- const EventLocation& event_location,
- DispatchEventCallback callback);
-
- // Returns true if the client has a pointer watcher and this event matches.
- bool EventMatchesPointerWatcher(const ui::Event& event) const;
-
- // Calls OnChangeCompleted() on the client.
- void NotifyChangeCompleted(uint32_t change_id,
- mojom::WindowManagerErrorCode error_code);
-
- // Callback for when WmMoveDragImage completes. This sends off the next
- // queued move under the image if the mouse had further moves while we were
- // waiting for the last move to be acknowledged.
- void OnWmMoveDragImageAck();
-
- // Called from SetDisplayRoot(), see mojom for details. Returns the root
- // of the display if successful, otherwise null.
- ServerWindow* ProcessSetDisplayRoot(
- const display::Display& display_to_create,
- const display::ViewportMetrics& transport_viewport_metrics,
- bool is_primary_display,
- const ClientWindowId& client_window_id,
- const std::vector<display::Display>& mirrors);
-
- bool ProcessSwapDisplayRoots(int64_t display_id1, int64_t display_id2);
- bool ProcessSetBlockingContainers(std::vector<mojom::BlockingContainersPtr>
- transport_all_blocking_containers);
-
- // Returns the ClientWindowId from a transport id. Uses id_ as the
- // ClientWindowId::client_id part if it was invalid. This function
- // do a straight mapping, there may not be a window with the returned id.
- ClientWindowId MakeClientWindowId(Id transport_window_id) const;
-
- // Returns the WindowTreeClient previously scheduled for an embed with the
- // given |token| from ScheduleEmbed(). If this client is the result of an
- // Embed() and ScheduleEmbed() was not called on this client, then this
- // recurses to the parent WindowTree. Recursing enables an acestor to call
- // ScheduleEmbed() and the ancestor to communicate the token with the client.
- mojom::WindowTreeClientPtr GetAndRemoveScheduledEmbedWindowTreeClient(
- const base::UnguessableToken& token);
-
- // AsyncEventDispatcher:
- void DispatchEvent(ServerWindow* target,
- const ui::Event& event,
- const EventLocation& event_location,
- DispatchEventCallback callback) override;
- void DispatchAccelerator(uint32_t accelerator_id,
- const ui::Event& event,
- AcceleratorCallback callback) override;
-
- // WindowTree:
- void NewWindow(
- uint32_t change_id,
- Id transport_window_id,
- const base::Optional<base::flat_map<std::string, std::vector<uint8_t>>>&
- transport_properties) override;
- void NewTopLevelWindow(
- uint32_t change_id,
- Id transport_window_id,
- const base::flat_map<std::string, std::vector<uint8_t>>&
- transport_properties) override;
- void DeleteWindow(uint32_t change_id, Id transport_window_id) override;
- void AddWindow(uint32_t change_id, Id parent_id, Id child_id) override;
- void RemoveWindowFromParent(uint32_t change_id, Id window_id) override;
- void AddTransientWindow(uint32_t change_id,
- Id window,
- Id transient_window) override;
- void RemoveTransientWindowFromParent(uint32_t change_id,
- Id transient_window_id) override;
- void SetModalType(uint32_t change_id, Id window_id, ModalType type) override;
- void SetChildModalParent(uint32_t change_id,
- Id window_id,
- Id parent_window_id) override;
- void ReorderWindow(uint32_t change_Id,
- Id window_id,
- Id relative_window_id,
- mojom::OrderDirection direction) override;
- void GetWindowTree(Id window_id, GetWindowTreeCallback callback) override;
- void SetCapture(uint32_t change_id, Id window_id) override;
- void ReleaseCapture(uint32_t change_id, Id window_id) override;
- void StartPointerWatcher(bool want_moves) override;
- void StopPointerWatcher() override;
- void SetWindowBounds(
- uint32_t change_id,
- Id window_id,
- const gfx::Rect& bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override;
- void SetWindowTransform(uint32_t change_id,
- Id window_id,
- const gfx::Transform& transform) override;
- void SetWindowVisibility(uint32_t change_id,
- Id window_id,
- bool visible) override;
- void SetWindowProperty(
- uint32_t change_id,
- Id transport_window_id,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& value) override;
- void SetWindowOpacity(uint32_t change_id,
- Id window_id,
- float opacity) override;
- void AttachCompositorFrameSink(
- Id transport_window_id,
- viz::mojom::CompositorFrameSinkRequest compositor_frame_sink,
- viz::mojom::CompositorFrameSinkClientPtr client) override;
- void Embed(Id transport_window_id,
- mojom::WindowTreeClientPtr client,
- uint32_t flags,
- EmbedCallback callback) override;
- void ScheduleEmbed(mojom::WindowTreeClientPtr client,
- ScheduleEmbedCallback callback) override;
- void EmbedUsingToken(Id transport_window_id,
- const base::UnguessableToken& token,
- uint32_t flags,
- EmbedUsingTokenCallback callback) override;
- void ScheduleEmbedForExistingClient(
- ClientSpecificId window_id,
- ScheduleEmbedForExistingClientCallback callback) override;
- void SetFocus(uint32_t change_id, Id transport_window_id) override;
- void SetCanFocus(Id transport_window_id, bool can_focus) override;
- void SetEventTargetingPolicy(Id transport_window_id,
- mojom::EventTargetingPolicy policy) override;
- void SetCursor(uint32_t change_id,
- Id transport_window_id,
- ui::CursorData cursor) override;
- void SetWindowTextInputState(Id transport_window_id,
- ui::mojom::TextInputStatePtr state) override;
- void SetImeVisibility(Id transport_window_id,
- bool visible,
- ui::mojom::TextInputStatePtr state) override;
- void OnWindowInputEventAck(uint32_t event_id,
- mojom::EventResult result) override;
- void DeactivateWindow(Id window_id) override;
- void SetClientArea(Id transport_window_id,
- const gfx::Insets& insets,
- const base::Optional<std::vector<gfx::Rect>>&
- transport_additional_client_areas) override;
- void SetCanAcceptDrops(Id window_id, bool accepts_drops) override;
- void SetHitTestMask(Id transport_window_id,
- const base::Optional<gfx::Rect>& mask) override;
- void StackAbove(uint32_t change_id, Id above_id, Id below_id) override;
- void StackAtTop(uint32_t change_id, Id window_id) override;
- void PerformWmAction(Id window_id, const std::string& action) override;
- void GetWindowManagerClient(
- mojo::AssociatedInterfaceRequest<mojom::WindowManagerClient> internal)
- override;
- void GetCursorLocationMemory(
- GetCursorLocationMemoryCallback callback) override;
- void PerformDragDrop(
- uint32_t change_id,
- Id source_window_id,
- const gfx::Point& screen_location,
- const base::flat_map<std::string, std::vector<uint8_t>>& drag_data,
- const gfx::ImageSkia& drag_image,
- const gfx::Vector2d& drag_image_offset,
- uint32_t drag_operation,
- ui::mojom::PointerKind source) override;
- void CancelDragDrop(Id window_id) override;
- void PerformWindowMove(uint32_t change_id,
- Id window_id,
- ui::mojom::MoveLoopSource source,
- const gfx::Point& cursor) override;
- void CancelWindowMove(Id window_id) override;
-
- // mojom::WindowManagerClient:
- void AddAccelerators(std::vector<mojom::WmAcceleratorPtr> accelerators,
- AddAcceleratorsCallback callback) override;
- void RemoveAccelerator(uint32_t id) override;
- void AddActivationParent(Id transport_window_id) override;
- void RemoveActivationParent(Id transport_window_id) override;
- void SetExtendedHitRegionForChildren(
- Id window_id,
- const gfx::Insets& mouse_insets,
- const gfx::Insets& touch_insets) override;
- void SetKeyEventsThatDontHideCursor(
- std::vector<::ui::mojom::EventMatcherPtr> dont_hide_cursor_list) override;
- void SetDisplayRoot(const display::Display& display,
- mojom::WmViewportMetricsPtr viewport_metrics,
- bool is_primary_display,
- Id window_id,
- const std::vector<display::Display>& mirrors,
- SetDisplayRootCallback callback) override;
- void SetDisplayConfiguration(
- const std::vector<display::Display>& displays,
- std::vector<ui::mojom::WmViewportMetricsPtr> transport_metrics,
- int64_t primary_display_id,
- int64_t internal_display_id,
- const std::vector<display::Display>& mirrors,
- SetDisplayConfigurationCallback callback) override;
- void SwapDisplayRoots(int64_t display_id1,
- int64_t display_id2,
- SwapDisplayRootsCallback callback) override;
- void SetBlockingContainers(
- std::vector<mojom::BlockingContainersPtr> blocking_containers,
- SetBlockingContainersCallback callback) override;
- void WmResponse(uint32_t change_id, bool response) override;
- void WmSetBoundsResponse(uint32_t change_id) override;
- void WmRequestClose(Id transport_window_id) override;
- void WmSetFrameDecorationValues(
- mojom::FrameDecorationValuesPtr values) override;
- void WmSetNonClientCursor(Id window_id, ui::CursorData cursor) override;
- void WmLockCursor() override;
- void WmUnlockCursor() override;
- void WmSetCursorVisible(bool visible) override;
- void WmSetCursorSize(ui::CursorSize cursor_size) override;
- void WmSetGlobalOverrideCursor(
- base::Optional<ui::CursorData> cursor) override;
- void WmMoveCursorToDisplayLocation(const gfx::Point& display_pixels,
- int64_t display_id) override;
- void WmConfineCursorToBounds(const gfx::Rect& bounds_in_pixles,
- int64_t display_id) override;
- void WmSetCursorTouchVisible(bool enabled) override;
- void OnWmCreatedTopLevelWindow(uint32_t change_id,
- Id transport_window_id) override;
- void OnAcceleratorAck(uint32_t event_id,
- mojom::EventResult result,
- const base::flat_map<std::string, std::vector<uint8_t>>&
- properties) override;
-
- // AccessPolicyDelegate:
- bool HasRootForAccessPolicy(const ServerWindow* window) const override;
- bool IsWindowKnownForAccessPolicy(const ServerWindow* window) const override;
- bool IsWindowRootOfAnotherTreeForAccessPolicy(
- const ServerWindow* window) const override;
- bool IsWindowCreatedByWindowManager(
- const ServerWindow* window) const override;
- bool ShouldInterceptEventsForAccessPolicy(
- const ServerWindow* window) const override;
-
- // DragSource:
- void OnDragMoved(const gfx::Point& location) override;
- void OnDragCompleted(bool success, uint32_t action_taken) override;
- DragTargetConnection* GetDragTargetForWindow(
- const ServerWindow* window) override;
-
- // DragTargetConnection:
- void PerformOnDragDropStart(
- const base::flat_map<std::string, std::vector<uint8_t>>& mime_data)
- override;
- void PerformOnDragEnter(
- const ServerWindow* window,
- uint32_t event_flags,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) override;
- void PerformOnDragOver(
- const ServerWindow* window,
- uint32_t event_flags,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) override;
- void PerformOnDragLeave(const ServerWindow* window) override;
- void PerformOnCompleteDrop(
- const ServerWindow* window,
- uint32_t event_flags,
- const gfx::Point& cursor_offset,
- uint32_t effect_bitmask,
- const base::Callback<void(uint32_t)>& callback) override;
- void PerformOnDragDropDone() override;
-
- WindowServer* window_server_;
-
- // True if this WindowTree was created by way of Embed().
- bool is_for_embedding_;
-
- // Id of this tree as assigned by WindowServer.
- const ClientSpecificId id_;
- std::string name_;
-
- std::unique_ptr<WindowTreeBinding> binding_;
-
- std::unique_ptr<ui::ws::AccessPolicy> access_policy_;
-
- // The roots, or embed points, of this tree. A WindowTree may have any
- // number of roots, including 0.
- std::set<const ServerWindow*> roots_;
-
- // The windows created by this tree. This tree owns these objects.
- std::set<ServerWindow*> created_windows_;
-
- // The client is allowed to assign ids.
- std::unordered_map<ClientWindowId, const ServerWindow*, ClientWindowIdHash>
- client_id_to_window_map_;
- std::unordered_map<const ServerWindow*, ClientWindowId>
- window_to_client_id_map_;
-
- // Id passed to the client and expected to be supplied back to
- // OnWindowInputEventAck() or OnAcceleratorAck().
- uint32_t event_ack_id_;
-
- DispatchEventCallback event_ack_callback_;
-
- AcceleratorCallback accelerator_ack_callback_;
-
- // A client is considered janky if it hasn't ACK'ed input events within a
- // reasonable timeframe.
- bool janky_ = false;
-
- // For performance reasons, only send move events if the client explicitly
- // requests them.
- bool pointer_watcher_want_moves_ = false;
-
- // True if StartPointerWatcher() was called.
- bool has_pointer_watcher_ = false;
-
- // WindowManager the current event came from.
- WindowManagerState* event_source_wms_ = nullptr;
-
- base::queue<std::unique_ptr<TargetedEvent>> event_queue_;
-
- // TODO(sky): move all window manager specific state into struct to make it
- // clear what applies only to the window manager.
- std::unique_ptr<mojo::AssociatedBinding<mojom::WindowManagerClient>>
- window_manager_internal_client_binding_;
- mojom::WindowManager* window_manager_internal_;
- std::unique_ptr<WindowManagerState> window_manager_state_;
- // See mojom for details.
- bool automatically_create_display_roots_ = true;
-
- std::unique_ptr<WaitingForTopLevelWindowInfo>
- waiting_for_top_level_window_info_;
- bool embedder_intercepts_events_ = false;
-
- // State kept while we're waiting for the window manager to ack a
- // WmMoveDragImage. Non-null while we're waiting for a response.
- struct DragMoveState;
- std::unique_ptr<DragMoveState> drag_move_state_;
-
- // Holds WindowTreeClients passed to ScheduleEmbed(). Entries are removed
- // when EmbedUsingToken() is called.
- using ScheduledEmbeds =
- base::flat_map<base::UnguessableToken, mojom::WindowTreeClientPtr>;
- ScheduledEmbeds scheduled_embeds_;
-
- // Controls whether the client can change the visibility of the roots.
- bool can_change_root_window_visibility_ = true;
-
- // A weak ptr factory for callbacks from the window manager for when we send
- // a image move. All weak ptrs are invalidated when a drag is completed.
- base::WeakPtrFactory<WindowTree> drag_weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTree);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_TREE_H_
diff --git a/services/ui/ws/window_tree_binding.cc b/services/ui/ws/window_tree_binding.cc
deleted file mode 100644
index 124ff4b7..0000000
--- a/services/ui/ws/window_tree_binding.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/window_tree_binding.h"
-
-#include "base/bind.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree.h"
-
-namespace ui {
-namespace ws {
-
-WindowTreeBinding::WindowTreeBinding(mojom::WindowTreeClient* client)
- : client_(client) {}
-
-WindowTreeBinding::~WindowTreeBinding() {}
-
-void WindowTreeBinding::ResetClientForShutdown() {
- client_ = CreateClientForShutdown();
-}
-
-DefaultWindowTreeBinding::DefaultWindowTreeBinding(
- WindowTree* tree,
- WindowServer* window_server,
- mojom::WindowTreeRequest service_request,
- mojom::WindowTreeClientPtr client)
- : WindowTreeBinding(client.get()),
- binding_(tree, std::move(service_request)),
- client_(std::move(client)) {
- // Both |window_server| and |tree| outlive us.
- binding_.set_connection_error_handler(
- base::Bind(&WindowServer::DestroyTree, base::Unretained(window_server),
- base::Unretained(tree)));
-}
-
-DefaultWindowTreeBinding::DefaultWindowTreeBinding(
- WindowTree* tree,
- mojom::WindowTreeClientPtr client)
- : WindowTreeBinding(client.get()),
- binding_(tree),
- client_(std::move(client)) {}
-
-DefaultWindowTreeBinding::~DefaultWindowTreeBinding() {}
-
-mojom::WindowTreePtr DefaultWindowTreeBinding::CreateInterfacePtrAndBind() {
- DCHECK(!binding_.is_bound());
- mojom::WindowTreePtr ptr;
- binding_.Bind(mojo::MakeRequest(&ptr));
- return ptr;
-}
-
-mojom::WindowManager* DefaultWindowTreeBinding::GetWindowManager() {
- client_->GetWindowManager(MakeRequest(&window_manager_internal_));
- return window_manager_internal_.get();
-}
-
-void DefaultWindowTreeBinding::SetIncomingMethodCallProcessingPaused(
- bool paused) {
- if (paused)
- binding_.PauseIncomingMethodCallProcessing();
- else
- binding_.ResumeIncomingMethodCallProcessing();
-}
-
-mojom::WindowTreeClient* DefaultWindowTreeBinding::CreateClientForShutdown() {
- client_.reset();
- MakeRequest(&client_);
- return client_.get();
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_tree_binding.h b/services/ui/ws/window_tree_binding.h
deleted file mode 100644
index 4b9b884..0000000
--- a/services/ui/ws/window_tree_binding.h
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_TREE_BINDING_H_
-#define SERVICES_UI_WS_WINDOW_TREE_BINDING_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class WindowServer;
-class WindowTree;
-
-// WindowTreeBinding manages the binding between a WindowTree and its
-// WindowTreeClient. WindowTreeBinding exists so that a mock implementation
-// of WindowTreeClient can be injected for tests. WindowTree owns its
-// associated WindowTreeBinding.
-class WindowTreeBinding {
- public:
- explicit WindowTreeBinding(mojom::WindowTreeClient* client);
- virtual ~WindowTreeBinding();
-
- mojom::WindowTreeClient* client() { return client_; }
-
- // Obtains a new WindowManager. This should only be called once.
- virtual mojom::WindowManager* GetWindowManager() = 0;
-
- virtual void SetIncomingMethodCallProcessingPaused(bool paused) = 0;
-
- // Called when the WindowServer is destroyed. Sets |client_| to
- // CreateClientForShutdown().
- void ResetClientForShutdown();
-
- protected:
- virtual mojom::WindowTreeClient* CreateClientForShutdown() = 0;
-
- private:
- mojom::WindowTreeClient* client_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTreeBinding);
-};
-
-// Bindings implementation of WindowTreeBinding.
-class DefaultWindowTreeBinding : public WindowTreeBinding {
- public:
- DefaultWindowTreeBinding(WindowTree* tree,
- WindowServer* window_server,
- mojom::WindowTreeRequest service_request,
- mojom::WindowTreeClientPtr client);
- DefaultWindowTreeBinding(WindowTree* tree,
- mojom::WindowTreeClientPtr client);
- ~DefaultWindowTreeBinding() override;
-
- // Use when created with the constructor that does not take a
- // WindowTreeRequest.
- mojom::WindowTreePtr CreateInterfacePtrAndBind();
-
- // WindowTreeBinding:
- mojom::WindowManager* GetWindowManager() override;
- void SetIncomingMethodCallProcessingPaused(bool paused) override;
-
- protected:
- // WindowTreeBinding:
- mojom::WindowTreeClient* CreateClientForShutdown() override;
-
- private:
- mojo::Binding<mojom::WindowTree> binding_;
- mojom::WindowTreeClientPtr client_;
- mojom::WindowManagerAssociatedPtr window_manager_internal_;
-
- DISALLOW_COPY_AND_ASSIGN(DefaultWindowTreeBinding);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_TREE_BINDING_H_
diff --git a/services/ui/ws/window_tree_client_unittest.cc b/services/ui/ws/window_tree_client_unittest.cc
deleted file mode 100644
index 30542aa9..0000000
--- a/services/ui/ws/window_tree_client_unittest.cc
+++ /dev/null
@@ -1,2564 +0,0 @@
-// Copyright 2014 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 <stddef.h>
-#include <stdint.h>
-
-#include "base/bind.h"
-#include "base/containers/flat_map.h"
-#include "base/macros.h"
-#include "base/run_loop.h"
-#include "base/strings/stringprintf.h"
-#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
-#include "mojo/public/cpp/bindings/associated_binding.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "services/service_manager/public/cpp/binder_registry.h"
-#include "services/service_manager/public/cpp/service_test.h"
-#include "services/ui/common/util.h"
-#include "services/ui/public/interfaces/constants.mojom.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/public/interfaces/window_tree_host_factory.mojom.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/test_change_tracker.h"
-#include "services/ui/ws/window_server_service_test_base.h"
-#include "ui/base/cursor/cursor.h"
-
-using mojo::InterfaceRequest;
-using service_manager::Service;
-using ui::mojom::WindowDataPtr;
-using ui::mojom::WindowTree;
-using ui::mojom::WindowTreeClient;
-
-namespace ui {
-namespace ws {
-namespace test {
-
-namespace {
-
-// Creates an id used for transport from the specified parameters.
-Id BuildWindowId(ClientSpecificId client_id,
- ClientSpecificId window_id) {
- const Id tmp = client_id;
- return (tmp << 32) | window_id;
-}
-
-// Callback function from WindowTree functions.
-// ----------------------------------
-
-void WindowTreeResultCallback(base::RunLoop* run_loop,
- std::vector<TestWindow>* windows,
- std::vector<WindowDataPtr> results) {
- WindowDatasToTestWindows(results, windows);
- run_loop->Quit();
-}
-
-void EmbedCallbackImpl(base::RunLoop* run_loop,
- bool* result_cache,
- bool result) {
- *result_cache = result;
- run_loop->Quit();
-}
-
-void ScheduleEmbedCallbackImpl(base::RunLoop* run_loop,
- base::UnguessableToken* resulting_token,
- const base::UnguessableToken& token) {
- *resulting_token = token;
- run_loop->Quit();
-}
-
-// -----------------------------------------------------------------------------
-
-bool EmbedUrl(service_manager::Connector* connector,
- WindowTree* tree,
- const std::string& url,
- Id root_id) {
- bool result = false;
- base::RunLoop run_loop;
- {
- mojom::WindowTreeClientPtr client;
- connector->BindInterface(url, &client);
- const uint32_t embed_flags = 0;
- tree->Embed(root_id, std::move(client), embed_flags,
- base::Bind(&EmbedCallbackImpl, &run_loop, &result));
- }
- run_loop.Run();
- return result;
-}
-
-bool Embed(WindowTree* tree, Id root_id, mojom::WindowTreeClientPtr client) {
- bool result = false;
- base::RunLoop run_loop;
- {
- const uint32_t embed_flags = 0;
- tree->Embed(root_id, std::move(client), embed_flags,
- base::Bind(&EmbedCallbackImpl, &run_loop, &result));
- }
- run_loop.Run();
- return result;
-}
-
-bool EmbedUsingToken(WindowTree* tree,
- Id root_id,
- const base::UnguessableToken& token) {
- bool result = false;
- base::RunLoop run_loop;
- const uint32_t embed_flags = 0;
- tree->EmbedUsingToken(root_id, token, embed_flags,
- base::Bind(&EmbedCallbackImpl, &run_loop, &result));
- run_loop.Run();
- return result;
-}
-
-void ScheduleEmbed(WindowTree* tree,
- mojom::WindowTreeClientPtr client,
- base::UnguessableToken* token) {
- base::RunLoop run_loop;
- tree->ScheduleEmbed(std::move(client),
- base::Bind(&ScheduleEmbedCallbackImpl, &run_loop, token));
- run_loop.Run();
-}
-
-void GetWindowTree(WindowTree* tree,
- Id window_id,
- std::vector<TestWindow>* windows) {
- base::RunLoop run_loop;
- tree->GetWindowTree(
- window_id, base::Bind(&WindowTreeResultCallback, &run_loop, windows));
- run_loop.Run();
-}
-
-// Utility functions -----------------------------------------------------------
-
-const Id kNullParentId = 0;
-std::string IdToString(Id id) {
- return (id == kNullParentId)
- ? "null"
- : base::StringPrintf("%d,%d", ClientIdFromTransportId(id),
- ClientWindowIdFromTransportId(id));
-}
-
-std::string WindowParentToString(Id window, Id parent) {
- return base::StringPrintf("window=%s parent=%s", IdToString(window).c_str(),
- IdToString(parent).c_str());
-}
-
-// -----------------------------------------------------------------------------
-
-// A WindowTreeClient implementation that logs all changes to a tracker.
-class TestWindowTreeClient : public mojom::WindowTreeClient,
- public TestChangeTracker::Delegate,
- public mojom::WindowManager {
- public:
- TestWindowTreeClient()
- : binding_(this),
- root_window_id_(0),
- // Start with a random large number so tests can use lower ids if they
- // want.
- next_change_id_(10000),
- waiting_change_id_(0),
- on_change_completed_result_(false),
- track_root_bounds_changes_(false) {
- tracker_.set_delegate(this);
- }
-
- void Bind(mojo::InterfaceRequest<mojom::WindowTreeClient> request) {
- binding_.Bind(std::move(request));
- }
-
- mojom::WindowTree* tree() { return tree_.get(); }
- TestChangeTracker* tracker() { return &tracker_; }
- Id root_window_id() const { return root_window_id_; }
-
- // Sets whether changes to the bounds of the root should be tracked. Normally
- // they are ignored (as during startup we often times get random size
- // changes).
- void set_track_root_bounds_changes(bool value) {
- track_root_bounds_changes_ = value;
- }
-
- // Runs a nested MessageLoop until |count| changes (calls to
- // WindowTreeClient functions) have been received.
- void WaitForChangeCount(size_t count) {
- if (tracker_.changes()->size() >= count)
- return;
-
- ASSERT_TRUE(wait_state_.get() == nullptr);
- wait_state_ = std::make_unique<WaitState>();
- wait_state_->change_count = count;
- wait_state_->run_loop.Run();
- wait_state_.reset();
- }
-
- uint32_t GetAndAdvanceChangeId() { return next_change_id_++; }
-
- // Runs a nested MessageLoop until OnEmbed() has been encountered.
- void WaitForOnEmbed() {
- if (tree_)
- return;
- embed_run_loop_ = std::make_unique<base::RunLoop>();
- embed_run_loop_->Run();
- embed_run_loop_.reset();
- }
-
- bool WaitForChangeCompleted(uint32_t id) {
- waiting_change_id_ = id;
- change_completed_run_loop_ = std::make_unique<base::RunLoop>();
- change_completed_run_loop_->Run();
- return on_change_completed_result_;
- }
-
- bool DeleteWindow(Id id) {
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->DeleteWindow(change_id, id);
- return WaitForChangeCompleted(change_id);
- }
-
- bool AddWindow(Id parent, Id child) {
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->AddWindow(change_id, parent, child);
- return WaitForChangeCompleted(change_id);
- }
-
- bool RemoveWindowFromParent(Id window_id) {
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->RemoveWindowFromParent(change_id, window_id);
- return WaitForChangeCompleted(change_id);
- }
-
- bool ReorderWindow(Id window_id,
- Id relative_window_id,
- mojom::OrderDirection direction) {
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->ReorderWindow(change_id, window_id, relative_window_id, direction);
- return WaitForChangeCompleted(change_id);
- }
-
- // Waits for all messages to be received by |ws|. This is done by attempting
- // to set opacity on an embed/invalid window. 1.0f is the default opacity
- // value. When we get the response we know all messages have been processed.
- bool WaitForAllMessages() { return !SetWindowOpacity(0, 1.0f); }
-
- Id NewWindow(ClientSpecificId window_id) {
- return NewWindowWithCompleteId(window_id);
- }
-
- // Generally you want NewWindow(), but use this if you need to test given
- // a complete window id (NewWindow() ors with the client id).
- Id NewWindowWithCompleteId(Id id) {
- base::flat_map<std::string, std::vector<uint8_t>> properties;
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->NewWindow(change_id, id, std::move(properties));
- return WaitForChangeCompleted(change_id) ? id : 0;
- }
-
- bool SetWindowProperty(Id window_id,
- const std::string& name,
- const std::vector<uint8_t>* data) {
- base::Optional<std::vector<uint8_t>> mojo_data;
- if (data)
- mojo_data.emplace(*data);
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->SetWindowProperty(change_id, window_id, name, mojo_data);
- return WaitForChangeCompleted(change_id);
- }
-
- bool SetCursor(Id window_id, const ui::CursorData& cursor) {
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->SetCursor(change_id, window_id, cursor);
- return WaitForChangeCompleted(change_id);
- }
-
- bool SetWindowVisibility(Id window_id, bool visible) {
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->SetWindowVisibility(change_id, window_id, visible);
- return WaitForChangeCompleted(change_id);
- }
-
- bool SetWindowOpacity(Id window_id, float opacity) {
- const uint32_t change_id = GetAndAdvanceChangeId();
- tree()->SetWindowOpacity(change_id, window_id, opacity);
- return WaitForChangeCompleted(change_id);
- }
-
- private:
- // Used when running a nested MessageLoop.
- struct WaitState {
- WaitState() : change_count(0) {}
-
- // Number of changes waiting for.
- size_t change_count;
- base::RunLoop run_loop;
- };
-
- // TestChangeTracker::Delegate:
- void OnChangeAdded() override {
- if (wait_state_.get() &&
- tracker_.changes()->size() >= wait_state_->change_count) {
- wait_state_->run_loop.Quit();
- }
- }
-
- // WindowTreeClient:
- void OnEmbed(
- WindowDataPtr root,
- mojom::WindowTreePtr tree,
- int64_t display_id,
- Id focused_window_id,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override {
- // TODO(sky): add coverage of |focused_window_id|.
- ASSERT_TRUE(root);
- root_window_id_ = root->window_id;
- tree_ = std::move(tree);
- tracker()->OnEmbed(std::move(root), drawn);
- if (embed_run_loop_)
- embed_run_loop_->Quit();
- }
- void OnEmbedFromToken(
- const base::UnguessableToken& token,
- mojom::WindowDataPtr root,
- int64_t display_id,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override {}
- void OnEmbeddedAppDisconnected(Id window_id) override {
- tracker()->OnEmbeddedAppDisconnected(window_id);
- }
- void OnUnembed(Id window_id) override { tracker()->OnUnembed(window_id); }
- void OnCaptureChanged(Id new_capture_window_id,
- Id old_capture_window_id) override {
- tracker()->OnCaptureChanged(new_capture_window_id, old_capture_window_id);
- }
- void OnFrameSinkIdAllocated(Id window_id,
- const viz::FrameSinkId& frame_sink_id) override {}
- void OnTopLevelCreated(
- uint32_t change_id,
- mojom::WindowDataPtr data,
- int64_t display_id,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override {
- tracker()->OnTopLevelCreated(change_id, std::move(data), drawn);
- }
- void OnWindowBoundsChanged(
- Id window_id,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override {
- // The bounds of the root may change during startup on Android at random
- // times. As this doesn't matter, and shouldn't impact test exepctations,
- // it is ignored.
- if (window_id == root_window_id_ && !track_root_bounds_changes_)
- return;
- tracker()->OnWindowBoundsChanged(window_id, old_bounds, new_bounds,
- local_surface_id);
- }
- void OnWindowTransformChanged(Id window_id,
- const gfx::Transform& old_transform,
- const gfx::Transform& new_transform) override {
- tracker()->OnWindowTransformChanged(window_id);
- }
- void OnClientAreaChanged(
- Id window_id,
- const gfx::Insets& new_client_area,
- const std::vector<gfx::Rect>& new_additional_client_areas) override {}
- void OnTransientWindowAdded(Id window_id, Id transient_window_id) override {
- tracker()->OnTransientWindowAdded(window_id, transient_window_id);
- }
- void OnTransientWindowRemoved(Id window_id, Id transient_window_id) override {
- tracker()->OnTransientWindowRemoved(window_id, transient_window_id);
- }
- void OnWindowHierarchyChanged(Id window,
- Id old_parent,
- Id new_parent,
- std::vector<WindowDataPtr> windows) override {
- tracker()->OnWindowHierarchyChanged(window, old_parent, new_parent,
- std::move(windows));
- }
- void OnWindowReordered(Id window_id,
- Id relative_window_id,
- mojom::OrderDirection direction) override {
- tracker()->OnWindowReordered(window_id, relative_window_id, direction);
- }
- void OnWindowDeleted(Id window) override {
- tracker()->OnWindowDeleted(window);
- }
- void OnWindowVisibilityChanged(Id window, bool visible) override {
- tracker()->OnWindowVisibilityChanged(window, visible);
- }
- void OnWindowOpacityChanged(Id window,
- float old_opacity,
- float new_opacity) override {
- tracker()->OnWindowOpacityChanged(window, new_opacity);
- }
- void OnWindowParentDrawnStateChanged(Id window, bool drawn) override {
- tracker()->OnWindowParentDrawnStateChanged(window, drawn);
- }
- void OnWindowInputEvent(
- uint32_t event_id,
- Id window_id,
- int64_t display_id,
- Id display_root_window_id,
- const gfx::PointF& event_location_in_screen_pixel_layout,
- std::unique_ptr<ui::Event> event,
- bool matches_pointer_watcher) override {
- // Ack input events to clear the state on the server. These can be received
- // during test startup. X11Window::DispatchEvent sends a synthetic move
- // event to notify of entry.
- tree()->OnWindowInputEventAck(event_id, mojom::EventResult::HANDLED);
- // Don't log input events as none of the tests care about them and they
- // may come in at random points.
- }
- void OnPointerEventObserved(std::unique_ptr<ui::Event>,
- Id window_id,
- int64_t display_id) override {}
- void OnWindowSharedPropertyChanged(
- Id window,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& new_data) override {
- tracker_.OnWindowSharedPropertyChanged(window, name, new_data);
- }
- // TODO(sky): add testing coverage.
- void OnWindowFocused(Id focused_window_id) override {}
- void OnWindowCursorChanged(Id window_id, ui::CursorData cursor) override {
- tracker_.OnWindowCursorChanged(window_id, cursor);
- }
-
- void OnDragDropStart(const base::flat_map<std::string, std::vector<uint8_t>>&
- drag_data) override {
- NOTIMPLEMENTED();
- }
-
- void OnWindowSurfaceChanged(Id window_id,
- const viz::SurfaceInfo& surface_info) override {
- tracker_.OnWindowSurfaceChanged(window_id, surface_info);
- }
-
- void OnDragEnter(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnDragEnterCallback callback) override {
- NOTIMPLEMENTED();
- }
- void OnDragOver(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnDragOverCallback callback) override {
- NOTIMPLEMENTED();
- }
- void OnDragLeave(Id window) override { NOTIMPLEMENTED(); }
- void OnCompleteDrop(Id window,
- uint32_t key_state,
- const gfx::Point& position,
- uint32_t effect_bitmask,
- OnCompleteDropCallback callback) override {
- NOTIMPLEMENTED();
- }
-
- void OnPerformDragDropCompleted(uint32_t change_id,
- bool success,
- uint32_t action_taken) override {
- NOTIMPLEMENTED();
- }
-
- void OnDragDropDone() override { NOTIMPLEMENTED(); }
-
- void OnChangeCompleted(uint32_t change_id, bool success) override {
- if (waiting_change_id_ == change_id && change_completed_run_loop_) {
- on_change_completed_result_ = success;
- change_completed_run_loop_->Quit();
- }
- }
- void RequestClose(Id window_id) override {}
- void GetWindowManager(mojo::AssociatedInterfaceRequest<mojom::WindowManager>
- internal) override {
- window_manager_binding_ =
- std::make_unique<mojo::AssociatedBinding<mojom::WindowManager>>(
- this, std::move(internal));
- tree_->GetWindowManagerClient(MakeRequest(&window_manager_client_));
- }
- void GetScreenProviderObserver(
- mojom::ScreenProviderObserverAssociatedRequest observer) override {
- // GetScreenProviderObserver() is only called in ws2.
- NOTREACHED();
- }
-
- // mojom::WindowManager:
- void OnConnect() override {}
- void WmOnAcceleratedWidgetForDisplay(
- int64_t display,
- gpu::SurfaceHandle surface_handle) override {}
- void WmNewDisplayAdded(
- const display::Display& display,
- mojom::WindowDataPtr root_data,
- bool drawn,
- const base::Optional<viz::LocalSurfaceId>& local_surface_id) override {
- NOTIMPLEMENTED();
- }
- void WmDisplayRemoved(int64_t display_id) override { NOTIMPLEMENTED(); }
- void WmDisplayModified(const display::Display& display) override {
- NOTIMPLEMENTED();
- }
- void WmSetBounds(uint32_t change_id,
- Id window_id,
- const gfx::Rect& bounds) override {
- window_manager_client_->WmResponse(change_id, false);
- }
- void WmSetProperty(
- uint32_t change_id,
- Id window_id,
- const std::string& name,
- const base::Optional<std::vector<uint8_t>>& value) override {
- window_manager_client_->WmResponse(change_id, false);
- }
- void WmSetModalType(Id window_id, ui::ModalType type) override {}
- void WmSetCanFocus(Id window_id, bool can_focus) override {}
- void WmCreateTopLevelWindow(
- uint32_t change_id,
- const viz::FrameSinkId& frame_sink_id,
- const base::flat_map<std::string, std::vector<uint8_t>>& properties)
- override {
- NOTIMPLEMENTED();
- }
- void WmClientJankinessChanged(ClientSpecificId client_id,
- bool janky) override {
- NOTIMPLEMENTED();
- }
- void WmBuildDragImage(const gfx::Point& screen_location,
- const gfx::ImageSkia& drag_image,
- const gfx::Vector2d& drag_image_offset,
- ui::mojom::PointerKind source) override {}
- void WmMoveDragImage(const gfx::Point& screen_location,
- WmMoveDragImageCallback callback) override {
- std::move(callback).Run();
- }
- void WmDestroyDragImage() override {}
- void WmPerformMoveLoop(uint32_t change_id,
- Id window_id,
- mojom::MoveLoopSource source,
- const gfx::Point& cursor_location) override {
- NOTIMPLEMENTED();
- }
- void WmCancelMoveLoop(uint32_t change_id) override { NOTIMPLEMENTED(); }
- void WmDeactivateWindow(Id window_id) override { NOTIMPLEMENTED(); }
- void WmStackAbove(uint32_t change_id, Id above_id, Id below_id) override {
- NOTIMPLEMENTED();
- }
- void WmStackAtTop(uint32_t change_id, Id window_id) override {
- NOTIMPLEMENTED();
- }
- void WmPerformWmAction(Id window_id, const std::string& action) override {
- NOTIMPLEMENTED();
- }
- void OnAccelerator(uint32_t ack_id,
- uint32_t accelerator_id,
- std::unique_ptr<ui::Event> event) override {
- NOTIMPLEMENTED();
- }
- void OnCursorTouchVisibleChanged(bool enabled) override { NOTIMPLEMENTED(); }
- void OnEventBlockedByModalWindow(Id window_id) override { NOTIMPLEMENTED(); }
-
- TestChangeTracker tracker_;
-
- mojom::WindowTreePtr tree_;
-
- // If non-null we're waiting for OnEmbed() using this RunLoop.
- std::unique_ptr<base::RunLoop> embed_run_loop_;
-
- // If non-null we're waiting for a certain number of change notifications to
- // be encountered.
- std::unique_ptr<WaitState> wait_state_;
-
- mojo::Binding<WindowTreeClient> binding_;
- Id root_window_id_;
- uint32_t next_change_id_;
- uint32_t waiting_change_id_;
- bool on_change_completed_result_;
- bool track_root_bounds_changes_;
- std::unique_ptr<base::RunLoop> change_completed_run_loop_;
-
- std::unique_ptr<mojo::AssociatedBinding<mojom::WindowManager>>
- window_manager_binding_;
- mojom::WindowManagerClientAssociatedPtr window_manager_client_;
-
- DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClient);
-};
-
-// -----------------------------------------------------------------------------
-
-// InterfaceFactory for vending TestWindowTreeClients.
-class WindowTreeClientFactory {
- public:
- WindowTreeClientFactory() {}
- ~WindowTreeClientFactory() {}
-
- // Runs a nested MessageLoop until a new instance has been created.
- std::unique_ptr<TestWindowTreeClient> WaitForInstance() {
- if (!client_impl_.get()) {
- DCHECK(!run_loop_);
- run_loop_ = std::make_unique<base::RunLoop>();
- run_loop_->Run();
- run_loop_.reset();
- }
- return std::move(client_impl_);
- }
-
- void BindWindowTreeClientRequest(
- mojom::WindowTreeClientRequest request) {
- client_impl_ = std::make_unique<TestWindowTreeClient>();
- client_impl_->Bind(std::move(request));
- if (run_loop_.get())
- run_loop_->Quit();
- }
-
- private:
- std::unique_ptr<TestWindowTreeClient> client_impl_;
- std::unique_ptr<base::RunLoop> run_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTreeClientFactory);
-};
-
-} // namespace
-
-class WindowTreeClientTest : public WindowServerServiceTestBase {
- public:
- WindowTreeClientTest() : root_window_id_(0) {}
-
- ~WindowTreeClientTest() override {}
-
- protected:
- // Returns the changes from the various clients.
- std::vector<Change>* changes1() { return wt_client1_->tracker()->changes(); }
- std::vector<Change>* changes2() { return wt_client2_->tracker()->changes(); }
- std::vector<Change>* changes3() { return wt_client3_->tracker()->changes(); }
-
- // Various clients. |wt1()|, being the first client, has special permissions
- // (it's treated as the window manager).
- WindowTree* wt1() { return wt_client1_->tree(); }
- WindowTree* wt2() { return wt_client2_->tree(); }
- WindowTree* wt3() { return wt_client3_->tree(); }
-
- TestWindowTreeClient* wt_client1() { return wt_client1_.get(); }
- TestWindowTreeClient* wt_client2() { return wt_client2_.get(); }
- TestWindowTreeClient* wt_client3() { return wt_client3_.get(); }
-
- Id root_window_id() const { return root_window_id_; }
-
- int client_id_1() const { return client_id_1_; }
- int client_id_2() const { return client_id_2_; }
- int client_id_3() const { return client_id_3_; }
-
- void EstablishSecondClientWithRoot(Id root_id) {
- ASSERT_TRUE(wt_client2_.get() == nullptr);
- wt_client2_ = EstablishClientViaEmbed(wt1(), root_id);
- ASSERT_GT(client_id_2_, 0);
- ASSERT_TRUE(wt_client2_.get() != nullptr);
- }
-
- void EstablishSecondClient(bool create_initial_window) {
- Id window_1_1 = 0;
- if (create_initial_window) {
- window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
- }
- ASSERT_NO_FATAL_FAILURE(
- EstablishSecondClientWithRoot(BuildWindowId(client_id_1(), 1)));
-
- if (create_initial_window) {
- // window_1_1 is created by wt_client1() so its client_id part should be
- // client_id_1() in wt_client2.
- EXPECT_EQ(
- "[" +
- WindowParentToString(
- BuildWindowId(client_id_1(),
- ClientWindowIdFromTransportId(window_1_1)),
- kNullParentId) +
- "]",
- ChangeWindowDescription(*changes2()));
- }
- }
-
- void EstablishThirdClient(WindowTree* owner, Id root_id) {
- ASSERT_TRUE(wt_client3_.get() == nullptr);
- wt_client3_ = EstablishClientViaEmbed(owner, root_id);
- ASSERT_TRUE(wt_client3_.get() != nullptr);
- }
-
- std::unique_ptr<TestWindowTreeClient> WaitForWindowTreeClient() {
- return client_factory_->WaitForInstance();
- }
-
- // Establishes a new client by way of Embed() on the specified WindowTree.
- std::unique_ptr<TestWindowTreeClient> EstablishClientViaEmbed(
- WindowTree* owner,
- Id root_id) {
- return EstablishClientViaEmbedWithPolicyBitmask(owner, root_id);
- }
-
- std::unique_ptr<TestWindowTreeClient>
- EstablishClientViaEmbedWithPolicyBitmask(WindowTree* owner, Id root_id) {
- if (!EmbedUrl(connector(), owner, test_name(), root_id)) {
- ADD_FAILURE() << "Embed() failed";
- return nullptr;
- }
- std::unique_ptr<TestWindowTreeClient> client =
- client_factory_->WaitForInstance();
- if (!client.get()) {
- ADD_FAILURE() << "WaitForInstance failed";
- return nullptr;
- }
- client->WaitForOnEmbed();
-
- // TODO(fsamuel): Currently the FrameSinkId maps directly to the server's
- // window ID. This is likely bad from a security perspective and should be
- // fixed.
- EXPECT_EQ("OnEmbed",
- SingleChangeToDescription(*client->tracker()->changes()));
- return client;
- }
-
- // WindowServerServiceTestBase:
- void OnBindInterface(const service_manager::BindSourceInfo& source_info,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle interface_pipe) override {
- registry_.BindInterface(interface_name, std::move(interface_pipe));
- }
-
- void SetUp() override {
- client_factory_ = std::make_unique<WindowTreeClientFactory>();
- registry_.AddInterface(
- base::Bind(&WindowTreeClientFactory::BindWindowTreeClientRequest,
- base::Unretained(client_factory_.get())));
-
- WindowServerServiceTestBase::SetUp();
-
- mojom::WindowTreeHostFactoryPtr factory;
- connector()->BindInterface(ui::mojom::kServiceName, &factory);
-
- mojom::WindowTreeClientPtr tree_client_ptr;
- wt_client1_ = std::make_unique<TestWindowTreeClient>();
- wt_client1_->Bind(MakeRequest(&tree_client_ptr));
-
- factory->CreateWindowTreeHost(MakeRequest(&host_),
- std::move(tree_client_ptr));
-
- // Next we should get an embed call on the "window manager" client.
- wt_client1_->WaitForOnEmbed();
-
- ASSERT_EQ(1u, changes1()->size());
- EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type);
- ASSERT_FALSE((*changes1())[0].windows.empty());
- root_window_id_ = (*changes1())[0].windows[0].window_id;
- ASSERT_EQ(root_window_id_, wt_client1_->root_window_id());
- changes1()->clear();
- }
-
- void TearDown() override {
- // Destroy these before the message loop is destroyed (happens in
- // WindowServerServiceTestBase::TearDown).
- wt_client1_.reset();
- wt_client2_.reset();
- wt_client3_.reset();
- client_factory_.reset();
- WindowServerServiceTestBase::TearDown();
- }
-
- std::unique_ptr<TestWindowTreeClient> wt_client1_;
- std::unique_ptr<TestWindowTreeClient> wt_client2_;
- std::unique_ptr<TestWindowTreeClient> wt_client3_;
-
- mojom::WindowTreeHostPtr host_;
-
- private:
- std::unique_ptr<WindowTreeClientFactory> client_factory_;
- int client_id_1_ = kWindowServerClientId + 1;
- int client_id_2_ = client_id_1_ + 1;
- int client_id_3_ = client_id_2_ + 1;
- Id root_window_id_;
- service_manager::BinderRegistry registry_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTreeClientTest);
-};
-
-// Verifies two clients get different ids.
-TEST_F(WindowTreeClientTest, TwoClientsGetDifferentClientIds) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
-
- ASSERT_EQ(1u, changes2()->size());
- ASSERT_NE(client_id_1(), client_id_2());
-}
-
-// Verifies when Embed() is invoked any child windows are removed.
-TEST_F(WindowTreeClientTest, WindowsRemovedWhenEmbedding) {
- // Two windows 1 and 2. 2 is parented to 1.
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
-
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_2);
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_1, window_1_2));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
- ASSERT_EQ(1u, changes2()->size());
- ASSERT_EQ(1u, (*changes2())[0].windows.size());
- // window_1_1 has a client_id part of client_id_1 in wt2.
- Id window11_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_1));
- EXPECT_EQ("[" + WindowParentToString(window11_in_wt2, kNullParentId) + "]",
- ChangeWindowDescription(*changes2()));
-
- // Embed() removed window 2.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), window_1_2, &windows);
- EXPECT_EQ(WindowParentToString(window_1_2, kNullParentId),
- SingleWindowDescription(windows));
- }
-
- // ws2 should not see window 2.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt2(), window11_in_wt2, &windows);
- EXPECT_EQ(WindowParentToString(window11_in_wt2, kNullParentId),
- SingleWindowDescription(windows));
- }
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt2(), window_1_2, &windows);
- EXPECT_TRUE(windows.empty());
- }
-
- // Windows 3 and 4 in client 2.
- Id window_2_3 = wt_client2()->NewWindow(3);
- Id window_2_4 = wt_client2()->NewWindow(4);
- ASSERT_TRUE(window_2_3);
- ASSERT_TRUE(window_2_4);
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_3, window_2_4));
-
- // Client 3 rooted at 2.
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(wt2(), window_2_3));
-
- // Window 4 should no longer have a parent.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt2(), window_2_3, &windows);
- EXPECT_EQ(WindowParentToString(window_2_3, kNullParentId),
- SingleWindowDescription(windows));
-
- windows.clear();
- GetWindowTree(wt2(), window_2_4, &windows);
- EXPECT_EQ(WindowParentToString(window_2_4, kNullParentId),
- SingleWindowDescription(windows));
- }
-
- // And window 4 should not be visible to client 3.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt3(), window_2_3, &windows);
- EXPECT_EQ("no windows", SingleWindowDescription(windows));
- }
-}
-
-// Verifies once Embed() has been invoked the parent client can't see any
-// children.
-TEST_F(WindowTreeClientTest, CantAccessChildrenOfEmbeddedWindow) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
-
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- Id window_2_2 = wt_client2()->NewWindow(2);
- ASSERT_TRUE(window_2_2);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_2));
-
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(wt2(), window_2_2));
-
- Id window_3_3 = wt_client3()->NewWindow(3);
- ASSERT_TRUE(window_3_3);
- ASSERT_TRUE(
- wt_client3()->AddWindow(wt_client3()->root_window_id(), window_3_3));
-
- // Even though 3 is a child of 2 client 2 can't see 3 as it's from a
- // different client.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt2(), window_2_2, &windows);
- EXPECT_EQ(WindowParentToString(window_2_2, window_1_1),
- SingleWindowDescription(windows));
- }
-
- // Client 2 shouldn't be able to get window 3 at all.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt2(), window_3_3, &windows);
- EXPECT_TRUE(windows.empty());
- }
-
- // Client 1 should be able to see it all (its the root).
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), window_1_1, &windows);
- ASSERT_EQ(3u, windows.size());
- // window_1_1 is created by wt1() so client_id part would be 0 in wt1().
- EXPECT_EQ(WindowParentToString(ClientWindowIdFromTransportId(window_1_1),
- kNullParentId),
- windows[0].ToString());
- // NOTE: we expect a match of WindowParentToString(window_2_2, window_1_1),
- // but the ids are in the id space of client2, which is not the same as
- // the id space of wt1().
- EXPECT_EQ("window=" + std::to_string(client_id_2()) + ",2 parent=0,1",
- windows[1].ToString());
- // Same thing here, we really want to test for
- // WindowParentToString(window_3_3, window_2_2).
- EXPECT_EQ("window=" + std::to_string(client_id_3()) +
- ",3 parent=" + std::to_string(client_id_2()) + ",2",
- windows[2].ToString());
- }
-}
-
-// Verifies once Embed() has been invoked the parent can't mutate the children.
-TEST_F(WindowTreeClientTest, CantModifyChildrenOfEmbeddedWindow) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
-
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
-
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(wt2(), window_2_1));
-
- Id window_2_2 = wt_client2()->NewWindow(2);
- ASSERT_TRUE(window_2_2);
- // Client 2 shouldn't be able to add anything to the window anymore.
- ASSERT_FALSE(wt_client2()->AddWindow(window_2_1, window_2_2));
-
- // Create window 3 in client 3 and add it to window 3.
- Id window_3_1 = wt_client3()->NewWindow(1);
- ASSERT_TRUE(window_3_1);
- // window_2_1 should have a client_id of client_id_2 in wt_client3.
- ASSERT_TRUE(wt_client3()->AddWindow(
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_1)),
- window_3_1));
-
- // Client 2 shouldn't be able to remove window 3.
- ASSERT_FALSE(wt_client2()->RemoveWindowFromParent(
- BuildWindowId(client_id_3(), ClientWindowIdFromTransportId(window_3_1))));
-}
-
-// Verifies client gets a valid id.
-TEST_F(WindowTreeClientTest, NewWindow) {
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
- EXPECT_TRUE(changes1()->empty());
-
- // Can't create a window with the same id.
- ASSERT_EQ(0u, wt_client1()->NewWindowWithCompleteId(window_1_1));
- EXPECT_TRUE(changes1()->empty());
-
- // Can't create a window with a bogus client id.
- ASSERT_EQ(0u, wt_client1()->NewWindowWithCompleteId(
- BuildWindowId(client_id_1() + 1, 1)));
- EXPECT_TRUE(changes1()->empty());
-}
-
-// Verifies AddWindow fails when window is already in position.
-TEST_F(WindowTreeClientTest, AddWindowWithNoChange) {
- // Create the embed point now so that the ids line up.
- ASSERT_TRUE(wt_client1()->NewWindow(1));
- Id window_1_21 = wt_client1()->NewWindow(21);
- Id window_1_31 = wt_client1()->NewWindow(31);
- ASSERT_TRUE(window_1_21);
- ASSERT_TRUE(window_1_31);
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
-
- // Make 3 a child of 2.
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_21, window_1_31));
-
- // Try again, this should fail.
- EXPECT_FALSE(wt_client1()->AddWindow(window_1_21, window_1_31));
-}
-
-// Verifies AddWindow fails when window is already in position.
-TEST_F(WindowTreeClientTest, AddAncestorFails) {
- // Create the embed point now so that the ids line up.
- ASSERT_TRUE(wt_client1()->NewWindow(1));
- Id window_1_21 = wt_client1()->NewWindow(21);
- Id window_1_31 = wt_client1()->NewWindow(31);
- ASSERT_TRUE(window_1_21);
- ASSERT_TRUE(window_1_31);
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
-
- // Make 3 a child of 2.
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_21, window_1_31));
-
- // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3.
- EXPECT_FALSE(wt_client1()->AddWindow(window_1_31, window_1_21));
-}
-
-// Verifies adding to root sends right notifications.
-TEST_F(WindowTreeClientTest, AddToRoot) {
- // Create the embed point now so that the ids line up.
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
- Id window_1_21 = wt_client1()->NewWindow(21);
- Id window_1_31 = wt_client1()->NewWindow(31);
- ASSERT_TRUE(window_1_21);
- ASSERT_TRUE(window_1_31);
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
- changes2()->clear();
-
- // Make 3 a child of 21.
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_21, window_1_31));
-
- // Make 21 a child of 1.
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_1, window_1_21));
-
- // Client 2 should not be told anything (because the window is from a
- // different client). Create a window to ensure we got a response from
- // the server.
- ASSERT_TRUE(wt_client2()->NewWindow(100));
- EXPECT_TRUE(changes2()->empty());
-}
-
-// Verifies HierarchyChanged is correctly sent for various adds/removes.
-TEST_F(WindowTreeClientTest, WindowHierarchyChangedWindows) {
- // Create the embed point now so that the ids line up.
- Id window_1_1 = wt_client1()->NewWindow(1);
- // client_id_1(),2->client_id_1(),11.
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_2);
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_2, true));
- Id window_1_11 = wt_client1()->NewWindow(11);
- ASSERT_TRUE(window_1_11);
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_11, true));
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_2, window_1_11));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, true));
-
- ASSERT_TRUE(wt_client2()->WaitForAllMessages());
- changes2()->clear();
-
- // window_1_1 has a client_id part of client_id_1 in wt2.
- Id window11_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_1));
-
- // client_id_1(),1->client_id_1(),2->client_id_1(),11
- {
- // Client 2 should not get anything (client_id_1(),2 is from another
- // client).
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_1, window_1_2));
- ASSERT_TRUE(wt_client2()->WaitForAllMessages());
- EXPECT_TRUE(changes2()->empty());
- }
-
- // 0,1->client_id_1(),1->client_id_1(),2->client_id_1(),11.
- {
- // Client 2 is now connected to the root, so it should have gotten a drawn
- // notification.
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- wt_client2_->WaitForChangeCount(1u);
- EXPECT_EQ("DrawnStateChanged window=" + IdToString(window11_in_wt2) +
- " drawn=true",
- SingleChangeToDescription(*changes2()));
- }
-
- // client_id_1(),1->client_id_1(),2->client_id_1(),11.
- {
- // Client 2 is no longer connected to the root, should get drawn state
- // changed.
- changes2()->clear();
- ASSERT_TRUE(wt_client1()->RemoveWindowFromParent(window_1_1));
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("DrawnStateChanged window=" + IdToString(window11_in_wt2) +
- " drawn=false",
- SingleChangeToDescription(*changes2()));
- }
-
- // client_id_1(),1->client_id_1(),2->client_id_1(),11->client_id_1(),111.
- Id window_1_111 = wt_client1()->NewWindow(111);
- ASSERT_TRUE(window_1_111);
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_111, true));
- {
- changes2()->clear();
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_11, window_1_111));
- ASSERT_TRUE(wt_client2()->WaitForAllMessages());
- EXPECT_TRUE(changes2()->empty());
- }
-
- // 0,1->client_id_1(),1->client_id_1(),2->client_id_1(),11->client_id_1(),111
- {
- changes2()->clear();
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("DrawnStateChanged window=" + IdToString(window11_in_wt2) +
- " drawn=true",
- SingleChangeToDescription(*changes2()));
- }
-}
-
-TEST_F(WindowTreeClientTest, WindowHierarchyChangedAddingKnownToUnknown) {
- // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no
- // parent).
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
-
- Id window_2_11 = wt_client2()->NewWindow(11);
- Id window_2_2 = wt_client2()->NewWindow(2);
- Id window_2_21 = wt_client2()->NewWindow(21);
- ASSERT_TRUE(window_2_11);
- ASSERT_TRUE(window_2_2);
- ASSERT_TRUE(window_2_21);
- // window_1_1 has a client_id part of 0 in wt1, while window_2_2 has that of
- // client_id_2.
- Id window11_in_wt1 = ClientWindowIdFromTransportId(window_1_1);
- Id window22_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_2));
-
- // Set up the hierarchy.
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_11));
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_2, window_2_21));
-
- // Remove 11, should result in a hierarchy change for the root.
- {
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->RemoveWindowFromParent(window_2_11));
-
- wt_client1_->WaitForChangeCount(1);
- // client_id_2(),1 should be IdToString(window_2_11), but window_2_11 is in
- // the id space of client2, not client1.
- EXPECT_EQ("HierarchyChanged window=" + std::to_string(client_id_2()) +
- ",11 old_parent=" + IdToString(window11_in_wt1) +
- " new_parent=null",
- SingleChangeToDescription(*changes1()));
- }
-
- // Add 2 to 1.
- {
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_2));
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window22_in_wt1) +
- " old_parent=null new_parent=" + IdToString(window11_in_wt1),
- SingleChangeToDescription(*changes1()));
- // "window=client_id_2(),3 parent=client_id_2(),2]" should be,
- // WindowParentToString(window_2_21, window_2_2), but isn't because of
- // differing id spaces.
- EXPECT_EQ("[" + WindowParentToString(window22_in_wt1, window11_in_wt1) +
- "],[window=" + std::to_string(client_id_2()) +
- ",21 parent=" + std::to_string(client_id_2()) + ",2]",
- ChangeWindowDescription(*changes1()));
- }
-}
-
-TEST_F(WindowTreeClientTest, ReorderWindow) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
-
- Id window_2_1 = wt_client2()->NewWindow(1);
- Id window_2_2 = wt_client2()->NewWindow(2);
- Id window_2_3 = wt_client2()->NewWindow(3);
- Id window_1_4 = wt_client1()->NewWindow(4); // Peer to client_id_1(),1
- Id window_1_5 = wt_client1()->NewWindow(5); // Peer to client_id_1(),1
- Id window_2_6 = wt_client2()->NewWindow(6); // Child of client_id_1(),2.
- Id window_2_7 = wt_client2()->NewWindow(7); // Unparented.
- Id window_2_8 = wt_client2()->NewWindow(8); // Unparented.
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(window_2_2);
- ASSERT_TRUE(window_2_3);
- ASSERT_TRUE(window_1_4);
- ASSERT_TRUE(window_1_5);
- ASSERT_TRUE(window_2_6);
- ASSERT_TRUE(window_2_7);
- ASSERT_TRUE(window_2_8);
-
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_1, window_2_2));
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_2, window_2_6));
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_1, window_2_3));
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_4));
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_5));
- ASSERT_TRUE(
- wt_client2()->AddWindow(BuildWindowId(client_id_1(), 1), window_2_1));
-
- // window_2_* has client_id part of client_id_2 in wt1.
- Id window22_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_2));
- Id window23_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_3));
- Id window26_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_6));
- Id window27_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_7));
- Id window28_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_8));
-
- {
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->ReorderWindow(window_2_2, window_2_3,
- mojom::OrderDirection::ABOVE));
-
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("Reordered window=" + IdToString(window22_in_wt1) + " relative=" +
- IdToString(window23_in_wt1) + " direction=above",
- SingleChangeToDescription(*changes1()));
- }
-
- {
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->ReorderWindow(window_2_2, window_2_3,
- mojom::OrderDirection::BELOW));
-
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("Reordered window=" + IdToString(window22_in_wt1) + " relative=" +
- IdToString(window23_in_wt1) + " direction=below",
- SingleChangeToDescription(*changes1()));
- }
-
- // view2 is already below view3.
- EXPECT_FALSE(wt_client2()->ReorderWindow(window_2_2, window_2_3,
- mojom::OrderDirection::BELOW));
-
- // view4 & 5 are unknown to client 2.
- EXPECT_FALSE(wt_client2()->ReorderWindow(window_1_4, window_1_5,
- mojom::OrderDirection::ABOVE));
-
- // view6 & view3 have different parents.
- EXPECT_FALSE(wt_client1()->ReorderWindow(window23_in_wt1, window26_in_wt1,
- mojom::OrderDirection::ABOVE));
-
- // Non-existent window-ids
- EXPECT_FALSE(wt_client1()->ReorderWindow(BuildWindowId(client_id_1(), 27),
- BuildWindowId(client_id_1(), 28),
- mojom::OrderDirection::ABOVE));
-
- // view7 & view8 are un-parented.
- EXPECT_FALSE(wt_client1()->ReorderWindow(window27_in_wt1, window28_in_wt1,
- mojom::OrderDirection::ABOVE));
-}
-
-// Verifies DeleteWindow works.
-TEST_F(WindowTreeClientTest, DeleteWindow) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- // window_2_1 is not created by wt1 so its client_id part is client_id_2,
- // while window_1_1 would have 0 for the client_id part.
- Id window21_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_1));
-
- // Make 2 a child of 1.
- {
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window21_in_wt1) +
- " old_parent=null new_parent=" +
- IdToString(ClientWindowIdFromTransportId(window_1_1)),
- SingleChangeToDescription(*changes1()));
- }
-
- // Delete 2.
- {
- changes1()->clear();
- changes2()->clear();
- ASSERT_TRUE(wt_client2()->DeleteWindow(window_2_1));
- EXPECT_TRUE(changes2()->empty());
-
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("WindowDeleted window=" + IdToString(window21_in_wt1),
- SingleChangeToDescription(*changes1()));
- }
-}
-
-// Verifies DeleteWindow() on the root suceeds.
-TEST_F(WindowTreeClientTest, DeleteRoot) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- EXPECT_TRUE(wt_client2()->DeleteWindow(window_1_1));
- // Client1 should get OnEmbeddedAppDisconnected().
- wt_client1_->WaitForChangeCount(1);
- // window_1_1 should have client_id of 0 in wt_client1 because it's created
- // by wt_client1.
- EXPECT_EQ("OnEmbeddedAppDisconnected window=" +
- IdToString(ClientWindowIdFromTransportId(window_1_1)),
- SingleChangeToDescription(*changes1()));
-
- // Create a new window and try adding to |window_1_1| from client 2, should
- // fail as client 2 no longer knows about |window_1_1|.
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- EXPECT_FALSE(wt_client2()->AddWindow(window_1_1, window_2_1));
-}
-
-// Verifies DeleteWindow() on the root suceeds.
-TEST_F(WindowTreeClientTest, DeleteRootWithChildren) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
- changes2()->clear();
- EXPECT_TRUE(wt_client2()->DeleteWindow(window_1_1));
- // DeleteWindow() should not result in any calls to client 2.
- EXPECT_TRUE(changes2()->empty());
-
- // Create a new window parented to 2_1. Should work as 2_1 is still valid.
- Id window_2_2 = wt_client2()->NewWindow(2);
- ASSERT_TRUE(window_2_2);
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_1, window_2_2));
-}
-
-// Verifies DeleteWindow isn't allowed from a separate client.
-TEST_F(WindowTreeClientTest, DeleteWindowFromAnotherClientDisallowed) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- // This id is unknown, so deletion should fail.
- EXPECT_FALSE(wt_client2()->DeleteWindow(BuildWindowId(client_id_1(), 2)));
-}
-
-// Verifies if a window was deleted and then reused that other clients are
-// properly notified.
-TEST_F(WindowTreeClientTest, ReuseDeletedWindowId) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
-
- // wt1 created window_1_1 but not window_2_1.
- Id window11_in_wt1 = ClientWindowIdFromTransportId(window_1_1);
- Id window21_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_1));
-
- // Add 2 to 1.
- {
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window21_in_wt1) +
- " old_parent=null new_parent=" + IdToString(window11_in_wt1),
- SingleChangeToDescription(*changes1()));
- EXPECT_EQ(
- "[" + WindowParentToString(window21_in_wt1, window11_in_wt1) + "]",
- ChangeWindowDescription(*changes1()));
- }
-
- // Delete 2.
- {
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->DeleteWindow(window_2_1));
-
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("WindowDeleted window=" + IdToString(window21_in_wt1),
- SingleChangeToDescription(*changes1()));
- }
-
- // Create 2 again, and add it back to 1. Should get the same notification.
- window_2_1 = wt_client2()->NewWindow(2);
- window21_in_wt1 = BuildWindowId(ClientIdFromTransportId(window21_in_wt1),
- ClientWindowIdFromTransportId(window_2_1));
- ASSERT_TRUE(window_2_1);
- {
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
-
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window21_in_wt1) +
- " old_parent=null new_parent=" + IdToString(window11_in_wt1),
- SingleChangeToDescription(*changes1()));
- EXPECT_EQ(
- "[" + WindowParentToString(window21_in_wt1, window11_in_wt1) + "]",
- ChangeWindowDescription(*changes1()));
- }
-}
-
-// Assertions for GetWindowTree.
-TEST_F(WindowTreeClientTest, GetWindowTree) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
-
- // Create 11 in first client and make it a child of 1.
- Id window_1_11 = wt_client1()->NewWindow(11);
- ASSERT_TRUE(window_1_11);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_1, window_1_11));
-
- // Create two windows in second client, 2 and 3, both children of 1.
- Id window_2_1 = wt_client2()->NewWindow(1);
- Id window_2_2 = wt_client2()->NewWindow(2);
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(window_2_2);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_2));
-
- // wt1 created window_1_1 and window_1_11, but not window_2_1 and window_2_2.
- Id window11_in_wt1 = ClientWindowIdFromTransportId(window_1_1);
- Id window111_in_wt1 = ClientWindowIdFromTransportId(window_1_11);
- Id window21_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_1));
- Id window22_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_2));
-
- // Verifies GetWindowTree() on the root. The root client sees all.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), root_window_id(), &windows);
- ASSERT_EQ(5u, windows.size());
- EXPECT_EQ(WindowParentToString(root_window_id(), kNullParentId),
- windows[0].ToString());
- EXPECT_EQ(WindowParentToString(window11_in_wt1, root_window_id()),
- windows[1].ToString());
- EXPECT_EQ(WindowParentToString(window111_in_wt1, window11_in_wt1),
- windows[2].ToString());
- EXPECT_EQ(WindowParentToString(window21_in_wt1, window11_in_wt1),
- windows[3].ToString());
- EXPECT_EQ(WindowParentToString(window22_in_wt1, window11_in_wt1),
- windows[4].ToString());
- }
-
- // Verifies GetWindowTree() on the window client_id_1(),1 from wt2(). wt2()
- // sees client_id_1(),1 as client_id_1(),1 is wt2()'s root and wt2() sees all
- // the windows it created.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt2(), window_1_1, &windows);
- ASSERT_EQ(3u, windows.size());
- EXPECT_EQ(WindowParentToString(window_1_1, kNullParentId),
- windows[0].ToString());
- EXPECT_EQ(WindowParentToString(window_2_1, window_1_1),
- windows[1].ToString());
- EXPECT_EQ(WindowParentToString(window_2_2, window_1_1),
- windows[2].ToString());
- }
-
- // Client 2 shouldn't be able to get the root tree.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt2(), root_window_id(), &windows);
- ASSERT_EQ(0u, windows.size());
- }
-}
-
-TEST_F(WindowTreeClientTest, SetWindowBounds) {
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
-
- changes2()->clear();
-
- wt_client2_->set_track_root_bounds_changes(true);
-
- viz::ParentLocalSurfaceIdAllocator allocator;
- viz::LocalSurfaceId local_surface_id = allocator.GenerateId();
- wt1()->SetWindowBounds(10, window_1_1, gfx::Rect(0, 0, 100, 100),
- local_surface_id);
- ASSERT_TRUE(wt_client1()->WaitForChangeCompleted(10));
-
- wt_client2_->WaitForChangeCount(1);
- // window_1_1 has a client_id part of client_id_1 in wt2.
- Id window11_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_1));
- EXPECT_EQ("BoundsChanged window=" + IdToString(window11_in_wt2) +
- " old_bounds=0,0 0x0 new_bounds=0,0 100x100 local_surface_id=" +
- local_surface_id.ToString(),
- SingleChangeToDescription(*changes2()));
-
- // Should not be possible to change the bounds of a window created by another
- // client.
- wt2()->SetWindowBounds(11, window11_in_wt2, gfx::Rect(0, 0, 0, 0),
- base::nullopt);
- ASSERT_FALSE(wt_client2()->WaitForChangeCompleted(11));
-}
-
-// Verify AddWindow fails when trying to manipulate windows in other roots.
-TEST_F(WindowTreeClientTest, CantMoveWindowsFromOtherRoot) {
- // Create 1 and 2 in the first client.
- Id window_1_1 = wt_client1()->NewWindow(1);
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_1);
- ASSERT_TRUE(window_1_2);
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
-
- // Try to move 2 to be a child of 1 from client 2. This should fail as 2
- // should not be able to access 1.
- ASSERT_FALSE(wt_client2()->AddWindow(window_1_1, window_1_2));
-
- // Try to reparent 1 to the root. A client is not allowed to reparent its
- // roots.
- ASSERT_FALSE(wt_client2()->AddWindow(root_window_id(), window_1_1));
-}
-
-// Verify RemoveWindowFromParent fails for windows that are descendants of the
-// roots.
-TEST_F(WindowTreeClientTest, CantRemoveWindowsInOtherRoots) {
- // Create 1 and 2 in the first client and parent both to the root.
- Id window_1_1 = wt_client1()->NewWindow(1);
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_1);
- ASSERT_TRUE(window_1_2);
-
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_2));
-
- // Establish the second client and give it the root 1.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
-
- // Client 2 should not be able to remove window 2 or 1 from its parent.
- ASSERT_FALSE(wt_client2()->RemoveWindowFromParent(window_1_2));
- ASSERT_FALSE(wt_client2()->RemoveWindowFromParent(window_1_1));
-
- // Create windows 10 and 11 in 2.
- Id window_2_10 = wt_client2()->NewWindow(10);
- Id window_2_11 = wt_client2()->NewWindow(11);
- ASSERT_TRUE(window_2_10);
- ASSERT_TRUE(window_2_11);
-
- // Parent 11 to 10.
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_10, window_2_11));
- // Remove 11 from 10.
- ASSERT_TRUE(wt_client2()->RemoveWindowFromParent(window_2_11));
-
- // Verify nothing was actually removed.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), root_window_id(), &windows);
- ASSERT_EQ(3u, windows.size());
- EXPECT_EQ(WindowParentToString(root_window_id(), kNullParentId),
- windows[0].ToString());
- EXPECT_EQ(WindowParentToString(window_1_1, root_window_id()),
- windows[1].ToString());
- EXPECT_EQ(WindowParentToString(window_1_2, root_window_id()),
- windows[2].ToString());
- }
-}
-
-// Verify GetWindowTree fails for windows that are not descendants of the roots.
-TEST_F(WindowTreeClientTest, CantGetWindowTreeOfOtherRoots) {
- // Create 1 and 2 in the first client and parent both to the root.
- Id window_1_1 = wt_client1()->NewWindow(1);
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_1);
- ASSERT_TRUE(window_1_2);
-
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_2));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
-
- std::vector<TestWindow> windows;
-
- // Should get nothing for the root.
- GetWindowTree(wt2(), root_window_id(), &windows);
- ASSERT_TRUE(windows.empty());
-
- // Should get nothing for window 2.
- GetWindowTree(wt2(), window_1_2, &windows);
- ASSERT_TRUE(windows.empty());
-
- // Should get window 1 if asked for.
- Id window11_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_1));
- GetWindowTree(wt2(), window11_in_wt2, &windows);
- ASSERT_EQ(1u, windows.size());
- EXPECT_EQ(WindowParentToString(window11_in_wt2, kNullParentId),
- windows[0].ToString());
-}
-
-TEST_F(WindowTreeClientTest, EmbedWithSameWindowId) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- changes2()->clear();
-
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(wt1(), window_1_1));
-
- // Client 2 should have been told of the unembed and delete.
- {
- wt_client2_->WaitForChangeCount(2);
- EXPECT_EQ("OnUnembed window=" + IdToString(window_1_1),
- ChangesToDescription1(*changes2())[0]);
- EXPECT_EQ("WindowDeleted window=" + IdToString(window_1_1),
- ChangesToDescription1(*changes2())[1]);
- }
-
- // Client 2 has no root. Verify it can't see window client_id_1(),1 anymore.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt2(), window_1_1, &windows);
- EXPECT_TRUE(windows.empty());
- }
-}
-
-TEST_F(WindowTreeClientTest, EmbedWithSameWindowId2) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- changes2()->clear();
-
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(wt1(), window_1_1));
-
- // Client 2 should have been told about the unembed and delete.
- wt_client2_->WaitForChangeCount(2);
- changes2()->clear();
-
- // Create a window in the third client and parent it to the root.
- Id window_3_1 = wt_client3()->NewWindow(1);
- ASSERT_TRUE(window_3_1);
- // After EstablishThirdClient, window_1_1 should have a ClientWindowId of
- // (client_id_2, 0).
- Id embedded_window_1_1_wt3 = BuildWindowId(client_id_2(), 0);
- ASSERT_TRUE(wt_client3()->AddWindow(embedded_window_1_1_wt3, window_3_1));
-
- // wt1 created window_1_1 but not window_3_1.
- Id window11_in_wt1 = ClientWindowIdFromTransportId(window_1_1);
- Id window31_in_wt1 =
- BuildWindowId(client_id_3(), ClientWindowIdFromTransportId(window_3_1));
-
- // Client 1 should have been told about the add (it owns the window).
- {
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window31_in_wt1) +
- " old_parent=null new_parent=" + IdToString(window11_in_wt1),
- SingleChangeToDescription(*changes1()));
- }
-
- // Embed client_id_1(),1 again.
- {
- changes3()->clear();
-
- // We should get a new client for the new embedding.
- std::unique_ptr<TestWindowTreeClient> client4(
- EstablishClientViaEmbed(wt1(), window_1_1));
- Id embedded_window_1_1_wt4 = BuildWindowId(client_id_3(), 0);
- ASSERT_TRUE(client4.get());
- EXPECT_EQ("[" +
- WindowParentToString(embedded_window_1_1_wt4, kNullParentId) +
- "]",
- ChangeWindowDescription(*client4->tracker()->changes()));
-
- // And 3 should get an unembed and delete.
- wt_client3_->WaitForChangeCount(2);
- EXPECT_EQ("OnUnembed window=" + IdToString(embedded_window_1_1_wt3),
- ChangesToDescription1(*changes3())[0]);
- EXPECT_EQ("WindowDeleted window=" + IdToString(embedded_window_1_1_wt3),
- ChangesToDescription1(*changes3())[1]);
- }
-
- // wt3() has no root. Verify it can't see window client_id_1(),1 anymore.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt3(), window_1_1, &windows);
- EXPECT_TRUE(windows.empty());
- }
-
- // Verify client_id_3(),1 is no longer parented to client_id_1(),1. We have to
- // do this from client_id_1(),1 as wt3() can no longer see client_id_1(),1.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), window_1_1, &windows);
- ASSERT_EQ(1u, windows.size());
- EXPECT_EQ(WindowParentToString(window11_in_wt1, kNullParentId),
- windows[0].ToString());
- }
-
- // Verify wt3() can still see the window it created client_id_3(),1.
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt3(), window_3_1, &windows);
- ASSERT_EQ(1u, windows.size());
- EXPECT_EQ(WindowParentToString(window_3_1, kNullParentId),
- windows[0].ToString());
- }
-}
-
-// Assertions for SetWindowVisibility.
-TEST_F(WindowTreeClientTest, SetWindowVisibility) {
- // Create 1 and 2 in the first client and parent both to the root.
- Id window_1_1 = wt_client1()->NewWindow(1);
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_1);
- ASSERT_TRUE(window_1_2);
-
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), root_window_id(), &windows);
- ASSERT_EQ(2u, windows.size());
- EXPECT_EQ(
- WindowParentToString(root_window_id(), kNullParentId) + " visible=true",
- windows[0].ToString2());
- EXPECT_EQ(
- WindowParentToString(window_1_1, root_window_id()) + " visible=false",
- windows[1].ToString2());
- }
-
- // Show all the windows.
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, true));
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_2, true));
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), root_window_id(), &windows);
- ASSERT_EQ(2u, windows.size());
- EXPECT_EQ(
- WindowParentToString(root_window_id(), kNullParentId) + " visible=true",
- windows[0].ToString2());
- EXPECT_EQ(
- WindowParentToString(window_1_1, root_window_id()) + " visible=true",
- windows[1].ToString2());
- }
-
- // Hide 1.
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, false));
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), window_1_1, &windows);
- ASSERT_EQ(1u, windows.size());
- EXPECT_EQ(
- WindowParentToString(window_1_1, root_window_id()) + " visible=false",
- windows[0].ToString2());
- }
-
- // Attach 2 to 1.
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_1, window_1_2));
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), window_1_1, &windows);
- ASSERT_EQ(2u, windows.size());
- EXPECT_EQ(
- WindowParentToString(window_1_1, root_window_id()) + " visible=false",
- windows[0].ToString2());
- EXPECT_EQ(WindowParentToString(window_1_2, window_1_1) + " visible=true",
- windows[1].ToString2());
- }
-
- // Show 1.
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, true));
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), window_1_1, &windows);
- ASSERT_EQ(2u, windows.size());
- EXPECT_EQ(
- WindowParentToString(window_1_1, root_window_id()) + " visible=true",
- windows[0].ToString2());
- EXPECT_EQ(WindowParentToString(window_1_2, window_1_1) + " visible=true",
- windows[1].ToString2());
- }
-}
-
-// Test that we hear the cursor change in other clients.
-TEST_F(WindowTreeClientTest, SetCursor) {
- // Get a second client to listen in.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- changes2()->clear();
-
- ASSERT_TRUE(wt_client1()->SetCursor(window_1_1,
- ui::CursorData(ui::CursorType::kIBeam)));
- wt_client2_->WaitForChangeCount(1u);
-
- EXPECT_EQ("CursorChanged id=" + IdToString(window_1_1) + " cursor_type=4",
- SingleChangeToDescription(*changes2()));
-}
-
-// Assertions for SetWindowVisibility sending notifications.
-TEST_F(WindowTreeClientTest, SetWindowVisibilityNotifications) {
- // Create client_id_1(),1 and client_id_1(),2. client_id_1(),2 is made a child
- // of client_id_1(),1 and client_id_1(),1 a child of the root.
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, true));
- // Setting to the same value should return true.
- EXPECT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, true));
-
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_2);
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_2, true));
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_1, window_1_2));
-
- // Establish the second client at client_id_1(),2.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClientWithRoot(window_1_2));
-
- // Add client_id_2(),3 as a child of client_id_1(),2.
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(wt_client2()->SetWindowVisibility(window_2_1, true));
- // window_1_2 has a client_id part of client_id_1 in wt2.
- Id window12_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_2));
- ASSERT_TRUE(wt_client2()->AddWindow(window12_in_wt2, window_2_1));
- ASSERT_TRUE(wt_client1()->WaitForAllMessages());
-
- changes2()->clear();
- // Hide client_id_1(),2 from client 1. Client 2 should see this.
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_2, false));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("VisibilityChanged window=" + IdToString(window12_in_wt2) +
- " visible=false",
- SingleChangeToDescription(*changes2()));
- }
-
- changes1()->clear();
- // Show client_id_1(),2 from client 2, client 1 should be notified.
- ASSERT_TRUE(wt_client2()->SetWindowVisibility(window12_in_wt2, true));
- {
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ(
- "VisibilityChanged window=" + IdToString(window_1_2) + " visible=true",
- SingleChangeToDescription(*changes1()));
- }
-
- changes2()->clear();
- // Hide client_id_1(),1, client 2 should be told the draw state changed.
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, false));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("DrawnStateChanged window=" + IdToString(window12_in_wt2) +
- " drawn=false",
- SingleChangeToDescription(*changes2()));
- }
-
- changes2()->clear();
- // Show client_id_1(),1 from client 1. Client 2 should see this.
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, true));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("DrawnStateChanged window=" + IdToString(window12_in_wt2) +
- " drawn=true",
- SingleChangeToDescription(*changes2()));
- }
-
- // Change visibility of client_id_2(),3, client 1 should see this.
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->SetWindowVisibility(window_2_1, false));
- {
- wt_client1_->WaitForChangeCount(1);
- EXPECT_EQ(
- "VisibilityChanged window=" +
- IdToString(BuildWindowId(
- client_id_2(), ClientWindowIdFromTransportId(window_2_1))) +
- " visible=false",
- SingleChangeToDescription(*changes1()));
- }
-
- changes2()->clear();
- // Remove client_id_1(),1 from the root, client 2 should see drawn state
- // changed.
- ASSERT_TRUE(wt_client1()->RemoveWindowFromParent(window_1_1));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("DrawnStateChanged window=" + IdToString(window12_in_wt2) +
- " drawn=false",
- SingleChangeToDescription(*changes2()));
- }
-
- changes2()->clear();
- // Add client_id_1(),1 back to the root, client 2 should see drawn state
- // changed.
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("DrawnStateChanged window=" + IdToString(window12_in_wt2) +
- " drawn=true",
- SingleChangeToDescription(*changes2()));
- }
-}
-
-// Assertions for SetWindowVisibility sending notifications.
-TEST_F(WindowTreeClientTest, SetWindowVisibilityNotifications2) {
- // Create client_id_1(),1 and client_id_1(),2. client_id_1(),2 is made a child
- // of client_id_1(),1 and client_id_1(),1 a child of the root.
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, true));
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_2);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_1, window_1_2));
-
- // Establish the second client at client_id_1(),2.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClientWithRoot(window_1_2));
- // window_1_2 has a client_id part of client_id_1 in wt2.
- Id window12_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_2));
- EXPECT_EQ("OnEmbed drawn=true", SingleChangeToDescription2(*changes2()));
- changes2()->clear();
-
- // Show client_id_1(),2 from client 1. Client 2 should see this.
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_2, true));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("VisibilityChanged window=" + IdToString(window12_in_wt2) +
- " visible=true",
- SingleChangeToDescription(*changes2()));
- }
-}
-
-// Assertions for SetWindowVisibility sending notifications.
-TEST_F(WindowTreeClientTest, SetWindowVisibilityNotifications3) {
- // Create client_id_1(),1 and client_id_1(),2. client_id_1(),2 is made a child
- // of client_id_1(),1 and client_id_1(),1 a child of the root.
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_2);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client1()->AddWindow(window_1_1, window_1_2));
-
- // Establish the second client at client_id_1(),2.
- // TODO(fsamuel): Currently the FrameSinkId maps directly to the server's
- // window ID. This is likely bad from a security perspective and should be
- // fixed.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClientWithRoot(window_1_2));
- // window_1_2 has a client_id part of client_id_1 in wt2.
- Id window12_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_2));
- EXPECT_EQ("OnEmbed drawn=false", SingleChangeToDescription2(*changes2()));
- changes2()->clear();
-
- // Show client_id_1(),1, drawn should be true for client_id_1(),2 (as that is
- // all the child sees).
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_1, true));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("DrawnStateChanged window=" + IdToString(window12_in_wt2) +
- " drawn=true",
- SingleChangeToDescription(*changes2()));
- }
- changes2()->clear();
-
- // Show client_id_1(),2, visible should be true.
- ASSERT_TRUE(wt_client1()->SetWindowVisibility(window_1_2, true));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("VisibilityChanged window=" + IdToString(window12_in_wt2) +
- " visible=true",
- SingleChangeToDescription(*changes2()));
- }
-}
-
-// Tests that when opacity is set on a window, that the calling client is not
-// notified, however children are. Also that setting the same opacity is
-// rejected and no one is notified.
-TEST_F(WindowTreeClientTest, SetOpacityNotifications) {
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClientWithRoot(window_1_1));
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- // window_1_1 has a client_id part of client_id_1 in wt2.
- Id window11_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_1));
- ASSERT_TRUE(wt_client2()->AddWindow(window11_in_wt2, window_2_1));
- ASSERT_TRUE(wt_client1()->WaitForAllMessages());
-
- changes1()->clear();
- changes2()->clear();
- // Change opacity, no notification for calling client.
- ASSERT_TRUE(wt_client1()->SetWindowOpacity(window_1_1, 0.5f));
- EXPECT_TRUE(changes1()->empty());
- wt_client2()->WaitForChangeCount(1);
- EXPECT_EQ("OpacityChanged window_id=" + IdToString(window11_in_wt2) +
- " opacity=0.50",
- SingleChangeToDescription(*changes2()));
-
- changes2()->clear();
- // Attempting to set the same opacity should succeed, but no notification as
- // there was no actual change.
- ASSERT_TRUE(wt_client1()->SetWindowOpacity(window_1_1, 0.5f));
- EXPECT_TRUE(changes1()->empty());
- wt_client2()->WaitForAllMessages();
- EXPECT_TRUE(changes2()->empty());
-}
-
-TEST_F(WindowTreeClientTest, SetWindowProperty) {
- Id window_1_1 = wt_client1()->NewWindow(1);
- ASSERT_TRUE(window_1_1);
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false));
- changes2()->clear();
-
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), root_window_id(), &windows);
- ASSERT_EQ(2u, windows.size());
- EXPECT_EQ(root_window_id(), windows[0].window_id);
- EXPECT_EQ(window_1_1, windows[1].window_id);
- ASSERT_EQ(0u, windows[1].properties.size());
- }
-
- // Set properties on 1.
- changes2()->clear();
- std::vector<uint8_t> one(1, '1');
- ASSERT_TRUE(wt_client1()->SetWindowProperty(window_1_1, "one", &one));
- // window_1_1 has a client_id part of client_id_1 in wt2.
- Id window11_in_wt2 =
- BuildWindowId(client_id_1(), ClientWindowIdFromTransportId(window_1_1));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("PropertyChanged window=" + IdToString(window11_in_wt2) +
- " key=one value=1",
- SingleChangeToDescription(*changes2()));
- }
-
- // Test that our properties exist in the window tree
- {
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), window_1_1, &windows);
- ASSERT_EQ(1u, windows.size());
- ASSERT_EQ(1u, windows[0].properties.size());
- EXPECT_EQ(one, windows[0].properties["one"]);
- }
-
- changes2()->clear();
- // Set back to null.
- ASSERT_TRUE(wt_client1()->SetWindowProperty(window_1_1, "one", NULL));
- {
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("PropertyChanged window=" + IdToString(window11_in_wt2) +
- " key=one value=NULL",
- SingleChangeToDescription(*changes2()));
- }
-}
-
-TEST_F(WindowTreeClientTest, OnEmbeddedAppDisconnected) {
- // Create client 2 and 3.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
- changes2()->clear();
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(wt2(), window_2_1));
-
- // Client 1 should get a hierarchy change for window_2_1.
- wt_client1_->WaitForChangeCount(1);
- changes1()->clear();
-
- // Close client 3. Client 2 (which had previously embedded 3) should
- // be notified of this.
- wt_client3_.reset();
- wt_client2_->WaitForChangeCount(1);
- EXPECT_EQ("OnEmbeddedAppDisconnected window=" + IdToString(window_2_1),
- SingleChangeToDescription(*changes2()));
-
- // The closing is only interesting to the root that did the embedding. Other
- // clients should not be notified of this.
- wt_client1_->WaitForAllMessages();
- EXPECT_TRUE(changes1()->empty());
-}
-
-// Verifies when the parent of an Embed() is destroyed the embedded app gets
-// a WindowDeleted (and doesn't trigger a DCHECK).
-TEST_F(WindowTreeClientTest, OnParentOfEmbedDisconnects) {
- // Create client 2 and 3.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- Id window_2_1 = wt_client2()->NewWindow(1);
- Id window_2_2 = wt_client2()->NewWindow(2);
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(window_2_2);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_1, window_2_2));
- changes2()->clear();
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(wt2(), window_2_2));
- changes3()->clear();
-
- // Close client 2. Client 3 should get a delete (for its root).
- wt_client2_.reset();
- wt_client3_->WaitForChangeCount(1);
- // window_2_2 has a client_id part of client_id_2 in wt3.
- EXPECT_EQ("WindowDeleted window=" +
- IdToString(BuildWindowId(
- client_id_2(), ClientWindowIdFromTransportId(window_2_2))),
- SingleChangeToDescription(*changes3()));
-}
-
-// Verifies WindowTreeImpl doesn't incorrectly erase from its internal
-// map when a window from another client with the same window_id is removed.
-TEST_F(WindowTreeClientTest, DontCleanMapOnDestroy) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- ASSERT_TRUE(wt_client2()->NewWindow(1));
- changes1()->clear();
- wt_client2_.reset();
- wt_client1_->WaitForChangeCount(1);
- // window_1_1 is created by wt1 so client_id part would be 0.
- EXPECT_EQ("OnEmbeddedAppDisconnected window=" +
- IdToString(ClientWindowIdFromTransportId(window_1_1)),
- SingleChangeToDescription(*changes1()));
- std::vector<TestWindow> windows;
- GetWindowTree(wt1(), window_1_1, &windows);
- EXPECT_FALSE(windows.empty());
-}
-
-// Verifies Embed() works when supplying a WindowTreeClient.
-TEST_F(WindowTreeClientTest, EmbedSupplyingWindowTreeClient) {
- ASSERT_TRUE(wt_client1()->NewWindow(1));
-
- TestWindowTreeClient client2;
- mojom::WindowTreeClientPtr client2_ptr;
- mojo::Binding<WindowTreeClient> client2_binding(
- &client2, mojo::MakeRequest(&client2_ptr));
- ASSERT_TRUE(Embed(wt1(), BuildWindowId(client_id_1(), 1),
- std::move(client2_ptr)));
- client2.WaitForOnEmbed();
- EXPECT_EQ("OnEmbed",
- SingleChangeToDescription(*client2.tracker()->changes()));
-}
-
-TEST_F(WindowTreeClientTest, EmbedUsingToken) {
- // Embed client2.
- ASSERT_TRUE(wt_client1()->NewWindow(1));
- TestWindowTreeClient client2;
- mojom::WindowTreeClientPtr client2_ptr;
- mojo::Binding<WindowTreeClient> client2_binding(
- &client2, mojo::MakeRequest(&client2_ptr));
- ASSERT_TRUE(
- Embed(wt1(), BuildWindowId(client_id_1(), 1), std::move(client2_ptr)));
- client2.WaitForOnEmbed();
- EXPECT_EQ("OnEmbed",
- SingleChangeToDescription(*client2.tracker()->changes()));
-
- // Schedule an embed of |client3| from wt1().
- TestWindowTreeClient client3;
- mojom::WindowTreeClientPtr client3_ptr;
- mojo::Binding<WindowTreeClient> client3_binding(
- &client3, mojo::MakeRequest(&client3_ptr));
- base::UnguessableToken token;
- ScheduleEmbed(wt1(), std::move(client3_ptr), &token);
-
- // Have |client2| embed using the token scheduled above.
- const Id window_id = client2.NewWindow(121);
- ASSERT_TRUE(window_id);
- ASSERT_TRUE(EmbedUsingToken(client2.tree(), BuildWindowId(client_id_2(), 121),
- token));
- client3.WaitForOnEmbed();
- EXPECT_EQ("OnEmbed",
- SingleChangeToDescription(*client3.tracker()->changes()));
-
- // EmbedUsingToken() should fail when passed a token that was already used.
- EXPECT_FALSE(EmbedUsingToken(client2.tree(),
- BuildWindowId(client_id_2(), 121), token));
-
- // EmbedUsingToken() should fail when passed a locally generated token.
- EXPECT_FALSE(EmbedUsingToken(client2.tree(),
- BuildWindowId(client_id_2(), 121),
- base::UnguessableToken::Create()));
-}
-
-TEST_F(WindowTreeClientTest, EmbedUsingTokenFailsWithInvalidWindow) {
- // Embed client2.
- ASSERT_TRUE(wt_client1()->NewWindow(1));
- TestWindowTreeClient client2;
- mojom::WindowTreeClientPtr client2_ptr;
- mojo::Binding<WindowTreeClient> client2_binding(
- &client2, mojo::MakeRequest(&client2_ptr));
- ASSERT_TRUE(
- Embed(wt1(), BuildWindowId(client_id_1(), 1), std::move(client2_ptr)));
- client2.WaitForOnEmbed();
- EXPECT_EQ("OnEmbed",
- SingleChangeToDescription(*client2.tracker()->changes()));
-
- // Schedule an embed of |client3| from wt1().
- TestWindowTreeClient client3;
- mojom::WindowTreeClientPtr client3_ptr;
- mojo::Binding<WindowTreeClient> client3_binding(
- &client3, mojo::MakeRequest(&client3_ptr));
- base::UnguessableToken token;
- ScheduleEmbed(wt1(), std::move(client3_ptr), &token);
-
- // This should fail as the window id does not identify a valid window.
- EXPECT_FALSE(EmbedUsingToken(client2.tree(),
- BuildWindowId(client_id_2(), 121), token));
-}
-
-TEST_F(WindowTreeClientTest, EmbedFailsFromOtherClient) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
-
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(wt2(), window_2_1));
-
- Id window_3_3 = wt_client3()->NewWindow(3);
- ASSERT_TRUE(window_3_3);
- // window_2_1 should have client_id of client_id_2 in wt_client3.
- ASSERT_TRUE(wt_client3()->AddWindow(
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_1)),
- window_3_3));
-
- // 2 should not be able to embed in window_3_3 as window_3_3 was not created
- // by
- // 2.
- EXPECT_FALSE(EmbedUrl(connector(), wt2(), test_name(), window_3_3));
-}
-
-// Verifies Embed() from window manager on another clients window works.
-TEST_F(WindowTreeClientTest, EmbedFromOtherClient) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
-
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
- Id window_2_1 = wt_client2()->NewWindow(1);
- ASSERT_TRUE(window_2_1);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
-
- changes2()->clear();
-
- // Establish a third client in window_2_1. window_2_1 has a client_id of
- // client_id_2 for other clients.
- ASSERT_NO_FATAL_FAILURE(EstablishThirdClient(
- wt1(),
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_1))));
-
- ASSERT_TRUE(wt_client2()->WaitForAllMessages());
- EXPECT_EQ(std::string(), SingleChangeToDescription(*changes2()));
-}
-
-TEST_F(WindowTreeClientTest, CantEmbedFromClientRoot) {
- // Shouldn't be able to embed into the root.
- ASSERT_FALSE(EmbedUrl(connector(), wt1(), test_name(), root_window_id()));
-
- // Even though the call above failed a WindowTreeClient was obtained. We need
- // to
- // wait for it else we throw off the next connect.
- WaitForWindowTreeClient();
-
- // Don't allow a client to embed into its own root.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- EXPECT_FALSE(EmbedUrl(connector(), wt2(), test_name(),
- BuildWindowId(client_id_1(), 1)));
-
- // Need to wait for a WindowTreeClient for same reason as above.
- WaitForWindowTreeClient();
-
- Id window_1_2 = wt_client1()->NewWindow(2);
- ASSERT_TRUE(window_1_2);
- ASSERT_TRUE(
- wt_client1()->AddWindow(BuildWindowId(client_id_1(), 1), window_1_2));
- ASSERT_TRUE(wt_client3_.get() == nullptr);
- wt_client3_ = EstablishClientViaEmbedWithPolicyBitmask(wt1(), window_1_2);
- ASSERT_TRUE(wt_client3_.get() != nullptr);
-
- // window_1_2 is ws3's root, so even though v3 is an embed root it should not
- // be able to Embed into itself.
- ASSERT_FALSE(EmbedUrl(connector(), wt3(), test_name(), window_1_2));
-}
-
-// Verifies that a transient window tracks its parent's lifetime.
-TEST_F(WindowTreeClientTest, TransientWindowTracksTransientParentLifetime) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(true));
- Id window_1_1 = BuildWindowId(client_id_1(), 1);
-
- Id window_2_1 = wt_client2()->NewWindow(1);
- Id window_2_2 = wt_client2()->NewWindow(2);
- Id window_2_3 = wt_client2()->NewWindow(3);
- ASSERT_TRUE(window_2_1);
- // window_2_* has a client_id part of client_id_2 in wt1.
- Id window21_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_1));
- Id window22_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_2));
- Id window23_in_wt1 =
- BuildWindowId(client_id_2(), ClientWindowIdFromTransportId(window_2_3));
-
- // root -> window_1_1 -> window_2_1
- // root -> window_1_1 -> window_2_2
- // root -> window_1_1 -> window_2_3
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_1));
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_2));
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_1, window_2_3));
-
- // window_2_2 and window_2_3 now track the lifetime of window_2_1.
- changes1()->clear();
- wt2()->AddTransientWindow(10, window_2_1, window_2_2);
- wt2()->AddTransientWindow(11, window_2_1, window_2_3);
- wt_client1()->WaitForChangeCount(2);
- EXPECT_EQ("AddTransientWindow parent = " + IdToString(window21_in_wt1) +
- " child = " + IdToString(window22_in_wt1),
- ChangesToDescription1(*changes1())[0]);
- EXPECT_EQ("AddTransientWindow parent = " + IdToString(window21_in_wt1) +
- " child = " + IdToString(window23_in_wt1),
- ChangesToDescription1(*changes1())[1]);
-
- changes1()->clear();
- wt2()->RemoveTransientWindowFromParent(12, window_2_3);
- wt_client1()->WaitForChangeCount(1);
- EXPECT_EQ("RemoveTransientWindowFromParent parent = " +
- IdToString(window21_in_wt1) +
- " child = " + IdToString(window23_in_wt1),
- SingleChangeToDescription(*changes1()));
-
- changes1()->clear();
- ASSERT_TRUE(wt_client2()->DeleteWindow(window_2_1));
- wt_client1()->WaitForChangeCount(2);
- EXPECT_EQ("WindowDeleted window=" + IdToString(window22_in_wt1),
- ChangesToDescription1(*changes1())[0]);
- EXPECT_EQ("WindowDeleted window=" + IdToString(window21_in_wt1),
- ChangesToDescription1(*changes1())[1]);
-}
-
-TEST_F(WindowTreeClientTest, Ids) {
- const Id window_1_100 = wt_client1()->NewWindow(100);
- ASSERT_TRUE(window_1_100);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_100));
-
- // Establish the second client at client_id_1(),100.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClientWithRoot(window_1_100));
-
- // client_id_1(),100 is the id in the wt_client1's id space. The new client
- // should see client_id_2(),1 (the server id).
- const Id window_1_100_in_ws2 = BuildWindowId(client_id_1(), 100);
- EXPECT_EQ(window_1_100_in_ws2, wt_client2()->root_window_id());
-
- // The first window created in the second client gets a server id of
- // client_id_2(),1 regardless of the id the client uses.
- const Id window_2_101 = wt_client2()->NewWindow(101);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_100_in_ws2, window_2_101));
- const Id window_2_101_in_ws1 = BuildWindowId(client_id_2(), 101);
- wt_client1()->WaitForChangeCount(1);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_101_in_ws1) +
- " old_parent=null new_parent=" + IdToString(window_1_100),
- SingleChangeToDescription(*changes1()));
- changes1()->clear();
-
- // Change the bounds of window_2_101 and make sure server gets it.
- wt2()->SetWindowBounds(11, window_2_101, gfx::Rect(1, 2, 3, 4),
- base::nullopt);
- ASSERT_TRUE(wt_client2()->WaitForChangeCompleted(11));
- wt_client1()->WaitForChangeCount(1);
- EXPECT_EQ(
- "BoundsChanged window=" + IdToString(window_2_101_in_ws1) +
- " old_bounds=0,0 0x0 new_bounds=1,2 3x4 local_surface_id=(none)",
- SingleChangeToDescription(*changes1()));
- changes2()->clear();
-
- // Remove 2_101 from wm, client1 should see the change.
- wt1()->RemoveWindowFromParent(12, window_2_101_in_ws1);
- ASSERT_TRUE(wt_client1()->WaitForChangeCompleted(12));
- wt_client2()->WaitForChangeCount(1);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_101) +
- " old_parent=" + IdToString(window_1_100_in_ws2) +
- " new_parent=null",
- SingleChangeToDescription(*changes2()));
-}
-
-// Tests that setting capture fails when no input event has occurred, and there
-// is no notification of lost capture.
-TEST_F(WindowTreeClientTest, ExplicitCaptureWithoutInput) {
- Id window_1_1 = wt_client1()->NewWindow(1);
-
- // Add the window to the root, so that they have a Display to handle input
- // capture.
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- changes1()->clear();
-
- // Since there has been no input, capture should not succeed. No lost capture
- // message is expected.
- wt1()->SetCapture(1, window_1_1);
- wt_client1_->WaitForAllMessages();
- EXPECT_TRUE(changes1()->empty());
-
- // Since there is no window with capture, lost capture should not be notified.
- wt1()->ReleaseCapture(3, window_1_1);
- wt_client1_->WaitForAllMessages();
- EXPECT_TRUE(changes1()->empty());
-}
-
-// TODO(jonross): Enable this once apptests can send input events to the server.
-// Enabling capture requires that the client be processing events.
-TEST_F(WindowTreeClientTest, DISABLED_ExplicitCapturePropagation) {
- Id window_1_1 = wt_client1()->NewWindow(1);
- Id window_1_2 = wt_client1()->NewWindow(2);
-
- // Add the windows to the root, so that they have a Display to handle input
- // capture.
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1));
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_2));
-
- changes1()->clear();
- // Window 1 takes capture then Window 2 takes capture.
- // Verify that window 1 has lost capture.
- wt1()->SetCapture(1, window_1_1);
- wt1()->SetCapture(2, window_1_2);
- wt_client1_->WaitForChangeCount(1);
-
- EXPECT_EQ("OnLostCapture window=" + IdToString(window_1_1),
- SingleChangeToDescription(*changes1()));
-
- changes1()->clear();
- // Explicitly releasing capture should not notify of lost capture.
- wt1()->ReleaseCapture(3, window_1_2);
- wt_client1_->WaitForAllMessages();
-
- EXPECT_TRUE(changes1()->empty());
-}
-
-TEST_F(WindowTreeClientTest, SurfaceIdPropagation) {
- const Id window_1_100 = wt_client1()->NewWindow(100);
- ASSERT_TRUE(window_1_100);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_100));
-
- // Establish the second client at client_id_1(),100.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClientWithRoot(window_1_100));
- changes2()->clear();
-
- // client_id_1(),100 is the id in the wt_client1's id space. The new client
- // should see client_id_2(),1 (the server id).
- const Id window_1_100_in_ws2 = BuildWindowId(client_id_1(), 100);
- EXPECT_EQ(window_1_100_in_ws2, wt_client2()->root_window_id());
-
- // Submit a CompositorFrame to window_1_100_in_ws2 (the embedded window in
- // wt2) and make sure the server gets it.
- {
- viz::mojom::CompositorFrameSinkPtr surface_ptr;
- viz::mojom::CompositorFrameSinkClientRequest client_request;
- viz::mojom::CompositorFrameSinkClientPtr surface_client_ptr;
- client_request = mojo::MakeRequest(&surface_client_ptr);
- wt2()->AttachCompositorFrameSink(window_1_100_in_ws2,
- mojo::MakeRequest(&surface_ptr),
- std::move(surface_client_ptr));
- viz::CompositorFrame compositor_frame;
- std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
- gfx::Rect frame_rect(0, 0, 100, 100);
- render_pass->SetNew(1, frame_rect, frame_rect, gfx::Transform());
- compositor_frame.render_pass_list.push_back(std::move(render_pass));
- compositor_frame.metadata.device_scale_factor = 1.f;
- compositor_frame.metadata.begin_frame_ack = viz::BeginFrameAck(0, 1, true);
- viz::LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create());
- surface_ptr->SubmitCompositorFrame(
- local_surface_id, std::move(compositor_frame), base::nullopt, 0);
- }
- // Make sure the parent connection gets the surface ID.
- wt_client1()->WaitForChangeCount(1);
- // Verify that the submitted frame is for |window_2_101|.
- viz::FrameSinkId frame_sink_id =
- changes1()->back().surface_id.frame_sink_id();
- // FrameSinkId is based on window's ClientWindowId.
- EXPECT_EQ(static_cast<size_t>(client_id_2()), frame_sink_id.client_id());
- EXPECT_EQ(0u, frame_sink_id.sink_id());
- changes1()->clear();
-
- // The first window created in the second client gets a server id of
- // client_id_2(),1 regardless of the id the client uses.
- const Id window_2_101 = wt_client2()->NewWindow(101);
- ASSERT_TRUE(wt_client2()->AddWindow(window_1_100_in_ws2, window_2_101));
- const Id window_2_101_in_ws2 = BuildWindowId(client_id_2(), 101);
- wt_client1()->WaitForChangeCount(1);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_101_in_ws2) +
- " old_parent=null new_parent=" + IdToString(window_1_100),
- SingleChangeToDescription(*changes1()));
- // Submit a CompositorFrame to window_2_101_in_ws2 (a regular window in
- // wt2) and make sure client gets it.
- {
- viz::mojom::CompositorFrameSinkPtr surface_ptr;
- viz::mojom::CompositorFrameSinkClientRequest client_request;
- viz::mojom::CompositorFrameSinkClientPtr surface_client_ptr;
- client_request = mojo::MakeRequest(&surface_client_ptr);
- wt2()->AttachCompositorFrameSink(window_2_101,
- mojo::MakeRequest(&surface_ptr),
- std::move(surface_client_ptr));
- viz::CompositorFrame compositor_frame;
- std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
- gfx::Rect frame_rect(0, 0, 100, 100);
- render_pass->SetNew(1, frame_rect, frame_rect, gfx::Transform());
- compositor_frame.render_pass_list.push_back(std::move(render_pass));
- compositor_frame.metadata.device_scale_factor = 1.f;
- compositor_frame.metadata.begin_frame_ack = viz::BeginFrameAck(0, 1, true);
- viz::LocalSurfaceId local_surface_id(2, base::UnguessableToken::Create());
- surface_ptr->SubmitCompositorFrame(
- local_surface_id, std::move(compositor_frame), base::nullopt, 0);
- }
- // Make sure the parent connection gets the surface ID.
- wt_client2()->WaitForChangeCount(1);
- // Verify that the submitted frame is for |window_2_101|.
- viz::FrameSinkId frame_sink_id2 =
- changes2()->back().surface_id.frame_sink_id();
- // FrameSinkId is based on window's ClientWindowId.
- EXPECT_NE(0u, frame_sink_id2.client_id());
- EXPECT_EQ(ClientWindowIdFromTransportId(window_2_101),
- frame_sink_id2.sink_id());
-}
-
-// Verifies when an unknown window with a known child is added to a hierarchy
-// the known child is identified in the WindowData.
-TEST_F(WindowTreeClientTest, AddUnknownWindowKnownParent) {
- const Id window_1_100 = wt_client1()->NewWindow(100);
- ASSERT_TRUE(window_1_100);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_100));
-
- // Establish the second client at client_id_1(),100.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClientWithRoot(window_1_100));
- const Id window_2_1 = wt_client2()->NewWindow(1000);
- const Id window_2_2 = wt_client2()->NewWindow(2000);
- // Add 2_1 to the root, remove 2_1, add 2_1 to 2_2 and then 2_2 to the parent.
- ASSERT_TRUE(
- wt_client2()->AddWindow(wt_client2()->root_window_id(), window_2_1));
- ASSERT_TRUE(wt_client2()->RemoveWindowFromParent(window_2_1));
- ASSERT_TRUE(wt_client2()->AddWindow(window_2_2, window_2_1));
- wt_client1()->WaitForChangeCount(2);
- changes1()->clear();
- ASSERT_TRUE(
- wt_client2()->AddWindow(wt_client2()->root_window_id(), window_2_2));
- wt_client1()->WaitForChangeCount(1);
- const Id window_2_1_in_wm = BuildWindowId(client_id_2(), 1000);
- const Id window_2_2_in_wm = BuildWindowId(client_id_2(), 2000);
- EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_2_in_wm) +
- " old_parent=null new_parent=" + IdToString(window_1_100),
- SingleChangeToDescription(*changes1()));
- EXPECT_EQ("[window=" + IdToString(window_2_2_in_wm) + " parent=" +
- IdToString(window_1_100) + "],[window=" +
- IdToString(window_2_1_in_wm) + " parent=" +
- IdToString(window_2_2_in_wm) + "]",
- ChangeWindowDescription(*changes1()));
-}
-
-TEST_F(WindowTreeClientTest, Transform) {
- const Id window1 = wt_client1()->NewWindow(100);
- ASSERT_TRUE(window1);
- ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window1));
-
- // Establish the second client at |window1|.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondClientWithRoot(window1));
-
- // The first window created in the second client gets a server id of
- // client_id_2(),1 regardless of the id the client uses.
- const Id window1_in_client2 = BuildWindowId(client_id_1(), 100);
- const Id window2 = wt_client2()->NewWindow(11);
- ASSERT_TRUE(wt_client2()->AddWindow(window1_in_client2, window2));
- const Id window2_in_client1 = BuildWindowId(client_id_2(), 11);
- wt_client1()->WaitForChangeCount(1);
- changes1()->clear();
-
- // Change the transform of |window2| and make sure server gets it.
- gfx::Transform transform;
- transform.Scale(SkIntToMScalar(2), SkIntToMScalar(2));
- const uint32_t transform_change_id = 12;
- wt2()->SetWindowTransform(transform_change_id, window2, transform);
- ASSERT_TRUE(wt_client2()->WaitForChangeCompleted(transform_change_id));
- wt_client1()->WaitForChangeCount(1);
- EXPECT_EQ("TransformChanged window_id=" + IdToString(window2_in_client1),
- SingleChangeToDescription(*changes1()));
-}
-
-// TODO(sky): need to better track changes to initial client. For example,
-// that SetBounsdWindows/AddWindow and the like don't result in messages to the
-// originating client.
-
-// TODO(sky): make sure coverage of what was
-// WindowManagerTest.SecondEmbedRoot_InitService and
-// WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window
-// manager
-// tests.
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_tree_factory.cc b/services/ui/ws/window_tree_factory.cc
deleted file mode 100644
index 0021fe46..0000000
--- a/services/ui/ws/window_tree_factory.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/window_tree_factory.h"
-
-#include "base/memory/ptr_util.h"
-#include "services/ui/ws/default_access_policy.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_tree.h"
-#include "services/ui/ws/window_tree_binding.h"
-
-namespace ui {
-namespace ws {
-
-WindowTreeFactory::WindowTreeFactory(WindowServer* window_server,
- const std::string& client_name)
- : window_server_(window_server),
- client_name_(client_name) {}
-
-WindowTreeFactory::~WindowTreeFactory() {}
-
-void WindowTreeFactory::CreateWindowTree(
- mojo::InterfaceRequest<mojom::WindowTree> tree_request,
- mojom::WindowTreeClientPtr client) {
- const bool is_for_embedding = false;
- std::unique_ptr<ws::WindowTree> service(
- new ws::WindowTree(window_server_, is_for_embedding, nullptr,
- base::WrapUnique(new DefaultAccessPolicy)));
- std::unique_ptr<ws::DefaultWindowTreeBinding> binding(
- new ws::DefaultWindowTreeBinding(service.get(), window_server_,
- std::move(tree_request),
- std::move(client)));
- service->set_name(client_name_);
- window_server_->AddTree(std::move(service), std::move(binding), nullptr);
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_tree_factory.h b/services/ui/ws/window_tree_factory.h
deleted file mode 100644
index 66f114fd..0000000
--- a/services/ui/ws/window_tree_factory.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_TREE_FACTORY_H_
-#define SERVICES_UI_WS_WINDOW_TREE_FACTORY_H_
-
-#include "base/macros.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class WindowServer;
-
-class WindowTreeFactory : public ui::mojom::WindowTreeFactory {
- public:
- WindowTreeFactory(WindowServer* window_server,
- const std::string& client_name);
- ~WindowTreeFactory() override;
-
- private:
- // ui::mojom::WindowTreeFactory:
- void CreateWindowTree(mojo::InterfaceRequest<mojom::WindowTree> tree_request,
- mojom::WindowTreeClientPtr client) override;
-
- WindowServer* window_server_;
- const std::string client_name_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTreeFactory);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_TREE_FACTORY_H_
diff --git a/services/ui/ws/window_tree_host_factory.cc b/services/ui/ws/window_tree_host_factory.cc
deleted file mode 100644
index 4675098..0000000
--- a/services/ui/ws/window_tree_host_factory.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2016 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 "services/ui/ws/window_tree_host_factory.h"
-
-#include "services/ui/display/viewport_metrics.h"
-#include "services/ui/ws/display.h"
-#include "services/ui/ws/display_binding.h"
-#include "services/ui/ws/window_server.h"
-
-namespace ui {
-namespace ws {
-
-WindowTreeHostFactory::WindowTreeHostFactory(WindowServer* window_server)
- : window_server_(window_server) {}
-
-WindowTreeHostFactory::~WindowTreeHostFactory() {}
-
-void WindowTreeHostFactory::AddBinding(
- mojom::WindowTreeHostFactoryRequest request) {
- bindings_.AddBinding(this, std::move(request));
-}
-
-void WindowTreeHostFactory::CreateWindowTreeHost(
- mojom::WindowTreeHostRequest host,
- mojom::WindowTreeClientPtr tree_client) {
- Display* ws_display = new Display(window_server_);
-
- std::unique_ptr<DisplayBindingImpl> display_binding(new DisplayBindingImpl(
- std::move(host), ws_display, std::move(tree_client), window_server_));
-
- // Provide an initial size for the WindowTreeHost.
- display::ViewportMetrics metrics;
- metrics.bounds_in_pixels = gfx::Rect(1024, 768);
- metrics.device_scale_factor = 1.0f;
- metrics.ui_scale_factor = 1.0f;
-
- display::Display display(1, metrics.bounds_in_pixels);
- ws_display->SetDisplay(display);
-
- ws_display->Init(metrics, std::move(display_binding));
-}
-
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws/window_tree_host_factory.h b/services/ui/ws/window_tree_host_factory.h
deleted file mode 100644
index de23bde..0000000
--- a/services/ui/ws/window_tree_host_factory.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2016 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.
-
-#ifndef SERVICES_UI_WS_WINDOW_TREE_HOST_FACTORY_H_
-#define SERVICES_UI_WS_WINDOW_TREE_HOST_FACTORY_H_
-
-#include <stdint.h>
-
-#include "mojo/public/cpp/bindings/binding_set.h"
-#include "services/ui/public/interfaces/window_tree_host_factory.mojom.h"
-
-namespace ui {
-namespace ws {
-
-class WindowServer;
-
-class WindowTreeHostFactory : public mojom::WindowTreeHostFactory {
- public:
- explicit WindowTreeHostFactory(WindowServer* window_server);
- ~WindowTreeHostFactory() override;
-
- void AddBinding(mojom::WindowTreeHostFactoryRequest request);
-
- private:
- // mojom::WindowTreeHostFactory implementation.
- void CreateWindowTreeHost(mojom::WindowTreeHostRequest host,
- mojom::WindowTreeClientPtr tree_client) override;
-
- WindowServer* window_server_;
- mojo::BindingSet<mojom::WindowTreeHostFactory> bindings_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTreeHostFactory);
-};
-
-} // namespace ws
-} // namespace ui
-
-#endif // SERVICES_UI_WS_WINDOW_TREE_HOST_FACTORY_H_
diff --git a/services/ui/ws/window_tree_unittest.cc b/services/ui/ws/window_tree_unittest.cc
deleted file mode 100644
index e38542a..0000000
--- a/services/ui/ws/window_tree_unittest.cc
+++ /dev/null
@@ -1,2212 +0,0 @@
-// Copyright 2014 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 "services/ui/ws/window_tree.h"
-
-#include <stdint.h>
-
-#include <string>
-#include <vector>
-
-#include "base/containers/flat_map.h"
-#include "base/macros.h"
-#include "base/memory/ptr_util.h"
-#include "base/strings/stringprintf.h"
-#include "services/service_manager/public/mojom/connector.mojom.h"
-#include "services/ui/common/task_runner_test_base.h"
-#include "services/ui/common/types.h"
-#include "services/ui/common/util.h"
-#include "services/ui/public/interfaces/window_tree.mojom.h"
-#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
-#include "services/ui/ws/default_access_policy.h"
-#include "services/ui/ws/display_manager.h"
-#include "services/ui/ws/ids.h"
-#include "services/ui/ws/platform_display.h"
-#include "services/ui/ws/platform_display_factory.h"
-#include "services/ui/ws/server_window.h"
-#include "services/ui/ws/test_change_tracker.h"
-#include "services/ui/ws/test_server_window_delegate.h"
-#include "services/ui/ws/test_utils.h"
-#include "services/ui/ws/user_display_manager.h"
-#include "services/ui/ws/window_manager_access_policy.h"
-#include "services/ui/ws/window_manager_display_root.h"
-#include "services/ui/ws/window_server.h"
-#include "services/ui/ws/window_server_delegate.h"
-#include "services/ui/ws/window_tree_binding.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/cursor/cursor.h"
-#include "ui/events/event.h"
-#include "ui/events/event_utils.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace ui {
-namespace ws {
-namespace test {
-namespace {
-
-const std::string kNextWindowClientIdString =
- std::to_string(kWindowManagerClientId + 1);
-
-std::string ClientWindowIdToString(const ClientWindowId& id) {
- return base::StringPrintf("%d,%d", id.client_id(), id.sink_id());
-}
-
-ClientWindowId BuildClientWindowId(WindowTree* tree,
- ClientSpecificId window_id) {
- return ClientWindowId(tree->id(), window_id);
-}
-
-// -----------------------------------------------------------------------------
-
-ui::PointerEvent CreatePointerDownEvent(int x, int y) {
- return ui::PointerEvent(ui::TouchEvent(
- ui::ET_TOUCH_PRESSED, gfx::Point(x, y), ui::EventTimeForNow(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
-}
-
-ui::PointerEvent CreatePointerUpEvent(int x, int y) {
- return ui::PointerEvent(ui::TouchEvent(
- ui::ET_TOUCH_RELEASED, gfx::Point(x, y), ui::EventTimeForNow(),
- ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)));
-}
-
-ui::PointerEvent CreatePointerWheelEvent(int x, int y) {
- return ui::PointerEvent(
- ui::MouseWheelEvent(gfx::Vector2d(), gfx::Point(x, y), gfx::Point(x, y),
- ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE));
-}
-
-ui::PointerEvent CreateMouseMoveEvent(int x, int y) {
- return ui::PointerEvent(
- ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(x, y), gfx::Point(x, y),
- ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE));
-}
-
-ui::PointerEvent CreateMouseDownEvent(int x, int y) {
- return ui::PointerEvent(
- ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(x, y), gfx::Point(x, y),
- ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON));
-}
-
-ui::PointerEvent CreateMouseUpEvent(int x, int y) {
- return ui::PointerEvent(
- ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(x, y), gfx::Point(x, y),
- ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
- ui::EF_LEFT_MOUSE_BUTTON));
-}
-
-ServerWindow* GetCaptureWindow(Display* display) {
- return display->window_manager_display_root()
- ->window_manager_state()
- ->capture_window();
-}
-
-class TestMoveLoopWindowManager : public TestWindowManager {
- public:
- TestMoveLoopWindowManager(WindowTree* tree) : tree_(tree) {}
- ~TestMoveLoopWindowManager() override {}
-
- void WmPerformMoveLoop(uint32_t change_id,
- Id window_id,
- mojom::MoveLoopSource source,
- const gfx::Point& cursor_location) override {
- static_cast<mojom::WindowManagerClient*>(tree_)->WmResponse(
- change_id, true);
- }
-
- private:
- WindowTree* tree_;
-
- DISALLOW_COPY_AND_ASSIGN(TestMoveLoopWindowManager);
-};
-
-// This creates a WindowTree similar to how connecting via WindowTreeFactory
-// creates a tree.
-WindowTree* CreateTreeViaFactory(WindowServer* window_server,
- TestWindowTreeBinding** binding) {
- const bool is_for_embedding = false;
- WindowTree* tree = new WindowTree(window_server, is_for_embedding, nullptr,
- std::make_unique<DefaultAccessPolicy>());
- *binding = new TestWindowTreeBinding(tree);
- window_server->AddTree(base::WrapUnique(tree), base::WrapUnique(*binding),
- nullptr);
- return tree;
-}
-
-} // namespace
-
-// -----------------------------------------------------------------------------
-
-class WindowTreeTest : public testing::Test {
- public:
- WindowTreeTest() {}
- ~WindowTreeTest() override {}
-
- ui::CursorType cursor_type() {
- return window_event_targeting_helper_.cursor_type();
- }
- Display* display() { return window_event_targeting_helper_.display(); }
- TestWindowTreeClient* last_window_tree_client() {
- return window_event_targeting_helper_.last_window_tree_client();
- }
- TestWindowTreeClient* wm_client() {
- return window_event_targeting_helper_.wm_client();
- }
- WindowServer* window_server() {
- return window_event_targeting_helper_.window_server();
- }
- WindowTree* wm_tree() {
- return window_event_targeting_helper_.window_server()->GetTreeWithId(
- kWindowManagerClientId);
- }
- WindowTree* last_tree() {
- return window_event_targeting_helper_.last_binding()
- ? window_event_targeting_helper_.last_binding()->tree()
- : nullptr;
- }
-
- // Simulates an event coming from the system. The event is not acked
- // immediately, use AckPreviousEvent() to do that.
- void DispatchEventWithoutAck(const ui::Event& event) {
- std::unique_ptr<Event> tmp = ui::Event::Clone(event);
- display()->ProcessEvent(tmp.get());
- }
-
- void set_window_manager_internal(WindowTree* tree,
- mojom::WindowManager* wm_internal) {
- WindowTreeTestApi(tree).set_window_manager_internal(wm_internal);
- }
-
- void AckPreviousEvent() {
- WindowManagerStateTestApi test_api(
- display()->window_manager_display_root()->window_manager_state());
- while (test_api.tree_awaiting_input_ack()) {
- WindowTreeTestApi(test_api.tree_awaiting_input_ack())
- .AckOldestEvent(mojom::EventResult::HANDLED);
- }
- }
-
- void DispatchEventAndAckImmediately(const ui::Event& event) {
- DispatchEventWithoutAck(event);
- AckPreviousEvent();
- }
-
- // Creates a new window from wm_tree() and embeds a new client in it.
- void SetupEventTargeting(TestWindowTreeClient** out_client,
- WindowTree** window_tree,
- ServerWindow** window);
-
- // Creates a new tree as the specified user. This does what creation via
- // a WindowTreeFactory does.
- WindowTree* CreateNewTree(TestWindowTreeBinding** binding) {
- return CreateTreeViaFactory(window_server(), binding);
- }
-
- TestWindowServerDelegate* test_window_server_delegate() {
- return window_event_targeting_helper_.test_window_server_delegate();
- }
-
- protected:
- WindowEventTargetingHelper window_event_targeting_helper_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(WindowTreeTest);
-};
-
-// Creates a new window in wm_tree(), adds it to the root, embeds a
-// new client in the window and creates a child of said window. |window| is
-// set to the child of |window_tree| that is created.
-void WindowTreeTest::SetupEventTargeting(TestWindowTreeClient** out_client,
- WindowTree** window_tree,
- ServerWindow** window) {
- ServerWindow* embed_window = window_event_targeting_helper_.CreatePrimaryTree(
- gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 50, 50));
- window_event_targeting_helper_.CreateSecondaryTree(
- embed_window, gfx::Rect(20, 20, 20, 20), out_client, window_tree, window);
- FirstRoot(*window_tree)->set_is_activation_parent(true);
-}
-
-// Verifies focus does not change on pointer events.
-TEST_F(WindowTreeTest, DontFocusOnPointer) {
- const ClientWindowId embed_window_id =
- BuildClientWindowId(wm_tree(), kEmbedTreeWindowId);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
- ServerWindow* embed_window = wm_tree()->GetWindowByClientId(embed_window_id);
- ASSERT_TRUE(embed_window);
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true));
- ASSERT_TRUE(FirstRoot(wm_tree()));
- const ClientWindowId wm_root_id = FirstRootId(wm_tree());
- EXPECT_TRUE(wm_tree()->AddWindow(wm_root_id, embed_window_id));
- ServerWindow* wm_root = FirstRoot(wm_tree());
- ASSERT_TRUE(wm_root);
- wm_root->SetBounds(gfx::Rect(0, 0, 100, 100));
- // This tests expects |wm_root| to be a possible target.
- wm_root->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- display()->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- mojom::WindowTreeClientPtr client;
- wm_client()->Bind(mojo::MakeRequest(&client));
- const uint32_t embed_flags = 0;
- wm_tree()->Embed(embed_window_id, std::move(client), embed_flags);
- WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window);
- ASSERT_TRUE(tree1 != nullptr);
- ASSERT_NE(tree1, wm_tree());
-
- embed_window->SetBounds(gfx::Rect(0, 0, 50, 50));
-
- const ClientWindowId child1_id(
- BuildClientWindowId(tree1, kEmbedTreeWindowId));
- EXPECT_TRUE(tree1->NewWindow(child1_id, ServerWindow::Properties()));
- EXPECT_TRUE(tree1->AddWindow(ClientWindowIdForWindow(tree1, embed_window),
- child1_id));
- ServerWindow* child1 = tree1->GetWindowByClientId(child1_id);
- ASSERT_TRUE(child1);
- child1->SetVisible(true);
- child1->SetBounds(gfx::Rect(20, 20, 20, 20));
-
- embed_window->set_is_activation_parent(true);
-
- // Dispatch a pointer event to the child1, focus should be null.
- DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22));
- Display* display1 = tree1->GetDisplay(embed_window);
- EXPECT_EQ(nullptr, display1->GetFocusedWindow());
-}
-
-TEST_F(WindowTreeTest, BasicInputEventTarget) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(
- SetupEventTargeting(&embed_client, &tree, &window));
-
- // Send an event to |v1|. |embed_client| should get the event, not
- // |wm_client|, since |v1| lives inside an embedded window.
- DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22));
- ASSERT_EQ(0u, wm_client()->tracker()->changes()->size());
- ASSERT_EQ(1u, embed_client->tracker()->changes()->size());
- // embed_client created this window that is receiving the event, so client_id
- // part would be reset to 0 before sending back to clients.
- EXPECT_EQ("InputEvent window=0," + std::to_string(kEmbedTreeWindowId) +
- " event_action=" + std::to_string(ui::ET_POINTER_DOWN),
- ChangesToDescription1(*embed_client->tracker()->changes())[0]);
-}
-
-TEST_F(WindowTreeTest, EventDispatcherMouseCursorSourceWindowResetOnRemove) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- window->SetBounds(gfx::Rect(0, 0, 100, 100));
-
- DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22));
-
- WindowManagerState* wms =
- display()->window_manager_display_root()->window_manager_state();
- EXPECT_EQ(window, wms->event_processor()->mouse_cursor_source_window());
-
- window->parent()->Remove(window);
- // The remove should reset the mouse_cursor_source_window(). The important
- // thing is it changes to something other than |window|.
- EXPECT_NE(window, wms->event_processor()->mouse_cursor_source_window());
-}
-
-// Verifies SetChildModalParent() works correctly.
-TEST_F(WindowTreeTest, SetChildModalParent) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- ClientWindowId w1_id;
- ServerWindow* w1 = NewWindowInTreeWithParent(tree, window, &w1_id);
- ASSERT_TRUE(w1);
- ClientWindowId w2_id;
- ServerWindow* w2 = NewWindowInTreeWithParent(tree, window, &w2_id);
- ASSERT_TRUE(w2);
- ASSERT_TRUE(tree->SetChildModalParent(w1_id, w2_id));
- EXPECT_EQ(w2, w1->GetChildModalParent());
- ASSERT_TRUE(tree->SetChildModalParent(w1_id, ClientWindowId()));
- EXPECT_EQ(nullptr, w1->GetChildModalParent());
-}
-
-// Tests that a client can watch for events outside its bounds.
-TEST_F(WindowTreeTest, StartPointerWatcher) {
- // Create an embedded client.
- TestWindowTreeClient* client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window));
-
- // Create an event outside the bounds of the client.
- ui::PointerEvent pointer_down = CreatePointerDownEvent(5, 5);
-
- // Events are not watched before starting a watcher.
- DispatchEventAndAckImmediately(pointer_down);
- ASSERT_EQ(0u, client->tracker()->changes()->size());
-
- // Create a watcher for all events excluding move events.
- WindowTreeTestApi(tree).StartPointerWatcher(false);
-
- // Pointer-down events are sent to the client.
- DispatchEventAndAckImmediately(pointer_down);
- ASSERT_EQ(1u, client->tracker()->changes()->size());
- EXPECT_EQ("PointerWatcherEvent event_action=" +
- std::to_string(ui::ET_POINTER_DOWN) + " window=null",
- ChangesToDescription1(*client->tracker()->changes())[0]);
- client->tracker()->changes()->clear();
-
- // Create a pointer wheel event outside the bounds of the client.
- ui::PointerEvent pointer_wheel = CreatePointerWheelEvent(5, 5);
-
- // Pointer-wheel events are sent to the client.
- DispatchEventAndAckImmediately(pointer_wheel);
- ASSERT_EQ(1u, client->tracker()->changes()->size());
- EXPECT_EQ("PointerWatcherEvent event_action=" +
- std::to_string(ui::ET_POINTER_WHEEL_CHANGED) + " window=null",
- ChangesToDescription1(*client->tracker()->changes())[0]);
- client->tracker()->changes()->clear();
-
- // Stopping the watcher stops sending events to the client.
- WindowTreeTestApi(tree).StopPointerWatcher();
- DispatchEventAndAckImmediately(pointer_down);
- ASSERT_EQ(0u, client->tracker()->changes()->size());
- DispatchEventAndAckImmediately(pointer_wheel);
- ASSERT_EQ(0u, client->tracker()->changes()->size());
-
- // Create a watcher for all events including move events.
- WindowTreeTestApi(tree).StartPointerWatcher(true);
-
- // Pointer-wheel events are sent to the client.
- DispatchEventAndAckImmediately(pointer_wheel);
- ASSERT_EQ(1u, client->tracker()->changes()->size());
- EXPECT_EQ("PointerWatcherEvent event_action=" +
- std::to_string(ui::ET_POINTER_WHEEL_CHANGED) + " window=null",
- ChangesToDescription1(*client->tracker()->changes())[0]);
-}
-
-// Verifies PointerWatcher sees windows known to it.
-TEST_F(WindowTreeTest, PointerWatcherGetsWindow) {
- // Create an embedded client.
- TestWindowTreeClient* client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window));
-
- WindowTreeTestApi(wm_tree()).StartPointerWatcher(false);
-
- // Create and dispatch an event that targets the embedded window.
- ui::PointerEvent pointer_down = CreatePointerDownEvent(25, 25);
- DispatchEventAndAckImmediately(pointer_down);
-
- ASSERT_EQ(1u, wm_client()->tracker()->changes()->size());
- EXPECT_EQ(
- "PointerWatcherEvent event_action=" +
- std::to_string(ui::ET_POINTER_DOWN) + " window=" +
- ClientWindowIdToString(ClientWindowIdForWindow(wm_tree(), window)),
- ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
-}
-
-// Tests that a client using a pointer watcher does not receive events that
-// don't match the |want_moves| setting.
-TEST_F(WindowTreeTest, StartPointerWatcherNonMatching) {
- // Create an embedded client.
- TestWindowTreeClient* client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window));
-
- // Create a watcher for all events excluding move events.
- WindowTreeTestApi(tree).StartPointerWatcher(false);
-
- // Pointer-move events are not sent to the client, since they don't match.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
- ASSERT_EQ(0u, client->tracker()->changes()->size());
-}
-
-// Tests that an event that both hits a client window and matches a pointer
-// watcher is sent only once to the client.
-TEST_F(WindowTreeTest, StartPointerWatcherSendsOnce) {
- // Create an embedded client.
- TestWindowTreeClient* client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&client, &tree, &window));
-
- // Create a watcher for all events excluding move events (which do not
- // cause focus changes).
- WindowTreeTestApi(tree).StartPointerWatcher(false);
-
- // Create an event inside the bounds of the client.
- ui::PointerEvent pointer_up = CreatePointerUpEvent(25, 25);
-
- // The event is dispatched once, with a flag set that it matched the pointer
- // watcher.
- DispatchEventAndAckImmediately(pointer_up);
- ASSERT_EQ(1u, client->tracker()->changes()->size());
- // clients that created this window is receiving the event, so client_id part
- // would be reset to 0 before sending back to clients.
- EXPECT_EQ("InputEvent window=0," + std::to_string(kEmbedTreeWindowId) +
- " event_action=" + std::to_string(ui::ET_POINTER_UP) +
- " matches_pointer_watcher",
- SingleChangeToDescription(*client->tracker()->changes()));
-}
-
-// Tests that a pointer watcher cannot watch keystrokes.
-TEST_F(WindowTreeTest, StartPointerWatcherKeyEventsDisallowed) {
- TestWindowTreeBinding* other_binding;
- WindowTree* other_tree = CreateNewTree(&other_binding);
- other_binding->client()->tracker()->changes()->clear();
-
- WindowTreeTestApi(other_tree).StartPointerWatcher(false);
- ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
- DispatchEventAndAckImmediately(key_pressed);
- EXPECT_EQ(0u, other_binding->client()->tracker()->changes()->size());
- EXPECT_EQ("InputEvent window=" + std::to_string(kWindowServerClientId) +
- ",3 event_action=" + std::to_string(ui::ET_KEY_PRESSED),
- SingleChangeToDescription(*wm_client()->tracker()->changes()));
-
- WindowTreeTestApi(wm_tree()).StartPointerWatcher(false);
- ui::KeyEvent key_released(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE);
- DispatchEventAndAckImmediately(key_released);
- EXPECT_EQ(0u, other_binding->client()->tracker()->changes()->size());
-}
-
-TEST_F(WindowTreeTest, KeyEventSentToWindowManagerWhenNothingFocused) {
- ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
- DispatchEventAndAckImmediately(key_pressed);
- EXPECT_EQ("InputEvent window=" + std::to_string(kWindowServerClientId) +
- ",3 event_action=" + std::to_string(ui::ET_KEY_PRESSED),
- SingleChangeToDescription(*wm_client()->tracker()->changes()));
-}
-
-TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- // Like in BasicInputEventTarget, we send a pointer down event to be
- // dispatched. This is only to place the mouse cursor over that window though.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22));
-
- // Set the cursor on the parent as that is where the cursor is picked up from.
- window->parent()->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
-
- // Because the cursor is over the window when SetCursor was called, we should
- // have immediately changed the cursor.
- EXPECT_EQ(ui::CursorType::kIBeam, cursor_type());
-}
-
-TEST_F(WindowTreeTest, CursorChangesWhenEnteringWindowWithDifferentCursor) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- // Let's create a pointer event outside the window and then move the pointer
- // inside.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
- // Set the cursor on the parent as that is where the cursor is picked up from.
- window->parent()->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- EXPECT_EQ(ui::CursorType::kPointer, cursor_type());
-
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22));
- EXPECT_EQ(ui::CursorType::kIBeam, cursor_type());
-}
-
-TEST_F(WindowTreeTest, DragOutsideWindow) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- // Start with the cursor outside the window. Setting the cursor shouldn't
- // change the cursor.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
- // Set the cursor on the parent as that is where the cursor is picked up from.
- window->parent()->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- EXPECT_EQ(ui::CursorType::kPointer, cursor_type());
-
- // Move the pointer to the inside of the window
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(21, 22));
- EXPECT_EQ(ui::CursorType::kIBeam, cursor_type());
-
- // Start the drag.
- DispatchEventAndAckImmediately(CreateMouseDownEvent(21, 22));
- EXPECT_EQ(ui::CursorType::kIBeam, cursor_type());
-
- // Move the cursor (mouse is still down) outside the window.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
- EXPECT_EQ(ui::CursorType::kIBeam, cursor_type());
-
- // Release the cursor. We should now adapt the cursor of the window
- // underneath the pointer.
- DispatchEventAndAckImmediately(CreateMouseUpEvent(5, 5));
- EXPECT_EQ(ui::CursorType::kPointer, cursor_type());
-}
-
-TEST_F(WindowTreeTest, ChangingWindowBoundsChangesCursor) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- // Put the cursor just outside the bounds of the window.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(41, 41));
- // Sets the cursor on the root as that is where the cursor is picked up from.
- window->parent()->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- EXPECT_EQ(ui::CursorType::kPointer, cursor_type());
-
- // Expand the bounds of the window so they now include where the cursor now
- // is.
- window->SetBounds(gfx::Rect(20, 20, 25, 25));
- EXPECT_EQ(ui::CursorType::kIBeam, cursor_type());
-
- // Contract the bounds again.
- window->SetBounds(gfx::Rect(20, 20, 20, 20));
- EXPECT_EQ(ui::CursorType::kPointer, cursor_type());
-}
-
-TEST_F(WindowTreeTest, WindowReorderingChangesCursor) {
- // Setup two trees parented to the root with the same bounds.
- ServerWindow* embed_window1 =
- window_event_targeting_helper_.CreatePrimaryTree(
- gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 50, 50));
- ServerWindow* embed_window2 =
- window_event_targeting_helper_.CreatePrimaryTree(
- gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 50, 50));
-
- ASSERT_EQ(embed_window1->parent(), embed_window2->parent());
- embed_window1->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- embed_window2->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- embed_window1->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- embed_window2->SetCursor(ui::CursorData(ui::CursorType::kCross));
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
- // Cursor should match that of top-most window, which is |embed_window2|.
- EXPECT_EQ(ui::CursorType::kCross, cursor_type());
- // Move |embed_window1| on top, cursor should now match it.
- embed_window1->parent()->StackChildAtTop(embed_window1);
- EXPECT_EQ(ui::CursorType::kIBeam, cursor_type());
-}
-
-// Assertions around moving cursor between trees with roots.
-TEST_F(WindowTreeTest, CursorMultipleTrees) {
- // Setup two trees parented to the root with the same bounds.
- ServerWindow* embed_window1 =
- window_event_targeting_helper_.CreatePrimaryTree(
- gfx::Rect(0, 0, 200, 200), gfx::Rect(0, 0, 10, 10));
- ServerWindow* embed_window2 =
- window_event_targeting_helper_.CreatePrimaryTree(
- gfx::Rect(0, 0, 200, 200), gfx::Rect(20, 20, 20, 20));
- embed_window1->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- embed_window2->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- embed_window2->parent()->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- embed_window1->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
- embed_window2->SetCursor(ui::CursorData(ui::CursorType::kCross));
- embed_window1->parent()->SetCursor(ui::CursorData(ui::CursorType::kCopy));
-
- // Create a child of |embed_window1|.
- ServerWindow* embed_window1_child = NewWindowInTreeWithParent(
- window_server()->GetTreeWithRoot(embed_window1), embed_window1);
- ASSERT_TRUE(embed_window1_child);
- embed_window1_child->SetBounds(gfx::Rect(0, 0, 10, 10));
- embed_window1_child->SetVisible(true);
-
- // Move mouse into |embed_window1|.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
- EXPECT_EQ(ui::CursorType::kIBeam, cursor_type());
-
- // Move mouse into |embed_window2|.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(25, 25));
- EXPECT_EQ(ui::CursorType::kCross, cursor_type());
-
- // Move mouse into area between, which should use cursor set on parent.
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(15, 15));
- EXPECT_EQ(ui::CursorType::kCopy, cursor_type());
-}
-
-TEST_F(WindowTreeTest, EventAck) {
- const ClientWindowId embed_window_id =
- BuildClientWindowId(wm_tree(), kEmbedTreeWindowId);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true));
- ASSERT_TRUE(FirstRoot(wm_tree()));
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id));
- ASSERT_EQ(1u, display()->root_window()->children().size());
- ServerWindow* wm_root = FirstRoot(wm_tree());
- ASSERT_TRUE(wm_root);
- wm_root->SetBounds(gfx::Rect(0, 0, 100, 100));
- // This tests expects |wm_root| to be a possible target.
- wm_root->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
-
- wm_client()->tracker()->changes()->clear();
- DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22));
- ASSERT_EQ(1u, wm_client()->tracker()->changes()->size());
- EXPECT_EQ("InputEvent window=" + std::to_string(kWindowServerClientId) +
- ",3 event_action=" + std::to_string(ui::ET_POINTER_MOVED),
- ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
- wm_client()->tracker()->changes()->clear();
-
- // Send another event. This event shouldn't reach the client.
- DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22));
- ASSERT_EQ(0u, wm_client()->tracker()->changes()->size());
-
- // Ack the first event. That should trigger the dispatch of the second event.
- AckPreviousEvent();
- ASSERT_EQ(1u, wm_client()->tracker()->changes()->size());
- EXPECT_EQ("InputEvent window=" + std::to_string(kWindowServerClientId) +
- ",3 event_action=" + std::to_string(ui::ET_POINTER_MOVED),
- ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
-}
-
-TEST_F(WindowTreeTest, RemoveWindowFromParentWithQueuedEvent) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- window->SetBounds(gfx::Rect(0, 0, 100, 100));
- window->set_is_activation_parent(true);
- ClientWindowId w1_id;
- ServerWindow* w1 =
- NewWindowInTreeWithParent(tree, window, &w1_id, gfx::Rect(0, 0, 20, 20));
- ASSERT_TRUE(w1);
- ClientWindowId w2_id;
- ServerWindow* w2 =
- NewWindowInTreeWithParent(tree, window, &w2_id, gfx::Rect(25, 0, 20, 20));
- ASSERT_TRUE(w2);
-
- DispatchEventAndAckImmediately(CreateMouseMoveEvent(5, 5));
-
- // This moves between |w1| and |w2|, which results in two events (move and
- // enter).
- DispatchEventWithoutAck(CreateMouseMoveEvent(27, 5));
-
- // There should be an event in flight for the move.
- EXPECT_TRUE(WindowTreeTestApi(tree).HasEventInFlight());
-
- // Simulate the client taking too long.
- WindowManagerStateTestApi wm_state_test_api(
- wm_tree()->window_manager_state());
- wm_state_test_api.OnEventAckTimeout(tree->id());
-
- // There should be an event queued (for the enter).
- EXPECT_EQ(1u, WindowTreeTestApi(tree).event_queue_size());
-
- // Remove the window from the hierarchy, which should make it so the client
- // doesn't get the queued event.
- w2->parent()->Remove(w2);
-
- // Ack the in flight event, which should trigger processing the queued event.
- // Because |w2| was removed, the event should not be dispatched to the client
- // and WindowManagerState should no longer be waiting (because there are no
- // inflight events).
- WindowTreeTestApi(tree).AckOldestEvent();
- EXPECT_FALSE(WindowTreeTestApi(tree).HasEventInFlight());
- EXPECT_EQ(nullptr, wm_state_test_api.tree_awaiting_input_ack());
-}
-
-// Establish client, call Embed() in WM, make sure to get FrameSinkId.
-TEST_F(WindowTreeTest, Embed) {
- const ClientWindowId embed_window_id =
- BuildClientWindowId(wm_tree(), kEmbedTreeWindowId);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
- ServerWindow* embed_window = wm_tree()->GetWindowByClientId(embed_window_id);
- ASSERT_TRUE(embed_window);
- const ClientWindowId wm_root_id = FirstRootId(wm_tree());
- EXPECT_TRUE(wm_tree()->AddWindow(wm_root_id, embed_window_id));
- ServerWindow* wm_root = FirstRoot(wm_tree());
- ASSERT_TRUE(wm_root);
- mojom::WindowTreeClientPtr client;
- wm_client()->Bind(mojo::MakeRequest(&client));
- const uint32_t embed_flags = 0;
- wm_tree()->Embed(embed_window_id, std::move(client), embed_flags);
- ASSERT_EQ(1u, wm_client()->tracker()->changes()->size())
- << SingleChangeToDescription(*wm_client()->tracker()->changes());
- // The window manager should be told about the FrameSinkId of the embedded
- // window. Clients that created this window is receiving the event, so
- // client_id part would be reset to 0 before sending back to clients.
- EXPECT_EQ(
- base::StringPrintf(
- "OnFrameSinkIdAllocated window=%s %s",
- ClientWindowIdToString(ClientWindowId(0, embed_window_id.sink_id()))
- .c_str(),
- embed_window->frame_sink_id().ToString().c_str()),
- SingleChangeToDescription(*wm_client()->tracker()->changes()));
-}
-
-TEST_F(WindowTreeTest, DisallowSetSystemModalForEmbedded) {
- const ClientWindowId embed_window_id =
- BuildClientWindowId(wm_tree(), kEmbedTreeWindowId);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
- ServerWindow* embed_window = wm_tree()->GetWindowByClientId(embed_window_id);
- ASSERT_TRUE(embed_window);
- const ClientWindowId wm_root_id = FirstRootId(wm_tree());
- EXPECT_TRUE(wm_tree()->AddWindow(wm_root_id, embed_window_id));
- ServerWindow* wm_root = FirstRoot(wm_tree());
- ASSERT_TRUE(wm_root);
- mojom::WindowTreeClientPtr client;
- wm_client()->Bind(mojo::MakeRequest(&client));
- const uint32_t embed_flags = 0;
- ASSERT_TRUE(
- wm_tree()->Embed(embed_window_id, std::move(client), embed_flags));
- ASSERT_TRUE(last_tree());
- EXPECT_FALSE(last_tree()->SetModalType(
- ClientWindowIdForWindow(last_tree(), embed_window), MODAL_TYPE_SYSTEM));
-}
-
-TEST_F(WindowTreeTest, ModalTypeSystemToModalTypeNone) {
- const ClientWindowId test_window_id = BuildClientWindowId(wm_tree(), 21);
- EXPECT_TRUE(wm_tree()->NewWindow(test_window_id, ServerWindow::Properties()));
- ServerWindow* test_window = wm_tree()->GetWindowByClientId(test_window_id);
- ASSERT_TRUE(test_window);
- test_window->SetVisible(true);
- const ClientWindowId wm_root_id = FirstRootId(wm_tree());
- EXPECT_TRUE(wm_tree()->AddWindow(wm_root_id, test_window_id));
- EXPECT_TRUE(wm_tree()->SetModalType(test_window_id, MODAL_TYPE_SYSTEM));
- WindowManagerState* wms =
- display()->window_manager_display_root()->window_manager_state();
- ModalWindowControllerTestApi modal_window_controller_test_api(
- EventProcessorTestApi(wms->event_processor()).modal_window_controller());
- EXPECT_EQ(test_window,
- modal_window_controller_test_api.GetActiveSystemModalWindow());
- EXPECT_TRUE(wm_tree()->SetModalType(test_window_id, MODAL_TYPE_NONE));
- EXPECT_EQ(nullptr,
- modal_window_controller_test_api.GetActiveSystemModalWindow());
-}
-
-TEST_F(WindowTreeTest, ModalTypeSystemUnparentedThenParented) {
- const ClientWindowId test_window_id = BuildClientWindowId(wm_tree(), 21);
- EXPECT_TRUE(wm_tree()->NewWindow(test_window_id, ServerWindow::Properties()));
- ServerWindow* test_window = wm_tree()->GetWindowByClientId(test_window_id);
- ASSERT_TRUE(test_window);
- test_window->SetVisible(true);
- const ClientWindowId wm_root_id = FirstRootId(wm_tree());
- EXPECT_TRUE(wm_tree()->SetModalType(test_window_id, MODAL_TYPE_SYSTEM));
- WindowManagerState* wms =
- display()->window_manager_display_root()->window_manager_state();
- ModalWindowControllerTestApi modal_window_controller_test_api(
- EventProcessorTestApi(wms->event_processor()).modal_window_controller());
- EXPECT_EQ(nullptr,
- modal_window_controller_test_api.GetActiveSystemModalWindow());
- EXPECT_TRUE(wm_tree()->AddWindow(wm_root_id, test_window_id));
- EXPECT_EQ(test_window,
- modal_window_controller_test_api.GetActiveSystemModalWindow());
- EXPECT_TRUE(wm_tree()->SetModalType(test_window_id, MODAL_TYPE_NONE));
- EXPECT_EQ(nullptr,
- modal_window_controller_test_api.GetActiveSystemModalWindow());
-}
-
-// Establish client, call NewTopLevelWindow(), make sure get id, and make
-// sure client paused.
-TEST_F(WindowTreeTest, NewTopLevelWindow) {
- TestWindowManager wm_internal;
- set_window_manager_internal(wm_tree(), &wm_internal);
-
- TestWindowTreeBinding* child_binding;
- WindowTree* child_tree = CreateNewTree(&child_binding);
- child_binding->client()->tracker()->changes()->clear();
- child_binding->client()->set_record_on_change_completed(true);
-
- // Create a new top level window.
- base::flat_map<std::string, std::vector<uint8_t>> properties;
- const uint32_t initial_change_id = 17;
- // Explicitly use an id that does not contain the client id.
- const ClientWindowId embed_window_id2_in_child(child_tree->id(), 27);
- static_cast<mojom::WindowTree*>(child_tree)
- ->NewTopLevelWindow(
- initial_change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- properties);
-
- // The binding should be paused until the wm acks the change.
- uint32_t wm_change_id = 0u;
- ASSERT_TRUE(wm_internal.did_call_create_top_level_window(&wm_change_id));
- EXPECT_TRUE(child_binding->is_paused());
-
- // Create the window for |embed_window_id2_in_child|.
- const ClientWindowId embed_window_id2 = BuildClientWindowId(wm_tree(), 2);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id2, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id2, true));
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id2));
-
- // Ack the change, which should resume the binding.
- child_binding->client()->tracker()->changes()->clear();
- static_cast<mojom::WindowManagerClient*>(wm_tree())
- ->OnWmCreatedTopLevelWindow(
- wm_change_id,
- wm_tree()->ClientWindowIdToTransportId(embed_window_id2));
-
- ServerWindow* embed_window = wm_tree()->GetWindowByClientId(embed_window_id2);
- ASSERT_TRUE(embed_window);
- EXPECT_EQ(embed_window_id2_in_child, embed_window->frame_sink_id());
- EXPECT_FALSE(child_binding->is_paused());
- // TODO(fsamuel): Currently the FrameSinkId maps directly to the server's
- // window ID. This is likely bad from a security perspective and should be
- // fixed.
- EXPECT_EQ(base::StringPrintf(
- "TopLevelCreated id=17 window_id=%s drawn=true",
- ClientWindowIdToString(
- ClientWindowId(0, embed_window_id2_in_child.sink_id()))
- .c_str()),
- SingleChangeToDescription(
- *child_binding->client()->tracker()->changes()));
- child_binding->client()->tracker()->changes()->clear();
-
- // Change the visibility of the window from the owner and make sure the
- // client sees the right id.
- EXPECT_TRUE(embed_window->visible());
- ASSERT_TRUE(wm_tree()->SetWindowVisibility(
- ClientWindowIdForWindow(wm_tree(), embed_window), false));
- EXPECT_FALSE(embed_window->visible());
- EXPECT_EQ("VisibilityChanged window=" +
- ClientWindowIdToString(
- ClientWindowId(0, embed_window_id2_in_child.sink_id())) +
- " visible=false",
- SingleChangeToDescription(
- *child_binding->client()->tracker()->changes()));
-
- // Set the visibility from the child using the client assigned id.
- ASSERT_TRUE(child_tree->SetWindowVisibility(embed_window_id2_in_child, true));
- EXPECT_TRUE(embed_window->visible());
-}
-
-// Tests that only the capture window can release capture.
-TEST_F(WindowTreeTest, ExplicitSetCapture) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
- const ServerWindow* root_window = *tree->roots().begin();
- tree->AddWindow(FirstRootId(tree), ClientWindowIdForWindow(tree, window));
- window->SetBounds(gfx::Rect(0, 0, 100, 100));
- ASSERT_TRUE(tree->GetDisplay(window));
-
- // Set capture.
- mojom::WindowTree* mojom_window_tree = static_cast<mojom::WindowTree*>(tree);
- uint32_t change_id = 42;
- mojom_window_tree->SetCapture(
- change_id, tree->ClientWindowIdToTransportId(window->frame_sink_id()));
- Display* display = tree->GetDisplay(window);
- EXPECT_EQ(window, GetCaptureWindow(display));
-
- // Only the capture window should be able to release capture
- mojom_window_tree->ReleaseCapture(
- ++change_id,
- tree->ClientWindowIdToTransportId(root_window->frame_sink_id()));
- EXPECT_EQ(window, GetCaptureWindow(display));
-
- mojom_window_tree->ReleaseCapture(
- ++change_id, tree->ClientWindowIdToTransportId(window->frame_sink_id()));
- EXPECT_EQ(nullptr, GetCaptureWindow(display));
-}
-
-// Tests that while a client is interacting with input, that capture is not
-// allowed for invisible windows.
-TEST_F(WindowTreeTest, CaptureWindowMustBeVisible) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
- tree->AddWindow(FirstRootId(tree), ClientWindowIdForWindow(tree, window));
- window->SetBounds(gfx::Rect(0, 0, 100, 100));
- ASSERT_TRUE(tree->GetDisplay(window));
-
- DispatchEventWithoutAck(CreatePointerDownEvent(10, 10));
- window->SetVisible(false);
- EXPECT_FALSE(tree->SetCapture(ClientWindowIdForWindow(tree, window)));
- EXPECT_NE(window, GetCaptureWindow(tree->GetDisplay(window)));
-}
-
-// Tests that showing a modal window releases the capture if the capture is on a
-// descendant of the modal parent.
-TEST_F(WindowTreeTest, ShowModalWindowWithDescendantCapture) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* w1 = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1));
-
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- const ServerWindow* root_window = *tree->roots().begin();
- ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
- ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
- Display* display = tree->GetDisplay(w1);
-
- // Create |w11| as a child of |w1| and make it visible.
- ClientWindowId w11_id = BuildClientWindowId(tree, 11);
- ASSERT_TRUE(tree->NewWindow(w11_id, ServerWindow::Properties()));
- ServerWindow* w11 = tree->GetWindowByClientId(w11_id);
- w11->SetBounds(gfx::Rect(10, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(w1_id, w11_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true));
-
- // Create |w2| as a child of |root_window| and modal to |w1| and leave it
- // hidden.
- ClientWindowId w2_id = BuildClientWindowId(tree, 3);
- ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
- ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
- ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
- ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW));
-
- // Set capture to |w11|.
- DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
- ASSERT_TRUE(tree->SetCapture(w11_id));
- EXPECT_EQ(w11, GetCaptureWindow(display));
- AckPreviousEvent();
-
- // Make |w2| visible. This should release capture as capture is set to a
- // descendant of the modal parent.
- ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
- EXPECT_EQ(nullptr, GetCaptureWindow(display));
-}
-
-// Tests that setting a visible window as modal releases the capture if the
-// capture is on a descendant of the modal parent.
-TEST_F(WindowTreeTest, VisibleWindowToModalWithDescendantCapture) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* w1 = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1));
-
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- const ServerWindow* root_window = *tree->roots().begin();
- ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
- ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
- Display* display = tree->GetDisplay(w1);
-
- // Create |w11| as a child of |w1| and make it visible.
- ClientWindowId w11_id = BuildClientWindowId(tree, 11);
- ASSERT_TRUE(tree->NewWindow(w11_id, ServerWindow::Properties()));
- ServerWindow* w11 = tree->GetWindowByClientId(w11_id);
- w11->SetBounds(gfx::Rect(10, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(w1_id, w11_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w11_id, true));
-
- // Create |w2| as a child of |root_window| and make it visible.
- ClientWindowId w2_id = BuildClientWindowId(tree, 3);
- ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
- ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
-
- // Set capture to |w11|.
- DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
- ASSERT_TRUE(tree->SetCapture(w11_id));
- EXPECT_EQ(w11, GetCaptureWindow(display));
- AckPreviousEvent();
-
- // Set |w2| modal to |w1|. This should release the capture as the capture is
- // set to a descendant of the modal parent.
- ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
- ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW));
- EXPECT_EQ(nullptr, GetCaptureWindow(display));
-}
-
-// Tests that showing a modal window does not change capture if the capture is
-// not on a descendant of the modal parent.
-TEST_F(WindowTreeTest, ShowModalWindowWithNonDescendantCapture) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* w1 = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1));
-
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- const ServerWindow* root_window = *tree->roots().begin();
- ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
- ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
- Display* display = tree->GetDisplay(w1);
-
- // Create |w2| as a child of |root_window| and modal to |w1| and leave it
- // hidden.
- ClientWindowId w2_id = BuildClientWindowId(tree, kEmbedTreeWindowId + 1);
- ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
- ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
- ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
- ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW));
-
- // Create |w3| as a child of |root_window| and make it visible.
- ClientWindowId w3_id = BuildClientWindowId(tree, kEmbedTreeWindowId + 2);
- ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties()));
- ServerWindow* w3 = tree->GetWindowByClientId(w3_id);
- w3->SetBounds(gfx::Rect(70, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true));
-
- // Set capture to |w3|.
- DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
- ASSERT_TRUE(tree->SetCapture(w3_id));
- EXPECT_EQ(w3, GetCaptureWindow(display));
- AckPreviousEvent();
-
- // Make |w2| visible. This should not change the capture as the capture is not
- // set to a descendant of the modal parent.
- ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
- EXPECT_EQ(w3, GetCaptureWindow(display));
-}
-
-// Tests that setting a visible window as modal does not change the capture if
-// the capture is not set to a descendant of the modal parent.
-TEST_F(WindowTreeTest, VisibleWindowToModalWithNonDescendantCapture) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* w1 = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1));
-
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- const ServerWindow* root_window = *tree->roots().begin();
- ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
- ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
- Display* display = tree->GetDisplay(w1);
-
- // Create |w2| and |w3| as children of |root_window| and make them visible.
- ClientWindowId w2_id = BuildClientWindowId(tree, kEmbedTreeWindowId + 1);
- ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
- ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
-
- ClientWindowId w3_id = BuildClientWindowId(tree, kEmbedTreeWindowId + 2);
- ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties()));
- ServerWindow* w3 = tree->GetWindowByClientId(w3_id);
- w3->SetBounds(gfx::Rect(70, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true));
-
- // Set capture to |w3|.
- DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
- ASSERT_TRUE(tree->SetCapture(w3_id));
- EXPECT_EQ(w3, GetCaptureWindow(display));
- AckPreviousEvent();
-
- // Set |w2| modal to |w1|. This should not release the capture as the capture
- // is not set to a descendant of the modal parent.
- ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
- ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW));
- EXPECT_EQ(w3, GetCaptureWindow(display));
-}
-
-// Tests that showing a system modal window releases the capture.
-TEST_F(WindowTreeTest, ShowSystemModalWindowWithCapture) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* w1 = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1));
-
- w1->SetBounds(gfx::Rect(10, 10, 10, 10));
- const ServerWindow* root_window = *tree->roots().begin();
- ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
- ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
- Display* display = tree->GetDisplay(w1);
-
- // Create a system modal window |w2| as a child of |root_window| and leave it
- // hidden.
- ClientWindowId w2_id = BuildClientWindowId(tree, kEmbedTreeWindowId + 1);
- ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
- ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
- w2->SetBounds(gfx::Rect(30, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
- ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_SYSTEM));
-
- // Set capture to |w1|.
- DispatchEventWithoutAck(CreatePointerDownEvent(15, 15));
- ASSERT_TRUE(tree->SetCapture(w1_id));
- EXPECT_EQ(w1, GetCaptureWindow(display));
- AckPreviousEvent();
-
- // Make |w2| visible. This should release capture as it is system modal
- // window.
- ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
- EXPECT_EQ(nullptr, GetCaptureWindow(display));
-}
-
-// Tests that setting a visible window as modal to system releases the capture.
-TEST_F(WindowTreeTest, VisibleWindowToSystemModalWithCapture) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* w1 = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1));
-
- w1->SetBounds(gfx::Rect(10, 10, 10, 10));
- const ServerWindow* root_window = *tree->roots().begin();
- ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
- ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
- Display* display = tree->GetDisplay(w1);
-
- // Create |w2| as a child of |root_window| and make it visible.
- ClientWindowId w2_id = BuildClientWindowId(tree, kEmbedTreeWindowId + 1);
- ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
- ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
- w2->SetBounds(gfx::Rect(30, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
-
- // Set capture to |w1|.
- DispatchEventWithoutAck(CreatePointerDownEvent(15, 15));
- ASSERT_TRUE(tree->SetCapture(w1_id));
- EXPECT_EQ(w1, GetCaptureWindow(display));
- AckPreviousEvent();
-
- // Make |w2| modal to system. This should release capture.
- ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_SYSTEM));
- EXPECT_EQ(nullptr, GetCaptureWindow(display));
-}
-
-// Tests that moving the capture window to a modal parent releases the capture
-// as capture cannot be blocked by a modal window.
-TEST_F(WindowTreeTest, MoveCaptureWindowToModalParent) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* w1 = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &w1));
-
- w1->SetBounds(gfx::Rect(10, 10, 30, 30));
- ServerWindow* root_window = FirstRoot(tree);
- ClientWindowId root_window_id = ClientWindowIdForWindow(tree, root_window);
- ClientWindowId w1_id = ClientWindowIdForWindow(tree, w1);
- Display* display = tree->GetDisplay(w1);
-
- // Create |w2| and |w3| as children of |root_window| and make them visible.
- ClientWindowId w2_id = BuildClientWindowId(tree, kEmbedTreeWindowId + 1);
- ASSERT_TRUE(tree->NewWindow(w2_id, ServerWindow::Properties()));
- ServerWindow* w2 = tree->GetWindowByClientId(w2_id);
- w2->SetBounds(gfx::Rect(50, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w2_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w2_id, true));
-
- ClientWindowId w3_id = BuildClientWindowId(tree, kEmbedTreeWindowId + 2);
- ASSERT_TRUE(tree->NewWindow(w3_id, ServerWindow::Properties()));
- ServerWindow* w3 = tree->GetWindowByClientId(w3_id);
- w3->SetBounds(gfx::Rect(70, 10, 10, 10));
- ASSERT_TRUE(tree->AddWindow(root_window_id, w3_id));
- ASSERT_TRUE(tree->SetWindowVisibility(w3_id, true));
-
- // Set |w2| modal to |w1|.
- ASSERT_TRUE(tree->AddTransientWindow(w1_id, w2_id));
- ASSERT_TRUE(tree->SetModalType(w2_id, MODAL_TYPE_WINDOW));
-
- // Set capture to |w3|.
- DispatchEventWithoutAck(CreatePointerDownEvent(25, 25));
- ASSERT_TRUE(tree->SetCapture(w3_id));
- EXPECT_EQ(w3, GetCaptureWindow(display));
- AckPreviousEvent();
-
- // Make |w3| child of |w1|. This should release capture as |w3| is now blocked
- // by a modal window.
- ASSERT_TRUE(tree->AddWindow(w1_id, w3_id));
- EXPECT_EQ(nullptr, GetCaptureWindow(display));
-}
-
-// Tests that opacity can be set on a known window.
-TEST_F(WindowTreeTest, SetOpacity) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- const float new_opacity = 0.5f;
- EXPECT_NE(new_opacity, window->opacity());
- ASSERT_TRUE(tree->SetWindowOpacity(ClientWindowIdForWindow(tree, window),
- new_opacity));
- EXPECT_EQ(new_opacity, window->opacity());
-
- // Re-applying the same opacity will succeed.
- EXPECT_TRUE(tree->SetWindowOpacity(ClientWindowIdForWindow(tree, window),
- new_opacity));
-}
-
-// Tests that opacity requests for unknown windows are rejected.
-TEST_F(WindowTreeTest, SetOpacityFailsOnUnknownWindow) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- const ClientWindowId root_id = FirstRootId(tree);
-
- EXPECT_FALSE(tree->SetWindowOpacity(
- ClientWindowId(root_id.client_id(), root_id.sink_id() + 10), .5f));
-}
-
-TEST_F(WindowTreeTest, SetCaptureTargetsRightConnection) {
- ServerWindow* window = window_event_targeting_helper_.CreatePrimaryTree(
- gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 50, 50));
- WindowTree* owning_tree =
- window_server()->GetTreeWithId(window->owning_tree_id());
- WindowTree* embed_tree = window_server()->GetTreeWithRoot(window);
- ASSERT_NE(owning_tree, embed_tree);
- ASSERT_TRUE(
- owning_tree->SetCapture(ClientWindowIdForWindow(owning_tree, window)));
- DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22));
- WindowManagerStateTestApi wm_state_test_api(
- display()->window_manager_display_root()->window_manager_state());
- EXPECT_EQ(owning_tree, wm_state_test_api.tree_awaiting_input_ack());
- AckPreviousEvent();
-
- // Set capture from the embedded client and make sure it gets the event.
- ASSERT_TRUE(
- embed_tree->SetCapture(ClientWindowIdForWindow(embed_tree, window)));
- DispatchEventWithoutAck(CreateMouseMoveEvent(22, 23));
- EXPECT_EQ(embed_tree, wm_state_test_api.tree_awaiting_input_ack());
-}
-
-TEST_F(WindowTreeTest, ValidMoveLoopWithWM) {
- TestWindowManager wm_internal;
- set_window_manager_internal(wm_tree(), &wm_internal);
-
- TestWindowTreeBinding* child_binding;
- WindowTree* child_tree = CreateNewTree(&child_binding);
- child_binding->client()->tracker()->changes()->clear();
- child_binding->client()->set_record_on_change_completed(true);
-
- // Create a new top level window.
- base::flat_map<std::string, std::vector<uint8_t>> properties;
- const uint32_t initial_change_id = 17;
- // Explicitly use an id that does not contain the client id.
- const ClientWindowId embed_window_id2_in_child(child_tree->id(), 27);
- static_cast<mojom::WindowTree*>(child_tree)
- ->NewTopLevelWindow(
- initial_change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- properties);
-
- // The binding should be paused until the wm acks the change.
- uint32_t wm_change_id = 0u;
- ASSERT_TRUE(wm_internal.did_call_create_top_level_window(&wm_change_id));
- EXPECT_TRUE(child_binding->is_paused());
-
- // Create the window for |embed_window_id2_in_child|.
- const ClientWindowId embed_window_id2 = BuildClientWindowId(wm_tree(), 2);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id2, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id2, true));
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id2));
-
- // Ack the change, which should resume the binding.
- child_binding->client()->tracker()->changes()->clear();
- static_cast<mojom::WindowManagerClient*>(wm_tree())
- ->OnWmCreatedTopLevelWindow(
- wm_change_id,
- wm_tree()->ClientWindowIdToTransportId(embed_window_id2));
- EXPECT_FALSE(child_binding->is_paused());
-
- // The child_tree is the one that has to make this call; the
- const uint32_t change_id = 7;
- static_cast<mojom::WindowTree*>(child_tree)
- ->PerformWindowMove(
- change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- mojom::MoveLoopSource::MOUSE, gfx::Point(0, 0));
-
- EXPECT_TRUE(wm_internal.on_perform_move_loop_called());
-}
-
-TEST_F(WindowTreeTest, MoveLoopAckOKByWM) {
- TestMoveLoopWindowManager wm_internal(wm_tree());
- set_window_manager_internal(wm_tree(), &wm_internal);
-
- TestWindowTreeBinding* child_binding;
- WindowTree* child_tree = CreateNewTree(&child_binding);
- child_binding->client()->tracker()->changes()->clear();
- child_binding->client()->set_record_on_change_completed(true);
-
- // Create a new top level window.
- base::flat_map<std::string, std::vector<uint8_t>> properties;
- const uint32_t initial_change_id = 17;
- // Explicitly use an id that does not contain the client id.
- const ClientWindowId embed_window_id2_in_child(child_tree->id(), 27);
- static_cast<mojom::WindowTree*>(child_tree)
- ->NewTopLevelWindow(
- initial_change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- properties);
-
- // The binding should be paused until the wm acks the change.
- uint32_t wm_change_id = 0u;
- ASSERT_TRUE(wm_internal.did_call_create_top_level_window(&wm_change_id));
- EXPECT_TRUE(child_binding->is_paused());
-
- // Create the window for |embed_window_id2_in_child|.
- const ClientWindowId embed_window_id2 = BuildClientWindowId(wm_tree(), 2);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id2, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id2, true));
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id2));
-
- // Ack the change, which should resume the binding.
- child_binding->client()->tracker()->changes()->clear();
- static_cast<mojom::WindowManagerClient*>(wm_tree())
- ->OnWmCreatedTopLevelWindow(
- wm_change_id,
- wm_tree()->ClientWindowIdToTransportId(embed_window_id2));
- EXPECT_FALSE(child_binding->is_paused());
-
- // The child_tree is the one that has to make this call; the
- const uint32_t change_id = 7;
- child_binding->client()->tracker()->changes()->clear();
- static_cast<mojom::WindowTree*>(child_tree)
- ->PerformWindowMove(
- change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- mojom::MoveLoopSource::MOUSE, gfx::Point(0, 0));
-
- // There should be three changes, the first two relating to capture changing,
- // the last for the completion.
- std::vector<Change>* child_changes =
- child_binding->client()->tracker()->changes();
- ASSERT_EQ(3u, child_changes->size());
- EXPECT_EQ(CHANGE_TYPE_CAPTURE_CHANGED, (*child_changes)[0].type);
- EXPECT_EQ(CHANGE_TYPE_CAPTURE_CHANGED, (*child_changes)[1].type);
- child_changes->erase(child_changes->begin(), child_changes->begin() + 2);
- EXPECT_EQ("ChangeCompleted id=7 sucess=true",
- SingleChangeToDescription(*child_changes));
-}
-
-TEST_F(WindowTreeTest, WindowManagerCantMoveLoop) {
- TestWindowManager wm_internal;
- set_window_manager_internal(wm_tree(), &wm_internal);
-
- TestWindowTreeBinding* child_binding;
- WindowTree* child_tree = CreateNewTree(&child_binding);
- child_binding->client()->tracker()->changes()->clear();
- child_binding->client()->set_record_on_change_completed(true);
-
- // Create a new top level window.
- base::flat_map<std::string, std::vector<uint8_t>> properties;
- const uint32_t initial_change_id = 17;
- // Explicitly use an id that does not contain the client id.
- const ClientWindowId embed_window_id2_in_child(child_tree->id(), 27);
- static_cast<mojom::WindowTree*>(child_tree)
- ->NewTopLevelWindow(
- initial_change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- properties);
-
- // The binding should be paused until the wm acks the change.
- uint32_t wm_change_id = 0u;
- ASSERT_TRUE(wm_internal.did_call_create_top_level_window(&wm_change_id));
- EXPECT_TRUE(child_binding->is_paused());
-
- // Create the window for |embed_window_id2_in_child|.
- const ClientWindowId embed_window_id2 = BuildClientWindowId(wm_tree(), 2);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id2, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id2, true));
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id2));
-
- // Ack the change, which should resume the binding.
- child_binding->client()->tracker()->changes()->clear();
- static_cast<mojom::WindowManagerClient*>(wm_tree())
- ->OnWmCreatedTopLevelWindow(
- wm_change_id,
- wm_tree()->ClientWindowIdToTransportId(embed_window_id2));
- EXPECT_FALSE(child_binding->is_paused());
-
- // Making this call from the wm_tree() must be invalid.
- const uint32_t change_id = 7;
- static_cast<mojom::WindowTree*>(wm_tree())->PerformWindowMove(
- change_id, wm_tree()->ClientWindowIdToTransportId(embed_window_id2),
- mojom::MoveLoopSource::MOUSE, gfx::Point(0, 0));
-
- EXPECT_FALSE(wm_internal.on_perform_move_loop_called());
-}
-
-TEST_F(WindowTreeTest, RevertWindowBoundsOnMoveLoopFailure) {
- TestWindowManager wm_internal;
- set_window_manager_internal(wm_tree(), &wm_internal);
-
- TestWindowTreeBinding* child_binding;
- WindowTree* child_tree = CreateNewTree(&child_binding);
- child_binding->client()->tracker()->changes()->clear();
- child_binding->client()->set_record_on_change_completed(true);
-
- // Create a new top level window.
- base::flat_map<std::string, std::vector<uint8_t>> properties;
- const uint32_t initial_change_id = 17;
- // Explicitly use an id that does not contain the client id.
- const ClientWindowId embed_window_id2_in_child(child_tree->id(), 27);
- static_cast<mojom::WindowTree*>(child_tree)
- ->NewTopLevelWindow(
- initial_change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- properties);
-
- // The binding should be paused until the wm acks the change.
- uint32_t wm_change_id = 0u;
- ASSERT_TRUE(wm_internal.did_call_create_top_level_window(&wm_change_id));
- EXPECT_TRUE(child_binding->is_paused());
-
- // Create the window for |embed_window_id2_in_child|.
- const ClientWindowId embed_window_id2 = BuildClientWindowId(wm_tree(), 2);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id2, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id2, true));
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id2));
-
- // Ack the change, which should resume the binding.
- child_binding->client()->tracker()->changes()->clear();
- static_cast<mojom::WindowManagerClient*>(wm_tree())
- ->OnWmCreatedTopLevelWindow(
- wm_change_id,
- wm_tree()->ClientWindowIdToTransportId(embed_window_id2));
- EXPECT_FALSE(child_binding->is_paused());
-
- // The child_tree is the one that has to make this call; the
- const uint32_t change_id = 7;
- static_cast<mojom::WindowTree*>(child_tree)
- ->PerformWindowMove(
- change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- mojom::MoveLoopSource::MOUSE, gfx::Point(0, 0));
-
- ServerWindow* server_window =
- wm_tree()->GetWindowByClientId(embed_window_id2);
- gfx::Rect old_bounds = server_window->bounds();
- server_window->SetBounds(gfx::Rect(10, 10, 20, 20));
-
- // Cancel the move loop.
- const uint32_t kFirstWMChange = 1;
- static_cast<mojom::WindowManagerClient*>(wm_tree())->WmResponse(
- kFirstWMChange, false);
-
- // Canceling the move loop should have reverted the bounds.
- EXPECT_EQ(old_bounds, server_window->bounds());
-}
-
-TEST_F(WindowTreeTest, InvalidMoveLoopStillAcksAttempt) {
- // We send a PerformWindowMove for an invalid window. We expect to receive a
- // non-success OnMoveLoopCompleted() event.
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- embed_client->set_record_on_change_completed(true);
-
- const uint32_t kChangeId = 8;
- const Id kInvalidWindowId = 1234567890;
- static_cast<mojom::WindowTree*>(tree)->PerformWindowMove(
- kChangeId, kInvalidWindowId, mojom::MoveLoopSource::MOUSE,
- gfx::Point(0, 0));
-
- EXPECT_EQ("ChangeCompleted id=8 sucess=false",
- SingleChangeToDescription(*embed_client->tracker()->changes()));
-}
-
-TEST_F(WindowTreeTest, SetCanAcceptEvents) {
- TestWindowTreeClient* embed_client = nullptr;
- WindowTree* tree = nullptr;
- ServerWindow* window = nullptr;
- EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
-
- EXPECT_EQ(mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS,
- window->event_targeting_policy());
- WindowTreeTestApi(tree).SetEventTargetingPolicy(
- tree->ClientWindowIdToTransportId(ClientWindowIdForWindow(tree, window)),
- mojom::EventTargetingPolicy::NONE);
- EXPECT_EQ(mojom::EventTargetingPolicy::NONE,
- window->event_targeting_policy());
-}
-
-// Verifies wm observers capture changes in client.
-TEST_F(WindowTreeTest, CaptureNotifiesWm) {
- ServerWindow* window = window_event_targeting_helper_.CreatePrimaryTree(
- gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 50, 50));
- TestWindowTreeClient* embed_client = last_window_tree_client();
- WindowTree* owning_tree =
- window_server()->GetTreeWithId(window->owning_tree_id());
- WindowTree* embed_tree = window_server()->GetTreeWithRoot(window);
- ASSERT_NE(owning_tree, embed_tree);
-
- const ClientWindowId embed_child_window_id =
- BuildClientWindowId(embed_tree, kEmbedTreeWindowId + 1);
- ASSERT_TRUE(
- embed_tree->NewWindow(embed_child_window_id, ServerWindow::Properties()));
- EXPECT_TRUE(embed_tree->SetWindowVisibility(embed_child_window_id, true));
- EXPECT_TRUE(
- embed_tree->AddWindow(FirstRootId(embed_tree), embed_child_window_id));
- wm_client()->tracker()->changes()->clear();
- embed_client->tracker()->changes()->clear();
- EXPECT_TRUE(embed_tree->SetCapture(embed_child_window_id));
- ASSERT_TRUE(!wm_client()->tracker()->changes()->empty());
- EXPECT_EQ("OnCaptureChanged new_window=" + kNextWindowClientIdString + "," +
- std::to_string(embed_child_window_id.sink_id()) +
- " old_window=null",
- ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
- EXPECT_TRUE(embed_client->tracker()->changes()->empty());
-
- // Set capture to embed window, and ensure notified as well.
- wm_client()->tracker()->changes()->clear();
- EXPECT_TRUE(embed_tree->SetCapture(FirstRootId(embed_tree)));
- ASSERT_TRUE(!wm_client()->tracker()->changes()->empty());
- // clients that created this window is receiving the event, so client_id part
- // would be reset to 0 before sending back to clients.
- EXPECT_EQ("OnCaptureChanged new_window=0," +
- std::to_string(kEmbedTreeWindowId) +
- " old_window=" + kNextWindowClientIdString + "," +
- std::to_string(embed_child_window_id.sink_id()),
- ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
- EXPECT_TRUE(embed_client->tracker()->changes()->empty());
- wm_client()->tracker()->changes()->clear();
-
- // Set capture from server and ensure embedded tree notified.
- EXPECT_TRUE(owning_tree->ReleaseCapture(
- ClientWindowIdForWindow(owning_tree, FirstRoot(embed_tree))));
- EXPECT_TRUE(wm_client()->tracker()->changes()->empty());
- ASSERT_TRUE(!embed_client->tracker()->changes()->empty());
- EXPECT_EQ("OnCaptureChanged new_window=null old_window=" +
- kWindowManagerClientIdString + ",1",
- ChangesToDescription1(*embed_client->tracker()->changes())[0]);
-}
-
-TEST_F(WindowTreeTest, SetModalTypeForwardedToWindowManager) {
- TestWindowManager wm_internal;
- set_window_manager_internal(wm_tree(), &wm_internal);
-
- TestWindowTreeBinding* child_binding = nullptr;
- WindowTree* child_tree = CreateNewTree(&child_binding);
-
- // Create a new top level window.
- base::flat_map<std::string, std::vector<uint8_t>> properties;
- const uint32_t initial_change_id = 17;
- // Explicitly use an id that does not contain the client id.
- const ClientWindowId embed_window_id2_in_child(child_tree->id(), 27);
- static_cast<mojom::WindowTree*>(child_tree)
- ->NewTopLevelWindow(
- initial_change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- properties);
-
- // Create the window for |embed_window_id2_in_child|.
- const ClientWindowId embed_window_id2 = BuildClientWindowId(wm_tree(), 2);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id2, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id2, true));
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id2));
-
- // Ack the change, which should resume the binding.
- static_cast<mojom::WindowManagerClient*>(wm_tree())
- ->OnWmCreatedTopLevelWindow(
- 0u, wm_tree()->ClientWindowIdToTransportId(embed_window_id2));
-
- // Change modal type to MODAL_TYPE_SYSTEM and check that it is forwarded to
- // the window manager.
- child_tree->SetModalType(embed_window_id2_in_child, MODAL_TYPE_SYSTEM);
- EXPECT_TRUE(wm_internal.on_set_modal_type_called());
-}
-
-TEST_F(WindowTreeTest, TestWindowManagerSettingCursorLocation) {
- const ClientWindowId embed_window_id =
- BuildClientWindowId(wm_tree(), kEmbedTreeWindowId);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
- ServerWindow* embed_window = wm_tree()->GetWindowByClientId(embed_window_id);
- ASSERT_TRUE(embed_window);
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true));
- ASSERT_TRUE(FirstRoot(wm_tree()));
- const ClientWindowId wm_root_id = FirstRootId(wm_tree());
- EXPECT_TRUE(wm_tree()->AddWindow(wm_root_id, embed_window_id));
- ServerWindow* wm_root = FirstRoot(wm_tree());
- ASSERT_TRUE(wm_root);
- wm_root->SetBounds(gfx::Rect(0, 0, 100, 100));
- // This tests expects |wm_root| to be a possible target.
- wm_root->set_event_targeting_policy(
- mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
- display()->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
- mojom::WindowTreeClientPtr client;
- wm_client()->Bind(mojo::MakeRequest(&client));
- const uint32_t embed_flags = 0;
- wm_tree()->Embed(embed_window_id, std::move(client), embed_flags);
- WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window);
- ASSERT_TRUE(tree1 != nullptr);
- ASSERT_NE(tree1, wm_tree());
-
- embed_window->SetBounds(gfx::Rect(20, 20, 20, 20));
- embed_window->SetCursor(ui::CursorData(ui::CursorType::kIBeam));
-
- // Because the cursor is still at the origin, changing the cursor shouldn't
- // have switched to ibeam.
- EXPECT_EQ(ui::CursorType::kPointer, cursor_type());
-
- // Have the window manager move the cursor within the embed window.
- static_cast<mojom::WindowManagerClient*>(wm_tree())
- ->WmMoveCursorToDisplayLocation(gfx::Point(21, 21), -1);
-}
-
-TEST_F(WindowTreeTest, TestWindowManagerConfineCursor) {
- const gfx::Rect bounds(10, 10, 100, 100);
- const int64_t display_id = display()->GetId();
- static_cast<mojom::WindowManagerClient*>(wm_tree())->WmConfineCursorToBounds(
- bounds, display_id);
-
- PlatformDisplay* platform_display = display()->platform_display();
- EXPECT_EQ(bounds, static_cast<TestPlatformDisplay*>(platform_display)
- ->confine_cursor_bounds());
-}
-
-using WindowTreeShutdownTest = testing::Test;
-
-// Makes sure WindowTreeClient doesn't get any messages during shutdown.
-TEST_F(WindowTreeShutdownTest, DontSendMessagesDuringShutdown) {
- std::unique_ptr<TestWindowTreeClient> client;
- {
- // Create a tree with one window.
- WindowServerTestHelper ws_test_helper;
- WindowServer* window_server = ws_test_helper.window_server();
- TestScreenManager screen_manager;
- screen_manager.Init(window_server->display_manager());
- screen_manager.AddDisplay();
-
- AddWindowManager(window_server);
- TestWindowTreeBinding* test_binding =
- ws_test_helper.window_server_delegate()->last_binding();
- ASSERT_TRUE(test_binding);
- WindowTree* tree = test_binding->tree();
- const ClientWindowId window_id = BuildClientWindowId(tree, 2);
- ASSERT_TRUE(tree->NewWindow(window_id, ServerWindow::Properties()));
-
- // Release the client so that it survices shutdown.
- client = test_binding->ReleaseClient();
- client->tracker()->changes()->clear();
- }
-
- // Client should not have got any messages after shutdown.
- EXPECT_TRUE(client->tracker()->changes()->empty());
-}
-
-// Used to test the window manager configured to manually create displays roots.
-class WindowTreeManualDisplayTest : public TaskRunnerTestBase {
- public:
- WindowTreeManualDisplayTest() {}
- ~WindowTreeManualDisplayTest() override {}
-
- WindowServer* window_server() { return ws_test_helper_.window_server(); }
- DisplayManager* display_manager() {
- return window_server()->display_manager();
- }
- TestWindowServerDelegate* window_server_delegate() {
- return ws_test_helper_.window_server_delegate();
- }
- TestScreenManager& screen_manager() { return screen_manager_; }
-
- protected:
- // testing::Test:
- void SetUp() override {
- TaskRunnerTestBase::SetUp();
- screen_manager_.Init(window_server()->display_manager());
- }
-
- private:
- WindowServerTestHelper ws_test_helper_;
- TestScreenManager screen_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowTreeManualDisplayTest);
-};
-
-TEST_F(WindowTreeManualDisplayTest, ClientCreatesDisplayRoot) {
- const bool automatically_create_display_roots = false;
- AddWindowManager(window_server(), automatically_create_display_roots);
-
- WindowManagerState* window_manager_state =
- window_server()->GetWindowManagerState();
- ASSERT_TRUE(window_manager_state);
- WindowTree* window_manager_tree = window_manager_state->window_tree();
- EXPECT_TRUE(window_manager_tree->roots().empty());
- TestWindowManager* test_window_manager =
- window_server_delegate()->last_binding()->window_manager();
- EXPECT_EQ(1, test_window_manager->connect_count());
- EXPECT_EQ(0, test_window_manager->display_added_count());
-
- // Create a window for the windowmanager and set it as the root.
- ClientWindowId display_root_id = BuildClientWindowId(window_manager_tree, 10);
- ASSERT_TRUE(window_manager_tree->NewWindow(display_root_id,
- ServerWindow::Properties()));
- ServerWindow* display_root =
- window_manager_tree->GetWindowByClientId(display_root_id);
- ASSERT_TRUE(display_root);
- display::Display display1 = MakeDisplay(0, 0, 1024, 768, 1.0f);
- display1.set_id(101);
-
- display::ViewportMetrics metrics;
- metrics.bounds_in_pixels = display1.bounds();
- metrics.device_scale_factor = 1.5;
- metrics.ui_scale_factor = 2.5;
- const bool is_primary_display = true;
- ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
- .ProcessSetDisplayRoot(display1, metrics, is_primary_display,
- display_root_id));
- EXPECT_TRUE(display_root->parent());
- EXPECT_TRUE(window_server_delegate()
- ->last_binding()
- ->client()
- ->tracker()
- ->changes()
- ->empty());
- EXPECT_EQ(1u, window_manager_tree->roots().size());
-
- // Delete the root, which should delete the WindowManagerDisplayRoot.
- EXPECT_TRUE(window_manager_tree->DeleteWindow(display_root_id));
- EXPECT_TRUE(window_manager_tree->roots().empty());
- EXPECT_TRUE(WindowManagerStateTestApi(window_manager_state)
- .window_manager_display_roots()
- .empty());
-}
-
-TEST_F(WindowTreeManualDisplayTest, MoveDisplayRootToNewDisplay) {
- const bool automatically_create_display_roots = false;
- AddWindowManager(window_server(), automatically_create_display_roots);
-
- WindowManagerState* window_manager_state =
- window_server()->GetWindowManagerState();
- ASSERT_TRUE(window_manager_state);
- WindowTree* window_manager_tree = window_manager_state->window_tree();
- EXPECT_TRUE(window_manager_tree->roots().empty());
- TestWindowManager* test_window_manager =
- window_server_delegate()->last_binding()->window_manager();
- EXPECT_EQ(1, test_window_manager->connect_count());
- EXPECT_EQ(0, test_window_manager->display_added_count());
-
- // Create a window for the windowmanager and set it as the root.
- ClientWindowId display_root_id = BuildClientWindowId(window_manager_tree, 10);
- ASSERT_TRUE(window_manager_tree->NewWindow(display_root_id,
- ServerWindow::Properties()));
- ServerWindow* display_root =
- window_manager_tree->GetWindowByClientId(display_root_id);
- ASSERT_TRUE(display_root);
- display::Display display1 = MakeDisplay(0, 0, 1024, 768, 1.0f);
- constexpr int64_t display1_id = 101;
- display1.set_id(display1_id);
-
- display::ViewportMetrics metrics;
- metrics.bounds_in_pixels = display1.bounds();
- metrics.device_scale_factor = 1.5;
- metrics.ui_scale_factor = 2.5;
- const bool is_primary_display = true;
- ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
- .ProcessSetDisplayRoot(display1, metrics, is_primary_display,
- display_root_id));
- ASSERT_TRUE(display_root->parent());
- const viz::FrameSinkId display1_parent_id =
- display_root->parent()->frame_sink_id();
- EXPECT_TRUE(window_server_delegate()
- ->last_binding()
- ->client()
- ->tracker()
- ->changes()
- ->empty());
- EXPECT_EQ(1u, window_manager_tree->roots().size());
-
- // Call ProcessSetDisplayRoot() again, with a different display.
- display::Display display2 = MakeDisplay(0, 0, 1024, 768, 1.0f);
- constexpr int64_t display2_id = 102;
- display2.set_id(display2_id);
- ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
- .ProcessSetDisplayRoot(display2, metrics, is_primary_display,
- display_root_id));
- ASSERT_TRUE(display_root->parent());
- EXPECT_NE(display1_parent_id, display_root->parent()->frame_sink_id());
- EXPECT_TRUE(window_server_delegate()
- ->last_binding()
- ->client()
- ->tracker()
- ->changes()
- ->empty());
- EXPECT_EQ(1u, window_manager_tree->roots().size());
- // The WindowManagerDisplayRoot for |display1| should have been deleted.
- EXPECT_EQ(1u, WindowManagerStateTestApi(window_manager_state)
- .window_manager_display_roots()
- .size());
- EXPECT_FALSE(window_server()->display_manager()->GetDisplayById(display1_id));
- EXPECT_TRUE(window_server()->display_manager()->GetDisplayById(display2_id));
-
- // Delete the root, which should delete the WindowManagerDisplayRoot.
- EXPECT_TRUE(window_manager_tree->DeleteWindow(display_root_id));
- EXPECT_TRUE(window_manager_tree->roots().empty());
- EXPECT_TRUE(WindowManagerStateTestApi(window_manager_state)
- .window_manager_display_roots()
- .empty());
-}
-
-TEST_F(WindowTreeManualDisplayTest,
- DisplayManagerObserverNotifiedWithManualRoots) {
- const bool automatically_create_display_roots = false;
- AddWindowManager(window_server(), automatically_create_display_roots);
-
- TestScreenProviderObserver screen_provider_observer;
- DisplayManager* display_manager = window_server()->display_manager();
- UserDisplayManager* user_display_manager =
- display_manager->GetUserDisplayManager();
- ASSERT_TRUE(user_display_manager);
- user_display_manager->AddObserver(screen_provider_observer.GetPtr());
-
- // Observer should not have been notified yet.
- //
- // NOTE: the RunUntilIdle() calls are necessary anytime the calls are checked
- // as the observer is called via mojo, which is async.
- RunUntilIdle();
- EXPECT_TRUE(screen_provider_observer.GetAndClearObserverCalls().empty());
-
- // Set frame decorations, again observer should not be notified.
- WindowManagerState* window_manager_state =
- window_server()->GetWindowManagerState();
- ASSERT_TRUE(window_manager_state);
- WindowTree* window_manager_tree = window_manager_state->window_tree();
- window_manager_state->SetFrameDecorationValues(
- mojom::FrameDecorationValues::New());
- RunUntilIdle();
- EXPECT_TRUE(screen_provider_observer.GetAndClearObserverCalls().empty());
-
- // Create a window for the windowmanager and set it as the root.
- ClientWindowId display_root_id = BuildClientWindowId(window_manager_tree, 10);
- ASSERT_TRUE(window_manager_tree->NewWindow(display_root_id,
- ServerWindow::Properties()));
- ServerWindow* display_root =
- window_manager_tree->GetWindowByClientId(display_root_id);
- ASSERT_TRUE(display_root);
- RunUntilIdle();
- EXPECT_TRUE(screen_provider_observer.GetAndClearObserverCalls().empty());
-
- // Add a new display.
- // The value for the scale factor doesn't matter, just choosing something
- // other than 1 to ensure values other than 1 correctly take.
- const float kDisplay1ScaleFactor = 2.25;
- display::Display display1 =
- MakeDisplay(0, 0, 1024, 768, kDisplay1ScaleFactor);
- const int64_t display_id1 = 101;
- display1.set_id(display_id1);
- display::ViewportMetrics metrics1;
- metrics1.bounds_in_pixels = display1.bounds();
- metrics1.device_scale_factor = kDisplay1ScaleFactor;
- metrics1.ui_scale_factor = 2.5;
- const bool is_primary_display = true;
- ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
- .ProcessSetDisplayRoot(display1, metrics1, is_primary_display,
- display_root_id));
- RunUntilIdle();
- EXPECT_TRUE(screen_provider_observer.GetAndClearObserverCalls().empty());
-
- // Configure the displays, updating the bounds of the first display.
- std::vector<display::Display> displays;
- displays.push_back(display1);
- std::vector<display::ViewportMetrics> viewport_metrics;
- viewport_metrics.push_back(metrics1);
- const gfx::Rect updated_bounds(1, 2, 3, 4);
- viewport_metrics[0].bounds_in_pixels = updated_bounds;
- std::vector<display::Display> mirrors;
- ASSERT_TRUE(display_manager->SetDisplayConfiguration(
- displays, viewport_metrics, display_id1, display::kInvalidDisplayId,
- mirrors));
- RunUntilIdle();
- EXPECT_EQ("OnDisplaysChanged " + std::to_string(display_id1) + " " +
- std::to_string(display::kInvalidDisplayId),
- screen_provider_observer.GetAndClearObserverCalls());
- PlatformDisplay* platform_display1 =
- display_manager->GetDisplayById(display_id1)->platform_display();
- ASSERT_TRUE(platform_display1);
- EXPECT_EQ(
- kDisplay1ScaleFactor * ui::mojom::kCursorMultiplierForExternalDisplays,
- static_cast<TestPlatformDisplay*>(platform_display1)->cursor_scale());
- EXPECT_EQ(updated_bounds, static_cast<TestPlatformDisplay*>(platform_display1)
- ->metrics()
- .bounds_in_pixels);
-
- // Create a window for the windowmanager and set it as the root.
- ClientWindowId display_root_id2 =
- BuildClientWindowId(window_manager_tree, 11);
- ASSERT_TRUE(window_manager_tree->NewWindow(display_root_id2,
- ServerWindow::Properties()));
- ServerWindow* display_root2 =
- window_manager_tree->GetWindowByClientId(display_root_id);
- ASSERT_TRUE(display_root2);
- RunUntilIdle();
- EXPECT_TRUE(screen_provider_observer.GetAndClearObserverCalls().empty());
-
- // Add another display.
- const float kDisplay2ScaleFactor = 1.75;
- display::Display display2 =
- MakeDisplay(0, 0, 1024, 768, kDisplay2ScaleFactor);
- const int64_t display_id2 = 102;
- display2.set_id(display_id2);
- display::ViewportMetrics metrics2;
- metrics2.bounds_in_pixels = display2.bounds();
- metrics2.device_scale_factor = kDisplay2ScaleFactor;
- metrics2.ui_scale_factor = 2.5;
- ASSERT_TRUE(
- WindowTreeTestApi(window_manager_tree)
- .ProcessSetDisplayRoot(display2, metrics2, false, display_root_id2));
- RunUntilIdle();
- EXPECT_TRUE(screen_provider_observer.GetAndClearObserverCalls().empty());
-
- // Make |display2| the default, and resize both displays.
- display1.set_bounds(gfx::Rect(0, 0, 1024, 1280));
- metrics1.bounds_in_pixels = display1.bounds();
- displays.clear();
- displays.push_back(display1);
-
- display2.set_bounds(gfx::Rect(0, 0, 500, 600));
- metrics2.bounds_in_pixels = display2.bounds();
- displays.push_back(display2);
-
- viewport_metrics.clear();
- viewport_metrics.push_back(metrics1);
- viewport_metrics.push_back(metrics2);
- ASSERT_TRUE(display_manager->SetDisplayConfiguration(
- displays, viewport_metrics, display_id2, display_id2, mirrors));
- RunUntilIdle();
- EXPECT_EQ("OnDisplaysChanged " + std::to_string(display_id1) + " " +
- std::to_string(display_id2) + " " + std::to_string(display_id2),
- screen_provider_observer.GetAndClearObserverCalls());
- EXPECT_EQ(
- kDisplay1ScaleFactor * ui::mojom::kCursorMultiplierForExternalDisplays,
- static_cast<TestPlatformDisplay*>(platform_display1)->cursor_scale());
- PlatformDisplay* platform_display2 =
- display_manager->GetDisplayById(display_id2)->platform_display();
- ASSERT_TRUE(platform_display2);
- EXPECT_EQ(
- kDisplay2ScaleFactor,
- static_cast<TestPlatformDisplay*>(platform_display2)->cursor_scale());
-
- // Delete the second display, no notification should be sent.
- EXPECT_TRUE(window_manager_tree->DeleteWindow(display_root_id2));
- RunUntilIdle();
- EXPECT_TRUE(screen_provider_observer.GetAndClearObserverCalls().empty());
- EXPECT_FALSE(display_manager->GetDisplayById(display_id2));
-
- // Set the config back to only the first.
- displays.clear();
- displays.push_back(display1);
-
- viewport_metrics.clear();
- viewport_metrics.push_back(metrics1);
- ASSERT_TRUE(display_manager->SetDisplayConfiguration(
- displays, viewport_metrics, display_id1, display_id1, mirrors));
- RunUntilIdle();
- EXPECT_EQ("OnDisplaysChanged " + std::to_string(display_id1) + " " +
- std::to_string(display_id1),
- screen_provider_observer.GetAndClearObserverCalls());
-
- // The display list should not have display2.
- display::DisplayList& display_list =
- display::ScreenManager::GetInstance()->GetScreen()->display_list();
- EXPECT_TRUE(display_list.FindDisplayById(display_id2) ==
- display_list.displays().end());
- ASSERT_TRUE(display_list.GetPrimaryDisplayIterator() !=
- display_list.displays().end());
- EXPECT_EQ(display_id1, display_list.GetPrimaryDisplayIterator()->id());
-}
-
-TEST_F(WindowTreeManualDisplayTest, SwapDisplayRoots) {
- const bool automatically_create_display_roots = false;
- AddWindowManager(window_server(), automatically_create_display_roots);
-
- WindowManagerState* window_manager_state =
- window_server()->GetWindowManagerState();
- ASSERT_TRUE(window_manager_state);
- WindowTree* window_manager_tree = window_manager_state->window_tree();
- window_manager_state->SetFrameDecorationValues(
- mojom::FrameDecorationValues::New());
-
- // Add two windows for the two displays.
- ClientWindowId display_root_id1 =
- BuildClientWindowId(window_manager_tree, 10);
- ASSERT_TRUE(window_manager_tree->NewWindow(display_root_id1,
- ServerWindow::Properties()));
- ServerWindow* display_root1 =
- window_manager_tree->GetWindowByClientId(display_root_id1);
- ASSERT_TRUE(display_root1);
-
- ClientWindowId display_root_id2 =
- BuildClientWindowId(window_manager_tree, 20);
- ASSERT_TRUE(window_manager_tree->NewWindow(display_root_id2,
- ServerWindow::Properties()));
- ServerWindow* display_root2 =
- window_manager_tree->GetWindowByClientId(display_root_id2);
- ASSERT_TRUE(display_root2);
- EXPECT_NE(display_root1, display_root2);
-
- // Add two displays.
- const int64_t display_id1 = 101;
- display::Display display1 = MakeDisplay(0, 0, 1024, 768, 1.0f);
- display1.set_id(display_id1);
- display::ViewportMetrics metrics;
- metrics.bounds_in_pixels = display1.bounds();
- metrics.device_scale_factor = 1.5;
- metrics.ui_scale_factor = 2.5;
- const bool is_primary_display = true;
- ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
- .ProcessSetDisplayRoot(display1, metrics, is_primary_display,
- display_root_id1));
-
- display::Display display2 = MakeDisplay(0, 0, 1024, 768, 1.0f);
- const int64_t display_id2 = 102;
- display2.set_id(display_id2);
- ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
- .ProcessSetDisplayRoot(display2, metrics, is_primary_display,
- display_root_id2));
-
- ServerWindow* display_root1_parent = display_root1->parent();
- ServerWindow* display_root2_parent = display_root2->parent();
- ASSERT_TRUE(WindowTreeTestApi(window_manager_tree)
- .ProcessSwapDisplayRoots(display_id1, display_id2));
- EXPECT_EQ(display_root1_parent, display_root2->parent());
- EXPECT_EQ(display_root2_parent, display_root1->parent());
-}
-
-TEST_F(WindowTreeTest, EmbedFlagEmbedderControlsVisibility) {
- const ClientWindowId embed_window_id =
- BuildClientWindowId(wm_tree(), kEmbedTreeWindowId);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
- ServerWindow* embed_window = wm_tree()->GetWindowByClientId(embed_window_id);
- ASSERT_TRUE(embed_window);
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id));
- mojom::WindowTreeClientPtr client;
- wm_client()->Bind(mojo::MakeRequest(&client));
- const uint32_t embed_flags = mojom::kEmbedFlagEmbedderControlsVisibility;
- wm_tree()->Embed(embed_window_id, std::move(client), embed_flags);
- WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window);
- ASSERT_TRUE(tree1);
- // |tree1| should not be able to control the visibility of its root because
- // |kEmbedFlagEmbedderControlsVisibility| was specified.
- EXPECT_FALSE(tree1->SetWindowVisibility(
- ClientWindowIdForWindow(tree1, embed_window), false));
- const ClientWindowId child_window_id = BuildClientWindowId(tree1, 101);
- // But |tree1| can control the visibility of any windows it creates.
- EXPECT_TRUE(tree1->NewWindow(child_window_id, ServerWindow::Properties()));
- EXPECT_TRUE(tree1->SetWindowVisibility(child_window_id, true));
-}
-
-TEST_F(WindowTreeTest, PerformWmAction) {
- TestWindowManager wm_internal;
- set_window_manager_internal(wm_tree(), &wm_internal);
-
- TestWindowTreeBinding* child_binding = nullptr;
- WindowTree* child_tree = CreateNewTree(&child_binding);
-
- // Create a new top level window.
- base::flat_map<std::string, std::vector<uint8_t>> properties;
- const uint32_t initial_change_id = 17;
- // Explicitly use an id that does not contain the client id.
- const ClientWindowId embed_window_id2_in_child(child_tree->id(), 27);
- static_cast<mojom::WindowTree*>(child_tree)
- ->NewTopLevelWindow(
- initial_change_id,
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- properties);
-
- // Create the window for |embed_window_id2_in_child|.
- const ClientWindowId embed_window_id2 = BuildClientWindowId(wm_tree(), 2);
- EXPECT_TRUE(
- wm_tree()->NewWindow(embed_window_id2, ServerWindow::Properties()));
- EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id2, true));
- EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id2));
-
- // Ack the change, which should resume the binding.
- static_cast<mojom::WindowManagerClient*>(wm_tree())
- ->OnWmCreatedTopLevelWindow(
- 0u, wm_tree()->ClientWindowIdToTransportId(embed_window_id2));
-
- static_cast<mojom::WindowTree*>(child_tree)
- ->PerformWmAction(
- child_tree->ClientWindowIdToTransportId(embed_window_id2_in_child),
- "test-action");
- EXPECT_EQ("test-action", wm_internal.last_wm_action());
-}
-
-TEST_F(WindowTreeTest, EmbedderInterceptsEventsSeesWindowsInEmbeddedClients) {
- // Make the root visible and give it bounds.
- ServerWindow* wm_root = FirstRoot(wm_tree());
- ASSERT_TRUE(wm_root);
- const gfx::Rect bounds(0, 0, 20, 20);
- wm_root->SetBounds(bounds);
- wm_root->SetVisible(true);
-
- // Create window for embedded (|w1|).
- ClientWindowId w1_id;
- ServerWindow* w1 =
- NewWindowInTreeWithParent(wm_tree(), wm_root, &w1_id, bounds);
- ASSERT_TRUE(w1);
-
- // Embed a new client in |w1|.
- TestWindowTreeBinding* embed_binding1 =
- test_window_server_delegate()->Embed(wm_tree(), w1);
- // Set the |is_for_embedding| to false, otherwise
- // kEmbedFlagEmbedderInterceptsEvents is ignored
- WindowTreeTestApi(embed_binding1->tree()).set_is_for_embedding(false);
- ASSERT_TRUE(embed_binding1);
-
- // Create |w2| (in the embedded tree).
- ClientWindowId w2_id;
- ServerWindow* w2 =
- NewWindowInTreeWithParent(embed_binding1->tree(), w1, &w2_id, bounds);
- ASSERT_TRUE(w2);
-
- // Embed a new client in |w2|.
- TestWindowTreeBinding* embed_binding2 = test_window_server_delegate()->Embed(
- embed_binding1->tree(), w2, mojom::kEmbedFlagEmbedderInterceptsEvents);
- ASSERT_TRUE(embed_binding2);
-
- // Create |w3| as a child of |w2|.
- ClientWindowId w3_id;
- ServerWindow* w3 =
- NewWindowInTreeWithParent(embed_binding2->tree(), w2, &w3_id, bounds);
- ASSERT_TRUE(w3);
-
- // Embed a new client in |w3|.
- TestWindowTreeBinding* embed_binding3 =
- test_window_server_delegate()->Embed(embed_binding2->tree(), w3);
- ASSERT_TRUE(embed_binding3);
-
- // Create |w4| as a child of |w3|.
- ClientWindowId w4_id;
- ServerWindow* w4 =
- NewWindowInTreeWithParent(embed_binding3->tree(), w3, &w4_id, bounds);
- ASSERT_TRUE(w4);
-
- // |w4| and |w3| should be known to embed_binding1->tree() because of
- // kEmbedFlagEmbedderInterceptsEvents. |w3| should not be known to
- // embed_binding2->tree(), because it has an invalid user id.
- EXPECT_TRUE(embed_binding1->tree()->IsWindowKnown(w3, nullptr));
- ClientWindowId w4_in_tree1_id;
- EXPECT_TRUE(embed_binding1->tree()->IsWindowKnown(w4, &w4_in_tree1_id));
- EXPECT_FALSE(embed_binding2->tree()->IsWindowKnown(w4, nullptr));
-
- // Verify an event targetting |w4| goes to embed_binding1->tree().
- embed_binding1->client()->tracker()->changes()->clear();
- AckPreviousEvent();
- DispatchEventWithoutAck(CreatePointerDownEvent(5, 5));
- WindowManagerStateTestApi wm_state_test_api(
- wm_tree()->window_manager_state());
- EXPECT_EQ(embed_binding1->tree(),
- wm_state_test_api.tree_awaiting_input_ack());
- // Event targets |w4|, but goes to embed_binding1->tree() (because of
- // kEmbedFlagEmbedderInterceptsEvents).
- EXPECT_EQ(1u, embed_binding1->client()->tracker()->changes()->size());
- EXPECT_EQ("InputEvent window=" + ClientWindowIdToString(w4_in_tree1_id) +
- " event_action=" + std::to_string(ui::ET_POINTER_DOWN),
- SingleChangeToDescription(
- *embed_binding1->client()->tracker()->changes()));
-}
-
-} // namespace test
-} // namespace ws
-} // namespace ui
diff --git a/services/ui/ws2/README.md b/services/ui/ws2/README.md
index 6b4e03e..4db4a1ac 100644
--- a/services/ui/ws2/README.md
+++ b/services/ui/ws2/README.md
@@ -23,3 +23,83 @@
draw to the screen (using Viz). This is mostly seamless to the tap_visualizer.
The tap_visualizer configures Views to use Mus, which results in Views and Aura,
using the WindowService.
+
+## Ids
+
+Each client connected to the Window Service is assigned a unique id inside the
+Window Service. This id is a monotonically increasing uint32_t. This is often
+referred to as the client_id.
+
+As clients do not know their id, they always supply 0 as the client id in the
+mojom related functions. Internally the Window Service maps 0 to the real client
+id.
+
+Windows have a couple of different (related) ids.
+
+### ClientWindowId
+
+ClientWindowId is a uint64_t pairing of a client_id and a window_id. The
+window_id is a uint32_t assigned by the client, and should be unique within that
+client's scope. When communicating with the Window Service, clients may use 0 as
+the client_id to refer to their own windows. The Window Service maps 0 to the
+real client_id. In Window Service code the id from the client is typically
+referred to as the transport_window_id. Mojom functions that receive the
+transport_window_id map it to a ClientWindowId. ClientWindowId is a real class
+that provides type safety.
+
+When a client is embedded in an existing window, the embedded client is given
+visibility to a Window created by the embedder. In this case the Window Service
+supplies the ClientWindowId to the embedded client and uses the ClientWindowId
+at the time the Window was created (the ClientWindowId actually comes from the
+FrameSinkId, see below for details on FrameSinkId). In other words, both the
+embedder and embedded client use the same ClientWindowId for the Window. See
+discussion on FrameSinkId for more details.
+
+For a client to establish an embed root, it first calls
+ScheduleEmbedForExistingClient(), so it can provide a window_id that is unique
+within its own scope. That client then passes the returned token to what will
+become its embedder to call EmbedUsingToken(). In this case, the embedder and
+embedded client do not use the same ClientWindowId for the Window.
+
+ClientWindowId is globally unique, but a Window may have multiple
+ClientWindowIds associated with it.
+
+### FrameSinkId
+
+Each Window has a FrameSinkId that is needed for both hit-testing and
+embedding. The FrameSinkId is initialized to the ClientWindowId of the client
+creating the Window, but it changes during an embedding. In particular, when a
+client calls Embed() the FrameSinkId of the Window changes such that the
+client_id of the FrameSinkId matches the client_id of the client being
+embedded and the sink_id is set to 0. The embedder is informed of this by way of
+OnFrameSinkIdAllocated(). The embedded client is informed of the original
+FrameSinkId (the client_id of the FrameSinkId matches the embedder's client_id).
+In client code the embedded client ends up *always* using a client_id of 0 for
+the FrameSinkId. This works because Viz knows the real client_id and handles
+mapping 0 to the real client_id.
+
+The FrameSinkId of top-level windows is set to the ClientWindowId from the
+client requesting the top-level (top-levels are created and owned by the Window
+Manager). The Window Manager is told the updated FrameSinkId when it is asked
+to create the top-level (WmCreateTopLevelWindow()).
+
+The FrameSinkId of an embed root's Window is set to the ClientWindowId of the
+embed root's Window from the embedded client.
+
+### LocalSurfaceId
+
+The LocalSurfaceId (which contains unguessable) is necessary if the client wants
+to submit a compositor-frame for the Window (it wants to show something on
+screen), and not needed if the client only wants to submit a hit-test region.
+The LocalSurfaceId may be assigned when the bounds and/or device-scale-factor
+changes. The LocalSurfaceId can change at other times as well (perhaps to
+synchronize an effect with the embedded client). The LocalSurfaceId is intended
+to allow for smooth resizes and ensures at embed points the CompositorFrame from
+both clients match. Client code supplies a LocalSurfaceId for windows that have
+another client embedded in them as well as windows with a LayerTreeFrameSink.
+The LocalSurfaceId comes from the owner of the window. The embedded client is
+told of changes to the LocalSurfaceId by way of OnWindowBoundsChanged(). This is
+still very much a work in progress.
+
+FrameSinkId is derived from the embedded client, where as LocalSurfaceId
+comes from the embedder.