views: Support specification of screen bounds for CefWindow creation (fixes issue #2980)

This commit is contained in:
Marshall Greenblatt
2020-09-02 14:25:25 -04:00
parent 4aad5f23a0
commit b579b37db4
10 changed files with 129 additions and 12 deletions

View File

@@ -70,9 +70,24 @@ void TestWindowDelegate::OnWindowCreated(CefRefPtr<CefWindow> window) {
EXPECT_TRUE(window->GetDisplay().get());
// Size will come from GetPreferredSize() on initial Window creation.
EXPECT_TRUE(got_get_preferred_size_);
// Size will come from GetGetInitialBounds() or GetPreferredSize() on
// initial Window creation.
EXPECT_TRUE(got_get_initial_bounds_);
if (config_.window_origin.IsEmpty())
EXPECT_TRUE(got_get_preferred_size_);
else
EXPECT_FALSE(got_get_preferred_size_);
CefRect client_bounds = window->GetBounds();
if (!config_.window_origin.IsEmpty()) {
EXPECT_EQ(config_.window_origin.x, client_bounds.x);
EXPECT_EQ(config_.window_origin.y, client_bounds.y);
} else {
// Default origin is (0,0).
EXPECT_EQ(0, client_bounds.x);
EXPECT_EQ(0, client_bounds.y);
}
if (config_.frameless) {
EXPECT_EQ(config_.window_size, client_bounds.width);
EXPECT_EQ(config_.window_size, client_bounds.height);
@@ -124,6 +139,17 @@ bool TestWindowDelegate::IsFrameless(CefRefPtr<CefWindow> window) {
return config_.frameless;
}
CefRect TestWindowDelegate::GetInitialBounds(CefRefPtr<CefWindow> window) {
got_get_initial_bounds_ = true;
if (!config_.window_origin.IsEmpty()) {
return CefRect(config_.window_origin.x, config_.window_origin.y,
window_size_.width, window_size_.height);
}
// Call GetPreferredSize().
return CefRect();
}
CefSize TestWindowDelegate::GetPreferredSize(CefRefPtr<CefView> view) {
got_get_preferred_size_ = true;
return window_size_;

View File

@@ -28,6 +28,7 @@ class TestWindowDelegate : public CefWindowDelegate {
bool frameless = false;
bool close_window = true;
int window_size = kWSize;
CefPoint window_origin = {};
};
// Creates a Window with a new TestWindowDelegate instance and executes
@@ -42,6 +43,7 @@ class TestWindowDelegate : public CefWindowDelegate {
void OnWindowCreated(CefRefPtr<CefWindow> window) override;
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override;
bool IsFrameless(CefRefPtr<CefWindow> window) override;
CefRect GetInitialBounds(CefRefPtr<CefWindow> window) override;
CefSize GetPreferredSize(CefRefPtr<CefView> view) override;
bool OnAccelerator(CefRefPtr<CefWindow> window, int command_id) override;
bool OnKeyEvent(CefRefPtr<CefWindow> window,
@@ -62,6 +64,7 @@ class TestWindowDelegate : public CefWindowDelegate {
CefRefPtr<CefWindow> window_;
bool got_get_initial_bounds_ = false;
bool got_get_preferred_size_ = false;
// Must be the last member.

View File

@@ -47,12 +47,23 @@ void WindowCreateFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::RunTest(event, config);
}
void RunWindowShowHide(CefRefPtr<CefWindow> window) {
void RunWindowShow(CefRefPtr<CefWindow> window) {
EXPECT_FALSE(window->IsVisible());
EXPECT_FALSE(window->IsDrawn());
window->Show();
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->IsDrawn());
}
void WindowCreateWithOriginImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.window_origin = {100, 200};
config.on_window_created = base::Bind(RunWindowShow);
TestWindowDelegate::RunTest(event, config);
}
void RunWindowShowHide(CefRefPtr<CefWindow> window) {
RunWindowShow(window);
window->Hide();
EXPECT_FALSE(window->IsVisible());
EXPECT_FALSE(window->IsDrawn());
@@ -481,6 +492,7 @@ void WindowAcceleratorImpl(CefRefPtr<CefWaitableEvent> event) {
// we presume that Chromium is testing).
WINDOW_TEST_ASYNC(WindowCreate)
WINDOW_TEST_ASYNC(WindowCreateFrameless)
WINDOW_TEST_ASYNC(WindowCreateWithOrigin)
WINDOW_TEST_ASYNC(WindowShowHide)
WINDOW_TEST_ASYNC(WindowShowHideFrameless)
WINDOW_TEST_ASYNC(WindowLayoutAndCoords)