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 { | |
tapted
2014/05/07 08:19:17
needs a class comment. Also FakeFoo sounds odd out
calamity
2014/05/08 07:46:32
Ok. This was named after the NTP's UI element whic
| |
30 public: | |
31 explicit FakeBarButton(views::ButtonListener* listener) | |
32 : views::CustomButton(listener) {} | |
33 | |
34 virtual ~FakeBarButton() {} | |
35 | |
36 // Overridden from views::View: | |
37 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
38 return gfx::Size(kFakeBarWidth, kFakeBarHeight); | |
39 } | |
40 | |
41 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
42 PaintButton( | |
43 canvas, | |
44 state() == STATE_HOVERED ? kPagerHoverColor : 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( | |
xiyuan
2014/05/07 17:32:16
Why do we need |instant_container_|? Since app lis
calamity
2014/05/08 07:46:32
This is mostly in preparation for adding the app t
| |
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)); | |
xiyuan
2014/05/07 17:32:16
Looks like we are using FakeBarButton as the place
calamity
2014/05/08 07:46:32
We will be adding app tiles below the bar. It's un
| |
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(), | |
tapted
2014/05/07 08:19:17
this looks out of place - I think only the width/h
xiyuan
2014/05/07 17:32:16
x/y might not be zero when a view has padding arou
| |
93 instant_container_size.width(), | |
94 rect.height() / 2); | |
tapted
2014/05/07 08:19:17
Why /2 here? (doesn't seem to match the comment -
calamity
2014/05/08 07:46:32
Deleted this whole thing.
| |
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(); | |
xiyuan
2014/05/07 17:32:16
This feels strange that when user clicks on place
calamity
2014/05/08 07:46:32
This is the behavior specified by the mocks. The m
| |
102 } | |
103 | |
104 } // namespace app_list | |
OLD | NEW |