1 /* 2 * This source file is part of libRocket, the HTML/CSS Interface Middleware 3 * 4 * For the latest information, see http://www.librocket.com 5 * 6 * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 * 26 */ 27 28 #ifndef ROCKETCOREEVENT_H 29 #define ROCKETCOREEVENT_H 30 31 #include "Dictionary.h" 32 #include "ScriptInterface.h" 33 #include "Header.h" 34 35 namespace Rocket { 36 namespace Core { 37 38 class Element; 39 class EventInstancer; 40 41 /** 42 An event that propogates through the element hierarchy. Events follow the DOM3 event specification. See 43 http://www.w3.org/TR/DOM-Level-3-Events/events.html. 44 45 @author Lloyd Weehuizen 46 */ 47 48 class ROCKETCORE_API Event : public ScriptInterface 49 { 50 public: 51 /// Constructor 52 Event(); 53 /// Constructor 54 /// @param[in] target The target element of this event 55 /// @param[in] type The event type 56 /// @param[in] parameters The event parameters 57 /// @param[in] interruptible Can this event have is propagation stopped? 58 Event(Element* target, const String& type, const Dictionary& parameters, bool interruptible = false); 59 /// Destructor 60 virtual ~Event(); 61 62 enum EventPhase { PHASE_UNKNOWN, PHASE_CAPTURE, PHASE_TARGET, PHASE_BUBBLE }; 63 64 /// Get the current propagation phase. 65 /// @return Current phase the event is in. 66 EventPhase GetPhase() const; 67 /// Set the current propagation phase 68 /// @param phase Switch the phase the event is in 69 void SetPhase(EventPhase phase); 70 71 /// Set the current element in the propagation. 72 /// @param[in] element The current element. 73 void SetCurrentElement(Element* element); 74 /// Get the current element in the propagation. 75 /// @return The current element in propagation. 76 Element* GetCurrentElement() const; 77 78 /// Get the target element 79 /// @return The target element of this event 80 Element* GetTargetElement() const; 81 82 /// Get the event type. 83 /// @return The event type. 84 const String& GetType() const; 85 /// Checks if the event is of a certain type. 86 /// @param type The name of the type to check for. 87 /// @return True if the event is of the requested type, false otherwise. 88 bool operator==(const String& type) const; 89 90 /// Has the event been stopped? 91 /// @return True if the event is still propogating 92 bool IsPropagating() const; 93 /// Stops the propagation of the event wherever it is 94 void StopPropagation(); 95 96 /// Returns the value of one of the event's parameters. 97 /// @param key[in] The name of the desired parameter. 98 /// @return The value of the requested parameter. 99 template < typename T > GetParameter(const String & key,const T & default_value)100 T GetParameter(const String& key, const T& default_value) 101 { 102 return parameters.Get(key, default_value); 103 } 104 /// Access the dictionary of parameters 105 /// @return The dictionary of parameters 106 const Dictionary* GetParameters() const; 107 108 /// Release this event. 109 virtual void OnReferenceDeactivate(); 110 111 protected: 112 String type; 113 Dictionary parameters; 114 115 Element* target_element; 116 Element* current_element; 117 118 private: 119 bool interruptible; 120 bool interruped; 121 122 EventPhase phase; 123 124 EventInstancer* instancer; 125 126 friend class Factory; 127 }; 128 129 } 130 } 131 132 #endif 133