| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/views/location_bar/icon_label_bubble_view.h" | 5 #include "chrome/browser/views/location_bar/icon_label_bubble_view.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "chrome/browser/views/location_bar/location_bar_view.h" | 8 #include "chrome/browser/views/location_bar/location_bar_view.h" |
| 9 #include "gfx/canvas.h" | 9 #include "gfx/canvas.h" |
| 10 #include "views/controls/image_view.h" | 10 #include "views/controls/image_view.h" |
| 11 #include "views/controls/label.h" | 11 #include "views/controls/label.h" |
| 12 | 12 |
| 13 // Amount to offset the image. | 13 // Amount of padding at the edges of the bubble. |
| 14 static const int kImageOffset = 1; | 14 static const int kBubbleOuterPadding = |
| 15 | 15 LocationBarView::kEdgeItemPadding - LocationBarView::kBubblePadding; |
| 16 // Amount to offset the label from the image. | |
| 17 static const int kLabelOffset = 3; | |
| 18 | 16 |
| 19 // Amount of padding after the label. | 17 // Amount of padding after the label. |
| 20 static const int kLabelPadding = 4; | 18 static const int kLabelPadding = 5; |
| 21 | 19 |
| 22 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], | 20 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], |
| 23 int contained_image, | 21 int contained_image, |
| 24 const SkColor& color) | 22 const SkColor& color) |
| 25 : background_painter_(background_images) { | 23 : background_painter_(background_images) { |
| 26 image_ = new views::ImageView(); | 24 image_ = new views::ImageView(); |
| 27 AddChildView(image_); | 25 AddChildView(image_); |
| 28 image_->SetImage( | 26 image_->SetImage( |
| 29 ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image)); | 27 ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image)); |
| 30 label_ = new views::Label(); | 28 label_ = new views::Label(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 | 39 |
| 42 void IconLabelBubbleView::SetLabel(const std::wstring& label) { | 40 void IconLabelBubbleView::SetLabel(const std::wstring& label) { |
| 43 label_->SetText(label); | 41 label_->SetText(label); |
| 44 } | 42 } |
| 45 | 43 |
| 46 void IconLabelBubbleView::SetImage(const SkBitmap& bitmap) { | 44 void IconLabelBubbleView::SetImage(const SkBitmap& bitmap) { |
| 47 image_->SetImage(bitmap); | 45 image_->SetImage(bitmap); |
| 48 } | 46 } |
| 49 | 47 |
| 50 void IconLabelBubbleView::Paint(gfx::Canvas* canvas) { | 48 void IconLabelBubbleView::Paint(gfx::Canvas* canvas) { |
| 51 int y_offset = (GetParent()->height() - height()) / 2; | |
| 52 canvas->TranslateInt(0, y_offset); | |
| 53 background_painter_.Paint(width(), height(), canvas); | 49 background_painter_.Paint(width(), height(), canvas); |
| 54 canvas->TranslateInt(0, -y_offset); | |
| 55 } | 50 } |
| 56 | 51 |
| 57 gfx::Size IconLabelBubbleView::GetPreferredSize() { | 52 gfx::Size IconLabelBubbleView::GetPreferredSize() { |
| 58 gfx::Size size(GetNonLabelSize()); | 53 gfx::Size size(GetNonLabelSize()); |
| 59 size.Enlarge(label_->GetPreferredSize().width(), 0); | 54 size.Enlarge(label_->GetPreferredSize().width(), 0); |
| 60 return size; | 55 return size; |
| 61 } | 56 } |
| 62 | 57 |
| 63 void IconLabelBubbleView::Layout() { | 58 void IconLabelBubbleView::Layout() { |
| 64 image_->SetBounds(kImageOffset, 0, image_->GetPreferredSize().width(), | 59 image_->SetBounds(kBubbleOuterPadding, 0, image_->GetPreferredSize().width(), |
| 65 height()); | 60 height()); |
| 66 const int label_height = label_->GetPreferredSize().height(); | 61 const int label_height = label_->GetPreferredSize().height(); |
| 67 label_->SetBounds(image_->x() + image_->width() + kLabelOffset, | 62 label_->SetBounds(image_->x() + image_->width() + |
| 68 (height() - label_height) / 2, width() - GetNonLabelWidth(), | 63 LocationBarView::kItemPadding, (height() - label_height) / 2, |
| 69 label_height); | 64 width() - GetNonLabelWidth(), label_height); |
| 70 } | 65 } |
| 71 | 66 |
| 72 void IconLabelBubbleView::SetElideInMiddle(bool elide_in_middle) { | 67 void IconLabelBubbleView::SetElideInMiddle(bool elide_in_middle) { |
| 73 label_->SetElideInMiddle(elide_in_middle); | 68 label_->SetElideInMiddle(elide_in_middle); |
| 74 } | 69 } |
| 75 | 70 |
| 76 gfx::Size IconLabelBubbleView::GetNonLabelSize() { | 71 gfx::Size IconLabelBubbleView::GetNonLabelSize() { |
| 77 return gfx::Size(GetNonLabelWidth(), background_painter_.height()); | 72 return gfx::Size(GetNonLabelWidth(), background_painter_.height()); |
| 78 } | 73 } |
| 79 | 74 |
| 80 int IconLabelBubbleView::GetNonLabelWidth() { | 75 int IconLabelBubbleView::GetNonLabelWidth() { |
| 81 return kImageOffset + image_->GetPreferredSize().width() + kLabelOffset + | 76 return kBubbleOuterPadding + image_->GetPreferredSize().width() + |
| 82 kLabelPadding; | 77 LocationBarView::kItemPadding + kBubbleOuterPadding; |
| 83 } | 78 } |
| OLD | NEW |