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

Side by Side Diff: ui/views/view_targeter_unittest.cc

Issue 533793002: Only target ui::ET_GESTURE_END to the default gesture handler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | ui/views/widget/root_view_targeter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/view_targeter.h" 5 #include "ui/views/view_targeter.h"
6 6
7 #include "ui/events/event_targeter.h" 7 #include "ui/events/event_targeter.h"
8 #include "ui/events/event_utils.h" 8 #include "ui/events/event_utils.h"
9 #include "ui/gfx/path.h" 9 #include "ui/gfx/path.h"
10 #include "ui/views/masked_targeter_delegate.h" 10 #include "ui/views/masked_targeter_delegate.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 grandchild->SetBounds(0, 0, 5, 5); 256 grandchild->SetBounds(0, 0, 5, 5);
257 257
258 widget.SetContentsView(content); 258 widget.SetContentsView(content);
259 content->AddChildView(child); 259 content->AddChildView(child);
260 child->AddChildView(grandchild); 260 child->AddChildView(grandchild);
261 261
262 internal::RootView* root_view = 262 internal::RootView* root_view =
263 static_cast<internal::RootView*>(widget.GetRootView()); 263 static_cast<internal::RootView*>(widget.GetRootView());
264 ui::EventTargeter* targeter = root_view->targeter(); 264 ui::EventTargeter* targeter = root_view->targeter();
265 265
266 // Define a GESTURE_TAP and a GESTURE_SCROLL_BEGIN. 266 // Define some gesture events for testing.
267 gfx::Rect bounding_box(gfx::Point(46, 46), gfx::Size(8, 8)); 267 gfx::Rect bounding_box(gfx::Point(46, 46), gfx::Size(8, 8));
268 gfx::Point center_point(bounding_box.CenterPoint()); 268 gfx::Point center_point(bounding_box.CenterPoint());
269 ui::GestureEventDetails details(ui::ET_GESTURE_TAP, 0.0f, 0.0f); 269 ui::GestureEventDetails details(ui::ET_GESTURE_TAP, 0.0f, 0.0f);
270 details.set_bounding_box(bounding_box); 270 details.set_bounding_box(bounding_box);
271 GestureEventForTest tap(details, center_point.x(), center_point.y()); 271 GestureEventForTest tap(details, center_point.x(), center_point.y());
272 details = ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0.0f, 0.0f); 272 details = ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0.0f, 0.0f);
273 details.set_bounding_box(bounding_box); 273 details.set_bounding_box(bounding_box);
274 GestureEventForTest scroll_begin(details, center_point.x(), center_point.y()); 274 GestureEventForTest scroll_begin(details, center_point.x(), center_point.y());
275 details = ui::GestureEventDetails(ui::ET_GESTURE_END, 0.0f, 0.0f);
276 details.set_bounding_box(bounding_box);
277 GestureEventForTest end(details, center_point.x(), center_point.y());
275 278
276 // Assume that the view currently handling gestures has been set as 279 // Assume that the view currently handling gestures has been set as
277 // |grandchild| by a previous gesture event. Thus subsequent gesture events 280 // |grandchild| by a previous gesture event. Thus subsequent TAP and
278 // should be initially targeted to |grandchild|, and re-targeting should 281 // SCROLL_BEGIN events should be initially targeted to |grandchild|, and
279 // be prohibited for all gesture event types except for GESTURE_SCROLL_BEGIN 282 // re-targeting should be prohibited for TAP but permitted for
280 // (which should be re-targeted to the parent of |grandchild|). 283 // GESTURE_SCROLL_BEGIN (which should be re-targeted to the parent of
284 // |grandchild|).
281 SetAllowGestureEventRetargeting(root_view, false); 285 SetAllowGestureEventRetargeting(root_view, false);
282 SetGestureHandler(root_view, grandchild); 286 SetGestureHandler(root_view, grandchild);
283 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &tap)); 287 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &tap));
284 EXPECT_EQ(NULL, targeter->FindNextBestTarget(grandchild, &tap)); 288 EXPECT_EQ(NULL, targeter->FindNextBestTarget(grandchild, &tap));
285 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &scroll_begin)); 289 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &scroll_begin));
286 EXPECT_EQ(child, targeter->FindNextBestTarget(grandchild, &scroll_begin)); 290 EXPECT_EQ(child, targeter->FindNextBestTarget(grandchild, &scroll_begin));
287 291
292 // GESTURE_END events should be targeted to the existing gesture handler,
293 // but re-targeting should be prohibited.
294 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &end));
295 EXPECT_EQ(NULL, targeter->FindNextBestTarget(grandchild, &tap));
296
288 // Assume that the view currently handling gestures is still set as 297 // Assume that the view currently handling gestures is still set as
289 // |grandchild|, but this was not done by a previous gesture. Thus we are 298 // |grandchild|, but this was not done by a previous gesture. Thus we are
290 // in the process of finding the View to which subsequent gestures will be 299 // in the process of finding the View to which subsequent gestures will be
291 // dispatched, so all gesture events should be re-targeted up the ancestor 300 // dispatched, so TAP and SCROLL_BEGIN events should be re-targeted up
292 // chain. 301 // the ancestor chain.
293 SetAllowGestureEventRetargeting(root_view, true); 302 SetAllowGestureEventRetargeting(root_view, true);
294 EXPECT_EQ(child, targeter->FindNextBestTarget(grandchild, &tap)); 303 EXPECT_EQ(child, targeter->FindNextBestTarget(grandchild, &tap));
295 EXPECT_EQ(child, targeter->FindNextBestTarget(grandchild, &scroll_begin)); 304 EXPECT_EQ(child, targeter->FindNextBestTarget(grandchild, &scroll_begin));
296 305
306 // GESTURE_END events are not permitted to be re-targeted up the ancestor
307 // chain; they are only ever targeted in the case where the gesture handler
308 // was established by a previous gesture.
309 EXPECT_EQ(NULL, targeter->FindNextBestTarget(grandchild, &end));
310
297 // Assume that the default gesture handler was set by the previous gesture, 311 // Assume that the default gesture handler was set by the previous gesture,
298 // but that this handler is currently NULL. No gesture events should be 312 // but that this handler is currently NULL. No gesture events should be
299 // re-targeted in this case (regardless of the view that is passed in to 313 // re-targeted in this case (regardless of the view that is passed in to
300 // FindNextBestTarget() as the previous target). 314 // FindNextBestTarget() as the previous target).
301 SetGestureHandler(root_view, NULL); 315 SetGestureHandler(root_view, NULL);
302 SetAllowGestureEventRetargeting(root_view, false); 316 SetAllowGestureEventRetargeting(root_view, false);
303 EXPECT_EQ(NULL, targeter->FindNextBestTarget(child, &tap)); 317 EXPECT_EQ(NULL, targeter->FindNextBestTarget(child, &tap));
304 EXPECT_EQ(NULL, targeter->FindNextBestTarget(NULL, &tap)); 318 EXPECT_EQ(NULL, targeter->FindNextBestTarget(NULL, &tap));
305 EXPECT_EQ(NULL, targeter->FindNextBestTarget(content, &scroll_begin)); 319 EXPECT_EQ(NULL, targeter->FindNextBestTarget(content, &scroll_begin));
320 EXPECT_EQ(NULL, targeter->FindNextBestTarget(content, &end));
306 321
307 // If no default gesture handler is currently set, targeting should be 322 // If no default gesture handler is currently set, targeting should be
308 // performed using the location of the gesture event. 323 // performed using the location of the gesture event for a TAP and a
324 // SCROLL_BEGIN.
309 SetAllowGestureEventRetargeting(root_view, true); 325 SetAllowGestureEventRetargeting(root_view, true);
310 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &tap)); 326 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &tap));
311 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &scroll_begin)); 327 EXPECT_EQ(grandchild, targeter->FindTargetForEvent(root_view, &scroll_begin));
328
329 // If no default gesture handler is currently set, GESTURE_END events
330 // should never be targeted or re-targeted to any View.
331 EXPECT_EQ(NULL, targeter->FindTargetForEvent(root_view, &end));
332 EXPECT_EQ(NULL, targeter->FindNextBestTarget(NULL, &end));
333 EXPECT_EQ(NULL, targeter->FindNextBestTarget(child, &end));
312 } 334 }
313 335
314 // Tests that the functions ViewTargeterDelegate::DoesIntersectRect() 336 // Tests that the functions ViewTargeterDelegate::DoesIntersectRect()
315 // and MaskedTargeterDelegate::DoesIntersectRect() work as intended when 337 // and MaskedTargeterDelegate::DoesIntersectRect() work as intended when
316 // called on views which are derived from ViewTargeterDelegate. 338 // called on views which are derived from ViewTargeterDelegate.
317 // Also verifies that ViewTargeterDelegate::DoesIntersectRect() can 339 // Also verifies that ViewTargeterDelegate::DoesIntersectRect() can
318 // be called from the ViewTargeter installed on RootView. 340 // be called from the ViewTargeter installed on RootView.
319 TEST_F(ViewTargeterTest, DoesIntersectRect) { 341 TEST_F(ViewTargeterTest, DoesIntersectRect) {
320 Widget widget; 342 Widget widget;
321 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 343 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin)); 461 EXPECT_EQ(v1, root_view->GetTooltipHandlerForPoint(v1_origin));
440 EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin)); 462 EXPECT_EQ(root_view, root_view->GetTooltipHandlerForPoint(v2_origin));
441 463
442 EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin)); 464 EXPECT_FALSE(v1->GetTooltipHandlerForPoint(v2_origin));
443 465
444 widget->CloseNow(); 466 widget->CloseNow();
445 } 467 }
446 468
447 } // namespace test 469 } // namespace test
448 } // namespace views 470 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/widget/root_view_targeter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698