Element.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROCKETCOREELEMENT_H
00029 #define ROCKETCOREELEMENT_H
00030
00031 #include <Rocket/Core/ReferenceCountable.h>
00032 #include <Rocket/Core/ScriptInterface.h>
00033 #include <Rocket/Core/Header.h>
00034 #include <Rocket/Core/Box.h>
00035 #include <Rocket/Core/Event.h>
00036 #include <Rocket/Core/Property.h>
00037 #include <Rocket/Core/Types.h>
00038
00039 namespace Rocket {
00040 namespace Core {
00041 class Dictionary;
00042 }
00043 }
00044
00045 namespace Rocket {
00046 namespace Core {
00047
00048 class Context;
00049 class Decorator;
00050 class ElementInstancer;
00051 class EventDispatcher;
00052 class EventListener;
00053 class ElementBackground;
00054 class ElementBorder;
00055 class ElementDecoration;
00056 class ElementDefinition;
00057 class ElementDocument;
00058 class ElementScroll;
00059 class ElementStyle;
00060 class FontFaceHandle;
00061 class PropertyDictionary;
00062 class RenderInterface;
00063 class StyleSheet;
00064
00071 class ROCKETCORE_API Element : public ScriptInterface
00072 {
00073 public:
00077 Element(const String& tag);
00078 virtual ~Element();
00079
00080 void Update();
00081 void Render();
00082
00084 Element* Clone() const;
00085
00089
00090
00091
00092 void SetClass(const String& class_name, bool activate);
00096 bool IsClassSet(const String& class_name) const;
00099 void SetClassNames(const String& class_names);
00102 String GetClassNames() const;
00104
00107 virtual StyleSheet* GetStyleSheet() const;
00108
00111 const ElementDefinition* GetDefinition();
00112
00116 String GetAddress(bool include_pseudo_classes = false) const;
00117
00122 void SetOffset(const Vector2f& offset, Element* offset_parent, bool offset_fixed = false);
00127 Vector2f GetRelativeOffset(Box::Area area = Box::CONTENT);
00132 Vector2f GetAbsoluteOffset(Box::Area area = Box::CONTENT);
00133
00136 void SetClientArea(Box::Area client_area);
00139 Box::Area GetClientArea() const;
00140
00145 void SetContentBox(const Vector2f& content_offset, const Vector2f& content_box);
00148 void SetBox(const Box& box);
00151 void AddBox(const Box& box);
00155 const Box& GetBox(int index = 0);
00158 int GetNumBoxes();
00159
00162 virtual float GetBaseline() const;
00167 virtual bool GetIntrinsicDimensions(Vector2f& dimensions);
00168
00172 virtual bool IsPointWithinElement(const Vector2f& point);
00173
00176 bool IsVisible() const;
00179 float GetZIndex() const;
00180
00183 FontFaceHandle* GetFontFaceHandle() const;
00184
00188
00189
00190
00191
00192 bool SetProperty(const String& name, const String& value);
00197 bool SetProperty(const String& name, const Property& property);
00201 void RemoveProperty(const String& name);
00206 const Property* GetProperty(const String& name);
00210 template < typename T >
00211 T GetProperty(const String& name);
00216 const Property* GetLocalProperty(const String& name);
00222 float ResolveProperty(const String& name, float base_value);
00223
00230 bool IterateProperties(int& index, PseudoClassList& pseudo_classes, String& name, const Property*& property) const;
00232
00236
00237
00238
00239 void SetPseudoClass(const String& pseudo_class, bool activate);
00243 bool IsPseudoClassSet(const String& pseudo_class) const;
00247 bool ArePseudoClassesSet(const PseudoClassList& pseudo_classes) const;
00250 const PseudoClassList& GetActivePseudoClasses() const;
00252
00256
00257
00258
00259 template< typename T >
00260 void SetAttribute(const String& name, const T& value);
00264 Variant* GetAttribute(const String& name) const;
00268 template< typename T >
00269 T GetAttribute(const String& name, const T& default_value) const;
00273 bool HasAttribute(const String& name);
00276 void RemoveAttribute(const String& name);
00279 void SetAttributes(const ElementAttributes* attributes);
00285 template< typename T >
00286 bool IterateAttributes(int& index, String& name, T& value) const;
00289 int GetNumAttributes() const;
00291
00295
00296
00297
00298
00299
00300
00301
00302
00303 bool IterateDecorators(int& index, PseudoClassList& pseudo_classes, String& name, Decorator*& decorator, DecoratorDataHandle& decorator_data);
00305
00308 Element* GetFocusLeafNode();
00309
00312 Context* GetContext();
00313
00317
00320 const String& GetTagName() const;
00321
00324 const String& GetId() const;
00327 void SetId(const String& id);
00328
00331 float GetAbsoluteLeft();
00334 float GetAbsoluteTop();
00335
00339 float GetClientLeft();
00343 float GetClientTop();
00347 float GetClientWidth();
00351 float GetClientHeight();
00352
00355 Element* GetOffsetParent();
00358 float GetOffsetLeft();
00361 float GetOffsetTop();
00364 float GetOffsetWidth();
00367 float GetOffsetHeight();
00368
00371 float GetScrollLeft();
00374 void SetScrollLeft(float scroll_left);
00377 float GetScrollTop();
00380 void SetScrollTop(float scroll_top);
00383 float GetScrollWidth();
00386 float GetScrollHeight();
00387
00390 ElementStyle* GetStyle();
00391
00394 virtual ElementDocument* GetOwnerDocument();
00395
00398 Element* GetParentNode() const;
00399
00402 Element* GetNextSibling() const;
00405 Element* GetPreviousSibling() const;
00406
00409 Element* GetFirstChild() const;
00412 Element* GetLastChild() const;
00416 Element* GetChild(int index) const;
00420 int GetNumChildren(bool include_non_dom_elements = false) const;
00421
00424 virtual void GetInnerRML(String& content) const;
00427 void SetInnerRML(const String& rml);
00428
00430
00434
00437 bool Focus();
00439 void Blur();
00441 void Click();
00442
00447 void AddEventListener(const String& event, EventListener* listener, bool in_capture_phase = false);
00452 void RemoveEventListener(const String& event, EventListener* listener, bool in_capture_phase = false);
00458 bool DispatchEvent(const String& event, const Dictionary& parameters, bool interruptible = false);
00459
00462 void ScrollIntoView(bool align_with_top = true);
00463
00467 void AppendChild(Element* element, bool dom_element = true);
00472 void InsertBefore(Element* element, Element* adjacent_element);
00477 bool ReplaceChild(Element* inserted_element, Element* replaced_element);
00481 bool RemoveChild(Element* element);
00484 bool HasChildNodes() const;
00485
00489 Element* GetElementById(const String& id);
00493 void GetElementsByTagName(ElementList& elements, const String& tag);
00495
00500
00501
00502 EventDispatcher* GetEventDispatcher() const;
00505 ElementBackground* GetElementBackground() const;
00508 ElementBorder* GetElementBorder() const;
00511 ElementDecoration* GetElementDecoration() const;
00514 ElementScroll* GetElementScroll() const;
00516
00519 RenderInterface* GetRenderInterface();
00520
00523 void SetInstancer(ElementInstancer* instancer);
00524
00527 virtual void ProcessEvent(Event& event);
00528
00529 protected:
00532 void ForceLocalStackingContext();
00533
00535 virtual void OnUpdate();
00537 virtual void OnRender();
00538
00540 virtual void OnLayout();
00541
00544 virtual void OnAttributeChange(const AttributeNameList& changed_attributes);
00547 virtual void OnPropertyChange(const PropertyNameList& changed_properties);
00548
00550
00551 virtual void OnChildAdd(Element* child);
00553
00554 virtual void OnChildRemove(Element* child);
00555
00557 virtual void UpdateLayout();
00559 virtual void DirtyLayout();
00560
00562 virtual void DirtyFont();
00563
00566 virtual void GetRML(String& content);
00567
00568 virtual void OnReferenceDeactivate();
00569
00570 private:
00571 void SetParent(Element* parent);
00572
00573 void ReleaseDeletedElements();
00574 void ReleaseElements(ElementList& elements);
00575
00576 void DirtyOffset();
00577 void UpdateOffset();
00578
00579 void BuildLocalStackingContext();
00580 void BuildStackingContext(ElementList* stacking_context);
00581 void DirtyStackingContext();
00582
00583 void DirtyStructure();
00584
00585
00586 String tag;
00587
00588
00589 String id;
00590
00591
00592 ElementInstancer* instancer;
00593
00594
00595 Element* parent;
00596
00597 Element* focus;
00598
00599
00600 EventDispatcher* event_dispatcher;
00601
00602 ElementStyle* style;
00603
00604 ElementBackground* background;
00605
00606 ElementBorder* border;
00607
00608 ElementDecoration* decoration;
00609
00610 ElementScroll* scroll;
00611
00612 ElementAttributes attributes;
00613
00614
00615 Element* offset_parent;
00616 Vector2f relative_offset_base;
00617 Vector2f relative_offset_position;
00618 bool offset_fixed;
00619
00620 mutable Vector2f absolute_offset;
00621 mutable bool offset_dirty;
00622
00623
00624 Vector2f scroll_offset;
00625
00626
00627 typedef std::vector< Box > BoxList;
00628 BoxList boxes;
00629
00630 Vector2f content_offset;
00631 Vector2f content_box;
00632
00633
00634 Box::Area client_area;
00635
00636
00637 bool visible;
00638
00639 ElementList children;
00640 int num_non_dom_children;
00641
00642 ElementList active_children;
00643 ElementList deleted_children;
00644
00645 float z_index;
00646 bool local_stacking_context;
00647 bool local_stacking_context_forced;
00648
00649 ElementList stacking_context;
00650 bool stacking_context_dirty;
00651
00652
00653 FontFaceHandle* font_face_handle;
00654
00655 friend class Context;
00656 friend class ElementStyle;
00657 friend class LayoutEngine;
00658 friend class LayoutInlineBox;
00659 };
00660
00661 #include <Rocket/Core/Element.inl>
00662
00663 }
00664 }
00665
00666 #endif