OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/app_list/views/start_page_view.h" | 5 #include "ui/app_list/views/start_page_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | |
7 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
8 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/app_list/app_list_item.h" | |
11 #include "ui/app_list/app_list_model.h" | |
12 #include "ui/app_list/app_list_view_delegate.h" | |
9 #include "ui/app_list/views/app_list_main_view.h" | 13 #include "ui/app_list/views/app_list_main_view.h" |
14 #include "ui/app_list/views/tile_item_view.h" | |
10 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
11 #include "ui/views/controls/button/custom_button.h" | 16 #include "ui/views/controls/button/custom_button.h" |
17 #include "ui/views/controls/image_view.h" | |
18 #include "ui/views/controls/label.h" | |
12 #include "ui/views/controls/webview/webview.h" | 19 #include "ui/views/controls/webview/webview.h" |
13 #include "ui/views/layout/box_layout.h" | 20 #include "ui/views/layout/box_layout.h" |
14 | 21 |
15 namespace app_list { | 22 namespace app_list { |
16 | 23 |
17 namespace { | 24 namespace { |
18 | 25 |
19 const int kTopMargin = 20; | 26 const int kTopMargin = 30; |
20 | 27 |
21 const int kWebViewWidth = 200; | 28 const int kWebViewWidth = 200; |
22 const int kWebViewHeight = 95; | 29 const int kWebViewHeight = 105; |
23 | 30 |
24 const int kInstantContainerSpacing = 15; | 31 const int kInstantContainerSpacing = 20; |
25 const int kBarPlaceholderWidth = 350; | 32 const int kBarPlaceholderWidth = 490; |
26 const int kBarPlaceholderHeight = 30; | 33 const int kBarPlaceholderHeight = 30; |
27 | 34 |
35 const int kNumStartPageTiles = 5; | |
36 const int kTileSpacing = 10; | |
37 | |
28 // A button that is the placeholder for the search bar in the start page view. | 38 // A button that is the placeholder for the search bar in the start page view. |
29 class BarPlaceholderButton : public views::CustomButton { | 39 class BarPlaceholderButton : public views::CustomButton { |
30 public: | 40 public: |
31 explicit BarPlaceholderButton(views::ButtonListener* listener) | 41 explicit BarPlaceholderButton(views::ButtonListener* listener) |
32 : views::CustomButton(listener) {} | 42 : views::CustomButton(listener) {} |
33 | 43 |
34 virtual ~BarPlaceholderButton() {} | 44 virtual ~BarPlaceholderButton() {} |
35 | 45 |
36 // Overridden from views::View: | 46 // Overridden from views::View: |
37 virtual gfx::Size GetPreferredSize() OVERRIDE { | 47 virtual gfx::Size GetPreferredSize() OVERRIDE { |
(...skipping 19 matching lines...) Expand all Loading... | |
57 paint.setColor(base_color); | 67 paint.setColor(base_color); |
58 canvas->DrawRect(rect, paint); | 68 canvas->DrawRect(rect, paint); |
59 } | 69 } |
60 | 70 |
61 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); | 71 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); |
62 }; | 72 }; |
63 | 73 |
64 } // namespace | 74 } // namespace |
65 | 75 |
66 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 76 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
67 content::WebContents* start_page_web_contents) | 77 AppListViewDelegate* view_delegate) |
68 : app_list_main_view_(app_list_main_view), | 78 : app_list_main_view_(app_list_main_view), |
69 instant_container_(new views::View) { | 79 model_(view_delegate->GetModel()), |
tapted
2014/05/20 05:22:31
What if GetModel() returns NULL?
Also, the model
calamity
2014/05/22 03:31:16
Ah yeah.. I forgot how much the app list had chang
| |
70 AddChildView(instant_container_); | 80 instant_container_(new views::View), |
71 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 81 tiles_container_(new views::View) { |
72 instant_container_->SetLayoutManager(new views::BoxLayout( | 82 SetLayoutManager(new views::BoxLayout( |
73 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); | 83 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); |
74 | 84 |
85 // The view containing the start page WebContants and the BarPlaceholder. | |
tapted
2014/05/20 05:22:31
typo: WebContants -> WebContents
calamity
2014/05/22 03:31:16
Done.
| |
86 AddChildView(instant_container_); | |
87 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | |
88 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | |
89 instant_layout_manager->set_main_axis_alignment( | |
90 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | |
91 instant_container_->SetLayoutManager(instant_layout_manager); | |
92 | |
93 content::WebContents* start_page_web_contents = | |
94 view_delegate->GetStartPageContents(); | |
75 views::WebView* web_view = | 95 views::WebView* web_view = |
76 new views::WebView(start_page_web_contents->GetBrowserContext()); | 96 new views::WebView(start_page_web_contents->GetBrowserContext()); |
77 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); | 97 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); |
78 web_view->SetWebContents(start_page_web_contents); | 98 web_view->SetWebContents(start_page_web_contents); |
79 | 99 |
80 instant_container_->AddChildView(web_view); | 100 instant_container_->AddChildView(web_view); |
81 instant_container_->AddChildView(new BarPlaceholderButton(this)); | 101 instant_container_->AddChildView(new BarPlaceholderButton(this)); |
102 | |
103 // The view containing the start page tiles. | |
104 AddChildView(tiles_container_); | |
105 views::BoxLayout* tiles_layout_manager = | |
106 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); | |
107 tiles_layout_manager->set_main_axis_alignment( | |
108 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
109 tiles_container_->SetLayoutManager(tiles_layout_manager); | |
110 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | |
111 TileItemView* tile = new TileItemView(); | |
112 tile->SetAppListItem(model_->top_level_item_list()->item_at(i)); | |
tapted
2014/05/20 05:22:31
nit: might be good to skip this line, and just cal
calamity
2014/05/22 03:31:16
Done.
| |
113 tiles_container_->AddChildView(tile); | |
114 } | |
82 } | 115 } |
83 | 116 |
84 StartPageView::~StartPageView() { | 117 StartPageView::~StartPageView() { |
85 } | 118 } |
86 | 119 |
87 void StartPageView::Reset() { | 120 void StartPageView::Reset() { |
88 instant_container_->SetVisible(true); | 121 instant_container_->SetVisible(true); |
122 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | |
123 TileItemView* tile = | |
124 static_cast<TileItemView*>(tiles_container_->child_at(i)); | |
tapted
2014/05/20 05:22:31
I think this would be nicer in a private function,
calamity
2014/05/22 03:31:16
Done.
| |
125 tile->SetAppListItem(model_->top_level_item_list()->item_at(i)); | |
tapted
2014/05/20 05:22:31
What if `i` >= model_->top_level_item_list().size(
calamity
2014/05/22 03:31:16
Done.
| |
126 } | |
89 } | 127 } |
90 | 128 |
91 void StartPageView::ButtonPressed(views::Button* sender, | 129 void StartPageView::ButtonPressed(views::Button* sender, |
92 const ui::Event& event) { | 130 const ui::Event& event) { |
93 app_list_main_view_->OnStartPageSearchButtonPressed(); | 131 app_list_main_view_->OnStartPageSearchButtonPressed(); |
94 instant_container_->SetVisible(false); | 132 instant_container_->SetVisible(false); |
95 } | 133 } |
96 | 134 |
97 } // namespace app_list | 135 } // namespace app_list |
OLD | NEW |