| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/autocomplete_input.h" | 5 #include "chrome/browser/autocomplete/autocomplete_input.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 "chrome/browser/external_protocol/external_protocol_handler.h" | 9 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
| 10 #include "chrome/browser/net/url_fixer_upper.h" | 10 #include "chrome/browser/net/url_fixer_upper.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 bool prevent_inline_autocomplete, | 43 bool prevent_inline_autocomplete, |
| 44 bool prefer_keyword, | 44 bool prefer_keyword, |
| 45 bool allow_exact_keyword_match, | 45 bool allow_exact_keyword_match, |
| 46 MatchesRequested matches_requested) | 46 MatchesRequested matches_requested) |
| 47 : cursor_position_(cursor_position), | 47 : cursor_position_(cursor_position), |
| 48 desired_tld_(desired_tld), | 48 desired_tld_(desired_tld), |
| 49 prevent_inline_autocomplete_(prevent_inline_autocomplete), | 49 prevent_inline_autocomplete_(prevent_inline_autocomplete), |
| 50 prefer_keyword_(prefer_keyword), | 50 prefer_keyword_(prefer_keyword), |
| 51 allow_exact_keyword_match_(allow_exact_keyword_match), | 51 allow_exact_keyword_match_(allow_exact_keyword_match), |
| 52 matches_requested_(matches_requested) { | 52 matches_requested_(matches_requested) { |
| 53 DCHECK(cursor_position <= text.length() || cursor_position == string16::npos); | 53 DCHECK(cursor_position <= text.length() || cursor_position == string16::npos) |
| 54 << "Text: '" << text << "', cp: " << cursor_position; |
| 54 // None of the providers care about leading white space so we always trim it. | 55 // None of the providers care about leading white space so we always trim it. |
| 55 // Providers that care about trailing white space handle trimming themselves. | 56 // Providers that care about trailing white space handle trimming themselves. |
| 56 if ((TrimWhitespace(text, TRIM_LEADING, &text_) & TRIM_LEADING) != 0) | 57 if ((TrimWhitespace(text, TRIM_LEADING, &text_) & TRIM_LEADING) != 0) |
| 57 AdjustCursorPositionIfNecessary(text.length() - text_.length(), | 58 AdjustCursorPositionIfNecessary(text.length() - text_.length(), |
| 58 &cursor_position_); | 59 &cursor_position_); |
| 59 | 60 |
| 60 GURL canonicalized_url; | 61 GURL canonicalized_url; |
| 61 type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url); | 62 type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url); |
| 62 | 63 |
| 63 if (type_ == INVALID) | 64 if (type_ == INVALID) |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 if (parts.query.is_nonempty()) | 486 if (parts.query.is_nonempty()) |
| 486 ++num_nonhost_components; | 487 ++num_nonhost_components; |
| 487 if (parts.ref.is_nonempty()) | 488 if (parts.ref.is_nonempty()) |
| 488 ++num_nonhost_components; | 489 ++num_nonhost_components; |
| 489 return num_nonhost_components; | 490 return num_nonhost_components; |
| 490 } | 491 } |
| 491 | 492 |
| 492 void AutocompleteInput::UpdateText(const string16& text, | 493 void AutocompleteInput::UpdateText(const string16& text, |
| 493 size_t cursor_position, | 494 size_t cursor_position, |
| 494 const url_parse::Parsed& parts) { | 495 const url_parse::Parsed& parts) { |
| 495 DCHECK(cursor_position <= text.length() || cursor_position == string16::npos); | 496 DCHECK(cursor_position <= text.length() || cursor_position == string16::npos) |
| 497 << "Text: '" << text << "', cp: " << cursor_position; |
| 496 text_ = text; | 498 text_ = text; |
| 497 cursor_position_ = cursor_position; | 499 cursor_position_ = cursor_position; |
| 498 parts_ = parts; | 500 parts_ = parts; |
| 499 } | 501 } |
| 500 | 502 |
| 501 bool AutocompleteInput::Equals(const AutocompleteInput& other) const { | |
| 502 return (text_ == other.text_) && | |
| 503 (cursor_position_ == other.cursor_position_) && | |
| 504 (type_ == other.type_) && | |
| 505 (desired_tld_ == other.desired_tld_) && | |
| 506 (scheme_ == other.scheme_) && | |
| 507 (prevent_inline_autocomplete_ == other.prevent_inline_autocomplete_) && | |
| 508 (prefer_keyword_ == other.prefer_keyword_) && | |
| 509 (matches_requested_ == other.matches_requested_); | |
| 510 } | |
| 511 | |
| 512 void AutocompleteInput::Clear() { | 503 void AutocompleteInput::Clear() { |
| 513 text_.clear(); | 504 text_.clear(); |
| 514 cursor_position_ = string16::npos; | 505 cursor_position_ = string16::npos; |
| 506 desired_tld_.clear(); |
| 515 type_ = INVALID; | 507 type_ = INVALID; |
| 516 parts_ = url_parse::Parsed(); | 508 parts_ = url_parse::Parsed(); |
| 517 scheme_.clear(); | 509 scheme_.clear(); |
| 518 desired_tld_.clear(); | 510 canonicalized_url_ = GURL(); |
| 519 prevent_inline_autocomplete_ = false; | 511 prevent_inline_autocomplete_ = false; |
| 520 prefer_keyword_ = false; | 512 prefer_keyword_ = false; |
| 513 allow_exact_keyword_match_ = false; |
| 514 matches_requested_ = ALL_MATCHES; |
| 521 } | 515 } |
| OLD | NEW |