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

Unified Diff: ui/app_list/views/start_page_view.cc

Issue 335343002: Add a DummySearchBoxView to the experimental app list start page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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/app_list/views/start_page_view.cc
diff --git a/ui/app_list/views/start_page_view.cc b/ui/app_list/views/start_page_view.cc
index e4d6487aa663f63f8c504426b1bb9390c56da275..56ba9a3ba10676fc48db875e23b91c752af00c9e 100644
--- a/ui/app_list/views/start_page_view.cc
+++ b/ui/app_list/views/start_page_view.cc
@@ -10,64 +10,82 @@
#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/app_list/views/search_box_view.h"
#include "ui/app_list/views/search_result_list_view.h"
#include "ui/app_list/views/tile_item_view.h"
#include "ui/gfx/canvas.h"
-#include "ui/views/controls/button/custom_button.h"
+#include "ui/views/background.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
+#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/box_layout.h"
namespace app_list {
namespace {
+// Layout constants
tapted 2014/06/18 02:46:05 nit: full-stop at the end of comments. More below.
calamity 2014/06/18 06:49:40 Done.
const int kTopMargin = 30;
+const int kInstantContainerSpacing = 20;
+// WebView constants
const int kWebViewWidth = 200;
const int kWebViewHeight = 105;
-const int kInstantContainerSpacing = 20;
-const int kBarPlaceholderWidth = 490;
-const int kBarPlaceholderHeight = 30;
+// DummySearchBoxView constants
+const int kDummySearchBoxWidth = 490;
+const int kDummySearchBoxHeight = 40;
+const SkColor kDummySearchBoxBorderColor =
+ SkColorSetARGB(0x30, 0xD0, 0xD0, 0xD0);
tapted 2014/06/18 02:46:06 If the thing behind the color is always solid, I t
calamity 2014/06/18 06:49:40 Done. Moved this to app_list_constants.h
+const int kDummySearchBoxBorderWidth = 1;
+const int kDummySearchBoxBorderBottomWidth = 2;
+const int kDummySearchBoxBorderCornerRadius = 2;
+// Tile container constants
const size_t kNumStartPageTiles = 5;
const int kTileSpacing = 10;
-// A button that is the placeholder for the search bar in the start page view.
-class BarPlaceholderButton : public views::CustomButton {
+// A placeholder search box which is sized to fit within the start page view.
+class DummySearchBoxView : public SearchBoxView {
public:
- explicit BarPlaceholderButton(views::ButtonListener* listener)
- : views::CustomButton(listener) {}
+ explicit DummySearchBoxView(SearchBoxViewDelegate* delegate,
tapted 2014/06/18 02:46:05 nit: explicit not required
calamity 2014/06/18 06:49:40 Done.
+ AppListViewDelegate* view_delegate)
+ : SearchBoxView(delegate, view_delegate) {}
- virtual ~BarPlaceholderButton() {}
+ virtual ~DummySearchBoxView() {}
// Overridden from views::View:
virtual gfx::Size GetPreferredSize() const OVERRIDE {
- return gfx::Size(kBarPlaceholderWidth, kBarPlaceholderHeight);
+ return gfx::Size(kDummySearchBoxWidth, kDummySearchBoxHeight);
}
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
- PaintButton(
- canvas,
- state() == STATE_HOVERED ? kPagerHoverColor : kPagerNormalColor);
- }
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DummySearchBoxView);
+};
+
+class DummySearchBoxBackground : public views::Background {
tapted 2014/06/18 02:46:06 this class needs a brief comment describing what P
calamity 2014/06/18 06:49:40 Done.
+ public:
+ DummySearchBoxBackground() {}
+ virtual ~DummySearchBoxBackground() {}
private:
- // Paints a rectangular button.
- void PaintButton(gfx::Canvas* canvas, SkColor base_color) {
- gfx::Rect rect(GetContentsBounds());
- rect.ClampToCenteredSize(
- gfx::Size(kBarPlaceholderWidth, kBarPlaceholderHeight));
+ // views::Background overrides:
+ virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
+ gfx::Rect bounds = view->GetContentsBounds();
SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kFill_Style);
- paint.setColor(base_color);
- canvas->DrawRect(rect, paint);
+ paint.setFlags(SkPaint::kAntiAlias_Flag);
+ paint.setColor(kDummySearchBoxBorderColor);
+ canvas->DrawRoundRect(bounds, kDummySearchBoxBorderCornerRadius, paint);
+ bounds.Inset(kDummySearchBoxBorderWidth,
+ kDummySearchBoxBorderWidth,
+ kDummySearchBoxBorderWidth,
+ kDummySearchBoxBorderBottomWidth);
+ paint.setColor(SK_ColorWHITE);
+ canvas->DrawRoundRect(bounds, kDummySearchBoxBorderCornerRadius, paint);
}
- DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton);
+ DISALLOW_COPY_AND_ASSIGN(DummySearchBoxBackground);
};
} // namespace
@@ -77,13 +95,34 @@ StartPageView::StartPageView(AppListMainView* app_list_main_view,
: app_list_main_view_(app_list_main_view),
model_(NULL),
view_delegate_(view_delegate),
+ search_box_view_(new DummySearchBoxView(this, view_delegate_)),
results_view_(
new SearchResultListView(app_list_main_view, view_delegate)),
instant_container_(new views::View),
tiles_container_(new views::View),
show_state_(SHOW_START_PAGE) {
- // The view containing the start page WebContents and the BarPlaceholder.
+ // The view containing the start page WebContents and DummySearchBoxView.
+ InitInstantContainer();
AddChildView(instant_container_);
+
+ // The view containing the search results.
+ AddChildView(results_view_);
+
+ // The view containing the start page tiles.
+ InitTilesContainer();
+ AddChildView(tiles_container_);
+
+ SetModel(view_delegate_->GetModel());
+ view_delegate_->AddObserver(this);
+}
+
+StartPageView::~StartPageView() {
+ view_delegate_->RemoveObserver(this);
+ if (model_)
+ model_->RemoveObserver(this);
+}
+
+void StartPageView::InitInstantContainer() {
views::BoxLayout* instant_layout_manager = new views::BoxLayout(
views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing);
instant_layout_manager->set_inside_border_insets(
@@ -92,17 +131,27 @@ StartPageView::StartPageView(AppListMainView* app_list_main_view,
views::BoxLayout::MAIN_AXIS_ALIGNMENT_END);
instant_container_->SetLayoutManager(instant_layout_manager);
- views::View* web_view = view_delegate->CreateStartPageWebView(
+ views::View* web_view = view_delegate_->CreateStartPageWebView(
gfx::Size(kWebViewWidth, kWebViewHeight));
if (web_view)
instant_container_->AddChildView(web_view);
- instant_container_->AddChildView(new BarPlaceholderButton(this));
- // The view containing the search results.
- AddChildView(results_view_);
+ // TODO(calamity): This container is needed to horizontally center the search
+ // box view. Remove this container once BoxLayout supports CrossAxisAlignment.
+ views::View* search_box_container = new views::View();
+ views::BoxLayout* layout_manager =
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
+ layout_manager->set_main_axis_alignment(
+ views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
+ search_box_container->SetLayoutManager(layout_manager);
- // The view containing the start page tiles.
- AddChildView(tiles_container_);
+ search_box_container->AddChildView(search_box_view_);
+ search_box_view_->set_background(new DummySearchBoxBackground());
tapted 2014/06/18 02:46:06 maybe do this in the DummySearchBoxView constructo
calamity 2014/06/18 06:49:40 Done.
+
+ instant_container_->AddChildView(search_box_container);
+}
+
+void StartPageView::InitTilesContainer() {
views::BoxLayout* tiles_layout_manager =
new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing);
tiles_layout_manager->set_main_axis_alignment(
@@ -113,15 +162,6 @@ StartPageView::StartPageView(AppListMainView* app_list_main_view,
tiles_container_->AddChildView(tile_item);
tile_views_.push_back(tile_item);
}
-
- SetModel(view_delegate_->GetModel());
- view_delegate_->AddObserver(this);
-}
-
-StartPageView::~StartPageView() {
- view_delegate_->RemoveObserver(this);
- if (model_)
- model_->RemoveObserver(this);
}
void StartPageView::SetModel(AppListModel* model) {
@@ -155,6 +195,9 @@ void StartPageView::SetShowState(ShowState show_state) {
instant_container_->SetVisible(show_state == SHOW_START_PAGE);
results_view_->SetVisible(show_state == SHOW_SEARCH_RESULTS);
+ if (show_state == SHOW_START_PAGE)
+ search_box_view_->search_box()->RequestFocus();
+
if (show_state_ == show_state)
return;
@@ -189,9 +232,12 @@ void StartPageView::Layout() {
tiles_container_->SetBoundsRect(bounds);
}
-void StartPageView::ButtonPressed(views::Button* sender,
- const ui::Event& event) {
- app_list_main_view_->OnStartPageSearchButtonPressed();
+void StartPageView::QueryChanged(SearchBoxView* sender) {
+ // Forward the search terms on to the real search box and clear the dummy
+ // search box.
+ app_list_main_view_->OnStartPageSearchTextfieldChanged(
+ sender->search_box()->text());
+ sender->search_box()->SetText(base::string16());
tapted 2014/06/18 02:46:06 each SearchBoxView has a reference to the the same
calamity 2014/06/18 06:49:40 Hmm. This doesn't _actually_ affect anything due t
calamity 2014/06/18 07:08:30 Actually, it looks like this isn't exactly easy. T
}
void StartPageView::OnProfilesChanged() {
« ui/app_list/views/app_list_main_view.cc ('K') | « ui/app_list/views/start_page_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698