Chromium Code Reviews| 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 kNumStartPageItems = 6; | |
| 21 | |
| 22 const int kTopMargin = 20; | |
| 23 | |
| 24 const int kWebViewWidth = 200; | |
| 25 const int kWebViewHeight = 95; | |
| 26 | |
| 27 const int kInstantContainerSpacing = 15; | |
| 28 const int kFakeBarWidth = 350; | |
| 29 const int kFakeBarHeight = 30; | |
| 30 | |
| 31 const int kStartPageTileSize = 64; | |
| 32 | |
| 33 class StartPageItemView : public views::CustomButton { | |
| 34 public: | |
| 35 explicit StartPageItemView(views::ButtonListener* listener) | |
| 36 : views::CustomButton(listener) {} | |
| 37 | |
| 38 virtual ~StartPageItemView() {} | |
| 39 | |
| 40 // Overridden from views::View: | |
| 41 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
| 42 return gfx::Size(kStartPageTileSize, kStartPageTileSize); | |
| 43 } | |
| 44 | |
| 45 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
| 46 PaintButton( | |
| 47 canvas, | |
| 48 state() == STATE_HOVERED ? kPagerHoverColor : kPagerNormalColor); | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 // Paints a rectangular button. | |
| 53 void PaintButton(gfx::Canvas* canvas, SkColor base_color) { | |
| 54 gfx::Rect rect(GetContentsBounds()); | |
| 55 rect.ClampToCenteredSize(gfx::Size(kStartPageTileSize, kStartPageTileSize)); | |
| 56 | |
| 57 SkPaint paint; | |
| 58 paint.setAntiAlias(true); | |
| 59 paint.setStyle(SkPaint::kFill_Style); | |
| 60 paint.setColor(base_color); | |
| 61 canvas->DrawRect(rect, paint); | |
| 62 } | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(StartPageItemView); | |
| 65 }; | |
| 66 | |
| 67 // A button that is the placeholder for the search bar in the start page view. | |
| 68 class BarPlaceholderButton : public views::CustomButton { | |
| 69 public: | |
| 70 explicit BarPlaceholderButton(views::ButtonListener* listener) | |
| 71 : views::CustomButton(listener) {} | |
| 72 | |
| 73 virtual ~BarPlaceholderButton() {} | |
| 74 | |
| 75 // Overridden from views::View: | |
| 76 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
| 77 return gfx::Size(kFakeBarWidth, kFakeBarHeight); | |
| 78 } | |
| 79 | |
| 80 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
| 81 PaintButton( | |
| 82 canvas, | |
| 83 state() == STATE_HOVERED ? kPagerHoverColor : kPagerNormalColor); | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 // Paints a rectangular button. | |
| 88 void PaintButton(gfx::Canvas* canvas, SkColor base_color) { | |
| 89 gfx::Rect rect(GetContentsBounds()); | |
| 90 rect.ClampToCenteredSize(gfx::Size(kFakeBarWidth, kFakeBarHeight)); | |
| 91 | |
| 92 SkPaint paint; | |
| 93 paint.setAntiAlias(true); | |
| 94 paint.setStyle(SkPaint::kFill_Style); | |
| 95 paint.setColor(base_color); | |
| 96 canvas->DrawRect(rect, paint); | |
| 97 } | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); | |
| 100 }; | |
| 101 | |
| 102 } // namespace | |
| 103 | |
| 104 StartPageView::StartPageView(AppListMainView* app_list_main_view, | |
| 105 content::WebContents* start_page_web_contents) | |
| 106 : app_list_main_view_(app_list_main_view), | |
| 107 instant_container_(new views::View) { | |
| 108 AddChildView(instant_container_); | |
| 109 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 110 instant_container_->SetLayoutManager(new views::BoxLayout( | |
| 111 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); | |
| 112 | |
| 113 views::WebView* web_view = | |
| 114 new views::WebView(start_page_web_contents->GetBrowserContext()); | |
| 115 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); | |
| 116 web_view->SetWebContents(start_page_web_contents); | |
| 117 | |
| 118 instant_container_->AddChildView(web_view); | |
| 119 instant_container_->AddChildView(new BarPlaceholderButton(this)); | |
| 120 | |
| 121 AddChildView(items_container_); | |
|
tapted
2014/05/08 10:15:22
I think your branches are still a little whacky.
calamity
2014/05/09 07:09:39
Done.
| |
| 122 views::BoxLayout* items_container_layout = new views::BoxLayout( | |
| 123 views::BoxLayout::kHorizontal, 40, kTopMargin, kInstantContainerSpacing); | |
| 124 items_container_layout->set_spread_blank_space(true); | |
| 125 items_container_->SetLayoutManager(items_container_layout); | |
| 126 for (size_t i = 0; i < kNumStartPageItems; ++i) { | |
| 127 items_container_->AddChildView(new StartPageItemView(this)); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 StartPageView::~StartPageView() { | |
| 132 } | |
| 133 | |
| 134 void StartPageView::Reset() { | |
| 135 instant_container_->SetVisible(true); | |
| 136 } | |
| 137 | |
| 138 void StartPageView::ButtonPressed(views::Button* sender, | |
| 139 const ui::Event& event) { | |
| 140 app_list_main_view_->search_box_view()->SetVisible(true); | |
| 141 app_list_main_view_->search_box_view()->RequestFocus(); | |
|
xiyuan
2014/05/08 16:17:48
Similar to Contents view, prefer to do these in a
calamity
2014/05/09 07:09:39
Done.
| |
| 142 instant_container_->SetVisible(false); | |
| 143 } | |
| 144 | |
| 145 } // namespace app_list | |
| OLD | NEW |