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 19 matching lines...) Expand all Loading... |
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 static bool supportsLabels(const Element& element) | |
41 { | |
42 if (!element.isHTMLElement()) | |
43 return false; | |
44 if (!toHTMLElement(element).isLabelable()) | |
45 return false; | |
46 return toLabelableElement(element).supportLabels(); | |
47 } | |
48 | |
49 inline HTMLLabelElement::HTMLLabelElement(Document& document) | 40 inline HTMLLabelElement::HTMLLabelElement(Document& document) |
50 : HTMLElement(labelTag, document) | 41 : HTMLElement(labelTag, document) |
51 { | 42 { |
52 ScriptWrappable::init(this); | 43 ScriptWrappable::init(this); |
53 } | 44 } |
54 | 45 |
55 DEFINE_NODE_FACTORY(HTMLLabelElement) | 46 DEFINE_NODE_FACTORY(HTMLLabelElement) |
56 | 47 |
57 bool HTMLLabelElement::rendererIsFocusable() const | 48 bool HTMLLabelElement::rendererIsFocusable() const |
58 { | 49 { |
59 HTMLLabelElement* that = const_cast<HTMLLabelElement*>(this); | 50 HTMLLabelElement* that = const_cast<HTMLLabelElement*>(this); |
60 return that->isContentEditable(); | 51 return that->isContentEditable(); |
61 } | 52 } |
62 | 53 |
63 LabelableElement* HTMLLabelElement::control() const | 54 LabelableElement* HTMLLabelElement::control() const |
64 { | 55 { |
65 const AtomicString& controlId = getAttribute(forAttr); | 56 const AtomicString& controlId = getAttribute(forAttr); |
66 if (controlId.isNull()) { | 57 if (controlId.isNull()) { |
67 // Search the children and descendants of the label element for a form e
lement. | 58 // Search the children and descendants of the label element for a form e
lement. |
68 // per http://dev.w3.org/html5/spec/Overview.html#the-label-element | 59 // per http://dev.w3.org/html5/spec/Overview.html#the-label-element |
69 // the form element must be "labelable form-associated element". | 60 // the form element must be "labelable form-associated element". |
70 for (Element* element = ElementTraversal::next(*this, this); element; el
ement = ElementTraversal::next(*element, this)) { | 61 for (LabelableElement* element = Traversal<LabelableElement>::next(*this
, this); element; element = Traversal<LabelableElement>::next(*element, this)) { |
71 if (!supportsLabels(*element)) | 62 if (element->supportLabels()) |
72 continue; | 63 return element; |
73 return toLabelableElement(element); | |
74 } | 64 } |
75 return 0; | 65 return 0; |
76 } | 66 } |
77 | 67 |
78 if (Element* element = treeScope().getElementById(controlId)) { | 68 if (Element* element = treeScope().getElementById(controlId)) { |
79 if (supportsLabels(*element)) | 69 if (isLabelableElement(*element) && toLabelableElement(*element).support
Labels()) |
80 return toLabelableElement(element); | 70 return toLabelableElement(element); |
81 } | 71 } |
82 | 72 |
83 return 0; | 73 return 0; |
84 } | 74 } |
85 | 75 |
86 HTMLFormElement* HTMLLabelElement::formOwner() const | 76 HTMLFormElement* HTMLLabelElement::formOwner() const |
87 { | 77 { |
88 return FormAssociatedElement::findAssociatedForm(this); | 78 return FormAssociatedElement::findAssociatedForm(this); |
89 } | 79 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 { | 229 { |
240 if (insertionPoint->isInTreeScope() && treeScope() == document()) { | 230 if (insertionPoint->isInTreeScope() && treeScope() == document()) { |
241 TreeScope& treeScope = insertionPoint->treeScope(); | 231 TreeScope& treeScope = insertionPoint->treeScope(); |
242 if (treeScope.shouldCacheLabelsByForAttribute()) | 232 if (treeScope.shouldCacheLabelsByForAttribute()) |
243 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); | 233 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); |
244 } | 234 } |
245 HTMLElement::removedFrom(insertionPoint); | 235 HTMLElement::removedFrom(insertionPoint); |
246 } | 236 } |
247 | 237 |
248 } // namespace | 238 } // namespace |
OLD | NEW |