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

Side by Side Diff: Source/core/html/forms/BaseMultipleFieldsDateAndTimeInputType.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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 bool DateTimeFormatValidator::validateFormat(const String& format, const BaseMul tipleFieldsDateAndTimeInputType& inputType) 123 bool DateTimeFormatValidator::validateFormat(const String& format, const BaseMul tipleFieldsDateAndTimeInputType& inputType)
124 { 124 {
125 if (!DateTimeFormat::parse(format, *this)) 125 if (!DateTimeFormat::parse(format, *this))
126 return false; 126 return false;
127 return inputType.isValidFormat(m_hasYear, m_hasMonth, m_hasWeek, m_hasDay, m _hasAMPM, m_hasHour, m_hasMinute, m_hasSecond); 127 return inputType.isValidFormat(m_hasYear, m_hasMonth, m_hasWeek, m_hasDay, m _hasAMPM, m_hasHour, m_hasMinute, m_hasSecond);
128 } 128 }
129 129
130 DateTimeEditElement* BaseMultipleFieldsDateAndTimeInputType::dateTimeEditElement () const 130 DateTimeEditElement* BaseMultipleFieldsDateAndTimeInputType::dateTimeEditElement () const
131 { 131 {
132 return toDateTimeEditElement(element()->userAgentShadowRoot()->getElementByI d(ShadowElementNames::dateTimeEdit())); 132 return toDateTimeEditElement(element().userAgentShadowRoot()->getElementById (ShadowElementNames::dateTimeEdit()));
133 } 133 }
134 134
135 SpinButtonElement* BaseMultipleFieldsDateAndTimeInputType::spinButtonElement() c onst 135 SpinButtonElement* BaseMultipleFieldsDateAndTimeInputType::spinButtonElement() c onst
136 { 136 {
137 return toSpinButtonElement(element()->userAgentShadowRoot()->getElementById( ShadowElementNames::spinButton())); 137 return toSpinButtonElement(element().userAgentShadowRoot()->getElementById(S hadowElementNames::spinButton()));
138 } 138 }
139 139
140 ClearButtonElement* BaseMultipleFieldsDateAndTimeInputType::clearButtonElement() const 140 ClearButtonElement* BaseMultipleFieldsDateAndTimeInputType::clearButtonElement() const
141 { 141 {
142 return toClearButtonElement(element()->userAgentShadowRoot()->getElementById (ShadowElementNames::clearButton())); 142 return toClearButtonElement(element().userAgentShadowRoot()->getElementById( ShadowElementNames::clearButton()));
143 } 143 }
144 144
145 PickerIndicatorElement* BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorE lement() const 145 PickerIndicatorElement* BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorE lement() const
146 { 146 {
147 return toPickerIndicatorElement(element()->userAgentShadowRoot()->getElement ById(ShadowElementNames::pickerIndicator())); 147 return toPickerIndicatorElement(element().userAgentShadowRoot()->getElementB yId(ShadowElementNames::pickerIndicator()));
148 } 148 }
149 149
150 inline bool BaseMultipleFieldsDateAndTimeInputType::containsFocusedShadowElement () const 150 inline bool BaseMultipleFieldsDateAndTimeInputType::containsFocusedShadowElement () const
151 { 151 {
152 return element()->userAgentShadowRoot()->contains(element()->document().focu sedElement()); 152 return element().userAgentShadowRoot()->contains(element().document().focuse dElement());
153 } 153 }
154 154
155 void BaseMultipleFieldsDateAndTimeInputType::didBlurFromControl() 155 void BaseMultipleFieldsDateAndTimeInputType::didBlurFromControl()
156 { 156 {
157 // We don't need to call blur(). This function is called when control 157 // We don't need to call blur(). This function is called when control
158 // lost focus. 158 // lost focus.
159 159
160 if (containsFocusedShadowElement()) 160 if (containsFocusedShadowElement())
161 return; 161 return;
162 RefPtr<HTMLInputElement> protector(element()); 162 RefPtr<HTMLInputElement> protector(element());
163 // Remove focus ring by CSS "focus" pseudo class. 163 // Remove focus ring by CSS "focus" pseudo class.
164 element()->setFocus(false); 164 element().setFocus(false);
165 } 165 }
166 166
167 void BaseMultipleFieldsDateAndTimeInputType::didFocusOnControl() 167 void BaseMultipleFieldsDateAndTimeInputType::didFocusOnControl()
168 { 168 {
169 // We don't need to call focus(). This function is called when control 169 // We don't need to call focus(). This function is called when control
170 // got focus. 170 // got focus.
171 171
172 if (!containsFocusedShadowElement()) 172 if (!containsFocusedShadowElement())
173 return; 173 return;
174 // Add focus ring by CSS "focus" pseudo class. 174 // Add focus ring by CSS "focus" pseudo class.
175 // FIXME: Setting the focus flag to non-focused element is too tricky. 175 // FIXME: Setting the focus flag to non-focused element is too tricky.
176 element()->setFocus(true); 176 element().setFocus(true);
177 } 177 }
178 178
179 void BaseMultipleFieldsDateAndTimeInputType::editControlValueChanged() 179 void BaseMultipleFieldsDateAndTimeInputType::editControlValueChanged()
180 { 180 {
181 RefPtr<HTMLInputElement> input(element()); 181 RefPtr<HTMLInputElement> input(element());
182 String oldValue = input->value(); 182 String oldValue = input->value();
183 String newValue = sanitizeValue(dateTimeEditElement()->value()); 183 String newValue = sanitizeValue(dateTimeEditElement()->value());
184 // Even if oldValue is null and newValue is "", we should assume they are sa me. 184 // Even if oldValue is null and newValue is "", we should assume they are sa me.
185 if ((oldValue.isEmpty() && newValue.isEmpty()) || oldValue == newValue) { 185 if ((oldValue.isEmpty() && newValue.isEmpty()) || oldValue == newValue) {
186 input->setNeedsValidityCheck(); 186 input->setNeedsValidityCheck();
187 } else { 187 } else {
188 input->setValueInternal(newValue, DispatchNoEvent); 188 input->setValueInternal(newValue, DispatchNoEvent);
189 input->setNeedsStyleRecalc(); 189 input->setNeedsStyleRecalc();
190 input->dispatchFormControlInputEvent(); 190 input->dispatchFormControlInputEvent();
191 input->dispatchFormControlChangeEvent(); 191 input->dispatchFormControlChangeEvent();
192 } 192 }
193 input->notifyFormStateChanged(); 193 input->notifyFormStateChanged();
194 input->updateClearButtonVisibility(); 194 input->updateClearButtonVisibility();
195 } 195 }
196 196
197 bool BaseMultipleFieldsDateAndTimeInputType::hasCustomFocusLogic() const 197 bool BaseMultipleFieldsDateAndTimeInputType::hasCustomFocusLogic() const
198 { 198 {
199 return false; 199 return false;
200 } 200 }
201 201
202 bool BaseMultipleFieldsDateAndTimeInputType::isEditControlOwnerDisabled() const 202 bool BaseMultipleFieldsDateAndTimeInputType::isEditControlOwnerDisabled() const
203 { 203 {
204 return element()->isDisabledFormControl(); 204 return element().isDisabledFormControl();
205 } 205 }
206 206
207 bool BaseMultipleFieldsDateAndTimeInputType::isEditControlOwnerReadOnly() const 207 bool BaseMultipleFieldsDateAndTimeInputType::isEditControlOwnerReadOnly() const
208 { 208 {
209 return element()->isReadOnly(); 209 return element().isReadOnly();
210 } 210 }
211 211
212 void BaseMultipleFieldsDateAndTimeInputType::focusAndSelectSpinButtonOwner() 212 void BaseMultipleFieldsDateAndTimeInputType::focusAndSelectSpinButtonOwner()
213 { 213 {
214 if (DateTimeEditElement* edit = dateTimeEditElement()) 214 if (DateTimeEditElement* edit = dateTimeEditElement())
215 edit->focusIfNoFocus(); 215 edit->focusIfNoFocus();
216 } 216 }
217 217
218 bool BaseMultipleFieldsDateAndTimeInputType::shouldSpinButtonRespondToMouseEvent s() 218 bool BaseMultipleFieldsDateAndTimeInputType::shouldSpinButtonRespondToMouseEvent s()
219 { 219 {
220 return !element()->isDisabledOrReadOnly(); 220 return !element().isDisabledOrReadOnly();
221 } 221 }
222 222
223 bool BaseMultipleFieldsDateAndTimeInputType::shouldSpinButtonRespondToWheelEvent s() 223 bool BaseMultipleFieldsDateAndTimeInputType::shouldSpinButtonRespondToWheelEvent s()
224 { 224 {
225 if (!shouldSpinButtonRespondToMouseEvents()) 225 if (!shouldSpinButtonRespondToMouseEvents())
226 return false; 226 return false;
227 if (DateTimeEditElement* edit = dateTimeEditElement()) 227 if (DateTimeEditElement* edit = dateTimeEditElement())
228 return edit->hasFocusedField(); 228 return edit->hasFocusedField();
229 return false; 229 return false;
230 } 230 }
231 231
232 void BaseMultipleFieldsDateAndTimeInputType::spinButtonStepDown() 232 void BaseMultipleFieldsDateAndTimeInputType::spinButtonStepDown()
233 { 233 {
234 if (DateTimeEditElement* edit = dateTimeEditElement()) 234 if (DateTimeEditElement* edit = dateTimeEditElement())
235 edit->stepDown(); 235 edit->stepDown();
236 } 236 }
237 237
238 void BaseMultipleFieldsDateAndTimeInputType::spinButtonStepUp() 238 void BaseMultipleFieldsDateAndTimeInputType::spinButtonStepUp()
239 { 239 {
240 if (DateTimeEditElement* edit = dateTimeEditElement()) 240 if (DateTimeEditElement* edit = dateTimeEditElement())
241 edit->stepUp(); 241 edit->stepUp();
242 } 242 }
243 243
244 bool BaseMultipleFieldsDateAndTimeInputType::isPickerIndicatorOwnerDisabledOrRea dOnly() const 244 bool BaseMultipleFieldsDateAndTimeInputType::isPickerIndicatorOwnerDisabledOrRea dOnly() const
245 { 245 {
246 return element()->isDisabledOrReadOnly(); 246 return element().isDisabledOrReadOnly();
247 } 247 }
248 248
249 void BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorChooseValue(const St ring& value) 249 void BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorChooseValue(const St ring& value)
250 { 250 {
251 if (element()->isValidValue(value)) { 251 if (element().isValidValue(value)) {
252 element()->setValue(value, DispatchInputAndChangeEvent); 252 element().setValue(value, DispatchInputAndChangeEvent);
253 return; 253 return;
254 } 254 }
255 255
256 DateTimeEditElement* edit = this->dateTimeEditElement(); 256 DateTimeEditElement* edit = this->dateTimeEditElement();
257 if (!edit) 257 if (!edit)
258 return; 258 return;
259 DateComponents date; 259 DateComponents date;
260 unsigned end; 260 unsigned end;
261 if (date.parseDate(value, 0, end) && end == value.length()) 261 if (date.parseDate(value, 0, end) && end == value.length())
262 edit->setOnlyYearMonthDay(date); 262 edit->setOnlyYearMonthDay(date);
263 } 263 }
264 264
265 bool BaseMultipleFieldsDateAndTimeInputType::setupDateTimeChooserParameters(Date TimeChooserParameters& parameters) 265 bool BaseMultipleFieldsDateAndTimeInputType::setupDateTimeChooserParameters(Date TimeChooserParameters& parameters)
266 { 266 {
267 return element()->setupDateTimeChooserParameters(parameters); 267 return element().setupDateTimeChooserParameters(parameters);
268 } 268 }
269 269
270 BaseMultipleFieldsDateAndTimeInputType::BaseMultipleFieldsDateAndTimeInputType(H TMLInputElement* element) 270 BaseMultipleFieldsDateAndTimeInputType::BaseMultipleFieldsDateAndTimeInputType(H TMLInputElement& element)
271 : BaseDateAndTimeInputType(element) 271 : BaseDateAndTimeInputType(element)
272 , m_isDestroyingShadowSubtree(false) 272 , m_isDestroyingShadowSubtree(false)
273 , m_pickerIndicatorIsVisible(false) 273 , m_pickerIndicatorIsVisible(false)
274 , m_pickerIndicatorIsAlwaysVisible(false) 274 , m_pickerIndicatorIsAlwaysVisible(false)
275 { 275 {
276 } 276 }
277 277
278 BaseMultipleFieldsDateAndTimeInputType::~BaseMultipleFieldsDateAndTimeInputType( ) 278 BaseMultipleFieldsDateAndTimeInputType::~BaseMultipleFieldsDateAndTimeInputType( )
279 { 279 {
280 if (SpinButtonElement* element = spinButtonElement()) 280 if (SpinButtonElement* element = spinButtonElement())
(...skipping 18 matching lines...) Expand all
299 } 299 }
300 300
301 PassRefPtr<RenderStyle> BaseMultipleFieldsDateAndTimeInputType::customStyleForRe nderer(PassRefPtr<RenderStyle> originalStyle) 301 PassRefPtr<RenderStyle> BaseMultipleFieldsDateAndTimeInputType::customStyleForRe nderer(PassRefPtr<RenderStyle> originalStyle)
302 { 302 {
303 EDisplay originalDisplay = originalStyle->display(); 303 EDisplay originalDisplay = originalStyle->display();
304 EDisplay newDisplay = originalDisplay; 304 EDisplay newDisplay = originalDisplay;
305 if (originalDisplay == INLINE || originalDisplay == INLINE_BLOCK) 305 if (originalDisplay == INLINE || originalDisplay == INLINE_BLOCK)
306 newDisplay = INLINE_FLEX; 306 newDisplay = INLINE_FLEX;
307 else if (originalDisplay == BLOCK) 307 else if (originalDisplay == BLOCK)
308 newDisplay = FLEX; 308 newDisplay = FLEX;
309 TextDirection contentDirection = element()->locale().isRTL() ? RTL : LTR; 309 TextDirection contentDirection = element().locale().isRTL() ? RTL : LTR;
310 if (originalStyle->direction() == contentDirection && originalDisplay == new Display) 310 if (originalStyle->direction() == contentDirection && originalDisplay == new Display)
311 return originalStyle; 311 return originalStyle;
312 312
313 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get()); 313 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
314 style->setDirection(contentDirection); 314 style->setDirection(contentDirection);
315 style->setDisplay(newDisplay); 315 style->setDisplay(newDisplay);
316 return style.release(); 316 return style.release();
317 } 317 }
318 318
319 void BaseMultipleFieldsDateAndTimeInputType::createShadowSubtree() 319 void BaseMultipleFieldsDateAndTimeInputType::createShadowSubtree()
320 { 320 {
321 ASSERT(element()->shadow()); 321 ASSERT(element().shadow());
322 322
323 // Element must not have a renderer here, because if it did 323 // Element must not have a renderer here, because if it did
324 // DateTimeEditElement::customStyleForRenderer() is called in appendChild() 324 // DateTimeEditElement::customStyleForRenderer() is called in appendChild()
325 // before the field wrapper element is created. 325 // before the field wrapper element is created.
326 // FIXME: This code should not depend on such craziness. 326 // FIXME: This code should not depend on such craziness.
327 ASSERT(!element()->renderer()); 327 ASSERT(!element().renderer());
328 328
329 Document& document = element()->document(); 329 Document& document = element().document();
330 ContainerNode* container = element()->userAgentShadowRoot(); 330 ContainerNode* container = element().userAgentShadowRoot();
331 331
332 container->appendChild(DateTimeEditElement::create(document, *this)); 332 container->appendChild(DateTimeEditElement::create(document, *this));
333 updateInnerTextValue(); 333 updateInnerTextValue();
334 container->appendChild(ClearButtonElement::create(document, *this)); 334 container->appendChild(ClearButtonElement::create(document, *this));
335 container->appendChild(SpinButtonElement::create(document, *this)); 335 container->appendChild(SpinButtonElement::create(document, *this));
336 336
337 bool shouldAddPickerIndicator = false; 337 bool shouldAddPickerIndicator = false;
338 if (InputType::themeSupportsDataListUI(this)) 338 if (InputType::themeSupportsDataListUI(this))
339 shouldAddPickerIndicator = true; 339 shouldAddPickerIndicator = true;
340 if (RenderTheme::theme().supportsCalendarPicker(formControlType())) { 340 if (RenderTheme::theme().supportsCalendarPicker(formControlType())) {
(...skipping 16 matching lines...) Expand all
357 if (ClearButtonElement* element = clearButtonElement()) 357 if (ClearButtonElement* element = clearButtonElement())
358 element->removeClearButtonOwner(); 358 element->removeClearButtonOwner();
359 if (DateTimeEditElement* element = dateTimeEditElement()) 359 if (DateTimeEditElement* element = dateTimeEditElement())
360 element->removeEditControlOwner(); 360 element->removeEditControlOwner();
361 if (PickerIndicatorElement* element = pickerIndicatorElement()) 361 if (PickerIndicatorElement* element = pickerIndicatorElement())
362 element->removePickerIndicatorOwner(); 362 element->removePickerIndicatorOwner();
363 363
364 // If a field element has focus, set focus back to the <input> itself before 364 // If a field element has focus, set focus back to the <input> itself before
365 // deleting the field. This prevents unnecessary focusout/blur events. 365 // deleting the field. This prevents unnecessary focusout/blur events.
366 if (containsFocusedShadowElement()) 366 if (containsFocusedShadowElement())
367 element()->focus(); 367 element().focus();
368 368
369 BaseDateAndTimeInputType::destroyShadowSubtree(); 369 BaseDateAndTimeInputType::destroyShadowSubtree();
370 m_isDestroyingShadowSubtree = false; 370 m_isDestroyingShadowSubtree = false;
371 } 371 }
372 372
373 void BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent(Element* oldFocuse dElement, FocusDirection direction) 373 void BaseMultipleFieldsDateAndTimeInputType::handleFocusEvent(Element* oldFocuse dElement, FocusDirection direction)
374 { 374 {
375 DateTimeEditElement* edit = dateTimeEditElement(); 375 DateTimeEditElement* edit = dateTimeEditElement();
376 if (!edit || m_isDestroyingShadowSubtree) 376 if (!edit || m_isDestroyingShadowSubtree)
377 return; 377 return;
378 if (direction == FocusDirectionBackward) { 378 if (direction == FocusDirectionBackward) {
379 if (element()->document().page()) 379 if (element().document().page())
380 element()->document().page()->focusController().advanceFocus(directi on); 380 element().document().page()->focusController().advanceFocus(directio n);
381 } else if (direction == FocusDirectionNone || direction == FocusDirectionMou se || direction == FocusDirectionPage) { 381 } else if (direction == FocusDirectionNone || direction == FocusDirectionMou se || direction == FocusDirectionPage) {
382 edit->focusByOwner(oldFocusedElement); 382 edit->focusByOwner(oldFocusedElement);
383 } else { 383 } else {
384 edit->focusByOwner(); 384 edit->focusByOwner();
385 } 385 }
386 } 386 }
387 387
388 void BaseMultipleFieldsDateAndTimeInputType::forwardEvent(Event* event) 388 void BaseMultipleFieldsDateAndTimeInputType::forwardEvent(Event* event)
389 { 389 {
390 if (SpinButtonElement* element = spinButtonElement()) { 390 if (SpinButtonElement* element = spinButtonElement()) {
(...skipping 28 matching lines...) Expand all
419 element->openPopup(); 419 element->openPopup();
420 event->setDefaultHandled(); 420 event->setDefaultHandled();
421 } else { 421 } else {
422 forwardEvent(event); 422 forwardEvent(event);
423 } 423 }
424 } 424 }
425 425
426 bool BaseMultipleFieldsDateAndTimeInputType::hasBadInput() const 426 bool BaseMultipleFieldsDateAndTimeInputType::hasBadInput() const
427 { 427 {
428 DateTimeEditElement* edit = dateTimeEditElement(); 428 DateTimeEditElement* edit = dateTimeEditElement();
429 return element()->value().isEmpty() && edit && edit->anyEditableFieldsHaveVa lues(); 429 return element().value().isEmpty() && edit && edit->anyEditableFieldsHaveVal ues();
430 } 430 }
431 431
432 AtomicString BaseMultipleFieldsDateAndTimeInputType::localeIdentifier() const 432 AtomicString BaseMultipleFieldsDateAndTimeInputType::localeIdentifier() const
433 { 433 {
434 return element()->computeInheritedLanguage(); 434 return element().computeInheritedLanguage();
435 } 435 }
436 436
437 void BaseMultipleFieldsDateAndTimeInputType::minOrMaxAttributeChanged() 437 void BaseMultipleFieldsDateAndTimeInputType::minOrMaxAttributeChanged()
438 { 438 {
439 updateInnerTextValue(); 439 updateInnerTextValue();
440 } 440 }
441 441
442 void BaseMultipleFieldsDateAndTimeInputType::readonlyAttributeChanged() 442 void BaseMultipleFieldsDateAndTimeInputType::readonlyAttributeChanged()
443 { 443 {
444 spinButtonElement()->releaseCapture(); 444 spinButtonElement()->releaseCapture();
445 clearButtonElement()->releaseCapture(); 445 clearButtonElement()->releaseCapture();
446 if (DateTimeEditElement* edit = dateTimeEditElement()) 446 if (DateTimeEditElement* edit = dateTimeEditElement())
447 edit->readOnlyStateChanged(); 447 edit->readOnlyStateChanged();
448 } 448 }
449 449
450 void BaseMultipleFieldsDateAndTimeInputType::restoreFormControlState(const FormC ontrolState& state) 450 void BaseMultipleFieldsDateAndTimeInputType::restoreFormControlState(const FormC ontrolState& state)
451 { 451 {
452 DateTimeEditElement* edit = dateTimeEditElement(); 452 DateTimeEditElement* edit = dateTimeEditElement();
453 if (!edit) 453 if (!edit)
454 return; 454 return;
455 DateTimeFieldsState dateTimeFieldsState = DateTimeFieldsState::restoreFormCo ntrolState(state); 455 DateTimeFieldsState dateTimeFieldsState = DateTimeFieldsState::restoreFormCo ntrolState(state);
456 edit->setValueAsDateTimeFieldsState(dateTimeFieldsState); 456 edit->setValueAsDateTimeFieldsState(dateTimeFieldsState);
457 element()->setValueInternal(sanitizeValue(edit->value()), DispatchNoEvent); 457 element().setValueInternal(sanitizeValue(edit->value()), DispatchNoEvent);
458 updateClearButtonVisibility(); 458 updateClearButtonVisibility();
459 } 459 }
460 460
461 FormControlState BaseMultipleFieldsDateAndTimeInputType::saveFormControlState() const 461 FormControlState BaseMultipleFieldsDateAndTimeInputType::saveFormControlState() const
462 { 462 {
463 if (DateTimeEditElement* edit = dateTimeEditElement()) 463 if (DateTimeEditElement* edit = dateTimeEditElement())
464 return edit->valueAsDateTimeFieldsState().saveFormControlState(); 464 return edit->valueAsDateTimeFieldsState().saveFormControlState();
465 return FormControlState(); 465 return FormControlState();
466 } 466 }
467 467
468 void BaseMultipleFieldsDateAndTimeInputType::setValue(const String& sanitizedVal ue, bool valueChanged, TextFieldEventBehavior eventBehavior) 468 void BaseMultipleFieldsDateAndTimeInputType::setValue(const String& sanitizedVal ue, bool valueChanged, TextFieldEventBehavior eventBehavior)
469 { 469 {
470 InputType::setValue(sanitizedValue, valueChanged, eventBehavior); 470 InputType::setValue(sanitizedValue, valueChanged, eventBehavior);
471 DateTimeEditElement* edit = dateTimeEditElement(); 471 DateTimeEditElement* edit = dateTimeEditElement();
472 if (valueChanged || (sanitizedValue.isEmpty() && edit && edit->anyEditableFi eldsHaveValues())) { 472 if (valueChanged || (sanitizedValue.isEmpty() && edit && edit->anyEditableFi eldsHaveValues())) {
473 updateInnerTextValue(); 473 updateInnerTextValue();
474 element()->setNeedsValidityCheck(); 474 element().setNeedsValidityCheck();
475 } 475 }
476 } 476 }
477 477
478 bool BaseMultipleFieldsDateAndTimeInputType::shouldUseInputMethod() const 478 bool BaseMultipleFieldsDateAndTimeInputType::shouldUseInputMethod() const
479 { 479 {
480 return false; 480 return false;
481 } 481 }
482 482
483 void BaseMultipleFieldsDateAndTimeInputType::stepAttributeChanged() 483 void BaseMultipleFieldsDateAndTimeInputType::stepAttributeChanged()
484 { 484 {
485 updateInnerTextValue(); 485 updateInnerTextValue();
486 } 486 }
487 487
488 void BaseMultipleFieldsDateAndTimeInputType::updateInnerTextValue() 488 void BaseMultipleFieldsDateAndTimeInputType::updateInnerTextValue()
489 { 489 {
490 DateTimeEditElement* edit = dateTimeEditElement(); 490 DateTimeEditElement* edit = dateTimeEditElement();
491 if (!edit) 491 if (!edit)
492 return; 492 return;
493 493
494 DateTimeEditElement::LayoutParameters layoutParameters(element()->locale(), createStepRange(AnyIsDefaultStep)); 494 DateTimeEditElement::LayoutParameters layoutParameters(element().locale(), c reateStepRange(AnyIsDefaultStep));
495 495
496 DateComponents date; 496 DateComponents date;
497 const bool hasValue = parseToDateComponents(element()->value(), &date); 497 const bool hasValue = parseToDateComponents(element().value(), &date);
498 if (!hasValue) 498 if (!hasValue)
499 setMillisecondToDateComponents(layoutParameters.stepRange.minimum().toDo uble(), &date); 499 setMillisecondToDateComponents(layoutParameters.stepRange.minimum().toDo uble(), &date);
500 500
501 setupLayoutParameters(layoutParameters, date); 501 setupLayoutParameters(layoutParameters, date);
502 502
503 const AtomicString pattern = edit->fastGetAttribute(HTMLNames::patternAttr); 503 const AtomicString pattern = edit->fastGetAttribute(HTMLNames::patternAttr);
504 if (!pattern.isEmpty()) 504 if (!pattern.isEmpty())
505 layoutParameters.dateTimeFormat = pattern; 505 layoutParameters.dateTimeFormat = pattern;
506 506
507 if (!DateTimeFormatValidator().validateFormat(layoutParameters.dateTimeForma t, *this)) 507 if (!DateTimeFormatValidator().validateFormat(layoutParameters.dateTimeForma t, *this))
508 layoutParameters.dateTimeFormat = layoutParameters.fallbackDateTimeForma t; 508 layoutParameters.dateTimeFormat = layoutParameters.fallbackDateTimeForma t;
509 509
510 if (hasValue) 510 if (hasValue)
511 edit->setValueAsDate(layoutParameters, date); 511 edit->setValueAsDate(layoutParameters, date);
512 else 512 else
513 edit->setEmptyValue(layoutParameters, date); 513 edit->setEmptyValue(layoutParameters, date);
514 updateClearButtonVisibility(); 514 updateClearButtonVisibility();
515 } 515 }
516 516
517 void BaseMultipleFieldsDateAndTimeInputType::valueAttributeChanged() 517 void BaseMultipleFieldsDateAndTimeInputType::valueAttributeChanged()
518 { 518 {
519 if (!element()->hasDirtyValue()) 519 if (!element().hasDirtyValue())
520 updateInnerTextValue(); 520 updateInnerTextValue();
521 } 521 }
522 522
523 void BaseMultipleFieldsDateAndTimeInputType::listAttributeTargetChanged() 523 void BaseMultipleFieldsDateAndTimeInputType::listAttributeTargetChanged()
524 { 524 {
525 updatePickerIndicatorVisibility(); 525 updatePickerIndicatorVisibility();
526 } 526 }
527 527
528 void BaseMultipleFieldsDateAndTimeInputType::updatePickerIndicatorVisibility() 528 void BaseMultipleFieldsDateAndTimeInputType::updatePickerIndicatorVisibility()
529 { 529 {
530 if (m_pickerIndicatorIsAlwaysVisible) { 530 if (m_pickerIndicatorIsAlwaysVisible) {
531 showPickerIndicator(); 531 showPickerIndicator();
532 return; 532 return;
533 } 533 }
534 if (RuntimeEnabledFeatures::dataListElementEnabled()) { 534 if (RuntimeEnabledFeatures::dataListElementEnabled()) {
535 if (HTMLDataListElement* dataList = element()->dataList()) { 535 if (HTMLDataListElement* dataList = element().dataList()) {
536 RefPtr<HTMLCollection> options = dataList->options(); 536 RefPtr<HTMLCollection> options = dataList->options();
537 for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement (options->item(i)); ++i) { 537 for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement (options->item(i)); ++i) {
538 if (element()->isValidValue(option->value())) { 538 if (element().isValidValue(option->value())) {
539 showPickerIndicator(); 539 showPickerIndicator();
540 return; 540 return;
541 } 541 }
542 } 542 }
543 } 543 }
544 hidePickerIndicator(); 544 hidePickerIndicator();
545 } 545 }
546 } 546 }
547 547
548 void BaseMultipleFieldsDateAndTimeInputType::hidePickerIndicator() 548 void BaseMultipleFieldsDateAndTimeInputType::hidePickerIndicator()
(...skipping 17 matching lines...) Expand all
566 bool BaseMultipleFieldsDateAndTimeInputType::shouldHaveSecondField(const DateCom ponents& date) const 566 bool BaseMultipleFieldsDateAndTimeInputType::shouldHaveSecondField(const DateCom ponents& date) const
567 { 567 {
568 StepRange stepRange = createStepRange(AnyIsDefaultStep); 568 StepRange stepRange = createStepRange(AnyIsDefaultStep);
569 return date.second() || date.millisecond() 569 return date.second() || date.millisecond()
570 || !stepRange.minimum().remainder(static_cast<int>(msPerMinute)).isZero( ) 570 || !stepRange.minimum().remainder(static_cast<int>(msPerMinute)).isZero( )
571 || !stepRange.step().remainder(static_cast<int>(msPerMinute)).isZero(); 571 || !stepRange.step().remainder(static_cast<int>(msPerMinute)).isZero();
572 } 572 }
573 573
574 void BaseMultipleFieldsDateAndTimeInputType::focusAndSelectClearButtonOwner() 574 void BaseMultipleFieldsDateAndTimeInputType::focusAndSelectClearButtonOwner()
575 { 575 {
576 element()->focus(); 576 element().focus();
577 } 577 }
578 578
579 bool BaseMultipleFieldsDateAndTimeInputType::shouldClearButtonRespondToMouseEven ts() 579 bool BaseMultipleFieldsDateAndTimeInputType::shouldClearButtonRespondToMouseEven ts()
580 { 580 {
581 return !element()->isDisabledOrReadOnly() && !element()->isRequired(); 581 return !element().isDisabledOrReadOnly() && !element().isRequired();
582 } 582 }
583 583
584 void BaseMultipleFieldsDateAndTimeInputType::clearValue() 584 void BaseMultipleFieldsDateAndTimeInputType::clearValue()
585 { 585 {
586 RefPtr<HTMLInputElement> input(element()); 586 RefPtr<HTMLInputElement> input(element());
587 input->setValue("", DispatchInputAndChangeEvent); 587 input->setValue("", DispatchInputAndChangeEvent);
588 input->updateClearButtonVisibility(); 588 input->updateClearButtonVisibility();
589 } 589 }
590 590
591 void BaseMultipleFieldsDateAndTimeInputType::updateClearButtonVisibility() 591 void BaseMultipleFieldsDateAndTimeInputType::updateClearButtonVisibility()
592 { 592 {
593 ClearButtonElement* clearButton = clearButtonElement(); 593 ClearButtonElement* clearButton = clearButtonElement();
594 if (!clearButton) 594 if (!clearButton)
595 return; 595 return;
596 596
597 if (element()->isRequired() || !dateTimeEditElement()->anyEditableFieldsHave Values()) 597 if (element().isRequired() || !dateTimeEditElement()->anyEditableFieldsHaveV alues())
598 clearButton->setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidde n); 598 clearButton->setInlineStyleProperty(CSSPropertyVisibility, CSSValueHidde n);
599 else 599 else
600 clearButton->removeInlineStyleProperty(CSSPropertyVisibility); 600 clearButton->removeInlineStyleProperty(CSSPropertyVisibility);
601 } 601 }
602 602
603 } // namespace WebCore 603 } // namespace WebCore
604 604
605 #endif 605 #endif
OLDNEW
« no previous file with comments | « Source/core/html/forms/BaseMultipleFieldsDateAndTimeInputType.h ('k') | Source/core/html/forms/BaseTextInputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698