OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/search/omnibox_provider.h" | 5 #include "chrome/browser/ui/app_list/search/omnibox_provider.h" |
6 | 6 |
7 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 7 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
8 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 8 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
9 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 9 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
12 #include "chrome/browser/ui/app_list/search/chrome_search_result.h" | |
13 #include "chrome/browser/ui/browser_navigator.h" | 12 #include "chrome/browser/ui/browser_navigator.h" |
14 #include "components/bookmarks/browser/bookmark_model.h" | 13 #include "components/bookmarks/browser/bookmark_model.h" |
15 #include "components/metrics/proto/omnibox_event.pb.h" | 14 #include "components/metrics/proto/omnibox_event.pb.h" |
16 #include "components/omnibox/autocomplete_input.h" | 15 #include "components/omnibox/autocomplete_input.h" |
17 #include "components/omnibox/autocomplete_match.h" | 16 #include "components/omnibox/autocomplete_match.h" |
18 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 18 #include "ui/app_list/search_result.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 | 20 |
21 namespace app_list { | 21 namespace app_list { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 int ACMatchStyleToTagStyle(int styles) { | 25 int ACMatchStyleToTagStyle(int styles) { |
26 int tag_styles = 0; | 26 int tag_styles = 0; |
27 if (styles & ACMatchClassification::URL) | 27 if (styles & ACMatchClassification::URL) |
28 tag_styles |= SearchResult::Tag::URL; | 28 tag_styles |= SearchResult::Tag::URL; |
(...skipping 29 matching lines...) Expand all Loading... |
58 tag_start = text_class.offset; | 58 tag_start = text_class.offset; |
59 tag_styles = ACMatchStyleToTagStyle(text_class.style); | 59 tag_styles = ACMatchStyleToTagStyle(text_class.style); |
60 } | 60 } |
61 | 61 |
62 if (tag_styles != SearchResult::Tag::NONE) { | 62 if (tag_styles != SearchResult::Tag::NONE) { |
63 tags->push_back(SearchResult::Tag( | 63 tags->push_back(SearchResult::Tag( |
64 tag_styles, tag_start, text.length())); | 64 tag_styles, tag_start, text.length())); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 class OmniboxResult : public ChromeSearchResult { | 68 class OmniboxResult : public SearchResult { |
69 public: | 69 public: |
70 OmniboxResult(Profile* profile, | 70 OmniboxResult(Profile* profile, |
71 AutocompleteController* autocomplete_controller, | 71 AutocompleteController* autocomplete_controller, |
72 const AutocompleteMatch& match) | 72 const AutocompleteMatch& match) |
73 : profile_(profile), | 73 : profile_(profile), |
74 autocomplete_controller_(autocomplete_controller), | 74 autocomplete_controller_(autocomplete_controller), |
75 match_(match) { | 75 match_(match) { |
76 if (match_.search_terms_args) { | 76 if (match_.search_terms_args) { |
77 match_.search_terms_args->from_app_list = true; | 77 match_.search_terms_args->from_app_list = true; |
78 autocomplete_controller_->UpdateMatchDestinationURL( | 78 autocomplete_controller_->UpdateMatchDestinationURL( |
79 *match_.search_terms_args, &match_); | 79 *match_.search_terms_args, &match_); |
80 } | 80 } |
81 set_id(match_.destination_url.spec()); | 81 set_id(match_.destination_url.spec()); |
82 | 82 |
83 // Derive relevance from omnibox relevance and normalize it to [0, 1]. | 83 // Derive relevance from omnibox relevance and normalize it to [0, 1]. |
84 // The magic number 1500 is the highest score of an omnibox result. | 84 // The magic number 1500 is the highest score of an omnibox result. |
85 // See comments in autocomplete_provider.h. | 85 // See comments in autocomplete_provider.h. |
86 set_relevance(match_.relevance / 1500.0); | 86 set_relevance(match_.relevance / 1500.0); |
87 | 87 |
88 UpdateIcon(); | 88 UpdateIcon(); |
89 UpdateTitleAndDetails(); | 89 UpdateTitleAndDetails(); |
90 } | 90 } |
91 virtual ~OmniboxResult() {} | 91 virtual ~OmniboxResult() {} |
92 | 92 |
93 // ChromeSearchResult overides: | 93 // SearchResult overides: |
94 virtual void Open(int event_flags) OVERRIDE { | 94 virtual void Open(int event_flags) OVERRIDE { |
95 chrome::NavigateParams params(profile_, | 95 chrome::NavigateParams params(profile_, |
96 match_.destination_url, | 96 match_.destination_url, |
97 match_.transition); | 97 match_.transition); |
98 params.disposition = ui::DispositionFromEventFlags(event_flags); | 98 params.disposition = ui::DispositionFromEventFlags(event_flags); |
99 chrome::Navigate(¶ms); | 99 chrome::Navigate(¶ms); |
100 } | 100 } |
101 | 101 |
102 virtual void InvokeAction(int action_index, int event_flags) OVERRIDE {} | 102 virtual scoped_ptr<SearchResult> Duplicate() OVERRIDE { |
103 | 103 return scoped_ptr<SearchResult>( |
104 virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE { | |
105 return scoped_ptr<ChromeSearchResult>( | |
106 new OmniboxResult(profile_, autocomplete_controller_, match_)).Pass(); | 104 new OmniboxResult(profile_, autocomplete_controller_, match_)).Pass(); |
107 } | 105 } |
108 | 106 |
109 virtual ChromeSearchResultType GetType() OVERRIDE { | 107 virtual SearchResultType GetType() OVERRIDE { |
110 return OMNIBOX_SEARCH_RESULT; | 108 return OMNIBOX_SEARCH_RESULT; |
111 } | 109 } |
112 | 110 |
113 private: | 111 private: |
114 void UpdateIcon() { | 112 void UpdateIcon() { |
115 BookmarkModel* bookmark_model = | 113 BookmarkModel* bookmark_model = |
116 BookmarkModelFactory::GetForProfile(profile_); | 114 BookmarkModelFactory::GetForProfile(profile_); |
117 bool is_bookmarked = | 115 bool is_bookmarked = |
118 bookmark_model && bookmark_model->IsBookmarked(match_.destination_url); | 116 bookmark_model && bookmark_model->IsBookmarked(match_.destination_url); |
119 int resource_id = is_bookmarked ? | 117 int resource_id = is_bookmarked ? |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 new OmniboxResult(profile_, controller_.get(), *it))); | 180 new OmniboxResult(profile_, controller_.get(), *it))); |
183 } | 181 } |
184 } | 182 } |
185 | 183 |
186 void OmniboxProvider::OnResultChanged(bool default_match_changed) { | 184 void OmniboxProvider::OnResultChanged(bool default_match_changed) { |
187 const AutocompleteResult& result = controller_->result(); | 185 const AutocompleteResult& result = controller_->result(); |
188 PopulateFromACResult(result); | 186 PopulateFromACResult(result); |
189 } | 187 } |
190 | 188 |
191 } // namespace app_list | 189 } // namespace app_list |
OLD | NEW |