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

Side by Side Diff: chrome/browser/ui/views/location_bar/content_setting_image_view.cc

Issue 1763713004: Adjusts content bubble animation with respect to icon size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjusts content bubble animation with respect to icon size (constant speed) Created 4 years, 9 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
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/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
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
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();
141 } 151 }
142 } 152 }
143 153
144 void ContentSettingImageView::AnimationProgressed( 154 void ContentSettingImageView::AnimationProgressed(
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 245
236 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, 246 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
237 bool visible) { 247 bool visible) {
238 // |widget| is a bubble that has just got shown / hidden. 248 // |widget| is a bubble that has just got shown / hidden.
239 if (!visible && !label()->visible()) 249 if (!visible && !label()->visible())
240 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED); 250 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED);
241 } 251 }
242 252
243 void ContentSettingImageView::OnClick() { 253 void ContentSettingImageView::OnClick() {
244 if (slide_animator_.is_animating()) { 254 if (slide_animator_.is_animating()) {
245 if (!pause_animation_) { 255 // If the user clicks while we're animating, the bubble arrow will be
256 // pointing to the image, and if we allow the animation to keep running, the
257 // image will move away from the arrow (or we'll have to move the bubble,
258 // which is even worse). So we want to stop the animation. We have two
259 // choices: jump to the final post-animation state (no label visible), or
260 // pause the animation where we are and continue running after the bubble
261 // closes. The former looks more jerky, so we avoid it unless the animation
262 // hasn't even fully exposed the image yet, in which case pausing with half
263 // an image visible will look broken.
264 const int final_width = image()->GetPreferredSize().width() +
265 GetBubbleOuterPadding(true) + GetBubbleOuterPadding(false);
266 if (!pause_animation_ && (width() > final_width)) {
246 pause_animation_ = true; 267 pause_animation_ = true;
247 pause_animation_state_ = slide_animator_.GetCurrentValue(); 268 pause_animation_state_ = slide_animator_.GetCurrentValue();
248 } 269 }
249 slide_animator_.Reset(); 270 slide_animator_.Reset();
250 } 271 }
251 272
252 content::WebContents* web_contents = parent_->GetWebContents(); 273 content::WebContents* web_contents = parent_->GetWebContents();
253 if (web_contents && !bubble_view_) { 274 if (web_contents && !bubble_view_) {
254 bubble_view_ = new ContentSettingBubbleContents( 275 bubble_view_ = new ContentSettingBubbleContents(
255 content_setting_image_model_->CreateBubbleModel( 276 content_setting_image_model_->CreateBubbleModel(
(...skipping 15 matching lines...) Expand all
271 } 292 }
272 293
273 void ContentSettingImageView::UpdateImage() { 294 void ContentSettingImageView::UpdateImage() {
274 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); 295 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
275 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); 296 image()->SetTooltipText(content_setting_image_model_->get_tooltip());
276 } 297 }
277 298
278 bool ContentSettingImageView::IsBubbleShowing() const { 299 bool ContentSettingImageView::IsBubbleShowing() const {
279 return bubble_view_ != nullptr; 300 return bubble_view_ != nullptr;
280 } 301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698