diff options
author | msw <msw@chromium.org> | 2016-03-25 16:31:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-25 23:33:11 +0000 |
commit | 1a0d283fa81e19b47fb85523f28c4a03f7dc1d24 (patch) | |
tree | 26f4394f6c50d429f2b967752f95d8e75bd93ef3 | |
parent | 19019f27a62f561909f0ec733510bacbd74b374c (diff) | |
download | chromium_src-1a0d283fa81e19b47fb85523f28c4a03f7dc1d24.zip chromium_src-1a0d283fa81e19b47fb85523f28c4a03f7dc1d24.tar.gz chromium_src-1a0d283fa81e19b47fb85523f28c4a03f7dc1d24.tar.bz2 |
Refine ash shelf tooltip closing on non-mash ChromeOS.
Fixes a regression from: https://codereview.chromium.org/1816753002
Also reverse expected behavior for touching tooltips.
(closes on stable, tests expected them to stay open...)
Inline bubble function definitions.
Call WillDeleteShelf earlier to fix a test crash...
TODO: Encapsulate more ShelfLayoutManager code.
BUG=595853
TEST=ChromeOS tooltips stay open on hover; close for external touches.
R=sky@chromium.org
Review URL: https://codereview.chromium.org/1828133004
Cr-Commit-Position: refs/heads/master@{#383404}
-rw-r--r-- | ash/shelf/shelf_layout_manager.cc | 1 | ||||
-rw-r--r-- | ash/shelf/shelf_tooltip_manager.cc | 116 | ||||
-rw-r--r-- | ash/shelf/shelf_tooltip_manager_unittest.cc | 32 |
3 files changed, 76 insertions, 73 deletions
diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc index f27899c..5d70e8d 100644 --- a/ash/shelf/shelf_layout_manager.cc +++ b/ash/shelf/shelf_layout_manager.cc @@ -236,6 +236,7 @@ void ShelfLayoutManager::PrepareForShutdown() { // Stop observing window change, otherwise we can attempt to update a // partially destructed shelf. aura::client::GetActivationClient(root_window_)->RemoveObserver(this); + FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, WillDeleteShelf()); } bool ShelfLayoutManager::IsVisible() const { diff --git a/ash/shelf/shelf_tooltip_manager.cc b/ash/shelf/shelf_tooltip_manager.cc index 5e25fb2..0f1d1fd 100644 --- a/ash/shelf/shelf_tooltip_manager.cc +++ b/ash/shelf/shelf_tooltip_manager.cc @@ -24,6 +24,7 @@ namespace ash { namespace { + const int kTooltipTopBottomMargin = 3; const int kTooltipLeftRightMargin = 10; const int kTooltipAppearanceDelay = 1000; // msec @@ -48,54 +49,47 @@ class ShelfTooltipManager::ShelfTooltipBubble public: ShelfTooltipBubble(views::View* anchor, views::BubbleBorder::Arrow arrow, - const base::string16& text); + const base::string16& text) + : views::BubbleDelegateView(anchor, arrow) { + gfx::Insets insets = + gfx::Insets(kArrowOffsetTopBottom, kArrowOffsetLeftRight); + // Adjust the anchor location for asymmetrical borders of shelf item. + if (anchor->border()) + insets += anchor->border()->GetInsets(); + + set_anchor_view_insets(insets); + set_close_on_esc(false); + set_close_on_deactivate(false); + set_can_activate(false); + set_accept_events(false); + set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin)); + set_shadow(views::BubbleBorder::SMALL_SHADOW); + SetLayoutManager(new views::FillLayout()); + // The anchor may not have the widget in tests. + if (anchor->GetWidget() && anchor->GetWidget()->GetNativeWindow()) { + set_parent_window(ash::Shell::GetContainer( + anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), + ash::kShellWindowId_SettingBubbleContainer)); + } + views::Label* label = new views::Label(text); + label->SetHorizontalAlignment(gfx::ALIGN_LEFT); + label->SetEnabledColor(kTooltipTextColor); + AddChildView(label); + views::BubbleDelegateView::CreateBubble(this); + SizeToContents(); + } private: // views::View overrides: - gfx::Size GetPreferredSize() const override; + gfx::Size GetPreferredSize() const override { + const gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); + return gfx::Size(std::min(size.width(), kTooltipMaxWidth), + std::max(size.height(), kTooltipMinHeight)); + } DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); }; -ShelfTooltipManager::ShelfTooltipBubble::ShelfTooltipBubble( - views::View* anchor, - views::BubbleBorder::Arrow arrow, - const base::string16& text) - : views::BubbleDelegateView(anchor, arrow) { - gfx::Insets insets = gfx::Insets(kArrowOffsetTopBottom, - kArrowOffsetLeftRight); - // Adjust the anchor location for asymmetrical borders of shelf item. - if (anchor->border()) - insets += anchor->border()->GetInsets(); - - set_anchor_view_insets(insets); - set_close_on_esc(false); - set_close_on_deactivate(false); - set_can_activate(false); - set_accept_events(false); - set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin)); - set_shadow(views::BubbleBorder::SMALL_SHADOW); - SetLayoutManager(new views::FillLayout()); - // The anchor may not have the widget in tests. - if (anchor->GetWidget() && anchor->GetWidget()->GetNativeWindow()) { - set_parent_window(ash::Shell::GetContainer( - anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), - ash::kShellWindowId_SettingBubbleContainer)); - } - views::Label* label = new views::Label(text); - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - label->SetEnabledColor(kTooltipTextColor); - AddChildView(label); - views::BubbleDelegateView::CreateBubble(this); - SizeToContents(); -} - -gfx::Size ShelfTooltipManager::ShelfTooltipBubble::GetPreferredSize() const { - const gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); - return gfx::Size(std::min(size.width(), kTooltipMaxWidth), - std::max(size.height(), kTooltipMinHeight)); -} - ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) : timer_delay_(kTooltipAppearanceDelay), shelf_view_(shelf_view), @@ -110,8 +104,10 @@ ShelfTooltipManager::~ShelfTooltipManager() { void ShelfTooltipManager::Init() { shelf_layout_manager_ = shelf_view_->shelf()->shelf_layout_manager(); shelf_layout_manager_->AddObserver(this); - // TODO(msw): Capture events outside the shelf to close tooltips? - shelf_view_->GetWidget()->GetNativeWindow()->AddPreTargetHandler(this); + + // TODO(msw): Observe events outside the shelf in mash, to close tooltips. + aura::Window* shelf_window = shelf_view_->GetWidget()->GetNativeWindow(); + shelf_window->GetRootWindow()->AddPreTargetHandler(this); } void ShelfTooltipManager::Close() { @@ -164,31 +160,29 @@ void ShelfTooltipManager::ShowTooltipWithDelay(views::View* view) { } void ShelfTooltipManager::OnEvent(ui::Event* event) { - // Close the tooltip on mouse press or exit, and on most non-mouse events. if (event->type() == ui::ET_MOUSE_PRESSED || - event->type() == ui::ET_MOUSE_EXITED || !event->IsMouseEvent()) { + event->type() == ui::ET_MOUSE_EXITED || !event->IsMouseEvent() || + event->target() != shelf_view_->GetWidget()->GetNativeWindow()) { if (!event->IsKeyEvent()) Close(); return; } gfx::Point point = static_cast<ui::LocatedEvent*>(event)->location(); + aura::Window::ConvertPointToTarget( + static_cast<aura::Window*>(event->target()), + shelf_view_->GetWidget()->GetNativeWindow(), &point); views::View::ConvertPointFromWidget(shelf_view_, &point); - if (IsVisible() && shelf_view_->ShouldHideTooltip(point)) { - Close(); - return; - } - views::View* view = shelf_view_->GetTooltipHandlerForPoint(point); const bool should_show = shelf_view_->ShouldShowTooltipForView(view); - if (IsVisible() && bubble_->GetAnchorView() != view && should_show) - ShowTooltip(view); - if (!IsVisible() && event->type() == ui::ET_MOUSE_MOVED) { - timer_.Stop(); - if (should_show) - ShowTooltipWithDelay(view); - } + timer_.Stop(); + if (IsVisible() && should_show && bubble_->GetAnchorView() != view) + ShowTooltip(view); + else if (!IsVisible() && should_show && event->type() == ui::ET_MOUSE_MOVED) + ShowTooltipWithDelay(view); + else if (IsVisible() && shelf_view_->ShouldHideTooltip(point)) + Close(); } void ShelfTooltipManager::WillDeleteShelf() { @@ -196,9 +190,11 @@ void ShelfTooltipManager::WillDeleteShelf() { shelf_layout_manager_->RemoveObserver(this); shelf_layout_manager_ = nullptr; - views::Widget* widget = shelf_view_ ? shelf_view_->GetWidget() : nullptr; - if (widget && widget->GetNativeWindow()) - widget->GetNativeWindow()->RemovePreTargetHandler(this); + if (shelf_view_ && shelf_view_->GetWidget()) { + aura::Window* shelf_window = shelf_view_->GetWidget()->GetNativeWindow(); + if (shelf_window && shelf_window->GetRootWindow()) + shelf_window->GetRootWindow()->RemovePreTargetHandler(this); + } shelf_view_ = nullptr; } diff --git a/ash/shelf/shelf_tooltip_manager_unittest.cc b/ash/shelf/shelf_tooltip_manager_unittest.cc index 3f2b2e8..7f6650e 100644 --- a/ash/shelf/shelf_tooltip_manager_unittest.cc +++ b/ash/shelf/shelf_tooltip_manager_unittest.cc @@ -173,35 +173,41 @@ TEST_F(ShelfTooltipManagerTest, HideForEvents) { EXPECT_FALSE(TooltipIsVisible()); } -// TODO(msw): Hiding for touch and gesture events outside the shelf is broken. -TEST_F(ShelfTooltipManagerTest, HideForEventsBroken) { +TEST_F(ShelfTooltipManagerTest, HideForExternalEvents) { ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); + // TODO(msw): Observe events outside the shelf in mash, to close tooltips. + aura::Window* shelf_window = shelf_->shelf_widget()->GetNativeWindow(); + bool closes = shelf_window->GetRootWindow() == Shell::GetPrimaryRootWindow(); + // Should hide for touches outside the shelf. ShowImmediately(); ASSERT_TRUE(TooltipIsVisible()); - generator.set_current_location(gfx::Point()); generator.PressTouch(); - EXPECT_TRUE(TooltipIsVisible()); + EXPECT_EQ(TooltipIsVisible(), !closes); + // Should hide for touch events on the tooltip. + ShowImmediately(); + ASSERT_TRUE(TooltipIsVisible()); + generator.set_current_location(GetTooltipWindow()->bounds().CenterPoint()); + generator.PressTouch(); + EXPECT_EQ(TooltipIsVisible(), !closes); + + // Should hide for gestures outside the shelf. + ShowImmediately(); + ASSERT_TRUE(TooltipIsVisible()); generator.GestureTapDownAndUp(gfx::Point()); - EXPECT_TRUE(TooltipIsVisible()); + EXPECT_EQ(TooltipIsVisible(), !closes); } -TEST_F(ShelfTooltipManagerTest, DoNotHideForEvents) { +TEST_F(ShelfTooltipManagerTest, DoNotHideForKeyEvents) { ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); + // Should not hide for key events. ShowImmediately(); ASSERT_TRUE(TooltipIsVisible()); - - // Should not hide for key events. generator.PressKey(ui::VKEY_A, ui::EF_NONE); EXPECT_TRUE(TooltipIsVisible()); - - // Should not hide for touch events on the tooltip. - generator.set_current_location(GetTooltipWindow()->bounds().CenterPoint()); - generator.PressTouch(); - EXPECT_TRUE(TooltipIsVisible()); } } // namespace test |