| 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 "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" | 5 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/color_utils.h" | 11 #include "ui/gfx/color_utils.h" |
| 12 #include "ui/views/controls/image_view.h" | 12 #include "ui/views/controls/image_view.h" |
| 13 #include "ui/views/painter.h" | 13 #include "ui/views/painter.h" |
| 14 | 14 |
| 15 | |
| 16 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], | 15 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], |
| 17 const int hover_background_images[], | 16 const int hover_background_images[], |
| 18 int contained_image, | 17 int contained_image, |
| 19 const gfx::FontList& font_list, | 18 const gfx::FontList& font_list, |
| 20 SkColor text_color, | 19 SkColor text_color, |
| 21 SkColor parent_background_color, | 20 SkColor parent_background_color, |
| 22 bool elide_in_middle) | 21 bool elide_in_middle) |
| 23 : background_painter_( | 22 : background_painter_( |
| 24 views::Painter::CreateImageGridPainter(background_images)), | 23 views::Painter::CreateImageGridPainter(background_images)), |
| 25 image_(new views::ImageView()), | 24 image_(new views::ImageView()), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 70 } |
| 72 | 71 |
| 73 void IconLabelBubbleView::SetLabel(const base::string16& label) { | 72 void IconLabelBubbleView::SetLabel(const base::string16& label) { |
| 74 label_->SetText(label); | 73 label_->SetText(label); |
| 75 } | 74 } |
| 76 | 75 |
| 77 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { | 76 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { |
| 78 image_->SetImage(image_skia); | 77 image_->SetImage(image_skia); |
| 79 } | 78 } |
| 80 | 79 |
| 80 const char* IconLabelBubbleView::GetClassName() const { |
| 81 return "IconLabelBubbleView"; |
| 82 } |
| 83 |
| 81 gfx::Size IconLabelBubbleView::GetPreferredSize() const { | 84 gfx::Size IconLabelBubbleView::GetPreferredSize() const { |
| 82 // Height will be ignored by the LocationBarView. | 85 // Height will be ignored by the LocationBarView. |
| 83 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); | 86 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); |
| 84 } | 87 } |
| 85 | 88 |
| 86 void IconLabelBubbleView::Layout() { | 89 void IconLabelBubbleView::Layout() { |
| 87 image_->SetBounds(GetBubbleOuterPadding(!is_extension_icon_), 0, | 90 image_->SetBounds(GetBubbleOuterPadding(!is_extension_icon_), 0, |
| 88 image_->GetPreferredSize().width(), height()); | 91 image_->GetPreferredSize().width(), height()); |
| 89 const int pre_label_width = GetPreLabelWidth(); | 92 const int pre_label_width = GetPreLabelWidth(); |
| 90 label_->SetBounds(pre_label_width, 0, | 93 label_->SetBounds(pre_label_width, 0, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 120 views::Painter* painter = (in_hover_ && hover_background_painter_) ? | 123 views::Painter* painter = (in_hover_ && hover_background_painter_) ? |
| 121 hover_background_painter_.get() : background_painter_.get(); | 124 hover_background_painter_.get() : background_painter_.get(); |
| 122 painter->Paint(canvas, size()); | 125 painter->Paint(canvas, size()); |
| 123 } | 126 } |
| 124 | 127 |
| 125 int IconLabelBubbleView::GetPreLabelWidth() const { | 128 int IconLabelBubbleView::GetPreLabelWidth() const { |
| 126 const int image_width = image_->GetPreferredSize().width(); | 129 const int image_width = image_->GetPreferredSize().width(); |
| 127 return GetBubbleOuterPadding(true) + | 130 return GetBubbleOuterPadding(true) + |
| 128 (image_width ? (image_width + LocationBarView::kItemPadding) : 0); | 131 (image_width ? (image_width + LocationBarView::kItemPadding) : 0); |
| 129 } | 132 } |
| OLD | NEW |