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

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

Issue 2586143004: Blur immediately if an attribute change made an element unfocasable. (Closed)
Patch Set: Update comments and a function name Created 4 years 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 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
(...skipping 21 matching lines...) Expand all
32 #include "core/html/HTMLFormElement.h" 32 #include "core/html/HTMLFormElement.h"
33 #include "core/html/HTMLInputElement.h" 33 #include "core/html/HTMLInputElement.h"
34 #include "core/html/HTMLLegendElement.h" 34 #include "core/html/HTMLLegendElement.h"
35 #include "core/html/ValidityState.h" 35 #include "core/html/ValidityState.h"
36 #include "core/html/parser/HTMLParserIdioms.h" 36 #include "core/html/parser/HTMLParserIdioms.h"
37 #include "core/inspector/ConsoleMessage.h" 37 #include "core/inspector/ConsoleMessage.h"
38 #include "core/layout/LayoutObject.h" 38 #include "core/layout/LayoutObject.h"
39 #include "core/layout/LayoutTheme.h" 39 #include "core/layout/LayoutTheme.h"
40 #include "core/page/Page.h" 40 #include "core/page/Page.h"
41 #include "core/page/ValidationMessageClient.h" 41 #include "core/page/ValidationMessageClient.h"
42 #include "platform/EventDispatchForbiddenScope.h"
42 #include "platform/text/BidiTextRun.h" 43 #include "platform/text/BidiTextRun.h"
43 #include "wtf/Vector.h" 44 #include "wtf/Vector.h"
44 45
45 namespace blink { 46 namespace blink {
46 47
47 using namespace HTMLNames; 48 using namespace HTMLNames;
48 49
49 HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, 50 HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName,
50 Document& document) 51 Document& document)
51 : LabelableElement(tagName, document), 52 : LabelableElement(tagName, document),
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void HTMLFormControlElement::ancestorDisabledStateWasChanged() { 129 void HTMLFormControlElement::ancestorDisabledStateWasChanged() {
129 m_ancestorDisabledState = AncestorDisabledStateUnknown; 130 m_ancestorDisabledState = AncestorDisabledStateUnknown;
130 disabledAttributeChanged(); 131 disabledAttributeChanged();
131 } 132 }
132 133
133 void HTMLFormControlElement::reset() { 134 void HTMLFormControlElement::reset() {
134 setAutofilled(false); 135 setAutofilled(false);
135 resetImpl(); 136 resetImpl();
136 } 137 }
137 138
139 void HTMLFormControlElement::attributeChanged(
140 const QualifiedName& name,
141 const AtomicString& oldValue,
142 const AtomicString& newValue,
143 AttributeModificationReason reason) {
144 HTMLElement::attributeChanged(name, oldValue, newValue, reason);
145 if (name == disabledAttr && oldValue.isNull() != newValue.isNull()) {
146 disabledAttributeChanged();
147 if (reason == AttributeModificationReason::kDirectly &&
148 isDisabledFormControl() && adjustedFocusedElementInTreeScope() == this)
149 blur();
150 }
151 }
152
138 void HTMLFormControlElement::parseAttribute(const QualifiedName& name, 153 void HTMLFormControlElement::parseAttribute(const QualifiedName& name,
139 const AtomicString& oldValue, 154 const AtomicString& oldValue,
140 const AtomicString& value) { 155 const AtomicString& value) {
141 if (name == formAttr) { 156 if (name == formAttr) {
142 formAttributeChanged(); 157 formAttributeChanged();
143 UseCounter::count(document(), UseCounter::FormAttribute); 158 UseCounter::count(document(), UseCounter::FormAttribute);
144 } else if (name == disabledAttr) {
145 if (oldValue.isNull() != value.isNull())
146 disabledAttributeChanged();
147 } else if (name == readonlyAttr) { 159 } else if (name == readonlyAttr) {
148 if (oldValue.isNull() != value.isNull()) { 160 if (oldValue.isNull() != value.isNull()) {
149 setNeedsWillValidateCheck(); 161 setNeedsWillValidateCheck();
150 pseudoStateChanged(CSSSelector::PseudoReadOnly); 162 pseudoStateChanged(CSSSelector::PseudoReadOnly);
151 pseudoStateChanged(CSSSelector::PseudoReadWrite); 163 pseudoStateChanged(CSSSelector::PseudoReadWrite);
152 if (layoutObject()) 164 if (layoutObject())
153 LayoutTheme::theme().controlStateChanged(*layoutObject(), 165 LayoutTheme::theme().controlStateChanged(*layoutObject(),
154 ReadOnlyControlState); 166 ReadOnlyControlState);
155 } 167 }
156 } else if (name == requiredAttr) { 168 } else if (name == requiredAttr) {
157 if (oldValue.isNull() != value.isNull()) 169 if (oldValue.isNull() != value.isNull())
158 requiredAttributeChanged(); 170 requiredAttributeChanged();
159 UseCounter::count(document(), UseCounter::RequiredAttribute); 171 UseCounter::count(document(), UseCounter::RequiredAttribute);
160 } else if (name == autofocusAttr) { 172 } else if (name == autofocusAttr) {
161 HTMLElement::parseAttribute(name, oldValue, value); 173 HTMLElement::parseAttribute(name, oldValue, value);
162 UseCounter::count(document(), UseCounter::AutoFocusAttribute); 174 UseCounter::count(document(), UseCounter::AutoFocusAttribute);
163 } else { 175 } else {
164 HTMLElement::parseAttribute(name, oldValue, value); 176 HTMLElement::parseAttribute(name, oldValue, value);
165 } 177 }
166 } 178 }
167 179
168 void HTMLFormControlElement::disabledAttributeChanged() { 180 void HTMLFormControlElement::disabledAttributeChanged() {
181 // Don't blur in this function because this is called for descendants of
182 // <fieldset> while tree traversal.
183 EventDispatchForbiddenScope eventForbidden;
184
169 setNeedsWillValidateCheck(); 185 setNeedsWillValidateCheck();
170 pseudoStateChanged(CSSSelector::PseudoDisabled); 186 pseudoStateChanged(CSSSelector::PseudoDisabled);
171 pseudoStateChanged(CSSSelector::PseudoEnabled); 187 pseudoStateChanged(CSSSelector::PseudoEnabled);
172 if (layoutObject()) 188 if (layoutObject())
173 LayoutTheme::theme().controlStateChanged(*layoutObject(), 189 LayoutTheme::theme().controlStateChanged(*layoutObject(),
174 EnabledControlState); 190 EnabledControlState);
175 if (isDisabledFormControl() && adjustedFocusedElementInTreeScope() == this) {
176 // We might want to call blur(), but it's dangerous to dispatch events
177 // here.
178 document().setNeedsFocusedElementCheck();
179 }
180 } 191 }
181 192
182 void HTMLFormControlElement::requiredAttributeChanged() { 193 void HTMLFormControlElement::requiredAttributeChanged() {
183 setNeedsValidityCheck(); 194 setNeedsValidityCheck();
184 pseudoStateChanged(CSSSelector::PseudoRequired); 195 pseudoStateChanged(CSSSelector::PseudoRequired);
185 pseudoStateChanged(CSSSelector::PseudoOptional); 196 pseudoStateChanged(CSSSelector::PseudoOptional);
186 } 197 }
187 198
188 bool HTMLFormControlElement::isReadOnly() const { 199 bool HTMLFormControlElement::isReadOnly() const {
189 return fastHasAttribute(HTMLNames::readonlyAttr); 200 return fastHasAttribute(HTMLNames::readonlyAttr);
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 const Element& source) { 636 const Element& source) {
626 HTMLElement::copyNonAttributePropertiesFromElement(source); 637 HTMLElement::copyNonAttributePropertiesFromElement(source);
627 setNeedsValidityCheck(); 638 setNeedsValidityCheck();
628 } 639 }
629 640
630 void HTMLFormControlElement::associateWith(HTMLFormElement* form) { 641 void HTMLFormControlElement::associateWith(HTMLFormElement* form) {
631 associateByParser(form); 642 associateByParser(form);
632 }; 643 };
633 644
634 } // namespace blink 645 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLFormControlElement.h ('k') | third_party/WebKit/Source/core/html/HTMLInputElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698