Event.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifndef ROCKETCOREEVENT_H
  28. #define ROCKETCOREEVENT_H
  29. #include "Dictionary.h"
  30. #include "ScriptInterface.h"
  31. #include "Header.h"
  32. namespace Rocket {
  33. namespace Core {
  34. class Element;
  35. class EventInstancer;
  36. /**
  37. An event that propogates through the element hierarchy. Events follow the DOM3 event specification. See
  38. http://www.w3.org/TR/DOM-Level-3-Events/events.html.
  39. @author Lloyd Weehuizen
  40. */
  41. class ROCKETCORE_API Event : public ScriptInterface
  42. {
  43. public:
  44. /// Constructor
  45. Event();
  46. /// Constructor
  47. /// @param[in] target The target element of this event
  48. /// @param[in] type The event type
  49. /// @param[in] parameters The event parameters
  50. /// @param[in] interruptible Can this event have is propagation stopped?
  51. Event(Element* target, const String& type, const Dictionary& parameters, bool interruptible = false);
  52. /// Destructor
  53. virtual ~Event();
  54. enum EventPhase { PHASE_UNKNOWN, PHASE_CAPTURE, PHASE_TARGET, PHASE_BUBBLE };
  55. /// Get the current propagation phase.
  56. /// @return Current phase the event is in.
  57. EventPhase GetPhase() const;
  58. /// Set the current propagation phase
  59. /// @param phase Switch the phase the event is in
  60. void SetPhase(EventPhase phase);
  61. /// Set the current element in the propagation.
  62. /// @param[in] element The current element.
  63. void SetCurrentElement(Element* element);
  64. /// Get the current element in the propagation.
  65. /// @return The current element in propagation.
  66. Element* GetCurrentElement() const;
  67. /// Get the target element
  68. /// @return The target element of this event
  69. Element* GetTargetElement() const;
  70. /// Get the event type.
  71. /// @return The event type.
  72. const String& GetType() const;
  73. /// Checks if the event is of a certain type.
  74. /// @param type The name of the type to check for.
  75. /// @return True if the event is of the requested type, false otherwise.
  76. bool operator==(const String& type) const;
  77. /// Has the event been stopped?
  78. /// @return True if the event is still propogating
  79. bool IsPropagating() const;
  80. /// Stops the propagation of the event wherever it is
  81. void StopPropagation();
  82. /// Returns the value of one of the event's parameters.
  83. /// @param key[in] The name of the desired parameter.
  84. /// @return The value of the requested parameter.
  85. template < typename T >
  86. T GetParameter(const String& key, const T& default_value)
  87. {
  88. return Get(parameters, key, default_value);
  89. }
  90. /// Access the dictionary of parameters
  91. /// @return The dictionary of parameters
  92. const Dictionary* GetParameters() const;
  93. /// Release this event.
  94. virtual void OnReferenceDeactivate();
  95. private:
  96. /// Project the mouse coordinates to the current element to enable
  97. /// interacting with transformed elements.
  98. void ProjectMouse(Element* element);
  99. protected:
  100. String type;
  101. Dictionary parameters;
  102. Element* target_element;
  103. Element* current_element;
  104. private:
  105. Dictionary parameters_backup;
  106. bool interruptible;
  107. bool interruped;
  108. EventPhase phase;
  109. EventInstancer* instancer;
  110. friend class Factory;
  111. };
  112. }
  113. }
  114. #endif