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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 class Document; | 46 class Document; |
47 class LayoutListItem; | 47 class LayoutListItem; |
48 class LayoutListMarker; | 48 class LayoutListMarker; |
49 class LayoutBlock; | 49 class LayoutBlock; |
50 | 50 |
51 // Single-pass text autosizer. Documentation at: | 51 // Single-pass text autosizer. Documentation at: |
52 // http://tinyurl.com/TextAutosizer | 52 // http://tinyurl.com/TextAutosizer |
53 | 53 |
54 class CORE_EXPORT TextAutosizer final : public NoBaseWillBeGarbageCollectedFinal
ized<TextAutosizer> { | 54 class CORE_EXPORT TextAutosizer final : public NoBaseWillBeGarbageCollectedFinal
ized<TextAutosizer> { |
| 55 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(TextAutosizer); |
55 WTF_MAKE_NONCOPYABLE(TextAutosizer); | 56 WTF_MAKE_NONCOPYABLE(TextAutosizer); |
56 public: | 57 public: |
57 static PassOwnPtrWillBeRawPtr<TextAutosizer> create(const Document* document
) | 58 static PassOwnPtrWillBeRawPtr<TextAutosizer> create(const Document* document
) |
58 { | 59 { |
59 return adoptPtrWillBeNoop(new TextAutosizer(document)); | 60 return adoptPtrWillBeNoop(new TextAutosizer(document)); |
60 } | 61 } |
61 static float computeAutosizedFontSize(float specifiedSize, float multiplier)
; | 62 static float computeAutosizedFontSize(float specifiedSize, float multiplier)
; |
62 | 63 |
63 void updatePageInfoInAllFrames(); | 64 void updatePageInfoInAllFrames(); |
64 void updatePageInfo(); | 65 void updatePageInfo(); |
65 void record(const LayoutBlock*); | 66 void record(const LayoutBlock*); |
66 void destroy(const LayoutBlock*); | 67 void destroy(const LayoutBlock*); |
67 | 68 |
68 bool pageNeedsAutosizing() const; | 69 bool pageNeedsAutosizing() const; |
69 | 70 |
70 DECLARE_TRACE(); | 71 DECLARE_TRACE(); |
71 | 72 |
72 class LayoutScope { | 73 class LayoutScope { |
73 STACK_ALLOCATED(); | 74 STACK_ALLOCATED(); |
74 public: | 75 public: |
75 explicit LayoutScope(LayoutBlock*); | 76 explicit LayoutScope(LayoutBlock*); |
76 ~LayoutScope(); | 77 ~LayoutScope(); |
77 protected: | 78 protected: |
78 RawPtrWillBeMember<TextAutosizer> m_textAutosizer; | 79 RawPtrWillBeMember<TextAutosizer> m_textAutosizer; |
79 LayoutBlock* m_block; | 80 LayoutBlock* m_block; |
80 }; | 81 }; |
81 | 82 |
82 class TableLayoutScope : LayoutScope { | 83 class TableLayoutScope : LayoutScope { |
| 84 STACK_ALLOCATED(); |
83 public: | 85 public: |
84 explicit TableLayoutScope(LayoutTable*); | 86 explicit TableLayoutScope(LayoutTable*); |
85 }; | 87 }; |
86 | 88 |
87 class CORE_EXPORT DeferUpdatePageInfo { | 89 class CORE_EXPORT DeferUpdatePageInfo { |
88 STACK_ALLOCATED(); | 90 STACK_ALLOCATED(); |
89 public: | 91 public: |
90 explicit DeferUpdatePageInfo(Page*); | 92 explicit DeferUpdatePageInfo(Page*); |
91 ~DeferUpdatePageInfo(); | 93 ~DeferUpdatePageInfo(); |
92 private: | 94 private: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 SUPPRESSING = 1 << 4 | 133 SUPPRESSING = 1 << 4 |
132 }; | 134 }; |
133 | 135 |
134 typedef unsigned BlockFlags; | 136 typedef unsigned BlockFlags; |
135 | 137 |
136 // A supercluster represents autosizing information about a set of two or | 138 // A supercluster represents autosizing information about a set of two or |
137 // more blocks that all have the same fingerprint. Clusters whose roots | 139 // more blocks that all have the same fingerprint. Clusters whose roots |
138 // belong to a supercluster will share a common multiplier and | 140 // belong to a supercluster will share a common multiplier and |
139 // text-length-based autosizing status. | 141 // text-length-based autosizing status. |
140 struct Supercluster { | 142 struct Supercluster { |
| 143 WTF_MAKE_FAST_ALLOCATED(Supercluster); |
| 144 public: |
141 explicit Supercluster(const BlockSet* roots) | 145 explicit Supercluster(const BlockSet* roots) |
142 : m_roots(roots) | 146 : m_roots(roots) |
143 , m_hasEnoughTextToAutosize(UnknownAmountOfText) | 147 , m_hasEnoughTextToAutosize(UnknownAmountOfText) |
144 , m_multiplier(0) | 148 , m_multiplier(0) |
145 { | 149 { |
146 } | 150 } |
147 | 151 |
148 const BlockSet* const m_roots; | 152 const BlockSet* const m_roots; |
149 HasEnoughTextToAutosize m_hasEnoughTextToAutosize; | 153 HasEnoughTextToAutosize m_hasEnoughTextToAutosize; |
150 float m_multiplier; | 154 float m_multiplier; |
151 }; | 155 }; |
152 | 156 |
153 struct Cluster { | 157 struct Cluster { |
| 158 WTF_MAKE_FAST_ALLOCATED(Cluster); |
| 159 public: |
154 explicit Cluster(const LayoutBlock* root, BlockFlags flags, Cluster* par
ent, Supercluster* supercluster = nullptr) | 160 explicit Cluster(const LayoutBlock* root, BlockFlags flags, Cluster* par
ent, Supercluster* supercluster = nullptr) |
155 : m_root(root) | 161 : m_root(root) |
156 , m_flags(flags) | 162 , m_flags(flags) |
157 , m_deepestBlockContainingAllText(nullptr) | 163 , m_deepestBlockContainingAllText(nullptr) |
158 , m_parent(parent) | 164 , m_parent(parent) |
159 , m_multiplier(0) | 165 , m_multiplier(0) |
160 , m_hasEnoughTextToAutosize(UnknownAmountOfText) | 166 , m_hasEnoughTextToAutosize(UnknownAmountOfText) |
161 , m_supercluster(supercluster) | 167 , m_supercluster(supercluster) |
162 , m_hasTableAncestor(root->isTableCell() || (m_parent && m_parent->m
_hasTableAncestor)) | 168 , m_hasTableAncestor(root->isTableCell() || (m_parent && m_parent->m
_hasTableAncestor)) |
163 { | 169 { |
(...skipping 15 matching lines...) Expand all Loading... |
179 Supercluster* m_supercluster; | 185 Supercluster* m_supercluster; |
180 bool m_hasTableAncestor; | 186 bool m_hasTableAncestor; |
181 }; | 187 }; |
182 | 188 |
183 enum TextLeafSearch { | 189 enum TextLeafSearch { |
184 First, | 190 First, |
185 Last | 191 Last |
186 }; | 192 }; |
187 | 193 |
188 struct FingerprintSourceData { | 194 struct FingerprintSourceData { |
| 195 STACK_ALLOCATED(); |
189 FingerprintSourceData() | 196 FingerprintSourceData() |
190 : m_parentHash(0) | 197 : m_parentHash(0) |
191 , m_qualifiedNameHash(0) | 198 , m_qualifiedNameHash(0) |
192 , m_packedStyleProperties(0) | 199 , m_packedStyleProperties(0) |
193 , m_column(0) | 200 , m_column(0) |
194 , m_width(0) | 201 , m_width(0) |
195 { | 202 { |
196 } | 203 } |
197 | 204 |
198 unsigned m_parentHash; | 205 unsigned m_parentHash; |
199 unsigned m_qualifiedNameHash; | 206 unsigned m_qualifiedNameHash; |
200 // Style specific selection of signals | 207 // Style specific selection of signals |
201 unsigned m_packedStyleProperties; | 208 unsigned m_packedStyleProperties; |
202 unsigned m_column; | 209 unsigned m_column; |
203 float m_width; | 210 float m_width; |
204 }; | 211 }; |
205 // Ensures efficient hashing using StringHasher. | 212 // Ensures efficient hashing using StringHasher. |
206 static_assert(!(sizeof(FingerprintSourceData) % sizeof(UChar)), | 213 static_assert(!(sizeof(FingerprintSourceData) % sizeof(UChar)), |
207 "sizeof(FingerprintSourceData) must be a multiple of UChar"); | 214 "sizeof(FingerprintSourceData) must be a multiple of UChar"); |
208 | 215 |
209 typedef unsigned Fingerprint; | 216 typedef unsigned Fingerprint; |
210 typedef HashMap<Fingerprint, OwnPtr<Supercluster>> SuperclusterMap; | 217 typedef HashMap<Fingerprint, OwnPtr<Supercluster>> SuperclusterMap; |
211 typedef Vector<OwnPtr<Cluster>> ClusterStack; | 218 typedef Vector<OwnPtr<Cluster>> ClusterStack; |
212 | 219 |
213 // Fingerprints are computed during style recalc, for (some subset of) | 220 // Fingerprints are computed during style recalc, for (some subset of) |
214 // blocks that will become cluster roots. | 221 // blocks that will become cluster roots. |
215 class FingerprintMapper { | 222 class FingerprintMapper { |
| 223 DISALLOW_ALLOCATION(); |
216 public: | 224 public: |
217 void add(const LayoutObject*, Fingerprint); | 225 void add(const LayoutObject*, Fingerprint); |
218 void addTentativeClusterRoot(const LayoutBlock*, Fingerprint); | 226 void addTentativeClusterRoot(const LayoutBlock*, Fingerprint); |
219 // Returns true if any BlockSet was modified or freed by the removal. | 227 // Returns true if any BlockSet was modified or freed by the removal. |
220 bool remove(const LayoutObject*); | 228 bool remove(const LayoutObject*); |
221 Fingerprint get(const LayoutObject*); | 229 Fingerprint get(const LayoutObject*); |
222 BlockSet* getTentativeClusterRoots(Fingerprint); | 230 BlockSet* getTentativeClusterRoots(Fingerprint); |
223 bool hasFingerprints() const { return !m_fingerprints.isEmpty(); } | 231 bool hasFingerprints() const { return !m_fingerprints.isEmpty(); } |
224 private: | 232 private: |
225 typedef HashMap<const LayoutObject*, Fingerprint> FingerprintMap; | 233 typedef HashMap<const LayoutObject*, Fingerprint> FingerprintMap; |
226 typedef HashMap<Fingerprint, OwnPtr<BlockSet>> ReverseFingerprintMap; | 234 typedef HashMap<Fingerprint, OwnPtr<BlockSet>> ReverseFingerprintMap; |
227 | 235 |
228 FingerprintMap m_fingerprints; | 236 FingerprintMap m_fingerprints; |
229 ReverseFingerprintMap m_blocksForFingerprint; | 237 ReverseFingerprintMap m_blocksForFingerprint; |
230 #if ENABLE(ASSERT) | 238 #if ENABLE(ASSERT) |
231 void assertMapsAreConsistent(); | 239 void assertMapsAreConsistent(); |
232 #endif | 240 #endif |
233 }; | 241 }; |
234 | 242 |
235 struct PageInfo { | 243 struct PageInfo { |
| 244 DISALLOW_ALLOCATION(); |
236 PageInfo() | 245 PageInfo() |
237 : m_frameWidth(0) | 246 : m_frameWidth(0) |
238 , m_layoutWidth(0) | 247 , m_layoutWidth(0) |
239 , m_baseMultiplier(0) | 248 , m_baseMultiplier(0) |
240 , m_pageNeedsAutosizing(false) | 249 , m_pageNeedsAutosizing(false) |
241 , m_hasAutosized(false) | 250 , m_hasAutosized(false) |
242 , m_settingEnabled(false) | 251 , m_settingEnabled(false) |
243 { | 252 { |
244 } | 253 } |
245 | 254 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 FingerprintMapper m_fingerprintMapper; | 318 FingerprintMapper m_fingerprintMapper; |
310 Vector<RefPtr<ComputedStyle>> m_stylesRetainedDuringLayout; | 319 Vector<RefPtr<ComputedStyle>> m_stylesRetainedDuringLayout; |
311 // FIXME: All frames should share the same m_pageInfo instance. | 320 // FIXME: All frames should share the same m_pageInfo instance. |
312 PageInfo m_pageInfo; | 321 PageInfo m_pageInfo; |
313 bool m_updatePageInfoDeferred; | 322 bool m_updatePageInfoDeferred; |
314 }; | 323 }; |
315 | 324 |
316 } // namespace blink | 325 } // namespace blink |
317 | 326 |
318 #endif // TextAutosizer_h | 327 #endif // TextAutosizer_h |
OLD | NEW |