Documentation
¶
Overview ¶
Package layout produces a render tree from a styled tree.
Overview ¶
Early draft, nothing useful here yet.
BSD License ¶
Copyright (c) 2017–2020, Norbert Pillmayer ¶
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of this software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Index ¶
- Variables
- func DefaultDisplayModeForHTMLNode(h *html.Node) (DisplayMode, DisplayMode)
- func DisplayModesForDOMNode(domnode *dom.W3CNode) (outerMode DisplayMode, innerMode DisplayMode)
- func ParseDisplay(display string) (DisplayMode, DisplayMode, error)
- func ReorderBoxTree(boxRoot *PrincipalBox) error
- func T() tracing.Trace
- type AnonymousBox
- func (anon *AnonymousBox) ChildIndices() (uint32, uint32)
- func (anon *AnonymousBox) DOMNode() w3cdom.Node
- func (anon *AnonymousBox) DisplayModes() (DisplayMode, DisplayMode)
- func (anon *AnonymousBox) IsAnonymous() bool
- func (anon *AnonymousBox) IsText() bool
- func (anon *AnonymousBox) String() string
- func (anon *AnonymousBox) TreeNode() *tree.Node
- type Container
- type DisplayMode
- type PrincipalBox
- func (pbox *PrincipalBox) AddChild(child *PrincipalBox) error
- func (pbox *PrincipalBox) AddTextChild(child *TextBox) error
- func (pbox *PrincipalBox) AppendChild(child *PrincipalBox)
- func (pbox *PrincipalBox) ChildIndices() (uint32, uint32)
- func (pbox *PrincipalBox) DOMNode() w3cdom.Node
- func (pbox *PrincipalBox) DisplayModes() (DisplayMode, DisplayMode)
- func (pbox *PrincipalBox) IsAnonymous() bool
- func (pbox *PrincipalBox) IsPrincipal() bool
- func (pbox *PrincipalBox) IsText() bool
- func (pbox *PrincipalBox) String() string
- func (pbox *PrincipalBox) TreeNode() *tree.Node
- type TextBox
Constants ¶
This section is empty.
Variables ¶
var ErrAnonBoxNotFound = fmt.Errorf("No anonymous box found for index")
ErrAnonBoxNotFound flags an error condition where an anonymous box should be present but could not be found.
var ErrNullChild = fmt.Errorf("Child box max not be null")
ErrNullChild flags an error condition when a non-nil child has been expected.
Functions ¶
func DefaultDisplayModeForHTMLNode ¶
func DefaultDisplayModeForHTMLNode(h *html.Node) (DisplayMode, DisplayMode)
DefaultDisplayModeForHTMLNode returns the default display mode for a HTML node type, as described by the CSS specification.
TODO possibly move this to package style (= part of browser defaults) If, then return a string.
func DisplayModesForDOMNode ¶
func DisplayModesForDOMNode(domnode *dom.W3CNode) (outerMode DisplayMode, innerMode DisplayMode)
DisplayModesForDOMNode returns outer and inner display mode for a given DOM node.
func ParseDisplay ¶
func ParseDisplay(display string) (DisplayMode, DisplayMode, error)
ParseDisplay returns mode flags from a display property string (outer and inner).
func ReorderBoxTree ¶
func ReorderBoxTree(boxRoot *PrincipalBox) error
ReorderBoxTree reorders box nodes of a render tree to account for "position" CSS properties. In a future version, CSS regions will be supported as well.
Types ¶
type AnonymousBox ¶
type AnonymousBox struct { tree.Node // an anonymous box is a node within the layout tree Box *box.Box // an anoymous box cannot be styled ChildInxFrom uint32 // this box represents children starting at #ChildInxFrom of the principal box ChildInxTo uint32 // this box represents children to #ChildInxTo // contains filtered or unexported fields }
AnonymousBox is a type for CSS anonymous boxes.
From the spec: "If a container box (inline or block) has a block-level box inside it, then we force it to have only block-level boxes inside it."
These block-level boxes are anonymous boxes. There are anonymous inline-level boxes, too. Both are not directly stylable by the user, but rather inherit the styles of their principal boxes.
func (*AnonymousBox) ChildIndices ¶
func (anon *AnonymousBox) ChildIndices() (uint32, uint32)
ChildIndices returns the positional indices of all child-boxes in reference to the principal box.
func (*AnonymousBox) DOMNode ¶
func (anon *AnonymousBox) DOMNode() w3cdom.Node
DOMNode returns the underlying DOM node for a render tree element.
func (*AnonymousBox) DisplayModes ¶
func (anon *AnonymousBox) DisplayModes() (DisplayMode, DisplayMode)
DisplayModes returns outer and inner display mode of this box.
func (*AnonymousBox) IsAnonymous ¶
func (anon *AnonymousBox) IsAnonymous() bool
IsAnonymous will always return true for an anonymous box.
func (*AnonymousBox) IsText ¶
func (anon *AnonymousBox) IsText() bool
IsText will always return false for an anonymous box.
func (*AnonymousBox) String ¶
func (anon *AnonymousBox) String() string
func (*AnonymousBox) TreeNode ¶
func (anon *AnonymousBox) TreeNode() *tree.Node
TreeNode returns the underlying tree node for a box.
type Container ¶
type Container interface { DOMNode() w3cdom.Node TreeNode() *tree.Node IsAnonymous() bool IsText() bool DisplayModes() (DisplayMode, DisplayMode) ChildIndices() (uint32, uint32) }
Container is an interface type for render tree nodes, i.e., boxes.
func BuildBoxTree ¶
BuildBoxTree creates a render box tree from a styled tree.
func NewBoxForDOMNode ¶
NewBoxForDOMNode creates an adequately initialized box for a given DOM node.
type DisplayMode ¶
type DisplayMode uint16
DisplayMode is a type for CSS property "display".
const ( NoMode DisplayMode = iota // unset or error condition DisplayNone DisplayMode = 0x0001 // CSS outer display = none FlowMode DisplayMode = 0x0002 // CSS inner display = flow BlockMode DisplayMode = 0x0004 // CSS block context (inner or outer) InlineMode DisplayMode = 0x0008 // CSS inline context ListItemMode DisplayMode = 0x0010 // CSS list-item display FlowRoot DisplayMode = 0x0020 // CSS flow-root display property FlexMode DisplayMode = 0x0040 // CSS inner display = flex GridMode DisplayMode = 0x0080 // CSS inner display = grid TableMode DisplayMode = 0x0100 // CSS table display property (inner or outer) ContentsMode DisplayMode = 0x0200 // CSS contents display mode, experimental ! )
Flags for box context and display mode (outer and inner).
func (DisplayMode) Contains ¶
func (disp DisplayMode) Contains(d DisplayMode) bool
Contains checks if a display mode contains a given atomic mode. Returns false for d = NoMode.
func (DisplayMode) FullString ¶
func (disp DisplayMode) FullString() string
FullString returns all atomic modes set in a display mode.
func (DisplayMode) Overlaps ¶
func (disp DisplayMode) Overlaps(d DisplayMode) bool
Overlaps returns true if a given display mode shares at least one atomic mode flag with disp (excluding NoMode).
func (*DisplayMode) Set ¶
func (disp *DisplayMode) Set(d DisplayMode)
Set sets a given atomic mode within this display mode.
func (DisplayMode) String ¶
func (i DisplayMode) String() string
func (DisplayMode) Symbol ¶
func (disp DisplayMode) Symbol() string
Symbol returns a Unicode symbol for a mode.
type PrincipalBox ¶
type PrincipalBox struct { tree.Node // a container is a node within the layout tree Box *box.StyledBox // styled box for a DOM node ChildInx uint32 // this box represents child #ChildInx of the parent principal box // contains filtered or unexported fields }
PrincipalBox is a (CSS-)styled box which may contain other boxes. It references a node in the styled tree, i.e., a stylable DOM element node.
func TreeNodeAsPrincipalBox ¶
func TreeNodeAsPrincipalBox(n *tree.Node) *PrincipalBox
TreeNodeAsPrincipalBox retrieves the payload of a tree node as a PrincipalBox. Will be called from clients as
box := layout.PrincipalBoxFromNode(n)
func (*PrincipalBox) AddChild ¶
func (pbox *PrincipalBox) AddChild(child *PrincipalBox) error
AddChild appends a child box to its parent principal box. The child is a principal box itself, i.e. references a styleable DOM node. The child must have its child index set.
func (*PrincipalBox) AddTextChild ¶
func (pbox *PrincipalBox) AddTextChild(child *TextBox) error
AddTextChild appends a child box to its parent principal box. The child is a text box, i.e., references a HTML text node. The child must have its child index set.
func (*PrincipalBox) AppendChild ¶
func (pbox *PrincipalBox) AppendChild(child *PrincipalBox)
AppendChild appends a child box to a principal box. The child is a principal box itself, i.e. references a styleable DOM node. It is appended as the last child of pbox.
func (*PrincipalBox) ChildIndices ¶
func (pbox *PrincipalBox) ChildIndices() (uint32, uint32)
ChildIndices returns the positional index of this box reference to the parent principal box. To comply with the PrincipalBox interface, it returns the index twice (from, to).
func (*PrincipalBox) DOMNode ¶
func (pbox *PrincipalBox) DOMNode() w3cdom.Node
DOMNode returns the underlying DOM node for a render tree element.
func (*PrincipalBox) DisplayModes ¶
func (pbox *PrincipalBox) DisplayModes() (DisplayMode, DisplayMode)
DisplayModes returns outer and inner display mode of this box.
func (*PrincipalBox) IsAnonymous ¶
func (pbox *PrincipalBox) IsAnonymous() bool
IsAnonymous will always return false for a container.
func (*PrincipalBox) IsPrincipal ¶
func (pbox *PrincipalBox) IsPrincipal() bool
IsPrincipal returns true if this is a principal box.
Some HTML elements create a mini-hierachy of boxes for rendering. The outermost box is called the principal box. It will always refer to the styled node. An example would be an "li"-element: it will create two sub-boxes, one for the list item marker and one for the item's text/content. Another example are anonymous boxes, which will be generated for reconciling context/level-discrepancies.
func (*PrincipalBox) IsText ¶
func (pbox *PrincipalBox) IsText() bool
IsText will always return false for a principal box.
func (*PrincipalBox) String ¶
func (pbox *PrincipalBox) String() string
func (*PrincipalBox) TreeNode ¶
func (pbox *PrincipalBox) TreeNode() *tree.Node
TreeNode returns the underlying tree node for a box.
type TextBox ¶
type TextBox struct { tree.Node // a text box is a node within the layout tree Box *box.Box // text box cannot be explicitely styled //outerMode DisplayMode // container lives in this mode (block or inline) ChildInx uint32 // this box represents a text node at #ChildInx of the principal box // contains filtered or unexported fields }
TextBox is a type for CSS inline text boxes. It references a text node in the DOM. They are not directly stylable by the user, but rather inherit the styles of their principal boxes. Text boxes have an inner display type of inline.
func (*TextBox) ChildIndices ¶
ChildIndices returns the positional index of the text node in reference to the principal box. To comply with the PrincipalBox interface, it returns the index twice (from, to).
func (*TextBox) DisplayModes ¶
func (tbox *TextBox) DisplayModes() (DisplayMode, DisplayMode)
DisplayModes always returns inline.
func (*TextBox) IsAnonymous ¶
IsAnonymous will always return true for a text box.