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

Side by Side Diff: services/window_manager/view_target.cc

Issue 1531403003: Delete the ViewManager and WindowManager services. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-3
Patch Set: rebase Created 4 years, 10 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 | « services/window_manager/view_target.h ('k') | services/window_manager/view_target_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 "services/window_manager/view_target.h"
6
7 #include "mojo/converters/geometry/geometry_type_converters.h"
8 #include "mojo/services/view_manager/cpp/view.h"
9 #include "mojo/services/view_manager/cpp/view_property.h"
10 #include "services/window_manager/view_targeter.h"
11 #include "services/window_manager/window_manager_app.h"
12 #include "ui/events/event.h"
13 #include "ui/events/event_target_iterator.h"
14 #include "ui/events/event_targeter.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/point3_f.h"
17 #include "ui/gfx/transform.h"
18
19 namespace window_manager {
20
21 namespace {
22
23 DEFINE_OWNED_VIEW_PROPERTY_KEY(ViewTarget, kViewTargetKey, nullptr);
24
25 } // namespace
26
27 ViewTarget::~ViewTarget() {
28 }
29
30 // static
31 ViewTarget* ViewTarget::TargetFromView(mojo::View* view) {
32 if (!view)
33 return nullptr;
34
35 ViewTarget* target = view->GetLocalProperty(kViewTargetKey);
36 if (target)
37 return target;
38
39 return new ViewTarget(view);
40 }
41
42 void ViewTarget::ConvertPointToTarget(const ViewTarget* source,
43 const ViewTarget* target,
44 gfx::Point* point) {
45 // TODO(erg): Do we need to deal with |source| and |target| being in
46 // different trees?
47 DCHECK_EQ(source->GetRoot(), target->GetRoot());
48 if (source == target)
49 return;
50
51 const ViewTarget* root_target = source->GetRoot();
52 CHECK_EQ(root_target, target->GetRoot());
53
54 if (source != root_target)
55 source->ConvertPointForAncestor(root_target, point);
56 if (target != root_target)
57 target->ConvertPointFromAncestor(root_target, point);
58 }
59
60 std::vector<ViewTarget*> ViewTarget::GetChildren() const {
61 std::vector<ViewTarget*> targets;
62 for (mojo::View* child : view_->children())
63 targets.push_back(TargetFromView(child));
64 return targets;
65 }
66
67 const ViewTarget* ViewTarget::GetParent() const {
68 return TargetFromView(view_->parent());
69 }
70
71 gfx::Rect ViewTarget::GetBounds() const {
72 return view_->bounds().To<gfx::Rect>();
73 }
74
75 bool ViewTarget::HasParent() const {
76 return !!view_->parent();
77 }
78
79 bool ViewTarget::IsVisible() const {
80 return view_->visible();
81 }
82
83 const ViewTarget* ViewTarget::GetRoot() const {
84 const ViewTarget* root = this;
85 for (const ViewTarget* parent = this; parent; parent = parent->GetParent())
86 root = parent;
87 return root;
88 }
89
90 scoped_ptr<ViewTargeter> ViewTarget::SetEventTargeter(
91 scoped_ptr<ViewTargeter> targeter) {
92 scoped_ptr<ViewTargeter> old_targeter = targeter_.Pass();
93 targeter_ = targeter.Pass();
94 return old_targeter;
95 }
96
97 bool ViewTarget::CanAcceptEvent(const ui::Event& event) {
98 // We need to make sure that a touch cancel event and any gesture events it
99 // creates can always reach the window. This ensures that we receive a valid
100 // touch / gesture stream.
101 if (event.IsEndingEvent())
102 return true;
103
104 if (!view_->visible())
105 return false;
106
107 // The top-most window can always process an event.
108 if (!view_->parent())
109 return true;
110
111 // In aura, we only accept events if this is a key event or if the user
112 // supplied a TargetHandler, usually the aura::WindowDelegate. Here, we're
113 // just forwarding events to other Views which may be in other processes, so
114 // always accept.
115 return true;
116 }
117
118 ui::EventTarget* ViewTarget::GetParentTarget() {
119 return TargetFromView(view_->parent());
120 }
121
122 scoped_ptr<ui::EventTargetIterator> ViewTarget::GetChildIterator() const {
123 return scoped_ptr<ui::EventTargetIterator>(
124 new ui::CopyingEventTargetIteratorImpl<ViewTarget>(GetChildren()));
125 }
126
127 ui::EventTargeter* ViewTarget::GetEventTargeter() {
128 return targeter_.get();
129 }
130
131 void ViewTarget::ConvertEventToTarget(ui::EventTarget* target,
132 ui::LocatedEvent* event) {
133 event->ConvertLocationToTarget(this, static_cast<ViewTarget*>(target));
134 }
135
136 ViewTarget::ViewTarget(mojo::View* view_to_wrap) : view_(view_to_wrap) {
137 DCHECK(view_->GetLocalProperty(kViewTargetKey) == nullptr);
138 view_->SetLocalProperty(kViewTargetKey, this);
139 }
140
141 bool ViewTarget::ConvertPointForAncestor(const ViewTarget* ancestor,
142 gfx::Point* point) const {
143 gfx::Vector2d offset;
144 bool result = GetTargetOffsetRelativeTo(ancestor, &offset);
145 *point += offset;
146 return result;
147 }
148
149 bool ViewTarget::ConvertPointFromAncestor(const ViewTarget* ancestor,
150 gfx::Point* point) const {
151 gfx::Vector2d offset;
152 bool result = GetTargetOffsetRelativeTo(ancestor, &offset);
153 *point -= offset;
154 return result;
155 }
156
157 bool ViewTarget::GetTargetOffsetRelativeTo(const ViewTarget* ancestor,
158 gfx::Vector2d* offset) const {
159 const ViewTarget* v = this;
160 for (; v && v != ancestor; v = v->GetParent()) {
161 gfx::Rect bounds = v->GetBounds();
162 *offset += gfx::Vector2d(bounds.x(), bounds.y());
163 }
164 return v == ancestor;
165 }
166
167 } // namespace window_manager
OLDNEW
« no previous file with comments | « services/window_manager/view_target.h ('k') | services/window_manager/view_target_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698