Chromium Code Reviews| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 | 63 |
| 64 void record(const RenderBlock*); | 64 void record(const RenderBlock*); |
| 65 void destroy(const RenderBlock*); | 65 void destroy(const RenderBlock*); |
| 66 | 66 |
| 67 void beginLayout(RenderBlock*); | 67 void beginLayout(RenderBlock*); |
| 68 void endLayout(RenderBlock*); | 68 void endLayout(RenderBlock*); |
| 69 | 69 |
| 70 void inflateListItem(RenderListItem*, RenderListMarker*); | 70 void inflateListItem(RenderListItem*, RenderListMarker*); |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 typedef HashSet<const RenderBlock*> BlockSet; | |
| 74 | |
| 75 struct Supercluster { | |
|
pdr.
2014/02/06 22:03:27
Can you add a comment here describing what supercl
skobes
2014/02/06 23:55:50
Done.
| |
| 76 explicit Supercluster(const BlockSet* roots) | |
| 77 : m_roots(roots) | |
| 78 , m_multiplier(0) | |
| 79 , m_anyClusterHasEnoughText(false) | |
| 80 { | |
| 81 } | |
| 82 | |
| 83 const BlockSet* const m_roots; | |
| 84 float m_multiplier; | |
| 85 bool m_anyClusterHasEnoughText; | |
| 86 }; | |
| 87 | |
| 73 struct Cluster { | 88 struct Cluster { |
| 74 explicit Cluster(const RenderBlock* root, bool autosize, Cluster* parent ) | 89 explicit Cluster(const RenderBlock* root, bool autosize, Cluster* parent , Supercluster* supercluster = 0) |
| 75 : m_root(root) | 90 : m_root(root) |
| 76 , m_deepestBlockContainingAllText(0) | 91 , m_deepestBlockContainingAllText(0) |
| 77 , m_parent(parent) | 92 , m_parent(parent) |
| 78 , m_autosize(autosize) | 93 , m_autosize(autosize) |
| 79 , m_multiplier(0) | 94 , m_multiplier(0) |
| 80 , m_textLength(-1) | 95 , m_textLength(-1) |
| 96 , m_supercluster(supercluster) | |
| 81 { | 97 { |
| 82 } | 98 } |
| 83 | 99 |
| 84 const RenderBlock* m_root; | 100 const RenderBlock* const m_root; |
| 85 // The deepest block containing all text is computed lazily (see: | 101 // The deepest block containing all text is computed lazily (see: |
| 86 // deepestBlockContainingAllText). A value of 0 indicates the value has not been computed yet. | 102 // deepestBlockContainingAllText). A value of 0 indicates the value has not been computed yet. |
| 87 const RenderBlock* m_deepestBlockContainingAllText; | 103 const RenderBlock* m_deepestBlockContainingAllText; |
| 88 Cluster* m_parent; | 104 Cluster* m_parent; |
| 89 bool m_autosize; | 105 bool m_autosize; |
| 90 // The multiplier is computed lazily (see: clusterMultiplier) because it must be calculated | 106 // The multiplier is computed lazily (see: clusterMultiplier) because it must be calculated |
| 91 // after the lowest block containing all text has entered layout (the | 107 // after the lowest block containing all text has entered layout (the |
| 92 // m_blocksThatHaveBegunLayout assertions cover this). Note: the multipl ier is still | 108 // m_blocksThatHaveBegunLayout assertions cover this). Note: the multipl ier is still |
| 93 // calculated when m_autosize is false because child clusters may depend on this multiplier. | 109 // calculated when m_autosize is false because child clusters may depend on this multiplier. |
| 94 float m_multiplier; | 110 float m_multiplier; |
| 95 // Text length is computed lazily (see: textLength). This is an approxim ation and characters | 111 // Text length is computed lazily (see: textLength). This is an approxim ation and characters |
| 96 // are assumed to be 1em wide. Negative values indicate the length has n ot been computed. | 112 // are assumed to be 1em wide. Negative values indicate the length has n ot been computed. |
| 97 int m_textLength; | 113 int m_textLength; |
| 114 // A set of blocks that are similar to this block. | |
| 115 Supercluster* m_supercluster; | |
| 98 }; | 116 }; |
| 99 | 117 |
| 100 enum TextLeafSearch { | 118 enum TextLeafSearch { |
| 101 First, | 119 First, |
| 102 Last | 120 Last |
| 103 }; | 121 }; |
| 104 | 122 |
| 105 typedef HashSet<const RenderBlock*> BlockSet; | 123 typedef HashMap<AtomicString, OwnPtr<Supercluster> > SuperclusterMap; |
| 106 typedef HashMap<const RenderBlock*, OwnPtr<Cluster> > ClusterMap; | 124 typedef Vector<OwnPtr<Cluster> > ClusterStack; |
| 107 typedef Vector<Cluster*> ClusterStack; | |
| 108 | 125 |
| 109 // Fingerprints are computed during style recalc, for (some subset of) | 126 // Fingerprints are computed during style recalc, for (some subset of) |
| 110 // blocks that will become cluster roots. | 127 // blocks that will become cluster roots. |
| 111 class FingerprintMapper { | 128 class FingerprintMapper { |
| 112 public: | 129 public: |
| 113 void add(const RenderBlock*, AtomicString); | 130 void add(const RenderBlock*, AtomicString); |
| 114 void remove(const RenderBlock*); | 131 void remove(const RenderBlock*); |
| 115 AtomicString get(const RenderBlock*); | 132 AtomicString get(const RenderBlock*); |
| 116 BlockSet& getBlocks(AtomicString); | 133 BlockSet& getBlocks(AtomicString); |
| 117 private: | 134 private: |
| 118 typedef HashMap<const RenderBlock*, AtomicString> FingerprintMap; | 135 typedef HashMap<const RenderBlock*, AtomicString> FingerprintMap; |
| 119 typedef HashMap<AtomicString, OwnPtr<BlockSet> > ReverseFingerprintMap; | 136 typedef HashMap<AtomicString, OwnPtr<BlockSet> > ReverseFingerprintMap; |
| 120 | 137 |
| 121 FingerprintMap m_fingerprints; | 138 FingerprintMap m_fingerprints; |
| 122 ReverseFingerprintMap m_blocksForFingerprint; | 139 ReverseFingerprintMap m_blocksForFingerprint; |
| 123 }; | 140 }; |
| 124 | 141 |
| 125 explicit FastTextAutosizer(const Document*); | 142 explicit FastTextAutosizer(const Document*); |
| 126 | 143 |
| 127 void inflate(RenderBlock*); | 144 void inflate(RenderBlock*); |
| 128 bool enabled(); | 145 bool enabled(); |
| 129 void prepareRenderViewInfo(RenderView*); | 146 void prepareRenderViewInfo(RenderView*); |
| 130 bool isFingerprintingCandidate(const RenderBlock*); | 147 bool isFingerprintingCandidate(const RenderBlock*); |
| 131 bool clusterHasEnoughTextToAutosize(Cluster*); | 148 bool clusterHasEnoughTextToAutosize(Cluster*); |
| 132 float textLength(Cluster*); | 149 float textLength(Cluster*); |
| 133 AtomicString computeFingerprint(const RenderBlock*); | 150 AtomicString computeFingerprint(const RenderBlock*); |
| 134 Cluster* maybeGetOrCreateCluster(const RenderBlock*); | 151 Cluster* maybeCreateCluster(const RenderBlock*); |
| 135 Cluster* addSupercluster(AtomicString, const RenderBlock*); | 152 Supercluster* getSupercluster(const RenderBlock*); |
| 136 const RenderBlock* deepestCommonAncestor(BlockSet&); | 153 const RenderBlock* deepestCommonAncestor(BlockSet&); |
| 137 float clusterMultiplier(Cluster*); | 154 float clusterMultiplier(Cluster*); |
| 155 float superclusterMultiplier(Supercluster*); | |
| 156 float multiplierFromBlock(const RenderBlock*); | |
| 138 void applyMultiplier(RenderObject*, float); | 157 void applyMultiplier(RenderObject*, float); |
| 139 bool mightBeWiderOrNarrowerDescendant(const RenderBlock*); | 158 bool mightBeWiderOrNarrowerDescendant(const RenderBlock*); |
| 140 bool isWiderDescendant(Cluster*); | 159 bool isWiderDescendant(Cluster*); |
| 141 bool isNarrowerDescendant(Cluster*); | 160 bool isNarrowerDescendant(Cluster*); |
| 142 | 161 |
| 143 Cluster* currentCluster() const; | 162 Cluster* currentCluster() const; |
| 144 | 163 |
| 145 RenderObject* nextChildSkippingChildrenOfBlocks(const RenderObject*, const R enderObject*); | 164 RenderObject* nextChildSkippingChildrenOfBlocks(const RenderObject*, const R enderObject*); |
| 146 | 165 |
| 147 const RenderBlock* deepestBlockContainingAllText(Cluster*); | 166 const RenderBlock* deepestBlockContainingAllText(Cluster*); |
| 148 // Returns the first text leaf that is in the current cluster. We attempt to not include text | 167 // Returns the first text leaf that is in the current cluster. We attempt to not include text |
| 149 // from descendant clusters but because descendant clusters may not exist, t his is only an approximation. | 168 // from descendant clusters but because descendant clusters may not exist, t his is only an approximation. |
| 150 // The TraversalDirection controls whether we return the first or the last t ext leaf. | 169 // The TraversalDirection controls whether we return the first or the last t ext leaf. |
| 151 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc h); | 170 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc h); |
| 152 | 171 |
| 153 const Document* m_document; | 172 const Document* m_document; |
| 154 int m_frameWidth; // Frame width in density-independent pixels (DIPs). | 173 int m_frameWidth; // Frame width in density-independent pixels (DIPs). |
| 155 int m_layoutWidth; // Layout width in CSS pixels. | 174 int m_layoutWidth; // Layout width in CSS pixels. |
| 156 float m_baseMultiplier; // Includes accessibility font scale factor and devi ce scale adjustment. | 175 float m_baseMultiplier; // Includes accessibility font scale factor and devi ce scale adjustment. |
| 157 #ifndef NDEBUG | 176 #ifndef NDEBUG |
| 158 bool m_renderViewInfoPrepared; | 177 bool m_renderViewInfoPrepared; |
| 159 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro perties of a block before beginLayout() is called on it. | 178 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro perties of a block before beginLayout() is called on it. |
| 160 #endif | 179 #endif |
| 161 | 180 |
| 162 // Clusters are created and destroyed during layout. The map key is the | 181 // Clusters are created and destroyed during layout. The map key is the |
| 163 // cluster root. Clusters whose roots share the same fingerprint use the | 182 // cluster root. Clusters whose roots share the same fingerprint use the |
| 164 // same multiplier. | 183 // same multiplier. |
| 165 ClusterMap m_clusters; | 184 SuperclusterMap m_superclusters; |
| 166 ClusterStack m_clusterStack; | 185 ClusterStack m_clusterStack; |
| 167 FingerprintMapper m_fingerprintMapper; | 186 FingerprintMapper m_fingerprintMapper; |
| 168 }; | 187 }; |
| 169 | 188 |
| 170 } // namespace WebCore | 189 } // namespace WebCore |
| 171 | 190 |
| 172 #endif // FastTextAutosizer_h | 191 #endif // FastTextAutosizer_h |
| OLD | NEW |