| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef TextAutosizer_h | 31 #ifndef TextAutosizer_h |
| 32 #define TextAutosizer_h | 32 #define TextAutosizer_h |
| 33 | 33 |
| 34 #include "core/layout/LayoutObject.h" |
| 34 #include "core/layout/LayoutTable.h" | 35 #include "core/layout/LayoutTable.h" |
| 35 #include "core/rendering/RenderObject.h" | |
| 36 #include "platform/heap/Handle.h" | 36 #include "platform/heap/Handle.h" |
| 37 #include "wtf/HashMap.h" | 37 #include "wtf/HashMap.h" |
| 38 #include "wtf/HashSet.h" | 38 #include "wtf/HashSet.h" |
| 39 #include "wtf/Noncopyable.h" | 39 #include "wtf/Noncopyable.h" |
| 40 #include "wtf/OwnPtr.h" | 40 #include "wtf/OwnPtr.h" |
| 41 #include "wtf/PassOwnPtr.h" | 41 #include "wtf/PassOwnPtr.h" |
| 42 | 42 |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 class Document; | 45 class Document; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 "sizeof(FingerprintSourceData) must be a multiple of UChar"); | 204 "sizeof(FingerprintSourceData) must be a multiple of UChar"); |
| 205 | 205 |
| 206 typedef unsigned Fingerprint; | 206 typedef unsigned Fingerprint; |
| 207 typedef HashMap<Fingerprint, OwnPtr<Supercluster> > SuperclusterMap; | 207 typedef HashMap<Fingerprint, OwnPtr<Supercluster> > SuperclusterMap; |
| 208 typedef Vector<OwnPtr<Cluster> > ClusterStack; | 208 typedef Vector<OwnPtr<Cluster> > ClusterStack; |
| 209 | 209 |
| 210 // Fingerprints are computed during style recalc, for (some subset of) | 210 // Fingerprints are computed during style recalc, for (some subset of) |
| 211 // blocks that will become cluster roots. | 211 // blocks that will become cluster roots. |
| 212 class FingerprintMapper { | 212 class FingerprintMapper { |
| 213 public: | 213 public: |
| 214 void add(const RenderObject*, Fingerprint); | 214 void add(const LayoutObject*, Fingerprint); |
| 215 void addTentativeClusterRoot(const RenderBlock*, Fingerprint); | 215 void addTentativeClusterRoot(const RenderBlock*, Fingerprint); |
| 216 // Returns true if any BlockSet was modified or freed by the removal. | 216 // Returns true if any BlockSet was modified or freed by the removal. |
| 217 bool remove(const RenderObject*); | 217 bool remove(const LayoutObject*); |
| 218 Fingerprint get(const RenderObject*); | 218 Fingerprint get(const LayoutObject*); |
| 219 BlockSet* getTentativeClusterRoots(Fingerprint); | 219 BlockSet* getTentativeClusterRoots(Fingerprint); |
| 220 bool hasFingerprints() const { return !m_fingerprints.isEmpty(); } | 220 bool hasFingerprints() const { return !m_fingerprints.isEmpty(); } |
| 221 private: | 221 private: |
| 222 typedef HashMap<const RenderObject*, Fingerprint> FingerprintMap; | 222 typedef HashMap<const LayoutObject*, Fingerprint> FingerprintMap; |
| 223 typedef HashMap<Fingerprint, OwnPtr<BlockSet> > ReverseFingerprintMap; | 223 typedef HashMap<Fingerprint, OwnPtr<BlockSet> > ReverseFingerprintMap; |
| 224 | 224 |
| 225 FingerprintMap m_fingerprints; | 225 FingerprintMap m_fingerprints; |
| 226 ReverseFingerprintMap m_blocksForFingerprint; | 226 ReverseFingerprintMap m_blocksForFingerprint; |
| 227 #if ENABLE(ASSERT) | 227 #if ENABLE(ASSERT) |
| 228 void assertMapsAreConsistent(); | 228 void assertMapsAreConsistent(); |
| 229 #endif | 229 #endif |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 struct PageInfo { | 232 struct PageInfo { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 246 bool m_pageNeedsAutosizing; | 246 bool m_pageNeedsAutosizing; |
| 247 bool m_hasAutosized; | 247 bool m_hasAutosized; |
| 248 bool m_settingEnabled; | 248 bool m_settingEnabled; |
| 249 }; | 249 }; |
| 250 | 250 |
| 251 explicit TextAutosizer(const Document*); | 251 explicit TextAutosizer(const Document*); |
| 252 | 252 |
| 253 void beginLayout(RenderBlock*); | 253 void beginLayout(RenderBlock*); |
| 254 void endLayout(RenderBlock*); | 254 void endLayout(RenderBlock*); |
| 255 void inflateAutoTable(LayoutTable*); | 255 void inflateAutoTable(LayoutTable*); |
| 256 float inflate(RenderObject*, InflateBehavior = ThisBlockOnly, float multipli
er = 0); | 256 float inflate(LayoutObject*, InflateBehavior = ThisBlockOnly, float multipli
er = 0); |
| 257 bool shouldHandleLayout() const; | 257 bool shouldHandleLayout() const; |
| 258 IntSize windowSize() const; | 258 IntSize windowSize() const; |
| 259 void setAllTextNeedsLayout(); | 259 void setAllTextNeedsLayout(); |
| 260 void resetMultipliers(); | 260 void resetMultipliers(); |
| 261 BeginLayoutBehavior prepareForLayout(const RenderBlock*); | 261 BeginLayoutBehavior prepareForLayout(const RenderBlock*); |
| 262 void prepareClusterStack(const RenderObject*); | 262 void prepareClusterStack(const LayoutObject*); |
| 263 bool clusterHasEnoughTextToAutosize(Cluster*, const RenderBlock* widthProvid
er = 0); | 263 bool clusterHasEnoughTextToAutosize(Cluster*, const RenderBlock* widthProvid
er = 0); |
| 264 bool superclusterHasEnoughTextToAutosize(Supercluster*, const RenderBlock* w
idthProvider = 0); | 264 bool superclusterHasEnoughTextToAutosize(Supercluster*, const RenderBlock* w
idthProvider = 0); |
| 265 bool clusterWouldHaveEnoughTextToAutosize(const RenderBlock* root, const Ren
derBlock* widthProvider = 0); | 265 bool clusterWouldHaveEnoughTextToAutosize(const RenderBlock* root, const Ren
derBlock* widthProvider = 0); |
| 266 Fingerprint getFingerprint(const RenderObject*); | 266 Fingerprint getFingerprint(const LayoutObject*); |
| 267 Fingerprint computeFingerprint(const RenderObject*); | 267 Fingerprint computeFingerprint(const LayoutObject*); |
| 268 Cluster* maybeCreateCluster(const RenderBlock*); | 268 Cluster* maybeCreateCluster(const RenderBlock*); |
| 269 Supercluster* getSupercluster(const RenderBlock*); | 269 Supercluster* getSupercluster(const RenderBlock*); |
| 270 float clusterMultiplier(Cluster*); | 270 float clusterMultiplier(Cluster*); |
| 271 float superclusterMultiplier(Cluster*); | 271 float superclusterMultiplier(Cluster*); |
| 272 // A cluster's width provider is typically the deepest block containing all
text. | 272 // A cluster's width provider is typically the deepest block containing all
text. |
| 273 // There are exceptions, such as tables and table cells which use the table
itself for width. | 273 // There are exceptions, such as tables and table cells which use the table
itself for width. |
| 274 const RenderBlock* clusterWidthProvider(const RenderBlock*) const; | 274 const RenderBlock* clusterWidthProvider(const RenderBlock*) const; |
| 275 const RenderBlock* maxClusterWidthProvider(const Supercluster*, const Render
Block* currentRoot) const; | 275 const RenderBlock* maxClusterWidthProvider(const Supercluster*, const Render
Block* currentRoot) const; |
| 276 // Typically this returns a block's computed width. In the case of tables la
yout, this | 276 // Typically this returns a block's computed width. In the case of tables la
yout, this |
| 277 // width is not yet known so the fixed width is used if it's available, or t
he containing | 277 // width is not yet known so the fixed width is used if it's available, or t
he containing |
| 278 // block's width otherwise. | 278 // block's width otherwise. |
| 279 float widthFromBlock(const RenderBlock*) const; | 279 float widthFromBlock(const RenderBlock*) const; |
| 280 float multiplierFromBlock(const RenderBlock*); | 280 float multiplierFromBlock(const RenderBlock*); |
| 281 void applyMultiplier(RenderObject*, float, RelayoutBehavior = AlreadyInLayou
t); | 281 void applyMultiplier(LayoutObject*, float, RelayoutBehavior = AlreadyInLayou
t); |
| 282 bool isWiderOrNarrowerDescendant(Cluster*); | 282 bool isWiderOrNarrowerDescendant(Cluster*); |
| 283 Cluster* currentCluster() const; | 283 Cluster* currentCluster() const; |
| 284 const RenderBlock* deepestBlockContainingAllText(Cluster*); | 284 const RenderBlock* deepestBlockContainingAllText(Cluster*); |
| 285 const RenderBlock* deepestBlockContainingAllText(const RenderBlock*) const; | 285 const RenderBlock* deepestBlockContainingAllText(const RenderBlock*) const; |
| 286 // Returns the first text leaf that is in the current cluster. We attempt to
not include text | 286 // Returns the first text leaf that is in the current cluster. We attempt to
not include text |
| 287 // from descendant clusters but because descendant clusters may not exist, t
his is only an approximation. | 287 // from descendant clusters but because descendant clusters may not exist, t
his is only an approximation. |
| 288 // The TraversalDirection controls whether we return the first or the last t
ext leaf. | 288 // The TraversalDirection controls whether we return the first or the last t
ext leaf. |
| 289 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc
h) const; | 289 const LayoutObject* findTextLeaf(const LayoutObject*, size_t&, TextLeafSearc
h) const; |
| 290 BlockFlags classifyBlock(const RenderObject*, BlockFlags mask = UINT_MAX) co
nst; | 290 BlockFlags classifyBlock(const LayoutObject*, BlockFlags mask = UINT_MAX) co
nst; |
| 291 #ifdef AUTOSIZING_DOM_DEBUG_INFO | 291 #ifdef AUTOSIZING_DOM_DEBUG_INFO |
| 292 void writeClusterDebugInfo(Cluster*); | 292 void writeClusterDebugInfo(Cluster*); |
| 293 #endif | 293 #endif |
| 294 | 294 |
| 295 RawPtrWillBeMember<const Document> m_document; | 295 RawPtrWillBeMember<const Document> m_document; |
| 296 const RenderBlock* m_firstBlockToBeginLayout; | 296 const RenderBlock* m_firstBlockToBeginLayout; |
| 297 #if ENABLE(ASSERT) | 297 #if ENABLE(ASSERT) |
| 298 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro
perties of a block before beginLayout() is called on it. | 298 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro
perties of a block before beginLayout() is called on it. |
| 299 #endif | 299 #endif |
| 300 | 300 |
| 301 // Clusters are created and destroyed during layout. The map key is the | 301 // Clusters are created and destroyed during layout. The map key is the |
| 302 // cluster root. Clusters whose roots share the same fingerprint use the | 302 // cluster root. Clusters whose roots share the same fingerprint use the |
| 303 // same multiplier. | 303 // same multiplier. |
| 304 SuperclusterMap m_superclusters; | 304 SuperclusterMap m_superclusters; |
| 305 ClusterStack m_clusterStack; | 305 ClusterStack m_clusterStack; |
| 306 FingerprintMapper m_fingerprintMapper; | 306 FingerprintMapper m_fingerprintMapper; |
| 307 Vector<RefPtr<RenderStyle> > m_stylesRetainedDuringLayout; | 307 Vector<RefPtr<RenderStyle> > m_stylesRetainedDuringLayout; |
| 308 // FIXME: All frames should share the same m_pageInfo instance. | 308 // FIXME: All frames should share the same m_pageInfo instance. |
| 309 PageInfo m_pageInfo; | 309 PageInfo m_pageInfo; |
| 310 bool m_updatePageInfoDeferred; | 310 bool m_updatePageInfoDeferred; |
| 311 }; | 311 }; |
| 312 | 312 |
| 313 } // namespace blink | 313 } // namespace blink |
| 314 | 314 |
| 315 #endif // TextAutosizer_h | 315 #endif // TextAutosizer_h |
| OLD | NEW |