Upstream version 9.38.198.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 top separator between searchbox and grid view.
23 const int kTopSeparatorSize = 1;
24
25 // Size of bottom separator between contents view and contents switcher.
26 const int kBottomSeparatorSize = 1;
27
28 }  // namespace
29
30 namespace app_list {
31
32 AppListBackground::AppListBackground(int corner_radius,
33                                      AppListMainView* main_view)
34     : corner_radius_(corner_radius),
35       main_view_(main_view) {
36 }
37
38 AppListBackground::~AppListBackground() {
39 }
40
41 void AppListBackground::Paint(gfx::Canvas* canvas,
42                               views::View* view) const {
43   gfx::Rect bounds = view->GetContentsBounds();
44
45   canvas->Save();
46   SkPath path;
47   // Contents corner radius is 1px smaller than border corner radius.
48   SkScalar radius = SkIntToScalar(corner_radius_ - 1);
49   path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius);
50   canvas->ClipPath(path, false);
51
52   SkPaint paint;
53   paint.setStyle(SkPaint::kFill_Style);
54
55   int contents_top = bounds.y();
56   views::View* search_box_view = main_view_->search_box_view();
57   if (main_view_->visible() && search_box_view->visible()) {
58     const gfx::Rect search_box_view_bounds =
59         search_box_view->ConvertRectToWidget(search_box_view->GetLocalBounds());
60     gfx::Rect search_box_rect(bounds.x(),
61                               bounds.y(),
62                               bounds.width(),
63                               search_box_view_bounds.bottom() - bounds.y());
64
65     paint.setColor(kSearchBoxBackground);
66     canvas->DrawRect(search_box_rect, paint);
67
68     gfx::Rect separator_rect(search_box_rect);
69     separator_rect.set_y(separator_rect.bottom());
70     separator_rect.set_height(kTopSeparatorSize);
71     canvas->FillRect(separator_rect, kTopSeparatorColor);
72     contents_top = separator_rect.bottom();
73   }
74
75   gfx::Rect contents_rect(bounds.x(),
76                           contents_top,
77                           bounds.width(),
78                           bounds.bottom() - contents_top);
79
80   paint.setColor(kContentsBackgroundColor);
81   canvas->DrawRect(contents_rect, paint);
82
83   if (app_list::switches::IsExperimentalAppListEnabled()) {
84     if (main_view_->visible()) {
85       views::View* contents_view = main_view_->contents_view();
86       const gfx::Rect contents_view_view_bounds =
87           contents_view->ConvertRectToWidget(contents_view->GetLocalBounds());
88       gfx::Rect separator_rect(contents_rect);
89       // Extra kContentsSwitcherSeparatorHeight pixels so the launcher page
90       // indicator overlays the separator rect.
91       separator_rect.set_y(contents_view_view_bounds.bottom() +
92                            kContentsSwitcherSeparatorHeight);
93       separator_rect.set_height(kBottomSeparatorSize);
94       canvas->FillRect(separator_rect, kBottomSeparatorColor);
95       int contents_switcher_top = separator_rect.bottom();
96       gfx::Rect contents_switcher_rect(bounds.x(),
97                                        contents_switcher_top,
98                                        bounds.width(),
99                                        bounds.bottom() - contents_switcher_top);
100       paint.setColor(kContentsSwitcherBackgroundColor);
101       canvas->DrawRect(contents_switcher_rect, paint);
102     }
103   }
104
105   canvas->Restore();
106 }
107
108 }  // namespace app_list