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

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

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 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/widget/root_view_targeter.h ('k') | ui/views/widget/root_view_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
(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_->gesture_handler_set_before_processing_);
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.set_size(gesture.details().bounding_box().size());
43 rect.Offset(-rect.width() / 2, -rect.height() / 2);
44 }
45
46 return root->GetEffectiveViewTargeter()->TargetForRect(root, rect);
47 }
48
49 ui::EventTarget* RootViewTargeter::FindNextBestTargetForGestureEvent(
50 ui::EventTarget* previous_target,
51 const ui::GestureEvent& gesture) {
52 // ET_GESTURE_END events should only ever be targeted to the default
53 // gesture handler set by a previous gesture, if one exists. Thus we do not
54 // permit any re-targeting of ET_GESTURE_END events.
55 if (gesture.type() == ui::ET_GESTURE_END)
56 return NULL;
57
58 // Prohibit re-targeting of gesture events (except for GESTURE_SCROLL_BEGIN
59 // events) if the default gesture handler was set by the dispatch of a
60 // previous gesture event.
61 if (root_view_->gesture_handler_set_before_processing_ &&
62 gesture.type() != ui::ET_GESTURE_SCROLL_BEGIN) {
63 return NULL;
64 }
65
66 // If |gesture_handler_| is NULL, it is either because the view was removed
67 // from the tree by the previous dispatch of |gesture| or because |gesture| is
68 // the GESTURE_END event corresponding to the removal of the last touch
69 // point. In either case, no further re-targeting of |gesture| should be
70 // permitted.
71 if (!root_view_->gesture_handler_)
72 return NULL;
73
74 return previous_target->GetParentTarget();
75 }
76
77 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view_targeter.h ('k') | ui/views/widget/root_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698