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

Unified Diff: ui/app_list/search_result_view.cc

Issue 10872099: ash: Add support for additional icons in apps search list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/app_list/search_result_view.h ('k') | ui/app_list/search_result_view_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/search_result_view.cc
diff --git a/ui/app_list/search_result_view.cc b/ui/app_list/search_result_view.cc
index 7c71e8e9fccb6b89dad6b46e986b6e1fa6f2868c..98f7405c380280a0e9b0c030e177b07e3690064b 100644
--- a/ui/app_list/search_result_view.cc
+++ b/ui/app_list/search_result_view.cc
@@ -8,7 +8,9 @@
#include "ui/app_list/search_result_list_view.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
+#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/render_text.h"
+#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/image_view.h"
namespace {
@@ -21,6 +23,15 @@ const int kIconViewWidth = kIconDimension + 2 * kIconPadding;
const int kTextTrailPadding = kIconPadding;
const int kBorderSize = 1;
+// Maximum dimensions of a search result's action icons.
+const int kActionIconDimension = 24;
+
+// Total space (including padding) used for each action icon's button.
+const int kActionButtonWidth = 32;
+
+// Extra margin at the right of the rightmost action icon.
+const int kActionButtonRightMargin = 8;
+
const SkColor kBorderColor = SkColorSetARGB(0x0F, 0, 0, 0);
const SkColor kDefaultTextColor = SkColorSetRGB(0x33, 0x33, 0x33);
@@ -89,10 +100,11 @@ namespace app_list {
const char SearchResultView::kViewClassName[] = "ui/app_list/SearchResultView";
SearchResultView::SearchResultView(SearchResultListView* list_view,
- views::ButtonListener* listener)
- : views::CustomButton(listener),
+ SearchResultViewDelegate* delegate)
+ : views::CustomButton(this),
result_(NULL),
list_view_(list_view),
+ delegate_(delegate),
icon_(new IconView) {
AddChildView(icon_);
}
@@ -109,6 +121,7 @@ void SearchResultView::SetResult(SearchResult* result) {
result_->AddObserver(this);
OnIconChanged();
+ OnActionIconsChanged();
UpdateTitleText();
UpdateDetailsText();
SchedulePaint();
@@ -155,6 +168,17 @@ void SearchResultView::Layout() {
icon_bounds.set_width(kIconViewWidth);
icon_bounds.Inset(kIconPadding, (rect.height() - kIconDimension) / 2);
icon_->SetBoundsRect(icon_bounds.Intersect(rect));
+
+ size_t num_buttons = action_buttons_.size();
+ for (size_t i = 0; i < num_buttons; ++i) {
+ views::ImageButton* button = action_buttons_[i];
+ gfx::Rect button_bounds(
+ rect.right() - kActionButtonRightMargin -
+ (num_buttons - i) * kActionButtonWidth,
+ (rect.y() + rect.height() - kActionIconDimension) / 2,
+ kActionButtonWidth, kActionIconDimension);
+ button->SetBoundsRect(button_bounds);
+ }
}
void SearchResultView::OnPaint(gfx::Canvas* canvas) {
@@ -178,7 +202,10 @@ void SearchResultView::OnPaint(gfx::Canvas* canvas) {
gfx::Rect text_bounds(rect);
text_bounds.set_x(kIconViewWidth);
- text_bounds.set_width(rect.width() - kIconViewWidth - kTextTrailPadding);
+ text_bounds.set_width(
+ rect.width() - kIconViewWidth - kTextTrailPadding -
+ action_buttons_.size() * kActionButtonWidth -
+ (!action_buttons_.empty() ? kActionButtonRightMargin : 0));
if (title_text_.get() && details_text_.get()) {
gfx::Size title_size(text_bounds.width(),
@@ -204,6 +231,22 @@ void SearchResultView::OnPaint(gfx::Canvas* canvas) {
}
}
+void SearchResultView::ButtonPressed(views::Button* sender,
+ const ui::Event& event) {
+ if (sender == this) {
+ delegate_->SearchResultActivated(this, event);
+ return;
+ }
+
+ for (size_t i = 0; i < action_buttons_.size(); ++i) {
+ if (sender == action_buttons_[i]) {
+ delegate_->SearchResultActionActivated(this, i, event);
+ return;
+ }
+ }
+ NOTREACHED() << "Got unexpected button press on " << sender;
+}
+
void SearchResultView::OnIconChanged() {
gfx::ImageSkia image(result_ ? result_->icon() : gfx::ImageSkia());
// Note this might leave the view with an old icon. But it is needed to avoid
@@ -215,12 +258,44 @@ void SearchResultView::OnIconChanged() {
return;
// Scales down big icons but leave small ones unchanged.
- if (image.width() > kIconDimension || image.height() > kIconDimension)
- icon_->SetImageSize(gfx::Size(kIconDimension, kIconDimension));
- else
+ if (image.width() > kIconDimension || image.height() > kIconDimension) {
+ image = gfx::ImageSkiaOperations::CreateResizedImage(
+ image,
+ skia::ImageOperations::RESIZE_BEST,
+ gfx::Size(kIconDimension, kIconDimension));
+ } else {
icon_->ResetImageSize();
+ }
icon_->SetImage(image);
}
+void SearchResultView::OnActionIconsChanged() {
+ while (action_buttons_.size() >
+ (result_ ? result_->action_icons().size() : 0)) {
+ RemoveChildView(action_buttons_.back());
+ action_buttons_.pop_back();
+ }
+
+ if (result_) {
+ while (action_buttons_.size() < result_->action_icons().size()) {
+ views::ImageButton* button = new views::ImageButton(this);
+ button->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
+ views::ImageButton::ALIGN_MIDDLE);
+ AddChildView(button);
+ action_buttons_.push_back(button);
+ }
+
+ const SearchResult::ActionIconSets& icons = result_->action_icons();
+ for (size_t i = 0; i < icons.size(); ++i) {
+ const SearchResult::ActionIconSet& icon = icons.at(i);
+ views::ImageButton* button = action_buttons_[i];
+ button->SetImage(views::CustomButton::BS_NORMAL, &icon.base_image);
+ button->SetImage(views::CustomButton::BS_HOT, &icon.hover_image);
+ button->SetImage(views::CustomButton::BS_PUSHED, &icon.pressed_image);
+ button->SetTooltipText(icon.tooltip_text);
+ }
+ }
+}
+
} // namespace app_list
« no previous file with comments | « ui/app_list/search_result_view.h ('k') | ui/app_list/search_result_view_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698