ElementDocument.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 ROCKETCOREELEMENTDOCUMENT_H
  28. #define ROCKETCOREELEMENTDOCUMENT_H
  29. #include <Rocket/Core/Element.h>
  30. namespace Rocket {
  31. namespace Core {
  32. class Stream;
  33. }
  34. }
  35. namespace Rocket {
  36. namespace Core {
  37. class Context;
  38. class DocumentHeader;
  39. class ElementText;
  40. class StyleSheet;
  41. /**
  42. Represents a document in the dom tree.
  43. @author Lloyd Weehuizen
  44. */
  45. class ROCKETCORE_API ElementDocument : public Element
  46. {
  47. public:
  48. ElementDocument(const String& tag);
  49. virtual ~ElementDocument();
  50. /// Process given document header
  51. void ProcessHeader(const DocumentHeader* header);
  52. /// Returns itself as the current document
  53. virtual ElementDocument* GetOwnerDocument();
  54. /// Returns the document's context.
  55. /// @return The context this document exists within.
  56. Context* GetContext();
  57. /// Sets the document's title.
  58. /// @param[in] title The new title of the document.
  59. void SetTitle(String& title);
  60. /// Returns the title of this document.
  61. /// @return The document's title.
  62. const String& GetTitle() const;
  63. /// Returns the source address of this document.
  64. /// @return The source of this document, usually a file name.
  65. const String& GetSourceURL() const;
  66. /// Sets the style sheet this document, and all of its children, uses.
  67. /// @param[in] style_sheet The style sheet to set on the document.
  68. void SetStyleSheet(StyleSheet* style_sheet);
  69. /// Returns the document's style sheet.
  70. /// @return The document's style sheet.
  71. virtual StyleSheet* GetStyleSheet() const;
  72. /// Brings the document to the front of the document stack.
  73. void PullToFront();
  74. /// Sends the document to the back of the document stack.
  75. void PushToBack();
  76. /**
  77. Flags used for displaying the document.
  78. */
  79. enum FocusFlags
  80. {
  81. NONE = 0,
  82. FOCUS = (1 << 1),
  83. MODAL = (1 << 2)
  84. };
  85. /// Show the document.
  86. /// @param[in] focus_flags Flags controlling the changing of focus. Leave as FOCUS to switch focus to the document.
  87. void Show(int focus_flags = FOCUS);
  88. /// Hide the document.
  89. void Hide();
  90. /// Close the document.
  91. void Close();
  92. /// Creates the named element.
  93. /// @param[in] name The tag name of the element.
  94. Element* CreateElement(const String& name);
  95. /// Create a text element with the given text content.
  96. /// @param[in] text The text content of the text element.
  97. ElementText* CreateTextNode(const String& text);
  98. /// Does the document have modal display set.
  99. /// @return True if the document is hogging focus.
  100. bool IsModal() const;
  101. /// Load a script into the document. Note that the base implementation does nothing, scripting language addons hook
  102. /// this method.
  103. /// @param[in] stream Stream of code to process.
  104. /// @param[in] source_name Name of the the script the source comes from, useful for debug information.
  105. virtual void LoadScript(Stream* stream, const String& source_name);
  106. /// Updates the layout if necessary.
  107. virtual void UpdateLayout();
  108. /// Updates the position of the document based on the style properties.
  109. void UpdatePosition();
  110. protected:
  111. /// Refreshes the document layout if required.
  112. virtual void OnUpdate();
  113. /// Repositions the document if necessary.
  114. virtual void OnPropertyChange(const PropertyNameList& changed_properties);
  115. /// Sets the dirty flag on the layout so the document will format its children before the next render.
  116. virtual void DirtyLayout();
  117. /// Processes the 'onpropertychange' event, checking for a change in position or size.
  118. virtual void ProcessEvent(Event& event);
  119. private:
  120. // Find the next element to focus, starting at the current element
  121. bool FocusNextTabElement(Element* current_element, bool forward);
  122. /// Searches forwards or backwards for a focusable element in the given substree
  123. bool SearchFocusSubtree(Element* element, bool forward);
  124. // Title of the document
  125. String title;
  126. // The original path this document came from
  127. String source_url;
  128. // The document's style sheet.
  129. StyleSheet* style_sheet;
  130. Context* context;
  131. // Is the current display modal
  132. bool modal;
  133. // Is the layout dirty?
  134. bool layout_dirty;
  135. bool lock_layout;
  136. friend class Context;
  137. friend class Factory;
  138. };
  139. }
  140. }
  141. #endif