| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 528 } |
| 529 | 529 |
| 530 void DateTimeEditElement::addField(DateTimeFieldElement* field) { | 530 void DateTimeEditElement::addField(DateTimeFieldElement* field) { |
| 531 if (m_fields.size() >= maximumNumberOfFields) | 531 if (m_fields.size() >= maximumNumberOfFields) |
| 532 return; | 532 return; |
| 533 m_fields.append(field); | 533 m_fields.append(field); |
| 534 fieldsWrapperElement()->appendChild(field); | 534 fieldsWrapperElement()->appendChild(field); |
| 535 } | 535 } |
| 536 | 536 |
| 537 bool DateTimeEditElement::anyEditableFieldsHaveValues() const { | 537 bool DateTimeEditElement::anyEditableFieldsHaveValues() const { |
| 538 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) { | 538 for (const auto& field : m_fields) { |
| 539 if (!m_fields[fieldIndex]->isDisabled() && m_fields[fieldIndex]->hasValue()) | 539 if (!field->isDisabled() && field->hasValue()) |
| 540 return true; | 540 return true; |
| 541 } | 541 } |
| 542 return false; | 542 return false; |
| 543 } | 543 } |
| 544 | 544 |
| 545 void DateTimeEditElement::blurByOwner() { | 545 void DateTimeEditElement::blurByOwner() { |
| 546 if (DateTimeFieldElement* field = focusedField()) | 546 if (DateTimeFieldElement* field = focusedField()) |
| 547 field->blur(); | 547 field->blur(); |
| 548 } | 548 } |
| 549 | 549 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 void DateTimeEditElement::fieldDidChangeValueByKeyboard() { | 760 void DateTimeEditElement::fieldDidChangeValueByKeyboard() { |
| 761 if (m_editControlOwner) | 761 if (m_editControlOwner) |
| 762 m_editControlOwner->editControlDidChangeValueByKeyboard(); | 762 m_editControlOwner->editControlDidChangeValueByKeyboard(); |
| 763 } | 763 } |
| 764 | 764 |
| 765 void DateTimeEditElement::readOnlyStateChanged() { | 765 void DateTimeEditElement::readOnlyStateChanged() { |
| 766 updateUIState(); | 766 updateUIState(); |
| 767 } | 767 } |
| 768 | 768 |
| 769 void DateTimeEditElement::resetFields() { | 769 void DateTimeEditElement::resetFields() { |
| 770 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) | 770 for (const auto& field : m_fields) |
| 771 m_fields[fieldIndex]->removeEventHandler(); | 771 field->removeEventHandler(); |
| 772 m_fields.shrink(0); | 772 m_fields.shrink(0); |
| 773 } | 773 } |
| 774 | 774 |
| 775 void DateTimeEditElement::defaultEventHandler(Event* event) { | 775 void DateTimeEditElement::defaultEventHandler(Event* event) { |
| 776 // In case of control owner forward event to control, e.g. DOM | 776 // In case of control owner forward event to control, e.g. DOM |
| 777 // dispatchEvent method. | 777 // dispatchEvent method. |
| 778 if (DateTimeFieldElement* field = focusedField()) { | 778 if (DateTimeFieldElement* field = focusedField()) { |
| 779 field->defaultEventHandler(event); | 779 field->defaultEventHandler(event); |
| 780 if (event->defaultHandled()) | 780 if (event->defaultHandled()) |
| 781 return; | 781 return; |
| 782 } | 782 } |
| 783 | 783 |
| 784 HTMLDivElement::defaultEventHandler(event); | 784 HTMLDivElement::defaultEventHandler(event); |
| 785 } | 785 } |
| 786 | 786 |
| 787 void DateTimeEditElement::setValueAsDate( | 787 void DateTimeEditElement::setValueAsDate( |
| 788 const LayoutParameters& layoutParameters, | 788 const LayoutParameters& layoutParameters, |
| 789 const DateComponents& date) { | 789 const DateComponents& date) { |
| 790 layout(layoutParameters, date); | 790 layout(layoutParameters, date); |
| 791 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) | 791 for (const auto& field : m_fields) |
| 792 m_fields[fieldIndex]->setValueAsDate(date); | 792 field->setValueAsDate(date); |
| 793 } | 793 } |
| 794 | 794 |
| 795 void DateTimeEditElement::setValueAsDateTimeFieldsState( | 795 void DateTimeEditElement::setValueAsDateTimeFieldsState( |
| 796 const DateTimeFieldsState& dateTimeFieldsState) { | 796 const DateTimeFieldsState& dateTimeFieldsState) { |
| 797 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) | 797 for (const auto& field : m_fields) |
| 798 m_fields[fieldIndex]->setValueAsDateTimeFieldsState(dateTimeFieldsState); | 798 field->setValueAsDateTimeFieldsState(dateTimeFieldsState); |
| 799 } | 799 } |
| 800 | 800 |
| 801 void DateTimeEditElement::setEmptyValue( | 801 void DateTimeEditElement::setEmptyValue( |
| 802 const LayoutParameters& layoutParameters, | 802 const LayoutParameters& layoutParameters, |
| 803 const DateComponents& dateForReadOnlyField) { | 803 const DateComponents& dateForReadOnlyField) { |
| 804 layout(layoutParameters, dateForReadOnlyField); | 804 layout(layoutParameters, dateForReadOnlyField); |
| 805 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) | 805 for (const auto& field : m_fields) |
| 806 m_fields[fieldIndex]->setEmptyValue(DateTimeFieldElement::DispatchNoEvent); | 806 field->setEmptyValue(DateTimeFieldElement::DispatchNoEvent); |
| 807 } | 807 } |
| 808 | 808 |
| 809 bool DateTimeEditElement::hasFocusedField() { | 809 bool DateTimeEditElement::hasFocusedField() { |
| 810 return focusedFieldIndex() != invalidFieldIndex; | 810 return focusedFieldIndex() != invalidFieldIndex; |
| 811 } | 811 } |
| 812 | 812 |
| 813 void DateTimeEditElement::setOnlyYearMonthDay(const DateComponents& date) { | 813 void DateTimeEditElement::setOnlyYearMonthDay(const DateComponents& date) { |
| 814 DCHECK_EQ(date.getType(), DateComponents::Date); | 814 DCHECK_EQ(date.getType(), DateComponents::Date); |
| 815 | 815 |
| 816 if (!m_editControlOwner) | 816 if (!m_editControlOwner) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 843 | 843 |
| 844 String DateTimeEditElement::value() const { | 844 String DateTimeEditElement::value() const { |
| 845 if (!m_editControlOwner) | 845 if (!m_editControlOwner) |
| 846 return emptyString(); | 846 return emptyString(); |
| 847 return m_editControlOwner->formatDateTimeFieldsState( | 847 return m_editControlOwner->formatDateTimeFieldsState( |
| 848 valueAsDateTimeFieldsState()); | 848 valueAsDateTimeFieldsState()); |
| 849 } | 849 } |
| 850 | 850 |
| 851 DateTimeFieldsState DateTimeEditElement::valueAsDateTimeFieldsState() const { | 851 DateTimeFieldsState DateTimeEditElement::valueAsDateTimeFieldsState() const { |
| 852 DateTimeFieldsState dateTimeFieldsState; | 852 DateTimeFieldsState dateTimeFieldsState; |
| 853 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) | 853 for (const auto& field : m_fields) |
| 854 m_fields[fieldIndex]->populateDateTimeFieldsState(dateTimeFieldsState); | 854 field->populateDateTimeFieldsState(dateTimeFieldsState); |
| 855 return dateTimeFieldsState; | 855 return dateTimeFieldsState; |
| 856 } | 856 } |
| 857 | 857 |
| 858 } // namespace blink | 858 } // namespace blink |
| OLD | NEW |