Title: [156180] trunk/Source/WebCore
Revision
156180
Author
[email protected]
Date
2013-09-20 10:32:18 -0700 (Fri, 20 Sep 2013)

Log Message

renderStyleOfEnclosingTextNode should update style before using a renderer
https://bugs.webkit.org/show_bug.cgi?id=121690

Reviewed by Enrica Casucci.

Merge https://chromium.googlesource.com/chromium/blink/+/65f089545e8c18cb268dfcbe56cba1cd8045527a

When accessing a renderer editing should always make sure that the style has been updated for the node.
Editing calls splitTextNode in a number of places and then accesses the renderer later. This patch is
the first of many to make sure editing always updates the style before attempting to access the renderer
(or style) of a node after calling a mutation method.

* editing/ApplyBlockElementCommand.cpp:
(WebCore::ApplyBlockElementCommand::renderStyleOfEnclosingTextNode):
* editing/ApplyBlockElementCommand.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (156179 => 156180)


--- trunk/Source/WebCore/ChangeLog	2013-09-20 17:28:36 UTC (rev 156179)
+++ trunk/Source/WebCore/ChangeLog	2013-09-20 17:32:18 UTC (rev 156180)
@@ -1,3 +1,21 @@
+2013-09-20  Ryosuke Niwa  <[email protected]>
+
+        renderStyleOfEnclosingTextNode should update style before using a renderer
+        https://bugs.webkit.org/show_bug.cgi?id=121690
+
+        Reviewed by Enrica Casucci.
+
+        Merge https://chromium.googlesource.com/chromium/blink/+/65f089545e8c18cb268dfcbe56cba1cd8045527a
+
+        When accessing a renderer editing should always make sure that the style has been updated for the node.
+        Editing calls splitTextNode in a number of places and then accesses the renderer later. This patch is
+        the first of many to make sure editing always updates the style before attempting to access the renderer
+        (or style) of a node after calling a mutation method.
+
+        * editing/ApplyBlockElementCommand.cpp:
+        (WebCore::ApplyBlockElementCommand::renderStyleOfEnclosingTextNode):
+        * editing/ApplyBlockElementCommand.h:
+
 2013-09-20  Darin Adler  <[email protected]>
 
         Fix a couple more CSS leaks

Modified: trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp (156179 => 156180)


--- trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp	2013-09-20 17:28:36 UTC (rev 156179)
+++ trunk/Source/WebCore/editing/ApplyBlockElementCommand.cpp	2013-09-20 17:32:18 UTC (rev 156180)
@@ -169,14 +169,20 @@
     return textAtPosition[0] == '\n';
 }
 
-static RenderStyle* renderStyleOfEnclosingTextNode(const Position& position)
+RenderStyle* ApplyBlockElementCommand::renderStyleOfEnclosingTextNode(const Position& position)
 {
     if (position.anchorType() != Position::PositionIsOffsetInAnchor
         || !position.containerNode()
-        || !position.containerNode()->isTextNode()
-        || !position.containerNode()->renderer())
+        || !position.containerNode()->isTextNode())
         return 0;
-    return position.containerNode()->renderer()->style();
+
+    document().updateStyleIfNeeded();
+
+    RenderObject* renderer = position.containerNode()->renderer();
+    if (!renderer)
+        return 0;
+
+    return renderer->style();
 }
 
 void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const VisiblePosition& endOfCurrentParagraph, Position& start, Position& end)

Modified: trunk/Source/WebCore/editing/ApplyBlockElementCommand.h (156179 => 156180)


--- trunk/Source/WebCore/editing/ApplyBlockElementCommand.h	2013-09-20 17:28:36 UTC (rev 156179)
+++ trunk/Source/WebCore/editing/ApplyBlockElementCommand.h	2013-09-20 17:32:18 UTC (rev 156180)
@@ -48,6 +48,7 @@
 private:
     virtual void doApply();
     virtual void formatRange(const Position& start, const Position& end, const Position& endOfSelection, RefPtr<Element>&) = 0;
+    RenderStyle* renderStyleOfEnclosingTextNode(const Position&);
     void rangeForParagraphSplittingTextNodesIfNeeded(const VisiblePosition&, Position&, Position&);
     VisiblePosition endOfNextParagrahSplittingTextNodesIfNeeded(VisiblePosition&, Position&, Position&);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to