layout

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: 11 Imported by: 0

README

LibNSLayout Architecture

LibNSLayout is a library for performing layout on a Document Object Model for HTML. Its purpose is to allow client applications to provide DOM information and convert that into a render list, which can be displayed by the client.

Dependencies

Clients of LibNSLayout must use the following additional libraries, because their types are used in the LibNSLayout interface:

  • LibDOM is used to provide the DOM interface.
  • LibCSS is used to provide the CSS handling.
  • LibWapcaplet is used for interned strings.
  • LibNSLog for logging.

Interface

The devision of responsibilities between LibNSLayout and its clients are as follows:

Client
  • Fetching the document to be displayed.
  • Creating a CSS selection context (with default user-agent, and user CSS).
  • Generating DOM.
  • Creating a LibNSLayout layout for the document, passing the DOM document, CSS selection context, appropriate CSS media descriptor, and scale.
  • Listening to DOM changes.
    • Fetching resources needed by DOM.
      • CSS (STYLE elements, and LINK elements):
        • Parsing the CSS.
        • Updating CSS selection context as stylesheets are fetched, and notifying LibNSLayout.
      • JavaScript (SCRIPT elements, and LINK elements)
        • Executing JavaScript.
      • Favicons (LINK elements.)
      • Images, Frames, Iframes.
    • Notifying LibNSLayout of DOM changes.
  • Performing resource fetches on behalf of LibNSLayout.
    • (Such as when LibNSLayout requires a background image or web font for an element due to CSS.)
  • Asking LibNSLayout to perform layout.
    • Displaying the returned render list.
  • Asking LibNSLayout for layout info (e.g. due to JavaScript.)
  • Passing mouse actions to LibNSLayout.
  • Passing keyboard input to LibNSLayout.
  • Passing scale changes to LibNSLayout.
  • Performing measurement of text; given a string & style, calculating its width in pixels.
LibNSLayout
  • Creates a layout object that's opaque to the client, and returns its handle.
  • Performs CSS selection as appropriate when DOM changes.
  • Asking client to fetch a resource that's needed for a computed style.
  • Asking client to measure text.
  • Performs line breaking.
  • Performs layout (if required) when asked by client and returns render list.
  • Performs layout (if required) when asked by client for layout info.

Box Layout

Module Layout is responsible for creating the render trecreating the render tree. This includes line-breaking for paragraphs.

When the client requires a layout, we would then walk the tree, ensuring every layout node has a valid x, y, width, and height.

Rendering

The client is responsible for rendering, and any compositing. When the client asks the layouter to layout, we return a render list.

Documentation

Overview

Package layout produces a render tree from a styled tree.

Overview

Early draft, nothing useful here yet.

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 (
	TypeBlockFormattingContext  frame.FormattingContextType = 100
	TypeInlineFormattingContext frame.FormattingContextType = 101
)

Variables

View Source
var ErrEnclosingWidthNotFixed error = errors.New("enclosing width not fixed")
View Source
var ErrHeightNotFixed error = errors.New("height of context not determined")
View Source
var ErrNotAPercentageDimension error = errors.New("input dimension not a percentage dimension")

Functions

func BoxTreeToLayoutTree

func BoxTreeToLayoutTree(boxRoot *boxtree.PrincipalBox, view *View) (syn synthesizedParams)

func CalcBlockWidths

func CalcBlockWidths(c frame.Container, inherited inheritedParams) (syn synthesizedParams)

Potentially recursive call to nested containers

func LayoutBlockFormattingContext

func LayoutBlockFormattingContext(ctx frame.Context, flowRoot *frame.FlowRoot) *frame.Box

func LayoutInlineFormattingContext

func LayoutInlineFormattingContext(ctx frame.Context, flowRoot *frame.FlowRoot) *frame.Box

func NewContextFor

func NewContextFor(c frame.Container) frame.Context

NewContextFor creates a formatting context for a container. If c already has a context set, this context will be returned.

func SolveWidthBottomUp

func SolveWidthBottomUp(c frame.Container, enclosing dimen.Dimen) (*frame.Box, error)

func T

func T() tracing.Trace

T traces to the engine tracer.

Types

type BlockContext

type BlockContext struct {
	frame.ContextBase
}

BlockContext establishes a CSS block formatting context.

“Block-level boxes are boxes that participate in a block formatting context. Each block-level element generates a principal block-level box that contains descendant boxes and generated content and is also the box involved in any positioning scheme. Some block-level elements may generate additional boxes in addition to the principal box [for example,]: 'list-item' elements. These additional boxes are placed with respect to the principal box.”

A new BFC will behave much like the outermost document in that it becomes a mini-layout inside the main layout. A BFC contains everything inside it, float and clear only apply to items inside the same formatting context, and margins only collapse between elements in the same formatting context.

func Block

func Block(ctx frame.Context) *BlockContext

func NewBlockContext

func NewBlockContext(c frame.Container, isRoot bool) *BlockContext

func (*BlockContext) AddContained

func (ctx *BlockContext) AddContained(c frame.Container)

func (*BlockContext) Layout

func (ctx *BlockContext) Layout(flowRoot *frame.FlowRoot) error

func (*BlockContext) Measure

func (ctx *BlockContext) Measure() (frame.Size, css.DimenT, css.DimenT)

func (*BlockContext) Type

type Event

type Event struct {
	// contains filtered or unexported fields
}

func NewEvent

func NewEvent(prio uint8, etype EventType) *Event

type EventQ

type EventQ struct {
	// contains filtered or unexported fields
}

A EventQ implements heap.Interface and holds events.

func (EventQ) Len

func (q EventQ) Len() int

Len is part of interface container/heap.

func (EventQ) Less

func (q EventQ) Less(i, j int) bool

Less is part of interface container/heap.

func (*EventQ) Pop

func (q *EventQ) Pop() interface{}

Pop is part of interface container/heap. Not intended for client use.

func (*EventQ) PopEvent

func (q *EventQ) PopEvent() *Event

PopEvent pops an event from the head of the queue.

func (*EventQ) Push

func (q *EventQ) Push(x interface{})

Push is part of interface container/heap. Not intended for client use.

func (*EventQ) PushEvent

func (q *EventQ) PushEvent(e *Event)

PushEvent pushes an event onto the queue.

func (EventQ) Swap

func (q EventQ) Swap(i, j int)

Swap is part of interface container/heap.

func (*EventQ) Update

func (q *EventQ) Update(e *Event, prio uint8)

Update modifies the priority of an event in the queue.

type EventType

type EventType uint8
const (
	VoidEvent EventType = iota
	ReflowEvent
	AbortEvent
)

type InlineContext

type InlineContext struct {
	frame.ContextBase
	// contains filtered or unexported fields
}

func Inline

func Inline(ctx frame.Context) *InlineContext

func NewInlineContext

func NewInlineContext(c frame.Container, isRoot bool) *InlineContext

func (*InlineContext) AddContained

func (ctx *InlineContext) AddContained(c frame.Container)

func (*InlineContext) Layout

func (ctx *InlineContext) Layout(flowRoot *frame.FlowRoot) error

func (*InlineContext) Measure

func (ctx *InlineContext) Measure() (frame.Size, css.DimenT, css.DimenT)

func (*InlineContext) Type

type Page

type Page struct {
	dimen.Rect // page size
	// contains filtered or unexported fields
}

func NewPage

func NewPage(papersize dimen.Point) *Page

type View

type View struct {
	Width dimen.Dimen
}

Jump to

Keyboard shortcuts

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