Flutter Windows Embedder
flutter::HostWindowSatellite Class Reference

#include <host_window_satellite.h>

Inheritance diagram for flutter::HostWindowSatellite:
flutter::HostWindowSized flutter::HostWindow flutter::FlutterWindowsViewSizingDelegate

Public Member Functions

 HostWindowSatellite (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const BoxConstraints &constraints, GetWindowPositionCallback get_position_callback, HWND parent, LPCWSTR title, bool sized_to_content, bool resizable)
 
 ~HostWindowSatellite () override
 
void OnParentMoved ()
 
void SetSatelliteParent (HWND new_parent)
 
- Public Member Functions inherited from flutter::HostWindow
virtual ~HostWindow ()
 
HWND GetWindowHandle () const
 
HWND GetFlutterViewWindowHandle () const
 
void SetContentSize (const WindowSizeRequest &size)
 
void SetConstraints (const WindowConstraints &constraints)
 
virtual void SetFullscreen (bool fullscreen, std::optional< FlutterEngineDisplayId > display_id)
 
virtual bool GetFullscreen () const
 
HostWindow * GetOwnerWindow () const
 
void UpdateModalStateLayer ()
 

Protected Member Functions

LRESULT HandleMessage (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) override
 
void OnFirstFrame () override
 
void ApplyContentSize (int32_t physical_width, int32_t physical_height) override
 
- Protected Member Functions inherited from flutter::HostWindowSized
 HostWindowSized (WindowManager *window_manager, FlutterWindowsEngine *engine, bool resizable)
 
 ~HostWindowSized () override=0
 
FlutterWindowsViewSizingDelegate * AsSizingDelegate ()
 
- Protected Member Functions inherited from flutter::HostWindow
WindowArchetype GetArchetype () const
 
void InitializeFlutterView (HostWindowInitializationParams const &params)
 
 HostWindow (WindowManager *window_manager, FlutterWindowsEngine *engine)
 
void AlignOriginWithFrame ()
 
void HandleWindowActivation (HWND hwnd, WPARAM wparam)
 
void EnableRecursively (bool enable)
 
HostWindow * FindFirstEnabledDescendant () const
 
std::vector< HostWindow * > GetOwnedWindows () const
 
void DisableRecursively ()
 
 FML_DISALLOW_COPY_AND_ASSIGN (HostWindow)
 

Additional Inherited Members

- Static Public Member Functions inherited from flutter::HostWindow
static std::unique_ptr< HostWindow > CreateRegularWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title, bool sized_to_content, bool resizable)
 
static std::unique_ptr< HostWindow > CreateDialogWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title, HWND parent, bool sized_to_content, bool resizable)
 
static std::unique_ptr< HostWindow > CreateTooltipWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent)
 
static std::unique_ptr< HostWindow > CreatePopupWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent)
 
static std::unique_ptr< HostWindow > CreateSatelliteWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent, LPCWSTR title, bool sized_to_content, bool resizable)
 
static HostWindow * GetThisFromHandle (HWND hwnd)
 
static ActualWindowSize GetWindowContentSize (HWND hwnd)
 
- Static Protected Member Functions inherited from flutter::HostWindowSized
static WindowRect GetWorkAreaForWindow (HWND hwnd)
 
- Static Protected Member Functions inherited from flutter::HostWindow
static std::optional< Size > GetWindowSizeForClientSize (WindowsProcTable const &win32, Size const &client_size, std::optional< Size > smallest, std::optional< Size > biggest, DWORD window_style, DWORD extended_window_style, std::optional< HWND > const &owner_hwnd)
 
static std::optional< Size > GetInitialWindowSize (FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const BoxConstraints &constraints, DWORD window_style, DWORD extended_window_style, std::optional< HWND > const &owner_window, bool sized_to_content)
 
static void FocusRootViewOf (HostWindow *window)
 
static LRESULT WndProc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
 
- Protected Attributes inherited from flutter::HostWindowSized
const bool resizable_
 
int physical_width_ = 0
 
int physical_height_ = 0
 
- Protected Attributes inherited from flutter::HostWindow
friend WindowManager
 
WindowManager *const window_manager_ = nullptr
 
FlutterWindowsEngine * engine_
 
std::unique_ptr< FlutterWindowsViewController > view_controller_
 
std::shared_ptr< int > alive_ = std::make_shared<int>(0)
 
WindowArchetype archetype_ = WindowArchetype::kRegular
 
HWND window_handle_
 
BoxConstraints box_constraints_
 
bool is_being_destroyed_ = false
 
bool is_fullscreen_ = false
 
SavedWindowInfo saved_window_info_
 
Microsoft::WRL::ComPtr< ITaskbarList2 > task_bar_list_
 

Detailed Description

Definition at line 27 of file host_window_satellite.h.

Constructor & Destructor Documentation

◆ HostWindowSatellite()

flutter::HostWindowSatellite::HostWindowSatellite ( WindowManager *  window_manager,
FlutterWindowsEngine *  engine,
const WindowSizeRequest &  preferred_size,
const BoxConstraints &  constraints,
GetWindowPositionCallback  get_position_callback,
HWND  parent,
LPCWSTR  title,
bool  sized_to_content,
bool  resizable 
)

Definition at line 28 of file host_window_satellite.cc.

38  : HostWindowSized(window_manager, engine, resizable),
39  get_position_callback_(get_position_callback),
40  parent_(parent),
41  isolate_(Isolate::Current()) {
42  FML_CHECK(sized_to_content || preferred_size.has_preferred_view_size);
43 
44  InitializeFlutterView(HostWindowInitializationParams{
45  .archetype = WindowArchetype::kSatellite,
46  .window_style = GetWindowStyleForSatellite(resizable),
47  .extended_window_style = 0,
48  .box_constraints = constraints,
49  .initial_window_rect =
50  GetInitialRect(engine, preferred_size, constraints, parent,
51  sized_to_content, resizable),
52  .title = title ? title : L"",
53  .owner_window = parent,
54  .sizing_delegate = sized_to_content ? AsSizingDelegate() : nullptr,
55  .is_sized_to_content = sized_to_content,
56  });
57 
58  UpdateParentOffset();
59 }
void InitializeFlutterView(HostWindowInitializationParams const &params)
Definition: host_window.cc:249
FlutterWindowsViewSizingDelegate * AsSizingDelegate()
HostWindowSized(WindowManager *window_manager, FlutterWindowsEngine *engine, bool resizable)
static Isolate Current()
Definition: isolate_scope.cc:9

◆ ~HostWindowSatellite()

flutter::HostWindowSatellite::~HostWindowSatellite ( )
override

Definition at line 61 of file host_window_satellite.cc.

61  {
62  // Reset the view while this most-derived object is still fully alive, to stop
63  // the raster thread from sizing it (via the overridden ApplyContentSize /
64  // GetWorkArea) before any subobject is torn down. See the destructor comment
65  // in host_window_sized.h for the rationale.
66  view_controller_.reset();
67 }
std::unique_ptr< FlutterWindowsViewController > view_controller_
Definition: host_window.h:314

References flutter::HostWindow::view_controller_.

Member Function Documentation

◆ ApplyContentSize()

void flutter::HostWindowSatellite::ApplyContentSize ( int32_t  physical_width,
int32_t  physical_height 
)
overrideprotectedvirtual

Reimplemented from flutter::HostWindowSized.

Definition at line 154 of file host_window_satellite.cc.

155  {
156  // Resize the window to fit its content. For resizable satellites this also
157  // stops content-size tracking after the first frame, so the user's subsequent
158  // manual resizes are forwarded to Flutter instead of being overridden.
159  HostWindowSized::ApplyContentSize(physical_width, physical_height);
160 
161  // Run the positioner only for the initial placement. Afterwards the satellite
162  // is positioned solely by following its parent.
163  ApplyInitialPosition();
164 }
virtual void ApplyContentSize(int32_t physical_width, int32_t physical_height)

References flutter::HostWindowSized::ApplyContentSize().

◆ HandleMessage()

LRESULT flutter::HostWindowSatellite::HandleMessage ( HWND  hwnd,
UINT  message,
WPARAM  wparam,
LPARAM  lparam 
)
overrideprotectedvirtual

Reimplemented from flutter::HostWindow.

Definition at line 254 of file host_window_satellite.cc.

257  {
258  switch (message) {
259  case WM_SYSCOMMAND:
260  // Disallow minimization.
261  if ((wparam & 0xFFF0) == SC_MINIMIZE) {
262  return 0;
263  }
264  break;
265 
266  case WM_ENTERSIZEMOVE:
267  is_in_move_size_loop_ = true;
268  break;
269 
270  case WM_EXITSIZEMOVE:
271  is_in_move_size_loop_ = false;
272  break;
273 
274  case WM_DPICHANGED: {
275  // While the user drags the satellite, or while it is already following
276  // its parent (whose loop corrects the position), use the default
277  // handling, which applies the system-suggested rectangle.
278  if (is_in_move_size_loop_ || is_following_parent_) {
279  break;
280  }
281 
282  // Otherwise the DPI change was not caused by the user moving the
283  // satellite (e.g. it followed its parent onto another monitor). Apply the
284  // suggested rectangle for its new size, without treating the
285  // accompanying move as a new offset from the parent, and then re-anchor
286  // the satellite to its parent.
287  bool const was_following_parent =
288  std::exchange(is_following_parent_, true);
289  LRESULT const result =
290  HostWindow::HandleMessage(hwnd, message, wparam, lparam);
291  is_following_parent_ = was_following_parent;
292  OnParentMoved();
293  return result;
294  }
295 
296  case WM_WINDOWPOSCHANGED: {
297  // When the satellite is moved other than by following its parent (e.g.
298  // dragged by the user), keep the new offset from the parent.
299  auto const* const window_pos = reinterpret_cast<WINDOWPOS*>(lparam);
300  if (!is_following_parent_ && window_pos &&
301  !(window_pos->flags & SWP_NOMOVE)) {
302  UpdateParentOffset();
303  }
304  break;
305  }
306 
307  case WM_ACTIVATE:
308  // Forward the message to Dart before handling it on the C++ side, so
309  // that Dart-side handlers (e.g. popup dismiss logic) can observe
310  // activation changes caused by satellite windows.
311  if (auto const result =
313  window_handle_, message, wparam, lparam)) {
314  return *result;
315  }
316 
317  HandleWindowActivation(hwnd, wparam);
318  return 0;
319  }
320 
321  return HostWindow::HandleMessage(hwnd, message, wparam, lparam);
322 }
WindowProcDelegateManager * window_proc_delegate_manager()
void HandleWindowActivation(HWND hwnd, WPARAM wparam)
Definition: host_window.cc:392
FlutterWindowsEngine * engine_
Definition: host_window.h:309
virtual LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
Definition: host_window.cc:432
std::optional< LRESULT > OnTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) const
Win32Message message

References flutter::HostWindow::engine_, flutter::HostWindow::HandleMessage(), flutter::HostWindow::HandleWindowActivation(), message, OnParentMoved(), flutter::WindowProcDelegateManager::OnTopLevelWindowProc(), flutter::HostWindow::window_handle_, and flutter::FlutterWindowsEngine::window_proc_delegate_manager().

◆ OnFirstFrame()

void flutter::HostWindowSatellite::OnFirstFrame ( )
overrideprotectedvirtual

Reimplemented from flutter::HostWindow.

Definition at line 148 of file host_window_satellite.cc.

148  {
149  // A satellite that is sized to content has already been placed from
150  // |ApplyContentSize|, which runs once the first frame has been generated.
151  ApplyInitialPosition();
152 }

◆ OnParentMoved()

void flutter::HostWindowSatellite::OnParentMoved ( )

Definition at line 196 of file host_window_satellite.cc.

196  {
197  bool const was_following_parent = std::exchange(is_following_parent_, true);
198 
199  // Moving the satellite may carry it onto a monitor with a different DPI. Its
200  // WM_DPICHANGED handler then resizes it to the system-suggested rectangle,
201  // which may also move it. A second pass corrects for that.
202  for (int pass = 0; pass < 2; ++pass) {
203  std::optional<POINT> const parent_origin = GetParentClientOrigin();
204  RECT window_rect;
205  if (!parent_origin || !GetWindowRect(window_handle_, &window_rect)) {
206  break;
207  }
208 
209  double const scale_factor = GetParentScaleFactor();
210  LONG const target_x =
211  parent_origin->x + std::lround(parent_offset_x_ * scale_factor);
212  LONG const target_y =
213  parent_origin->y + std::lround(parent_offset_y_ * scale_factor);
214  if (target_x == window_rect.left && target_y == window_rect.top) {
215  break;
216  }
217 
218  SetWindowPos(window_handle_, nullptr, target_x, target_y, 0, 0,
219  SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
220  }
221 
222  is_following_parent_ = was_following_parent;
223 }

References flutter::HostWindow::window_handle_.

Referenced by HandleMessage().

◆ SetSatelliteParent()

void flutter::HostWindowSatellite::SetSatelliteParent ( HWND  new_parent)

Definition at line 225 of file host_window_satellite.cc.

225  {
226  if (new_parent == parent_ || new_parent == nullptr) {
227  return;
228  }
229 
230  // Reject a reparent that would make this satellite its own ancestor.
231  for (HWND ancestor = new_parent; ancestor != nullptr;
232  ancestor = GetWindow(ancestor, GW_OWNER)) {
233  if (ancestor == window_handle_) {
234  FML_LOG(ERROR) << "Refusing to anchor a satellite window to itself or to "
235  "one of its own satellites.";
236  return;
237  }
238  }
239 
240  parent_ = new_parent;
241  // Transfer ownership to the new parent, so that the satellite is destroyed
242  // alongside it.
243  SetWindowLongPtr(window_handle_, GWLP_HWNDPARENT,
244  reinterpret_cast<LONG_PTR>(new_parent));
245  SetWindowPos(window_handle_, nullptr, 0, 0, 0, 0,
246  SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE |
247  SWP_FRAMECHANGED);
248 
249  // Measure the offset against the new parent so that reparenting does not
250  // move the satellite.
251  UpdateParentOffset();
252 }

References flutter::HostWindow::window_handle_.


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