Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Windows] Begin decoupling text input plugin from the view #47833

Merged
merged 3 commits into from
Nov 30, 2023
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: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -7160,7 +7160,6 @@ ORIGIN: ../../../flutter/shell/platform/windows/text_input_manager.cc + ../../..
ORIGIN: ../../../flutter/shell/platform/windows/text_input_manager.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/text_input_plugin_delegate.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/window_binding_handler.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -9978,7 +9977,6 @@ FILE: ../../../flutter/shell/platform/windows/text_input_manager.cc
FILE: ../../../flutter/shell/platform/windows/text_input_manager.h
FILE: ../../../flutter/shell/platform/windows/text_input_plugin.cc
FILE: ../../../flutter/shell/platform/windows/text_input_plugin.h
FILE: ../../../flutter/shell/platform/windows/text_input_plugin_delegate.h
FILE: ../../../flutter/shell/platform/windows/window_binding_handler.h
FILE: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h
FILE: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc
Expand Down
20 changes: 10 additions & 10 deletions shell/platform/windows/cursor_handler_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class CursorHandlerTest : public WindowsTest {
FlutterWindowsView* view() { return view_.get(); }
MockWindowBindingHandler* window() { return window_; }

void use_headless_engine() {
void UseHeadlessEngine() {
FlutterWindowsEngineBuilder builder{GetContext()};

engine_ = builder.Build();
}

void use_engine_with_view() {
void UseEngineWithView() {
FlutterWindowsEngineBuilder builder{GetContext()};

auto window = std::make_unique<MockWindowBindingHandler>();
Expand All @@ -93,7 +93,7 @@ class CursorHandlerTest : public WindowsTest {
};

TEST_F(CursorHandlerTest, ActivateSystemCursor) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
CursorHandler cursor_handler(&messenger, engine());
Expand All @@ -119,7 +119,7 @@ TEST_F(CursorHandlerTest, ActivateSystemCursor) {
}

TEST_F(CursorHandlerTest, ActivateSystemCursorRequiresView) {
use_headless_engine();
UseHeadlessEngine();

TestBinaryMessenger messenger;
CursorHandler cursor_handler(&messenger, engine());
Expand All @@ -146,7 +146,7 @@ TEST_F(CursorHandlerTest, ActivateSystemCursorRequiresView) {
}

TEST_F(CursorHandlerTest, CreateCustomCursor) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
CursorHandler cursor_handler(&messenger, engine());
Expand Down Expand Up @@ -177,7 +177,7 @@ TEST_F(CursorHandlerTest, CreateCustomCursor) {
}

TEST_F(CursorHandlerTest, SetCustomCursor) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
CursorHandler cursor_handler(&messenger, engine());
Expand Down Expand Up @@ -217,7 +217,7 @@ TEST_F(CursorHandlerTest, SetCustomCursor) {
}

TEST_F(CursorHandlerTest, SetCustomCursorRequiresView) {
use_headless_engine();
UseHeadlessEngine();

TestBinaryMessenger messenger;
CursorHandler cursor_handler(&messenger, engine());
Expand Down Expand Up @@ -258,7 +258,7 @@ TEST_F(CursorHandlerTest, SetCustomCursorRequiresView) {
}

TEST_F(CursorHandlerTest, SetNonexistentCustomCursor) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
CursorHandler cursor_handler(&messenger, engine());
Expand Down Expand Up @@ -287,7 +287,7 @@ TEST_F(CursorHandlerTest, SetNonexistentCustomCursor) {
}

TEST_F(CursorHandlerTest, DeleteCustomCursor) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
CursorHandler cursor_handler(&messenger, engine());
Expand Down Expand Up @@ -325,7 +325,7 @@ TEST_F(CursorHandlerTest, DeleteCustomCursor) {
}

TEST_F(CursorHandlerTest, DeleteNonexistentCustomCursor) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
CursorHandler cursor_handler(&messenger, engine());
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/windows/flutter_windows_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ FlutterWindowsEngine::CreateKeyboardKeyHandler(

std::unique_ptr<TextInputPlugin> FlutterWindowsEngine::CreateTextInputPlugin(
BinaryMessenger* messenger) {
return std::make_unique<TextInputPlugin>(messenger, view_);
return std::make_unique<TextInputPlugin>(messenger, this);
}

bool FlutterWindowsEngine::RegisterExternalTexture(int64_t texture_id) {
Expand Down
17 changes: 8 additions & 9 deletions shell/platform/windows/flutter_windows_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "flutter/shell/platform/windows/angle_surface_manager.h"
#include "flutter/shell/platform/windows/flutter_windows_engine.h"
#include "flutter/shell/platform/windows/public/flutter_windows.h"
#include "flutter/shell/platform/windows/text_input_plugin_delegate.h"
#include "flutter/shell/platform/windows/window_binding_handler.h"
#include "flutter/shell/platform/windows/window_binding_handler_delegate.h"
#include "flutter/shell/platform/windows/window_state.h"
Expand All @@ -30,10 +29,9 @@ namespace flutter {
// ID for the window frame buffer.
inline constexpr uint32_t kWindowFrameBufferID = 0;

// An OS-windowing neutral abstration for flutter
// view that works with win32 hwnds and Windows::UI::Composition visuals.
class FlutterWindowsView : public WindowBindingHandlerDelegate,
public TextInputPluginDelegate {
// An OS-windowing neutral abstration for a Flutter view that works
// with win32 HWNDs.
class FlutterWindowsView : public WindowBindingHandlerDelegate {
public:
// Creates a FlutterWindowsView with the given implementor of
// WindowBindingHandler.
Expand Down Expand Up @@ -186,11 +184,12 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate,
// |WindowBindingHandlerDelegate|
virtual gfx::NativeViewAccessible GetNativeViewAccessible() override;

// |TextInputPluginDelegate|
void OnCursorRectUpdated(const Rect& rect) override;
// Notifies the delegate of the updated the cursor rect in Flutter root view
// coordinates.
virtual void OnCursorRectUpdated(const Rect& rect);

// |TextInputPluginDelegate|
void OnResetImeComposing() override;
// Notifies the delegate that the system IME composing state should be reset.
virtual void OnResetImeComposing();

// Called when a WM_ONCOMPOSITIONCHANGED message is received.
void OnDwmCompositionChanged();
Expand Down
46 changes: 23 additions & 23 deletions shell/platform/windows/platform_handler_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ class PlatformHandlerTest : public WindowsTest {
protected:
FlutterWindowsEngine* engine() { return engine_.get(); }

void use_headless_engine() {
void UseHeadlessEngine() {
FlutterWindowsEngineBuilder builder{GetContext()};

engine_ = builder.Build();
}

void use_engine_with_view() {
void UseEngineWithView() {
FlutterWindowsEngineBuilder builder{GetContext()};

auto window = std::make_unique<NiceMock<MockWindowBindingHandler>>();
Expand All @@ -166,7 +166,7 @@ class PlatformHandlerTest : public WindowsTest {
};

TEST_F(PlatformHandlerTest, GetClipboardData) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -190,7 +190,7 @@ TEST_F(PlatformHandlerTest, GetClipboardData) {
}

TEST_F(PlatformHandlerTest, GetClipboardDataRejectsUnknownContentType) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine());
Expand All @@ -203,7 +203,7 @@ TEST_F(PlatformHandlerTest, GetClipboardDataRejectsUnknownContentType) {
}

TEST_F(PlatformHandlerTest, GetClipboardDataRequiresView) {
use_headless_engine();
UseHeadlessEngine();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine());
Expand All @@ -217,7 +217,7 @@ TEST_F(PlatformHandlerTest, GetClipboardDataRequiresView) {
}

TEST_F(PlatformHandlerTest, GetClipboardDataReportsOpenFailure) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -237,7 +237,7 @@ TEST_F(PlatformHandlerTest, GetClipboardDataReportsOpenFailure) {
}

TEST_F(PlatformHandlerTest, GetClipboardDataReportsGetDataFailure) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -261,7 +261,7 @@ TEST_F(PlatformHandlerTest, GetClipboardDataReportsGetDataFailure) {
}

TEST_F(PlatformHandlerTest, ClipboardHasStrings) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -282,7 +282,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStrings) {
}

TEST_F(PlatformHandlerTest, ClipboardHasStringsReturnsFalse) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -303,7 +303,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsReturnsFalse) {
}

TEST_F(PlatformHandlerTest, ClipboardHasStringsRejectsUnknownContentType) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine());
Expand All @@ -315,7 +315,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsRejectsUnknownContentType) {
}

TEST_F(PlatformHandlerTest, ClipboardHasStringsRequiresView) {
use_headless_engine();
UseHeadlessEngine();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine());
Expand All @@ -330,7 +330,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsRequiresView) {

// Regression test for https://github.com/flutter/flutter/issues/95817.
TEST_F(PlatformHandlerTest, ClipboardHasStringsIgnoresPermissionErrors) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -350,7 +350,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsIgnoresPermissionErrors) {
}

TEST_F(PlatformHandlerTest, ClipboardHasStringsReportsErrors) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -370,7 +370,7 @@ TEST_F(PlatformHandlerTest, ClipboardHasStringsReportsErrors) {
}

TEST_F(PlatformHandlerTest, ClipboardSetData) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -397,7 +397,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetData) {

// Regression test for: https://github.com/flutter/flutter/issues/121976
TEST_F(PlatformHandlerTest, ClipboardSetDataTextMustBeString) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine());
Expand All @@ -409,7 +409,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataTextMustBeString) {
}

TEST_F(PlatformHandlerTest, ClipboardSetDataUnknownType) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine());
Expand All @@ -421,7 +421,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataUnknownType) {
}

TEST_F(PlatformHandlerTest, ClipboardSetDataRequiresView) {
use_headless_engine();
UseHeadlessEngine();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine());
Expand All @@ -435,7 +435,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataRequiresView) {
}

TEST_F(PlatformHandlerTest, ClipboardSetDataReportsOpenFailure) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -455,7 +455,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataReportsOpenFailure) {
}

TEST_F(PlatformHandlerTest, ClipboardSetDataReportsSetDataFailure) {
use_engine_with_view();
UseEngineWithView();

TestBinaryMessenger messenger;
PlatformHandler platform_handler(&messenger, engine(), []() {
Expand All @@ -478,7 +478,7 @@ TEST_F(PlatformHandlerTest, ClipboardSetDataReportsSetDataFailure) {
}

TEST_F(PlatformHandlerTest, PlaySystemSound) {
use_headless_engine();
UseHeadlessEngine();

TestBinaryMessenger messenger;
MockPlatformHandler platform_handler(&messenger, engine());
Expand All @@ -496,7 +496,7 @@ TEST_F(PlatformHandlerTest, PlaySystemSound) {
}

TEST_F(PlatformHandlerTest, SystemExitApplicationRequired) {
use_headless_engine();
UseHeadlessEngine();
UINT exit_code = 0;

TestBinaryMessenger messenger([](const std::string& channel,
Expand All @@ -518,7 +518,7 @@ TEST_F(PlatformHandlerTest, SystemExitApplicationRequired) {
}

TEST_F(PlatformHandlerTest, SystemExitApplicationCancelableCancel) {
use_headless_engine();
UseHeadlessEngine();
bool called_cancel = false;

TestBinaryMessenger messenger(
Expand All @@ -539,7 +539,7 @@ TEST_F(PlatformHandlerTest, SystemExitApplicationCancelableCancel) {
}

TEST_F(PlatformHandlerTest, SystemExitApplicationCancelableExit) {
use_headless_engine();
UseHeadlessEngine();
bool called_cancel = false;
UINT exit_code = 0;

Expand Down
Loading