| Index: ui/events/event_processor_unittest.cc
|
| diff --git a/ui/events/event_processor_unittest.cc b/ui/events/event_processor_unittest.cc
|
| index 4bf4f0dff9122a4c426dfa067024042f6cd5637d..834f7b0c333a2d53822c80e8c76cc8c700d56405 100644
|
| --- a/ui/events/event_processor_unittest.cc
|
| +++ b/ui/events/event_processor_unittest.cc
|
| @@ -63,116 +63,6 @@ TEST_F(EventProcessorTest, Basic) {
|
| EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
|
| }
|
|
|
| -template<typename T>
|
| -class BoundsEventTargeter : public EventTargeter {
|
| - public:
|
| - ~BoundsEventTargeter() override {}
|
| -
|
| - protected:
|
| - bool SubtreeShouldBeExploredForEvent(
|
| - EventTarget* target, const LocatedEvent& event) override {
|
| - T* t = static_cast<T*>(target);
|
| - return (t->bounds().Contains(event.location()));
|
| - }
|
| -};
|
| -
|
| -class BoundsTestTarget : public TestEventTarget {
|
| - public:
|
| - BoundsTestTarget() {}
|
| - ~BoundsTestTarget() override {}
|
| -
|
| - void set_bounds(gfx::Rect rect) { bounds_ = rect; }
|
| - gfx::Rect bounds() const { return bounds_; }
|
| -
|
| - static void ConvertPointToTarget(BoundsTestTarget* source,
|
| - BoundsTestTarget* target,
|
| - gfx::Point* location) {
|
| - gfx::Vector2d vector;
|
| - if (source->Contains(target)) {
|
| - for (; target && target != source;
|
| - target = static_cast<BoundsTestTarget*>(target->parent())) {
|
| - vector += target->bounds().OffsetFromOrigin();
|
| - }
|
| - *location -= vector;
|
| - } else if (target->Contains(source)) {
|
| - for (; source && source != target;
|
| - source = static_cast<BoundsTestTarget*>(source->parent())) {
|
| - vector += source->bounds().OffsetFromOrigin();
|
| - }
|
| - *location += vector;
|
| - } else {
|
| - NOTREACHED();
|
| - }
|
| - }
|
| -
|
| - private:
|
| - // EventTarget:
|
| - void ConvertEventToTarget(EventTarget* target, LocatedEvent* event) override {
|
| - event->ConvertLocationToTarget(this,
|
| - static_cast<BoundsTestTarget*>(target));
|
| - }
|
| -
|
| - gfx::Rect bounds_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(BoundsTestTarget);
|
| -};
|
| -
|
| -TEST_F(EventProcessorTest, Bounds) {
|
| - scoped_ptr<BoundsTestTarget> parent(new BoundsTestTarget());
|
| - scoped_ptr<BoundsTestTarget> child(new BoundsTestTarget());
|
| - scoped_ptr<BoundsTestTarget> grandchild(new BoundsTestTarget());
|
| -
|
| - parent->set_bounds(gfx::Rect(0, 0, 30, 30));
|
| - child->set_bounds(gfx::Rect(5, 5, 20, 20));
|
| - grandchild->set_bounds(gfx::Rect(5, 5, 5, 5));
|
| -
|
| - child->AddChild(scoped_ptr<TestEventTarget>(grandchild.Pass()));
|
| - parent->AddChild(scoped_ptr<TestEventTarget>(child.Pass()));
|
| - root()->AddChild(scoped_ptr<TestEventTarget>(parent.Pass()));
|
| -
|
| - ASSERT_EQ(1u, root()->child_count());
|
| - ASSERT_EQ(1u, root()->child_at(0)->child_count());
|
| - ASSERT_EQ(1u, root()->child_at(0)->child_at(0)->child_count());
|
| -
|
| - TestEventTarget* parent_r = root()->child_at(0);
|
| - TestEventTarget* child_r = parent_r->child_at(0);
|
| - TestEventTarget* grandchild_r = child_r->child_at(0);
|
| -
|
| - // Dispatch a mouse event that falls on the parent, but not on the child. When
|
| - // the default event-targeter used, the event will still reach |grandchild|,
|
| - // because the default targeter does not look at the bounds.
|
| - MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(1, 1), gfx::Point(1, 1),
|
| - EventTimeForNow(), EF_NONE, EF_NONE);
|
| - DispatchEvent(&mouse);
|
| - EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - grandchild_r->ResetReceivedEvents();
|
| -
|
| - // Now install a targeter on the parent that looks at the bounds and makes
|
| - // sure the event reaches the target only if the location of the event within
|
| - // the bounds of the target.
|
| - MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(1, 1), gfx::Point(1, 1),
|
| - EventTimeForNow(), EF_NONE, EF_NONE);
|
| - parent_r->SetEventTargeter(scoped_ptr<EventTargeter>(
|
| - new BoundsEventTargeter<BoundsTestTarget>()));
|
| - DispatchEvent(&mouse2);
|
| - EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_TRUE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_FALSE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - parent_r->ResetReceivedEvents();
|
| -
|
| - MouseEvent second(ET_MOUSE_MOVED, gfx::Point(12, 12), gfx::Point(12, 12),
|
| - EventTimeForNow(), EF_NONE, EF_NONE);
|
| - DispatchEvent(&second);
|
| - EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED));
|
| -}
|
| -
|
| // ReDispatchEventHandler is used to receive mouse events and forward them
|
| // to a specified EventProcessor. Verifies that the event has the correct
|
| // target and phase both before and after the nested event processing. Also
|
| @@ -319,43 +209,6 @@ TEST_F(EventProcessorTest, OnEventProcessingStarted) {
|
| EXPECT_EQ(1, processor()->num_times_processing_finished());
|
| }
|
|
|
| -class IgnoreEventTargeter : public EventTargeter {
|
| - public:
|
| - IgnoreEventTargeter() {}
|
| - ~IgnoreEventTargeter() override {}
|
| -
|
| - private:
|
| - // EventTargeter:
|
| - bool SubtreeShouldBeExploredForEvent(EventTarget* target,
|
| - const LocatedEvent& event) override {
|
| - return false;
|
| - }
|
| -};
|
| -
|
| -// Verifies that the EventTargeter installed on an EventTarget can dictate
|
| -// whether the target itself can process an event.
|
| -TEST_F(EventProcessorTest, TargeterChecksOwningEventTarget) {
|
| - scoped_ptr<TestEventTarget> child(new TestEventTarget());
|
| - root()->AddChild(child.Pass());
|
| -
|
| - MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10),
|
| - EventTimeForNow(), EF_NONE, EF_NONE);
|
| - DispatchEvent(&mouse);
|
| - EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - root()->child_at(0)->ResetReceivedEvents();
|
| -
|
| - // Install an event handler on |child| which always prevents the target from
|
| - // receiving event.
|
| - root()->child_at(0)->SetEventTargeter(
|
| - scoped_ptr<EventTargeter>(new IgnoreEventTargeter()));
|
| - MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10),
|
| - EventTimeForNow(), EF_NONE, EF_NONE);
|
| - DispatchEvent(&mouse2);
|
| - EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
|
| - EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
|
| -}
|
| -
|
| // An EventTargeter which is used to allow a bubbling behaviour in event
|
| // dispatch: if an event is not handled after being dispatched to its
|
| // initial target, the event is dispatched to the next-best target as
|
|
|