| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/shelf/shelf_tooltip_manager.h" | 5 #include "ash/shelf/shelf_tooltip_manager.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
| 9 #include "ash/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 ui::EventHandler* event_handler = GetEventHandler(); | 184 ui::EventHandler* event_handler = GetEventHandler(); |
| 185 | 185 |
| 186 // Should not hide for key events. | 186 // Should not hide for key events. |
| 187 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 187 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 188 SetEventTarget(root_window, &key_event); | 188 SetEventTarget(root_window, &key_event); |
| 189 event_handler->OnKeyEvent(&key_event); | 189 event_handler->OnKeyEvent(&key_event); |
| 190 EXPECT_FALSE(key_event.handled()); | 190 EXPECT_FALSE(key_event.handled()); |
| 191 EXPECT_TRUE(TooltipIsVisible()); | 191 EXPECT_TRUE(TooltipIsVisible()); |
| 192 | 192 |
| 193 // Should hide for touch events. | 193 // Should hide for touch events. |
| 194 ui::TouchEvent touch_event( | 194 ui::TouchEvent touch_event(ui::ET_TOUCH_PRESSED, gfx::PointF(), 0, |
| 195 ui::ET_TOUCH_PRESSED, gfx::Point(), 0, base::TimeDelta()); | 195 base::TimeDelta()); |
| 196 SetEventTarget(root_window, &touch_event); | 196 SetEventTarget(root_window, &touch_event); |
| 197 event_handler->OnTouchEvent(&touch_event); | 197 event_handler->OnTouchEvent(&touch_event); |
| 198 EXPECT_FALSE(touch_event.handled()); | 198 EXPECT_FALSE(touch_event.handled()); |
| 199 EXPECT_FALSE(TooltipIsVisible()); | 199 EXPECT_FALSE(TooltipIsVisible()); |
| 200 | 200 |
| 201 // Shouldn't hide if the touch happens on the tooltip. | 201 // Shouldn't hide if the touch happens on the tooltip. |
| 202 ShowImmediately(); | 202 ShowImmediately(); |
| 203 views::Widget* tooltip_widget = GetTooltipWidget(); | 203 views::Widget* tooltip_widget = GetTooltipWidget(); |
| 204 SetEventTarget(tooltip_widget->GetNativeWindow(), &touch_event); | 204 SetEventTarget(tooltip_widget->GetNativeWindow(), &touch_event); |
| 205 event_handler->OnTouchEvent(&touch_event); | 205 event_handler->OnTouchEvent(&touch_event); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 220 EXPECT_FALSE(TooltipIsVisible()); | 220 EXPECT_FALSE(TooltipIsVisible()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(ShelfTooltipManagerTest, HideForMouseMoveEvent) { | 223 TEST_F(ShelfTooltipManagerTest, HideForMouseMoveEvent) { |
| 224 ShowImmediately(); | 224 ShowImmediately(); |
| 225 ASSERT_TRUE(TooltipIsVisible()); | 225 ASSERT_TRUE(TooltipIsVisible()); |
| 226 | 226 |
| 227 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); | 227 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 228 ui::EventHandler* event_handler = GetEventHandler(); | 228 ui::EventHandler* event_handler = GetEventHandler(); |
| 229 | 229 |
| 230 gfx::Rect tooltip_rect = GetTooltipWidget()->GetNativeWindow()->bounds(); | 230 auto tooltip_rect = |
| 231 gfx::RectF(GetTooltipWidget()->GetNativeWindow()->bounds()); |
| 231 ASSERT_FALSE(tooltip_rect.IsEmpty()); | 232 ASSERT_FALSE(tooltip_rect.IsEmpty()); |
| 232 | 233 |
| 233 // Shouldn't hide if the mouse is in the tooltip. | 234 // Shouldn't hide if the mouse is in the tooltip. |
| 234 ui::MouseEvent mouse_event(ui::ET_MOUSE_MOVED, tooltip_rect.CenterPoint(), | 235 ui::MouseEvent mouse_event(ui::ET_MOUSE_MOVED, tooltip_rect.CenterPoint(), |
| 235 tooltip_rect.CenterPoint(), ui::EventTimeForNow(), | 236 tooltip_rect.CenterPoint(), ui::EventTimeForNow(), |
| 236 ui::EF_NONE, ui::EF_NONE); | 237 ui::EF_NONE, ui::EF_NONE); |
| 237 ui::LocatedEventTestApi test_api(&mouse_event); | 238 ui::LocatedEventTestApi test_api(&mouse_event); |
| 238 | 239 |
| 239 SetEventTarget(root_window, &mouse_event); | 240 SetEventTarget(root_window, &mouse_event); |
| 240 event_handler->OnMouseEvent(&mouse_event); | 241 event_handler->OnMouseEvent(&mouse_event); |
| 241 EXPECT_FALSE(mouse_event.handled()); | 242 EXPECT_FALSE(mouse_event.handled()); |
| 242 EXPECT_TRUE(TooltipIsVisible()); | 243 EXPECT_TRUE(TooltipIsVisible()); |
| 243 | 244 |
| 244 // Should hide if the mouse is out of the tooltip. | 245 // Should hide if the mouse is out of the tooltip. |
| 245 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1)); | 246 test_api.set_location(tooltip_rect.origin() + gfx::Vector2dF(-1.f, -1.f)); |
| 246 event_handler->OnMouseEvent(&mouse_event); | 247 event_handler->OnMouseEvent(&mouse_event); |
| 247 EXPECT_FALSE(mouse_event.handled()); | 248 EXPECT_FALSE(mouse_event.handled()); |
| 248 RunAllPendingInMessageLoop(); | 249 RunAllPendingInMessageLoop(); |
| 249 EXPECT_FALSE(TooltipIsVisible()); | 250 EXPECT_FALSE(TooltipIsVisible()); |
| 250 } | 251 } |
| 251 | 252 |
| 252 // Checks that tooltip is hidden when mouse is pressed in anywhere. | 253 // Checks that tooltip is hidden when mouse is pressed in anywhere. |
| 253 TEST_F(ShelfTooltipManagerTest, HideForMouseClickEvent) { | 254 TEST_F(ShelfTooltipManagerTest, HideForMouseClickEvent) { |
| 254 ShowImmediately(); | 255 ShowImmediately(); |
| 255 ASSERT_TRUE(TooltipIsVisible()); | 256 ASSERT_TRUE(TooltipIsVisible()); |
| 256 | 257 |
| 257 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); | 258 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 258 ui::EventHandler* event_handler = GetEventHandler(); | 259 ui::EventHandler* event_handler = GetEventHandler(); |
| 259 | 260 |
| 260 gfx::Rect tooltip_rect = GetTooltipWidget()->GetNativeWindow()->bounds(); | 261 gfx::Rect tooltip_rect = GetTooltipWidget()->GetNativeWindow()->bounds(); |
| 261 ASSERT_FALSE(tooltip_rect.IsEmpty()); | 262 ASSERT_FALSE(tooltip_rect.IsEmpty()); |
| 262 | 263 |
| 263 // Should hide if the mouse is pressed in the tooltip. | 264 // Should hide if the mouse is pressed in the tooltip. |
| 264 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, tooltip_rect.CenterPoint(), | 265 ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, |
| 265 tooltip_rect.CenterPoint(), ui::EventTimeForNow(), | 266 gfx::PointF(tooltip_rect.CenterPoint()), |
| 266 ui::EF_NONE, ui::EF_NONE); | 267 gfx::PointF(tooltip_rect.CenterPoint()), |
| 268 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 267 | 269 |
| 268 SetEventTarget(root_window, &mouse_event); | 270 SetEventTarget(root_window, &mouse_event); |
| 269 event_handler->OnMouseEvent(&mouse_event); | 271 event_handler->OnMouseEvent(&mouse_event); |
| 270 EXPECT_FALSE(mouse_event.handled()); | 272 EXPECT_FALSE(mouse_event.handled()); |
| 271 RunAllPendingInMessageLoop(); | 273 RunAllPendingInMessageLoop(); |
| 272 EXPECT_FALSE(TooltipIsVisible()); | 274 EXPECT_FALSE(TooltipIsVisible()); |
| 273 | 275 |
| 274 // Should hide if the mouse is pressed outside of the tooltip. | 276 // Should hide if the mouse is pressed outside of the tooltip. |
| 275 ShowImmediately(); | 277 ShowImmediately(); |
| 276 ASSERT_TRUE(TooltipIsVisible()); | 278 ASSERT_TRUE(TooltipIsVisible()); |
| 277 | 279 |
| 278 ui::LocatedEventTestApi test_api(&mouse_event); | 280 ui::LocatedEventTestApi test_api(&mouse_event); |
| 279 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1)); | 281 test_api.set_location(gfx::PointF(tooltip_rect.origin()) + |
| 282 gfx::Vector2dF(-1.f, -1.f)); |
| 280 | 283 |
| 281 SetEventTarget(root_window, &mouse_event); | 284 SetEventTarget(root_window, &mouse_event); |
| 282 event_handler->OnMouseEvent(&mouse_event); | 285 event_handler->OnMouseEvent(&mouse_event); |
| 283 EXPECT_FALSE(mouse_event.handled()); | 286 EXPECT_FALSE(mouse_event.handled()); |
| 284 RunAllPendingInMessageLoop(); | 287 RunAllPendingInMessageLoop(); |
| 285 EXPECT_FALSE(TooltipIsVisible()); | 288 EXPECT_FALSE(TooltipIsVisible()); |
| 286 } | 289 } |
| 287 | 290 |
| 288 } // namespace test | 291 } // namespace test |
| 289 } // namespace ash | 292 } // namespace ash |
| OLD | NEW |