From 942181c8ae24336de6ca5b28414238f8739de835 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Wed, 30 Jul 2014 17:16:26 +0200 Subject: [PATCH] Canvas: Support for preventDefault() on Events. --- simgear/canvas/CanvasEvent.cxx | 15 ++++++++++++++- simgear/canvas/CanvasEvent.hxx | 26 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/simgear/canvas/CanvasEvent.cxx b/simgear/canvas/CanvasEvent.cxx index 44786551..a438472b 100644 --- a/simgear/canvas/CanvasEvent.cxx +++ b/simgear/canvas/CanvasEvent.cxx @@ -27,7 +27,8 @@ namespace canvas Event::Event(): type(UNKNOWN), time(-1), - propagation_stopped(false) + propagation_stopped(false), + default_prevented(false) { } @@ -80,6 +81,18 @@ namespace canvas propagation_stopped = true; } + //---------------------------------------------------------------------------- + void Event::preventDefault() + { + default_prevented = true; + } + + //---------------------------------------------------------------------------- + bool Event::defaultPrevented() const + { + return default_prevented; + } + //---------------------------------------------------------------------------- int Event::getOrRegisterType(const std::string& type_str) { diff --git a/simgear/canvas/CanvasEvent.hxx b/simgear/canvas/CanvasEvent.hxx index 92ccdf19..23da1048 100644 --- a/simgear/canvas/CanvasEvent.hxx +++ b/simgear/canvas/CanvasEvent.hxx @@ -56,7 +56,8 @@ namespace canvas ElementWeakPtr target, current_target; double time; - bool propagation_stopped; + bool propagation_stopped, + default_prevented; Event(); @@ -82,10 +83,33 @@ namespace canvas ElementWeakPtr getTarget() const; ElementWeakPtr getCurrentTarget() const; + /** + * Get time at which the event was generated. + */ double getTime() const; + /** + * Prevent further propagation of the event during event flow. + * + * @note This does not prevent calling further event handlers registered + * on the current event target. + */ void stopPropagation(); + /** + * Cancel any default action normally taken as result of this event. + * + * @note For event handlers registered on the DesktopGroup (Nasal: + * canvas.getDesktop()) this stops the event from being further + * propagated to the normal FlightGear input event handling code. + */ + void preventDefault(); + + /** + * Get if preventDefault() has been called. + */ + bool defaultPrevented() const; + static int getOrRegisterType(const std::string& type); static int strToType(const std::string& type); static std::string typeToStr(int type); -- 2.39.5