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

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

Issue 7065003: Merge 86976 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/742/
Patch Set: Created 9 years, 7 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
« no previous file with comments | « Source/WebCore/dom/Document.cpp ('k') | Source/WebCore/html/HTMLInputElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 m_required = !attr->isNull(); 113 m_required = !attr->isNull();
114 if (oldRequired != m_required) { 114 if (oldRequired != m_required) {
115 setNeedsValidityCheck(); 115 setNeedsValidityCheck();
116 setNeedsStyleRecalc(); // Updates for :required :optional classes. 116 setNeedsStyleRecalc(); // Updates for :required :optional classes.
117 } 117 }
118 } else 118 } else
119 HTMLElement::parseMappedAttribute(attr); 119 HTMLElement::parseMappedAttribute(attr);
120 setNeedsWillValidateCheck(); 120 setNeedsWillValidateCheck();
121 } 121 }
122 122
123 static bool shouldAutofocus(HTMLFormControlElement* element)
124 {
125 if (!element->autofocus())
126 return false;
127 if (!element->renderer())
128 return false;
129 if (element->document()->ignoreAutofocus())
130 return false;
131 if (element->isReadOnlyFormControl())
132 return false;
133
134 // FIXME: Should this set of hasTagName checks be replaced by a
135 // virtual member function?
136 if (element->hasTagName(inputTag))
137 return !static_cast<HTMLInputElement*>(element)->isInputTypeHidden();
138 if (element->hasTagName(selectTag))
139 return true;
140 if (element->hasTagName(keygenTag))
141 return true;
142 if (element->hasTagName(buttonTag))
143 return true;
144 if (element->hasTagName(textareaTag))
145 return true;
146
147 return false;
148 }
149
150 static void focusPostAttach(Node* element)
151 {
152 static_cast<Element*>(element)->focus();
153 element->deref();
154 }
155
123 void HTMLFormControlElement::attach() 156 void HTMLFormControlElement::attach()
124 { 157 {
125 ASSERT(!attached()); 158 ASSERT(!attached());
126 159
160 suspendPostAttachCallbacks();
161
127 HTMLElement::attach(); 162 HTMLElement::attach();
128 163
129 // The call to updateFromElement() needs to go after the call through 164 // The call to updateFromElement() needs to go after the call through
130 // to the base class's attach() because that can sometimes do a close 165 // to the base class's attach() because that can sometimes do a close
131 // on the renderer. 166 // on the renderer.
132 if (renderer()) 167 if (renderer())
133 renderer()->updateFromElement(); 168 renderer()->updateFromElement();
134 169
135 // Focus the element if it should honour its autofocus attribute. 170 if (shouldAutofocus(this)) {
136 // We have to determine if the element is a TextArea/Input/Button/Select, 171 ref();
137 // if input type hidden ignore autofocus. So if disabled or readonly. 172 queuePostAttachCallback(focusPostAttach, this);
138 bool isInputTypeHidden = false; 173 }
139 if (hasTagName(inputTag))
140 isInputTypeHidden = static_cast<HTMLInputElement*>(this)->isInputTypeHid den();
141 174
142 if (autofocus() && renderer() && !document()->ignoreAutofocus() && !isReadOn lyFormControl() && 175 resumePostAttachCallbacks();
143 ((hasTagName(inputTag) && !isInputTypeHidden) || hasTagName(selectTa g) ||
144 hasTagName(keygenTag) || hasTagName(buttonTag) || hasTagName(texta reaTag)))
145 focus();
146 } 176 }
147 177
148 void HTMLFormControlElement::willMoveToNewOwnerDocument() 178 void HTMLFormControlElement::willMoveToNewOwnerDocument()
149 { 179 {
150 FormAssociatedElement::willMoveToNewOwnerDocument(); 180 FormAssociatedElement::willMoveToNewOwnerDocument();
151 HTMLElement::willMoveToNewOwnerDocument(); 181 HTMLElement::willMoveToNewOwnerDocument();
152 } 182 }
153 183
154 void HTMLFormControlElement::insertedIntoTree(bool deep) 184 void HTMLFormControlElement::insertedIntoTree(bool deep)
155 { 185 {
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 updatePlaceholderVisibility(true); 714 updatePlaceholderVisibility(true);
685 else if (attr->name() == onselectAttr) 715 else if (attr->name() == onselectAttr)
686 setAttributeEventListener(eventNames().selectEvent, createAttributeEvent Listener(this, attr)); 716 setAttributeEventListener(eventNames().selectEvent, createAttributeEvent Listener(this, attr));
687 else if (attr->name() == onchangeAttr) 717 else if (attr->name() == onchangeAttr)
688 setAttributeEventListener(eventNames().changeEvent, createAttributeEvent Listener(this, attr)); 718 setAttributeEventListener(eventNames().changeEvent, createAttributeEvent Listener(this, attr));
689 else 719 else
690 HTMLFormControlElementWithState::parseMappedAttribute(attr); 720 HTMLFormControlElementWithState::parseMappedAttribute(attr);
691 } 721 }
692 722
693 } // namespace Webcore 723 } // namespace Webcore
OLDNEW
« no previous file with comments | « Source/WebCore/dom/Document.cpp ('k') | Source/WebCore/html/HTMLInputElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698