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