Diff
Modified: trunk/LayoutTests/ChangeLog (97586 => 97587)
--- trunk/LayoutTests/ChangeLog 2011-10-17 06:02:33 UTC (rev 97586)
+++ trunk/LayoutTests/ChangeLog 2011-10-17 06:05:00 UTC (rev 97587)
@@ -1,3 +1,16 @@
+2011-10-16 Ryosuke Niwa <rn...@webkit.org>
+
+ Expose rangeFromLocationAndLength and locationAndLengthFromRange via internals object
+ https://bugs.webkit.org/show_bug.cgi?id=68330
+
+ Reviewed by Hajime Morita.
+
+ Add a basic test that uses internals.rangeFromLocationAndLength, internals.locationFromRange,
+ and internals.lengthFromRange.
+
+ * editing/text-iterator/range-to-from-location-and-length-expected.txt: Added.
+ * editing/text-iterator/range-to-from-location-and-length.html: Added.
+
2011-10-16 Kent Tamura <tk...@chromium.org>
Update test exepctations.
Added: trunk/LayoutTests/editing/text-iterator/range-to-from-location-and-length-expected.txt (0 => 97587)
--- trunk/LayoutTests/editing/text-iterator/range-to-from-location-and-length-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/text-iterator/range-to-from-location-and-length-expected.txt 2011-10-17 06:05:00 UTC (rev 97587)
@@ -0,0 +1,16 @@
+PASS locationAndLengthFromRange(range(p.firstChild, 0, p.firstChild, 3)) is [0, 1]
+PASS locationAndLengthFromRange(range(p.firstChild, 1, p.firstChild, 4)) is [0, 2]
+PASS locationAndLengthFromRange(range(p.firstChild, 2, p.firstChild, 3)) is [0, 1]
+PASS internals.rangeFromLocationAndLength(container, 0, 1).toArray() is [p.firstChild, 2, p.firstChild, 3]
+PASS locationAndLengthFromRange(range(p.firstChild, 2, p.firstChild, 7)) is [0, 5]
+PASS locationAndLengthFromRange(range(p.firstChild, 2, p, 1)) is [0, 5]
+PASS locationAndLengthFromRange(range(p.firstChild, 2, p, 2)) is [0, 6]
+PASS locationAndLengthFromRange(range(p.firstChild, 2, p.childNodes[2], 1)) is [0, 6]
+PASS internals.rangeFromLocationAndLength(container, 1, 4).toArray() is [p.firstChild, 3, p.firstChild, 7]
+PASS internals.rangeFromLocationAndLength(container, 0, 6).toArray() is [p.firstChild, 2, p.childNodes[2], 1]
+PASS locationAndLengthFromRange(range(p.childNodes[2], 6, p, 3)) is [11, 1]
+FAIL internals.rangeFromLocationAndLength(container, 11, 2).toArray() should be [object Text],6,[object HTMLDivElement],0. Was [object Text],6,[object HTMLParagraphElement],3.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/editing/text-iterator/range-to-from-location-and-length.html (0 => 97587)
--- trunk/LayoutTests/editing/text-iterator/range-to-from-location-and-length.html (rev 0)
+++ trunk/LayoutTests/editing/text-iterator/range-to-from-location-and-length.html 2011-10-17 06:05:00 UTC (rev 97587)
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+</head>
+<body>
+<div id="test" contenteditable>
+<p> hello<br>
+world.</p>
+<blockquote><div>|<br></div></blockquote>
+<em>webkit</em>
+</div>
+<div id="console"></div>
+<script>
+
+if (!window.internals)
+ testFailed('This test requires internals object');
+else {
+ var container = document.getElementById('test');
+
+ function range(startContainer, startOffset, endContainer, endOffset) {
+ var range = document.createRange();
+ range.setStart(startContainer, startOffset);
+ range.setEnd(endContainer, endOffset);
+ return range;
+ }
+
+ function locationAndLengthFromRange(range) {
+ var location = internals.locationFromRange(container, range);
+ var length = internals.lengthFromRange(container, range);
+ return [location, length];
+ }
+
+ Range.prototype.toArray = function () {
+ return [this.startContainer, this.startOffset, this.endContainer, this.endOffset];
+ }
+
+ var p = document.querySelector('#test p');
+ var div = document.querySelector('#test div');
+ var r = internals.rangeFromLocationAndLength(container, 0, 1);
+ shouldBe('locationAndLengthFromRange(range(p.firstChild, 0, p.firstChild, 3))', '[0, 1]');
+ shouldBe('locationAndLengthFromRange(range(p.firstChild, 1, p.firstChild, 4))', '[0, 2]');
+ shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p.firstChild, 3))', '[0, 1]');
+ shouldBe('internals.rangeFromLocationAndLength(container, 0, 1).toArray()', '[p.firstChild, 2, p.firstChild, 3]');
+
+ shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p.firstChild, 7))', '[0, 5]');
+ shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p, 1))', '[0, 5]');
+ shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p, 2))', '[0, 6]');
+ shouldBe('locationAndLengthFromRange(range(p.firstChild, 2, p.childNodes[2], 1))', '[0, 6]');
+ shouldBe('internals.rangeFromLocationAndLength(container, 1, 4).toArray()', '[p.firstChild, 3, p.firstChild, 7]');
+ shouldBe('internals.rangeFromLocationAndLength(container, 0, 6).toArray()', '[p.firstChild, 2, p.childNodes[2], 1]');
+
+ shouldBe('locationAndLengthFromRange(range(p.childNodes[2], 6, p, 3))', '[11, 1]');
+ shouldBe('internals.rangeFromLocationAndLength(container, 11, 2).toArray()', '[p.childNodes[2], 6, div, 0]');
+
+ container.style.display = 'none';
+}
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (97586 => 97587)
--- trunk/Source/WebCore/ChangeLog 2011-10-17 06:02:33 UTC (rev 97586)
+++ trunk/Source/WebCore/ChangeLog 2011-10-17 06:05:00 UTC (rev 97587)
@@ -1,3 +1,23 @@
+2011-10-16 Ryosuke Niwa <rn...@webkit.org>
+
+ Expose rangeFromLocationAndLength and locationAndLengthFromRange via internals object
+ https://bugs.webkit.org/show_bug.cgi?id=68330
+
+ Reviewed by Hajime Morita.
+
+ Add rangeFromLocationAndLength, locationFromRange, and lengthFromRange to window.internals.
+
+ Test: editing/text-iterator/range-to-from-location-and-length.html
+
+ * WebCore.exp.in:
+ * testing/Internals.cpp:
+ (WebCore::Internals::scrollElementToRect):
+ (WebCore::Internals::rangeFromLocationAndLength):
+ (WebCore::Internals::locationFromRange):
+ (WebCore::Internals::lengthFromRange):
+ * testing/Internals.h:
+ * testing/Internals.idl:
+
2011-10-16 Kentaro Hara <hara...@chromium.org>
Generate MessageChannel constructor by [Constructor] IDL
Modified: trunk/Source/WebCore/WebCore.exp.in (97586 => 97587)
--- trunk/Source/WebCore/WebCore.exp.in 2011-10-17 06:02:33 UTC (rev 97586)
+++ trunk/Source/WebCore/WebCore.exp.in 2011-10-17 06:05:00 UTC (rev 97587)
@@ -877,6 +877,7 @@
__ZN7WebCore7cookiesEPKNS_8DocumentERKNS_4KURLE
__ZN7WebCore7nsColorERKNS_5ColorE
__ZN7WebCore7replaceERN3WTF6StringERKNS_17RegularExpressionERKS1_
+__ZN7WebCore7toRangeEN3JSC7JSValueE
__ZN7WebCore8Document11createRangeEv
__ZN7WebCore8Document12updateLayoutEv
__ZN7WebCore8Document13svgExtensionsEv
Modified: trunk/Source/WebCore/testing/Internals.cpp (97586 => 97587)
--- trunk/Source/WebCore/testing/Internals.cpp 2011-10-17 06:02:33 UTC (rev 97586)
+++ trunk/Source/WebCore/testing/Internals.cpp 2011-10-17 06:05:00 UTC (rev 97587)
@@ -41,19 +41,22 @@
#include "IntRect.h"
#include "NodeRenderingContext.h"
#include "Page.h"
-#if ENABLE(GESTURE_EVENTS)
-#include "PlatformGestureEvent.h"
-#endif
#include "Range.h"
#include "RenderObject.h"
#include "RenderTreeAsText.h"
-#if ENABLE(SMOOTH_SCROLLING)
-#include "ScrollAnimator.h"
-#endif
#include "Settings.h"
#include "ShadowContentElement.h"
#include "ShadowRoot.h"
+#include "TextIterator.h"
+#if ENABLE(GESTURE_EVENTS)
+#include "PlatformGestureEvent.h"
+#endif
+
+#if ENABLE(SMOOTH_SCROLLING)
+#include "ScrollAnimator.h"
+#endif
+
#if ENABLE(INPUT_COLOR)
#include "ColorChooser.h"
#endif
@@ -414,6 +417,16 @@
inputElement->setSuggestedValue(value);
}
+void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionCode& ec)
+{
+ if (!element || !element->document() || !element->document()->view()) {
+ ec = INVALID_ACCESS_ERR;
+ return;
+ }
+ FrameView* frameView = element->document()->view();
+ frameView->scrollElementToRect(element, IntRect(x, y, w, h));
+}
+
void Internals::paintControlTints(Document* document, ExceptionCode& ec)
{
if (!document || !document->view()) {
@@ -425,14 +438,39 @@
frameView->paintControlTints();
}
-void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionCode& ec)
+PassRefPtr<Range> Internals::rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode& ec)
{
- if (!element || !element->document() || !element->document()->view()) {
+ if (!scope) {
ec = INVALID_ACCESS_ERR;
- return;
+ return 0;
}
- FrameView* frameView = element->document()->view();
- frameView->scrollElementToRect(element, IntRect(x, y, w, h));
+
+ return TextIterator::rangeFromLocationAndLength(scope, rangeLocation, rangeLength);
}
+unsigned Internals::locationFromRange(Element* scope, const Range* range, ExceptionCode& ec)
+{
+ if (!scope || !range) {
+ ec = INVALID_ACCESS_ERR;
+ return 0;
+ }
+
+ size_t location = 0;
+ size_t unusedLength = 0;
+ TextIterator::getLocationAndLengthFromRange(scope, range, location, unusedLength);
+ return location;
}
+
+unsigned Internals::lengthFromRange(Element* scope, const Range* range, ExceptionCode& ec)
+{
+ if (!scope || !range) {
+ ec = INVALID_ACCESS_ERR;
+ return 0;
+ }
+
+ size_t unusedLocation = 0;
+ size_t length = 0;
+ TextIterator::getLocationAndLengthFromRange(scope, range, unusedLocation, length);
+ return length;
+}
+}
Modified: trunk/Source/WebCore/testing/Internals.h (97586 => 97587)
--- trunk/Source/WebCore/testing/Internals.h 2011-10-17 06:02:33 UTC (rev 97586)
+++ trunk/Source/WebCore/testing/Internals.h 2011-10-17 06:05:00 UTC (rev 97587)
@@ -92,10 +92,14 @@
void setSuggestedValue(Element* inputElement, const String&, ExceptionCode&);
void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionCode&);
+ void paintControlTints(Document*, ExceptionCode&);
+
+ PassRefPtr<Range> rangeFromLocationAndLength(Element* scope, int rangeLocation, int rangeLength, ExceptionCode&);
+ unsigned locationFromRange(Element* scope, const Range*, ExceptionCode&);
+ unsigned lengthFromRange(Element* scope, const Range*, ExceptionCode&);
+
static const char* internalsId;
- void paintControlTints(Document*, ExceptionCode&);
-
private:
Internals();
Modified: trunk/Source/WebCore/testing/Internals.idl (97586 => 97587)
--- trunk/Source/WebCore/testing/Internals.idl 2011-10-17 06:02:33 UTC (rev 97586)
+++ trunk/Source/WebCore/testing/Internals.idl 2011-10-17 06:05:00 UTC (rev 97587)
@@ -67,6 +67,10 @@
void paintControlTints(in Document document) raises (DOMException);
void scrollElementToRect(in Element element, in long x, in long y, in long w, in long h) raises (DOMException);
+
+ Range rangeFromLocationAndLength(in Element scope, in long rangeLocation, in long rangeLength) raises (DOMException);
+ unsigned long locationFromRange(in Element scope, in Range range) raises (DOMException);
+ unsigned long lengthFromRange(in Element scope, in Range range) raises (DOMException);
};
}
Modified: trunk/Source/WebKit2/win/WebKit2.def (97586 => 97587)
--- trunk/Source/WebKit2/win/WebKit2.def 2011-10-17 06:02:33 UTC (rev 97586)
+++ trunk/Source/WebKit2/win/WebKit2.def 2011-10-17 06:05:00 UTC (rev 97587)
@@ -156,14 +156,16 @@
?externalRepresentation@WebCore@@YA?AVString@WTF@@PAVElement@1@I@Z
?getCachedDOMStructure@WebCore@@YAPAVStructure@JSC@@PAVJSDOMGlobalObject@1@PBUClassInfo@3@@Z
?getElementById@TreeScope@WebCore@@QBEPAVElement@2@ABVAtomicString@WTF@@@Z
+ ?getLocationAndLengthFromRange@TextIterator@WebCore@@SA_NPAVElement@2@PBVRange@2@AAI2@Z
?isPreloaded@CachedResourceLoader@WebCore@@QBE_NABVString@WTF@@@Z
?jsStringSlowCase@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@AAV?$HashMap@PAVStringImpl@WTF@@V?$Weak@VJSString@JSC@@@JSC@@UStringHash@2@U?$HashTraits@PAVStringImpl@WTF@@@2@U?$HashTraits@V?$Weak@VJSString@JSC@@@JSC@@@2@@WTF@@PAVStringImpl@6@@Z
?lastChangeWasUserEdit@HTMLTextFormControlElement@WebCore@@QBE_NXZ
?markersFor@DocumentMarkerController@WebCore@@QAE?AV?$Vector@PAVDocumentMarker@WebCore@@$0A@@WTF@@PAVNode@2@@Z
?page@Document@WebCore@@QBEPAVPage@2@XZ
?paintControlTints@FrameView@WebCore@@AAEXXZ
+ ?rangeFromLocationAndLength@TextIterator@WebCore@@SA?AV?$PassRefPtr@VRange@WebCore@@@WTF@@PAVElement@2@HH_N@Z
+ ?removeShadowRoot@Element@WebCore@@QAEXXZ
?scrollElementToRect@FrameView@WebCore@@QAEXPAVElement@2@ABVIntRect@2@@Z
- ?removeShadowRoot@Element@WebCore@@QAEXXZ
?setDOMException@WebCore@@YAXPAVExecState@JSC@@H@Z
?setResourcesDataSizeLimitsFromInternals@InspectorController@WebCore@@QAEXHH@Z
?setScrollbarsSuppressed@ScrollView@WebCore@@QAEX_N0@Z
@@ -177,6 +179,7 @@
?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVClientRect@1@@Z
?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVNode@1@@Z
?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVRange@1@@Z
+ ?toRange@WebCore@@YAPAVRange@1@VJSValue@JSC@@@Z
?updateLayoutIgnorePendingStylesheets@Document@WebCore@@QAEXXZ
?view@Document@WebCore@@QBEPAVFrameView@2@XZ
?virtualFunctionToPreventWeakVtable@JSDOMWrapper@WebCore@@MAEXXZ
Modified: trunk/Source/autotools/symbols.filter (97586 => 97587)
--- trunk/Source/autotools/symbols.filter 2011-10-17 06:02:33 UTC (rev 97586)
+++ trunk/Source/autotools/symbols.filter 2011-10-17 06:05:00 UTC (rev 97587)
@@ -41,7 +41,8 @@
_ZN7WebCore11EventTarget17toGeneratedStreamEv;
_ZN7WebCore11EventTarget8toStreamEv;
_ZN7WebCore12JSDOMWrapper34virtualFunctionToPreventWeakVtableEv;
-_ZNK7WebCore12RenderObject23absoluteBoundingBoxRectEb;
+_ZN7WebCore12TextIterator26rangeFromLocationAndLengthEPNS_7ElementEiib;
+_ZN7WebCore12TextIterator29getLocationAndLengthFromRangeEPNS_7ElementEPKNS_5RangeERmS6_;
_ZN7WebCore13createWrapperEPN3JSC9ExecStateEPNS_17JSDOMGlobalObjectEPNS_4NodeE;
_ZN7WebCore15setDOMExceptionEPN3JSC9ExecStateEi;
_ZN7WebCore16HTMLInputElement17setSuggestedValueERKN3WTF6StringE;
@@ -60,9 +61,11 @@
_ZN7WebCore6toNodeEN3JSC7JSValueE;
_ZN7WebCore7Element16ensureShadowRootEv;
_ZN7WebCore7Element16removeShadowRootEv;
+_ZN7WebCore7toRangeEN3JSC7JSValueE;
_ZN7WebCore9JSElement10putVirtualEPN3JSC9ExecStateERKNS1_10IdentifierENS1_7JSValueERNS1_15PutPropertySlotE;
_ZN7WebCore9JSElement6s_infoE;
_ZN7WebCore9toElementEN3JSC7JSValueE;
+_ZNK7WebCore12RenderObject23absoluteBoundingBoxRectEb;
_ZNK7WebCore16HTMLInputElement14suggestedValueEv;
_ZNK7WebCore20CachedResourceLoader11isPreloadedERKN3WTF6StringE;
_ZNK7WebCore26HTMLTextFormControlElement21lastChangeWasUserEditEv;