| 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 "grit/theme_resources.h" | 9 #include "grit/theme_resources.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/color_utils.h" | 12 #include "ui/gfx/color_utils.h" |
| 13 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/controls/label.h" | 14 #include "ui/views/controls/label.h" |
| 15 #include "ui/views/painter.h" | 15 #include "ui/views/painter.h" |
| 16 | 16 |
| 17 | 17 |
| 18 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], | 18 IconLabelBubbleView::IconLabelBubbleView(const int background_images[], |
| 19 const int hover_background_images[], | 19 const int hover_background_images[], |
| 20 int contained_image, | 20 int contained_image, |
| 21 const gfx::Font& font, | 21 const gfx::FontList& font_list, |
| 22 int font_y_offset, | 22 int font_y_offset, |
| 23 SkColor text_color, | 23 SkColor text_color, |
| 24 SkColor parent_background_color, | 24 SkColor parent_background_color, |
| 25 bool elide_in_middle) | 25 bool elide_in_middle) |
| 26 : background_painter_( | 26 : background_painter_( |
| 27 views::Painter::CreateImageGridPainter(background_images)), | 27 views::Painter::CreateImageGridPainter(background_images)), |
| 28 image_(new views::ImageView()), | 28 image_(new views::ImageView()), |
| 29 label_(new views::Label()), | 29 label_(new views::Label(string16(), font_list)), |
| 30 is_extension_icon_(false), | 30 is_extension_icon_(false), |
| 31 in_hover_(false) { | 31 in_hover_(false) { |
| 32 image_->SetImage( | 32 image_->SetImage( |
| 33 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 33 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 34 contained_image)); | 34 contained_image)); |
| 35 | 35 |
| 36 // Disable separate hit testing for |image_|. This prevents views treating | 36 // Disable separate hit testing for |image_|. This prevents views treating |
| 37 // |image_| as a separate mouse hover region from |this|. | 37 // |image_| as a separate mouse hover region from |this|. |
| 38 image_->set_interactive(false); | 38 image_->set_interactive(false); |
| 39 AddChildView(image_); | 39 AddChildView(image_); |
| 40 | 40 |
| 41 if (hover_background_images) { | 41 if (hover_background_images) { |
| 42 hover_background_painter_.reset( | 42 hover_background_painter_.reset( |
| 43 views::Painter::CreateImageGridPainter(hover_background_images)); | 43 views::Painter::CreateImageGridPainter(hover_background_images)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 label_->set_border(views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); | 46 label_->set_border(views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); |
| 47 label_->SetFont(font); | |
| 48 label_->SetEnabledColor(text_color); | 47 label_->SetEnabledColor(text_color); |
| 49 // Calculate the actual background color for the label. The background images | 48 // Calculate the actual background color for the label. The background images |
| 50 // are painted atop |parent_background_color|. We grab the color of the | 49 // are painted atop |parent_background_color|. We grab the color of the |
| 51 // middle pixel of the middle image of the background, which we treat as the | 50 // middle pixel of the middle image of the background, which we treat as the |
| 52 // representative color of the entire background (reasonable, given the | 51 // representative color of the entire background (reasonable, given the |
| 53 // current appearance of these images). Then we alpha-blend it over the | 52 // current appearance of these images). Then we alpha-blend it over the |
| 54 // parent background color to determine the actual color the label text will | 53 // parent background color to determine the actual color the label text will |
| 55 // sit atop. | 54 // sit atop. |
| 56 const SkBitmap& bitmap( | 55 const SkBitmap& bitmap( |
| 57 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 56 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 views::Painter* painter = (in_hover_ && hover_background_painter_) ? | 125 views::Painter* painter = (in_hover_ && hover_background_painter_) ? |
| 127 hover_background_painter_.get() : background_painter_.get(); | 126 hover_background_painter_.get() : background_painter_.get(); |
| 128 painter->Paint(canvas, size()); | 127 painter->Paint(canvas, size()); |
| 129 } | 128 } |
| 130 | 129 |
| 131 int IconLabelBubbleView::GetPreLabelWidth() const { | 130 int IconLabelBubbleView::GetPreLabelWidth() const { |
| 132 const int image_width = image_->GetPreferredSize().width(); | 131 const int image_width = image_->GetPreferredSize().width(); |
| 133 return GetBubbleOuterPadding(true) + | 132 return GetBubbleOuterPadding(true) + |
| 134 (image_width ? (image_width + LocationBarView::GetItemPadding()) : 0); | 133 (image_width ? (image_width + LocationBarView::GetItemPadding()) : 0); |
| 135 } | 134 } |
| OLD | NEW |