Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
52 changes: 26 additions & 26 deletions shell/platform/windows/flutter_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ namespace {
// constant for machines running at 100% scaling.
constexpr int base_dpi = 96;

static const int kMinTouchDeviceId = 0;
static const int kMaxTouchDeviceId = 128;

static const int kLinesPerScrollWindowsDefault = 3;

// Maps a Flutter cursor name to an HCURSOR.
//
// Returns the arrow cursor for unknown constants.
Expand Down Expand Up @@ -88,12 +93,28 @@ static FlutterPointerDeviceKind GetFlutterPointerDeviceKind() {
return kFlutterPointerDeviceKindMouse;
}

} // namespace

static const int kMinTouchDeviceId = 0;
static const int kMaxTouchDeviceId = 128;
// Translates button codes from Win32 API to FlutterPointerMouseButtons.
static uint64_t ConvertWinButtonToFlutterButton(UINT button) {
switch (button) {
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
return kFlutterPointerButtonMousePrimary;
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
return kFlutterPointerButtonMouseSecondary;
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
return kFlutterPointerButtonMouseMiddle;
case XBUTTON1:
return kFlutterPointerButtonMouseBack;
case XBUTTON2:
return kFlutterPointerButtonMouseForward;
}
FML_LOG(WARNING) << "Mouse button not recognized: " << button;
return 0;
}

static const int kLinesPerScrollWindowsDefault = 3;
} // namespace

FlutterWindow::FlutterWindow(
int width,
Expand Down Expand Up @@ -178,27 +199,6 @@ void FlutterWindow::OnWindowResized() {
DwmFlush();
}

// Translates button codes from Win32 API to FlutterPointerMouseButtons.
static uint64_t ConvertWinButtonToFlutterButton(UINT button) {
switch (button) {
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
return kFlutterPointerButtonMousePrimary;
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
return kFlutterPointerButtonMouseSecondary;
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
return kFlutterPointerButtonMouseMiddle;
case XBUTTON1:
return kFlutterPointerButtonMouseBack;
case XBUTTON2:
return kFlutterPointerButtonMouseForward;
}
FML_LOG(WARNING) << "Mouse button not recognized: " << button;
return 0;
}

void FlutterWindow::OnDpiScale(unsigned int dpi){};

// When DesktopWindow notifies that a WM_Size message has come in
Expand Down
63 changes: 32 additions & 31 deletions shell/platform/windows/flutter_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
virtual void OnWindowStateEvent(WindowStateEvent event);

protected:
// OS callback called by message pump. Handles the WM_NCCREATE message which
// is passed when the non-client area is being created and enables automatic
// non-client DPI scaling so that the non-client area automatically
// responsponds to changes in DPI. All other messages are handled by
// MessageHandler.
static LRESULT CALLBACK WndProc(HWND const window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept;

// Win32's DefWindowProc.
//
// Used as the fallback behavior of HandleMessage. Exposed for dependency
Expand All @@ -226,16 +236,6 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
// icon.
WNDCLASS RegisterWindowClass(std::wstring& title);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do a pass on protected members to check if they can be made private instead? It looks like RegisterWindowClass should be private, there may be more.


// OS callback called by message pump. Handles the WM_NCCREATE message which
// is passed when the non-client area is being created and enables automatic
// non-client DPI scaling so that the non-client area automatically
// responsponds to changes in DPI. All other messages are handled by
// MessageHandler.
static LRESULT CALLBACK WndProc(HWND const window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept;

// Processes and route salient window messages for mouse handling,
// size change and DPI. Delegates handling of these to member overloads that
// inheriting classes can handle.
Expand Down Expand Up @@ -316,6 +316,25 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
std::unique_ptr<DirectManipulationOwner> direct_manipulation_owner_;

private:
// WM_DPICHANGED_BEFOREPARENT defined in more recent Windows
// SDK
const static long kWmDpiChangedBeforeParent = 0x02E2;

// Timer identifier for DirectManipulation gesture polling.
const static int kDirectManipulationTimer = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and above, while you're in here, let's also switch these to static const for consistency with elsewhere.


// Retrieves a class instance pointer for |window|
static FlutterWindow* GetThisFromHandle(HWND const window) noexcept;

// Activates tracking for a "mouse leave" event.
void TrackMouseLeaveEvent(HWND hwnd);

// Stores new width and height and calls |OnResize| to notify inheritors
void HandleResize(UINT width, UINT height);

// Updates the cached scroll_offset_multiplier_ value based off OS settings.
void UpdateScrollOffsetMultiplier();

// A pointer to a FlutterWindowsView that can be used to update engine
// windowing and input state.
WindowBindingHandlerDelegate* binding_handler_delegate_;
Expand All @@ -331,17 +350,6 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
// proper application lifecycle state can be updated once the view is set.
bool restored_ = false;
bool focused_ = false;
// Activates tracking for a "mouse leave" event.
void TrackMouseLeaveEvent(HWND hwnd);

// Stores new width and height and calls |OnResize| to notify inheritors
void HandleResize(UINT width, UINT height);

// Retrieves a class instance pointer for |window|
static FlutterWindow* GetThisFromHandle(HWND const window) noexcept;

// Updates the cached scroll_offset_multiplier_ value based off OS settings.
void UpdateScrollOffsetMultiplier();

int current_dpi_ = 0;
int current_width_ = 0;
Expand All @@ -350,10 +358,6 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
// Holds the conversion factor from lines scrolled to pixels scrolled.
float scroll_offset_multiplier_;

// WM_DPICHANGED_BEFOREPARENT defined in more recent Windows
// SDK
const static long kWmDpiChangedBeforeParent = 0x02E2;

// Member variable to hold window handle.
HWND window_handle_ = nullptr;

Expand All @@ -371,6 +375,9 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
double mouse_x_ = 0;
double mouse_y_ = 0;

// Generates touch point IDs for touch events.
SequentialIdGenerator touch_id_generator_;

// Abstracts Windows APIs that may not be available on all supported versions
// of Windows.
std::unique_ptr<WindowsProcTable> windows_proc_table_;
Expand All @@ -384,12 +391,6 @@ class FlutterWindow : public KeyboardManager::WindowDelegate,
// Used for temporarily storing the WM_TOUCH-provided touch points.
std::vector<TOUCHINPUT> touch_points_;

// Generates touch point IDs for touch events.
SequentialIdGenerator touch_id_generator_;

// Timer identifier for DirectManipulation gesture polling.
const static int kDirectManipulationTimer = 1;

// Implements IRawElementProviderFragmentRoot when UIA is enabled.
std::unique_ptr<ui::AXFragmentRootWin> ax_fragment_root_;

Expand Down