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

Unified Diff: Source/core/dom/Element.cpp

Issue 52443003: Reland 160869 "Move innerHTML and outerHTML to Element" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index 41c734aa68083ac7e8da55ccc916ff6d1dcdfd13..1602593cadb0486cc9543e6a16b79764018144ef 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -72,6 +72,7 @@
#include "core/editing/FrameSelection.h"
#include "core/editing/TextIterator.h"
#include "core/editing/htmlediting.h"
+#include "core/editing/markup.h"
#include "core/events/EventDispatcher.h"
#include "core/events/FocusEvent.h"
#include "core/frame/ContentSecurityPolicy.h"
@@ -86,6 +87,7 @@
#include "core/html/HTMLLabelElement.h"
#include "core/html/HTMLOptionsCollection.h"
#include "core/html/HTMLTableRowsCollection.h"
+#include "core/html/HTMLTemplateElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/page/FocusController.h"
#include "core/page/Page.h"
@@ -2202,6 +2204,50 @@ void Element::dispatchFocusOutEvent(const AtomicString& eventType, Element* newF
dispatchScopedEventDispatchMediator(FocusOutEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document().domWindow(), 0, newFocusedElement)));
}
+String Element::innerHTML() const
+{
+ return createMarkup(this, ChildrenOnly);
+}
+
+String Element::outerHTML() const
+{
+ return createMarkup(this);
+}
+
+void Element::setInnerHTML(const String& html, ExceptionState& es)
+{
+ if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, "innerHTML", es)) {
+ ContainerNode* container = this;
+ if (hasTagName(templateTag))
+ container = toHTMLTemplateElement(this)->content();
+ replaceChildrenWithFragment(container, fragment.release(), es);
+ }
+}
+
+void Element::setOuterHTML(const String& html, ExceptionState& es)
+{
+ Node* p = parentNode();
+ if (!p || !p->isElementNode()) {
+ es.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
+ return;
+ }
+ RefPtr<Element> parent = toElement(p);
+ RefPtr<Node> prev = previousSibling();
+ RefPtr<Node> next = nextSibling();
+
+ RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, parent.get(), AllowScriptingContent, "outerHTML", es);
+ if (es.hadException())
+ return;
+
+ parent->replaceChild(fragment.release(), this, es);
+ RefPtr<Node> node = next ? next->previousSibling() : 0;
+ if (!es.hadException() && node && node->isTextNode())
+ mergeWithNextTextNode(node.release(), es);
+
+ if (!es.hadException() && prev && prev->isTextNode())
+ mergeWithNextTextNode(prev.release(), es);
+}
+
String Element::innerText()
{
// We need to update layout, since plainText uses line boxes in the render tree.
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/Element.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698