OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | |
10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
15 #include "chrome/browser/autocomplete/autocomplete_match.h" | 16 #include "chrome/browser/autocomplete/autocomplete_match.h" |
16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
17 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" | 18 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" |
18 #include "chrome/browser/autocomplete/keyword_provider.h" | 19 #include "chrome/browser/autocomplete/keyword_provider.h" |
19 #include "chrome/browser/autocomplete/search_provider.h" | 20 #include "chrome/browser/autocomplete/search_provider.h" |
20 #include "chrome/browser/command_updater.h" | 21 #include "chrome/browser/command_updater.h" |
21 #include "chrome/browser/extensions/extension_omnibox_api.h" | 22 #include "chrome/browser/extensions/extension_omnibox_api.h" |
22 #include "chrome/browser/google/google_url_tracker.h" | 23 #include "chrome/browser/google/google_url_tracker.h" |
23 #include "chrome/browser/instant/instant_controller.h" | 24 #include "chrome/browser/instant/instant_controller.h" |
24 #include "chrome/browser/net/predictor_api.h" | 25 #include "chrome/browser/net/predictor_api.h" |
25 #include "chrome/browser/net/url_fixer_upper.h" | 26 #include "chrome/browser/net/url_fixer_upper.h" |
27 #include "chrome/browser/prerender/prerender_manager.h" | |
26 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/search_engines/template_url.h" | 29 #include "chrome/browser/search_engines/template_url.h" |
28 #include "chrome/browser/search_engines/template_url_service.h" | 30 #include "chrome/browser/search_engines/template_url_service.h" |
29 #include "chrome/browser/search_engines/template_url_service_factory.h" | 31 #include "chrome/browser/search_engines/template_url_service_factory.h" |
30 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_list.h" |
31 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 33 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 34 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
35 #include "chrome/common/chrome_switches.h" | |
33 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
34 #include "content/browser/user_metrics.h" | 37 #include "content/browser/user_metrics.h" |
35 #include "content/common/notification_service.h" | 38 #include "content/common/notification_service.h" |
36 #include "googleurl/src/gurl.h" | 39 #include "googleurl/src/gurl.h" |
37 #include "googleurl/src/url_util.h" | 40 #include "googleurl/src/url_util.h" |
38 #include "third_party/skia/include/core/SkBitmap.h" | 41 #include "third_party/skia/include/core/SkBitmap.h" |
39 | 42 |
40 /////////////////////////////////////////////////////////////////////////////// | 43 /////////////////////////////////////////////////////////////////////////////// |
41 // AutocompleteEditController | 44 // AutocompleteEditController |
42 | 45 |
(...skipping 29 matching lines...) Expand all Loading... | |
72 popup_(NULL), | 75 popup_(NULL), |
73 controller_(controller), | 76 controller_(controller), |
74 has_focus_(false), | 77 has_focus_(false), |
75 user_input_in_progress_(false), | 78 user_input_in_progress_(false), |
76 just_deleted_text_(false), | 79 just_deleted_text_(false), |
77 has_temporary_text_(false), | 80 has_temporary_text_(false), |
78 paste_state_(NONE), | 81 paste_state_(NONE), |
79 control_key_state_(UP), | 82 control_key_state_(UP), |
80 is_keyword_hint_(false), | 83 is_keyword_hint_(false), |
81 profile_(profile), | 84 profile_(profile), |
82 update_instant_(true), | 85 in_revert_(false), |
83 allow_exact_keyword_match_(false), | 86 allow_exact_keyword_match_(false), |
84 instant_complete_behavior_(INSTANT_COMPLETE_DELAYED) { | 87 instant_complete_behavior_(INSTANT_COMPLETE_DELAYED) { |
85 } | 88 } |
86 | 89 |
87 AutocompleteEditModel::~AutocompleteEditModel() { | 90 AutocompleteEditModel::~AutocompleteEditModel() { |
88 } | 91 } |
89 | 92 |
90 void AutocompleteEditModel::SetProfile(Profile* profile) { | 93 void AutocompleteEditModel::SetProfile(Profile* profile) { |
91 DCHECK(profile); | 94 DCHECK(profile); |
92 profile_ = profile; | 95 profile_ = profile; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 | 209 |
207 bool AutocompleteEditModel::AcceptCurrentInstantPreview() { | 210 bool AutocompleteEditModel::AcceptCurrentInstantPreview() { |
208 return InstantController::CommitIfCurrent(controller_->GetInstant()); | 211 return InstantController::CommitIfCurrent(controller_->GetInstant()); |
209 } | 212 } |
210 | 213 |
211 void AutocompleteEditModel::OnChanged() { | 214 void AutocompleteEditModel::OnChanged() { |
212 InstantController* instant = controller_->GetInstant(); | 215 InstantController* instant = controller_->GetInstant(); |
213 string16 suggested_text; | 216 string16 suggested_text; |
214 TabContentsWrapper* tab = controller_->GetTabContentsWrapper(); | 217 TabContentsWrapper* tab = controller_->GetTabContentsWrapper(); |
215 bool might_support_instant = false; | 218 bool might_support_instant = false; |
216 if (update_instant_ && instant && tab) { | 219 if (!in_revert_ && tab) { |
217 if (user_input_in_progress() && popup_->IsOpen()) { | 220 if (instant) { |
218 AutocompleteMatch current_match = CurrentMatch(); | 221 if (user_input_in_progress() && popup_->IsOpen()) { |
219 if (current_match.destination_url == PermanentURL()) { | 222 AutocompleteMatch current_match = CurrentMatch(); |
220 // The destination is the same as the current url. This typically | 223 if (current_match.destination_url == PermanentURL()) { |
221 // happens if the user presses the down error in the omnibox, in which | 224 // The destination is the same as the current url. This typically |
222 // case we don't want to load a preview. | 225 // happens if the user presses the down error in the omnibox, in which |
223 instant->DestroyPreviewContentsAndLeaveActive(); | 226 // case we don't want to load a preview. |
227 instant->DestroyPreviewContentsAndLeaveActive(); | |
228 } else { | |
229 instant->Update(tab, current_match, view_->GetText(), | |
230 UseVerbatimInstant(), &suggested_text); | |
231 } | |
224 } else { | 232 } else { |
225 instant->Update(tab, CurrentMatch(), view_->GetText(), | 233 instant->DestroyPreviewContents(); |
226 UseVerbatimInstant(), &suggested_text); | |
227 } | 234 } |
228 } else { | 235 might_support_instant = instant->MightSupportInstant(); |
229 instant->DestroyPreviewContents(); | 236 } else if (tab->tab_contents() && user_input_in_progress() && |
sky
2011/06/20 21:11:44
Remove the tab_contents() check, it's always non-n
dominich
2011/06/20 21:55:37
Done.
| |
237 popup_->IsOpen()) { | |
238 // Start Prerender of this page instead. | |
239 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
240 if (cl->HasSwitch(switches::kPrerenderFromOmnibox)) { | |
241 prerender::PrerenderManager* prerender_manager = | |
242 tab->tab_contents()->profile()->GetPrerenderManager(); | |
243 if (prerender_manager) { | |
244 prerender_manager->AddPrerenderWithNoTag( | |
245 CurrentMatch().destination_url); | |
246 } | |
247 } | |
230 } | 248 } |
231 might_support_instant = instant->MightSupportInstant(); | |
232 } | 249 } |
233 | 250 |
234 if (!might_support_instant) { | 251 if (!might_support_instant) { |
235 // Hide any suggestions we might be showing. | 252 // Hide any suggestions we might be showing. |
236 view_->SetInstantSuggestion(string16(), false); | 253 view_->SetInstantSuggestion(string16(), false); |
237 | 254 |
238 // No need to wait any longer for instant. | 255 // No need to wait any longer for instant. |
239 FinalizeInstantQuery(string16(), string16(), false); | 256 FinalizeInstantQuery(string16(), string16(), false); |
240 } else { | 257 } else { |
241 SetSuggestedText(suggested_text, instant_complete_behavior_); | 258 SetSuggestedText(suggested_text, instant_complete_behavior_); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 autocomplete_controller_->Start( | 409 autocomplete_controller_->Start( |
393 user_text_, GetDesiredTLD(), | 410 user_text_, GetDesiredTLD(), |
394 prevent_inline_autocomplete || just_deleted_text_ || | 411 prevent_inline_autocomplete || just_deleted_text_ || |
395 (has_selected_text && inline_autocomplete_text_.empty()) || | 412 (has_selected_text && inline_autocomplete_text_.empty()) || |
396 (paste_state_ != NONE), keyword_is_selected, | 413 (paste_state_ != NONE), keyword_is_selected, |
397 keyword_is_selected || allow_exact_keyword_match_, | 414 keyword_is_selected || allow_exact_keyword_match_, |
398 AutocompleteInput::ALL_MATCHES); | 415 AutocompleteInput::ALL_MATCHES); |
399 } | 416 } |
400 | 417 |
401 void AutocompleteEditModel::StopAutocomplete() { | 418 void AutocompleteEditModel::StopAutocomplete() { |
402 if (popup_->IsOpen() && update_instant_) { | 419 if (popup_->IsOpen() && !in_revert_) { |
403 InstantController* instant = controller_->GetInstant(); | 420 InstantController* instant = controller_->GetInstant(); |
404 if (instant && !instant->commit_on_mouse_up()) | 421 if (instant && !instant->commit_on_mouse_up()) |
405 instant->DestroyPreviewContents(); | 422 instant->DestroyPreviewContents(); |
406 } | 423 } |
407 | 424 |
408 autocomplete_controller_->Stop(true); | 425 autocomplete_controller_->Stop(true); |
409 } | 426 } |
410 | 427 |
411 bool AutocompleteEditModel::CanPasteAndGo(const string16& text) const { | 428 bool AutocompleteEditModel::CanPasteAndGo(const string16& text) const { |
412 if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) | 429 if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 if (template_url) { | 544 if (template_url) { |
528 UserMetrics::RecordAction(UserMetricsAction("AcceptedKeyword")); | 545 UserMetrics::RecordAction(UserMetricsAction("AcceptedKeyword")); |
529 template_url_service->IncrementUsageCount(template_url); | 546 template_url_service->IncrementUsageCount(template_url); |
530 } | 547 } |
531 | 548 |
532 // NOTE: We purposefully don't increment the usage count of the default | 549 // NOTE: We purposefully don't increment the usage count of the default |
533 // search engine, if applicable; see comments in template_url.h. | 550 // search engine, if applicable; see comments in template_url.h. |
534 } | 551 } |
535 | 552 |
536 if (disposition != NEW_BACKGROUND_TAB) { | 553 if (disposition != NEW_BACKGROUND_TAB) { |
537 update_instant_ = false; | 554 in_revert_ = true; |
538 view_->RevertAll(); // Revert the box to its unedited state | 555 view_->RevertAll(); // Revert the box to its unedited state |
539 } | 556 } |
540 | 557 |
541 if (match.type == AutocompleteMatch::EXTENSION_APP) { | 558 if (match.type == AutocompleteMatch::EXTENSION_APP) { |
542 LaunchAppFromOmnibox(match, profile_, disposition); | 559 LaunchAppFromOmnibox(match, profile_, disposition); |
543 } else { | 560 } else { |
544 controller_->OnAutocompleteAccept(match.destination_url, disposition, | 561 controller_->OnAutocompleteAccept(match.destination_url, disposition, |
545 match.transition, alternate_nav_url); | 562 match.transition, alternate_nav_url); |
546 } | 563 } |
547 | 564 |
548 InstantController* instant = controller_->GetInstant(); | 565 InstantController* instant = controller_->GetInstant(); |
549 if (instant && !popup_->IsOpen()) | 566 if (instant && !popup_->IsOpen()) |
550 instant->DestroyPreviewContents(); | 567 instant->DestroyPreviewContents(); |
551 update_instant_ = true; | 568 in_revert_ = false; |
552 } | 569 } |
553 | 570 |
554 bool AutocompleteEditModel::AcceptKeyword() { | 571 bool AutocompleteEditModel::AcceptKeyword() { |
555 DCHECK(is_keyword_hint_ && !keyword_.empty()); | 572 DCHECK(is_keyword_hint_ && !keyword_.empty()); |
556 | 573 |
557 view_->OnBeforePossibleChange(); | 574 view_->OnBeforePossibleChange(); |
558 view_->SetWindowTextAndCaretPos(string16(), 0); | 575 view_->SetWindowTextAndCaretPos(string16(), 0); |
559 is_keyword_hint_ = false; | 576 is_keyword_hint_ = false; |
560 view_->OnAfterPossibleChange(); | 577 view_->OnAfterPossibleChange(); |
561 just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this | 578 just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 // static | 1030 // static |
1014 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1031 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
1015 switch (c) { | 1032 switch (c) { |
1016 case 0x0020: // Space | 1033 case 0x0020: // Space |
1017 case 0x3000: // Ideographic Space | 1034 case 0x3000: // Ideographic Space |
1018 return true; | 1035 return true; |
1019 default: | 1036 default: |
1020 return false; | 1037 return false; |
1021 } | 1038 } |
1022 } | 1039 } |
OLD | NEW |