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