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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..da61e94ca32c76e68cea93602319040e24facefd |
--- /dev/null |
+++ b/ui/app_list/views/start_page_view.cc |
@@ -0,0 +1,104 @@ |
+// 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/start_page_view.h" |
+ |
+#include "content/public/browser/web_contents.h" |
+#include "ui/app_list/app_list_constants.h" |
+#include "ui/app_list/views/app_list_main_view.h" |
+#include "ui/app_list/views/search_box_view.h" |
+#include "ui/gfx/canvas.h" |
+#include "ui/views/controls/button/custom_button.h" |
+#include "ui/views/controls/webview/webview.h" |
+#include "ui/views/layout/box_layout.h" |
+ |
+namespace app_list { |
+ |
+namespace { |
+ |
+const int kTopMargin = 20; |
+ |
+const int kWebViewWidth = 200; |
+const int kWebViewHeight = 95; |
+ |
+const int kInstantContainerSpacing = 15; |
+const int kFakeBarWidth = 350; |
+const int kFakeBarHeight = 30; |
+ |
+class FakeBarButton : public views::CustomButton { |
tapted
2014/05/07 08:19:17
needs a class comment. Also FakeFoo sounds odd out
calamity
2014/05/08 07:46:32
Ok. This was named after the NTP's UI element whic
|
+ public: |
+ explicit FakeBarButton(views::ButtonListener* listener) |
+ : views::CustomButton(listener) {} |
+ |
+ virtual ~FakeBarButton() {} |
+ |
+ // Overridden from views::View: |
+ virtual gfx::Size GetPreferredSize() OVERRIDE { |
+ return gfx::Size(kFakeBarWidth, kFakeBarHeight); |
+ } |
+ |
+ 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(kFakeBarWidth, kFakeBarHeight)); |
+ |
+ SkPaint paint; |
+ paint.setAntiAlias(true); |
+ paint.setStyle(SkPaint::kFill_Style); |
+ paint.setColor(base_color); |
+ canvas->DrawRect(rect, paint); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakeBarButton); |
+}; |
+ |
+} // namespace |
+ |
+StartPageView::StartPageView(AppListMainView* app_list_main_view, |
+ content::WebContents* start_page_web_contents) |
+ : app_list_main_view_(app_list_main_view), |
+ instant_container_(new views::View) { |
+ AddChildView(instant_container_); |
+ instant_container_->SetLayoutManager(new views::BoxLayout( |
xiyuan
2014/05/07 17:32:16
Why do we need |instant_container_|? Since app lis
calamity
2014/05/08 07:46:32
This is mostly in preparation for adding the app t
|
+ views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); |
+ |
+ views::WebView* web_view = |
+ new views::WebView(start_page_web_contents->GetBrowserContext()); |
+ web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); |
+ web_view->SetWebContents(start_page_web_contents); |
+ |
+ instant_container_->AddChildView(web_view); |
+ instant_container_->AddChildView(new FakeBarButton(this)); |
xiyuan
2014/05/07 17:32:16
Looks like we are using FakeBarButton as the place
calamity
2014/05/08 07:46:32
We will be adding app tiles below the bar. It's un
|
+} |
+ |
+StartPageView::~StartPageView() { |
+} |
+ |
+void StartPageView::Layout() { |
+ gfx::Rect rect(GetContentsBounds()); |
+ |
+ // Makes |instant_container_| horizontally center and vertically fill. |
+ gfx::Size instant_container_size(instant_container_->GetPreferredSize()); |
+ gfx::Rect top_half_bounds( |
+ rect.CenterPoint().x() - instant_container_size.width() / 2, |
+ rect.y(), |
tapted
2014/05/07 08:19:17
this looks out of place - I think only the width/h
xiyuan
2014/05/07 17:32:16
x/y might not be zero when a view has padding arou
|
+ instant_container_size.width(), |
+ rect.height() / 2); |
tapted
2014/05/07 08:19:17
Why /2 here? (doesn't seem to match the comment -
calamity
2014/05/08 07:46:32
Deleted this whole thing.
|
+ instant_container_->SetBoundsRect(top_half_bounds); |
+} |
+ |
+void StartPageView::ButtonPressed(views::Button* sender, |
+ const ui::Event& event) { |
+ app_list_main_view_->search_box_view()->SetVisible(true); |
+ app_list_main_view_->search_box_view()->RequestFocus(); |
xiyuan
2014/05/07 17:32:16
This feels strange that when user clicks on place
calamity
2014/05/08 07:46:32
This is the behavior specified by the mocks. The m
|
+} |
+ |
+} // namespace app_list |