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

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: Move on top of the recently committed local view property stuff. 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 Vector2d;
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
sky 2014/11/17 22:39:27 Update description to reflect how you now store ma
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);
sky 2014/11/17 22:39:27 explicit
26 ~ViewTarget() override; 38 ~ViewTarget() override;
27 39
40 // Returns the ViewTarget for a View.
41 static ViewTarget* TargetFromView(View* view);
sky 2014/11/17 22:39:27 Did you consider making the constructor private an
Elliot Glaysher 2014/11/17 23:33:01 Done. This also changes WindowManagerApp so that i
42
43 // Converts |point| from |source|'s coordinates to |target|'s. If |source| is
44 // NULL, the function returns without modifying |point|. |target| cannot be
45 // NULL.
46 static void ConvertPointToTarget(const ViewTarget* source,
47 const ViewTarget* target,
48 gfx::Point* point);
49
28 View* view() { return view_; } 50 View* view() { return view_; }
29 51
52 std::vector<ViewTarget*> GetChildren() const;
sky 2014/11/17 22:39:27 Should return vector of const ViewTarget (or not b
Elliot Glaysher 2014/11/17 23:33:01 Removed const, added interface to re-add const her
53 ViewTarget* GetParent() const;
sky 2014/11/17 22:39:27 const methods should return const pointers, otherw
54 gfx::Rect GetBounds() const;
30 bool HasParent() const; 55 bool HasParent() const;
31 bool IsVisible() const; 56 bool IsVisible() const;
32 57
33 // We keep track of our children here. 58 const ViewTarget* GetRoot() const;
34 void AddChild(ViewTarget* view);
35 59
36 // Sets a new ViewTargeter for the view, and returns the previous 60 // Sets a new ViewTargeter for the view, and returns the previous
37 // ViewTargeter. 61 // ViewTargeter.
38 scoped_ptr<ViewTargeter> SetEventTargeter(scoped_ptr<ViewTargeter> targeter); 62 scoped_ptr<ViewTargeter> SetEventTargeter(scoped_ptr<ViewTargeter> targeter);
39 63
40 // Overridden from ui::EventTarget: 64 // Overridden from ui::EventTarget:
41 bool CanAcceptEvent(const ui::Event& event) override; 65 bool CanAcceptEvent(const ui::Event& event) override;
42 EventTarget* GetParentTarget() override; 66 EventTarget* GetParentTarget() override;
43 scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override; 67 scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override;
44 ui::EventTargeter* GetEventTargeter() override; 68 ui::EventTargeter* GetEventTargeter() override;
45 void ConvertEventToTarget(ui::EventTarget* target, 69 void ConvertEventToTarget(ui::EventTarget* target,
46 ui::LocatedEvent* event) override; 70 ui::LocatedEvent* event) override;
47 71
72 // Overridden from ViewObserver:
73 void OnViewDestroying(View* view) override;
74
48 private: 75 private:
49 // The WindowManagerApp which owns us. 76 bool ConvertPointForAncestor(const ViewTarget* ancestor,
50 WindowManagerApp* app_; 77 gfx::Point* point) const;
78 bool ConvertPointFromAncestor(const ViewTarget* ancestor,
79 gfx::Point* point) const;
80 bool GetTargetOffsetRelativeTo(const ViewTarget* ancestor,
81 gfx::Vector2d* offset) const;
51 82
52 // The mojo::View that we dispatch to. 83 // The mojo::View that we dispatch to.
53 View* view_; 84 View* view_;
54 85
55 std::vector<ViewTarget*> children_;
56
57 scoped_ptr<ViewTargeter> targeter_; 86 scoped_ptr<ViewTargeter> targeter_;
58 87
59 DISALLOW_COPY_AND_ASSIGN(ViewTarget); 88 DISALLOW_COPY_AND_ASSIGN(ViewTarget);
60 }; 89 };
61 90
62 } // namespace mojo 91 } // namespace mojo
63 92
64 #endif // MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_ 93 #endif // MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698