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/. */ 6 7 /* Per-block-formatting-context manager of font size inflation for pan and zoom 8 * UI. */ 9 10 #ifndef nsFontInflationData_h_ 11 #define nsFontInflationData_h_ 12 13 #include "nsContainerFrame.h" 14 15 class nsFontInflationData { 16 using ReflowInput = mozilla::ReflowInput; 17 18 public: 19 static nsFontInflationData* FindFontInflationDataFor(const nsIFrame* aFrame); 20 21 // Returns whether the usable width changed (which requires the 22 // caller to mark its descendants dirty) 23 static bool UpdateFontInflationDataISizeFor(const ReflowInput& aReflowInput); 24 25 static void MarkFontInflationDataTextDirty(nsIFrame* aFrame); 26 InflationEnabled()27 bool InflationEnabled() { 28 if (mTextDirty) { 29 ScanText(); 30 } 31 return mInflationEnabled; 32 } 33 UsableISize()34 nscoord UsableISize() const { return mUsableISize; } 35 36 private: 37 explicit nsFontInflationData(nsIFrame* aBFCFrame); 38 39 nsFontInflationData(const nsFontInflationData&) = delete; 40 void operator=(const nsFontInflationData&) = delete; 41 42 void UpdateISize(const ReflowInput& aReflowInput); 43 enum SearchDirection { eFromStart, eFromEnd }; 44 static nsIFrame* FindEdgeInflatableFrameIn(nsIFrame* aFrame, 45 SearchDirection aDirection); 46 MarkTextDirty()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); 55 FlowRootFor(const nsIFrame * aFrame)56 static const nsIFrame* FlowRootFor(const nsIFrame* aFrame) { 57 while (!(aFrame->GetStateBits() & NS_FRAME_FONT_INFLATION_FLOW_ROOT)) { 58 aFrame = aFrame->GetParent(); 59 } 60 return aFrame; 61 } 62 63 nsIFrame* mBFCFrame; 64 nscoord mUsableISize; 65 nscoord mTextAmount, mTextThreshold; 66 bool mInflationEnabled; // for this BFC 67 bool mTextDirty; 68 }; 69 70 #endif /* !defined(nsFontInflationData_h_) */ 71