@@ -34,28 +34,23 @@ static constexpr int32_t kDefaultPointerDeviceId = 0;
3434// key event handler.
3535class SpyKeyboardKeyHandler : public KeyboardHandlerBase {
3636 public:
37- SpyKeyboardKeyHandler (flutter::BinaryMessenger* messenger,
38- KeyboardKeyHandler::EventDispatcher dispatch_event) {
39- real_implementation_ = std::make_unique<KeyboardKeyHandler>(dispatch_event);
37+ SpyKeyboardKeyHandler (flutter::BinaryMessenger* messenger) {
38+ real_implementation_ = std::make_unique<KeyboardKeyHandler>();
4039 real_implementation_->AddDelegate (
4140 std::make_unique<KeyboardKeyChannelHandler>(messenger));
42- ON_CALL (*this , KeyboardHook (_, _, _, _, _, _))
41+ ON_CALL (*this , KeyboardHook (_, _, _, _, _, _, _ ))
4342 .WillByDefault (Invoke (real_implementation_.get (),
4443 &KeyboardKeyHandler::KeyboardHook));
4544 }
4645
47- MOCK_METHOD6 (KeyboardHook,
48- bool (int key,
46+ MOCK_METHOD7 (KeyboardHook,
47+ void (int key,
4948 int scancode,
5049 int action,
5150 char32_t character,
5251 bool extended,
53- bool was_down));
54- MOCK_METHOD0 (ComposeBeginHook, void ());
55- MOCK_METHOD0 (ComposeCommitHook, void ());
56- MOCK_METHOD0 (ComposeEndHook, void ());
57- MOCK_METHOD2 (ComposeChangeHook,
58- void (const std::u16string& text, int cursor_pos));
52+ bool was_down,
53+ KeyEventCallback callback));
5954
6055 private:
6156 std::unique_ptr<KeyboardKeyHandler> real_implementation_;
@@ -101,7 +96,10 @@ class SpyTextInputPlugin : public TextInputPlugin,
10196class MockFlutterWindowWin32 : public FlutterWindowWin32 ,
10297 public MockMessageQueue {
10398 public:
104- MockFlutterWindowWin32 () : FlutterWindowWin32(800 , 600 ) {
99+ MockFlutterWindowWin32 (WPARAM virtual_key = 0 , bool is_printable = true )
100+ : virtual_key_(virtual_key),
101+ is_printable_ (is_printable),
102+ FlutterWindowWin32(800 , 600 ) {
105103 ON_CALL (*this , GetDpiScale ())
106104 .WillByDefault (Return (this ->FlutterWindowWin32 ::GetDpiScale ()));
107105 }
@@ -151,27 +149,68 @@ class MockFlutterWindowWin32 : public FlutterWindowWin32,
151149 MOCK_METHOD0 (OnResetImeComposing, void ());
152150
153151 protected:
154- virtual BOOL Win32PeekMessage (LPMSG lpMsg,
155- UINT wMsgFilterMin,
156- UINT wMsgFilterMax,
157- UINT wRemoveMsg) override {
152+ // |KeyboardManagerWin32::WindowDelegate|
153+ BOOL Win32PeekMessage (LPMSG lpMsg,
154+ UINT wMsgFilterMin,
155+ UINT wMsgFilterMax,
156+ UINT wRemoveMsg) override {
158157 return MockMessageQueue::Win32PeekMessage (lpMsg, wMsgFilterMin,
159158 wMsgFilterMax, wRemoveMsg);
160159 }
161160
161+ // |KeyboardManagerWin32::WindowDelegate|
162162 LRESULT Win32DefWindowProc (HWND hWnd,
163163 UINT Msg,
164164 WPARAM wParam,
165165 LPARAM lParam) override {
166166 return kWmResultDefault ;
167167 }
168168
169- private:
169+ // |KeyboardManagerWin32::WindowDelegate|
170+ UINT Win32DispatchEvent (UINT cInputs, LPINPUT pInputs, int cbSize) override {
171+ for (UINT input_idx = 0 ; input_idx < cInputs; input_idx += 1 ) {
172+ SendInput (pInputs[input_idx].ki );
173+ }
174+ return 1 ;
175+ }
176+
177+ // |MockMessageQueue|
170178 LRESULT Win32SendMessage (UINT const message,
171179 WPARAM const wparam,
172180 LPARAM const lparam) override {
173181 return HandleMessage (message, wparam, lparam);
174182 }
183+
184+ private:
185+ UINT SendInput (KEYBDINPUT kbdinput) {
186+ // Simulate the event loop by just sending the event sent to
187+ // "SendInput" directly to the window.
188+ const bool is_key_up = kbdinput.dwFlags & KEYEVENTF_KEYUP;
189+ const UINT message = is_key_up ? WM_KEYUP : WM_KEYDOWN;
190+
191+ const LPARAM lparam = CreateKeyEventLparam (
192+ kbdinput.wScan , kbdinput.dwFlags & KEYEVENTF_EXTENDEDKEY, is_key_up);
193+ // Windows would normally fill in the virtual key code for us, so we
194+ // simulate it for the test with the key we know is in the test. The
195+ // KBDINPUT we're passed doesn't have it filled in (on purpose, so that
196+ // Windows will fill it in).
197+ //
198+ // TODO(dkwingsmt): Don't check the message results for redispatched
199+ // messages for now, because making them work takes non-trivial rework
200+ // to our current structure. https://github.com/flutter/flutter/issues/87843
201+ // If this is resolved, change them to kWmResultDefault.
202+ pending_responds_.push_back (
203+ Win32Message{message, virtual_key_, lparam, kWmResultDontCheck });
204+ if (is_printable_ && (kbdinput.dwFlags & KEYEVENTF_KEYUP) == 0 ) {
205+ pending_responds_.push_back (
206+ Win32Message{WM_CHAR, virtual_key_, lparam, kWmResultDontCheck });
207+ }
208+ return 1 ;
209+ }
210+
211+ std::vector<Win32Message> pending_responds_;
212+ WPARAM virtual_key_;
213+ bool is_printable_;
175214};
176215
177216class MockWindowBindingHandlerDelegate : public WindowBindingHandlerDelegate {
@@ -201,7 +240,8 @@ class MockWindowBindingHandlerDelegate : public WindowBindingHandlerDelegate {
201240 FlutterPointerMouseButtons));
202241 MOCK_METHOD2 (OnPointerLeave, void (FlutterPointerDeviceKind, int32_t ));
203242 MOCK_METHOD1 (OnText, void (const std::u16string&));
204- MOCK_METHOD6 (OnKey, bool (int , int , int , char32_t , bool , bool ));
243+ MOCK_METHOD7 (OnKey,
244+ void (int , int , int , char32_t , bool , bool , KeyEventCallback));
205245 MOCK_METHOD0 (OnComposeBegin, void ());
206246 MOCK_METHOD0 (OnComposeCommit, void ());
207247 MOCK_METHOD0 (OnComposeEnd, void ());
@@ -223,32 +263,19 @@ class MockWindowBindingHandlerDelegate : public WindowBindingHandlerDelegate {
223263// to register the keyboard hook handlers that can be spied upon.
224264class TestFlutterWindowsView : public FlutterWindowsView {
225265 public:
226- TestFlutterWindowsView (std::unique_ptr<WindowBindingHandler> window_binding,
227- WPARAM virtual_key,
228- bool is_printable = true )
229- : FlutterWindowsView(std::move(window_binding)),
230- virtual_key_ (virtual_key),
231- is_printable_(is_printable) {}
266+ TestFlutterWindowsView (std::unique_ptr<WindowBindingHandler> window_binding)
267+ : FlutterWindowsView(std::move(window_binding)) {}
232268
233269 SpyKeyboardKeyHandler* key_event_handler;
234270 SpyTextInputPlugin* text_input_plugin;
235271
236- void InjectPendingEvents (MockFlutterWindowWin32* win32window) {
237- win32window->InjectMessageList (pending_responds_.size (),
238- pending_responds_.data ());
239- pending_responds_.clear ();
240- }
241-
242272 protected:
243273 std::unique_ptr<KeyboardHandlerBase> CreateKeyboardKeyHandler (
244274 flutter::BinaryMessenger* messenger,
245- flutter::KeyboardKeyHandler::EventDispatcher dispatch_event,
246275 flutter::KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state)
247276 override {
248- auto spy_key_event_handler = std::make_unique<SpyKeyboardKeyHandler>(
249- messenger, [this ](UINT cInputs, LPINPUT pInputs, int cbSize) -> UINT {
250- return this ->SendInput (cInputs, pInputs, cbSize);
251- });
277+ auto spy_key_event_handler =
278+ std::make_unique<SpyKeyboardKeyHandler>(messenger);
252279 key_event_handler = spy_key_event_handler.get ();
253280 return spy_key_event_handler;
254281 }
@@ -260,38 +287,6 @@ class TestFlutterWindowsView : public FlutterWindowsView {
260287 text_input_plugin = spy_key_event_handler.get ();
261288 return spy_key_event_handler;
262289 }
263-
264- private:
265- UINT SendInput (UINT cInputs, LPINPUT pInputs, int cbSize) {
266- // Simulate the event loop by just sending the event sent to
267- // "SendInput" directly to the window.
268- const KEYBDINPUT kbdinput = pInputs->ki ;
269- const bool is_key_up = kbdinput.dwFlags & KEYEVENTF_KEYUP;
270- const UINT message = is_key_up ? WM_KEYUP : WM_KEYDOWN;
271-
272- const LPARAM lparam = CreateKeyEventLparam (
273- kbdinput.wScan , kbdinput.dwFlags & KEYEVENTF_EXTENDEDKEY, is_key_up);
274- // Windows would normally fill in the virtual key code for us, so we
275- // simulate it for the test with the key we know is in the test. The
276- // KBDINPUT we're passed doesn't have it filled in (on purpose, so that
277- // Windows will fill it in).
278- //
279- // TODO(dkwingsmt): Don't check the message results for redispatched
280- // messages for now, because making them work takes non-trivial rework
281- // to our current structure. https://github.com/flutter/flutter/issues/87843
282- // If this is resolved, change them to kWmResultDefault.
283- pending_responds_.push_back (
284- Win32Message{message, virtual_key_, lparam, kWmResultDontCheck });
285- if (is_printable_ && (kbdinput.dwFlags & KEYEVENTF_KEYUP) == 0 ) {
286- pending_responds_.push_back (
287- Win32Message{WM_CHAR, virtual_key_, lparam, kWmResultDontCheck });
288- }
289- return 1 ;
290- }
291-
292- std::vector<Win32Message> pending_responds_;
293- WPARAM virtual_key_;
294- bool is_printable_;
295290};
296291
297292// The static value to return as the "handled" value from the framework for key
0 commit comments