OLD | NEW |
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 |
11 * License as published by the Free Software Foundation; either | 11 * License as published by the Free Software Foundation; either |
12 * version 2 of the License, or (at your option) any later version. | 12 * version 2 of the License, or (at your option) any later version. |
13 * | 13 * |
14 * This library is distributed in the hope that it will be useful, | 14 * This library is distributed in the hope that it will be useful, |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 * Library General Public License for more details. | 17 * Library General Public License for more details. |
18 * | 18 * |
19 * You should have received a copy of the GNU Library General Public License | 19 * You should have received a copy of the GNU Library General Public License |
20 * along with this library; see the file COPYING.LIB. If not, write to | 20 * along with this library; see the file COPYING.LIB. If not, write to |
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 * Boston, MA 02110-1301, USA. | 22 * Boston, MA 02110-1301, USA. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #include "core/dom/Range.h" | 26 #include "core/dom/Range.h" |
27 | 27 |
| 28 #include "HTMLNames.h" |
28 #include "bindings/v8/ExceptionState.h" | 29 #include "bindings/v8/ExceptionState.h" |
29 #include "core/dom/ClientRect.h" | 30 #include "core/dom/ClientRect.h" |
30 #include "core/dom/ClientRectList.h" | 31 #include "core/dom/ClientRectList.h" |
31 #include "core/dom/DocumentFragment.h" | 32 #include "core/dom/DocumentFragment.h" |
32 #include "core/dom/ExceptionCode.h" | 33 #include "core/dom/ExceptionCode.h" |
33 #include "core/dom/Node.h" | 34 #include "core/dom/Node.h" |
34 #include "core/dom/NodeTraversal.h" | 35 #include "core/dom/NodeTraversal.h" |
35 #include "core/dom/NodeWithIndex.h" | 36 #include "core/dom/NodeWithIndex.h" |
36 #include "core/dom/ProcessingInstruction.h" | 37 #include "core/dom/ProcessingInstruction.h" |
37 #include "core/events/ScopedEventQueue.h" | |
38 #include "core/dom/Text.h" | 38 #include "core/dom/Text.h" |
39 #include "core/editing/TextIterator.h" | 39 #include "core/editing/TextIterator.h" |
40 #include "core/editing/VisiblePosition.h" | 40 #include "core/editing/VisiblePosition.h" |
41 #include "core/editing/VisibleUnits.h" | 41 #include "core/editing/VisibleUnits.h" |
42 #include "core/editing/markup.h" | 42 #include "core/editing/markup.h" |
| 43 #include "core/events/ScopedEventQueue.h" |
| 44 #include "core/html/HTMLBodyElement.h" |
| 45 #include "core/html/HTMLDocument.h" |
43 #include "core/html/HTMLElement.h" | 46 #include "core/html/HTMLElement.h" |
44 #include "core/rendering/RenderBoxModelObject.h" | 47 #include "core/rendering/RenderBoxModelObject.h" |
45 #include "core/rendering/RenderText.h" | 48 #include "core/rendering/RenderText.h" |
| 49 #include "core/svg/SVGElement.h" |
46 #include "platform/geometry/FloatQuad.h" | 50 #include "platform/geometry/FloatQuad.h" |
47 #include "wtf/RefCountedLeakCounter.h" | 51 #include "wtf/RefCountedLeakCounter.h" |
48 #include "wtf/text/CString.h" | 52 #include "wtf/text/CString.h" |
49 #include "wtf/text/StringBuilder.h" | 53 #include "wtf/text/StringBuilder.h" |
50 #ifndef NDEBUG | 54 #ifndef NDEBUG |
51 #include <stdio.h> | 55 #include <stdio.h> |
52 #endif | 56 #endif |
53 | 57 |
54 namespace WebCore { | 58 namespace WebCore { |
55 | 59 |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 | 1100 |
1097 // We need to update layout, since plainText uses line boxes in the render t
ree. | 1101 // We need to update layout, since plainText uses line boxes in the render t
ree. |
1098 // FIXME: As with innerText, we'd like this to work even if there are no ren
der objects. | 1102 // FIXME: As with innerText, we'd like this to work even if there are no ren
der objects. |
1099 m_start.container()->document().updateLayout(); | 1103 m_start.container()->document().updateLayout(); |
1100 | 1104 |
1101 return plainText(this); | 1105 return plainText(this); |
1102 } | 1106 } |
1103 | 1107 |
1104 PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& marku
p, ExceptionState& exceptionState) | 1108 PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& marku
p, ExceptionState& exceptionState) |
1105 { | 1109 { |
1106 if (!m_start.container()) { | 1110 // Algorithm at http://domparsing.spec.whatwg.org/#extensions-to-the-range-i
nterface |
| 1111 |
| 1112 Node* startContainer = m_start.container(); |
| 1113 if (!startContainer) { |
1107 exceptionState.throwDOMException(InvalidStateError, "The range has no co
ntainer. Perhaps 'detatch()' has been invoked on this object?"); | 1114 exceptionState.throwDOMException(InvalidStateError, "The range has no co
ntainer. Perhaps 'detatch()' has been invoked on this object?"); |
1108 return 0; | 1115 return 0; |
1109 } | 1116 } |
1110 | 1117 |
1111 Node* element = m_start.container()->isElementNode() ? m_start.container() :
m_start.container()->parentNode(); | 1118 // Step 1. |
1112 if (!element || !element->isHTMLElement()) { | 1119 Node* element; |
1113 exceptionState.throwDOMException(NotSupportedError, "The range's contain
er must be an HTML element."); | 1120 if (!m_start.offset() && (m_start.container()->isDocumentNode() || m_start.c
ontainer()->isDocumentFragment())) { |
1114 return 0; | 1121 element = 0; |
| 1122 } else if (startContainer->isElementNode()) { |
| 1123 element = startContainer; |
| 1124 } else { |
| 1125 element = startContainer->parentNode(); |
| 1126 if (!element || !element->isElementNode()) { |
| 1127 exceptionState.throwDOMException(NotSupportedError, "The range's con
tainer must be an Element, Document, or DocumentFragment."); |
| 1128 return 0; |
| 1129 } |
1115 } | 1130 } |
| 1131 ASSERT(!element || element->isElementNode()); |
1116 | 1132 |
1117 RefPtr<DocumentFragment> fragment = WebCore::createContextualFragment(markup
, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, excep
tionState); | 1133 // Step 2. |
| 1134 RefPtr<HTMLBodyElement> fakeBody = 0; |
| 1135 if (!element || (element->isHTMLElement() && toHTMLElement(element)->hasLoca
lName(HTMLNames::htmlTag))) { |
| 1136 // Try to use the existing <body> element, if it is available. |
| 1137 if (startContainer->document().isHTMLDocument()) // FIXME: this returns
false for XHTML documents, and they probably have a <body> |
| 1138 element = toHTMLDocument(startContainer->document()).htmlBodyElement
(); |
| 1139 |
| 1140 if (!element) { |
| 1141 fakeBody = HTMLBodyElement::create(startContainer->document()); |
| 1142 element = fakeBody.get(); |
| 1143 } |
| 1144 } else { |
| 1145 if (!element->isHTMLElement() && !element->isSVGElement()) { |
| 1146 exceptionState.throwDOMException(NotSupportedError, "The range's con
tainer must be an Element, Document, or DocumentFragment."); |
| 1147 return 0; |
| 1148 } |
| 1149 } |
| 1150 ASSERT(element && (element->isHTMLElement() || element->isSVGElement())); |
| 1151 |
| 1152 // Steps 3, 4, 5. |
| 1153 RefPtr<DocumentFragment> fragment; |
| 1154 if (element->isHTMLElement()) |
| 1155 fragment = WebCore::createContextualFragment(markup, toHTMLElement(eleme
nt), AllowScriptingContentAndDoNotMarkAlreadyStarted, exceptionState); |
| 1156 else |
| 1157 fragment = WebCore::createContextualFragment(markup, toSVGElement(elemen
t), AllowScriptingContentAndDoNotMarkAlreadyStarted, exceptionState); |
| 1158 |
1118 if (!fragment) | 1159 if (!fragment) |
1119 return 0; | 1160 return 0; |
1120 | 1161 |
1121 return fragment.release(); | 1162 return fragment.release(); |
1122 } | 1163 } |
1123 | 1164 |
1124 | 1165 |
1125 void Range::detach(ExceptionState& exceptionState) | 1166 void Range::detach(ExceptionState& exceptionState) |
1126 { | 1167 { |
1127 // Check first to see if we've already detached: | 1168 // Check first to see if we've already detached: |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 | 1956 |
1916 void showTree(const WebCore::Range* range) | 1957 void showTree(const WebCore::Range* range) |
1917 { | 1958 { |
1918 if (range && range->boundaryPointsValid()) { | 1959 if (range && range->boundaryPointsValid()) { |
1919 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1960 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
1920 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1961 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
1921 } | 1962 } |
1922 } | 1963 } |
1923 | 1964 |
1924 #endif | 1965 #endif |
OLD | NEW |