Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Make the engine create the view #50673

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions shell/platform/windows/accessibility_bridge_windows_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace flutter {
namespace testing {

namespace {
using ::testing::NiceMock;

// A structure representing a Win32 MSAA event targeting a specified node.
struct MsaaEvent {
Expand Down Expand Up @@ -88,8 +89,9 @@ class AccessibilityBridgeWindowsSpy : public AccessibilityBridgeWindows {
// AccessibilityBridgeWindowsSpy.
class FlutterWindowsViewSpy : public FlutterWindowsView {
public:
explicit FlutterWindowsViewSpy(std::unique_ptr<WindowBindingHandler> handler)
: FlutterWindowsView(std::move(handler)) {}
FlutterWindowsViewSpy(FlutterWindowsEngine* engine,
std::unique_ptr<WindowBindingHandler> handler)
: FlutterWindowsView(engine, std::move(handler)) {}

protected:
virtual std::shared_ptr<AccessibilityBridgeWindows>
Expand Down Expand Up @@ -187,10 +189,10 @@ void ExpectWinEventFromAXEvent(int32_t node_id,
ui::AXEventGenerator::Event ax_event,
ax::mojom::Event expected_event) {
auto engine = GetTestEngine();
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
FlutterWindowsViewSpy view(std::move(window_binding_handler));
view.SetEngine(engine.get());
FlutterWindowsViewSpy view{
engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
EngineModifier modifier{engine.get()};
modifier.SetImplicitView(&view);
view.OnUpdateSemanticsEnabled(true);

auto bridge = GetAccessibilityBridgeSpy(view);
Expand All @@ -208,10 +210,10 @@ void ExpectWinEventFromAXEventOnFocusNode(int32_t node_id,
ax::mojom::Event expected_event,
int32_t focus_id) {
auto engine = GetTestEngine();
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
FlutterWindowsViewSpy view(std::move(window_binding_handler));
view.SetEngine(engine.get());
FlutterWindowsViewSpy view{
engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
EngineModifier modifier{engine.get()};
modifier.SetImplicitView(&view);
view.OnUpdateSemanticsEnabled(true);

auto bridge = GetAccessibilityBridgeSpy(view);
Expand All @@ -234,10 +236,10 @@ void ExpectWinEventFromAXEventOnFocusNode(int32_t node_id,

TEST(AccessibilityBridgeWindows, GetParent) {
auto engine = GetTestEngine();
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
FlutterWindowsViewSpy view(std::move(window_binding_handler));
view.SetEngine(engine.get());
FlutterWindowsViewSpy view{
engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
EngineModifier modifier{engine.get()};
modifier.SetImplicitView(&view);
view.OnUpdateSemanticsEnabled(true);

auto bridge = view.accessibility_bridge().lock();
Expand All @@ -251,10 +253,10 @@ TEST(AccessibilityBridgeWindows, GetParent) {

TEST(AccessibilityBridgeWindows, GetParentOnRootRetunsNullptr) {
auto engine = GetTestEngine();
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
FlutterWindowsViewSpy view(std::move(window_binding_handler));
view.SetEngine(engine.get());
FlutterWindowsViewSpy view{
engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
EngineModifier modifier{engine.get()};
modifier.SetImplicitView(&view);
view.OnUpdateSemanticsEnabled(true);

auto bridge = view.accessibility_bridge().lock();
Expand All @@ -266,17 +268,16 @@ TEST(AccessibilityBridgeWindows, GetParentOnRootRetunsNullptr) {

TEST(AccessibilityBridgeWindows, DispatchAccessibilityAction) {
auto engine = GetTestEngine();
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
FlutterWindowsViewSpy view(std::move(window_binding_handler));
view.SetEngine(engine.get());
FlutterWindowsViewSpy view{
engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
EngineModifier modifier{engine.get()};
modifier.SetImplicitView(&view);
view.OnUpdateSemanticsEnabled(true);

auto bridge = view.accessibility_bridge().lock();
PopulateAXTree(bridge);

FlutterSemanticsAction actual_action = kFlutterSemanticsActionTap;
EngineModifier modifier(view.GetEngine());
modifier.embedder_api().DispatchSemanticsAction = MOCK_ENGINE_PROC(
DispatchSemanticsAction,
([&actual_action](FLUTTER_API_SYMBOL(FlutterEngine) engine, uint64_t id,
Expand All @@ -303,10 +304,10 @@ TEST(AccessibilityBridgeWindows, OnAccessibilityEventChildrenChanged) {

TEST(AccessibilityBridgeWindows, OnAccessibilityEventFocusChanged) {
auto engine = GetTestEngine();
auto window_binding_handler =
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
FlutterWindowsViewSpy view(std::move(window_binding_handler));
view.SetEngine(engine.get());
FlutterWindowsViewSpy view{
engine.get(), std::make_unique<NiceMock<MockWindowBindingHandler>>()};
EngineModifier modifier{engine.get()};
modifier.SetImplicitView(&view);
view.OnUpdateSemanticsEnabled(true);

auto bridge = GetAccessibilityBridgeSpy(view);
Expand Down
8 changes: 5 additions & 3 deletions shell/platform/windows/compositor_opengl_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CompositorOpenGLTest : public WindowsTest {
FlutterWindowsEngineBuilder builder{GetContext()};

engine_ = builder.Build();
EngineModifier modifier(engine_.get());
EngineModifier modifier{engine_.get()};
modifier.SetEGLManager(std::move(egl_manager));
}

Expand All @@ -95,7 +95,8 @@ class CompositorOpenGLTest : public WindowsTest {
EXPECT_CALL(*window.get(), SetView).Times(1);
EXPECT_CALL(*window.get(), GetWindowHandle).WillRepeatedly(Return(nullptr));

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

if (add_surface) {
auto surface = std::make_unique<egl::MockWindowSurface>();
Expand All @@ -107,7 +108,8 @@ class CompositorOpenGLTest : public WindowsTest {
modifier.SetSurface(std::move(surface));
}

engine_->SetView(view_.get());
EngineModifier modifier{engine_.get()};
modifier.SetImplicitView(view_.get());
}

private:
Expand Down
11 changes: 7 additions & 4 deletions shell/platform/windows/compositor_software_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ using ::testing::Return;

class MockFlutterWindowsView : public FlutterWindowsView {
public:
MockFlutterWindowsView(std::unique_ptr<WindowBindingHandler> window)
: FlutterWindowsView(std::move(window)) {}
MockFlutterWindowsView(FlutterWindowsEngine* engine,
std::unique_ptr<WindowBindingHandler> window)
: FlutterWindowsView(engine, std::move(window)) {}
virtual ~MockFlutterWindowsView() = default;

MOCK_METHOD(bool,
Expand Down Expand Up @@ -59,9 +60,11 @@ class CompositorSoftwareTest : public WindowsTest {
EXPECT_CALL(*window.get(), GetWindowHandle).WillRepeatedly(Return(nullptr));

engine_ = builder.Build();
view_ = std::make_unique<MockFlutterWindowsView>(std::move(window));
view_ = std::make_unique<MockFlutterWindowsView>(engine_.get(),
std::move(window));

engine_->SetView(view_.get());
EngineModifier modifier{engine_.get()};
modifier.SetImplicitView(view_.get());
}

private:
Expand Down
11 changes: 7 additions & 4 deletions shell/platform/windows/cursor_handler_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/testing/engine_modifier.h"
#include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
#include "flutter/shell/platform/windows/testing/test_binary_messenger.h"
Expand Down Expand Up @@ -73,14 +74,16 @@ class CursorHandlerTest : public WindowsTest {
FlutterWindowsEngineBuilder builder{GetContext()};

auto window = std::make_unique<MockWindowBindingHandler>();
EXPECT_CALL(*window.get(), SetView).Times(1);
EXPECT_CALL(*window.get(), GetWindowHandle).WillRepeatedly(Return(nullptr));

window_ = window.get();
EXPECT_CALL(*window_, SetView).Times(1);

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

engine_->SetView(view_.get());
EngineModifier modifier{engine_.get()};
modifier.SetImplicitView(view_.get());
}

private:
Expand Down
16 changes: 10 additions & 6 deletions shell/platform/windows/flutter_window_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "flutter/fml/macros.h"
#include "flutter/shell/platform/windows/flutter_window.h"
#include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h"
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h"
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler_delegate.h"
#include "flutter/shell/platform/windows/testing/windows_test.h"
Expand All @@ -26,7 +27,7 @@ static constexpr int32_t kDefaultPointerDeviceId = 0;
class MockFlutterWindow : public FlutterWindow {
public:
MockFlutterWindow(bool reset_view_on_exit = true)
: FlutterWindow(), reset_view_on_exit_(reset_view_on_exit) {
: reset_view_on_exit_(reset_view_on_exit) {
ON_CALL(*this, GetDpiScale())
.WillByDefault(Return(this->FlutterWindow::GetDpiScale()));
}
Expand Down Expand Up @@ -95,8 +96,9 @@ class MockFlutterWindow : public FlutterWindow {

class MockFlutterWindowsView : public FlutterWindowsView {
public:
MockFlutterWindowsView(std::unique_ptr<WindowBindingHandler> window_binding)
: FlutterWindowsView(std::move(window_binding)) {}
MockFlutterWindowsView(FlutterWindowsEngine* engine,
std::unique_ptr<WindowBindingHandler> window_binding)
: FlutterWindowsView(engine, std::move(window_binding)) {}
~MockFlutterWindowsView() {}

MOCK_METHOD(void,
Expand Down Expand Up @@ -313,12 +315,14 @@ TEST_F(FlutterWindowTest, AccessibilityNodeWithoutView) {
// Ensure that announcing the alert propagates the message to the alert node.
// Different screen readers use different properties for alerts.
TEST_F(FlutterWindowTest, AlertNode) {
std::unique_ptr<MockFlutterWindow> win32window =
std::make_unique<MockFlutterWindow>();
std::unique_ptr<FlutterWindowsEngine> engine =
FlutterWindowsEngineBuilder{GetContext()}.Build();
auto win32window = std::make_unique<MockFlutterWindow>();
EXPECT_CALL(*win32window.get(), GetAxFragmentRootDelegate())
.WillRepeatedly(Return(nullptr));
EXPECT_CALL(*win32window.get(), OnWindowStateEvent).Times(AnyNumber());
MockFlutterWindowsView view(std::move(win32window));
EXPECT_CALL(*win32window.get(), GetWindowHandle).Times(AnyNumber());
MockFlutterWindowsView view{engine.get(), std::move(win32window)};
std::wstring message = L"Test alert";
EXPECT_CALL(view, NotifyWinEventWrapper(_, ax::mojom::Event::kAlert))
.Times(1);
Expand Down
5 changes: 2 additions & 3 deletions shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(
width, height, engine_ptr->windows_proc_table());

auto engine = std::unique_ptr<flutter::FlutterWindowsEngine>(engine_ptr);
auto view = std::make_unique<flutter::FlutterWindowsView>(
std::move(window_wrapper), engine_ptr->windows_proc_table());
std::unique_ptr<flutter::FlutterWindowsView> view =
engine->CreateView(std::move(window_wrapper));
auto controller = std::make_unique<flutter::FlutterWindowsViewController>(
std::move(engine), std::move(view));

controller->view()->SetEngine(controller->engine());
controller->view()->CreateRenderSurface();
if (!controller->engine()->running()) {
if (!controller->engine()->Run()) {
Expand Down
10 changes: 8 additions & 2 deletions shell/platform/windows/flutter_windows_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,15 @@ bool FlutterWindowsEngine::Stop() {
return false;
}

void FlutterWindowsEngine::SetView(FlutterWindowsView* view) {
view_ = view;
std::unique_ptr<FlutterWindowsView> FlutterWindowsEngine::CreateView(
std::unique_ptr<WindowBindingHandler> window) {
auto view = std::make_unique<FlutterWindowsView>(this, std::move(window),
windows_proc_table_);

view_ = view.get();
InitializeKeyboard();

return std::move(view);
}

void FlutterWindowsEngine::OnVsync(intptr_t baton) {
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/windows/flutter_windows_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ class FlutterWindowsEngine {
// Returns false if stopping the engine fails, or if it was not running.
virtual bool Stop();

// Sets the view that is displaying this engine's content.
void SetView(FlutterWindowsView* view);
// Create the view that is displaying this engine's content.
std::unique_ptr<FlutterWindowsView> CreateView(
std::unique_ptr<WindowBindingHandler> window);

// The view displaying this engine's content, if any. This will be null for
// headless engines.
Expand Down
Loading