| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_widget.h" | 5 #include "ash/shelf/shelf_widget.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shelf/shelf.h" | 8 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_button.h" | 9 #include "ash/shelf/shelf_button.h" |
| 10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen(); | 203 gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen(); |
| 204 EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds)); | 204 EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds)); |
| 205 | 205 |
| 206 ui::EventTarget* root = widget->GetNativeWindow()->GetRootWindow(); | 206 ui::EventTarget* root = widget->GetNativeWindow()->GetRootWindow(); |
| 207 ui::EventTargeter* targeter = root->GetEventTargeter(); | 207 ui::EventTargeter* targeter = root->GetEventTargeter(); |
| 208 { | 208 { |
| 209 // Create a mouse-event targeting the top of the shelf widget. The | 209 // Create a mouse-event targeting the top of the shelf widget. The |
| 210 // window-targeter should find |widget| as the target (instead of the | 210 // window-targeter should find |widget| as the target (instead of the |
| 211 // shelf). | 211 // shelf). |
| 212 gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1); | 212 gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1); |
| 213 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 213 ui::MouseEvent mouse( |
| 214 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 214 ui::ET_MOUSE_MOVED, event_location, event_location, |
| 215 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 216 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 215 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 217 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
| 216 EXPECT_EQ(widget->GetNativeWindow(), target); | 218 EXPECT_EQ(widget->GetNativeWindow(), target); |
| 217 } | 219 } |
| 218 | 220 |
| 219 // Change shelf alignment to verify that the targeter insets are updated. | 221 // Change shelf alignment to verify that the targeter insets are updated. |
| 220 shelf_layout_manager->SetAlignment(SHELF_ALIGNMENT_LEFT); | 222 shelf_layout_manager->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 221 shelf_layout_manager->LayoutShelf(); | 223 shelf_layout_manager->LayoutShelf(); |
| 222 shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); | 224 shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); |
| 223 { | 225 { |
| 224 // Create a mouse-event targeting the right edge of the shelf widget. The | 226 // Create a mouse-event targeting the right edge of the shelf widget. The |
| 225 // window-targeter should find |widget| as the target (instead of the | 227 // window-targeter should find |widget| as the target (instead of the |
| 226 // shelf). | 228 // shelf). |
| 227 gfx::Point event_location(shelf_bounds.right() - 1, widget_bounds.y() + 5); | 229 gfx::Point event_location(shelf_bounds.right() - 1, widget_bounds.y() + 5); |
| 228 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 230 ui::MouseEvent mouse( |
| 229 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 231 ui::ET_MOUSE_MOVED, event_location, event_location, |
| 232 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 233 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 230 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 234 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
| 231 EXPECT_EQ(widget->GetNativeWindow(), target); | 235 EXPECT_EQ(widget->GetNativeWindow(), target); |
| 232 } | 236 } |
| 233 | 237 |
| 234 // Now restore shelf alignment (bottom) and auto-hide (hidden) the shelf. | 238 // Now restore shelf alignment (bottom) and auto-hide (hidden) the shelf. |
| 235 shelf_layout_manager->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | 239 shelf_layout_manager->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| 236 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 240 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 237 shelf_layout_manager->LayoutShelf(); | 241 shelf_layout_manager->LayoutShelf(); |
| 238 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_layout_manager->visibility_state()); | 242 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_layout_manager->visibility_state()); |
| 239 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_layout_manager->auto_hide_state()); | 243 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_layout_manager->auto_hide_state()); |
| 240 shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); | 244 shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); |
| 241 EXPECT_TRUE(!shelf_bounds.IsEmpty()); | 245 EXPECT_TRUE(!shelf_bounds.IsEmpty()); |
| 242 | 246 |
| 243 // Move |widget| so it still overlaps the shelf. | 247 // Move |widget| so it still overlaps the shelf. |
| 244 widget->SetBounds(gfx::Rect(0, | 248 widget->SetBounds(gfx::Rect(0, |
| 245 shelf_bounds.y() - kWindowHeight + kOverlapSize, | 249 shelf_bounds.y() - kWindowHeight + kOverlapSize, |
| 246 kWindowWidth, kWindowHeight)); | 250 kWindowWidth, kWindowHeight)); |
| 247 widget_bounds = widget->GetWindowBoundsInScreen(); | 251 widget_bounds = widget->GetWindowBoundsInScreen(); |
| 248 EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds)); | 252 EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds)); |
| 249 { | 253 { |
| 250 // Create a mouse-event targeting the top of the shelf widget. This time, | 254 // Create a mouse-event targeting the top of the shelf widget. This time, |
| 251 // window-target should find the shelf as the target. | 255 // window-target should find the shelf as the target. |
| 252 gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1); | 256 gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1); |
| 253 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 257 ui::MouseEvent mouse( |
| 254 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 258 ui::ET_MOUSE_MOVED, event_location, event_location, |
| 259 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE, |
| 260 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 255 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 261 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
| 256 EXPECT_EQ(shelf_widget->GetNativeWindow(), target); | 262 EXPECT_EQ(shelf_widget->GetNativeWindow(), target); |
| 257 } | 263 } |
| 258 } | 264 } |
| 259 | 265 |
| 260 // Tests that the shelf has a slightly larger hit-region for touch-events when | 266 // Tests that the shelf has a slightly larger hit-region for touch-events when |
| 261 // it's in the auto-hidden state. | 267 // it's in the auto-hidden state. |
| 262 TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) { | 268 TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) { |
| 263 ShelfWidget* shelf_widget = GetShelfWidget(); | 269 ShelfWidget* shelf_widget = GetShelfWidget(); |
| 264 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); | 270 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 { | 308 { |
| 303 gfx::Point event_location(20, shelf_bounds.y() - 1); | 309 gfx::Point event_location(20, shelf_bounds.y() - 1); |
| 304 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0, | 310 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0, |
| 305 ui::EventTimeForNow()); | 311 ui::EventTimeForNow()); |
| 306 EXPECT_EQ(shelf_widget->GetNativeWindow(), | 312 EXPECT_EQ(shelf_widget->GetNativeWindow(), |
| 307 targeter->FindTargetForEvent(root, &touch)); | 313 targeter->FindTargetForEvent(root, &touch)); |
| 308 } | 314 } |
| 309 } | 315 } |
| 310 | 316 |
| 311 } // namespace ash | 317 } // namespace ash |
| OLD | NEW |