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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/window_manager/view_target.h
diff --git a/mojo/services/window_manager/view_target.h b/mojo/services/window_manager/view_target.h
index 990a2715dafd84cbedad496edb53fd31e5c37578..a580be251e5ce1c64417d2306bf9124b8876f387 100644
--- a/mojo/services/window_manager/view_target.h
+++ b/mojo/services/window_manager/view_target.h
@@ -5,8 +5,15 @@
#ifndef MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_
#define MOJO_SERVICES_WINDOW_MANAGER_VIEW_TARGET_H_
+#include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "ui/events/event_target.h"
+namespace gfx {
+class Point;
+class Rect;
+class Transform;
+}
+
namespace ui {
class EventTargeter;
}
@@ -17,26 +24,48 @@ class View;
class ViewTargeter;
class WindowManagerApp;
-// A wrapper class around mojo::View. We maintain a shadow tree of ViewTargets,
-// which mirrors the main View tree. The ViewTarget tree wraps mojo::View
-// because we can't subclass View to implement the event targeting interfaces.
-class ViewTarget : public ui::EventTarget {
+// A wrapper class around mojo::View; we can't subclass View to implement the
+// event targeting interfaces, so we create a separate object which observes
+// the View and ties its lifetime to it.
+//
+// Instead of maintaining a shadow tree, we keep a static mapping between a
+// View and all live ViewTarget objects. We observe the View and then delete
+// and deregister ourselves when our View is deleted.
+class ViewTarget : public ui::EventTarget,
+ public ViewObserver {
public:
- ViewTarget(WindowManagerApp* app, View* view_to_wrap);
- ~ViewTarget() override;
+ ViewTarget(View* view_to_wrap);
+
+ // Returns the ViewTarget for a View.
+ static ViewTarget* TargetFromView(View* view);
+
+ // Converts |point| from |source|'s coordinates to |target|'s. If |source| is
+ // NULL, the function returns without modifying |point|. |target| cannot be
+ // NULL.
+ static void ConvertPointToTarget(const ViewTarget* source,
+ const ViewTarget* target,
+ gfx::Point* point);
View* view() { return view_; }
+ std::vector<ViewTarget*> GetChildren() const;
+ ViewTarget* GetParent() const;
+ gfx::Rect GetBounds() const;
bool HasParent() const;
bool IsVisible() const;
- // We keep track of our children here.
- void AddChild(ViewTarget* view);
+ const ViewTarget* GetRoot() const;
// Sets a new ViewTargeter for the view, and returns the previous
// ViewTargeter.
scoped_ptr<ViewTargeter> SetEventTargeter(scoped_ptr<ViewTargeter> targeter);
+ // Converts a transform to be relative to the given |ancestor|. Returns
+ // whether success (that is, whether the given ancestor was really an
+ // ancestor of this layer).
+ bool GetTargetTransformRelativeTo(const ViewTarget* ancestor,
+ gfx::Transform* transform) const;
+
// Overridden from ui::EventTarget:
bool CanAcceptEvent(const ui::Event& event) override;
EventTarget* GetParentTarget() override;
@@ -45,15 +74,22 @@ class ViewTarget : public ui::EventTarget {
void ConvertEventToTarget(ui::EventTarget* target,
ui::LocatedEvent* event) override;
+ // Overridden from ViewObserver:
+ void OnViewDestroying(View* view) override;
+
+ protected:
+ // Protected so testing subclasses can still instantiate this.
+ ~ViewTarget() override;
+
private:
- // The WindowManagerApp which owns us.
- WindowManagerApp* app_;
+ bool ConvertPointForAncestor(const ViewTarget* ancestor,
+ gfx::Point* point) const;
+ bool ConvertPointFromAncestor(const ViewTarget* ancestor,
+ gfx::Point* point) const;
// The mojo::View that we dispatch to.
View* view_;
- std::vector<ViewTarget*> children_;
-
scoped_ptr<ViewTargeter> targeter_;
DISALLOW_COPY_AND_ASSIGN(ViewTarget);

Powered by Google App Engine
This is Rietveld 408576698