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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/location_bar/content_setting_image_view.cc
diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
index f1a33e4891c4148bf2c4a0e5c2bf33621c8be4d0..1711eb48e5f8e6353e2d22ee9966520e84d859bf 100644
--- a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
+++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc
@@ -139,20 +139,12 @@ void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) {
if (!label()->visible() && !activated)
ink_drop_delegate_->OnAction(views::InkDropState::HIDDEN);
if (activated)
- OnClick();
-}
-
-bool ContentSettingImageView::OnKeyPressed(const ui::KeyEvent& event) {
- if (event.key_code() != ui::VKEY_SPACE && event.key_code() != ui::VKEY_RETURN)
- return false;
-
- OnClick();
- return true;
+ OnActivate();
}
void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP)
- OnClick();
+ OnActivate();
if ((event->type() == ui::ET_GESTURE_TAP) ||
(event->type() == ui::ET_GESTURE_TAP_DOWN))
event->SetHandled();
@@ -204,6 +196,50 @@ bool ContentSettingImageView::IsShrinking() const {
slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction));
}
+bool ContentSettingImageView::OnActivate() {
+ if (slide_animator_.is_animating()) {
+ // If the user clicks while we're animating, the bubble arrow will be
+ // pointing to the image, and if we allow the animation to keep running, the
+ // image will move away from the arrow (or we'll have to move the bubble,
+ // which is even worse). So we want to stop the animation. We have two
+ // choices: jump to the final post-animation state (no label visible), or
+ // pause the animation where we are and continue running after the bubble
+ // closes. The former looks more jerky, so we avoid it unless the animation
+ // hasn't even fully exposed the image yet, in which case pausing with half
+ // an image visible will look broken.
+ if (!pause_animation_ && ShouldShowBackground() &&
+ (width() > MinimumWidthForImageWithBackgroundShown())) {
+ pause_animation_ = true;
+ pause_animation_state_ = slide_animator_.GetCurrentValue();
+ }
+ slide_animator_.Reset();
+ }
+
+ content::WebContents* web_contents = parent_->GetWebContents();
+ if (web_contents && !bubble_view_) {
+ bubble_view_ = new ContentSettingBubbleContents(
+ content_setting_image_model_->CreateBubbleModel(
+ parent_->delegate()->GetContentSettingBubbleModelDelegate(),
+ web_contents, parent_->profile()),
+ web_contents, this, views::BubbleBorder::TOP_RIGHT);
+ views::Widget* bubble_widget =
+ views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
+ bubble_widget->AddObserver(this);
+ // This is triggered by an input event. If the user clicks the icon while
+ // it's not animating, the icon will be placed in an active state, so the
+ // bubble doesn't need an arrow. If the user clicks during an animation,
+ // the animation simply pauses and no other visible state change occurs, so
+ // show the arrow in this case.
+ if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) {
+ ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
+ bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
+ }
+ bubble_widget->Show();
+ }
+
+ return true;
+}
+
void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) {
slide_animator_.Reset();
if (!pause_animation_) {
@@ -246,48 +282,6 @@ void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget,
ink_drop_delegate_->OnAction(views::InkDropState::DEACTIVATED);
}
-void ContentSettingImageView::OnClick() {
- if (slide_animator_.is_animating()) {
- // If the user clicks while we're animating, the bubble arrow will be
- // pointing to the image, and if we allow the animation to keep running, the
- // image will move away from the arrow (or we'll have to move the bubble,
- // which is even worse). So we want to stop the animation. We have two
- // choices: jump to the final post-animation state (no label visible), or
- // pause the animation where we are and continue running after the bubble
- // closes. The former looks more jerky, so we avoid it unless the animation
- // hasn't even fully exposed the image yet, in which case pausing with half
- // an image visible will look broken.
- if (!pause_animation_ && ShouldShowBackground() &&
- (width() > MinimumWidthForImageWithBackgroundShown())) {
- pause_animation_ = true;
- pause_animation_state_ = slide_animator_.GetCurrentValue();
- }
- slide_animator_.Reset();
- }
-
- content::WebContents* web_contents = parent_->GetWebContents();
- if (web_contents && !bubble_view_) {
- bubble_view_ = new ContentSettingBubbleContents(
- content_setting_image_model_->CreateBubbleModel(
- parent_->delegate()->GetContentSettingBubbleModelDelegate(),
- web_contents, parent_->profile()),
- web_contents, this, views::BubbleBorder::TOP_RIGHT);
- views::Widget* bubble_widget =
- views::BubbleDialogDelegateView::CreateBubble(bubble_view_);
- bubble_widget->AddObserver(this);
- // This is triggered by an input event. If the user clicks the icon while
- // it's not animating, the icon will be placed in an active state, so the
- // bubble doesn't need an arrow. If the user clicks during an animation,
- // the animation simply pauses and no other visible state change occurs, so
- // show the arrow in this case.
- if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) {
- ink_drop_delegate_->OnAction(views::InkDropState::ACTIVATED);
- bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
- }
- bubble_widget->Show();
- }
-}
-
void ContentSettingImageView::UpdateImage() {
SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia());
image()->SetTooltipText(content_setting_image_model_->get_tooltip());

Powered by Google App Engine
This is Rietveld 408576698