From 652b61777488edc231ed47d3c88f680978881245 Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Mon, 8 Oct 2012 04:42:26 +0000 Subject: [PATCH] :first-line pseudo selector ignoring words created from :before https://bugs.webkit.org/show_bug.cgi?id=80794 Patch by Arpita Bahuguna on 2012-10-07 Reviewed by Daniel Bates. Source/WebCore: The :first-line pseudo-element style is not applied for content which is generated from the :before/:after pseudo-elements. Test: fast/css/first-line-style-for-before-after-content.html * rendering/RenderObject.cpp: (WebCore::firstLineStyleForCachedUncachedType): Added a new static helper function incorporating the common functionality of both uncachedFirstLineStyle() and firstLineStyleSlowCase() functions. It also modifies the functionality to handle the scenario when :first-line style needs to be applied on content generated from :before/:after. While getting the :first-line style we should also consider the case when the content is generated from a :before/:after pseudo-element in which case the RenderInline's parent should be considered for obtaining the first-line style. (WebCore): (WebCore::RenderObject::uncachedFirstLineStyle): (WebCore::RenderObject::firstLineStyleSlowCase): Moved the duplicate code between the two functions to the common helper function firstLineStyleForCachedUncachedType(). LayoutTests: * fast/css/first-line-style-for-before-after-content-expected.html: Added. * fast/css/first-line-style-for-before-after-content.html: Added. Added ref test for verification of the scenario when :first-line style is applied to content generated from :before/:after pseudo-elements. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130616 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 12 ++++ ...yle-for-before-after-content-expected.html | 34 +++++++++++ ...t-line-style-for-before-after-content.html | 46 ++++++++++++++ Source/WebCore/ChangeLog | 31 ++++++++++ Source/WebCore/rendering/RenderObject.cpp | 61 +++++++++++-------- 5 files changed, 158 insertions(+), 26 deletions(-) create mode 100644 LayoutTests/fast/css/first-line-style-for-before-after-content-expected.html create mode 100644 LayoutTests/fast/css/first-line-style-for-before-after-content.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 1740d73ce382..b9b34e6c67b3 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,15 @@ +2012-10-07 Arpita Bahuguna + + :first-line pseudo selector ignoring words created from :before + https://bugs.webkit.org/show_bug.cgi?id=80794 + + Reviewed by Daniel Bates. + + * fast/css/first-line-style-for-before-after-content-expected.html: Added. + * fast/css/first-line-style-for-before-after-content.html: Added. + Added ref test for verification of the scenario when :first-line style + is applied to content generated from :before/:after pseudo-elements. + 2012-10-07 Nick Carter [chromium] Crash in WebCore::GraphicsLayerChromium::setContentsToImage diff --git a/LayoutTests/fast/css/first-line-style-for-before-after-content-expected.html b/LayoutTests/fast/css/first-line-style-for-before-after-content-expected.html new file mode 100644 index 000000000000..5c4ffff4e0e9 --- /dev/null +++ b/LayoutTests/fast/css/first-line-style-for-before-after-content-expected.html @@ -0,0 +1,34 @@ + + + + + + +
Test for Bugzilla Bug 80794: :first-line pseudo selector ignoring words created from :before.
+
The :first-line pseudo-element style is not applied to content generated from :before/:after pseudo-elements.
+
+ +
In the following paragraph the first-letter should be displayed in blue color and the first-line in green color including the words 'The first line'. This test verifies the behavior with :before style specified on a block flow element.
+

The first line of this paragraph should be displayed in green color.

+ +
In the following paragraph the first-letter should be displayed in blue color and the first-line in green color including the words 'The first line'. This test verifies the behavior with :before style specified on an inline element.
+

The first line of this paragraph should be displayed in green color.

+ +
In the following paragraph the first-letter should be displayed in blue color and the first-line in green color including the words 'in green color.'. This test verifies the behavior with :after style specified on a block flow element.
+

Display in green color.

+ +
In the following paragraph the first-letter should be displayed in blue color and the first-line in green color including the words 'in green color.'. This test verifies the behavior with :after style specified on an inline element.
+

Display in green color.

+ + + diff --git a/LayoutTests/fast/css/first-line-style-for-before-after-content.html b/LayoutTests/fast/css/first-line-style-for-before-after-content.html new file mode 100644 index 000000000000..77a8737765b4 --- /dev/null +++ b/LayoutTests/fast/css/first-line-style-for-before-after-content.html @@ -0,0 +1,46 @@ + + + + + + +
Test for Bugzilla Bug 80794: :first-line pseudo selector ignoring words created from :before.
+
The :first-line pseudo-element style is not applied to content generated from :before/:after pseudo-elements.
+
+ +
In the following paragraph the first-letter should be displayed in blue color and the first-line in green color including the words 'The first line'. This test verifies the behavior with :before style specified on a block flow element.
+

of this paragraph should be displayed in green color.

+ +
In the following paragraph the first-letter should be displayed in blue color and the first-line in green color including the words 'The first line'. This test verifies the behavior with :before style specified on an inline element.
+

of this paragraph should be displayed in green color.

+ +
In the following paragraph the first-letter should be displayed in blue color and the first-line in green color including the words 'in green color.'. This test verifies the behavior with :after style specified on a block flow element.
+

Display

+ +
In the following paragraph the first-letter should be displayed in blue color and the first-line in green color including the words 'in green color.'. This test verifies the behavior with :after style specified on an inline element.
+

Display

+ + + diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 2038200a01d8..8a07c8a68ebd 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,34 @@ +2012-10-07 Arpita Bahuguna + + :first-line pseudo selector ignoring words created from :before + https://bugs.webkit.org/show_bug.cgi?id=80794 + + Reviewed by Daniel Bates. + + The :first-line pseudo-element style is not applied for content + which is generated from the :before/:after pseudo-elements. + + Test: fast/css/first-line-style-for-before-after-content.html + + * rendering/RenderObject.cpp: + (WebCore::firstLineStyleForCachedUncachedType): + Added a new static helper function incorporating the common + functionality of both uncachedFirstLineStyle() and firstLineStyleSlowCase() + functions. It also modifies the functionality to handle the + scenario when :first-line style needs to be applied on content + generated from :before/:after. + + While getting the :first-line style we should also consider the case + when the content is generated from a :before/:after pseudo-element in + which case the RenderInline's parent should be considered for + obtaining the first-line style. + + (WebCore): + (WebCore::RenderObject::uncachedFirstLineStyle): + (WebCore::RenderObject::firstLineStyleSlowCase): + Moved the duplicate code between the two functions to the common + helper function firstLineStyleForCachedUncachedType(). + 2012-10-07 Peter Wang Web Inspector: The front-end should provide the position in original source file when set a breakpoint diff --git a/Source/WebCore/rendering/RenderObject.cpp b/Source/WebCore/rendering/RenderObject.cpp index d45ce37ba9fd..12f3a37fa37d 100755 --- a/Source/WebCore/rendering/RenderObject.cpp +++ b/Source/WebCore/rendering/RenderObject.cpp @@ -2602,6 +2602,37 @@ void RenderObject::layout() setNeedsLayout(false); } +enum StyleCacheState { + Cached, + Uncached +}; + +static PassRefPtr firstLineStyleForCachedUncachedType(StyleCacheState type, const RenderObject* renderer, RenderStyle* style) +{ + const RenderObject* rendererForFirstLineStyle = renderer; + if (renderer->isBeforeOrAfterContent()) + rendererForFirstLineStyle = renderer->parent(); + + if (rendererForFirstLineStyle->isBlockFlow()) { + if (RenderBlock* firstLineBlock = rendererForFirstLineStyle->firstLineBlock()) { + if (type == Cached) + return firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style); + return firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == renderer ? style : 0); + } + } else if (!rendererForFirstLineStyle->isAnonymous() && rendererForFirstLineStyle->isRenderInline()) { + RenderStyle* parentStyle = rendererForFirstLineStyle->parent()->firstLineStyle(); + if (parentStyle != rendererForFirstLineStyle->parent()->style()) { + if (type == Cached) { + // A first-line style is in effect. Cache a first-line style for ourselves. + rendererForFirstLineStyle->style()->setHasPseudoStyle(FIRST_LINE_INHERITED); + return rendererForFirstLineStyle->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle); + } + return rendererForFirstLineStyle->getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style); + } + } + return 0; +} + PassRefPtr RenderObject::uncachedFirstLineStyle(RenderStyle* style) const { if (!document()->styleSheetCollection()->usesFirstLineRules()) @@ -2609,39 +2640,17 @@ PassRefPtr RenderObject::uncachedFirstLineStyle(RenderStyle* style) ASSERT(!isText()); - RefPtr result; - - if (isBlockFlow()) { - if (RenderBlock* firstLineBlock = this->firstLineBlock()) - result = firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == this ? style : 0); - } else if (!isAnonymous() && isRenderInline()) { - RenderStyle* parentStyle = parent()->firstLineStyle(); - if (parentStyle != parent()->style()) - result = getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style); - } - - return result.release(); + return firstLineStyleForCachedUncachedType(Uncached, this, style); } RenderStyle* RenderObject::firstLineStyleSlowCase() const { ASSERT(document()->styleSheetCollection()->usesFirstLineRules()); - RenderStyle* style = m_style.get(); - const RenderObject* renderer = isText() ? parent() : this; - if (renderer->isBlockFlow()) { - if (RenderBlock* firstLineBlock = renderer->firstLineBlock()) - style = firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style); - } else if (!renderer->isAnonymous() && renderer->isRenderInline()) { - RenderStyle* parentStyle = renderer->parent()->firstLineStyle(); - if (parentStyle != renderer->parent()->style()) { - // A first-line style is in effect. Cache a first-line style for ourselves. - renderer->style()->setHasPseudoStyle(FIRST_LINE_INHERITED); - style = renderer->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle); - } - } + if (RefPtr style = firstLineStyleForCachedUncachedType(Cached, isText() ? parent() : this, m_style.get())) + return style.get(); - return style; + return m_style.get(); } RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const -- 2.36.0