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

Replace the HomeCard by the AppList in Athena (2nd)

This is a reland of https://codereview.chromium.org/306083005/.
That was reverted because it implicitly added a dependency on
content from athena_shell.

This is identical to the original CL but still safe because
the dependency issue has been fixed already.

BUG=370204
TBR=oshima@chromium.org, benwells@chromium.org, reed@google.com
TEST=manually

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275373 0039d316-1c4b-4281-b951-d872f2087c98
parent dcd31ce4
......@@ -12,6 +12,7 @@
'type': '<(component)',
'dependencies': [
'../ui/aura/aura.gyp:aura',
'../ui/app_list/app_list.gyp:app_list',
'../ui/views/views.gyp:views',
'../ui/accessibility/accessibility.gyp:ax_gen',
'../skia/skia.gyp:skia',
......@@ -31,8 +32,8 @@
'activity/public/activity_view_manager.h',
'activity/public/activity_view_model.h',
'athena_export.h',
'home/home_card_delegate_view.cc',
'home/home_card_delegate_view.h',
'home/app_list_view_delegate.cc',
'home/app_list_view_delegate.h',
'home/home_card_impl.cc',
'home/public/home_card.h',
'screen/background_controller.cc',
......
include_rules = [
"+athena/screen/public",
"+third_party/skia/include",
"+ui/aura",
"+ui/app_list",
"+ui/gfx/image",
"+ui/views",
"+ui/wm/core",
]
// 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/app_list_view_delegate.h"
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkBitmap.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/search_box_model.h"
#include "ui/app_list/search_result.h"
#include "ui/app_list/speech_ui_model.h"
#include "ui/gfx/image/image_skia.h"
namespace athena {
namespace {
const int kIconSize = 64;
class DummyItem : public app_list::AppListItem {
public:
enum Type {
DUMMY_MAIL,
DUMMY_CALENDAR,
DUMMY_VIDEO,
DUMMY_MUSIC,
DUMMY_CONTACT,
LAST_TYPE,
};
static std::string GetTitle(Type type) {
switch (type) {
case DUMMY_MAIL:
return "mail";
case DUMMY_CALENDAR:
return "calendar";
case DUMMY_VIDEO:
return "video";
case DUMMY_MUSIC:
return "music";
case DUMMY_CONTACT:
return "contact";
case LAST_TYPE:
break;
}
NOTREACHED();
return "";
}
static std::string GetId(Type type) {
return std::string("id-") + GetTitle(type);
}
explicit DummyItem(Type type)
: app_list::AppListItem(GetId(type)),
type_(type) {
SetIcon(GetIcon(), false /* has_shadow */);
SetName(GetTitle(type_));
}
private:
gfx::ImageSkia GetIcon() const {
SkColor color = SK_ColorWHITE;
switch (type_) {
case DUMMY_MAIL:
color = SK_ColorRED;
break;
case DUMMY_CALENDAR:
color = SK_ColorBLUE;
break;
case DUMMY_VIDEO:
color = SK_ColorGREEN;
break;
case DUMMY_MUSIC:
color = SK_ColorYELLOW;
break;
case DUMMY_CONTACT:
color = SK_ColorCYAN;
break;
case LAST_TYPE:
NOTREACHED();
break;
}
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize);
bitmap.allocPixels();
bitmap.eraseColor(color);
return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
}
Type type_;
DISALLOW_COPY_AND_ASSIGN(DummyItem);
};
} // namespace
AppListViewDelegate::AppListViewDelegate()
: model_(new app_list::AppListModel),
speech_ui_(new app_list::SpeechUIModel(
app_list::SPEECH_RECOGNITION_OFF)) {
PopulateApps();
// TODO(mukai): get the text from the resources.
model_->search_box()->SetHintText(base::ASCIIToUTF16("Search"));
}
AppListViewDelegate::~AppListViewDelegate() {
}
void AppListViewDelegate::PopulateApps() {
for (int i = 0; i < static_cast<int>(DummyItem::LAST_TYPE); ++i) {
model_->AddItem(scoped_ptr<app_list::AppListItem>(
new DummyItem(static_cast<DummyItem::Type>(i))));
}
}
bool AppListViewDelegate::ForceNativeDesktop() const {
return false;
}
void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) {
// Nothing needs to be done.
}
app_list::AppListModel* AppListViewDelegate::GetModel() {
return model_.get();
}
app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() {
return speech_ui_.get();
}
void AppListViewDelegate::GetShortcutPathForApp(
const std::string& app_id,
const base::Callback<void(const base::FilePath&)>& callback) {
// Windows only, nothing is necessary.
}
void AppListViewDelegate::StartSearch() {
// TODO(mukai): implement this.
}
void AppListViewDelegate::StopSearch() {
// TODO(mukai): implement this.
}
void AppListViewDelegate::OpenSearchResult(app_list::SearchResult* result,
bool auto_launch,
int event_flags) {
// TODO(mukai): implement this.
}
void AppListViewDelegate::InvokeSearchResultAction(
app_list::SearchResult* result,
int action_index,
int event_flags) {
// TODO(mukai): implement this.
}
base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() {
// Used by voice search, nothing needs to be done for now.
return base::TimeDelta();
}
void AppListViewDelegate::AutoLaunchCanceled() {
// Used by voice search, nothing needs to be done for now.
}
void AppListViewDelegate::ViewInitialized() {
// Nothing needs to be done.
}
void AppListViewDelegate::Dismiss() {
// Nothing needs to be done.
}
void AppListViewDelegate::ViewClosing() {
// Nothing needs to be done.
}
gfx::ImageSkia AppListViewDelegate::GetWindowIcon() {
return gfx::ImageSkia();
}
void AppListViewDelegate::OpenSettings() {
// Nothing needs to be done for now.
// TODO(mukai): should invoke the settings app.
}
void AppListViewDelegate::OpenHelp() {
// Nothing needs to be done for now.
// TODO(mukai): should invoke the help app.
}
void AppListViewDelegate::OpenFeedback() {
// Nothing needs to be done for now.
// TODO(mukai): should invoke the feedback app.
}
void AppListViewDelegate::ToggleSpeechRecognition() {
// Nothing needs to be done.
}
void AppListViewDelegate::ShowForProfileByPath(
const base::FilePath& profile_path) {
// Nothing needs to be done.
}
views::View* AppListViewDelegate::CreateStartPageWebView(
const gfx::Size& size) {
return NULL;
}
bool AppListViewDelegate::IsSpeechRecognitionEnabled() {
return false;
}
const app_list::AppListViewDelegate::Users&
AppListViewDelegate::GetUsers() const {
return users_;
}
bool AppListViewDelegate::ShouldCenterWindow() const {
return true;
}
} // namespace athena
// 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.
#ifndef ATHENA_HOME_APP_LIST_VIEW_DELEGATE_H_
#define ATHENA_HOME_APP_LIST_VIEW_DELEGATE_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "ui/app_list/app_list_view_delegate.h"
namespace athena {
class AppListViewDelegate : public app_list::AppListViewDelegate {
public:
AppListViewDelegate();
virtual ~AppListViewDelegate();
private:
void PopulateApps();
// Overridden from app_list::AppListViewDelegate:
virtual bool ForceNativeDesktop() const OVERRIDE;
virtual void SetProfileByPath(const base::FilePath& profile_path) OVERRIDE;
virtual app_list::AppListModel* GetModel() OVERRIDE;
virtual app_list::SpeechUIModel* GetSpeechUI() OVERRIDE;
virtual void GetShortcutPathForApp(
const std::string& app_id,
const base::Callback<void(const base::FilePath&)>& callback) OVERRIDE;
virtual void StartSearch() OVERRIDE;
virtual void StopSearch() OVERRIDE;
virtual void OpenSearchResult(app_list::SearchResult* result,
bool auto_launch,
int event_flags) OVERRIDE;
virtual void InvokeSearchResultAction(app_list::SearchResult* result,
int action_index,
int event_flags) OVERRIDE;
virtual base::TimeDelta GetAutoLaunchTimeout() OVERRIDE;
virtual void AutoLaunchCanceled() OVERRIDE;
virtual void ViewInitialized() OVERRIDE;
virtual void Dismiss() OVERRIDE;
virtual void ViewClosing() OVERRIDE;
virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
virtual void OpenSettings() OVERRIDE;
virtual void OpenHelp() OVERRIDE;
virtual void OpenFeedback() OVERRIDE;
virtual void ToggleSpeechRecognition() OVERRIDE;
virtual void ShowForProfileByPath(
const base::FilePath& profile_path) OVERRIDE;
virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE;
virtual bool IsSpeechRecognitionEnabled() OVERRIDE;
virtual const Users& GetUsers() const OVERRIDE;
virtual bool ShouldCenterWindow() const OVERRIDE;
scoped_ptr<app_list::AppListModel> model_;
scoped_ptr<app_list::SpeechUIModel> speech_ui_;
Users users_;
DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
};
} // namespace athena
#endif // ATHENA_HOME_APP_LIST_VIEW_DELEGATE_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/home_card_delegate_view.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/widget/widget.h"
namespace athena {
HomeCardDelegateView::HomeCardDelegateView() {
const SkColor kHomeTopColor = 0xDDFFFFFF;
const SkColor kHomeBottomColor = 0xAAEEEEEE;
const SkColor kHomeBorderColor = 0xDDFFFFFF;
set_background(views::Background::CreateVerticalGradientBackground(
kHomeTopColor, kHomeBottomColor));
scoped_ptr<views::Border> border(
views::Border::CreateSolidBorder(5, kHomeBorderColor));
SetBorder(border.Pass());
}
HomeCardDelegateView::~HomeCardDelegateView() {
}
void HomeCardDelegateView::OnMouseEvent(ui::MouseEvent* event) {
// Temp code to test animation.
if (event->type() == ui::ET_MOUSE_PRESSED) {
views::Widget* widget = GetWidget();
if (widget->IsVisible())
widget->Hide();
}
}
void HomeCardDelegateView::DeleteDelegate() {
delete this;
}
views::Widget* HomeCardDelegateView::GetWidget() {
return views::View::GetWidget();
}
const views::Widget* HomeCardDelegateView::GetWidget() const {
return views::View::GetWidget();
}
views::View* HomeCardDelegateView::GetContentsView() {
return this;
}
} // namespace athena
// 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.
#ifndef ATHENA_HOME_HOME_CARD_DELEGATE_VIEW_H_
#define ATHENA_HOME_HOME_CARD_DELEGATE_VIEW_H_
#include "ui/views/view.h"
#include "ui/views/widget/widget_delegate.h"
namespace athena {
class HomeCardDelegateView : public views::WidgetDelegate, public views::View {
public:
HomeCardDelegateView();
virtual ~HomeCardDelegateView();
private:
// views::View
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
// views::WidgetDelegate:
virtual void DeleteDelegate() OVERRIDE;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
virtual views::View* GetContentsView() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(HomeCardDelegateView);
};
} // namespace athena
#endif // ATHENA_HOME_HOME_CARD_DELEGATE_VIEW_H_
......@@ -4,11 +4,12 @@
#include "athena/home/public/home_card.h"
#include "athena/home/home_card_delegate_view.h"
#include "athena/home/app_list_view_delegate.h"
#include "athena/screen/public/screen_manager.h"
#include "ui/app_list/pagination_model.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/visibility_controller.h"
#include "ui/wm/core/window_animations.h"
......@@ -41,8 +42,12 @@ class HomeCardLayoutManager : public aura::LayoutManager {
}
void Layout() {
const int kHomeCardHeight = 50;
const int kHomeCardHeight = 150;
const int kHomeCardHorizontalMargin = 50;
// Currently the home card is provided as a bubble and the bounds has to be
// increased to cancel the shadow.
// TODO(mukai): stops using the bubble and remove this.
const int kHomeCardShadowWidth = 30;
if (container_->children().size() < 1)
return;
aura::Window* home_card = container_->children()[0];
......@@ -54,6 +59,7 @@ class HomeCardLayoutManager : public aura::LayoutManager {
screen_bounds.height() - kHomeCardHeight,
kHomeCardHorizontalMargin,
0);
card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth);
SetChildBoundsDirect(home_card, card_bounds);
}
......@@ -75,7 +81,8 @@ class HomeCardImpl : public HomeCard {
DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
};
HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) {
HomeCardImpl::HomeCardImpl()
: home_card_widget_(NULL) {
DCHECK(!instance);
instance = this;
}
......@@ -92,23 +99,16 @@ void HomeCardImpl::Init() {
container->SetLayoutManager(new HomeCardLayoutManager(container));
wm::SetChildWindowVisibilityChangesAnimated(container);
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.delegate = new HomeCardDelegateView();
params.parent = container;
home_card_widget_ = new views::Widget;
home_card_widget_->Init(params);
home_card_widget_->GetNativeView()->SetName("HomeCardWidget");
aura::Window* home_card_window = home_card_widget_->GetNativeView();
wm::SetWindowVisibilityAnimationType(
home_card_window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
wm::SetWindowVisibilityAnimationTransition(home_card_window,
wm::ANIMATE_BOTH);
home_card_widget_->Show();
app_list::AppListView* view = new app_list::AppListView(
new AppListViewDelegate);
view->InitAsBubbleAtFixedLocation(
container,
0 /* initial_apps_page */,
gfx::Point(),
views::BubbleBorder::FLOAT,
true /* border_accepts_events */);
home_card_widget_ = view->GetWidget();
view->ShowWhenReady();
}
} // namespace
......
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