Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutObject.cpp

Issue 2787123007: Do the obvious thing for first-line styles.
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) 5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc.
7 * All rights reserved. 7 * All rights reserved.
8 * Copyright (C) 2009 Google Inc. All rights reserved. 8 * Copyright (C) 2009 Google Inc. All rights reserved.
9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved.
10 * (http://www.torchmobile.com/) 10 * (http://www.torchmobile.com/)
(...skipping 3009 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 setNormalChildNeedsLayout(true); 3020 setNormalChildNeedsLayout(true);
3021 layout(); 3021 layout();
3022 } 3022 }
3023 3023
3024 enum StyleCacheState { Cached, Uncached }; 3024 enum StyleCacheState { Cached, Uncached };
3025 3025
3026 static PassRefPtr<ComputedStyle> firstLineStyleForCachedUncachedType( 3026 static PassRefPtr<ComputedStyle> firstLineStyleForCachedUncachedType(
3027 StyleCacheState type, 3027 StyleCacheState type,
3028 const LayoutObject* layoutObject, 3028 const LayoutObject* layoutObject,
3029 ComputedStyle* style) { 3029 ComputedStyle* style) {
3030 const LayoutObject* layoutObjectForFirstLineStyle = layoutObject; 3030 return type == Cached
3031 if (layoutObject->isBeforeOrAfterContent()) 3031 ? layoutObject->getCachedPseudoStyle(PseudoIdFirstLine, style)
3032 layoutObjectForFirstLineStyle = layoutObject->parent(); 3032 : layoutObject->getUncachedPseudoStyle(
3033 3033 PseudoStyleRequest(PseudoIdFirstLine), style);
3034 if (layoutObjectForFirstLineStyle->behavesLikeBlockContainer()) {
3035 if (const LayoutBlock* firstLineBlock =
3036 toLayoutBlock(layoutObjectForFirstLineStyle)
3037 ->enclosingFirstLineStyleBlock()) {
3038 if (type == Cached)
3039 return firstLineBlock->getCachedPseudoStyle(PseudoIdFirstLine, style);
3040 return firstLineBlock->getUncachedPseudoStyle(
3041 PseudoStyleRequest(PseudoIdFirstLine), style);
3042 }
3043 } else if (!layoutObjectForFirstLineStyle->isAnonymous() &&
3044 layoutObjectForFirstLineStyle->isLayoutInline() &&
3045 !layoutObjectForFirstLineStyle->node()
3046 ->isFirstLetterPseudoElement()) {
3047 const ComputedStyle* parentStyle =
3048 layoutObjectForFirstLineStyle->parent()->firstLineStyle();
3049 if (parentStyle != layoutObjectForFirstLineStyle->parent()->style()) {
3050 if (type == Cached) {
3051 // A first-line style is in effect. Cache a first-line style for
3052 // ourselves.
3053 layoutObjectForFirstLineStyle->mutableStyleRef().setHasPseudoStyle(
3054 PseudoIdFirstLineInherited);
3055 return layoutObjectForFirstLineStyle->getCachedPseudoStyle(
3056 PseudoIdFirstLineInherited, parentStyle);
3057 }
3058 return layoutObjectForFirstLineStyle->getUncachedPseudoStyle(
3059 PseudoStyleRequest(PseudoIdFirstLineInherited), parentStyle);
3060 }
3061 }
3062 return nullptr;
3063 } 3034 }
3064 3035
3065 PassRefPtr<ComputedStyle> LayoutObject::uncachedFirstLineStyle() const { 3036 PassRefPtr<ComputedStyle> LayoutObject::uncachedFirstLineStyle() const {
3066 if (!document().styleEngine().usesFirstLineRules()) 3037 if (!document().styleEngine().usesFirstLineRules())
3067 return nullptr; 3038 return nullptr;
3068 3039
3069 ASSERT(!isText()); 3040 ASSERT(!isText());
3070 3041
3071 return firstLineStyleForCachedUncachedType(Uncached, this, m_style.get()); 3042 return firstLineStyleForCachedUncachedType(Uncached, this, m_style.get());
3072 } 3043 }
3073 3044
3074 ComputedStyle* LayoutObject::cachedFirstLineStyle() const { 3045 ComputedStyle* LayoutObject::cachedFirstLineStyle() const {
3075 ASSERT(document().styleEngine().usesFirstLineRules()); 3046 ASSERT(document().styleEngine().usesFirstLineRules());
3076 3047
3077 if (RefPtr<ComputedStyle> style = firstLineStyleForCachedUncachedType( 3048 if (RefPtr<ComputedStyle> style =
3078 Cached, isText() ? parent() : this, m_style.get())) 3049 firstLineStyleForCachedUncachedType(Cached, this, m_style.get()))
3079 return style.get(); 3050 return style.get();
3080 3051
3081 return m_style.get(); 3052 return m_style.get();
3082 } 3053 }
3083 3054
3084 ComputedStyle* LayoutObject::getCachedPseudoStyle( 3055 ComputedStyle* LayoutObject::getCachedPseudoStyle(
3085 PseudoId pseudo, 3056 PseudoId pseudo,
3086 const ComputedStyle* parentStyle) const { 3057 const ComputedStyle* parentStyle) const {
3087 if (pseudo < FirstInternalPseudoId && !style()->hasPseudoStyle(pseudo)) 3058 if (pseudo < FirstInternalPseudoId && !style()->hasPseudoStyle(pseudo))
3088 return nullptr; 3059 return nullptr;
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
3647 const blink::LayoutObject* root = object1; 3618 const blink::LayoutObject* root = object1;
3648 while (root->parent()) 3619 while (root->parent())
3649 root = root->parent(); 3620 root = root->parent();
3650 root->showLayoutTreeAndMark(object1, "*", object2, "-", 0); 3621 root->showLayoutTreeAndMark(object1, "*", object2, "-", 0);
3651 } else { 3622 } else {
3652 WTFLogAlways("%s", "Cannot showLayoutTree. Root is (nil)"); 3623 WTFLogAlways("%s", "Cannot showLayoutTree. Root is (nil)");
3653 } 3624 }
3654 } 3625 }
3655 3626
3656 #endif 3627 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698