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/strings/utf_string_conversions.h" | 7 #include "base/strings/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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // static | 28 // static |
29 const int ContentSettingImageView::kOpenTimeMS = 150; | 29 const int ContentSettingImageView::kOpenTimeMS = 150; |
30 const int ContentSettingImageView::kAnimationDurationMS = | 30 const int ContentSettingImageView::kAnimationDurationMS = |
31 (kOpenTimeMS * 2) + kStayOpenTimeMS; | 31 (kOpenTimeMS * 2) + kStayOpenTimeMS; |
32 | 32 |
33 ContentSettingImageView::ContentSettingImageView( | 33 ContentSettingImageView::ContentSettingImageView( |
34 ContentSettingsType content_type, | 34 ContentSettingsType content_type, |
35 LocationBarView* parent, | 35 LocationBarView* parent, |
36 const gfx::FontList& font_list, | 36 const gfx::FontList& font_list, |
37 int font_y_offset, | |
38 SkColor text_color, | 37 SkColor text_color, |
39 SkColor parent_background_color) | 38 SkColor parent_background_color) |
40 : parent_(parent), | 39 : parent_(parent), |
41 content_setting_image_model_( | 40 content_setting_image_model_( |
42 ContentSettingImageModel::CreateContentSettingImageModel( | 41 ContentSettingImageModel::CreateContentSettingImageModel( |
43 content_type)), | 42 content_type)), |
44 background_painter_( | 43 background_painter_( |
45 views::Painter::CreateImageGridPainter(kBackgroundImages)), | 44 views::Painter::CreateImageGridPainter(kBackgroundImages)), |
46 icon_(new views::ImageView), | 45 icon_(new views::ImageView), |
47 text_label_(new views::Label(string16(), font_list)), | 46 text_label_(new views::Label(string16(), font_list)), |
48 slide_animator_(this), | 47 slide_animator_(this), |
49 pause_animation_(false), | 48 pause_animation_(false), |
50 pause_animation_state_(0.0), | 49 pause_animation_state_(0.0), |
51 bubble_widget_(NULL) { | 50 bubble_widget_(NULL) { |
52 icon_->SetHorizontalAlignment(views::ImageView::LEADING); | 51 icon_->SetHorizontalAlignment(views::ImageView::LEADING); |
53 AddChildView(icon_); | 52 AddChildView(icon_); |
54 | 53 |
55 text_label_->SetVisible(false); | 54 text_label_->SetVisible(false); |
56 text_label_->set_border( | |
57 views::Border::CreateEmptyBorder(font_y_offset, 0, 0, 0)); | |
58 text_label_->SetEnabledColor(text_color); | 55 text_label_->SetEnabledColor(text_color); |
59 // Calculate the actual background color for the label. The background images | 56 // Calculate the actual background color for the label. The background images |
60 // are painted atop |parent_background_color|. We grab the color of the | 57 // are painted atop |parent_background_color|. We grab the color of the |
61 // middle pixel of the middle image of the background, which we treat as the | 58 // middle pixel of the middle image of the background, which we treat as the |
62 // representative color of the entire background (reasonable, given the | 59 // representative color of the entire background (reasonable, given the |
63 // current appearance of these images). Then we alpha-blend it over the | 60 // current appearance of these images). Then we alpha-blend it over the |
64 // parent background color to determine the actual color the label text will | 61 // parent background color to determine the actual color the label text will |
65 // sit atop. | 62 // sit atop. |
66 const SkBitmap& bitmap( | 63 const SkBitmap& bitmap( |
67 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 64 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 200 } |
204 | 201 |
205 void ContentSettingImageView::Layout() { | 202 void ContentSettingImageView::Layout() { |
206 const int icon_width = icon_->GetPreferredSize().width(); | 203 const int icon_width = icon_->GetPreferredSize().width(); |
207 icon_->SetBounds( | 204 icon_->SetBounds( |
208 std::min((width() - icon_width) / 2, GetBubbleOuterPadding(true)), 0, | 205 std::min((width() - icon_width) / 2, GetBubbleOuterPadding(true)), 0, |
209 icon_width, height()); | 206 icon_width, height()); |
210 text_label_->SetBounds( | 207 text_label_->SetBounds( |
211 icon_->bounds().right() + LocationBarView::GetItemPadding(), 0, | 208 icon_->bounds().right() + LocationBarView::GetItemPadding(), 0, |
212 std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0), | 209 std::max(width() - GetTotalSpacingWhileAnimating() - icon_width, 0), |
213 text_label_->GetPreferredSize().height()); | 210 height()); |
214 } | 211 } |
215 | 212 |
216 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { | 213 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { |
217 // We want to show the bubble on mouse release; that is the standard behavior | 214 // We want to show the bubble on mouse release; that is the standard behavior |
218 // for buttons. | 215 // for buttons. |
219 return true; | 216 return true; |
220 } | 217 } |
221 | 218 |
222 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { | 219 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { |
223 if (HitTestPoint(event.location())) | 220 if (HitTestPoint(event.location())) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 bubble_widget_ = | 270 bubble_widget_ = |
274 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( | 271 parent_->delegate()->CreateViewsBubble(new ContentSettingBubbleContents( |
275 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 272 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
276 parent_->delegate()->GetContentSettingBubbleModelDelegate(), | 273 parent_->delegate()->GetContentSettingBubbleModelDelegate(), |
277 web_contents, parent_->profile(), | 274 web_contents, parent_->profile(), |
278 content_setting_image_model_->get_content_settings_type()), | 275 content_setting_image_model_->get_content_settings_type()), |
279 this, views::BubbleBorder::TOP_RIGHT)); | 276 this, views::BubbleBorder::TOP_RIGHT)); |
280 bubble_widget_->AddObserver(this); | 277 bubble_widget_->AddObserver(this); |
281 bubble_widget_->Show(); | 278 bubble_widget_->Show(); |
282 } | 279 } |
283 | |
OLD | NEW |