Commit ce2ea780 authored by mukai@chromium.org's avatar mukai@chromium.org

Redesign the home card bottom state.

This CL also renames the class name to AthenaStartPageView
and I am expecting to use the same view to CENTERED state,
so that we can achieve the smooth state transition meanwhile.

BUG=401570
R=sadrul@chromium.org
TEST=manually

Review URL: https://codereview.chromium.org/473623002

Cr-Commit-Position: refs/heads/master@{#289690}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289690 0039d316-1c4b-4281-b951-d872f2087c98
parent 3e305903
...@@ -48,8 +48,8 @@ ...@@ -48,8 +48,8 @@
'common/switches.h', 'common/switches.h',
'home/app_list_view_delegate.cc', 'home/app_list_view_delegate.cc',
'home/app_list_view_delegate.h', 'home/app_list_view_delegate.h',
'home/bottom_home_view.cc', 'home/athena_start_page_view.cc',
'home/bottom_home_view.h', 'home/athena_start_page_view.h',
'home/home_card_impl.cc', 'home/home_card_impl.cc',
'home/minimized_home.cc', 'home/minimized_home.cc',
'home/minimized_home.h', 'home/minimized_home.h',
......
// 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 "athena/home/athena_start_page_view.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/app_list/app_list_item.h"
#include "ui/app_list/app_list_item_list.h"
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/gfx/canvas.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/round_rect_painter.h"
namespace {
const size_t kMaxIconNum = 3;
const int kIconSize = 50;
const int kIconMargin = 25;
const int kBorderWidth = 1;
const int kCornerRadius = 1;
// The preferred height for VISIBLE_BOTTOM state.
const int kPreferredHeightBottom = 100;
class PlaceHolderButton : public views::ImageButton,
public views::ButtonListener {
public:
PlaceHolderButton()
: ImageButton(this) {
gfx::Canvas canvas(gfx::Size(kIconSize, kIconSize), 1.0f, true);
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(SkColorSetRGB(86, 119, 252));
paint.setFlags(SkPaint::kAntiAlias_Flag);
canvas.DrawCircle(
gfx::Point(kIconSize / 2, kIconSize / 2), kIconSize / 2, paint);
scoped_ptr<gfx::ImageSkia> image(
new gfx::ImageSkia(canvas.ExtractImageRep()));
SetImage(STATE_NORMAL, image.get());
}
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE {
// Do nothing: remove these place holders.
}
DISALLOW_COPY_AND_ASSIGN(PlaceHolderButton);
};
class AppIconButton : public views::ImageButton,
public views::ButtonListener {
public:
explicit AppIconButton(app_list::AppListItem* item)
: ImageButton(this),
item_(item) {
// TODO(mukai): icon should be resized.
SetImage(STATE_NORMAL, &item->icon());
}
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE {
DCHECK_EQ(sender, this);
item_->Activate(event.flags());
}
app_list::AppListItem* item_;
DISALLOW_COPY_AND_ASSIGN(AppIconButton);
};
// The background to paint the round rectangle of the view area.
class RoundRectBackground : public views::Background {
public:
RoundRectBackground(SkColor color, int corner_radius)
: color_(color),
corner_radius_(corner_radius) {}
virtual ~RoundRectBackground() {}
private:
// views::Background:
virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(color_);
canvas->DrawRoundRect(view->GetContentsBounds(), corner_radius_, paint);
}
SkColor color_;
int corner_radius_;
DISALLOW_COPY_AND_ASSIGN(RoundRectBackground);
};
} // namespace
namespace athena {
AthenaStartPageView::AthenaStartPageView(
app_list::AppListViewDelegate* view_delegate) {
app_list::AppListItemList* top_level =
view_delegate->GetModel()->top_level_item_list();
container_ = new views::View();
AddChildView(container_);
views::BoxLayout* box_layout = new views::BoxLayout(
views::BoxLayout::kHorizontal, kIconMargin, kIconMargin, kIconMargin);
box_layout->set_main_axis_alignment(
views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
box_layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
container_->SetLayoutManager(box_layout);
for (size_t i = 0; i < std::min(top_level->item_count(), kMaxIconNum); ++i)
container_->AddChildView(new AppIconButton(top_level->item_at(i)));
views::View* search_box_container = new views::View();
search_box_container->set_background(
new RoundRectBackground(SK_ColorWHITE, kCornerRadius));
search_box_container->SetBorder(views::Border::CreateBorderPainter(
new views::RoundRectPainter(SK_ColorGRAY, kCornerRadius),
gfx::Insets(kBorderWidth, kBorderWidth, kBorderWidth, kBorderWidth)));
search_box_container->SetLayoutManager(new views::FillLayout());
search_box_container->AddChildView(
new app_list::SearchBoxView(this, view_delegate));
container_->AddChildView(search_box_container);
box_layout->SetFlexForView(search_box_container, 1);
for (size_t i = 0; i < kMaxIconNum; ++i)
container_->AddChildView(new PlaceHolderButton());
set_background(views::Background::CreateSolidBackground(
255, 255, 255, 255 * 0.9));
}
AthenaStartPageView::~AthenaStartPageView() {}
void AthenaStartPageView::Layout() {
gfx::Rect container_bounds = bounds();
container_bounds.set_height(kPreferredHeightBottom);
container_->SetBoundsRect(container_bounds);
}
void AthenaStartPageView::QueryChanged(app_list::SearchBoxView* sender) {
// Nothing needs to be done.
}
} // namespace athena
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef ATHENA_HOME_BOTTOM_HOME_VIEW_H_ #ifndef ATHENA_HOME_ATHENA_START_PAGE_VIEW_H_
#define ATHENA_HOME_BOTTOM_HOME_VIEW_H_ #define ATHENA_HOME_ATHENA_START_PAGE_VIEW_H_
#include "athena/home/public/home_card.h"
#include "ui/app_list/views/search_box_view_delegate.h" #include "ui/app_list/views/search_box_view_delegate.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -14,23 +15,26 @@ class AppListViewDelegate; ...@@ -14,23 +15,26 @@ class AppListViewDelegate;
namespace athena { namespace athena {
// The view of 'VISIBLE_BOTTOM' state of home card, which occupies // It will replace app_list::StartPageView in Athena UI in the future.
// smaller area and provides limited functionalities. // Right now it's simply used for VISIBLE_BOTTOM state.
class BottomHomeView : public views::View, class AthenaStartPageView : public views::View,
public app_list::SearchBoxViewDelegate { public app_list::SearchBoxViewDelegate {
public: public:
explicit BottomHomeView(app_list::AppListViewDelegate* delegate); explicit AthenaStartPageView(app_list::AppListViewDelegate* delegate);
virtual ~BottomHomeView(); virtual ~AthenaStartPageView();
private: private:
// Overridden from app_list::SearchBoxViewDelegate: // views::View:
virtual void Layout() OVERRIDE;
// app_list::SearchBoxViewDelegate:
virtual void QueryChanged(app_list::SearchBoxView* sender) OVERRIDE; virtual void QueryChanged(app_list::SearchBoxView* sender) OVERRIDE;
app_list::AppListViewDelegate* view_delegate_; views::View* container_;
DISALLOW_COPY_AND_ASSIGN(BottomHomeView); DISALLOW_COPY_AND_ASSIGN(AthenaStartPageView);
}; };
} // namespace athena } // namespace athena
#endif // ATHENA_HOME_BOTTOM_HOME_VIEW_H_ #endif // ATHENA_HOME_ATHENA_START_PAGE_VIEW_H_
// 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 "athena/home/bottom_home_view.h"
#include "ui/app_list/app_list_item_list.h"
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/app_list/views/tile_item_view.h"
#include "ui/gfx/canvas.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/painter.h"
#include "ui/views/shadow_border.h"
namespace {
class BottomHomeBackground : public views::Background {
public:
explicit BottomHomeBackground(views::View* search_box)
: search_box_(search_box),
painter_(views::Painter::CreateVerticalGradient(
SkColorSetA(SK_ColorWHITE, 0x7f),
SK_ColorWHITE)) {}
virtual ~BottomHomeBackground() {}
private:
// views::Background:
virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
CHECK_EQ(view, search_box_->parent());
views::Painter::PaintPainterAt(
canvas,
painter_.get(),
gfx::Rect(0, 0, view->width(), search_box_->y()));
canvas->FillRect(gfx::Rect(0,
search_box_->y(),
view->width(),
view->height() - search_box_->y()),
SK_ColorWHITE);
}
views::View* search_box_;
scoped_ptr<views::Painter> painter_;
DISALLOW_COPY_AND_ASSIGN(BottomHomeBackground);
};
} // namespace
namespace athena {
BottomHomeView::BottomHomeView(app_list::AppListViewDelegate* view_delegate)
: view_delegate_(view_delegate) {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
app_list::AppListModel* model = view_delegate->GetModel();
app_list::AppListItemList* top_level = model->top_level_item_list();
views::View* items_container = new views::View();
AddChildView(items_container);
views::BoxLayout* items_layout = new views::BoxLayout(
views::BoxLayout::kHorizontal, 0, 0, 0);
items_layout->SetDefaultFlex(1);
items_container->SetLayoutManager(items_layout);
for (size_t i = 0; i < top_level->item_count(); ++i) {
app_list::TileItemView* tile_item_view = new app_list::TileItemView();
tile_item_view->SetAppListItem(top_level->item_at(i));
items_container->AddChildView(tile_item_view);
tile_item_view->set_background(NULL);
}
app_list::SearchBoxView* search_box = new app_list::SearchBoxView(
this, view_delegate);
AddChildView(search_box);
search_box->SetBorder(
views::Border::CreateSolidSidedBorder(1, 0, 0, 0, SK_ColorGRAY));
set_background(new BottomHomeBackground(search_box));
}
BottomHomeView::~BottomHomeView() {}
void BottomHomeView::QueryChanged(app_list::SearchBoxView* sender) {
// Nothing needs to be done.
}
} // namespace athena
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "athena/common/container_priorities.h" #include "athena/common/container_priorities.h"
#include "athena/home/app_list_view_delegate.h" #include "athena/home/app_list_view_delegate.h"
#include "athena/home/bottom_home_view.h" #include "athena/home/athena_start_page_view.h"
#include "athena/home/minimized_home.h" #include "athena/home/minimized_home.h"
#include "athena/home/public/app_model_builder.h" #include "athena/home/public/app_model_builder.h"
#include "athena/input/public/accelerator_manager.h" #include "athena/input/public/accelerator_manager.h"
...@@ -36,12 +36,11 @@ namespace athena { ...@@ -36,12 +36,11 @@ namespace athena {
namespace { namespace {
HomeCard* instance = NULL; HomeCard* instance = NULL;
const int kHomeCardHeight = 100;
const int kHomeCardMinimizedHeight = 6;
gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds,
HomeCard::State state) { HomeCard::State state) {
const int kHomeCardHeight = 150;
const int kHomeCardMinimizedHeight = 8;
switch (state) { switch (state) {
case HomeCard::HIDDEN: case HomeCard::HIDDEN:
break; break;
...@@ -269,23 +268,50 @@ class HomeCardView : public views::WidgetDelegateView { ...@@ -269,23 +268,50 @@ class HomeCardView : public views::WidgetDelegateView {
aura::Window* container, aura::Window* container,
HomeCardGestureManager::Delegate* gesture_delegate) HomeCardGestureManager::Delegate* gesture_delegate)
: gesture_delegate_(gesture_delegate) { : gesture_delegate_(gesture_delegate) {
bottom_view_ = new BottomHomeView(view_delegate); bottom_view_ = new AthenaStartPageView(view_delegate);
AddChildView(bottom_view_); AddChildView(bottom_view_);
bottom_view_->SetPaintToLayer(true);
bottom_view_->layer()->SetFillsBoundsOpaquely(false);
main_view_ = new app_list::AppListMainView( main_view_ = new app_list::AppListMainView(
view_delegate, 0 /* initial_apps_page */, container); view_delegate, 0 /* initial_apps_page */, container);
AddChildView(main_view_); AddChildView(main_view_);
main_view_->set_background( main_view_->set_background(
views::Background::CreateSolidBackground(SK_ColorWHITE)); views::Background::CreateSolidBackground(SK_ColorWHITE));
main_view_->SetPaintToLayer(true);
minimized_view_ = CreateMinimizedHome(); minimized_view_ = CreateMinimizedHome();
minimized_view_->SetPaintToLayer(true);
AddChildView(minimized_view_); AddChildView(minimized_view_);
} }
void SetStateProgress(HomeCard::State from_state,
HomeCard::State to_state,
float progress) {
if (from_state == HomeCard::VISIBLE_BOTTOM &&
to_state == HomeCard::VISIBLE_MINIMIZED) {
SetStateProgress(to_state, from_state, 1.0 - progress);
return;
}
// View from minimized to bottom.
if (from_state == HomeCard::VISIBLE_MINIMIZED &&
to_state == HomeCard::VISIBLE_BOTTOM) {
bottom_view_->SetVisible(true);
minimized_view_->SetVisible(true);
minimized_view_->layer()->SetOpacity(1.0f - progress);
return;
}
SetState(to_state);
}
void SetState(HomeCard::State state) { void SetState(HomeCard::State state) {
bottom_view_->SetVisible(state == HomeCard::VISIBLE_BOTTOM); bottom_view_->SetVisible(state == HomeCard::VISIBLE_BOTTOM);
main_view_->SetVisible(state == HomeCard::VISIBLE_CENTERED); main_view_->SetVisible(state == HomeCard::VISIBLE_CENTERED);
minimized_view_->SetVisible(state == HomeCard::VISIBLE_MINIMIZED); minimized_view_->SetVisible(state == HomeCard::VISIBLE_MINIMIZED);
if (minimized_view_->visible())
minimized_view_->layer()->SetOpacity(1.0f);
if (state == HomeCard::VISIBLE_CENTERED) { if (state == HomeCard::VISIBLE_CENTERED) {
app_list::ContentsView* contents_view = main_view_->contents_view(); app_list::ContentsView* contents_view = main_view_->contents_view();
contents_view->SetActivePage(contents_view->GetPageIndexForNamedPage( contents_view->SetActivePage(contents_view->GetPageIndexForNamedPage(
...@@ -306,13 +332,16 @@ class HomeCardView : public views::WidgetDelegateView { ...@@ -306,13 +332,16 @@ class HomeCardView : public views::WidgetDelegateView {
for (int i = 0; i < child_count(); ++i) { for (int i = 0; i < child_count(); ++i) {
views::View* child = child_at(i); views::View* child = child_at(i);
if (child->visible()) { if (child->visible()) {
child->SetBoundsRect(bounds()); if (child == minimized_view_) {
return; gfx::Rect minimized_bounds = bounds();
minimized_bounds.set_y(
minimized_bounds.bottom() - kHomeCardMinimizedHeight);
child->SetBoundsRect(minimized_bounds);
} else {
child->SetBoundsRect(bounds());
}
} }
} }
// One of the child views has to be visible.
NOTREACHED();
} }
virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
if (!gesture_manager_ && if (!gesture_manager_ &&
...@@ -332,7 +361,7 @@ class HomeCardView : public views::WidgetDelegateView { ...@@ -332,7 +361,7 @@ class HomeCardView : public views::WidgetDelegateView {
} }
app_list::AppListMainView* main_view_; app_list::AppListMainView* main_view_;
BottomHomeView* bottom_view_; views::View* bottom_view_;
views::View* minimized_view_; views::View* minimized_view_;
scoped_ptr<HomeCardGestureManager> gesture_manager_; scoped_ptr<HomeCardGestureManager> gesture_manager_;
HomeCardGestureManager::Delegate* gesture_delegate_; HomeCardGestureManager::Delegate* gesture_delegate_;
...@@ -547,9 +576,7 @@ void HomeCardImpl::OnGestureEnded(State final_state) { ...@@ -547,9 +576,7 @@ void HomeCardImpl::OnGestureEnded(State final_state) {
void HomeCardImpl::OnGestureProgressed( void HomeCardImpl::OnGestureProgressed(
State from_state, State to_state, float progress) { State from_state, State to_state, float progress) {
// Do not update |state_| but update the look of home_card_view. home_card_view_->SetStateProgress(from_state, to_state, progress);
// TODO(mukai): allow mixed visual of |from_state| and |to_state|.
home_card_view_->SetState(to_state);
gfx::Rect screen_bounds = gfx::Rect screen_bounds =
home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds(); home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment