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: Source/core/html/forms/TextFieldInputType.cpp

Issue 27746003: Have InputType factories take an HTMLInputElement reference in parameter (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 2 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
« no previous file with comments | « Source/core/html/forms/TextFieldInputType.h ('k') | Source/core/html/forms/TextInputType.h » ('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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "core/page/Settings.h" 51 #include "core/page/Settings.h"
52 #include "core/rendering/RenderLayer.h" 52 #include "core/rendering/RenderLayer.h"
53 #include "core/rendering/RenderTextControlSingleLine.h" 53 #include "core/rendering/RenderTextControlSingleLine.h"
54 #include "core/rendering/RenderTheme.h" 54 #include "core/rendering/RenderTheme.h"
55 #include "wtf/text/WTFString.h" 55 #include "wtf/text/WTFString.h"
56 56
57 namespace WebCore { 57 namespace WebCore {
58 58
59 using namespace HTMLNames; 59 using namespace HTMLNames;
60 60
61 TextFieldInputType::TextFieldInputType(HTMLInputElement* element) 61 TextFieldInputType::TextFieldInputType(HTMLInputElement& element)
62 : InputType(element) 62 : InputType(element)
63 { 63 {
64 } 64 }
65 65
66 TextFieldInputType::~TextFieldInputType() 66 TextFieldInputType::~TextFieldInputType()
67 { 67 {
68 if (SpinButtonElement* spinButton = spinButtonElement()) 68 if (SpinButtonElement* spinButton = spinButtonElement())
69 spinButton->removeSpinButtonOwner(); 69 spinButton->removeSpinButtonOwner();
70 } 70 }
71 71
72 SpinButtonElement* TextFieldInputType::spinButtonElement() const 72 SpinButtonElement* TextFieldInputType::spinButtonElement() const
73 { 73 {
74 return toSpinButtonElement(element()->userAgentShadowRoot()->getElementById( ShadowElementNames::spinButton())); 74 return toSpinButtonElement(element().userAgentShadowRoot()->getElementById(S hadowElementNames::spinButton()));
75 } 75 }
76 76
77 bool TextFieldInputType::shouldShowFocusRingOnMouseFocus() const 77 bool TextFieldInputType::shouldShowFocusRingOnMouseFocus() const
78 { 78 {
79 return true; 79 return true;
80 } 80 }
81 81
82 bool TextFieldInputType::isTextField() const 82 bool TextFieldInputType::isTextField() const
83 { 83 {
84 return true; 84 return true;
85 } 85 }
86 86
87 static inline bool shouldIgnoreRequiredAttribute(const HTMLInputElement& input) 87 static inline bool shouldIgnoreRequiredAttribute(const HTMLInputElement& input)
88 { 88 {
89 if (!input.document().settings() || !input.document().settings()->needsSiteS pecificQuirks()) 89 if (!input.document().settings() || !input.document().settings()->needsSiteS pecificQuirks())
90 return false; 90 return false;
91 if (!equalIgnoringCase(input.document().url().host(), "egov.uscis.gov")) 91 if (!equalIgnoringCase(input.document().url().host(), "egov.uscis.gov"))
92 return false; 92 return false;
93 return input.fastGetAttribute(requiredAttr) == "no"; 93 return input.fastGetAttribute(requiredAttr) == "no";
94 } 94 }
95 95
96 bool TextFieldInputType::valueMissing(const String& value) const 96 bool TextFieldInputType::valueMissing(const String& value) const
97 { 97 {
98 return !shouldIgnoreRequiredAttribute(*element()) && element()->isRequired() && value.isEmpty(); 98 return !shouldIgnoreRequiredAttribute(element()) && element().isRequired() & & value.isEmpty();
99 } 99 }
100 100
101 bool TextFieldInputType::canSetSuggestedValue() 101 bool TextFieldInputType::canSetSuggestedValue()
102 { 102 {
103 return true; 103 return true;
104 } 104 }
105 105
106 void TextFieldInputType::setValue(const String& sanitizedValue, bool valueChange d, TextFieldEventBehavior eventBehavior) 106 void TextFieldInputType::setValue(const String& sanitizedValue, bool valueChange d, TextFieldEventBehavior eventBehavior)
107 { 107 {
108 // Grab this input element to keep reference even if JS event handler 108 // Grab this input element to keep reference even if JS event handler
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 case DispatchNoEvent: 144 case DispatchNoEvent:
145 break; 145 break;
146 } 146 }
147 147
148 if (!input->focused()) 148 if (!input->focused())
149 input->setTextAsOfLastFormControlChangeEvent(sanitizedValue); 149 input->setTextAsOfLastFormControlChangeEvent(sanitizedValue);
150 } 150 }
151 151
152 void TextFieldInputType::handleKeydownEvent(KeyboardEvent* event) 152 void TextFieldInputType::handleKeydownEvent(KeyboardEvent* event)
153 { 153 {
154 if (!element()->focused()) 154 if (!element().focused())
155 return; 155 return;
156 Frame* frame = element()->document().frame(); 156 Frame* frame = element().document().frame();
157 if (!frame || !frame->editor().doTextFieldCommandFromEvent(element(), event) ) 157 if (!frame || !frame->editor().doTextFieldCommandFromEvent(&element(), event ))
158 return; 158 return;
159 event->setDefaultHandled(); 159 event->setDefaultHandled();
160 } 160 }
161 161
162 void TextFieldInputType::handleKeydownEventForSpinButton(KeyboardEvent* event) 162 void TextFieldInputType::handleKeydownEventForSpinButton(KeyboardEvent* event)
163 { 163 {
164 if (element()->isDisabledOrReadOnly()) 164 if (element().isDisabledOrReadOnly())
165 return; 165 return;
166 const String& key = event->keyIdentifier(); 166 const String& key = event->keyIdentifier();
167 if (key == "Up") 167 if (key == "Up")
168 spinButtonStepUp(); 168 spinButtonStepUp();
169 else if (key == "Down") 169 else if (key == "Down")
170 spinButtonStepDown(); 170 spinButtonStepDown();
171 else 171 else
172 return; 172 return;
173 event->setDefaultHandled(); 173 event->setDefaultHandled();
174 } 174 }
175 175
176 void TextFieldInputType::forwardEvent(Event* event) 176 void TextFieldInputType::forwardEvent(Event* event)
177 { 177 {
178 if (SpinButtonElement* spinButton = spinButtonElement()) { 178 if (SpinButtonElement* spinButton = spinButtonElement()) {
179 spinButton->forwardEvent(event); 179 spinButton->forwardEvent(event);
180 if (event->defaultHandled()) 180 if (event->defaultHandled())
181 return; 181 return;
182 } 182 }
183 183
184 if (element()->renderer() && (event->isMouseEvent() || event->isDragEvent() || event->hasInterface(EventNames::WheelEvent) || event->type() == EventTypeName s::blur || event->type() == EventTypeNames::focus)) { 184 if (element().renderer() && (event->isMouseEvent() || event->isDragEvent() | | event->hasInterface(EventNames::WheelEvent) || event->type() == EventTypeNames ::blur || event->type() == EventTypeNames::focus)) {
185 RenderTextControlSingleLine* renderTextControl = toRenderTextControlSing leLine(element()->renderer()); 185 RenderTextControlSingleLine* renderTextControl = toRenderTextControlSing leLine(element().renderer());
186 if (event->type() == EventTypeNames::blur) { 186 if (event->type() == EventTypeNames::blur) {
187 if (RenderBox* innerTextRenderer = innerTextElement()->renderBox()) { 187 if (RenderBox* innerTextRenderer = innerTextElement()->renderBox()) {
188 // FIXME: This class has no need to know about RenderLayer! 188 // FIXME: This class has no need to know about RenderLayer!
189 if (RenderLayer* innerLayer = innerTextRenderer->layer()) { 189 if (RenderLayer* innerLayer = innerTextRenderer->layer()) {
190 RenderLayerScrollableArea* innerScrollableArea = innerLayer- >scrollableArea(); 190 RenderLayerScrollableArea* innerScrollableArea = innerLayer- >scrollableArea();
191 IntSize scrollOffset(!renderTextControl->style()->isLeftToRi ghtDirection() ? innerScrollableArea->scrollWidth() : 0, 0); 191 IntSize scrollOffset(!renderTextControl->style()->isLeftToRi ghtDirection() ? innerScrollableArea->scrollWidth() : 0, 0);
192 innerScrollableArea->scrollToOffset(scrollOffset, ScrollOffs etClamped); 192 innerScrollableArea->scrollToOffset(scrollOffset, ScrollOffs etClamped);
193 } 193 }
194 } 194 }
195 195
196 renderTextControl->capsLockStateMayHaveChanged(); 196 renderTextControl->capsLockStateMayHaveChanged();
197 } else if (event->type() == EventTypeNames::focus) { 197 } else if (event->type() == EventTypeNames::focus) {
198 renderTextControl->capsLockStateMayHaveChanged(); 198 renderTextControl->capsLockStateMayHaveChanged();
199 } 199 }
200 200
201 element()->forwardEvent(event); 201 element().forwardEvent(event);
202 } 202 }
203 } 203 }
204 204
205 void TextFieldInputType::handleFocusEvent(Element* oldFocusedNode, FocusDirectio n focusDirection) 205 void TextFieldInputType::handleFocusEvent(Element* oldFocusedNode, FocusDirectio n focusDirection)
206 { 206 {
207 InputType::handleFocusEvent(oldFocusedNode, focusDirection); 207 InputType::handleFocusEvent(oldFocusedNode, focusDirection);
208 element()->beginEditing(); 208 element().beginEditing();
209 } 209 }
210 210
211 void TextFieldInputType::handleBlurEvent() 211 void TextFieldInputType::handleBlurEvent()
212 { 212 {
213 InputType::handleBlurEvent(); 213 InputType::handleBlurEvent();
214 element()->endEditing(); 214 element().endEditing();
215 } 215 }
216 216
217 bool TextFieldInputType::shouldSubmitImplicitly(Event* event) 217 bool TextFieldInputType::shouldSubmitImplicitly(Event* event)
218 { 218 {
219 return (event->type() == EventTypeNames::textInput && event->hasInterface(Ev entNames::TextEvent) && toTextEvent(event)->data() == "\n") || InputType::should SubmitImplicitly(event); 219 return (event->type() == EventTypeNames::textInput && event->hasInterface(Ev entNames::TextEvent) && toTextEvent(event)->data() == "\n") || InputType::should SubmitImplicitly(event);
220 } 220 }
221 221
222 RenderObject* TextFieldInputType::createRenderer(RenderStyle*) const 222 RenderObject* TextFieldInputType::createRenderer(RenderStyle*) const
223 { 223 {
224 return new RenderTextControlSingleLine(element()); 224 return new RenderTextControlSingleLine(&element());
225 } 225 }
226 226
227 bool TextFieldInputType::needsContainer() const 227 bool TextFieldInputType::needsContainer() const
228 { 228 {
229 #if ENABLE(INPUT_SPEECH) 229 #if ENABLE(INPUT_SPEECH)
230 return element()->isSpeechEnabled(); 230 return element().isSpeechEnabled();
231 #else 231 #else
232 return false; 232 return false;
233 #endif 233 #endif
234 } 234 }
235 235
236 bool TextFieldInputType::shouldHaveSpinButton() const 236 bool TextFieldInputType::shouldHaveSpinButton() const
237 { 237 {
238 return RenderTheme::theme().shouldHaveSpinButton(element()); 238 return RenderTheme::theme().shouldHaveSpinButton(&element());
239 } 239 }
240 240
241 void TextFieldInputType::createShadowSubtree() 241 void TextFieldInputType::createShadowSubtree()
242 { 242 {
243 ASSERT(element()->shadow()); 243 ASSERT(element().shadow());
244 ShadowRoot* shadowRoot = element()->userAgentShadowRoot(); 244 ShadowRoot* shadowRoot = element().userAgentShadowRoot();
245 ASSERT(!shadowRoot->hasChildNodes()); 245 ASSERT(!shadowRoot->hasChildNodes());
246 246
247 Document& document = element()->document(); 247 Document& document = element().document();
248 bool shouldHaveSpinButton = this->shouldHaveSpinButton(); 248 bool shouldHaveSpinButton = this->shouldHaveSpinButton();
249 bool createsContainer = shouldHaveSpinButton || needsContainer(); 249 bool createsContainer = shouldHaveSpinButton || needsContainer();
250 250
251 m_innerText = TextControlInnerTextElement::create(document); 251 m_innerText = TextControlInnerTextElement::create(document);
252 if (!createsContainer) { 252 if (!createsContainer) {
253 shadowRoot->appendChild(m_innerText); 253 shadowRoot->appendChild(m_innerText);
254 return; 254 return;
255 } 255 }
256 256
257 RefPtr<TextControlInnerContainer> container = TextControlInnerContainer::cre ate(document); 257 RefPtr<TextControlInnerContainer> container = TextControlInnerContainer::cre ate(document);
258 container->setPart(AtomicString("-webkit-textfield-decoration-container", At omicString::ConstructFromLiteral)); 258 container->setPart(AtomicString("-webkit-textfield-decoration-container", At omicString::ConstructFromLiteral));
259 shadowRoot->appendChild(container); 259 shadowRoot->appendChild(container);
260 260
261 RefPtr<EditingViewPortElement> editingViewPort = EditingViewPortElement::cre ate(document); 261 RefPtr<EditingViewPortElement> editingViewPort = EditingViewPortElement::cre ate(document);
262 editingViewPort->appendChild(m_innerText); 262 editingViewPort->appendChild(m_innerText);
263 container->appendChild(editingViewPort.release()); 263 container->appendChild(editingViewPort.release());
264 264
265 #if ENABLE(INPUT_SPEECH) 265 #if ENABLE(INPUT_SPEECH)
266 if (element()->isSpeechEnabled()) 266 if (element().isSpeechEnabled())
267 container->appendChild(InputFieldSpeechButtonElement::create(document)); 267 container->appendChild(InputFieldSpeechButtonElement::create(document));
268 #endif 268 #endif
269 269
270 if (shouldHaveSpinButton) 270 if (shouldHaveSpinButton)
271 container->appendChild(SpinButtonElement::create(document, *this)); 271 container->appendChild(SpinButtonElement::create(document, *this));
272 } 272 }
273 273
274 Element* TextFieldInputType::containerElement() const 274 Element* TextFieldInputType::containerElement() const
275 { 275 {
276 return element()->userAgentShadowRoot()->getElementById(ShadowElementNames:: textFieldContainer()); 276 return element().userAgentShadowRoot()->getElementById(ShadowElementNames::t extFieldContainer());
277 } 277 }
278 278
279 HTMLElement* TextFieldInputType::innerTextElement() const 279 HTMLElement* TextFieldInputType::innerTextElement() const
280 { 280 {
281 ASSERT(m_innerText); 281 ASSERT(m_innerText);
282 return m_innerText.get(); 282 return m_innerText.get();
283 } 283 }
284 284
285 void TextFieldInputType::destroyShadowSubtree() 285 void TextFieldInputType::destroyShadowSubtree()
286 { 286 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 return limitLength(proposedValue.removeCharacters(isASCIILineBreak), HTMLInp utElement::maximumLength); 348 return limitLength(proposedValue.removeCharacters(isASCIILineBreak), HTMLInp utElement::maximumLength);
349 } 349 }
350 350
351 void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event) 351 void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event)
352 { 352 {
353 // Make sure that the text to be inserted will not violate the maxLength. 353 // Make sure that the text to be inserted will not violate the maxLength.
354 354
355 // We use HTMLInputElement::innerTextValue() instead of 355 // We use HTMLInputElement::innerTextValue() instead of
356 // HTMLInputElement::value() because they can be mismatched by 356 // HTMLInputElement::value() because they can be mismatched by
357 // sanitizeValue() in HTMLInputElement::subtreeHasChanged() in some cases. 357 // sanitizeValue() in HTMLInputElement::subtreeHasChanged() in some cases.
358 unsigned oldLength = element()->innerTextValue().length(); 358 unsigned oldLength = element().innerTextValue().length();
359 359
360 // selectionLength represents the selection length of this text field to be 360 // selectionLength represents the selection length of this text field to be
361 // removed by this insertion. 361 // removed by this insertion.
362 // If the text field has no focus, we don't need to take account of the 362 // If the text field has no focus, we don't need to take account of the
363 // selection length. The selection is the source of text drag-and-drop in 363 // selection length. The selection is the source of text drag-and-drop in
364 // that case, and nothing in the text field will be removed. 364 // that case, and nothing in the text field will be removed.
365 unsigned selectionLength = element()->focused() ? plainText(element()->docum ent().frame()->selection().selection().toNormalizedRange().get()).length() : 0; 365 unsigned selectionLength = element().focused() ? plainText(element().documen t().frame()->selection().selection().toNormalizedRange().get()).length() : 0;
366 ASSERT(oldLength >= selectionLength); 366 ASSERT(oldLength >= selectionLength);
367 367
368 // Selected characters will be removed by the next text event. 368 // Selected characters will be removed by the next text event.
369 unsigned baseLength = oldLength - selectionLength; 369 unsigned baseLength = oldLength - selectionLength;
370 unsigned maxLength = static_cast<unsigned>(isTextType() ? element()->maxLeng th() : HTMLInputElement::maximumLength); // maxLength can never be negative. 370 unsigned maxLength = static_cast<unsigned>(isTextType() ? element().maxLengt h() : HTMLInputElement::maximumLength); // maxLength can never be negative.
371 unsigned appendableLength = maxLength > baseLength ? maxLength - baseLength : 0; 371 unsigned appendableLength = maxLength > baseLength ? maxLength - baseLength : 0;
372 372
373 // Truncate the inserted text to avoid violating the maxLength and other con straints. 373 // Truncate the inserted text to avoid violating the maxLength and other con straints.
374 String eventText = event->text(); 374 String eventText = event->text();
375 unsigned textLength = eventText.length(); 375 unsigned textLength = eventText.length();
376 while (textLength > 0 && isASCIILineBreak(eventText[textLength - 1])) 376 while (textLength > 0 && isASCIILineBreak(eventText[textLength - 1]))
377 textLength--; 377 textLength--;
378 eventText.truncate(textLength); 378 eventText.truncate(textLength);
379 eventText.replace("\r\n", " "); 379 eventText.replace("\r\n", " ");
380 eventText.replace('\r', ' '); 380 eventText.replace('\r', ' ');
381 eventText.replace('\n', ' '); 381 eventText.replace('\n', ' ');
382 382
383 event->setText(limitLength(eventText, appendableLength)); 383 event->setText(limitLength(eventText, appendableLength));
384 } 384 }
385 385
386 bool TextFieldInputType::shouldRespectListAttribute() 386 bool TextFieldInputType::shouldRespectListAttribute()
387 { 387 {
388 return InputType::themeSupportsDataListUI(this); 388 return InputType::themeSupportsDataListUI(this);
389 } 389 }
390 390
391 void TextFieldInputType::updatePlaceholderText() 391 void TextFieldInputType::updatePlaceholderText()
392 { 392 {
393 if (!supportsPlaceholder()) 393 if (!supportsPlaceholder())
394 return; 394 return;
395 HTMLElement* placeholder = element()->placeholderElement(); 395 HTMLElement* placeholder = element().placeholderElement();
396 String placeholderText = element()->strippedPlaceholder(); 396 String placeholderText = element().strippedPlaceholder();
397 if (placeholderText.isEmpty()) { 397 if (placeholderText.isEmpty()) {
398 if (placeholder) 398 if (placeholder)
399 placeholder->remove(ASSERT_NO_EXCEPTION); 399 placeholder->remove(ASSERT_NO_EXCEPTION);
400 return; 400 return;
401 } 401 }
402 if (!placeholder) { 402 if (!placeholder) {
403 RefPtr<HTMLElement> newElement = HTMLDivElement::create(element()->docum ent()); 403 RefPtr<HTMLElement> newElement = HTMLDivElement::create(element().docume nt());
404 placeholder = newElement.get(); 404 placeholder = newElement.get();
405 placeholder->setPart(AtomicString("-webkit-input-placeholder", AtomicStr ing::ConstructFromLiteral)); 405 placeholder->setPart(AtomicString("-webkit-input-placeholder", AtomicStr ing::ConstructFromLiteral));
406 placeholder->setAttribute(idAttr, ShadowElementNames::placeholder()); 406 placeholder->setAttribute(idAttr, ShadowElementNames::placeholder());
407 Element* container = containerElement(); 407 Element* container = containerElement();
408 Node* previous = container ? container : innerTextElement(); 408 Node* previous = container ? container : innerTextElement();
409 previous->parentNode()->insertBefore(placeholder, previous->nextSibling( )); 409 previous->parentNode()->insertBefore(placeholder, previous->nextSibling( ));
410 ASSERT_WITH_SECURITY_IMPLICATION(placeholder->parentNode() == previous-> parentNode()); 410 ASSERT_WITH_SECURITY_IMPLICATION(placeholder->parentNode() == previous-> parentNode());
411 } 411 }
412 placeholder->setTextContent(placeholderText, ASSERT_NO_EXCEPTION); 412 placeholder->setTextContent(placeholderText, ASSERT_NO_EXCEPTION);
413 } 413 }
414 414
415 bool TextFieldInputType::appendFormData(FormDataList& list, bool multipart) cons t 415 bool TextFieldInputType::appendFormData(FormDataList& list, bool multipart) cons t
416 { 416 {
417 InputType::appendFormData(list, multipart); 417 InputType::appendFormData(list, multipart);
418 const AtomicString& dirnameAttrValue = element()->fastGetAttribute(dirnameAt tr); 418 const AtomicString& dirnameAttrValue = element().fastGetAttribute(dirnameAtt r);
419 if (!dirnameAttrValue.isNull()) 419 if (!dirnameAttrValue.isNull())
420 list.appendData(dirnameAttrValue, element()->directionForFormData()); 420 list.appendData(dirnameAttrValue, element().directionForFormData());
421 return true; 421 return true;
422 } 422 }
423 423
424 String TextFieldInputType::convertFromVisibleValue(const String& visibleValue) c onst 424 String TextFieldInputType::convertFromVisibleValue(const String& visibleValue) c onst
425 { 425 {
426 return visibleValue; 426 return visibleValue;
427 } 427 }
428 428
429 void TextFieldInputType::subtreeHasChanged() 429 void TextFieldInputType::subtreeHasChanged()
430 { 430 {
431 ASSERT(element()->renderer()); 431 ASSERT(element().renderer());
432 432
433 bool wasChanged = element()->wasChangedSinceLastFormControlChangeEvent(); 433 bool wasChanged = element().wasChangedSinceLastFormControlChangeEvent();
434 element()->setChangedSinceLastFormControlChangeEvent(true); 434 element().setChangedSinceLastFormControlChangeEvent(true);
435 435
436 // We don't need to call sanitizeUserInputValue() function here because 436 // We don't need to call sanitizeUserInputValue() function here because
437 // HTMLInputElement::handleBeforeTextInsertedEvent() has already called 437 // HTMLInputElement::handleBeforeTextInsertedEvent() has already called
438 // sanitizeUserInputValue(). 438 // sanitizeUserInputValue().
439 // sanitizeValue() is needed because IME input doesn't dispatch BeforeTextIn sertedEvent. 439 // sanitizeValue() is needed because IME input doesn't dispatch BeforeTextIn sertedEvent.
440 element()->setValueFromRenderer(sanitizeValue(convertFromVisibleValue(elemen t()->innerTextValue()))); 440 element().setValueFromRenderer(sanitizeValue(convertFromVisibleValue(element ().innerTextValue())));
441 element()->updatePlaceholderVisibility(false); 441 element().updatePlaceholderVisibility(false);
442 // Recalc for :invalid change. 442 // Recalc for :invalid change.
443 element()->setNeedsStyleRecalc(); 443 element().setNeedsStyleRecalc();
444 444
445 didSetValueByUserEdit(wasChanged ? ValueChangeStateChanged : ValueChangeStat eNone); 445 didSetValueByUserEdit(wasChanged ? ValueChangeStateChanged : ValueChangeStat eNone);
446 } 446 }
447 447
448 void TextFieldInputType::didSetValueByUserEdit(ValueChangeState state) 448 void TextFieldInputType::didSetValueByUserEdit(ValueChangeState state)
449 { 449 {
450 if (!element()->focused()) 450 if (!element().focused())
451 return; 451 return;
452 if (Frame* frame = element()->document().frame()) 452 if (Frame* frame = element().document().frame())
453 frame->editor().textDidChangeInTextField(element()); 453 frame->editor().textDidChangeInTextField(&element());
454 } 454 }
455 455
456 void TextFieldInputType::spinButtonStepDown() 456 void TextFieldInputType::spinButtonStepDown()
457 { 457 {
458 stepUpFromRenderer(-1); 458 stepUpFromRenderer(-1);
459 } 459 }
460 460
461 void TextFieldInputType::spinButtonStepUp() 461 void TextFieldInputType::spinButtonStepUp()
462 { 462 {
463 stepUpFromRenderer(1); 463 stepUpFromRenderer(1);
464 } 464 }
465 465
466 void TextFieldInputType::updateInnerTextValue() 466 void TextFieldInputType::updateInnerTextValue()
467 { 467 {
468 if (!element()->suggestedValue().isNull()) { 468 if (!element().suggestedValue().isNull()) {
469 element()->setInnerTextValue(element()->suggestedValue()); 469 element().setInnerTextValue(element().suggestedValue());
470 element()->updatePlaceholderVisibility(false); 470 element().updatePlaceholderVisibility(false);
471 } else if (!element()->formControlValueMatchesRenderer()) { 471 } else if (!element().formControlValueMatchesRenderer()) {
472 // Update the renderer value if the formControlValueMatchesRenderer() fl ag is false. 472 // Update the renderer value if the formControlValueMatchesRenderer() fl ag is false.
473 // It protects an unacceptable renderer value from being overwritten wit h the DOM value. 473 // It protects an unacceptable renderer value from being overwritten wit h the DOM value.
474 element()->setInnerTextValue(visibleValue()); 474 element().setInnerTextValue(visibleValue());
475 element()->updatePlaceholderVisibility(false); 475 element().updatePlaceholderVisibility(false);
476 } 476 }
477 } 477 }
478 478
479 void TextFieldInputType::focusAndSelectSpinButtonOwner() 479 void TextFieldInputType::focusAndSelectSpinButtonOwner()
480 { 480 {
481 RefPtr<HTMLInputElement> input(element()); 481 RefPtr<HTMLInputElement> input(element());
482 input->focus(); 482 input->focus();
483 input->select(); 483 input->select();
484 } 484 }
485 485
486 bool TextFieldInputType::shouldSpinButtonRespondToMouseEvents() 486 bool TextFieldInputType::shouldSpinButtonRespondToMouseEvents()
487 { 487 {
488 return !element()->isDisabledOrReadOnly(); 488 return !element().isDisabledOrReadOnly();
489 } 489 }
490 490
491 bool TextFieldInputType::shouldSpinButtonRespondToWheelEvents() 491 bool TextFieldInputType::shouldSpinButtonRespondToWheelEvents()
492 { 492 {
493 return shouldSpinButtonRespondToMouseEvents() && element()->focused(); 493 return shouldSpinButtonRespondToMouseEvents() && element().focused();
494 } 494 }
495 495
496 } // namespace WebCore 496 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/forms/TextFieldInputType.h ('k') | Source/core/html/forms/TextInputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698