| 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/browser.h" | 9 #include "chrome/browser/ui/browser_show_actions.h" |
| 10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 11 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 11 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 13 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" | 13 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
| 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 15 #include "chrome/browser/ui/views/window.h" | 15 #include "chrome/browser/ui/views/window.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "third_party/skia/include/core/SkShader.h" | 17 #include "third_party/skia/include/core/SkShader.h" |
| 18 #include "ui/base/animation/slide_animation.h" | 18 #include "ui/base/animation/slide_animation.h" |
| 19 #include "ui/base/animation/tween.h" | 19 #include "ui/base/animation/tween.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 44 | 44 |
| 45 | 45 |
| 46 // The fraction of the animation we'll spend animating the string into view, and | 46 // The fraction of the animation we'll spend animating the string into view, and |
| 47 // then again animating it closed - total animation (slide out, show, then | 47 // then again animating it closed - total animation (slide out, show, then |
| 48 // slide in) is 1.0. | 48 // slide in) is 1.0. |
| 49 const double kAnimatingFraction = kOpenTimeMs * 1.0 / kMoveTimeMs; | 49 const double kAnimatingFraction = kOpenTimeMs * 1.0 / kMoveTimeMs; |
| 50 } | 50 } |
| 51 | 51 |
| 52 ContentSettingImageView::ContentSettingImageView( | 52 ContentSettingImageView::ContentSettingImageView( |
| 53 ContentSettingsType content_type, | 53 ContentSettingsType content_type, |
| 54 LocationBarView* parent) | 54 LocationBarView* parent, |
| 55 BrowserShowContentRelated* delegate) |
| 55 : content_setting_image_model_( | 56 : content_setting_image_model_( |
| 56 ContentSettingImageModel::CreateContentSettingImageModel( | 57 ContentSettingImageModel::CreateContentSettingImageModel( |
| 57 content_type)), | 58 content_type)), |
| 58 bubble_widget_(NULL), | 59 bubble_widget_(NULL), |
| 59 parent_(parent), | 60 parent_(parent), |
| 61 delegate_(delegate), |
| 60 pause_animation_(false), | 62 pause_animation_(false), |
| 61 text_size_(0), | 63 text_size_(0), |
| 62 visible_text_size_(0) { | 64 visible_text_size_(0) { |
| 63 SetHorizontalAlignment(ImageView::LEADING); | 65 SetHorizontalAlignment(ImageView::LEADING); |
| 64 } | 66 } |
| 65 | 67 |
| 66 ContentSettingImageView::~ContentSettingImageView() { | 68 ContentSettingImageView::~ContentSettingImageView() { |
| 67 if (bubble_widget_) { | 69 if (bubble_widget_) { |
| 68 bubble_widget_->RemoveObserver(this); | 70 bubble_widget_->RemoveObserver(this); |
| 69 bubble_widget_ = NULL; | 71 bubble_widget_ = NULL; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 TabContentsWrapper* tab_contents = parent_->GetTabContentsWrapper(); | 174 TabContentsWrapper* tab_contents = parent_->GetTabContentsWrapper(); |
| 173 if (!tab_contents) | 175 if (!tab_contents) |
| 174 return; | 176 return; |
| 175 | 177 |
| 176 // Stop animation. | 178 // Stop animation. |
| 177 if (slide_animator_.get() && slide_animator_->is_animating()) { | 179 if (slide_animator_.get() && slide_animator_->is_animating()) { |
| 178 slide_animator_->Reset(); | 180 slide_animator_->Reset(); |
| 179 pause_animation_ = true; | 181 pause_animation_ = true; |
| 180 } | 182 } |
| 181 | 183 |
| 182 Profile* profile = parent_->browser()->profile(); | 184 Profile* profile = parent_->profile(); |
| 183 ContentSettingBubbleContents* bubble = new ContentSettingBubbleContents( | 185 ContentSettingBubbleContents* bubble = new ContentSettingBubbleContents( |
| 184 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 186 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 185 parent_->browser(), | 187 delegate_, |
| 186 tab_contents, | 188 tab_contents, |
| 187 profile, | 189 profile, |
| 188 content_setting_image_model_->get_content_settings_type()), | 190 content_setting_image_model_->get_content_settings_type()), |
| 189 profile, | 191 profile, |
| 190 tab_contents->web_contents(), | 192 tab_contents->web_contents(), |
| 191 this, | 193 this, |
| 192 views::BubbleBorder::TOP_RIGHT); | 194 views::BubbleBorder::TOP_RIGHT); |
| 193 bubble_widget_ = browser::CreateViewsBubble(bubble); | 195 bubble_widget_ = parent_->CreateViewsBubble(bubble); |
| 194 bubble_widget_->AddObserver(this); | 196 bubble_widget_->AddObserver(this); |
| 195 bubble->Show(); | 197 bubble->Show(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 void ContentSettingImageView::OnPaint(gfx::Canvas* canvas) { | 200 void ContentSettingImageView::OnPaint(gfx::Canvas* canvas) { |
| 199 // During the animation we draw a border, an icon and the text. The text area | 201 // During the animation we draw a border, an icon and the text. The text area |
| 200 // is changing in size during the animation, giving the appearance of the text | 202 // is changing in size during the animation, giving the appearance of the text |
| 201 // sliding out and then back in. When the text completely slid out the yellow | 203 // sliding out and then back in. When the text completely slid out the yellow |
| 202 // border is no longer painted around the icon. |visible_text_size_| is 0 when | 204 // border is no longer painted around the icon. |visible_text_size_| is 0 when |
| 203 // animation is stopped. | 205 // animation is stopped. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 bubble_widget_->RemoveObserver(this); | 261 bubble_widget_->RemoveObserver(this); |
| 260 bubble_widget_ = NULL; | 262 bubble_widget_ = NULL; |
| 261 } | 263 } |
| 262 if (pause_animation_) { | 264 if (pause_animation_) { |
| 263 slide_animator_->Reset( | 265 slide_animator_->Reset( |
| 264 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_); | 266 1.0 - (visible_text_size_ * kAnimatingFraction) / text_size_); |
| 265 pause_animation_ = false; | 267 pause_animation_ = false; |
| 266 slide_animator_->Show(); | 268 slide_animator_->Show(); |
| 267 } | 269 } |
| 268 } | 270 } |
| OLD | NEW |