| 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 of padding at the edges of the bubble. | 13 // Amount of padding at the edges of the bubble. |
| 14 static const int kBubbleOuterPadding = | 14 static const int kBubbleOuterPadding = |
| 15 LocationBarView::kEdgeItemPadding - LocationBarView::kBubblePadding; | 15 LocationBarView::kEdgeItemPadding - LocationBarView::kBubblePadding; |
| 16 | 16 |
| 17 // Amount of padding after the label. | 17 // Amount of padding after the label. |
| 18 static const int kLabelPadding = 5; | 18 static const int kLabelPadding = 5; |
| 19 | 19 |
| 20 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], | 20 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], |
| 21 int contained_image, | 21 int contained_image, |
| 22 const SkColor& color) | 22 const SkColor& color) |
| 23 : background_painter_(background_images) { | 23 : background_painter_(background_images), |
| 24 item_padding_(LocationBarView::kItemPadding) { |
| 24 image_ = new views::ImageView(); | 25 image_ = new views::ImageView(); |
| 25 AddChildView(image_); | 26 AddChildView(image_); |
| 26 image_->SetImage( | 27 image_->SetImage( |
| 27 ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image)); | 28 ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image)); |
| 28 label_ = new views::Label(); | 29 label_ = new views::Label(); |
| 29 AddChildView(label_); | 30 AddChildView(label_); |
| 30 label_->SetColor(color); | 31 label_->SetColor(color); |
| 31 } | 32 } |
| 32 | 33 |
| 33 IconLabelBubbleView::~IconLabelBubbleView() { | 34 IconLabelBubbleView::~IconLabelBubbleView() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 53 gfx::Size size(GetNonLabelSize()); | 54 gfx::Size size(GetNonLabelSize()); |
| 54 size.Enlarge(label_->GetPreferredSize().width(), 0); | 55 size.Enlarge(label_->GetPreferredSize().width(), 0); |
| 55 return size; | 56 return size; |
| 56 } | 57 } |
| 57 | 58 |
| 58 void IconLabelBubbleView::Layout() { | 59 void IconLabelBubbleView::Layout() { |
| 59 image_->SetBounds(kBubbleOuterPadding, 0, image_->GetPreferredSize().width(), | 60 image_->SetBounds(kBubbleOuterPadding, 0, image_->GetPreferredSize().width(), |
| 60 height()); | 61 height()); |
| 61 const int label_height = label_->GetPreferredSize().height(); | 62 const int label_height = label_->GetPreferredSize().height(); |
| 62 label_->SetBounds(image_->x() + image_->width() + | 63 label_->SetBounds(image_->x() + image_->width() + |
| 63 LocationBarView::kItemPadding, (height() - label_height) / 2, | 64 item_padding_ , (height() - label_height) / 2, |
| 64 width() - GetNonLabelWidth(), label_height); | 65 width() - GetNonLabelWidth(), label_height); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void IconLabelBubbleView::SetElideInMiddle(bool elide_in_middle) { | 68 void IconLabelBubbleView::SetElideInMiddle(bool elide_in_middle) { |
| 68 label_->SetElideInMiddle(elide_in_middle); | 69 label_->SetElideInMiddle(elide_in_middle); |
| 69 } | 70 } |
| 70 | 71 |
| 71 gfx::Size IconLabelBubbleView::GetNonLabelSize() { | 72 gfx::Size IconLabelBubbleView::GetNonLabelSize() { |
| 72 return gfx::Size(GetNonLabelWidth(), background_painter_.height()); | 73 return gfx::Size(GetNonLabelWidth(), background_painter_.height()); |
| 73 } | 74 } |
| 74 | 75 |
| 75 int IconLabelBubbleView::GetNonLabelWidth() { | 76 int IconLabelBubbleView::GetNonLabelWidth() { |
| 76 return kBubbleOuterPadding + image_->GetPreferredSize().width() + | 77 return kBubbleOuterPadding + image_->GetPreferredSize().width() + |
| 77 LocationBarView::kItemPadding + kBubbleOuterPadding; | 78 item_padding_ + kBubbleOuterPadding; |
| 78 } | 79 } |
| OLD | NEW |