| 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/views/bubble/bubble_border.h" | 5 #include "ui/views/bubble/bubble_border.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 } // namespace internal | 69 } // namespace internal |
| 70 | 70 |
| 71 namespace { | 71 namespace { |
| 72 | 72 |
| 73 // The border and arrow stroke size used in image assets, in pixels. | 73 // The border and arrow stroke size used in image assets, in pixels. |
| 74 const int kStroke = 1; | 74 const int kStroke = 1; |
| 75 | 75 |
| 76 // Bubble border and arrow image resource ids. They don't use the IMAGE_GRID | 76 // Bubble border and arrow image resource ids. They don't use the IMAGE_GRID |
| 77 // macro because there is no center image. | 77 // macro because there is no center image. |
| 78 const int kShadowImages[] = { | |
| 79 IDR_BUBBLE_SHADOW_TL, IDR_BUBBLE_SHADOW_T, IDR_BUBBLE_SHADOW_TR, | |
| 80 IDR_BUBBLE_SHADOW_L, 0, IDR_BUBBLE_SHADOW_R, | |
| 81 IDR_BUBBLE_SHADOW_BL, IDR_BUBBLE_SHADOW_B, IDR_BUBBLE_SHADOW_BR }; | |
| 82 const int kShadowArrows[] = { 0, 0, 0, 0 }; | |
| 83 | |
| 84 const int kNoShadowImages[] = { | 78 const int kNoShadowImages[] = { |
| 85 IDR_BUBBLE_TL, IDR_BUBBLE_T, IDR_BUBBLE_TR, | 79 IDR_BUBBLE_TL, IDR_BUBBLE_T, IDR_BUBBLE_TR, |
| 86 IDR_BUBBLE_L, 0, IDR_BUBBLE_R, | 80 IDR_BUBBLE_L, 0, IDR_BUBBLE_R, |
| 87 IDR_BUBBLE_BL, IDR_BUBBLE_B, IDR_BUBBLE_BR }; | 81 IDR_BUBBLE_BL, IDR_BUBBLE_B, IDR_BUBBLE_BR }; |
| 88 const int kNoShadowArrows[] = { | 82 const int kNoShadowArrows[] = { |
| 89 IDR_BUBBLE_L_ARROW, IDR_BUBBLE_T_ARROW, | 83 IDR_BUBBLE_L_ARROW, IDR_BUBBLE_T_ARROW, |
| 90 IDR_BUBBLE_R_ARROW, IDR_BUBBLE_B_ARROW, }; | 84 IDR_BUBBLE_R_ARROW, IDR_BUBBLE_B_ARROW, }; |
| 91 | 85 |
| 92 const int kBigShadowImages[] = { | 86 const int kBigShadowImages[] = { |
| 93 IDR_WINDOW_BUBBLE_SHADOW_BIG_TOP_LEFT, | 87 IDR_WINDOW_BUBBLE_SHADOW_BIG_TOP_LEFT, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 BorderImages* GetBorderImages(BubbleBorder::Shadow shadow) { | 121 BorderImages* GetBorderImages(BubbleBorder::Shadow shadow) { |
| 128 // Keep a cache of bubble border image-set painters, arrows, and metrics. | 122 // Keep a cache of bubble border image-set painters, arrows, and metrics. |
| 129 static BorderImages* kBorderImages[BubbleBorder::SHADOW_COUNT] = { NULL }; | 123 static BorderImages* kBorderImages[BubbleBorder::SHADOW_COUNT] = { NULL }; |
| 130 | 124 |
| 131 CHECK_LT(shadow, BubbleBorder::SHADOW_COUNT); | 125 CHECK_LT(shadow, BubbleBorder::SHADOW_COUNT); |
| 132 struct BorderImages*& set = kBorderImages[shadow]; | 126 struct BorderImages*& set = kBorderImages[shadow]; |
| 133 if (set) | 127 if (set) |
| 134 return set; | 128 return set; |
| 135 | 129 |
| 136 switch (shadow) { | 130 switch (shadow) { |
| 137 case BubbleBorder::SHADOW: | |
| 138 // Note: SHADOW's border interior thickness is actually 10, but 0 is used | |
| 139 // here to match the legacy appearance of SHADOW's extra large inset. | |
| 140 set = new BorderImages(kShadowImages, kShadowArrows, 0, 0, 3); | |
| 141 break; | |
| 142 case BubbleBorder::NO_SHADOW: | 131 case BubbleBorder::NO_SHADOW: |
| 143 case BubbleBorder::NO_SHADOW_OPAQUE_BORDER: | 132 case BubbleBorder::NO_SHADOW_OPAQUE_BORDER: |
| 144 set = new BorderImages(kNoShadowImages, kNoShadowArrows, 6, 7, 4); | 133 set = new BorderImages(kNoShadowImages, kNoShadowArrows, 6, 7, 4); |
| 145 break; | 134 break; |
| 146 case BubbleBorder::BIG_SHADOW: | 135 case BubbleBorder::BIG_SHADOW: |
| 147 set = new BorderImages(kBigShadowImages, kBigShadowArrows, 23, 9, 2); | 136 set = new BorderImages(kBigShadowImages, kBigShadowArrows, 23, 9, 2); |
| 148 break; | 137 break; |
| 149 case BubbleBorder::SMALL_SHADOW: | 138 case BubbleBorder::SMALL_SHADOW: |
| 150 set = new BorderImages(kSmallShadowImages, kSmallShadowArrows, 5, 6, 2); | 139 set = new BorderImages(kSmallShadowImages, kSmallShadowArrows, 5, 6, 2); |
| 151 break; | 140 break; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 362 |
| 374 // Fill the contents with a round-rect region to match the border images. | 363 // Fill the contents with a round-rect region to match the border images. |
| 375 SkPaint paint; | 364 SkPaint paint; |
| 376 paint.setAntiAlias(true); | 365 paint.setAntiAlias(true); |
| 377 paint.setStyle(SkPaint::kFill_Style); | 366 paint.setStyle(SkPaint::kFill_Style); |
| 378 paint.setColor(border_->background_color()); | 367 paint.setColor(border_->background_color()); |
| 379 SkPath path; | 368 SkPath path; |
| 380 gfx::Rect bounds(view->GetLocalBounds()); | 369 gfx::Rect bounds(view->GetLocalBounds()); |
| 381 bounds.Inset(border_->GetInsets()); | 370 bounds.Inset(border_->GetInsets()); |
| 382 | 371 |
| 383 // Note: This matches the legacy appearance of SHADOW's extra large inset. | |
| 384 if (border_->shadow() == BubbleBorder::SHADOW) | |
| 385 bounds.Inset(-10, -10); | |
| 386 | |
| 387 SkScalar radius = SkIntToScalar(border_->GetBorderCornerRadius()); | 372 SkScalar radius = SkIntToScalar(border_->GetBorderCornerRadius()); |
| 388 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); | 373 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); |
| 389 canvas->DrawPath(path, paint); | 374 canvas->DrawPath(path, paint); |
| 390 } | 375 } |
| 391 | 376 |
| 392 } // namespace views | 377 } // namespace views |
| OLD | NEW |