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>
9
10namespace flutter {
12 WindowManager* window_manager,
14 const BoxConstraints& constraints,
15 GetWindowPositionCallback get_position_callback,
16 HWND parent)
17 : HostWindowSized(window_manager, engine, /*resizable=*/false),
18 get_position_callback_(get_position_callback),
19 parent_(parent),
20 isolate_(Isolate::Current()) {
21 // Use minimum constraints as initial size to ensure the view can be created
22 // with valid metrics.
23 auto const initial_width =
24 static_cast<double>(constraints.smallest().width());
25 auto const initial_height =
26 static_cast<double>(constraints.smallest().height());
27
30 .window_style = WS_POPUP,
31 .extended_window_style = WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW,
32 .box_constraints = constraints,
33 .initial_window_rect = {{0, 0}, {initial_width, initial_height}},
34 .title = L"",
35 .owner_window = parent,
36 .nCmdShow = SW_SHOWNOACTIVATE,
37 .sizing_delegate = AsSizingDelegate(),
38 .is_sized_to_content = true});
39 SetWindowLongPtr(window_handle_, GWLP_HWNDPARENT,
40 reinterpret_cast<LONG_PTR>(parent_));
41}
42
44 // Reset the view while this most-derived object is still fully alive, to stop
45 // the raster thread from sizing it (via the overridden ApplyContentSize /
46 // GetWorkArea) before any subobject is torn down. See the destructor comment
47 // in host_window_sized.h for the rationale.
48 view_controller_.reset();
49}
50
51void HostWindowTooltip::ApplyContentSize(int32_t physical_width,
52 int32_t physical_height) {
54}
55
56WindowRect HostWindowTooltip::GetWorkArea() const {
57 constexpr int32_t kDefaultWorkAreaSize = 10000;
58 WindowRect work_area = {0, 0, kDefaultWorkAreaSize, kDefaultWorkAreaSize};
59 HMONITOR monitor = MonitorFromWindow(parent_, MONITOR_DEFAULTTONEAREST);
60 if (monitor) {
61 MONITORINFO monitor_info = {0};
62 monitor_info.cbSize = sizeof(monitor_info);
63 if (GetMonitorInfo(monitor, &monitor_info)) {
64 work_area.left = monitor_info.rcWork.left;
65 work_area.top = monitor_info.rcWork.top;
66 work_area.width = monitor_info.rcWork.right - monitor_info.rcWork.left;
67 work_area.height = monitor_info.rcWork.bottom - monitor_info.rcWork.top;
68 }
69 }
70 return work_area;
71}
72
74 RECT parent_client_rect;
75 GetClientRect(parent_, &parent_client_rect);
76
77 // Convert top-left and bottom-right points to screen coordinates.
78 POINT parent_top_left = {parent_client_rect.left, parent_client_rect.top};
79 POINT parent_bottom_right = {parent_client_rect.right,
80 parent_client_rect.bottom};
81
82 ClientToScreen(parent_, &parent_top_left);
83 ClientToScreen(parent_, &parent_bottom_right);
84
85 // Get monitor from HWND and usable work area.
86 HMONITOR monitor = MonitorFromWindow(parent_, MONITOR_DEFAULTTONEAREST);
87 WindowRect work_area = GetWorkArea();
88
89 IsolateScope scope(isolate_);
90 auto rect = get_position_callback_(
92 WindowRect{parent_top_left.x, parent_top_left.y,
93 parent_bottom_right.x - parent_top_left.x,
94 parent_bottom_right.y - parent_top_left.y},
95 work_area);
96 SetWindowPos(window_handle_, nullptr, rect->left, rect->top, rect->width,
97 rect->height, SWP_NOACTIVATE | SWP_NOOWNERZORDER);
98 free(rect);
99
100 // The positioner constrained the dimensions more than current size, apply
101 // positioner constraints.
102 if (rect->width < physical_width_ || rect->height < physical_height_) {
103 auto metrics_event = view_controller_->view()->CreateWindowMetricsEvent();
104 view_controller_->engine()->SendWindowMetricsEvent(metrics_event);
105 }
106}
107
110 WPARAM wparam,
111 LPARAM lparam) {
112 switch (message) {
113 case WM_MOUSEACTIVATE:
114 // Prevent activation when clicked
115 return MA_NOACTIVATE;
116
117 case WM_NCACTIVATE:
118 // Return TRUE to prevent visual activation changes
119 return TRUE;
120
121 case WM_ACTIVATE:
122 // Immediately deactivate if somehow activated
123 if (LOWORD(wparam) != WA_INACTIVE) {
124 HWND hFocus = GetFocus();
125 SetFocus(nullptr);
126 }
127 break;
128 }
129
130 return HostWindow::HandleMessage(hwnd, message, wparam, lparam);
131}
132
133} // 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
return TRUE
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