Commit a9e005a0 authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Port Views MenuButton Pressed Lock Logic to Cocoa BrowserActionButton

Before this change, when the user clicks on the button to dismiss the
Extension Popup, the popup would dismiss and destroy. Next, the
incoming mouse-up would note that the popup is already gone and show
the popup.

We want the popup to stay closed if it was dismissed by clicking the
action button.

The Views Browser doesn't have this problem because MenuButton tracks
the last time the locked state was released and suppresses any
activation if it occurs too soon.

This change simply carries similar logic from Views MenuButton to
Cocoa BrowserActionButton.

BUG=825866

Change-Id: I089f0ab8658277ae8cbf71e2813e62aeb3c5505f
Reviewed-on: https://chromium-review.googlesource.com/991596Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547755}
parent fa714c67
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
...@@ -40,6 +41,9 @@ NSString* const kBrowserActionButtonDragEndNotification = ...@@ -40,6 +41,9 @@ NSString* const kBrowserActionButtonDragEndNotification =
static const CGFloat kAnimationDuration = 0.2; static const CGFloat kAnimationDuration = 0.2;
static const CGFloat kMinimumDragDistance = 5; static const CGFloat kMinimumDragDistance = 5;
// Mirrors ui/views/mouse_constants.h for suppressing popup activation.
static const int kMinimumMsBetweenCloseOpenPopup = 100;
@interface BrowserActionButton () @interface BrowserActionButton ()
- (void)endDrag; - (void)endDrag;
- (void)updateHighlightedState; - (void)updateHighlightedState;
...@@ -61,6 +65,13 @@ class ToolbarActionViewDelegateBridge : public ToolbarActionViewDelegate { ...@@ -61,6 +65,13 @@ class ToolbarActionViewDelegateBridge : public ToolbarActionViewDelegate {
bool user_shown_popup_visible() const { return user_shown_popup_visible_; } bool user_shown_popup_visible() const { return user_shown_popup_visible_; }
bool CanShowPopup() const {
// If the user clicks on the browser action button to close the bubble,
// don't show the next popup too soon on the mouse button up.
base::TimeDelta delta = base::TimeTicks::Now() - popup_closed_time_;
return delta.InMilliseconds() >= kMinimumMsBetweenCloseOpenPopup;
}
private: private:
// ToolbarActionViewDelegate: // ToolbarActionViewDelegate:
content::WebContents* GetCurrentWebContents() const override; content::WebContents* GetCurrentWebContents() const override;
...@@ -72,6 +83,11 @@ class ToolbarActionViewDelegateBridge : public ToolbarActionViewDelegate { ...@@ -72,6 +83,11 @@ class ToolbarActionViewDelegateBridge : public ToolbarActionViewDelegate {
// A helper method to implement showing the context menu. // A helper method to implement showing the context menu.
void DoShowContextMenu(); void DoShowContextMenu();
// Tracks when the menu was closed so that the button can ignore the incoming
// mouse button up event if its too soon. This simulates the same behavior
// provided by the views toolkit MenuButton Pressed Locked tracking state.
base::TimeTicks popup_closed_time_;
// The owning button. Weak. // The owning button. Weak.
BrowserActionButton* owner_; BrowserActionButton* owner_;
...@@ -157,6 +173,7 @@ void ToolbarActionViewDelegateBridge::OnPopupShown(bool by_user) { ...@@ -157,6 +173,7 @@ void ToolbarActionViewDelegateBridge::OnPopupShown(bool by_user) {
} }
void ToolbarActionViewDelegateBridge::OnPopupClosed() { void ToolbarActionViewDelegateBridge::OnPopupClosed() {
popup_closed_time_ = base::TimeTicks::Now();
user_shown_popup_visible_ = false; user_shown_popup_visible_ = false;
[owner_ updateHighlightedState]; [owner_ updateHighlightedState];
} }
...@@ -330,7 +347,9 @@ void ToolbarActionViewDelegateBridge::DoShowContextMenu() { ...@@ -330,7 +347,9 @@ void ToolbarActionViewDelegateBridge::DoShowContextMenu() {
fromView:nil]; fromView:nil];
// Only perform the click if we didn't drag the button. // Only perform the click if we didn't drag the button.
if (NSPointInRect(location, [self bounds]) && !isBeingDragged_) { if (NSPointInRect(location, [self bounds]) && !isBeingDragged_) {
[self performClick:self]; if (viewControllerDelegate_->CanShowPopup()) {
[self performClick:self];
}
} else { } else {
// Make sure an ESC to end a drag doesn't trigger 2 endDrags. // Make sure an ESC to end a drag doesn't trigger 2 endDrags.
if (isBeingDragged_) { if (isBeingDragged_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment