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

Side by Side Diff: mojo/services/window_manager/view_target.h

Issue 724973003: Get event targetting working for mouse events. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Patch beautification. Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_ 5 #ifndef MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_
6 #define MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_ 6 #define MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_
7 7
8 #include "mojo/services/public/cpp/view_manager/view_observer.h"
8 #include "ui/events/event_target.h" 9 #include "ui/events/event_target.h"
9 10
11 namespace gfx {
12 class Point;
13 class Rect;
14 class Transform;
15 }
16
10 namespace ui { 17 namespace ui {
11 class EventTargeter; 18 class EventTargeter;
12 } 19 }
13 20
14 namespace mojo { 21 namespace mojo {
15 22
16 class View; 23 class View;
17 class ViewTargeter; 24 class ViewTargeter;
18 class WindowManagerApp; 25 class WindowManagerApp;
19 26
20 // A wrapper class around mojo::View. We maintain a shadow tree of ViewTargets, 27 // A wrapper class around mojo::View; we can't subclass View to implement the
21 // which mirrors the main View tree. The ViewTarget tree wraps mojo::View 28 // event targeting interfaces, so we create a separate object which observes
22 // because we can't subclass View to implement the event targeting interfaces. 29 // the View and ties its lifetime to it.
23 class ViewTarget : public ui::EventTarget { 30 //
31 // Instead of maintaining a shadow tree, we keep a static mapping between a
32 // View and all live ViewTarget objects. We observe the View and then delete
33 // and deregister ourselves when our View is deleted.
34 class ViewTarget : public ui::EventTarget,
35 public ViewObserver {
24 public: 36 public:
25 ViewTarget(WindowManagerApp* app, View* view_to_wrap); 37 ViewTarget(View* view_to_wrap);
26 ~ViewTarget() override; 38
39 // Returns the ViewTarget for a View.
40 static ViewTarget* TargetFromView(View* view);
41
42 // Converts |point| from |source|'s coordinates to |target|'s. If |source| is
43 // NULL, the function returns without modifying |point|. |target| cannot be
44 // NULL.
45 static void ConvertPointToTarget(const ViewTarget* source,
46 const ViewTarget* target,
47 gfx::Point* point);
27 48
28 View* view() { return view_; } 49 View* view() { return view_; }
29 50
51 std::vector<ViewTarget*> GetChildren() const;
52 ViewTarget* GetParent() const;
53 gfx::Rect GetBounds() const;
30 bool HasParent() const; 54 bool HasParent() const;
31 bool IsVisible() const; 55 bool IsVisible() const;
32 56
33 // We keep track of our children here. 57 const ViewTarget* GetRoot() const;
34 void AddChild(ViewTarget* view);
35 58
36 // Sets a new ViewTargeter for the view, and returns the previous 59 // Sets a new ViewTargeter for the view, and returns the previous
37 // ViewTargeter. 60 // ViewTargeter.
38 scoped_ptr<ViewTargeter> SetEventTargeter(scoped_ptr<ViewTargeter> targeter); 61 scoped_ptr<ViewTargeter> SetEventTargeter(scoped_ptr<ViewTargeter> targeter);
39 62
63 // Converts a transform to be relative to the given |ancestor|. Returns
64 // whether success (that is, whether the given ancestor was really an
65 // ancestor of this layer).
66 bool GetTargetTransformRelativeTo(const ViewTarget* ancestor,
67 gfx::Transform* transform) const;
68
40 // Overridden from ui::EventTarget: 69 // Overridden from ui::EventTarget:
41 bool CanAcceptEvent(const ui::Event& event) override; 70 bool CanAcceptEvent(const ui::Event& event) override;
42 EventTarget* GetParentTarget() override; 71 EventTarget* GetParentTarget() override;
43 scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override; 72 scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override;
44 ui::EventTargeter* GetEventTargeter() override; 73 ui::EventTargeter* GetEventTargeter() override;
45 void ConvertEventToTarget(ui::EventTarget* target, 74 void ConvertEventToTarget(ui::EventTarget* target,
46 ui::LocatedEvent* event) override; 75 ui::LocatedEvent* event) override;
47 76
77 // Overridden from ViewObserver:
78 void OnViewDestroying(View* view) override;
79
80 protected:
81 // Protected so testing subclasses can still instantiate this.
82 ~ViewTarget() override;
83
48 private: 84 private:
49 // The WindowManagerApp which owns us. 85 bool ConvertPointForAncestor(const ViewTarget* ancestor,
50 WindowManagerApp* app_; 86 gfx::Point* point) const;
87 bool ConvertPointFromAncestor(const ViewTarget* ancestor,
88 gfx::Point* point) const;
51 89
52 // The mojo::View that we dispatch to. 90 // The mojo::View that we dispatch to.
53 View* view_; 91 View* view_;
54 92
55 std::vector<ViewTarget*> children_;
56
57 scoped_ptr<ViewTargeter> targeter_; 93 scoped_ptr<ViewTargeter> targeter_;
58 94
59 DISALLOW_COPY_AND_ASSIGN(ViewTarget); 95 DISALLOW_COPY_AND_ASSIGN(ViewTarget);
60 }; 96 };
61 97
62 } // namespace mojo 98 } // namespace mojo
63 99
64 #endif // MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_ 100 #endif // MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698