| 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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 label_->SetEnabledColor(text_color); | 47 label_->SetEnabledColor(text_color); |
| 48 // Calculate the actual background color for the label. The background images | 48 // Calculate the actual background color for the label. The background images |
| 49 // 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 |
| 50 // 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 |
| 51 // representative color of the entire background (reasonable, given the | 51 // representative color of the entire background (reasonable, given the |
| 52 // 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 |
| 53 // 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 |
| 54 // sit atop. | 54 // sit atop. |
| 55 const SkBitmap& bitmap( | 55 const SkBitmap& bitmap( |
| 56 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 56 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 57 background_images[4])->GetRepresentation( | 57 background_images[4])->GetRepresentation(1.0f).sk_bitmap()); |
| 58 ui::SCALE_FACTOR_100P).sk_bitmap()); | |
| 59 SkAutoLockPixels pixel_lock(bitmap); | 58 SkAutoLockPixels pixel_lock(bitmap); |
| 60 SkColor background_image_color = | 59 SkColor background_image_color = |
| 61 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2); | 60 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2); |
| 62 // Tricky bit: We alpha blend an opaque version of |background_image_color| | 61 // Tricky bit: We alpha blend an opaque version of |background_image_color| |
| 63 // against |parent_background_color| using the original image grid color's | 62 // against |parent_background_color| using the original image grid color's |
| 64 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged | 63 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged |
| 65 // even if |a| is a color with non-255 alpha. | 64 // even if |a| is a color with non-255 alpha. |
| 66 label_->SetBackgroundColor( | 65 label_->SetBackgroundColor( |
| 67 color_utils::AlphaBlend(SkColorSetA(background_image_color, 255), | 66 color_utils::AlphaBlend(SkColorSetA(background_image_color, 255), |
| 68 parent_background_color, | 67 parent_background_color, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 views::Painter* painter = (in_hover_ && hover_background_painter_) ? | 124 views::Painter* painter = (in_hover_ && hover_background_painter_) ? |
| 126 hover_background_painter_.get() : background_painter_.get(); | 125 hover_background_painter_.get() : background_painter_.get(); |
| 127 painter->Paint(canvas, size()); | 126 painter->Paint(canvas, size()); |
| 128 } | 127 } |
| 129 | 128 |
| 130 int IconLabelBubbleView::GetPreLabelWidth() const { | 129 int IconLabelBubbleView::GetPreLabelWidth() const { |
| 131 const int image_width = image_->GetPreferredSize().width(); | 130 const int image_width = image_->GetPreferredSize().width(); |
| 132 return GetBubbleOuterPadding(true) + | 131 return GetBubbleOuterPadding(true) + |
| 133 (image_width ? (image_width + LocationBarView::GetItemPadding()) : 0); | 132 (image_width ? (image_width + LocationBarView::GetItemPadding()) : 0); |
| 134 } | 133 } |
| OLD | NEW |