Commit 4e2e4686 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Chromium LUCI CQ

Store requested bounds in WTHPlatform when creating platform windows

Early calls to Widget::SetBounds() for native windows with the same size
(but changing origin location, for example) may lead to "host resized"
event being propagated to widget's views tree when it shouldn't. Which
leads to tricky side effects, such as crbug.com/1151092 under Wayland,
for example. This avoids it by making sure initial bounding rectangle is
cached at WTHPlatform when creating the PlatformWindow instance.

R=sky@chromium.org

Bug: 1151092
Change-Id: I476dc11ef336e8443c83dfa874d160a1a6a9581f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593547Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#837711}
parent a1ae0828
...@@ -68,6 +68,11 @@ WindowTreeHostPlatform::WindowTreeHostPlatform(std::unique_ptr<Window> window) ...@@ -68,6 +68,11 @@ WindowTreeHostPlatform::WindowTreeHostPlatform(std::unique_ptr<Window> window)
void WindowTreeHostPlatform::CreateAndSetPlatformWindow( void WindowTreeHostPlatform::CreateAndSetPlatformWindow(
ui::PlatformWindowInitProperties properties) { ui::PlatformWindowInitProperties properties) {
// Cache initial bounds used to create |platform_window_| so that it does not
// end up propagating unneeded bounds change event when it is first notified
// through OnBoundsChanged, which may lead to unneeded re-layouts, etc.
bounds_in_pixels_ = properties.bounds;
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_OZONE) || defined(USE_X11)
#if defined(USE_OZONE) #if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) { if (features::IsUsingOzonePlatform()) {
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <utility> #include <utility>
#include "base/run_loop.h" #include "base/run_loop.h"
#include "ui/aura/window_tree_host.h"
#include "ui/aura/window_tree_host_observer.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/widget_observer.h" #include "ui/views/widget/widget_observer.h"
...@@ -207,4 +209,49 @@ TEST_F(DesktopWindowTreeHostPlatformTest, SetBoundsWithMinMax) { ...@@ -207,4 +209,49 @@ TEST_F(DesktopWindowTreeHostPlatformTest, SetBoundsWithMinMax) {
widget.GetWindowBoundsInScreen().size().ToString()); widget.GetWindowBoundsInScreen().size().ToString());
} }
class ResizeObserver : public aura::WindowTreeHostObserver {
public:
explicit ResizeObserver(aura::WindowTreeHost* host) : host_(host) {
host_->AddObserver(this);
}
ResizeObserver(const ResizeObserver&) = delete;
ResizeObserver& operator=(const ResizeObserver&) = delete;
~ResizeObserver() override { host_->RemoveObserver(this); }
int bounds_change_count() const { return bounds_change_count_; }
int resize_count() const { return resize_count_; }
// aura::WindowTreeHostObserver:
void OnHostResized(aura::WindowTreeHost* host) override { resize_count_++; }
void OnHostWillProcessBoundsChange(aura::WindowTreeHost* host) override {
bounds_change_count_++;
}
private:
aura::WindowTreeHost* const host_;
int resize_count_ = 0;
int bounds_change_count_ = 0;
};
// Verifies that setting widget bounds, just after creating it, with the same
// size passed in InitParams does not lead to a "bounds change" event. Prevents
// regressions, such as https://crbug.com/1151092.
TEST_F(DesktopWindowTreeHostPlatformTest, SetBoundsWithUnchangedSize) {
auto widget = CreateWidgetWithNativeWidget();
widget->Show();
EXPECT_EQ(gfx::Size(100, 100), widget->GetWindowBoundsInScreen().size());
auto* host = widget->GetNativeWindow()->GetHost();
ResizeObserver observer(host);
auto* dwth_platform = DesktopWindowTreeHostPlatform::GetHostForWidget(
widget->GetNativeWindow()->GetHost()->GetAcceleratedWidget());
ASSERT_TRUE(dwth_platform);
// Check with different origin.
dwth_platform->SetBoundsInPixels(gfx::Rect(2, 2, 100, 100));
EXPECT_EQ(1, observer.bounds_change_count());
EXPECT_EQ(0, observer.resize_count());
}
} // namespace views } // namespace views
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