Update path of checkdeps to buildtools checkout
[chromium-blink-merge.git] / ui / app_list / views / app_list_background.cc
blob19085e60bb3892675ad004f109971f9485b4d355
1 // Copyright (c) 2012 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.
5 #include "ui/app_list/views/app_list_background.h"
7 #include "base/command_line.h"
8 #include "grit/ui_resources.h"
9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "third_party/skia/include/core/SkPath.h"
11 #include "ui/app_list/app_list_constants.h"
12 #include "ui/app_list/app_list_switches.h"
13 #include "ui/app_list/views/app_list_main_view.h"
14 #include "ui/app_list/views/contents_view.h"
15 #include "ui/app_list/views/search_box_view.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/gfx/skia_util.h"
20 #include "ui/views/view.h"
22 namespace {
24 // Size of top separator between searchbox and grid view.
25 const int kTopSeparatorSize = 1;
27 // Size of bottom separator between contents view and contents switcher.
28 const int kBottomSeparatorSize = 1;
30 } // namespace
32 namespace app_list {
34 AppListBackground::AppListBackground(int corner_radius,
35 AppListMainView* main_view)
36 : corner_radius_(corner_radius),
37 main_view_(main_view) {
40 AppListBackground::~AppListBackground() {
43 void AppListBackground::Paint(gfx::Canvas* canvas,
44 views::View* view) const {
45 gfx::Rect bounds = view->GetContentsBounds();
47 canvas->Save();
48 SkPath path;
49 // Contents corner radius is 1px smaller than border corner radius.
50 SkScalar radius = SkIntToScalar(corner_radius_ - 1);
51 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius);
52 canvas->ClipPath(path, false);
54 SkPaint paint;
55 paint.setStyle(SkPaint::kFill_Style);
57 int contents_top = bounds.y();
58 views::View* search_box_view = main_view_->search_box_view();
59 if (main_view_->visible() && search_box_view->visible()) {
60 const gfx::Rect search_box_view_bounds =
61 search_box_view->ConvertRectToWidget(search_box_view->GetLocalBounds());
62 gfx::Rect search_box_rect(bounds.x(),
63 bounds.y(),
64 bounds.width(),
65 search_box_view_bounds.bottom() - bounds.y());
67 paint.setColor(kSearchBoxBackground);
68 canvas->DrawRect(search_box_rect, paint);
70 gfx::Rect separator_rect(search_box_rect);
71 separator_rect.set_y(separator_rect.bottom());
72 separator_rect.set_height(kTopSeparatorSize);
73 canvas->FillRect(separator_rect, kTopSeparatorColor);
74 contents_top = separator_rect.bottom();
77 gfx::Rect contents_rect(bounds.x(),
78 contents_top,
79 bounds.width(),
80 bounds.bottom() - contents_top);
82 paint.setColor(kContentsBackgroundColor);
83 canvas->DrawRect(contents_rect, paint);
85 if (app_list::switches::IsExperimentalAppListEnabled()) {
86 if (main_view_->visible()) {
87 views::View* contents_view = main_view_->contents_view();
88 const gfx::Rect contents_view_view_bounds =
89 contents_view->ConvertRectToWidget(contents_view->GetLocalBounds());
90 gfx::Rect separator_rect(contents_rect);
91 separator_rect.set_y(contents_view_view_bounds.bottom());
92 separator_rect.set_height(kBottomSeparatorSize);
93 canvas->FillRect(separator_rect, kBottomSeparatorColor);
94 int contents_switcher_top = separator_rect.bottom();
95 gfx::Rect contents_switcher_rect(bounds.x(),
96 contents_switcher_top,
97 bounds.width(),
98 bounds.bottom() - contents_switcher_top);
99 paint.setColor(kContentsSwitcherBackgroundColor);
100 canvas->DrawRect(contents_switcher_rect, paint);
103 // Draw a banner in the corner of the app list if it is the experimental app
104 // list.
105 const gfx::ImageSkia& experimental_icon =
106 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
107 IDR_APP_LIST_EXPERIMENTAL_ICON);
108 canvas->DrawImageInt(experimental_icon,
109 contents_rect.right() - experimental_icon.width(),
110 contents_rect.bottom() - experimental_icon.height());
113 canvas->Restore();
116 } // namespace app_list