ElementDocument.h

00001 /*
00002  * This source file is part of libRocket, the HTML/CSS Interface Middleware
00003  *
00004  * For the latest information, see http://www.librocket.com
00005  *
00006  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documentation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  *
00026  */
00027 
00028 #ifndef ROCKETCOREELEMENTDOCUMENT_H
00029 #define ROCKETCOREELEMENTDOCUMENT_H
00030 
00031 #include <Rocket/Core/Element.h>
00032 
00033 namespace Rocket {
00034 namespace Core {
00035 
00036 class Stream;
00037 
00038 }
00039 }
00040 
00041 namespace Rocket {
00042 namespace Core {
00043 
00044 class Context;
00045 class DocumentHeader;
00046 class ElementText;
00047 class StyleSheet;
00048 
00055 class ROCKETCORE_API ElementDocument : public Element
00056 {
00057 public:
00058         ElementDocument(const String& tag);
00059         virtual ~ElementDocument();
00060 
00062         void ProcessHeader(const DocumentHeader* header);
00063 
00065         virtual ElementDocument* GetOwnerDocument();
00066 
00069         Context* GetContext();
00070 
00073         void SetTitle(String& title);
00076         const String& GetTitle() const;
00077 
00080         const String& GetSourceURL() const;
00081 
00084         void SetStyleSheet(StyleSheet* style_sheet);
00087         virtual StyleSheet* GetStyleSheet() const;
00088 
00090         void PullToFront();
00092         void PushToBack();
00093 
00097         enum FocusFlags
00098         {
00099                 NONE = 0,
00100                 FOCUS = (1 << 1),
00101                 MODAL = (1 << 2)
00102         };
00103 
00106         void Show(int focus_flags = FOCUS);
00108         void Hide();
00110         void Close();
00111 
00114         Element* CreateElement(const String& name);
00117         ElementText* CreateTextNode(const String& text);
00118 
00121         bool IsModal() const;
00122 
00127         virtual void LoadScript(Stream* stream, const String& source_name);
00128 
00130         virtual void UpdateLayout();
00132         void UpdatePosition();
00133 
00134 protected:
00136         virtual void OnUpdate();
00137 
00139         virtual void OnPropertyChange(const PropertyNameList& changed_properties);
00140 
00142         virtual void DirtyLayout();
00143 
00145         virtual void ProcessEvent(Event& event);
00146 
00147 private:
00148         // Find the next element to focus, starting at the current element
00149         bool FocusNextTabElement(Element* current_element, bool forward);
00151         bool SearchFocusSubtree(Element* element, bool forward);
00152 
00153         // Title of the document
00154         String title;
00155 
00156         // The original path this document came from
00157         String source_url;
00158 
00159         // The document's style sheet.
00160         StyleSheet* style_sheet;
00161 
00162         Context* context;
00163 
00164         // Is the current display modal
00165         bool modal;
00166 
00167         // Is the layout dirty?
00168         bool layout_dirty;
00169         bool lock_layout;
00170 
00171         friend class Context;
00172         friend class Factory;
00173 };
00174 
00175 }
00176 }
00177 
00178 #endif