summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML/Layout/LayoutNode.cpp
AgeCommit message (Collapse)Author
2020-03-07LibWeb: Rename directory LibHTML => LibWebAndreas Kling
Let's rename this to LibWeb since it aims to provide more parts of the web platform than just HTML. :^)
2020-03-07LibWeb: Move everything into the Web namespaceAndreas Kling
2020-02-06LibGUI: Remove leading G from filenamesAndreas Kling
2020-02-06LibGfx: Unpublish FloatPoint from the global namespaceAndreas Kling
2020-02-06LibDraw: Put all classes in the Gfx namespaceAndreas Kling
I started adding things to a Draw namespace, but it somehow felt really wrong seeing Draw::Rect and Draw::Bitmap, etc. So instead, let's rename the library to LibGfx. :^)
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-11-18LibHTML: Use floating point numbers throughout the layout treeAndreas Kling
2019-11-04LibHTML: Add a convenient way to get from any layout node to the rootAndreas Kling
2019-10-20LibHTML: Implement "text-align: justify"Andreas Kling
In order for this to work nicely, I made the line box classes use float instead of int for its geometry information. Justification works by distributing all of the whitespace on the line (including the trailing whitespace before the line break) evenly across the spaces in-between words. We should probably use floating point (or maybe fixed point?) for all the layout metrics stuff. But one thing at a time. :^)
2019-10-20LibHTML+Browser: Support scrolling to anchor with <a href="#foo">Andreas Kling
This patch implements basic support for <a href="#foo"> fragment links. To figure out where we actually want to scroll to, we have to do something different based on the layout node's box type. So if it's a regular LayoutBox we can just use the LayoutBox::position(). However, if it's an inline layout node, we use the position of the first line box fragment in the containing block contributed by this layout node or one of its descendants.
2019-10-15LibHTML: LayoutNode::set_needs_display() needs to invalidate fragmentsAndreas Kling
If a LayoutNode is split into line box fragments, we need to walk our fragments and invalidate them. It was not enough to do this only for LayoutBox nodes.
2019-10-15LibHTML: Introduce LayoutBox and LayoutNodeWithStyleAndBoxModelMetricsAndreas Kling
To streamline the layout tree and remove irrelevant data from classes that don't need it, this patch adds two new LayoutNode subclasses. LayoutNodeWithStyleAndBoxModelMetrics should be inherited by any layout node that cares about box model metrics (margin, border, and padding.) LayoutBox should be inherited by any layout node that can have a rect. This makes LayoutText significantly smaller (from 140 to 40 bytes) and clarifies a lot of things about the layout tree. I'm also adding next_sibling() and previous_sibling() overloads to LayoutBlock that return a LayoutBlock*. This is okay since blocks only ever have block siblings. Do also note that the semantics of is<T> slightly change in this patch: is<T>(nullptr) now returns true, to facilitate allowing to<T>(nullptr).
2019-10-15LibHTML: Add is<T> and to<T> helpers for LayoutNode class familyAndreas Kling
2019-10-13LibHTML: Add some convenient geometry getters on LayoutNodeAndreas Kling
Add x(), y(), size() and position() and use them around the codebase.
2019-10-13LibHTML: Move layout root from HtmlView to DocumentAndreas Kling
The layout root is now kept alive via Document::m_layout_root. This will allow us to do more layout-related things inside the inner layer of LibHTML without reaching out to the HtmlView. I'd like to keep HtmlView at a slightly higher level, to prevent it from getting too complex. This patch also fixes accidental disconnection of the layout tree from the DOM after doing a layout tree rebuild. ~LayoutNode() now only unsets the DOM node's layout_node() if it's itself.
2019-10-09LibHTML: Implement the <blink> elementAndreas Kling
Just in time for Serenity's 1st birthday, here is the <blink> element! This patch adds a bunch of different mechanisms to enable partial repaints of the layout tree (LayoutNode::set_needs_display())) It also adds LayoutNode::is_visible(), which can be toggled to prevent a LayoutNode from rendering anything (it still takes up space though.)
2019-10-08LibHTML: Use an enum for CSS property ID'sAndreas Kling
Instead of using string everywhere, have the CSS parser produce enum values, since they are a lot nicer to work with. In the future we should generate most of this code based on a list of supported CSS properties.
2019-10-07LibHTML: Add LayoutNodeWithStyle class, make LayoutText style-lessAndreas Kling
Since LayoutText always inherits style, it shouldn't store any style of its own. This patch adds a LayoutNodeWithStyle class to sit between LayoutNode and everyone who wants to inherit from LayoutNode except LayoutText :^) Since LayoutText can never have children, we also know that the parent of any LayoutNode is always going to be a LayoutNodeWithStyle. So this patch makes LayoutNode::parent() return LayoutNodeWithStyle*.
2019-10-07LibHTML: Rename "style_properties" to "style" everywhereAndreas Kling
2019-10-06LibHTML: Respect the link color set via <body link>Andreas Kling
The default style for "a" tags now has { color: -libhtml-link; }. We implement this vendor-specific property by querying the containing document for the appropriate link color. Currently we only use the basic link color, but in the future this can be extended to remember visited links, etc.
2019-10-05LibHTML: Implement basic layout for inline <img alt>Andreas Kling
LayoutReplaced objects can now participate in inline layout. It's very hackish, but basically LayoutReplaced will just add itself to the last line in the containing block. This patch gets rid of the idea that only LayoutInline subclasses can be split into lines, by moving the split_into_lines() virtual up to LayoutNode and overriding it in LayoutReplaced.
2019-10-04LibHTML: Add support for <body bgcolor="#rrggbb" text="#rrggbb">Andreas Kling
This patch implements basic support for presentational hints, which are old-school HTML attributes that affect style. You add support for a presentational hint attribute by overriding Element::apply_presentational_hints(StyleProperties&) and setting all of the corresponding CSS properties as appropriate. To make the background color fill the entire document, not just the bounds of the <body> element's LayoutNode, we special-case it in the HtmlView::paint_event() code for now. I'm not entirely sure what the nicest solution would be, but I'm sure we'll discover it eventually.
2019-10-04LibHTML: Rename LayoutNode::style_properties() to LayoutNode::style()Andreas Kling
2019-10-04LibHTML: Rename ComputedStyle to BoxModelMetricsAndreas Kling
There was nothing left in ComputedStyle except the box model metrics, so this patch gives it a more representative name. Note that style information is fetched directly from StyleProperties, which is basically the CSS property name/value pairs that apply to an element.
2019-10-04LibHTML: LayoutText should always use parent's style propertiesAndreas Kling
This patch makes StyleProperties heap-allocated and ref-counted so that a LayoutNode can be without one. The ref-counting also allows anonymous blocks to share style with their parent block. LayoutText never needs a StyleProperties, since text always inherits style from its parent element. This is handled by style_properties().
2019-10-01LibHTML: Implement the <hr> elementAndreas Kling
This also meant I had to implement basic support for the border-styles "inset" and "outset". If it's neither of those, we default to "solid".
2019-10-01LibHTML: Implement basic border renderingAndreas Kling
We currently assume the border-style is solid, and simply draw a box around the padded LayoutNode rect. :^)
2019-10-01LibHTML: Include padding when rendering background colorsAndreas Kling
2019-09-29LibHTML: Implement basic support for background-colorAndreas Kling
2019-09-29LibHTML: Have Document track its hovered NodeAndreas Kling
This gets set from HtmlView::mousemove_event() at the moment.
2019-09-29LibHTML: Add LayoutNode::document() for easy accessAndreas Kling
Every LayoutNode indirectly belongs to some Document. For anonymous LayoutNodes, we simply traverse the parent chain until we find someone with a Node from which we can get a Document&.
2019-09-29LibHTML: Make hit testing work for LayoutTextAndreas Kling
LayoutText can't simply rely on its LayoutNode::rect() for hit testing. Instead, we have to iterate over the individual runs and see if we're hitting any of them. Also, LayoutNode::hit_test() now always recurses into children, since we can't trust the rect() to tell the truth (inline rects are wrong.)
2019-09-28LibHTML: Implement naive hit testingAndreas Kling
We don't have proper line boxes yet, so we can't easily hit test inline text.
2019-09-28LibHTML: Implement renderingSergey Bugaev
2019-09-28LibHTML: Get rid of the style treeSergey Bugaev
We now create a layout tree directly from the DOM tree. This way we don't actually lose text nodes ^)
2019-07-08LibHTML: Create anonymous blocks around inline children of blocks.Andreas Kling
2019-07-04Libraries: Create top level directory for libraries.Andreas Kling
Things were getting a little crowded in the project root, so this patch moves the Lib*/ directories into Libraries/.