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

Side by Side Diff: chrome/browser/ui/app_list/search/omnibox_provider.cc

Issue 621823004: Simplifies the structure of app_list search a bit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 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
OLDNEW
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" 12 #include "chrome/browser/ui/app_list/search/search_util.h"
13 #include "chrome/browser/ui/browser_navigator.h" 13 #include "chrome/browser/ui/browser_navigator.h"
14 #include "components/bookmarks/browser/bookmark_model.h" 14 #include "components/bookmarks/browser/bookmark_model.h"
15 #include "components/metrics/proto/omnibox_event.pb.h" 15 #include "components/metrics/proto/omnibox_event.pb.h"
16 #include "components/omnibox/autocomplete_input.h" 16 #include "components/omnibox/autocomplete_input.h"
17 #include "components/omnibox/autocomplete_match.h" 17 #include "components/omnibox/autocomplete_match.h"
18 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
19 #include "ui/app_list/search_result.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 21
21 namespace app_list { 22 namespace app_list {
22 23
23 namespace { 24 namespace {
24 25
25 int ACMatchStyleToTagStyle(int styles) { 26 int ACMatchStyleToTagStyle(int styles) {
26 int tag_styles = 0; 27 int tag_styles = 0;
27 if (styles & ACMatchClassification::URL) 28 if (styles & ACMatchClassification::URL)
28 tag_styles |= SearchResult::Tag::URL; 29 tag_styles |= SearchResult::Tag::URL;
(...skipping 29 matching lines...) Expand all
58 tag_start = text_class.offset; 59 tag_start = text_class.offset;
59 tag_styles = ACMatchStyleToTagStyle(text_class.style); 60 tag_styles = ACMatchStyleToTagStyle(text_class.style);
60 } 61 }
61 62
62 if (tag_styles != SearchResult::Tag::NONE) { 63 if (tag_styles != SearchResult::Tag::NONE) {
63 tags->push_back(SearchResult::Tag( 64 tags->push_back(SearchResult::Tag(
64 tag_styles, tag_start, text.length())); 65 tag_styles, tag_start, text.length()));
65 } 66 }
66 } 67 }
67 68
68 class OmniboxResult : public ChromeSearchResult { 69 class OmniboxResult : public SearchResult {
69 public: 70 public:
70 OmniboxResult(Profile* profile, 71 OmniboxResult(Profile* profile,
71 AutocompleteController* autocomplete_controller, 72 AutocompleteController* autocomplete_controller,
72 const AutocompleteMatch& match) 73 const AutocompleteMatch& match)
73 : profile_(profile), 74 : profile_(profile),
74 autocomplete_controller_(autocomplete_controller), 75 autocomplete_controller_(autocomplete_controller),
75 match_(match) { 76 match_(match) {
76 if (match_.search_terms_args) { 77 if (match_.search_terms_args) {
77 match_.search_terms_args->from_app_list = true; 78 match_.search_terms_args->from_app_list = true;
78 autocomplete_controller_->UpdateMatchDestinationURL( 79 autocomplete_controller_->UpdateMatchDestinationURL(
79 *match_.search_terms_args, &match_); 80 *match_.search_terms_args, &match_);
80 } 81 }
81 set_id(match_.destination_url.spec()); 82 set_id(match_.destination_url.spec());
82 83
83 // Derive relevance from omnibox relevance and normalize it to [0, 1]. 84 // Derive relevance from omnibox relevance and normalize it to [0, 1].
84 // The magic number 1500 is the highest score of an omnibox result. 85 // The magic number 1500 is the highest score of an omnibox result.
85 // See comments in autocomplete_provider.h. 86 // See comments in autocomplete_provider.h.
86 set_relevance(match_.relevance / 1500.0); 87 set_relevance(match_.relevance / 1500.0);
87 88
88 UpdateIcon(); 89 UpdateIcon();
89 UpdateTitleAndDetails(); 90 UpdateTitleAndDetails();
90 } 91 }
91 virtual ~OmniboxResult() {} 92 virtual ~OmniboxResult() {}
92 93
93 // ChromeSearchResult overides: 94 // SearchResult overrides:
94 virtual void Open(int event_flags) override { 95 virtual void Open(int event_flags) override {
96 RecordHistogram(OMNIBOX_SEARCH_RESULT);
95 chrome::NavigateParams params(profile_, 97 chrome::NavigateParams params(profile_,
96 match_.destination_url, 98 match_.destination_url,
97 match_.transition); 99 match_.transition);
98 params.disposition = ui::DispositionFromEventFlags(event_flags); 100 params.disposition = ui::DispositionFromEventFlags(event_flags);
99 chrome::Navigate(&params); 101 chrome::Navigate(&params);
100 } 102 }
101 103
102 virtual void InvokeAction(int action_index, int event_flags) override {} 104 virtual scoped_ptr<SearchResult> Duplicate() override {
103 105 return scoped_ptr<SearchResult>(
104 virtual scoped_ptr<ChromeSearchResult> Duplicate() override { 106 new OmniboxResult(profile_, autocomplete_controller_, match_));
105 return scoped_ptr<ChromeSearchResult>(
106 new OmniboxResult(profile_, autocomplete_controller_, match_)).Pass();
107 }
108
109 virtual ChromeSearchResultType GetType() override {
110 return OMNIBOX_SEARCH_RESULT;
111 } 107 }
112 108
113 private: 109 private:
114 void UpdateIcon() { 110 void UpdateIcon() {
115 BookmarkModel* bookmark_model = 111 BookmarkModel* bookmark_model =
116 BookmarkModelFactory::GetForProfile(profile_); 112 BookmarkModelFactory::GetForProfile(profile_);
117 bool is_bookmarked = 113 bool is_bookmarked =
118 bookmark_model && bookmark_model->IsBookmarked(match_.destination_url); 114 bookmark_model && bookmark_model->IsBookmarked(match_.destination_url);
119 int resource_id = is_bookmarked ? 115 int resource_id = is_bookmarked ?
120 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); 116 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 new OmniboxResult(profile_, controller_.get(), *it))); 178 new OmniboxResult(profile_, controller_.get(), *it)));
183 } 179 }
184 } 180 }
185 181
186 void OmniboxProvider::OnResultChanged(bool default_match_changed) { 182 void OmniboxProvider::OnResultChanged(bool default_match_changed) {
187 const AutocompleteResult& result = controller_->result(); 183 const AutocompleteResult& result = controller_->result();
188 PopulateFromACResult(result); 184 PopulateFromACResult(result);
189 } 185 }
190 186
191 } // namespace app_list 187 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/mixer_unittest.cc ('k') | chrome/browser/ui/app_list/search/people/people_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698