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

Side by Side Diff: components/autofill/content/renderer/form_autofill_util.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses review comments. Created 5 years, 8 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
OLDNEW
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 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 data.value.substr(0, input_element->maxLength())); 876 data.value.substr(0, input_element->maxLength()));
876 input_element->setAutofilled(true); 877 input_element->setAutofilled(true);
877 } else if (IsTextAreaElement(*field) || IsSelectElement(*field)) { 878 } else if (IsTextAreaElement(*field) || IsSelectElement(*field)) {
878 field->setSuggestedValue(data.value); 879 field->setSuggestedValue(data.value);
879 field->setAutofilled(true); 880 field->setAutofilled(true);
880 } 881 }
881 882
882 if (is_initiating_node && 883 if (is_initiating_node &&
883 (IsTextInput(input_element) || IsTextAreaElement(*field))) { 884 (IsTextInput(input_element) || IsTextAreaElement(*field))) {
884 // Select the part of the text that the user didn't type. 885 // Select the part of the text that the user didn't type.
885 int start = field->value().length(); 886 if (IsFeatureSubstringMatchEnabled()) {
886 int end = field->suggestedValue().length(); 887 size_t start = 0;
887 field->setSelectionRange(start, end); 888 size_t end = 0;
889 if (base::string16::npos !=
890 autofill::ComputeRange(field->suggestedValue(), field->value(),
Evan Stade 2015/03/31 21:41:52 can you use StartsAt directly
Pritam Nikam 2015/04/01 09:10:37 StartsAt() is not equipped handle all complected c
891 &start, &end)) {
892 field->setSelectionRange(start, end);
893 }
894 } else {
895 field->setSelectionRange(field->value().length(),
896 field->suggestedValue().length());
897 }
888 } 898 }
889 } 899 }
890 900
891 // Recursively checks whether |node| or any of its children have a non-empty 901 // Recursively checks whether |node| or any of its children have a non-empty
892 // bounding box. The recursion depth is bounded by |depth|. 902 // bounding box. The recursion depth is bounded by |depth|.
893 bool IsWebNodeVisibleImpl(const blink::WebNode& node, const int depth) { 903 bool IsWebNodeVisibleImpl(const blink::WebNode& node, const int depth) {
894 if (depth < 0) 904 if (depth < 0)
895 return false; 905 return false;
896 if (node.hasNonEmptyBoundingBox()) 906 if (node.hasNonEmptyBoundingBox())
897 return true; 907 return true;
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 1550
1541 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) { 1551 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) {
1542 gfx::Rect bounding_box(element->boundsInViewportSpace()); 1552 gfx::Rect bounding_box(element->boundsInViewportSpace());
1543 return gfx::RectF(bounding_box.x() * scale, 1553 return gfx::RectF(bounding_box.x() * scale,
1544 bounding_box.y() * scale, 1554 bounding_box.y() * scale,
1545 bounding_box.width() * scale, 1555 bounding_box.width() * scale,
1546 bounding_box.height() * scale); 1556 bounding_box.height() * scale);
1547 } 1557 }
1548 1558
1549 } // namespace autofill 1559 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698