Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: Source/core/rendering/FastTextAutosizer.h

Issue 145123010: Fix supercluster logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address review comment. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 { 84 {
85 if (m_textAutosizer) 85 if (m_textAutosizer)
86 m_textAutosizer->endLayout(m_block); 86 m_textAutosizer->endLayout(m_block);
87 } 87 }
88 private: 88 private:
89 FastTextAutosizer* m_textAutosizer; 89 FastTextAutosizer* m_textAutosizer;
90 RenderBlock* m_block; 90 RenderBlock* m_block;
91 }; 91 };
92 92
93 private: 93 private:
94 typedef HashSet<const RenderBlock*> BlockSet;
95
96 // A supercluster represents autosizing information about a set of two or
97 // more blocks that all have the same fingerprint. Clusters whose roots
98 // belong to a supercluster will share a common multiplier and
99 // text-length-based autosizing status.
100 struct Supercluster {
101 explicit Supercluster(const BlockSet* roots)
102 : m_roots(roots)
103 , m_multiplier(0)
104 , m_anyClusterHasEnoughText(false)
105 {
106 }
107
108 const BlockSet* const m_roots;
109 float m_multiplier;
110 bool m_anyClusterHasEnoughText;
111 };
112
94 struct Cluster { 113 struct Cluster {
95 explicit Cluster(const RenderBlock* root, bool autosize, Cluster* parent ) 114 explicit Cluster(const RenderBlock* root, bool autosize, Cluster* parent , Supercluster* supercluster = 0)
96 : m_root(root) 115 : m_root(root)
97 , m_deepestBlockContainingAllText(0) 116 , m_deepestBlockContainingAllText(0)
98 , m_parent(parent) 117 , m_parent(parent)
99 , m_autosize(autosize) 118 , m_autosize(autosize)
100 , m_multiplier(0) 119 , m_multiplier(0)
101 , m_textLength(-1) 120 , m_textLength(-1)
121 , m_supercluster(supercluster)
102 { 122 {
103 } 123 }
104 124
105 const RenderBlock* m_root; 125 const RenderBlock* const m_root;
106 // The deepest block containing all text is computed lazily (see: 126 // The deepest block containing all text is computed lazily (see:
107 // deepestBlockContainingAllText). A value of 0 indicates the value has not been computed yet. 127 // deepestBlockContainingAllText). A value of 0 indicates the value has not been computed yet.
108 const RenderBlock* m_deepestBlockContainingAllText; 128 const RenderBlock* m_deepestBlockContainingAllText;
109 Cluster* m_parent; 129 Cluster* m_parent;
110 bool m_autosize; 130 bool m_autosize;
111 // The multiplier is computed lazily (see: clusterMultiplier) because it must be calculated 131 // The multiplier is computed lazily (see: clusterMultiplier) because it must be calculated
112 // after the lowest block containing all text has entered layout (the 132 // after the lowest block containing all text has entered layout (the
113 // m_blocksThatHaveBegunLayout assertions cover this). Note: the multipl ier is still 133 // m_blocksThatHaveBegunLayout assertions cover this). Note: the multipl ier is still
114 // calculated when m_autosize is false because child clusters may depend on this multiplier. 134 // calculated when m_autosize is false because child clusters may depend on this multiplier.
115 float m_multiplier; 135 float m_multiplier;
116 // Text length is computed lazily (see: textLength). This is an approxim ation and characters 136 // Text length is computed lazily (see: textLength). This is an approxim ation and characters
117 // are assumed to be 1em wide. Negative values indicate the length has n ot been computed. 137 // are assumed to be 1em wide. Negative values indicate the length has n ot been computed.
118 int m_textLength; 138 int m_textLength;
139 // A set of blocks that are similar to this block.
140 Supercluster* m_supercluster;
119 }; 141 };
120 142
121 enum TextLeafSearch { 143 enum TextLeafSearch {
122 First, 144 First,
123 Last 145 Last
124 }; 146 };
125 147
126 typedef HashSet<const RenderBlock*> BlockSet; 148 typedef HashMap<AtomicString, OwnPtr<Supercluster> > SuperclusterMap;
127 typedef HashMap<const RenderBlock*, OwnPtr<Cluster> > ClusterMap; 149 typedef Vector<OwnPtr<Cluster> > ClusterStack;
128 typedef Vector<Cluster*> ClusterStack;
129 150
130 // Fingerprints are computed during style recalc, for (some subset of) 151 // Fingerprints are computed during style recalc, for (some subset of)
131 // blocks that will become cluster roots. 152 // blocks that will become cluster roots.
132 class FingerprintMapper { 153 class FingerprintMapper {
133 public: 154 public:
134 void add(const RenderBlock*, AtomicString); 155 void add(const RenderBlock*, AtomicString);
135 void remove(const RenderBlock*); 156 void remove(const RenderBlock*);
136 AtomicString get(const RenderBlock*); 157 AtomicString get(const RenderBlock*);
137 BlockSet& getBlocks(AtomicString); 158 BlockSet& getBlocks(AtomicString);
138 private: 159 private:
139 typedef HashMap<const RenderBlock*, AtomicString> FingerprintMap; 160 typedef HashMap<const RenderBlock*, AtomicString> FingerprintMap;
140 typedef HashMap<AtomicString, OwnPtr<BlockSet> > ReverseFingerprintMap; 161 typedef HashMap<AtomicString, OwnPtr<BlockSet> > ReverseFingerprintMap;
141 162
142 FingerprintMap m_fingerprints; 163 FingerprintMap m_fingerprints;
143 ReverseFingerprintMap m_blocksForFingerprint; 164 ReverseFingerprintMap m_blocksForFingerprint;
144 }; 165 };
145 166
146 explicit FastTextAutosizer(const Document*); 167 explicit FastTextAutosizer(const Document*);
147 168
148 void beginLayout(RenderBlock*); 169 void beginLayout(RenderBlock*);
149 void endLayout(RenderBlock*); 170 void endLayout(RenderBlock*);
150 void inflate(RenderBlock*); 171 void inflate(RenderBlock*);
151 bool enabled(); 172 bool enabled();
152 void prepareRenderViewInfo(RenderView*); 173 void prepareRenderViewInfo(RenderView*);
153 bool isFingerprintingCandidate(const RenderBlock*); 174 bool isFingerprintingCandidate(const RenderBlock*);
154 bool clusterHasEnoughTextToAutosize(Cluster*); 175 bool clusterHasEnoughTextToAutosize(Cluster*);
176 bool clusterWouldHaveEnoughTextToAutosize(const RenderBlock*);
155 float textLength(Cluster*); 177 float textLength(Cluster*);
156 AtomicString computeFingerprint(const RenderBlock*); 178 AtomicString computeFingerprint(const RenderBlock*);
157 Cluster* maybeGetOrCreateCluster(const RenderBlock*); 179 Cluster* maybeCreateCluster(const RenderBlock*);
158 Cluster* addSupercluster(AtomicString, const RenderBlock*); 180 Supercluster* getSupercluster(const RenderBlock*);
159 const RenderBlock* deepestCommonAncestor(BlockSet&); 181 const RenderBlock* deepestCommonAncestor(BlockSet&);
160 float clusterMultiplier(Cluster*); 182 float clusterMultiplier(Cluster*);
183 float superclusterMultiplier(Supercluster*);
184 float multiplierFromBlock(const RenderBlock*);
161 void applyMultiplier(RenderObject*, float); 185 void applyMultiplier(RenderObject*, float);
162 bool mightBeWiderOrNarrowerDescendant(const RenderBlock*); 186 bool mightBeWiderOrNarrowerDescendant(const RenderBlock*);
163 bool isWiderDescendant(Cluster*); 187 bool isWiderDescendant(Cluster*);
164 bool isNarrowerDescendant(Cluster*); 188 bool isNarrowerDescendant(Cluster*);
165 189
166 Cluster* currentCluster() const; 190 Cluster* currentCluster() const;
167 191
168 RenderObject* nextChildSkippingChildrenOfBlocks(const RenderObject*, const R enderObject*); 192 RenderObject* nextChildSkippingChildrenOfBlocks(const RenderObject*, const R enderObject*);
169 193
170 const RenderBlock* deepestBlockContainingAllText(Cluster*); 194 const RenderBlock* deepestBlockContainingAllText(Cluster*);
195 const RenderBlock* deepestBlockContainingAllText(const RenderBlock*);
171 // Returns the first text leaf that is in the current cluster. We attempt to not include text 196 // Returns the first text leaf that is in the current cluster. We attempt to not include text
172 // from descendant clusters but because descendant clusters may not exist, t his is only an approximation. 197 // from descendant clusters but because descendant clusters may not exist, t his is only an approximation.
173 // The TraversalDirection controls whether we return the first or the last t ext leaf. 198 // The TraversalDirection controls whether we return the first or the last t ext leaf.
174 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc h); 199 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc h);
175 200
176 const Document* m_document; 201 const Document* m_document;
177 int m_frameWidth; // Frame width in density-independent pixels (DIPs). 202 int m_frameWidth; // Frame width in density-independent pixels (DIPs).
178 int m_layoutWidth; // Layout width in CSS pixels. 203 int m_layoutWidth; // Layout width in CSS pixels.
179 float m_baseMultiplier; // Includes accessibility font scale factor and devi ce scale adjustment. 204 float m_baseMultiplier; // Includes accessibility font scale factor and devi ce scale adjustment.
180 #ifndef NDEBUG 205 #ifndef NDEBUG
181 bool m_renderViewInfoPrepared; 206 bool m_renderViewInfoPrepared;
182 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro perties of a block before beginLayout() is called on it. 207 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro perties of a block before beginLayout() is called on it.
183 #endif 208 #endif
184 209
185 // Clusters are created and destroyed during layout. The map key is the 210 // Clusters are created and destroyed during layout. The map key is the
186 // cluster root. Clusters whose roots share the same fingerprint use the 211 // cluster root. Clusters whose roots share the same fingerprint use the
187 // same multiplier. 212 // same multiplier.
188 ClusterMap m_clusters; 213 SuperclusterMap m_superclusters;
189 ClusterStack m_clusterStack; 214 ClusterStack m_clusterStack;
190 FingerprintMapper m_fingerprintMapper; 215 FingerprintMapper m_fingerprintMapper;
191 }; 216 };
192 217
193 } // namespace WebCore 218 } // namespace WebCore
194 219
195 #endif // FastTextAutosizer_h 220 #endif // FastTextAutosizer_h
OLDNEW
« no previous file with comments | « LayoutTests/fast/text-autosizing/textarea-fontsize-change-expected.html ('k') | Source/core/rendering/FastTextAutosizer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698