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" |
| 47 #include "core/svg/SVGSVGElement.h" | |
| 46 #include "platform/geometry/FloatQuad.h" | 48 #include "platform/geometry/FloatQuad.h" |
| 47 #include "wtf/RefCountedLeakCounter.h" | 49 #include "wtf/RefCountedLeakCounter.h" |
| 48 #include "wtf/text/CString.h" | 50 #include "wtf/text/CString.h" |
| 49 #include "wtf/text/StringBuilder.h" | 51 #include "wtf/text/StringBuilder.h" |
| 50 #ifndef NDEBUG | 52 #ifndef NDEBUG |
| 51 #include <stdio.h> | 53 #include <stdio.h> |
| 52 #endif | 54 #endif |
| 53 | 55 |
| 54 namespace WebCore { | 56 namespace WebCore { |
| 55 | 57 |
| 56 using namespace std; | 58 using namespace std; |
| 57 using namespace HTMLNames; | |
| 58 | 59 |
| 59 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, rangeCounter, ("Range")); | 60 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, rangeCounter, ("Range")); |
| 60 | 61 |
| 61 inline Range::Range(Document& ownerDocument) | 62 inline Range::Range(Document& ownerDocument) |
| 62 : m_ownerDocument(&ownerDocument) | 63 : m_ownerDocument(&ownerDocument) |
| 63 , m_start(m_ownerDocument) | 64 , m_start(m_ownerDocument) |
| 64 , m_end(m_ownerDocument) | 65 , m_end(m_ownerDocument) |
| 65 { | 66 { |
| 66 #ifndef NDEBUG | 67 #ifndef NDEBUG |
| 67 rangeCounter.increment(); | 68 rangeCounter.increment(); |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 974 { | 975 { |
| 975 // We need to update layout, since plainText uses line boxes in the render t ree. | 976 // We need to update layout, since plainText uses line boxes in the render t ree. |
| 976 // FIXME: As with innerText, we'd like this to work even if there are no ren der objects. | 977 // FIXME: As with innerText, we'd like this to work even if there are no ren der objects. |
| 977 m_start.container()->document().updateLayout(); | 978 m_start.container()->document().updateLayout(); |
| 978 | 979 |
| 979 return plainText(this); | 980 return plainText(this); |
| 980 } | 981 } |
| 981 | 982 |
| 982 PassRefPtrWillBeRawPtr<DocumentFragment> Range::createContextualFragment(const S tring& markup, ExceptionState& exceptionState) | 983 PassRefPtrWillBeRawPtr<DocumentFragment> Range::createContextualFragment(const S tring& markup, ExceptionState& exceptionState) |
| 983 { | 984 { |
| 984 Node* element = m_start.container()->isElementNode() ? m_start.container() : m_start.container()->parentNode(); | 985 // Algorithm: http://domparsing.spec.whatwg.org/#extensions-to-the-range-int erface |
| 985 if (!element || !element->isHTMLElement()) { | 986 |
| 986 exceptionState.throwDOMException(NotSupportedError, "The range's contain er must be an HTML element."); | 987 Node* node = m_start.container(); |
| 988 | |
| 989 // Step 1. | |
| 990 RefPtrWillBeRawPtr<Element> element; | |
| 991 if (!m_start.offset() && (node->isDocumentNode() || node->isDocumentFragment ())) | |
| 992 element = nullptr; | |
| 993 else if (node->isElementNode()) | |
| 994 element = toElement(node); | |
| 995 else | |
| 996 element = node->parentElement(); | |
| 997 | |
| 998 // Step 2. | |
| 999 if (!element || isHTMLHtmlElement(element)) { | |
| 1000 Document& document = node->document(); | |
| 1001 | |
| 1002 if (document.isHTMLDocument() || document.isXHTMLDocument()) { | |
| 1003 // Optimization over spec: try to reuse the existing <body> element, if it is available. | |
| 1004 element = document.body(); | |
| 1005 if (!element) | |
| 1006 element = HTMLBodyElement::create(document); | |
|
eseidel
2014/06/04 15:00:22
It's a bit odd to pass in a detached contextElemen
pwnall-personal
2014/06/05 22:59:50
FWIW, in my interpretation of the spec, the Range'
| |
| 1007 } else if (document.isSVGDocument()) { | |
| 1008 element = document.documentElement(); | |
| 1009 if (!element) | |
| 1010 element = SVGSVGElement::create(document); | |
| 1011 } | |
| 1012 } | |
| 1013 | |
| 1014 if (!element || (!element->isHTMLElement() && !element->isSVGElement())) { | |
| 1015 exceptionState.throwDOMException(NotSupportedError, "The range's contain er must be an HTML or SVG Element, Document, or DocumentFragment."); | |
| 987 return nullptr; | 1016 return nullptr; |
| 988 } | 1017 } |
| 989 | 1018 |
| 990 RefPtrWillBeRawPtr<DocumentFragment> fragment = WebCore::createContextualFra gment(markup, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadySt arted, exceptionState); | 1019 // Steps 3, 4, 5. |
| 1020 RefPtrWillBeRawPtr<DocumentFragment> fragment = WebCore::createContextualFra gment(markup, element.get(), AllowScriptingContentAndDoNotMarkAlreadyStarted, ex ceptionState); | |
| 991 if (!fragment) | 1021 if (!fragment) |
| 992 return nullptr; | 1022 return nullptr; |
| 993 | 1023 |
| 994 return fragment.release(); | 1024 return fragment.release(); |
| 995 } | 1025 } |
| 996 | 1026 |
| 997 | 1027 |
| 998 void Range::detach() | 1028 void Range::detach() |
| 999 { | 1029 { |
| 1000 // This is now a no-op as per the DOM specification. | 1030 // This is now a no-op as per the DOM specification. |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1691 | 1721 |
| 1692 void showTree(const WebCore::Range* range) | 1722 void showTree(const WebCore::Range* range) |
| 1693 { | 1723 { |
| 1694 if (range && range->boundaryPointsValid()) { | 1724 if (range && range->boundaryPointsValid()) { |
| 1695 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); | 1725 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); |
| 1696 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); | 1726 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); |
| 1697 } | 1727 } |
| 1698 } | 1728 } |
| 1699 | 1729 |
| 1700 #endif | 1730 #endif |
| OLD | NEW |