| 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/SkGradientShader.h" | 9 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/path.h" |
| 11 #include "ui/gfx/skia_util.h" | 12 #include "ui/gfx/skia_util.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Bubble border corner radius. | 16 // Bubble border corner radius. |
| 16 const int kCornerRadius = 2; | 17 const int kCornerRadius = 2; |
| 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; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 118 |
| 118 namespace app_list { | 119 namespace app_list { |
| 119 | 120 |
| 120 AppListBubbleBorder::AppListBubbleBorder(views::View* app_list_view, | 121 AppListBubbleBorder::AppListBubbleBorder(views::View* app_list_view, |
| 121 views::View* search_box_view) | 122 views::View* search_box_view) |
| 122 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, | 123 : views::BubbleBorder(views::BubbleBorder::BOTTOM_RIGHT, |
| 123 views::BubbleBorder::NO_SHADOW), | 124 views::BubbleBorder::NO_SHADOW), |
| 124 app_list_view_(app_list_view), | 125 app_list_view_(app_list_view), |
| 125 search_box_view_(search_box_view) { | 126 search_box_view_(search_box_view) { |
| 126 const gfx::ShadowValue kShadows[] = { | 127 const gfx::ShadowValue kShadows[] = { |
| 127 // Offset (0, 5), blur=8, color=0.36 black | 128 // Offset (0, 5), blur=30, color=0.36 black |
| 128 gfx::ShadowValue(gfx::Point(0, 5), 30, SkColorSetARGB(0x72, 0, 0, 0)), | 129 gfx::ShadowValue(gfx::Point(0, 5), 30, SkColorSetARGB(0x72, 0, 0, 0)), |
| 129 }; | 130 }; |
| 130 shadows_.assign(kShadows, kShadows + arraysize(kShadows)); | 131 shadows_.assign(kShadows, kShadows + arraysize(kShadows)); |
| 131 } | 132 } |
| 132 | 133 |
| 133 AppListBubbleBorder::~AppListBubbleBorder() { | 134 AppListBubbleBorder::~AppListBubbleBorder() { |
| 134 } | 135 } |
| 135 | 136 |
| 136 bool AppListBubbleBorder::ArrowAtTopOrBottom() const { | 137 bool AppListBubbleBorder::ArrowAtTopOrBottom() const { |
| 137 return arrow_location() == views::BubbleBorder::TOP_LEFT || | 138 return arrow_location() == views::BubbleBorder::TOP_LEFT || |
| 138 arrow_location() == views::BubbleBorder::TOP_RIGHT || | 139 arrow_location() == views::BubbleBorder::TOP_RIGHT || |
| 139 arrow_location() == views::BubbleBorder::BOTTOM_LEFT || | 140 arrow_location() == views::BubbleBorder::BOTTOM_LEFT || |
| 140 arrow_location() == views::BubbleBorder::BOTTOM_RIGHT; | 141 arrow_location() == views::BubbleBorder::BOTTOM_RIGHT; |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool AppListBubbleBorder::ArrowOnLeftOrRight() const { | 144 bool AppListBubbleBorder::ArrowOnLeftOrRight() const { |
| 144 return arrow_location() == views::BubbleBorder::LEFT_TOP || | 145 return arrow_location() == views::BubbleBorder::LEFT_TOP || |
| 145 arrow_location() == views::BubbleBorder::LEFT_BOTTOM || | 146 arrow_location() == views::BubbleBorder::LEFT_BOTTOM || |
| 146 arrow_location() == views::BubbleBorder::RIGHT_TOP || | 147 arrow_location() == views::BubbleBorder::RIGHT_TOP || |
| 147 arrow_location() == views::BubbleBorder::RIGHT_BOTTOM; | 148 arrow_location() == views::BubbleBorder::RIGHT_BOTTOM; |
| 148 } | 149 } |
| 149 | 150 |
| 151 void AppListBubbleBorder::GetMask(const gfx::Rect& bounds, |
| 152 gfx::Path* mask) const { |
| 153 gfx::Insets insets; |
| 154 GetInsets(&insets); |
| 155 |
| 156 gfx::Rect content_bounds(bounds); |
| 157 content_bounds.Inset(insets); |
| 158 |
| 159 BuildShape(content_bounds, |
| 160 arrow_location(), |
| 161 SkIntToScalar(GetArrowOffset()), |
| 162 SkIntToScalar(kBorderSize), |
| 163 mask); |
| 164 } |
| 165 |
| 150 int AppListBubbleBorder::GetArrowOffset() const { | 166 int AppListBubbleBorder::GetArrowOffset() const { |
| 151 if (ArrowAtTopOrBottom()) { | 167 if (ArrowAtTopOrBottom()) { |
| 152 // Picks x offset and moves bubble arrow in the opposite direction. | 168 // Picks x offset and moves bubble arrow in the opposite direction. |
| 153 // i.e. If bubble bounds is moved to right (positive offset), we need to | 169 // i.e. If bubble bounds is moved to right (positive offset), we need to |
| 154 // move arrow to left so that it points to the same position. | 170 // move arrow to left so that it points to the same position. |
| 155 return -offset_.x(); | 171 return -offset_.x(); |
| 156 } else if (ArrowOnLeftOrRight()) { | 172 } else if (ArrowOnLeftOrRight()) { |
| 157 // Picks y offset and moves bubble arrow in the opposite direction. | 173 // Picks y offset and moves bubble arrow in the opposite direction. |
| 158 return -offset_.y(); | 174 return -offset_.y(); |
| 159 } | 175 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 canvas->ClipPath(path); | 342 canvas->ClipPath(path); |
| 327 | 343 |
| 328 // Use full bounds so that arrow is also painted. | 344 // Use full bounds so that arrow is also painted. |
| 329 const gfx::Rect& bounds = view.bounds(); | 345 const gfx::Rect& bounds = view.bounds(); |
| 330 PaintBackground(canvas, bounds); | 346 PaintBackground(canvas, bounds); |
| 331 | 347 |
| 332 canvas->Restore(); | 348 canvas->Restore(); |
| 333 } | 349 } |
| 334 | 350 |
| 335 } // namespace app_list | 351 } // namespace app_list |
| OLD | NEW |