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/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 Loading... | |
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 Loading... | |
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; | |
sky
2012/08/07 20:46:19
You need to return CONSUMED for event.type() == ui
Greg Billock
2012/08/07 22:11:41
Done.
| |
137 } | |
138 return ui::GESTURE_STATUS_UNKNOWN; | |
139 } | |
140 | |
141 | |
129 void ContentSettingImageView::AnimationEnded(const ui::Animation* animation) { | 142 void ContentSettingImageView::AnimationEnded(const ui::Animation* animation) { |
130 if (pause_animation_) | 143 if (pause_animation_) |
131 pause_animation_ = false; | 144 pause_animation_ = false; |
132 slide_animator_->Reset(); | 145 slide_animator_->Reset(); |
133 } | 146 } |
134 | 147 |
135 void ContentSettingImageView::AnimationProgressed( | 148 void ContentSettingImageView::AnimationProgressed( |
136 const ui::Animation* animation) { | 149 const ui::Animation* animation) { |
137 if (pause_animation_) | 150 if (pause_animation_) |
138 return; | 151 return; |
(...skipping 22 matching lines...) Expand all Loading... | |
161 bool ContentSettingImageView::OnMousePressed(const views::MouseEvent& event) { | 174 bool ContentSettingImageView::OnMousePressed(const views::MouseEvent& event) { |
162 // We want to show the bubble on mouse release; that is the standard behavior | 175 // We want to show the bubble on mouse release; that is the standard behavior |
163 // for buttons. | 176 // for buttons. |
164 return true; | 177 return true; |
165 } | 178 } |
166 | 179 |
167 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) { | 180 void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event) { |
168 if (!HitTest(event.location())) | 181 if (!HitTest(event.location())) |
169 return; | 182 return; |
170 | 183 |
184 OnClick(); | |
185 } | |
186 | |
187 void ContentSettingImageView::OnClick() { | |
171 TabContents* tab_contents = parent_->GetTabContents(); | 188 TabContents* tab_contents = parent_->GetTabContents(); |
172 if (!tab_contents) | 189 if (!tab_contents) |
173 return; | 190 return; |
174 | 191 |
175 // Stop animation. | 192 // Stop animation. |
176 if (slide_animator_.get() && slide_animator_->is_animating()) { | 193 if (slide_animator_.get() && slide_animator_->is_animating()) { |
177 slide_animator_->Reset(); | 194 slide_animator_->Reset(); |
178 pause_animation_ = true; | 195 pause_animation_ = true; |
179 } | 196 } |
180 | 197 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 } | 244 } |
228 | 245 |
229 void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) { | 246 void ContentSettingImageView::OnPaintBackground(gfx::Canvas* canvas) { |
230 if (slide_animator_.get() && | 247 if (slide_animator_.get() && |
231 (slide_animator_->is_animating() || pause_animation_)) { | 248 (slide_animator_->is_animating() || pause_animation_)) { |
232 // Paint yellow gradient background if in animation mode. | 249 // Paint yellow gradient background if in animation mode. |
233 const int kEdgeThickness = 1; | 250 const int kEdgeThickness = 1; |
234 SkPaint paint; | 251 SkPaint paint; |
235 paint.setShader(gfx::CreateGradientShader(kEdgeThickness, | 252 paint.setShader(gfx::CreateGradientShader(kEdgeThickness, |
236 height() - (2 * kEdgeThickness), | 253 height() - (2 * kEdgeThickness), |
237 kTopBoxColor, kBottomBoxColor)); | 254 GradientTopColor(), GradientBottomColor())); |
238 SkSafeUnref(paint.getShader()); | 255 SkSafeUnref(paint.getShader()); |
239 SkRect color_rect; | 256 SkRect color_rect; |
240 color_rect.iset(0, 0, width() - 1, height() - 1); | 257 color_rect.iset(0, 0, width() - 1, height() - 1); |
241 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, | 258 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, |
242 kBoxCornerRadius, paint); | 259 kBoxCornerRadius, paint); |
243 SkPaint outer_paint; | 260 SkPaint outer_paint; |
244 outer_paint.setStyle(SkPaint::kStroke_Style); | 261 outer_paint.setStyle(SkPaint::kStroke_Style); |
245 outer_paint.setColor(kBorderColor); | 262 outer_paint.setColor(ButtonBorderColor()); |
246 color_rect.inset(SkIntToScalar(kEdgeThickness), | 263 color_rect.inset(SkIntToScalar(kEdgeThickness), |
247 SkIntToScalar(kEdgeThickness)); | 264 SkIntToScalar(kEdgeThickness)); |
248 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, | 265 canvas->sk_canvas()->drawRoundRect(color_rect, kBoxCornerRadius, |
249 kBoxCornerRadius, outer_paint); | 266 kBoxCornerRadius, outer_paint); |
250 } else { | 267 } else { |
251 views::ImageView::OnPaintBackground(canvas); | 268 views::ImageView::OnPaintBackground(canvas); |
252 return; | 269 return; |
253 } | 270 } |
254 } | 271 } |
255 | 272 |
256 void ContentSettingImageView::OnWidgetClosing(views::Widget* widget) { | 273 void ContentSettingImageView::OnWidgetClosing(views::Widget* widget) { |
257 if (bubble_widget_) { | 274 if (bubble_widget_) { |
258 bubble_widget_->RemoveObserver(this); | 275 bubble_widget_->RemoveObserver(this); |
259 bubble_widget_ = NULL; | 276 bubble_widget_ = NULL; |
260 } | 277 } |
261 if (pause_animation_) { | 278 if (pause_animation_) { |
262 slide_animator_->Reset( | 279 slide_animator_->Reset( |
263 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_); | 280 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_); |
264 pause_animation_ = false; | 281 pause_animation_ = false; |
265 slide_animator_->Show(); | 282 slide_animator_->Show(); |
266 } | 283 } |
267 } | 284 } |
268 | 285 |
269 int ContentSettingImageView::GetBuiltInHorizontalPadding() const { | 286 int ContentSettingImageView::GetBuiltInHorizontalPadding() const { |
270 return GetBuiltInHorizontalPaddingImpl(); | 287 return GetBuiltInHorizontalPaddingImpl(); |
271 } | 288 } |
272 | 289 |
290 SkColor ContentSettingImageView::ButtonBorderColor() const { | |
291 return kBorderColor; | |
292 } | |
293 | |
294 SkColor ContentSettingImageView::GradientTopColor() const { | |
295 return kTopBoxColor; | |
296 } | |
297 | |
298 SkColor ContentSettingImageView::GradientBottomColor() const { | |
299 return kBottomBoxColor; | |
300 } | |
OLD | NEW |