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() const OVERRIDE { | 47 virtual gfx::Size GetPreferredSize() const 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_(NULL), |
70 AddChildView(instant_container_); | 80 view_delegate_(view_delegate), |
71 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 81 instant_container_(new views::View), |
72 instant_container_->SetLayoutManager(new views::BoxLayout( | 82 tiles_container_(new views::View) { |
| 83 SetLayoutManager(new views::BoxLayout( |
73 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); | 84 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); |
74 | 85 |
| 86 // The view containing the start page WebContents and the BarPlaceholder. |
| 87 AddChildView(instant_container_); |
| 88 views::BoxLayout* instant_layout_manager = new views::BoxLayout( |
| 89 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); |
| 90 instant_layout_manager->set_main_axis_alignment( |
| 91 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
| 92 instant_container_->SetLayoutManager(instant_layout_manager); |
| 93 |
| 94 content::WebContents* start_page_web_contents = |
| 95 view_delegate->GetStartPageContents(); |
75 views::WebView* web_view = new views::WebView( | 96 views::WebView* web_view = new views::WebView( |
76 start_page_web_contents ? start_page_web_contents->GetBrowserContext() | 97 start_page_web_contents ? start_page_web_contents->GetBrowserContext() |
77 : NULL); | 98 : NULL); |
78 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); | 99 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); |
79 web_view->SetWebContents(start_page_web_contents); | 100 web_view->SetWebContents(start_page_web_contents); |
80 | 101 |
81 instant_container_->AddChildView(web_view); | 102 instant_container_->AddChildView(web_view); |
82 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 TileItemView* tile_item = new TileItemView(); |
| 114 tiles_container_->AddChildView(tile_item); |
| 115 tile_views_.push_back(tile_item); |
| 116 } |
| 117 |
| 118 SetModel(view_delegate_->GetModel()); |
| 119 view_delegate_->AddObserver(this); |
83 } | 120 } |
84 | 121 |
85 StartPageView::~StartPageView() { | 122 StartPageView::~StartPageView() { |
| 123 view_delegate_->RemoveObserver(this); |
| 124 } |
| 125 |
| 126 void StartPageView::SetModel(AppListModel* model) { |
| 127 DCHECK(model); |
| 128 if (model_) |
| 129 model_->RemoveObserver(this); |
| 130 model_ = model; |
| 131 model_->AddObserver(this); |
| 132 Reset(); |
86 } | 133 } |
87 | 134 |
88 void StartPageView::Reset() { | 135 void StartPageView::Reset() { |
89 instant_container_->SetVisible(true); | 136 instant_container_->SetVisible(true); |
| 137 if (!model_ || !model_->top_level_item_list()) |
| 138 return; |
| 139 |
| 140 for (size_t i = 0; i < kNumStartPageTiles; ++i) { |
| 141 AppListItem* item = NULL; |
| 142 if (i < model_->top_level_item_list()->item_count()) |
| 143 item = model_->top_level_item_list()->item_at(i); |
| 144 tile_views_[i]->SetAppListItem(item); |
| 145 } |
| 146 |
| 147 Layout(); |
90 } | 148 } |
91 | 149 |
92 void StartPageView::ButtonPressed(views::Button* sender, | 150 void StartPageView::ButtonPressed(views::Button* sender, |
93 const ui::Event& event) { | 151 const ui::Event& event) { |
94 app_list_main_view_->OnStartPageSearchButtonPressed(); | 152 app_list_main_view_->OnStartPageSearchButtonPressed(); |
95 instant_container_->SetVisible(false); | 153 instant_container_->SetVisible(false); |
96 } | 154 } |
97 | 155 |
| 156 void StartPageView::OnProfilesChanged() { |
| 157 SetModel(view_delegate_->GetModel()); |
| 158 } |
| 159 |
| 160 void StartPageView::OnAppListModelStatusChanged() { |
| 161 Reset(); |
| 162 } |
| 163 |
| 164 void StartPageView::OnAppListItemAdded(AppListItem* item) { |
| 165 Reset(); |
| 166 } |
| 167 |
| 168 void StartPageView::OnAppListItemDeleted() { |
| 169 Reset(); |
| 170 } |
| 171 |
| 172 void StartPageView::OnAppListItemUpdated(AppListItem* item) { |
| 173 Reset(); |
| 174 } |
| 175 |
98 } // namespace app_list | 176 } // namespace app_list |
OLD | NEW |