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

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

Issue 1802263002: Add three UseCounters for LABEL element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 9 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 16 matching lines...) Expand all
27 #include "core/HTMLNames.h" 27 #include "core/HTMLNames.h"
28 #include "core/dom/Document.h" 28 #include "core/dom/Document.h"
29 #include "core/dom/ElementTraversal.h" 29 #include "core/dom/ElementTraversal.h"
30 #include "core/editing/EditingUtilities.h" 30 #include "core/editing/EditingUtilities.h"
31 #include "core/editing/FrameSelection.h" 31 #include "core/editing/FrameSelection.h"
32 #include "core/editing/SelectionController.h" 32 #include "core/editing/SelectionController.h"
33 #include "core/events/MouseEvent.h" 33 #include "core/events/MouseEvent.h"
34 #include "core/frame/LocalFrame.h" 34 #include "core/frame/LocalFrame.h"
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/input/EventHandler.h" 38 #include "core/input/EventHandler.h"
38 #include "core/layout/LayoutObject.h" 39 #include "core/layout/LayoutObject.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 using namespace HTMLNames; 43 using namespace HTMLNames;
43 44
44 inline HTMLLabelElement::HTMLLabelElement(Document& document, HTMLFormElement* f orm) 45 inline HTMLLabelElement::HTMLLabelElement(Document& document, HTMLFormElement* f orm)
45 : HTMLElement(labelTag, document) 46 : HTMLElement(labelTag, document)
46 , m_processingClick(false) 47 , m_processingClick(false)
47 { 48 {
48 FormAssociatedElement::associateByParser(form); 49 FormAssociatedElement::associateByParser(form);
49 } 50 }
50 51
51 PassRefPtrWillBeRawPtr<HTMLLabelElement> HTMLLabelElement::create(Document& docu ment, HTMLFormElement* form) 52 PassRefPtrWillBeRawPtr<HTMLLabelElement> HTMLLabelElement::create(Document& docu ment, HTMLFormElement* form)
52 { 53 {
53 RefPtrWillBeRawPtr<HTMLLabelElement> labelElement = adoptRefWillBeNoop(new H TMLLabelElement(document, form)); 54 RefPtrWillBeRawPtr<HTMLLabelElement> labelElement = adoptRefWillBeNoop(new H TMLLabelElement(document, form));
54 return labelElement.release(); 55 return labelElement.release();
55 } 56 }
56 57
57 LabelableElement* HTMLLabelElement::control() const 58 LabelableElement* HTMLLabelElement::control() const
58 { 59 {
59 const AtomicString& controlId = getAttribute(forAttr); 60 const AtomicString& controlId = getAttribute(forAttr);
60 if (controlId.isNull()) { 61 if (controlId.isNull()) {
61 // Search the children and descendants of the label element for a form e lement. 62 // Search the children and descendants of the label element for a form e lement.
62 // per http://dev.w3.org/html5/spec/Overview.html#the-label-element 63 // per http://dev.w3.org/html5/spec/Overview.html#the-label-element
63 // the form element must be "labelable form-associated element". 64 // the form element must be "labelable form-associated element".
64 for (LabelableElement& element : Traversal<LabelableElement>::descendant sOf(*this)) { 65 for (LabelableElement& element : Traversal<LabelableElement>::descendant sOf(*this)) {
65 if (element.supportLabels()) 66 if (element.supportLabels()) {
67 if (!element.isFormControlElement())
68 UseCounter::count(document(), UseCounter::HTMLLabelElementCo ntrolForNonFormAssociatedElement);
66 return &element; 69 return &element;
70 }
67 } 71 }
68 return nullptr; 72 return nullptr;
69 } 73 }
70 74
71 if (Element* element = treeScope().getElementById(controlId)) { 75 if (Element* element = treeScope().getElementById(controlId)) {
72 if (isLabelableElement(*element) && toLabelableElement(*element).support Labels()) 76 if (isLabelableElement(*element) && toLabelableElement(*element).support Labels()) {
77 if (!element->isFormControlElement())
78 UseCounter::count(document(), UseCounter::HTMLLabelElementContro lForNonFormAssociatedElement);
73 return toLabelableElement(element); 79 return toLabelableElement(element);
80 }
74 } 81 }
75 82
76 return nullptr; 83 return nullptr;
77 } 84 }
78 85
79 HTMLFormElement* HTMLLabelElement::formOwner() const 86 HTMLFormElement* HTMLLabelElement::formOwner() const
80 { 87 {
81 return FormAssociatedElement::form(); 88 return FormAssociatedElement::form();
82 } 89 }
83 90
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 }
105
84 void HTMLLabelElement::setActive(bool down) 106 void HTMLLabelElement::setActive(bool down)
85 { 107 {
86 if (down != active()) { 108 if (down != active()) {
87 // Update our status first. 109 // Update our status first.
88 HTMLElement::setActive(down); 110 HTMLElement::setActive(down);
89 } 111 }
90 112
91 // Also update our corresponding control. 113 // Also update our corresponding control.
92 HTMLElement* controlElement = control(); 114 HTMLElement* controlElement = control();
93 if (controlElement && controlElement->active() != active()) 115 if (controlElement && controlElement->active() != active())
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 if (attributeName == forAttr) { 301 if (attributeName == forAttr) {
280 TreeScope& scope = treeScope(); 302 TreeScope& scope = treeScope();
281 if (scope.shouldCacheLabelsByForAttribute()) 303 if (scope.shouldCacheLabelsByForAttribute())
282 updateLabel(scope, oldValue, attributeValue); 304 updateLabel(scope, oldValue, attributeValue);
283 } 305 }
284 HTMLElement::parseAttribute(attributeName, oldValue, attributeValue); 306 HTMLElement::parseAttribute(attributeName, oldValue, attributeValue);
285 } 307 }
286 } 308 }
287 309
288 } // namespace blink 310 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLLabelElement.h ('k') | third_party/WebKit/Source/core/html/HTMLLabelElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698