OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/app_list/views/start_page_view.h" |
| 6 |
| 7 #include "content/public/browser/web_contents.h" |
| 8 #include "ui/app_list/app_list_constants.h" |
| 9 #include "ui/app_list/views/app_list_main_view.h" |
| 10 #include "ui/app_list/views/search_box_view.h" |
| 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/views/controls/button/custom_button.h" |
| 13 #include "ui/views/controls/webview/webview.h" |
| 14 #include "ui/views/layout/box_layout.h" |
| 15 |
| 16 namespace app_list { |
| 17 |
| 18 namespace { |
| 19 |
| 20 const int kTopMargin = 20; |
| 21 |
| 22 const int kWebViewWidth = 200; |
| 23 const int kWebViewHeight = 95; |
| 24 |
| 25 const int kInstantContainerSpacing = 15; |
| 26 const int kFakeBarWidth = 350; |
| 27 const int kFakeBarHeight = 30; |
| 28 |
| 29 class FakeBarButton : public views::CustomButton { |
| 30 public: |
| 31 explicit FakeBarButton(views::ButtonListener* listener) |
| 32 : views::CustomButton(listener) { |
| 33 } |
| 34 |
| 35 virtual ~FakeBarButton() {} |
| 36 |
| 37 // Overridden from views::View: |
| 38 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 39 return gfx::Size(kFakeBarWidth, kFakeBarHeight); |
| 40 } |
| 41 |
| 42 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 43 PaintButton(canvas, state() == STATE_HOVERED ? kPagerHoverColor |
| 44 : kPagerNormalColor); |
| 45 } |
| 46 |
| 47 private: |
| 48 // Paints a rectangular button. |
| 49 void PaintButton(gfx::Canvas* canvas, SkColor base_color) { |
| 50 gfx::Rect rect(GetContentsBounds()); |
| 51 rect.ClampToCenteredSize(gfx::Size(kFakeBarWidth, kFakeBarHeight)); |
| 52 |
| 53 SkPaint paint; |
| 54 paint.setAntiAlias(true); |
| 55 paint.setStyle(SkPaint::kFill_Style); |
| 56 paint.setColor(base_color); |
| 57 canvas->DrawRect(rect, paint); |
| 58 } |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(FakeBarButton); |
| 61 }; |
| 62 |
| 63 } // namespace |
| 64 |
| 65 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
| 66 content::WebContents* start_page_web_contents) |
| 67 : app_list_main_view_(app_list_main_view), |
| 68 instant_container_(new views::View) { |
| 69 AddChildView(instant_container_); |
| 70 instant_container_->SetLayoutManager(new views::BoxLayout( |
| 71 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); |
| 72 |
| 73 views::WebView* web_view = |
| 74 new views::WebView(start_page_web_contents->GetBrowserContext()); |
| 75 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); |
| 76 web_view->SetWebContents(start_page_web_contents); |
| 77 |
| 78 instant_container_->AddChildView(web_view); |
| 79 instant_container_->AddChildView(new FakeBarButton(this)); |
| 80 } |
| 81 |
| 82 StartPageView::~StartPageView() { |
| 83 } |
| 84 |
| 85 void StartPageView::Layout() { |
| 86 gfx::Rect rect(GetContentsBounds()); |
| 87 |
| 88 // Makes |instant_container_| horizontally center and vertically fill. |
| 89 gfx::Size instant_container_size(instant_container_->GetPreferredSize()); |
| 90 gfx::Rect top_half_bounds( |
| 91 rect.CenterPoint().x() - instant_container_size.width() / 2, |
| 92 rect.y(), |
| 93 instant_container_size.width(), |
| 94 rect.height() / 2); |
| 95 instant_container_->SetBoundsRect(top_half_bounds); |
| 96 } |
| 97 |
| 98 void StartPageView::ButtonPressed(views::Button* sender, |
| 99 const ui::Event& event) { |
| 100 app_list_main_view_->search_box_view()->SetVisible(true); |
| 101 app_list_main_view_->search_box_view()->RequestFocus(); |
| 102 } |
| 103 |
| 104 } // namespace app_list |
OLD | NEW |