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

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

Issue 115693010: Fix Range.createContextualFragment for non-Element contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 6 years, 6 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
« no previous file with comments | « LayoutTests/http/tests/dom/resources/svg-document.svg ('k') | Source/core/editing/markup.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
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 HTMLNames;
57
58 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, rangeCounter, ("Range")); 58 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, rangeCounter, ("Range"));
59 59
60 inline Range::Range(Document& ownerDocument) 60 inline Range::Range(Document& ownerDocument)
61 : m_ownerDocument(&ownerDocument) 61 : m_ownerDocument(&ownerDocument)
62 , m_start(m_ownerDocument) 62 , m_start(m_ownerDocument)
63 , m_end(m_ownerDocument) 63 , m_end(m_ownerDocument)
64 { 64 {
65 #ifndef NDEBUG 65 #ifndef NDEBUG
66 rangeCounter.increment(); 66 rangeCounter.increment();
67 #endif 67 #endif
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 { 952 {
953 // We need to update layout, since plainText uses line boxes in the render t ree. 953 // We need to update layout, since plainText uses line boxes in the render t ree.
954 // FIXME: As with innerText, we'd like this to work even if there are no ren der objects. 954 // FIXME: As with innerText, we'd like this to work even if there are no ren der objects.
955 m_start.container()->document().updateLayout(); 955 m_start.container()->document().updateLayout();
956 956
957 return plainText(this); 957 return plainText(this);
958 } 958 }
959 959
960 PassRefPtrWillBeRawPtr<DocumentFragment> Range::createContextualFragment(const S tring& markup, ExceptionState& exceptionState) 960 PassRefPtrWillBeRawPtr<DocumentFragment> Range::createContextualFragment(const S tring& markup, ExceptionState& exceptionState)
961 { 961 {
962 Node* element = m_start.container()->isElementNode() ? m_start.container() : m_start.container()->parentNode(); 962 // Algorithm: http://domparsing.spec.whatwg.org/#extensions-to-the-range-int erface
963 if (!element || !element->isHTMLElement()) { 963
964 exceptionState.throwDOMException(NotSupportedError, "The range's contain er must be an HTML element."); 964 Node* node = m_start.container();
965
966 // Step 1.
967 RefPtrWillBeRawPtr<Element> element;
968 if (!m_start.offset() && (node->isDocumentNode() || node->isDocumentFragment ()))
969 element = nullptr;
970 else if (node->isElementNode())
971 element = toElement(node);
972 else
973 element = node->parentElement();
974
975 // Step 2.
976 if (!element || isHTMLHtmlElement(element)) {
977 Document& document = node->document();
978
979 if (document.isHTMLDocument() || document.isXHTMLDocument()) {
980 // Optimization over spec: try to reuse the existing <body> element, if it is available.
981 element = document.body();
982 if (!element)
983 element = HTMLBodyElement::create(document);
984 } else if (document.isSVGDocument()) {
985 element = document.documentElement();
986 if (!element)
987 element = SVGSVGElement::create(document);
988 }
989 }
990
991 if (!element || (!element->isHTMLElement() && !element->isSVGElement())) {
992 exceptionState.throwDOMException(NotSupportedError, "The range's contain er must be an HTML or SVG Element, Document, or DocumentFragment.");
965 return nullptr; 993 return nullptr;
966 } 994 }
967 995
968 RefPtrWillBeRawPtr<DocumentFragment> fragment = WebCore::createContextualFra gment(markup, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadySt arted, exceptionState); 996 // Steps 3, 4, 5.
997 RefPtrWillBeRawPtr<DocumentFragment> fragment = WebCore::createContextualFra gment(markup, element.get(), AllowScriptingContentAndDoNotMarkAlreadyStarted, ex ceptionState);
969 if (!fragment) 998 if (!fragment)
970 return nullptr; 999 return nullptr;
971 1000
972 return fragment.release(); 1001 return fragment.release();
973 } 1002 }
974 1003
975 1004
976 void Range::detach() 1005 void Range::detach()
977 { 1006 {
978 // This is now a no-op as per the DOM specification. 1007 // This is now a no-op as per the DOM specification.
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 1713
1685 void showTree(const WebCore::Range* range) 1714 void showTree(const WebCore::Range* range)
1686 { 1715 {
1687 if (range && range->boundaryPointsValid()) { 1716 if (range && range->boundaryPointsValid()) {
1688 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1717 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1689 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1718 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1690 } 1719 }
1691 } 1720 }
1692 1721
1693 #endif 1722 #endif
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/dom/resources/svg-document.svg ('k') | Source/core/editing/markup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698