ui/views/view_targeter_unittest.cc
TEST_F(ViewTargeterTest, ViewTargeterForScrollEvents) {
  Widget widget;
  Widget::InitParams init_params =
      CreateParams(Widget::InitParams::TYPE_POPUP);
  init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
  init_params.bounds = gfx::Rect(0, 0, 200, 200);
  widget.Init(init_params);

  // The coordinates used for SetBounds() are in the parent coordinate space.
  View* content = new View;
  content->SetBounds(0, 0, 100, 100);
  View* child = new View;
  child->SetBounds(50, 50, 20, 20);
  View* grandchild = new View;
  grandchild->SetBounds(0, 0, 5, 5);

  widget.SetContentsView(content);
  content->AddChildView(child);
  child->AddChildView(grandchild);

  internal::RootView* root_view =
      static_cast<internal::RootView*>(widget.GetRootView());
  ViewTargeter* view_targeter = new ViewTargeter(root_view);
  ui::EventTargeter* targeter = view_targeter;
  root_view->SetEventTargeter(make_scoped_ptr(view_targeter));

  // The event falls within the bounds of |child| and |content| but not
  // |grandchild|, so |child| should be the initial target for the event.
  ui::ScrollEvent scroll(ui::ET_SCROLL,
                         gfx::Point(60, 60),
                         ui::EventTimeForNow(),
                         0,
                         0, 3,
                         0, 3,
                         2);
  ui::EventTarget* current_target = targeter->FindTargetForEvent(root_view,
                                                                 &scroll);
  EXPECT_EQ(child, static_cast<View*>(current_target));

  // Verify that FindNextBestTarget() will return the parent view of the
  // argument (and NULL if the argument has no parent view).
  current_target = targeter->FindNextBestTarget(child, &scroll);
  EXPECT_EQ(content, static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(content, &scroll);
  EXPECT_EQ(widget.GetRootView(), static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(widget.GetRootView(),
                                                &scroll);
  EXPECT_EQ(NULL, static_cast<View*>(current_target));

  // The event falls outside of the original specified bounds of |content|,
  // |child|, and |grandchild|. But since |content| is the contents view,
  // and contents views are resized to fill the entire area of the root
  // view, the event's initial target should still be |content|.
  scroll = ui::ScrollEvent(ui::ET_SCROLL,
                           gfx::Point(150, 150),
                           ui::EventTimeForNow(),
                           0,
                           0, 3,
                           0, 3,
                           2);
  current_target = targeter->FindTargetForEvent(root_view, &scroll);
  EXPECT_EQ(content, static_cast<View*>(current_target));
}
// Verifies that the the functions ViewTargeter::FindTargetForEvent()
// and ViewTargeter::FindNextBestTarget() are implemented correctly
// for scroll events.
Verifies that the the functions ViewTargeter::FindTargetForEvent()
and ViewTargeter::FindNextBestTarget() are implemented correctly
for scroll events.
Verifies that the the functions ViewTargeter :: FindTargetForEvent () and ViewTargeter :: FindNextBestTarget () are implemented correctly for scroll events .
TEST_F(ViewTargeterTest, ViewTargeterForScrollEvents) {
  Widget widget;
  Widget::InitParams init_params =
      CreateParams(Widget::InitParams::TYPE_POPUP);
  init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
  init_params.bounds = gfx::Rect(0, 0, 200, 200);
  widget.Init(init_params);
  View* content = new View;
  content->SetBounds(0, 0, 100, 100);
  View* child = new View;
  child->SetBounds(50, 50, 20, 20);
  View* grandchild = new View;
  grandchild->SetBounds(0, 0, 5, 5);
  widget.SetContentsView(content);
  content->AddChildView(child);
  child->AddChildView(grandchild);
  internal::RootView* root_view =
      static_cast<internal::RootView*>(widget.GetRootView());
  ViewTargeter* view_targeter = new ViewTargeter(root_view);
  ui::EventTargeter* targeter = view_targeter;
  root_view->SetEventTargeter(make_scoped_ptr(view_targeter));
  ui::ScrollEvent scroll(ui::ET_SCROLL,
                         gfx::Point(60, 60),
                         ui::EventTimeForNow(),
                         0,
                         0, 3,
                         0, 3,
                         2);
  ui::EventTarget* current_target = targeter->FindTargetForEvent(root_view,
                                                                 &scroll);
  EXPECT_EQ(child, static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(child, &scroll);
  EXPECT_EQ(content, static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(content, &scroll);
  EXPECT_EQ(widget.GetRootView(), static_cast<View*>(current_target));
  current_target = targeter->FindNextBestTarget(widget.GetRootView(),
                                                &scroll);
  EXPECT_EQ(NULL, static_cast<View*>(current_target));
  scroll = ui::ScrollEvent(ui::ET_SCROLL,
                           gfx::Point(150, 150),
                           ui::EventTimeForNow(),
                           0,
                           0, 3,
                           0, 3,
                           2);
  current_target = targeter->FindTargetForEvent(root_view, &scroll);
  EXPECT_EQ(content, static_cast<View*>(current_target));
}
TEST_F ( ViewTargeterTest , ViewTargeterForScrollEvents ) { Widget widget ; Widget :: InitParams init_params = CreateParams ( Widget :: InitParams :: TYPE_POPUP ) ; init_params . ownership = Widget :: InitParams :: WIDGET_OWNS_NATIVE_WIDGET ; init_params . bounds = gfx :: Rect ( 0 , 0 , 200 , 200 ) ; widget . Init ( init_params ) ; View * content = new View ; content -> SetBounds ( 0 , 0 , 100 , 100 ) ; View * child = new View ; child -> SetBounds ( 50 , 50 , 20 , 20 ) ; View * grandchild = new View ; grandchild -> SetBounds ( 0 , 0 , 5 , 5 ) ; widget . SetContentsView ( content ) ; content -> AddChildView ( child ) ; child -> AddChildView ( grandchild ) ; internal :: RootView * root_view = static_cast < internal :: RootView * > ( widget . GetRootView ( ) ) ; ViewTargeter * view_targeter = new ViewTargeter ( root_view ) ; ui :: EventTargeter * targeter = view_targeter ; root_view -> SetEventTargeter ( make_scoped_ptr ( view_targeter ) ) ; ui :: ScrollEvent scroll ( ui :: ET_SCROLL , gfx :: Point ( 60 , 60 ) , ui :: EventTimeForNow ( ) , 0 , 0 , 3 , 0 , 3 , 2 ) ; ui :: EventTarget * current_target = targeter -> FindTargetForEvent ( root_view , & scroll ) ; EXPECT_EQ ( child , static_cast < View * > ( current_target ) ) ; current_target = targeter -> FindNextBestTarget ( child , & scroll ) ; EXPECT_EQ ( content , static_cast < View * > ( current_target ) ) ; current_target = targeter -> FindNextBestTarget ( content , & scroll ) ; EXPECT_EQ ( widget . GetRootView ( ) , static_cast < View * > ( current_target ) ) ; current_target = targeter -> FindNextBestTarget ( widget . GetRootView ( ) , & scroll ) ; EXPECT_EQ ( NULL , static_cast < View * > ( current_target ) ) ; scroll = ui :: ScrollEvent ( ui :: ET_SCROLL , gfx :: Point ( 150 , 150 ) , ui :: EventTimeForNow ( ) , 0 , 0 , 3 , 0 , 3 , 2 ) ; current_target = targeter -> FindTargetForEvent ( root_view , & scroll ) ; EXPECT_EQ ( content , static_cast < View * > ( current_target ) ) ; }
Verifies that the the functions ViewTargeter::FindTargetForEvent()
and ViewTargeter::FindNextBestTarget() are implemented correctly
for scroll events.
Verifies that the the functions ViewTargeter :: FindTargetForEvent () and ViewTargeter :: FindNextBestTarget () are implemented correctly for scroll events .
// The coordinates used for SetBounds() are in the parent coordinate space. // The event falls within the bounds of |child| and |content| but not // |grandchild|, so |child| should be the initial target for the event. // Verify that FindNextBestTarget() will return the parent view of the // argument (and NULL if the argument has no parent view). // The event falls outside of the original specified bounds of |content|, // |child|, and |grandchild|. But since |content| is the contents view, // and contents views are resized to fill the entire area of the root // view, the event's initial target should still be |content|.