2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
#include <LibWeb/Frame.h>
|
|
|
|
#include <LibWeb/Layout/LayoutDocument.h>
|
2020-06-05 19:13:27 +02:00
|
|
|
#include <LibWeb/Layout/LayoutWidget.h>
|
|
|
|
#include <LibWeb/PageView.h>
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
namespace Web {
|
|
|
|
|
2020-06-05 23:36:02 +02:00
|
|
|
Frame::Frame()
|
2020-06-06 13:02:44 +02:00
|
|
|
: m_loader(*this)
|
2020-06-05 23:36:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-28 18:21:22 +02:00
|
|
|
Frame::Frame(PageView& page_view)
|
2020-06-06 13:02:44 +02:00
|
|
|
: m_loader(*this)
|
|
|
|
, m_page_view(page_view.make_weak_ptr())
|
2019-10-04 15:50:04 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Frame::~Frame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Frame::set_document(Document* document)
|
|
|
|
{
|
|
|
|
if (m_document == document)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_document)
|
|
|
|
m_document->detach_from_frame({}, *this);
|
|
|
|
|
|
|
|
m_document = document;
|
|
|
|
|
|
|
|
if (m_document)
|
|
|
|
m_document->attach_to_frame({}, *this);
|
2020-06-06 13:02:44 +02:00
|
|
|
|
|
|
|
if (on_set_document)
|
|
|
|
on_set_document(m_document);
|
2019-10-04 15:50:04 +02:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
void Frame::set_size(const Gfx::Size& size)
|
2019-10-04 15:50:04 +02:00
|
|
|
{
|
|
|
|
if (m_size == size)
|
|
|
|
return;
|
|
|
|
m_size = size;
|
|
|
|
}
|
2019-10-09 21:25:29 +02:00
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
void Frame::set_viewport_rect(const Gfx::Rect& rect)
|
2019-12-18 20:54:23 +01:00
|
|
|
{
|
|
|
|
if (m_viewport_rect == rect)
|
|
|
|
return;
|
|
|
|
m_viewport_rect = rect;
|
2019-12-18 20:57:18 +01:00
|
|
|
|
|
|
|
if (m_document && m_document->layout_node())
|
|
|
|
m_document->layout_node()->did_set_viewport_rect({}, rect);
|
2019-12-18 20:54:23 +01:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
void Frame::set_needs_display(const Gfx::Rect& rect)
|
2019-10-09 21:25:29 +02:00
|
|
|
{
|
2019-12-18 22:16:27 +01:00
|
|
|
if (!m_viewport_rect.intersects(rect))
|
|
|
|
return;
|
|
|
|
|
2019-10-09 21:25:29 +02:00
|
|
|
if (!on_set_needs_display)
|
|
|
|
return;
|
|
|
|
on_set_needs_display(rect);
|
|
|
|
}
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2020-06-01 19:50:47 +02:00
|
|
|
void Frame::did_scroll(Badge<PageView>)
|
|
|
|
{
|
|
|
|
if (!m_document)
|
|
|
|
return;
|
|
|
|
if (!m_document->layout_node())
|
|
|
|
return;
|
2020-06-05 19:13:27 +02:00
|
|
|
m_document->layout_node()->for_each_in_subtree_of_type<LayoutWidget>([&](auto& layout_widget) {
|
|
|
|
layout_widget.update_widget();
|
2020-06-01 19:50:47 +02:00
|
|
|
return IterationDecision::Continue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-06 13:02:44 +02:00
|
|
|
void Frame::scroll_to_anchor(const String& fragment)
|
|
|
|
{
|
|
|
|
// FIXME: We should be able to scroll iframes to an anchor, too!
|
|
|
|
if (!m_page_view)
|
|
|
|
return;
|
|
|
|
// FIXME: This logic is backwards, the work should be done in here,
|
|
|
|
// and then we just request that the "view" scrolls to a certain content offset.
|
|
|
|
m_page_view->scroll_to_anchor(fragment);
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|