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

Side by Side Diff: Source/core/rendering/TextAutosizer.cpp

Issue 17071009: Consistently autosize markers in <ul> and <ol> lists. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@ls-TA-margins-14June
Patch Set: removed the setMarginStart related modification Created 7 years, 6 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
« no previous file with comments | « Source/core/rendering/TextAutosizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 static RenderListItem* getAncestorListItem(const RenderObject* renderer) 84 static RenderListItem* getAncestorListItem(const RenderObject* renderer)
85 { 85 {
86 RenderObject* ancestor = renderer->parent(); 86 RenderObject* ancestor = renderer->parent();
87 while (ancestor && (ancestor->isRenderInline() || ancestor->isAnonymousBlock ())) 87 while (ancestor && (ancestor->isRenderInline() || ancestor->isAnonymousBlock ()))
88 ancestor = ancestor->parent(); 88 ancestor = ancestor->parent();
89 89
90 return (ancestor && ancestor->isListItem()) ? toRenderListItem(ancestor) : 0 ; 90 return (ancestor && ancestor->isListItem()) ? toRenderListItem(ancestor) : 0 ;
91 } 91 }
92 92
93 static RenderObject* getAncestorList(const RenderObject* renderer)
94 {
95 for (RenderObject* ancestor = renderer->parent(); ancestor; ancestor = ances tor->parent()) {
96 Node* parentNode = ancestor->generatingNode();
97 if (parentNode && (parentNode->hasTagName(olTag) || parentNode->hasTagNa me(ulTag)))
Julien - ping for review 2013/06/21 19:01:53 HTML5 allows <menu> in the toolbar state for the c
timvolodine 2013/06/21 19:21:37 Done.
98 return ancestor;
99 }
100 return 0;
101 }
102
93 TextAutosizer::TextAutosizer(Document* document) 103 TextAutosizer::TextAutosizer(Document* document)
94 : m_document(document) 104 : m_document(document)
95 { 105 {
96 } 106 }
97 107
98 TextAutosizer::~TextAutosizer() 108 TextAutosizer::~TextAutosizer()
99 { 109 {
100 } 110 }
101 111
102 void TextAutosizer::recalculateMultipliers() 112 void TextAutosizer::recalculateMultipliers()
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 ASSERT(isAutosizingContainer(container)); 219 ASSERT(isAutosizingContainer(container));
210 220
211 float localMultiplier = containerShouldBeAutosized(container) ? multiplier: 1; 221 float localMultiplier = containerShouldBeAutosized(container) ? multiplier: 1;
212 222
213 RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(sub treeRoot, subtreeRoot); 223 RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(sub treeRoot, subtreeRoot);
214 while (descendant) { 224 while (descendant) {
215 if (descendant->isText()) { 225 if (descendant->isText()) {
216 if (localMultiplier != 1 && descendant->style()->textAutosizingMulti plier() == 1) { 226 if (localMultiplier != 1 && descendant->style()->textAutosizingMulti plier() == 1) {
217 setMultiplier(descendant, localMultiplier); 227 setMultiplier(descendant, localMultiplier);
218 setMultiplier(descendant->parent(), localMultiplier); // Parent does line spacing. 228 setMultiplier(descendant->parent(), localMultiplier); // Parent does line spacing.
229
219 if (RenderListItem* listItemAncestor = getAncestorListItem(desce ndant)) { 230 if (RenderListItem* listItemAncestor = getAncestorListItem(desce ndant)) {
220 if (listItemAncestor->style()->textAutosizingMultiplier() == 1) 231 if (RenderObject* list = getAncestorList(listItemAncestor)) {
221 setMultiplier(listItemAncestor, localMultiplier); 232 if (list->style()->textAutosizingMultiplier() == 1)
233 setMultiplierForList(list, localMultiplier);
234 }
222 } 235 }
223 } 236 }
224 } else if (isAutosizingContainer(descendant)) { 237 } else if (isAutosizingContainer(descendant)) {
225 RenderBlock* descendantBlock = toRenderBlock(descendant); 238 RenderBlock* descendantBlock = toRenderBlock(descendant);
226 TextAutosizingClusterInfo descendantClusterInfo(descendantBlock); 239 TextAutosizingClusterInfo descendantClusterInfo(descendantBlock);
227 if (isWiderDescendant(descendantBlock, clusterInfo) || isIndependent Descendant(descendantBlock)) 240 if (isWiderDescendant(descendantBlock, clusterInfo) || isIndependent Descendant(descendantBlock))
228 processCluster(descendantClusterInfo, descendantBlock, descendan tBlock, windowInfo); 241 processCluster(descendantClusterInfo, descendantBlock, descendan tBlock, windowInfo);
229 else if (isNarrowDescendant(descendantBlock, clusterInfo)) { 242 else if (isNarrowDescendant(descendantBlock, clusterInfo)) {
230 // Narrow descendants are processed together later to be able to apply the same multiplier 243 // Narrow descendants are processed together later to be able to apply the same multiplier
231 // to each of them if necessary. 244 // to each of them if necessary.
232 clusterInfo.narrowDescendants.append(descendantClusterInfo); 245 clusterInfo.narrowDescendants.append(descendantClusterInfo);
233 } else 246 } else
234 processContainer(multiplier, descendantBlock, clusterInfo, desce ndantBlock, windowInfo); 247 processContainer(multiplier, descendantBlock, clusterInfo, desce ndantBlock, windowInfo);
235 } 248 }
236 descendant = nextInPreOrderSkippingDescendantsOfContainers(descendant, s ubtreeRoot); 249 descendant = nextInPreOrderSkippingDescendantsOfContainers(descendant, s ubtreeRoot);
237 } 250 }
238 } 251 }
239 252
240 void TextAutosizer::setMultiplier(RenderObject* renderer, float multiplier) 253 void TextAutosizer::setMultiplier(RenderObject* renderer, float multiplier)
241 { 254 {
242 RefPtr<RenderStyle> newStyle = RenderStyle::clone(renderer->style()); 255 RefPtr<RenderStyle> newStyle = RenderStyle::clone(renderer->style());
243 newStyle->setTextAutosizingMultiplier(multiplier); 256 newStyle->setTextAutosizingMultiplier(multiplier);
244 renderer->setStyle(newStyle.release()); 257 renderer->setStyle(newStyle.release());
245 } 258 }
246 259
260 void TextAutosizer::setMultiplierForList(RenderObject* renderer, float multiplie r)
261 {
262 #ifndef NDEBUG
263 Node* parentNode = renderer->generatingNode();
264 ASSERT(parentNode);
265 ASSERT(parentNode->hasTagName(olTag) || parentNode->hasTagName(ulTag));
266 #endif
267 RefPtr<RenderStyle> newListStyle = RenderStyle::clone(renderer->style());
268 newListStyle->setTextAutosizingMultiplier(multiplier);
269 renderer->setStyle(newListStyle.release());
Julien - ping for review 2013/06/21 19:01:53 It seems that this is just setMultiplier() above.
timvolodine 2013/06/21 19:21:37 Done.
270
271 // Make sure all list items are autosized consistently.
272 for (RenderObject* child = renderer->firstChild(); child; child = child->nex tSibling()) {
273 if (child->isListItem() && child->style()->textAutosizingMultiplier() == 1)
274 setMultiplier(child, multiplier);
275 }
276 }
277
247 float TextAutosizer::computeAutosizedFontSize(float specifiedSize, float multipl ier) 278 float TextAutosizer::computeAutosizedFontSize(float specifiedSize, float multipl ier)
248 { 279 {
249 // Somewhat arbitrary "pleasant" font size. 280 // Somewhat arbitrary "pleasant" font size.
250 const float pleasantSize = 16; 281 const float pleasantSize = 16;
251 282
252 // Multiply fonts that the page author has specified to be larger than 283 // Multiply fonts that the page author has specified to be larger than
253 // pleasantSize by less and less, until huge fonts are not increased at all. 284 // pleasantSize by less and less, until huge fonts are not increased at all.
254 // For specifiedSize between 0 and pleasantSize we directly apply the 285 // For specifiedSize between 0 and pleasantSize we directly apply the
255 // multiplier; hence for specifiedSize == pleasantSize, computedSize will be 286 // multiplier; hence for specifiedSize == pleasantSize, computedSize will be
256 // multiplier * pleasantSize. For greater specifiedSizes we want to 287 // multiplier * pleasantSize. For greater specifiedSizes we want to
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 if (i + 1 < clusterInfos.size()) { 657 if (i + 1 < clusterInfos.size()) {
627 float currentWidth = clusterInfos[i].root->contentLogicalWidth(); 658 float currentWidth = clusterInfos[i].root->contentLogicalWidth();
628 float nextWidth = clusterInfos[i + 1].root->contentLogicalWidth(); 659 float nextWidth = clusterInfos[i + 1].root->contentLogicalWidth();
629 if (currentWidth - nextWidth > maxWidthDifferenceWithinGroup) 660 if (currentWidth - nextWidth > maxWidthDifferenceWithinGroup)
630 groups.grow(groups.size() + 1); 661 groups.grow(groups.size() + 1);
631 } 662 }
632 } 663 }
633 } 664 }
634 665
635 } // namespace WebCore 666 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/TextAutosizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698