Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Unified Diff: third_party/WebKit/Source/core/dom/Range.cpp

Issue 2775003003: Move Node::lengthOfContents into Range, its only user. (Closed)
Patch Set: const. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/Node.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Range.cpp
diff --git a/third_party/WebKit/Source/core/dom/Range.cpp b/third_party/WebKit/Source/core/dom/Range.cpp
index 938dfec2fd5f1c6284af20b88ace609fa7d671b0..338d8ff652ec60caeccb9ed18642b30384831cd8 100644
--- a/third_party/WebKit/Source/core/dom/Range.cpp
+++ b/third_party/WebKit/Source/core/dom/Range.cpp
@@ -26,8 +26,10 @@
#include "core/dom/Range.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "core/dom/CharacterData.h"
#include "core/dom/ClientRect.h"
#include "core/dom/ClientRectList.h"
+#include "core/dom/ContainerNode.h"
#include "core/dom/DocumentFragment.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/Node.h"
@@ -528,6 +530,27 @@ static inline Node* childOfCommonRootBeforeOffset(Node* container,
return container;
}
+static unsigned lengthOfContents(const Node* node) {
+ // This switch statement must be consistent with that of
+ // Range::processContentsBetweenOffsets.
+ switch (node->getNodeType()) {
+ case Node::kTextNode:
+ case Node::kCdataSectionNode:
+ case Node::kCommentNode:
+ case Node::kProcessingInstructionNode:
+ return toCharacterData(node)->length();
+ case Node::kElementNode:
+ case Node::kDocumentNode:
+ case Node::kDocumentFragmentNode:
+ return toContainerNode(node)->countChildren();
+ case Node::kAttributeNode:
+ case Node::kDocumentTypeNode:
+ return 0;
+ }
+ NOTREACHED();
+ return 0;
+}
+
DocumentFragment* Range::processContents(ActionType action,
ExceptionState& exceptionState) {
typedef HeapVector<Member<Node>> NodeVector;
@@ -587,7 +610,7 @@ DocumentFragment* Range::processContents(ActionType action,
commonRoot->contains(originalStart.container())) {
leftContents = processContentsBetweenOffsets(
action, nullptr, originalStart.container(), originalStart.offset(),
- originalStart.container()->lengthOfContents(), exceptionState);
+ lengthOfContents(originalStart.container()), exceptionState);
leftContents = processAncestorsAndTheirSiblings(
action, originalStart.container(), ProcessContentsForward, leftContents,
commonRoot, exceptionState);
@@ -675,7 +698,7 @@ Node* Range::processContentsBetweenOffsets(ActionType action,
DCHECK_LE(startOffset, endOffset);
// This switch statement must be consistent with that of
- // Node::lengthOfContents.
+ // lengthOfContents.
Node* result = nullptr;
switch (container->getNodeType()) {
case Node::kTextNode:
« no previous file with comments | « third_party/WebKit/Source/core/dom/Node.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698