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