Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: ui/app_list/app_list_bubble_border.cc

Issue 10386224: app_list: Add search box and search result view for v2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win_aura Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/app_list/app_list_bubble_border.h" 5 #include "ui/app_list/app_list_bubble_border.h"
6 6
7 #include "third_party/skia/include/core/SkPath.h" 7 #include "third_party/skia/include/core/SkPath.h"
8 #include "third_party/skia/include/core/SkPaint.h" 8 #include "third_party/skia/include/core/SkPaint.h"
9 #include "third_party/skia/include/effects/SkBlurDrawLooper.h" 9 #include "third_party/skia/include/effects/SkBlurDrawLooper.h"
10 #include "third_party/skia/include/effects/SkGradientShader.h" 10 #include "third_party/skia/include/effects/SkGradientShader.h"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Bubble border corner radius. 15 // Bubble border corner radius.
16 const int kCornerRadius = 3; 16 const int kCornerRadius = 3;
17 17
18 // Arrow width and height. 18 // Arrow width and height.
19 const int kArrowHeight = 10; 19 const int kArrowHeight = 10;
20 const int kArrowWidth = 20; 20 const int kArrowWidth = 20;
21 21
22 // Bubble border color and width. 22 // Bubble border color and width.
23 const SkColor kBorderColor = SkColorSetARGB(0xFF, 0, 0, 0); 23 const SkColor kBorderColor = SkColorSetARGB(0xFF, 0, 0, 0);
24 const int kBorderSize = 1; 24 const int kBorderSize = 1;
25 25
26 // Bubble shadow color and radius. 26 // Bubble shadow color and radius.
27 const SkColor kShadowColor = SkColorSetARGB(0xFF, 0, 0, 0); 27 const SkColor kShadowColor = SkColorSetARGB(0xFF, 0, 0, 0);
28 const int kShadowRadius = 4; 28 const int kShadowRadius = 4;
29 29
30 const SkColor kSearchBoxBackground = SK_ColorWHITE;
31
30 // Colors and sizes of top separator between searchbox and grid view. 32 // Colors and sizes of top separator between searchbox and grid view.
31 const SkColor kTopSeparatorColor = SkColorSetRGB(0xDB, 0xDB, 0xDB); 33 const SkColor kTopSeparatorColor = SkColorSetRGB(0xDB, 0xDB, 0xDB);
32 const int kTopSeparatorSize = 1; 34 const int kTopSeparatorSize = 1;
33 const SkColor kTopSeparatorGradientColor1 = SkColorSetRGB(0xEF, 0xEF, 0xEF); 35 const SkColor kTopSeparatorGradientColor1 = SkColorSetRGB(0xEF, 0xEF, 0xEF);
34 const SkColor kTopSeparatorGradientColor2 = SkColorSetRGB(0xF9, 0xF9, 0xF9); 36 const SkColor kTopSeparatorGradientColor2 = SkColorSetRGB(0xF9, 0xF9, 0xF9);
35 const int kTopSeparatorGradientSize = 9; 37 const int kTopSeparatorGradientSize = 9;
36 38
37 // Colors and sizes of bottom separator bwtween grid view and page switcher.
38 const SkColor kFooterBorderGradientColor1 = SkColorSetRGB(0x9F, 0x9F, 0x9F);
39 const SkColor kFooterBorderGradientColor2 = SkColorSetRGB(0xD9, 0xD9, 0xD9);
40 const int kFooterBorderSize = 3;
41 const SkColor kFooterBackground = SkColorSetRGB(0xD9, 0xD9, 0xD9);
42
43 // TODO(xiyuan): Merge this with the one in skia_util. 39 // TODO(xiyuan): Merge this with the one in skia_util.
44 SkShader* CreateVerticalGradientShader(int start_point, 40 SkShader* CreateVerticalGradientShader(int start_point,
45 int end_point, 41 int end_point,
46 SkColor start_color, 42 SkColor start_color,
47 SkColor end_color, 43 SkColor end_color,
48 SkShader::TileMode mode) { 44 SkShader::TileMode mode) {
49 SkColor grad_colors[2] = { start_color, end_color}; 45 SkColor grad_colors[2] = { start_color, end_color};
50 SkPoint grad_points[2]; 46 SkPoint grad_points[2];
51 grad_points[0].iset(0, start_point); 47 grad_points[0].iset(0, start_point);
52 grad_points[1].iset(0, end_point); 48 grad_points[1].iset(0, end_point);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 path->lineTo(center_x + arrow_offset + half_array_width, bottom); 82 path->lineTo(center_x + arrow_offset + half_array_width, bottom);
87 path->arcTo(right, bottom, right, center_y, SkIntToScalar(kCornerRadius)); 83 path->arcTo(right, bottom, right, center_y, SkIntToScalar(kCornerRadius));
88 path->arcTo(right, top, center_x, top, SkIntToScalar(kCornerRadius)); 84 path->arcTo(right, top, center_x, top, SkIntToScalar(kCornerRadius));
89 path->close(); 85 path->close();
90 } 86 }
91 87
92 } // namespace 88 } // namespace
93 89
94 namespace app_list { 90 namespace app_list {
95 91
96 AppListBubbleBorder::AppListBubbleBorder(views::View* app_list_view) 92 AppListBubbleBorder::AppListBubbleBorder(views::View* app_list_view,
93 views::View* search_box_view,
94 views::View* grid_view,
95 views::View* results_view)
97 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, 96 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT,
98 views::BubbleBorder::NO_SHADOW), 97 views::BubbleBorder::NO_SHADOW),
99 app_list_view_(app_list_view), 98 app_list_view_(app_list_view),
99 search_box_view_(search_box_view),
100 grid_view_(grid_view),
101 results_view_(results_view),
100 arrow_offset_(0) { 102 arrow_offset_(0) {
101 } 103 }
102 104
103 AppListBubbleBorder::~AppListBubbleBorder() { 105 AppListBubbleBorder::~AppListBubbleBorder() {
104 } 106 }
105 107
106 void AppListBubbleBorder::PaintModelViewBackground( 108 void AppListBubbleBorder::PaintSearchBoxBackground(
107 gfx::Canvas* canvas, 109 gfx::Canvas* canvas,
108 const gfx::Rect& bounds) const { 110 const gfx::Rect& bounds) const {
109 const views::View* page_switcher = app_list_view_->child_at(1); 111 const gfx::Rect search_box_view_bounds =
110 const gfx::Rect page_switcher_bounds = 112 app_list_view_->ConvertRectToWidget(search_box_view_->bounds());
111 app_list_view_->ConvertRectToWidget(page_switcher->bounds());
112 gfx::Rect rect(bounds.x(), 113 gfx::Rect rect(bounds.x(),
113 bounds.y(), 114 bounds.y(),
114 bounds.width(), 115 bounds.width(),
115 page_switcher_bounds.y() - bounds.y()); 116 search_box_view_bounds.bottom() - bounds.y());
116 117
117 // TODO(xiyuan): Draw 1px separator line after SearchBoxView is added. 118 SkPaint paint;
119 paint.setStyle(SkPaint::kFill_Style);
120 paint.setColor(kSearchBoxBackground);
121 canvas->DrawRect(rect, paint);
122
123 gfx::Rect seperator_rect(rect);
124 seperator_rect.set_y(seperator_rect.bottom());
125 seperator_rect.set_height(kTopSeparatorSize);
126 canvas->FillRect(seperator_rect, kTopSeparatorColor);
127 }
128
129 void AppListBubbleBorder::PaintSearchResultListBackground(
130 gfx::Canvas* canvas,
131 const gfx::Rect& bounds) const {
132 if (!results_view_->visible())
133 return;
134
135 const gfx::Rect search_box_view_bounds =
136 app_list_view_->ConvertRectToWidget(search_box_view_->bounds());
137 int start_y = search_box_view_bounds.bottom() + kTopSeparatorSize;
138 gfx::Rect rect(bounds.x(),
139 start_y,
140 bounds.width(),
141 bounds.bottom() - start_y + kArrowHeight);
142
143 SkPaint paint;
144 paint.setStyle(SkPaint::kFill_Style);
145 paint.setColor(kSearchBoxBackground);
146 canvas->DrawRect(rect, paint);
147 }
148
149 void AppListBubbleBorder::PaintAppsGridBackground(
150 gfx::Canvas* canvas,
151 const gfx::Rect& bounds) const {
152 if (!grid_view_->visible())
153 return;
154
155 const gfx::Rect search_box_view_bounds =
156 app_list_view_->ConvertRectToWidget(search_box_view_->bounds());
157 int start_y = search_box_view_bounds.bottom() + kTopSeparatorSize;
158 gfx::Rect rect(bounds.x(),
159 start_y,
160 bounds.width(),
161 bounds.bottom() - start_y + kArrowHeight);
118 162
119 SkPaint paint; 163 SkPaint paint;
120 paint.setStyle(SkPaint::kFill_Style); 164 paint.setStyle(SkPaint::kFill_Style);
121 SkSafeUnref(paint.setShader(CreateVerticalGradientShader( 165 SkSafeUnref(paint.setShader(CreateVerticalGradientShader(
122 rect.y(), 166 rect.y(),
123 rect.y() + kTopSeparatorGradientSize, 167 rect.y() + kTopSeparatorGradientSize,
124 kTopSeparatorGradientColor1, 168 kTopSeparatorGradientColor1,
125 kTopSeparatorGradientColor2, 169 kTopSeparatorGradientColor2,
126 SkShader::kClamp_TileMode))); 170 SkShader::kClamp_TileMode)));
127 canvas->DrawRect(rect, paint); 171 canvas->DrawRect(rect, paint);
128 } 172 }
129 173
130 void AppListBubbleBorder::PaintPageSwitcherBackground(
131 gfx::Canvas* canvas,
132 const gfx::Rect& bounds) const {
133 const views::View* page_switcher = app_list_view_->child_at(1);
134 const gfx::Rect page_switcher_bounds =
135 app_list_view_->ConvertRectToWidget(page_switcher->bounds());
136
137 gfx::Rect rect(bounds.x(),
138 page_switcher_bounds.y(),
139 bounds.width(),
140 kFooterBorderSize);
141 SkPaint paint;
142 paint.setStyle(SkPaint::kFill_Style);
143 SkSafeUnref(paint.setShader(CreateVerticalGradientShader(
144 rect.y(),
145 rect.bottom(),
146 kFooterBorderGradientColor1,
147 kFooterBorderGradientColor2,
148 SkShader::kClamp_TileMode)));
149 canvas->DrawRect(rect, paint);
150
151 rect.set_y(rect.bottom());
152 rect.set_height(bounds.bottom() - rect.y() + kArrowHeight - kBorderSize);
153 canvas->FillRect(rect, kFooterBackground);
154 }
155
156 void AppListBubbleBorder::GetInsets(gfx::Insets* insets) const { 174 void AppListBubbleBorder::GetInsets(gfx::Insets* insets) const {
157 insets->Set(kShadowRadius + kBorderSize, 175 insets->Set(kShadowRadius + kBorderSize,
158 kShadowRadius + kBorderSize, 176 kShadowRadius + kBorderSize,
159 kShadowRadius + kBorderSize + kArrowHeight, 177 kShadowRadius + kBorderSize + kArrowHeight,
160 kShadowRadius + kBorderSize); 178 kShadowRadius + kBorderSize);
161 } 179 }
162 180
163 gfx::Rect AppListBubbleBorder::GetBounds( 181 gfx::Rect AppListBubbleBorder::GetBounds(
164 const gfx::Rect& position_relative_to, 182 const gfx::Rect& position_relative_to,
165 const gfx::Size& contents_size) const { 183 const gfx::Size& contents_size) const {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 canvas->DrawPath(path, paint); 223 canvas->DrawPath(path, paint);
206 224
207 // Pads with kBoprderSize pixels to leave space for border lines. 225 // Pads with kBoprderSize pixels to leave space for border lines.
208 BuildShape(bounds, 226 BuildShape(bounds,
209 SkIntToScalar(kBorderSize), 227 SkIntToScalar(kBorderSize),
210 SkIntToScalar(arrow_offset_), 228 SkIntToScalar(arrow_offset_),
211 &path); 229 &path);
212 canvas->Save(); 230 canvas->Save();
213 canvas->ClipPath(path); 231 canvas->ClipPath(path);
214 232
215 PaintModelViewBackground(canvas, bounds); 233 PaintSearchBoxBackground(canvas, bounds);
216 PaintPageSwitcherBackground(canvas, bounds); 234 PaintAppsGridBackground(canvas, bounds);
235 PaintSearchResultListBackground(canvas, bounds);
217 236
218 canvas->Restore(); 237 canvas->Restore();
219 } 238 }
220 239
221 } // namespace app_list 240 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698