Flutter Windows Embedder
host_window.h
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 
5 #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_
7 
8 #include <windows.h>
9 #include <memory>
10 #include <optional>
11 
12 #include "flutter/fml/macros.h"
16 
17 namespace flutter {
18 
19 class WindowManager;
20 class FlutterWindowsView;
21 class FlutterWindowsViewController;
22 
23 // A Win32 window that hosts a |FlutterWindow| in its client area.
24 class HostWindow {
25  public:
26  virtual ~HostWindow();
27 
28  // Creates a native Win32 window with a child view confined to its client
29  // area. |controller| is a pointer to the controller that manages the
30  // |HostWindow|. |engine| is a pointer to the engine that manages
31  // the controller. On success, a valid window handle can be retrieved
32  // via |HostWindow::GetWindowHandle|. |nullptr| will be returned
33  // on failure.
34  static std::unique_ptr<HostWindow> CreateRegularWindow(
35  WindowManager* controller,
36  FlutterWindowsEngine* engine,
37  const WindowSizing& content_size);
38 
39  // Returns the instance pointer for |hwnd| or nullptr if invalid.
40  static HostWindow* GetThisFromHandle(HWND hwnd);
41 
42  // Returns the backing window handle, or nullptr if the native window is not
43  // created or has already been destroyed.
44  HWND GetWindowHandle() const;
45 
46  // Resizes the window to accommodate a client area of the given
47  // |size|.
48  void SetContentSize(const WindowSizing& size);
49 
50  private:
51  friend WindowManager;
52 
53  HostWindow(WindowManager* controller,
54  FlutterWindowsEngine* engine,
55  WindowArchetype archetype,
56  std::unique_ptr<FlutterWindowsViewController> view_controller,
57  const BoxConstraints& constraints,
58  HWND hwnd);
59 
60  // Sets the focus to the child view window of |window|.
61  static void FocusViewOf(HostWindow* window);
62 
63  // OS callback called by message pump. Handles the WM_NCCREATE message which
64  // is passed when the non-client area is being created and enables automatic
65  // non-client DPI scaling so that the non-client area automatically
66  // responds to changes in DPI. Delegates other messages to the controller.
67  static LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
68 
69  // Processes and routes salient window messages for mouse handling,
70  // size change and DPI. Delegates handling of these to member overloads that
71  // inheriting classes can handle.
72  LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
73 
74  // Controller for this window.
75  WindowManager* const window_manager_ = nullptr;
76 
77  // The Flutter engine that owns this window.
78  FlutterWindowsEngine* engine_;
79 
80  // Controller for the view hosted in this window. Value-initialized if the
81  // window is created from an existing top-level native window created by the
82  // runner.
83  std::unique_ptr<FlutterWindowsViewController> view_controller_;
84 
85  // The window archetype.
87 
88  // Backing handle for this window.
89  HWND window_handle_ = nullptr;
90 
91  // The constraints on the window's client area.
92  BoxConstraints box_constraints_;
93 
94  FML_DISALLOW_COPY_AND_ASSIGN(HostWindow);
95 };
96 
97 } // namespace flutter
98 
99 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_
HWND GetWindowHandle() const
Definition: host_window.cc:347
void SetContentSize(const WindowSizing &size)
Definition: host_window.cc:466
static std::unique_ptr< HostWindow > CreateRegularWindow(WindowManager *controller, FlutterWindowsEngine *engine, const WindowSizing &content_size)
Definition: host_window.cc:200
static HostWindow * GetThisFromHandle(HWND hwnd)
Definition: host_window.cc:343
Win32Message message
WindowArchetype
Definition: windowing.h:13