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

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, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 // determine what keyword, if any, is applicable. 1000 // determine what keyword, if any, is applicable.
1000 // 1001 //
1001 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that 1002 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that
1002 // will have updated our state already, so in that case we don't also return 1003 // will have updated our state already, so in that case we don't also return
1003 // true from this function. 1004 // true from this function.
1004 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && 1005 return !(text_differs && allow_keyword_ui_change && !just_deleted_text &&
1005 no_selection && (selection_start == user_text_.length()) && 1006 no_selection && (selection_start == user_text_.length()) &&
1006 MaybeAcceptKeywordBySpace(user_text_)); 1007 MaybeAcceptKeywordBySpace(user_text_));
1007 } 1008 }
1008 1009
1009 void OmniboxEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { 1010 void OmniboxEditModel::OnPopupBoundsChanged(const gfx::Rect& bounds) {
1010 InstantController* instant = controller_->GetInstant(); 1011 InstantController* instant = controller_->GetInstant();
1011 if (instant) 1012 if (instant)
1012 instant->SetOmniboxBounds(bounds); 1013 instant->SetPopupBounds(bounds);
1014 }
1015
1016 void OmniboxEditModel::OnOmniboxBoundsChanged(const gfx::Rect& bounds) {
1017 InstantController* instant = controller_->GetInstant();
1018 if (instant) {
1019 int start;
1020 int end;
1021 if (base::i18n::IsRTL()) {
dhollowa 2012/11/16 17:29:03 A couple questions. (1) Isn't this supposed to be
samarth 2012/11/16 22:08:26 I'm also confused why this isn't the other way aro
dhollowa 2012/11/16 22:14:28 Not sure, but consider: b = { x = 10, y = 20, w =
melevin 2012/11/16 22:17:14 Oops, yes it is.
melevin 2012/11/16 22:34:43 They are relative to the browser window, so x=0 y=
samarth 2012/11/19 21:42:44 Ok, I get it now. I was misreading the API: I thou
1022 start = bounds.x();
1023 end = bounds.x() + bounds.width();
1024 } else {
1025 start = bounds.x() + bounds.width();
1026 end = bounds.x();
1027 }
1028 instant->SetMarginSize(start, end);
1029 }
1013 } 1030 }
1014 1031
1015 void OmniboxEditModel::OnResultChanged(bool default_match_changed) { 1032 void OmniboxEditModel::OnResultChanged(bool default_match_changed) {
1016 const bool was_open = popup_->IsOpen(); 1033 const bool was_open = popup_->IsOpen();
1017 if (default_match_changed) { 1034 if (default_match_changed) {
1018 string16 inline_autocomplete_text; 1035 string16 inline_autocomplete_text;
1019 string16 keyword; 1036 string16 keyword;
1020 bool is_keyword_hint = false; 1037 bool is_keyword_hint = false;
1021 const AutocompleteResult& result = this->result(); 1038 const AutocompleteResult& result = this->result();
1022 const AutocompleteResult::const_iterator match(result.default_match()); 1039 const AutocompleteResult::const_iterator match(result.default_match());
(...skipping 16 matching lines...) Expand all
1039 } 1056 }
1040 1057
1041 popup_->OnResultChanged(); 1058 popup_->OnResultChanged();
1042 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, 1059 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword,
1043 is_keyword_hint); 1060 is_keyword_hint);
1044 } else { 1061 } else {
1045 popup_->OnResultChanged(); 1062 popup_->OnResultChanged();
1046 } 1063 }
1047 1064
1048 if (popup_->IsOpen()) { 1065 if (popup_->IsOpen()) {
1049 PopupBoundsChangedTo(popup_->view()->GetTargetBounds()); 1066 OnPopupBoundsChanged(popup_->view()->GetTargetBounds());
1050 } else if (was_open) { 1067 } else if (was_open) {
1051 // Accepts the temporary text as the user text, because it makes little 1068 // Accepts the temporary text as the user text, because it makes little
1052 // sense to have temporary text when the popup is closed. 1069 // sense to have temporary text when the popup is closed.
1053 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); 1070 InternalSetUserText(UserTextFromDisplayText(view_->GetText()));
1054 has_temporary_text_ = false; 1071 has_temporary_text_ = false;
1055 is_temporary_text_set_by_instant_ = false; 1072 is_temporary_text_set_by_instant_ = false;
1056 PopupBoundsChangedTo(gfx::Rect()); 1073 OnPopupBoundsChanged(gfx::Rect());
1057 NotifySearchTabHelper(); 1074 NotifySearchTabHelper();
1058 } 1075 }
1059 1076
1060 if (InstantController* instant = controller_->GetInstant()) 1077 if (InstantController* instant = controller_->GetInstant())
1061 instant->HandleAutocompleteResults(*autocomplete_controller_->providers()); 1078 instant->HandleAutocompleteResults(*autocomplete_controller_->providers());
1062 } 1079 }
1063 1080
1064 bool OmniboxEditModel::query_in_progress() const { 1081 bool OmniboxEditModel::query_in_progress() const {
1065 return !autocomplete_controller_->done(); 1082 return !autocomplete_controller_->done();
1066 } 1083 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 } 1305 }
1289 1306
1290 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1307 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1291 const string16& text, 1308 const string16& text,
1292 AutocompleteMatch* match, 1309 AutocompleteMatch* match,
1293 GURL* alternate_nav_url) const { 1310 GURL* alternate_nav_url) const {
1294 DCHECK(match); 1311 DCHECK(match);
1295 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1312 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1296 string16(), false, false, match, alternate_nav_url); 1313 string16(), false, false, match, alternate_nav_url);
1297 } 1314 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698