OLD | NEW |
(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 #ifndef SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_ |
| 6 #define SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_ |
| 7 |
| 8 #include "ui/events/event_target.h" |
| 9 |
| 10 namespace gfx { |
| 11 class Point; |
| 12 class Rect; |
| 13 class Vector2d; |
| 14 } |
| 15 |
| 16 namespace ui { |
| 17 class EventTargeter; |
| 18 } |
| 19 |
| 20 namespace mojo { |
| 21 class View; |
| 22 } |
| 23 |
| 24 namespace window_manager { |
| 25 |
| 26 class TestView; |
| 27 class ViewTargeter; |
| 28 class WindowManagerApp; |
| 29 |
| 30 // A wrapper class around mojo::View; we can't subclass View to implement the |
| 31 // event targeting interfaces, so we create a separate object which observes |
| 32 // the View and ties its lifetime to it. |
| 33 // |
| 34 // We set ourselves as a property of the view passed in, and we are owned by |
| 35 // said View. |
| 36 class ViewTarget : public ui::EventTarget { |
| 37 public: |
| 38 ~ViewTarget() override; |
| 39 |
| 40 // Returns the ViewTarget for a View. ViewTargets are owned by the |view| |
| 41 // passed in, and are created on demand. |
| 42 static ViewTarget* TargetFromView(mojo::View* view); |
| 43 |
| 44 // Converts |point| from |source|'s coordinates to |target|'s. If |source| is |
| 45 // NULL, the function returns without modifying |point|. |target| cannot be |
| 46 // NULL. |
| 47 static void ConvertPointToTarget(const ViewTarget* source, |
| 48 const ViewTarget* target, |
| 49 gfx::Point* point); |
| 50 |
| 51 mojo::View* view() { return view_; } |
| 52 |
| 53 // TODO(erg): Make this const once we've removed aura from the tree and it's |
| 54 // feasible to change all callers of the EventTargeter interface to pass and |
| 55 // accept const objects. (When that gets done, re-const the |
| 56 // EventTargetIterator::GetNextTarget and EventTarget::GetChildIterator |
| 57 // interfaces.) |
| 58 std::vector<ViewTarget*> GetChildren() const; |
| 59 |
| 60 const ViewTarget* GetParent() const; |
| 61 gfx::Rect GetBounds() const; |
| 62 bool HasParent() const; |
| 63 bool IsVisible() const; |
| 64 |
| 65 const ViewTarget* GetRoot() const; |
| 66 |
| 67 // Sets a new ViewTargeter for the view, and returns the previous |
| 68 // ViewTargeter. |
| 69 scoped_ptr<ViewTargeter> SetEventTargeter(scoped_ptr<ViewTargeter> targeter); |
| 70 |
| 71 // Overridden from ui::EventTarget: |
| 72 bool CanAcceptEvent(const ui::Event& event) override; |
| 73 EventTarget* GetParentTarget() override; |
| 74 scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override; |
| 75 ui::EventTargeter* GetEventTargeter() override; |
| 76 void ConvertEventToTarget(ui::EventTarget* target, |
| 77 ui::LocatedEvent* event) override; |
| 78 |
| 79 private: |
| 80 friend class TestView; |
| 81 explicit ViewTarget(mojo::View* view_to_wrap); |
| 82 |
| 83 bool ConvertPointForAncestor(const ViewTarget* ancestor, |
| 84 gfx::Point* point) const; |
| 85 bool ConvertPointFromAncestor(const ViewTarget* ancestor, |
| 86 gfx::Point* point) const; |
| 87 bool GetTargetOffsetRelativeTo(const ViewTarget* ancestor, |
| 88 gfx::Vector2d* offset) const; |
| 89 |
| 90 // The mojo::View that we dispatch to. |
| 91 mojo::View* view_; |
| 92 |
| 93 scoped_ptr<ViewTargeter> targeter_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(ViewTarget); |
| 96 }; |
| 97 |
| 98 } // namespace window_manager |
| 99 |
| 100 #endif // SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_ |
OLD | NEW |