⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 102188 in webkit


Ignore:
Timestamp:
Dec 6, 2011, 4:26:59 PM (15 years ago)
Author:
macpherson@chromium.org
Message:

Implement remaining border-image and webkit-maskbox-image properties in CSSStyleApplyProperty.
https://bugs.webkit.org/show_bug.cgi?id=73391

Reviewed by Hajime Morita.

No new tests / refacoring only.

  • css/CSSStyleApplyProperty.cpp:

(WebCore::ApplyPropertyBorderImageModifier::getValue):
(WebCore::ApplyPropertyBorderImageModifier::setValue):
(WebCore::ApplyPropertyBorderImageModifier::applyInheritValue):
(WebCore::ApplyPropertyBorderImageModifier::applyInitialValue):
(WebCore::ApplyPropertyBorderImageModifier::applyValue):
(WebCore::ApplyPropertyBorderImageModifier::createHandler):
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):

  • css/CSSStyleSelector.cpp:

(WebCore::CSSStyleSelector::applyProperty):

  • css/CSSStyleSelector.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r102187 r102188  
     12011-12-06  Luke Macpherson   <macpherson@chromium.org>
     2
     3        Implement remaining border-image and webkit-maskbox-image properties in CSSStyleApplyProperty.
     4        https://bugs.webkit.org/show_bug.cgi?id=73391
     5
     6        Reviewed by Hajime Morita.
     7
     8        No new tests / refacoring only.
     9
     10        * css/CSSStyleApplyProperty.cpp:
     11        (WebCore::ApplyPropertyBorderImageModifier::getValue):
     12        (WebCore::ApplyPropertyBorderImageModifier::setValue):
     13        (WebCore::ApplyPropertyBorderImageModifier::applyInheritValue):
     14        (WebCore::ApplyPropertyBorderImageModifier::applyInitialValue):
     15        (WebCore::ApplyPropertyBorderImageModifier::applyValue):
     16        (WebCore::ApplyPropertyBorderImageModifier::createHandler):
     17        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
     18        * css/CSSStyleSelector.cpp:
     19        (WebCore::CSSStyleSelector::applyProperty):
     20        * css/CSSStyleSelector.h:
     21
    1222011-12-06  Pavel Feldman  <pfeldman@google.com>
    223
  • trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp

    r102183 r102188  
    630630        return PropertyHandler(handler.inheritFunction(), handler.initialFunction(), &applyValue);
    631631    }
     632};
     633
     634enum BorderImageModifierType { Outset, Repeat, Slice, Width };
     635template <BorderImageType type, BorderImageModifierType modifier>
     636class ApplyPropertyBorderImageModifier {
     637private:
     638    static inline const NinePieceImage& getValue(RenderStyle* style) { return type == Image ? style->borderImage() : style->maskBoxImage(); }
     639    static inline void setValue(RenderStyle* style, const NinePieceImage& value) { return type == Image ? style->setBorderImage(value) : style->setMaskBoxImage(value); }
     640public:
     641    static void applyInheritValue(CSSStyleSelector* selector)
     642    {
     643        NinePieceImage image(getValue(selector->style()));
     644        switch (modifier) {
     645        case Outset:
     646            image.copyOutsetFrom(getValue(selector->parentStyle()));
     647            break;
     648        case Repeat:
     649            image.copyRepeatFrom(getValue(selector->parentStyle()));
     650            break;
     651        case Slice:
     652            image.copyImageSlicesFrom(getValue(selector->parentStyle()));
     653            break;
     654        case Width:
     655            image.copyBorderSlicesFrom(getValue(selector->parentStyle()));
     656            break;
     657        }
     658        setValue(selector->style(), image);
     659    }
     660
     661    static void applyInitialValue(CSSStyleSelector* selector)
     662    {
     663        NinePieceImage image(getValue(selector->style()));
     664        switch (modifier) {
     665        case Outset:
     666            image.setOutset(LengthBox());
     667            break;
     668        case Repeat:
     669            image.setHorizontalRule(StretchImageRule);
     670            image.setVerticalRule(StretchImageRule);
     671            break;
     672        case Slice:
     673            // Masks have a different initial value for slices. Preserve the value of 0 for backwards compatibility.
     674            image.setImageSlices(type == Image ? LengthBox(Length(100, Percent), Length(100, Percent), Length(100, Percent), Length(100, Percent)) : LengthBox());
     675            image.setFill(false);
     676            break;
     677        case Width:
     678            // Masks have a different initial value for widths. They use an 'auto' value rather than trying to fit to the border.
     679            image.setBorderSlices(type == Image ? LengthBox(Length(1, Relative), Length(1, Relative), Length(1, Relative), Length(1, Relative)) : LengthBox());
     680            break;
     681        }
     682        setValue(selector->style(), image);
     683    }
     684
     685    static void applyValue(CSSStyleSelector* selector, CSSValue* value)
     686    {
     687        NinePieceImage image(getValue(selector->style()));
     688        switch (modifier) {
     689        case Outset:
     690            image.setOutset(selector->mapNinePieceImageQuad(value));
     691            break;
     692        case Repeat:
     693            selector->mapNinePieceImageRepeat(value, image);
     694            break;
     695        case Slice:
     696            selector->mapNinePieceImageSlice(value, image);
     697            break;
     698        case Width:
     699            image.setBorderSlices(selector->mapNinePieceImageQuad(value));
     700            break;
     701        }
     702        setValue(selector->style(), image);
     703    }
     704
     705    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
    632706};
    633707
     
    12811355    setPropertyHandler(CSSPropertyWebkitMaskBoxImage, ApplyPropertyBorderImage<Mask, CSSPropertyWebkitMaskBoxImage, &RenderStyle::maskBoxImage, &RenderStyle::setMaskBoxImage, &CSSStyleSelector::mapNinePieceImage>::createHandler());
    12821356
     1357    setPropertyHandler(CSSPropertyBorderImageOutset, ApplyPropertyBorderImageModifier<Image, Outset>::createHandler());
     1358    setPropertyHandler(CSSPropertyWebkitMaskBoxImageOutset, ApplyPropertyBorderImageModifier<Mask, Outset>::createHandler());
     1359    setPropertyHandler(CSSPropertyBorderImageRepeat, ApplyPropertyBorderImageModifier<Image, Repeat>::createHandler());
     1360    setPropertyHandler(CSSPropertyWebkitMaskBoxImageRepeat, ApplyPropertyBorderImageModifier<Mask, Repeat>::createHandler());
     1361    setPropertyHandler(CSSPropertyBorderImageSlice, ApplyPropertyBorderImageModifier<Image, Slice>::createHandler());
     1362    setPropertyHandler(CSSPropertyWebkitMaskBoxImageSlice, ApplyPropertyBorderImageModifier<Mask, Slice>::createHandler());
     1363    setPropertyHandler(CSSPropertyBorderImageWidth, ApplyPropertyBorderImageModifier<Image, Width>::createHandler());
     1364    setPropertyHandler(CSSPropertyWebkitMaskBoxImageWidth, ApplyPropertyBorderImageModifier<Mask, Width>::createHandler());
     1365
    12831366    setPropertyHandler(CSSPropertyBorderTopLeftRadius, ApplyPropertyBorderRadius<&RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius, &RenderStyle::initialBorderRadius>::createHandler());
    12841367    setPropertyHandler(CSSPropertyBorderTopRightRadius, ApplyPropertyBorderRadius<&RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius, &RenderStyle::initialBorderRadius>::createHandler());
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r102183 r102188  
    31713171        HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(appearance, Appearance)
    31723172        return;
    3173     case CSSPropertyBorderImageOutset:
    3174     case CSSPropertyWebkitMaskBoxImageOutset: {
    3175         bool isBorderImage = id == CSSPropertyBorderImageOutset;
    3176         NinePieceImage image(isBorderImage ? m_style->borderImage() : m_style->maskBoxImage());
    3177         if (isInherit)
    3178             image.copyOutsetFrom(isBorderImage ? m_parentStyle->borderImage() : m_parentStyle->maskBoxImage());
    3179         else if (isInitial)
    3180             image.setOutset(LengthBox());
    3181         else
    3182             image.setOutset(mapNinePieceImageQuad(value));
    3183 
    3184         if (isBorderImage)
    3185             m_style->setBorderImage(image);
    3186         else
    3187             m_style->setMaskBoxImage(image);
    3188         return;
    3189     }
    3190     case CSSPropertyBorderImageRepeat:
    3191     case CSSPropertyWebkitMaskBoxImageRepeat: {
    3192         bool isBorderImage = id == CSSPropertyBorderImageRepeat;
    3193         NinePieceImage image(isBorderImage ? m_style->borderImage() : m_style->maskBoxImage());
    3194         if (isInherit)
    3195             image.copyRepeatFrom(isBorderImage ? m_parentStyle->borderImage() : m_parentStyle->maskBoxImage());
    3196         else if (isInitial) {
    3197             image.setHorizontalRule(StretchImageRule);
    3198             image.setVerticalRule(StretchImageRule);
    3199         } else
    3200             mapNinePieceImageRepeat(value, image);
    3201 
    3202         if (isBorderImage)
    3203             m_style->setBorderImage(image);
    3204         else
    3205             m_style->setMaskBoxImage(image);
    3206         return;
    3207     }
    3208     case CSSPropertyBorderImageSlice:
    3209     case CSSPropertyWebkitMaskBoxImageSlice: {
    3210         bool isBorderImage = id == CSSPropertyBorderImageSlice;
    3211         NinePieceImage image(isBorderImage ? m_style->borderImage() : m_style->maskBoxImage());
    3212         if (isInherit)
    3213             image.copyImageSlicesFrom(isBorderImage ? m_parentStyle->borderImage() : m_parentStyle->maskBoxImage());
    3214         else if (isInitial) {
    3215             // Masks have a different initial value for slices. Preserve the value of 0 for backwards compatibility.
    3216             image.setImageSlices(isBorderImage ? LengthBox(Length(100, Percent), Length(100, Percent), Length(100, Percent), Length(100, Percent)) : LengthBox());
    3217             image.setFill(false);
    3218         } else
    3219             mapNinePieceImageSlice(value, image);
    3220 
    3221         if (isBorderImage)
    3222             m_style->setBorderImage(image);
    3223         else
    3224             m_style->setMaskBoxImage(image);
    3225         return;
    3226     }
    3227     case CSSPropertyBorderImageWidth:
    3228     case CSSPropertyWebkitMaskBoxImageWidth: {
    3229         bool isBorderImage = id == CSSPropertyBorderImageWidth;
    3230         NinePieceImage image(isBorderImage ? m_style->borderImage() : m_style->maskBoxImage());
    3231         if (isInherit)
    3232             image.copyBorderSlicesFrom(isBorderImage ? m_parentStyle->borderImage() : m_parentStyle->maskBoxImage());
    3233         else if (isInitial) {
    3234             // Masks have a different initial value for slices. They use an 'auto' value rather than trying to fit to the border.
    3235             image.setBorderSlices(isBorderImage ? LengthBox(Length(1, Relative), Length(1, Relative), Length(1, Relative), Length(1, Relative)) : LengthBox());
    3236         } else
    3237             image.setBorderSlices(mapNinePieceImageQuad(value));
    3238 
    3239         if (isBorderImage)
    3240             m_style->setBorderImage(image);
    3241         else
    3242             m_style->setMaskBoxImage(image);
    3243         return;
    3244     }
    32453173    case CSSPropertyImageRendering:
    32463174        HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(imageRendering, ImageRendering);
     
    38733801    case CSSPropertyWebkitBorderImage:
    38743802    case CSSPropertyWebkitMaskBoxImage:
     3803    case CSSPropertyBorderImageOutset:
     3804    case CSSPropertyWebkitMaskBoxImageOutset:
     3805    case CSSPropertyBorderImageRepeat:
     3806    case CSSPropertyWebkitMaskBoxImageRepeat:
     3807    case CSSPropertyBorderImageSlice:
     3808    case CSSPropertyWebkitMaskBoxImageSlice:
     3809    case CSSPropertyBorderImageWidth:
     3810    case CSSPropertyWebkitMaskBoxImageWidth:
    38753811    case CSSPropertyBorderTop:
    38763812    case CSSPropertyBorderRight:
  • trunk/Source/WebCore/css/CSSStyleSelector.h

    r101899 r102188  
    331331    void mapAnimationTimingFunction(Animation*, CSSValue*);
    332332
     333public:
    333334    void mapNinePieceImage(CSSPropertyID, CSSValue*, NinePieceImage&);
    334335    void mapNinePieceImageSlice(CSSValue*, NinePieceImage&);
    335336    LengthBox mapNinePieceImageQuad(CSSValue*);
    336337    void mapNinePieceImageRepeat(CSSValue*, NinePieceImage&);
    337 
     338private:
    338339    bool canShareStyleWithControl(StyledElement*) const;
    339340
Note: See TracChangeset for help on using the changeset viewer.