Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / views / app_list_background.cc
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.
4
5 #include "ui/app_list/views/app_list_background.h"
6
7 #include "base/command_line.h"
8 #include "third_party/skia/include/core/SkPaint.h"
9 #include "third_party/skia/include/core/SkPath.h"
10 #include "ui/app_list/app_list_constants.h"
11 #include "ui/app_list/app_list_switches.h"
12 #include "ui/app_list/views/app_list_main_view.h"
13 #include "ui/app_list/views/contents_view.h"
14 #include "ui/app_list/views/search_box_view.h"
15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/skia_util.h"
18 #include "ui/views/view.h"
19
20 namespace {
21
22 // Size of bottom separator between contents view and contents switcher.
23 const int kBottomSeparatorSize = 1;
24
25 }  // namespace
26
27 namespace app_list {
28
29 AppListBackground::AppListBackground(int corner_radius,
30                                      AppListMainView* main_view)
31     : corner_radius_(corner_radius),
32       main_view_(main_view) {
33 }
34
35 AppListBackground::~AppListBackground() {
36 }
37
38 void AppListBackground::Paint(gfx::Canvas* canvas,
39                               views::View* view) const {
40   gfx::Rect bounds = view->GetContentsBounds();
41
42   canvas->Save();
43   SkPath path;
44   // Contents corner radius is 1px smaller than border corner radius.
45   SkScalar radius = SkIntToScalar(corner_radius_ - 1);
46   path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius);
47   canvas->ClipPath(path, false);
48
49   SkPaint paint;
50   paint.setStyle(SkPaint::kFill_Style);
51
52   int contents_top = bounds.y();
53   gfx::Rect contents_rect(bounds.x(),
54                           contents_top,
55                           bounds.width(),
56                           bounds.bottom() - contents_top);
57
58   paint.setColor(kContentsBackgroundColor);
59   canvas->DrawRect(contents_rect, paint);
60
61   if (app_list::switches::IsExperimentalAppListEnabled()) {
62     if (main_view_->visible()) {
63       views::View* contents_view = main_view_->contents_view();
64       const gfx::Rect contents_view_view_bounds =
65           contents_view->ConvertRectToWidget(contents_view->GetLocalBounds());
66       gfx::Rect separator_rect(contents_rect);
67       separator_rect.Inset(
68           kExperimentalWindowPadding + main_view_->GetInsets().left(), 0);
69       separator_rect.set_y(contents_view_view_bounds.bottom() - 1);
70       separator_rect.set_height(kBottomSeparatorSize);
71       canvas->FillRect(separator_rect, kBottomSeparatorColor);
72     }
73   }
74
75   canvas->Restore();
76 }
77
78 }  // namespace app_list