Chromium Code Reviews| 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 "chrome/browser/autocomplete/autocomplete_edit.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/string_util.h" | |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/app/chrome_dll_resource.h" | 12 #include "chrome/app/chrome_dll_resource.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 13 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 14 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 15 #include "chrome/browser/autocomplete/keyword_provider.h" | 16 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 16 #include "chrome/browser/command_updater.h" | 17 #include "chrome/browser/command_updater.h" |
| 17 #include "chrome/browser/metrics/user_metrics.h" | 18 #include "chrome/browser/metrics/user_metrics.h" |
| 18 #include "chrome/browser/net/dns_global.h" | 19 #include "chrome/browser/net/dns_global.h" |
| 19 #include "chrome/browser/net/url_fixer_upper.h" | 20 #include "chrome/browser/net/url_fixer_upper.h" |
| 20 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 21 #include "chrome/browser/search_engines/template_url.h" | 22 #include "chrome/browser/search_engines/template_url.h" |
| 22 #include "chrome/browser/search_engines/template_url_model.h" | 23 #include "chrome/browser/search_engines/template_url_model.h" |
| 23 #include "chrome/common/notification_service.h" | 24 #include "chrome/common/notification_service.h" |
| 25 #include "chrome/common/url_constants.h" | |
| 24 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 25 #include "googleurl/src/url_util.h" | 27 #include "googleurl/src/url_util.h" |
| 26 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
| 27 | 29 |
| 28 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
| 29 // AutocompleteEditModel | 31 // AutocompleteEditModel |
| 30 | 32 |
| 31 AutocompleteEditModel::AutocompleteEditModel( | 33 AutocompleteEditModel::AutocompleteEditModel( |
| 32 AutocompleteEditView* view, | 34 AutocompleteEditView* view, |
| 33 AutocompleteEditController* controller, | 35 AutocompleteEditController* controller, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 url_parse::Parsed parts; | 160 url_parse::Parsed parts; |
| 159 const AutocompleteInput::Type type = AutocompleteInput::Parse( | 161 const AutocompleteInput::Type type = AutocompleteInput::Parse( |
| 160 UserTextFromDisplayText(text), std::wstring(), &parts, NULL); | 162 UserTextFromDisplayText(text), std::wstring(), &parts, NULL); |
| 161 if (type != AutocompleteInput::URL) | 163 if (type != AutocompleteInput::URL) |
| 162 return false; | 164 return false; |
| 163 | 165 |
| 164 *url = GURL(URLFixerUpper::FixupURL(WideToUTF8(text), std::string())); | 166 *url = GURL(URLFixerUpper::FixupURL(WideToUTF8(text), std::string())); |
| 165 return true; | 167 return true; |
| 166 } | 168 } |
| 167 | 169 |
| 170 void AutocompleteEditModel::AdjustTextForCopy(int sel_start, | |
| 171 bool is_all_selected, | |
| 172 std::wstring* text, | |
| 173 GURL* url, | |
| 174 bool* write_url) { | |
| 175 *write_url = false; | |
| 176 | |
| 177 if (sel_start != 0) | |
| 178 return; | |
| 179 | |
| 180 // We can't use CurrentTextIsURL() or GetDataForURLExport() because right now | |
| 181 // the user is probably holding down control to cause the copy, which will | |
| 182 // screw up our calculation of the desired_tld. | |
| 183 if (!GetURLForText(*text, url)) | |
| 184 return; // Can't be parsed as a url, no need to adjust text. | |
| 185 | |
| 186 if (!user_input_in_progress() && is_all_selected) { | |
|
Evan Stade
2010/04/26 23:52:33
comment here about no unescaping? otherwise this c
| |
| 187 *text = UTF8ToWide(url->spec()); | |
| 188 *write_url = true; | |
| 189 return; | |
| 190 } | |
| 191 | |
| 192 // Prefix the text with 'http://' if the text doesn't start with 'http://', | |
| 193 // the text parses as a url with a scheme of http, the user selected the | |
| 194 // entire host, and the user hasn't edited the host or manually removed the | |
| 195 // scheme. | |
| 196 if (url->SchemeIs(chrome::kHttpScheme)) { | |
| 197 std::wstring http = ASCIIToWide(chrome::kHttpScheme) + | |
| 198 ASCIIToWide(chrome::kStandardSchemeSeparator); | |
| 199 std::wstring host = UTF8ToWide(url->host()); | |
| 200 if (text->compare(0, http.length(), http) != 0 && | |
| 201 text->length() >= host.length() && | |
| 202 permanent_text_.compare(0, host.length(), host) == 0) { | |
| 203 *text = http + *text; | |
| 204 *write_url = true; | |
| 205 } | |
| 206 } | |
| 207 } | |
| 208 | |
| 168 void AutocompleteEditModel::SetInputInProgress(bool in_progress) { | 209 void AutocompleteEditModel::SetInputInProgress(bool in_progress) { |
| 169 if (user_input_in_progress_ == in_progress) | 210 if (user_input_in_progress_ == in_progress) |
| 170 return; | 211 return; |
| 171 | 212 |
| 172 user_input_in_progress_ = in_progress; | 213 user_input_in_progress_ = in_progress; |
| 173 controller_->OnInputInProgress(in_progress); | 214 controller_->OnInputInProgress(in_progress); |
| 174 } | 215 } |
| 175 | 216 |
| 176 void AutocompleteEditModel::Revert() { | 217 void AutocompleteEditModel::Revert() { |
| 177 SetInputInProgress(false); | 218 SetInputInProgress(false); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 AutocompleteMatch* match, | 619 AutocompleteMatch* match, |
| 579 GURL* alternate_nav_url) const { | 620 GURL* alternate_nav_url) const { |
| 580 if (popup_->IsOpen() || query_in_progress()) { | 621 if (popup_->IsOpen() || query_in_progress()) { |
| 581 popup_->InfoForCurrentSelection(match, alternate_nav_url); | 622 popup_->InfoForCurrentSelection(match, alternate_nav_url); |
| 582 } else { | 623 } else { |
| 583 profile_->GetAutocompleteClassifier()->Classify( | 624 profile_->GetAutocompleteClassifier()->Classify( |
| 584 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), match, | 625 UserTextFromDisplayText(view_->GetText()), GetDesiredTLD(), match, |
| 585 alternate_nav_url); | 626 alternate_nav_url); |
| 586 } | 627 } |
| 587 } | 628 } |
| OLD | NEW |