ElementUtilities.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 ROCKETCOREELEMENTUTILITIES_H
00029 #define ROCKETCOREELEMENTUTILITIES_H
00030 
00031 #include <Rocket/Core/Header.h>
00032 #include <Rocket/Core/Box.h>
00033 #include <Rocket/Core/WString.h>
00034 #include <Rocket/Core/Types.h>
00035 
00036 namespace Rocket {
00037 namespace Core {
00038 
00039 class Context;
00040 class FontFaceHandle;
00041 class RenderInterface;
00042 
00049 class ROCKETCORE_API ElementUtilities
00050 {
00051 public:
00052         enum PositionAnchor
00053         {
00054                 TOP = 1 << 0,
00055                 BOTTOM = 1 << 1,
00056                 LEFT = 1 << 2,
00057                 RIGHT = 1 << 3,
00058 
00059                 TOP_LEFT = TOP | LEFT,
00060                 TOP_RIGHT = TOP | RIGHT,
00061                 BOTTOM_LEFT = BOTTOM | LEFT,
00062                 BOTTOM_RIGHT = BOTTOM | RIGHT
00063         };
00064 
00068         static Element* GetElementById(Element* root_element, const String& id);
00073         static void GetElementsByTagName(ElementList& elements, Element* root_element, const String& tag);
00074 
00078         static FontFaceHandle* GetFontFaceHandle(Element* element);
00082         static int GetFontSize(Element* element);
00086         static int GetLineHeight(Element* element);
00091         static int GetStringWidth(Element* element, const WString& string);
00092 
00095         static void BindEventAttributes(Element* element);
00096 
00102         static bool GetClippingRegion(Vector2i& clip_origin, Vector2i& clip_dimensions, Element* element);
00107         static bool SetClippingRegion(Element* element, Context* context = NULL);
00110         static void PushClipCache(RenderInterface* render_interface);
00111 
00116         static bool FormatElement(Element* element, const Vector2f& containing_block);
00117 
00123         static void BuildBox(Box& box, const Vector2f& containing_block, Element* element, bool inline_element = false);
00124 
00129         static bool PositionElement(Element* element, const Vector2f& offset);
00135         static bool PositionElement(Element* element, const Vector2f& offset, PositionAnchor anchor);
00136 };
00137 
00138 }
00139 }
00140 
00141 #endif