boxtree

package
v0.1.0-experimental.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package boxtree produces a box-tree from a styled tree (DOM).

______________________________________________________________________

BSD License

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

Constants

View Source
const (
	TypePrincipal frame.ContainerType = 100
	TypeAnonymous frame.ContainerType = 101
	TypeText      frame.ContainerType = 102
)

Variables

View Source
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.

View Source
var ErrDOMRootIsNull = errors.New("DOM root is null")
View Source
var ErrNoBoxTreeCreated = errors.New("no box tree created")
View Source
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 BuildBoxTree

func BuildBoxTree(domRoot *dom.W3CNode) (frame.Container, error)

BuildBoxTree creates a render box tree from a styled tree.

func ContainerName

func ContainerName(c frame.Container) string

func NewBoxForDOMNode

func NewBoxForDOMNode(domnode *dom.W3CNode) frame.Container

NewBoxForDOMNode creates an adequately initialized box for a given DOM node.

func T

func T() tracing.Trace

T traces to the engine tracer.

Types

type AnonymousBox

type AnonymousBox struct {
	frame.ContainerBase
	Box *frame.Box // an anoymous box cannot be styled
	// 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 NewAnonymousBox

func NewAnonymousBox(mode css.DisplayMode) *AnonymousBox

func (*AnonymousBox) CSSBox

func (anon *AnonymousBox) CSSBox() *frame.Box

CSSBox returns the underlying box of a render tree element.

func (*AnonymousBox) Context

func (anon *AnonymousBox) Context() frame.Context

func (*AnonymousBox) DOMNode

func (anon *AnonymousBox) DOMNode() *dom.W3CNode

DOMNode returns the underlying DOM node for a render tree element. For anonymous boxes, it returns the DOM node corresponding to the parent container, which should be of type PrincipalBox.

func (*AnonymousBox) PresetContained

func (anon *AnonymousBox) PresetContained() bool

func (*AnonymousBox) SetContext

func (anon *AnonymousBox) SetContext(ctx frame.Context)

func (*AnonymousBox) TreeNode

func (anon *AnonymousBox) TreeNode() *tree.Node

TreeNode returns the underlying tree node for a box.

func (*AnonymousBox) Type

func (anon *AnonymousBox) Type() frame.ContainerType

Type returns TypeAnonymous

type PrincipalBox

type PrincipalBox struct {
	frame.ContainerBase
	Box *frame.StyledBox // styled box for a DOM node
	// 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 NewPrincipalBox

func NewPrincipalBox(domnode *dom.W3CNode, mode css.DisplayMode) *PrincipalBox

NewPrincipalBox creates either a block-level container or an inline-level container

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, at int) 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, at int) 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.

If the child's display mode does not correspond to the context of pbox, an anonymous box may be inserterd.

func (*PrincipalBox) CSSBox

func (pbox *PrincipalBox) CSSBox() *frame.Box

CSSBox returns the underlying box of a render tree element.

func (*PrincipalBox) Context

func (pbox *PrincipalBox) Context() frame.Context

func (*PrincipalBox) DOMNode

func (pbox *PrincipalBox) DOMNode() *dom.W3CNode

DOMNode returns the underlying DOM node for a render tree element.

func (*PrincipalBox) PresetContained

func (pbox *PrincipalBox) PresetContained() bool

func (*PrincipalBox) SetContext

func (pbox *PrincipalBox) SetContext(ctx frame.Context)

func (*PrincipalBox) Type

func (pbox *PrincipalBox) Type() frame.ContainerType

Type returns TypePrincipal

type TextBox

type TextBox struct {
	frame.ContainerBase
	//tree.Node              // a text box is a node within the layout tree
	Box *frame.Box // text box cannot be explicitely styled

	WSCollapse bool
	WSWrap     bool
	// contains filtered or unexported fields
}

TextBox is a provisional type for CSS inline text boxes. It references a text node in the DOM. Text boxes will in a later stage be replaced by line boxes, which will subsume all text boxes under a common parent.

func NewTextBox

func NewTextBox(domnode *dom.W3CNode) *TextBox

func (*TextBox) CSSBox

func (tbox *TextBox) CSSBox() *frame.Box

CSSBox returns the underlying box of a render tree element.

func (*TextBox) Context

func (tbox *TextBox) Context() frame.Context

func (*TextBox) DOMNode

func (tbox *TextBox) DOMNode() *dom.W3CNode

DOMNode returns the underlying DOM node for a render tree element.

func (*TextBox) PresetContained

func (tbox *TextBox) PresetContained() bool

func (*TextBox) SetContext

func (tbox *TextBox) SetContext(frame.Context)

func (*TextBox) Type

func (tbox *TextBox) Type() frame.ContainerType

Type returns TypeText

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL