Chromium Code Reviews| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 TouchableLocationBarView::Init(this); | 61 TouchableLocationBarView::Init(this); |
| 62 } | 62 } |
| 63 | 63 |
| 64 ContentSettingImageView::~ContentSettingImageView() { | 64 ContentSettingImageView::~ContentSettingImageView() { |
| 65 if (bubble_widget_) { | 65 if (bubble_widget_) { |
| 66 bubble_widget_->RemoveObserver(this); | 66 bubble_widget_->RemoveObserver(this); |
| 67 bubble_widget_ = NULL; | 67 bubble_widget_ = NULL; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ContentSettingImageView::UpdateFromWebContents(WebContents* web_contents) { | 71 void ContentSettingImageView::Update(TabContents* tab_contents) { |
| 72 content_setting_image_model_->UpdateFromWebContents(web_contents); | 72 if (tab_contents) { |
|
Bernhard Bauer
2012/07/31 23:31:18
Could we do an early-ish return if tab_content is
Greg Billock
2012/08/06 22:49:47
We could. That slightly changes the logic -- it'll
Bernhard Bauer
2012/08/07 00:08:37
Yeah... It's fine with me if you want to leave it
| |
| 73 content_setting_image_model_->UpdateFromWebContents( | |
| 74 tab_contents->web_contents()); | |
| 75 } | |
| 73 if (!content_setting_image_model_->is_visible()) { | 76 if (!content_setting_image_model_->is_visible()) { |
| 74 SetVisible(false); | 77 SetVisible(false); |
| 75 return; | 78 return; |
| 76 } | 79 } |
| 77 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 80 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 78 content_setting_image_model_->get_icon())); | 81 content_setting_image_model_->get_icon())); |
| 79 SetTooltipText(UTF8ToUTF16(content_setting_image_model_->get_tooltip())); | 82 SetTooltipText(UTF8ToUTF16(content_setting_image_model_->get_tooltip())); |
| 80 SetVisible(true); | 83 SetVisible(true); |
| 81 | 84 |
| 82 TabSpecificContentSettings* content_settings = NULL; | 85 TabSpecificContentSettings* content_settings = NULL; |
| 83 if (web_contents) { | 86 if (tab_contents) |
| 84 content_settings = | 87 content_settings = tab_contents->content_settings(); |
| 85 TabContents::FromWebContents(web_contents)->content_settings(); | 88 |
| 86 } | |
| 87 if (!content_settings || content_settings->IsBlockageIndicated( | 89 if (!content_settings || content_settings->IsBlockageIndicated( |
| 88 content_setting_image_model_->get_content_settings_type())) | 90 content_setting_image_model_->get_content_settings_type())) |
| 89 return; | 91 return; |
| 90 | 92 |
| 91 // The content blockage was not yet indicated to the user. Start indication | 93 // The content blockage was not yet indicated to the user. Start indication |
| 92 // animation and clear "not yet shown" flag. | 94 // animation and clear "not yet shown" flag. |
| 93 content_settings->SetBlockageHasBeenIndicated( | 95 content_settings->SetBlockageHasBeenIndicated( |
| 94 content_setting_image_model_->get_content_settings_type()); | 96 content_setting_image_model_->get_content_settings_type()); |
| 95 | 97 |
| 96 int animated_string_id = | 98 int animated_string_id = |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 bool ContentSettingImageView::OnMousePressed(const views::MouseEvent& event) { | 162 bool ContentSettingImageView::OnMousePressed(const views::MouseEvent& event) { |
| 161 // We want to show the bubble on mouse release; that is the standard behavior | 163 // We want to show the bubble on mouse release; that is the standard behavior |
| 162 // for buttons. | 164 // for buttons. |
| 163 return true; | 165 return true; |
| 164 } | 166 } |
| 165 | 167 |
| 166 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) { | 168 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) { |
| 167 if (!HitTest(event.location())) | 169 if (!HitTest(event.location())) |
| 168 return; | 170 return; |
| 169 | 171 |
| 172 OnClick(); | |
| 173 } | |
| 174 | |
| 175 void ContentSettingImageView::OnClick() { | |
| 170 TabContents* tab_contents = parent_->GetTabContents(); | 176 TabContents* tab_contents = parent_->GetTabContents(); |
| 171 if (!tab_contents) | 177 if (!tab_contents) |
| 172 return; | 178 return; |
| 173 | 179 |
| 174 // Stop animation. | 180 // Stop animation. |
| 175 if (slide_animator_.get() && slide_animator_->is_animating()) { | 181 if (slide_animator_.get() && slide_animator_->is_animating()) { |
| 176 slide_animator_->Reset(); | 182 slide_animator_->Reset(); |
| 177 pause_animation_ = true; | 183 pause_animation_ = true; |
| 178 } | 184 } |
| 179 | 185 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 } | 232 } |
| 227 | 233 |
| 228 void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) { | 234 void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) { |
| 229 if (slide_animator_.get() && | 235 if (slide_animator_.get() && |
| 230 (slide_animator_->is_animating() || pause_animation_)) { | 236 (slide_animator_->is_animating() || pause_animation_)) { |
| 231 // Paint yellow gradient background if in animation mode. | 237 // Paint yellow gradient background if in animation mode. |
| 232 const int kEdgeThickness = 1; | 238 const int kEdgeThickness = 1; |
| 233 SkPaint paint; | 239 SkPaint paint; |
| 234 paint.setShader(gfx::CreateGradientShader(kEdgeThickness, | 240 paint.setShader(gfx::CreateGradientShader(kEdgeThickness, |
| 235 height() - (2 * kEdgeThickness), | 241 height() - (2 * kEdgeThickness), |
| 236 kTopBoxColor, kBottomBoxColor)); | 242 gradient_top_color(), gradient_bottom_color())); |
| 237 SkSafeUnref(paint.getShader()); | 243 SkSafeUnref(paint.getShader()); |
| 238 SkRect color_rect; | 244 SkRect color_rect; |
| 239 color_rect.iset(0, 0, width() - 1, height() - 1); | 245 color_rect.iset(0, 0, width() - 1, height() - 1); |
| 240 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, | 246 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, |
| 241 kBoxCornerRadius, paint); | 247 kBoxCornerRadius, paint); |
| 242 SkPaint outer_paint; | 248 SkPaint outer_paint; |
| 243 outer_paint.setStyle(SkPaint::kStroke_Style); | 249 outer_paint.setStyle(SkPaint::kStroke_Style); |
| 244 outer_paint.setColor(kBorderColor); | 250 outer_paint.setColor(button_border_color()); |
| 245 color_rect.inset(SkIntToScalar(kEdgeThickness), | 251 color_rect.inset(SkIntToScalar(kEdgeThickness), |
| 246 SkIntToScalar(kEdgeThickness)); | 252 SkIntToScalar(kEdgeThickness)); |
| 247 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, | 253 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, |
| 248 kBoxCornerRadius, outer_paint); | 254 kBoxCornerRadius, outer_paint); |
| 249 } else { | 255 } else { |
| 250 views::ImageView::OnPaintBackground(canvas); | 256 views::ImageView::OnPaintBackground(canvas); |
| 251 return; | 257 return; |
| 252 } | 258 } |
| 253 } | 259 } |
| 254 | 260 |
| 255 void ContentSettingImageView::OnWidgetClosing(views::Widget* widget) { | 261 void ContentSettingImageView::OnWidgetClosing(views::Widget* widget) { |
| 256 if (bubble_widget_) { | 262 if (bubble_widget_) { |
| 257 bubble_widget_->RemoveObserver(this); | 263 bubble_widget_->RemoveObserver(this); |
| 258 bubble_widget_ = NULL; | 264 bubble_widget_ = NULL; |
| 259 } | 265 } |
| 260 if (pause_animation_) { | 266 if (pause_animation_) { |
| 261 slide_animator_->Reset( | 267 slide_animator_->Reset( |
| 262 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_); | 268 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_); |
| 263 pause_animation_ = false; | 269 pause_animation_ = false; |
| 264 slide_animator_->Show(); | 270 slide_animator_->Show(); |
| 265 } | 271 } |
| 266 } | 272 } |
| 267 | 273 |
| 268 int ContentSettingImageView::GetBuiltInHorizontalPadding() const { | 274 int ContentSettingImageView::GetBuiltInHorizontalPadding() const { |
| 269 return GetBuiltInHorizontalPaddingImpl(); | 275 return GetBuiltInHorizontalPaddingImpl(); |
| 270 } | 276 } |
| 271 | 277 |
| 278 SkColor ContentSettingImageView::button_border_color() const { | |
| 279 return kBorderColor; | |
| 280 } | |
| 281 | |
| 282 SkColor ContentSettingImageView::gradient_top_color() const { | |
| 283 return kTopBoxColor; | |
| 284 } | |
| 285 | |
| 286 SkColor ContentSettingImageView::gradient_bottom_color() const { | |
| 287 return kBottomBoxColor; | |
| 288 } | |
| OLD | NEW |