Commit 14a00c76 authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

ash: Cleanup TrayBubbleView MouseWatcher and delegates

Cleanup TrayBubbleView's MouseWatcher comments.
Remove a TimeDelta that was being used incorrectly.
(controls the callback delay, not a mouse sampling rate)

Remove no-op delegate function overrides (default is no-op).
Remove a call to the no-op BubbleDialogDelegateView::OnGestureEvent.

Bug: None
Test: No tray bubble (volume/brightness) auto-close regressions.
Change-Id: I1bf3775b22a147f2d42557ff4a71dba153c5bb6c
Reviewed-on: https://chromium-review.googlesource.com/1241195Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593662}
parent 99774c50
......@@ -492,13 +492,6 @@ void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) {
CloseBubble();
}
void ImeMenuTray::BubbleViewDestroyed() {
}
void ImeMenuTray::OnMouseEnteredView() {}
void ImeMenuTray::OnMouseExitedView() {}
base::string16 ImeMenuTray::GetAccessibleNameForBubble() {
return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
}
......
......@@ -65,9 +65,6 @@ class ASH_EXPORT ImeMenuTray : public TrayBackgroundView,
void OnIMEMenuActivationChanged(bool is_activated) override;
// TrayBubbleView::Delegate:
void BubbleViewDestroyed() override;
void OnMouseEnteredView() override;
void OnMouseExitedView() override;
base::string16 GetAccessibleNameForBubble() override;
bool ShouldEnableExtraKeyboardAccessibility() override;
void HideBubble(const TrayBubbleView* bubble_view) override;
......
......@@ -477,10 +477,6 @@ void NotificationTray::BubbleViewDestroyed() {
message_center_bubble()->bubble()->BubbleViewDestroyed();
}
void NotificationTray::OnMouseEnteredView() {}
void NotificationTray::OnMouseExitedView() {}
base::string16 NotificationTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray();
}
......
......@@ -73,8 +73,6 @@ class ASH_EXPORT NotificationTray
// Overridden from TrayBubbleView::Delegate.
void BubbleViewDestroyed() override;
void OnMouseEnteredView() override;
void OnMouseExitedView() override;
base::string16 GetAccessibleNameForBubble() override;
bool ShouldEnableExtraKeyboardAccessibility() override;
void HideBubble(const TrayBubbleView* bubble_view) override;
......
......@@ -320,10 +320,6 @@ void PaletteTray::BubbleViewDestroyed() {
PaletteGroup::MODE) != PaletteToolId::NONE);
}
void PaletteTray::OnMouseEnteredView() {}
void PaletteTray::OnMouseExitedView() {}
base::string16 PaletteTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray();
}
......
......@@ -97,8 +97,6 @@ class ASH_EXPORT PaletteTray : public TrayBackgroundView,
// TrayBubbleView::Delegate:
void BubbleViewDestroyed() override;
void OnMouseEnteredView() override;
void OnMouseExitedView() override;
base::string16 GetAccessibleNameForBubble() override;
bool ShouldEnableExtraKeyboardAccessibility() override;
void HideBubble(const TrayBubbleView* bubble_view) override;
......
......@@ -42,10 +42,6 @@ namespace ash {
namespace {
// The sampling time for mouse position changes in ms - which is roughly a frame
// time.
const int kFrameTimeInMS = 30;
BubbleBorder::Arrow GetArrowAlignment(
TrayBubbleView::AnchorAlignment alignment) {
if (alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
......@@ -401,32 +397,23 @@ int TrayBubbleView::GetHeightForWidth(int width) const {
void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) {
mouse_watcher_.reset();
if (delegate_ && !(event.flags() & ui::EF_IS_SYNTHESIZED)) {
// Coming here the user was actively moving the mouse over the bubble and
// we inform the delegate that we entered. This will prevent the bubble
// to auto close.
// The user actively moved the mouse over the bubble; inform the delegate.
delegate_->OnMouseEnteredView();
mouse_actively_entered_ = true;
} else {
// Coming here the bubble got shown and the mouse was 'accidentally' over it
// which is not a reason to prevent the bubble to auto close. As such we
// do not call the delegate, but wait for the first mouse move within the
// bubble. The used MouseWatcher will notify use of a movement and call
// |MouseMovedOutOfHost|.
// The mouse was located over the bubble when it was first shown; use
// MouseWatcher to wait for user interaction before signaling the delegate.
mouse_watcher_ = std::make_unique<views::MouseWatcher>(
std::make_unique<MouseMoveDetectorHost>(), this);
// Set the mouse sampling frequency to roughly a frame time so that the user
// cannot see a lag.
mouse_watcher_->set_notify_on_exit_time(
base::TimeDelta::FromMilliseconds(kFrameTimeInMS));
mouse_watcher_->set_notify_on_exit_time(base::TimeDelta());
mouse_watcher_->Start(GetWidget()->GetNativeWindow());
}
}
void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) {
// If there was a mouse watcher waiting for mouse movements we disable it
// immediately since we now leave the bubble.
// Disable any MouseWatcher waiting for user interaction inside the bubble.
mouse_watcher_.reset();
// Do not notify the delegate of an exit if we never told it that we entered.
// Only notify the delegate on exit if it was notified on enter.
if (delegate_ && mouse_actively_entered_)
delegate_->OnMouseExitedView();
}
......@@ -441,19 +428,14 @@ void TrayBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
void TrayBubbleView::OnGestureEvent(ui::GestureEvent* event) {
if (delegate_)
delegate_->ProcessGestureEventForBubble(event);
if (!event->handled())
BubbleDialogDelegateView::OnGestureEvent(event);
}
void TrayBubbleView::MouseMovedOutOfHost() {
// The mouse was accidentally over the bubble when it opened and the AutoClose
// logic was not activated. Now that the user did move the mouse we tell the
// delegate to disable AutoClose.
// The user moved the mouse that was over the bubble when it was first shown.
if (delegate_)
delegate_->OnMouseEnteredView();
mouse_actively_entered_ = true;
mouse_watcher_->Stop();
mouse_watcher_.reset();
}
void TrayBubbleView::ChildPreferredSizeChanged(View* child) {
......
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