| 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 "ui/app_list/search_result.h" | 5 #include "ui/app_list/search_result.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
| 10 #include "ui/app_list/search/tokenized_string.h" | 10 #include "ui/app_list/search/tokenized_string.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 SearchResult::SearchResult() | 34 SearchResult::SearchResult() |
| 35 : relevance_(0), | 35 : relevance_(0), |
| 36 display_type_(DISPLAY_LIST), | 36 display_type_(DISPLAY_LIST), |
| 37 distance_from_origin_(-1), | 37 distance_from_origin_(-1), |
| 38 voice_result_(false), | 38 voice_result_(false), |
| 39 is_installing_(false), | 39 is_installing_(false), |
| 40 percent_downloaded_(0) { | 40 percent_downloaded_(0) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 SearchResult::~SearchResult() { | 43 SearchResult::~SearchResult() { |
| 44 FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnResultDestroying()); | 44 for (auto& observer : observers_) |
| 45 observer.OnResultDestroying(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void SearchResult::SetIcon(const gfx::ImageSkia& icon) { | 48 void SearchResult::SetIcon(const gfx::ImageSkia& icon) { |
| 48 icon_ = icon; | 49 icon_ = icon; |
| 49 FOR_EACH_OBSERVER(SearchResultObserver, | 50 for (auto& observer : observers_) |
| 50 observers_, | 51 observer.OnIconChanged(); |
| 51 OnIconChanged()); | |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SearchResult::SetBadgeIcon(const gfx::ImageSkia& badge_icon) { | 54 void SearchResult::SetBadgeIcon(const gfx::ImageSkia& badge_icon) { |
| 55 badge_icon_ = badge_icon; | 55 badge_icon_ = badge_icon; |
| 56 FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnBadgeIconChanged()); | 56 for (auto& observer : observers_) |
| 57 observer.OnBadgeIconChanged(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void SearchResult::SetActions(const Actions& sets) { | 60 void SearchResult::SetActions(const Actions& sets) { |
| 60 actions_ = sets; | 61 actions_ = sets; |
| 61 FOR_EACH_OBSERVER(SearchResultObserver, | 62 for (auto& observer : observers_) |
| 62 observers_, | 63 observer.OnActionsChanged(); |
| 63 OnActionsChanged()); | |
| 64 } | 64 } |
| 65 | 65 |
| 66 void SearchResult::SetIsInstalling(bool is_installing) { | 66 void SearchResult::SetIsInstalling(bool is_installing) { |
| 67 if (is_installing_ == is_installing) | 67 if (is_installing_ == is_installing) |
| 68 return; | 68 return; |
| 69 | 69 |
| 70 is_installing_ = is_installing; | 70 is_installing_ = is_installing; |
| 71 FOR_EACH_OBSERVER(SearchResultObserver, | 71 for (auto& observer : observers_) |
| 72 observers_, | 72 observer.OnIsInstallingChanged(); |
| 73 OnIsInstallingChanged()); | |
| 74 } | 73 } |
| 75 | 74 |
| 76 void SearchResult::SetPercentDownloaded(int percent_downloaded) { | 75 void SearchResult::SetPercentDownloaded(int percent_downloaded) { |
| 77 if (percent_downloaded_ == percent_downloaded) | 76 if (percent_downloaded_ == percent_downloaded) |
| 78 return; | 77 return; |
| 79 | 78 |
| 80 percent_downloaded_ = percent_downloaded; | 79 percent_downloaded_ = percent_downloaded; |
| 81 FOR_EACH_OBSERVER(SearchResultObserver, | 80 for (auto& observer : observers_) |
| 82 observers_, | 81 observer.OnPercentDownloadedChanged(); |
| 83 OnPercentDownloadedChanged()); | |
| 84 } | 82 } |
| 85 | 83 |
| 86 int SearchResult::GetPreferredIconDimension() const { | 84 int SearchResult::GetPreferredIconDimension() const { |
| 87 switch (display_type_) { | 85 switch (display_type_) { |
| 88 case DISPLAY_RECOMMENDATION: // Falls through. | 86 case DISPLAY_RECOMMENDATION: // Falls through. |
| 89 case DISPLAY_TILE: | 87 case DISPLAY_TILE: |
| 90 return kTileIconSize; | 88 return kTileIconSize; |
| 91 case DISPLAY_LIST: | 89 case DISPLAY_LIST: |
| 92 return kListIconSize; | 90 return kListIconSize; |
| 93 case DISPLAY_NONE: | 91 case DISPLAY_NONE: |
| 94 return 0; | 92 return 0; |
| 95 case DISPLAY_TYPE_LAST: | 93 case DISPLAY_TYPE_LAST: |
| 96 break; | 94 break; |
| 97 } | 95 } |
| 98 NOTREACHED(); | 96 NOTREACHED(); |
| 99 return 0; | 97 return 0; |
| 100 } | 98 } |
| 101 | 99 |
| 102 void SearchResult::NotifyItemInstalled() { | 100 void SearchResult::NotifyItemInstalled() { |
| 103 FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnItemInstalled()); | 101 for (auto& observer : observers_) |
| 102 observer.OnItemInstalled(); |
| 104 } | 103 } |
| 105 | 104 |
| 106 void SearchResult::AddObserver(SearchResultObserver* observer) { | 105 void SearchResult::AddObserver(SearchResultObserver* observer) { |
| 107 observers_.AddObserver(observer); | 106 observers_.AddObserver(observer); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void SearchResult::RemoveObserver(SearchResultObserver* observer) { | 109 void SearchResult::RemoveObserver(SearchResultObserver* observer) { |
| 111 observers_.RemoveObserver(observer); | 110 observers_.RemoveObserver(observer); |
| 112 } | 111 } |
| 113 | 112 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 157 } |
| 159 | 158 |
| 160 // Insert the delimiters (in reverse order, to preserve indices). | 159 // Insert the delimiters (in reverse order, to preserve indices). |
| 161 for (auto it = inserts.rbegin(); it != inserts.rend(); ++it) | 160 for (auto it = inserts.rbegin(); it != inserts.rend(); ++it) |
| 162 result.insert(it->first, it->second); | 161 result.insert(it->first, it->second); |
| 163 | 162 |
| 164 return result; | 163 return result; |
| 165 } | 164 } |
| 166 | 165 |
| 167 } // namespace app_list | 166 } // namespace app_list |
| OLD | NEW |