Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 11359198: Implement the Instant extended API startMargin, endMargin, and rtl properties and the onmarginchang… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 7 #include <string>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/rtl.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/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 16 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
16 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 17 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
17 #include "chrome/browser/autocomplete/autocomplete_input.h" 18 #include "chrome/browser/autocomplete/autocomplete_input.h"
18 #include "chrome/browser/autocomplete/autocomplete_log.h" 19 #include "chrome/browser/autocomplete/autocomplete_log.h"
19 #include "chrome/browser/autocomplete/autocomplete_provider.h" 20 #include "chrome/browser/autocomplete/autocomplete_provider.h"
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 // determine what keyword, if any, is applicable. 992 // determine what keyword, if any, is applicable.
992 // 993 //
993 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that 994 // 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 995 // will have updated our state already, so in that case we don't also return
995 // true from this function. 996 // true from this function.
996 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && 997 return !(text_differs && allow_keyword_ui_change && !just_deleted_text &&
997 no_selection && (selection_start == user_text_.length()) && 998 no_selection && (selection_start == user_text_.length()) &&
998 MaybeAcceptKeywordBySpace(user_text_)); 999 MaybeAcceptKeywordBySpace(user_text_));
999 } 1000 }
1000 1001
1001 void OmniboxEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { 1002 void OmniboxEditModel::OnPopupBoundsChanged(const gfx::Rect& bounds) {
1002 if (InstantController* instant = controller_->GetInstant()) 1003 if (InstantController* instant = controller_->GetInstant())
1003 instant->SetOmniboxBounds(bounds); 1004 instant->SetPopupBounds(bounds);
1005 }
1006
1007 void OmniboxEditModel::OnOmniboxBoundsChanged(const gfx::Rect& omnibox_bounds,
1008 const gfx::Rect& parent_bounds) {
1009 if (InstantController* instant = controller_->GetInstant()) {
1010 int start = omnibox_bounds.x();
1011 int end = parent_bounds.x() + parent_bounds.width() -
1012 omnibox_bounds.width() - start;
1013 if (base::i18n::IsRTL()) {
1014 int tmp = start;
dhollowa 2012/11/28 16:44:08 std::swap(start, end)
melevin 2012/11/28 20:28:19 I've always been conflicted about this function. I
dhollowa 2012/11/28 20:44:33 Yes. It expresses intent clearly and adds to read
1015 start = end;
1016 end = tmp;
1017 }
1018 instant->SetMarginSize(start, end);
1019 }
1004 } 1020 }
1005 1021
1006 void OmniboxEditModel::OnResultChanged(bool default_match_changed) { 1022 void OmniboxEditModel::OnResultChanged(bool default_match_changed) {
1007 const bool was_open = popup_->IsOpen(); 1023 const bool was_open = popup_->IsOpen();
1008 if (default_match_changed) { 1024 if (default_match_changed) {
1009 string16 inline_autocomplete_text; 1025 string16 inline_autocomplete_text;
1010 string16 keyword; 1026 string16 keyword;
1011 bool is_keyword_hint = false; 1027 bool is_keyword_hint = false;
1012 const AutocompleteResult& result = this->result(); 1028 const AutocompleteResult& result = this->result();
1013 const AutocompleteResult::const_iterator match(result.default_match()); 1029 const AutocompleteResult::const_iterator match(result.default_match());
(...skipping 16 matching lines...) Expand all
1030 } 1046 }
1031 1047
1032 popup_->OnResultChanged(); 1048 popup_->OnResultChanged();
1033 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, 1049 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword,
1034 is_keyword_hint); 1050 is_keyword_hint);
1035 } else { 1051 } else {
1036 popup_->OnResultChanged(); 1052 popup_->OnResultChanged();
1037 } 1053 }
1038 1054
1039 if (popup_->IsOpen()) { 1055 if (popup_->IsOpen()) {
1040 PopupBoundsChangedTo(popup_->view()->GetTargetBounds()); 1056 OnPopupBoundsChanged(popup_->view()->GetTargetBounds());
1041 } else if (was_open) { 1057 } else if (was_open) {
1042 // Accepts the temporary text as the user text, because it makes little 1058 // Accepts the temporary text as the user text, because it makes little
1043 // sense to have temporary text when the popup is closed. 1059 // sense to have temporary text when the popup is closed.
1044 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); 1060 InternalSetUserText(UserTextFromDisplayText(view_->GetText()));
1045 has_temporary_text_ = false; 1061 has_temporary_text_ = false;
1046 is_temporary_text_set_by_instant_ = false; 1062 is_temporary_text_set_by_instant_ = false;
1047 PopupBoundsChangedTo(gfx::Rect()); 1063 OnPopupBoundsChanged(gfx::Rect());
1048 NotifySearchTabHelper(); 1064 NotifySearchTabHelper();
1049 } 1065 }
1050 1066
1051 if (InstantController* instant = controller_->GetInstant()) 1067 if (InstantController* instant = controller_->GetInstant())
1052 instant->HandleAutocompleteResults(*autocomplete_controller_->providers()); 1068 instant->HandleAutocompleteResults(*autocomplete_controller_->providers());
1053 } 1069 }
1054 1070
1055 bool OmniboxEditModel::query_in_progress() const { 1071 bool OmniboxEditModel::query_in_progress() const {
1056 return !autocomplete_controller_->done(); 1072 return !autocomplete_controller_->done();
1057 } 1073 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 } 1287 }
1272 1288
1273 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1289 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1274 const string16& text, 1290 const string16& text,
1275 AutocompleteMatch* match, 1291 AutocompleteMatch* match,
1276 GURL* alternate_nav_url) const { 1292 GURL* alternate_nav_url) const {
1277 DCHECK(match); 1293 DCHECK(match);
1278 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1294 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1279 string16(), false, false, match, alternate_nav_url); 1295 string16(), false, false, match, alternate_nav_url);
1280 } 1296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698