| 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/content_setting_image_view.h" | 5 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 10 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 10 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" | 11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
| 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/color_utils.h" | 16 #include "ui/gfx/color_utils.h" |
| 17 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
| 18 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 const int kBackgroundImages[] = IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE); | 23 const int kBackgroundImages[] = { |
| 24 IDR_OMNIBOX_CONTENT_SETTING_BUBBLE_LEFT, |
| 25 IDR_OMNIBOX_CONTENT_SETTING_BUBBLE_CENTER, |
| 26 IDR_OMNIBOX_CONTENT_SETTING_BUBBLE_RIGHT, |
| 27 }; |
| 24 const int kStayOpenTimeMS = 3200; // Time spent with animation fully open. | 28 const int kStayOpenTimeMS = 3200; // Time spent with animation fully open. |
| 25 } | 29 } |
| 26 | 30 |
| 27 | 31 |
| 28 // static | 32 // static |
| 29 const int ContentSettingImageView::kOpenTimeMS = 150; | 33 const int ContentSettingImageView::kOpenTimeMS = 150; |
| 30 const int ContentSettingImageView::kAnimationDurationMS = | 34 const int ContentSettingImageView::kAnimationDurationMS = |
| 31 (kOpenTimeMS * 2) + kStayOpenTimeMS; | 35 (kOpenTimeMS * 2) + kStayOpenTimeMS; |
| 32 | 36 |
| 33 ContentSettingImageView::ContentSettingImageView( | 37 ContentSettingImageView::ContentSettingImageView( |
| 34 ContentSettingsType content_type, | 38 ContentSettingsType content_type, |
| 35 LocationBarView* parent, | 39 LocationBarView* parent, |
| 36 const gfx::Font& font, | 40 const gfx::Font& font, |
| 37 int font_y_offset, | 41 int font_y_offset, |
| 38 SkColor text_color, | 42 SkColor text_color, |
| 39 SkColor parent_background_color) | 43 SkColor parent_background_color) |
| 40 : parent_(parent), | 44 : parent_(parent), |
| 41 content_setting_image_model_( | 45 content_setting_image_model_( |
| 42 ContentSettingImageModel::CreateContentSettingImageModel( | 46 ContentSettingImageModel::CreateContentSettingImageModel( |
| 43 content_type)), | 47 content_type)), |
| 44 background_painter_( | 48 background_painter_(new views::HorizontalPainter(kBackgroundImages)), |
| 45 views::Painter::CreateImageGridPainter(kBackgroundImages)), | |
| 46 icon_(new views::ImageView), | 49 icon_(new views::ImageView), |
| 47 text_label_(new views::Label), | 50 text_label_(new views::Label), |
| 48 slide_animator_(this), | 51 slide_animator_(this), |
| 49 pause_animation_(false), | 52 pause_animation_(false), |
| 50 pause_animation_state_(0.0), | 53 pause_animation_state_(0.0), |
| 51 bubble_widget_(NULL) { | 54 bubble_widget_(NULL) { |
| 52 icon_->SetHorizontalAlignment(views::ImageView::LEADING); | 55 icon_->SetHorizontalAlignment(views::ImageView::LEADING); |
| 53 AddChildView(icon_); | 56 AddChildView(icon_); |
| 54 | 57 |
| 55 text_label_->SetVisible(false); | 58 text_label_->SetVisible(false); |
| 56 text_label_->set_border( | 59 text_label_->set_border( |
| 57 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); | 60 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); |
| 58 text_label_->SetFont(font); | 61 text_label_->SetFont(font); |
| 59 text_label_->SetEnabledColor(text_color); | 62 text_label_->SetEnabledColor(text_color); |
| 60 // Calculate the actual background color for the label. The background images | 63 // Calculate the actual background color for the label. The background images |
| 61 // are painted atop |parent_background_color|. We grab the color of the | 64 // are painted atop |parent_background_color|. We grab the color of the |
| 62 // middle pixel of the middle image of the background, which we treat as the | 65 // middle pixel of the middle image of the background, which we treat as the |
| 63 // representative color of the entire background (reasonable, given the | 66 // representative color of the entire background (reasonable, given the |
| 64 // current appearance of these images). Then we alpha-blend it over the | 67 // current appearance of these images). Then we alpha-blend it over the |
| 65 // parent background color to determine the actual color the label text will | 68 // parent background color to determine the actual color the label text will |
| 66 // sit atop. | 69 // sit atop. |
| 67 const SkBitmap& bitmap( | 70 const SkBitmap& bitmap( |
| 68 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 71 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 69 kBackgroundImages[4])->GetRepresentation( | 72 kBackgroundImages[1])->GetRepresentation( |
| 70 ui::SCALE_FACTOR_100P).sk_bitmap()); | 73 ui::SCALE_FACTOR_100P).sk_bitmap()); |
| 71 SkAutoLockPixels pixel_lock(bitmap); | 74 SkAutoLockPixels pixel_lock(bitmap); |
| 72 SkColor background_image_color = | 75 SkColor background_image_color = |
| 73 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2); | 76 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2); |
| 74 // Tricky bit: We alpha blend an opaque version of |background_image_color| | 77 // Tricky bit: We alpha blend an opaque version of |background_image_color| |
| 75 // against |parent_background_color| using the original image grid color's | 78 // against |parent_background_color| using the original image grid color's |
| 76 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged | 79 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged |
| 77 // even if |a| is a color with non-255 alpha. | 80 // even if |a| is a color with non-255 alpha. |
| 78 text_label_->SetBackgroundColor( | 81 text_label_->SetBackgroundColor( |
| 79 color_utils::AlphaBlend(SkColorSetA(background_image_color, 255), | 82 color_utils::AlphaBlend(SkColorSetA(background_image_color, 255), |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( | 256 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( |
| 254 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 257 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 255 parent_->delegate()->GetContentSettingBubbleModelDelegate(), | 258 parent_->delegate()->GetContentSettingBubbleModelDelegate(), |
| 256 web_contents, parent_->profile(), | 259 web_contents, parent_->profile(), |
| 257 content_setting_image_model_->get_content_settings_type()), | 260 content_setting_image_model_->get_content_settings_type()), |
| 258 web_contents, this, views::BubbleBorder::TOP_RIGHT)); | 261 web_contents, this, views::BubbleBorder::TOP_RIGHT)); |
| 259 bubble_widget_->AddObserver(this); | 262 bubble_widget_->AddObserver(this); |
| 260 bubble_widget_->Show(); | 263 bubble_widget_->Show(); |
| 261 } | 264 } |
| 262 } | 265 } |
| OLD | NEW |