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 "third_party/skia/include/core/SkPaint.h"
8 #include "third_party/skia/include/core/SkPath.h"
9 #include "ui/app_list/app_list_constants.h"
10 #include "ui/app_list/views/app_list_main_view.h"
11 #include "ui/app_list/views/search_box_view.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/skia_util.h"
15 #include "ui/views/view.h"
19 // Size of top separator between searchbox and grid view.
20 const int kTopSeparatorSize
= 1;
26 AppListBackground::AppListBackground(int corner_radius
,
27 AppListMainView
* main_view
)
28 : corner_radius_(corner_radius
),
29 main_view_(main_view
) {
32 AppListBackground::~AppListBackground() {
35 void AppListBackground::Paint(gfx::Canvas
* canvas
,
36 views::View
* view
) const {
37 gfx::Rect bounds
= view
->GetContentsBounds();
41 // Contents corner radius is 1px smaller than border corner radius.
42 SkScalar radius
= SkIntToScalar(corner_radius_
- 1);
43 path
.addRoundRect(gfx::RectToSkRect(bounds
), radius
, radius
);
44 canvas
->ClipPath(path
);
47 paint
.setStyle(SkPaint::kFill_Style
);
49 int contents_top
= bounds
.y();
50 if (main_view_
->visible()) {
51 views::View
* search_box_view
= main_view_
->search_box_view();
52 const gfx::Rect search_box_view_bounds
=
53 search_box_view
->ConvertRectToWidget(search_box_view
->GetLocalBounds());
54 gfx::Rect
search_box_rect(bounds
.x(),
57 search_box_view_bounds
.bottom() - bounds
.y());
59 paint
.setColor(kSearchBoxBackground
);
60 canvas
->DrawRect(search_box_rect
, paint
);
62 gfx::Rect
seperator_rect(search_box_rect
);
63 seperator_rect
.set_y(seperator_rect
.bottom());
64 seperator_rect
.set_height(kTopSeparatorSize
);
65 canvas
->FillRect(seperator_rect
, kTopSeparatorColor
);
66 contents_top
= seperator_rect
.bottom();
69 gfx::Rect
contents_rect(bounds
.x(),
72 bounds
.bottom() - contents_top
);
74 paint
.setColor(kContentsBackgroundColor
);
75 canvas
->DrawRect(contents_rect
, paint
);
79 } // namespace app_list