OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/form_field.h" | 5 #include "webkit/glue/form_field.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebOptionElement.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebSelectElement.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebSelectElement.h" |
11 | 12 |
12 using WebKit::WebFormControlElement; | 13 using WebKit::WebFormControlElement; |
| 14 using WebKit::WebElement; |
13 using WebKit::WebInputElement; | 15 using WebKit::WebInputElement; |
| 16 using WebKit::WebOptionElement; |
14 using WebKit::WebSelectElement; | 17 using WebKit::WebSelectElement; |
| 18 using WebKit::WebVector; |
15 | 19 |
16 namespace webkit_glue { | 20 namespace webkit_glue { |
17 | 21 |
18 FormField::FormField() | 22 FormField::FormField() |
19 : size_(0) { | 23 : size_(0) { |
20 } | 24 } |
21 | 25 |
22 // TODO(jhawkins): This constructor should probably be deprecated and the | 26 // TODO(jhawkins): This constructor should probably be deprecated and the |
23 // functionality moved to FormManager. | 27 // functionality moved to FormManager. |
24 FormField::FormField(WebFormControlElement element) | 28 FormField::FormField(WebFormControlElement element) |
25 : size_(0) { | 29 : size_(0) { |
26 name_ = element.nameForAutofill(); | 30 name_ = element.nameForAutofill(); |
27 | 31 |
28 // TODO(jhawkins): Extract the field label. For now we just use the field | 32 // TODO(jhawkins): Extract the field label. For now we just use the field |
29 // name. | 33 // name. |
30 label_ = name_; | 34 label_ = name_; |
31 | 35 |
32 form_control_type_ = element.formControlType(); | 36 form_control_type_ = element.formControlType(); |
33 if (form_control_type_ == ASCIIToUTF16("text")) { | 37 if (form_control_type_ == ASCIIToUTF16("text")) { |
34 const WebInputElement& input_element = element.toConst<WebInputElement>(); | 38 const WebInputElement& input_element = element.toConst<WebInputElement>(); |
35 value_ = input_element.value(); | 39 value_ = input_element.value(); |
36 size_ = input_element.size(); | 40 size_ = input_element.size(); |
37 } else if (form_control_type_ == ASCIIToUTF16("select-one")) { | 41 } else if (form_control_type_ == ASCIIToUTF16("select-one")) { |
38 WebSelectElement select_element = element.to<WebSelectElement>(); | 42 WebSelectElement select_element = element.to<WebSelectElement>(); |
39 value_ = select_element.value(); | 43 value_ = select_element.value(); |
| 44 |
| 45 // For select-one elements copy option strings. |
| 46 WebVector<WebElement> list_items = select_element.listItems(); |
| 47 option_strings_.reserve(list_items.size()); |
| 48 for (size_t i = 0; i < list_items.size(); ++i) { |
| 49 if (list_items[i].hasTagName("option")) |
| 50 option_strings_.push_back(list_items[i].to<WebOptionElement>().value()); |
| 51 } |
40 } | 52 } |
41 | 53 |
42 TrimWhitespace(value_, TRIM_LEADING, &value_); | 54 TrimWhitespace(value_, TRIM_LEADING, &value_); |
43 } | 55 } |
44 | 56 |
45 FormField::FormField(const string16& label, | 57 FormField::FormField(const string16& label, |
46 const string16& name, | 58 const string16& name, |
47 const string16& value, | 59 const string16& value, |
48 const string16& form_control_type, | 60 const string16& form_control_type, |
49 int size) | 61 int size) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 << UTF16ToUTF8(field.name()) | 94 << UTF16ToUTF8(field.name()) |
83 << " " | 95 << " " |
84 << UTF16ToUTF8(field.value()) | 96 << UTF16ToUTF8(field.value()) |
85 << " " | 97 << " " |
86 << UTF16ToUTF8(field.form_control_type()) | 98 << UTF16ToUTF8(field.form_control_type()) |
87 << " " | 99 << " " |
88 << field.size(); | 100 << field.size(); |
89 } | 101 } |
90 | 102 |
91 } // namespace webkit_glue | 103 } // namespace webkit_glue |
OLD | NEW |