diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-10-03 19:26:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-05 18:51:39 +0200 |
commit | fd51b02f9d2b400f73887b88ea81099513cded87 (patch) | |
tree | fff06f1754876079f507fbced8f3662d14915ac8 /Userland/Libraries/LibWeb/DOM | |
parent | de82764f2feac3ffe3b265f3b4f6a68feca9a9eb (diff) | |
download | serenity-fd51b02f9d2b400f73887b88ea81099513cded87.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Window.cpp | 44 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Window.h | 1 |
2 files changed, 45 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp index 79960998cf..0c48fb471f 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.cpp +++ b/Userland/Libraries/LibWeb/DOM/Window.cpp @@ -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 { diff --git a/Userland/Libraries/LibWeb/DOM/Window.h b/Userland/Libraries/LibWeb/DOM/Window.h index 3ee7d723c4..f521879cab 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.h +++ b/Userland/Libraries/LibWeb/DOM/Window.h @@ -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; |