summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorcalamity@chromium.org <calamity@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 10:49:50 +0000
committercalamity@chromium.org <calamity@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 10:49:50 +0000
commit09074b387c6f2394759ff903d5c685ab33d6f185 (patch)
treeab5f4ef4bea184040ff3f28aed10ab954261942b /ui
parentcdb76e5109a402145f92b7fe52d8fa92abc0a417 (diff)
downloadchromium_src-09074b387c6f2394759ff903d5c685ab33d6f185.zip
chromium_src-09074b387c6f2394759ff903d5c685ab33d6f185.tar.gz
chromium_src-09074b387c6f2394759ff903d5c685ab33d6f185.tar.bz2
Add a contents view switcher to the experimental app list.
This CL adds a switcher view to the bottom of the experimental app list with buttons that switch the currently displayed contents view. BUG= Review URL: https://codereview.chromium.org/174823002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254093 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/app_list/app_list.gyp2
-rw-r--r--ui/app_list/app_list_constants.cc2
-rw-r--r--ui/app_list/app_list_constants.h2
-rw-r--r--ui/app_list/app_list_switches.cc7
-rw-r--r--ui/app_list/app_list_switches.h2
-rw-r--r--ui/app_list/views/app_list_background.cc38
-rw-r--r--ui/app_list/views/app_list_main_view.cc4
-rw-r--r--ui/app_list/views/app_list_main_view.h2
-rw-r--r--ui/app_list/views/contents_switcher_view.cc98
-rw-r--r--ui/app_list/views/contents_switcher_view.h40
-rw-r--r--ui/app_list/views/contents_view.h13
11 files changed, 191 insertions, 19 deletions
diff --git a/ui/app_list/app_list.gyp b/ui/app_list/app_list.gyp
index 91e5bf4..f5aa616 100644
--- a/ui/app_list/app_list.gyp
+++ b/ui/app_list/app_list.gyp
@@ -105,6 +105,8 @@
'views/apps_grid_view_delegate.h',
'views/cached_label.cc',
'views/cached_label.h',
+ 'views/contents_switcher_view.cc',
+ 'views/contents_switcher_view.h',
'views/contents_view.cc',
'views/contents_view.h',
'views/folder_background_view.cc',
diff --git a/ui/app_list/app_list_constants.cc b/ui/app_list/app_list_constants.cc
index c34004a..08383f5 100644
--- a/ui/app_list/app_list_constants.cc
+++ b/ui/app_list/app_list_constants.cc
@@ -7,8 +7,10 @@
namespace app_list {
const SkColor kContentsBackgroundColor = SkColorSetRGB(0xFB, 0xFB, 0xFB);
+const SkColor kContentsSwitcherBackgroundColor = SK_ColorWHITE;
const SkColor kSearchBoxBackground = SK_ColorWHITE;
const SkColor kTopSeparatorColor = SkColorSetRGB(0xE5, 0xE5, 0xE5);
+const SkColor kBottomSeparatorColor = SkColorSetRGB(0xE5, 0xE5, 0xE5);
// 6% black over kContentsBackgroundColor
const SkColor kHighlightedColor = SkColorSetRGB(0xE6, 0xE6, 0xE6);
diff --git a/ui/app_list/app_list_constants.h b/ui/app_list/app_list_constants.h
index 6edb4fc..8245017 100644
--- a/ui/app_list/app_list_constants.h
+++ b/ui/app_list/app_list_constants.h
@@ -13,8 +13,10 @@
namespace app_list {
APP_LIST_EXPORT extern const SkColor kContentsBackgroundColor;
+APP_LIST_EXPORT extern const SkColor kContentsSwitcherBackgroundColor;
APP_LIST_EXPORT extern const SkColor kSearchBoxBackground;
APP_LIST_EXPORT extern const SkColor kTopSeparatorColor;
+APP_LIST_EXPORT extern const SkColor kBottomSeparatorColor;
APP_LIST_EXPORT extern const SkColor kHighlightedColor;
APP_LIST_EXPORT extern const SkColor kSelectedColor;
diff --git a/ui/app_list/app_list_switches.cc b/ui/app_list/app_list_switches.cc
index 211c754..bbc7d06 100644
--- a/ui/app_list/app_list_switches.cc
+++ b/ui/app_list/app_list_switches.cc
@@ -39,5 +39,10 @@ bool IsAppInfoEnabled() {
return CommandLine::ForCurrentProcess()->HasSwitch(kEnableAppInfo);
}
-} // namespcae switches
+bool IsExperimentalAppListEnabled() {
+ return CommandLine::ForCurrentProcess()->HasSwitch(
+ kEnableExperimentalAppList);
+}
+
+} // namespace switches
} // namespace app_list
diff --git a/ui/app_list/app_list_switches.h b/ui/app_list/app_list_switches.h
index 3e522c6..9b2b633 100644
--- a/ui/app_list/app_list_switches.h
+++ b/ui/app_list/app_list_switches.h
@@ -21,6 +21,8 @@ bool APP_LIST_EXPORT IsVoiceSearchEnabled();
bool APP_LIST_EXPORT IsAppInfoEnabled();
+bool APP_LIST_EXPORT IsExperimentalAppListEnabled();
+
} // namespace switches
} // namespace app_list
diff --git a/ui/app_list/views/app_list_background.cc b/ui/app_list/views/app_list_background.cc
index ad196f5..083f441 100644
--- a/ui/app_list/views/app_list_background.cc
+++ b/ui/app_list/views/app_list_background.cc
@@ -11,6 +11,7 @@
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/views/app_list_main_view.h"
+#include "ui/app_list/views/contents_view.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
@@ -23,6 +24,9 @@ namespace {
// Size of top separator between searchbox and grid view.
const int kTopSeparatorSize = 1;
+// Size of bottom separator between contents view and contents switcher.
+const int kBottomSeparatorSize = 1;
+
} // namespace
namespace app_list {
@@ -63,11 +67,11 @@ void AppListBackground::Paint(gfx::Canvas* canvas,
paint.setColor(kSearchBoxBackground);
canvas->DrawRect(search_box_rect, paint);
- gfx::Rect seperator_rect(search_box_rect);
- seperator_rect.set_y(seperator_rect.bottom());
- seperator_rect.set_height(kTopSeparatorSize);
- canvas->FillRect(seperator_rect, kTopSeparatorColor);
- contents_top = seperator_rect.bottom();
+ gfx::Rect separator_rect(search_box_rect);
+ separator_rect.set_y(separator_rect.bottom());
+ separator_rect.set_height(kTopSeparatorSize);
+ canvas->FillRect(separator_rect, kTopSeparatorColor);
+ contents_top = separator_rect.bottom();
}
gfx::Rect contents_rect(bounds.x(),
@@ -78,10 +82,26 @@ void AppListBackground::Paint(gfx::Canvas* canvas,
paint.setColor(kContentsBackgroundColor);
canvas->DrawRect(contents_rect, paint);
- // Draw a banner in the corner of the app list if it is the experimental app
- // list.
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- app_list::switches::kEnableExperimentalAppList)) {
+ if (app_list::switches::IsExperimentalAppListEnabled()) {
+ if (main_view_->visible()) {
+ views::View* contents_view = main_view_->contents_view();
+ const gfx::Rect contents_view_view_bounds =
+ contents_view->ConvertRectToWidget(contents_view->GetLocalBounds());
+ gfx::Rect separator_rect(contents_rect);
+ separator_rect.set_y(contents_view_view_bounds.bottom());
+ separator_rect.set_height(kBottomSeparatorSize);
+ canvas->FillRect(separator_rect, kBottomSeparatorColor);
+ int contents_switcher_top = separator_rect.bottom();
+ gfx::Rect contents_switcher_rect(bounds.x(),
+ contents_switcher_top,
+ bounds.width(),
+ bounds.bottom() - contents_switcher_top);
+ paint.setColor(kContentsSwitcherBackgroundColor);
+ canvas->DrawRect(contents_switcher_rect, paint);
+ }
+
+ // Draw a banner in the corner of the app list if it is the experimental app
+ // list.
const gfx::ImageSkia& experimental_icon =
*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_APP_LIST_EXPERIMENTAL_ICON);
diff --git a/ui/app_list/views/app_list_main_view.cc b/ui/app_list/views/app_list_main_view.cc
index b68cc26..ad5e2eb 100644
--- a/ui/app_list/views/app_list_main_view.cc
+++ b/ui/app_list/views/app_list_main_view.cc
@@ -15,10 +15,12 @@
#include "ui/app_list/app_list_folder_item.h"
#include "ui/app_list/app_list_item.h"
#include "ui/app_list/app_list_model.h"
+#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/app_list_view_delegate.h"
#include "ui/app_list/pagination_model.h"
#include "ui/app_list/search_box_model.h"
#include "ui/app_list/views/app_list_item_view.h"
+#include "ui/app_list/views/contents_switcher_view.h"
#include "ui/app_list/views/contents_view.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/views/controls/textfield/textfield.h"
@@ -97,6 +99,8 @@ AppListMainView::AppListMainView(AppListViewDelegate* delegate,
search_box_view_ = new SearchBoxView(this, delegate);
AddChildView(search_box_view_);
AddContentsView();
+ if (app_list::switches::IsExperimentalAppListEnabled())
+ AddChildView(new ContentsSwitcherView(contents_view_));
}
void AppListMainView::AddContentsView() {
diff --git a/ui/app_list/views/app_list_main_view.h b/ui/app_list/views/app_list_main_view.h
index d680476d..1d79cd5 100644
--- a/ui/app_list/views/app_list_main_view.h
+++ b/ui/app_list/views/app_list_main_view.h
@@ -58,7 +58,7 @@ class APP_LIST_EXPORT AppListMainView : public views::View,
void SetDragAndDropHostOfCurrentAppList(
ApplicationDragAndDropHost* drag_and_drop_host);
- ContentsView* contents_view() { return contents_view_; }
+ ContentsView* contents_view() const { return contents_view_; }
private:
class IconLoader;
diff --git a/ui/app_list/views/contents_switcher_view.cc b/ui/app_list/views/contents_switcher_view.cc
new file mode 100644
index 0000000..d931720
--- /dev/null
+++ b/ui/app_list/views/contents_switcher_view.cc
@@ -0,0 +1,98 @@
+// 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/contents_switcher_view.h"
+
+#include "ui/app_list/app_list_constants.h"
+#include "ui/app_list/views/contents_view.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/controls/button/custom_button.h"
+#include "ui/views/layout/box_layout.h"
+
+namespace app_list {
+
+namespace {
+
+const int kPreferredHeight = 36;
+
+const int kButtonSpacing = 4;
+const int kButtonWidth = 36;
+const int kButtonHeight = 36;
+
+class ContentsSwitcherButton : public views::CustomButton {
+ public:
+ explicit ContentsSwitcherButton(views::ButtonListener* listener,
+ ContentsView::ShowState show_state)
+ : views::CustomButton(listener) {
+ set_tag(show_state);
+ }
+
+ virtual ~ContentsSwitcherButton() {}
+
+ // Overridden from views::View:
+ virtual gfx::Size GetPreferredSize() OVERRIDE {
+ return gfx::Size(kButtonWidth, kButtonHeight);
+ }
+
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ PaintButton(
+ canvas,
+ state() == STATE_HOVERED ? kPagerHoverColor : kPagerNormalColor);
+ }
+
+ private:
+ // Paints a rectangular button.
+ void PaintButton(gfx::Canvas* canvas, SkColor base_color) {
+ gfx::Rect rect(GetContentsBounds());
+ rect.ClampToCenteredSize(gfx::Size(kButtonWidth, kButtonHeight));
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(base_color);
+ canvas->DrawRect(rect, paint);
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(ContentsSwitcherButton);
+};
+
+} // namespace
+
+ContentsSwitcherView::ContentsSwitcherView(ContentsView* contents_view)
+ : contents_view_(contents_view), buttons_(new views::View) {
+ AddChildView(buttons_);
+
+ buttons_->SetLayoutManager(new views::BoxLayout(
+ views::BoxLayout::kHorizontal, 0, 0, kButtonSpacing));
+ buttons_->AddChildView(
+ new ContentsSwitcherButton(this, ContentsView::SHOW_APPS));
+ buttons_->AddChildView(
+ new ContentsSwitcherButton(this, ContentsView::SHOW_SEARCH_RESULTS));
+}
+
+ContentsSwitcherView::~ContentsSwitcherView() {}
+
+gfx::Size ContentsSwitcherView::GetPreferredSize() {
+ return gfx::Size(buttons_->GetPreferredSize().width(), kPreferredHeight);
+}
+
+void ContentsSwitcherView::Layout() {
+ gfx::Rect rect(GetContentsBounds());
+
+ // Makes |buttons_| horizontally center and vertically fill.
+ gfx::Size buttons_size(buttons_->GetPreferredSize());
+ gfx::Rect buttons_bounds(rect.CenterPoint().x() - buttons_size.width() / 2,
+ rect.y(),
+ buttons_size.width(),
+ rect.height());
+ buttons_->SetBoundsRect(gfx::IntersectRects(rect, buttons_bounds));
+}
+
+void ContentsSwitcherView::ButtonPressed(views::Button* sender,
+ const ui::Event& event) {
+ contents_view_->SetShowState(
+ static_cast<ContentsView::ShowState>(sender->tag()));
+}
+
+} // namespace app_list
diff --git a/ui/app_list/views/contents_switcher_view.h b/ui/app_list/views/contents_switcher_view.h
new file mode 100644
index 0000000..df6d6fea
--- /dev/null
+++ b/ui/app_list/views/contents_switcher_view.h
@@ -0,0 +1,40 @@
+// 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 UI_APP_LIST_VIEWS_CONTENTS_SWITCHER_VIEW_H_
+#define UI_APP_LIST_VIEWS_CONTENTS_SWITCHER_VIEW_H_
+
+#include "base/basictypes.h"
+#include "ui/views/controls/button/button.h"
+#include "ui/views/view.h"
+
+namespace app_list {
+
+class ContentsView;
+
+// A view that contains buttons to switch the displayed view in the given
+// ContentsView.
+class ContentsSwitcherView : public views::View, public views::ButtonListener {
+ public:
+ explicit ContentsSwitcherView(ContentsView* contents_view);
+ virtual ~ContentsSwitcherView();
+
+ private:
+ // Overridden from views::View:
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void Layout() OVERRIDE;
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const ui::Event& event) OVERRIDE;
+
+ ContentsView* contents_view_; // Owned by views hierarchy.
+ views::View* buttons_; // Owned by views hierarchy.
+
+ DISALLOW_COPY_AND_ASSIGN(ContentsSwitcherView);
+};
+
+} // namespace app_list
+
+#endif // UI_APP_LIST_VIEWS_CONTENTS_SWITCHER_VIEW_H_
diff --git a/ui/app_list/views/contents_view.h b/ui/app_list/views/contents_view.h
index d1fcac1..eb2ec6d 100644
--- a/ui/app_list/views/contents_view.h
+++ b/ui/app_list/views/contents_view.h
@@ -36,6 +36,8 @@ class PaginationModel;
// and animates the transition between show states.
class ContentsView : public views::View {
public:
+ enum ShowState { SHOW_APPS, SHOW_SEARCH_RESULTS, };
+
ContentsView(AppListMainView* app_list_main_view,
PaginationModel* pagination_model,
AppListModel* model,
@@ -53,6 +55,9 @@ class ContentsView : public views::View {
void ShowSearchResults(bool show);
void ShowFolderContent(AppListFolderItem* folder);
+ // Sets show state and animates the subviews to match the show state.
+ void SetShowState(ShowState show_state);
+
void Prerender();
AppsContainerView* apps_container_view() { return apps_container_view_; }
@@ -64,14 +69,6 @@ class ContentsView : public views::View {
virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
private:
- enum ShowState {
- SHOW_APPS,
- SHOW_SEARCH_RESULTS,
- };
-
- // Sets show state.
- void SetShowState(ShowState show_state);
-
// Invoked when show state is changed.
void ShowStateChanged();