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

Unified Diff: ash/app_list/app_list_item_view.cc

Issue 9479031: aura: Implement new app list mock. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compilation error Created 8 years, 10 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 | « ash/app_list/app_list_item_view.h ('k') | ash/app_list/app_list_item_view_listener.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/app_list/app_list_item_view.cc
diff --git a/ash/app_list/app_list_item_view.cc b/ash/app_list/app_list_item_view.cc
index 41c1f891f65263c419fb4d222b2fec9b31ca2532..3c46058a27ba47984279d4a00ef0e54f5715a905 100644
--- a/ash/app_list/app_list_item_view.cc
+++ b/ash/app_list/app_list_item_view.cc
@@ -1,15 +1,15 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/app_list/app_list_item_view.h"
-#include "ash/app_list/app_list_item_group_view.h"
#include "ash/app_list/app_list_item_model.h"
-#include "ash/app_list/app_list_item_view_listener.h"
+#include "ash/app_list/app_list_model_view.h"
#include "ash/app_list/drop_shadow_label.h"
#include "base/utf_string_conversions.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/base/animation/throb_animation.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
@@ -21,33 +21,48 @@ namespace ash {
namespace {
-const double kFocusedScale = 1.1;
+const int kIconTitleSpacing = 5;
const SkColor kTitleColor = SK_ColorWHITE;
+const SkColor kHoverColor = SkColorSetARGB(0x33, 0xFF, 0xFF, 0xFF); // 0.2 white
gfx::Font GetTitleFont() {
static gfx::Font* font = NULL;
if (!font) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
font = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont).DeriveFont(
- 2, gfx::Font::BOLD));
+ 1, gfx::Font::BOLD));
}
return *font;
}
+// An image view that is not interactive.
+class StaticImageView : public views::ImageView {
+ public:
+ StaticImageView() : ImageView() {
+ }
+
+ private:
+ // views::View overrides:
+ virtual bool HitTest(const gfx::Point& l) const OVERRIDE {
+ return false;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(StaticImageView);
+};
+
} // namespace
AppListItemView::AppListItemView(AppListItemModel* model,
- AppListItemViewListener* listener)
- : model_(model),
- listener_(listener),
- icon_(new views::ImageView),
+ views::ButtonListener* listener)
+ : CustomButton(listener),
+ model_(model),
+ icon_(new StaticImageView),
title_(new DropShadowLabel) {
- set_focusable(true);
-
title_->SetFont(GetTitleFont());
title_->SetBackgroundColor(0);
title_->SetEnabledColor(kTitleColor);
+ title_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
AddChildView(icon_);
AddChildView(title_);
@@ -61,11 +76,6 @@ AppListItemView::~AppListItemView() {
model_->RemoveObserver(this);
}
-void AppListItemView::NotifyActivated(int event_flags) {
- if (listener_)
- listener_->AppListItemActivated(this, event_flags);
-}
-
void AppListItemView::ItemIconChanged() {
icon_->SetImage(model_->icon());
}
@@ -75,88 +85,39 @@ void AppListItemView::ItemTitleChanged() {
}
gfx::Size AppListItemView::GetPreferredSize() {
- return gfx::Size(kTileSize, kTileSize);
+ gfx::Size icon_size = icon_->GetPreferredSize();
+ gfx::Size title_size = title_->GetPreferredSize();
+
+ return gfx::Size(icon_size.width() + kIconTitleSpacing + title_size.width(),
+ std::max(icon_size.height(), title_size.height()));
}
void AppListItemView::Layout() {
gfx::Rect rect(GetContentsBounds());
- gfx::Size title_size = title_->GetPreferredSize();
-
- if (!HasFocus()) {
- const int horiz_padding = (kTileSize - kIconSize) / 2;
- const int vert_padding = (kTileSize - title_size.height() - kIconSize) / 2;
- rect.Inset(horiz_padding, vert_padding);
- }
-
- icon_->SetBounds(rect.x(), rect.y(),
- rect.width(), rect.height() - title_size.height());
- title_->SetBounds(rect.x(), rect.bottom() - title_size.height(),
- rect.width(), title_size.height());
-}
+ int preferred_icon_size = rect.height() - kIconPadding * 2;
+ gfx::Size icon_size(preferred_icon_size, preferred_icon_size);
-void AppListItemView::OnFocus() {
- View::OnFocus();
-
- gfx::Size icon_size = icon_->GetPreferredSize();
- icon_size.set_width(icon_size.width() * kFocusedScale);
- icon_size.set_height(icon_size.height() * kFocusedScale);
-
- gfx::Size max_size = GetPreferredSize();
- if (icon_size.width() > max_size.width() ||
- icon_size.height() > max_size.height()) {
- double aspect =
- static_cast<double>(icon_size.width()) / icon_size.height();
-
- if (aspect > 1) {
- icon_size.set_width(max_size.width());
- icon_size.set_height(icon_size.width() / aspect);
- } else {
- icon_size.set_height(max_size.height());
- icon_size.set_width(icon_size.height() * aspect);
- }
- }
+ gfx::Size title_size = title_->GetPreferredSize();
icon_->SetImageSize(icon_size);
- Layout();
-
- AppListItemGroupView* group_view =
- static_cast<AppListItemGroupView*>(parent());
- group_view->UpdateFocusedTile(this);
-}
+ icon_->SetBounds(rect.x(), rect.y(),
+ icon_size.width(), rect.height());
-void AppListItemView::OnBlur() {
- icon_->ResetImageSize();
- Layout();
- SchedulePaint();
+ title_->SetBounds(rect.x() + icon_size.width() + kIconTitleSpacing,
+ rect.y(),
+ rect.width() - icon_size.width() - kIconTitleSpacing,
+ rect.height());
}
-bool AppListItemView::OnKeyPressed(const views::KeyEvent& event) {
- if (event.key_code() == ui::VKEY_RETURN) {
- NotifyActivated(event.flags());
- return true;
+void AppListItemView::OnPaint(gfx::Canvas* canvas) {
+ gfx::Rect rect(GetContentsBounds());
+ if (hover_animation_->is_animating()) {
+ int alpha = SkColorGetA(kHoverColor) * hover_animation_->GetCurrentValue();
+ canvas->FillRect(rect, SkColorSetA(kHoverColor, alpha));
+ } else if (state() == BS_HOT) {
+ canvas->FillRect(rect, kHoverColor);
}
-
- return false;
-}
-
-bool AppListItemView::OnMousePressed(const views::MouseEvent& event) {
- views::View* hit_view = GetEventHandlerForPoint(event.location());
- bool hit = hit_view != this;
- if (hit)
- RequestFocus();
-
- return hit;
-}
-
-void AppListItemView::OnMouseReleased(const views::MouseEvent& event) {
- views::View* hit_view = GetEventHandlerForPoint(event.location());
- if (hit_view != this)
- NotifyActivated(event.flags());
-}
-
-void AppListItemView::OnPaintFocusBorder(gfx::Canvas* canvas) {
- // No focus border for AppListItemView.
}
} // namespace ash
« no previous file with comments | « ash/app_list/app_list_item_view.h ('k') | ash/app_list/app_list_item_view_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698