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

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: Moved InkDropHostView::AsLocatedEvent() to event_utils.(h|cc) as ToLocatedEventOrNull(). 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"
11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" 11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h"
12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
13 #include "grit/theme_resources.h" 13 #include "grit/theme_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/material_design/material_design_controller.h" 15 #include "ui/base/material_design/material_design_controller.h"
16 #include "ui/base/theme_provider.h" 16 #include "ui/base/theme_provider.h"
17 #include "ui/events/event_utils.h"
17 #include "ui/gfx/color_palette.h" 18 #include "ui/gfx/color_palette.h"
18 #include "ui/gfx/color_utils.h" 19 #include "ui/gfx/color_utils.h"
19 #include "ui/views/controls/image_view.h" 20 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 23
23 namespace { 24 namespace {
24 // Time spent with animation fully open. 25 // Time spent with animation fully open.
25 const int kStayOpenTimeMS = 3200; 26 const int kStayOpenTimeMS = 3200;
26 } 27 }
(...skipping 58 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 86 // If the content usage or blockage should be indicated to the user, start the
86 // animation and record that the icon has been shown. 87 // animation and record that the icon has been shown.
87 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) 88 if (!content_setting_image_model_->ShouldRunAnimation(web_contents))
88 return; 89 return;
89 90
90 // We just ignore this blockage if we're already showing some other string to 91 // 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 92 // 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. 93 // 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(); 94 int string_id = content_setting_image_model_->explanatory_string_id();
94 if (string_id && !label()->visible()) { 95 if (string_id && !label()->visible()) {
95 AnimateInkDrop(views::InkDropState::HIDDEN); 96 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */);
96 SetLabel(l10n_util::GetStringUTF16(string_id)); 97 SetLabel(l10n_util::GetStringUTF16(string_id));
97 label()->SetVisible(true); 98 label()->SetVisible(true);
98 slide_animator_.Show(); 99 slide_animator_.Show();
99 } 100 }
100 101
101 content_setting_image_model_->SetAnimationHasRun(web_contents); 102 content_setting_image_model_->SetAnimationHasRun(web_contents);
102 } 103 }
103 104
104 const char* ContentSettingImageView::GetClassName() const { 105 const char* ContentSettingImageView::GetClassName() const {
105 return "ContentSettingsImageView"; 106 return "ContentSettingsImageView";
106 } 107 }
107 108
108 void ContentSettingImageView::OnBoundsChanged( 109 void ContentSettingImageView::OnBoundsChanged(
109 const gfx::Rect& previous_bounds) { 110 const gfx::Rect& previous_bounds) {
110 if (bubble_view_) 111 if (bubble_view_)
111 bubble_view_->OnAnchorBoundsChanged(); 112 bubble_view_->OnAnchorBoundsChanged();
112 } 113 }
113 114
114 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { 115 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) {
115 // If the bubble is showing then don't reshow it when the mouse is released. 116 // If the bubble is showing then don't reshow it when the mouse is released.
116 suppress_mouse_released_action_ = bubble_view_ != nullptr; 117 suppress_mouse_released_action_ = bubble_view_ != nullptr;
117 if (!suppress_mouse_released_action_ && !label()->visible()) 118 if (!suppress_mouse_released_action_ && !label()->visible())
118 AnimateInkDrop(views::InkDropState::ACTION_PENDING); 119 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event);
119 120
120 // We want to show the bubble on mouse release; that is the standard behavior 121 // We want to show the bubble on mouse release; that is the standard behavior
121 // for buttons. 122 // for buttons.
122 return true; 123 return true;
123 } 124 }
124 125
125 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { 126 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) {
126 // If this is the second click on this view then the bubble was showing on the 127 // 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 128 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by
128 // doing nothing here. 129 // doing nothing here.
129 if (suppress_mouse_released_action_) { 130 if (suppress_mouse_released_action_) {
130 suppress_mouse_released_action_ = false; 131 suppress_mouse_released_action_ = false;
131 return; 132 return;
132 } 133 }
133 const bool activated = HitTestPoint(event.location()); 134 const bool activated = HitTestPoint(event.location());
134 if (!label()->visible() && !activated) 135 if (!label()->visible() && !activated)
135 AnimateInkDrop(views::InkDropState::HIDDEN); 136 AnimateInkDrop(views::InkDropState::HIDDEN, &event);
136 if (activated) 137 if (activated)
137 OnActivate(); 138 OnActivate(&event);
138 } 139 }
139 140
140 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { 141 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) {
141 if (event->type() == ui::ET_GESTURE_TAP) 142 if (event->type() == ui::ET_GESTURE_TAP)
142 OnActivate(); 143 OnActivate(event);
143 if ((event->type() == ui::ET_GESTURE_TAP) || 144 if ((event->type() == ui::ET_GESTURE_TAP) ||
144 (event->type() == ui::ET_GESTURE_TAP_DOWN)) 145 (event->type() == ui::ET_GESTURE_TAP_DOWN))
145 event->SetHandled(); 146 event->SetHandled();
146 } 147 }
147 148
148 void ContentSettingImageView::OnNativeThemeChanged( 149 void ContentSettingImageView::OnNativeThemeChanged(
149 const ui::NativeTheme* native_theme) { 150 const ui::NativeTheme* native_theme) {
150 if (ui::MaterialDesignController::IsModeMaterial()) 151 if (ui::MaterialDesignController::IsModeMaterial())
151 UpdateImage(); 152 UpdateImage();
152 153
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return size_fraction; 185 return size_fraction;
185 } 186 }
186 187
187 bool ContentSettingImageView::IsShrinking() const { 188 bool ContentSettingImageView::IsShrinking() const {
188 const double kOpenFraction = 189 const double kOpenFraction =
189 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; 190 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
190 return (!pause_animation_ && slide_animator_.is_animating() && 191 return (!pause_animation_ && slide_animator_.is_animating() &&
191 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction)); 192 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction));
192 } 193 }
193 194
194 bool ContentSettingImageView::OnActivate() { 195 bool ContentSettingImageView::OnActivate(const ui::Event* event) {
195 if (slide_animator_.is_animating()) { 196 if (slide_animator_.is_animating()) {
196 // If the user clicks while we're animating, the bubble arrow will be 197 // 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 198 // 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, 199 // 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 200 // 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 201 // 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 202 // 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 203 // 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 204 // hasn't even fully exposed the image yet, in which case pausing with half
204 // an image visible will look broken. 205 // an image visible will look broken.
(...skipping 14 matching lines...) Expand all
219 web_contents, this, views::BubbleBorder::TOP_RIGHT); 220 web_contents, this, views::BubbleBorder::TOP_RIGHT);
220 views::Widget* bubble_widget = 221 views::Widget* bubble_widget =
221 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); 222 views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
222 bubble_widget->AddObserver(this); 223 bubble_widget->AddObserver(this);
223 // This is triggered by an input event. If the user clicks the icon while 224 // 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 225 // 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, 226 // 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 227 // the animation simply pauses and no other visible state change occurs, so
227 // show the arrow in this case. 228 // show the arrow in this case.
228 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) { 229 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) {
229 AnimateInkDrop(views::InkDropState::ACTIVATED); 230 AnimateInkDrop(views::InkDropState::ACTIVATED,
231 ToLocatedEventOrNull(event));
230 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); 232 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
231 } 233 }
232 bubble_widget->Show(); 234 bubble_widget->Show();
233 } 235 }
234 236
235 return true; 237 return true;
236 } 238 }
237 239
238 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { 240 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
239 slide_animator_.Reset(); 241 slide_animator_.Reset();
(...skipping 27 matching lines...) Expand all
267 slide_animator_.Reset(pause_animation_state_); 269 slide_animator_.Reset(pause_animation_state_);
268 pause_animation_ = false; 270 pause_animation_ = false;
269 slide_animator_.Show(); 271 slide_animator_.Show();
270 } 272 }
271 } 273 }
272 274
273 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, 275 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
274 bool visible) { 276 bool visible) {
275 // |widget| is a bubble that has just got shown / hidden. 277 // |widget| is a bubble that has just got shown / hidden.
276 if (!visible && !label()->visible()) 278 if (!visible && !label()->visible())
277 AnimateInkDrop(views::InkDropState::DEACTIVATED); 279 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */);
278 } 280 }
279 281
280 void ContentSettingImageView::UpdateImage() { 282 void ContentSettingImageView::UpdateImage() {
281 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); 283 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
282 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); 284 image()->SetTooltipText(content_setting_image_model_->get_tooltip());
283 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698