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

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

Issue 180743004: Disable FTA when max multiplier is 1. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 {
pdr. 2014/03/01 05:16:43 This can end up being a bit verbose. Typically I s
skobes 2014/03/04 00:00:25 Done.
98 Unknown, 81 HasEnoughTextToAutosize_Unknown,
99 Yes, 82 HasEnoughTextToAutosize_Yes,
100 No 83 HasEnoughTextToAutosize_No
84 };
85
86 enum PageNeedsAutosizing {
87 PageNeedsAutosizing_Unknown,
pdr. 2014/03/01 05:16:43 Ditto here
skobes 2014/03/04 00:00:25 Done.
88 PageNeedsAutosizing_Yes,
89 PageNeedsAutosizing_No
101 }; 90 };
102 91
103 // A supercluster represents autosizing information about a set of two or 92 // A supercluster represents autosizing information about a set of two or
104 // more blocks that all have the same fingerprint. Clusters whose roots 93 // more blocks that all have the same fingerprint. Clusters whose roots
105 // belong to a supercluster will share a common multiplier and 94 // belong to a supercluster will share a common multiplier and
106 // text-length-based autosizing status. 95 // text-length-based autosizing status.
107 struct Supercluster { 96 struct Supercluster {
108 explicit Supercluster(const BlockSet* roots) 97 explicit Supercluster(const BlockSet* roots)
109 : m_roots(roots) 98 : m_roots(roots)
110 , m_multiplier(0) 99 , m_multiplier(0)
111 { 100 {
112 } 101 }
113 102
114 const BlockSet* const m_roots; 103 const BlockSet* const m_roots;
115 float m_multiplier; 104 float m_multiplier;
116 }; 105 };
117 106
118 struct Cluster { 107 struct Cluster {
119 explicit Cluster(const RenderBlock* root, bool autosize, Cluster* parent , Supercluster* supercluster = 0) 108 explicit Cluster(const RenderBlock* root, bool autosize, Cluster* parent , Supercluster* supercluster = 0)
120 : m_root(root) 109 : m_root(root)
121 , m_deepestBlockContainingAllText(0) 110 , m_deepestBlockContainingAllText(0)
122 , m_parent(parent) 111 , m_parent(parent)
123 , m_autosize(autosize) 112 , m_autosize(autosize)
124 , m_multiplier(0) 113 , m_multiplier(0)
125 , m_hasEnoughTextToAutosize(Unknown) 114 , m_hasEnoughTextToAutosize(HasEnoughTextToAutosize_Unknown)
126 , m_supercluster(supercluster) 115 , m_supercluster(supercluster)
127 , m_hasTableAncestor(root->isTableCell() || (m_parent && m_parent->m _hasTableAncestor)) 116 , m_hasTableAncestor(root->isTableCell() || (m_parent && m_parent->m _hasTableAncestor))
128 { 117 {
129 } 118 }
130 119
131 const RenderBlock* const m_root; 120 const RenderBlock* const m_root;
132 // The deepest block containing all text is computed lazily (see: 121 // The deepest block containing all text is computed lazily (see:
133 // deepestBlockContainingAllText). A value of 0 indicates the value has not been computed yet. 122 // deepestBlockContainingAllText). A value of 0 indicates the value has not been computed yet.
134 const RenderBlock* m_deepestBlockContainingAllText; 123 const RenderBlock* m_deepestBlockContainingAllText;
135 Cluster* m_parent; 124 Cluster* m_parent;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 ReverseFingerprintMap m_blocksForFingerprint; 179 ReverseFingerprintMap m_blocksForFingerprint;
191 }; 180 };
192 181
193 explicit FastTextAutosizer(const Document*); 182 explicit FastTextAutosizer(const Document*);
194 183
195 void beginLayout(RenderBlock*); 184 void beginLayout(RenderBlock*);
196 void endLayout(RenderBlock*); 185 void endLayout(RenderBlock*);
197 void inflateTable(RenderTable*); 186 void inflateTable(RenderTable*);
198 void inflate(RenderBlock*); 187 void inflate(RenderBlock*);
199 bool enabled(); 188 bool enabled();
200 void prepareRenderViewInfo(); 189 void updateRenderViewInfo();
201 void prepareClusterStack(const RenderObject*); 190 void prepareClusterStack(const RenderObject*);
202 bool isFingerprintingCandidate(const RenderBlock*); 191 bool isFingerprintingCandidate(const RenderBlock*);
203 bool clusterHasEnoughTextToAutosize(Cluster*, const RenderBlock* widthProvid er = 0); 192 bool clusterHasEnoughTextToAutosize(Cluster*, const RenderBlock* widthProvid er = 0);
204 bool clusterWouldHaveEnoughTextToAutosize(const RenderBlock* root, const Ren derBlock* widthProvider = 0); 193 bool clusterWouldHaveEnoughTextToAutosize(const RenderBlock* root, const Ren derBlock* widthProvider = 0);
205 Fingerprint getFingerprint(const RenderObject*); 194 Fingerprint getFingerprint(const RenderObject*);
206 Fingerprint computeFingerprint(const RenderObject*); 195 Fingerprint computeFingerprint(const RenderObject*);
207 Cluster* maybeCreateCluster(const RenderBlock*); 196 Cluster* maybeCreateCluster(const RenderBlock*);
208 Supercluster* getSupercluster(const RenderBlock*); 197 Supercluster* getSupercluster(const RenderBlock*);
209 const RenderBlock* deepestCommonAncestor(BlockSet&); 198 const RenderBlock* deepestCommonAncestor(BlockSet&);
210 float clusterMultiplier(Cluster*); 199 float clusterMultiplier(Cluster*);
211 float superclusterMultiplier(Supercluster*); 200 float superclusterMultiplier(Supercluster*);
212 // A cluster's width provider is typically the deepest block containing all text. 201 // 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. 202 // There are exceptions, such as tables and table cells which use the table itself for width.
214 const RenderBlock* clusterWidthProvider(const RenderBlock*); 203 const RenderBlock* clusterWidthProvider(const RenderBlock*);
215 // Typically this returns a block's computed width. In the case of tables la yout, this 204 // 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 205 // width is not yet known so the fixed width is used if it's available, or t he containing
217 // block's width otherwise. 206 // block's width otherwise.
218 float widthFromBlock(const RenderBlock*); 207 float widthFromBlock(const RenderBlock*);
219 float multiplierFromBlock(const RenderBlock*); 208 float multiplierFromBlock(const RenderBlock*);
220 void applyMultiplier(RenderObject*, float); 209 void applyMultiplier(RenderObject*, float);
221 bool mightBeWiderOrNarrowerDescendant(const RenderBlock*); 210 bool mightBeWiderOrNarrowerDescendant(const RenderBlock*);
222 bool isWiderOrNarrowerDescendant(Cluster*); 211 bool isWiderOrNarrowerDescendant(Cluster*);
223 bool isLayoutRoot(const RenderBlock*) const; 212 bool isLayoutRoot(const RenderBlock*) const;
213 bool isInLayout() const;
224 214
225 Cluster* currentCluster() const; 215 Cluster* currentCluster() const;
226 216
227 RenderObject* nextChildSkippingChildrenOfBlocks(const RenderObject*, const R enderObject*); 217 RenderObject* nextChildSkippingChildrenOfBlocks(const RenderObject*, const R enderObject*);
228 218
229 const RenderBlock* deepestBlockContainingAllText(Cluster*); 219 const RenderBlock* deepestBlockContainingAllText(Cluster*);
230 const RenderBlock* deepestBlockContainingAllText(const RenderBlock*); 220 const RenderBlock* deepestBlockContainingAllText(const RenderBlock*);
231 // Returns the first text leaf that is in the current cluster. We attempt to not include text 221 // 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. 222 // 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. 223 // The TraversalDirection controls whether we return the first or the last t ext leaf.
234 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc h); 224 const RenderObject* findTextLeaf(const RenderObject*, size_t&, TextLeafSearc h);
235 225
236 const Document* m_document; 226 const Document* m_document;
237 int m_frameWidth; // LocalFrame width in density-independent pixels (DIPs). 227 int m_frameWidth; // LocalFrame width in density-independent pixels (DIPs).
238 int m_layoutWidth; // Layout width in CSS pixels. 228 int m_layoutWidth; // Layout width in CSS pixels.
239 float m_baseMultiplier; // Includes accessibility font scale factor and devi ce scale adjustment. 229 float m_baseMultiplier; // Includes accessibility font scale factor and devi ce scale adjustment.
230 PageNeedsAutosizing m_pageNeedsAutosizing;
240 const RenderBlock* m_firstBlock; // First block to receive beginLayout. 231 const RenderBlock* m_firstBlock; // First block to receive beginLayout.
241 #ifndef NDEBUG 232 #ifndef NDEBUG
242 bool m_renderViewInfoPrepared; 233 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. 234 BlockSet m_blocksThatHaveBegunLayout; // Used to ensure we don't compute pro perties of a block before beginLayout() is called on it.
244 #endif 235 #endif
245 236
246 // Clusters are created and destroyed during layout. The map key is the 237 // Clusters are created and destroyed during layout. The map key is the
247 // cluster root. Clusters whose roots share the same fingerprint use the 238 // cluster root. Clusters whose roots share the same fingerprint use the
248 // same multiplier. 239 // same multiplier.
249 SuperclusterMap m_superclusters; 240 SuperclusterMap m_superclusters;
250 ClusterStack m_clusterStack; 241 ClusterStack m_clusterStack;
251 FingerprintMapper m_fingerprintMapper; 242 FingerprintMapper m_fingerprintMapper;
252 }; 243 };
253 244
254 } // namespace WebCore 245 } // namespace WebCore
255 246
256 #endif // FastTextAutosizer_h 247 #endif // FastTextAutosizer_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/rendering/FastTextAutosizer.cpp » ('j') | Source/core/rendering/FastTextAutosizer.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698