Commit 186521f9 authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Emit window bounds when the window is transformed.

The transform can be applied on overview mode and can affect
the bounds in screen.

Bug: 931161
Test: services_unittests
Change-Id: I5ef15745d73f7ffcd74e5844ffeef18b0d544d66
Reviewed-on: https://chromium-review.googlesource.com/c/1480206
Commit-Queue: Jun Mukai <mukai@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634009}
parent 8cd24180
...@@ -393,6 +393,15 @@ void ClientRoot::OnWindowVisibilityChanged(aura::Window* window, bool visible) { ...@@ -393,6 +393,15 @@ void ClientRoot::OnWindowVisibilityChanged(aura::Window* window, bool visible) {
} }
} }
void ClientRoot::OnWindowTransformed(aura::Window* window,
ui::PropertyChangeReason reason) {
// Transform can affect the window bounds in screen. See
// https://crbug.com/931161.
DCHECK_EQ(window, window_);
if (window->GetBoundsInScreen().origin() != last_bounds_.origin())
NotifyClientOfNewBounds();
}
void ClientRoot::OnHostResized(aura::WindowTreeHost* host) { void ClientRoot::OnHostResized(aura::WindowTreeHost* host) {
// This function is also called when the device-scale-factor changes too. // This function is also called when the device-scale-factor changes too.
CheckForScaleFactorChange(); CheckForScaleFactorChange();
......
...@@ -134,6 +134,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) ClientRoot ...@@ -134,6 +134,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) ClientRoot
int64_t new_display_id) override; int64_t new_display_id) override;
void OnDidMoveWindowToDisplay(aura::Window* window) override; void OnDidMoveWindowToDisplay(aura::Window* window) override;
void OnWindowVisibilityChanged(aura::Window* window, bool visible) override; void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
void OnWindowTransformed(aura::Window* window,
ui::PropertyChangeReason reason) override;
// aura::WindowTreeHostObserver: // aura::WindowTreeHostObserver:
void OnHostResized(aura::WindowTreeHost* host) override; void OnHostResized(aura::WindowTreeHost* host) override;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/run_loop.h"
#include "services/ws/public/cpp/property_type_converters.h" #include "services/ws/public/cpp/property_type_converters.h"
#include "services/ws/public/mojom/window_manager.mojom.h" #include "services/ws/public/mojom/window_manager.mojom.h"
#include "services/ws/window_service.h" #include "services/ws/window_service.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/aura/window_tracker.h" #include "ui/aura/window_tracker.h"
#include "ui/gfx/transform.h"
namespace ws { namespace ws {
namespace { namespace {
...@@ -51,6 +53,36 @@ class CascadingPropertyTestHelper : public aura::WindowObserver { ...@@ -51,6 +53,36 @@ class CascadingPropertyTestHelper : public aura::WindowObserver {
DISALLOW_COPY_AND_ASSIGN(CascadingPropertyTestHelper); DISALLOW_COPY_AND_ASSIGN(CascadingPropertyTestHelper);
}; };
class TransformWaiter : public aura::WindowObserver {
public:
explicit TransformWaiter(aura::Window* window)
: run_loop_(base::RunLoop::Type::kNestableTasksAllowed), window_(window) {
window_->AddObserver(this);
}
~TransformWaiter() override { window_->RemoveObserver(this); }
void Wait() { run_loop_.Run(); }
private:
// aura::WindowObserver:
void OnWindowTransformed(aura::Window* window,
ui::PropertyChangeReason reason) override {
run_loop_.QuitWhenIdle();
}
base::RunLoop run_loop_;
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(TransformWaiter);
};
void SetTransformAndWait(aura::Window* window,
const gfx::Transform& transform) {
TransformWaiter waiter(window);
window->SetTransform(transform);
waiter.Wait();
}
// Verifies a property change that occurs while servicing a property change from // Verifies a property change that occurs while servicing a property change from
// the client results in notifying the client of the new property. // the client results in notifying the client of the new property.
TEST(ClientRoot, CascadingPropertyChange) { TEST(ClientRoot, CascadingPropertyChange) {
...@@ -247,5 +279,33 @@ TEST(ClientRoot, EmbedWindowClientVisibilityChanges) { ...@@ -247,5 +279,33 @@ TEST(ClientRoot, EmbedWindowClientVisibilityChanges) {
EXPECT_TRUE(embedding_changes->empty()); EXPECT_TRUE(embedding_changes->empty());
} }
TEST(ClientRoot, ClientNotifiedOfPositionChangefromTransform) {
WindowServiceTestSetup setup;
aura::Window* window = setup.window_tree_test_helper()->NewTopLevelWindow();
window->SetBounds(gfx::Rect(0, 5, 100, 200));
setup.changes()->clear();
window->SetBounds(gfx::Rect(10, 15, 100, 200));
auto iter =
FirstChangeOfType(*setup.changes(), CHANGE_TYPE_NODE_BOUNDS_CHANGED);
ASSERT_NE(iter, setup.changes()->end());
EXPECT_EQ(gfx::Rect(10, 15, 100, 200), iter->bounds);
setup.changes()->clear();
gfx::Transform transform;
transform.Translate(gfx::Vector2dF(10.0, 20.0));
SetTransformAndWait(window, transform);
iter = FirstChangeOfType(*setup.changes(), CHANGE_TYPE_NODE_BOUNDS_CHANGED);
ASSERT_NE(iter, setup.changes()->end());
EXPECT_EQ(gfx::Rect(20, 35, 100, 200), iter->bounds);
setup.changes()->clear();
SetTransformAndWait(window, gfx::Transform());
iter = FirstChangeOfType(*setup.changes(), CHANGE_TYPE_NODE_BOUNDS_CHANGED);
ASSERT_NE(iter, setup.changes()->end());
EXPECT_EQ(gfx::Rect(10, 15, 100, 200), iter->bounds);
setup.changes()->clear();
}
} // namespace } // namespace
} // namespace ws } // namespace ws
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment