| OLD | NEW |
| 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 19 matching lines...) Expand all Loading... |
| 30 #include "IntSize.h" | 30 #include "IntSize.h" |
| 31 #include "RenderObject.h" | 31 #include "RenderObject.h" |
| 32 #include "RenderStyle.h" | 32 #include "RenderStyle.h" |
| 33 #include "RenderText.h" | 33 #include "RenderText.h" |
| 34 #include "RenderView.h" | 34 #include "RenderView.h" |
| 35 #include "Settings.h" | 35 #include "Settings.h" |
| 36 #include "StyleInheritedData.h" | 36 #include "StyleInheritedData.h" |
| 37 | 37 |
| 38 #include <algorithm> | 38 #include <algorithm> |
| 39 #include <wtf/StdLibExtras.h> | 39 #include <wtf/StdLibExtras.h> |
| 40 #include <wtf/Vector.h> |
| 40 | 41 |
| 41 namespace WebCore { | 42 namespace WebCore { |
| 42 | 43 |
| 43 using namespace HTMLNames; | 44 using namespace HTMLNames; |
| 44 | 45 |
| 45 struct TextAutosizingWindowInfo { | 46 struct TextAutosizingWindowInfo { |
| 46 IntSize windowSize; | 47 IntSize windowSize; |
| 47 IntSize minLayoutSize; | 48 IntSize minLayoutSize; |
| 48 }; | 49 }; |
| 49 | 50 |
| 51 // Represents cluster related data. Instances should not persist between calls t
o processSubtree. |
| 50 struct TextAutosizingClusterInfo { | 52 struct TextAutosizingClusterInfo { |
| 51 explicit TextAutosizingClusterInfo(RenderBlock* root) | 53 explicit TextAutosizingClusterInfo(RenderBlock* root) |
| 52 : root(root) | 54 : root(root) |
| 53 , blockContainingAllText(0) | 55 , blockContainingAllText(0) |
| 54 , maxAllowedDifferenceFromTextWidth(150) | 56 , maxAllowedDifferenceFromTextWidth(150) |
| 55 { | 57 { |
| 56 } | 58 } |
| 57 | 59 |
| 58 RenderBlock* root; | 60 RenderBlock* root; |
| 59 const RenderBlock* blockContainingAllText; | 61 const RenderBlock* blockContainingAllText; |
| 60 | 62 |
| 61 // Upper limit on the difference between the width of the cluster's block co
ntaining all | 63 // Upper limit on the difference between the width of the cluster's block co
ntaining all |
| 62 // text and that of a narrow child before the child becomes a separate clust
er. | 64 // text and that of a narrow child before the child becomes a separate clust
er. |
| 63 float maxAllowedDifferenceFromTextWidth; | 65 float maxAllowedDifferenceFromTextWidth; |
| 66 |
| 67 // Descendants of the cluster that are narrower than the block containing al
l text and must be |
| 68 // processed together. |
| 69 Vector<TextAutosizingClusterInfo> narrowDescendants; |
| 64 }; | 70 }; |
| 65 | 71 |
| 66 | 72 |
| 67 static const Vector<QualifiedName>& formInputTags() | 73 static const Vector<QualifiedName>& formInputTags() |
| 68 { | 74 { |
| 69 // Returns the tags for the form input elements. | 75 // Returns the tags for the form input elements. |
| 70 DEFINE_STATIC_LOCAL(Vector<QualifiedName>, formInputTags, ()); | 76 DEFINE_STATIC_LOCAL(Vector<QualifiedName>, formInputTags, ()); |
| 71 if (formInputTags.isEmpty()) { | 77 if (formInputTags.isEmpty()) { |
| 72 formInputTags.append(inputTag); | 78 formInputTags.append(inputTag); |
| 73 formInputTags.append(buttonTag); | 79 formInputTags.append(buttonTag); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 int logicalLayoutWidth = clusterInfo.root->isHorizontalWritingMode() ? w
indowInfo.minLayoutSize.width() : windowInfo.minLayoutSize.height(); | 149 int logicalLayoutWidth = clusterInfo.root->isHorizontalWritingMode() ? w
indowInfo.minLayoutSize.width() : windowInfo.minLayoutSize.height(); |
| 144 // Ignore box width in excess of the layout width, to avoid extreme mult
ipliers. | 150 // Ignore box width in excess of the layout width, to avoid extreme mult
ipliers. |
| 145 float logicalClusterWidth = std::min<float>(textWidth, logicalLayoutWidt
h); | 151 float logicalClusterWidth = std::min<float>(textWidth, logicalLayoutWidt
h); |
| 146 | 152 |
| 147 multiplier = logicalClusterWidth / logicalWindowWidth; | 153 multiplier = logicalClusterWidth / logicalWindowWidth; |
| 148 multiplier *= m_document->settings()->textAutosizingFontScaleFactor(); | 154 multiplier *= m_document->settings()->textAutosizingFontScaleFactor(); |
| 149 multiplier = std::max(1.0f, multiplier); | 155 multiplier = std::max(1.0f, multiplier); |
| 150 } | 156 } |
| 151 | 157 |
| 152 processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo
); | 158 processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo
); |
| 159 |
| 160 Vector<TextAutosizingClusterInfo>& narrowDescendants = clusterInfo.narrowDes
cendants; |
| 161 for (size_t i = 0; i < narrowDescendants.size(); ++i) { |
| 162 TextAutosizingClusterInfo& descendantClusterInfo = narrowDescendants[i]; |
| 163 processCluster(descendantClusterInfo, descendantClusterInfo.root, descen
dantClusterInfo.root, windowInfo); |
| 164 } |
| 153 } | 165 } |
| 154 | 166 |
| 155 void TextAutosizer::processContainer(float multiplier, RenderBlock* container, T
extAutosizingClusterInfo& clusterInfo, RenderObject* subtreeRoot, const TextAuto
sizingWindowInfo& windowInfo) | 167 void TextAutosizer::processContainer(float multiplier, RenderBlock* container, T
extAutosizingClusterInfo& clusterInfo, RenderObject* subtreeRoot, const TextAuto
sizingWindowInfo& windowInfo) |
| 156 { | 168 { |
| 157 ASSERT(isAutosizingContainer(container)); | 169 ASSERT(isAutosizingContainer(container)); |
| 158 | 170 |
| 159 float localMultiplier = containerShouldBeAutosized(container) ? multiplier:
1; | 171 float localMultiplier = containerShouldBeAutosized(container) ? multiplier:
1; |
| 160 | 172 |
| 161 RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(sub
treeRoot, subtreeRoot); | 173 RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(sub
treeRoot, subtreeRoot); |
| 162 while (descendant) { | 174 while (descendant) { |
| 163 if (descendant->isText()) { | 175 if (descendant->isText()) { |
| 164 if (localMultiplier != descendant->style()->textAutosizingMultiplier
()) { | 176 if (localMultiplier != descendant->style()->textAutosizingMultiplier
()) { |
| 165 setMultiplier(descendant, localMultiplier); | 177 setMultiplier(descendant, localMultiplier); |
| 166 setMultiplier(descendant->parent(), localMultiplier); // Parent
does line spacing. | 178 setMultiplier(descendant->parent(), localMultiplier); // Parent
does line spacing. |
| 167 } | 179 } |
| 168 // FIXME: Increase list marker size proportionately. | 180 // FIXME: Increase list marker size proportionately. |
| 169 } else if (isAutosizingContainer(descendant)) { | 181 } else if (isAutosizingContainer(descendant)) { |
| 170 RenderBlock* descendantBlock = toRenderBlock(descendant); | 182 RenderBlock* descendantBlock = toRenderBlock(descendant); |
| 171 if (isAutosizingCluster(descendantBlock, clusterInfo)) { | 183 TextAutosizingClusterInfo descendantClusterInfo(descendantBlock); |
| 172 TextAutosizingClusterInfo descendantClusterInfo(descendantBlock)
; | 184 if (isWiderDescendant(descendantBlock, clusterInfo) || isIndependent
Descendant(descendantBlock)) |
| 173 processCluster(descendantClusterInfo, descendantBlock, descendan
tBlock, windowInfo); | 185 processCluster(descendantClusterInfo, descendantBlock, descendan
tBlock, windowInfo); |
| 186 else if (isNarrowDescendant(descendantBlock, clusterInfo)) { |
| 187 // Narrow descendants are processed together later to be able to
apply the same multiplier |
| 188 // to each of them if necessary. |
| 189 clusterInfo.narrowDescendants.append(descendantClusterInfo); |
| 174 } else | 190 } else |
| 175 processContainer(multiplier, descendantBlock, clusterInfo, desce
ndantBlock, windowInfo); | 191 processContainer(multiplier, descendantBlock, clusterInfo, desce
ndantBlock, windowInfo); |
| 176 } | 192 } |
| 177 descendant = nextInPreOrderSkippingDescendantsOfContainers(descendant, s
ubtreeRoot); | 193 descendant = nextInPreOrderSkippingDescendantsOfContainers(descendant, s
ubtreeRoot); |
| 178 } | 194 } |
| 179 } | 195 } |
| 180 | 196 |
| 181 void TextAutosizer::setMultiplier(RenderObject* renderer, float multiplier) | 197 void TextAutosizer::setMultiplier(RenderObject* renderer, float multiplier) |
| 182 { | 198 { |
| 183 RefPtr<RenderStyle> newStyle = RenderStyle::clone(renderer->style()); | 199 RefPtr<RenderStyle> newStyle = RenderStyle::clone(renderer->style()); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 child = (direction == FirstToLast) ? child->nextSibling() : child->previ
ousSibling(); | 531 child = (direction == FirstToLast) ? child->nextSibling() : child->previ
ousSibling(); |
| 516 } | 532 } |
| 517 --depth; | 533 --depth; |
| 518 | 534 |
| 519 return 0; | 535 return 0; |
| 520 } | 536 } |
| 521 | 537 |
| 522 } // namespace WebCore | 538 } // namespace WebCore |
| 523 | 539 |
| 524 #endif // ENABLE(TEXT_AUTOSIZING) | 540 #endif // ENABLE(TEXT_AUTOSIZING) |
| OLD | NEW |