diff options
author | Kristian Monsen <kristianm@google.com> | 2011-07-07 22:08:31 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-07-07 22:08:31 +0100 |
commit | a37288025960d07eaad4f09905dbb9734c389c22 (patch) | |
tree | 4a65bf45e5b64c8cd6787ae8f6b3c403562817ef | |
parent | 2ffb1b9dca346e24046fc05b04438222f8448383 (diff) | |
download | external_webkit-a37288025960d07eaad4f09905dbb9734c389c22.zip external_webkit-a37288025960d07eaad4f09905dbb9734c389c22.tar.gz external_webkit-a37288025960d07eaad4f09905dbb9734c389c22.tar.bz2 |
Merge Chromium at r12.0.742.93: Direct access in FormField
FormField changed to a struct with public members instead of
a class with setters and getters. CL:
http://codereview.chromium.org/6625087
Change-Id: I02f589b671147c1ff09661b032c979c85e15a264
4 files changed, 58 insertions, 70 deletions
diff --git a/Source/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.cpp b/Source/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.cpp index 6af0875..1116b7f 100644 --- a/Source/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.cpp +++ b/Source/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.cpp @@ -52,31 +52,31 @@ using namespace WebCore::HTMLNames; namespace webkit_glue { FormField::FormField() - : max_length_(0), - is_autofilled_(false) { + : max_length(0), + is_autofilled(false) { } // TODO: This constructor should probably be deprecated and the // functionality moved to FormManager. FormField::FormField(const HTMLFormControlElement& element) - : max_length_(0), - is_autofilled_(false) { - name_ = nameForAutoFill(element); + : max_length(0), + is_autofilled(false) { + name = nameForAutoFill(element); // TODO: Extract the field label. For now we just use the field // name. - label_ = name_; + label = name; - form_control_type_ = formControlType(element); - if (form_control_type_ == kText) { + form_control_type = formControlType(element); + if (form_control_type == kText) { const HTMLInputElement& input_element = static_cast<const HTMLInputElement&>(element); - value_ = WTFStringToString16(input_element.value()); - max_length_ = input_element.size(); - is_autofilled_ = input_element.isAutofilled(); - } else if (form_control_type_ == kSelectOne) { + value = WTFStringToString16(input_element.value()); + max_length = input_element.size(); + is_autofilled = input_element.isAutofilled(); + } else if (form_control_type == kSelectOne) { const HTMLSelectElement& const_select_element = static_cast<const HTMLSelectElement&>(element); HTMLSelectElement& select_element = const_cast<HTMLSelectElement&>(const_select_element); - value_ = WTFStringToString16(select_element.value()); + value = WTFStringToString16(select_element.value()); // For select-one elements copy option strings. WTF::Vector<Element*> list_items = select_element.listItems(); @@ -87,16 +87,16 @@ FormField::FormField(const HTMLFormControlElement& element) } } - TrimWhitespace(value_, TRIM_LEADING, &value_); + TrimWhitespace(value, TRIM_LEADING, &value); } -FormField::FormField(const string16& label, const string16& name, const string16& value, const string16& form_control_type, int max_length, bool is_autofilled) - : label_(label), - name_(name), - value_(value), - form_control_type_(form_control_type), - max_length_(max_length), - is_autofilled_(is_autofilled) { +FormField::FormField(const string16& _label, const string16& _name, const string16& _value, const string16& _form_control_type, int _max_length, bool _is_autofilled) + : label(_label), + name(_name), + value(_value), + form_control_type(_form_control_type), + max_length(_max_length), + is_autofilled(_is_autofilled) { } FormField::~FormField() { @@ -105,10 +105,10 @@ FormField::~FormField() { bool FormField::operator==(const FormField& field) const { // A FormField stores a value, but the value is not part of the identity of // the field, so we don't want to compare the values. - return (label_ == field.label_ && - name_ == field.name_ && - form_control_type_ == field.form_control_type_ && - max_length_ == field.max_length_); + return (label == field.label && + name == field.name && + form_control_type == field.form_control_type && + max_length == field.max_length); } bool FormField::operator!=(const FormField& field) const { @@ -116,24 +116,24 @@ bool FormField::operator!=(const FormField& field) const { } bool FormField::StrictlyEqualsHack(const FormField& field) const { - return (label_ == field.label_ && - name_ == field.name_ && - value_ == field.value_ && - form_control_type_ == field.form_control_type_ && - max_length_ == field.max_length_); + return (label == field.label && + name == field.name && + value == field.value && + form_control_type == field.form_control_type && + max_length == field.max_length); } std::ostream& operator<<(std::ostream& os, const FormField& field) { return os - << UTF16ToUTF8(field.label()) + << UTF16ToUTF8(field.label) << " " - << UTF16ToUTF8(field.name()) + << UTF16ToUTF8(field.name) << " " - << UTF16ToUTF8(field.value()) + << UTF16ToUTF8(field.value) << " " - << UTF16ToUTF8(field.form_control_type()) + << UTF16ToUTF8(field.form_control_type) << " " - << field.max_length(); + << field.max_length; } } // namespace webkit_glue diff --git a/Source/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.h b/Source/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.h index c5e3ecc..9379c09 100644 --- a/Source/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.h +++ b/Source/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.h @@ -48,23 +48,17 @@ public: FormField(const string16& label, const string16& name, const string16& value, const string16& form_control_type, int max_length, bool is_autofilled); virtual ~FormField(); - const string16& label() const { return label_; } - const string16& name() const { return name_; } - const string16& value() const { return value_; } - const string16& form_control_type() const { return form_control_type_; } - int max_length() const { return max_length_; } - bool is_autofilled() const { return is_autofilled_; } + string16 label; + string16 name; + string16 value; + string16 form_control_type; + int max_length; + bool is_autofilled; // Returns option string for elements for which they make sense (select-one, // for example) for the rest of elements return an empty array. const std::vector<string16>& option_strings() const { return option_strings_; } - void set_label(const string16& label) { label_ = label; } - void set_name(const string16& name) { name_ = name; } - void set_value(const string16& value) { value_ = value; } - void set_form_control_type(const string16& form_control_type) { form_control_type_ = form_control_type; } - void set_max_length(int max_length) { max_length_ = max_length; } - void set_autofilled(bool is_autofilled) { is_autofilled_ = is_autofilled; } void set_option_strings(const std::vector<string16>& strings) { option_strings_ = strings; } // Equality tests for identity which does not include |value_| or |size_|. @@ -79,12 +73,6 @@ public: bool StrictlyEqualsHack(const FormField& field) const; private: - string16 label_; - string16 name_; - string16 value_; - string16 form_control_type_; - int max_length_; - bool is_autofilled_; std::vector<string16> option_strings_; }; diff --git a/Source/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.cpp b/Source/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.cpp index 9652794..44a8c34 100644 --- a/Source/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.cpp +++ b/Source/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.cpp @@ -310,8 +310,8 @@ void FormManager::HTMLFormControlElementToFormField(HTMLFormControlElement* elem // The label is not officially part of a HTMLFormControlElement; however, the // labels for all form control elements are scraped from the DOM and set in // WebFormElementToFormData. - field->set_name(nameForAutoFill(*element)); - field->set_form_control_type(formControlType(*element)); + field->name = nameForAutoFill(*element); + field->form_control_type = formControlType(*element); if (extract_mask & EXTRACT_OPTIONS) { std::vector<string16> option_strings; @@ -321,8 +321,8 @@ void FormManager::HTMLFormControlElementToFormField(HTMLFormControlElement* elem if (formControlType(*element) == kText) { HTMLInputElement* input_element = static_cast<HTMLInputElement*>(element); - field->set_max_length(input_element->maxLength()); - field->set_autofilled(input_element->isAutofilled()); + field->max_length = input_element->maxLength(); + field->is_autofilled = input_element->isAutofilled(); } if (!(extract_mask & EXTRACT_VALUE)) @@ -359,7 +359,7 @@ void FormManager::HTMLFormControlElementToFormField(HTMLFormControlElement* elem if (value.size() > kMaxDataLength) value = value.substr(0, kMaxDataLength); - field->set_value(value); + field->value = value; } // static @@ -442,7 +442,7 @@ bool FormManager::HTMLFormElementToFormData(HTMLFormElement* element, Requiremen // TODO: A label element is mapped to a form control element's id. // field->name() will contain the id only if the name does not exist. Add // an id() method to HTMLFormControlElement and use that here. - name_map[field->name()] = field; + name_map[field->name] = field; fields_extracted[i] = true; } @@ -465,7 +465,7 @@ bool FormManager::HTMLFormElementToFormData(HTMLFormElement* element, Requiremen std::map<string16, FormField*>::iterator iter = name_map.find(nameForAutoFill(*field_element)); if (iter != name_map.end()) - iter->second->set_label(FindChildText(label)); + iter->second->label = FindChildText(label); } // Loop through the form control elements, extracting the label text from the @@ -482,8 +482,8 @@ bool FormManager::HTMLFormElementToFormData(HTMLFormElement* element, Requiremen continue; const HTMLFormControlElement* control_element = static_cast<HTMLFormControlElement*>(control_elements[i]); - if (form_fields[field_idx]->label().empty()) - form_fields[field_idx]->set_label(FormManager::InferLabelForElement(*control_element)); + if (form_fields[field_idx]->label.empty()) + form_fields[field_idx]->label = FormManager::InferLabelForElement(*control_element); ++field_idx; @@ -786,13 +786,13 @@ void FormManager::ForEachMatchingFormField(FormElement* form, Node* node, Requir // Search forward in the |form| for a corresponding field. size_t k = j; - while (k < data.fields.size() && element_name != data.fields[k].name()) + while (k < data.fields.size() && element_name != data.fields[k].name) k++; if (k >= data.fields.size()) continue; - DCHECK_EQ(data.fields[k].name(), element_name); + DCHECK_EQ(data.fields[k].name, element_name); bool is_initiating_node = false; @@ -829,7 +829,7 @@ void FormManager::ForEachMatchingFormField(FormElement* form, Node* node, Requir void FormManager::FillFormField(HTMLFormControlElement* field, const FormField* data, bool is_initiating_node) { // Nothing to fill. - if (data->value().empty()) + if (data->value.empty()) return; if (formControlType(*field) == kText) { @@ -837,7 +837,7 @@ void FormManager::FillFormField(HTMLFormControlElement* field, const FormField* // If the maxlength attribute contains a negative value, maxLength() // returns the default maxlength value. - input_element->setValue(data->value().substr(0, input_element->maxLength()).c_str()); + input_element->setValue(data->value.substr(0, input_element->maxLength()).c_str()); input_element->setAutofilled(true); if (is_initiating_node) { int length = input_element->value().length(); @@ -845,13 +845,13 @@ void FormManager::FillFormField(HTMLFormControlElement* field, const FormField* } } else if (formControlType(*field) == kSelectOne) { HTMLSelectElement* select_element = static_cast<HTMLSelectElement*>(field); - select_element->setValue(data->value().c_str()); + select_element->setValue(data->value.c_str()); } } void FormManager::PreviewFormField(HTMLFormControlElement* field, const FormField* data, bool is_initiating_node) { // Nothing to preview. - if (data->value().empty()) + if (data->value.empty()) return; // Only preview input fields. @@ -862,7 +862,7 @@ void FormManager::PreviewFormField(HTMLFormControlElement* field, const FormFiel // If the maxlength attribute contains a negative value, maxLength() // returns the default maxlength value. - input_element->setSuggestedValue(data->value().substr(0, input_element->maxLength()).c_str()); + input_element->setSuggestedValue(data->value.substr(0, input_element->maxLength()).c_str()); input_element->setAutofilled(true); if (is_initiating_node) input_element->setSelectionRange(0, input_element->suggestedValue().length()); diff --git a/Source/WebKit/android/WebCoreSupport/autofill/WebAutofill.cpp b/Source/WebKit/android/WebCoreSupport/autofill/WebAutofill.cpp index 51d2d44..7ab7abd 100644 --- a/Source/WebKit/android/WebCoreSupport/autofill/WebAutofill.cpp +++ b/Source/WebKit/android/WebCoreSupport/autofill/WebAutofill.cpp @@ -160,7 +160,7 @@ void WebAutofill::formFieldFocused(WebCore::HTMLFormControlElement* formFieldEle // Get the FormField from the Node. webkit_glue::FormField* formField = new webkit_glue::FormField; FormManager::HTMLFormControlElementToFormField(formFieldElement, FormManager::EXTRACT_NONE, formField); - formField->set_label(FormManager::LabelForElement(*formFieldElement)); + formField->label = FormManager::LabelForElement(*formFieldElement); webkit_glue::FormData* form = new webkit_glue::FormData; mFormManager->FindFormWithFormControlElement(formFieldElement, FormManager::REQUIRE_AUTOCOMPLETE, form); |