Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
host_window_tooltip.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6#include <cstdio>
7#include <memory>
10
11namespace flutter {
13 WindowManager* window_manager,
15 const BoxConstraints& constraints,
16 GetWindowPositionCallback get_position_callback,
17 HWND parent)
18 : HostWindowSized(window_manager, engine, /*resizable=*/false),
19 get_position_callback_(get_position_callback),
20 parent_(parent),
21 isolate_(Isolate::Current()) {
22 // Use minimum constraints as initial size to ensure the view can be created
23 // with valid metrics.
24 auto const initial_width =
25 static_cast<double>(constraints.smallest().width());
26 auto const initial_height =
27 static_cast<double>(constraints.smallest().height());
28
31 .window_style = WS_POPUP,
32 .extended_window_style = WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW,
33 .box_constraints = constraints,
34 .initial_window_rect = {{0, 0}, {initial_width, initial_height}},
35 .title = L"",
36 .owner_window = parent,
37 .nCmdShow = SW_SHOWNOACTIVATE,
38 .sizing_delegate = AsSizingDelegate(),
39 .is_sized_to_content = true});
40 SetWindowLongPtr(window_handle_, GWLP_HWNDPARENT,
41 reinterpret_cast<LONG_PTR>(parent_));
42}
43
45 // Reset the view while this most-derived object is still fully alive, to stop
46 // the raster thread from sizing it (via the overridden ApplyContentSize /
47 // GetWorkArea) before any subobject is torn down. See the destructor comment
48 // in host_window_sized.h for the rationale.
49 view_controller_.reset();
50}
51
52void HostWindowTooltip::ApplyContentSize(int32_t physical_width,
53 int32_t physical_height) {
55}
56
57WindowRect HostWindowTooltip::GetWorkArea() const {
58 constexpr int32_t kDefaultWorkAreaSize = 10000;
59 WindowRect work_area = {0, 0, kDefaultWorkAreaSize, kDefaultWorkAreaSize};
60 HMONITOR monitor = MonitorFromWindow(parent_, MONITOR_DEFAULTTONEAREST);
61 if (monitor) {
62 MONITORINFO monitor_info = {0};
63 monitor_info.cbSize = sizeof(monitor_info);
64 if (GetMonitorInfo(monitor, &monitor_info)) {
65 work_area.left = monitor_info.rcWork.left;
66 work_area.top = monitor_info.rcWork.top;
67 work_area.width = monitor_info.rcWork.right - monitor_info.rcWork.left;
68 work_area.height = monitor_info.rcWork.bottom - monitor_info.rcWork.top;
69 }
70 }
71 return work_area;
72}
73
75 RECT parent_client_rect;
76 GetClientRect(parent_, &parent_client_rect);
77
78 // Convert top-left and bottom-right points to screen coordinates.
79 POINT parent_top_left = {parent_client_rect.left, parent_client_rect.top};
80 POINT parent_bottom_right = {parent_client_rect.right,
81 parent_client_rect.bottom};
82
83 ClientToScreen(parent_, &parent_top_left);
84 ClientToScreen(parent_, &parent_bottom_right);
85
86 // Get monitor from HWND and usable work area.
87 HMONITOR monitor = MonitorFromWindow(parent_, MONITOR_DEFAULTTONEAREST);
88 WindowRect work_area = GetWorkArea();
89
90 IsolateScope scope(isolate_);
91 std::unique_ptr<WindowRect, decltype(&free)> rect(
92 get_position_callback_(
94 WindowRect{parent_top_left.x, parent_top_left.y,
95 parent_bottom_right.x - parent_top_left.x,
96 parent_bottom_right.y - parent_top_left.y},
97 work_area),
98 free);
99 if (!rect) {
100 return;
101 }
102 SetWindowPos(window_handle_, nullptr, rect->left, rect->top, rect->width,
103 rect->height, SWP_NOACTIVATE | SWP_NOOWNERZORDER);
104
105 // The positioner constrained the dimensions more than current size, apply
106 // positioner constraints.
107 if (rect->width < physical_width_ || rect->height < physical_height_) {
108 auto metrics_event = view_controller_->view()->CreateWindowMetricsEvent();
109 view_controller_->engine()->SendWindowMetricsEvent(metrics_event);
110 }
111}
112
115 WPARAM wparam,
116 LPARAM lparam) {
117 switch (message) {
118 case WM_MOUSEACTIVATE:
119 // Prevent activation when clicked
120 return MA_NOACTIVATE;
121
122 case WM_NCACTIVATE:
123 // Return TRUE to prevent visual activation changes
124 return TRUE;
125
126 case WM_ACTIVATE:
127 // Immediately deactivate if somehow activated
128 if (LOWORD(wparam) != WA_INACTIVE) {
129 HWND hFocus = GetFocus();
130 SetFocus(nullptr);
131 }
132 break;
133 }
134
135 return HostWindow::HandleMessage(hwnd, message, wparam, lparam);
136}
137
138} // namespace flutter
Size smallest() const
Definition geometry.h:94
void InitializeFlutterView(HostWindowInitializationParams const &params)
std::unique_ptr< FlutterWindowsViewController > view_controller_
virtual LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
FlutterWindowsViewSizingDelegate * AsSizingDelegate()
LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) override
HostWindowTooltip(WindowManager *window_manager, FlutterWindowsEngine *engine, const BoxConstraints &constraints, GetWindowPositionCallback get_position_callback, HWND parent)
void ApplyContentSize(int32_t physical_width, int32_t physical_height) override
double height() const
Definition geometry.h:45
double width() const
Definition geometry.h:44
FlutterEngine engine
Definition main.cc:84
const char * message
WindowRect *(* GetWindowPositionCallback)(const WindowSize &child_size, const WindowRect &parent_rect, const WindowRect &output_rect)
LONG_PTR LRESULT
unsigned int UINT
LONG_PTR LPARAM
__w64 long LONG_PTR
UINT_PTR WPARAM