Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: chrome/browser/ui/views/location_bar/content_setting_image_view.cc

Issue 10821114: Refactor the content setting view to allow a subclass for the web intents button. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 TouchableLocationBarView::Init(this); 62 TouchableLocationBarView::Init(this);
63 } 63 }
64 64
65 ContentSettingImageView::~ContentSettingImageView() { 65 ContentSettingImageView::~ContentSettingImageView() {
66 if (bubble_widget_) { 66 if (bubble_widget_) {
67 bubble_widget_->RemoveObserver(this); 67 bubble_widget_->RemoveObserver(this);
68 bubble_widget_ = NULL; 68 bubble_widget_ = NULL;
69 } 69 }
70 } 70 }
71 71
72 void ContentSettingImageView::UpdateFromWebContents(WebContents* web_contents) { 72 void ContentSettingImageView::Update(TabContents* tab_contents) {
73 content_setting_image_model_->UpdateFromWebContents(web_contents); 73 if (tab_contents) {
74 content_setting_image_model_->UpdateFromWebContents(
75 tab_contents->web_contents());
76 }
74 if (!content_setting_image_model_->is_visible()) { 77 if (!content_setting_image_model_->is_visible()) {
75 SetVisible(false); 78 SetVisible(false);
76 return; 79 return;
77 } 80 }
78 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 81 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
79 content_setting_image_model_->get_icon())); 82 content_setting_image_model_->get_icon()));
80 SetTooltipText(UTF8ToUTF16(content_setting_image_model_->get_tooltip())); 83 SetTooltipText(UTF8ToUTF16(content_setting_image_model_->get_tooltip()));
81 SetVisible(true); 84 SetVisible(true);
82 85
83 TabSpecificContentSettings* content_settings = NULL; 86 TabSpecificContentSettings* content_settings = NULL;
84 if (web_contents) { 87 if (tab_contents)
85 content_settings = 88 content_settings = tab_contents->content_settings();
86 TabContents::FromWebContents(web_contents)->content_settings(); 89
87 }
88 if (!content_settings || content_settings->IsBlockageIndicated( 90 if (!content_settings || content_settings->IsBlockageIndicated(
89 content_setting_image_model_->get_content_settings_type())) 91 content_setting_image_model_->get_content_settings_type()))
90 return; 92 return;
91 93
92 // The content blockage was not yet indicated to the user. Start indication 94 // The content blockage was not yet indicated to the user. Start indication
93 // animation and clear "not yet shown" flag. 95 // animation and clear "not yet shown" flag.
94 content_settings->SetBlockageHasBeenIndicated( 96 content_settings->SetBlockageHasBeenIndicated(
95 content_setting_image_model_->get_content_settings_type()); 97 content_setting_image_model_->get_content_settings_type());
96 98
97 int animated_string_id = 99 int animated_string_id =
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 const ui::Animation* animation) { 159 const ui::Animation* animation) {
158 AnimationEnded(animation); 160 AnimationEnded(animation);
159 } 161 }
160 162
161 bool ContentSettingImageView::OnMousePressed(const views::MouseEvent& event) { 163 bool ContentSettingImageView::OnMousePressed(const views::MouseEvent& event) {
162 // We want to show the bubble on mouse release; that is the standard behavior 164 // We want to show the bubble on mouse release; that is the standard behavior
163 // for buttons. 165 // for buttons.
164 return true; 166 return true;
165 } 167 }
166 168
167 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) { 169 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) {
sky 2012/08/07 03:33:00 This class needs to override OnGestureEvent and tr
Greg Billock 2012/08/07 19:29:04 Done.
168 if (!HitTest(event.location())) 170 if (!HitTest(event.location()))
169 return; 171 return;
170 172
173 OnClick();
174 }
175
176 void ContentSettingImageView::OnClick() {
171 TabContents* tab_contents = parent_->GetTabContents(); 177 TabContents* tab_contents = parent_->GetTabContents();
172 if (!tab_contents) 178 if (!tab_contents)
173 return; 179 return;
174 180
175 // Stop animation. 181 // Stop animation.
176 if (slide_animator_.get() && slide_animator_->is_animating()) { 182 if (slide_animator_.get() && slide_animator_->is_animating()) {
177 slide_animator_->Reset(); 183 slide_animator_->Reset();
178 pause_animation_ = true; 184 pause_animation_ = true;
179 } 185 }
180 186
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 233 }
228 234
229 void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) { 235 void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) {
230 if (slide_animator_.get() && 236 if (slide_animator_.get() &&
231 (slide_animator_->is_animating() || pause_animation_)) { 237 (slide_animator_->is_animating() || pause_animation_)) {
232 // Paint yellow gradient background if in animation mode. 238 // Paint yellow gradient background if in animation mode.
233 const int kEdgeThickness = 1; 239 const int kEdgeThickness = 1;
234 SkPaint paint; 240 SkPaint paint;
235 paint.setShader(gfx::CreateGradientShader(kEdgeThickness, 241 paint.setShader(gfx::CreateGradientShader(kEdgeThickness,
236 height() - (2 * kEdgeThickness), 242 height() - (2 * kEdgeThickness),
237 kTopBoxColor, kBottomBoxColor)); 243 gradient_top_color(), gradient_bottom_color()));
238 SkSafeUnref(paint.getShader()); 244 SkSafeUnref(paint.getShader());
239 SkRect color_rect; 245 SkRect color_rect;
240 color_rect.iset(0, 0, width() - 1, height() - 1); 246 color_rect.iset(0, 0, width() - 1, height() - 1);
241 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, 247 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius,
242 kBoxCornerRadius, paint); 248 kBoxCornerRadius, paint);
243 SkPaint outer_paint; 249 SkPaint outer_paint;
244 outer_paint.setStyle(SkPaint::kStroke_Style); 250 outer_paint.setStyle(SkPaint::kStroke_Style);
245 outer_paint.setColor(kBorderColor); 251 outer_paint.setColor(button_border_color());
246 color_rect.inset(SkIntToScalar(kEdgeThickness), 252 color_rect.inset(SkIntToScalar(kEdgeThickness),
247 SkIntToScalar(kEdgeThickness)); 253 SkIntToScalar(kEdgeThickness));
248 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, 254 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius,
249 kBoxCornerRadius, outer_paint); 255 kBoxCornerRadius, outer_paint);
250 } else { 256 } else {
251 views::ImageView::OnPaintBackground(canvas); 257 views::ImageView::OnPaintBackground(canvas);
252 return; 258 return;
253 } 259 }
254 } 260 }
255 261
256 void ContentSettingImageView::OnWidgetClosing(views::Widget* widget) { 262 void ContentSettingImageView::OnWidgetClosing(views::Widget* widget) {
257 if (bubble_widget_) { 263 if (bubble_widget_) {
258 bubble_widget_->RemoveObserver(this); 264 bubble_widget_->RemoveObserver(this);
259 bubble_widget_ = NULL; 265 bubble_widget_ = NULL;
260 } 266 }
261 if (pause_animation_) { 267 if (pause_animation_) {
262 slide_animator_->Reset( 268 slide_animator_->Reset(
263 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_); 269 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_);
264 pause_animation_ = false; 270 pause_animation_ = false;
265 slide_animator_->Show(); 271 slide_animator_->Show();
266 } 272 }
267 } 273 }
268 274
269 int ContentSettingImageView::GetBuiltInHorizontalPadding() const { 275 int ContentSettingImageView::GetBuiltInHorizontalPadding() const {
270 return GetBuiltInHorizontalPaddingImpl(); 276 return GetBuiltInHorizontalPaddingImpl();
271 } 277 }
272 278
279 SkColor ContentSettingImageView::button_border_color() const {
sky 2012/08/07 03:33:00 Order doesn't match header.
Greg Billock 2012/08/07 19:29:04 These are right under GetBuiltInHorizontalPadding
280 return kBorderColor;
281 }
282
283 SkColor ContentSettingImageView::gradient_top_color() const {
284 return kTopBoxColor;
285 }
286
287 SkColor ContentSettingImageView::gradient_bottom_color() const {
288 return kBottomBoxColor;
289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698