homehtmlayoutcsss!-dom-object

H-SMILE core. CSSS! (css-script) language.

DOM element object

$1() function returns object that represents DOM element.  DOM element as an object supports three types of accessors:

  • element.attribute - access to DOM attributes of the element.
  • element:state-flag - access to runtime flags of the DOM element: hover, active, focus, etc.
  • element::style-attribute - access to style attributes of the DOM element.

DOM element has also various methods that are accessible through the dot notation: domobj.function-name().

DOM element attributes

Any attribute of DOM element can be set or removed from the element.

To remove attribute from element's attribute collection assign null to it:

self.show = true; // will assign value "true" to the show attribute;
self.show = null; // will remove show attribute from
                  // the collection of DOM element attributes.

DOM element state values

Element has synthetic and plain state fields. Following code will set :visited state field for the link element when that link will be clicked.

a:link
{
  click!: self:visited = true;
}

Synthetic state fields:

  • :value - represents value of the DOM element. For input elements that is value of the input element (handled by correspondent behavior attached to the element). For plain DOM elements that is text portion of the element.
  • :index -  is the index of the element in its parent collection. Index is an integer in the range: 1 .. parent().children() .

Plain state fields are all of type boolean. Names of these state flags are exactly the same as correspondent CSS pseudo-classes:

  • :link - any element having href attribute
  • :hover - element is under the cursor, mouse hover
  • :active - element is activated, e.g. pressed
  • :focus - element is in focus
  • :visited - aux flag - not used internally now.
  • :current - current item in collection, e.g. current <option> in <select>
  • :checked - element is checked (or selected), e.g. check box or itme in multiselect
  • :disabled - element is disabled, behavior related flag.
  • :readonly - element is read-only, behavior related flag.
  • :expanded - element is in expanded state - nodes in tree view e.g. <options> in <select>
  • :collapsed - mutually exclusive with EXPANDED
  • :incomplete - element has images (back/fore/bullet) requested but not delivered.
  • :animating - is currently animating
  • :focusable - shall accept focus
  • :anchor - first element in selection (<select miltiple>), :CURRENT is the current.
  • :synthetic - synthesized DOM elements - e.g. all missed cells in tables (<td>) are getting this flag
  • :owns-popup - anchor(owner) element of visible popup.
  • :tab-focus - element got focus by tab traversal. engine set it together with :focus.
  • :empty - element is empty.
  • :busy - element is busy. HTMLayoutRequestElementData will set this flag if external data was requested for the element. When data will be delivered engine will reset this flag on the element.
  • :drag_over - drag over the block that can accept it (so is current drop target). Flag is set for the drop target block. At any given moment of time it can be only one such block.
  • :drop-target - active drop target. Multiple elements can have this flag when D&D is active.
  • :moving - dragging/moving - the flag is set for the moving element (copy of the drag-source).
  • :copying - dragging/copying - the flag is set for the copying element (copy of the drag-source).
  • :drag-source - is set in element that is being dragged.
  • :popup - this element is in popup state and presented to the user - out of flow now
  • :pressed - pressed - close to active but has wider life span - e.g. in MOUSE_UP it is still on, so behavior can check it in MOUSE_UP to discover CLICK condition.
  • :has-children- has more than one child.
  • :has-child - has exactly single child.
  • :ltr -  the element or one of its nearest container has @dir and that dir has "ltr" value.
  • :rtl -  the element or one of its nearest container has @dir and that dir has "rtl" value.

Style attributes of the DOM element

CSSS! allows to set value of all supported CSS attributes. Full list of supported attributes can be found at: http://www.terrainformatica.com/htmlayout/cssmap.whtm

Following style rule will show fade-out effect when some div will get fade-out DOM attribute:

div[fade-out]
{
  assigned!: self::opacity = 1.0, self.start-timer(50);
  timer!: self::opacity < 1.0?
          self::opacity = self::opacity + 0.1 # return cancel /* to stop the timer */;
}

Functions (methods) supported by the DOM element

There is a set of methods that are defined for the DOM element in CSSS! :

  • element.parent() - DOM element, returns parent of the DOM element.
  • element.children() - integer, returns number of children of the element.
  • element.child(n:integer) - DOM element, returns child element at index n. n is a positive number in the range 1..children().
  • element.next() - DOM element, returns next sibling DOM element of this one.
  • element.previous() - DOM element, returns previous sibling DOM element of this one.
  • selectors methods:
    • element.$( selector ) - returns set of elements matching the selector. The method does lookup only among children of the element. :root pseudo class matches the element iself in this metod.  Example: self.$(:root > li):expanded = true will set expanded state for only li elements that are immediate children of the self.
    • element.$1( selector ) - the same as above but will return single element matching the selector.
    • element.$p( selector ) - returns set of parent elements of the element. :root is global DOM root element here.
    • element.$1p( selector ) - returns nearest parent element matching the selector. :root is global DOM root element here.
  • element.start-timer(period:integer) - starts timer on the element with the period (milliseconds). The timer will periodically rise timer! event on the element. To stop timer use either stop-timer() call or return cancel from the timer! event handler.
  • element.stop-timer() - stops timer previously set by the start-timer() method.
  • element.scroll-to-view() - ensures that element is viewable.
  • element.box-type-what() - is a set of methods allowing to retrieve measured metrics of the element. Example:
    self.box-border-width() call will return width (number of pixels) of the border box of the element. type part in the function name is one of:
    • margin - margin box of the element;
    • border - border box of the element;
    • padding - padding box of the element;
    • content - content box of the element (content outline box).
    • inner - inner box of the element;

    what part of the name is one of:

    • left - left side of the box;
    • right - right side of the box;
    • top - top of the box;
    • bottom - bottom side of the box;
    • width - width of the box;
    • height - height of the box;

    Combinations of these names gives in total 30 functions of the element.box-...-...() family.

  • element.x-what() is a set of functions that retrieve relative x position of the element.
    what part in the name can be one of the following:
    • parent - return value of the function is horizontal position of the element relative to its parent;
    • root - position of the element relative to the root element (<html>);
    • view - position of the element relative to the view (window);
    • screen - absolute position of the element on the screen.
  • element.y-what() is a set of functions that retrieve relative y position of the element. what part in the name is the same as above.
  • element.start-animation([duration]) - starts animation that results in calling animation-start!, animation-tick! and animation-end! events. The duration parameter accepts value in seconds: self.start-animation(0.4s) - will start animation that will last 400ms.
  • element.text-width("string") - returns width of the string in pixels measured using current style of the element.
  • element.min-intrinsic-width(), element.max-intrinsic-width() - intrinsic widths of the element.
  • element.min-intrinsic-height(), element.max-intrinsic-height() - intrinsic heights of the element.

HTMLayout

Download

Documentation

Screenshots!

HTMLayout Wrappers