summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-09 23:53:41 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-11 00:21:49 +0100
commita4d51b3dc22d2fb4abad7b19e4ec424261707e27 (patch)
tree85dbbefdd825d99e8a3cc4b77dbd69ccf02006ab /Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
parentdb404af6df5d0d9fd17cea345bea8989a9473e60 (diff)
downloadserenity-a4d51b3dc22d2fb4abad7b19e4ec424261707e27.zip
LibWeb: Add Painting::Box and move things from Layout::Box into it
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.)
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
index b2e3c4d94b..3dba508a0d 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -13,6 +13,7 @@
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/Layout/ImageBox.h>
#include <LibWeb/Loader/ResourceLoader.h>
+#include <LibWeb/Painting/Box.h>
namespace Web::HTML {
@@ -84,8 +85,8 @@ unsigned HTMLImageElement::width() const
const_cast<DOM::Document&>(document()).update_layout();
// Return the rendered width of the image, in CSS pixels, if the image is being rendered.
- if (layout_node() && is<Layout::Box>(*layout_node()))
- return static_cast<Layout::Box const&>(*layout_node()).content_width();
+ if (auto* paint_box = this->paint_box())
+ return paint_box->content_width();
// ...or else the density-corrected intrinsic width and height of the image, in CSS pixels,
// if the image has intrinsic dimensions and is available but not being rendered.
@@ -107,8 +108,8 @@ unsigned HTMLImageElement::height() const
const_cast<DOM::Document&>(document()).update_layout();
// Return the rendered height of the image, in CSS pixels, if the image is being rendered.
- if (layout_node() && is<Layout::Box>(*layout_node()))
- return static_cast<Layout::Box const&>(*layout_node()).content_height();
+ if (auto* paint_box = this->paint_box())
+ return paint_box->content_height();
// ...or else the density-corrected intrinsic height and height of the image, in CSS pixels,
// if the image has intrinsic dimensions and is available but not being rendered.