Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / views / widget / root_view_targeter.cc
blob3c4b9e21c40587d021e1e8c0a680d83684babf8c
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.
5 #include "ui/views/widget/root_view_targeter.h"
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"
13 namespace views {
15 RootViewTargeter::RootViewTargeter(ViewTargeterDelegate* delegate,
16 internal::RootView* root_view)
17 : ViewTargeter(delegate), root_view_(root_view) {
20 RootViewTargeter::~RootViewTargeter() {
23 View* RootViewTargeter::FindTargetForGestureEvent(
24 View* root,
25 const ui::GestureEvent& gesture) {
26 CHECK_EQ(root, root_view_);
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_;
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);
46 return root->GetEffectiveViewTargeter()->TargetForRect(root, rect);
49 ui::EventTarget* RootViewTargeter::FindNextBestTargetForGestureEvent(
50 ui::EventTarget* previous_target,
51 const ui::GestureEvent& gesture) {
52 // GESTURE_SCROLL_BEGIN events are always permitted to be re-targeted, even
53 // if |allow_gesture_event_retargeting_| is false.
54 if (!root_view_->allow_gesture_event_retargeting_ &&
55 gesture.type() != ui::ET_GESTURE_SCROLL_BEGIN) {
56 return NULL;
59 // 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
61 // 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
63 // permitted.
64 if (!root_view_->gesture_handler_)
65 return NULL;
67 return previous_target->GetParentTarget();
70 } // namespace views