Add ICU message format support
[chromium-blink-merge.git] / ui / views / view_targeter.cc
blob5e52ce9c2d665e45411ab333b1bb837c4bc3d951
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/view_targeter.h"
7 #include "ui/events/event_target.h"
8 #include "ui/views/focus/focus_manager.h"
9 #include "ui/views/view.h"
10 #include "ui/views/view_targeter_delegate.h"
12 namespace views {
14 ViewTargeter::ViewTargeter(ViewTargeterDelegate* delegate)
15 : delegate_(delegate) {
16 DCHECK(delegate_);
19 ViewTargeter::~ViewTargeter() {}
21 bool ViewTargeter::DoesIntersectRect(const View* target,
22 const gfx::Rect& rect) const {
23 return delegate_->DoesIntersectRect(target, rect);
26 View* ViewTargeter::TargetForRect(View* root, const gfx::Rect& rect) const {
27 return delegate_->TargetForRect(root, rect);
30 ui::EventTarget* ViewTargeter::FindTargetForEvent(ui::EventTarget* root,
31 ui::Event* event) {
32 View* view = static_cast<View*>(root);
34 if (event->IsKeyEvent())
35 return FindTargetForKeyEvent(view, *static_cast<ui::KeyEvent*>(event));
37 if (event->IsScrollEvent()) {
38 return FindTargetForScrollEvent(view,
39 *static_cast<ui::ScrollEvent*>(event));
42 if (event->IsGestureEvent()) {
43 ui::GestureEvent* gesture = event->AsGestureEvent();
44 View* gesture_target = FindTargetForGestureEvent(view, *gesture);
45 root->ConvertEventToTarget(gesture_target, gesture);
46 return gesture_target;
49 NOTREACHED() << "ViewTargeter does not yet support this event type.";
50 return NULL;
53 ui::EventTarget* ViewTargeter::FindNextBestTarget(
54 ui::EventTarget* previous_target,
55 ui::Event* event) {
56 if (!previous_target)
57 return NULL;
59 if (event->IsGestureEvent()) {
60 ui::GestureEvent* gesture = event->AsGestureEvent();
61 ui::EventTarget* next_target =
62 FindNextBestTargetForGestureEvent(previous_target, *gesture);
63 previous_target->ConvertEventToTarget(next_target, gesture);
64 return next_target;
67 return previous_target->GetParentTarget();
70 View* ViewTargeter::FindTargetForKeyEvent(View* root, const ui::KeyEvent& key) {
71 if (root->GetFocusManager())
72 return root->GetFocusManager()->GetFocusedView();
73 return NULL;
76 View* ViewTargeter::FindTargetForScrollEvent(View* root,
77 const ui::ScrollEvent& scroll) {
78 gfx::Rect rect(scroll.location(), gfx::Size(1, 1));
79 return root->GetEffectiveViewTargeter()->TargetForRect(root, rect);
82 View* ViewTargeter::FindTargetForGestureEvent(View* root,
83 const ui::GestureEvent& gesture) {
84 // TODO(tdanderson): The only code path that performs targeting for gestures
85 // uses the ViewTargeter installed on the RootView (i.e.,
86 // a RootViewTargeter). Provide a default implementation
87 // here if we need to be able to perform gesture targeting
88 // starting at an arbitrary node in a Views tree.
89 NOTREACHED();
90 return NULL;
93 ui::EventTarget* ViewTargeter::FindNextBestTargetForGestureEvent(
94 ui::EventTarget* previous_target,
95 const ui::GestureEvent& gesture) {
96 NOTREACHED();
97 return NULL;
100 } // namespace views