From 3be897a3d563b10821584721e393112b2f8c513a Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Wed, 25 Sep 2019 12:00:50 +0300 Subject: [PATCH] LibHTML: Add ComputedStyle::full_margin() This is an utility to easily get the full margin size (the sum of margin proper, border and padding) of an element in pixels. --- Libraries/LibHTML/Layout/ComputedStyle.cpp | 10 ++++++++++ Libraries/LibHTML/Layout/ComputedStyle.h | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Libraries/LibHTML/Layout/ComputedStyle.cpp b/Libraries/LibHTML/Layout/ComputedStyle.cpp index 2716ff6463a..e5948039ae6 100644 --- a/Libraries/LibHTML/Layout/ComputedStyle.cpp +++ b/Libraries/LibHTML/Layout/ComputedStyle.cpp @@ -7,3 +7,13 @@ ComputedStyle::ComputedStyle() ComputedStyle::~ComputedStyle() { } + +ComputedStyle::PixelBox ComputedStyle::full_margin() const +{ + return { + m_margin.top.to_px() + m_border.top.to_px() + m_padding.top.to_px(), + m_margin.right.to_px() + m_border.right.to_px() + m_padding.right.to_px(), + m_margin.bottom.to_px() + m_border.bottom.to_px() + m_padding.bottom.to_px(), + m_margin.left.to_px() + m_border.left.to_px() + m_padding.left.to_px(), + }; +} diff --git a/Libraries/LibHTML/Layout/ComputedStyle.h b/Libraries/LibHTML/Layout/ComputedStyle.h index c3569005361..2fba7f6275e 100644 --- a/Libraries/LibHTML/Layout/ComputedStyle.h +++ b/Libraries/LibHTML/Layout/ComputedStyle.h @@ -1,8 +1,8 @@ #pragma once -#include #include #include +#include enum FontStyle { Normal, @@ -30,6 +30,15 @@ public: const Size& size() const { return m_size; } Size& size() { return m_size; } + struct PixelBox { + int top; + int right; + int bottom; + int left; + }; + + PixelBox full_margin() const; + private: Color m_text_color; Color m_background_color;