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

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

Issue 201293002: Add Traversal<*Element>::firstAncestor() API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix editing failures Created 6 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 | Annotate | Revision Log
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 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007 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
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/html/HTMLFormControlElement.h" 26 #include "core/html/HTMLFormControlElement.h"
27 27
28 #include "core/events/Event.h" 28 #include "core/events/Event.h"
29 #include "core/html/HTMLDataListElement.h"
29 #include "core/html/HTMLFieldSetElement.h" 30 #include "core/html/HTMLFieldSetElement.h"
30 #include "core/html/HTMLFormElement.h" 31 #include "core/html/HTMLFormElement.h"
31 #include "core/html/HTMLInputElement.h" 32 #include "core/html/HTMLInputElement.h"
32 #include "core/html/HTMLLegendElement.h" 33 #include "core/html/HTMLLegendElement.h"
33 #include "core/html/ValidityState.h" 34 #include "core/html/ValidityState.h"
34 #include "core/html/forms/ValidationMessage.h" 35 #include "core/html/forms/ValidationMessage.h"
35 #include "core/frame/UseCounter.h" 36 #include "core/frame/UseCounter.h"
36 #include "core/rendering/RenderBox.h" 37 #include "core/rendering/RenderBox.h"
37 #include "core/rendering/RenderTheme.h" 38 #include "core/rendering/RenderTheme.h"
38 #include "wtf/Vector.h" 39 #include "wtf/Vector.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 bool HTMLFormControlElement::formNoValidate() const 96 bool HTMLFormControlElement::formNoValidate() const
96 { 97 {
97 return fastHasAttribute(formnovalidateAttr); 98 return fastHasAttribute(formnovalidateAttr);
98 } 99 }
99 100
100 void HTMLFormControlElement::updateAncestorDisabledState() const 101 void HTMLFormControlElement::updateAncestorDisabledState() const
101 { 102 {
102 HTMLFieldSetElement* fieldSetAncestor = 0; 103 HTMLFieldSetElement* fieldSetAncestor = 0;
103 ContainerNode* legendAncestor = 0; 104 ContainerNode* legendAncestor = 0;
104 for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor-> parentNode()) { 105 for (HTMLElement* ancestor = Traversal<HTMLElement>::firstAncestor(*this); a ncestor; ancestor = Traversal<HTMLElement>::firstAncestor(*ancestor)) {
105 if (!legendAncestor && isHTMLLegendElement(*ancestor)) 106 if (!legendAncestor && isHTMLLegendElement(*ancestor))
106 legendAncestor = ancestor; 107 legendAncestor = ancestor;
107 if (isHTMLFieldSetElement(*ancestor)) { 108 if (isHTMLFieldSetElement(*ancestor)) {
108 fieldSetAncestor = toHTMLFieldSetElement(ancestor); 109 fieldSetAncestor = toHTMLFieldSetElement(ancestor);
109 break; 110 break;
110 } 111 }
111 } 112 }
112 m_ancestorDisabledState = (fieldSetAncestor && fieldSetAncestor->isDisabledF ormControl() && !(legendAncestor && legendAncestor == fieldSetAncestor->legend() )) ? AncestorDisabledStateDisabled : AncestorDisabledStateEnabled; 113 m_ancestorDisabledState = (fieldSetAncestor && fieldSetAncestor->isDisabledF ormControl() && !(legendAncestor && legendAncestor == fieldSetAncestor->legend() )) ? AncestorDisabledStateDisabled : AncestorDisabledStateEnabled;
113 } 114 }
114 115
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 349
349 short HTMLFormControlElement::tabIndex() const 350 short HTMLFormControlElement::tabIndex() const
350 { 351 {
351 // Skip the supportsFocus check in HTMLElement. 352 // Skip the supportsFocus check in HTMLElement.
352 return Element::tabIndex(); 353 return Element::tabIndex();
353 } 354 }
354 355
355 bool HTMLFormControlElement::recalcWillValidate() const 356 bool HTMLFormControlElement::recalcWillValidate() const
356 { 357 {
357 if (m_dataListAncestorState == Unknown) { 358 if (m_dataListAncestorState == Unknown) {
358 for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancest or->parentNode()) { 359 if (Traversal<HTMLDataListElement>::firstAncestor(*this))
359 if (isHTMLDataListElement(*ancestor)) { 360 m_dataListAncestorState = InsideDataList;
360 m_dataListAncestorState = InsideDataList; 361 else
361 break;
362 }
363 }
364 if (m_dataListAncestorState == Unknown)
365 m_dataListAncestorState = NotInsideDataList; 362 m_dataListAncestorState = NotInsideDataList;
366 } 363 }
367 return m_dataListAncestorState == NotInsideDataList && !isDisabledOrReadOnly (); 364 return m_dataListAncestorState == NotInsideDataList && !isDisabledOrReadOnly ();
368 } 365 }
369 366
370 bool HTMLFormControlElement::willValidate() const 367 bool HTMLFormControlElement::willValidate() const
371 { 368 {
372 if (!m_willValidateInitialized || m_dataListAncestorState == Unknown) { 369 if (!m_willValidateInitialized || m_dataListAncestorState == Unknown) {
373 m_willValidateInitialized = true; 370 m_willValidateInitialized = true;
374 bool newWillValidate = recalcWillValidate(); 371 bool newWillValidate = recalcWillValidate();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return canBeSuccessfulSubmitButton() && !isDisabledFormControl(); 472 return canBeSuccessfulSubmitButton() && !isDisabledFormControl();
476 } 473 }
477 474
478 bool HTMLFormControlElement::isDefaultButtonForForm() const 475 bool HTMLFormControlElement::isDefaultButtonForForm() const
479 { 476 {
480 return isSuccessfulSubmitButton() && form() && form()->defaultButton() == th is; 477 return isSuccessfulSubmitButton() && form() && form()->defaultButton() == th is;
481 } 478 }
482 479
483 HTMLFormControlElement* HTMLFormControlElement::enclosingFormControlElement(Node * node) 480 HTMLFormControlElement* HTMLFormControlElement::enclosingFormControlElement(Node * node)
484 { 481 {
485 for (; node; node = node->parentNode()) { 482 if (!node || isHTMLFormControlElement(*node))
486 if (node->isElementNode() && toElement(node)->isFormControlElement()) 483 return toHTMLFormControlElement(node);
487 return toHTMLFormControlElement(node); 484 return Traversal<HTMLFormControlElement>::firstAncestor(*node);
esprehn 2014/03/27 13:28:16 This also could have been firstAncestorOrSelf(node
488 }
489 return 0;
490 } 485 }
491 486
492 String HTMLFormControlElement::nameForAutofill() const 487 String HTMLFormControlElement::nameForAutofill() const
493 { 488 {
494 String fullName = name(); 489 String fullName = name();
495 String trimmedName = fullName.stripWhiteSpace(); 490 String trimmedName = fullName.stripWhiteSpace();
496 if (!trimmedName.isEmpty()) 491 if (!trimmedName.isEmpty())
497 return trimmedName; 492 return trimmedName;
498 fullName = getIdAttribute(); 493 fullName = getIdAttribute();
499 trimmedName = fullName.stripWhiteSpace(); 494 trimmedName = fullName.stripWhiteSpace();
500 return trimmedName; 495 return trimmedName;
501 } 496 }
502 497
503 void HTMLFormControlElement::setFocus(bool flag) 498 void HTMLFormControlElement::setFocus(bool flag)
504 { 499 {
505 LabelableElement::setFocus(flag); 500 LabelableElement::setFocus(flag);
506 501
507 if (!flag && wasChangedSinceLastFormControlChangeEvent()) 502 if (!flag && wasChangedSinceLastFormControlChangeEvent())
508 dispatchFormControlChangeEvent(); 503 dispatchFormControlChangeEvent();
509 } 504 }
510 505
511 } // namespace Webcore 506 } // namespace Webcore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698