Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -3919,6 +3919,7 @@ ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_texture_registra
ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows_view_controller.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/keyboard_handler_base.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.h + ../../../flutter/LICENSE
Expand Down Expand Up @@ -6717,6 +6718,7 @@ FILE: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.
FILE: ../../../flutter/shell/platform/windows/flutter_windows_texture_registrar.h
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.cc
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view.h
FILE: ../../../flutter/shell/platform/windows/flutter_windows_view_controller.h
FILE: ../../../flutter/shell/platform/windows/keyboard_handler_base.h
FILE: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.cc
FILE: ../../../flutter/shell/platform/windows/keyboard_key_channel_handler.h
Expand Down
1 change: 1 addition & 0 deletions shell/platform/windows/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ source_set("flutter_windows_source") {
"flutter_windows_texture_registrar.h",
"flutter_windows_view.cc",
"flutter_windows_view.h",
"flutter_windows_view_controller.h",
"keyboard_handler_base.h",
"keyboard_key_channel_handler.cc",
"keyboard_key_channel_handler.h",
Expand Down
18 changes: 12 additions & 6 deletions shell/platform/windows/accessibility_bridge_windows_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ std::shared_ptr<AccessibilityBridgeWindowsSpy> GetAccessibilityBridgeSpy(
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(GetTestEngine());
view.SetEngine(engine.get());
view.OnUpdateSemanticsEnabled(true);

auto bridge = GetAccessibilityBridgeSpy(view);
Expand All @@ -206,10 +207,11 @@ void ExpectWinEventFromAXEventOnFocusNode(int32_t node_id,
ui::AXEventGenerator::Event ax_event,
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(GetTestEngine());
view.SetEngine(engine.get());
view.OnUpdateSemanticsEnabled(true);

auto bridge = GetAccessibilityBridgeSpy(view);
Expand All @@ -231,10 +233,11 @@ void ExpectWinEventFromAXEventOnFocusNode(int32_t node_id,
} // namespace

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(GetTestEngine());
view.SetEngine(engine.get());
view.OnUpdateSemanticsEnabled(true);

auto bridge = view.accessibility_bridge().lock();
Expand All @@ -247,10 +250,11 @@ 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(GetTestEngine());
view.SetEngine(engine.get());
view.OnUpdateSemanticsEnabled(true);

auto bridge = view.accessibility_bridge().lock();
Expand All @@ -261,10 +265,11 @@ 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(GetTestEngine());
view.SetEngine(engine.get());
view.OnUpdateSemanticsEnabled(true);

auto bridge = view.accessibility_bridge().lock();
Expand Down Expand Up @@ -297,10 +302,11 @@ 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(GetTestEngine());
view.SetEngine(engine.get());
view.OnUpdateSemanticsEnabled(true);

auto bridge = GetAccessibilityBridgeSpy(view);
Expand Down
62 changes: 40 additions & 22 deletions shell/platform/windows/flutter_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "flutter/shell/platform/windows/flutter_window.h"
#include "flutter/shell/platform/windows/flutter_windows_engine.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/flutter_windows_view_controller.h"
#include "flutter/shell/platform/windows/window_binding_handler.h"
#include "flutter/shell/platform/windows/window_state.h"

Expand All @@ -39,6 +40,16 @@ static FlutterDesktopEngineRef HandleForEngine(
return reinterpret_cast<FlutterDesktopEngineRef>(engine);
}

static flutter::FlutterWindowsViewController* ViewControllerFromHandle(
FlutterDesktopViewControllerRef ref) {
return reinterpret_cast<flutter::FlutterWindowsViewController*>(ref);
}

static FlutterDesktopViewControllerRef HandleForViewController(
flutter::FlutterWindowsViewController* view_controller) {
return reinterpret_cast<FlutterDesktopViewControllerRef>(view_controller);
}

// Returns the view corresponding to the given opaque API handle.
static flutter::FlutterWindowsView* ViewFromHandle(FlutterDesktopViewRef ref) {
return reinterpret_cast<flutter::FlutterWindowsView*>(ref);
Expand All @@ -64,58 +75,65 @@ static FlutterDesktopTextureRegistrarRef HandleForTextureRegistrar(
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(
int width,
int height,
FlutterDesktopEngineRef engine) {
FlutterDesktopEngineRef engine_ref) {
std::unique_ptr<flutter::WindowBindingHandler> window_wrapper =
std::make_unique<flutter::FlutterWindow>(width, height);

auto state = std::make_unique<FlutterDesktopViewControllerState>();
state->view =
auto engine = std::unique_ptr<flutter::FlutterWindowsEngine>(
EngineFromHandle(engine_ref));
auto view =
std::make_unique<flutter::FlutterWindowsView>(std::move(window_wrapper));
// Take ownership of the engine, starting it if necessary.
state->view->SetEngine(
std::unique_ptr<flutter::FlutterWindowsEngine>(EngineFromHandle(engine)));
state->view->CreateRenderSurface();
if (!state->view->GetEngine()->running()) {
if (!state->view->GetEngine()->Run()) {
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()) {
return nullptr;
}
}

// Must happen after engine is running.
state->view->SendInitialBounds();
state->view->SendInitialAccessibilityFeatures();
return state.release();
controller->view()->SendInitialBounds();
controller->view()->SendInitialAccessibilityFeatures();

return HandleForViewController(controller.release());
}

void FlutterDesktopViewControllerDestroy(
FlutterDesktopViewControllerRef controller) {
void FlutterDesktopViewControllerDestroy(FlutterDesktopViewControllerRef ref) {
auto controller = ViewControllerFromHandle(ref);
delete controller;
}

FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(
FlutterDesktopViewControllerRef controller) {
return HandleForEngine(controller->view->GetEngine());
FlutterDesktopViewControllerRef ref) {
auto controller = ViewControllerFromHandle(ref);
return HandleForEngine(controller->engine());
}

FlutterDesktopViewRef FlutterDesktopViewControllerGetView(
FlutterDesktopViewControllerRef controller) {
return HandleForView(controller->view.get());
FlutterDesktopViewControllerRef ref) {
auto controller = ViewControllerFromHandle(ref);
return HandleForView(controller->view());
}

void FlutterDesktopViewControllerForceRedraw(
FlutterDesktopViewControllerRef controller) {
controller->view->ForceRedraw();
FlutterDesktopViewControllerRef ref) {
auto controller = ViewControllerFromHandle(ref);
controller->view()->ForceRedraw();
}

bool FlutterDesktopViewControllerHandleTopLevelWindowProc(
FlutterDesktopViewControllerRef controller,
FlutterDesktopViewControllerRef ref,
HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam,
LRESULT* result) {
auto controller = ViewControllerFromHandle(ref);
std::optional<LRESULT> delegate_result =
controller->view->GetEngine()
controller->engine()
->window_proc_delegate_manager()
->OnTopLevelWindowProc(hwnd, message, wparam, lparam);
if (delegate_result) {
Expand Down
Loading