Text::renderer() should return RenderText
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Oct 2013 16:00:10 +0000 (16:00 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Oct 2013 16:00:10 +0000 (16:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122729

Reviewed by Andreas Kling.

Tighten typing.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157373 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Text.cpp
Source/WebCore/dom/Text.h
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/DeleteSelectionCommand.cpp
Source/WebCore/editing/HTMLInterchange.cpp
Source/WebCore/editing/InsertIntoTextNodeCommand.cpp
Source/WebCore/editing/InsertLineBreakCommand.cpp
Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/page/Frame.cpp
Source/WebCore/rendering/RenderText.h
Source/WebCore/style/StyleResolveTree.cpp

index 70be305..4e6ebc3 100644 (file)
@@ -1,3 +1,12 @@
+2013-10-13  Antti Koivisto  <antti@apple.com>
+
+        Text::renderer() should return RenderText
+        https://bugs.webkit.org/show_bug.cgi?id=122729
+
+        Reviewed by Andreas Kling.
+        
+        Tighten typing.
+
 2013-10-13  Andreas Kling  <akling@apple.com>
 
         Devirtualize RenderView::viewRect().
index ce355af..adf4e13 100644 (file)
@@ -87,7 +87,7 @@ PassRefPtr<Text> Text::splitText(unsigned offset, ExceptionCode& ec)
         document().textNodeSplit(this);
 
     if (renderer())
-        toRenderText(renderer())->setTextWithOffset(dataImpl(), 0, oldStr.length());
+        renderer()->setTextWithOffset(dataImpl(), 0, oldStr.length());
 
     return newText.release();
 }
index faa6791..2c87621 100644 (file)
@@ -51,6 +51,8 @@ public:
     
     virtual bool canContainRangeEndPoint() const OVERRIDE FINAL { return true; }
 
+    RenderText* renderer() const;
+
 protected:
     Text(Document& document, const String& data, ConstructionType type)
         : CharacterData(document, data, type)
@@ -70,10 +72,9 @@ private:
 #endif
 };
 
-inline bool isText(const Node& node)
-{
-    return node.isTextNode();
-}
+void isText(const Text&); // Catch unnecessary runtime check of type known at compile time.
+void isText(const ContainerNode&); // Catch unnecessary runtime check of type known at compile time.
+inline bool isText(const Node& node) { return node.isTextNode(); }
 
 NODE_TYPE_CASTS(Text)
 
index ab28873..2e68109 100644 (file)
@@ -734,7 +734,7 @@ void CompositeEditCommand::deleteInsignificantText(PassRefPtr<Text> textNode, un
 
     document().updateLayout();
 
-    RenderText* textRenderer = toRenderText(textNode->renderer());
+    RenderText* textRenderer = textNode->renderer();
     if (!textRenderer)
         return;
 
index 1826cfe..76b1bbd 100644 (file)
@@ -39,6 +39,7 @@
 #include "HTMLTableElement.h"
 #include "NodeTraversal.h"
 #include "RenderTableCell.h"
+#include "RenderText.h"
 #include "Text.h"
 #include "VisibleUnits.h"
 
index 4e7a16f..e71a0c8 100644 (file)
@@ -27,6 +27,7 @@
 #include "HTMLInterchange.h"
 
 #include "RenderElement.h"
+#include "RenderText.h"
 #include "Text.h"
 #include "TextIterator.h"
 #include <wtf/text/StringBuilder.h>
index c544595..d737726 100644 (file)
@@ -57,7 +57,7 @@ void InsertIntoTextNodeCommand::doApply()
         return;
 
     if (passwordEchoEnabled) {
-        RenderText* renderText = toRenderText(m_node->renderer());
+        RenderText* renderText = m_node->renderer();
         if (renderText && renderText->isSecure())
             renderText->momentarilyRevealLastTypedCharacter(m_offset + m_text.length() - 1);
     }
index ed151b8..b3afb06 100644 (file)
@@ -35,6 +35,7 @@
 #include "HTMLTableElement.h"
 #include "Range.h"
 #include "RenderElement.h"
+#include "RenderText.h"
 #include "Text.h"
 #include "VisiblePosition.h"
 #include "VisibleUnits.h"
index 9818d12..afdf58f 100644 (file)
@@ -34,7 +34,7 @@
 #include "HTMLNames.h"
 #include "InsertLineBreakCommand.h"
 #include "NodeTraversal.h"
-#include "RenderObject.h"
+#include "RenderText.h"
 #include "Text.h"
 #include "VisibleUnits.h"
 #include "htmlediting.h"
index 0bc2d53..0e2314d 100644 (file)
@@ -667,9 +667,9 @@ void ReplaceSelectionCommand::moveNodeOutOfAncestor(PassRefPtr<Node> prpNode, Pa
         removeNode(ancestor.release());
 }
 
-static inline bool nodeHasVisibleRenderText(Text* text)
+static inline bool hasRenderedText(const Text& text)
 {
-    return text->renderer() && toRenderText(text->renderer())->hasRenderedText();
+    return text.renderer() && text.renderer()->hasRenderedText();
 }
 
 void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(InsertedNodes& insertedNodes)
@@ -677,7 +677,7 @@ void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(InsertedNodes& ins
     document().updateLayoutIgnorePendingStylesheets();
 
     Node* lastLeafInserted = insertedNodes.lastLeafInserted();
-    if (lastLeafInserted && lastLeafInserted->isTextNode() && !nodeHasVisibleRenderText(toText(lastLeafInserted))
+    if (lastLeafInserted && lastLeafInserted->isTextNode() && !hasRenderedText(toText(*lastLeafInserted))
         && !enclosingNodeWithTag(firstPositionInOrBeforeNode(lastLeafInserted), selectTag)
         && !enclosingNodeWithTag(firstPositionInOrBeforeNode(lastLeafInserted), scriptTag)) {
         insertedNodes.willRemoveNode(lastLeafInserted);
@@ -687,7 +687,7 @@ void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(InsertedNodes& ins
     // We don't have to make sure that firstNodeInserted isn't inside a select or script element
     // because it is a top level node in the fragment and the user can't insert into those elements.
     Node* firstNodeInserted = insertedNodes.firstNodeInserted();
-    if (firstNodeInserted && firstNodeInserted->isTextNode() && !nodeHasVisibleRenderText(toText(firstNodeInserted))) {
+    if (firstNodeInserted && firstNodeInserted->isTextNode() && !hasRenderedText(toText(*firstNodeInserted))) {
         insertedNodes.willRemoveNode(firstNodeInserted);
         removeNode(firstNodeInserted);
     }
index f47d865..3ba148b 100644 (file)
@@ -77,6 +77,7 @@
 #include "PageGroup.h"
 #include "RegularExpression.h"
 #include "RenderTableCell.h"
+#include "RenderText.h"
 #include "RenderTextControl.h"
 #include "RenderTheme.h"
 #include "RenderView.h"
index 298b215..dedb81a 100644 (file)
 
 #include "RenderElement.h"
 #include "RenderTextLineBoxes.h"
+#include "Text.h"
 #include <wtf/Forward.h>
 
 namespace WebCore {
 
 class InlineTextBox;
-class Text;
 
 class RenderText : public RenderObject {
 public:
@@ -134,8 +134,6 @@ public:
 
     InlineTextBox* findNextInlineTextBox(int offset, int& pos) const { return m_lineBoxes.findNext(offset, pos); }
 
-    void checkConsistency() const;
-
     bool isAllCollapsibleWhitespace() const;
 
     bool canUseSimpleFontCodePath() const { return m_canUseSimpleFontCodePath; }
@@ -250,13 +248,12 @@ inline RenderStyle* RenderText::firstLineStyle() const
     return parent()->firstLineStyle();
 }
 
-#ifdef NDEBUG
-inline void RenderText::checkConsistency() const
+void applyTextTransform(const RenderStyle*, String&, UChar);
+
+inline RenderText* Text::renderer() const
 {
+    return toRenderText(Node::renderer());
 }
-#endif
-
-void applyTextTransform(const RenderStyle*, String&, UChar);
 
 } // namespace WebCore
 
index 674dc89..cb923b8 100644 (file)
@@ -409,7 +409,7 @@ void updateTextRendererAfterContentChange(Text& textNode, unsigned offsetOfRepla
 {
     if (!textNode.attached())
         return;
-    RenderText* textRenderer = toRenderText(textNode.renderer());
+    RenderText* textRenderer = textNode.renderer();
     if (!textRenderer) {
         attachTextRenderer(textNode);
         reattachTextRenderersForWhitespaceOnlySiblingsAfterAttachIfNeeded(textNode);
@@ -628,7 +628,7 @@ static Change resolveLocal(Element& current, Change inheritedChange)
 
 static void updateTextStyle(Text& text)
 {
-    RenderText* renderer = toRenderText(text.renderer());
+    RenderText* renderer = text.renderer();
 
     if (!text.needsStyleRecalc())
         return;