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

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

Issue 2586143004: Blur immediately if an attribute change made an element unfocasable. (Closed)
Patch Set: rebase Created 3 years, 12 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, 2010 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 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 12 matching lines...) Expand all
23 */ 23 */
24 24
25 #include "core/html/HTMLFieldSetElement.h" 25 #include "core/html/HTMLFieldSetElement.h"
26 26
27 #include "core/HTMLNames.h" 27 #include "core/HTMLNames.h"
28 #include "core/dom/ElementTraversal.h" 28 #include "core/dom/ElementTraversal.h"
29 #include "core/dom/NodeListsNodeData.h" 29 #include "core/dom/NodeListsNodeData.h"
30 #include "core/html/HTMLCollection.h" 30 #include "core/html/HTMLCollection.h"
31 #include "core/html/HTMLLegendElement.h" 31 #include "core/html/HTMLLegendElement.h"
32 #include "core/layout/LayoutFieldset.h" 32 #include "core/layout/LayoutFieldset.h"
33 #include "platform/EventDispatchForbiddenScope.h"
33 #include "wtf/StdLibExtras.h" 34 #include "wtf/StdLibExtras.h"
34 35
35 namespace blink { 36 namespace blink {
36 37
37 using namespace HTMLNames; 38 using namespace HTMLNames;
38 39
39 inline HTMLFieldSetElement::HTMLFieldSetElement(Document& document) 40 inline HTMLFieldSetElement::HTMLFieldSetElement(Document& document)
40 : HTMLFormControlElement(fieldsetTag, document) {} 41 : HTMLFormControlElement(fieldsetTag, document) {}
41 42
42 HTMLFieldSetElement* HTMLFieldSetElement::create(Document& document) { 43 HTMLFieldSetElement* HTMLFieldSetElement::create(Document& document) {
(...skipping 12 matching lines...) Expand all
55 return false; 56 return false;
56 } 57 }
57 } 58 }
58 return true; 59 return true;
59 } 60 }
60 61
61 bool HTMLFieldSetElement::isSubmittableElement() { 62 bool HTMLFieldSetElement::isSubmittableElement() {
62 return false; 63 return false;
63 } 64 }
64 65
65 void HTMLFieldSetElement::invalidateDisabledStateUnder(Element& base) { 66 // Returns a focused element if it's in descendants of |base|.
66 for (HTMLFormControlElement& element : 67 Element* HTMLFieldSetElement::invalidateDisabledStateUnder(Element& base) {
kochi 2016/12/21 05:58:09 The name of the function and return value seem irr
tkent 2016/12/21 06:51:15 invalidateDescendantDisabledStateAndFindFocusedOne
kochi 2016/12/21 08:05:19 Yeah, long but readable. As the function only call
67 Traversal<HTMLFormControlElement>::descendantsOf(base)) 68 Element* focusedElement = adjustedFocusedElementInTreeScope();
68 element.ancestorDisabledStateWasChanged(); 69 bool shouldBlur = false;
70 {
71 EventDispatchForbiddenScope eventForbidden;
72 for (HTMLFormControlElement& element :
73 Traversal<HTMLFormControlElement>::descendantsOf(base)) {
74 element.ancestorDisabledStateWasChanged();
75 if (focusedElement == &element && element.isDisabledFormControl())
76 shouldBlur = true;
77 }
78 }
79 return shouldBlur ? focusedElement : nullptr;
69 } 80 }
70 81
71 void HTMLFieldSetElement::disabledAttributeChanged() { 82 void HTMLFieldSetElement::disabledAttributeChanged() {
72 // This element must be updated before the style of nodes in its subtree gets 83 // This element must be updated before the style of nodes in its subtree gets
73 // recalculated. 84 // recalculated.
74 HTMLFormControlElement::disabledAttributeChanged(); 85 HTMLFormControlElement::disabledAttributeChanged();
75 invalidateDisabledStateUnder(*this); 86 if (Element* focusedElement = invalidateDisabledStateUnder(*this))
87 focusedElement->blur();
76 } 88 }
77 89
78 void HTMLFieldSetElement::childrenChanged(const ChildrenChange& change) { 90 void HTMLFieldSetElement::childrenChanged(const ChildrenChange& change) {
79 HTMLFormControlElement::childrenChanged(change); 91 HTMLFormControlElement::childrenChanged(change);
80 for (HTMLLegendElement& legend : 92 Element* focusedElement = nullptr;
81 Traversal<HTMLLegendElement>::childrenOf(*this)) 93 {
82 invalidateDisabledStateUnder(legend); 94 EventDispatchForbiddenScope eventForbidden;
95 for (HTMLLegendElement& legend :
96 Traversal<HTMLLegendElement>::childrenOf(*this)) {
97 if (Element* element = invalidateDisabledStateUnder(legend))
98 focusedElement = element;
99 }
100 }
101 if (focusedElement)
102 focusedElement->blur();
83 } 103 }
84 104
85 bool HTMLFieldSetElement::supportsFocus() const { 105 bool HTMLFieldSetElement::supportsFocus() const {
86 return HTMLElement::supportsFocus() && !isDisabledFormControl(); 106 return HTMLElement::supportsFocus() && !isDisabledFormControl();
87 } 107 }
88 108
89 const AtomicString& HTMLFieldSetElement::formControlType() const { 109 const AtomicString& HTMLFieldSetElement::formControlType() const {
90 DEFINE_STATIC_LOCAL(const AtomicString, fieldset, ("fieldset")); 110 DEFINE_STATIC_LOCAL(const AtomicString, fieldset, ("fieldset"));
91 return fieldset; 111 return fieldset;
92 } 112 }
93 113
94 LayoutObject* HTMLFieldSetElement::createLayoutObject(const ComputedStyle&) { 114 LayoutObject* HTMLFieldSetElement::createLayoutObject(const ComputedStyle&) {
95 return new LayoutFieldset(this); 115 return new LayoutFieldset(this);
96 } 116 }
97 117
98 HTMLLegendElement* HTMLFieldSetElement::legend() const { 118 HTMLLegendElement* HTMLFieldSetElement::legend() const {
99 return Traversal<HTMLLegendElement>::firstChild(*this); 119 return Traversal<HTMLLegendElement>::firstChild(*this);
100 } 120 }
101 121
102 HTMLCollection* HTMLFieldSetElement::elements() { 122 HTMLCollection* HTMLFieldSetElement::elements() {
103 return ensureCachedCollection<HTMLCollection>(FormControls); 123 return ensureCachedCollection<HTMLCollection>(FormControls);
104 } 124 }
105 125
106 int HTMLFieldSetElement::tabIndex() const { 126 int HTMLFieldSetElement::tabIndex() const {
107 return HTMLElement::tabIndex(); 127 return HTMLElement::tabIndex();
108 } 128 }
109 129
110 } // namespace blink 130 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698