ElementDecoration.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 ROCKETCOREELEMENTDECORATION_H
  28. #define ROCKETCOREELEMENTDECORATION_H
  29. #include "../../Include/Rocket/Core/Types.h"
  30. namespace Rocket {
  31. namespace Core {
  32. class Decorator;
  33. class Element;
  34. /**
  35. Manages an elements decorator state
  36. @author Lloyd Weehuizen
  37. */
  38. class ElementDecoration
  39. {
  40. public:
  41. /// Constructor
  42. /// @param element The element this decorator with acting on
  43. ElementDecoration(Element* element);
  44. ~ElementDecoration();
  45. // Releases existing decorators and loads all decorators required by the element's definition.
  46. bool ReloadDecorators();
  47. /// Renders all appropriate decorators.
  48. void RenderDecorators();
  49. /// Mark decorators as dirty and force them to reset themselves
  50. void DirtyDecorators();
  51. /// Iterates over all active decorators attached to the decoration's element.
  52. /// @param[inout] index Index to fetch. This is incremented after the fetch.
  53. /// @param[out] pseudo_classes The pseudo-classes the decorator required to be active before it renders.
  54. /// @param[out] name The name of the decorator at the specified index.
  55. /// @param[out] decorator The decorator at the specified index.
  56. /// @param[out] decorator_data This element's handle to any data is has stored against the decorator.
  57. /// @return True if a decorator was successfully fetched, false if not.
  58. bool IterateDecorators(int& index, PseudoClassList& pseudo_classes, String& name, Decorator*& decorator, DecoratorDataHandle& decorator_data) const;
  59. private:
  60. // Loads a single decorator and adds it to the list of loaded decorators for this element.
  61. int LoadDecorator(Decorator* decorator);
  62. // Releases all existing decorators and frees their data.
  63. void ReleaseDecorators();
  64. // Updates the list of active decorators (if necessary)
  65. void UpdateActiveDecorators();
  66. struct DecoratorHandle
  67. {
  68. Decorator* decorator;
  69. DecoratorDataHandle decorator_data;
  70. };
  71. typedef std::vector< DecoratorHandle > DecoratorList;
  72. typedef std::pair< PseudoClassList, int > PseudoClassDecoratorIndex;
  73. typedef std::vector< PseudoClassDecoratorIndex > PseudoClassDecoratorIndexList;
  74. typedef std::map< String, PseudoClassDecoratorIndexList > DecoratorIndex;
  75. // The element this decorator belongs to
  76. Element* element;
  77. // The list of every decorator used by this element in every class.
  78. DecoratorList decorators;
  79. // The list of currently active decorators.
  80. std::vector< int > active_decorators;
  81. bool active_decorators_dirty;
  82. // For each unique decorator name, this stores (in order of specificity) the name of the pseudo-class that has
  83. // a definition for it, and the index into the list of decorators.
  84. DecoratorIndex decorator_index;
  85. };
  86. }
  87. }
  88. #endif