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

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: Consume tap-down gesture 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"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" 12 #include "chrome/browser/ui/views/content_setting_bubble_contents.h"
13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "third_party/skia/include/core/SkShader.h" 15 #include "third_party/skia/include/core/SkShader.h"
16 #include "ui/base/animation/slide_animation.h" 16 #include "ui/base/animation/slide_animation.h"
17 #include "ui/base/animation/tween.h" 17 #include "ui/base/animation/tween.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/skia_util.h" 21 #include "ui/gfx/skia_util.h"
22 #include "ui/views/border.h" 22 #include "ui/views/border.h"
23 #include "ui/views/events/event.h"
23 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
24 25
25 using content::WebContents; 26 using content::WebContents;
26 27
27 namespace { 28 namespace {
28 // Animation parameters. 29 // Animation parameters.
29 const int kOpenTimeMs = 150; 30 const int kOpenTimeMs = 150;
30 const int kFullOpenedTimeMs = 3200; 31 const int kFullOpenedTimeMs = 3200;
31 const int kMoveTimeMs = kFullOpenedTimeMs + 2 * kOpenTimeMs; 32 const int kMoveTimeMs = kFullOpenedTimeMs + 2 * kOpenTimeMs;
32 const int kFrameRateHz = 60; 33 const int kFrameRateHz = 60;
(...skipping 29 matching lines...) Expand all
62 TouchableLocationBarView::Init(this); 63 TouchableLocationBarView::Init(this);
63 } 64 }
64 65
65 ContentSettingImageView::~ContentSettingImageView() { 66 ContentSettingImageView::~ContentSettingImageView() {
66 if (bubble_widget_) { 67 if (bubble_widget_) {
67 bubble_widget_->RemoveObserver(this); 68 bubble_widget_->RemoveObserver(this);
68 bubble_widget_ = NULL; 69 bubble_widget_ = NULL;
69 } 70 }
70 } 71 }
71 72
72 void ContentSettingImageView::UpdateFromWebContents(WebContents* web_contents) { 73 void ContentSettingImageView::Update(TabContents* tab_contents) {
73 content_setting_image_model_->UpdateFromWebContents(web_contents); 74 if (tab_contents) {
75 content_setting_image_model_->UpdateFromWebContents(
76 tab_contents->web_contents());
77 }
74 if (!content_setting_image_model_->is_visible()) { 78 if (!content_setting_image_model_->is_visible()) {
75 SetVisible(false); 79 SetVisible(false);
76 return; 80 return;
77 } 81 }
78 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 82 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
79 content_setting_image_model_->get_icon())); 83 content_setting_image_model_->get_icon()));
80 SetTooltipText(UTF8ToUTF16(content_setting_image_model_->get_tooltip())); 84 SetTooltipText(UTF8ToUTF16(content_setting_image_model_->get_tooltip()));
81 SetVisible(true); 85 SetVisible(true);
82 86
83 TabSpecificContentSettings* content_settings = NULL; 87 TabSpecificContentSettings* content_settings = NULL;
84 if (web_contents) { 88 if (tab_contents)
85 content_settings = 89 content_settings = tab_contents->content_settings();
86 TabContents::FromWebContents(web_contents)->content_settings(); 90
87 }
88 if (!content_settings || content_settings->IsBlockageIndicated( 91 if (!content_settings || content_settings->IsBlockageIndicated(
89 content_setting_image_model_->get_content_settings_type())) 92 content_setting_image_model_->get_content_settings_type()))
90 return; 93 return;
91 94
92 // The content blockage was not yet indicated to the user. Start indication 95 // The content blockage was not yet indicated to the user. Start indication
93 // animation and clear "not yet shown" flag. 96 // animation and clear "not yet shown" flag.
94 content_settings->SetBlockageHasBeenIndicated( 97 content_settings->SetBlockageHasBeenIndicated(
95 content_setting_image_model_->get_content_settings_type()); 98 content_setting_image_model_->get_content_settings_type());
96 99
97 int animated_string_id = 100 int animated_string_id =
(...skipping 21 matching lines...) Expand all
119 } 122 }
120 } 123 }
121 124
122 gfx::Size ContentSettingImageView::GetPreferredSize() { 125 gfx::Size ContentSettingImageView::GetPreferredSize() {
123 gfx::Size preferred_size(views::ImageView::GetPreferredSize()); 126 gfx::Size preferred_size(views::ImageView::GetPreferredSize());
124 // When view is animated visible_text_size_ > 0, it is 0 otherwise. 127 // When view is animated visible_text_size_ > 0, it is 0 otherwise.
125 preferred_size.set_width(preferred_size.width() + visible_text_size_); 128 preferred_size.set_width(preferred_size.width() + visible_text_size_);
126 return preferred_size; 129 return preferred_size;
127 } 130 }
128 131
132 ui::GestureStatus ContentSettingImageView::OnGestureEvent(
133 const views::GestureEvent& event) {
134 if (event.type() == ui::ET_GESTURE_TAP) {
135 OnClick();
136 return ui::GESTURE_STATUS_CONSUMED;
137 } else if (event.type() == ui::ET_GESTURE_TAP_DOWN) {
138 return ui::GESTURE_STATUS_CONSUMED;
139 }
140
141 return ui::GESTURE_STATUS_UNKNOWN;
142 }
143
144
129 void ContentSettingImageView::AnimationEnded(const ui::Animation* animation) { 145 void ContentSettingImageView::AnimationEnded(const ui::Animation* animation) {
130 if (pause_animation_) 146 if (pause_animation_)
131 pause_animation_ = false; 147 pause_animation_ = false;
132 slide_animator_->Reset(); 148 slide_animator_->Reset();
133 } 149 }
134 150
135 void ContentSettingImageView::AnimationProgressed( 151 void ContentSettingImageView::AnimationProgressed(
136 const ui::Animation* animation) { 152 const ui::Animation* animation) {
137 if (pause_animation_) 153 if (pause_animation_)
138 return; 154 return;
(...skipping 22 matching lines...) Expand all
161 bool ContentSettingImageView::OnMousePressed(const views::MouseEvent& event) { 177 bool ContentSettingImageView::OnMousePressed(const views::MouseEvent& event) {
162 // We want to show the bubble on mouse release; that is the standard behavior 178 // We want to show the bubble on mouse release; that is the standard behavior
163 // for buttons. 179 // for buttons.
164 return true; 180 return true;
165 } 181 }
166 182
167 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) { 183 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) {
168 if (!HitTest(event.location())) 184 if (!HitTest(event.location()))
169 return; 185 return;
170 186
187 OnClick();
188 }
189
190 void ContentSettingImageView::OnClick() {
171 TabContents* tab_contents = parent_->GetTabContents(); 191 TabContents* tab_contents = parent_->GetTabContents();
172 if (!tab_contents) 192 if (!tab_contents)
173 return; 193 return;
174 194
175 // Stop animation. 195 // Stop animation.
176 if (slide_animator_.get() && slide_animator_->is_animating()) { 196 if (slide_animator_.get() && slide_animator_->is_animating()) {
177 slide_animator_->Reset(); 197 slide_animator_->Reset();
178 pause_animation_ = true; 198 pause_animation_ = true;
179 } 199 }
180 200
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 247 }
228 248
229 void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) { 249 void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) {
230 if (slide_animator_.get() && 250 if (slide_animator_.get() &&
231 (slide_animator_->is_animating() || pause_animation_)) { 251 (slide_animator_->is_animating() || pause_animation_)) {
232 // Paint yellow gradient background if in animation mode. 252 // Paint yellow gradient background if in animation mode.
233 const int kEdgeThickness = 1; 253 const int kEdgeThickness = 1;
234 SkPaint paint; 254 SkPaint paint;
235 paint.setShader(gfx::CreateGradientShader(kEdgeThickness, 255 paint.setShader(gfx::CreateGradientShader(kEdgeThickness,
236 height() - (2 * kEdgeThickness), 256 height() - (2 * kEdgeThickness),
237 kTopBoxColor, kBottomBoxColor)); 257 GradientTopColor(), GradientBottomColor()));
238 SkSafeUnref(paint.getShader()); 258 SkSafeUnref(paint.getShader());
239 SkRect color_rect; 259 SkRect color_rect;
240 color_rect.iset(0, 0, width() - 1, height() - 1); 260 color_rect.iset(0, 0, width() - 1, height() - 1);
241 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, 261 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius,
242 kBoxCornerRadius, paint); 262 kBoxCornerRadius, paint);
243 SkPaint outer_paint; 263 SkPaint outer_paint;
244 outer_paint.setStyle(SkPaint::kStroke_Style); 264 outer_paint.setStyle(SkPaint::kStroke_Style);
245 outer_paint.setColor(kBorderColor); 265 outer_paint.setColor(ButtonBorderColor());
246 color_rect.inset(SkIntToScalar(kEdgeThickness), 266 color_rect.inset(SkIntToScalar(kEdgeThickness),
247 SkIntToScalar(kEdgeThickness)); 267 SkIntToScalar(kEdgeThickness));
248 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, 268 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius,
249 kBoxCornerRadius, outer_paint); 269 kBoxCornerRadius, outer_paint);
250 } else { 270 } else {
251 views::ImageView::OnPaintBackground(canvas); 271 views::ImageView::OnPaintBackground(canvas);
252 return; 272 return;
253 } 273 }
254 } 274 }
255 275
256 void ContentSettingImageView::OnWidgetClosing(views::Widget* widget) { 276 void ContentSettingImageView::OnWidgetClosing(views::Widget* widget) {
257 if (bubble_widget_) { 277 if (bubble_widget_) {
258 bubble_widget_->RemoveObserver(this); 278 bubble_widget_->RemoveObserver(this);
259 bubble_widget_ = NULL; 279 bubble_widget_ = NULL;
260 } 280 }
261 if (pause_animation_) { 281 if (pause_animation_) {
262 slide_animator_->Reset( 282 slide_animator_->Reset(
263 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_); 283 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_);
264 pause_animation_ = false; 284 pause_animation_ = false;
265 slide_animator_->Show(); 285 slide_animator_->Show();
266 } 286 }
267 } 287 }
268 288
269 int ContentSettingImageView::GetBuiltInHorizontalPadding() const { 289 int ContentSettingImageView::GetBuiltInHorizontalPadding() const {
270 return GetBuiltInHorizontalPaddingImpl(); 290 return GetBuiltInHorizontalPaddingImpl();
271 } 291 }
272 292
293 SkColor ContentSettingImageView::ButtonBorderColor() const {
294 return kBorderColor;
295 }
296
297 SkColor ContentSettingImageView::GradientTopColor() const {
298 return kTopBoxColor;
299 }
300
301 SkColor ContentSettingImageView::GradientBottomColor() const {
302 return kBottomBoxColor;
303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698