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

Side by Side Diff: Source/core/html/HTMLLabelElement.cpp

Issue 569993002: <label> should support form association by parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase + TestCase Created 6 years, 3 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
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 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 19 matching lines...) Expand all
30 #include "core/dom/ElementTraversal.h" 30 #include "core/dom/ElementTraversal.h"
31 #include "core/editing/FrameSelection.h" 31 #include "core/editing/FrameSelection.h"
32 #include "core/events/MouseEvent.h" 32 #include "core/events/MouseEvent.h"
33 #include "core/frame/LocalFrame.h" 33 #include "core/frame/LocalFrame.h"
34 #include "core/html/FormAssociatedElement.h" 34 #include "core/html/FormAssociatedElement.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 using namespace HTMLNames; 38 using namespace HTMLNames;
39 39
40 inline HTMLLabelElement::HTMLLabelElement(Document& document) 40 inline HTMLLabelElement::HTMLLabelElement(Document& document, HTMLFormElement* f orm)
41 : HTMLElement(labelTag, document) 41 : HTMLElement(labelTag, document)
42 { 42 {
43 FormAssociatedElement::associateByParser(form);
43 } 44 }
44 45
45 DEFINE_NODE_FACTORY(HTMLLabelElement) 46 PassRefPtrWillBeRawPtr<HTMLLabelElement> HTMLLabelElement::create(Document& docu ment, HTMLFormElement* form)
47 {
48 RefPtrWillBeRawPtr<HTMLLabelElement> labelElement = adoptRefWillBeNoop(new H TMLLabelElement(document, form));
49 return labelElement.release();
50 }
46 51
47 bool HTMLLabelElement::rendererIsFocusable() const 52 bool HTMLLabelElement::rendererIsFocusable() const
48 { 53 {
49 HTMLLabelElement* that = const_cast<HTMLLabelElement*>(this); 54 HTMLLabelElement* that = const_cast<HTMLLabelElement*>(this);
50 return that->isContentEditable(); 55 return that->isContentEditable();
51 } 56 }
52 57
53 LabelableElement* HTMLLabelElement::control() const 58 LabelableElement* HTMLLabelElement::control() const
54 { 59 {
55 const AtomicString& controlId = getAttribute(forAttr); 60 const AtomicString& controlId = getAttribute(forAttr);
(...skipping 11 matching lines...) Expand all
67 if (Element* element = treeScope().getElementById(controlId)) { 72 if (Element* element = treeScope().getElementById(controlId)) {
68 if (isLabelableElement(*element) && toLabelableElement(*element).support Labels()) 73 if (isLabelableElement(*element) && toLabelableElement(*element).support Labels())
69 return toLabelableElement(element); 74 return toLabelableElement(element);
70 } 75 }
71 76
72 return 0; 77 return 0;
73 } 78 }
74 79
75 HTMLFormElement* HTMLLabelElement::formOwner() const 80 HTMLFormElement* HTMLLabelElement::formOwner() const
76 { 81 {
77 return FormAssociatedElement::findAssociatedForm(this); 82 return !fastGetAttribute(formAttr).isNull() ? FormAssociatedElement::findAss ociatedForm(this) : FormAssociatedElement::form();
keishi 2014/09/16 01:59:19 I think we shouldn't need to use findAssociatedFor
spartha 2014/09/17 11:02:18 Done.
78 } 83 }
79 84
80 void HTMLLabelElement::setActive(bool down) 85 void HTMLLabelElement::setActive(bool down)
81 { 86 {
82 if (down == active()) 87 if (down == active())
83 return; 88 return;
84 89
85 // Update our status first. 90 // Update our status first.
86 HTMLElement::setActive(down); 91 HTMLElement::setActive(down);
87 92
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 195 }
191 196
192 void HTMLLabelElement::updateLabel(TreeScope& scope, const AtomicString& oldForA ttributeValue, const AtomicString& newForAttributeValue) 197 void HTMLLabelElement::updateLabel(TreeScope& scope, const AtomicString& oldForA ttributeValue, const AtomicString& newForAttributeValue)
193 { 198 {
194 if (!inDocument()) 199 if (!inDocument())
195 return; 200 return;
196 201
197 if (oldForAttributeValue == newForAttributeValue) 202 if (oldForAttributeValue == newForAttributeValue)
198 return; 203 return;
199 204
205 HTMLElement* label = this;
200 if (!oldForAttributeValue.isEmpty()) 206 if (!oldForAttributeValue.isEmpty())
201 scope.removeLabel(oldForAttributeValue, toHTMLLabelElement(this)); 207 scope.removeLabel(oldForAttributeValue, toHTMLLabelElement(label));
keishi 2014/09/16 01:59:19 I think we don't need to use toHTMLLabelElement an
spartha 2014/09/17 11:02:18 Done.
202 if (!newForAttributeValue.isEmpty()) 208 if (!newForAttributeValue.isEmpty())
203 scope.addLabel(newForAttributeValue, toHTMLLabelElement(this)); 209 scope.addLabel(newForAttributeValue, toHTMLLabelElement(label));
204 } 210 }
205 211
206 void HTMLLabelElement::attributeWillChange(const QualifiedName& name, const Atom icString& oldValue, const AtomicString& newValue) 212 void HTMLLabelElement::attributeWillChange(const QualifiedName& name, const Atom icString& oldValue, const AtomicString& newValue)
207 { 213 {
208 if (name == HTMLNames::forAttr) { 214 if (name == HTMLNames::forAttr) {
209 TreeScope& scope = treeScope(); 215 TreeScope& scope = treeScope();
210 if (scope.shouldCacheLabelsByForAttribute()) 216 if (scope.shouldCacheLabelsByForAttribute())
211 updateLabel(scope, oldValue, newValue); 217 updateLabel(scope, oldValue, newValue);
212 } 218 }
213 HTMLElement::attributeWillChange(name, oldValue, newValue); 219 HTMLElement::attributeWillChange(name, oldValue, newValue);
214 } 220 }
215 221
216 Node::InsertionNotificationRequest HTMLLabelElement::insertedInto(ContainerNode* insertionPoint) 222 Node::InsertionNotificationRequest HTMLLabelElement::insertedInto(ContainerNode* insertionPoint)
217 { 223 {
218 InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoi nt); 224 InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoi nt);
225 FormAssociatedElement::insertedInto(insertionPoint);
219 if (insertionPoint->isInTreeScope()) { 226 if (insertionPoint->isInTreeScope()) {
220 TreeScope& scope = insertionPoint->treeScope(); 227 TreeScope& scope = insertionPoint->treeScope();
221 if (scope == treeScope() && scope.shouldCacheLabelsByForAttribute()) 228 if (scope == treeScope() && scope.shouldCacheLabelsByForAttribute())
222 updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); 229 updateLabel(scope, nullAtom, fastGetAttribute(forAttr));
223 } 230 }
224 return result; 231 return result;
225 } 232 }
226 233
227 void HTMLLabelElement::removedFrom(ContainerNode* insertionPoint) 234 void HTMLLabelElement::removedFrom(ContainerNode* insertionPoint)
228 { 235 {
229 if (insertionPoint->isInTreeScope() && treeScope() == document()) { 236 if (insertionPoint->isInTreeScope() && treeScope() == document()) {
230 TreeScope& treeScope = insertionPoint->treeScope(); 237 TreeScope& treeScope = insertionPoint->treeScope();
231 if (treeScope.shouldCacheLabelsByForAttribute()) 238 if (treeScope.shouldCacheLabelsByForAttribute())
232 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); 239 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom);
233 } 240 }
234 HTMLElement::removedFrom(insertionPoint); 241 HTMLElement::removedFrom(insertionPoint);
242 FormAssociatedElement::removedFrom(insertionPoint);
243 }
244
245 void HTMLLabelElement::trace(Visitor* visitor)
246 {
247 HTMLElement::trace(visitor);
248 FormAssociatedElement::trace(visitor);
235 } 249 }
236 250
237 } // namespace 251 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698