mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-09 06:37:21 +00:00
LibWeb: Add Document::viewport_rect()
This is a convenience helper that returns an empty rect if there is no browsing context (to get the actual rect from).
This commit is contained in:
parent
b8e694c0f2
commit
ae5313d33c
|
@ -968,7 +968,7 @@ void Document::update_layout()
|
|||
if (!browsing_context())
|
||||
return;
|
||||
|
||||
auto viewport_rect = browsing_context()->viewport_rect();
|
||||
auto viewport_rect = this->viewport_rect();
|
||||
|
||||
if (!m_layout_root) {
|
||||
Layout::TreeBuilder tree_builder;
|
||||
|
@ -2101,10 +2101,7 @@ void Document::run_the_resize_steps()
|
|||
// or an iframe element’s dimensions are changed) since the last time these steps were run,
|
||||
// fire an event named resize at the Window object associated with doc.
|
||||
|
||||
if (!browsing_context())
|
||||
return;
|
||||
|
||||
auto viewport_size = browsing_context()->viewport_rect().size().to_type<int>();
|
||||
auto viewport_size = viewport_rect().size().to_type<int>();
|
||||
if (m_last_viewport_size == viewport_size)
|
||||
return;
|
||||
m_last_viewport_size = viewport_size;
|
||||
|
@ -2987,6 +2984,13 @@ HTML::ListOfAvailableImages const& Document::list_of_available_images() const
|
|||
return *m_list_of_available_images;
|
||||
}
|
||||
|
||||
CSSPixelRect Document::viewport_rect() const
|
||||
{
|
||||
if (auto* browsing_context = this->browsing_context())
|
||||
return browsing_context->viewport_rect();
|
||||
return CSSPixelRect {};
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<CSS::VisualViewport> Document::visual_viewport()
|
||||
{
|
||||
if (!m_visual_viewport)
|
||||
|
|
|
@ -390,6 +390,7 @@ public:
|
|||
void add_media_query_list(JS::NonnullGCPtr<CSS::MediaQueryList>);
|
||||
|
||||
JS::NonnullGCPtr<CSS::VisualViewport> visual_viewport();
|
||||
[[nodiscard]] CSSPixelRect viewport_rect() const;
|
||||
|
||||
bool has_focus() const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user