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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_model.cc

Issue 6731036: Enabled pressing TAB to cycle through the Omnibox results. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 8 months 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) 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_popup_model.h" 5 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "unicode/ubidi.h" 9 #include "unicode/ubidi.h"
10 10
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 CHECK(selected_line_ != kNoMatch); 94 CHECK(selected_line_ != kNoMatch);
95 GURL current_destination(result.match_at(selected_line_).destination_url); 95 GURL current_destination(result.match_at(selected_line_).destination_url);
96 view_->InvalidateLine(selected_line_); 96 view_->InvalidateLine(selected_line_);
97 selected_line_ = line; 97 selected_line_ = line;
98 view_->InvalidateLine(selected_line_); 98 view_->InvalidateLine(selected_line_);
99 99
100 // Update the edit with the new data for this match. 100 // Update the edit with the new data for this match.
101 // TODO(pkasting): If |selected_line_| moves to the controller, this can be 101 // TODO(pkasting): If |selected_line_| moves to the controller, this can be
102 // eliminated and just become a call to the observer on the edit. 102 // eliminated and just become a call to the observer on the edit.
103 string16 keyword; 103 string16 keyword;
104 const bool is_keyword_hint = GetKeywordForMatch(match, &keyword); 104 bool is_keyword_hint = false;
105
106 if (match.keyword.get()) {
107 keyword = match.keyword->text;
108 is_keyword_hint = match.keyword->is_keyword_hint;
109 }
105 if (reset_to_default) { 110 if (reset_to_default) {
106 string16 inline_autocomplete_text; 111 string16 inline_autocomplete_text;
107 if ((match.inline_autocomplete_offset != string16::npos) && 112 if ((match.inline_autocomplete_offset != string16::npos) &&
108 (match.inline_autocomplete_offset < match.fill_into_edit.length())) { 113 (match.inline_autocomplete_offset < match.fill_into_edit.length())) {
109 inline_autocomplete_text = 114 inline_autocomplete_text =
110 match.fill_into_edit.substr(match.inline_autocomplete_offset); 115 match.fill_into_edit.substr(match.inline_autocomplete_offset);
111 } 116 }
112 edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL, 117 edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL,
113 keyword, is_keyword_hint); 118 keyword, is_keyword_hint);
114 } else { 119 } else {
115 edit_model_->OnPopupDataChanged(match.fill_into_edit, &current_destination, 120 edit_model_->OnPopupDataChanged(match.fill_into_edit, &current_destination,
116 keyword, is_keyword_hint); 121 keyword, is_keyword_hint);
117 } 122 }
118 123
119 // Repaint old and new selected lines immediately, so that the edit doesn't 124 // Repaint old and new selected lines immediately, so that the edit doesn't
120 // appear to update [much] faster than the popup. 125 // appear to update [much] faster than the popup.
121 view_->PaintUpdatesNow(); 126 view_->PaintUpdatesNow();
122 } 127 }
123 128
124 void AutocompletePopupModel::ResetToDefaultMatch() { 129 void AutocompletePopupModel::ResetToDefaultMatch() {
125 const AutocompleteResult& result = this->result(); 130 const AutocompleteResult& result = this->result();
126 CHECK(!result.empty()); 131 CHECK(!result.empty());
127 SetSelectedLine(result.default_match() - result.begin(), true, false); 132 SetSelectedLine(result.default_match() - result.begin(), true, false);
128 view_->OnDragCanceled(); 133 view_->OnDragCanceled();
129 } 134 }
130 135
131 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
132 string16* keyword) const {
133 // If the current match is a keyword, return that as the selected keyword.
134 if (TemplateURL::SupportsReplacement(match.template_url)) {
135 keyword->assign(match.template_url->keyword());
136 return false;
137 }
138
139 // See if the current match's fill_into_edit corresponds to a keyword.
140 return GetKeywordForText(match.fill_into_edit, keyword);
141 }
142
143 bool AutocompletePopupModel::GetKeywordForText(const string16& text,
144 string16* keyword) const {
145 // Creates keyword_hint first in case |keyword| is a pointer to |text|.
146 const string16 keyword_hint(TemplateURLModel::CleanUserInputKeyword(text));
147
148 // Assume we have no keyword until we find otherwise.
149 keyword->clear();
150
151 if (keyword_hint.empty())
152 return false;
153 if (!profile_->GetTemplateURLModel())
154 return false;
155 profile_->GetTemplateURLModel()->Load();
156
157 // Don't provide a hint if this keyword doesn't support replacement.
158 const TemplateURL* const template_url =
159 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword_hint);
160 if (!TemplateURL::SupportsReplacement(template_url))
161 return false;
162
163 // Don't provide a hint for inactive/disabled extension keywords.
164 if (template_url->IsExtensionKeyword()) {
165 const Extension* extension = profile_->GetExtensionService()->
166 GetExtensionById(template_url->GetExtensionId(), false);
167 if (!extension ||
168 (profile_->IsOffTheRecord() &&
169 !profile_->GetExtensionService()->
170 IsIncognitoEnabled(extension->id())))
171 return false;
172 }
173
174 keyword->assign(keyword_hint);
175 return true;
176 }
177
178 void AutocompletePopupModel::Move(int count) { 136 void AutocompletePopupModel::Move(int count) {
179 const AutocompleteResult& result = this->result(); 137 const AutocompleteResult& result = this->result();
180 if (result.empty()) 138 if (result.empty())
181 return; 139 return;
182 140
183 // The user is using the keyboard to change the selection, so stop tracking 141 // The user is using the keyboard to change the selection, so stop tracking
184 // hover. 142 // hover.
185 SetHoveredLine(kNoMatch); 143 SetHoveredLine(kNoMatch);
186 144
187 // Clamp the new line to [0, result_.count() - 1]. 145 // Clamp the new line to [0, result_.count() - 1].
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 CHECK((selected_line_ != kNoMatch) || result.empty()); 197 CHECK((selected_line_ != kNoMatch) || result.empty());
240 manually_selected_match_.Clear(); 198 manually_selected_match_.Clear();
241 // If we're going to trim the window size to no longer include the hovered 199 // If we're going to trim the window size to no longer include the hovered
242 // line, turn hover off. Practically, this shouldn't happen, but it 200 // line, turn hover off. Practically, this shouldn't happen, but it
243 // doesn't hurt to be defensive. 201 // doesn't hurt to be defensive.
244 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) 202 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_))
245 SetHoveredLine(kNoMatch); 203 SetHoveredLine(kNoMatch);
246 204
247 view_->UpdatePopupAppearance(); 205 view_->UpdatePopupAppearance();
248 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698