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

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

Issue 44333002: Move innerHTML and outerHTML to Element (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased to latest master Created 7 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "core/dom/SelectorQuery.h" 65 #include "core/dom/SelectorQuery.h"
66 #include "core/dom/Text.h" 66 #include "core/dom/Text.h"
67 #include "core/dom/WhitespaceChildList.h" 67 #include "core/dom/WhitespaceChildList.h"
68 #include "core/dom/custom/CustomElement.h" 68 #include "core/dom/custom/CustomElement.h"
69 #include "core/dom/custom/CustomElementRegistrationContext.h" 69 #include "core/dom/custom/CustomElementRegistrationContext.h"
70 #include "core/dom/shadow/InsertionPoint.h" 70 #include "core/dom/shadow/InsertionPoint.h"
71 #include "core/dom/shadow/ShadowRoot.h" 71 #include "core/dom/shadow/ShadowRoot.h"
72 #include "core/editing/FrameSelection.h" 72 #include "core/editing/FrameSelection.h"
73 #include "core/editing/TextIterator.h" 73 #include "core/editing/TextIterator.h"
74 #include "core/editing/htmlediting.h" 74 #include "core/editing/htmlediting.h"
75 #include "core/editing/markup.h"
75 #include "core/events/EventDispatcher.h" 76 #include "core/events/EventDispatcher.h"
76 #include "core/events/FocusEvent.h" 77 #include "core/events/FocusEvent.h"
77 #include "core/frame/ContentSecurityPolicy.h" 78 #include "core/frame/ContentSecurityPolicy.h"
78 #include "core/frame/Frame.h" 79 #include "core/frame/Frame.h"
79 #include "core/frame/FrameView.h" 80 #include "core/frame/FrameView.h"
80 #include "core/html/ClassList.h" 81 #include "core/html/ClassList.h"
81 #include "core/html/HTMLCollection.h" 82 #include "core/html/HTMLCollection.h"
82 #include "core/html/HTMLDocument.h" 83 #include "core/html/HTMLDocument.h"
83 #include "core/html/HTMLElement.h" 84 #include "core/html/HTMLElement.h"
84 #include "core/html/HTMLFormControlsCollection.h" 85 #include "core/html/HTMLFormControlsCollection.h"
85 #include "core/html/HTMLFrameOwnerElement.h" 86 #include "core/html/HTMLFrameOwnerElement.h"
86 #include "core/html/HTMLLabelElement.h" 87 #include "core/html/HTMLLabelElement.h"
87 #include "core/html/HTMLOptionsCollection.h" 88 #include "core/html/HTMLOptionsCollection.h"
88 #include "core/html/HTMLTableRowsCollection.h" 89 #include "core/html/HTMLTableRowsCollection.h"
90 #include "core/html/HTMLTemplateElement.h"
89 #include "core/html/parser/HTMLParserIdioms.h" 91 #include "core/html/parser/HTMLParserIdioms.h"
90 #include "core/page/FocusController.h" 92 #include "core/page/FocusController.h"
91 #include "core/page/Page.h" 93 #include "core/page/Page.h"
92 #include "core/page/PointerLockController.h" 94 #include "core/page/PointerLockController.h"
93 #include "core/rendering/FlowThreadController.h" 95 #include "core/rendering/FlowThreadController.h"
94 #include "core/rendering/RenderRegion.h" 96 #include "core/rendering/RenderRegion.h"
95 #include "core/rendering/RenderView.h" 97 #include "core/rendering/RenderView.h"
96 #include "core/rendering/RenderWidget.h" 98 #include "core/rendering/RenderWidget.h"
97 #include "core/svg/SVGDocumentExtensions.h" 99 #include "core/svg/SVGDocumentExtensions.h"
98 #include "core/svg/SVGElement.h" 100 #include "core/svg/SVGElement.h"
(...skipping 2096 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 dispatchScopedEventDispatchMediator(FocusInEventDispatchMediator::create(Foc usEvent::create(eventType, true, false, document().domWindow(), 0, oldFocusedEle ment))); 2197 dispatchScopedEventDispatchMediator(FocusInEventDispatchMediator::create(Foc usEvent::create(eventType, true, false, document().domWindow(), 0, oldFocusedEle ment)));
2196 } 2198 }
2197 2199
2198 void Element::dispatchFocusOutEvent(const AtomicString& eventType, Element* newF ocusedElement) 2200 void Element::dispatchFocusOutEvent(const AtomicString& eventType, Element* newF ocusedElement)
2199 { 2201 {
2200 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); 2202 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
2201 ASSERT(eventType == EventTypeNames::focusout || eventType == EventTypeNames: :DOMFocusOut); 2203 ASSERT(eventType == EventTypeNames::focusout || eventType == EventTypeNames: :DOMFocusOut);
2202 dispatchScopedEventDispatchMediator(FocusOutEventDispatchMediator::create(Fo cusEvent::create(eventType, true, false, document().domWindow(), 0, newFocusedEl ement))); 2204 dispatchScopedEventDispatchMediator(FocusOutEventDispatchMediator::create(Fo cusEvent::create(eventType, true, false, document().domWindow(), 0, newFocusedEl ement)));
2203 } 2205 }
2204 2206
2207 String Element::innerHTML() const
2208 {
2209 return createMarkup(this, ChildrenOnly);
2210 }
2211
2212 String Element::outerHTML() const
2213 {
2214 return createMarkup(this);
2215 }
2216
2217 void Element::setInnerHTML(const String& html, ExceptionState& es)
2218 {
2219 if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html , this, AllowScriptingContent, "innerHTML", es)) {
2220 ContainerNode* container = this;
2221 if (hasTagName(templateTag))
2222 container = toHTMLTemplateElement(this)->content();
2223 replaceChildrenWithFragment(container, fragment.release(), es);
2224 }
2225 }
2226
2227 void Element::setOuterHTML(const String& html, ExceptionState& es)
2228 {
2229 Node* p = parentNode();
2230 if (!p || !p->isElementNode()) {
2231 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
2232 return;
2233 }
2234 RefPtr<Element> parent = toElement(p);
2235 RefPtr<Node> prev = previousSibling();
2236 RefPtr<Node> next = nextSibling();
2237
2238 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, pa rent.get(), AllowScriptingContent, "outerHTML", es);
2239 if (es.hadException())
2240 return;
2241
2242 parent->replaceChild(fragment.release(), this, es);
2243 RefPtr<Node> node = next ? next->previousSibling() : 0;
2244 if (!es.hadException() && node && node->isTextNode())
2245 mergeWithNextTextNode(node.release(), es);
2246
2247 if (!es.hadException() && prev && prev->isTextNode())
2248 mergeWithNextTextNode(prev.release(), es);
2249 }
2250
2205 String Element::innerText() 2251 String Element::innerText()
2206 { 2252 {
2207 // We need to update layout, since plainText uses line boxes in the render t ree. 2253 // We need to update layout, since plainText uses line boxes in the render t ree.
2208 document().updateLayoutIgnorePendingStylesheets(); 2254 document().updateLayoutIgnorePendingStylesheets();
2209 2255
2210 if (!renderer()) 2256 if (!renderer())
2211 return textContent(true); 2257 return textContent(true);
2212 2258
2213 return plainText(rangeOfContents(const_cast<Element*>(this)).get()); 2259 return plainText(rangeOfContents(const_cast<Element*>(this)).get());
2214 } 2260 }
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
3425 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems 3471 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems
3426 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 3472 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405
3427 if (hasTagName(optionTag) || hasTagName(optgroupTag)) 3473 if (hasTagName(optionTag) || hasTagName(optgroupTag))
3428 return false; 3474 return false;
3429 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3475 if (FullscreenElementStack::isActiveFullScreenElement(this))
3430 return false; 3476 return false;
3431 return true; 3477 return true;
3432 } 3478 }
3433 3479
3434 } // namespace WebCore 3480 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698