Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / views / view_targeter.cc
blob3c5af01909eacd873c1a83b59f52de3af5b128e2
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 bool ViewTargeter::SubtreeCanAcceptEvent(
71 ui::EventTarget* target,
72 const ui::LocatedEvent& event) const {
73 NOTREACHED();
74 return false;
77 bool ViewTargeter::EventLocationInsideBounds(
78 ui::EventTarget* target,
79 const ui::LocatedEvent& event) const {
80 NOTREACHED();
81 return false;
84 View* ViewTargeter::FindTargetForKeyEvent(View* root, const ui::KeyEvent& key) {
85 if (root->GetFocusManager())
86 return root->GetFocusManager()->GetFocusedView();
87 return NULL;
90 View* ViewTargeter::FindTargetForScrollEvent(View* root,
91 const ui::ScrollEvent& scroll) {
92 gfx::Rect rect(scroll.location(), gfx::Size(1, 1));
93 return root->GetEffectiveViewTargeter()->TargetForRect(root, rect);
96 View* ViewTargeter::FindTargetForGestureEvent(View* root,
97 const ui::GestureEvent& gesture) {
98 // TODO(tdanderson): The only code path that performs targeting for gestures
99 // uses the ViewTargeter installed on the RootView (i.e.,
100 // a RootViewTargeter). Provide a default implementation
101 // here if we need to be able to perform gesture targeting
102 // starting at an arbitrary node in a Views tree.
103 NOTREACHED();
104 return NULL;
107 ui::EventTarget* ViewTargeter::FindNextBestTargetForGestureEvent(
108 ui::EventTarget* previous_target,
109 const ui::GestureEvent& gesture) {
110 NOTREACHED();
111 return NULL;
114 } // namespace views