| OLD | NEW |
| 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/app_list/view_ids.h" |
| 11 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Bubble border corner radius. | 16 // Bubble border corner radius. |
| 16 const int kCornerRadius = 3; | 17 const int kCornerRadius = 3; |
| 17 | 18 |
| 18 // Arrow width and height. | 19 // Arrow width and height. |
| 19 const int kArrowHeight = 10; | 20 const int kArrowHeight = 10; |
| 20 const int kArrowWidth = 20; | 21 const int kArrowWidth = 20; |
| 21 | 22 |
| 22 // Bubble border color and width. | 23 // Bubble border color and width. |
| 23 const SkColor kBorderColor = SkColorSetARGB(0xFF, 0, 0, 0); | 24 const SkColor kBorderColor = SkColorSetARGB(0xFF, 0, 0, 0); |
| 24 const int kBorderSize = 1; | 25 const int kBorderSize = 1; |
| 25 | 26 |
| 26 // Bubble shadow color and radius. | 27 // Bubble shadow color and radius. |
| 27 const SkColor kShadowColor = SkColorSetARGB(0xFF, 0, 0, 0); | 28 const SkColor kShadowColor = SkColorSetARGB(0xFF, 0, 0, 0); |
| 28 const int kShadowRadius = 4; | 29 const int kShadowRadius = 4; |
| 29 | 30 |
| 31 const SkColor kSearchBoxBackground = SK_ColorWHITE; |
| 32 |
| 30 // Colors and sizes of top separator between searchbox and grid view. | 33 // Colors and sizes of top separator between searchbox and grid view. |
| 31 const SkColor kTopSeparatorColor = SkColorSetRGB(0xDB, 0xDB, 0xDB); | 34 const SkColor kTopSeparatorColor = SkColorSetRGB(0xDB, 0xDB, 0xDB); |
| 32 const int kTopSeparatorSize = 1; | 35 const int kTopSeparatorSize = 1; |
| 33 const SkColor kTopSeparatorGradientColor1 = SkColorSetRGB(0xEF, 0xEF, 0xEF); | 36 const SkColor kTopSeparatorGradientColor1 = SkColorSetRGB(0xEF, 0xEF, 0xEF); |
| 34 const SkColor kTopSeparatorGradientColor2 = SkColorSetRGB(0xF9, 0xF9, 0xF9); | 37 const SkColor kTopSeparatorGradientColor2 = SkColorSetRGB(0xF9, 0xF9, 0xF9); |
| 35 const int kTopSeparatorGradientSize = 9; | 38 const int kTopSeparatorGradientSize = 9; |
| 36 | 39 |
| 37 // Colors and sizes of bottom separator bwtween grid view and page switcher. | 40 // Colors and sizes of bottom separator bwtween grid view and page switcher. |
| 38 const SkColor kFooterBorderGradientColor1 = SkColorSetRGB(0x9F, 0x9F, 0x9F); | 41 const SkColor kFooterBorderGradientColor1 = SkColorSetRGB(0x9F, 0x9F, 0x9F); |
| 39 const SkColor kFooterBorderGradientColor2 = SkColorSetRGB(0xD9, 0xD9, 0xD9); | 42 const SkColor kFooterBorderGradientColor2 = SkColorSetRGB(0xD9, 0xD9, 0xD9); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 AppListBubbleBorder::AppListBubbleBorder(views::View* app_list_view) | 99 AppListBubbleBorder::AppListBubbleBorder(views::View* app_list_view) |
| 97 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, | 100 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, |
| 98 views::BubbleBorder::NO_SHADOW), | 101 views::BubbleBorder::NO_SHADOW), |
| 99 app_list_view_(app_list_view), | 102 app_list_view_(app_list_view), |
| 100 arrow_offset_(0) { | 103 arrow_offset_(0) { |
| 101 } | 104 } |
| 102 | 105 |
| 103 AppListBubbleBorder::~AppListBubbleBorder() { | 106 AppListBubbleBorder::~AppListBubbleBorder() { |
| 104 } | 107 } |
| 105 | 108 |
| 106 void AppListBubbleBorder::PaintModelViewBackground( | 109 void AppListBubbleBorder::PaintSearchBoxBackground( |
| 107 gfx::Canvas* canvas, | 110 gfx::Canvas* canvas, |
| 108 const gfx::Rect& bounds) const { | 111 const gfx::Rect& bounds) const { |
| 109 const views::View* page_switcher = app_list_view_->child_at(1); | 112 const views::View* search_box_view = |
| 110 const gfx::Rect page_switcher_bounds = | 113 app_list_view_->GetViewByID(VIEW_ID_SEARCH_BOX); |
| 111 app_list_view_->ConvertRectToWidget(page_switcher->bounds()); | 114 const gfx::Rect search_box_view_bounds = |
| 115 app_list_view_->ConvertRectToWidget(search_box_view->bounds()); |
| 112 gfx::Rect rect(bounds.x(), | 116 gfx::Rect rect(bounds.x(), |
| 113 bounds.y(), | 117 bounds.y(), |
| 114 bounds.width(), | 118 bounds.width(), |
| 115 page_switcher_bounds.y() - bounds.y()); | 119 search_box_view_bounds.bottom() - bounds.y()); |
| 116 | |
| 117 // TODO(xiyuan): Draw 1px separator line after SearchBoxView is added. | |
| 118 | 120 |
| 119 SkPaint paint; | 121 SkPaint paint; |
| 120 paint.setStyle(SkPaint::kFill_Style); | 122 paint.setStyle(SkPaint::kFill_Style); |
| 123 paint.setColor(kSearchBoxBackground); |
| 124 canvas->DrawRect(rect, paint); |
| 125 |
| 126 gfx::Rect seperator_rect(rect); |
| 127 seperator_rect.set_y(seperator_rect.bottom()); |
| 128 seperator_rect.set_height(kTopSeparatorSize); |
| 129 canvas->FillRect(seperator_rect, kTopSeparatorColor); |
| 130 } |
| 131 |
| 132 void AppListBubbleBorder::PaintSearchResultListBackground( |
| 133 gfx::Canvas* canvas, |
| 134 const gfx::Rect& bounds) const { |
| 135 const views::View* results_view = |
| 136 app_list_view_->GetViewByID(VIEW_ID_SEARCH_RESULTS); |
| 137 if (!results_view->visible()) |
| 138 return; |
| 139 |
| 140 const views::View* search_box_view = |
| 141 app_list_view_->GetViewByID(VIEW_ID_SEARCH_BOX); |
| 142 const gfx::Rect search_box_view_bounds = |
| 143 app_list_view_->ConvertRectToWidget(search_box_view->bounds()); |
| 144 int start_y = search_box_view_bounds.bottom() + kTopSeparatorSize; |
| 145 gfx::Rect rect(bounds.x(), |
| 146 start_y, |
| 147 bounds.width(), |
| 148 bounds.bottom() - start_y + kArrowHeight); |
| 149 |
| 150 SkPaint paint; |
| 151 paint.setStyle(SkPaint::kFill_Style); |
| 152 paint.setColor(kSearchBoxBackground); |
| 153 canvas->DrawRect(rect, paint); |
| 154 } |
| 155 |
| 156 void AppListBubbleBorder::PaintAppsGridBackground( |
| 157 gfx::Canvas* canvas, |
| 158 const gfx::Rect& bounds) const { |
| 159 const views::View* grid = |
| 160 app_list_view_->GetViewByID(VIEW_ID_APPS_GRID); |
| 161 if (!grid->visible()) |
| 162 return; |
| 163 |
| 164 const views::View* search_box_view = |
| 165 app_list_view_->GetViewByID(VIEW_ID_SEARCH_BOX); |
| 166 const gfx::Rect search_box_view_bounds = |
| 167 app_list_view_->ConvertRectToWidget(search_box_view->bounds()); |
| 168 const views::View* page_switcher = |
| 169 app_list_view_->GetViewByID(VIEW_ID_PAGE_SWITCHER); |
| 170 const gfx::Rect page_switcher_bounds = |
| 171 app_list_view_->ConvertRectToWidget(page_switcher->bounds()); |
| 172 int start_y = search_box_view_bounds.bottom() + kTopSeparatorSize; |
| 173 gfx::Rect rect(bounds.x(), |
| 174 start_y, |
| 175 bounds.width(), |
| 176 page_switcher_bounds.y() - start_y); |
| 177 |
| 178 SkPaint paint; |
| 179 paint.setStyle(SkPaint::kFill_Style); |
| 121 SkSafeUnref(paint.setShader(CreateVerticalGradientShader( | 180 SkSafeUnref(paint.setShader(CreateVerticalGradientShader( |
| 122 rect.y(), | 181 rect.y(), |
| 123 rect.y() + kTopSeparatorGradientSize, | 182 rect.y() + kTopSeparatorGradientSize, |
| 124 kTopSeparatorGradientColor1, | 183 kTopSeparatorGradientColor1, |
| 125 kTopSeparatorGradientColor2, | 184 kTopSeparatorGradientColor2, |
| 126 SkShader::kClamp_TileMode))); | 185 SkShader::kClamp_TileMode))); |
| 127 canvas->DrawRect(rect, paint); | 186 canvas->DrawRect(rect, paint); |
| 128 } | 187 } |
| 129 | 188 |
| 130 void AppListBubbleBorder::PaintPageSwitcherBackground( | 189 void AppListBubbleBorder::PaintPageSwitcherBackground( |
| 131 gfx::Canvas* canvas, | 190 gfx::Canvas* canvas, |
| 132 const gfx::Rect& bounds) const { | 191 const gfx::Rect& bounds) const { |
| 133 const views::View* page_switcher = app_list_view_->child_at(1); | 192 const views::View* page_switcher = |
| 193 app_list_view_->GetViewByID(VIEW_ID_PAGE_SWITCHER); |
| 194 if (!page_switcher->visible()) |
| 195 return; |
| 196 |
| 134 const gfx::Rect page_switcher_bounds = | 197 const gfx::Rect page_switcher_bounds = |
| 135 app_list_view_->ConvertRectToWidget(page_switcher->bounds()); | 198 app_list_view_->ConvertRectToWidget(page_switcher->bounds()); |
| 136 | 199 |
| 137 gfx::Rect rect(bounds.x(), | 200 gfx::Rect rect(bounds.x(), |
| 138 page_switcher_bounds.y(), | 201 page_switcher_bounds.y(), |
| 139 bounds.width(), | 202 bounds.width(), |
| 140 kFooterBorderSize); | 203 kFooterBorderSize); |
| 141 SkPaint paint; | 204 SkPaint paint; |
| 142 paint.setStyle(SkPaint::kFill_Style); | 205 paint.setStyle(SkPaint::kFill_Style); |
| 143 SkSafeUnref(paint.setShader(CreateVerticalGradientShader( | 206 SkSafeUnref(paint.setShader(CreateVerticalGradientShader( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 canvas->DrawPath(path, paint); | 268 canvas->DrawPath(path, paint); |
| 206 | 269 |
| 207 // Pads with kBoprderSize pixels to leave space for border lines. | 270 // Pads with kBoprderSize pixels to leave space for border lines. |
| 208 BuildShape(bounds, | 271 BuildShape(bounds, |
| 209 SkIntToScalar(kBorderSize), | 272 SkIntToScalar(kBorderSize), |
| 210 SkIntToScalar(arrow_offset_), | 273 SkIntToScalar(arrow_offset_), |
| 211 &path); | 274 &path); |
| 212 canvas->Save(); | 275 canvas->Save(); |
| 213 canvas->ClipPath(path); | 276 canvas->ClipPath(path); |
| 214 | 277 |
| 215 PaintModelViewBackground(canvas, bounds); | 278 PaintSearchBoxBackground(canvas, bounds); |
| 279 PaintAppsGridBackground(canvas, bounds); |
| 216 PaintPageSwitcherBackground(canvas, bounds); | 280 PaintPageSwitcherBackground(canvas, bounds); |
| 281 PaintSearchResultListBackground(canvas, bounds); |
| 217 | 282 |
| 218 canvas->Restore(); | 283 canvas->Restore(); |
| 219 } | 284 } |
| 220 | 285 |
| 221 } // namespace app_list | 286 } // namespace app_list |
| OLD | NEW |