• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Antti Koivisto (koivisto@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 "RenderStyle.h"
24 
25 #include "CSSStyleSelector.h"
26 #include "CachedImage.h"
27 #include "CounterContent.h"
28 #include "FontSelector.h"
29 #include "RenderArena.h"
30 #include "RenderObject.h"
31 #include "StyleImage.h"
32 #include <wtf/StdLibExtras.h>
33 #include <algorithm>
34 
35 using namespace std;
36 
37 namespace WebCore {
38 
defaultStyle()39 inline RenderStyle* defaultStyle()
40 {
41     static RenderStyle* s_defaultStyle = RenderStyle::createDefaultStyle().releaseRef();
42     return s_defaultStyle;
43 }
44 
create()45 PassRefPtr<RenderStyle> RenderStyle::create()
46 {
47     return adoptRef(new RenderStyle());
48 }
49 
createDefaultStyle()50 PassRefPtr<RenderStyle> RenderStyle::createDefaultStyle()
51 {
52     return adoptRef(new RenderStyle(true));
53 }
54 
clone(const RenderStyle * other)55 PassRefPtr<RenderStyle> RenderStyle::clone(const RenderStyle* other)
56 {
57     return adoptRef(new RenderStyle(*other));
58 }
59 
RenderStyle()60 RenderStyle::RenderStyle()
61     : m_pseudoState(PseudoUnknown)
62     , m_affectedByAttributeSelectors(false)
63     , m_unique(false)
64     , m_affectedByEmpty(false)
65     , m_emptyState(false)
66     , m_childrenAffectedByFirstChildRules(false)
67     , m_childrenAffectedByLastChildRules(false)
68     , m_childrenAffectedByDirectAdjacentRules(false)
69     , m_childrenAffectedByForwardPositionalRules(false)
70     , m_childrenAffectedByBackwardPositionalRules(false)
71     , m_firstChildState(false)
72     , m_lastChildState(false)
73     , m_childIndex(0)
74     , box(defaultStyle()->box)
75     , visual(defaultStyle()->visual)
76     , background(defaultStyle()->background)
77     , surround(defaultStyle()->surround)
78     , rareNonInheritedData(defaultStyle()->rareNonInheritedData)
79     , rareInheritedData(defaultStyle()->rareInheritedData)
80     , inherited(defaultStyle()->inherited)
81 #if ENABLE(SVG)
82     , m_svgStyle(defaultStyle()->m_svgStyle)
83 #endif
84 {
85     setBitDefaults(); // Would it be faster to copy this from the default style?
86 }
87 
RenderStyle(bool)88 RenderStyle::RenderStyle(bool)
89     : m_pseudoState(PseudoUnknown)
90     , m_affectedByAttributeSelectors(false)
91     , m_unique(false)
92     , m_affectedByEmpty(false)
93     , m_emptyState(false)
94     , m_childrenAffectedByFirstChildRules(false)
95     , m_childrenAffectedByLastChildRules(false)
96     , m_childrenAffectedByDirectAdjacentRules(false)
97     , m_childrenAffectedByForwardPositionalRules(false)
98     , m_childrenAffectedByBackwardPositionalRules(false)
99     , m_firstChildState(false)
100     , m_lastChildState(false)
101     , m_childIndex(0)
102 {
103     setBitDefaults();
104 
105     box.init();
106     visual.init();
107     background.init();
108     surround.init();
109     rareNonInheritedData.init();
110     rareNonInheritedData.access()->flexibleBox.init();
111     rareNonInheritedData.access()->marquee.init();
112     rareNonInheritedData.access()->m_multiCol.init();
113     rareNonInheritedData.access()->m_transform.init();
114     rareInheritedData.init();
115     inherited.init();
116 
117 #if ENABLE(SVG)
118     m_svgStyle.init();
119 #endif
120 }
121 
RenderStyle(const RenderStyle & o)122 RenderStyle::RenderStyle(const RenderStyle& o)
123     : RefCounted<RenderStyle>()
124     , m_pseudoState(o.m_pseudoState)
125     , m_affectedByAttributeSelectors(false)
126     , m_unique(false)
127     , m_affectedByEmpty(false)
128     , m_emptyState(false)
129     , m_childrenAffectedByFirstChildRules(false)
130     , m_childrenAffectedByLastChildRules(false)
131     , m_childrenAffectedByDirectAdjacentRules(false)
132     , m_childrenAffectedByForwardPositionalRules(false)
133     , m_childrenAffectedByBackwardPositionalRules(false)
134     , m_firstChildState(false)
135     , m_lastChildState(false)
136     , m_childIndex(0)
137     , box(o.box)
138     , visual(o.visual)
139     , background(o.background)
140     , surround(o.surround)
141     , rareNonInheritedData(o.rareNonInheritedData)
142     , rareInheritedData(o.rareInheritedData)
143     , inherited(o.inherited)
144 #if ENABLE(SVG)
145     , m_svgStyle(o.m_svgStyle)
146 #endif
147     , inherited_flags(o.inherited_flags)
148     , noninherited_flags(o.noninherited_flags)
149 {
150 }
151 
inheritFrom(const RenderStyle * inheritParent)152 void RenderStyle::inheritFrom(const RenderStyle* inheritParent)
153 {
154     rareInheritedData = inheritParent->rareInheritedData;
155     inherited = inheritParent->inherited;
156     inherited_flags = inheritParent->inherited_flags;
157 #if ENABLE(SVG)
158     if (m_svgStyle != inheritParent->m_svgStyle)
159         m_svgStyle.access()->inheritFrom(inheritParent->m_svgStyle.get());
160 #endif
161 }
162 
~RenderStyle()163 RenderStyle::~RenderStyle()
164 {
165 }
166 
operator ==(const RenderStyle & o) const167 bool RenderStyle::operator==(const RenderStyle& o) const
168 {
169     // compare everything except the pseudoStyle pointer
170     return inherited_flags == o.inherited_flags &&
171             noninherited_flags == o.noninherited_flags &&
172             box == o.box &&
173             visual == o.visual &&
174             background == o.background &&
175             surround == o.surround &&
176             rareNonInheritedData == o.rareNonInheritedData &&
177             rareInheritedData == o.rareInheritedData &&
178             inherited == o.inherited
179 #if ENABLE(SVG)
180             && m_svgStyle == o.m_svgStyle
181 #endif
182             ;
183 }
184 
isStyleAvailable() const185 bool RenderStyle::isStyleAvailable() const
186 {
187     return this != CSSStyleSelector::styleNotYetAvailable();
188 }
189 
pseudoBit(PseudoId pseudo)190 static inline int pseudoBit(PseudoId pseudo)
191 {
192     return 1 << (pseudo - 1);
193 }
194 
hasPseudoStyle(PseudoId pseudo) const195 bool RenderStyle::hasPseudoStyle(PseudoId pseudo) const
196 {
197     ASSERT(pseudo > NOPSEUDO);
198     ASSERT(pseudo < FIRST_INTERNAL_PSEUDOID);
199     return pseudoBit(pseudo) & noninherited_flags._pseudoBits;
200 }
201 
setHasPseudoStyle(PseudoId pseudo)202 void RenderStyle::setHasPseudoStyle(PseudoId pseudo)
203 {
204     ASSERT(pseudo > NOPSEUDO);
205     ASSERT(pseudo < FIRST_INTERNAL_PSEUDOID);
206     noninherited_flags._pseudoBits |= pseudoBit(pseudo);
207 }
208 
getCachedPseudoStyle(PseudoId pid) const209 RenderStyle* RenderStyle::getCachedPseudoStyle(PseudoId pid) const
210 {
211     if (!m_cachedPseudoStyle || styleType() != NOPSEUDO)
212         return 0;
213     RenderStyle* ps = m_cachedPseudoStyle.get();
214     while (ps && ps->styleType() != pid)
215         ps = ps->m_cachedPseudoStyle.get();
216     return ps;
217 }
218 
addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo)219 RenderStyle* RenderStyle::addCachedPseudoStyle(PassRefPtr<RenderStyle> pseudo)
220 {
221     if (!pseudo)
222         return 0;
223     pseudo->m_cachedPseudoStyle = m_cachedPseudoStyle;
224     m_cachedPseudoStyle = pseudo;
225     return m_cachedPseudoStyle.get();
226 }
227 
getPseudoStyleCache(PseudoStyleCache & cache) const228 void RenderStyle::getPseudoStyleCache(PseudoStyleCache& cache) const
229 {
230     ASSERT(cache.isEmpty());
231     for (RenderStyle* pseudoStyle = m_cachedPseudoStyle.get(); pseudoStyle; pseudoStyle = pseudoStyle->m_cachedPseudoStyle.get())
232         cache.append(pseudoStyle);
233 }
234 
inheritedNotEqual(const RenderStyle * other) const235 bool RenderStyle::inheritedNotEqual(const RenderStyle* other) const
236 {
237     return inherited_flags != other->inherited_flags ||
238            inherited != other->inherited ||
239 #if ENABLE(SVG)
240            m_svgStyle->inheritedNotEqual(other->m_svgStyle.get()) ||
241 #endif
242            rareInheritedData != other->rareInheritedData;
243 }
244 
positionedObjectMoved(const LengthBox & a,const LengthBox & b)245 static bool positionedObjectMoved(const LengthBox& a, const LengthBox& b)
246 {
247     // If any unit types are different, then we can't guarantee
248     // that this was just a movement.
249     if (a.left().type() != b.left().type() ||
250         a.right().type() != b.right().type() ||
251         a.top().type() != b.top().type() ||
252         a.bottom().type() != b.bottom().type())
253         return false;
254 
255     // Only one unit can be non-auto in the horizontal direction and
256     // in the vertical direction.  Otherwise the adjustment of values
257     // is changing the size of the box.
258     if (!a.left().isIntrinsicOrAuto() && !a.right().isIntrinsicOrAuto())
259         return false;
260     if (!a.top().isIntrinsicOrAuto() && !a.bottom().isIntrinsicOrAuto())
261         return false;
262 
263     // One of the units is fixed or percent in both directions and stayed
264     // that way in the new style.  Therefore all we are doing is moving.
265     return true;
266 }
267 
268 /*
269   compares two styles. The result gives an idea of the action that
270   needs to be taken when replacing the old style with a new one.
271 
272   CbLayout: The containing block of the object needs a relayout.
273   Layout: the RenderObject needs a relayout after the style change
274   Visible: The change is visible, but no relayout is needed
275   NonVisible: The object does need neither repaint nor relayout after
276        the change.
277 
278   ### TODO:
279   A lot can be optimised here based on the display type, lots of
280   optimisations are unimplemented, and currently result in the
281   worst case result causing a relayout of the containing block.
282 */
diff(const RenderStyle * other,unsigned & changedContextSensitiveProperties) const283 StyleDifference RenderStyle::diff(const RenderStyle* other, unsigned& changedContextSensitiveProperties) const
284 {
285     changedContextSensitiveProperties = ContextSensitivePropertyNone;
286 
287 #if ENABLE(SVG)
288     // This is horribly inefficient.  Eventually we'll have to integrate
289     // this more directly by calling: Diff svgDiff = svgStyle->diff(other)
290     // and then checking svgDiff and returning from the appropriate places below.
291     if (m_svgStyle != other->m_svgStyle)
292         return StyleDifferenceLayout;
293 #endif
294 
295     if (box->width != other->box->width ||
296         box->min_width != other->box->min_width ||
297         box->max_width != other->box->max_width ||
298         box->height != other->box->height ||
299         box->min_height != other->box->min_height ||
300         box->max_height != other->box->max_height)
301         return StyleDifferenceLayout;
302 
303     if (box->vertical_align != other->box->vertical_align || noninherited_flags._vertical_align != other->noninherited_flags._vertical_align)
304         return StyleDifferenceLayout;
305 
306     if (box->boxSizing != other->box->boxSizing)
307         return StyleDifferenceLayout;
308 
309     if (surround->margin != other->surround->margin)
310         return StyleDifferenceLayout;
311 
312     if (surround->padding != other->surround->padding)
313         return StyleDifferenceLayout;
314 
315     if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
316         if (rareNonInheritedData->m_appearance != other->rareNonInheritedData->m_appearance ||
317             rareNonInheritedData->marginTopCollapse != other->rareNonInheritedData->marginTopCollapse ||
318             rareNonInheritedData->marginBottomCollapse != other->rareNonInheritedData->marginBottomCollapse ||
319             rareNonInheritedData->lineClamp != other->rareNonInheritedData->lineClamp ||
320             rareNonInheritedData->textOverflow != other->rareNonInheritedData->textOverflow)
321             return StyleDifferenceLayout;
322 
323         if (rareNonInheritedData->flexibleBox.get() != other->rareNonInheritedData->flexibleBox.get() &&
324             *rareNonInheritedData->flexibleBox.get() != *other->rareNonInheritedData->flexibleBox.get())
325             return StyleDifferenceLayout;
326 
327         // FIXME: We should add an optimized form of layout that just recomputes visual overflow.
328         if (!rareNonInheritedData->shadowDataEquivalent(*other->rareNonInheritedData.get()))
329             return StyleDifferenceLayout;
330 
331         if (!rareNonInheritedData->reflectionDataEquivalent(*other->rareNonInheritedData.get()))
332             return StyleDifferenceLayout;
333 
334         if (rareNonInheritedData->m_multiCol.get() != other->rareNonInheritedData->m_multiCol.get() &&
335             *rareNonInheritedData->m_multiCol.get() != *other->rareNonInheritedData->m_multiCol.get())
336             return StyleDifferenceLayout;
337 
338         if (rareNonInheritedData->m_transform.get() != other->rareNonInheritedData->m_transform.get() &&
339             *rareNonInheritedData->m_transform.get() != *other->rareNonInheritedData->m_transform.get()) {
340 #if USE(ACCELERATED_COMPOSITING)
341             changedContextSensitiveProperties |= ContextSensitivePropertyTransform;
342             // Don't return; keep looking for another change
343 #else
344             return StyleDifferenceLayout;
345 #endif
346         }
347 
348 #if !USE(ACCELERATED_COMPOSITING)
349         if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
350             if (rareNonInheritedData->m_transformStyle3D != other->rareNonInheritedData->m_transformStyle3D ||
351                 rareNonInheritedData->m_backfaceVisibility != other->rareNonInheritedData->m_backfaceVisibility ||
352                 rareNonInheritedData->m_perspective != other->rareNonInheritedData->m_perspective ||
353                 rareNonInheritedData->m_perspectiveOriginX != other->rareNonInheritedData->m_perspectiveOriginX ||
354                 rareNonInheritedData->m_perspectiveOriginY != other->rareNonInheritedData->m_perspectiveOriginY)
355                 return StyleDifferenceLayout;
356         }
357 #endif
358 
359 #if ENABLE(DASHBOARD_SUPPORT)
360         // If regions change, trigger a relayout to re-calc regions.
361         if (rareNonInheritedData->m_dashboardRegions != other->rareNonInheritedData->m_dashboardRegions)
362             return StyleDifferenceLayout;
363 #endif
364     }
365 
366     if (rareInheritedData.get() != other->rareInheritedData.get()) {
367         if (rareInheritedData->highlight != other->rareInheritedData->highlight ||
368             rareInheritedData->textSizeAdjust != other->rareInheritedData->textSizeAdjust ||
369             rareInheritedData->wordBreak != other->rareInheritedData->wordBreak ||
370             rareInheritedData->wordWrap != other->rareInheritedData->wordWrap ||
371             rareInheritedData->nbspMode != other->rareInheritedData->nbspMode ||
372             rareInheritedData->khtmlLineBreak != other->rareInheritedData->khtmlLineBreak ||
373             rareInheritedData->textSecurity != other->rareInheritedData->textSecurity)
374             return StyleDifferenceLayout;
375 
376         if (!rareInheritedData->shadowDataEquivalent(*other->rareInheritedData.get()))
377             return StyleDifferenceLayout;
378 
379         if (textStrokeWidth() != other->textStrokeWidth())
380             return StyleDifferenceLayout;
381     }
382 
383     if (inherited->indent != other->inherited->indent ||
384         inherited->line_height != other->inherited->line_height ||
385         inherited->list_style_image != other->inherited->list_style_image ||
386         inherited->font != other->inherited->font ||
387         inherited->horizontal_border_spacing != other->inherited->horizontal_border_spacing ||
388         inherited->vertical_border_spacing != other->inherited->vertical_border_spacing ||
389         inherited_flags._box_direction != other->inherited_flags._box_direction ||
390         inherited_flags._visuallyOrdered != other->inherited_flags._visuallyOrdered ||
391         inherited_flags._htmlHacks != other->inherited_flags._htmlHacks ||
392         noninherited_flags._position != other->noninherited_flags._position ||
393         noninherited_flags._floating != other->noninherited_flags._floating ||
394         noninherited_flags._originalDisplay != other->noninherited_flags._originalDisplay)
395         return StyleDifferenceLayout;
396 
397 
398     if (((int)noninherited_flags._effectiveDisplay) >= TABLE) {
399         if (inherited_flags._border_collapse != other->inherited_flags._border_collapse ||
400             inherited_flags._empty_cells != other->inherited_flags._empty_cells ||
401             inherited_flags._caption_side != other->inherited_flags._caption_side ||
402             noninherited_flags._table_layout != other->noninherited_flags._table_layout)
403             return StyleDifferenceLayout;
404 
405         // In the collapsing border model, 'hidden' suppresses other borders, while 'none'
406         // does not, so these style differences can be width differences.
407         if (inherited_flags._border_collapse &&
408             ((borderTopStyle() == BHIDDEN && other->borderTopStyle() == BNONE) ||
409              (borderTopStyle() == BNONE && other->borderTopStyle() == BHIDDEN) ||
410              (borderBottomStyle() == BHIDDEN && other->borderBottomStyle() == BNONE) ||
411              (borderBottomStyle() == BNONE && other->borderBottomStyle() == BHIDDEN) ||
412              (borderLeftStyle() == BHIDDEN && other->borderLeftStyle() == BNONE) ||
413              (borderLeftStyle() == BNONE && other->borderLeftStyle() == BHIDDEN) ||
414              (borderRightStyle() == BHIDDEN && other->borderRightStyle() == BNONE) ||
415              (borderRightStyle() == BNONE && other->borderRightStyle() == BHIDDEN)))
416             return StyleDifferenceLayout;
417     }
418 
419     if (noninherited_flags._effectiveDisplay == LIST_ITEM) {
420         if (inherited_flags._list_style_type != other->inherited_flags._list_style_type ||
421             inherited_flags._list_style_position != other->inherited_flags._list_style_position)
422             return StyleDifferenceLayout;
423     }
424 
425     if (inherited_flags._text_align != other->inherited_flags._text_align ||
426         inherited_flags._text_transform != other->inherited_flags._text_transform ||
427         inherited_flags._direction != other->inherited_flags._direction ||
428         inherited_flags._white_space != other->inherited_flags._white_space ||
429         noninherited_flags._clear != other->noninherited_flags._clear)
430         return StyleDifferenceLayout;
431 
432     // Overflow returns a layout hint.
433     if (noninherited_flags._overflowX != other->noninherited_flags._overflowX ||
434         noninherited_flags._overflowY != other->noninherited_flags._overflowY)
435         return StyleDifferenceLayout;
436 
437     // If our border widths change, then we need to layout.  Other changes to borders
438     // only necessitate a repaint.
439     if (borderLeftWidth() != other->borderLeftWidth() ||
440         borderTopWidth() != other->borderTopWidth() ||
441         borderBottomWidth() != other->borderBottomWidth() ||
442         borderRightWidth() != other->borderRightWidth())
443         return StyleDifferenceLayout;
444 
445     // If the counter directives change, trigger a relayout to re-calculate counter values and rebuild the counter node tree.
446     const CounterDirectiveMap* mapA = rareNonInheritedData->m_counterDirectives.get();
447     const CounterDirectiveMap* mapB = other->rareNonInheritedData->m_counterDirectives.get();
448     if (!(mapA == mapB || (mapA && mapB && *mapA == *mapB)))
449         return StyleDifferenceLayout;
450     if (visual->counterIncrement != other->visual->counterIncrement ||
451         visual->counterReset != other->visual->counterReset)
452         return StyleDifferenceLayout;
453 
454     if (inherited->m_effectiveZoom != other->inherited->m_effectiveZoom)
455         return StyleDifferenceLayout;
456 
457     if ((rareNonInheritedData->opacity == 1 && other->rareNonInheritedData->opacity < 1) ||
458         (rareNonInheritedData->opacity < 1 && other->rareNonInheritedData->opacity == 1)) {
459         // FIXME: We should add an optimized form of layout that just recomputes visual overflow.
460         return StyleDifferenceLayout;
461     }
462 
463     // Make sure these left/top/right/bottom checks stay below all layout checks and above
464     // all visible checks.
465     if (position() != StaticPosition) {
466         if (surround->offset != other->surround->offset) {
467              // Optimize for the case where a positioned layer is moving but not changing size.
468             if (position() == AbsolutePosition && positionedObjectMoved(surround->offset, other->surround->offset))
469                 return StyleDifferenceLayoutPositionedMovementOnly;
470 
471             // FIXME: We will need to do a bit of work in RenderObject/Box::setStyle before we
472             // can stop doing a layout when relative positioned objects move.  In particular, we'll need
473             // to update scrolling positions and figure out how to do a repaint properly of the updated layer.
474             //if (other->position() == RelativePosition)
475             //    return RepaintLayer;
476             //else
477                 return StyleDifferenceLayout;
478         } else if (box->z_index != other->box->z_index || box->z_auto != other->box->z_auto ||
479                  visual->clip != other->visual->clip || visual->hasClip != other->visual->hasClip)
480             return StyleDifferenceRepaintLayer;
481     }
482 
483     if (rareNonInheritedData->opacity != other->rareNonInheritedData->opacity) {
484 #if USE(ACCELERATED_COMPOSITING)
485         changedContextSensitiveProperties |= ContextSensitivePropertyOpacity;
486         // Don't return; keep looking for another change.
487 #else
488         return StyleDifferenceRepaintLayer;
489 #endif
490     }
491 
492     if (rareNonInheritedData->m_mask != other->rareNonInheritedData->m_mask ||
493         rareNonInheritedData->m_maskBoxImage != other->rareNonInheritedData->m_maskBoxImage)
494         return StyleDifferenceRepaintLayer;
495 
496     if (inherited->color != other->inherited->color ||
497         inherited_flags._visibility != other->inherited_flags._visibility ||
498         inherited_flags._text_decorations != other->inherited_flags._text_decorations ||
499         inherited_flags._force_backgrounds_to_white != other->inherited_flags._force_backgrounds_to_white ||
500         surround->border != other->surround->border ||
501         *background.get() != *other->background.get() ||
502         visual->textDecoration != other->visual->textDecoration ||
503         rareInheritedData->userModify != other->rareInheritedData->userModify ||
504         rareInheritedData->userSelect != other->rareInheritedData->userSelect ||
505         rareNonInheritedData->userDrag != other->rareNonInheritedData->userDrag ||
506         rareNonInheritedData->m_borderFit != other->rareNonInheritedData->m_borderFit ||
507         rareInheritedData->textFillColor != other->rareInheritedData->textFillColor ||
508         rareInheritedData->textStrokeColor != other->rareInheritedData->textStrokeColor)
509         return StyleDifferenceRepaint;
510 
511 #if USE(ACCELERATED_COMPOSITING)
512     if (rareNonInheritedData.get() != other->rareNonInheritedData.get()) {
513         if (rareNonInheritedData->m_transformStyle3D != other->rareNonInheritedData->m_transformStyle3D ||
514             rareNonInheritedData->m_backfaceVisibility != other->rareNonInheritedData->m_backfaceVisibility ||
515             rareNonInheritedData->m_perspective != other->rareNonInheritedData->m_perspective ||
516             rareNonInheritedData->m_perspectiveOriginX != other->rareNonInheritedData->m_perspectiveOriginX ||
517             rareNonInheritedData->m_perspectiveOriginY != other->rareNonInheritedData->m_perspectiveOriginY)
518             return StyleDifferenceRecompositeLayer;
519     }
520 #endif
521 
522     // Cursors are not checked, since they will be set appropriately in response to mouse events,
523     // so they don't need to cause any repaint or layout.
524 
525     // Animations don't need to be checked either.  We always set the new style on the RenderObject, so we will get a chance to fire off
526     // the resulting transition properly.
527     return StyleDifferenceEqual;
528 }
529 
setClip(Length top,Length right,Length bottom,Length left)530 void RenderStyle::setClip(Length top, Length right, Length bottom, Length left)
531 {
532     StyleVisualData* data = visual.access();
533     data->clip.m_top = top;
534     data->clip.m_right = right;
535     data->clip.m_bottom = bottom;
536     data->clip.m_left = left;
537 }
538 
addCursor(CachedImage * image,const IntPoint & hotSpot)539 void RenderStyle::addCursor(CachedImage* image, const IntPoint& hotSpot)
540 {
541     CursorData data;
542     data.cursorImage = image;
543     data.hotSpot = hotSpot;
544     if (!inherited.access()->cursorData)
545         inherited.access()->cursorData = CursorList::create();
546     inherited.access()->cursorData->append(data);
547 }
548 
setCursorList(PassRefPtr<CursorList> other)549 void RenderStyle::setCursorList(PassRefPtr<CursorList> other)
550 {
551     inherited.access()->cursorData = other;
552 }
553 
clearCursorList()554 void RenderStyle::clearCursorList()
555 {
556     if (inherited->cursorData)
557         inherited.access()->cursorData = 0;
558 }
559 
clearContent()560 void RenderStyle::clearContent()
561 {
562     if (rareNonInheritedData->m_content)
563         rareNonInheritedData->m_content->clear();
564 }
565 
setContent(PassRefPtr<StyleImage> image,bool add)566 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
567 {
568     if (!image)
569         return; // The object is null. Nothing to do. Just bail.
570 
571     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
572     ContentData* lastContent = content.get();
573     while (lastContent && lastContent->next())
574         lastContent = lastContent->next();
575 
576     bool reuseContent = !add;
577     ContentData* newContentData;
578     if (reuseContent && content) {
579         content->clear();
580         newContentData = content.release();
581     } else
582         newContentData = new ContentData;
583 
584     if (lastContent && !reuseContent)
585         lastContent->setNext(newContentData);
586     else
587         content.set(newContentData);
588 
589     newContentData->setImage(image);
590 }
591 
setContent(PassRefPtr<StringImpl> s,bool add)592 void RenderStyle::setContent(PassRefPtr<StringImpl> s, bool add)
593 {
594     if (!s)
595         return; // The string is null. Nothing to do. Just bail.
596 
597     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
598     ContentData* lastContent = content.get();
599     while (lastContent && lastContent->next())
600         lastContent = lastContent->next();
601 
602     bool reuseContent = !add;
603     if (add && lastContent) {
604         if (lastContent->isText()) {
605             // We can augment the existing string and share this ContentData node.
606             String newStr = lastContent->text();
607             newStr.append(s.get());
608             lastContent->setText(newStr.impl());
609             return;
610         }
611     }
612 
613     ContentData* newContentData = 0;
614     if (reuseContent && content) {
615         content->clear();
616         newContentData = content.release();
617     } else
618         newContentData = new ContentData;
619 
620     if (lastContent && !reuseContent)
621         lastContent->setNext(newContentData);
622     else
623         content.set(newContentData);
624 
625     newContentData->setText(s);
626 }
627 
setContent(CounterContent * c,bool add)628 void RenderStyle::setContent(CounterContent* c, bool add)
629 {
630     if (!c)
631         return;
632 
633     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
634     ContentData* lastContent = content.get();
635     while (lastContent && lastContent->next())
636         lastContent = lastContent->next();
637 
638     bool reuseContent = !add;
639     ContentData* newContentData = 0;
640     if (reuseContent && content) {
641         content->clear();
642         newContentData = content.release();
643     } else
644         newContentData = new ContentData;
645 
646     if (lastContent && !reuseContent)
647         lastContent->setNext(newContentData);
648     else
649         content.set(newContentData);
650 
651     newContentData->setCounter(c);
652 }
653 
applyTransform(TransformationMatrix & transform,const IntSize & borderBoxSize,ApplyTransformOrigin applyOrigin) const654 void RenderStyle::applyTransform(TransformationMatrix& transform, const IntSize& borderBoxSize, ApplyTransformOrigin applyOrigin) const
655 {
656     // transform-origin brackets the transform with translate operations.
657     // Optimize for the case where the only transform is a translation, since the transform-origin is irrelevant
658     // in that case.
659     bool applyTransformOrigin = false;
660     unsigned s = rareNonInheritedData->m_transform->m_operations.operations().size();
661     unsigned i;
662     if (applyOrigin == IncludeTransformOrigin) {
663         for (i = 0; i < s; i++) {
664             TransformOperation::OperationType type = rareNonInheritedData->m_transform->m_operations.operations()[i]->getOperationType();
665             if (type != TransformOperation::TRANSLATE_X &&
666                     type != TransformOperation::TRANSLATE_Y &&
667                     type != TransformOperation::TRANSLATE &&
668                     type != TransformOperation::TRANSLATE_Z &&
669                     type != TransformOperation::TRANSLATE_3D
670                     ) {
671                 applyTransformOrigin = true;
672                 break;
673             }
674         }
675     }
676 
677     if (applyTransformOrigin) {
678         transform.translate3d(transformOriginX().calcFloatValue(borderBoxSize.width()), transformOriginY().calcFloatValue(borderBoxSize.height()), transformOriginZ());
679     }
680 
681     for (i = 0; i < s; i++)
682         rareNonInheritedData->m_transform->m_operations.operations()[i]->apply(transform, borderBoxSize);
683 
684     if (applyTransformOrigin) {
685         transform.translate3d(-transformOriginX().calcFloatValue(borderBoxSize.width()), -transformOriginY().calcFloatValue(borderBoxSize.height()), -transformOriginZ());
686     }
687 }
688 
689 #if ENABLE(XBL)
addBindingURI(StringImpl * uri)690 void RenderStyle::addBindingURI(StringImpl* uri)
691 {
692     BindingURI* binding = new BindingURI(uri);
693     if (!bindingURIs())
694         SET_VAR(rareNonInheritedData, bindingURI, binding)
695     else
696         for (BindingURI* b = bindingURIs(); b; b = b->next()) {
697             if (!b->next())
698                 b->setNext(binding);
699         }
700 }
701 #endif
702 
setTextShadow(ShadowData * val,bool add)703 void RenderStyle::setTextShadow(ShadowData* val, bool add)
704 {
705     ASSERT(!val || (!val->spread && val->style == Normal));
706 
707     StyleRareInheritedData* rareData = rareInheritedData.access();
708     if (!add) {
709         delete rareData->textShadow;
710         rareData->textShadow = val;
711         return;
712     }
713 
714     val->next = rareData->textShadow;
715     rareData->textShadow = val;
716 }
717 
setBoxShadow(ShadowData * shadowData,bool add)718 void RenderStyle::setBoxShadow(ShadowData* shadowData, bool add)
719 {
720     StyleRareNonInheritedData* rareData = rareNonInheritedData.access();
721     if (!add) {
722         rareData->m_boxShadow.set(shadowData);
723         return;
724     }
725 
726     shadowData->next = rareData->m_boxShadow.release();
727     rareData->m_boxShadow.set(shadowData);
728 }
729 
getBorderRadiiForRect(const IntRect & r,IntSize & topLeft,IntSize & topRight,IntSize & bottomLeft,IntSize & bottomRight) const730 void RenderStyle::getBorderRadiiForRect(const IntRect& r, IntSize& topLeft, IntSize& topRight, IntSize& bottomLeft, IntSize& bottomRight) const
731 {
732     topLeft = surround->border.topLeft;
733     topRight = surround->border.topRight;
734 
735     bottomLeft = surround->border.bottomLeft;
736     bottomRight = surround->border.bottomRight;
737 
738     // Constrain corner radii using CSS3 rules:
739     // http://www.w3.org/TR/css3-background/#the-border-radius
740 
741     float factor = 1;
742     unsigned radiiSum;
743 
744     // top
745     radiiSum = static_cast<unsigned>(topLeft.width()) + static_cast<unsigned>(topRight.width()); // Casts to avoid integer overflow.
746     if (radiiSum > static_cast<unsigned>(r.width()))
747         factor = min(static_cast<float>(r.width()) / radiiSum, factor);
748 
749     // bottom
750     radiiSum = static_cast<unsigned>(bottomLeft.width()) + static_cast<unsigned>(bottomRight.width());
751     if (radiiSum > static_cast<unsigned>(r.width()))
752         factor = min(static_cast<float>(r.width()) / radiiSum, factor);
753 
754     // left
755     radiiSum = static_cast<unsigned>(topLeft.height()) + static_cast<unsigned>(bottomLeft.height());
756     if (radiiSum > static_cast<unsigned>(r.height()))
757         factor = min(static_cast<float>(r.height()) / radiiSum, factor);
758 
759     // right
760     radiiSum = static_cast<unsigned>(topRight.height()) + static_cast<unsigned>(bottomRight.height());
761     if (radiiSum > static_cast<unsigned>(r.height()))
762         factor = min(static_cast<float>(r.height()) / radiiSum, factor);
763 
764     // Scale all radii by f if necessary.
765     if (factor < 1) {
766         // If either radius on a corner becomes zero, reset both radii on that corner.
767         topLeft.scale(factor);
768         if (!topLeft.width() || !topLeft.height())
769             topLeft = IntSize();
770         topRight.scale(factor);
771         if (!topRight.width() || !topRight.height())
772             topRight = IntSize();
773         bottomLeft.scale(factor);
774         if (!bottomLeft.width() || !bottomLeft.height())
775             bottomLeft = IntSize();
776         bottomRight.scale(factor);
777         if (!bottomRight.width() || !bottomRight.height())
778             bottomRight = IntSize();
779     }
780 }
781 
counterDirectives() const782 const CounterDirectiveMap* RenderStyle::counterDirectives() const
783 {
784     return rareNonInheritedData->m_counterDirectives.get();
785 }
786 
accessCounterDirectives()787 CounterDirectiveMap& RenderStyle::accessCounterDirectives()
788 {
789     OwnPtr<CounterDirectiveMap>& map = rareNonInheritedData.access()->m_counterDirectives;
790     if (!map)
791         map.set(new CounterDirectiveMap);
792     return *map.get();
793 }
794 
795 #if ENABLE(DASHBOARD_SUPPORT)
initialDashboardRegions()796 const Vector<StyleDashboardRegion>& RenderStyle::initialDashboardRegions()
797 {
798     DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, emptyList, ());
799     return emptyList;
800 }
801 
noneDashboardRegions()802 const Vector<StyleDashboardRegion>& RenderStyle::noneDashboardRegions()
803 {
804     DEFINE_STATIC_LOCAL(Vector<StyleDashboardRegion>, noneList, ());
805     static bool noneListInitialized = false;
806 
807     if (!noneListInitialized) {
808         StyleDashboardRegion region;
809         region.label = "";
810         region.offset.m_top  = Length();
811         region.offset.m_right = Length();
812         region.offset.m_bottom = Length();
813         region.offset.m_left = Length();
814         region.type = StyleDashboardRegion::None;
815         noneList.append(region);
816         noneListInitialized = true;
817     }
818     return noneList;
819 }
820 #endif
821 
adjustAnimations()822 void RenderStyle::adjustAnimations()
823 {
824     AnimationList* animationList = rareNonInheritedData->m_animations.get();
825     if (!animationList)
826         return;
827 
828     // Get rid of empty animations and anything beyond them
829     for (size_t i = 0; i < animationList->size(); ++i) {
830         if (animationList->animation(i)->isEmpty()) {
831             animationList->resize(i);
832             break;
833         }
834     }
835 
836     if (animationList->isEmpty()) {
837         clearAnimations();
838         return;
839     }
840 
841     // Repeat patterns into layers that don't have some properties set.
842     animationList->fillUnsetProperties();
843 }
844 
adjustTransitions()845 void RenderStyle::adjustTransitions()
846 {
847     AnimationList* transitionList = rareNonInheritedData->m_transitions.get();
848     if (!transitionList)
849         return;
850 
851     // Get rid of empty transitions and anything beyond them
852     for (size_t i = 0; i < transitionList->size(); ++i) {
853         if (transitionList->animation(i)->isEmpty()) {
854             transitionList->resize(i);
855             break;
856         }
857     }
858 
859     if (transitionList->isEmpty()) {
860         clearTransitions();
861         return;
862     }
863 
864     // Repeat patterns into layers that don't have some properties set.
865     transitionList->fillUnsetProperties();
866 
867     // Make sure there are no duplicate properties. This is an O(n^2) algorithm
868     // but the lists tend to be very short, so it is probably ok
869     for (size_t i = 0; i < transitionList->size(); ++i) {
870         for (size_t j = i+1; j < transitionList->size(); ++j) {
871             if (transitionList->animation(i)->property() == transitionList->animation(j)->property()) {
872                 // toss i
873                 transitionList->remove(i);
874                 j = i;
875             }
876         }
877     }
878 }
879 
accessAnimations()880 AnimationList* RenderStyle::accessAnimations()
881 {
882     if (!rareNonInheritedData.access()->m_animations)
883         rareNonInheritedData.access()->m_animations.set(new AnimationList());
884     return rareNonInheritedData->m_animations.get();
885 }
886 
accessTransitions()887 AnimationList* RenderStyle::accessTransitions()
888 {
889     if (!rareNonInheritedData.access()->m_transitions)
890         rareNonInheritedData.access()->m_transitions.set(new AnimationList());
891     return rareNonInheritedData->m_transitions.get();
892 }
893 
transitionForProperty(int property) const894 const Animation* RenderStyle::transitionForProperty(int property) const
895 {
896     if (transitions()) {
897         for (size_t i = 0; i < transitions()->size(); ++i) {
898             const Animation* p = transitions()->animation(i);
899             if (p->property() == cAnimateAll || p->property() == property) {
900                 return p;
901             }
902         }
903     }
904     return 0;
905 }
906 
setBlendedFontSize(int size)907 void RenderStyle::setBlendedFontSize(int size)
908 {
909     FontDescription desc(fontDescription());
910     desc.setSpecifiedSize(size);
911     desc.setComputedSize(size);
912     setFontDescription(desc);
913     font().update(font().fontSelector());
914 }
915 
getBoxShadowExtent(int & top,int & right,int & bottom,int & left) const916 void RenderStyle::getBoxShadowExtent(int &top, int &right, int &bottom, int &left) const
917 {
918     top = 0;
919     right = 0;
920     bottom = 0;
921     left = 0;
922 
923     for (ShadowData* boxShadow = this->boxShadow(); boxShadow; boxShadow = boxShadow->next) {
924         if (boxShadow->style == Inset)
925             continue;
926         int blurAndSpread = boxShadow->blur + boxShadow->spread;
927 
928         top = min(top, boxShadow->y - blurAndSpread);
929         right = max(right, boxShadow->x + blurAndSpread);
930         bottom = max(bottom, boxShadow->y + blurAndSpread);
931         left = min(left, boxShadow->x - blurAndSpread);
932     }
933 }
934 
getBoxShadowHorizontalExtent(int & left,int & right) const935 void RenderStyle::getBoxShadowHorizontalExtent(int &left, int &right) const
936 {
937     left = 0;
938     right = 0;
939 
940     for (ShadowData* boxShadow = this->boxShadow(); boxShadow; boxShadow = boxShadow->next) {
941         if (boxShadow->style == Inset)
942             continue;
943         int blurAndSpread = boxShadow->blur + boxShadow->spread;
944 
945         left = min(left, boxShadow->x - blurAndSpread);
946         right = max(right, boxShadow->x + blurAndSpread);
947     }
948 }
949 
getBoxShadowVerticalExtent(int & top,int & bottom) const950 void RenderStyle::getBoxShadowVerticalExtent(int &top, int &bottom) const
951 {
952     top = 0;
953     bottom = 0;
954 
955     for (ShadowData* boxShadow = this->boxShadow(); boxShadow; boxShadow = boxShadow->next) {
956         if (boxShadow->style == Inset)
957             continue;
958         int blurAndSpread = boxShadow->blur + boxShadow->spread;
959 
960         top = min(top, boxShadow->y - blurAndSpread);
961         bottom = max(bottom, boxShadow->y + blurAndSpread);
962     }
963 }
964 
965 } // namespace WebCore
966