LibWeb: Split GridAreaShorthandStyleValue out of StyleValue.{h,cpp}

This commit is contained in:
Sam Atkins 2023-03-24 14:48:19 +00:00 committed by Linus Groh
parent 4dc99e49a1
commit 675cb3b9da
Notes: sideshowbarker 2024-07-17 08:45:34 +09:00
8 changed files with 100 additions and 55 deletions

View file

@ -77,6 +77,7 @@ set(SOURCES
CSS/StyleValues/FlexFlowStyleValue.cpp
CSS/StyleValues/FlexStyleValue.cpp
CSS/StyleValues/FontStyleValue.cpp
CSS/StyleValues/GridAreaShorthandStyleValue.cpp
CSS/StyleValues/GridTemplateAreaStyleValue.cpp
CSS/Supports.cpp
CSS/SyntaxHighlighter/SyntaxHighlighter.cpp

View file

@ -43,6 +43,7 @@
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
#include <LibWeb/CSS/StyleValues/FontStyleValue.h>
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Dump.h>

View file

@ -18,6 +18,7 @@
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Layout/Viewport.h>

View file

@ -34,6 +34,7 @@
#include <LibWeb/CSS/StyleValues/FlexFlowStyleValue.h>
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
#include <LibWeb/CSS/StyleValues/FontStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/FontCache.h>

View file

@ -25,6 +25,7 @@
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
#include <LibWeb/CSS/StyleValues/FontStyleValue.h>
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/BrowsingContext.h>
@ -1035,20 +1036,6 @@ ErrorOr<String> GridTrackPlacementShorthandStyleValue::to_string() const
return String::formatted("{} / {}", TRY(m_properties.start->grid_track_placement().to_string()), TRY(m_properties.end->grid_track_placement().to_string()));
}
ErrorOr<String> GridAreaShorthandStyleValue::to_string() const
{
StringBuilder builder;
if (!m_properties.row_start->as_grid_track_placement().grid_track_placement().is_auto())
TRY(builder.try_appendff("{}", TRY(m_properties.row_start->as_grid_track_placement().grid_track_placement().to_string())));
if (!m_properties.column_start->as_grid_track_placement().grid_track_placement().is_auto())
TRY(builder.try_appendff(" / {}", TRY(m_properties.column_start->as_grid_track_placement().grid_track_placement().to_string())));
if (!m_properties.row_end->as_grid_track_placement().grid_track_placement().is_auto())
TRY(builder.try_appendff(" / {}", TRY(m_properties.row_end->as_grid_track_placement().grid_track_placement().to_string())));
if (!m_properties.column_end->as_grid_track_placement().grid_track_placement().is_auto())
TRY(builder.try_appendff(" / {}", TRY(m_properties.column_end->as_grid_track_placement().grid_track_placement().to_string())));
return builder.to_string();
}
ErrorOr<String> GridTrackPlacementStyleValue::to_string() const
{
return m_grid_track_placement.to_string();

View file

@ -714,47 +714,6 @@ private:
} m_properties;
};
class GridAreaShorthandStyleValue final : public StyleValueWithDefaultOperators<GridAreaShorthandStyleValue> {
public:
static ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> create(
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end)
{
return adopt_ref(*new GridAreaShorthandStyleValue(row_start, column_start, row_end, column_end));
}
static ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> create(GridTrackPlacement row_start, GridTrackPlacement column_start, GridTrackPlacement row_end, GridTrackPlacement column_end)
{
return adopt_ref(*new GridAreaShorthandStyleValue(GridTrackPlacementStyleValue::create(row_start), GridTrackPlacementStyleValue::create(column_start), GridTrackPlacementStyleValue::create(row_end), GridTrackPlacementStyleValue::create(column_end)));
}
virtual ~GridAreaShorthandStyleValue() override = default;
auto row_start() const { return m_properties.row_start; }
auto column_start() const { return m_properties.column_start; }
auto row_end() const { return m_properties.row_end; }
auto column_end() const { return m_properties.column_end; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(GridAreaShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
private:
GridAreaShorthandStyleValue(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end)
: StyleValueWithDefaultOperators(Type::GridAreaShorthand)
, m_properties { .row_start = move(row_start), .column_start = move(column_start), .row_end = move(row_end), .column_end = move(column_end) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start;
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start;
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end;
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end;
bool operator==(Properties const&) const = default;
} m_properties;
};
class GridTrackSizeStyleValue final : public StyleValueWithDefaultOperators<GridTrackSizeStyleValue> {
public:
static ValueComparingNonnullRefPtr<GridTrackSizeStyleValue> create(CSS::GridTrackSizeList grid_track_size_list);

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "GridAreaShorthandStyleValue.h"
namespace Web::CSS {
ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> GridAreaShorthandStyleValue::create(
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end)
{
return adopt_ref(*new GridAreaShorthandStyleValue(row_start, column_start, row_end, column_end));
}
ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> GridAreaShorthandStyleValue::create(GridTrackPlacement row_start, GridTrackPlacement column_start, GridTrackPlacement row_end, GridTrackPlacement column_end)
{
return adopt_ref(*new GridAreaShorthandStyleValue(GridTrackPlacementStyleValue::create(row_start), GridTrackPlacementStyleValue::create(column_start), GridTrackPlacementStyleValue::create(row_end), GridTrackPlacementStyleValue::create(column_end)));
}
ErrorOr<String> GridAreaShorthandStyleValue::to_string() const
{
StringBuilder builder;
if (!m_properties.row_start->as_grid_track_placement().grid_track_placement().is_auto())
TRY(builder.try_appendff("{}", TRY(m_properties.row_start->as_grid_track_placement().grid_track_placement().to_string())));
if (!m_properties.column_start->as_grid_track_placement().grid_track_placement().is_auto())
TRY(builder.try_appendff(" / {}", TRY(m_properties.column_start->as_grid_track_placement().grid_track_placement().to_string())));
if (!m_properties.row_end->as_grid_track_placement().grid_track_placement().is_auto())
TRY(builder.try_appendff(" / {}", TRY(m_properties.row_end->as_grid_track_placement().grid_track_placement().to_string())));
if (!m_properties.column_end->as_grid_track_placement().grid_track_placement().is_auto())
TRY(builder.try_appendff(" / {}", TRY(m_properties.column_end->as_grid_track_placement().grid_track_placement().to_string())));
return builder.to_string();
}
bool GridAreaShorthandStyleValue::Properties::operator==(GridAreaShorthandStyleValue::Properties const&) const = default;
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/StyleValue.h>
namespace Web::CSS {
class GridAreaShorthandStyleValue final : public StyleValueWithDefaultOperators<GridAreaShorthandStyleValue> {
public:
static ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> create(
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end,
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end);
static ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> create(GridTrackPlacement row_start, GridTrackPlacement column_start, GridTrackPlacement row_end, GridTrackPlacement column_end);
virtual ~GridAreaShorthandStyleValue() override = default;
auto row_start() const { return m_properties.row_start; }
auto column_start() const { return m_properties.column_start; }
auto row_end() const { return m_properties.row_end; }
auto column_end() const { return m_properties.column_end; }
virtual ErrorOr<String> to_string() const override;
bool properties_equal(GridAreaShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
private:
GridAreaShorthandStyleValue(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end)
: StyleValueWithDefaultOperators(Type::GridAreaShorthand)
, m_properties { .row_start = move(row_start), .column_start = move(column_start), .row_end = move(row_end), .column_end = move(column_end) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start;
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start;
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end;
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end;
bool operator==(Properties const&) const;
} m_properties;
};
}