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

Unified 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, 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
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index dcc525a5e8b869143f617ac65f55e063a2d58e35..24252585f41457cf50e650bf6c68bce48d4dd060 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.

Powered by Google App Engine
This is Rietveld 408576698