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

Unified Diff: Source/core/html/HTMLLabelElement.cpp

Issue 404833003: Move HTMLLabelElement-related complexity out of Element (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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/html/HTMLLabelElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLLabelElement.cpp
diff --git a/Source/core/html/HTMLLabelElement.cpp b/Source/core/html/HTMLLabelElement.cpp
index c18f34344bfef47c07f3348924208e255ffe234b..643fbf32bff33194cdf9f77583903c9f8a85951b 100644
--- a/Source/core/html/HTMLLabelElement.cpp
+++ b/Source/core/html/HTMLLabelElement.cpp
@@ -200,4 +200,49 @@ void HTMLLabelElement::accessKeyAction(bool sendMouseEvents)
HTMLElement::accessKeyAction(sendMouseEvents);
}
+void HTMLLabelElement::updateLabel(TreeScope& scope, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue)
+{
+ if (!inDocument())
+ return;
+
+ if (oldForAttributeValue == newForAttributeValue)
+ return;
+
+ if (!oldForAttributeValue.isEmpty())
+ scope.removeLabel(oldForAttributeValue, toHTMLLabelElement(this));
+ if (!newForAttributeValue.isEmpty())
+ scope.addLabel(newForAttributeValue, toHTMLLabelElement(this));
+}
+
+void HTMLLabelElement::attributeWillChange(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
+{
+ if (name == HTMLNames::forAttr) {
+ TreeScope& scope = treeScope();
+ if (scope.shouldCacheLabelsByForAttribute())
+ updateLabel(scope, oldValue, newValue);
+ }
+ HTMLElement::attributeWillChange(name, oldValue, newValue);
+}
+
+Node::InsertionNotificationRequest HTMLLabelElement::insertedInto(ContainerNode* insertionPoint)
+{
+ InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoint);
+ if (insertionPoint->isInTreeScope()) {
+ TreeScope& scope = insertionPoint->treeScope();
+ if (scope == treeScope() && scope.shouldCacheLabelsByForAttribute())
+ updateLabel(scope, nullAtom, fastGetAttribute(forAttr));
+ }
+ return result;
+}
+
+void HTMLLabelElement::removedFrom(ContainerNode* insertionPoint)
+{
+ if (insertionPoint->isInTreeScope() && treeScope() == document()) {
+ TreeScope& treeScope = insertionPoint->treeScope();
+ if (treeScope.shouldCacheLabelsByForAttribute())
+ updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom);
+ }
+ HTMLElement::removedFrom(insertionPoint);
+}
+
} // namespace
« no previous file with comments | « Source/core/html/HTMLLabelElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698