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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/themes/theme_properties.h" | 8 #include "chrome/browser/themes/theme_properties.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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 pause_animation_state_(0.0), | 49 pause_animation_state_(0.0), |
| 50 bubble_view_(nullptr), | 50 bubble_view_(nullptr), |
| 51 suppress_mouse_released_action_(false), | 51 suppress_mouse_released_action_(false), |
| 52 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) { | 52 ink_drop_delegate_(new views::ButtonInkDropDelegate(this, this)) { |
| 53 if (!ui::MaterialDesignController::IsModeMaterial()) { | 53 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 54 static const int kBackgroundImages[] = | 54 static const int kBackgroundImages[] = |
| 55 IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE); | 55 IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE); |
| 56 SetBackgroundImageGrid(kBackgroundImages); | 56 SetBackgroundImageGrid(kBackgroundImages); |
| 57 } | 57 } |
| 58 | 58 |
| 59 image()->SetHorizontalAlignment(views::ImageView::LEADING); | 59 image()->SetHorizontalAlignment(base::i18n::IsRTL() |
| 60 ? views::ImageView::TRAILING | |
| 61 : views::ImageView::LEADING); | |
| 60 image()->set_interactive(true); | 62 image()->set_interactive(true); |
| 61 image()->EnableCanvasFlippingForRTLUI(true); | 63 image()->EnableCanvasFlippingForRTLUI(true); |
| 62 image()->SetAccessibilityFocusable(true); | 64 image()->SetAccessibilityFocusable(true); |
| 63 label()->SetElideBehavior(gfx::NO_ELIDE); | 65 label()->SetElideBehavior(gfx::NO_ELIDE); |
| 64 label()->SetVisible(false); | 66 label()->SetVisible(false); |
| 65 | 67 |
| 66 slide_animator_.SetSlideDuration(kAnimationDurationMS); | 68 slide_animator_.SetSlideDuration(kAnimationDurationMS); |
| 67 slide_animator_.SetTweenType(gfx::Tween::LINEAR); | 69 slide_animator_.SetTweenType(gfx::Tween::LINEAR); |
| 68 } | 70 } |
| 69 | 71 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 SkColor ContentSettingImageView::GetTextColor() const { | 108 SkColor ContentSettingImageView::GetTextColor() const { |
| 107 return GetNativeTheme()->GetSystemColor( | 109 return GetNativeTheme()->GetSystemColor( |
| 108 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 110 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 109 } | 111 } |
| 110 | 112 |
| 111 SkColor ContentSettingImageView::GetBorderColor() const { | 113 SkColor ContentSettingImageView::GetBorderColor() const { |
| 112 return gfx::kGoogleYellow700; | 114 return gfx::kGoogleYellow700; |
| 113 } | 115 } |
| 114 | 116 |
| 115 bool ContentSettingImageView::ShouldShowBackground() const { | 117 bool ContentSettingImageView::ShouldShowBackground() const { |
| 116 return slide_animator_.is_animating() || pause_animation_; | 118 return label()->visible() && |
| 119 (slide_animator_.is_animating() || pause_animation_); | |
| 117 } | 120 } |
| 118 | 121 |
| 119 double ContentSettingImageView::WidthMultiplier() const { | 122 double ContentSettingImageView::WidthMultiplier() const { |
| 120 double state = pause_animation_ ? pause_animation_state_ | 123 double state = pause_animation_ ? pause_animation_state_ |
| 121 : slide_animator_.GetCurrentValue(); | 124 : slide_animator_.GetCurrentValue(); |
| 122 // The fraction of the animation we'll spend animating the string into view, | 125 // The fraction of the animation we'll spend animating the string into view, |
| 123 // which is also the fraction we'll spend animating it closed; total | 126 // which is also the fraction we'll spend animating it closed; total |
| 124 // animation (slide out, show, then slide in) is 1.0. | 127 // animation (slide out, show, then slide in) is 1.0. |
|
Peter Kasting
2016/03/07 20:24:27
We probably need more comments here, since now we
varkha
2016/03/08 18:01:03
Timings should be matching the original comment no
| |
| 125 const double kOpenFraction = | 128 const double kOpenFraction = |
| 126 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; | 129 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; |
| 127 double size_fraction = 1.0; | 130 double size_fraction = 1.0; |
| 128 if (state < kOpenFraction) | 131 if (state < kOpenFraction) |
| 129 size_fraction = state / kOpenFraction; | 132 size_fraction = state / kOpenFraction; |
| 130 if (state > (1.0 - kOpenFraction)) | 133 if (state > (1.0 - kOpenFraction)) |
| 131 size_fraction = (1.0 - state) / kOpenFraction; | 134 size_fraction = (1.0 - state) / kOpenFraction; |
| 132 return size_fraction; | 135 return size_fraction; |
| 133 } | 136 } |
| 134 | 137 |
| 138 void ContentSettingImageView::StopAnimation() { | |
| 139 slide_animator_.Stop(); | |
|
Peter Kasting
2016/03/07 20:24:27
Stop() is redundant with Reset(). You should only
varkha
2016/03/08 18:01:03
Done. also this method is no longer necessary.
| |
| 140 slide_animator_.Reset(); | |
| 141 } | |
| 142 | |
| 143 bool ContentSettingImageView::IsShrinking() const { | |
| 144 const double kOpenFraction = | |
| 145 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; | |
| 146 return (!pause_animation_ && slide_animator_.is_animating() && | |
| 147 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction)); | |
| 148 } | |
| 149 | |
| 135 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { | 150 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { |
| 136 slide_animator_.Reset(); | 151 slide_animator_.Reset(); |
| 137 if (!pause_animation_) { | 152 if (!pause_animation_) { |
| 138 label()->SetVisible(false); | 153 label()->SetVisible(false); |
| 139 parent_->Layout(); | 154 parent_->Layout(); |
| 140 parent_->SchedulePaint(); | 155 parent_->SchedulePaint(); |
| 156 SchedulePaint(); | |
|
Peter Kasting
2016/03/07 20:24:27
Given the definition of SchedulePaint(), it seems
varkha
2016/03/08 18:01:03
Done.
varkha
2016/03/08 21:56:03
Will remove the commented line obviously before co
| |
| 141 } | 157 } |
| 142 } | 158 } |
| 143 | 159 |
| 144 void ContentSettingImageView::AnimationProgressed( | 160 void ContentSettingImageView::AnimationProgressed( |
| 145 const gfx::Animation* animation) { | 161 const gfx::Animation* animation) { |
| 146 if (!pause_animation_) { | 162 if (!pause_animation_) { |
| 147 parent_->Layout(); | 163 parent_->Layout(); |
| 148 parent_->SchedulePaint(); | 164 parent_->SchedulePaint(); |
| 149 } | 165 } |
| 150 } | 166 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 // |widget| is a bubble that has just got shown / hidden. | 254 // |widget| is a bubble that has just got shown / hidden. |
| 239 if (!visible && !label()->visible()) | 255 if (!visible && !label()->visible()) |
| 240 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED); | 256 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED); |
| 241 } | 257 } |
| 242 | 258 |
| 243 void ContentSettingImageView::OnClick() { | 259 void ContentSettingImageView::OnClick() { |
| 244 if (slide_animator_.is_animating()) { | 260 if (slide_animator_.is_animating()) { |
| 245 if (!pause_animation_) { | 261 if (!pause_animation_) { |
| 246 pause_animation_ = true; | 262 pause_animation_ = true; |
| 247 pause_animation_state_ = slide_animator_.GetCurrentValue(); | 263 pause_animation_state_ = slide_animator_.GetCurrentValue(); |
| 264 | |
| 265 // Snap animation to target if a user clicks before the image is exposed. | |
|
Peter Kasting
2016/03/07 20:24:27
Nit: a -> the
varkha
2016/03/08 18:01:03
Done.
| |
| 266 const double kOpenFraction = | |
| 267 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; | |
| 268 if (pause_animation_state_ < kOpenFraction && | |
|
Peter Kasting
2016/03/07 20:24:27
Is this first portion of the conditional needed?
varkha
2016/03/08 18:01:03
Done.
| |
| 269 width() < image()->GetPreferredSize().width() + | |
| 270 GetBubbleOuterPadding(true) + | |
| 271 GetBubbleOuterPadding(false)) { | |
| 272 pause_animation_ = false; | |
| 273 StopAnimation(); | |
| 274 } | |
| 248 } | 275 } |
| 249 slide_animator_.Reset(); | 276 slide_animator_.Reset(); |
| 250 } | 277 } |
| 251 | 278 |
| 252 content::WebContents* web_contents = parent_->GetWebContents(); | 279 content::WebContents* web_contents = parent_->GetWebContents(); |
| 253 if (web_contents && !bubble_view_) { | 280 if (web_contents && !bubble_view_) { |
| 254 bubble_view_ = new ContentSettingBubbleContents( | 281 bubble_view_ = new ContentSettingBubbleContents( |
| 255 content_setting_image_model_->CreateBubbleModel( | 282 content_setting_image_model_->CreateBubbleModel( |
| 256 parent_->delegate()->GetContentSettingBubbleModelDelegate(), | 283 parent_->delegate()->GetContentSettingBubbleModelDelegate(), |
| 257 web_contents, parent_->profile()), | 284 web_contents, parent_->profile()), |
| 258 web_contents, this, views::BubbleBorder::TOP_RIGHT); | 285 web_contents, this, views::BubbleBorder::TOP_RIGHT); |
| 259 views::Widget* bubble_widget = | 286 views::Widget* bubble_widget = |
| 260 parent_->delegate()->CreateViewsBubble(bubble_view_); | 287 parent_->delegate()->CreateViewsBubble(bubble_view_); |
| 261 bubble_widget->AddObserver(this); | 288 bubble_widget->AddObserver(this); |
| 262 bubble_widget->Show(); | 289 bubble_widget->Show(); |
| 263 } | 290 } |
| 264 } | 291 } |
| 265 | 292 |
| 266 void ContentSettingImageView::UpdateImage() { | 293 void ContentSettingImageView::UpdateImage() { |
| 267 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 294 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
| 268 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); | 295 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); |
| 269 } | 296 } |
| 270 | 297 |
| 271 bool ContentSettingImageView::IsBubbleShowing() const { | 298 bool ContentSettingImageView::IsBubbleShowing() const { |
| 272 return bubble_view_ != nullptr; | 299 return bubble_view_ != nullptr; |
| 273 } | 300 } |
| OLD | NEW |