|
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* Per-block-formatting-context manager of font size inflation for pan and zoom UI. */ |
|
7 |
|
8 #ifndef nsFontInflationData_h_ |
|
9 #define nsFontInflationData_h_ |
|
10 |
|
11 #include "nsIFrame.h" |
|
12 |
|
13 struct nsHTMLReflowState; |
|
14 |
|
15 class nsFontInflationData |
|
16 { |
|
17 public: |
|
18 |
|
19 static nsFontInflationData* FindFontInflationDataFor(const nsIFrame *aFrame); |
|
20 |
|
21 // Returns whether the effective width changed (which requires the |
|
22 // caller to mark its descendants dirty |
|
23 static bool |
|
24 UpdateFontInflationDataWidthFor(const nsHTMLReflowState& aReflowState); |
|
25 |
|
26 static void MarkFontInflationDataTextDirty(nsIFrame *aFrame); |
|
27 |
|
28 bool InflationEnabled() { |
|
29 if (mTextDirty) { |
|
30 ScanText(); |
|
31 } |
|
32 return mInflationEnabled; |
|
33 } |
|
34 |
|
35 nscoord EffectiveWidth() const { |
|
36 return mNCAWidth; |
|
37 } |
|
38 |
|
39 private: |
|
40 |
|
41 nsFontInflationData(nsIFrame* aBFCFrame); |
|
42 |
|
43 nsFontInflationData(const nsFontInflationData&) MOZ_DELETE; |
|
44 void operator=(const nsFontInflationData&) MOZ_DELETE; |
|
45 |
|
46 void UpdateWidth(const nsHTMLReflowState &aReflowState); |
|
47 enum SearchDirection { eFromStart, eFromEnd }; |
|
48 static nsIFrame* FindEdgeInflatableFrameIn(nsIFrame *aFrame, |
|
49 SearchDirection aDirection); |
|
50 |
|
51 void MarkTextDirty() { mTextDirty = true; } |
|
52 void ScanText(); |
|
53 // Scan text in the subtree rooted at aFrame. Increment mTextAmount |
|
54 // by multiplying the number of characters found by the font size |
|
55 // (yielding the width that would be occupied by the characters if |
|
56 // they were all em squares). But stop scanning if mTextAmount |
|
57 // crosses mTextThreshold. |
|
58 void ScanTextIn(nsIFrame *aFrame); |
|
59 |
|
60 static const nsIFrame* FlowRootFor(const nsIFrame *aFrame) |
|
61 { |
|
62 while (!(aFrame->GetStateBits() & NS_FRAME_FONT_INFLATION_FLOW_ROOT)) { |
|
63 aFrame = aFrame->GetParent(); |
|
64 } |
|
65 return aFrame; |
|
66 } |
|
67 |
|
68 nsIFrame *mBFCFrame; |
|
69 nscoord mNCAWidth; |
|
70 nscoord mTextAmount, mTextThreshold; |
|
71 bool mInflationEnabled; // for this BFC |
|
72 bool mTextDirty; |
|
73 }; |
|
74 |
|
75 #endif /* !defined(nsFontInflationData_h_) */ |