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

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: fixed comments 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 // FIXME: Add support for <menu> elements as a possible ancestor of an <li> element,
96 // see http://www.whatwg.org/specs/web-apps/current-work/multipage/grouping- content.html#the-li-element
97 for (RenderObject* ancestor = renderer->parent(); ancestor; ancestor = ances tor->parent()) {
98 Node* parentNode = ancestor->generatingNode();
99 if (parentNode && (parentNode->hasTagName(olTag) || parentNode->hasTagNa me(ulTag)))
100 return ancestor;
101 }
102 return 0;
103 }
104
93 TextAutosizer::TextAutosizer(Document* document) 105 TextAutosizer::TextAutosizer(Document* document)
94 : m_document(document) 106 : m_document(document)
95 { 107 {
96 } 108 }
97 109
98 TextAutosizer::~TextAutosizer() 110 TextAutosizer::~TextAutosizer()
99 { 111 {
100 } 112 }
101 113
102 void TextAutosizer::recalculateMultipliers() 114 void TextAutosizer::recalculateMultipliers()
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 ASSERT(isAutosizingContainer(container)); 221 ASSERT(isAutosizingContainer(container));
210 222
211 float localMultiplier = containerShouldBeAutosized(container) ? multiplier: 1; 223 float localMultiplier = containerShouldBeAutosized(container) ? multiplier: 1;
212 224
213 RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(sub treeRoot, subtreeRoot); 225 RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(sub treeRoot, subtreeRoot);
214 while (descendant) { 226 while (descendant) {
215 if (descendant->isText()) { 227 if (descendant->isText()) {
216 if (localMultiplier != 1 && descendant->style()->textAutosizingMulti plier() == 1) { 228 if (localMultiplier != 1 && descendant->style()->textAutosizingMulti plier() == 1) {
217 setMultiplier(descendant, localMultiplier); 229 setMultiplier(descendant, localMultiplier);
218 setMultiplier(descendant->parent(), localMultiplier); // Parent does line spacing. 230 setMultiplier(descendant->parent(), localMultiplier); // Parent does line spacing.
231
219 if (RenderListItem* listItemAncestor = getAncestorListItem(desce ndant)) { 232 if (RenderListItem* listItemAncestor = getAncestorListItem(desce ndant)) {
220 if (listItemAncestor->style()->textAutosizingMultiplier() == 1) 233 if (RenderObject* list = getAncestorList(listItemAncestor)) {
221 setMultiplier(listItemAncestor, localMultiplier); 234 if (list->style()->textAutosizingMultiplier() == 1)
235 setMultiplierForList(list, localMultiplier);
236 }
222 } 237 }
223 } 238 }
224 } else if (isAutosizingContainer(descendant)) { 239 } else if (isAutosizingContainer(descendant)) {
225 RenderBlock* descendantBlock = toRenderBlock(descendant); 240 RenderBlock* descendantBlock = toRenderBlock(descendant);
226 TextAutosizingClusterInfo descendantClusterInfo(descendantBlock); 241 TextAutosizingClusterInfo descendantClusterInfo(descendantBlock);
227 if (isWiderDescendant(descendantBlock, clusterInfo) || isIndependent Descendant(descendantBlock)) 242 if (isWiderDescendant(descendantBlock, clusterInfo) || isIndependent Descendant(descendantBlock))
228 processCluster(descendantClusterInfo, descendantBlock, descendan tBlock, windowInfo); 243 processCluster(descendantClusterInfo, descendantBlock, descendan tBlock, windowInfo);
229 else if (isNarrowDescendant(descendantBlock, clusterInfo)) { 244 else if (isNarrowDescendant(descendantBlock, clusterInfo)) {
230 // Narrow descendants are processed together later to be able to apply the same multiplier 245 // Narrow descendants are processed together later to be able to apply the same multiplier
231 // to each of them if necessary. 246 // to each of them if necessary.
232 clusterInfo.narrowDescendants.append(descendantClusterInfo); 247 clusterInfo.narrowDescendants.append(descendantClusterInfo);
233 } else 248 } else
234 processContainer(multiplier, descendantBlock, clusterInfo, desce ndantBlock, windowInfo); 249 processContainer(multiplier, descendantBlock, clusterInfo, desce ndantBlock, windowInfo);
235 } 250 }
236 descendant = nextInPreOrderSkippingDescendantsOfContainers(descendant, s ubtreeRoot); 251 descendant = nextInPreOrderSkippingDescendantsOfContainers(descendant, s ubtreeRoot);
237 } 252 }
238 } 253 }
239 254
240 void TextAutosizer::setMultiplier(RenderObject* renderer, float multiplier) 255 void TextAutosizer::setMultiplier(RenderObject* renderer, float multiplier)
241 { 256 {
257 // FIXME: Investigate if a clone() is needed and whether it does the right t hing w.r.t. style sharing.
242 RefPtr<RenderStyle> newStyle = RenderStyle::clone(renderer->style()); 258 RefPtr<RenderStyle> newStyle = RenderStyle::clone(renderer->style());
243 newStyle->setTextAutosizingMultiplier(multiplier); 259 newStyle->setTextAutosizingMultiplier(multiplier);
244 renderer->setStyle(newStyle.release()); 260 renderer->setStyle(newStyle.release());
245 } 261 }
246 262
263 void TextAutosizer::setMultiplierForList(RenderObject* renderer, float multiplie r)
264 {
265 #ifndef NDEBUG
266 Node* parentNode = renderer->generatingNode();
267 ASSERT(parentNode);
268 ASSERT(parentNode->hasTagName(olTag) || parentNode->hasTagName(ulTag));
269 #endif
270 setMultiplier(renderer, multiplier);
271
272 // Make sure all list items are autosized consistently.
273 for (RenderObject* child = renderer->firstChild(); child; child = child->nex tSibling()) {
274 if (child->isListItem() && child->style()->textAutosizingMultiplier() == 1)
275 setMultiplier(child, multiplier);
276 }
277 }
278
247 float TextAutosizer::computeAutosizedFontSize(float specifiedSize, float multipl ier) 279 float TextAutosizer::computeAutosizedFontSize(float specifiedSize, float multipl ier)
248 { 280 {
249 // Somewhat arbitrary "pleasant" font size. 281 // Somewhat arbitrary "pleasant" font size.
250 const float pleasantSize = 16; 282 const float pleasantSize = 16;
251 283
252 // Multiply fonts that the page author has specified to be larger than 284 // 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. 285 // pleasantSize by less and less, until huge fonts are not increased at all.
254 // For specifiedSize between 0 and pleasantSize we directly apply the 286 // For specifiedSize between 0 and pleasantSize we directly apply the
255 // multiplier; hence for specifiedSize == pleasantSize, computedSize will be 287 // multiplier; hence for specifiedSize == pleasantSize, computedSize will be
256 // multiplier * pleasantSize. For greater specifiedSizes we want to 288 // 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()) { 658 if (i + 1 < clusterInfos.size()) {
627 float currentWidth = clusterInfos[i].root->contentLogicalWidth(); 659 float currentWidth = clusterInfos[i].root->contentLogicalWidth();
628 float nextWidth = clusterInfos[i + 1].root->contentLogicalWidth(); 660 float nextWidth = clusterInfos[i + 1].root->contentLogicalWidth();
629 if (currentWidth - nextWidth > maxWidthDifferenceWithinGroup) 661 if (currentWidth - nextWidth > maxWidthDifferenceWithinGroup)
630 groups.grow(groups.size() + 1); 662 groups.grow(groups.size() + 1);
631 } 663 }
632 } 664 }
633 } 665 }
634 666
635 } // namespace WebCore 667 } // 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