Chromium Code Reviews| Index: views/bubble/bubble_border.cc |
| diff --git a/views/bubble/bubble_border.cc b/views/bubble/bubble_border.cc |
| index 70f08dd7506de0dd4e74f6675adcec140f21755d..fe5d075628ae1d98635f87b695e9b9efcef4d770 100644 |
| --- a/views/bubble/bubble_border.cc |
| +++ b/views/bubble/bubble_border.cc |
| @@ -17,21 +17,8 @@ |
| namespace views { |
| // static |
| -SkBitmap* BubbleBorder::left_ = NULL; |
| -SkBitmap* BubbleBorder::top_left_ = NULL; |
| -SkBitmap* BubbleBorder::top_ = NULL; |
| -SkBitmap* BubbleBorder::top_right_ = NULL; |
| -SkBitmap* BubbleBorder::right_ = NULL; |
| -SkBitmap* BubbleBorder::bottom_right_ = NULL; |
| -SkBitmap* BubbleBorder::bottom_ = NULL; |
| -SkBitmap* BubbleBorder::bottom_left_ = NULL; |
| -SkBitmap* BubbleBorder::top_arrow_ = NULL; |
| -SkBitmap* BubbleBorder::bottom_arrow_ = NULL; |
| -SkBitmap* BubbleBorder::left_arrow_ = NULL; |
| -SkBitmap* BubbleBorder::right_arrow_ = NULL; |
| - |
| -// static |
| -int BubbleBorder::arrow_offset_; |
| +struct BorderImages* BubbleBorder::normal_images_ = NULL; |
| +struct BorderImages* BubbleBorder::shadow_images_ = NULL; |
| // The height inside the arrow image, in pixels. |
| static const int kArrowInteriorHeight = 7; |
| @@ -171,39 +158,65 @@ int BubbleBorder::SetArrowOffset(int offset, const gfx::Size& contents_size) { |
| return override_arrow_offset_; |
| } |
| -// static |
| -void BubbleBorder::InitClass() { |
| - static bool initialized = false; |
| - if (!initialized) { |
| - // Load images. |
| +void BubbleBorder::InitClass(Shadow shadow) { |
| + if (shadow == SHADOW && shadow_images_ == NULL) { |
| ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| - left_ = rb.GetBitmapNamed(IDR_BUBBLE_L); |
| - top_left_ = rb.GetBitmapNamed(IDR_BUBBLE_TL); |
| - top_ = rb.GetBitmapNamed(IDR_BUBBLE_T); |
| - top_right_ = rb.GetBitmapNamed(IDR_BUBBLE_TR); |
| - right_ = rb.GetBitmapNamed(IDR_BUBBLE_R); |
| - bottom_right_ = rb.GetBitmapNamed(IDR_BUBBLE_BR); |
| - bottom_ = rb.GetBitmapNamed(IDR_BUBBLE_B); |
| - bottom_left_ = rb.GetBitmapNamed(IDR_BUBBLE_BL); |
| - left_arrow_ = rb.GetBitmapNamed(IDR_BUBBLE_L_ARROW); |
| - top_arrow_ = rb.GetBitmapNamed(IDR_BUBBLE_T_ARROW); |
| - right_arrow_ = rb.GetBitmapNamed(IDR_BUBBLE_R_ARROW); |
| - bottom_arrow_ = rb.GetBitmapNamed(IDR_BUBBLE_B_ARROW); |
| - |
| - // Calculate horizontal and vertical insets for arrow by ensuring that |
| - // the widest arrow and corner images will have enough room to avoid overlap |
| - int offset_x = |
| - (std::max(top_arrow_->width(), bottom_arrow_->width()) / 2) + |
| - std::max(std::max(top_left_->width(), top_right_->width()), |
| - std::max(bottom_left_->width(), bottom_right_->width())); |
| - int offset_y = |
| - (std::max(left_arrow_->height(), right_arrow_->height()) / 2) + |
| - std::max(std::max(top_left_->height(), top_right_->height()), |
| - std::max(bottom_left_->height(), bottom_right_->height())); |
| - arrow_offset_ = std::max(offset_x, offset_y); |
| - |
| - initialized = true; |
| + shadow_images_ = new BorderImages(); |
| + shadow_images_->left = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_L); |
| + shadow_images_->top_left = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_TL); |
| + shadow_images_->top = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_T); |
| + shadow_images_->top_right = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_TR); |
| + shadow_images_->right = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_R); |
| + shadow_images_->bottom_right = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_BR); |
| + shadow_images_->bottom = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_B); |
| + shadow_images_->bottom_left = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_BL); |
| + shadow_images_->left_arrow = new SkBitmap(); |
| + shadow_images_->top_arrow = new SkBitmap(); |
| + shadow_images_->right_arrow = new SkBitmap(); |
| + shadow_images_->bottom_arrow = new SkBitmap(); |
| + } else if (shadow == NO_SHADOW && normal_images_ == NULL) { |
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| + normal_images_ = new BorderImages(); |
| + normal_images_->left = rb.GetBitmapNamed(IDR_BUBBLE_L); |
| + normal_images_->top_left = rb.GetBitmapNamed(IDR_BUBBLE_TL); |
| + normal_images_->top = rb.GetBitmapNamed(IDR_BUBBLE_T); |
| + normal_images_->top_right = rb.GetBitmapNamed(IDR_BUBBLE_TR); |
| + normal_images_->right = rb.GetBitmapNamed(IDR_BUBBLE_R); |
| + normal_images_->bottom_right = rb.GetBitmapNamed(IDR_BUBBLE_BR); |
| + normal_images_->bottom = rb.GetBitmapNamed(IDR_BUBBLE_B); |
| + normal_images_->bottom_left = rb.GetBitmapNamed(IDR_BUBBLE_BL); |
| + normal_images_->left_arrow = rb.GetBitmapNamed(IDR_BUBBLE_L_ARROW); |
| + normal_images_->top_arrow = rb.GetBitmapNamed(IDR_BUBBLE_T_ARROW); |
| + normal_images_->right_arrow = rb.GetBitmapNamed(IDR_BUBBLE_R_ARROW); |
| + normal_images_->bottom_arrow = rb.GetBitmapNamed(IDR_BUBBLE_B_ARROW); |
| } |
| + |
| + struct BorderImages* images = |
| + shadow == SHADOW ? shadow_images_ : normal_images_; |
| + left_ = images->left; |
| + top_left_ = images->top_left; |
| + top_ = images->top; |
| + top_right_ = images->top_right; |
| + right_ = images->right; |
| + bottom_right_ = images->bottom_right; |
| + bottom_ = images->bottom; |
| + bottom_left_ = images->bottom_left; |
| + left_arrow_ = images->left_arrow; |
| + top_arrow_ = images->top_arrow; |
| + right_arrow_ = images->right_arrow; |
| + bottom_arrow_ = images->bottom_arrow; |
| + |
| + // Calculate horizontal and vertical insets for arrow by ensuring that |
| + // the widest arrow and corner images will have enough room to avoid overlap |
| + int offset_x = |
| + (std::max(top_arrow_->width(), bottom_arrow_->width()) / 2) + |
| + std::max(std::max(top_left_->width(), top_right_->width()), |
| + std::max(bottom_left_->width(), bottom_right_->width())); |
| + int offset_y = |
| + (std::max(left_arrow_->height(), right_arrow_->height()) / 2) + |
| + std::max(std::max(top_left_->height(), top_right_->height()), |
| + std::max(bottom_left_->height(), bottom_right_->height())); |
| + arrow_offset_ = std::max(offset_x, offset_y); |
|
sky
2011/11/15 05:06:37
This method is poorly named now that it sets both
koz (OOO until 15th September)
2011/11/15 06:35:43
Done.
|
| } |
| BubbleBorder::~BubbleBorder() {} |