OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
6 | 6 |
7 #include <algorithm> | |
7 #include <string> | 8 #include <string> |
8 | 9 |
9 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/i18n/rtl.h" | |
10 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
11 #include "base/string_util.h" | 13 #include "base/string_util.h" |
12 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
14 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
16 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
17 #include "chrome/browser/autocomplete/autocomplete_input.h" | 19 #include "chrome/browser/autocomplete/autocomplete_input.h" |
18 #include "chrome/browser/autocomplete/autocomplete_log.h" | 20 #include "chrome/browser/autocomplete/autocomplete_log.h" |
19 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 21 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
991 // determine what keyword, if any, is applicable. | 993 // determine what keyword, if any, is applicable. |
992 // | 994 // |
993 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that | 995 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that |
994 // will have updated our state already, so in that case we don't also return | 996 // will have updated our state already, so in that case we don't also return |
995 // true from this function. | 997 // true from this function. |
996 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && | 998 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && |
997 no_selection && (selection_start == user_text_.length()) && | 999 no_selection && (selection_start == user_text_.length()) && |
998 MaybeAcceptKeywordBySpace(user_text_)); | 1000 MaybeAcceptKeywordBySpace(user_text_)); |
999 } | 1001 } |
1000 | 1002 |
1001 void OmniboxEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { | 1003 void OmniboxEditModel::OnPopupBoundsChanged(const gfx::Rect& bounds) { |
1002 if (InstantController* instant = controller_->GetInstant()) | 1004 if (InstantController* instant = controller_->GetInstant()) |
1003 instant->SetOmniboxBounds(bounds); | 1005 instant->SetPopupBounds(bounds); |
1006 } | |
1007 | |
1008 void OmniboxEditModel::OnOmniboxBoundsChanged(const gfx::Rect& omnibox_bounds, | |
sky
2012/11/28 22:29:02
Passing bounds like this strikes me as specific to
melevin
2012/11/30 23:37:09
Done.
| |
1009 const gfx::Rect& parent_bounds) { | |
1010 if (InstantController* instant = controller_->GetInstant()) { | |
1011 int start = omnibox_bounds.x(); | |
1012 int end = parent_bounds.x() + parent_bounds.width() - | |
1013 omnibox_bounds.width() - start; | |
1014 if (base::i18n::IsRTL()) | |
1015 std::swap(start, end); | |
1016 instant->SetMarginSize(start, end); | |
1017 } | |
1004 } | 1018 } |
1005 | 1019 |
1006 void OmniboxEditModel::OnResultChanged(bool default_match_changed) { | 1020 void OmniboxEditModel::OnResultChanged(bool default_match_changed) { |
1007 const bool was_open = popup_->IsOpen(); | 1021 const bool was_open = popup_->IsOpen(); |
1008 if (default_match_changed) { | 1022 if (default_match_changed) { |
1009 string16 inline_autocomplete_text; | 1023 string16 inline_autocomplete_text; |
1010 string16 keyword; | 1024 string16 keyword; |
1011 bool is_keyword_hint = false; | 1025 bool is_keyword_hint = false; |
1012 const AutocompleteResult& result = this->result(); | 1026 const AutocompleteResult& result = this->result(); |
1013 const AutocompleteResult::const_iterator match(result.default_match()); | 1027 const AutocompleteResult::const_iterator match(result.default_match()); |
(...skipping 16 matching lines...) Expand all Loading... | |
1030 } | 1044 } |
1031 | 1045 |
1032 popup_->OnResultChanged(); | 1046 popup_->OnResultChanged(); |
1033 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, | 1047 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, |
1034 is_keyword_hint); | 1048 is_keyword_hint); |
1035 } else { | 1049 } else { |
1036 popup_->OnResultChanged(); | 1050 popup_->OnResultChanged(); |
1037 } | 1051 } |
1038 | 1052 |
1039 if (popup_->IsOpen()) { | 1053 if (popup_->IsOpen()) { |
1040 PopupBoundsChangedTo(popup_->view()->GetTargetBounds()); | 1054 OnPopupBoundsChanged(popup_->view()->GetTargetBounds()); |
1041 } else if (was_open) { | 1055 } else if (was_open) { |
1042 // Accepts the temporary text as the user text, because it makes little | 1056 // Accepts the temporary text as the user text, because it makes little |
1043 // sense to have temporary text when the popup is closed. | 1057 // sense to have temporary text when the popup is closed. |
1044 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); | 1058 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); |
1045 has_temporary_text_ = false; | 1059 has_temporary_text_ = false; |
1046 is_temporary_text_set_by_instant_ = false; | 1060 is_temporary_text_set_by_instant_ = false; |
1047 PopupBoundsChangedTo(gfx::Rect()); | 1061 OnPopupBoundsChanged(gfx::Rect()); |
1048 NotifySearchTabHelper(); | 1062 NotifySearchTabHelper(); |
1049 } | 1063 } |
1050 | 1064 |
1051 if (InstantController* instant = controller_->GetInstant()) | 1065 if (InstantController* instant = controller_->GetInstant()) |
1052 instant->HandleAutocompleteResults(*autocomplete_controller_->providers()); | 1066 instant->HandleAutocompleteResults(*autocomplete_controller_->providers()); |
1053 } | 1067 } |
1054 | 1068 |
1055 bool OmniboxEditModel::query_in_progress() const { | 1069 bool OmniboxEditModel::query_in_progress() const { |
1056 return !autocomplete_controller_->done(); | 1070 return !autocomplete_controller_->done(); |
1057 } | 1071 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1271 } | 1285 } |
1272 | 1286 |
1273 void OmniboxEditModel::ClassifyStringForPasteAndGo( | 1287 void OmniboxEditModel::ClassifyStringForPasteAndGo( |
1274 const string16& text, | 1288 const string16& text, |
1275 AutocompleteMatch* match, | 1289 AutocompleteMatch* match, |
1276 GURL* alternate_nav_url) const { | 1290 GURL* alternate_nav_url) const { |
1277 DCHECK(match); | 1291 DCHECK(match); |
1278 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, | 1292 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, |
1279 string16(), false, false, match, alternate_nav_url); | 1293 string16(), false, false, match, alternate_nav_url); |
1280 } | 1294 } |
OLD | NEW |