Chromium Code Reviews| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 controller_(controller), | 72 controller_(controller), |
| 73 has_focus_(false), | 73 has_focus_(false), |
| 74 user_input_in_progress_(false), | 74 user_input_in_progress_(false), |
| 75 just_deleted_text_(false), | 75 just_deleted_text_(false), |
| 76 has_temporary_text_(false), | 76 has_temporary_text_(false), |
| 77 paste_state_(NONE), | 77 paste_state_(NONE), |
| 78 control_key_state_(UP), | 78 control_key_state_(UP), |
| 79 is_keyword_hint_(false), | 79 is_keyword_hint_(false), |
| 80 paste_and_go_transition_(PageTransition::TYPED), | 80 paste_and_go_transition_(PageTransition::TYPED), |
| 81 profile_(profile), | 81 profile_(profile), |
| 82 update_instant_(true) { | 82 update_instant_(true), |
| 83 instant_complete_behavior_(INSTANT_COMPLETE_DELAYED) { | |
| 83 } | 84 } |
| 84 | 85 |
| 85 AutocompleteEditModel::~AutocompleteEditModel() { | 86 AutocompleteEditModel::~AutocompleteEditModel() { |
| 86 } | 87 } |
| 87 | 88 |
| 88 void AutocompleteEditModel::SetProfile(Profile* profile) { | 89 void AutocompleteEditModel::SetProfile(Profile* profile) { |
| 89 DCHECK(profile); | 90 DCHECK(profile); |
| 90 profile_ = profile; | 91 profile_ = profile; |
| 91 autocomplete_controller_->SetProfile(profile); | 92 autocomplete_controller_->SetProfile(profile); |
| 92 popup_->set_profile(profile); | 93 popup_->set_profile(profile); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 view_->OnBeforePossibleChange(); | 166 view_->OnBeforePossibleChange(); |
| 166 view_->SetWindowTextAndCaretPos(final_text, final_text.length()); | 167 view_->SetWindowTextAndCaretPos(final_text, final_text.length()); |
| 167 view_->OnAfterPossibleChange(); | 168 view_->OnAfterPossibleChange(); |
| 168 } else if (popup_->IsOpen()) { | 169 } else if (popup_->IsOpen()) { |
| 169 SearchProvider* search_provider = | 170 SearchProvider* search_provider = |
| 170 autocomplete_controller_->search_provider(); | 171 autocomplete_controller_->search_provider(); |
| 171 search_provider->FinalizeInstantQuery(input_text, suggest_text); | 172 search_provider->FinalizeInstantQuery(input_text, suggest_text); |
| 172 } | 173 } |
| 173 } | 174 } |
| 174 | 175 |
| 175 void AutocompleteEditModel::SetSuggestedText(const string16& text) { | 176 void AutocompleteEditModel::SetSuggestedText( |
| 176 // This method is internally invoked to reset suggest text, so we only do | 177 const string16& text, |
| 177 // anything if the text isn't empty. | 178 InstantCompleteBehavior behavior) { |
| 178 // TODO: if we keep autocomplete, make it so this isn't invoked with empty | 179 instant_complete_behavior_ = behavior; |
| 179 // text. | 180 if (instant_complete_behavior_ == INSTANT_COMPLETE_NOW) { |
| 180 if (!text.empty()) | 181 if (!text.empty()) |
| 181 FinalizeInstantQuery(view_->GetText(), text, false); | 182 FinalizeInstantQuery(view_->GetText(), text, false); |
| 183 else | |
| 184 view_->SetInstantSuggestion(text, false); | |
| 185 } else { | |
| 186 DCHECK((behavior == INSTANT_COMPLETE_DELAYED) || | |
| 187 (behavior == INSTANT_COMPLETE_NEVER)); | |
| 188 view_->SetInstantSuggestion(text, behavior == INSTANT_COMPLETE_DELAYED); | |
| 189 } | |
| 182 } | 190 } |
| 183 | 191 |
| 184 bool AutocompleteEditModel::CommitSuggestedText(bool skip_inline_autocomplete) { | 192 bool AutocompleteEditModel::CommitSuggestedText(bool skip_inline_autocomplete) { |
| 185 if (!controller_->GetInstant()) | 193 if (!controller_->GetInstant()) |
| 186 return false; | 194 return false; |
| 187 | 195 |
| 188 const string16 suggestion = view_->GetInstantSuggestion(); | 196 const string16 suggestion = view_->GetInstantSuggestion(); |
| 189 if (suggestion.empty()) | 197 if (suggestion.empty()) |
| 190 return false; | 198 return false; |
| 191 | 199 |
| 192 FinalizeInstantQuery(view_->GetText(), suggestion, skip_inline_autocomplete); | 200 FinalizeInstantQuery(view_->GetText(), suggestion, skip_inline_autocomplete); |
| 193 return true; | 201 return true; |
| 194 } | 202 } |
| 195 | 203 |
| 196 bool AutocompleteEditModel::AcceptCurrentInstantPreview() { | 204 bool AutocompleteEditModel::AcceptCurrentInstantPreview() { |
| 197 return InstantController::CommitIfCurrent(controller_->GetInstant()); | 205 return InstantController::CommitIfCurrent(controller_->GetInstant()); |
| 198 } | 206 } |
| 199 | 207 |
| 200 void AutocompleteEditModel::OnChanged() { | 208 void AutocompleteEditModel::OnChanged() { |
| 201 InstantController* instant = controller_->GetInstant(); | 209 InstantController* instant = controller_->GetInstant(); |
| 202 string16 suggested_text; | 210 string16 suggested_text; |
| 203 TabContentsWrapper* tab = controller_->GetTabContentsWrapper(); | 211 TabContentsWrapper* tab = controller_->GetTabContentsWrapper(); |
| 212 bool might_support_instant = false; | |
| 204 if (update_instant_ && instant && tab) { | 213 if (update_instant_ && instant && tab) { |
| 205 if (user_input_in_progress() && popup_->IsOpen()) { | 214 if (user_input_in_progress() && popup_->IsOpen()) { |
| 206 AutocompleteMatch current_match = CurrentMatch(); | 215 AutocompleteMatch current_match = CurrentMatch(); |
| 207 if (current_match.destination_url == PermanentURL()) { | 216 if (current_match.destination_url == PermanentURL()) { |
| 208 // The destination is the same as the current url. This typically | 217 // The destination is the same as the current url. This typically |
| 209 // happens if the user presses the down error in the omnibox, in which | 218 // happens if the user presses the down error in the omnibox, in which |
| 210 // case we don't want to load a preview. | 219 // case we don't want to load a preview. |
| 211 instant->DestroyPreviewContentsAndLeaveActive(); | 220 instant->DestroyPreviewContentsAndLeaveActive(); |
| 212 } else { | 221 } else { |
| 213 instant->Update(tab, CurrentMatch(), view_->GetText(), | 222 instant->Update(tab, CurrentMatch(), view_->GetText(), |
| 214 UseVerbatimInstant(), &suggested_text); | 223 UseVerbatimInstant(), &suggested_text); |
| 215 } | 224 } |
| 216 } else { | 225 } else { |
| 217 instant->DestroyPreviewContents(); | 226 instant->DestroyPreviewContents(); |
| 218 } | 227 } |
| 219 if (!instant->MightSupportInstant()) | 228 might_support_instant = instant->MightSupportInstant(); |
| 220 FinalizeInstantQuery(string16(), string16(), false); | |
| 221 } | 229 } |
| 222 | 230 |
| 223 SetSuggestedText(suggested_text); | 231 if (!might_support_instant) { |
|
Peter Kasting
2011/03/29 00:10:27
Nit: I'd remove the "!" and reverse the conditions
| |
| 232 // Hide any suggestions we might be showing. | |
| 233 view_->SetInstantSuggestion(string16(), false); | |
| 234 | |
| 235 // No need to wait any longer for instant. | |
| 236 FinalizeInstantQuery(string16(), string16(), false); | |
| 237 } else { | |
| 238 SetSuggestedText(suggested_text, instant_complete_behavior_); | |
| 239 } | |
| 224 | 240 |
| 225 controller_->OnChanged(); | 241 controller_->OnChanged(); |
| 226 } | 242 } |
| 227 | 243 |
| 228 void AutocompleteEditModel::GetDataForURLExport(GURL* url, | 244 void AutocompleteEditModel::GetDataForURLExport(GURL* url, |
| 229 string16* title, | 245 string16* title, |
| 230 SkBitmap* favicon) { | 246 SkBitmap* favicon) { |
| 231 AutocompleteMatch match; | 247 AutocompleteMatch match; |
| 232 GetInfoForCurrentText(&match, NULL); | 248 GetInfoForCurrentText(&match, NULL); |
| 233 *url = match.destination_url; | 249 *url = match.destination_url; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 has_focus_ = true; | 577 has_focus_ = true; |
| 562 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; | 578 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; |
| 563 NotificationService::current()->Notify( | 579 NotificationService::current()->Notify( |
| 564 NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, | 580 NotificationType::AUTOCOMPLETE_EDIT_FOCUSED, |
| 565 Source<AutocompleteEditModel>(this), | 581 Source<AutocompleteEditModel>(this), |
| 566 NotificationService::NoDetails()); | 582 NotificationService::NoDetails()); |
| 567 } | 583 } |
| 568 | 584 |
| 569 void AutocompleteEditModel::OnWillKillFocus( | 585 void AutocompleteEditModel::OnWillKillFocus( |
| 570 gfx::NativeView view_gaining_focus) { | 586 gfx::NativeView view_gaining_focus) { |
| 571 SetSuggestedText(string16()); | 587 SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); |
| 572 | 588 |
| 573 InstantController* instant = controller_->GetInstant(); | 589 InstantController* instant = controller_->GetInstant(); |
| 574 if (instant) | 590 if (instant) |
| 575 instant->OnAutocompleteLostFocus(view_gaining_focus); | 591 instant->OnAutocompleteLostFocus(view_gaining_focus); |
| 576 } | 592 } |
| 577 | 593 |
| 578 void AutocompleteEditModel::OnKillFocus() { | 594 void AutocompleteEditModel::OnKillFocus() { |
| 579 has_focus_ = false; | 595 has_focus_ = false; |
| 580 control_key_state_ = UP; | 596 control_key_state_ = UP; |
| 581 paste_state_ = NONE; | 597 paste_state_ = NONE; |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 // static | 958 // static |
| 943 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 959 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
| 944 switch (c) { | 960 switch (c) { |
| 945 case 0x0020: // Space | 961 case 0x0020: // Space |
| 946 case 0x3000: // Ideographic Space | 962 case 0x3000: // Ideographic Space |
| 947 return true; | 963 return true; |
| 948 default: | 964 default: |
| 949 return false; | 965 return false; |
| 950 } | 966 } |
| 951 } | 967 } |
| OLD | NEW |