Add ICU message format support
[chromium-blink-merge.git] / ui / views / widget / root_view_targeter.cc
blob6cc41f27449bd1d1ddc456d2f7e9b3c8de2043e2
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_->gesture_handler_set_before_processing_);
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 // 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;
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;
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;
74 return previous_target->GetParentTarget();
77 } // namespace views