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

Side by Side Diff: Source/core/dom/Range.cpp

Issue 25571006: Fix out-of-date offset in selection range code. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Test with description. Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
5 * (C) 2001 Peter Kelly (pmk@post.com) 5 * (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 if (es.hadException()) 1034 if (es.hadException())
1035 return; 1035 return;
1036 1036
1037 if (collapsed) 1037 if (collapsed)
1038 m_end.setToBeforeChild(newText.get()); 1038 m_end.setToBeforeChild(newText.get());
1039 } else { 1039 } else {
1040 RefPtr<Node> lastChild; 1040 RefPtr<Node> lastChild;
1041 if (collapsed) 1041 if (collapsed)
1042 lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? newNode- >lastChild() : newNode; 1042 lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? newNode- >lastChild() : newNode;
1043 1043
1044 int startOffset = m_start.offset();
1045 container = m_start.container(); 1044 container = m_start.container();
1046 container->insertBefore(newNode.release(), container->childNode(startOff set), es); 1045 container->insertBefore(newNode.release(), container->childNode(m_start. offset()), es);
1047 if (es.hadException()) 1046 if (es.hadException())
1048 return; 1047 return;
1049 1048
1049 // Note that m_start.offset() may have changed as a result of container- >insertBefore,
1050 // when the node we are inserting comes before the range in the same con tainer.
1050 if (collapsed && numNewChildren) 1051 if (collapsed && numNewChildren)
1051 m_end.set(m_start.container(), startOffset + numNewChildren, lastChi ld.get()); 1052 m_end.set(m_start.container(), m_start.offset() + numNewChildren, la stChild.get());
yosin_UTC9 2013/10/03 01:41:19 Does |numNewChildren| keep right value when mutati
1052 } 1053 }
1053 } 1054 }
1054 1055
1055 String Range::toString(ExceptionState& es) const 1056 String Range::toString(ExceptionState& es) const
1056 { 1057 {
1057 if (!m_start.container()) { 1058 if (!m_start.container()) {
1058 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("toString", "Range", "The range has no container. Perhaps 'detatch()' has bee n invoked on this object?")); 1059 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("toString", "Range", "The range has no container. Perhaps 'detatch()' has bee n invoked on this object?"));
1059 return String(); 1060 return String();
1060 } 1061 }
1061 1062
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 1902
1902 void showTree(const WebCore::Range* range) 1903 void showTree(const WebCore::Range* range)
1903 { 1904 {
1904 if (range && range->boundaryPointsValid()) { 1905 if (range && range->boundaryPointsValid()) {
1905 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1906 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1906 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1907 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1907 } 1908 }
1908 } 1909 }
1909 1910
1910 #endif 1911 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698