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 20 matching lines...) Expand all Loading... |
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 #include "core/page/EventHandler.h" | 35 #include "core/page/EventHandler.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 using namespace HTMLNames; | 39 using namespace HTMLNames; |
40 | 40 |
41 inline HTMLLabelElement::HTMLLabelElement(Document& document) | 41 inline HTMLLabelElement::HTMLLabelElement(Document& document, HTMLFormElement* f
orm) |
42 : HTMLElement(labelTag, document) | 42 : HTMLElement(labelTag, document) |
43 { | 43 { |
| 44 FormAssociatedElement::associateByParser(form); |
44 } | 45 } |
45 | 46 |
46 DEFINE_NODE_FACTORY(HTMLLabelElement) | 47 PassRefPtrWillBeRawPtr<HTMLLabelElement> HTMLLabelElement::create(Document& docu
ment, HTMLFormElement* form) |
| 48 { |
| 49 RefPtrWillBeRawPtr<HTMLLabelElement> labelElement = adoptRefWillBeNoop(new H
TMLLabelElement(document, form)); |
| 50 return labelElement.release(); |
| 51 } |
47 | 52 |
48 bool HTMLLabelElement::rendererIsFocusable() const | 53 bool HTMLLabelElement::rendererIsFocusable() const |
49 { | 54 { |
50 HTMLLabelElement* that = const_cast<HTMLLabelElement*>(this); | 55 HTMLLabelElement* that = const_cast<HTMLLabelElement*>(this); |
51 return that->isContentEditable(); | 56 return that->isContentEditable(); |
52 } | 57 } |
53 | 58 |
54 LabelableElement* HTMLLabelElement::control() const | 59 LabelableElement* HTMLLabelElement::control() const |
55 { | 60 { |
56 const AtomicString& controlId = getAttribute(forAttr); | 61 const AtomicString& controlId = getAttribute(forAttr); |
(...skipping 11 matching lines...) Expand all Loading... |
68 if (Element* element = treeScope().getElementById(controlId)) { | 73 if (Element* element = treeScope().getElementById(controlId)) { |
69 if (isLabelableElement(*element) && toLabelableElement(*element).support
Labels()) | 74 if (isLabelableElement(*element) && toLabelableElement(*element).support
Labels()) |
70 return toLabelableElement(element); | 75 return toLabelableElement(element); |
71 } | 76 } |
72 | 77 |
73 return 0; | 78 return 0; |
74 } | 79 } |
75 | 80 |
76 HTMLFormElement* HTMLLabelElement::formOwner() const | 81 HTMLFormElement* HTMLLabelElement::formOwner() const |
77 { | 82 { |
78 return FormAssociatedElement::findAssociatedForm(this); | 83 return FormAssociatedElement::form(); |
79 } | 84 } |
80 | 85 |
81 void HTMLLabelElement::setActive(bool down) | 86 void HTMLLabelElement::setActive(bool down) |
82 { | 87 { |
83 if (down == active()) | 88 if (down == active()) |
84 return; | 89 return; |
85 | 90 |
86 // Update our status first. | 91 // Update our status first. |
87 HTMLElement::setActive(down); | 92 HTMLElement::setActive(down); |
88 | 93 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 224 |
220 void HTMLLabelElement::updateLabel(TreeScope& scope, const AtomicString& oldForA
ttributeValue, const AtomicString& newForAttributeValue) | 225 void HTMLLabelElement::updateLabel(TreeScope& scope, const AtomicString& oldForA
ttributeValue, const AtomicString& newForAttributeValue) |
221 { | 226 { |
222 if (!inDocument()) | 227 if (!inDocument()) |
223 return; | 228 return; |
224 | 229 |
225 if (oldForAttributeValue == newForAttributeValue) | 230 if (oldForAttributeValue == newForAttributeValue) |
226 return; | 231 return; |
227 | 232 |
228 if (!oldForAttributeValue.isEmpty()) | 233 if (!oldForAttributeValue.isEmpty()) |
229 scope.removeLabel(oldForAttributeValue, toHTMLLabelElement(this)); | 234 scope.removeLabel(oldForAttributeValue, this); |
230 if (!newForAttributeValue.isEmpty()) | 235 if (!newForAttributeValue.isEmpty()) |
231 scope.addLabel(newForAttributeValue, toHTMLLabelElement(this)); | 236 scope.addLabel(newForAttributeValue, this); |
232 } | 237 } |
233 | 238 |
234 void HTMLLabelElement::attributeWillChange(const QualifiedName& name, const Atom
icString& oldValue, const AtomicString& newValue) | 239 void HTMLLabelElement::attributeWillChange(const QualifiedName& name, const Atom
icString& oldValue, const AtomicString& newValue) |
235 { | 240 { |
236 if (name == HTMLNames::forAttr) { | 241 if (name == HTMLNames::forAttr) { |
237 TreeScope& scope = treeScope(); | 242 TreeScope& scope = treeScope(); |
238 if (scope.shouldCacheLabelsByForAttribute()) | 243 if (scope.shouldCacheLabelsByForAttribute()) |
239 updateLabel(scope, oldValue, newValue); | 244 updateLabel(scope, oldValue, newValue); |
240 } | 245 } |
241 HTMLElement::attributeWillChange(name, oldValue, newValue); | 246 HTMLElement::attributeWillChange(name, oldValue, newValue); |
242 } | 247 } |
243 | 248 |
244 Node::InsertionNotificationRequest HTMLLabelElement::insertedInto(ContainerNode*
insertionPoint) | 249 Node::InsertionNotificationRequest HTMLLabelElement::insertedInto(ContainerNode*
insertionPoint) |
245 { | 250 { |
246 InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoi
nt); | 251 InsertionNotificationRequest result = HTMLElement::insertedInto(insertionPoi
nt); |
| 252 FormAssociatedElement::insertedInto(insertionPoint); |
247 if (insertionPoint->isInTreeScope()) { | 253 if (insertionPoint->isInTreeScope()) { |
248 TreeScope& scope = insertionPoint->treeScope(); | 254 TreeScope& scope = insertionPoint->treeScope(); |
249 if (scope == treeScope() && scope.shouldCacheLabelsByForAttribute()) | 255 if (scope == treeScope() && scope.shouldCacheLabelsByForAttribute()) |
250 updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); | 256 updateLabel(scope, nullAtom, fastGetAttribute(forAttr)); |
251 } | 257 } |
252 return result; | 258 return result; |
253 } | 259 } |
254 | 260 |
255 void HTMLLabelElement::removedFrom(ContainerNode* insertionPoint) | 261 void HTMLLabelElement::removedFrom(ContainerNode* insertionPoint) |
256 { | 262 { |
257 if (insertionPoint->isInTreeScope() && treeScope() == document()) { | 263 if (insertionPoint->isInTreeScope() && treeScope() == document()) { |
258 TreeScope& treeScope = insertionPoint->treeScope(); | 264 TreeScope& treeScope = insertionPoint->treeScope(); |
259 if (treeScope.shouldCacheLabelsByForAttribute()) | 265 if (treeScope.shouldCacheLabelsByForAttribute()) |
260 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); | 266 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); |
261 } | 267 } |
262 HTMLElement::removedFrom(insertionPoint); | 268 HTMLElement::removedFrom(insertionPoint); |
| 269 FormAssociatedElement::removedFrom(insertionPoint); |
| 270 } |
| 271 |
| 272 void HTMLLabelElement::trace(Visitor* visitor) |
| 273 { |
| 274 HTMLElement::trace(visitor); |
| 275 FormAssociatedElement::trace(visitor); |
| 276 } |
| 277 |
| 278 void HTMLLabelElement::parseAttribute(const QualifiedName& attributeName, const
AtomicString& attributeValue) |
| 279 { |
| 280 if (attributeName == formAttr) |
| 281 formAttributeChanged(); |
| 282 else |
| 283 HTMLElement::parseAttribute(attributeName, attributeValue); |
263 } | 284 } |
264 | 285 |
265 } // namespace | 286 } // namespace |
OLD | NEW |