summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM/Element.cpp
AgeCommit message (Collapse)Author
2022-03-18LibWeb: Invalidate layout after setting Element.innerHTMLAndreas Kling
It's not enough to only relayout here, since the API can substantially change the DOM. We have to rebuild the layout tree.
2022-03-17Libraries: Use default constructors/destructors in LibWebLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-03-16LibWeb: Don't discard update_style_recursively() return valueAndreas Kling
This was causing us to miss layout invalidations. With this fixed, we can remove the invalidation from Element::recompute_style() along with the associated FIXME. Thanks to Idan for spotting this! :^)
2022-03-16LibWeb: Avoid layout invalidation for some CSS property changesAndreas Kling
Use the new CSS::property_affects_layout() helper to figure out if we actually need to perform a full relayout after recomputing style. There are three tiers of required invalidation after an element receives new style: none, repaint only, or full relayout. This avoids the need to rebuild the layout tree (and perform layout on it) when trivial properties like "color" etc are changed.
2022-03-16LibWeb: Schedule a relayout after setting Element.innerHTMLAndreas Kling
2022-03-16LibWeb: Make Element::set_shadow_root() disconnect any previous rootAndreas Kling
2022-03-15LibWeb: Rename Element::specified_css_values() => computed_css_values()Andreas Kling
Let's make it very clear that these are *computed* values, and not at all the specified values. The specified values are currently discarded by the CSS cascade algorithm.
2022-03-15LibWeb: Rename Element::computed_style() to resolved_css_values()Andreas Kling
This more accurately reflects what's actually being returned.
2022-03-15LibWeb: Actually connect ShadowRoot to its host elementAndreas Kling
This way we can traverse from inside a shadow root across the boundary to the outside. :^)
2022-03-13LibWeb: Make Element::recompute_style() really compare propertiesAndreas Kling
It's not enough to compare StyleProperties pointers to see if something changed, we have to do a deep compare.
2022-03-11LibWeb: Move PaintingBox to its own .cpp and .h filesAndreas Kling
2022-03-11LibWeb: Use Layout::Box::paint_box() accessor in more placesAndreas Kling
2022-03-11LibWeb: Rename Painting::Box => PaintableAndreas Kling
Calling this "Box" made it very confusing to look at code that used both Layout::Box and Painting::Box. Let's try calling it Paintable instead.
2022-03-11LibWeb: Add Painting::Box and move things from Layout::Box into itAndreas Kling
The "paintable" state in Layout::Box was actually not safe to access until after layout had been performed. As a first step towards making this harder to mess up accidentally, this patch moves painting information from Layout::Box to a new class: Painting::Box. Every layout can have a corresponding paint box, and it holds the final used metrics determined by layout. The paint box is created and populated by FormattingState::commit(). I've also added DOM::Node::paint_box() as a convenient way to access the paint box (if available) of a given DOM node. Going forward, I believe this will allow us to better separate data that belongs to layout vs painting, and also open up opportunities for naturally invalidating caches in the paint box (since it's reconstituted by every layout.)
2022-03-10LibWeb: Display pseudo-elements in the DOM inspectorSam Atkins
This patch only makes them appear in the tree - they are not yet inspectable themselves.
2022-03-09LibWeb: Always relayout document on element style changeAndreas Kling
Let's get this right before trying to make it fast. This patch removes the code that tried to do less work when an element's style changes, and instead simply invalidates the entire document. Note that invalidations are still coalesced, and will not be synchronized until update_style() and/or update_layout() is used.
2022-03-08LibWeb: Remove outdated FIXME comment in Namespaces validate_and_extractnetworkException
As step "2. Validate qualifiedName" got implemented in bfa7aad0f6443249ae1a8f577b3150ac32add7a3, parts is known to have a length of 2.
2022-03-04LibWeb: Don't create unwanted layout nodes when recomputing styleAndreas Kling
When recomputing the style for an element that previously didn't have a corresponding layout node, it may become necessary to create a layout node for it. However, we should not do this if it's within a subtree that can't have layout children. Nor should we do it for elements who have an ancestor with display:none.
2022-03-02LibWeb: Support (and validate) prefixes in Document.createElementNS()Andreas Kling
1% progression on ACID3. :^)
2022-03-02LibWeb: Fix bogus result from "validate and extract" DOM operationAndreas Kling
We were returning a QualifiedName with the localName and namespace fields swapped.
2022-02-25LibWeb: Allow all ASCII whitespace chars between element class namesAndreas Kling
1% progression on ACID3. :^)
2022-02-25LibWeb: Extract code for creating a Layout::Node based on display typeSam Atkins
We need to run the same logic for creating the ::before and ::after pseudo-elements, so this saves us from duplicating the code.
2022-02-25LibWeb: Make `display: foo` box constructors take the Element by pointerSam Atkins
This means we can instantiate them for pseudo-elements, which don't have an associated Element. They all pass it to their parent as a `Layout::Node*` and handle a lack of `layout_node()` already so this won't affect any functionality.
2022-02-19LibWeb: Move QualifiedName into the Web::DOM namespaceAndreas Kling
2022-02-16LibWeb: Support Element.closest(selectors)Edwin Hoksberg
2022-02-15LibWeb: Add Element::did_remove_attribute() virtualAndreas Kling
This allows subclasses to react to DOM attributes being removed.
2022-02-13LibWeb: Don't crash on unknown CSS display types, fall back to inlineAndreas Kling
This patch also adds CSS::Display::to_string() so we can log the unimplemented CSS display value (if you have LIBWEB_CSS_DEBUG enabled).
2022-02-12LibWeb: Add stub implementation for Element's getClientRectsDerpyCrabs
getClientRects supposed to return a list of bounding DOMRect for each box fragment of Element's layout, but most elements have only one box fragment, so implementing it with getBoundingClientRect is useful.
2022-02-05LibWeb: Add a partial implementation of Element.setAttributeNS()Andreas Kling
This implementation does some of the required validation and then passes through the localName and value to Element.setAttribute().
2022-02-05LibWeb: Remove CSS::StyleInvalidator in favor of dirtying + lazy updateAndreas Kling
Style updates are lazy since late last year, so the StyleInvalidator is actually hurting us more than it's helping by running the entire CSS selector machine on the whole DOM for every attribute change. Instead, simply mark the entire DOM dirty and let the lazy style update mechanism run *once* on next event loop iteration.
2022-02-05LibWeb: Compute element style in Layout::TreeBuilderAndreas Kling
Instead of making each Layout::Node compute style for itself, we now compute it in TreeBuilder before even calling create_layout_node(). For non-element DOM nodes, we create the style and layout tree node in TreeBuilder. This allows us to move create_layout_node() from DOM::Node to DOM::Element.
2021-12-30LibWeb: Implement Element.getAttributeNamesLuke Wilde
2021-12-05LibWeb: Cast unused smart-pointer return values to voidSam Atkins
2021-11-18LibWeb: Move BrowsingContext into HTML/Andreas Kling
Browsing contexts are defined by the HTML specification, so let's move them into the HTML directory. :^)
2021-10-28LibWeb: Remove two lowercase string creations from Element::has_classTimothy Flynn
2021-10-28LibWeb: Do not create lowercase strings in NamedNodeMap::get_attributeTimothy Flynn
Rather than following the spec exactly and creating lowercase strings, we can simply do a case-insensitive string comparison. The caveat is that creating attributes must follow the spec by creating the attribute name with a lowercase string.
2021-10-18LibWeb: Implement the Element classList attributeTimothy Flynn
And ensure it is updated (if it exists) when the 'class' attribute is changed.
2021-10-17LibWeb: Reimplement Element attribute related methods with NamedNodeMapTimothy Flynn
2021-10-17LibWeb: Set an attribute's owning element when it is knownTimothy Flynn
2021-10-17LibWeb: Implement Attribute closer to the spec and with an IDL fileTimothy Flynn
Note our Attribute class is what the spec refers to as just "Attr". The main differences between the existing implementation and the spec are just that the spec defines more fields. Attributes can contain namespace URIs and prefixes. However, note that these are not parsed in HTML documents unless the document content-type is XML. So for now, these are initialized to null. Web pages are able to set the namespace via JavaScript (setAttributeNS), so these fields may be filled in when the corresponding APIs are implemented. The main change to be aware of is that an attribute is a node. This has implications on how attributes are stored in the Element class. Nodes are non-copyable and non-movable because these constructors are deleted by the EventTarget base class. This means attributes cannot be stored in a Vector or HashMap as these containers assume copyability / movability. So for now, the Vector holding attributes is changed to hold RefPtrs to attributes instead. This might change when attribute storage is implemented according to the spec (by way of NamedNodeMap).
2021-10-12LibWeb: Mark elements for style update after their children changeAndreas Kling
2021-10-06LibWeb: Clean up static function in headerBen Wiederhake
'static' for a function means that the symbol shall not be made public for the result of the current compilation unit. This does not make sense in a header, especially not if it's a large function that is used in more than one place and not that performance-sensitive.
2021-10-06LibWeb: Rename Layout::BlockBox => BlockContainerAndreas Kling
There's a subtle difference here. A "block box" in the spec is a block-level box, while a "block container" is a box whose children are either all inline-level boxes in an IFC, or all block-level boxes participating in a BFC. Notably, an "inline-block" box is a "block container" but not a "block box" since it is itself inline-level.
2021-10-06LibWeb: Start work towards modern CSS "display" valuesAndreas Kling
Until now, we've internally thought of the CSS "display" property as a single-value property. In practice, "display" is a much more complex property that comes in a number of configurations. The most interesting one is the two-part format that describes the outside and inside behavior of a box. Switching our own internal representation towards this model will allow for much cleaner abstractions around layout and the various formatting contexts. Note that we don't *parse* two-part "display" yet, this is only about changing the internal representation of the property. Spec: https://drafts.csswg.org/css-display
2021-10-06LibWeb: Make CSS layout lazierAndreas Kling
Instead of doing layout synchronously whenever something changes, we now use a basic event loop timer to defer and coalesce relayouts. If you did something that requires a relayout of the page, make sure to call Document::set_needs_layout() and it will get coalesced with all the other layout updates. There's lots of room for improvement here, but this already makes many web pages significantly snappier. :^) Also, note that this exposes a number of layout bugs where we have been relying on multiple relayouts to calculate the correct dimensions for things. Now that we only do a single layout in many cases, these kind of problems are much more noticeable. That should also make them easier to figure out and fix. :^)
2021-09-30LibWeb: Support Element.client{Top,Left,Width,Height}Andreas Kling
2021-09-30LibWeb: Support Element.matches(selectors)Andreas Kling
This returns whether an element matches any of a set of selectors.
2021-09-27LibWeb: Add DOMRect and Element.getBoundingClientRect()Andreas Kling
This marks our entry into the Web::Geometry namespace, based on the "Geometry" spec at https://drafts.fxtf.org/geometry/
2021-09-25LibWeb: Rename HTMLDocumentParser => HTMLParserAndreas Kling
2021-09-24LibWeb: Rename CSS::StyleResolver => StyleComputerAndreas Kling
Resolved style is a spec concept that refers to the weird mix of computed style and used style reflected by getComputedStyle(). The purpose of this class is to produce the *computed* style for a given element, so let's call it StyleComputer.