Index: Source/core/css/resolver/FontBuilder.cpp |
diff --git a/Source/core/css/resolver/FontBuilder.cpp b/Source/core/css/resolver/FontBuilder.cpp |
index 073dd94d3eee6eba6a54fa4014126dcc2c2069c6..2bc7804c038aaa935a804596e96a02cbd00a60d6 100644 |
--- a/Source/core/css/resolver/FontBuilder.cpp |
+++ b/Source/core/css/resolver/FontBuilder.cpp |
@@ -25,7 +25,6 @@ |
#include "core/css/CSSCalculationValue.h" |
#include "core/css/CSSToLengthConversionData.h" |
-#include "core/css/FontSize.h" |
#include "core/frame/LocalFrame.h" |
#include "core/frame/Settings.h" |
#include "core/rendering/RenderTheme.h" |
@@ -63,7 +62,6 @@ private: |
FontBuilder::FontBuilder() |
: m_document(nullptr) |
- , m_fontSizehasViewportUnits(false) |
, m_style(0) |
, m_fontDirty(false) |
{ |
@@ -102,8 +100,7 @@ void FontBuilder::setInitial(float effectiveZoom) |
scope.reset(); |
setFontFamilyToStandard(scope.fontDescription(), m_document); |
- scope.fontDescription().setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1); |
- setSize(scope.fontDescription(), effectiveZoom, FontSize::fontSizeForKeyword(m_document, CSSValueMedium, NonFixedPitchFont)); |
+ setSize(scope.fontDescription(), FontBuilder::initialSize()); |
} |
void FontBuilder::inheritFrom(const FontDescription& fontDescription) |
@@ -233,131 +230,22 @@ void FontBuilder::setFontFamilyValue(CSSValue* value) |
if (!currFamily) |
return; |
- if (scope.fontDescription().keywordSize() && scope.fontDescription().fixedPitchFontType() != oldFixedPitchFontType) { |
- scope.fontDescription().setSpecifiedSize(FontSize::fontSizeForKeyword(m_document, |
- static_cast<CSSValueID>(CSSValueXxSmall + scope.fontDescription().keywordSize() - 1), scope.fontDescription().fixedPitchFontType())); |
- } |
-} |
- |
-void FontBuilder::setFontSizeInitial() |
-{ |
- FontDescriptionChangeScope scope(this); |
- |
- float size = FontSize::fontSizeForKeyword(m_document, CSSValueMedium, scope.fontDescription().fixedPitchFontType()); |
- |
- if (size < 0) |
- return; |
- |
- scope.fontDescription().setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1); |
- scope.fontDescription().setSpecifiedSize(size); |
+ if (scope.fontDescription().keywordSize() && scope.fontDescription().fixedPitchFontType() != oldFixedPitchFontType) |
+ setSize(scope.fontDescription(), FontDescription::Size(scope.fontDescription().keywordSize(), 0.0f, false)); |
} |
-void FontBuilder::setFontSizeInherit(const FontDescription& parentFontDescription) |
-{ |
- FontDescriptionChangeScope scope(this); |
- |
- float size = parentFontDescription.specifiedSize(); |
- |
- if (size < 0) |
- return; |
- |
- scope.fontDescription().setKeywordSize(parentFontDescription.keywordSize()); |
- scope.fontDescription().setSpecifiedSize(size); |
-} |
- |
-// FIXME: Figure out where we fall in the size ranges (xx-small to xxx-large) |
-// and scale down/up to the next size level. |
-static float largerFontSize(float size) |
-{ |
- return size * 1.2f; |
-} |
- |
-static float smallerFontSize(float size) |
-{ |
- return size / 1.2f; |
-} |
- |
-// FIXME: Have to pass RenderStyles here for calc/computed values. This shouldn't be neecessary. |
-void FontBuilder::setFontSizeValue(CSSValue* value, RenderStyle* parentStyle, const RenderStyle* rootElementStyle) |
+void FontBuilder::setWeight(FontWeight fontWeight) |
{ |
- if (!value->isPrimitiveValue()) |
- return; |
- |
- CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
- |
FontDescriptionChangeScope scope(this); |
- scope.fontDescription().setKeywordSize(0); |
- float parentSize = 0; |
- bool parentIsAbsoluteSize = false; |
- float size = 0; |
- |
- // FIXME: Find out when parentStyle could be 0? |
- if (parentStyle) { |
- parentSize = parentStyle->fontDescription().specifiedSize(); |
- parentIsAbsoluteSize = parentStyle->fontDescription().isAbsoluteSize(); |
- } |
- |
- if (CSSValueID valueID = primitiveValue->getValueID()) { |
- switch (valueID) { |
- case CSSValueXxSmall: |
- case CSSValueXSmall: |
- case CSSValueSmall: |
- case CSSValueMedium: |
- case CSSValueLarge: |
- case CSSValueXLarge: |
- case CSSValueXxLarge: |
- case CSSValueWebkitXxxLarge: |
- size = FontSize::fontSizeForKeyword(m_document, valueID, scope.fontDescription().fixedPitchFontType()); |
- scope.fontDescription().setKeywordSize(valueID - CSSValueXxSmall + 1); |
- break; |
- case CSSValueLarger: |
- size = largerFontSize(parentSize); |
- break; |
- case CSSValueSmaller: |
- size = smallerFontSize(parentSize); |
- break; |
- default: |
- return; |
- } |
- |
- scope.fontDescription().setIsAbsoluteSize(parentIsAbsoluteSize && (valueID == CSSValueLarger || valueID == CSSValueSmaller)); |
- } else { |
- scope.fontDescription().setIsAbsoluteSize(parentIsAbsoluteSize || !(primitiveValue->isPercentage() || primitiveValue->isFontRelativeLength())); |
- if (primitiveValue->isPercentage()) { |
- size = (primitiveValue->getFloatValue() * parentSize) / 100.0f; |
- } else { |
- // If we have viewport units the conversion will mark the parent style as having viewport units. |
- bool parentHasViewportUnits = parentStyle->hasViewportUnits(); |
- parentStyle->setHasViewportUnits(false); |
- CSSToLengthConversionData conversionData(parentStyle, rootElementStyle, m_document->renderView(), 1.0f, true); |
- if (primitiveValue->isLength()) |
- size = primitiveValue->computeLength<float>(conversionData); |
- else if (primitiveValue->isCalculatedPercentageWithLength()) |
- size = primitiveValue->cssCalcValue()->toCalcValue(conversionData)->evaluate(parentSize); |
- else |
- ASSERT_NOT_REACHED(); |
- m_fontSizehasViewportUnits = parentStyle->hasViewportUnits(); |
- parentStyle->setHasViewportUnits(parentHasViewportUnits); |
- } |
- } |
- |
- if (size < 0) |
- return; |
- |
- // Overly large font sizes will cause crashes on some platforms (such as Windows). |
- // Cap font size here to make sure that doesn't happen. |
- size = std::min(maximumAllowedFontSize, size); |
- |
- |
- scope.fontDescription().setSpecifiedSize(size); |
+ scope.fontDescription().setWeight(fontWeight); |
} |
-void FontBuilder::setWeight(FontWeight fontWeight) |
+void FontBuilder::setSize(const FontDescription::Size& size) |
{ |
FontDescriptionChangeScope scope(this); |
- scope.fontDescription().setWeight(fontWeight); |
+ setSize(scope.fontDescription(), size); |
} |
void FontBuilder::setStretch(FontStretch fontStretch) |
@@ -424,10 +312,23 @@ void FontBuilder::setFeatureSettings(PassRefPtr<FontFeatureSettings> settings) |
scope.fontDescription().setFeatureSettings(settings); |
} |
-void FontBuilder::setSize(FontDescription& fontDescription, float effectiveZoom, float size) |
+void FontBuilder::setSize(FontDescription& fontDescription, const FontDescription::Size& size) |
{ |
- fontDescription.setSpecifiedSize(size); |
- fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription, effectiveZoom, size)); |
+ float specifiedSize = size.value; |
+ |
+ if (!specifiedSize && size.keyword) |
+ specifiedSize = FontSize::fontSizeForKeyword(m_document, size.keyword, fontDescription.fixedPitchFontType()); |
+ |
+ if (specifiedSize < 0) |
+ return; |
+ |
+ // Overly large font sizes will cause crashes on some platforms (such as Windows). |
+ // Cap font size here to make sure that doesn't happen. |
+ specifiedSize = std::min(maximumAllowedFontSize, specifiedSize); |
+ |
+ fontDescription.setKeywordSize(size.keyword); |
+ fontDescription.setSpecifiedSize(specifiedSize); |
+ fontDescription.setIsAbsoluteSize(size.isAbsolute); |
} |
float FontBuilder::getComputedSizeFromSpecifiedSize(FontDescription& fontDescription, float effectiveZoom, float specifiedSize) |
@@ -516,7 +417,7 @@ void FontBuilder::checkForGenericFamilyChange(RenderStyle* style, const RenderSt |
// multiplying by our scale factor. |
float size; |
if (scope.fontDescription().keywordSize()) { |
- size = FontSize::fontSizeForKeyword(m_document, static_cast<CSSValueID>(CSSValueXxSmall + scope.fontDescription().keywordSize() - 1), scope.fontDescription().fixedPitchFontType()); |
+ size = FontSize::fontSizeForKeyword(m_document, scope.fontDescription().keywordSize(), scope.fontDescription().fixedPitchFontType()); |
} else { |
Settings* settings = m_document->settings(); |
float fixedScaleFactor = (settings && settings->defaultFixedFontSize() && settings->defaultFontSize()) |
@@ -527,19 +428,23 @@ void FontBuilder::checkForGenericFamilyChange(RenderStyle* style, const RenderSt |
scope.fontDescription().specifiedSize() * fixedScaleFactor; |
} |
- setSize(scope.fontDescription(), style->effectiveZoom(), size); |
+ scope.fontDescription().setSpecifiedSize(size); |
+ updateComputedSize(scope.fontDescription(), style); |
} |
void FontBuilder::updateComputedSize(RenderStyle* style, const RenderStyle* parentStyle) |
{ |
FontDescriptionChangeScope scope(this); |
+ updateComputedSize(scope.fontDescription(), style); |
+} |
- float computedSize = getComputedSizeFromSpecifiedSize(scope.fontDescription(), style->effectiveZoom(), scope.fontDescription().specifiedSize()); |
+void FontBuilder::updateComputedSize(FontDescription& fontDescription, RenderStyle* style) |
+{ |
+ float computedSize = getComputedSizeFromSpecifiedSize(fontDescription, style->effectiveZoom(), fontDescription.specifiedSize()); |
float multiplier = style->textAutosizingMultiplier(); |
if (multiplier > 1) |
computedSize = TextAutosizer::computeAutosizedFontSize(computedSize, multiplier); |
- |
- scope.fontDescription().setComputedSize(computedSize); |
+ fontDescription.setComputedSize(computedSize); |
} |
// FIXME: style param should come first |
@@ -561,10 +466,9 @@ void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon |
fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle->locale())); |
setFontFamilyToStandard(fontDescription, m_document); |
- fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1); |
- int size = FontSize::fontSizeForKeyword(m_document, CSSValueMedium, NonFixedPitchFont); |
- fontDescription.setSpecifiedSize(size); |
- fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescription, documentStyle->effectiveZoom(), size)); |
+ |
+ setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize(), 0.0f, false)); |
+ updateComputedSize(fontDescription, documentStyle); |
FontOrientation fontOrientation; |
NonCJKGlyphOrientation glyphOrientation; |