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, 2009, 2010 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/StyleRareInheritedData.h"
     24 
     25 #include "core/rendering/style/CursorList.h"
     26 #include "core/rendering/style/QuotesData.h"
     27 #include "core/rendering/style/RenderStyle.h"
     28 #include "core/rendering/style/RenderStyleConstants.h"
     29 #include "core/rendering/style/ShadowData.h"
     30 #include "core/rendering/style/StyleImage.h"
     31 
     32 namespace WebCore {
     33 
     34 struct SameSizeAsStyleRareInheritedData : public RefCounted<SameSizeAsStyleRareInheritedData> {
     35     void* styleImage;
     36     StyleColor firstColor;
     37     float firstFloat;
     38     StyleColor colors[5];
     39     void* ownPtrs[1];
     40     AtomicString atomicStrings[5];
     41     void* refPtrs[2];
     42     Length lengths[1];
     43     float secondFloat;
     44     unsigned m_bitfields[2];
     45     short pagedMediaShorts[2];
     46     unsigned unsigneds[1];
     47     short hyphenationShorts[3];
     48 
     49     StyleColor touchColors;
     50 
     51     void* variableDataRefs[1];
     52 };
     53 
     54 COMPILE_ASSERT(sizeof(StyleRareInheritedData) == sizeof(SameSizeAsStyleRareInheritedData), StyleRareInheritedData_should_bit_pack);
     55 
     56 StyleRareInheritedData::StyleRareInheritedData()
     57     : listStyleImage(RenderStyle::initialListStyleImage())
     58     , textStrokeWidth(RenderStyle::initialTextStrokeWidth())
     59     , indent(RenderStyle::initialTextIndent())
     60     , m_effectiveZoom(RenderStyle::initialZoom())
     61     , widows(RenderStyle::initialWidows())
     62     , orphans(RenderStyle::initialOrphans())
     63     , m_hasAutoWidows(true)
     64     , m_hasAutoOrphans(true)
     65     , textSecurity(RenderStyle::initialTextSecurity())
     66     , userModify(READ_ONLY)
     67     , wordBreak(RenderStyle::initialWordBreak())
     68     , overflowWrap(RenderStyle::initialOverflowWrap())
     69     , lineBreak(LineBreakAuto)
     70     , resize(RenderStyle::initialResize())
     71     , userSelect(RenderStyle::initialUserSelect())
     72     , speak(SpeakNormal)
     73     , hyphens(HyphensManual)
     74     , textEmphasisFill(TextEmphasisFillFilled)
     75     , textEmphasisMark(TextEmphasisMarkNone)
     76     , textEmphasisPosition(TextEmphasisPositionOver)
     77     , m_textAlignLast(RenderStyle::initialTextAlignLast())
     78     , m_textOrientation(TextOrientationVerticalRight)
     79 #if ENABLE(CSS3_TEXT)
     80     , m_textIndentLine(RenderStyle::initialTextIndentLine())
     81 #endif
     82     , m_lineBoxContain(RenderStyle::initialLineBoxContain())
     83     , m_imageRendering(RenderStyle::initialImageRendering())
     84     , m_lineSnap(RenderStyle::initialLineSnap())
     85     , m_lineAlign(RenderStyle::initialLineAlign())
     86 #if ENABLE(CSS3_TEXT)
     87     , m_textUnderlinePosition(RenderStyle::initialTextUnderlinePosition())
     88 #endif // CSS3_TEXT
     89     , m_rubyPosition(RenderStyle::initialRubyPosition())
     90     , hyphenationLimitBefore(-1)
     91     , hyphenationLimitAfter(-1)
     92     , hyphenationLimitLines(-1)
     93     , m_lineGrid(RenderStyle::initialLineGrid())
     94     , m_tabSize(RenderStyle::initialTabSize())
     95     , tapHighlightColor(RenderStyle::initialTapHighlightColor())
     96 {
     97     m_variables.init();
     98 }
     99 
    100 StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
    101     : RefCounted<StyleRareInheritedData>()
    102     , listStyleImage(o.listStyleImage)
    103     , textStrokeColor(o.textStrokeColor)
    104     , textStrokeWidth(o.textStrokeWidth)
    105     , textFillColor(o.textFillColor)
    106     , textEmphasisColor(o.textEmphasisColor)
    107     , visitedLinkTextStrokeColor(o.visitedLinkTextStrokeColor)
    108     , visitedLinkTextFillColor(o.visitedLinkTextFillColor)
    109     , visitedLinkTextEmphasisColor(o.visitedLinkTextEmphasisColor)
    110     , textShadow(cloneShadow(o.textShadow))
    111     , highlight(o.highlight)
    112     , cursorData(o.cursorData)
    113     , indent(o.indent)
    114     , m_effectiveZoom(o.m_effectiveZoom)
    115     , widows(o.widows)
    116     , orphans(o.orphans)
    117     , m_hasAutoWidows(o.m_hasAutoWidows)
    118     , m_hasAutoOrphans(o.m_hasAutoOrphans)
    119     , textSecurity(o.textSecurity)
    120     , userModify(o.userModify)
    121     , wordBreak(o.wordBreak)
    122     , overflowWrap(o.overflowWrap)
    123     , lineBreak(o.lineBreak)
    124     , resize(o.resize)
    125     , userSelect(o.userSelect)
    126     , speak(o.speak)
    127     , hyphens(o.hyphens)
    128     , textEmphasisFill(o.textEmphasisFill)
    129     , textEmphasisMark(o.textEmphasisMark)
    130     , textEmphasisPosition(o.textEmphasisPosition)
    131     , m_textAlignLast(o.m_textAlignLast)
    132     , m_textOrientation(o.m_textOrientation)
    133 #if ENABLE(CSS3_TEXT)
    134     , m_textIndentLine(o.m_textIndentLine)
    135 #endif
    136     , m_lineBoxContain(o.m_lineBoxContain)
    137     , m_imageRendering(o.m_imageRendering)
    138     , m_lineSnap(o.m_lineSnap)
    139     , m_lineAlign(o.m_lineAlign)
    140 #if ENABLE(CSS3_TEXT)
    141     , m_textUnderlinePosition(o.m_textUnderlinePosition)
    142 #endif // CSS3_TEXT
    143     , m_rubyPosition(o.m_rubyPosition)
    144     , hyphenationString(o.hyphenationString)
    145     , hyphenationLimitBefore(o.hyphenationLimitBefore)
    146     , hyphenationLimitAfter(o.hyphenationLimitAfter)
    147     , hyphenationLimitLines(o.hyphenationLimitLines)
    148     , locale(o.locale)
    149     , textEmphasisCustomMark(o.textEmphasisCustomMark)
    150     , m_lineGrid(o.m_lineGrid)
    151     , m_tabSize(o.m_tabSize)
    152     , tapHighlightColor(o.tapHighlightColor)
    153     , m_variables(o.m_variables)
    154 {
    155 }
    156 
    157 StyleRareInheritedData::~StyleRareInheritedData()
    158 {
    159 }
    160 
    161 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
    162 {
    163     if (c1 == c2)
    164         return true;
    165     if ((!c1 && c2) || (c1 && !c2))
    166         return false;
    167     return (*c1 == *c2);
    168 }
    169 
    170 bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
    171 {
    172     return textStrokeColor == o.textStrokeColor
    173         && textStrokeWidth == o.textStrokeWidth
    174         && textFillColor == o.textFillColor
    175         && textEmphasisColor == o.textEmphasisColor
    176         && visitedLinkTextStrokeColor == o.visitedLinkTextStrokeColor
    177         && visitedLinkTextFillColor == o.visitedLinkTextFillColor
    178         && visitedLinkTextEmphasisColor == o.visitedLinkTextEmphasisColor
    179         && tapHighlightColor == o.tapHighlightColor
    180         && shadowDataEquivalent(o)
    181         && highlight == o.highlight
    182         && cursorDataEquivalent(cursorData.get(), o.cursorData.get())
    183         && indent == o.indent
    184         && m_effectiveZoom == o.m_effectiveZoom
    185         && widows == o.widows
    186         && orphans == o.orphans
    187         && m_hasAutoWidows == o.m_hasAutoWidows
    188         && m_hasAutoOrphans == o.m_hasAutoOrphans
    189         && textSecurity == o.textSecurity
    190         && userModify == o.userModify
    191         && wordBreak == o.wordBreak
    192         && overflowWrap == o.overflowWrap
    193         && lineBreak == o.lineBreak
    194         && resize == o.resize
    195         && userSelect == o.userSelect
    196         && speak == o.speak
    197         && hyphens == o.hyphens
    198         && hyphenationLimitBefore == o.hyphenationLimitBefore
    199         && hyphenationLimitAfter == o.hyphenationLimitAfter
    200         && hyphenationLimitLines == o.hyphenationLimitLines
    201         && textEmphasisFill == o.textEmphasisFill
    202         && textEmphasisMark == o.textEmphasisMark
    203         && textEmphasisPosition == o.textEmphasisPosition
    204         && m_textAlignLast == o.m_textAlignLast
    205         && m_textOrientation == o.m_textOrientation
    206 #if ENABLE(CSS3_TEXT)
    207         && m_textIndentLine == o.m_textIndentLine
    208 #endif
    209         && m_lineBoxContain == o.m_lineBoxContain
    210         && hyphenationString == o.hyphenationString
    211         && locale == o.locale
    212         && textEmphasisCustomMark == o.textEmphasisCustomMark
    213         && QuotesData::equals(quotes.get(), o.quotes.get())
    214         && m_tabSize == o.m_tabSize
    215         && m_lineGrid == o.m_lineGrid
    216         && m_imageRendering == o.m_imageRendering
    217 #if ENABLE(CSS3_TEXT)
    218         && m_textUnderlinePosition == o.m_textUnderlinePosition
    219 #endif // CSS3_TEXT
    220         && m_rubyPosition == o.m_rubyPosition
    221         && m_lineSnap == o.m_lineSnap
    222         && m_variables == o.m_variables
    223         && m_lineAlign == o.m_lineAlign
    224         && StyleImage::imagesEquivalent(listStyleImage.get(), o.listStyleImage.get());
    225 }
    226 
    227 bool StyleRareInheritedData::shadowDataEquivalent(const StyleRareInheritedData& o) const
    228 {
    229     if ((!textShadow && o.textShadow) || (textShadow && !o.textShadow))
    230         return false;
    231     if (textShadow && o.textShadow && (*textShadow != *o.textShadow))
    232         return false;
    233     return true;
    234 }
    235 
    236 } // namespace WebCore
    237