diff --git a/engine/core/dom/Node.cpp b/engine/core/dom/Node.cpp index 2efcb14220c..2d6c00b7a39 100644 --- a/engine/core/dom/Node.cpp +++ b/engine/core/dom/Node.cpp @@ -381,25 +381,6 @@ void Node::remove(ExceptionState& exceptionState) parent->removeChild(this, exceptionState); } -void Node::normalize() -{ - // Go through the subtree beneath us, normalizing all nodes. This means that - // any two adjacent text nodes are merged and any empty text nodes are removed. - - RefPtr node = this; - while (Node* firstChild = node->firstChild()) - node = firstChild; - while (node) { - if (node == this) - break; - - if (node->nodeType() == TEXT_NODE) - node = toText(node)->mergeNextSiblingNodesIfPossible(); - else - node = NodeTraversal::nextPostOrder(*node); - } -} - const AtomicString& Node::localName() const { return nullAtom; diff --git a/engine/core/dom/Node.h b/engine/core/dom/Node.h index 9efa372d6f8..0994031bbf0 100644 --- a/engine/core/dom/Node.h +++ b/engine/core/dom/Node.h @@ -168,7 +168,6 @@ public: bool hasChildren() const { return firstChild(); } virtual PassRefPtr cloneNode(bool deep = false) = 0; virtual const AtomicString& localName() const; - void normalize(); bool isSameNode(Node* other) const { return this == other; } bool isEqualNode(Node*) const; diff --git a/engine/core/dom/Text.cpp b/engine/core/dom/Text.cpp index b010c4969c9..9d91a66d9e4 100644 --- a/engine/core/dom/Text.cpp +++ b/engine/core/dom/Text.cpp @@ -48,55 +48,6 @@ PassRefPtr Text::createEditingText(Document& document, const String& data) return adoptRef(new Text(document, data, CreateEditingText)); } -PassRefPtr Text::mergeNextSiblingNodesIfPossible() -{ - RefPtr protect(this); - - // Remove empty text nodes. - if (!length()) { - // Care must be taken to get the next node before removing the current node. - RefPtr nextNode(NodeTraversal::nextPostOrder(*this)); - remove(IGNORE_EXCEPTION); - return nextNode.release(); - } - - // Merge text nodes. - while (Node* nextSibling = this->nextSibling()) { - if (nextSibling->nodeType() != TEXT_NODE) - break; - - RefPtr nextText = toText(nextSibling); - - // Remove empty text nodes. - if (!nextText->length()) { - nextText->remove(IGNORE_EXCEPTION); - continue; - } - - // Both non-empty text nodes. Merge them. - unsigned offset = length(); - String nextTextData = nextText->data(); - String oldTextData = data(); - setDataWithoutUpdate(data() + nextTextData); - updateTextRenderer(oldTextData.length(), 0); - - // Empty nextText for layout update. - nextText->setDataWithoutUpdate(emptyString()); - nextText->updateTextRenderer(0, nextTextData.length()); - - document().didMergeTextNodes(*nextText, offset); - - // Restore nextText for mutation event. - nextText->setDataWithoutUpdate(nextTextData); - nextText->updateTextRenderer(0, 0); - - didModifyData(oldTextData); - nextText->remove(IGNORE_EXCEPTION); - } - - return NodeTraversal::nextPostOrder(*this); -} - PassRefPtr Text::splitText(unsigned offset, ExceptionState& exceptionState) { // IndexSizeError: Raised if the specified offset is negative or greater than @@ -127,96 +78,6 @@ PassRefPtr Text::splitText(unsigned offset, ExceptionState& exceptionState return newText.release(); } -static const Text* earliestLogicallyAdjacentTextNode(const Text* t) -{ - for (const Node* n = t->previousSibling(); n; n = n->previousSibling()) { - Node::NodeType type = n->nodeType(); - if (type == Node::TEXT_NODE) { - t = toText(n); - continue; - } - - break; - } - return t; -} - -static const Text* latestLogicallyAdjacentTextNode(const Text* t) -{ - for (const Node* n = t->nextSibling(); n; n = n->nextSibling()) { - Node::NodeType type = n->nodeType(); - if (type == Node::TEXT_NODE) { - t = toText(n); - continue; - } - - break; - } - return t; -} - -String Text::wholeText() const -{ - const Text* startText = earliestLogicallyAdjacentTextNode(this); - const Text* endText = latestLogicallyAdjacentTextNode(this); - - Node* onePastEndText = endText->nextSibling(); - unsigned resultLength = 0; - for (const Node* n = startText; n != onePastEndText; n = n->nextSibling()) { - if (!n->isTextNode()) - continue; - const String& data = toText(n)->data(); - if (std::numeric_limits::max() - data.length() < resultLength) - CRASH(); - resultLength += data.length(); - } - StringBuilder result; - result.reserveCapacity(resultLength); - for (const Node* n = startText; n != onePastEndText; n = n->nextSibling()) { - if (!n->isTextNode()) - continue; - result.append(toText(n)->data()); - } - ASSERT(result.length() == resultLength); - - return result.toString(); -} - -PassRefPtr Text::replaceWholeText(const String& newText) -{ - // Remove all adjacent text nodes, and replace the contents of this one. - - // Protect startText and endText against mutation event handlers removing the last ref - RefPtr startText = const_cast(earliestLogicallyAdjacentTextNode(this)); - RefPtr endText = const_cast(latestLogicallyAdjacentTextNode(this)); - - RefPtr protectedThis(this); // Mutation event handlers could cause our last ref to go away - RefPtr parent = parentNode(); // Protect against mutation handlers moving this node during traversal - for (RefPtr n = startText; n && n != this && n->isTextNode() && n->parentNode() == parent;) { - RefPtr nodeToRemove(n.release()); - n = nodeToRemove->nextSibling(); - parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION); - } - - if (this != endText) { - Node* onePastEndText = endText->nextSibling(); - for (RefPtr n = nextSibling(); n && n != onePastEndText && n->isTextNode() && n->parentNode() == parent;) { - RefPtr nodeToRemove(n.release()); - n = nodeToRemove->nextSibling(); - parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION); - } - } - - if (newText.isEmpty()) { - if (parent && parentNode() == parent) - parent->removeChild(this, IGNORE_EXCEPTION); - return nullptr; - } - - setData(newText); - return protectedThis.release(); -} - String Text::nodeName() const { return "#text"; diff --git a/engine/core/dom/Text.h b/engine/core/dom/Text.h index 66b04e990d6..89ebb0bc98a 100644 --- a/engine/core/dom/Text.h +++ b/engine/core/dom/Text.h @@ -40,16 +40,8 @@ public: RenderText* renderer() const; - // mergeNextSiblingNodesIfPossible() merges next sibling nodes if possible - // then returns a node not merged. - PassRefPtr mergeNextSiblingNodesIfPossible(); PassRefPtr splitText(unsigned offset, ExceptionState&); - // DOM Level 3: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1312295772 - - String wholeText() const; - PassRefPtr replaceWholeText(const String&); - void recalcTextStyle(StyleRecalcChange, Text* nextTextSibling); bool textRendererIsNeeded(const RenderStyle&, const RenderObject& parent); RenderText* createTextRenderer(RenderStyle*); diff --git a/engine/core/dom/Text.idl b/engine/core/dom/Text.idl index 9b6fcd98ca5..116566e3ee9 100644 --- a/engine/core/dom/Text.idl +++ b/engine/core/dom/Text.idl @@ -24,10 +24,6 @@ // DOM Level 1 [RaisesException] Text splitText(unsigned long offset); - // Introduced in DOM Level 3: - readonly attribute DOMString wholeText; - [MeasureAs=TextReplaceWholeText] Text replaceWholeText(DOMString content); // Removed from DOM4. - // Shadow DOM API NodeList getDestinationInsertionPoints(); }; diff --git a/engine/core/html/ime/InputMethodContext.cpp b/engine/core/html/ime/InputMethodContext.cpp index 0bbb5ac5a3d..5fe0d36baf0 100644 --- a/engine/core/html/ime/InputMethodContext.cpp +++ b/engine/core/html/ime/InputMethodContext.cpp @@ -95,15 +95,6 @@ bool InputMethodContext::hasFocus() const return element && element->isHTMLElement() && m_element == toHTMLElement(element); } -String InputMethodContext::compositionText() const -{ - if (!hasFocus()) - return emptyString(); - - Text* text = inputMethodController().compositionNode(); - return text ? text->wholeText() : emptyString(); -} - CompositionUnderline InputMethodContext::selectedSegment() const { CompositionUnderline underline; diff --git a/engine/core/html/ime/InputMethodContext.h b/engine/core/html/ime/InputMethodContext.h index b30a36e3773..f66f97d532b 100644 --- a/engine/core/html/ime/InputMethodContext.h +++ b/engine/core/html/ime/InputMethodContext.h @@ -63,7 +63,6 @@ public: unsigned compositionEndOffset(); void confirmComposition(); - String compositionText() const; int selectionStart() const; int selectionEnd() const; const Vector& segments();