michael@0: /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Per-block-formatting-context manager of font size inflation for pan and zoom UI. */ michael@0: michael@0: #ifndef nsFontInflationData_h_ michael@0: #define nsFontInflationData_h_ michael@0: michael@0: #include "nsIFrame.h" michael@0: michael@0: struct nsHTMLReflowState; michael@0: michael@0: class nsFontInflationData michael@0: { michael@0: public: michael@0: michael@0: static nsFontInflationData* FindFontInflationDataFor(const nsIFrame *aFrame); michael@0: michael@0: // Returns whether the effective width changed (which requires the michael@0: // caller to mark its descendants dirty michael@0: static bool michael@0: UpdateFontInflationDataWidthFor(const nsHTMLReflowState& aReflowState); michael@0: michael@0: static void MarkFontInflationDataTextDirty(nsIFrame *aFrame); michael@0: michael@0: bool InflationEnabled() { michael@0: if (mTextDirty) { michael@0: ScanText(); michael@0: } michael@0: return mInflationEnabled; michael@0: } michael@0: michael@0: nscoord EffectiveWidth() const { michael@0: return mNCAWidth; michael@0: } michael@0: michael@0: private: michael@0: michael@0: nsFontInflationData(nsIFrame* aBFCFrame); michael@0: michael@0: nsFontInflationData(const nsFontInflationData&) MOZ_DELETE; michael@0: void operator=(const nsFontInflationData&) MOZ_DELETE; michael@0: michael@0: void UpdateWidth(const nsHTMLReflowState &aReflowState); michael@0: enum SearchDirection { eFromStart, eFromEnd }; michael@0: static nsIFrame* FindEdgeInflatableFrameIn(nsIFrame *aFrame, michael@0: SearchDirection aDirection); michael@0: michael@0: void MarkTextDirty() { mTextDirty = true; } michael@0: void ScanText(); michael@0: // Scan text in the subtree rooted at aFrame. Increment mTextAmount michael@0: // by multiplying the number of characters found by the font size michael@0: // (yielding the width that would be occupied by the characters if michael@0: // they were all em squares). But stop scanning if mTextAmount michael@0: // crosses mTextThreshold. michael@0: void ScanTextIn(nsIFrame *aFrame); michael@0: michael@0: static const nsIFrame* FlowRootFor(const nsIFrame *aFrame) michael@0: { michael@0: while (!(aFrame->GetStateBits() & NS_FRAME_FONT_INFLATION_FLOW_ROOT)) { michael@0: aFrame = aFrame->GetParent(); michael@0: } michael@0: return aFrame; michael@0: } michael@0: michael@0: nsIFrame *mBFCFrame; michael@0: nscoord mNCAWidth; michael@0: nscoord mTextAmount, mTextThreshold; michael@0: bool mInflationEnabled; // for this BFC michael@0: bool mTextDirty; michael@0: }; michael@0: michael@0: #endif /* !defined(nsFontInflationData_h_) */