Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/app_list/search/people/people_result.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/ui/app_list/search/common/url_icon_source.h" | |
| 14 #include "grit/theme_resources.h" | |
| 15 #include "ui/base/l10n/l10n_util.h" | |
| 16 | |
| 17 | |
|
xiyuan
2013/09/04 23:15:41
nit: nuke one empty line
rkc
2013/09/04 23:48:02
Done.
| |
| 18 namespace { | |
| 19 | |
| 20 const int kIconSize = 32; | |
|
xiyuan
2013/09/04 23:15:41
We probably should move this to a common place to
rkc
2013/09/04 23:48:02
As of now there didn't seem like a good place to p
| |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 namespace app_list { | |
| 25 | |
| 26 PeopleResult::PeopleResult(Profile* profile, | |
| 27 const std::string& id, | |
| 28 const std::string& display_name, | |
| 29 double interaction_rank, | |
| 30 const GURL& image_url) | |
| 31 : profile_(profile), | |
| 32 id_(id), | |
| 33 display_name_(display_name), | |
| 34 interaction_rank_(interaction_rank), | |
| 35 image_url_(image_url), | |
| 36 weak_factory_(this) { | |
| 37 set_id(id_); | |
| 38 set_title(UTF8ToUTF16(display_name_)); | |
| 39 set_relevance(interaction_rank_); | |
|
xiyuan
2013/09/04 23:15:41
Is |interaction_rank_| in range [0,1]? Relevance n
rkc
2013/09/04 23:48:02
Yes, interaction rank is in the range of 0-1.
| |
| 40 | |
| 41 image_ = gfx::ImageSkia( | |
| 42 new UrlIconSource(base::Bind(&PeopleResult::OnIconLoaded, | |
| 43 weak_factory_.GetWeakPtr()), | |
| 44 profile_->GetRequestContext(), | |
| 45 image_url_, | |
| 46 kIconSize, | |
| 47 IDR_PROFILE_PICTURE_LOADING), | |
| 48 gfx::Size(kIconSize, kIconSize)); | |
| 49 SetIcon(image_); | |
| 50 } | |
| 51 | |
| 52 PeopleResult::~PeopleResult() { | |
| 53 } | |
| 54 | |
| 55 void PeopleResult::Open(int event_flags) { | |
| 56 // TODO(rkc): Navigate to the person's profile? | |
| 57 } | |
| 58 | |
| 59 void PeopleResult::InvokeAction(int action_index, int event_flags) { | |
| 60 DCHECK_EQ(0, action_index); | |
| 61 // TODO(rkc): Decide what to do here. | |
| 62 } | |
| 63 | |
| 64 scoped_ptr<ChromeSearchResult> PeopleResult::Duplicate() { | |
| 65 return scoped_ptr<ChromeSearchResult>(new PeopleResult(profile_, id_, | |
| 66 display_name_, | |
| 67 interaction_rank_, | |
| 68 image_url_)).Pass(); | |
| 69 } | |
| 70 | |
| 71 void PeopleResult::OnIconLoaded() { | |
| 72 // Remove the existing image reps since the icon data is loaded and they | |
| 73 // need to be re-created. | |
| 74 const std::vector<gfx::ImageSkiaRep>& image_reps = image_.image_reps(); | |
| 75 for (size_t i = 0; i < image_reps.size(); ++i) | |
| 76 image_.RemoveRepresentation(image_reps[i].scale_factor()); | |
| 77 | |
| 78 SetIcon(image_); | |
| 79 } | |
| 80 | |
| 81 ChromeSearchResultType PeopleResult::GetType() { | |
| 82 return SEARCH_PEOPLE_SEARCH_RESULT; | |
| 83 } | |
| 84 | |
| 85 } // namespace app_list | |
| OLD | NEW |