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

Side by Side Diff: ui/views/widget/root_view_targeter.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 | « ui/views/view_targeter_unittest.cc ('k') | ui/views/widget/widget_unittest.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/widget/root_view_targeter.h" 5 #include "ui/views/widget/root_view_targeter.h"
6 6
7 #include "ui/views/view.h" 7 #include "ui/views/view.h"
8 #include "ui/views/view_targeter_delegate.h" 8 #include "ui/views/view_targeter_delegate.h"
9 #include "ui/views/views_switches.h" 9 #include "ui/views/views_switches.h"
10 #include "ui/views/widget/root_view.h" 10 #include "ui/views/widget/root_view.h"
(...skipping 13 matching lines...) Expand all
24 View* root, 24 View* root,
25 const ui::GestureEvent& gesture) { 25 const ui::GestureEvent& gesture) {
26 CHECK_EQ(root, root_view_); 26 CHECK_EQ(root, root_view_);
27 27
28 // Return the default gesture handler if one is already set. 28 // Return the default gesture handler if one is already set.
29 if (root_view_->gesture_handler_) { 29 if (root_view_->gesture_handler_) {
30 CHECK(!root_view_->allow_gesture_event_retargeting_); 30 CHECK(!root_view_->allow_gesture_event_retargeting_);
31 return root_view_->gesture_handler_; 31 return root_view_->gesture_handler_;
32 } 32 }
33 33
34 // If no default gesture handler has already been set, do not perform any
35 // targeting for a ET_GESTURE_END event.
36 if (gesture.type() == ui::ET_GESTURE_END)
37 return NULL;
38
34 // If rect-based targeting is enabled, use the gesture's bounding box to 39 // If rect-based targeting is enabled, use the gesture's bounding box to
35 // determine the target. Otherwise use the center point of the gesture's 40 // determine the target. Otherwise use the center point of the gesture's
36 // bounding box to determine the target. 41 // bounding box to determine the target.
37 gfx::Rect rect(gesture.location(), gfx::Size(1, 1)); 42 gfx::Rect rect(gesture.location(), gfx::Size(1, 1));
38 if (views::switches::IsRectBasedTargetingEnabled() && 43 if (views::switches::IsRectBasedTargetingEnabled() &&
39 !gesture.details().bounding_box().IsEmpty()) { 44 !gesture.details().bounding_box().IsEmpty()) {
40 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect() 45 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect()
41 // once crbug.com/313392 is resolved. 46 // once crbug.com/313392 is resolved.
42 rect.set_size(gesture.details().bounding_box().size()); 47 rect.set_size(gesture.details().bounding_box().size());
43 rect.Offset(-rect.width() / 2, -rect.height() / 2); 48 rect.Offset(-rect.width() / 2, -rect.height() / 2);
44 } 49 }
45 50
46 return root->GetEffectiveViewTargeter()->TargetForRect(root, rect); 51 return root->GetEffectiveViewTargeter()->TargetForRect(root, rect);
47 } 52 }
48 53
49 ui::EventTarget* RootViewTargeter::FindNextBestTargetForGestureEvent( 54 ui::EventTarget* RootViewTargeter::FindNextBestTargetForGestureEvent(
50 ui::EventTarget* previous_target, 55 ui::EventTarget* previous_target,
51 const ui::GestureEvent& gesture) { 56 const ui::GestureEvent& gesture) {
57 // ET_GESTURE_END events should only ever be targeted to the default
58 // gesture handler set by a previous gesture, if one exists. Thus we do not
59 // permit any re-targeting of ET_GESTURE_END events.
60 if (gesture.type() == ui::ET_GESTURE_END)
61 return NULL;
62
52 // GESTURE_SCROLL_BEGIN events are always permitted to be re-targeted, even 63 // GESTURE_SCROLL_BEGIN events are always permitted to be re-targeted, even
53 // if |allow_gesture_event_retargeting_| is false. 64 // if |allow_gesture_event_retargeting_| is false.
54 if (!root_view_->allow_gesture_event_retargeting_ && 65 if (!root_view_->allow_gesture_event_retargeting_ &&
55 gesture.type() != ui::ET_GESTURE_SCROLL_BEGIN) { 66 gesture.type() != ui::ET_GESTURE_SCROLL_BEGIN) {
56 return NULL; 67 return NULL;
57 } 68 }
58 69
59 // If |gesture_handler_| is NULL, it is either because the view was removed 70 // If |gesture_handler_| is NULL, it is either because the view was removed
60 // from the tree by the previous dispatch of |gesture| or because |gesture| is 71 // from the tree by the previous dispatch of |gesture| or because |gesture| is
61 // the GESTURE_END event corresponding to the removal of the last touch 72 // the GESTURE_END event corresponding to the removal of the last touch
62 // point. In either case, no further re-targeting of |gesture| should be 73 // point. In either case, no further re-targeting of |gesture| should be
63 // permitted. 74 // permitted.
64 if (!root_view_->gesture_handler_) 75 if (!root_view_->gesture_handler_)
65 return NULL; 76 return NULL;
66 77
67 return previous_target->GetParentTarget(); 78 return previous_target->GetParentTarget();
68 } 79 }
69 80
70 } // namespace views 81 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view_targeter_unittest.cc ('k') | ui/views/widget/widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698