2020-06-04 16:06:32 +02:00
/*
* Copyright ( c ) 2020 , Andreas Kling < kling @ serenityos . org >
*
2021-04-22 01:24:48 -07:00
* SPDX - License - Identifier : BSD - 2 - Clause
2020-06-04 16:06:32 +02:00
*/
# include <LibWeb/CSS/StyleSheetList.h>
2022-02-10 17:49:50 +01:00
# include <LibWeb/DOM/Document.h>
2020-06-04 16:06:32 +02:00
2020-07-21 16:23:08 +02:00
namespace Web : : CSS {
2020-06-04 16:06:32 +02:00
2021-03-08 11:22:18 +01:00
void StyleSheetList : : add_sheet ( NonnullRefPtr < CSSStyleSheet > sheet )
2020-06-04 16:06:32 +02:00
{
2021-09-29 23:46:16 +02:00
VERIFY ( ! m_sheets . contains_slow ( sheet ) ) ;
2022-03-09 19:57:15 +01:00
sheet - > set_style_sheet_list ( { } , this ) ;
2022-04-08 21:27:35 +02:00
m_sheets . append ( sheet ) ;
2022-02-10 17:49:50 +01:00
2022-03-14 20:31:57 +01:00
m_document . style_computer ( ) . invalidate_rule_cache ( ) ;
2022-04-08 21:27:35 +02:00
m_document . style_computer ( ) . load_fonts_from_sheet ( * sheet ) ;
2022-02-10 17:49:50 +01:00
m_document . invalidate_style ( ) ;
2020-06-04 16:06:32 +02:00
}
2021-09-29 23:46:16 +02:00
void StyleSheetList : : remove_sheet ( CSSStyleSheet & sheet )
{
2022-03-09 19:57:15 +01:00
sheet . set_style_sheet_list ( { } , nullptr ) ;
2021-09-29 23:46:16 +02:00
m_sheets . remove_first_matching ( [ & ] ( auto & entry ) { return & * entry = = & sheet ; } ) ;
2022-02-10 17:49:50 +01:00
2022-03-14 20:31:57 +01:00
m_document . style_computer ( ) . invalidate_rule_cache ( ) ;
2022-02-10 17:49:50 +01:00
m_document . invalidate_style ( ) ;
2021-09-29 23:46:16 +02:00
}
2020-07-26 19:37:56 +02:00
StyleSheetList : : StyleSheetList ( DOM : : Document & document )
2020-06-04 16:06:32 +02:00
: m_document ( document )
{
}
2021-10-15 19:38:39 +01:00
// https://www.w3.org/TR/cssom/#ref-for-dfn-supported-property-indices%E2%91%A1
2021-09-29 13:03:09 +01:00
bool StyleSheetList : : is_supported_property_index ( u32 index ) const
{
// The object’ s supported property indices are the numbers in the range zero to one less than the number of CSS style sheets represented by the collection.
// If there are no such CSS style sheets, then there are no supported property indices.
if ( m_sheets . is_empty ( ) )
return false ;
return index < m_sheets . size ( ) ;
}
2020-06-04 16:06:32 +02:00
}