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 size_t 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 view_delegate_(view_delegate), |
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 view_delegate->AddObserver(this); |
83 | |
84 SetLayoutManager(new views::BoxLayout( | |
73 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); | 85 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); |
74 | 86 |
87 // The view containing the start page WebContents and the BarPlaceholder. | |
88 AddChildView(instant_container_); | |
89 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | |
90 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | |
91 instant_layout_manager->set_main_axis_alignment( | |
92 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | |
93 instant_container_->SetLayoutManager(instant_layout_manager); | |
94 | |
95 content::WebContents* start_page_web_contents = | |
96 view_delegate->GetStartPageContents(); | |
75 views::WebView* web_view = | 97 views::WebView* web_view = |
76 new views::WebView(start_page_web_contents->GetBrowserContext()); | 98 new views::WebView(start_page_web_contents->GetBrowserContext()); |
77 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); | 99 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); |
78 web_view->SetWebContents(start_page_web_contents); | 100 web_view->SetWebContents(start_page_web_contents); |
79 | 101 |
80 instant_container_->AddChildView(web_view); | 102 instant_container_->AddChildView(web_view); |
81 instant_container_->AddChildView(new BarPlaceholderButton(this)); | 103 instant_container_->AddChildView(new BarPlaceholderButton(this)); |
104 | |
105 // The view containing the start page tiles. | |
106 AddChildView(tiles_container_); | |
107 views::BoxLayout* tiles_layout_manager = | |
108 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); | |
109 tiles_layout_manager->set_main_axis_alignment( | |
110 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
111 tiles_container_->SetLayoutManager(tiles_layout_manager); | |
112 for (size_t i = 0; i < kNumStartPageTiles; ++i) | |
113 tiles_container_->AddChildView(new TileItemView()); | |
114 | |
115 Reset(); | |
82 } | 116 } |
83 | 117 |
84 StartPageView::~StartPageView() { | 118 StartPageView::~StartPageView() { |
119 view_delegate_->RemoveObserver(this); | |
120 } | |
121 | |
122 TileItemView* StartPageView::GetTileViewAt(int index) { | |
123 return static_cast<TileItemView*>(tiles_container_->child_at(index)); | |
85 } | 124 } |
86 | 125 |
87 void StartPageView::Reset() { | 126 void StartPageView::Reset() { |
88 instant_container_->SetVisible(true); | 127 instant_container_->SetVisible(true); |
128 AppListModel* model = view_delegate_->GetModel(); | |
129 if (!model || !model->top_level_item_list()) | |
130 return; | |
131 | |
132 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | |
133 AppListItem* item = NULL; | |
134 if (i < model->top_level_item_list()->item_count()) | |
135 item = model->top_level_item_list()->item_at(i); | |
136 GetTileViewAt(i)->SetAppListItem(item); | |
137 } | |
138 | |
139 Layout(); | |
tapted
2014/05/22 04:56:11
I'm guessing this will left-align tiles when there
calamity
2014/05/27 04:29:11
This center aligns due to BOX_ALIGN_CENTER. To cha
| |
89 } | 140 } |
90 | 141 |
91 void StartPageView::ButtonPressed(views::Button* sender, | 142 void StartPageView::ButtonPressed(views::Button* sender, |
92 const ui::Event& event) { | 143 const ui::Event& event) { |
93 app_list_main_view_->OnStartPageSearchButtonPressed(); | 144 app_list_main_view_->OnStartPageSearchButtonPressed(); |
94 instant_container_->SetVisible(false); | 145 instant_container_->SetVisible(false); |
95 } | 146 } |
96 | 147 |
148 void StartPageView::OnProfilesChanged() { | |
149 Reset(); | |
150 } | |
151 | |
97 } // namespace app_list | 152 } // namespace app_list |
OLD | NEW |