Flutter Engine
flutter::WindowWin32 Class Referenceabstract

#include <window_win32.h>

Inheritance diagram for flutter::WindowWin32:
flutter::KeyboardManagerWin32::WindowDelegate flutter::FlutterWindowWin32 flutter::testing::MockWin32Window flutter::testing::FlutterWindowWin32Test

Public Member Functions

 WindowWin32 ()
 
 WindowWin32 (std::unique_ptr< TextInputManagerWin32 > text_input_manager)
 
virtual ~WindowWin32 ()
 
void InitializeChild (const char *title, unsigned int width, unsigned int height)
 
HWND GetWindowHandle ()
 
virtual BOOL Win32PeekMessage (LPMSG lpMsg, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg) override
 
virtual uint32_t Win32MapVkToChar (uint32_t virtual_key) override
 
virtual UINT Win32DispatchMessage (UINT Msg, WPARAM wParam, LPARAM lParam) override
 
- Public Member Functions inherited from flutter::KeyboardManagerWin32::WindowDelegate
virtual ~WindowDelegate ()=default
 
virtual void OnText (const std::u16string &text)=0
 
virtual void OnKey (int key, int scancode, int action, char32_t character, bool extended, bool was_down, KeyEventCallback callback)=0
 

Protected Member Functions

std::wstring NarrowToWide (const char *source)
 
WNDCLASS RegisterWindowClass (std::wstring &title)
 
LRESULT HandleMessage (UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept
 
LRESULT HandleDpiChange (HWND hWnd, WPARAM wParam, LPARAM lParam, bool top_level)
 
virtual void OnDpiScale (UINT dpi)=0
 
virtual void OnResize (UINT width, UINT height)=0
 
virtual void OnPointerMove (double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id)=0
 
virtual void OnPointerDown (double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, UINT button)=0
 
virtual void OnPointerUp (double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, UINT button)=0
 
virtual void OnPointerLeave (double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id)=0
 
virtual void OnSetCursor ()=0
 
LRESULT OnGetObject (UINT const message, WPARAM const wparam, LPARAM const lparam)
 
virtual void OnComposeBegin ()=0
 
virtual void OnComposeCommit ()=0
 
virtual void OnComposeEnd ()=0
 
virtual void OnComposeChange (const std::u16string &text, int cursor_pos)=0
 
virtual void OnImeSetContext (UINT const message, WPARAM const wparam, LPARAM const lparam)
 
virtual void OnImeStartComposition (UINT const message, WPARAM const wparam, LPARAM const lparam)
 
virtual void OnImeComposition (UINT const message, WPARAM const wparam, LPARAM const lparam)
 
virtual void OnImeEndComposition (UINT const message, WPARAM const wparam, LPARAM const lparam)
 
virtual void OnImeRequest (UINT const message, WPARAM const wparam, LPARAM const lparam)
 
virtual void AbortImeComposing ()
 
virtual void UpdateCursorRect (const Rect &rect)
 
virtual void OnUpdateSemanticsEnabled (bool enabled)=0
 
virtual void OnScroll (double delta_x, double delta_y, FlutterPointerDeviceKind device_kind, int32_t device_id)=0
 
UINT GetCurrentDPI ()
 
UINT GetCurrentWidth ()
 
UINT GetCurrentHeight ()
 
virtual LRESULT Win32DefWindowProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 
virtual gfx::NativeViewAccessible GetNativeViewAccessible ()=0
 

Static Protected Member Functions

static LRESULT CALLBACK WndProc (HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept
 

Protected Attributes

std::unique_ptr< DirectManipulationOwnerdirect_manipulation_owner_
 

Additional Inherited Members

- Public Types inherited from flutter::KeyboardManagerWin32::WindowDelegate
using KeyEventCallback = std::function< void(bool)>
 

Detailed Description

Definition at line 28 of file window_win32.h.

Constructor & Destructor Documentation

◆ WindowWin32() [1/2]

flutter::WindowWin32::WindowWin32 ( )

Definition at line 54 of file window_win32.cc.

54 : WindowWin32(nullptr) {}

◆ WindowWin32() [2/2]

flutter::WindowWin32::WindowWin32 ( std::unique_ptr< TextInputManagerWin32 text_input_manager)

Definition at line 56 of file window_win32.cc.

References flutter::GetDpiForHWND().

58  : touch_id_generator_(kMinTouchDeviceId, kMaxTouchDeviceId),
59  text_input_manager_(std::move(text_input_manager)) {
60  // Get the DPI of the primary monitor as the initial DPI. If Per-Monitor V2 is
61  // supported, |current_dpi_| should be updated in the
62  // kWmDpiChangedBeforeParent message.
63  current_dpi_ = GetDpiForHWND(nullptr);
64  if (text_input_manager_ == nullptr) {
65  text_input_manager_ = std::make_unique<TextInputManagerWin32>();
66  }
67  keyboard_manager_ = std::make_unique<KeyboardManagerWin32>(this);
68 }
UINT GetDpiForHWND(HWND hwnd)

◆ ~WindowWin32()

flutter::WindowWin32::~WindowWin32 ( )
virtual

Definition at line 70 of file window_win32.cc.

70  {
71  Destroy();
72 }

Member Function Documentation

◆ AbortImeComposing()

void flutter::WindowWin32::AbortImeComposing ( )
protectedvirtual

Definition at line 275 of file window_win32.cc.

Referenced by flutter::FlutterWindowWin32::OnResetImeComposing().

275  {
276  text_input_manager_->AbortComposing();
277 }

◆ GetCurrentDPI()

UINT flutter::WindowWin32::GetCurrentDPI ( )
protected

Definition at line 543 of file window_win32.cc.

Referenced by flutter::testing::MockWin32Window::GetDpi(), and flutter::FlutterWindowWin32::GetDpiScale().

543  {
544  return current_dpi_;
545 }

◆ GetCurrentHeight()

UINT flutter::WindowWin32::GetCurrentHeight ( )
protected

Definition at line 551 of file window_win32.cc.

Referenced by flutter::FlutterWindowWin32::GetPhysicalWindowBounds().

551  {
552  return current_height_;
553 }

◆ GetCurrentWidth()

UINT flutter::WindowWin32::GetCurrentWidth ( )
protected

Definition at line 547 of file window_win32.cc.

Referenced by flutter::FlutterWindowWin32::GetPhysicalWindowBounds().

547  {
548  return current_width_;
549 }

◆ GetNativeViewAccessible()

virtual gfx::NativeViewAccessible flutter::WindowWin32::GetNativeViewAccessible ( )
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by OnGetObject().

◆ GetWindowHandle()

◆ HandleDpiChange()

LRESULT flutter::WindowWin32::HandleDpiChange ( HWND  hWnd,
WPARAM  wParam,
LPARAM  lParam,
bool  top_level 
)
protected

◆ HandleMessage()

LRESULT flutter::WindowWin32::HandleMessage ( UINT const  message,
WPARAM const  wparam,
LPARAM const  lparam 
)
protectednoexcept

Definition at line 308 of file window_win32.cc.

References direct_manipulation_owner_, flutter::GetDpiForHWND(), flutter::SequentialIdGenerator::GetGeneratedId(), height, kFlutterPointerDeviceKindMouse, kFlutterPointerDeviceKindTouch, message, OnDpiScale(), OnGetObject(), OnImeComposition(), OnImeEndComposition(), OnImeRequest(), OnImeSetContext(), OnImeStartComposition(), OnPointerDown(), OnPointerLeave(), OnPointerMove(), OnPointerUp(), OnScroll(), OnSetCursor(), flutter::SequentialIdGenerator::ReleaseNumber(), TRUE, width, and Win32DefWindowProc().

Referenced by flutter::testing::MockWin32Window::InjectWindowMessage().

310  {
311  LPARAM result_lparam = lparam;
312  int xPos = 0, yPos = 0;
313  UINT width = 0, height = 0;
314  UINT button_pressed = 0;
315  FlutterPointerDeviceKind device_kind;
316 
317  switch (message) {
318  case kWmDpiChangedBeforeParent:
319  current_dpi_ = GetDpiForHWND(window_handle_);
320  OnDpiScale(current_dpi_);
321  return 0;
322  case WM_SIZE:
323  width = LOWORD(lparam);
324  height = HIWORD(lparam);
325 
326  current_width_ = width;
327  current_height_ = height;
328  HandleResize(width, height);
329  break;
330  case WM_TOUCH: {
331  UINT num_points = LOWORD(wparam);
332  touch_points_.resize(num_points);
333  auto touch_input_handle = reinterpret_cast<HTOUCHINPUT>(lparam);
334  if (GetTouchInputInfo(touch_input_handle, num_points,
335  touch_points_.data(), sizeof(TOUCHINPUT))) {
336  for (const auto& touch : touch_points_) {
337  // Generate a mapped ID for the Windows-provided touch ID
338  auto touch_id = touch_id_generator_.GetGeneratedId(touch.dwID);
339 
340  POINT pt = {TOUCH_COORD_TO_PIXEL(touch.x),
341  TOUCH_COORD_TO_PIXEL(touch.y)};
342  ScreenToClient(window_handle_, &pt);
343  auto x = static_cast<double>(pt.x);
344  auto y = static_cast<double>(pt.y);
345 
346  if (touch.dwFlags & TOUCHEVENTF_DOWN) {
348  WM_LBUTTONDOWN);
349  } else if (touch.dwFlags & TOUCHEVENTF_MOVE) {
351  } else if (touch.dwFlags & TOUCHEVENTF_UP) {
353  WM_LBUTTONDOWN);
355  touch_id_generator_.ReleaseNumber(touch.dwID);
356  }
357  }
358  CloseTouchInputHandle(touch_input_handle);
359  }
360  return 0;
361  }
362  case WM_MOUSEMOVE:
363  device_kind = GetFlutterPointerDeviceKind();
364  if (device_kind == kFlutterPointerDeviceKindMouse) {
365  TrackMouseLeaveEvent(window_handle_);
366 
367  xPos = GET_X_LPARAM(lparam);
368  yPos = GET_Y_LPARAM(lparam);
369  mouse_x_ = static_cast<double>(xPos);
370  mouse_y_ = static_cast<double>(yPos);
371 
372  OnPointerMove(mouse_x_, mouse_y_, device_kind, kDefaultPointerDeviceId);
373  }
374  break;
375  case WM_MOUSELEAVE:
376  device_kind = GetFlutterPointerDeviceKind();
377  if (device_kind == kFlutterPointerDeviceKindMouse) {
378  OnPointerLeave(mouse_x_, mouse_y_, device_kind,
379  kDefaultPointerDeviceId);
380  }
381 
382  // Once the tracked event is received, the TrackMouseEvent function
383  // resets. Set to false to make sure it's called once mouse movement is
384  // detected again.
385  tracking_mouse_leave_ = false;
386  break;
387  case WM_SETCURSOR: {
388  UINT hit_test_result = LOWORD(lparam);
389  if (hit_test_result == HTCLIENT) {
390  OnSetCursor();
391  return TRUE;
392  }
393  break;
394  }
395  case WM_SETFOCUS:
396  ::CreateCaret(window_handle_, nullptr, 1, 1);
397  break;
398  case WM_KILLFOCUS:
399  ::DestroyCaret();
400  break;
401  case WM_LBUTTONDOWN:
402  case WM_RBUTTONDOWN:
403  case WM_MBUTTONDOWN:
404  case WM_XBUTTONDOWN:
405  device_kind = GetFlutterPointerDeviceKind();
406  if (device_kind != kFlutterPointerDeviceKindMouse) {
407  break;
408  }
409 
410  if (message == WM_LBUTTONDOWN) {
411  // Capture the pointer in case the user drags outside the client area.
412  // In this case, the "mouse leave" event is delayed until the user
413  // releases the button. It's only activated on left click given that
414  // it's more common for apps to handle dragging with only the left
415  // button.
416  SetCapture(window_handle_);
417  }
418  button_pressed = message;
419  if (message == WM_XBUTTONDOWN) {
420  button_pressed = GET_XBUTTON_WPARAM(wparam);
421  }
422  xPos = GET_X_LPARAM(lparam);
423  yPos = GET_Y_LPARAM(lparam);
424  OnPointerDown(static_cast<double>(xPos), static_cast<double>(yPos),
425  device_kind, kDefaultPointerDeviceId, button_pressed);
426  break;
427  case WM_LBUTTONUP:
428  case WM_RBUTTONUP:
429  case WM_MBUTTONUP:
430  case WM_XBUTTONUP:
431  device_kind = GetFlutterPointerDeviceKind();
432  if (device_kind != kFlutterPointerDeviceKindMouse) {
433  break;
434  }
435 
436  if (message == WM_LBUTTONUP) {
437  ReleaseCapture();
438  }
439  button_pressed = message;
440  if (message == WM_XBUTTONUP) {
441  button_pressed = GET_XBUTTON_WPARAM(wparam);
442  }
443  xPos = GET_X_LPARAM(lparam);
444  yPos = GET_Y_LPARAM(lparam);
445  OnPointerUp(static_cast<double>(xPos), static_cast<double>(yPos),
446  device_kind, kDefaultPointerDeviceId, button_pressed);
447  break;
448  case WM_MOUSEWHEEL:
449  OnScroll(0.0,
450  -(static_cast<short>(HIWORD(wparam)) /
451  static_cast<double>(WHEEL_DELTA)),
452  kFlutterPointerDeviceKindMouse, kDefaultPointerDeviceId);
453  break;
454  case WM_MOUSEHWHEEL:
455  OnScroll((static_cast<short>(HIWORD(wparam)) /
456  static_cast<double>(WHEEL_DELTA)),
457  0.0, kFlutterPointerDeviceKindMouse, kDefaultPointerDeviceId);
458  break;
459  case WM_GETOBJECT: {
460  LRESULT lresult = OnGetObject(message, wparam, lparam);
461  if (lresult) {
462  return lresult;
463  }
464  break;
465  }
466  case WM_TIMER:
467  if (wparam == kDirectManipulationTimer) {
468  direct_manipulation_owner_->Update();
469  SetTimer(window_handle_, kDirectManipulationTimer,
470  1000 / directManipulationPollingRate_, nullptr);
471  return 0;
472  }
473  break;
474  case DM_POINTERHITTEST: {
476  UINT contactId = GET_POINTERID_WPARAM(wparam);
477  POINTER_INPUT_TYPE pointerType;
478  if (GetPointerType(contactId, &pointerType) &&
479  pointerType == PT_TOUCHPAD) {
480  direct_manipulation_owner_->SetContact(contactId);
481  }
482  }
483  break;
484  }
485  case WM_INPUTLANGCHANGE:
486  // TODO(cbracken): pass this to TextInputManager to aid with
487  // language-specific issues.
488  break;
489  case WM_IME_SETCONTEXT:
490  OnImeSetContext(message, wparam, lparam);
491  // Strip the ISC_SHOWUICOMPOSITIONWINDOW bit from lparam before passing it
492  // to DefWindowProc() so that the composition window is hidden since
493  // Flutter renders the composing string itself.
494  result_lparam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
495  break;
496  case WM_IME_STARTCOMPOSITION:
497  OnImeStartComposition(message, wparam, lparam);
498  // Suppress further processing by DefWindowProc() so that the default
499  // system IME style isn't used, but rather the one set in the
500  // WM_IME_SETCONTEXT handler.
501  return TRUE;
502  case WM_IME_COMPOSITION:
503  OnImeComposition(message, wparam, lparam);
504  if (lparam & GCS_RESULTSTR || lparam & GCS_COMPSTR) {
505  // Suppress further processing by DefWindowProc() since otherwise it
506  // will emit the result string as WM_CHAR messages on commit. Instead,
507  // committing the composing text to the EditableText string is handled
508  // in TextInputModel::CommitComposing, triggered by
509  // OnImeEndComposition().
510  return TRUE;
511  }
512  break;
513  case WM_IME_ENDCOMPOSITION:
514  OnImeEndComposition(message, wparam, lparam);
515  return TRUE;
516  case WM_IME_REQUEST:
517  OnImeRequest(message, wparam, lparam);
518  break;
519  case WM_UNICHAR: {
520  // Tell third-pary app, we can support Unicode.
521  if (wparam == UNICODE_NOCHAR)
522  return TRUE;
523  // DefWindowProc will send WM_CHAR for this WM_UNICHAR.
524  break;
525  }
526  case WM_DEADCHAR:
527  case WM_SYSDEADCHAR:
528  case WM_CHAR:
529  case WM_SYSCHAR:
530  case WM_KEYDOWN:
531  case WM_SYSKEYDOWN:
532  case WM_KEYUP:
533  case WM_SYSKEYUP:
534  if (keyboard_manager_->HandleMessage(message, wparam, lparam)) {
535  return 0;
536  }
537  break;
538  }
539 
540  return Win32DefWindowProc(window_handle_, message, wparam, result_lparam);
541 }
virtual void OnScroll(double delta_x, double delta_y, FlutterPointerDeviceKind device_kind, int32_t device_id)=0
virtual void OnImeStartComposition(UINT const message, WPARAM const wparam, LPARAM const lparam)
UINT GetDpiForHWND(HWND hwnd)
LRESULT OnGetObject(UINT const message, WPARAM const wparam, LPARAM const lparam)
virtual void OnDpiScale(UINT dpi)=0
virtual LRESULT Win32DefWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
virtual void OnPointerUp(double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, UINT button)=0
Win32Message message
FlutterPointerDeviceKind
The device type that created a pointer event.
Definition: embedder.h:753
LONG_PTR LRESULT
Definition: windows_types.h:61
std::unique_ptr< DirectManipulationOwner > direct_manipulation_owner_
Definition: window_win32.h:217
virtual void OnImeComposition(UINT const message, WPARAM const wparam, LPARAM const lparam)
virtual void OnPointerLeave(double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id)=0
virtual void OnPointerDown(double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id, UINT button)=0
virtual void OnPointerMove(double x, double y, FlutterPointerDeviceKind device_kind, int32_t device_id)=0
virtual void OnImeEndComposition(UINT const message, WPARAM const wparam, LPARAM const lparam)
virtual void OnSetCursor()=0
virtual void OnImeRequest(UINT const message, WPARAM const wparam, LPARAM const lparam)
int32_t width
int32_t height
LONG_PTR LPARAM
Definition: windows_types.h:60
uint32_t GetGeneratedId(uint32_t number)
unsigned int UINT
Definition: windows_types.h:32
virtual void OnImeSetContext(UINT const message, WPARAM const wparam, LPARAM const lparam)

◆ InitializeChild()

void flutter::WindowWin32::InitializeChild ( const char *  title,
unsigned int  width,
unsigned int  height 
)

Definition at line 74 of file window_win32.cc.

References direct_manipulation_owner_, error, FALSE, GetLastError(), height, message, NarrowToWide(), RegisterWindowClass(), result, flutter::size, and width.

Referenced by flutter::FlutterWindowWin32::FlutterWindowWin32().

76  {
77  Destroy();
78  std::wstring converted_title = NarrowToWide(title);
79 
80  WNDCLASS window_class = RegisterWindowClass(converted_title);
81 
82  auto* result = CreateWindowEx(
83  0, window_class.lpszClassName, converted_title.c_str(),
84  WS_CHILD | WS_VISIBLE, CW_DEFAULT, CW_DEFAULT, width, height,
85  HWND_MESSAGE, nullptr, window_class.hInstance, this);
86 
87  if (result == nullptr) {
88  auto error = GetLastError();
89  LPWSTR message = nullptr;
90  size_t size = FormatMessageW(
91  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
92  FORMAT_MESSAGE_IGNORE_INSERTS,
93  NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
94  reinterpret_cast<LPWSTR>(&message), 0, NULL);
95  OutputDebugString(message);
96  LocalFree(message);
97  }
98  DEVMODE dmi;
99  ZeroMemory(&dmi, sizeof(dmi));
100  dmi.dmSize = sizeof(dmi);
101  if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmi)) {
102  directManipulationPollingRate_ = dmi.dmDisplayFrequency;
103  } else {
104  OutputDebugString(
105  L"Failed to get framerate, will use default of 60 Hz for gesture "
106  L"polling.");
107  }
108  SetUserObjectInformationA(GetCurrentProcess(),
109  UOI_TIMERPROC_EXCEPTION_SUPPRESSION, FALSE, 1);
110  SetTimer(result, kDirectManipulationTimer,
111  1000 / directManipulationPollingRate_, nullptr);
112  direct_manipulation_owner_ = std::make_unique<DirectManipulationOwner>(this);
113  direct_manipulation_owner_->Init(width, height);
114 }
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
Win32Message message
WNDCLASS RegisterWindowClass(std::wstring &title)
std::unique_ptr< DirectManipulationOwner > direct_manipulation_owner_
Definition: window_win32.h:217
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data observatory The hostname IP address on which the Dart Observatory should be served If not defaults to or::depending on whether ipv6 is specified disable Disable the Dart Observatory The observatory is never available in release mode Bind to the IPv6 localhost address for the Dart Observatory Ignored if observatory host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent Remove all existing persistent cache This is mainly for debugging purposes such as reproducing the shader compilation jank use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:226
int32_t width
int32_t height
std::wstring NarrowToWide(const char *source)
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)
return FALSE

◆ NarrowToWide()

std::wstring flutter::WindowWin32::NarrowToWide ( const char *  source)
protected

Definition at line 116 of file window_win32.cc.

References length.

Referenced by InitializeChild().

116  {
117  size_t length = strlen(source);
118  size_t outlen = 0;
119  std::wstring wideTitle(length, L'#');
120  mbstowcs_s(&outlen, &wideTitle[0], length + 1, source, length);
121  return wideTitle;
122 }
size_t length

◆ OnComposeBegin()

virtual void flutter::WindowWin32::OnComposeBegin ( )
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by OnImeStartComposition().

◆ OnComposeChange()

virtual void flutter::WindowWin32::OnComposeChange ( const std::u16string &  text,
int  cursor_pos 
)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by OnImeComposition().

◆ OnComposeCommit()

virtual void flutter::WindowWin32::OnComposeCommit ( )
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by OnImeComposition().

◆ OnComposeEnd()

virtual void flutter::WindowWin32::OnComposeEnd ( )
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by OnImeEndComposition().

◆ OnDpiScale()

virtual void flutter::WindowWin32::OnDpiScale ( UINT  dpi)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by HandleMessage().

◆ OnGetObject()

LRESULT flutter::WindowWin32::OnGetObject ( UINT const  message,
WPARAM const  wparam,
LPARAM const  lparam 
)
protected

Definition at line 173 of file window_win32.cc.

References GetNativeViewAccessible(), and OnUpdateSemanticsEnabled().

Referenced by HandleMessage().

175  {
176  LRESULT reference_result = static_cast<LRESULT>(0L);
177 
178  // Only the lower 32 bits of lparam are valid when checking the object id
179  // because it sometimes gets sign-extended incorrectly (but not always).
180  DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(lparam));
181 
182  bool is_uia_request = static_cast<DWORD>(UiaRootObjectId) == obj_id;
183  bool is_msaa_request = static_cast<DWORD>(OBJID_CLIENT) == obj_id;
184 
185  if (is_uia_request || is_msaa_request) {
186  // On Windows, we don't get a notification that the screen reader has been
187  // enabled or disabled. There is an API to query for screen reader state,
188  // but that state isn't set by all screen readers, including by Narrator,
189  // the screen reader that ships with Windows:
190  // https://docs.microsoft.com/en-us/windows/win32/winauto/screen-reader-parameter
191  //
192  // Instead, we enable semantics in Flutter if Windows issues queries for
193  // Microsoft Active Accessibility (MSAA) COM objects.
195  }
196 
198  if (is_uia_request && root_view) {
199  // TODO(cbracken): https://github.com/flutter/flutter/issues/94782
200  // Implement when we adopt UIA support.
201  } else if (is_msaa_request && root_view) {
202  // Return the IAccessible for the root view.
203  Microsoft::WRL::ComPtr<IAccessible> root(root_view);
204  LRESULT lresult = LresultFromObject(IID_IAccessible, wparam, root.Get());
205  return lresult;
206  }
207  return 0;
208 }
LONG_PTR LRESULT
Definition: windows_types.h:61
UnimplementedNativeViewAccessible * NativeViewAccessible
unsigned long DWORD
Definition: windows_types.h:22
virtual gfx::NativeViewAccessible GetNativeViewAccessible()=0
virtual void OnUpdateSemanticsEnabled(bool enabled)=0

◆ OnImeComposition()

void flutter::WindowWin32::OnImeComposition ( UINT const  message,
WPARAM const  wparam,
LPARAM const  lparam 
)
protectedvirtual

Definition at line 225 of file window_win32.cc.

References OnComposeChange(), OnComposeCommit(), and text.

Referenced by flutter::testing::MockWin32Window::CallOnImeComposition(), and HandleMessage().

227  {
228  // Update the IME window position.
229  text_input_manager_->UpdateImeWindow();
230 
231  if (lparam == 0) {
232  OnComposeChange(u"", 0);
233  OnComposeCommit();
234  }
235 
236  // Process GCS_RESULTSTR at fisrt, because Google Japanese Input and ATOK send
237  // both GCS_RESULTSTR and GCS_COMPSTR to commit composed text and send new
238  // composing text.
239  if (lparam & GCS_RESULTSTR) {
240  // Commit but don't end composing.
241  // Read the committed composing string.
242  long pos = text_input_manager_->GetComposingCursorPosition();
243  std::optional<std::u16string> text = text_input_manager_->GetResultString();
244  if (text) {
245  OnComposeChange(text.value(), pos);
246  OnComposeCommit();
247  }
248  }
249  if (lparam & GCS_COMPSTR) {
250  // Read the in-progress composing string.
251  long pos = text_input_manager_->GetComposingCursorPosition();
252  std::optional<std::u16string> text =
253  text_input_manager_->GetComposingString();
254  if (text) {
255  OnComposeChange(text.value(), pos);
256  }
257  }
258 }
virtual void OnComposeChange(const std::u16string &text, int cursor_pos)=0
std::u16string text
virtual void OnComposeCommit()=0

◆ OnImeEndComposition()

void flutter::WindowWin32::OnImeEndComposition ( UINT const  message,
WPARAM const  wparam,
LPARAM const  lparam 
)
protectedvirtual

Definition at line 260 of file window_win32.cc.

References OnComposeEnd().

Referenced by HandleMessage().

262  {
263  text_input_manager_->DestroyImeWindow();
264  OnComposeEnd();
265 }
virtual void OnComposeEnd()=0

◆ OnImeRequest()

void flutter::WindowWin32::OnImeRequest ( UINT const  message,
WPARAM const  wparam,
LPARAM const  lparam 
)
protectedvirtual

Definition at line 267 of file window_win32.cc.

Referenced by HandleMessage().

269  {
270  // TODO(cbracken): Handle IMR_RECONVERTSTRING, IMR_DOCUMENTFEED,
271  // and IMR_QUERYCHARPOSITION messages.
272  // https://github.com/flutter/flutter/issues/74547
273 }

◆ OnImeSetContext()

void flutter::WindowWin32::OnImeSetContext ( UINT const  message,
WPARAM const  wparam,
LPARAM const  lparam 
)
protectedvirtual

Definition at line 210 of file window_win32.cc.

Referenced by HandleMessage().

212  {
213  if (wparam != 0) {
214  text_input_manager_->CreateImeWindow();
215  }
216 }

◆ OnImeStartComposition()

void flutter::WindowWin32::OnImeStartComposition ( UINT const  message,
WPARAM const  wparam,
LPARAM const  lparam 
)
protectedvirtual

Definition at line 218 of file window_win32.cc.

References OnComposeBegin().

Referenced by HandleMessage().

220  {
221  text_input_manager_->CreateImeWindow();
222  OnComposeBegin();
223 }
virtual void OnComposeBegin()=0

◆ OnPointerDown()

virtual void flutter::WindowWin32::OnPointerDown ( double  x,
double  y,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id,
UINT  button 
)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by HandleMessage().

◆ OnPointerLeave()

virtual void flutter::WindowWin32::OnPointerLeave ( double  x,
double  y,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id 
)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by HandleMessage().

◆ OnPointerMove()

virtual void flutter::WindowWin32::OnPointerMove ( double  x,
double  y,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id 
)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by HandleMessage().

◆ OnPointerUp()

virtual void flutter::WindowWin32::OnPointerUp ( double  x,
double  y,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id,
UINT  button 
)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by HandleMessage().

◆ OnResize()

virtual void flutter::WindowWin32::OnResize ( UINT  width,
UINT  height 
)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by GetWindowHandle().

◆ OnScroll()

virtual void flutter::WindowWin32::OnScroll ( double  delta_x,
double  delta_y,
FlutterPointerDeviceKind  device_kind,
int32_t  device_id 
)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by HandleMessage().

◆ OnSetCursor()

virtual void flutter::WindowWin32::OnSetCursor ( )
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by HandleMessage().

◆ OnUpdateSemanticsEnabled()

virtual void flutter::WindowWin32::OnUpdateSemanticsEnabled ( bool  enabled)
protectedpure virtual

Implemented in flutter::FlutterWindowWin32.

Referenced by OnGetObject().

◆ RegisterWindowClass()

WNDCLASS flutter::WindowWin32::RegisterWindowClass ( std::wstring &  title)
protected

Definition at line 124 of file window_win32.cc.

References WndProc().

Referenced by InitializeChild().

124  {
125  window_class_name_ = title;
126 
127  WNDCLASS window_class{};
128  window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
129  window_class.lpszClassName = title.c_str();
130  window_class.style = CS_HREDRAW | CS_VREDRAW;
131  window_class.cbClsExtra = 0;
132  window_class.cbWndExtra = 0;
133  window_class.hInstance = GetModuleHandle(nullptr);
134  window_class.hIcon = nullptr;
135  window_class.hbrBackground = 0;
136  window_class.lpszMenuName = nullptr;
137  window_class.lpfnWndProc = WndProc;
138  RegisterClass(&window_class);
139  return window_class;
140 }
static LRESULT CALLBACK WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept

◆ UpdateCursorRect()

void flutter::WindowWin32::UpdateCursorRect ( const Rect rect)
protectedvirtual

Definition at line 279 of file window_win32.cc.

Referenced by flutter::FlutterWindowWin32::OnCursorRectUpdated().

279  {
280  text_input_manager_->UpdateCaretRect(rect);
281 }

◆ Win32DefWindowProc()

LRESULT flutter::WindowWin32::Win32DefWindowProc ( HWND  hWnd,
UINT  Msg,
WPARAM  wParam,
LPARAM  lParam 
)
protectedvirtual

Reimplemented in flutter::testing::MockWin32Window.

Definition at line 583 of file window_win32.cc.

Referenced by HandleMessage().

586  {
587  return ::DefWindowProc(hWnd, Msg, wParam, lParam);
588 }

◆ Win32DispatchMessage()

UINT flutter::WindowWin32::Win32DispatchMessage ( UINT  Msg,
WPARAM  wParam,
LPARAM  lParam 
)
overridevirtual

Implements flutter::KeyboardManagerWin32::WindowDelegate.

Definition at line 602 of file window_win32.cc.

References SendMessage.

602  {
603  return ::SendMessage(window_handle_, Msg, wParam, lParam);
604 }
#define SendMessage

◆ Win32MapVkToChar()

uint32_t flutter::WindowWin32::Win32MapVkToChar ( uint32_t  virtual_key)
overridevirtual

Implements flutter::KeyboardManagerWin32::WindowDelegate.

Definition at line 598 of file window_win32.cc.

598  {
599  return ::MapVirtualKey(virtual_key, MAPVK_VK_TO_CHAR);
600 }

◆ Win32PeekMessage()

BOOL flutter::WindowWin32::Win32PeekMessage ( LPMSG  lpMsg,
UINT  wMsgFilterMin,
UINT  wMsgFilterMax,
UINT  wRemoveMsg 
)
overridevirtual

Implements flutter::KeyboardManagerWin32::WindowDelegate.

Definition at line 590 of file window_win32.cc.

593  {
594  return ::PeekMessage(lpMsg, window_handle_, wMsgFilterMin, wMsgFilterMax,
595  wRemoveMsg);
596 }

◆ WndProc()

LRESULT CALLBACK flutter::WindowWin32::WndProc ( HWND const  window,
UINT const  message,
WPARAM const  wparam,
LPARAM const  lparam 
)
staticprotectednoexcept

Definition at line 142 of file window_win32.cc.

References message, and window.

Referenced by RegisterWindowClass().

145  {
146  if (message == WM_NCCREATE) {
147  auto cs = reinterpret_cast<CREATESTRUCT*>(lparam);
148  SetWindowLongPtr(window, GWLP_USERDATA,
149  reinterpret_cast<LONG_PTR>(cs->lpCreateParams));
150 
151  auto that = static_cast<WindowWin32*>(cs->lpCreateParams);
152  that->window_handle_ = window;
153  that->text_input_manager_->SetWindowHandle(window);
154  RegisterTouchWindow(window, 0);
155  } else if (WindowWin32* that = GetThisFromHandle(window)) {
156  return that->HandleMessage(message, wparam, lparam);
157  }
158 
159  return DefWindowProc(window, message, wparam, lparam);
160 }
Win32Message message
GLFWwindow * window
Definition: main.cc:43

Member Data Documentation

◆ direct_manipulation_owner_

std::unique_ptr<DirectManipulationOwner> flutter::WindowWin32::direct_manipulation_owner_
protected

The documentation for this class was generated from the following files: