mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Split GridAreaShorthandStyleValue out of StyleValue.{h,cpp}
This commit is contained in:
parent
4dc99e49a1
commit
675cb3b9da
Notes:
sideshowbarker
2024-07-17 08:45:34 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/675cb3b9da Pull-request: https://github.com/SerenityOS/serenity/pull/18040
8 changed files with 100 additions and 55 deletions
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue