OLD | NEW |
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 24 matching lines...) Expand all Loading... |
35 #include "core/frame/UseCounter.h" | 35 #include "core/frame/UseCounter.h" |
36 #include "core/html/FormAssociatedElement.h" | 36 #include "core/html/FormAssociatedElement.h" |
37 #include "core/html/HTMLFormControlElement.h" | 37 #include "core/html/HTMLFormControlElement.h" |
38 #include "core/input/EventHandler.h" | 38 #include "core/input/EventHandler.h" |
39 #include "core/layout/LayoutObject.h" | 39 #include "core/layout/LayoutObject.h" |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 using namespace HTMLNames; | 43 using namespace HTMLNames; |
44 | 44 |
45 inline HTMLLabelElement::HTMLLabelElement(Document& document, HTMLFormElement* f
orm) | 45 inline HTMLLabelElement::HTMLLabelElement(Document& document) |
46 : HTMLElement(labelTag, document) | 46 : HTMLElement(labelTag, document) |
47 , m_processingClick(false) | 47 , m_processingClick(false) |
48 { | 48 { |
49 FormAssociatedElement::associateByParser(form); | |
50 } | 49 } |
51 | 50 |
52 HTMLLabelElement* HTMLLabelElement::create(Document& document, HTMLFormElement*
form) | 51 HTMLLabelElement* HTMLLabelElement::create(Document& document) |
53 { | 52 { |
54 HTMLLabelElement* labelElement = new HTMLLabelElement(document, form); | 53 return new HTMLLabelElement(document); |
55 return labelElement; | |
56 } | 54 } |
57 | 55 |
58 LabelableElement* HTMLLabelElement::control() const | 56 LabelableElement* HTMLLabelElement::control() const |
59 { | 57 { |
60 const AtomicString& controlId = getAttribute(forAttr); | 58 const AtomicString& controlId = getAttribute(forAttr); |
61 if (controlId.isNull()) { | 59 if (controlId.isNull()) { |
62 // Search the children and descendants of the label element for a form e
lement. | 60 // Search the children and descendants of the label element for a form e
lement. |
63 // per http://dev.w3.org/html5/spec/Overview.html#the-label-element | 61 // per http://dev.w3.org/html5/spec/Overview.html#the-label-element |
64 // the form element must be "labelable form-associated element". | 62 // the form element must be "labelable form-associated element". |
65 for (LabelableElement& element : Traversal<LabelableElement>::descendant
sOf(*this)) { | 63 for (LabelableElement& element : Traversal<LabelableElement>::descendant
sOf(*this)) { |
(...skipping 10 matching lines...) Expand all Loading... |
76 if (isLabelableElement(*element) && toLabelableElement(*element).support
Labels()) { | 74 if (isLabelableElement(*element) && toLabelableElement(*element).support
Labels()) { |
77 if (!element->isFormControlElement()) | 75 if (!element->isFormControlElement()) |
78 UseCounter::count(document(), UseCounter::HTMLLabelElementContro
lForNonFormAssociatedElement); | 76 UseCounter::count(document(), UseCounter::HTMLLabelElementContro
lForNonFormAssociatedElement); |
79 return toLabelableElement(element); | 77 return toLabelableElement(element); |
80 } | 78 } |
81 } | 79 } |
82 | 80 |
83 return nullptr; | 81 return nullptr; |
84 } | 82 } |
85 | 83 |
86 HTMLFormElement* HTMLLabelElement::formOwner() const | 84 HTMLFormElement* HTMLLabelElement::form() const |
87 { | 85 { |
88 return FormAssociatedElement::form(); | 86 if (LabelableElement* control = this->control()) |
89 } | 87 return control->isFormControlElement() ? toHTMLFormControlElement(contro
l)->form() : nullptr; |
90 | 88 return nullptr; |
91 HTMLFormElement* HTMLLabelElement::formForBinding() const | |
92 { | |
93 HTMLFormElement* formOwner = FormAssociatedElement::form(); | |
94 HTMLFormElement* controlForm = nullptr; | |
95 if (LabelableElement* control = this->control()) { | |
96 if (control->isFormControlElement()) | |
97 controlForm = toHTMLFormControlElement(control)->form(); | |
98 } | |
99 if (formOwner != controlForm) | |
100 UseCounter::count(document(), UseCounter::HTMLLabelElementFormIsDifferen
tFromControlForm); | |
101 if (!controlForm && formOwner && formOwner == findFormAncestor()) | |
102 UseCounter::count(document(), UseCounter::HTMLLabelElementHasNoControlAn
dFormIsAncestor); | |
103 return formOwner; | |
104 } | 89 } |
105 | 90 |
106 void HTMLLabelElement::setActive(bool down) | 91 void HTMLLabelElement::setActive(bool down) |
107 { | 92 { |
108 if (down != active()) { | 93 if (down != active()) { |
109 // Update our status first. | 94 // Update our status first. |
110 HTMLElement::setActive(down); | 95 HTMLElement::setActive(down); |
111 } | 96 } |
112 | 97 |
113 // Also update our corresponding control. | 98 // Also update our corresponding control. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 238 |
254 if (!oldForAttributeValue.isEmpty()) | 239 if (!oldForAttributeValue.isEmpty()) |
255 scope.removeLabel(oldForAttributeValue, this); | 240 scope.removeLabel(oldForAttributeValue, this); |
256 if (!newForAttributeValue.isEmpty()) | 241 if (!newForAttributeValue.isEmpty()) |
257 scope.addLabel(newForAttributeValue, this); | 242 scope.addLabel(newForAttributeValue, this); |
258 } | 243 } |
259 | 244 |
260 Node::InsertionNotificationRequest HTMLLabelElement::insertedInto(ContainerNode*
insertionPoint) | 245 Node::InsertionNotificationRequest HTMLLabelElement::insertedInto(ContainerNode*
insertionPoint) |
261 { | 246 { |
262 InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoi
nt); | 247 InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoi
nt); |
263 FormAssociatedElement::insertedInto(insertionPoint); | |
264 if (insertionPoint->isInTreeScope()) { | 248 if (insertionPoint->isInTreeScope()) { |
265 TreeScope& scope = insertionPoint->treeScope(); | 249 TreeScope& scope = insertionPoint->treeScope(); |
266 if (scope == treeScope() && scope.shouldCacheLabelsByForAttribute()) | 250 if (scope == treeScope() && scope.shouldCacheLabelsByForAttribute()) |
267 updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); | 251 updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); |
268 } | 252 } |
269 | 253 |
270 // Trigger for elements outside of forms. | 254 // Trigger for elements outside of forms. |
271 if (!formOwner() && insertionPoint->inShadowIncludingDocument()) | 255 if (!formOwner() && insertionPoint->inShadowIncludingDocument()) |
272 document().didAssociateFormControl(this); | 256 document().didAssociateFormControl(this); |
273 | 257 |
274 return result; | 258 return result; |
275 } | 259 } |
276 | 260 |
277 void HTMLLabelElement::removedFrom(ContainerNode* insertionPoint) | 261 void HTMLLabelElement::removedFrom(ContainerNode* insertionPoint) |
278 { | 262 { |
279 if (insertionPoint->isInTreeScope() && treeScope() == document()) { | 263 if (insertionPoint->isInTreeScope() && treeScope() == document()) { |
280 TreeScope& treeScope = insertionPoint->treeScope(); | 264 TreeScope& treeScope = insertionPoint->treeScope(); |
281 if (treeScope.shouldCacheLabelsByForAttribute()) | 265 if (treeScope.shouldCacheLabelsByForAttribute()) |
282 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); | 266 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); |
283 } | 267 } |
284 HTMLElement::removedFrom(insertionPoint); | 268 HTMLElement::removedFrom(insertionPoint); |
285 FormAssociatedElement::removedFrom(insertionPoint); | |
286 document().removeFormAssociation(this); | 269 document().removeFormAssociation(this); |
287 } | 270 } |
288 | 271 |
289 DEFINE_TRACE(HTMLLabelElement) | |
290 { | |
291 HTMLElement::trace(visitor); | |
292 FormAssociatedElement::trace(visitor); | |
293 } | |
294 | |
295 void HTMLLabelElement::parseAttribute(const QualifiedName& attributeName, const
AtomicString& oldValue, const AtomicString& attributeValue) | 272 void HTMLLabelElement::parseAttribute(const QualifiedName& attributeName, const
AtomicString& oldValue, const AtomicString& attributeValue) |
296 { | 273 { |
297 if (attributeName == formAttr) { | 274 if (attributeName == forAttr) { |
298 formAttributeChanged(); | 275 TreeScope& scope = treeScope(); |
299 UseCounter::count(document(), UseCounter::HTMLLabelElementFormContentAtt
ribute); | 276 if (scope.shouldCacheLabelsByForAttribute()) |
300 } else { | 277 updateLabel(scope, oldValue, attributeValue); |
301 if (attributeName == forAttr) { | |
302 TreeScope& scope = treeScope(); | |
303 if (scope.shouldCacheLabelsByForAttribute()) | |
304 updateLabel(scope, oldValue, attributeValue); | |
305 } | |
306 HTMLElement::parseAttribute(attributeName, oldValue, attributeValue); | |
307 } | 278 } |
| 279 HTMLElement::parseAttribute(attributeName, oldValue, attributeValue); |
308 } | 280 } |
309 | 281 |
310 } // namespace blink | 282 } // namespace blink |
OLD | NEW |