Ignore:
Timestamp:
Sep 28, 2013, 11:30:16 AM (12 years ago)
Author:
Antti Koivisto
Message:

Clean up code for getting first line style
https://bugs.webkit.org/show_bug.cgi?id=122037

Reviewed by Andreas Kling.

We have confusing RenderObject::style(bool firstLine). Get rid of it in favour of
just using RenderObject::firstLineStyle() where appropriate.

Also switch to RenderStyle references in many places and move first line style caching
code down to RenderElement.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r156527 r156608  
    22332233}
    22342234
    2235 enum StyleCacheState {
    2236     Cached,
    2237     Uncached
    2238 };
    2239 
    2240 static PassRefPtr<RenderStyle> firstLineStyleForCachedUncachedType(StyleCacheState type, const RenderObject* renderer, RenderStyle* style)
    2241 {
    2242     const RenderObject* rendererForFirstLineStyle = renderer;
    2243     if (renderer->isBeforeOrAfterContent())
    2244         rendererForFirstLineStyle = renderer->parent();
    2245 
    2246     if (rendererForFirstLineStyle->isRenderBlockFlow() || rendererForFirstLineStyle->isRenderButton()) {
    2247         if (RenderBlock* firstLineBlock = rendererForFirstLineStyle->firstLineBlock()) {
    2248             if (type == Cached)
    2249                 return firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style);
    2250             return firstLineBlock->getUncachedPseudoStyle(PseudoStyleRequest(FIRST_LINE), style, firstLineBlock == renderer ? style : 0);
    2251         }
    2252     } else if (!rendererForFirstLineStyle->isAnonymous() && rendererForFirstLineStyle->isRenderInline()) {
    2253         RenderStyle* parentStyle = rendererForFirstLineStyle->parent()->firstLineStyle();
    2254         if (parentStyle != rendererForFirstLineStyle->parent()->style()) {
    2255             if (type == Cached) {
    2256                 // A first-line style is in effect. Cache a first-line style for ourselves.
    2257                 rendererForFirstLineStyle->style()->setHasPseudoStyle(FIRST_LINE_INHERITED);
    2258                 return rendererForFirstLineStyle->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle);
    2259             }
    2260             return rendererForFirstLineStyle->getUncachedPseudoStyle(PseudoStyleRequest(FIRST_LINE_INHERITED), parentStyle, style);
    2261         }
    2262     }
    2263     return 0;
    2264 }
    2265 
    2266 PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const
    2267 {
    2268     if (!document().styleSheetCollection().usesFirstLineRules())
    2269         return 0;
    2270 
    2271     ASSERT(!isText());
    2272 
    2273     return firstLineStyleForCachedUncachedType(Uncached, this, style);
    2274 }
    2275 
    2276 RenderStyle* RenderObject::cachedFirstLineStyle() const
    2277 {
    2278     ASSERT(document().styleSheetCollection().usesFirstLineRules());
    2279 
    2280     RenderStyle* style = this->style();
    2281     if (RefPtr<RenderStyle> firstLineStyle = firstLineStyleForCachedUncachedType(Cached, isText() ? parent() : this, style))
    2282         return firstLineStyle.get();
    2283 
    2284     return style;
    2285 }
    2286 
    22872235RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const
    22882236{
     
    23552303    Color resultColor;
    23562304    do {
    2357         styleToUse = curr->style(firstlineStyle);
     2305        styleToUse = firstlineStyle ? curr->firstLineStyle() : curr->style();
    23582306        currDecs = styleToUse->textDecoration();
    23592307        resultColor = decorationColor(styleToUse);
     
    23822330    // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
    23832331    if (decorations && curr) {
    2384         styleToUse = curr->style(firstlineStyle);
     2332        styleToUse = firstlineStyle ? curr->firstLineStyle() : curr->style();
    23852333        resultColor = decorationColor(styleToUse);
    23862334        if (decorations & TextDecorationUnderline)
Note: See TracChangeset for help on using the changeset viewer.