OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 class FastTextAutosizer FINAL { | 54 class FastTextAutosizer FINAL { |
55 WTF_MAKE_NONCOPYABLE(FastTextAutosizer); | 55 WTF_MAKE_NONCOPYABLE(FastTextAutosizer); |
56 | 56 |
57 public: | 57 public: |
58 static PassOwnPtr<FastTextAutosizer> create(const Document* document) | 58 static PassOwnPtr<FastTextAutosizer> create(const Document* document) |
59 { | 59 { |
60 return adoptPtr(new FastTextAutosizer(document)); | 60 return adoptPtr(new FastTextAutosizer(document)); |
61 } | 61 } |
62 | 62 |
63 void updatePageInfoInAllFrames(); | |
64 void updatePageInfo(); | |
65 void record(const RenderBlock*); | 63 void record(const RenderBlock*); |
66 void destroy(const RenderBlock*); | 64 void destroy(const RenderBlock*); |
67 void inflateListItem(RenderListItem*, RenderListMarker*); | 65 void inflateListItem(RenderListItem*, RenderListMarker*); |
68 | 66 |
69 class LayoutScope { | 67 class LayoutScope { |
70 public: | 68 public: |
71 explicit LayoutScope(RenderBlock*); | 69 explicit LayoutScope(RenderBlock*); |
72 ~LayoutScope(); | 70 ~LayoutScope(); |
73 private: | 71 private: |
74 FastTextAutosizer* m_textAutosizer; | 72 FastTextAutosizer* m_textAutosizer; |
75 RenderBlock* m_block; | 73 RenderBlock* m_block; |
76 }; | 74 }; |
77 | 75 |
78 private: | 76 private: |
79 typedef HashSet<const RenderBlock*> BlockSet; | 77 typedef HashSet<const RenderBlock*> BlockSet; |
80 | 78 |
81 enum HasEnoughTextToAutosize { | 79 enum HasEnoughTextToAutosize { |
82 UnknownAmountOfText, | 80 UnknownAmountOfText, |
83 HasEnoughText, | 81 HasEnoughText, |
84 NotEnoughText | 82 NotEnoughText |
85 }; | 83 }; |
86 | 84 |
87 enum RelayoutBehavior { | 85 enum PageAutosizingStatus { |
88 AlreadyInLayout, // The default; appropriate if we are already in layout
. | 86 PageAutosizingStatusUnknown, |
89 LayoutNeeded // Use this if changing a multiplier outside of layout. | 87 PageNeedsAutosizing, |
| 88 PageDoesNotNeedAutosizing |
90 }; | 89 }; |
91 | 90 |
92 // A supercluster represents autosizing information about a set of two or | 91 // A supercluster represents autosizing information about a set of two or |
93 // more blocks that all have the same fingerprint. Clusters whose roots | 92 // more blocks that all have the same fingerprint. Clusters whose roots |
94 // belong to a supercluster will share a common multiplier and | 93 // belong to a supercluster will share a common multiplier and |
95 // text-length-based autosizing status. | 94 // text-length-based autosizing status. |
96 struct Supercluster { | 95 struct Supercluster { |
97 explicit Supercluster(const BlockSet* roots) | 96 explicit Supercluster(const BlockSet* roots) |
98 : m_roots(roots) | 97 : m_roots(roots) |
99 , m_multiplier(0) | 98 , m_multiplier(0) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 #endif | 183 #endif |
185 }; | 184 }; |
186 | 185 |
187 explicit FastTextAutosizer(const Document*); | 186 explicit FastTextAutosizer(const Document*); |
188 | 187 |
189 void beginLayout(RenderBlock*); | 188 void beginLayout(RenderBlock*); |
190 void endLayout(RenderBlock*); | 189 void endLayout(RenderBlock*); |
191 void inflateTable(RenderTable*); | 190 void inflateTable(RenderTable*); |
192 void inflate(RenderBlock*); | 191 void inflate(RenderBlock*); |
193 bool enabled(); | 192 bool enabled(); |
194 void setAllTextNeedsLayout(); | 193 void updateRenderViewInfo(); |
195 void resetMultipliers(); | |
196 void prepareClusterStack(const RenderObject*); | 194 void prepareClusterStack(const RenderObject*); |
197 bool isFingerprintingCandidate(const RenderBlock*); | 195 bool isFingerprintingCandidate(const RenderBlock*); |
198 bool clusterHasEnoughTextToAutosize(Cluster*, const RenderBlock* widthProvid
er = 0); | 196 bool clusterHasEnoughTextToAutosize(Cluster*, const RenderBlock* widthProvid
er = 0); |
199 bool anyClusterHasEnoughTextToAutosize(const BlockSet* roots, const RenderBl
ock* widthProvider = 0); | 197 bool anyClusterHasEnoughTextToAutosize(const BlockSet* roots, const RenderBl
ock* widthProvider = 0); |
200 bool clusterWouldHaveEnoughTextToAutosize(const RenderBlock* root, const Ren
derBlock* widthProvider = 0); | 198 bool clusterWouldHaveEnoughTextToAutosize(const RenderBlock* root, const Ren
derBlock* widthProvider = 0); |
201 Fingerprint getFingerprint(const RenderObject*); | 199 Fingerprint getFingerprint(const RenderObject*); |
202 Fingerprint computeFingerprint(const RenderObject*); | 200 Fingerprint computeFingerprint(const RenderObject*); |
203 Cluster* maybeCreateCluster(const RenderBlock*); | 201 Cluster* maybeCreateCluster(const RenderBlock*); |
204 Supercluster* getSupercluster(const RenderBlock*); | 202 Supercluster* getSupercluster(const RenderBlock*); |
205 const RenderBlock* deepestCommonAncestor(BlockSet&); | 203 const RenderBlock* deepestCommonAncestor(BlockSet&); |
206 float clusterMultiplier(Cluster*); | 204 float clusterMultiplier(Cluster*); |
207 float superclusterMultiplier(Cluster*); | 205 float superclusterMultiplier(Cluster*); |
208 // A cluster's width provider is typically the deepest block containing all
text. | 206 // A cluster's width provider is typically the deepest block containing all
text. |
209 // There are exceptions, such as tables and table cells which use the table
itself for width. | 207 // There are exceptions, such as tables and table cells which use the table
itself for width. |
210 const RenderBlock* clusterWidthProvider(const RenderBlock*); | 208 const RenderBlock* clusterWidthProvider(const RenderBlock*); |
211 // Typically this returns a block's computed width. In the case of tables la
yout, this | 209 // Typically this returns a block's computed width. In the case of tables la
yout, this |
212 // width is not yet known so the fixed width is used if it's available, or t
he containing | 210 // width is not yet known so the fixed width is used if it's available, or t
he containing |
213 // block's width otherwise. | 211 // block's width otherwise. |
214 float widthFromBlock(const RenderBlock*); | 212 float widthFromBlock(const RenderBlock*); |
215 float multiplierFromBlock(const RenderBlock*); | 213 float multiplierFromBlock(const RenderBlock*); |
216 void applyMultiplier(RenderObject*, float, RelayoutBehavior = AlreadyInLayou
t); | 214 void applyMultiplier(RenderObject*, float); |
217 bool isWiderOrNarrowerDescendant(Cluster*); | 215 bool isWiderOrNarrowerDescendant(Cluster*); |
218 bool isLayoutRoot(const RenderBlock*) const; | 216 bool isLayoutRoot(const RenderBlock*) const; |
219 | 217 |
220 Cluster* currentCluster() const; | 218 Cluster* currentCluster() const; |
221 | 219 |
222 RenderObject* nextChildSkippingChildrenOfBlocks(const RenderObject*, const R
enderObject*); | 220 RenderObject* nextChildSkippingChildrenOfBlocks(const RenderObject*, const R
enderObject*); |
223 | 221 |
224 const RenderBlock* deepestBlockContainingAllText(Cluster*); | 222 const RenderBlock* deepestBlockContainingAllText(Cluster*); |
225 const RenderBlock* deepestBlockContainingAllText(const RenderBlock*); | 223 const RenderBlock* deepestBlockContainingAllText(const RenderBlock*); |
226 // Returns the first text leaf that is in the current cluster. We attempt to
not include text | 224 // Returns the first text leaf that is in the current cluster. We attempt to
not include text |
227 // from descendant clusters but because descendant clusters may not exist, t
his is only an approximation. | 225 // from descendant clusters but because descendant clusters may not exist, t
his is only an approximation. |
228 // The TraversalDirection controls whether we return the first or the last t
ext leaf. | 226 // The TraversalDirection controls whether we return the first or the last t
ext leaf. |
229 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc
h); | 227 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc
h); |
230 | 228 |
231 const Document* m_document; | 229 const Document* m_document; |
232 int m_frameWidth; // LocalFrame width in density-independent pixels (DIPs). | 230 int m_frameWidth; // LocalFrame width in density-independent pixels (DIPs). |
233 int m_layoutWidth; // Layout width in CSS pixels. | 231 int m_layoutWidth; // Layout width in CSS pixels. |
234 float m_baseMultiplier; // Includes accessibility font scale factor and devi
ce scale adjustment. | 232 float m_baseMultiplier; // Includes accessibility font scale factor and devi
ce scale adjustment. |
235 bool m_pageNeedsAutosizing; | 233 PageAutosizingStatus m_pageAutosizingStatus; |
236 bool m_previouslyAutosized; | |
237 const RenderBlock* m_firstBlock; // First block to receive beginLayout. | 234 const RenderBlock* m_firstBlock; // First block to receive beginLayout. |
238 #ifndef NDEBUG | 235 #ifndef NDEBUG |
| 236 bool m_renderViewInfoPrepared; |
239 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro
perties of a block before beginLayout() is called on it. | 237 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro
perties of a block before beginLayout() is called on it. |
240 #endif | 238 #endif |
241 | 239 |
242 // Clusters are created and destroyed during layout. The map key is the | 240 // Clusters are created and destroyed during layout. The map key is the |
243 // cluster root. Clusters whose roots share the same fingerprint use the | 241 // cluster root. Clusters whose roots share the same fingerprint use the |
244 // same multiplier. | 242 // same multiplier. |
245 SuperclusterMap m_superclusters; | 243 SuperclusterMap m_superclusters; |
246 ClusterStack m_clusterStack; | 244 ClusterStack m_clusterStack; |
247 FingerprintMapper m_fingerprintMapper; | 245 FingerprintMapper m_fingerprintMapper; |
248 }; | 246 }; |
249 | 247 |
250 } // namespace WebCore | 248 } // namespace WebCore |
251 | 249 |
252 #endif // FastTextAutosizer_h | 250 #endif // FastTextAutosizer_h |
OLD | NEW |