Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / generic / nsFontInflationData.h
blob80a422fe323d91df6f7424ad1c8e094c2a8b584b
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Per-block-formatting-context manager of font size inflation for pan and zoom
8 * UI. */
10 #ifndef nsFontInflationData_h_
11 #define nsFontInflationData_h_
13 #include "nsContainerFrame.h"
15 class nsFontInflationData {
16 using ReflowInput = mozilla::ReflowInput;
18 public:
19 static nsFontInflationData* FindFontInflationDataFor(const nsIFrame* aFrame);
21 // Returns whether the usable width changed (which requires the
22 // caller to mark its descendants dirty)
23 static bool UpdateFontInflationDataISizeFor(const ReflowInput& aReflowInput);
25 static void MarkFontInflationDataTextDirty(nsIFrame* aFrame);
27 bool InflationEnabled() {
28 if (mTextDirty) {
29 ScanText();
31 return mInflationEnabled;
34 nscoord UsableISize() const { return mUsableISize; }
36 private:
37 explicit nsFontInflationData(nsIFrame* aBFCFrame);
39 nsFontInflationData(const nsFontInflationData&) = delete;
40 void operator=(const nsFontInflationData&) = delete;
42 void UpdateISize(const ReflowInput& aReflowInput);
43 enum SearchDirection { eFromStart, eFromEnd };
44 static nsIFrame* FindEdgeInflatableFrameIn(nsIFrame* aFrame,
45 SearchDirection aDirection);
47 void MarkTextDirty() { mTextDirty = true; }
48 void ScanText();
49 // Scan text in the subtree rooted at aFrame. Increment mTextAmount
50 // by multiplying the number of characters found by the font size
51 // (yielding the inline-size that would be occupied by the characters if
52 // they were all em squares). But stop scanning if mTextAmount
53 // crosses mTextThreshold.
54 void ScanTextIn(nsIFrame* aFrame);
56 static const nsIFrame* FlowRootFor(const nsIFrame* aFrame) {
57 while (!aFrame->HasAnyStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT)) {
58 aFrame = aFrame->GetParent();
60 return aFrame;
63 nsIFrame* mBFCFrame;
64 nscoord mUsableISize;
65 nscoord mTextAmount, mTextThreshold;
66 bool mInflationEnabled; // for this BFC
67 bool mTextDirty;
70 #endif /* !defined(nsFontInflationData_h_) */