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