Index: ui/app_list/views/tile_item_view.cc |
diff --git a/ui/app_list/views/tile_item_view.cc b/ui/app_list/views/tile_item_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..71073436b34ec2ec210d84964d0e9d77eb700688 |
--- /dev/null |
+++ b/ui/app_list/views/tile_item_view.cc |
@@ -0,0 +1,121 @@ |
+// Copyright 2014 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 "ui/app_list/views/tile_item_view.h" |
+ |
+#include "base/strings/utf_string_conversions.h" |
+#include "ui/app_list/app_list_constants.h" |
+#include "ui/app_list/app_list_item.h" |
+#include "ui/app_list/app_list_model.h" |
+#include "ui/app_list/app_list_view_delegate.h" |
+#include "ui/app_list/views/app_list_main_view.h" |
+#include "ui/gfx/canvas.h" |
+#include "ui/gfx/color_analysis.h" |
+#include "ui/gfx/color_utils.h" |
+#include "ui/views/background.h" |
+#include "ui/views/controls/image_view.h" |
+#include "ui/views/controls/label.h" |
+#include "ui/views/layout/box_layout.h" |
+ |
+namespace { |
+ |
+const int kTileSize = 90; |
+const SkColor kTileBackgroundColor = SK_ColorWHITE; |
+const SkColor kTileBorderColor = 0X80D0D0D0; |
tapted
2014/05/20 05:22:31
use SkColorSetARGB(0x80, 0xD0, 0xD0, 0xD0);
calamity
2014/05/22 03:31:16
Done.
|
+const int kTileColorStripHeight = 2; |
+const SkAlpha kTileColorStripOpacity = 0X5F; |
+const int kTileCornerRadius = 2; |
+ |
+// A background for the start page item view which consists of a rounded rect |
+// with a dominant color strip at the bottom. |
+class TileItemBackground : public views::Background { |
+ public: |
+ TileItemBackground() {} |
+ virtual ~TileItemBackground() {} |
+ |
+ void set_strip_color(SkColor strip_color) { strip_color_ = strip_color; } |
+ |
+ virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
tapted
2014/05/20 05:22:31
nit: // Overidden from views::Background::Paint:
calamity
2014/05/22 03:31:16
Done.
|
+ // Paint a rectangle for the color strip. |
+ SkPaint paint; |
+ paint.setColor(SkColorSetA(strip_color_, kTileColorStripOpacity)); |
+ paint.setFlags(SkPaint::kAntiAlias_Flag); |
+ canvas->DrawRoundRect(view->GetContentsBounds(), kTileCornerRadius, paint); |
tapted
2014/05/20 05:22:31
The tiles in the screenshot look a little glitchy
calamity
2014/05/22 03:31:16
Switched the border drawing to use fill rather tha
|
+ |
+ // Paint the main background rectangle, leaving part of the color strip |
+ // unobscured. |
+ gfx::Rect static_background_rect(view->GetContentsBounds()); |
+ static_background_rect.set_height(static_background_rect.height() - |
+ kTileColorStripHeight); |
+ paint.setColor(kTileBackgroundColor); |
+ canvas->DrawRoundRect(static_background_rect, kTileCornerRadius, paint); |
+ |
+ // Paint the border. |
+ paint.setColor(kTileBorderColor); |
+ paint.setStyle(SkPaint::kStroke_Style); |
+ canvas->DrawRoundRect(view->GetContentsBounds(), kTileCornerRadius, paint); |
+ } |
+ |
+ private: |
+ SkColor strip_color_; |
+}; |
tapted
2014/05/20 05:22:31
nit: DISALLOW_COPY_AND_ASSIGN(..)
calamity
2014/05/22 03:31:16
Done.
|
+ |
+} // namespace |
+ |
+namespace app_list { |
+ |
+TileItemView::TileItemView() |
+ : views::CustomButton(this), |
+ item_(NULL), |
+ icon_(new views::ImageView), |
tapted
2014/05/20 05:22:31
Does this need a drop-shadow to match the grid? Pr
calamity
2014/05/22 03:31:16
Unknown. Mocks don't have them.
|
+ title_(new views::Label), |
+ background_(new TileItemBackground()) { |
+ set_background(background_); |
+ |
+ views::BoxLayout* layout_manager = |
+ new views::BoxLayout(views::BoxLayout::kVertical, 10, 0, 0); |
+ layout_manager->set_main_axis_alignment( |
+ views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
+ SetLayoutManager(layout_manager); |
+ |
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
+ title_->SetAutoColorReadabilityEnabled(false); |
+ title_->SetEnabledColor(kGridTitleColor); |
+ title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); |
+ title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
tapted
2014/05/20 05:22:31
You should set set the background color on title_
tapted
2014/05/20 05:24:40
Actually, it looks like views can find an opaque b
|
+ |
+ AddChildView(icon_); |
+ AddChildView(title_); |
+} |
+ |
+TileItemView::~TileItemView() { |
+} |
+ |
+void TileItemView::SetAppListItem(AppListItem* item) { |
+ item_ = item; |
+ if (!item) { |
+ SetVisible(false); |
+ icon_->SetImage(NULL); |
+ title_->SetText(base::string16()); |
+ return; |
+ } |
+ |
+ SetVisible(true); |
+ icon_->SetImage(item_->icon()); |
+ title_->SetText(base::UTF8ToUTF16(item_->name())); |
+ |
+ background_->set_strip_color( |
+ color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap())); |
+} |
+ |
+gfx::Size TileItemView::GetPreferredSize() { |
+ return gfx::Size(kTileSize, kTileSize); |
+} |
+ |
+void TileItemView::ButtonPressed(views::Button* sender, |
+ const ui::Event& event) { |
+ item_->Activate(event.flags()); |
+} |
+ |
+} // namespace app_list |