Home | History | Annotate | Download | only in style
      1 /*
      2  * Copyright (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      3  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  *
     20  */
     21 
     22 #include "config.h"
     23 #include "core/rendering/style/StyleRareNonInheritedData.h"
     24 
     25 #include "core/rendering/style/ContentData.h"
     26 #include "core/rendering/style/DataEquivalency.h"
     27 #include "core/rendering/style/RenderStyle.h"
     28 #include "core/rendering/style/ShadowList.h"
     29 #include "core/rendering/style/StyleFilterData.h"
     30 #include "core/rendering/style/StyleTransformData.h"
     31 #include "core/rendering/svg/ReferenceFilterBuilder.h"
     32 
     33 namespace WebCore {
     34 
     35 StyleRareNonInheritedData::StyleRareNonInheritedData()
     36     : opacity(RenderStyle::initialOpacity())
     37     , m_aspectRatioDenominator(RenderStyle::initialAspectRatioDenominator())
     38     , m_aspectRatioNumerator(RenderStyle::initialAspectRatioNumerator())
     39     , m_perspective(RenderStyle::initialPerspective())
     40     , m_perspectiveOriginX(RenderStyle::initialPerspectiveOriginX())
     41     , m_perspectiveOriginY(RenderStyle::initialPerspectiveOriginY())
     42     , lineClamp(RenderStyle::initialLineClamp())
     43     , m_draggableRegionMode(DraggableRegionNone)
     44     , m_mask(MaskFillLayer, true)
     45     , m_pageSize()
     46     , m_shapeOutside(RenderStyle::initialShapeOutside())
     47     , m_shapeMargin(RenderStyle::initialShapeMargin())
     48     , m_shapeImageThreshold(RenderStyle::initialShapeImageThreshold())
     49     , m_clipPath(RenderStyle::initialClipPath())
     50     , m_textDecorationColor(StyleColor::currentColor())
     51     , m_visitedLinkTextDecorationColor(StyleColor::currentColor())
     52     , m_visitedLinkBackgroundColor(RenderStyle::initialBackgroundColor())
     53     , m_visitedLinkOutlineColor(StyleColor::currentColor())
     54     , m_visitedLinkBorderLeftColor(StyleColor::currentColor())
     55     , m_visitedLinkBorderRightColor(StyleColor::currentColor())
     56     , m_visitedLinkBorderTopColor(StyleColor::currentColor())
     57     , m_visitedLinkBorderBottomColor(StyleColor::currentColor())
     58     , m_order(RenderStyle::initialOrder())
     59     , m_objectPosition(RenderStyle::initialObjectPosition())
     60     , m_pageSizeType(PAGE_SIZE_AUTO)
     61     , m_transformStyle3D(RenderStyle::initialTransformStyle3D())
     62     , m_backfaceVisibility(RenderStyle::initialBackfaceVisibility())
     63     , m_alignContent(RenderStyle::initialAlignContent())
     64     , m_alignItems(RenderStyle::initialAlignItems())
     65     , m_alignItemsOverflowAlignment(RenderStyle::initialAlignItemsOverflowAlignment())
     66     , m_alignSelf(RenderStyle::initialAlignSelf())
     67     , m_alignSelfOverflowAlignment(RenderStyle::initialAlignSelfOverflowAlignment())
     68     , m_justifyContent(RenderStyle::initialJustifyContent())
     69     , userDrag(RenderStyle::initialUserDrag())
     70     , textOverflow(RenderStyle::initialTextOverflow())
     71     , marginBeforeCollapse(MCOLLAPSE)
     72     , marginAfterCollapse(MCOLLAPSE)
     73     , m_appearance(RenderStyle::initialAppearance())
     74     , m_borderFit(RenderStyle::initialBorderFit())
     75     , m_textCombine(RenderStyle::initialTextCombine())
     76     , m_textDecorationStyle(RenderStyle::initialTextDecorationStyle())
     77     , m_wrapFlow(RenderStyle::initialWrapFlow())
     78     , m_wrapThrough(RenderStyle::initialWrapThrough())
     79     , m_hasCurrentOpacityAnimation(false)
     80     , m_hasCurrentTransformAnimation(false)
     81     , m_hasCurrentFilterAnimation(false)
     82     , m_runningOpacityAnimationOnCompositor(false)
     83     , m_runningTransformAnimationOnCompositor(false)
     84     , m_runningFilterAnimationOnCompositor(false)
     85     , m_hasAspectRatio(false)
     86     , m_effectiveBlendMode(RenderStyle::initialBlendMode())
     87     , m_touchAction(RenderStyle::initialTouchAction())
     88     , m_objectFit(RenderStyle::initialObjectFit())
     89     , m_isolation(RenderStyle::initialIsolation())
     90     , m_justifySelf(RenderStyle::initialJustifySelf())
     91     , m_justifySelfOverflowAlignment(RenderStyle::initialJustifySelfOverflowAlignment())
     92     , m_scrollBehavior(RenderStyle::initialScrollBehavior())
     93     , m_requiresAcceleratedCompositingForExternalReasons(false)
     94 {
     95     m_maskBoxImage.setMaskDefaults();
     96 }
     97 
     98 StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInheritedData& o)
     99     : RefCounted<StyleRareNonInheritedData>()
    100     , opacity(o.opacity)
    101     , m_aspectRatioDenominator(o.m_aspectRatioDenominator)
    102     , m_aspectRatioNumerator(o.m_aspectRatioNumerator)
    103     , m_perspective(o.m_perspective)
    104     , m_perspectiveOriginX(o.m_perspectiveOriginX)
    105     , m_perspectiveOriginY(o.m_perspectiveOriginY)
    106     , lineClamp(o.lineClamp)
    107     , m_draggableRegionMode(o.m_draggableRegionMode)
    108     , m_deprecatedFlexibleBox(o.m_deprecatedFlexibleBox)
    109     , m_flexibleBox(o.m_flexibleBox)
    110     , m_marquee(o.m_marquee)
    111     , m_multiCol(o.m_multiCol)
    112     , m_transform(o.m_transform)
    113     , m_willChange(o.m_willChange)
    114     , m_filter(o.m_filter)
    115     , m_grid(o.m_grid)
    116     , m_gridItem(o.m_gridItem)
    117     , m_content(o.m_content ? o.m_content->clone() : nullptr)
    118     , m_counterDirectives(o.m_counterDirectives ? clone(*o.m_counterDirectives) : nullptr)
    119     , m_boxShadow(o.m_boxShadow)
    120     , m_boxReflect(o.m_boxReflect)
    121     , m_animations(o.m_animations ? CSSAnimationData::create(*o.m_animations) : nullptr)
    122     , m_transitions(o.m_transitions ? CSSTransitionData::create(*o.m_transitions) : nullptr)
    123     , m_mask(o.m_mask)
    124     , m_maskBoxImage(o.m_maskBoxImage)
    125     , m_pageSize(o.m_pageSize)
    126     , m_shapeOutside(o.m_shapeOutside)
    127     , m_shapeMargin(o.m_shapeMargin)
    128     , m_shapeImageThreshold(o.m_shapeImageThreshold)
    129     , m_clipPath(o.m_clipPath)
    130     , m_textDecorationColor(o.m_textDecorationColor)
    131     , m_visitedLinkTextDecorationColor(o.m_visitedLinkTextDecorationColor)
    132     , m_visitedLinkBackgroundColor(o.m_visitedLinkBackgroundColor)
    133     , m_visitedLinkOutlineColor(o.m_visitedLinkOutlineColor)
    134     , m_visitedLinkBorderLeftColor(o.m_visitedLinkBorderLeftColor)
    135     , m_visitedLinkBorderRightColor(o.m_visitedLinkBorderRightColor)
    136     , m_visitedLinkBorderTopColor(o.m_visitedLinkBorderTopColor)
    137     , m_visitedLinkBorderBottomColor(o.m_visitedLinkBorderBottomColor)
    138     , m_order(o.m_order)
    139     , m_objectPosition(o.m_objectPosition)
    140     , m_pageSizeType(o.m_pageSizeType)
    141     , m_transformStyle3D(o.m_transformStyle3D)
    142     , m_backfaceVisibility(o.m_backfaceVisibility)
    143     , m_alignContent(o.m_alignContent)
    144     , m_alignItems(o.m_alignItems)
    145     , m_alignItemsOverflowAlignment(o.m_alignItemsOverflowAlignment)
    146     , m_alignSelf(o.m_alignSelf)
    147     , m_alignSelfOverflowAlignment(o.m_alignSelfOverflowAlignment)
    148     , m_justifyContent(o.m_justifyContent)
    149     , userDrag(o.userDrag)
    150     , textOverflow(o.textOverflow)
    151     , marginBeforeCollapse(o.marginBeforeCollapse)
    152     , marginAfterCollapse(o.marginAfterCollapse)
    153     , m_appearance(o.m_appearance)
    154     , m_borderFit(o.m_borderFit)
    155     , m_textCombine(o.m_textCombine)
    156     , m_textDecorationStyle(o.m_textDecorationStyle)
    157     , m_wrapFlow(o.m_wrapFlow)
    158     , m_wrapThrough(o.m_wrapThrough)
    159     , m_hasCurrentOpacityAnimation(o.m_hasCurrentOpacityAnimation)
    160     , m_hasCurrentTransformAnimation(o.m_hasCurrentTransformAnimation)
    161     , m_hasCurrentFilterAnimation(o.m_hasCurrentFilterAnimation)
    162     , m_runningOpacityAnimationOnCompositor(o.m_runningOpacityAnimationOnCompositor)
    163     , m_runningTransformAnimationOnCompositor(o.m_runningTransformAnimationOnCompositor)
    164     , m_runningFilterAnimationOnCompositor(o.m_runningFilterAnimationOnCompositor)
    165     , m_hasAspectRatio(o.m_hasAspectRatio)
    166     , m_effectiveBlendMode(o.m_effectiveBlendMode)
    167     , m_touchAction(o.m_touchAction)
    168     , m_objectFit(o.m_objectFit)
    169     , m_isolation(o.m_isolation)
    170     , m_justifySelf(o.m_justifySelf)
    171     , m_justifySelfOverflowAlignment(o.m_justifySelfOverflowAlignment)
    172     , m_scrollBehavior(o.m_scrollBehavior)
    173     , m_requiresAcceleratedCompositingForExternalReasons(o.m_requiresAcceleratedCompositingForExternalReasons)
    174 {
    175 }
    176 
    177 StyleRareNonInheritedData::~StyleRareNonInheritedData()
    178 {
    179     const FilterOperations& filterOperations = m_filter->m_operations;
    180     for (unsigned i = 0; i < filterOperations.size(); ++i)
    181         ReferenceFilterBuilder::clearDocumentResourceReference(filterOperations.at(i));
    182 }
    183 
    184 bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) const
    185 {
    186     return opacity == o.opacity
    187         && m_aspectRatioDenominator == o.m_aspectRatioDenominator
    188         && m_aspectRatioNumerator == o.m_aspectRatioNumerator
    189         && m_perspective == o.m_perspective
    190         && m_perspectiveOriginX == o.m_perspectiveOriginX
    191         && m_perspectiveOriginY == o.m_perspectiveOriginY
    192         && lineClamp == o.lineClamp
    193         && m_draggableRegionMode == o.m_draggableRegionMode
    194         && m_deprecatedFlexibleBox == o.m_deprecatedFlexibleBox
    195         && m_flexibleBox == o.m_flexibleBox
    196         && m_marquee == o.m_marquee
    197         && m_multiCol == o.m_multiCol
    198         && m_transform == o.m_transform
    199         && m_willChange == o.m_willChange
    200         && m_filter == o.m_filter
    201         && m_grid == o.m_grid
    202         && m_gridItem == o.m_gridItem
    203         && contentDataEquivalent(o)
    204         && counterDataEquivalent(o)
    205         && shadowDataEquivalent(o)
    206         && reflectionDataEquivalent(o)
    207         && animationDataEquivalent(o)
    208         && transitionDataEquivalent(o)
    209         && m_mask == o.m_mask
    210         && m_maskBoxImage == o.m_maskBoxImage
    211         && m_pageSize == o.m_pageSize
    212         && m_shapeOutside == o.m_shapeOutside
    213         && m_shapeMargin == o.m_shapeMargin
    214         && m_shapeImageThreshold == o.m_shapeImageThreshold
    215         && m_clipPath == o.m_clipPath
    216         && m_textDecorationColor == o.m_textDecorationColor
    217         && m_visitedLinkTextDecorationColor == o.m_visitedLinkTextDecorationColor
    218         && m_visitedLinkBackgroundColor == o.m_visitedLinkBackgroundColor
    219         && m_visitedLinkOutlineColor == o.m_visitedLinkOutlineColor
    220         && m_visitedLinkBorderLeftColor == o.m_visitedLinkBorderLeftColor
    221         && m_visitedLinkBorderRightColor == o.m_visitedLinkBorderRightColor
    222         && m_visitedLinkBorderTopColor == o.m_visitedLinkBorderTopColor
    223         && m_visitedLinkBorderBottomColor == o.m_visitedLinkBorderBottomColor
    224         && m_order == o.m_order
    225         && m_objectPosition == o.m_objectPosition
    226         && m_callbackSelectors == o.m_callbackSelectors
    227         && m_pageSizeType == o.m_pageSizeType
    228         && m_transformStyle3D == o.m_transformStyle3D
    229         && m_backfaceVisibility == o.m_backfaceVisibility
    230         && m_alignContent == o.m_alignContent
    231         && m_alignItems == o.m_alignItems
    232         && m_alignItemsOverflowAlignment == o.m_alignItemsOverflowAlignment
    233         && m_alignSelf == o.m_alignSelf
    234         && m_alignSelfOverflowAlignment == o.m_alignSelfOverflowAlignment
    235         && m_justifyContent == o.m_justifyContent
    236         && userDrag == o.userDrag
    237         && textOverflow == o.textOverflow
    238         && marginBeforeCollapse == o.marginBeforeCollapse
    239         && marginAfterCollapse == o.marginAfterCollapse
    240         && m_appearance == o.m_appearance
    241         && m_borderFit == o.m_borderFit
    242         && m_textCombine == o.m_textCombine
    243         && m_textDecorationStyle == o.m_textDecorationStyle
    244         && m_wrapFlow == o.m_wrapFlow
    245         && m_wrapThrough == o.m_wrapThrough
    246         && m_hasCurrentOpacityAnimation == o.m_hasCurrentOpacityAnimation
    247         && m_hasCurrentTransformAnimation == o.m_hasCurrentTransformAnimation
    248         && m_hasCurrentFilterAnimation == o.m_hasCurrentFilterAnimation
    249         && m_effectiveBlendMode == o.m_effectiveBlendMode
    250         && m_hasAspectRatio == o.m_hasAspectRatio
    251         && m_touchAction == o.m_touchAction
    252         && m_objectFit == o.m_objectFit
    253         && m_isolation == o.m_isolation
    254         && m_justifySelf == o.m_justifySelf
    255         && m_justifySelfOverflowAlignment == o.m_justifySelfOverflowAlignment
    256         && m_scrollBehavior == o.m_scrollBehavior
    257         && m_requiresAcceleratedCompositingForExternalReasons == o.m_requiresAcceleratedCompositingForExternalReasons;
    258 }
    259 
    260 bool StyleRareNonInheritedData::contentDataEquivalent(const StyleRareNonInheritedData& o) const
    261 {
    262     ContentData* a = m_content.get();
    263     ContentData* b = o.m_content.get();
    264 
    265     while (a && b && *a == *b) {
    266         a = a->next();
    267         b = b->next();
    268     }
    269 
    270     return !a && !b;
    271 }
    272 
    273 bool StyleRareNonInheritedData::counterDataEquivalent(const StyleRareNonInheritedData& o) const
    274 {
    275     return dataEquivalent(m_counterDirectives, o.m_counterDirectives);
    276 }
    277 
    278 bool StyleRareNonInheritedData::shadowDataEquivalent(const StyleRareNonInheritedData& o) const
    279 {
    280     return dataEquivalent(m_boxShadow, o.m_boxShadow);
    281 }
    282 
    283 bool StyleRareNonInheritedData::reflectionDataEquivalent(const StyleRareNonInheritedData& o) const
    284 {
    285     return dataEquivalent(m_boxReflect, o.m_boxReflect);
    286 }
    287 
    288 bool StyleRareNonInheritedData::animationDataEquivalent(const StyleRareNonInheritedData& o) const
    289 {
    290     if (!m_animations && !o.m_animations)
    291         return true;
    292     if (!m_animations || !o.m_animations)
    293         return false;
    294     return m_animations->animationsMatchForStyleRecalc(*o.m_animations);
    295 }
    296 
    297 bool StyleRareNonInheritedData::transitionDataEquivalent(const StyleRareNonInheritedData& o) const
    298 {
    299     if (!m_transitions && !o.m_transitions)
    300         return true;
    301     if (!m_transitions || !o.m_transitions)
    302         return false;
    303     return m_transitions->transitionsMatchForStyleRecalc(*o.m_transitions);
    304 }
    305 
    306 bool StyleRareNonInheritedData::hasFilters() const
    307 {
    308     return m_filter.get() && !m_filter->m_operations.isEmpty();
    309 }
    310 
    311 } // namespace WebCore
    312