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

Unified Diff: ui/aura_shell/app_list/tile_view.cc

Issue 8890049: [Aura] Implement views-based applist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and refactored Created 9 years 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
Index: ui/aura_shell/app_list/tile_view.cc
diff --git a/ui/aura_shell/app_list/tile_view.cc b/ui/aura_shell/app_list/tile_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..82bb2d4501508617eab26b9fc9662478f2c60907
--- /dev/null
+++ b/ui/aura_shell/app_list/tile_view.cc
@@ -0,0 +1,162 @@
+// Copyright (c) 2011 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/aura_shell/app_list/tile_view.h"
+
+#include "base/utf_string_conversions.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/font.h"
+#include "ui/aura_shell/app_list/app_list_view.h"
+#include "ui/aura_shell/app_list/app_list_item_model.h"
+#include "ui/aura_shell/app_list/drop_shadow_label.h"
+#include "ui/aura_shell/app_list/tiles_page_view.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/widget/widget.h"
+#include "third_party/skia/include/core/SkColor.h"
+
+namespace aura_shell {
+
+namespace {
+
+const double kFocusedScale = 1.1;
+
+// TitleLabel for a TileView.
+class TitleLabel : public DropShadowLabel {
+ public:
+ TitleLabel() {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ SetFont(rb.GetFont(ResourceBundle::BaseFont).DeriveFont(
+ 2, gfx::Font::BOLD));
+ SetBackgroundColor(0);
+ SetEnabledColor(SK_ColorWHITE);
+ }
+
+ virtual ~TitleLabel() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TitleLabel);
+};
+
+} // namespace
+
+TileView::TileView(AppListItemModel* model)
+ : model_(model),
+ icon_(new views::ImageView),
+ label_(new TitleLabel) {
+ set_focusable(true);
+
+ AddChildView(icon_);
+ ItemIconChanged();
+
+ AddChildView(label_);
+ ItemTitleChanged();
+
+ model_->AddObserver(this);
+}
+
+TileView::~TileView() {
+ model_->RemoveObserver(this);
+}
+
+void TileView::ItemIconChanged() {
+ icon_->SetImage(model_->icon());
+}
+
+void TileView::ItemTitleChanged() {
+ label_->SetText(UTF8ToUTF16(model_->title()));
+}
+
+void TileView::Activate(int event_flags) {
+ model_->Activate(event_flags);
+ static_cast<AppListView*>(GetWidget()->widget_delegate())->Close();
+}
+
+gfx::Size TileView::GetPreferredSize() {
+ return gfx::Size(kTileSize, kTileSize);
+}
+
+void TileView::Layout() {
+ gfx::Rect rect(GetContentsBounds());
+
+ gfx::Size title_size = label_->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());
+
+ label_->SetBounds(rect.x(), rect.bottom() - title_size.height(),
+ rect.width(), title_size.height());
+}
+
+void TileView::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);
+ }
+ }
+
+ icon_->SetImageSize(icon_size);
+ Layout();
+
+ TilesPageView* tiles_page = static_cast<TilesPageView*>(parent());
+ tiles_page->UpdateFocusedTile(this);
+
+ View::OnFocus();
+}
+
+void TileView::OnBlur() {
+ icon_->ResetImageSize();
+ Layout();
+ SchedulePaint();
+}
+
+bool TileView::OnKeyPressed(const views::KeyEvent& event) {
+ if (event.key_code() == ui::VKEY_RETURN) {
+ Activate(event.flags());
+ return true;
+ }
+
+ return false;
+}
+
+bool TileView::OnMousePressed(const views::MouseEvent& event) {
+ views::View* hit_view = GetEventHandlerForPoint(event.location());
+ bool hit = hit_view != this;
+ if (hit)
+ RequestFocus();
+
+ return hit;
+}
+
+void TileView::OnMouseReleased(const views::MouseEvent& event) {
+ views::View* hit_view = GetEventHandlerForPoint(event.location());
+ if (hit_view != this)
+ Activate(event.flags());
+}
+
+void TileView::OnPaintFocusBorder(gfx::Canvas* canvas) {
+ // No focus border for TileView.
+}
+
+} // namespace aura_shell

Powered by Google App Engine
This is Rietveld 408576698