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

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

Issue 1915063003: Change ContentSettingImageView activation to key release (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by 132 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by
133 // doing nothing here. 133 // doing nothing here.
134 if (suppress_mouse_released_action_) { 134 if (suppress_mouse_released_action_) {
135 suppress_mouse_released_action_ = false; 135 suppress_mouse_released_action_ = false;
136 return; 136 return;
137 } 137 }
138 const bool activated = HitTestPoint(event.location()); 138 const bool activated = HitTestPoint(event.location());
139 if (!label()->visible() && !activated) 139 if (!label()->visible() && !activated)
140 ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN); 140 ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN);
141 if (activated) 141 if (activated)
142 OnClick(); 142 OnActivate();
143 }
144
145 bool ContentSettingImageView::OnKeyPressed(const ui::KeyEvent& event) {
146 if (event.key_code() != ui::VKEY_SPACE && event.key_code() != ui::VKEY_RETURN)
147 return false;
148
149 OnClick();
150 return true;
151 } 143 }
152 144
153 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { 145 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) {
154 if (event->type() == ui::ET_GESTURE_TAP) 146 if (event->type() == ui::ET_GESTURE_TAP)
155 OnClick(); 147 OnActivate();
156 if ((event->type() == ui::ET_GESTURE_TAP) || 148 if ((event->type() == ui::ET_GESTURE_TAP) ||
157 (event->type() == ui::ET_GESTURE_TAP_DOWN)) 149 (event->type() == ui::ET_GESTURE_TAP_DOWN))
158 event->SetHandled(); 150 event->SetHandled();
159 } 151 }
160 152
161 void ContentSettingImageView::OnNativeThemeChanged( 153 void ContentSettingImageView::OnNativeThemeChanged(
162 const ui::NativeTheme* native_theme) { 154 const ui::NativeTheme* native_theme) {
163 if (ui::MaterialDesignController::IsModeMaterial()) 155 if (ui::MaterialDesignController::IsModeMaterial())
164 UpdateImage(); 156 UpdateImage();
165 157
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return size_fraction; 189 return size_fraction;
198 } 190 }
199 191
200 bool ContentSettingImageView::IsShrinking() const { 192 bool ContentSettingImageView::IsShrinking() const {
201 const double kOpenFraction = 193 const double kOpenFraction =
202 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; 194 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS;
203 return (!pause_animation_ && slide_animator_.is_animating() && 195 return (!pause_animation_ && slide_animator_.is_animating() &&
204 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction)); 196 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction));
205 } 197 }
206 198
199 bool ContentSettingImageView::OnActivate() {
200 if (slide_animator_.is_animating()) {
201 // If the user clicks while we're animating, the bubble arrow will be
202 // pointing to the image, and if we allow the animation to keep running, the
203 // image will move away from the arrow (or we'll have to move the bubble,
204 // which is even worse). So we want to stop the animation. We have two
205 // choices: jump to the final post-animation state (no label visible), or
206 // pause the animation where we are and continue running after the bubble
207 // closes. The former looks more jerky, so we avoid it unless the animation
208 // hasn't even fully exposed the image yet, in which case pausing with half
209 // an image visible will look broken.
210 if (!pause_animation_ && ShouldShowBackground() &&
211 (width() > MinimumWidthForImageWithBackgroundShown())) {
212 pause_animation_ = true;
213 pause_animation_state_ = slide_animator_.GetCurrentValue();
214 }
215 slide_animator_.Reset();
216 }
217
218 content::WebContents* web_contents = parent_->GetWebContents();
219 if (web_contents && !bubble_view_) {
220 bubble_view_ = new ContentSettingBubbleContents(
221 content_setting_image_model_->CreateBubbleModel(
222 parent_->delegate()->GetContentSettingBubbleModelDelegate(),
223 web_contents, parent_->profile()),
224 web_contents, this, views::BubbleBorder::TOP_RIGHT);
225 views::Widget* bubble_widget =
226 views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
227 bubble_widget->AddObserver(this);
228 // This is triggered by an input event. If the user clicks the icon while
229 // it's not animating, the icon will be placed in an active state, so the
230 // bubble doesn't need an arrow. If the user clicks during an animation,
231 // the animation simply pauses and no other visible state change occurs, so
232 // show the arrow in this case.
233 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) {
234 ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
235 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
236 }
237 bubble_widget->Show();
238 }
239
240 return true;
241 }
242
207 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { 243 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
208 slide_animator_.Reset(); 244 slide_animator_.Reset();
209 if (!pause_animation_) { 245 if (!pause_animation_) {
210 label()->SetVisible(false); 246 label()->SetVisible(false);
211 parent_->Layout(); 247 parent_->Layout();
212 parent_->SchedulePaint(); 248 parent_->SchedulePaint();
213 } 249 }
214 } 250 }
215 251
216 void ContentSettingImageView::AnimationProgressed( 252 void ContentSettingImageView::AnimationProgressed(
(...skipping 22 matching lines...) Expand all
239 } 275 }
240 } 276 }
241 277
242 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, 278 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
243 bool visible) { 279 bool visible) {
244 // |widget| is a bubble that has just got shown / hidden. 280 // |widget| is a bubble that has just got shown / hidden.
245 if (!visible && !label()->visible()) 281 if (!visible && !label()->visible())
246 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED); 282 ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED);
247 } 283 }
248 284
249 void ContentSettingImageView::OnClick() {
250 if (slide_animator_.is_animating()) {
251 // If the user clicks while we're animating, the bubble arrow will be
252 // pointing to the image, and if we allow the animation to keep running, the
253 // image will move away from the arrow (or we'll have to move the bubble,
254 // which is even worse). So we want to stop the animation. We have two
255 // choices: jump to the final post-animation state (no label visible), or
256 // pause the animation where we are and continue running after the bubble
257 // closes. The former looks more jerky, so we avoid it unless the animation
258 // hasn't even fully exposed the image yet, in which case pausing with half
259 // an image visible will look broken.
260 if (!pause_animation_ && ShouldShowBackground() &&
261 (width() > MinimumWidthForImageWithBackgroundShown())) {
262 pause_animation_ = true;
263 pause_animation_state_ = slide_animator_.GetCurrentValue();
264 }
265 slide_animator_.Reset();
266 }
267
268 content::WebContents* web_contents = parent_->GetWebContents();
269 if (web_contents && !bubble_view_) {
270 bubble_view_ = new ContentSettingBubbleContents(
271 content_setting_image_model_->CreateBubbleModel(
272 parent_->delegate()->GetContentSettingBubbleModelDelegate(),
273 web_contents, parent_->profile()),
274 web_contents, this, views::BubbleBorder::TOP_RIGHT);
275 views::Widget* bubble_widget =
276 views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
277 bubble_widget->AddObserver(this);
278 // This is triggered by an input event. If the user clicks the icon while
279 // it's not animating, the icon will be placed in an active state, so the
280 // bubble doesn't need an arrow. If the user clicks during an animation,
281 // the animation simply pauses and no other visible state change occurs, so
282 // show the arrow in this case.
283 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) {
284 ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
285 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
286 }
287 bubble_widget->Show();
288 }
289 }
290
291 void ContentSettingImageView::UpdateImage() { 285 void ContentSettingImageView::UpdateImage() {
292 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); 286 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
293 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); 287 image()->SetTooltipText(content_setting_image_model_->get_tooltip());
294 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698