Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_native_widget_aura_unittest.cc

Issue 1372253002: gfx: Make conversions from gfx::Point to PointF explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pointfconvert-gfx: . Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "ui/aura/client/aura_constants.h" 8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/client/cursor_client.h" 9 #include "ui/aura/client/cursor_client.h"
10 #include "ui/aura/client/window_tree_client.h" 10 #include "ui/aura/client/window_tree_client.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 444
445 // The following code verifies we can correctly destroy a Widget from a mouse 445 // The following code verifies we can correctly destroy a Widget from a mouse
446 // enter/exit. We could test move/drag/enter/exit but in general we don't run 446 // enter/exit. We could test move/drag/enter/exit but in general we don't run
447 // nested message loops from such events, nor has the code ever really dealt 447 // nested message loops from such events, nor has the code ever really dealt
448 // with this situation. 448 // with this situation.
449 449
450 // Generates two moves (first generates enter, second real move), a press, drag 450 // Generates two moves (first generates enter, second real move), a press, drag
451 // and release stopping at |last_event_type|. 451 // and release stopping at |last_event_type|.
452 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { 452 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) {
453 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); 453 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen());
454 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), 454 auto screen_center = gfx::PointF(screen_bounds.CenterPoint());
455 screen_bounds.CenterPoint(), ui::EventTimeForNow(), 455 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_center, screen_center,
456 0, 0); 456 ui::EventTimeForNow(), 0, 0);
457 ui::EventProcessor* dispatcher = WidgetTest::GetEventProcessor(widget); 457 ui::EventProcessor* dispatcher = WidgetTest::GetEventProcessor(widget);
458 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event); 458 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event);
459 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) 459 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed)
460 return; 460 return;
461 details = dispatcher->OnEventFromSource(&move_event); 461 details = dispatcher->OnEventFromSource(&move_event);
462 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed) 462 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed)
463 return; 463 return;
464 464
465 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), 465 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_center, screen_center,
466 screen_bounds.CenterPoint(), ui::EventTimeForNow(), 466 ui::EventTimeForNow(), 0, 0);
467 0, 0);
468 details = dispatcher->OnEventFromSource(&press_event); 467 details = dispatcher->OnEventFromSource(&press_event);
469 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed) 468 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed)
470 return; 469 return;
471 470
472 gfx::Point end_point(screen_bounds.CenterPoint()); 471 auto end_point = gfx::PointF(screen_bounds.CenterPoint());
473 end_point.Offset(1, 1); 472 end_point.Offset(1.f, 1.f);
474 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, 473 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point,
475 ui::EventTimeForNow(), 0, 0); 474 ui::EventTimeForNow(), 0, 0);
476 details = dispatcher->OnEventFromSource(&drag_event); 475 details = dispatcher->OnEventFromSource(&drag_event);
477 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed) 476 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed)
478 return; 477 return;
479 478
480 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, 479 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point,
481 ui::EventTimeForNow(), 0, 0); 480 ui::EventTimeForNow(), 0, 0);
482 details = dispatcher->OnEventFromSource(&release_event); 481 details = dispatcher->OnEventFromSource(&release_event);
483 if (details.dispatcher_destroyed) 482 if (details.dispatcher_destroyed)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 new PlatformDesktopNativeWidget(&top_level_widget); 536 new PlatformDesktopNativeWidget(&top_level_widget);
538 top_level_widget.Init(init_params); 537 top_level_widget.Init(init_params);
539 top_level_widget.Show(); 538 top_level_widget.Show();
540 EXPECT_TRUE(top_level_widget.IsVisible()); 539 EXPECT_TRUE(top_level_widget.IsVisible());
541 540
542 // Create a view and validate that a mouse moves makes it to the view. 541 // Create a view and validate that a mouse moves makes it to the view.
543 EventCountView* widget_view = new EventCountView(); 542 EventCountView* widget_view = new EventCountView();
544 widget_view->SetBounds(0, 0, 10, 10); 543 widget_view->SetBounds(0, 0, 10, 10);
545 top_level_widget.GetRootView()->AddChildView(widget_view); 544 top_level_widget.GetRootView()->AddChildView(widget_view);
546 545
547 gfx::Point cursor_location_main(5, 5); 546 gfx::PointF cursor_location_main(5.f, 5.f);
548 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, cursor_location_main, 547 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, cursor_location_main,
549 cursor_location_main, ui::EventTimeForNow(), 548 cursor_location_main, ui::EventTimeForNow(),
550 ui::EF_NONE, ui::EF_NONE); 549 ui::EF_NONE, ui::EF_NONE);
551 ui::EventDispatchDetails details = 550 ui::EventDispatchDetails details =
552 GetEventProcessor(&top_level_widget)->OnEventFromSource(&move_main); 551 GetEventProcessor(&top_level_widget)->OnEventFromSource(&move_main);
553 ASSERT_FALSE(details.dispatcher_destroyed); 552 ASSERT_FALSE(details.dispatcher_destroyed);
554 553
555 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); 554 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED));
556 widget_view->ResetCounts(); 555 widget_view->ResetCounts();
557 556
558 // Create a modal dialog and validate that a mouse down message makes it to 557 // Create a modal dialog and validate that a mouse down message makes it to
559 // the main view within the dialog. 558 // the main view within the dialog.
560 559
561 // This instance will be destroyed when the dialog is destroyed. 560 // This instance will be destroyed when the dialog is destroyed.
562 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; 561 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate;
563 562
564 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( 563 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
565 dialog_delegate, NULL, top_level_widget.GetNativeView()); 564 dialog_delegate, NULL, top_level_widget.GetNativeView());
566 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); 565 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
567 EventCountView* dialog_widget_view = new EventCountView(); 566 EventCountView* dialog_widget_view = new EventCountView();
568 dialog_widget_view->SetBounds(0, 0, 50, 50); 567 dialog_widget_view->SetBounds(0, 0, 50, 50);
569 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); 568 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view);
570 modal_dialog_widget->Show(); 569 modal_dialog_widget->Show();
571 EXPECT_TRUE(modal_dialog_widget->IsVisible()); 570 EXPECT_TRUE(modal_dialog_widget->IsVisible());
572 571
573 gfx::Point cursor_location_dialog(100, 100); 572 gfx::PointF cursor_location_dialog(100.f, 100.f);
574 ui::MouseEvent mouse_down_dialog( 573 ui::MouseEvent mouse_down_dialog(
575 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog, 574 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog,
576 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 575 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
577 details = GetEventProcessor(&top_level_widget)->OnEventFromSource( 576 details = GetEventProcessor(&top_level_widget)->OnEventFromSource(
578 &mouse_down_dialog); 577 &mouse_down_dialog);
579 ASSERT_FALSE(details.dispatcher_destroyed); 578 ASSERT_FALSE(details.dispatcher_destroyed);
580 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); 579 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED));
581 580
582 // Send a mouse move message to the main window. It should not be received by 581 // Send a mouse move message to the main window. It should not be received by
583 // the main window as the modal dialog is still active. 582 // the main window as the modal dialog is still active.
584 gfx::Point cursor_location_main2(6, 6); 583 gfx::PointF cursor_location_main2(6.f, 6.f);
585 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, cursor_location_main2, 584 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, cursor_location_main2,
586 cursor_location_main2, ui::EventTimeForNow(), 585 cursor_location_main2, ui::EventTimeForNow(),
587 ui::EF_NONE, ui::EF_NONE); 586 ui::EF_NONE, ui::EF_NONE);
588 details = GetEventProcessor(&top_level_widget)->OnEventFromSource( 587 details = GetEventProcessor(&top_level_widget)->OnEventFromSource(
589 &mouse_down_main); 588 &mouse_down_main);
590 ASSERT_FALSE(details.dispatcher_destroyed); 589 ASSERT_FALSE(details.dispatcher_destroyed);
591 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); 590 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED));
592 591
593 modal_dialog_widget->CloseNow(); 592 modal_dialog_widget->CloseNow();
594 top_level_widget.CloseNow(); 593 top_level_widget.CloseNow();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 reinterpret_cast<WPARAM>(win32_window), 626 reinterpret_cast<WPARAM>(win32_window),
628 MAKELPARAM(WM_LBUTTONDOWN, HTCLIENT)); 627 MAKELPARAM(WM_LBUTTONDOWN, HTCLIENT));
629 EXPECT_EQ(activate_result, MA_ACTIVATE); 628 EXPECT_EQ(activate_result, MA_ACTIVATE);
630 629
631 modal_dialog_widget->CloseNow(); 630 modal_dialog_widget->CloseNow();
632 } 631 }
633 #endif // defined(OS_WIN) 632 #endif // defined(OS_WIN)
634 633
635 } // namespace test 634 } // namespace test
636 } // namespace views 635 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698