Commit d6520b7d authored by Shawn Gallea's avatar Shawn Gallea Committed by Commit Bot

Add rounded corners when window is visible

This is needed to determine if rounded corners
are needed via window visibility.

Bug: b/156276792
Test: On device
Change-Id: Ibd893ccdac4af1e72789f8217b99433a41b8b25f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2202533
Commit-Queue: Shawn Gallea <sagallea@google.com>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Reviewed-by: default avatarRyan Daum <rdaum@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771163}
parent 291b9897
...@@ -589,6 +589,14 @@ cast_source_set("unittests") { ...@@ -589,6 +589,14 @@ cast_source_set("unittests") {
"//ui/events:test_support", "//ui/events:test_support",
] ]
} }
if (is_linux && use_ozone) {
sources += [ "webview/webview_window_manager_unittest.cc" ]
deps += [
"//chromecast/graphics",
"//components/exo",
]
}
} }
if (is_android) { if (is_android) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chromecast/browser/webview/webview_window_manager.h" #include "chromecast/browser/webview/webview_window_manager.h"
#include "base/stl_util.h"
#include "chromecast/graphics/cast_window_manager.h" #include "chromecast/graphics/cast_window_manager.h"
#include "components/exo/shell_surface_util.h" #include "components/exo/shell_surface_util.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
...@@ -18,36 +19,54 @@ class RoundedCornersObserver : public WebviewWindowManager::Observer, ...@@ -18,36 +19,54 @@ class RoundedCornersObserver : public WebviewWindowManager::Observer,
public aura::WindowObserver { public aura::WindowObserver {
public: public:
explicit RoundedCornersObserver(CastWindowManager* cast_window_manager) explicit RoundedCornersObserver(CastWindowManager* cast_window_manager)
: cast_window_manager_(cast_window_manager) {} : cast_window_manager_(cast_window_manager) {
DCHECK(cast_window_manager);
}
~RoundedCornersObserver() override {} ~RoundedCornersObserver() override {}
// WebviewWindowManager::Observer implementation // WebviewWindowManager::Observer implementation
void OnNewWebviewContainerWindow(aura::Window* window, int app_id) override { void OnNewWebviewContainerWindow(aura::Window* window, int app_id) override {
// Observe the lifecycle of this window so we can remove rounded corners // Observe the lifecycle of this window so we can add rounded corners
// when it goes away. // when it is visible.
window->AddObserver(this); window->AddObserver(this);
observed_container_windows_.insert(window);
// Add rounded corners on the first created window. if (window->IsVisible())
if (cast_window_manager_ && !num_container_windows_) { OnWindowVisibilityChanged(window, true);
cast_window_manager_->SetEnableRoundedCorners(true);
}
num_container_windows_++;
} }
// aura::WindowObserver implementation // aura::WindowObserver implementation
void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
if (!base::Contains(observed_container_windows_, window))
return;
num_visible_container_windows_ += visible ? 1 : -1;
DCHECK_GE(num_visible_container_windows_, 0);
cast_window_manager_->SetEnableRoundedCorners(
num_visible_container_windows_);
}
void OnWindowDestroyed(aura::Window* window) override { void OnWindowDestroyed(aura::Window* window) override {
if (!base::Contains(observed_container_windows_, window))
return;
observed_container_windows_.erase(window);
if (window->IsVisible()) {
num_visible_container_windows_--;
DCHECK_GE(num_visible_container_windows_, 0);
} else {
return;
}
// Remove the rounded corners when we're out of container windows. // Remove the rounded corners when we're out of container windows.
num_container_windows_--; if (!num_visible_container_windows_) {
DCHECK_GE(num_container_windows_, 0);
if (cast_window_manager_ && !num_container_windows_) {
cast_window_manager_->SetEnableRoundedCorners(false); cast_window_manager_->SetEnableRoundedCorners(false);
} }
} }
private: private:
CastWindowManager* cast_window_manager_; CastWindowManager* cast_window_manager_;
int num_container_windows_ = 0; int num_visible_container_windows_ = 0;
std::unordered_set<aura::Window*> observed_container_windows_;
DISALLOW_COPY_AND_ASSIGN(RoundedCornersObserver); DISALLOW_COPY_AND_ASSIGN(RoundedCornersObserver);
}; };
......
// Copyright 2020 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 "chromecast/browser/webview/webview_window_manager.h"
#include "chromecast/graphics/cast_window_manager_aura.h"
#include "components/exo/surface.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/base/class_property.h"
#include "ui/compositor/layer_type.h"
using ::testing::StrictMock;
namespace chromecast {
class MockCastWindowManager : public CastWindowManagerAura {
public:
MOCK_METHOD(void, SetEnableRoundedCorners, (bool enable), (override));
private:
using CastWindowManagerAura::CastWindowManagerAura;
};
class WebviewWindowManagerTest : public testing::Test {
public:
WebviewWindowManagerTest()
: env_(aura::Env::CreateInstance()),
mock_cast_window_manager_(new StrictMock<MockCastWindowManager>(true)),
webview_window_manager_(
new WebviewWindowManager(mock_cast_window_manager_.get())) {}
WebviewWindowManagerTest(const WebviewWindowManagerTest&) = delete;
WebviewWindowManagerTest& operator=(const WebviewWindowManagerTest&) = delete;
protected:
std::unique_ptr<aura::Env> env_;
std::unique_ptr<StrictMock<MockCastWindowManager>> mock_cast_window_manager_;
std::unique_ptr<WebviewWindowManager> webview_window_manager_;
};
TEST_F(WebviewWindowManagerTest, NoSetProperty) {
std::unique_ptr<aura::Window> window =
std::make_unique<aura::Window>(nullptr);
window->Init(ui::LAYER_TEXTURED);
window->Show();
window->Hide();
// StrictMock is used to verify SetEnableRoundedCorners is not called when
// kClientSurfaceIdKey property is not set.
}
TEST_F(WebviewWindowManagerTest,
SetRoundedCornersOnWindowAfterSettingExoPropertyAndShowing) {
std::unique_ptr<aura::Window> window =
std::make_unique<aura::Window>(nullptr);
window->Init(ui::LAYER_TEXTURED);
window->SetProperty(exo::kClientSurfaceIdKey, 1);
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(true));
window->Show();
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(false));
window = nullptr;
}
TEST_F(WebviewWindowManagerTest,
SetRoundedCornersOnVisibleWindowAfterSettingExoProperty) {
std::unique_ptr<aura::Window> window =
std::make_unique<aura::Window>(nullptr);
window->Init(ui::LAYER_TEXTURED);
window->Show();
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(true));
window->SetProperty(exo::kClientSurfaceIdKey, 1);
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(false));
window = nullptr;
}
TEST_F(WebviewWindowManagerTest, RemoveRoundedCornersAfterHidingWindow) {
std::unique_ptr<aura::Window> window =
std::make_unique<aura::Window>(nullptr);
window->Init(ui::LAYER_TEXTURED);
window->SetProperty(exo::kClientSurfaceIdKey, 1);
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(true));
window->Show();
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(false));
window->Hide();
}
TEST_F(WebviewWindowManagerTest,
RemoveRoundedCornersAfterHidingMultipleWindows) {
std::unique_ptr<aura::Window> window1 =
std::make_unique<aura::Window>(nullptr);
window1->Init(ui::LAYER_TEXTURED);
std::unique_ptr<aura::Window> window2 =
std::make_unique<aura::Window>(nullptr);
window2->Init(ui::LAYER_TEXTURED);
window1->SetProperty(exo::kClientSurfaceIdKey, 1);
window2->SetProperty(exo::kClientSurfaceIdKey, 2);
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(true))
.Times(3);
window1->Show();
window2->Show();
window1->Hide();
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(false));
window2->Hide();
}
TEST_F(WebviewWindowManagerTest,
RemoveRoundedCornersAfterDestroyingMultipleWindows) {
std::unique_ptr<aura::Window> window1 =
std::make_unique<aura::Window>(nullptr);
window1->Init(ui::LAYER_TEXTURED);
std::unique_ptr<aura::Window> window2 =
std::make_unique<aura::Window>(nullptr);
window2->Init(ui::LAYER_TEXTURED);
window1->SetProperty(exo::kClientSurfaceIdKey, 1);
window2->SetProperty(exo::kClientSurfaceIdKey, 2);
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(true))
.Times(2);
window1->Show();
window2->Show();
window1 = nullptr;
EXPECT_CALL(*mock_cast_window_manager_, SetEnableRoundedCorners(false));
window2 = nullptr;
}
} // namespace chromecast
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