diff options
author | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 20:09:08 +0000 |
---|---|---|
committer | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 20:09:08 +0000 |
commit | 26f26df9ade748422be49f8c023b37384adfaf73 (patch) | |
tree | 1eb614a029cfd2a589ec34de95be25bfe03d3293 | |
parent | 2557b7b6e367d4b94370de5671ad1f340c039519 (diff) | |
download | chromium_src-26f26df9ade748422be49f8c023b37384adfaf73.zip chromium_src-26f26df9ade748422be49f8c023b37384adfaf73.tar.gz chromium_src-26f26df9ade748422be49f8c023b37384adfaf73.tar.bz2 |
Remove tooltip bubble when mouse moves from launcher item to it.
Fix was easy (removing code!), unit test took a while.
BUG=247884
TEST=unittest
Review URL: https://chromiumcodereview.appspot.com/16845003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206150 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/launcher/launcher_tooltip_manager.cc | 34 | ||||
-rw-r--r-- | ash/launcher/launcher_tooltip_manager.h | 4 | ||||
-rw-r--r-- | ash/launcher/launcher_view_unittest.cc | 42 |
3 files changed, 64 insertions, 16 deletions
diff --git a/ash/launcher/launcher_tooltip_manager.cc b/ash/launcher/launcher_tooltip_manager.cc index 3313790..3fa02b4 100644 --- a/ash/launcher/launcher_tooltip_manager.cc +++ b/ash/launcher/launcher_tooltip_manager.cc @@ -226,14 +226,7 @@ void LauncherTooltipManager::ResetTimer() { if (shelf_layout_manager_ && !shelf_layout_manager_->IsVisible()) return; - base::OneShotTimer<LauncherTooltipManager>* new_timer = - new base::OneShotTimer<LauncherTooltipManager>(); - new_timer->Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(kTooltipAppearanceDelay), - this, - &LauncherTooltipManager::ShowInternal); - timer_.reset(new_timer); + CreateTimer(kTooltipAppearanceDelay); } void LauncherTooltipManager::StopTimer() { @@ -247,9 +240,13 @@ bool LauncherTooltipManager::IsVisible() { return widget_ && widget_->IsVisible(); } +void LauncherTooltipManager::CreateZeroDelayTimerForTest() { + CreateTimer(0); +} + void LauncherTooltipManager::OnMouseEvent(ui::MouseEvent* event) { - DCHECK(event->target()); DCHECK(event); + DCHECK(event->target()); if (!widget_ || !widget_->IsVisible()) return; @@ -267,13 +264,7 @@ void LauncherTooltipManager::OnMouseEvent(ui::MouseEvent* event) { target, launcher_view_->GetWidget()->GetNativeWindow(), &location_in_launcher_view); - gfx::Point location_on_screen = event->location(); - aura::Window::ConvertPointToTarget( - target, target->GetRootWindow(), &location_on_screen); - gfx::Rect bubble_rect = widget_->GetWindowBoundsInScreen(); - - if (launcher_view_->ShouldHideTooltip(location_in_launcher_view) && - !bubble_rect.Contains(location_on_screen)) { + if (launcher_view_->ShouldHideTooltip(location_in_launcher_view)) { // Because this mouse event may arrive to |view_|, here we just schedule // the closing event rather than directly calling Close(). CloseSoon(); @@ -367,5 +358,16 @@ void LauncherTooltipManager::CreateBubble(views::View* anchor, native_view, views::corewm::ANIMATE_HIDE); } +void LauncherTooltipManager::CreateTimer(int delay_in_ms) { + base::OneShotTimer<LauncherTooltipManager>* new_timer = + new base::OneShotTimer<LauncherTooltipManager>(); + new_timer->Start( + FROM_HERE, + base::TimeDelta::FromMilliseconds(delay_in_ms), + this, + &LauncherTooltipManager::ShowInternal); + timer_.reset(new base::OneShotTimer<LauncherTooltipManager>()); +} + } // namespace internal } // namespace ash diff --git a/ash/launcher/launcher_tooltip_manager.h b/ash/launcher/launcher_tooltip_manager.h index 852c30cb..a4cacd2 100644 --- a/ash/launcher/launcher_tooltip_manager.h +++ b/ash/launcher/launcher_tooltip_manager.h @@ -73,6 +73,9 @@ class ASH_EXPORT LauncherTooltipManager : public ui::EventHandler, // Returns true if the tooltip is currently visible. bool IsVisible(); + // Create an instant timer for test purposes. + void CreateZeroDelayTimerForTest(); + protected: // ui::EventHandler overrides: virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; @@ -95,6 +98,7 @@ protected: void CloseSoon(); void ShowInternal(); void CreateBubble(views::View* anchor, const base::string16& text); + void CreateTimer(int delay_in_ms); LauncherTooltipBubble* view_; views::Widget* widget_; diff --git a/ash/launcher/launcher_view_unittest.cc b/ash/launcher/launcher_view_unittest.cc index 3297f04..6ca05b0 100644 --- a/ash/launcher/launcher_view_unittest.cc +++ b/ash/launcher/launcher_view_unittest.cc @@ -27,6 +27,7 @@ #include "grit/ash_resources.h" #include "ui/aura/root_window.h" #include "ui/aura/test/aura_test_base.h" +#include "ui/aura/test/event_generator.h" #include "ui/aura/window.h" #include "ui/base/events/event.h" #include "ui/base/events/event_constants.h" @@ -919,6 +920,47 @@ TEST_F(LauncherViewTest, ShouldHideTooltipWithAppListWindowTest) { app_list_button->GetMirroredBounds().CenterPoint())); } +// Test that by moving the mouse cursor off the button onto the bubble it closes +// the bubble. +TEST_F(LauncherViewTest, ShouldHideTooltipWhenHoveringOnTooltip) { + internal::LauncherTooltipManager* tooltip_manager = + launcher_view_->tooltip_manager(); + tooltip_manager->CreateZeroDelayTimerForTest(); + aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); + + // Move the mouse off any item and check that no tooltip is shown. + generator.MoveMouseTo(gfx::Point(0, 0)); + EXPECT_FALSE(tooltip_manager->IsVisible()); + + // Move the mouse over the button and check that it is visible. + views::View* app_list_button = launcher_view_->GetAppListButtonView(); + gfx::Rect bounds = app_list_button->GetBoundsInScreen(); + generator.MoveMouseTo(bounds.CenterPoint()); + // Wait for the timer to go off. + RunAllPendingInMessageLoop(); + EXPECT_TRUE(tooltip_manager->IsVisible()); + + // Move the mouse cursor slightly to the right of the item. The tooltip should + // stay open. + generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0); + // Make sure there is no delayed close. + RunAllPendingInMessageLoop(); + EXPECT_TRUE(tooltip_manager->IsVisible()); + + // Move back - it should still stay open. + generator.MoveMouseBy(bounds.width() / 2 + 5, 0); + // Make sure there is no delayed close. + RunAllPendingInMessageLoop(); + EXPECT_TRUE(tooltip_manager->IsVisible()); + + // Now move the mouse cursor slightly above the item - so that it is over the + // tooltip bubble. Now it should disappear. + generator.MoveMouseBy(0, -(bounds.height() / 2 + 5)); + // Wait until the delayed close kicked in. + RunAllPendingInMessageLoop(); + EXPECT_FALSE(tooltip_manager->IsVisible()); +} + // Resizing launcher view while an add animation without fade-in is running, // which happens when overflow happens. App list button should end up in its // new ideal bounds. |