diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-06 01:12:57 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-06 01:12:57 +0100 |
commit | c1c5444c14115cd0d0637383c92b806abb262f77 (patch) | |
tree | 131716d649dc74ab6dbf0ba96aff6b5a154f4bc9 /Userland/Libraries/LibWeb/DOM | |
parent | 0608de8c1290b64dd56035efd0306ababe438933 (diff) | |
download | serenity-c1c5444c14115cd0d0637383c92b806abb262f77.zip |
LibWeb: Make window.inner{Width,Height} return *viewport* size
These were incorrectly returning the content width and height of the
initial containing block. Also added spec links and comments.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Window.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp index 6b8bb26ea0..4275d13ea6 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.cpp +++ b/Userland/Libraries/LibWeb/DOM/Window.cpp @@ -256,18 +256,24 @@ JS::Object* Window::create_wrapper(JS::GlobalObject& global_object) return &global_object; } +// https://www.w3.org/TR/cssom-view-1/#dom-window-innerwidth int Window::inner_width() const { - if (!associated_document().layout_node()) - return 0; - return associated_document().layout_node()->content_width(); + // The innerWidth attribute must return the viewport width including the size of a rendered scroll bar (if any), + // or zero if there is no viewport. + if (auto const* browsing_context = associated_document().browsing_context()) + return browsing_context->viewport_rect().width(); + return 0; } +// https://www.w3.org/TR/cssom-view-1/#dom-window-innerheight int Window::inner_height() const { - if (!associated_document().layout_node()) - return 0; - return associated_document().layout_node()->content_height(); + // The innerHeight attribute must return the viewport height including the size of a rendered scroll bar (if any), + // or zero if there is no viewport. + if (auto const* browsing_context = associated_document().browsing_context()) + return browsing_context->viewport_rect().height(); + return 0; } Page* Window::page() |