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/RenderStyle.h"
     27 #include "core/rendering/style/ShadowList.h"
     28 #include "core/rendering/style/StyleFilterData.h"
     29 #include "core/rendering/style/StyleTransformData.h"
     30 #include "core/rendering/svg/ReferenceFilterBuilder.h"
     31 
     32 namespace WebCore {
     33 
     34 StyleRareNonInheritedData::StyleRareNonInheritedData()
     35     : opacity(RenderStyle::initialOpacity())
     36     , m_aspectRatioDenominator(RenderStyle::initialAspectRatioDenominator())
     37     , m_aspectRatioNumerator(RenderStyle::initialAspectRatioNumerator())
     38     , m_perspective(RenderStyle::initialPerspective())
     39     , m_perspectiveOriginX(RenderStyle::initialPerspectiveOriginX())
     40     , m_perspectiveOriginY(RenderStyle::initialPerspectiveOriginY())
     41     , lineClamp(RenderStyle::initialLineClamp())
     42     , m_draggableRegionMode(DraggableRegionNone)
     43     , m_mask(MaskFillLayer, true)
     44     , m_pageSize()
     45     , m_shapeInside(RenderStyle::initialShapeInside())
     46     , m_shapeOutside(RenderStyle::initialShapeOutside())
     47     , m_shapeMargin(RenderStyle::initialShapeMargin())
     48     , m_shapePadding(RenderStyle::initialShapePadding())
     49     , m_shapeImageThreshold(RenderStyle::initialShapeImageThreshold())
     50     , m_clipPath(RenderStyle::initialClipPath())
     51     , m_visitedLinkBackgroundColor(RenderStyle::initialBackgroundColor())
     52     , m_order(RenderStyle::initialOrder())
     53     , m_objectPosition(RenderStyle::initialObjectPosition())
     54     , m_flowThread(RenderStyle::initialFlowThread())
     55     , m_regionThread(RenderStyle::initialRegionThread())
     56     , m_regionFragment(RenderStyle::initialRegionFragment())
     57     , m_regionBreakAfter(RenderStyle::initialPageBreak())
     58     , m_regionBreakBefore(RenderStyle::initialPageBreak())
     59     , m_regionBreakInside(RenderStyle::initialPageBreak())
     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_alignSelf(RenderStyle::initialAlignSelf())
     66     , m_justifyContent(RenderStyle::initialJustifyContent())
     67     , userDrag(RenderStyle::initialUserDrag())
     68     , textOverflow(RenderStyle::initialTextOverflow())
     69     , marginBeforeCollapse(MCOLLAPSE)
     70     , marginAfterCollapse(MCOLLAPSE)
     71     , m_appearance(RenderStyle::initialAppearance())
     72     , m_borderFit(RenderStyle::initialBorderFit())
     73     , m_textCombine(RenderStyle::initialTextCombine())
     74     , m_textDecorationStyle(RenderStyle::initialTextDecorationStyle())
     75     , m_wrapFlow(RenderStyle::initialWrapFlow())
     76     , m_wrapThrough(RenderStyle::initialWrapThrough())
     77     , m_runningAcceleratedAnimation(false)
     78     , m_hasAspectRatio(false)
     79     , m_effectiveBlendMode(RenderStyle::initialBlendMode())
     80     , m_touchAction(RenderStyle::initialTouchAction())
     81     , m_objectFit(RenderStyle::initialObjectFit())
     82     , m_isolation(RenderStyle::initialIsolation())
     83 {
     84     m_maskBoxImage.setMaskDefaults();
     85 }
     86 
     87 StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInheritedData& o)
     88     : RefCounted<StyleRareNonInheritedData>()
     89     , opacity(o.opacity)
     90     , m_aspectRatioDenominator(o.m_aspectRatioDenominator)
     91     , m_aspectRatioNumerator(o.m_aspectRatioNumerator)
     92     , m_perspective(o.m_perspective)
     93     , m_perspectiveOriginX(o.m_perspectiveOriginX)
     94     , m_perspectiveOriginY(o.m_perspectiveOriginY)
     95     , lineClamp(o.lineClamp)
     96     , m_draggableRegionMode(o.m_draggableRegionMode)
     97     , m_deprecatedFlexibleBox(o.m_deprecatedFlexibleBox)
     98     , m_flexibleBox(o.m_flexibleBox)
     99     , m_marquee(o.m_marquee)
    100     , m_multiCol(o.m_multiCol)
    101     , m_transform(o.m_transform)
    102     , m_filter(o.m_filter)
    103     , m_grid(o.m_grid)
    104     , m_gridItem(o.m_gridItem)
    105     , m_content(o.m_content ? o.m_content->clone() : nullptr)
    106     , m_counterDirectives(o.m_counterDirectives ? clone(*o.m_counterDirectives) : nullptr)
    107     , m_boxShadow(o.m_boxShadow)
    108     , m_boxReflect(o.m_boxReflect)
    109     , m_animations(o.m_animations ? adoptPtr(new CSSAnimationDataList(*o.m_animations)) : nullptr)
    110     , m_transitions(o.m_transitions ? adoptPtr(new CSSAnimationDataList(*o.m_transitions)) : nullptr)
    111     , m_mask(o.m_mask)
    112     , m_maskBoxImage(o.m_maskBoxImage)
    113     , m_pageSize(o.m_pageSize)
    114     , m_shapeInside(o.m_shapeInside)
    115     , m_shapeOutside(o.m_shapeOutside)
    116     , m_shapeMargin(o.m_shapeMargin)
    117     , m_shapePadding(o.m_shapePadding)
    118     , m_shapeImageThreshold(o.m_shapeImageThreshold)
    119     , m_clipPath(o.m_clipPath)
    120     , m_textDecorationColor(o.m_textDecorationColor)
    121     , m_visitedLinkTextDecorationColor(o.m_visitedLinkTextDecorationColor)
    122     , m_visitedLinkBackgroundColor(o.m_visitedLinkBackgroundColor)
    123     , m_visitedLinkOutlineColor(o.m_visitedLinkOutlineColor)
    124     , m_visitedLinkBorderLeftColor(o.m_visitedLinkBorderLeftColor)
    125     , m_visitedLinkBorderRightColor(o.m_visitedLinkBorderRightColor)
    126     , m_visitedLinkBorderTopColor(o.m_visitedLinkBorderTopColor)
    127     , m_visitedLinkBorderBottomColor(o.m_visitedLinkBorderBottomColor)
    128     , m_order(o.m_order)
    129     , m_objectPosition(o.m_objectPosition)
    130     , m_flowThread(o.m_flowThread)
    131     , m_regionThread(o.m_regionThread)
    132     , m_regionFragment(o.m_regionFragment)
    133     , m_regionBreakAfter(o.m_regionBreakAfter)
    134     , m_regionBreakBefore(o.m_regionBreakBefore)
    135     , m_regionBreakInside(o.m_regionBreakInside)
    136     , m_pageSizeType(o.m_pageSizeType)
    137     , m_transformStyle3D(o.m_transformStyle3D)
    138     , m_backfaceVisibility(o.m_backfaceVisibility)
    139     , m_alignContent(o.m_alignContent)
    140     , m_alignItems(o.m_alignItems)
    141     , m_alignSelf(o.m_alignSelf)
    142     , m_justifyContent(o.m_justifyContent)
    143     , userDrag(o.userDrag)
    144     , textOverflow(o.textOverflow)
    145     , marginBeforeCollapse(o.marginBeforeCollapse)
    146     , marginAfterCollapse(o.marginAfterCollapse)
    147     , m_appearance(o.m_appearance)
    148     , m_borderFit(o.m_borderFit)
    149     , m_textCombine(o.m_textCombine)
    150     , m_textDecorationStyle(o.m_textDecorationStyle)
    151     , m_wrapFlow(o.m_wrapFlow)
    152     , m_wrapThrough(o.m_wrapThrough)
    153     , m_runningAcceleratedAnimation(o.m_runningAcceleratedAnimation)
    154     , m_hasAspectRatio(o.m_hasAspectRatio)
    155     , m_effectiveBlendMode(o.m_effectiveBlendMode)
    156     , m_touchAction(o.m_touchAction)
    157     , m_objectFit(o.m_objectFit)
    158     , m_isolation(o.m_isolation)
    159 {
    160 }
    161 
    162 StyleRareNonInheritedData::~StyleRareNonInheritedData()
    163 {
    164     const FilterOperations& filterOperations = m_filter->m_operations;
    165     for (unsigned i = 0; i < filterOperations.size(); ++i)
    166         ReferenceFilterBuilder::clearDocumentResourceReference(filterOperations.at(i));
    167 }
    168 
    169 bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) const
    170 {
    171     return opacity == o.opacity
    172         && m_aspectRatioDenominator == o.m_aspectRatioDenominator
    173         && m_aspectRatioNumerator == o.m_aspectRatioNumerator
    174         && m_perspective == o.m_perspective
    175         && m_perspectiveOriginX == o.m_perspectiveOriginX
    176         && m_perspectiveOriginY == o.m_perspectiveOriginY
    177         && lineClamp == o.lineClamp
    178         && m_draggableRegionMode == o.m_draggableRegionMode
    179         && m_deprecatedFlexibleBox == o.m_deprecatedFlexibleBox
    180         && m_flexibleBox == o.m_flexibleBox
    181         && m_marquee == o.m_marquee
    182         && m_multiCol == o.m_multiCol
    183         && m_transform == o.m_transform
    184         && m_filter == o.m_filter
    185         && m_grid == o.m_grid
    186         && m_gridItem == o.m_gridItem
    187         && contentDataEquivalent(o)
    188         && counterDataEquivalent(o)
    189         && shadowDataEquivalent(o)
    190         && reflectionDataEquivalent(o)
    191         && animationDataEquivalent(o)
    192         && transitionDataEquivalent(o)
    193         && m_mask == o.m_mask
    194         && m_maskBoxImage == o.m_maskBoxImage
    195         && m_pageSize == o.m_pageSize
    196         && m_shapeInside == o.m_shapeInside
    197         && m_shapeOutside == o.m_shapeOutside
    198         && m_shapeMargin == o.m_shapeMargin
    199         && m_shapePadding == o.m_shapePadding
    200         && m_shapeImageThreshold == o.m_shapeImageThreshold
    201         && m_clipPath == o.m_clipPath
    202         && m_textDecorationColor == o.m_textDecorationColor
    203         && m_visitedLinkTextDecorationColor == o.m_visitedLinkTextDecorationColor
    204         && m_visitedLinkBackgroundColor == o.m_visitedLinkBackgroundColor
    205         && m_visitedLinkOutlineColor == o.m_visitedLinkOutlineColor
    206         && m_visitedLinkBorderLeftColor == o.m_visitedLinkBorderLeftColor
    207         && m_visitedLinkBorderRightColor == o.m_visitedLinkBorderRightColor
    208         && m_visitedLinkBorderTopColor == o.m_visitedLinkBorderTopColor
    209         && m_visitedLinkBorderBottomColor == o.m_visitedLinkBorderBottomColor
    210         && m_order == o.m_order
    211         && m_objectPosition == o.m_objectPosition
    212         && m_callbackSelectors == o.m_callbackSelectors
    213         && m_flowThread == o.m_flowThread
    214         && m_regionThread == o.m_regionThread
    215         && m_regionFragment == o.m_regionFragment
    216         && m_regionBreakAfter == o.m_regionBreakAfter
    217         && m_regionBreakBefore == o.m_regionBreakBefore
    218         && m_regionBreakInside == o.m_regionBreakInside
    219         && m_pageSizeType == o.m_pageSizeType
    220         && m_transformStyle3D == o.m_transformStyle3D
    221         && m_backfaceVisibility == o.m_backfaceVisibility
    222         && m_alignContent == o.m_alignContent
    223         && m_alignItems == o.m_alignItems
    224         && m_alignSelf == o.m_alignSelf
    225         && m_justifyContent == o.m_justifyContent
    226         && userDrag == o.userDrag
    227         && textOverflow == o.textOverflow
    228         && marginBeforeCollapse == o.marginBeforeCollapse
    229         && marginAfterCollapse == o.marginAfterCollapse
    230         && m_appearance == o.m_appearance
    231         && m_borderFit == o.m_borderFit
    232         && m_textCombine == o.m_textCombine
    233         && m_textDecorationStyle == o.m_textDecorationStyle
    234         && m_wrapFlow == o.m_wrapFlow
    235         && m_wrapThrough == o.m_wrapThrough
    236         && !m_runningAcceleratedAnimation && !o.m_runningAcceleratedAnimation
    237         && m_effectiveBlendMode == o.m_effectiveBlendMode
    238         && m_hasAspectRatio == o.m_hasAspectRatio
    239         && m_touchAction == o.m_touchAction
    240         && m_objectFit == o.m_objectFit
    241         && m_isolation == o.m_isolation;
    242 }
    243 
    244 bool StyleRareNonInheritedData::contentDataEquivalent(const StyleRareNonInheritedData& o) const
    245 {
    246     ContentData* a = m_content.get();
    247     ContentData* b = o.m_content.get();
    248 
    249     while (a && b && *a == *b) {
    250         a = a->next();
    251         b = b->next();
    252     }
    253 
    254     return !a && !b;
    255 }
    256 
    257 bool StyleRareNonInheritedData::counterDataEquivalent(const StyleRareNonInheritedData& o) const
    258 {
    259     if (m_counterDirectives.get() == o.m_counterDirectives.get())
    260         return true;
    261 
    262     if (m_counterDirectives && o.m_counterDirectives && *m_counterDirectives == *o.m_counterDirectives)
    263         return true;
    264 
    265     return false;
    266 }
    267 
    268 bool StyleRareNonInheritedData::shadowDataEquivalent(const StyleRareNonInheritedData& o) const
    269 {
    270     if ((!m_boxShadow && o.m_boxShadow) || (m_boxShadow && !o.m_boxShadow))
    271         return false;
    272     if (m_boxShadow && o.m_boxShadow && (*m_boxShadow != *o.m_boxShadow))
    273         return false;
    274     return true;
    275 }
    276 
    277 bool StyleRareNonInheritedData::reflectionDataEquivalent(const StyleRareNonInheritedData& o) const
    278 {
    279     if (m_boxReflect != o.m_boxReflect) {
    280         if (!m_boxReflect || !o.m_boxReflect)
    281             return false;
    282         return *m_boxReflect == *o.m_boxReflect;
    283     }
    284     return true;
    285 }
    286 
    287 bool StyleRareNonInheritedData::animationDataEquivalent(const StyleRareNonInheritedData& o) const
    288 {
    289     if ((!m_animations && o.m_animations) || (m_animations && !o.m_animations))
    290         return false;
    291     if (m_animations && o.m_animations && (*m_animations != *o.m_animations))
    292         return false;
    293     return true;
    294 }
    295 
    296 bool StyleRareNonInheritedData::transitionDataEquivalent(const StyleRareNonInheritedData& o) const
    297 {
    298     if ((!m_transitions && o.m_transitions) || (m_transitions && !o.m_transitions))
    299         return false;
    300     if (m_transitions && o.m_transitions && (*m_transitions != *o.m_transitions))
    301         return false;
    302     return true;
    303 }
    304 
    305 bool StyleRareNonInheritedData::hasFilters() const
    306 {
    307     return m_filter.get() && !m_filter->m_operations.isEmpty();
    308 }
    309 
    310 } // namespace WebCore
    311