| OLD | NEW |
| 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_popup_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_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 |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
| 17 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
| 18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 19 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" | 19 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" |
| 20 #include "ui/gfx/image/image.h" |
| 20 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
| 21 | 22 |
| 22 /////////////////////////////////////////////////////////////////////////////// | 23 /////////////////////////////////////////////////////////////////////////////// |
| 23 // OmniboxPopupModel | 24 // OmniboxPopupModel |
| 24 | 25 |
| 25 const size_t OmniboxPopupModel::kNoMatch = -1; | 26 const size_t OmniboxPopupModel::kNoMatch = -1; |
| 26 | 27 |
| 27 OmniboxPopupModel::OmniboxPopupModel( | 28 OmniboxPopupModel::OmniboxPopupModel( |
| 28 OmniboxPopupView* popup_view, | 29 OmniboxPopupView* popup_view, |
| 29 OmniboxEditModel* edit_model) | 30 OmniboxEditModel* edit_model) |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 SetSelectedLine(selected_line, false, true); | 192 SetSelectedLine(selected_line, false, true); |
| 192 } | 193 } |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 | 196 |
| 196 gfx::Image OmniboxPopupModel::GetIconIfExtensionMatch( | 197 gfx::Image OmniboxPopupModel::GetIconIfExtensionMatch( |
| 197 const AutocompleteMatch& match) const { | 198 const AutocompleteMatch& match) const { |
| 198 Profile* profile = edit_model_->profile(); | 199 Profile* profile = edit_model_->profile(); |
| 199 const TemplateURL* template_url = match.GetTemplateURL(profile, false); | 200 const TemplateURL* template_url = match.GetTemplateURL(profile, false); |
| 200 if (template_url && template_url->IsExtensionKeyword()) { | 201 if (template_url && template_url->IsExtensionKeyword()) { |
| 201 return profile->GetExtensionService()->GetOmniboxPopupIcon( | 202 return extensions::OmniboxAPI::Get(profile)->GetOmniboxPopupIcon( |
| 202 template_url->GetExtensionId()); | 203 template_url->GetExtensionId()); |
| 203 } | 204 } |
| 204 return gfx::Image(); | 205 return gfx::Image(); |
| 205 } | 206 } |
| 206 | 207 |
| 207 void OmniboxPopupModel::OnResultChanged() { | 208 void OmniboxPopupModel::OnResultChanged() { |
| 208 const AutocompleteResult& result = this->result(); | 209 const AutocompleteResult& result = this->result(); |
| 209 selected_line_ = result.default_match() == result.end() ? | 210 selected_line_ = result.default_match() == result.end() ? |
| 210 kNoMatch : static_cast<size_t>(result.default_match() - result.begin()); | 211 kNoMatch : static_cast<size_t>(result.default_match() - result.begin()); |
| 211 // There had better not be a nonempty result set with no default match. | 212 // There had better not be a nonempty result set with no default match. |
| 212 CHECK((selected_line_ != kNoMatch) || result.empty()); | 213 CHECK((selected_line_ != kNoMatch) || result.empty()); |
| 213 manually_selected_match_.Clear(); | 214 manually_selected_match_.Clear(); |
| 214 selected_line_state_ = NORMAL; | 215 selected_line_state_ = NORMAL; |
| 215 // If we're going to trim the window size to no longer include the hovered | 216 // If we're going to trim the window size to no longer include the hovered |
| 216 // line, turn hover off. Practically, this shouldn't happen, but it | 217 // line, turn hover off. Practically, this shouldn't happen, but it |
| 217 // doesn't hurt to be defensive. | 218 // doesn't hurt to be defensive. |
| 218 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) | 219 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) |
| 219 SetHoveredLine(kNoMatch); | 220 SetHoveredLine(kNoMatch); |
| 220 | 221 |
| 221 view_->UpdatePopupAppearance(); | 222 view_->UpdatePopupAppearance(); |
| 222 } | 223 } |
| OLD | NEW |