Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
host_window_sized.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_SIZED_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_SIZED_H_
7
8#include <memory>
9
10#include "host_window.h"
12
13namespace flutter {
14
15// Base class for the sized-to-content archetypes: HostWindowRegular,
16// HostWindowDialog, HostWindowPopup, and HostWindowTooltip.
17//
18// Provides the shared sized-to-content implementation used by these
19// archetypes: tracking the last rendered content size and reacting to it after
20// each frame. The default reaction resizes the window in place and optionally
21// disables content-size tracking once the user resizes the window.
22// HostWindowPopup and HostWindowTooltip override ApplyContentSize() to instead
23// reposition themselves relative to a parent window whenever their content
24// size changes.
27 protected:
28 HostWindowSized(WindowManager* window_manager,
30 bool resizable);
31
32 // Pure virtual to make HostWindowSized abstract: only the concrete
33 // archetypes (HostWindowRegular, HostWindowDialog, HostWindowPopup,
34 // HostWindowTooltip) may be instantiated.
35 //
36 // Each derived class must reset |view_controller_| at the very start of its
37 // own destructor, while the most-derived object is still fully alive.
38 //
39 // When sized to content, this object is the view's
40 // FlutterWindowsViewSizingDelegate, and the view (owned by
41 // |view_controller_|, a member of the HostWindow base class) drives sizing
42 // from the raster thread via DidUpdateViewSize -> ApplyContentSize /
43 // GetWorkArea. Several of these entry points are overridden by derived
44 // classes. If the view were destroyed by the HostWindow base destructor
45 // instead, it would run *after* the derived destructor: by then the derived
46 // subobject (and its vtable overrides) is gone, so an in-flight raster-thread
47 // sizing call could land in a destroyed object and crash. Resetting
48 // |view_controller_| in the derived destructor triggers
49 // FlutterWindowsEngine::RemoveView, which guarantees the raster thread no
50 // longer presents to (or sizes) this view before any subobject is torn down.
51 //
52 // The base destructor asserts that |view_controller_| has already been reset.
53 ~HostWindowSized() override = 0;
54
55 // Returns a pointer to this as a FlutterWindowsViewSizingDelegate, for use
56 // as HostWindowInitializationParams::sizing_delegate. This is necessary
57 // because FlutterWindowsViewSizingDelegate is a private base of this class
58 // and the conversion is therefore inaccessible to derived classes.
60
61 // Called on the platform thread after the rendered content size has changed
62 // to |physical_width| x |physical_height| (in physical pixels). The base
63 // implementation resizes the window in place to fit the content and, for
64 // resizable windows, stops tracking content size after the initial frame.
65 // Subclasses that position themselves relative to a parent override this.
66 virtual void ApplyContentSize(int32_t physical_width,
67 int32_t physical_height);
68
69 // Whether the user can manually resize this window.
70 const bool resizable_;
71
72 // Used to track whether the view is still alive in tasks posted from the
73 // raster thread.
74 std::shared_ptr<int> view_alive_;
75
76 // The last physical-pixel size reported to DidUpdateViewSize.
79
80 private:
81 // FlutterWindowsViewSizingDelegate:
82 void DidUpdateViewSize(int32_t width, int32_t height) override;
83 WindowRect GetWorkArea() const override;
84};
85
86} // namespace flutter
87
88#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_SIZED_H_
std::shared_ptr< int > view_alive_
virtual void ApplyContentSize(int32_t physical_width, int32_t physical_height)
FlutterWindowsViewSizingDelegate * AsSizingDelegate()
FlutterEngine engine
Definition main.cc:84
int32_t height
int32_t width