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

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: Rebase after r171018 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 <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 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 // determine what keyword, if any, is applicable. 989 // determine what keyword, if any, is applicable.
988 // 990 //
989 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that 991 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that
990 // will have updated our state already, so in that case we don't also return 992 // will have updated our state already, so in that case we don't also return
991 // true from this function. 993 // true from this function.
992 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && 994 return !(text_differs && allow_keyword_ui_change && !just_deleted_text &&
993 no_selection && (selection_start == user_text_.length()) && 995 no_selection && (selection_start == user_text_.length()) &&
994 MaybeAcceptKeywordBySpace(user_text_)); 996 MaybeAcceptKeywordBySpace(user_text_));
995 } 997 }
996 998
997 void OmniboxEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { 999 void OmniboxEditModel::OnPopupBoundsChanged(const gfx::Rect& bounds) {
998 if (InstantController* instant = controller_->GetInstant()) 1000 if (InstantController* instant = controller_->GetInstant())
999 instant->SetOmniboxBounds(bounds); 1001 instant->SetPopupBounds(bounds);
1002 }
1003
1004 void OmniboxEditModel::OnOmniboxBoundsChanged(const gfx::Rect& omnibox_bounds) {
1005 if (InstantController* instant = controller_->GetInstant()) {
1006 const gfx::Rect container_bounds = view_->GetContainerBounds();
1007 int start = omnibox_bounds.x();
1008 int end = container_bounds.x() + container_bounds.width() -
1009 omnibox_bounds.width() - start;
1010 if (base::i18n::IsRTL())
1011 std::swap(start, end);
1012 instant->SetMarginSize(start, end);
1013 }
1000 } 1014 }
1001 1015
1002 void OmniboxEditModel::OnResultChanged(bool default_match_changed) { 1016 void OmniboxEditModel::OnResultChanged(bool default_match_changed) {
1003 const bool was_open = popup_->IsOpen(); 1017 const bool was_open = popup_->IsOpen();
1004 if (default_match_changed) { 1018 if (default_match_changed) {
1005 string16 inline_autocomplete_text; 1019 string16 inline_autocomplete_text;
1006 string16 keyword; 1020 string16 keyword;
1007 bool is_keyword_hint = false; 1021 bool is_keyword_hint = false;
1008 const AutocompleteResult& result = this->result(); 1022 const AutocompleteResult& result = this->result();
1009 const AutocompleteResult::const_iterator match(result.default_match()); 1023 const AutocompleteResult::const_iterator match(result.default_match());
(...skipping 16 matching lines...) Expand all
1026 } 1040 }
1027 1041
1028 popup_->OnResultChanged(); 1042 popup_->OnResultChanged();
1029 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, 1043 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword,
1030 is_keyword_hint); 1044 is_keyword_hint);
1031 } else { 1045 } else {
1032 popup_->OnResultChanged(); 1046 popup_->OnResultChanged();
1033 } 1047 }
1034 1048
1035 if (popup_->IsOpen()) { 1049 if (popup_->IsOpen()) {
1036 PopupBoundsChangedTo(popup_->view()->GetTargetBounds()); 1050 OnPopupBoundsChanged(popup_->view()->GetTargetBounds());
1037 } else if (was_open) { 1051 } else if (was_open) {
1038 // Accepts the temporary text as the user text, because it makes little 1052 // Accepts the temporary text as the user text, because it makes little
1039 // sense to have temporary text when the popup is closed. 1053 // sense to have temporary text when the popup is closed.
1040 InternalSetUserText(UserTextFromDisplayText(view_->GetText())); 1054 InternalSetUserText(UserTextFromDisplayText(view_->GetText()));
1041 has_temporary_text_ = false; 1055 has_temporary_text_ = false;
1042 is_temporary_text_set_by_instant_ = false; 1056 is_temporary_text_set_by_instant_ = false;
1043 PopupBoundsChangedTo(gfx::Rect()); 1057 OnPopupBoundsChanged(gfx::Rect());
1044 NotifySearchTabHelper(); 1058 NotifySearchTabHelper();
1045 } 1059 }
1046 1060
1047 if (InstantController* instant = controller_->GetInstant()) 1061 if (InstantController* instant = controller_->GetInstant())
1048 instant->HandleAutocompleteResults(*autocomplete_controller_->providers()); 1062 instant->HandleAutocompleteResults(*autocomplete_controller_->providers());
1049 } 1063 }
1050 1064
1051 bool OmniboxEditModel::query_in_progress() const { 1065 bool OmniboxEditModel::query_in_progress() const {
1052 return !autocomplete_controller_->done(); 1066 return !autocomplete_controller_->done();
1053 } 1067 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 } 1276 }
1263 1277
1264 void OmniboxEditModel::ClassifyStringForPasteAndGo( 1278 void OmniboxEditModel::ClassifyStringForPasteAndGo(
1265 const string16& text, 1279 const string16& text,
1266 AutocompleteMatch* match, 1280 AutocompleteMatch* match,
1267 GURL* alternate_nav_url) const { 1281 GURL* alternate_nav_url) const {
1268 DCHECK(match); 1282 DCHECK(match);
1269 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text, 1283 AutocompleteClassifierFactory::GetForProfile(profile_)->Classify(text,
1270 string16(), false, false, match, alternate_nav_url); 1284 string16(), false, false, match, alternate_nav_url);
1271 } 1285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698