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

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

Issue 2042073002: Centered flood fill style ink drop ripples on mouse/touch points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Polished for review. Created 4 years, 6 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // If the content usage or blockage should be indicated to the user, start the 85 // If the content usage or blockage should be indicated to the user, start the
86 // animation and record that the icon has been shown. 86 // animation and record that the icon has been shown.
87 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) 87 if (!content_setting_image_model_->ShouldRunAnimation(web_contents))
88 return; 88 return;
89 89
90 // We just ignore this blockage if we're already showing some other string to 90 // We just ignore this blockage if we're already showing some other string to
91 // the user. If this becomes a problem, we could design some sort of queueing 91 // the user. If this becomes a problem, we could design some sort of queueing
92 // mechanism to show one after the other, but it doesn't seem important now. 92 // mechanism to show one after the other, but it doesn't seem important now.
93 int string_id = content_setting_image_model_->explanatory_string_id(); 93 int string_id = content_setting_image_model_->explanatory_string_id();
94 if (string_id && !label()->visible()) { 94 if (string_id && !label()->visible()) {
95 AnimateInkDrop(views::InkDropState::HIDDEN); 95 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */);
96 SetLabel(l10n_util::GetStringUTF16(string_id)); 96 SetLabel(l10n_util::GetStringUTF16(string_id));
97 label()->SetVisible(true); 97 label()->SetVisible(true);
98 slide_animator_.Show(); 98 slide_animator_.Show();
99 } 99 }
100 100
101 content_setting_image_model_->SetAnimationHasRun(web_contents); 101 content_setting_image_model_->SetAnimationHasRun(web_contents);
102 } 102 }
103 103
104 const char* ContentSettingImageView::GetClassName() const { 104 const char* ContentSettingImageView::GetClassName() const {
105 return "ContentSettingsImageView"; 105 return "ContentSettingsImageView";
106 } 106 }
107 107
108 void ContentSettingImageView::OnBoundsChanged( 108 void ContentSettingImageView::OnBoundsChanged(
109 const gfx::Rect& previous_bounds) { 109 const gfx::Rect& previous_bounds) {
110 if (bubble_view_) 110 if (bubble_view_)
111 bubble_view_->OnAnchorBoundsChanged(); 111 bubble_view_->OnAnchorBoundsChanged();
112 } 112 }
113 113
114 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { 114 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) {
115 // If the bubble is showing then don't reshow it when the mouse is released. 115 // If the bubble is showing then don't reshow it when the mouse is released.
116 suppress_mouse_released_action_ = bubble_view_ != nullptr; 116 suppress_mouse_released_action_ = bubble_view_ != nullptr;
117 if (!suppress_mouse_released_action_ && !label()->visible()) 117 if (!suppress_mouse_released_action_ && !label()->visible())
118 AnimateInkDrop(views::InkDropState::ACTION_PENDING); 118 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event);
119 119
120 // We want to show the bubble on mouse release; that is the standard behavior 120 // We want to show the bubble on mouse release; that is the standard behavior
121 // for buttons. 121 // for buttons.
122 return true; 122 return true;
123 } 123 }
124 124
125 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { 125 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) {
126 // If this is the second click on this view then the bubble was showing on the 126 // If this is the second click on this view then the bubble was showing on the
127 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by 127 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by
128 // doing nothing here. 128 // doing nothing here.
129 if (suppress_mouse_released_action_) { 129 if (suppress_mouse_released_action_) {
130 suppress_mouse_released_action_ = false; 130 suppress_mouse_released_action_ = false;
131 return; 131 return;
132 } 132 }
133 const bool activated = HitTestPoint(event.location()); 133 const bool activated = HitTestPoint(event.location());
134 if (!label()->visible() && !activated) 134 if (!label()->visible() && !activated)
135 AnimateInkDrop(views::InkDropState::HIDDEN); 135 AnimateInkDrop(views::InkDropState::HIDDEN, &event);
136 if (activated) 136 if (activated)
137 OnActivate(); 137 OnActivate(&event);
138 } 138 }
139 139
140 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { 140 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) {
141 if (event->type() == ui::ET_GESTURE_TAP) 141 if (event->type() == ui::ET_GESTURE_TAP)
142 OnActivate(); 142 OnActivate(event);
143 if ((event->type() == ui::ET_GESTURE_TAP) || 143 if ((event->type() == ui::ET_GESTURE_TAP) ||
144 (event->type() == ui::ET_GESTURE_TAP_DOWN)) 144 (event->type() == ui::ET_GESTURE_TAP_DOWN))
145 event->SetHandled(); 145 event->SetHandled();
146 } 146 }
147 147
148 void ContentSettingImageView::OnNativeThemeChanged( 148 void ContentSettingImageView::OnNativeThemeChanged(
149 const ui::NativeTheme* native_theme) { 149 const ui::NativeTheme* native_theme) {
150 if (ui::MaterialDesignController::IsModeMaterial()) 150 if (ui::MaterialDesignController::IsModeMaterial())
151 UpdateImage(); 151 UpdateImage();
152 152
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return size_fraction; 184 return size_fraction;
185 } 185 }
186 186
187 bool ContentSettingImageView::IsShrinking() const { 187 bool ContentSettingImageView::IsShrinking() const {
188 const double kOpenFraction = 188 const double kOpenFraction =
189 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; 189 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
190 return (!pause_animation_ && slide_animator_.is_animating() && 190 return (!pause_animation_ && slide_animator_.is_animating() &&
191 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction)); 191 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction));
192 } 192 }
193 193
194 bool ContentSettingImageView::OnActivate() { 194 bool ContentSettingImageView::OnActivate(const ui::Event* event) {
195 if (slide_animator_.is_animating()) { 195 if (slide_animator_.is_animating()) {
196 // If the user clicks while we're animating, the bubble arrow will be 196 // If the user clicks while we're animating, the bubble arrow will be
197 // pointing to the image, and if we allow the animation to keep running, the 197 // pointing to the image, and if we allow the animation to keep running, the
198 // image will move away from the arrow (or we'll have to move the bubble, 198 // image will move away from the arrow (or we'll have to move the bubble,
199 // which is even worse). So we want to stop the animation. We have two 199 // which is even worse). So we want to stop the animation. We have two
200 // choices: jump to the final post-animation state (no label visible), or 200 // choices: jump to the final post-animation state (no label visible), or
201 // pause the animation where we are and continue running after the bubble 201 // pause the animation where we are and continue running after the bubble
202 // closes. The former looks more jerky, so we avoid it unless the animation 202 // closes. The former looks more jerky, so we avoid it unless the animation
203 // hasn't even fully exposed the image yet, in which case pausing with half 203 // hasn't even fully exposed the image yet, in which case pausing with half
204 // an image visible will look broken. 204 // an image visible will look broken.
(...skipping 14 matching lines...) Expand all
219 web_contents, this, views::BubbleBorder::TOP_RIGHT); 219 web_contents, this, views::BubbleBorder::TOP_RIGHT);
220 views::Widget* bubble_widget = 220 views::Widget* bubble_widget =
221 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); 221 views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
222 bubble_widget->AddObserver(this); 222 bubble_widget->AddObserver(this);
223 // This is triggered by an input event. If the user clicks the icon while 223 // This is triggered by an input event. If the user clicks the icon while
224 // it's not animating, the icon will be placed in an active state, so the 224 // it's not animating, the icon will be placed in an active state, so the
225 // bubble doesn't need an arrow. If the user clicks during an animation, 225 // bubble doesn't need an arrow. If the user clicks during an animation,
226 // the animation simply pauses and no other visible state change occurs, so 226 // the animation simply pauses and no other visible state change occurs, so
227 // show the arrow in this case. 227 // show the arrow in this case.
228 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) { 228 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) {
229 AnimateInkDrop(views::InkDropState::ACTIVATED); 229 AnimateInkDrop(views::InkDropState::ACTIVATED, event);
230 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); 230 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
231 } 231 }
232 bubble_widget->Show(); 232 bubble_widget->Show();
233 } 233 }
234 234
235 return true; 235 return true;
236 } 236 }
237 237
238 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { 238 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
239 slide_animator_.Reset(); 239 slide_animator_.Reset();
(...skipping 27 matching lines...) Expand all
267 slide_animator_.Reset(pause_animation_state_); 267 slide_animator_.Reset(pause_animation_state_);
268 pause_animation_ = false; 268 pause_animation_ = false;
269 slide_animator_.Show(); 269 slide_animator_.Show();
270 } 270 }
271 } 271 }
272 272
273 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, 273 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
274 bool visible) { 274 bool visible) {
275 // |widget| is a bubble that has just got shown / hidden. 275 // |widget| is a bubble that has just got shown / hidden.
276 if (!visible && !label()->visible()) 276 if (!visible && !label()->visible())
277 AnimateInkDrop(views::InkDropState::DEACTIVATED); 277 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */);
278 } 278 }
279 279
280 void ContentSettingImageView::UpdateImage() { 280 void ContentSettingImageView::UpdateImage() {
281 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); 281 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
282 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); 282 image()->SetTooltipText(content_setting_image_model_->get_tooltip());
283 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698