mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibWeb: Implement Window::query_media_feature()
This method provides the needed information to evaluate media queries. Every feature in Media Queries Level 4 is present, either as code or as a FIXME: https://www.w3.org/TR/mediaqueries-4/#media-descriptor-table There's a draft Level 5 which I have ignored for now. Some are unimplemented for now since we do not have access to the requested information. Some require StyleValue types that we do not yet support. Many are hard-coded for now since we do not (and may never) support monochrome or text-only displays for Browser.
This commit is contained in:
parent
de82764f2f
commit
fd51b02f9d
Notes:
sideshowbarker
2024-07-18 03:01:19 +09:00
Author: https://github.com/AtkinsSJ
Commit: fd51b02f9d
Pull-request: https://github.com/SerenityOS/serenity/pull/10367
2 changed files with 45 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -287,6 +288,49 @@ NonnullRefPtr<CSS::MediaQueryList> Window::match_media(String media)
|
|||
return CSS::MediaQueryList::create(associated_document(), parse_media_query_list(CSS::ParsingContext(associated_document()), media));
|
||||
}
|
||||
|
||||
RefPtr<CSS::StyleValue> Window::query_media_feature(FlyString const& name) const
|
||||
{
|
||||
// FIXME: Many of these should be dependent on the hardware
|
||||
|
||||
if (name.equals_ignoring_case("any-hover"sv))
|
||||
return CSS::IdentifierStyleValue::create(CSS::ValueID::Hover);
|
||||
if (name.equals_ignoring_case("any-pointer"sv))
|
||||
return CSS::IdentifierStyleValue::create(CSS::ValueID::Fine);
|
||||
// FIXME: aspect-ratio
|
||||
if (name.equals_ignoring_case("color"sv))
|
||||
return CSS::NumericStyleValue::create(32);
|
||||
if (name.equals_ignoring_case("color-gamut"sv))
|
||||
return CSS::IdentifierStyleValue::create(CSS::ValueID::Srgb);
|
||||
if (name.equals_ignoring_case("color-index"sv))
|
||||
return CSS::NumericStyleValue::create(0);
|
||||
// FIXME: device-aspect-ratio
|
||||
// FIXME: device-height
|
||||
// FIXME: device-width
|
||||
if (name.equals_ignoring_case("grid"sv))
|
||||
return CSS::NumericStyleValue::create(0);
|
||||
if (name.equals_ignoring_case("height"sv))
|
||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(inner_height()));
|
||||
if (name.equals_ignoring_case("hover"sv))
|
||||
return CSS::IdentifierStyleValue::create(CSS::ValueID::Hover);
|
||||
if (name.equals_ignoring_case("monochrome"sv))
|
||||
return CSS::NumericStyleValue::create(0);
|
||||
if (name.equals_ignoring_case("hover"sv))
|
||||
return CSS::IdentifierStyleValue::create(inner_height() >= inner_width() ? CSS::ValueID::Portrait : CSS::ValueID::Landscape);
|
||||
if (name.equals_ignoring_case("overflow-block"sv))
|
||||
return CSS::IdentifierStyleValue::create(CSS::ValueID::Scroll);
|
||||
// FIXME: overflow-inline
|
||||
if (name.equals_ignoring_case("pointer"sv))
|
||||
return CSS::IdentifierStyleValue::create(CSS::ValueID::Fine);
|
||||
// FIXME: resolution
|
||||
if (name.equals_ignoring_case("scan"sv))
|
||||
return CSS::IdentifierStyleValue::create(CSS::ValueID::Progressive);
|
||||
if (name.equals_ignoring_case("update"sv))
|
||||
return CSS::IdentifierStyleValue::create(CSS::ValueID::Fast);
|
||||
if (name.equals_ignoring_case("width"sv))
|
||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(inner_width()));
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-view/#dom-window-scrollx
|
||||
float Window::scroll_x() const
|
||||
{
|
||||
|
|
|
@ -84,6 +84,7 @@ public:
|
|||
|
||||
NonnullRefPtr<CSS::CSSStyleDeclaration> get_computed_style(DOM::Element&) const;
|
||||
NonnullRefPtr<CSS::MediaQueryList> match_media(String);
|
||||
RefPtr<CSS::StyleValue> query_media_feature(FlyString const&) const;
|
||||
|
||||
float scroll_x() const;
|
||||
float scroll_y() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue