Ignore:
Timestamp:
Sep 10, 2013, 7:39:05 PM (12 years ago)
Author:
[email protected]
Message:

[iOS] Upstream text autosizing
https://bugs.webkit.org/show_bug.cgi?id=121111

Reviewed by Andy Estes and Sam Weinig.

Source/WebCore:

Tests: platform/iphone-simulator/text-autosizing/anonymous-block.html

platform/iphone-simulator/text-autosizing/contenteditable.html
platform/iphone-simulator/text-autosizing/first-letter.html
platform/iphone-simulator/text-autosizing/font-family-case-insensitive.html
platform/iphone-simulator/text-autosizing/lists.html
platform/iphone-simulator/text-autosizing/overflow.html
platform/iphone-simulator/text-autosizing/percent-adjust-length-line-height.html
platform/iphone-simulator/text-autosizing/percent-adjust-number-line-height.html
platform/iphone-simulator/text-autosizing/percent-adjust-percent-line-height.html

  • WebCore.exp.in:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::propertyValue):

  • css/CSSParser.cpp:

(WebCore::isValidKeywordPropertyAndValue):
(WebCore::CSSParser::parseValue):

  • css/CSSProperty.cpp:

(WebCore::CSSProperty::isInheritedProperty):

  • css/CSSPropertyNames.in: Add property -webkit-text-size-adjust.
  • css/DeprecatedStyleBuilder.cpp:

(WebCore::ApplyPropertyLineHeightForIOSTextAutosizing::applyValue): Added.
(WebCore::ApplyPropertyLineHeightForIOSTextAutosizing::applyInitialValue): Added.
(WebCore::ApplyPropertyLineHeightForIOSTextAutosizing::applyInheritValue): Added.
(WebCore::ApplyPropertyLineHeightForIOSTextAutosizing::createHandler): Added.
(WebCore::DeprecatedStyleBuilder::DeprecatedStyleBuilder):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::updateFont):
(WebCore::StyleResolver::applyProperties): Add COMPILE_ASSERT to ensure that
all properties that affect font size, including -webkit-text-size-adjust, are
resolved before properties that depend on them; see <rdar://problem/13522835>.
(WebCore::StyleResolver::applyProperty):
(WebCore::StyleResolver::checkForTextSizeAdjust): Added.

  • css/StyleResolver.h:
  • dom/Document.cpp:

(WebCore::TextAutoSizingTraits::constructDeletedValue): Added.
(WebCore::TextAutoSizingTraits::isDeletedValue): Added.
(WebCore::Document::detach):
(WebCore::Document::addAutoSizingNode): Added.
(WebCore::Document::validateAutoSizingNodes): Added.
(WebCore::Document::resetAutoSizingNodes): Added.

  • dom/Document.h:
  • editing/EditingStyle.cpp:
  • page/Frame.h: Add declarations for setTextAutosizingWidth(), textAutosizingWidth().
  • page/FrameView.cpp:

(WebCore::FrameView::layout):

  • page/Settings.in: Generate setter and getter for setting minimumZoomFontSize.
  • platform/graphics/Font.h:

(WebCore::Font::equalForTextAutoSizing): Added.

  • platform/graphics/FontDescription.cpp:

(WebCore::FontDescription::familiesEqualForTextAutoSizing): Added.

  • platform/graphics/FontDescription.h:

(WebCore::FontDescription::equalForTextAutoSizing): Added.

  • rendering/RenderBlock.cpp:

(WebCore::RenderBlock::RenderBlock):
(WebCore::isVisibleRenderText): Added.
(WebCore::resizeTextPermitted): Added.
(WebCore::RenderBlock::immediateLineCount): Added.
(WebCore::isNonBlocksOrNonFixedHeightListItems): Added.
(WebCore::oneLineTextMultiplier): Added.
(WebCore::textMultiplier): Added.
(WebCore::RenderBlock::adjustComputedFontSizes): Added.

  • rendering/RenderBlock.h:

(WebCore::RenderBlock::resetComputedFontSize): Added.

  • rendering/RenderObject.cpp:

(WebCore::RenderObject::traverseNext): Added.
(WebCore::includeNonFixedHeight): Added.
(WebCore::RenderObject::adjustComputedFontSizesOnBlocks): Added.
(WebCore::RenderObject::resetTextAutosizing): Added.

  • rendering/RenderObject.h:
  • rendering/RenderText.cpp:

(WebCore::RenderText::RenderText):

  • rendering/RenderText.h:

(WebCore::RenderText::candidateComputedTextSize): Added.
(WebCore::RenderText::setCandidateComputedTextSize): Added.

  • rendering/style/RenderStyle.cpp:

(WebCore::computeFontHash):
(WebCore::RenderStyle::hashForTextAutosizing): Added.
(WebCore::RenderStyle::equalForTextAutosizing): Added.
(WebCore::RenderStyle::changeRequiresLayout):
(WebCore::RenderStyle::specifiedLineHeight): Added; iOS-specific variant.
We should reconcile this getter with the getter of the same name that is
compiled when building with IOS_TEXT_AUTOSIZING disabled.
(WebCore::RenderStyle::setSpecifiedLineHeight): Added.

  • rendering/style/RenderStyle.h:

(WebCore::RenderStyle::initialSpecifiedLineHeight): Added.
(WebCore::RenderStyle::initialTextSizeAdjust): Added.
(WebCore::RenderStyle::setTextSizeAdjust): Added.
(WebCore::RenderStyle::textSizeAdjust): Added.

  • rendering/style/StyleInheritedData.cpp:

(WebCore::StyleInheritedData::StyleInheritedData):
(WebCore::StyleInheritedData::operator==):

  • rendering/style/StyleInheritedData.h:
  • rendering/style/StyleRareInheritedData.cpp:

(WebCore::StyleRareInheritedData::StyleRareInheritedData):
(WebCore::StyleRareInheritedData::operator==):

  • rendering/style/StyleRareInheritedData.h:
  • rendering/style/TextSizeAdjustment.h: Added.

(TextSizeAdjustment::TextSizeAdjustment):
(TextSizeAdjustment::percentage):
(TextSizeAdjustment::multiplier):
(TextSizeAdjustment::isAuto):
(TextSizeAdjustment::isNone):
(TextSizeAdjustment::isPercentage):
(TextSizeAdjustment::operator == ):
(TextSizeAdjustment::operator != ):

Source/WebKit/mac:

  • WebView/WebFrame.mm:

(-[WebFrame resetTextAutosizingBeforeLayout]): Added.
(-[WebFrame _setVisibleSize:]): Added.
(-[WebFrame _setTextAutosizingWidth:]): Added.

  • WebView/WebFramePrivate.h:
  • WebView/WebPreferenceKeysPrivate.h:
  • WebView/WebPreferences.mm:

(+[WebPreferences initialize]):
(-[WebPreferences _setMinimumZoomFontSize:]): Added.
(-[WebPreferences _minimumZoomFontSize]): Added.

Source/WTF:

Define iOS text autosizing to be enabled on iOS unless otherwise defined.

  • wtf/FeatureDefines.h:

Tools:

Implement infrastructure to test the iOS text autosizing code.

  • DumpRenderTree/TestRunner.cpp:

(setTextAutosizingEnabledCallback): Added.
(TestRunner::staticFunctions):

  • DumpRenderTree/TestRunner.h:
  • DumpRenderTree/mac/DumpRenderTree.mm:

(resetDefaultsToConsistentValues):

  • DumpRenderTree/mac/TestRunnerMac.mm:

(TestRunner::setTextAutosizingEnabled): Added.

LayoutTests:

Add tests to ensure we don't regress iOS text autosizing.

  • platform/iphone-simulator/text-autosizing/anonymous-block-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/anonymous-block.html: Added.
  • platform/iphone-simulator/text-autosizing/contenteditable-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/contenteditable.html: Added.
  • platform/iphone-simulator/text-autosizing/first-letter-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/first-letter.html: Added.
  • platform/iphone-simulator/text-autosizing/font-family-case-insensitive-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/font-family-case-insensitive.html: Added.
  • platform/iphone-simulator/text-autosizing/lists-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/lists.html: Added.
  • platform/iphone-simulator/text-autosizing/overflow-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/overflow.html: Added.
  • platform/iphone-simulator/text-autosizing/percent-adjust-length-line-height-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/percent-adjust-length-line-height.html: Added.
  • platform/iphone-simulator/text-autosizing/percent-adjust-number-line-height-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/percent-adjust-number-line-height.html: Added.
  • platform/iphone-simulator/text-autosizing/percent-adjust-percent-line-height-expected.txt: Added.
  • platform/iphone-simulator/text-autosizing/percent-adjust-percent-line-height.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/DeprecatedStyleBuilder.cpp

    r155217 r155496  
    14131413    }
    14141414};
     1415
     1416#if ENABLE(IOS_TEXT_AUTOSIZING)
     1417// FIXME: Share more code with class ApplyPropertyLineHeight.
     1418class ApplyPropertyLineHeightForIOSTextAutosizing {
     1419public:
     1420    static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1421    {
     1422        if (!value->isPrimitiveValue())
     1423            return;
     1424
     1425        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
     1426        Length lineHeight;
     1427
     1428        if (primitiveValue->getIdent() == CSSValueNormal)
     1429            lineHeight = RenderStyle::initialLineHeight();
     1430        else if (primitiveValue->isLength()) {
     1431            double multiplier = styleResolver->style()->effectiveZoom();
     1432            if (styleResolver->style()->textSizeAdjust().isNone()) {
     1433                if (Frame* frame = styleResolver->document().frame())
     1434                    multiplier *= frame->textZoomFactor();
     1435            }
     1436            lineHeight = primitiveValue->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle(), multiplier);
     1437            if (styleResolver->style()->textSizeAdjust().isPercentage())
     1438                lineHeight = Length(lineHeight.value() * styleResolver->style()->textSizeAdjust().multiplier(), Fixed);
     1439        } else if (primitiveValue->isPercentage()) {
     1440            // FIXME: percentage should not be restricted to an integer here.
     1441            lineHeight = Length((styleResolver->style()->fontSize() * primitiveValue->getIntValue()) / 100, Fixed);
     1442        } else if (primitiveValue->isNumber()) {
     1443            // FIXME: number and percentage values should produce the same type of Length (ie. Fixed or Percent).
     1444            if (styleResolver->style()->textSizeAdjust().isPercentage())
     1445                lineHeight = Length(primitiveValue->getDoubleValue() * styleResolver->style()->textSizeAdjust().multiplier() * 100.0, Percent);
     1446            else
     1447                lineHeight = Length(primitiveValue->getDoubleValue() * 100.0, Percent);
     1448        } else if (primitiveValue->isViewportPercentageLength())
     1449            lineHeight = primitiveValue->viewportPercentageLength();
     1450        else
     1451            return;
     1452        styleResolver->style()->setLineHeight(lineHeight);
     1453        styleResolver->style()->setSpecifiedLineHeight(lineHeight);
     1454    }
     1455
     1456    static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
     1457    {
     1458        styleResolver->style()->setLineHeight(RenderStyle::initialLineHeight());
     1459        styleResolver->style()->setSpecifiedLineHeight(RenderStyle::initialSpecifiedLineHeight());
     1460    }
     1461
     1462    static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
     1463    {
     1464        styleResolver->style()->setLineHeight(styleResolver->parentStyle()->lineHeight());
     1465        styleResolver->style()->setSpecifiedLineHeight(styleResolver->parentStyle()->specifiedLineHeight());
     1466    }
     1467
     1468    static PropertyHandler createHandler()
     1469    {
     1470        return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue);
     1471    }
     1472};
     1473#endif
    14151474
    14161475class ApplyPropertyPageSize {
     
    21562215    setPropertyHandler(CSSPropertyLeft, ApplyPropertyLength<&RenderStyle::left, &RenderStyle::setLeft, &RenderStyle::initialOffset, AutoEnabled>::createHandler());
    21572216    setPropertyHandler(CSSPropertyLetterSpacing, ApplyPropertyComputeLength<int, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing, &RenderStyle::initialLetterWordSpacing, NormalEnabled, ThicknessDisabled, SVGZoomEnabled>::createHandler());
     2217#if ENABLE(IOS_TEXT_AUTOSIZING)
     2218    setPropertyHandler(CSSPropertyLineHeight, ApplyPropertyLineHeightForIOSTextAutosizing::createHandler());
     2219#else
    21582220    setPropertyHandler(CSSPropertyLineHeight, ApplyPropertyLineHeight::createHandler());
     2221#endif
    21592222    setPropertyHandler(CSSPropertyListStyleImage, ApplyPropertyStyleImage<&RenderStyle::listStyleImage, &RenderStyle::setListStyleImage, &RenderStyle::initialListStyleImage, CSSPropertyListStyleImage>::createHandler());
    21602223    setPropertyHandler(CSSPropertyListStylePosition, ApplyPropertyDefault<EListStylePosition, &RenderStyle::listStylePosition, EListStylePosition, &RenderStyle::setListStylePosition, EListStylePosition, &RenderStyle::initialListStylePosition>::createHandler());
Note: See TracChangeset for help on using the changeset viewer.