Chromium Code Reviews| 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 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 #include "core/dom/Node.h" | 33 #include "core/dom/Node.h" |
| 34 #include "core/dom/NodeTraversal.h" | 34 #include "core/dom/NodeTraversal.h" |
| 35 #include "core/dom/NodeWithIndex.h" | 35 #include "core/dom/NodeWithIndex.h" |
| 36 #include "core/dom/ProcessingInstruction.h" | 36 #include "core/dom/ProcessingInstruction.h" |
| 37 #include "core/dom/Text.h" | 37 #include "core/dom/Text.h" |
| 38 #include "core/editing/TextIterator.h" | 38 #include "core/editing/TextIterator.h" |
| 39 #include "core/editing/VisiblePosition.h" | 39 #include "core/editing/VisiblePosition.h" |
| 40 #include "core/editing/VisibleUnits.h" | 40 #include "core/editing/VisibleUnits.h" |
| 41 #include "core/editing/markup.h" | 41 #include "core/editing/markup.h" |
| 42 #include "core/events/ScopedEventQueue.h" | 42 #include "core/events/ScopedEventQueue.h" |
| 43 #include "core/html/HTMLBodyElement.h" | |
| 43 #include "core/html/HTMLElement.h" | 44 #include "core/html/HTMLElement.h" |
| 44 #include "core/rendering/RenderBoxModelObject.h" | 45 #include "core/rendering/RenderBoxModelObject.h" |
| 45 #include "core/rendering/RenderText.h" | 46 #include "core/rendering/RenderText.h" |
| 46 #include "platform/geometry/FloatQuad.h" | 47 #include "platform/geometry/FloatQuad.h" |
| 47 #include "wtf/RefCountedLeakCounter.h" | 48 #include "wtf/RefCountedLeakCounter.h" |
| 48 #include "wtf/text/CString.h" | 49 #include "wtf/text/CString.h" |
| 49 #include "wtf/text/StringBuilder.h" | 50 #include "wtf/text/StringBuilder.h" |
| 50 #ifndef NDEBUG | 51 #ifndef NDEBUG |
| 51 #include <stdio.h> | 52 #include <stdio.h> |
| 52 #endif | 53 #endif |
| 53 | 54 |
| 54 namespace WebCore { | 55 namespace WebCore { |
| 55 | 56 |
| 56 using namespace std; | 57 using namespace std; |
| 57 using namespace HTMLNames; | |
| 58 | 58 |
| 59 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, rangeCounter, ("Range")); | 59 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, rangeCounter, ("Range")); |
| 60 | 60 |
| 61 inline Range::Range(Document& ownerDocument) | 61 inline Range::Range(Document& ownerDocument) |
| 62 : m_ownerDocument(&ownerDocument) | 62 : m_ownerDocument(&ownerDocument) |
| 63 , m_start(m_ownerDocument) | 63 , m_start(m_ownerDocument) |
| 64 , m_end(m_ownerDocument) | 64 , m_end(m_ownerDocument) |
| 65 { | 65 { |
| 66 #ifndef NDEBUG | 66 #ifndef NDEBUG |
| 67 rangeCounter.increment(); | 67 rangeCounter.increment(); |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 { | 972 { |
| 973 // We need to update layout, since plainText uses line boxes in the render t ree. | 973 // We need to update layout, since plainText uses line boxes in the render t ree. |
| 974 // FIXME: As with innerText, we'd like this to work even if there are no ren der objects. | 974 // FIXME: As with innerText, we'd like this to work even if there are no ren der objects. |
| 975 m_start.container()->document().updateLayout(); | 975 m_start.container()->document().updateLayout(); |
| 976 | 976 |
| 977 return plainText(this); | 977 return plainText(this); |
| 978 } | 978 } |
| 979 | 979 |
| 980 PassRefPtrWillBeRawPtr<DocumentFragment> Range::createContextualFragment(const S tring& markup, ExceptionState& exceptionState) | 980 PassRefPtrWillBeRawPtr<DocumentFragment> Range::createContextualFragment(const S tring& markup, ExceptionState& exceptionState) |
| 981 { | 981 { |
| 982 Node* element = m_start.container()->isElementNode() ? m_start.container() : m_start.container()->parentNode(); | 982 // Algorithm: http://domparsing.spec.whatwg.org/#extensions-to-the-range-int erface |
| 983 if (!element || !element->isHTMLElement()) { | 983 |
| 984 exceptionState.throwDOMException(NotSupportedError, "The range's contain er must be an HTML element."); | 984 Node* node = m_start.container(); |
| 985 return nullptr; | 985 |
| 986 // Step 1. | |
| 987 RefPtrWillBeRawPtr<Element> element; | |
| 988 if (!m_start.offset() && (node->isDocumentNode() || node->isDocumentFragment ())) { | |
| 989 element = nullptr; | |
| 990 } else if (node->isElementNode()) { | |
| 991 element = toElement(node); | |
| 992 } else { | |
| 993 element = node->parentElement(); | |
| 994 if (!element) { | |
| 995 exceptionState.throwDOMException(NotSupportedError, "The range's con tainer must be an Element, Document, or DocumentFragment."); | |
|
eseidel
2014/06/03 00:32:46
We could be more specific here. It's just that Ra
pwnall-personal
2014/06/04 06:54:37
I re-read the spec, and I'm pretty sure we can get
| |
| 996 return nullptr; | |
| 997 } | |
| 986 } | 998 } |
| 987 | 999 |
| 988 RefPtrWillBeRawPtr<DocumentFragment> fragment = WebCore::createContextualFra gment(markup, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadySt arted, exceptionState); | 1000 // Step 2. |
| 1001 if (!element || isHTMLHtmlElement(element)) { | |
| 1002 Document& document = node->document(); | |
| 1003 | |
| 1004 if (document.isSVGDocument()) { | |
|
eseidel
2014/06/03 00:27:02
I think you want to reverse this, no? If it's an
pwnall-personal
2014/06/04 06:54:37
Done.
Sorry, for some reason I confused XML and X
| |
| 1005 element = document.documentElement(); | |
| 1006 } else { | |
| 1007 // Optimization over spec: try to reuse the existing <body> element, if it is available. | |
| 1008 ASSERT(document.isHTMLDocument() || document.isXHTMLDocument()); | |
| 1009 element = document.body(); | |
| 1010 } | |
| 1011 | |
| 1012 if (!element) { | |
| 1013 // SVG documents always have an <svg> root element, should never nee d a fake node. | |
|
eseidel
2014/06/03 00:27:02
I'm not sure that's true. an empty .svg file migh
pwnall-personal
2014/06/04 06:54:38
You're right. Thank you very much for pointing tha
| |
| 1014 ASSERT(!document.isSVGDocument()); | |
| 1015 element = HTMLBodyElement::create(document); | |
|
eseidel
2014/06/03 00:32:46
I don't really understand what this is going to do
pwnall-personal
2014/06/04 06:54:38
At least as far as the spec is concerned, the fake
| |
| 1016 } | |
| 1017 } else { | |
| 1018 if (!element->isHTMLElement() && !element->isSVGElement()) { | |
| 1019 exceptionState.throwDOMException(NotSupportedError, "The range's con tainer must be an Element, Document, or DocumentFragment."); | |
|
eseidel
2014/06/03 00:27:02
We throw this in multiple places? Why even bother
pwnall-personal
2014/06/04 06:54:38
Now the exception is only thrown in one place, if
| |
| 1020 return nullptr; | |
| 1021 } | |
| 1022 } | |
| 1023 ASSERT(element && (element->isHTMLElement() || element->isSVGElement())); | |
|
eseidel
2014/06/03 00:32:46
If you bumped the other if (!element) out of the e
pwnall-personal
2014/06/04 06:54:38
Done.
| |
| 1024 | |
| 1025 // Steps 3, 4, 5. | |
| 1026 RefPtrWillBeRawPtr<DocumentFragment> fragment = WebCore::createContextualFra gment(markup, element.get(), AllowScriptingContentAndDoNotMarkAlreadyStarted, ex ceptionState); | |
| 989 if (!fragment) | 1027 if (!fragment) |
| 990 return nullptr; | 1028 return nullptr; |
| 991 | 1029 |
| 992 return fragment.release(); | 1030 return fragment.release(); |
| 993 } | 1031 } |
| 994 | 1032 |
| 995 | 1033 |
| 996 void Range::detach() | 1034 void Range::detach() |
| 997 { | 1035 { |
| 998 // This is now a no-op as per the DOM specification. | 1036 // This is now a no-op as per the DOM specification. |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1688 | 1726 |
| 1689 void showTree(const WebCore::Range* range) | 1727 void showTree(const WebCore::Range* range) |
| 1690 { | 1728 { |
| 1691 if (range && range->boundaryPointsValid()) { | 1729 if (range && range->boundaryPointsValid()) { |
| 1692 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); | 1730 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); |
| 1693 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); | 1731 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); |
| 1694 } | 1732 } |
| 1695 } | 1733 } |
| 1696 | 1734 |
| 1697 #endif | 1735 #endif |
| OLD | NEW |