Skip to content

Commit

Permalink
Plumbing the min and max size to the framework from the embedder
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Feb 5, 2025
1 parent bdc0576 commit 97f52a1
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ class FlutterWindowsViewSpy : public FlutterWindowsView {
public:
FlutterWindowsViewSpy(FlutterWindowsEngine* engine,
std::unique_ptr<WindowBindingHandler> handler)
: FlutterWindowsView(kImplicitViewId, engine, std::move(handler), std::nullopt, std::nullopt) {}
: FlutterWindowsView(kImplicitViewId,
engine,
std::move(handler),
std::nullopt,
std::nullopt) {}

protected:
virtual std::shared_ptr<AccessibilityBridgeWindows>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class CompositorOpenGLTest : public WindowsTest {
EXPECT_CALL(*window.get(), GetWindowHandle).WillRepeatedly(Return(nullptr));

view_ = std::make_unique<FlutterWindowsView>(kImplicitViewId, engine_.get(),
std::move(window), std::nullopt,
std::nullopt);
std::move(window),
std::nullopt, std::nullopt);

if (add_surface) {
auto surface = std::make_unique<egl::MockWindowSurface>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ class MockFlutterWindowsView : public FlutterWindowsView {
public:
MockFlutterWindowsView(FlutterWindowsEngine* engine,
std::unique_ptr<WindowBindingHandler> window)
: FlutterWindowsView(kImplicitViewId, engine, std::move(window), std::nullopt, std::nullopt) {}
: FlutterWindowsView(kImplicitViewId,
engine,
std::move(window),
std::nullopt,
std::nullopt) {}
virtual ~MockFlutterWindowsView() = default;

MOCK_METHOD(bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class CursorHandlerTest : public WindowsTest {
window_ = window.get();
engine_ = builder.Build();
view_ = std::make_unique<FlutterWindowsView>(kImplicitViewId, engine_.get(),
std::move(window), std::nullopt,
std::nullopt);
std::move(window),
std::nullopt, std::nullopt);

EngineModifier modifier{engine_.get()};
modifier.SetImplicitView(view_.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ class MockFlutterWindowsView : public FlutterWindowsView {
public:
MockFlutterWindowsView(FlutterWindowsEngine* engine,
std::unique_ptr<WindowBindingHandler> window_binding)
: FlutterWindowsView(kImplicitViewId, engine, std::move(window_binding), std::nullopt, std::nullopt) {
}
: FlutterWindowsView(kImplicitViewId,
engine,
std::move(window_binding),
std::nullopt,
std::nullopt) {}
~MockFlutterWindowsView() {}

MOCK_METHOD(void,
Expand Down
4 changes: 2 additions & 2 deletions engine/src/flutter/shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static FlutterDesktopViewControllerRef CreateViewController(
engine = std::unique_ptr<flutter::FlutterWindowsEngine>(engine_ptr);
}

std::unique_ptr<flutter::FlutterWindowsView> view =
engine_ptr->CreateView(std::move(window_wrapper), std::nullopt, std::nullopt);
std::unique_ptr<flutter::FlutterWindowsView> view = engine_ptr->CreateView(
std::move(window_wrapper), std::nullopt, std::nullopt);
if (!view) {
return nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ std::unique_ptr<FlutterWindowsView> FlutterWindowsEngine::CreateView(
std::optional<Size> max_size) {
auto view_id = next_view_id_;
auto view = std::make_unique<FlutterWindowsView>(
view_id, this, std::move(window), min_size, max_size, windows_proc_table_);
view_id, this, std::move(window), min_size, max_size,
windows_proc_table_);

view->CreateRenderSurface();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,11 @@ class MockFlutterWindowsView : public FlutterWindowsView {
public:
MockFlutterWindowsView(FlutterWindowsEngine* engine,
std::unique_ptr<WindowBindingHandler> wbh)
: FlutterWindowsView(kImplicitViewId, engine, std::move(wbh), std::nullopt, std::nullopt) {}
: FlutterWindowsView(kImplicitViewId,
engine,
std::move(wbh),
std::nullopt,
std::nullopt) {}
~MockFlutterWindowsView() {}

MOCK_METHOD(void,
Expand Down Expand Up @@ -1283,16 +1287,17 @@ TEST_F(FlutterWindowsEngineTest, AddViewFailureDoesNotHang) {
// engine.
auto implicit_window = std::make_unique<NiceMock<MockWindowBindingHandler>>();

std::unique_ptr<FlutterWindowsView> implicit_view =
engine->CreateView(std::move(implicit_window), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> implicit_view = engine->CreateView(
std::move(implicit_window), std::nullopt, std::nullopt);

EXPECT_TRUE(implicit_view);

// Create a second view. The embedder attempts to add it to the engine.
auto second_window = std::make_unique<NiceMock<MockWindowBindingHandler>>();

EXPECT_DEBUG_DEATH(engine->CreateView(std::move(second_window), std::nullopt, std::nullopt),
"FlutterEngineAddView returned an unexpected result");
EXPECT_DEBUG_DEATH(
engine->CreateView(std::move(second_window), std::nullopt, std::nullopt),
"FlutterEngineAddView returned an unexpected result");
}

TEST_F(FlutterWindowsEngineTest, RemoveViewFailureDoesNotHang) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate {
FlutterWindowsView(
FlutterViewId view_id,
FlutterWindowsEngine* engine,
std::unique_ptr<WindowBindingHandler> window_binding,\
std::unique_ptr<WindowBindingHandler> window_binding,
std::optional<Size> min_size,
std::optional<Size> max_size,
std::shared_ptr<WindowsProcTable> windows_proc_table = nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ TEST(FlutterWindowsViewTest, SubMenuExpandedState) {

auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::move(window_binding_handler), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::move(window_binding_handler), std::nullopt, std::nullopt);

// Enable semantics to instantiate accessibility bridge.
view->OnUpdateSemanticsEnabled(true);
Expand Down Expand Up @@ -268,7 +268,8 @@ TEST(FlutterWindowsViewTest, Shutdown) {
.WillOnce(Return(&render_context));
EXPECT_CALL(render_context, ClearCurrent).WillOnce(Return(true));

view = engine->CreateView(std::move(window_binding_handler), std::nullopt, std::nullopt);
view = engine->CreateView(std::move(window_binding_handler), std::nullopt,
std::nullopt);
}

// The view must be removed before the surface can be destroyed.
Expand All @@ -293,8 +294,9 @@ TEST(FlutterWindowsViewTest, KeySequence) {

test_response = false;

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

view->OnKey(kVirtualKeyA, kScanCodeKeyA, WM_KEYDOWN, 'a', false, false,
[](bool handled) {});
Expand All @@ -309,8 +311,9 @@ TEST(FlutterWindowsViewTest, KeySequence) {
TEST(FlutterWindowsViewTest, KeyEventCallback) {
std::unique_ptr<FlutterWindowsEngine> engine = GetTestEngine();

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

class MockCallback {
public:
Expand Down Expand Up @@ -350,8 +353,8 @@ TEST(FlutterWindowsViewTest, EnableSemantics) {

auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::move(window_binding_handler), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::move(window_binding_handler), std::nullopt, std::nullopt);

view->OnUpdateSemanticsEnabled(true);
EXPECT_TRUE(semantics_enabled);
Expand All @@ -367,8 +370,8 @@ TEST(FlutterWindowsViewTest, AddSemanticsNodeUpdate) {

auto window_binding_handler =
std::make_unique<NiceMock<MockWindowBindingHandler>>();
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::move(window_binding_handler), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::move(window_binding_handler), std::nullopt, std::nullopt);

// Enable semantics to instantiate accessibility bridge.
view->OnUpdateSemanticsEnabled(true);
Expand Down Expand Up @@ -464,8 +467,9 @@ TEST(FlutterWindowsViewTest, AddSemanticsNodeUpdateWithChildren) {
return kSuccess;
};

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

// Enable semantics to instantiate accessibility bridge.
view->OnUpdateSemanticsEnabled(true);
Expand Down Expand Up @@ -660,8 +664,9 @@ TEST(FlutterWindowsViewTest, NonZeroSemanticsRoot) {
return kSuccess;
};

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

// Enable semantics to instantiate accessibility bridge.
view->OnUpdateSemanticsEnabled(true);
Expand Down Expand Up @@ -790,8 +795,9 @@ TEST(FlutterWindowsViewTest, AccessibilityHitTesting) {
return kSuccess;
};

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

// Enable semantics to instantiate accessibility bridge.
view->OnUpdateSemanticsEnabled(true);
Expand Down Expand Up @@ -913,8 +919,9 @@ TEST(FlutterWindowsViewTest, WindowResizeTests) {

engine_modifier.SetEGLManager(std::move(egl_manager));

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

fml::AutoResetWaitableEvent metrics_sent_latch;
engine_modifier.embedder_api().SendWindowMetricsEvent = MOCK_ENGINE_PROC(
Expand Down Expand Up @@ -982,8 +989,9 @@ TEST(FlutterWindowsViewTest, TestEmptyFrameResizes) {
return kSuccess;
}));

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

ViewModifier view_modifier{view.get()};
engine_modifier.SetEGLManager(std::move(egl_manager));
Expand Down Expand Up @@ -1026,8 +1034,9 @@ TEST(FlutterWindowsViewTest, WindowResizeRace) {
EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(true));
EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(true));

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

ViewModifier view_modifier{view.get()};
engine_modifier.SetEGLManager(std::move(egl_manager));
Expand Down Expand Up @@ -1074,8 +1083,9 @@ TEST(FlutterWindowsViewTest, WindowResizeInvalidSurface) {
EXPECT_CALL(*surface.get(), IsValid).WillRepeatedly(Return(false));
EXPECT_CALL(*surface.get(), Destroy).WillOnce(Return(false));

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

ViewModifier view_modifier{view.get()};
engine_modifier.SetEGLManager(std::move(egl_manager));
Expand All @@ -1102,8 +1112,9 @@ TEST(FlutterWindowsViewTest, WindowResizeWithoutSurface) {

EXPECT_CALL(*egl_manager.get(), CreateWindowSurface).Times(0);

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

modifier.SetEGLManager(std::move(egl_manager));

Expand All @@ -1123,7 +1134,8 @@ TEST(FlutterWindowsViewTest, WindowRepaintTests) {
EngineModifier modifier(engine.get());

FlutterWindowsView view{kImplicitViewId, engine.get(),
std::make_unique<flutter::FlutterWindow>(100, 100), std::nullopt, std::nullopt};
std::make_unique<flutter::FlutterWindow>(100, 100),
std::nullopt, std::nullopt};

bool schedule_frame_called = false;
modifier.embedder_api().ScheduleFrame =
Expand All @@ -1150,8 +1162,9 @@ TEST(FlutterWindowsViewTest, CheckboxNativeState) {
return kSuccess;
};

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

// Enable semantics to instantiate accessibility bridge.
view->OnUpdateSemanticsEnabled(true);
Expand Down Expand Up @@ -1294,8 +1307,9 @@ TEST(FlutterWindowsViewTest, SwitchNativeState) {
return kSuccess;
};

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

// Enable semantics to instantiate accessibility bridge.
view->OnUpdateSemanticsEnabled(true);
Expand Down Expand Up @@ -1411,8 +1425,9 @@ TEST(FlutterWindowsViewTest, TooltipNodeData) {
return kSuccess;
};

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);

// Enable semantics to instantiate accessibility bridge.
view->OnUpdateSemanticsEnabled(true);
Expand Down Expand Up @@ -1490,8 +1505,9 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAtStartup) {
EngineModifier modifier{engine.get()};
modifier.SetEGLManager(std::move(egl_manager));

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);
}

// Blocks until the v-blank if it is enabled by the window.
Expand Down Expand Up @@ -1525,8 +1541,9 @@ TEST(FlutterWindowsViewTest, EnablesVSyncAtStartup) {
EngineModifier modifier{engine.get()};
modifier.SetEGLManager(std::move(egl_manager));

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);
}

// Don't block until the v-blank if it is disabled by the window.
Expand Down Expand Up @@ -1568,8 +1585,9 @@ TEST(FlutterWindowsViewTest, DisablesVSyncAfterStartup) {
EngineModifier modifier{engine.get()};
modifier.SetEGLManager(std::move(egl_manager));

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);
}

// Blocks until the v-blank if it is enabled by the window.
Expand Down Expand Up @@ -1614,8 +1632,9 @@ TEST(FlutterWindowsViewTest, EnablesVSyncAfterStartup) {
EngineModifier modifier{engine.get()};
modifier.SetEGLManager(std::move(egl_manager));

std::unique_ptr<FlutterWindowsView> view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::unique_ptr<FlutterWindowsView> view =
engine->CreateView(std::make_unique<NiceMock<MockWindowBindingHandler>>(),
std::nullopt, std::nullopt);
}

// Desktop Window Manager composition can be disabled on Windows 7.
Expand Down Expand Up @@ -1660,7 +1679,8 @@ TEST(FlutterWindowsViewTest, UpdatesVSyncOnDwmUpdates) {
engine_modifier.SetEGLManager(std::move(egl_manager));

view = engine->CreateView(
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt, std::nullopt);
std::make_unique<NiceMock<MockWindowBindingHandler>>(), std::nullopt,
std::nullopt);
}

// Disabling DWM composition should enable vsync blocking on the surface.
Expand Down
Loading

0 comments on commit 97f52a1

Please sign in to comment.