Remove lots of Text APIs.

I also removed Node#normalize() which is Text related
and doesn't seem like something we need. Frameworks
can implement it if needed.

Remove most of the media stack.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/698213002
This commit is contained in:
Elliott Sprehn 2014-11-03 22:34:23 -08:00
parent 4ecaa91c6c
commit e2a6aca882
7 changed files with 0 additions and 181 deletions

View File

@ -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> 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;

View File

@ -168,7 +168,6 @@ public:
bool hasChildren() const { return firstChild(); }
virtual PassRefPtr<Node> cloneNode(bool deep = false) = 0;
virtual const AtomicString& localName() const;
void normalize();
bool isSameNode(Node* other) const { return this == other; }
bool isEqualNode(Node*) const;

View File

@ -48,55 +48,6 @@ PassRefPtr<Text> Text::createEditingText(Document& document, const String& data)
return adoptRef(new Text(document, data, CreateEditingText));
}
PassRefPtr<Node> Text::mergeNextSiblingNodesIfPossible()
{
RefPtr<Node> protect(this);
// Remove empty text nodes.
if (!length()) {
// Care must be taken to get the next node before removing the current node.
RefPtr<Node> 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<Text> 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> Text::splitText(unsigned offset, ExceptionState& exceptionState)
{
// IndexSizeError: Raised if the specified offset is negative or greater than
@ -127,96 +78,6 @@ PassRefPtr<Text> 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<unsigned>::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> 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<Text> startText = const_cast<Text*>(earliestLogicallyAdjacentTextNode(this));
RefPtr<Text> endText = const_cast<Text*>(latestLogicallyAdjacentTextNode(this));
RefPtr<Text> protectedThis(this); // Mutation event handlers could cause our last ref to go away
RefPtr<ContainerNode> parent = parentNode(); // Protect against mutation handlers moving this node during traversal
for (RefPtr<Node> n = startText; n && n != this && n->isTextNode() && n->parentNode() == parent;) {
RefPtr<Node> nodeToRemove(n.release());
n = nodeToRemove->nextSibling();
parent->removeChild(nodeToRemove.get(), IGNORE_EXCEPTION);
}
if (this != endText) {
Node* onePastEndText = endText->nextSibling();
for (RefPtr<Node> n = nextSibling(); n && n != onePastEndText && n->isTextNode() && n->parentNode() == parent;) {
RefPtr<Node> 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";

View File

@ -40,16 +40,8 @@ public:
RenderText* renderer() const;
// mergeNextSiblingNodesIfPossible() merges next sibling nodes if possible
// then returns a node not merged.
PassRefPtr<Node> mergeNextSiblingNodesIfPossible();
PassRefPtr<Text> splitText(unsigned offset, ExceptionState&);
// DOM Level 3: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1312295772
String wholeText() const;
PassRefPtr<Text> replaceWholeText(const String&);
void recalcTextStyle(StyleRecalcChange, Text* nextTextSibling);
bool textRendererIsNeeded(const RenderStyle&, const RenderObject& parent);
RenderText* createTextRenderer(RenderStyle*);

View File

@ -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();
};

View File

@ -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;

View File

@ -63,7 +63,6 @@ public:
unsigned compositionEndOffset();
void confirmComposition();
String compositionText() const;
int selectionStart() const;
int selectionEnd() const;
const Vector<unsigned>& segments();