OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/renderer/form_autofill_util.h" | 5 #include "components/autofill/content/renderer/form_autofill_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "components/autofill/core/common/autofill_data_validation.h" | 16 #include "components/autofill/core/common/autofill_data_validation.h" |
17 #include "components/autofill/core/common/autofill_switches.h" | 17 #include "components/autofill/core/common/autofill_switches.h" |
| 18 #include "components/autofill/core/common/autofill_util.h" |
18 #include "components/autofill/core/common/form_data.h" | 19 #include "components/autofill/core/common/form_data.h" |
19 #include "components/autofill/core/common/form_field_data.h" | 20 #include "components/autofill/core/common/form_field_data.h" |
20 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
21 #include "third_party/WebKit/public/platform/WebVector.h" | 22 #include "third_party/WebKit/public/platform/WebVector.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebElement.h" | 24 #include "third_party/WebKit/public/web/WebElement.h" |
24 #include "third_party/WebKit/public/web/WebElementCollection.h" | 25 #include "third_party/WebKit/public/web/WebElementCollection.h" |
25 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 26 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
26 #include "third_party/WebKit/public/web/WebFormElement.h" | 27 #include "third_party/WebKit/public/web/WebFormElement.h" |
27 #include "third_party/WebKit/public/web/WebInputElement.h" | 28 #include "third_party/WebKit/public/web/WebInputElement.h" |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 data.value.substr(0, input_element->maxLength())); | 864 data.value.substr(0, input_element->maxLength())); |
864 input_element->setAutofilled(true); | 865 input_element->setAutofilled(true); |
865 } else if (IsTextAreaElement(*field) || IsSelectElement(*field)) { | 866 } else if (IsTextAreaElement(*field) || IsSelectElement(*field)) { |
866 field->setSuggestedValue(data.value); | 867 field->setSuggestedValue(data.value); |
867 field->setAutofilled(true); | 868 field->setAutofilled(true); |
868 } | 869 } |
869 | 870 |
870 if (is_initiating_node && | 871 if (is_initiating_node && |
871 (IsTextInput(input_element) || IsTextAreaElement(*field))) { | 872 (IsTextInput(input_element) || IsTextAreaElement(*field))) { |
872 // Select the part of the text that the user didn't type. | 873 // Select the part of the text that the user didn't type. |
873 int start = field->value().length(); | 874 if (IsFeatureSubstringMatchEnabled()) { |
874 int end = field->suggestedValue().length(); | 875 size_t start = 0; |
875 field->setSelectionRange(start, end); | 876 size_t end = 0; |
| 877 if (base::string16::npos != |
| 878 autofill::ComputeRange(field->suggestedValue(), field->value(), |
| 879 &start, &end)) { |
| 880 field->setSelectionRange(start, end); |
| 881 } |
| 882 } else { |
| 883 field->setSelectionRange(field->value().length(), |
| 884 field->suggestedValue().length()); |
| 885 } |
876 } | 886 } |
877 } | 887 } |
878 | 888 |
879 // Recursively checks whether |node| or any of its children have a non-empty | 889 // Recursively checks whether |node| or any of its children have a non-empty |
880 // bounding box. The recursion depth is bounded by |depth|. | 890 // bounding box. The recursion depth is bounded by |depth|. |
881 bool IsWebNodeVisibleImpl(const blink::WebNode& node, const int depth) { | 891 bool IsWebNodeVisibleImpl(const blink::WebNode& node, const int depth) { |
882 if (depth < 0) | 892 if (depth < 0) |
883 return false; | 893 return false; |
884 if (node.hasNonEmptyBoundingBox()) | 894 if (node.hasNonEmptyBoundingBox()) |
885 return true; | 895 return true; |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 | 1508 |
1499 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) { | 1509 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) { |
1500 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1510 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
1501 return gfx::RectF(bounding_box.x() * scale, | 1511 return gfx::RectF(bounding_box.x() * scale, |
1502 bounding_box.y() * scale, | 1512 bounding_box.y() * scale, |
1503 bounding_box.width() * scale, | 1513 bounding_box.width() * scale, |
1504 bounding_box.height() * scale); | 1514 bounding_box.height() * scale); |
1505 } | 1515 } |
1506 | 1516 |
1507 } // namespace autofill | 1517 } // namespace autofill |
OLD | NEW |