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 11 matching lines...) Expand all Loading... | |
| 22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
| 23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 // Time spent with animation fully open. | 26 // Time spent with animation fully open. |
| 27 const int kStayOpenTimeMS = 3200; | 27 const int kStayOpenTimeMS = 3200; |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 const int ContentSettingImageView::kOpenTimeMS = 150; | 32 const int ContentSettingImageView::kOpenTimeMS = 15000; |
|
Peter Kasting
2016/03/08 22:07:06
You don't want to commit this :)
varkha
2016/03/10 22:25:56
Wasn't planning on it!
| |
| 33 const int ContentSettingImageView::kAnimationDurationMS = | 33 const int ContentSettingImageView::kAnimationDurationMS = |
| 34 (kOpenTimeMS * 2) + kStayOpenTimeMS; | 34 (kOpenTimeMS * 2) + kStayOpenTimeMS; |
| 35 | 35 |
| 36 ContentSettingImageView::ContentSettingImageView( | 36 ContentSettingImageView::ContentSettingImageView( |
| 37 ContentSettingImageModel* image_model, | 37 ContentSettingImageModel* image_model, |
| 38 LocationBarView* parent, | 38 LocationBarView* parent, |
| 39 const gfx::FontList& font_list, | 39 const gfx::FontList& font_list, |
| 40 SkColor parent_background_color) | 40 SkColor parent_background_color) |
| 41 : IconLabelBubbleView(0, | 41 : IconLabelBubbleView(0, |
| 42 font_list, | 42 font_list, |
| 43 parent_background_color, | 43 parent_background_color, |
| 44 false), | 44 false), |
| 45 parent_(parent), | 45 parent_(parent), |
| 46 content_setting_image_model_(image_model), | 46 content_setting_image_model_(image_model), |
| 47 slide_animator_(this), | 47 slide_animator_(this), |
| 48 pause_animation_(false), | 48 pause_animation_(false), |
| 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. |
| 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 bool ContentSettingImageView::IsShrinking() const { | |
| 139 const double kOpenFraction = | |
| 140 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; | |
| 141 return (!pause_animation_ && slide_animator_.is_animating() && | |
| 142 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction)); | |
| 143 } | |
| 144 | |
| 135 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { | 145 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { |
| 136 slide_animator_.Reset(); | 146 slide_animator_.Reset(); |
| 137 if (!pause_animation_) { | 147 if (!pause_animation_) { |
| 138 label()->SetVisible(false); | 148 label()->SetVisible(false); |
| 139 parent_->Layout(); | 149 parent_->Layout(); |
| 140 parent_->SchedulePaint(); | 150 parent_->SchedulePaint(); |
| 151 // SchedulePaint(); | |
|
Peter Kasting
2016/03/08 22:07:06
Remove or else uncomment and add notes as to why
varkha
2016/03/10 22:25:56
Done.
| |
| 141 } | 152 } |
| 142 } | 153 } |
| 143 | 154 |
| 144 void ContentSettingImageView::AnimationProgressed( | 155 void ContentSettingImageView::AnimationProgressed( |
| 145 const gfx::Animation* animation) { | 156 const gfx::Animation* animation) { |
| 146 if (!pause_animation_) { | 157 if (!pause_animation_) { |
| 147 parent_->Layout(); | 158 parent_->Layout(); |
| 148 parent_->SchedulePaint(); | 159 parent_->SchedulePaint(); |
| 149 } | 160 } |
| 150 } | 161 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 // |widget| is a bubble that has just got shown / hidden. | 249 // |widget| is a bubble that has just got shown / hidden. |
| 239 if (!visible && !label()->visible()) | 250 if (!visible && !label()->visible()) |
| 240 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED); | 251 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED); |
| 241 } | 252 } |
| 242 | 253 |
| 243 void ContentSettingImageView::OnClick() { | 254 void ContentSettingImageView::OnClick() { |
| 244 if (slide_animator_.is_animating()) { | 255 if (slide_animator_.is_animating()) { |
| 245 if (!pause_animation_) { | 256 if (!pause_animation_) { |
| 246 pause_animation_ = true; | 257 pause_animation_ = true; |
| 247 pause_animation_state_ = slide_animator_.GetCurrentValue(); | 258 pause_animation_state_ = slide_animator_.GetCurrentValue(); |
| 259 | |
| 260 // Snap animation to target if the click happens before the image is | |
| 261 // exposed. | |
| 262 if (width() < image()->GetPreferredSize().width() + | |
| 263 GetBubbleOuterPadding(true) + | |
| 264 GetBubbleOuterPadding(false)) { | |
| 265 pause_animation_ = false; | |
| 266 } | |
|
Peter Kasting
2016/03/08 22:07:06
Nit: Seems like this would make more sense hoisted
varkha
2016/03/10 22:25:56
Done. Thanks for the wording. You also got the sub
| |
| 248 } | 267 } |
| 249 slide_animator_.Reset(); | 268 slide_animator_.Reset(); |
| 250 } | 269 } |
| 251 | 270 |
| 252 content::WebContents* web_contents = parent_->GetWebContents(); | 271 content::WebContents* web_contents = parent_->GetWebContents(); |
| 253 if (web_contents && !bubble_view_) { | 272 if (web_contents && !bubble_view_) { |
| 254 bubble_view_ = new ContentSettingBubbleContents( | 273 bubble_view_ = new ContentSettingBubbleContents( |
| 255 content_setting_image_model_->CreateBubbleModel( | 274 content_setting_image_model_->CreateBubbleModel( |
| 256 parent_->delegate()->GetContentSettingBubbleModelDelegate(), | 275 parent_->delegate()->GetContentSettingBubbleModelDelegate(), |
| 257 web_contents, parent_->profile()), | 276 web_contents, parent_->profile()), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 268 } | 287 } |
| 269 | 288 |
| 270 void ContentSettingImageView::UpdateImage() { | 289 void ContentSettingImageView::UpdateImage() { |
| 271 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 290 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
| 272 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); | 291 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); |
| 273 } | 292 } |
| 274 | 293 |
| 275 bool ContentSettingImageView::IsBubbleShowing() const { | 294 bool ContentSettingImageView::IsBubbleShowing() const { |
| 276 return bubble_view_ != nullptr; | 295 return bubble_view_ != nullptr; |
| 277 } | 296 } |
| OLD | NEW |