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

Side by Side Diff: ui/views/widget/root_view_targeter.cc

Issue 481433006: Support targeting for gestures in ViewTargeter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Introduce RootViewTargeter 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/widget/root_view_targeter.h"
6
7 #include "ui/views/view.h"
8 #include "ui/views/view_targeter_delegate.h"
9 #include "ui/views/views_switches.h"
10 #include "ui/views/widget/root_view.h"
11 #include "ui/views/widget/widget.h"
12
13 namespace views {
14
15 RootViewTargeter::RootViewTargeter(ViewTargeterDelegate* delegate,
16 internal::RootView* root_view)
17 : ViewTargeter(delegate), root_view_(root_view) {
18 }
19
20 RootViewTargeter::~RootViewTargeter() {
21 }
22
23 View* RootViewTargeter::FindTargetForGestureEvent(
24 View* root,
25 const ui::GestureEvent& gesture) {
26 CHECK_EQ(root, root_view_);
27
28 // Return the default gesture handler if one is already set.
29 if (root_view_->gesture_handler_) {
30 CHECK(!root_view_->allow_gesture_event_retargeting_);
31 return root_view_->gesture_handler_;
32 }
33
34 // 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
36 // bounding box to determine the target.
37 gfx::Rect rect(gesture.location(), gfx::Size(1, 1));
38 if (views::switches::IsRectBasedTargetingEnabled() &&
39 !gesture.details().bounding_box().IsEmpty()) {
40 // TODO(tdanderson): Pass in the bounding box to GetEventHandlerForRect()
41 // once crbug.com/313392 is resolved.
42 rect = gfx::Rect(gesture.details().bounding_box());
43 rect.set_origin(gesture.location());
sadrul 2014/08/27 22:49:54 You could do: rect = gfx::Rect(gesture.location(
tdanderson 2014/08/27 23:25:57 Did you mean .bounding_box().size()? I eliminated
44 rect.Offset(-rect.width() / 2, -rect.height() / 2);
45 }
46
47 return root->GetEffectiveViewTargeter()->TargetForRect(root, rect);
48 }
49
50 ui::EventTarget* RootViewTargeter::FindNextBestTargetForGestureEvent(
51 ui::EventTarget* previous_target,
52 const ui::GestureEvent& gesture) {
53 // GESTURE_SCROLL_BEGIN events are always permitted to be re-targeted, even
54 // if |allow_gesture_event_retargeting_| is false.
55 if (!root_view_->allow_gesture_event_retargeting_ &&
56 gesture.type() != ui::ET_GESTURE_SCROLL_BEGIN) {
57 return NULL;
58 }
59
60 // If |gesture_handler_| is NULL, it is either because the view was removed
61 // from the tree by the previous dispatch of |gesture| or because |gesture| is
62 // the GESTURE_END event corresponding to the removal of the last touch
63 // point. In either case, no further re-targeting of |gesture| should be
64 // permitted.
65 if (!root_view_->gesture_handler_)
66 return NULL;
67
68 return previous_target->GetParentTarget();
69 }
70
71 } // namespace views
OLDNEW
« ui/views/view_targeter.cc ('K') | « ui/views/widget/root_view_targeter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698