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" | |
xiyuan
2014/05/09 07:59:46
nit: not needed any more.
calamity
2014/05/12 03:00:42
Done.
| |
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 kBarPlaceholderWidth = 350; | |
27 const int kBarPlaceholderHeight = 30; | |
28 | |
29 // A button that is the placeholder for the search bar in the start page view. | |
30 class BarPlaceholderButton : public views::CustomButton { | |
31 public: | |
32 explicit BarPlaceholderButton(views::ButtonListener* listener) | |
33 : views::CustomButton(listener) {} | |
34 | |
35 virtual ~BarPlaceholderButton() {} | |
36 | |
37 // Overridden from views::View: | |
38 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
39 return gfx::Size(kBarPlaceholderWidth, kBarPlaceholderHeight); | |
40 } | |
41 | |
42 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
43 PaintButton( | |
44 canvas, | |
45 state() == STATE_HOVERED ? kPagerHoverColor : kPagerNormalColor); | |
46 } | |
47 | |
48 private: | |
49 // Paints a rectangular button. | |
50 void PaintButton(gfx::Canvas* canvas, SkColor base_color) { | |
51 gfx::Rect rect(GetContentsBounds()); | |
52 rect.ClampToCenteredSize( | |
53 gfx::Size(kBarPlaceholderWidth, kBarPlaceholderHeight)); | |
54 | |
55 SkPaint paint; | |
56 paint.setAntiAlias(true); | |
57 paint.setStyle(SkPaint::kFill_Style); | |
58 paint.setColor(base_color); | |
59 canvas->DrawRect(rect, paint); | |
60 } | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); | |
63 }; | |
64 | |
65 } // namespace | |
66 | |
67 StartPageView::StartPageView(AppListMainView* app_list_main_view, | |
68 content::WebContents* start_page_web_contents) | |
69 : app_list_main_view_(app_list_main_view), | |
70 instant_container_(new views::View) { | |
71 AddChildView(instant_container_); | |
72 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
xiyuan
2014/05/09 07:59:46
I assume BoxLayout here is for adding more child v
calamity
2014/05/12 03:00:42
Yep.
| |
73 instant_container_->SetLayoutManager(new views::BoxLayout( | |
74 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); | |
75 | |
76 views::WebView* web_view = | |
77 new views::WebView(start_page_web_contents->GetBrowserContext()); | |
78 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); | |
79 web_view->SetWebContents(start_page_web_contents); | |
80 | |
81 instant_container_->AddChildView(web_view); | |
82 instant_container_->AddChildView(new BarPlaceholderButton(this)); | |
83 } | |
84 | |
85 StartPageView::~StartPageView() { | |
86 } | |
87 | |
88 void StartPageView::Reset() { | |
89 instant_container_->SetVisible(true); | |
90 } | |
91 | |
92 void StartPageView::ButtonPressed(views::Button* sender, | |
93 const ui::Event& event) { | |
94 app_list_main_view_->OnStartPageSearchButtonPressed(); | |
95 instant_container_->SetVisible(false); | |
96 } | |
97 | |
98 } // namespace app_list | |
OLD | NEW |