flutter_flutter/shell/platform/windows/win32_flutter_window.h
Greg Spencer c8620c3fc1
Implement delayed key event synthesis for Windows (#23524)
This changes the Windows text handling so that keyboard events are sent to the framework first for handling, and then passed to the text input plugin, so that the framework has a chance to handle keys before they get given to the text field.

This is complicated by the async nature of the interaction with the framework, since Windows wants a synchronous response. So, in this change, I always tell Windows that the event was handled, and if the framework (eventually) responds that it wasn't, then I synthesize a new event and send it with SendEvent.

I also added support for detecting "extended" keys, since that was missing, and converted the OnKey handlers in the API to return a bool to indicate whether or not they have handled the event.
2021-01-22 18:14:39 -08:00

103 lines
2.9 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOW_H_
#define FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOW_H_
#include <windowsx.h>
#include <iostream>
#include <string>
#include <vector>
#include "flutter/shell/platform/common/cpp/geometry.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/windows/flutter_windows_view.h"
#include "flutter/shell/platform/windows/win32_window.h"
#include "flutter/shell/platform/windows/window_binding_handler.h"
namespace flutter {
// A win32 flutter child window used as implementatin for flutter view. In the
// future, there will likely be a CoreWindow-based FlutterWindow as well. At
// the point may make sense to dependency inject the native window rather than
// inherit.
class Win32FlutterWindow : public Win32Window, public WindowBindingHandler {
public:
// Create flutter Window for use as child window
Win32FlutterWindow(int width, int height);
virtual ~Win32FlutterWindow();
// |Win32Window|
void OnDpiScale(unsigned int dpi) override;
// |Win32Window|
void OnResize(unsigned int width, unsigned int height) override;
// |Win32Window|
void OnPointerMove(double x, double y) override;
// |Win32Window|
void OnPointerDown(double x, double y, UINT button) override;
// |Win32Window|
void OnPointerUp(double x, double y, UINT button) override;
// |Win32Window|
void OnPointerLeave() override;
// |Win32Window|
void OnSetCursor() override;
// |Win32Window|
void OnText(const std::u16string& text) override;
// |Win32Window|
bool OnKey(int key,
int scancode,
int action,
char32_t character,
bool extended) override;
// |Win32Window|
void OnScroll(double delta_x, double delta_y) override;
// |FlutterWindowBindingHandler|
void SetView(WindowBindingHandlerDelegate* view) override;
// |FlutterWindowBindingHandler|
WindowsRenderTarget GetRenderTarget() override;
// |FlutterWindowBindingHandler|
float GetDpiScale() override;
// |FlutterWindowBindingHandler|
PhysicalWindowBounds GetPhysicalWindowBounds() override;
// |FlutterWindowBindingHandler|
void UpdateFlutterCursor(const std::string& cursor_name) override;
// |FlutterWindowBindingHandler|
void UpdateCursorRect(const Rect& rect) override;
// |FlutterWindowBindingHandler|
void OnWindowResized() override;
private:
// A pointer to a FlutterWindowsView that can be used to update engine
// windowing and input state.
WindowBindingHandlerDelegate* binding_handler_delegate_;
// The last cursor set by Flutter. Defaults to the arrow cursor.
HCURSOR current_cursor_;
// The cursor rect set by Flutter.
RECT cursor_rect_;
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOW_H_