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

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: Incorporated Vaclav's review comments. Created 5 years, 5 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_regexes.h" 17 #include "components/autofill/core/common/autofill_regexes.h"
18 #include "components/autofill/core/common/autofill_switches.h" 18 #include "components/autofill/core/common/autofill_switches.h"
19 #include "components/autofill/core/common/autofill_util.h"
19 #include "components/autofill/core/common/form_data.h" 20 #include "components/autofill/core/common/form_data.h"
20 #include "components/autofill/core/common/form_field_data.h" 21 #include "components/autofill/core/common/form_field_data.h"
21 #include "third_party/WebKit/public/platform/WebString.h" 22 #include "third_party/WebKit/public/platform/WebString.h"
22 #include "third_party/WebKit/public/platform/WebVector.h" 23 #include "third_party/WebKit/public/platform/WebVector.h"
23 #include "third_party/WebKit/public/web/WebDocument.h" 24 #include "third_party/WebKit/public/web/WebDocument.h"
24 #include "third_party/WebKit/public/web/WebElement.h" 25 #include "third_party/WebKit/public/web/WebElement.h"
25 #include "third_party/WebKit/public/web/WebElementCollection.h" 26 #include "third_party/WebKit/public/web/WebElementCollection.h"
26 #include "third_party/WebKit/public/web/WebFormControlElement.h" 27 #include "third_party/WebKit/public/web/WebFormControlElement.h"
27 #include "third_party/WebKit/public/web/WebFormElement.h" 28 #include "third_party/WebKit/public/web/WebFormElement.h"
28 #include "third_party/WebKit/public/web/WebInputElement.h" 29 #include "third_party/WebKit/public/web/WebInputElement.h"
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 data.value.substr(0, input_element->maxLength())); 865 data.value.substr(0, input_element->maxLength()));
865 input_element->setAutofilled(true); 866 input_element->setAutofilled(true);
866 } else if (IsTextAreaElement(*field) || IsSelectElement(*field)) { 867 } else if (IsTextAreaElement(*field) || IsSelectElement(*field)) {
867 field->setSuggestedValue(data.value); 868 field->setSuggestedValue(data.value);
868 field->setAutofilled(true); 869 field->setAutofilled(true);
869 } 870 }
870 871
871 if (is_initiating_node && 872 if (is_initiating_node &&
872 (IsTextInput(input_element) || IsTextAreaElement(*field))) { 873 (IsTextInput(input_element) || IsTextAreaElement(*field))) {
873 // Select the part of the text that the user didn't type. 874 // Select the part of the text that the user didn't type.
874 int start = field->value().length(); 875 PreviewSuggestion(field->suggestedValue(), field->value(), field);
875 int end = field->suggestedValue().length();
876 field->setSelectionRange(start, end);
877 } 876 }
878 } 877 }
879 878
880 // Recursively checks whether |node| or any of its children have a non-empty 879 // Recursively checks whether |node| or any of its children have a non-empty
881 // bounding box. The recursion depth is bounded by |depth|. 880 // bounding box. The recursion depth is bounded by |depth|.
882 bool IsWebNodeVisibleImpl(const blink::WebNode& node, const int depth) { 881 bool IsWebNodeVisibleImpl(const blink::WebNode& node, const int depth) {
883 if (depth < 0) 882 if (depth < 0)
884 return false; 883 return false;
885 if (node.hasNonEmptyBoundingBox()) 884 if (node.hasNonEmptyBoundingBox())
886 return true; 885 return true;
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 } 1526 }
1528 1527
1529 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) { 1528 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) {
1530 gfx::Rect bounding_box(element->boundsInViewportSpace()); 1529 gfx::Rect bounding_box(element->boundsInViewportSpace());
1531 return gfx::RectF(bounding_box.x() * scale, 1530 return gfx::RectF(bounding_box.x() * scale,
1532 bounding_box.y() * scale, 1531 bounding_box.y() * scale,
1533 bounding_box.width() * scale, 1532 bounding_box.width() * scale,
1534 bounding_box.height() * scale); 1533 bounding_box.height() * scale);
1535 } 1534 }
1536 1535
1536 void PreviewSuggestion(const base::string16& suggestion,
1537 const base::string16& user_input,
1538 blink::WebFormControlElement* input_element) {
1539 size_t selection_start = user_input.length();
1540 if (IsFeatureSubstringMatchEnabled()) {
1541 size_t offset =
1542 autofill::GetTextSelectionStart(suggestion, user_input, false);
1543 // Zero selection start is for password manager, which can show usernames
1544 // that do not begin with the user input value.
1545 selection_start = (offset == base::string16::npos) ? 0 : offset;
1546 }
1547
1548 input_element->setSelectionRange(selection_start, suggestion.length());
1549 }
1550
1537 } // namespace autofill 1551 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698