LibWeb: Rename Web::Frame to Web::BrowsingContext

Our "frame" concept very closely matches what the web specs call a
"browsing context", so let's rename it to that. :^)

The "main frame" becomes the "top-level browsing context",
and "sub-frames" are now "nested browsing contexts".
This commit is contained in:
Andreas Kling 2021-05-30 12:36:53 +02:00
parent 8be98af77c
commit 4190fd2199
Notes: sideshowbarker 2024-07-18 17:10:44 +09:00
43 changed files with 241 additions and 241 deletions

View File

@ -31,7 +31,7 @@
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/OutOfProcessWebView.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Browser {

View File

@ -26,7 +26,7 @@
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Origin.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/WebAssembly/WebAssemblyObject.h>
#include <LibWeb/Bindings/WindowObjectHelper.h>
@ -344,10 +344,10 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::top_getter)
auto* impl = impl_from(vm, global_object);
if (!impl)
return {};
auto* this_frame = impl->document().frame();
VERIFY(this_frame);
VERIFY(this_frame->main_frame().document());
auto& top_window = this_frame->main_frame().document()->window();
auto* this_browsing_context = impl->document().browsing_context();
VERIFY(this_browsing_context);
VERIFY(this_browsing_context->top_level_browsing_context().document());
auto& top_window = this_browsing_context->top_level_browsing_context().document()->window();
return top_window.wrapper();
}
@ -356,14 +356,14 @@ JS_DEFINE_NATIVE_GETTER(WindowObject::parent_getter)
auto* impl = impl_from(vm, global_object);
if (!impl)
return {};
auto* this_frame = impl->document().frame();
VERIFY(this_frame);
if (this_frame->parent()) {
VERIFY(this_frame->parent()->document());
auto& parent_window = this_frame->parent()->document()->window();
auto* this_browsing_context = impl->document().browsing_context();
VERIFY(this_browsing_context);
if (this_browsing_context->parent()) {
VERIFY(this_browsing_context->parent()->document());
auto& parent_window = this_browsing_context->parent()->document()->window();
return parent_window.wrapper();
}
VERIFY(this_frame == &this_frame->main_frame());
VERIFY(this_browsing_context == &this_browsing_context->top_level_browsing_context());
return impl->wrapper();
}

View File

@ -205,9 +205,9 @@ set(SOURCES
Namespace.cpp
NavigationTiming/PerformanceTiming.cpp
OutOfProcessWebView.cpp
Page/BrowsingContext.cpp
Page/EditEventHandler.cpp
Page/EventHandler.cpp
Page/Frame.cpp
Page/Page.cpp
Painting/BorderPainting.cpp
Painting/StackingContext.cpp

View File

@ -7,7 +7,7 @@
#include <LibWeb/CSS/Length.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLHtmlElement.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::CSS {
@ -21,16 +21,16 @@ float Length::relative_length_to_px(const Layout::Node& layout_node) const
case Type::Rem:
return m_value * layout_node.document().document_element()->layout_node()->font_size();
case Type::Vw:
return layout_node.document().frame()->viewport_rect().width() * (m_value / 100);
return layout_node.document().browsing_context()->viewport_rect().width() * (m_value / 100);
case Type::Vh:
return layout_node.document().frame()->viewport_rect().height() * (m_value / 100);
return layout_node.document().browsing_context()->viewport_rect().height() * (m_value / 100);
case Type::Vmin: {
auto viewport = layout_node.document().frame()->viewport_rect();
auto viewport = layout_node.document().browsing_context()->viewport_rect();
return min(viewport.width(), viewport.height()) * (m_value / 100);
}
case Type::Vmax: {
auto viewport = layout_node.document().frame()->viewport_rect();
auto viewport = layout_node.document().browsing_context()->viewport_rect();
return max(viewport.width(), viewport.height()) * (m_value / 100);
}

View File

@ -11,7 +11,7 @@
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Loader/LoadRequest.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::CSS {
@ -165,8 +165,8 @@ void ImageStyleValue::resource_did_load()
return;
m_bitmap = resource()->bitmap();
// FIXME: Do less than a full repaint if possible?
if (m_document->frame())
m_document->frame()->set_needs_display({});
if (m_document->browsing_context())
m_document->browsing_context()->set_needs_display({});
}
}

View File

@ -50,7 +50,7 @@
#include <LibWeb/Layout/TreeBuilder.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/Origin.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/SVG/TagNames.h>
#include <LibWeb/UIEvents/MouseEvent.h>
#include <ctype.h>
@ -281,22 +281,22 @@ void Document::set_title(const String& title)
title_element->append_child(adopt_ref(*new Text(*this, title)));
if (auto* page = this->page()) {
if (frame() == &page->main_frame())
if (browsing_context() == &page->top_level_browsing_context())
page->client().page_did_change_title(title);
}
}
void Document::attach_to_frame(Badge<Frame>, Frame& frame)
void Document::attach_to_browsing_context(Badge<BrowsingContext>, BrowsingContext& browsing_context)
{
m_frame = frame;
m_browsing_context = browsing_context;
update_layout();
}
void Document::detach_from_frame(Badge<Frame>, Frame& frame)
void Document::detach_from_browsing_context(Badge<BrowsingContext>, BrowsingContext& browsing_context)
{
VERIFY(&frame == m_frame);
VERIFY(&browsing_context == m_browsing_context);
tear_down_layout_tree();
m_frame = nullptr;
m_browsing_context = nullptr;
}
void Document::tear_down_layout_tree()
@ -399,7 +399,7 @@ void Document::force_layout()
void Document::update_layout()
{
if (!frame())
if (!browsing_context())
return;
if (!m_layout_root) {
@ -412,7 +412,7 @@ void Document::update_layout()
m_layout_root->set_needs_display();
if (frame()->is_main_frame()) {
if (browsing_context()->is_top_level()) {
if (auto* page = this->page())
page->client().page_did_layout();
}
@ -881,12 +881,12 @@ void Document::set_ready_state(const String& ready_state)
Page* Document::page()
{
return m_frame ? m_frame->page() : nullptr;
return m_browsing_context ? m_browsing_context->page() : nullptr;
}
const Page* Document::page() const
{
return m_frame ? m_frame->page() : nullptr;
return m_browsing_context ? m_browsing_context->page() : nullptr;
}
EventTarget* Document::get_parent(const Event& event)

View File

@ -115,11 +115,11 @@ public:
String title() const;
void set_title(const String&);
void attach_to_frame(Badge<Frame>, Frame&);
void detach_from_frame(Badge<Frame>, Frame&);
void attach_to_browsing_context(Badge<BrowsingContext>, BrowsingContext&);
void detach_from_browsing_context(Badge<BrowsingContext>, BrowsingContext&);
Frame* frame() { return m_frame.ptr(); }
const Frame* frame() const { return m_frame.ptr(); }
BrowsingContext* browsing_context() { return m_browsing_context.ptr(); }
const BrowsingContext* browsing_context() const { return m_browsing_context.ptr(); }
Page* page();
const Page* page() const;
@ -297,7 +297,7 @@ private:
RefPtr<CSS::StyleSheetList> m_style_sheets;
RefPtr<Node> m_hovered_node;
RefPtr<Node> m_inspected_node;
WeakPtr<Frame> m_frame;
WeakPtr<BrowsingContext> m_browsing_context;
URL m_url;
RefPtr<Window> m_window;

View File

@ -14,7 +14,7 @@
#include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::DOM {
@ -139,7 +139,7 @@ void Window::cancel_animation_frame(i32 id)
void Window::did_set_location_href(Badge<Bindings::LocationObject>, const URL& new_href)
{
auto* frame = document().frame();
auto* frame = document().browsing_context();
if (!frame)
return;
frame->loader().load(new_href, FrameLoader::Type::Navigation);
@ -147,7 +147,7 @@ void Window::did_set_location_href(Badge<Bindings::LocationObject>, const URL& n
void Window::did_call_location_reload(Badge<Bindings::LocationObject>)
{
auto* frame = document().frame();
auto* frame = document().browsing_context();
if (!frame)
return;
frame->loader().load(document().url(), FrameLoader::Type::Reload);

View File

@ -179,7 +179,7 @@ class TextNode;
namespace Web {
class EventHandler;
class EditEventHandler;
class Frame;
class BrowsingContext;
class FrameLoader;
class InProcessWebView;
class LoadRequest;

View File

@ -8,7 +8,7 @@
#include <LibWeb/DOM/Event.h>
#include <LibWeb/HTML/FrameHostElement.h>
#include <LibWeb/Origin.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::HTML {
@ -26,18 +26,18 @@ void FrameHostElement::inserted()
HTMLElement::inserted();
if (!is_connected())
return;
if (auto* frame = document().frame()) {
m_content_frame = Frame::create_subframe(*this, frame->main_frame());
m_content_frame->set_frame_nesting_levels(frame->frame_nesting_levels());
m_content_frame->register_frame_nesting(document().url());
if (auto* frame = document().browsing_context()) {
m_nested_browsing_context = BrowsingContext::create_nested(*this, frame->top_level_browsing_context());
m_nested_browsing_context->set_frame_nesting_levels(frame->frame_nesting_levels());
m_nested_browsing_context->register_frame_nesting(document().url());
}
}
Origin FrameHostElement::content_origin() const
{
if (!m_content_frame || !m_content_frame->document())
if (!m_nested_browsing_context || !m_nested_browsing_context->document())
return {};
return m_content_frame->document()->origin();
return m_nested_browsing_context->document()->origin();
}
bool FrameHostElement::may_access_from_origin(const Origin& origin) const
@ -47,10 +47,10 @@ bool FrameHostElement::may_access_from_origin(const Origin& origin) const
const DOM::Document* FrameHostElement::content_document() const
{
return m_content_frame ? m_content_frame->document() : nullptr;
return m_nested_browsing_context ? m_nested_browsing_context->document() : nullptr;
}
void FrameHostElement::content_frame_did_load(Badge<FrameLoader>)
void FrameHostElement::nested_browsing_context_did_load(Badge<FrameLoader>)
{
dispatch_event(DOM::Event::create(EventNames::load));
}

View File

@ -15,20 +15,20 @@ public:
FrameHostElement(DOM::Document&, QualifiedName);
virtual ~FrameHostElement() override;
Frame* content_frame() { return m_content_frame; }
const Frame* content_frame() const { return m_content_frame; }
BrowsingContext* nested_browsing_context() { return m_nested_browsing_context; }
const BrowsingContext* nested_browsing_context() const { return m_nested_browsing_context; }
const DOM::Document* content_document() const;
Origin content_origin() const;
bool may_access_from_origin(const Origin&) const;
void content_frame_did_load(Badge<FrameLoader>);
void nested_browsing_context_did_load(Badge<FrameLoader>);
virtual void inserted() override;
protected:
RefPtr<Frame> m_content_frame;
RefPtr<BrowsingContext> m_nested_browsing_context;
};
}

View File

@ -10,7 +10,7 @@
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/SubmitEvent.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/URLEncoder.h>
namespace Web::HTML {

View File

@ -8,7 +8,7 @@
#include <LibWeb/HTML/HTMLIFrameElement.h>
#include <LibWeb/Layout/FrameBox.h>
#include <LibWeb/Origin.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::HTML {
@ -43,7 +43,7 @@ void HTMLIFrameElement::inserted()
void HTMLIFrameElement::load_src(const String& value)
{
if (!m_content_frame)
if (!m_nested_browsing_context)
return;
if (value.is_null())
@ -60,7 +60,7 @@ void HTMLIFrameElement::load_src(const String& value)
}
dbgln("Loading iframe document from {}", value);
m_content_frame->loader().load(url, FrameLoader::Type::IFrame);
m_nested_browsing_context->loader().load(url, FrameLoader::Type::IFrame);
}
}

View File

@ -17,7 +17,7 @@
#include <LibWeb/Layout/ButtonBox.h>
#include <LibWeb/Layout/CheckBox.h>
#include <LibWeb/Layout/RadioButton.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::HTML {

View File

@ -23,7 +23,7 @@ void HTMLTitleElement::children_changed()
{
HTMLElement::children_changed();
if (auto* page = document().page()) {
if (document().frame() == &page->main_frame())
if (document().browsing_context() == &page->top_level_browsing_context())
page->client().page_did_change_title(document().title());
}
}

View File

@ -23,8 +23,8 @@
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Painting/PaintContext.h>
#include <LibWeb/UIEvents/MouseEvent.h>
@ -89,7 +89,7 @@ void InProcessWebView::select_all()
String InProcessWebView::selected_text() const
{
return page().focused_frame().selected_text();
return page().focused_context().selected_text();
}
void InProcessWebView::page_did_layout()
@ -104,7 +104,7 @@ void InProcessWebView::page_did_change_title(const String& title)
on_title_change(title);
}
void InProcessWebView::page_did_set_document_in_main_frame(DOM::Document* document)
void InProcessWebView::page_did_set_document_in_top_level_browsing_context(DOM::Document* document)
{
if (on_set_document)
on_set_document(document);
@ -210,17 +210,17 @@ void InProcessWebView::layout_and_sync_size()
bool had_vertical_scrollbar = vertical_scrollbar().is_visible();
bool had_horizontal_scrollbar = horizontal_scrollbar().is_visible();
page().main_frame().set_size(available_size());
page().top_level_browsing_context().set_size(available_size());
set_content_size(layout_root()->size().to_type<int>());
// NOTE: If layout caused us to gain or lose scrollbars, we have to lay out again
// since the scrollbars now take up some of the available space.
if (had_vertical_scrollbar != vertical_scrollbar().is_visible() || had_horizontal_scrollbar != horizontal_scrollbar().is_visible()) {
page().main_frame().set_size(available_size());
page().top_level_browsing_context().set_size(available_size());
set_content_size(layout_root()->size().to_type<int>());
}
page().main_frame().set_viewport_scroll_offset({ horizontal_scrollbar().value(), vertical_scrollbar().value() });
page().top_level_browsing_context().set_viewport_scroll_offset({ horizontal_scrollbar().value(), vertical_scrollbar().value() });
}
void InProcessWebView::resize_event(GUI::ResizeEvent& event)
@ -319,9 +319,9 @@ void InProcessWebView::keydown_event(GUI::KeyEvent& event)
URL InProcessWebView::url() const
{
if (!page().main_frame().document())
if (!page().top_level_browsing_context().document())
return {};
return page().main_frame().document()->url();
return page().top_level_browsing_context().document()->url();
}
void InProcessWebView::reload()
@ -331,13 +331,13 @@ void InProcessWebView::reload()
void InProcessWebView::load_html(const StringView& html, const URL& url)
{
page().main_frame().loader().load_html(html, url);
page().top_level_browsing_context().loader().load_html(html, url);
}
bool InProcessWebView::load(const URL& url)
{
set_override_cursor(Gfx::StandardCursor::None);
return page().main_frame().loader().load(url, FrameLoader::Type::Navigation);
return page().top_level_browsing_context().loader().load(url, FrameLoader::Type::Navigation);
}
const Layout::InitialContainingBlockBox* InProcessWebView::layout_root() const
@ -360,27 +360,27 @@ void InProcessWebView::page_did_request_scroll_into_view(const Gfx::IntRect& rec
void InProcessWebView::load_empty_document()
{
page().main_frame().set_document(nullptr);
page().top_level_browsing_context().set_document(nullptr);
}
DOM::Document* InProcessWebView::document()
{
return page().main_frame().document();
return page().top_level_browsing_context().document();
}
const DOM::Document* InProcessWebView::document() const
{
return page().main_frame().document();
return page().top_level_browsing_context().document();
}
void InProcessWebView::set_document(DOM::Document* document)
{
page().main_frame().set_document(document);
page().top_level_browsing_context().set_document(document);
}
void InProcessWebView::did_scroll()
{
page().main_frame().set_viewport_scroll_offset({ horizontal_scrollbar().value(), vertical_scrollbar().value() });
page().top_level_browsing_context().set_viewport_scroll_offset({ horizontal_scrollbar().value(), vertical_scrollbar().value() });
}
void InProcessWebView::drop_event(GUI::DropEvent& event)

View File

@ -70,7 +70,7 @@ private:
virtual Gfx::Palette palette() const override { return GUI::AbstractScrollableWidget::palette(); }
virtual Gfx::IntRect screen_rect() const override { return GUI::Desktop::the().rect(); }
virtual void page_did_change_title(const String&) override;
virtual void page_did_set_document_in_main_frame(DOM::Document*) override;
virtual void page_did_set_document_in_top_level_browsing_context(DOM::Document*) override;
virtual void page_did_start_loading(const URL&) override;
virtual void page_did_finish_loading(const URL&) override;
virtual void page_did_change_selection() override;

View File

@ -13,7 +13,7 @@
#include <LibWeb/Layout/InlineFormattingContext.h>
#include <LibWeb/Layout/ListItemBox.h>
#include <LibWeb/Layout/ReplacedBox.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {
@ -516,7 +516,7 @@ void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_fl
void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_mode)
{
auto viewport_rect = context_box().frame().viewport_rect();
auto viewport_rect = context_box().browsing_context().viewport_rect();
auto& icb = downcast<Layout::InitialContainingBlockBox>(context_box());
icb.build_stacking_context_tree();

View File

@ -10,7 +10,7 @@
#include <LibWeb/HTML/HTMLHtmlElement.h>
#include <LibWeb/Layout/BlockBox.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Painting/BorderPainting.h>
namespace Web::Layout {
@ -293,7 +293,7 @@ HitTestResult Box::hit_test(const Gfx::IntPoint& position, HitTestType type) con
void Box::set_needs_display()
{
if (!is_inline()) {
frame().set_needs_display(enclosing_int_rect(absolute_rect()));
browsing_context().set_needs_display(enclosing_int_rect(absolute_rect()));
return;
}

View File

@ -11,7 +11,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Layout/ButtonBox.h>
#include <LibWeb/Layout/Label.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {
@ -63,7 +63,7 @@ void ButtonBox::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsi
set_needs_display();
m_tracking_mouse = true;
frame().event_handler().set_mouse_event_tracking_layout_node(this);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(this);
}
void ButtonBox::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)
@ -73,7 +73,7 @@ void ButtonBox::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& positio
// NOTE: Handling the click may run arbitrary JS, which could disappear this node.
NonnullRefPtr protected_this = *this;
NonnullRefPtr protected_frame = frame();
NonnullRefPtr protected_frame = browsing_context();
bool is_inside_node_or_label = enclosing_int_rect(absolute_rect()).contains(position);
if (!is_inside_node_or_label)
@ -114,7 +114,7 @@ void ButtonBox::handle_associated_label_mouseup(Badge<Label>)
{
// NOTE: Handling the click may run arbitrary JS, which could disappear this node.
NonnullRefPtr protected_this = *this;
NonnullRefPtr protected_frame = frame();
NonnullRefPtr protected_frame = browsing_context();
dom_node().did_click_button({});
m_being_pressed = false;

View File

@ -10,7 +10,7 @@
#include <LibGfx/StylePainter.h>
#include <LibWeb/Layout/CheckBox.h>
#include <LibWeb/Layout/Label.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {
@ -48,7 +48,7 @@ void CheckBox::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsig
set_needs_display();
m_tracking_mouse = true;
frame().event_handler().set_mouse_event_tracking_layout_node(this);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(this);
}
void CheckBox::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)
@ -68,7 +68,7 @@ void CheckBox::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position
m_being_pressed = false;
m_tracking_mouse = false;
frame().event_handler().set_mouse_event_tracking_layout_node(nullptr);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(nullptr);
}
void CheckBox::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned, unsigned)

View File

@ -10,7 +10,7 @@
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/FrameBox.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {
@ -25,7 +25,7 @@ FrameBox::~FrameBox()
void FrameBox::prepare_for_replaced_layout()
{
VERIFY(dom_node().content_frame());
VERIFY(dom_node().nested_browsing_context());
set_has_intrinsic_width(true);
set_has_intrinsic_height(true);
@ -52,14 +52,14 @@ void FrameBox::paint(PaintContext& context, PaintPhase phase)
context.painter().add_clip_rect(enclosing_int_rect(absolute_rect()));
context.painter().translate(absolute_x(), absolute_y());
context.set_viewport_rect({ {}, dom_node().content_frame()->size() });
context.set_viewport_rect({ {}, dom_node().nested_browsing_context()->size() });
const_cast<Layout::InitialContainingBlockBox*>(hosted_layout_tree)->paint_all_phases(context);
context.set_viewport_rect(old_viewport_rect);
context.painter().restore();
if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
if (dom_node().content_frame()->is_focused_frame()) {
if (dom_node().nested_browsing_context()->is_focused_context()) {
context.painter().draw_rect(absolute_rect().to_type<int>(), Color::Cyan);
}
}
@ -70,8 +70,8 @@ void FrameBox::did_set_rect()
{
ReplacedBox::did_set_rect();
VERIFY(dom_node().content_frame());
dom_node().content_frame()->set_size(size().to_type<int>());
VERIFY(dom_node().nested_browsing_context());
dom_node().nested_browsing_context()->set_size(size().to_type<int>());
}
}

View File

@ -8,7 +8,7 @@
#include <LibGfx/Painter.h>
#include <LibGfx/StylePainter.h>
#include <LibWeb/Layout/ImageBox.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {
@ -16,12 +16,12 @@ ImageBox::ImageBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr
: ReplacedBox(document, element, move(style))
, m_image_loader(image_loader)
{
frame().register_viewport_client(*this);
browsing_context().register_viewport_client(*this);
}
ImageBox::~ImageBox()
{
frame().unregister_viewport_client(*this);
browsing_context().unregister_viewport_client(*this);
}
int ImageBox::preferred_width() const

View File

@ -8,13 +8,13 @@
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/Layout/ReplacedBox.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {
class ImageBox
: public ReplacedBox
, public Frame::ViewportClient {
, public BrowsingContext::ViewportClient {
public:
ImageBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>, const ImageLoader&);
virtual ~ImageBox() override;

View File

@ -7,7 +7,7 @@
#include <LibGfx/Painter.h>
#include <LibWeb/Dump.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Painting/StackingContext.h>
namespace Web::Layout {

View File

@ -13,7 +13,7 @@
#include <LibWeb/Layout/Label.h>
#include <LibWeb/Layout/LabelableNode.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {

View File

@ -15,7 +15,7 @@
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {
@ -104,16 +104,16 @@ HitTestResult Node::hit_test(const Gfx::IntPoint& position, HitTestType type) co
return result;
}
const Frame& Node::frame() const
const BrowsingContext& Node::browsing_context() const
{
VERIFY(document().frame());
return *document().frame();
VERIFY(document().browsing_context());
return *document().browsing_context();
}
Frame& Node::frame()
BrowsingContext& Node::browsing_context()
{
VERIFY(document().frame());
return *document().frame();
VERIFY(document().browsing_context());
return *document().browsing_context();
}
const InitialContainingBlockBox& Node::root() const
@ -140,7 +140,7 @@ void Node::set_needs_display()
if (auto* block = containing_block()) {
block->for_each_fragment([&](auto& fragment) {
if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) {
frame().set_needs_display(enclosing_int_rect(fragment.absolute_rect()));
browsing_context().set_needs_display(enclosing_int_rect(fragment.absolute_rect()));
}
return IterationDecision::Continue;
});

View File

@ -65,8 +65,8 @@ public:
DOM::Document& document() { return m_document; }
const DOM::Document& document() const { return m_document; }
const Frame& frame() const;
Frame& frame();
const BrowsingContext& browsing_context() const;
BrowsingContext& browsing_context();
const InitialContainingBlockBox& root() const;
InitialContainingBlockBox& root();

View File

@ -10,7 +10,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Layout/Label.h>
#include <LibWeb/Layout/RadioButton.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {
@ -48,7 +48,7 @@ void RadioButton::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, un
set_needs_display();
m_tracking_mouse = true;
frame().event_handler().set_mouse_event_tracking_layout_node(this);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(this);
}
void RadioButton::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)
@ -68,7 +68,7 @@ void RadioButton::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& posit
m_being_pressed = false;
m_tracking_mouse = false;
frame().event_handler().set_mouse_event_tracking_layout_node(nullptr);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(nullptr);
}
void RadioButton::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned, unsigned)

View File

@ -12,7 +12,7 @@
#include <LibWeb/Layout/TableFormattingContext.h>
#include <LibWeb/Layout/TableRowBox.h>
#include <LibWeb/Layout/TableRowGroupBox.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
namespace Web::Layout {

View File

@ -12,7 +12,7 @@
#include <LibWeb/Layout/InlineFormattingContext.h>
#include <LibWeb/Layout/Label.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <ctype.h>
namespace Web::Layout {
@ -77,17 +77,17 @@ void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& frag
void TextNode::paint_cursor_if_needed(PaintContext& context, const LineBoxFragment& fragment) const
{
if (!frame().is_focused_frame())
if (!browsing_context().is_focused_context())
return;
if (!frame().cursor_blink_state())
if (!browsing_context().cursor_blink_state())
return;
if (frame().cursor_position().node() != &dom_node())
if (browsing_context().cursor_position().node() != &dom_node())
return;
// NOTE: This checks if the cursor is before the start or after the end of the fragment. If it is at the end, after all text, it should still be painted.
if (frame().cursor_position().offset() < (unsigned)fragment.start() || frame().cursor_position().offset() > (unsigned)(fragment.start() + fragment.length()))
if (browsing_context().cursor_position().offset() < (unsigned)fragment.start() || browsing_context().cursor_position().offset() > (unsigned)(fragment.start() + fragment.length()))
return;
if (!fragment.layout_node().dom_node() || !fragment.layout_node().dom_node()->is_editable())
@ -95,7 +95,7 @@ void TextNode::paint_cursor_if_needed(PaintContext& context, const LineBoxFragme
auto fragment_rect = fragment.absolute_rect();
float cursor_x = fragment_rect.x() + font().width(fragment.text().substring_view(0, frame().cursor_position().offset() - fragment.start()));
float cursor_x = fragment_rect.x() + font().width(fragment.text().substring_view(0, browsing_context().cursor_position().offset() - fragment.start()));
float cursor_top = fragment_rect.top();
float cursor_height = fragment_rect.height();
Gfx::IntRect cursor_rect(cursor_x, cursor_top, 1, cursor_height);
@ -234,7 +234,7 @@ void TextNode::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint& positi
if (!parent() || !is<Label>(*parent()))
return;
downcast<Label>(*parent()).handle_mousedown_on_label({}, position, button);
frame().event_handler().set_mouse_event_tracking_layout_node(this);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(this);
}
void TextNode::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)
@ -246,7 +246,7 @@ void TextNode::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position
NonnullRefPtr protect = *this;
downcast<Label>(*parent()).handle_mouseup_on_label({}, position, button);
frame().event_handler().set_mouse_event_tracking_layout_node(nullptr);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(nullptr);
}
void TextNode::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)

View File

@ -18,13 +18,13 @@
#include <LibWeb/Loader/FrameLoader.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Page/Page.h>
namespace Web {
FrameLoader::FrameLoader(Frame& frame)
: m_frame(frame)
FrameLoader::FrameLoader(BrowsingContext& browsing_context)
: m_browsing_context(browsing_context)
{
}
@ -136,7 +136,7 @@ bool FrameLoader::load(const LoadRequest& request, Type type)
return false;
}
if (!m_frame.is_frame_nesting_allowed(request.url())) {
if (!m_browsing_context.is_frame_nesting_allowed(request.url())) {
dbgln("No further recursion is allowed for the frame, abort load!");
return false;
}
@ -144,7 +144,7 @@ bool FrameLoader::load(const LoadRequest& request, Type type)
auto& url = request.url();
if (type == Type::Navigation || type == Type::Reload) {
if (auto* page = frame().page())
if (auto* page = browsing_context().page())
page->client().page_did_start_loading(url);
}
@ -171,7 +171,7 @@ bool FrameLoader::load(const LoadRequest& request, Type type)
return;
}
dbgln("Decoded favicon, {}", bitmap->size());
if (auto* page = frame().page())
if (auto* page = browsing_context().page())
page->client().page_did_change_favicon(*bitmap);
});
}
@ -188,7 +188,7 @@ bool FrameLoader::load(const URL& url, Type type)
return false;
}
auto request = LoadRequest::create_for_url_on_page(url, frame().page());
auto request = LoadRequest::create_for_url_on_page(url, browsing_context().page());
return load(request, type);
}
@ -197,7 +197,7 @@ void FrameLoader::load_html(const StringView& html, const URL& url)
auto document = DOM::Document::create(url);
HTML::HTMLDocumentParser parser(document, html, "utf-8");
parser.run(url);
frame().set_document(&parser.document());
browsing_context().set_document(&parser.document());
}
// FIXME: Use an actual templating engine (our own one when it's built, preferably
@ -217,7 +217,7 @@ void FrameLoader::load_error_page(const URL& failed_url, const String& error)
generator.append(data);
auto document = HTML::parse_html_document(generator.as_string_view(), failed_url, "utf-8");
VERIFY(document);
frame().set_document(document);
browsing_context().set_document(document);
},
[](auto& error, auto) {
dbgln("Failed to load error page: {}", error);
@ -259,7 +259,7 @@ void FrameLoader::resource_did_load()
document->set_encoding(resource()->encoding());
document->set_content_type(resource()->mime_type());
frame().set_document(document);
browsing_context().set_document(document);
if (!parse_document(*document, resource()->encoded_data())) {
load_error_page(url, "Failed to parse content.");
@ -272,15 +272,15 @@ void FrameLoader::resource_did_load()
document->set_cookie(set_cookie.value(), Cookie::Source::Http);
if (!url.fragment().is_empty())
frame().scroll_to_anchor(url.fragment());
browsing_context().scroll_to_anchor(url.fragment());
if (auto* host_element = frame().host_element()) {
if (auto* host_element = browsing_context().host_element()) {
// FIXME: Perhaps in the future we'll have a better common base class for <frame> and <iframe>
VERIFY(is<HTML::HTMLIFrameElement>(*host_element));
downcast<HTML::HTMLIFrameElement>(*host_element).content_frame_did_load({});
downcast<HTML::HTMLIFrameElement>(*host_element).nested_browsing_context_did_load({});
}
if (auto* page = frame().page())
if (auto* page = browsing_context().page())
page->client().page_did_finish_loading(url);
}

View File

@ -23,7 +23,7 @@ public:
IFrame,
};
explicit FrameLoader(Frame&);
explicit FrameLoader(BrowsingContext&);
~FrameLoader();
bool load(const URL&, Type);
@ -31,8 +31,8 @@ public:
void load_html(const StringView&, const URL&);
Frame& frame() { return m_frame; }
const Frame& frame() const { return m_frame; }
BrowsingContext& browsing_context() { return m_browsing_context; }
const BrowsingContext& browsing_context() const { return m_browsing_context; }
private:
// ^ResourceClient
@ -42,7 +42,7 @@ private:
void load_error_page(const URL& failed_url, const String& error_message);
bool parse_document(DOM::Document&, const ByteBuffer& data);
Frame& m_frame;
BrowsingContext& m_browsing_context;
size_t m_redirects_count { 0 };
};

View File

@ -13,14 +13,14 @@
#include <LibWeb/Layout/BreakNode.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/UIEvents/EventNames.h>
namespace Web {
Frame::Frame(DOM::Element& host_element, Frame& main_frame)
: m_page(*main_frame.page())
, m_main_frame(main_frame)
BrowsingContext::BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context)
: m_page(*top_level_browsing_context.page())
, m_top_level_browsing_context(top_level_browsing_context)
, m_loader(*this)
, m_event_handler({}, *this)
, m_host_element(host_element)
@ -28,23 +28,23 @@ Frame::Frame(DOM::Element& host_element, Frame& main_frame)
setup();
}
Frame::Frame(Page& page)
BrowsingContext::BrowsingContext(Page& page)
: m_page(page)
, m_main_frame(*this)
, m_top_level_browsing_context(*this)
, m_loader(*this)
, m_event_handler({}, *this)
{
setup();
}
Frame::~Frame()
BrowsingContext::~BrowsingContext()
{
}
void Frame::setup()
void BrowsingContext::setup()
{
m_cursor_blink_timer = Core::Timer::construct(500, [this] {
if (!is_focused_frame())
if (!is_focused_context())
return;
if (m_cursor_position.node() && m_cursor_position.node()->layout_node()) {
m_cursor_blink_state = !m_cursor_blink_state;
@ -53,24 +53,24 @@ void Frame::setup()
});
}
void Frame::did_edit(Badge<EditEventHandler>)
void BrowsingContext::did_edit(Badge<EditEventHandler>)
{
reset_cursor_blink_cycle();
}
void Frame::reset_cursor_blink_cycle()
void BrowsingContext::reset_cursor_blink_cycle()
{
m_cursor_blink_state = true;
m_cursor_blink_timer->restart();
m_cursor_position.node()->layout_node()->set_needs_display();
}
bool Frame::is_focused_frame() const
bool BrowsingContext::is_focused_context() const
{
return m_page && &m_page->focused_frame() == this;
return m_page && &m_page->focused_context() == this;
}
void Frame::set_document(DOM::Document* document)
void BrowsingContext::set_document(DOM::Document* document)
{
if (m_document == document)
return;
@ -78,21 +78,21 @@ void Frame::set_document(DOM::Document* document)
m_cursor_position = {};
if (m_document)
m_document->detach_from_frame({}, *this);
m_document->detach_from_browsing_context({}, *this);
m_document = document;
if (m_document) {
m_document->attach_to_frame({}, *this);
if (m_page && is_main_frame())
m_document->attach_to_browsing_context({}, *this);
if (m_page && is_top_level())
m_page->client().page_did_change_title(m_document->title());
}
if (m_page)
m_page->client().page_did_set_document_in_main_frame(m_document);
m_page->client().page_did_set_document_in_top_level_browsing_context(m_document);
}
void Frame::set_viewport_rect(const Gfx::IntRect& rect)
void BrowsingContext::set_viewport_rect(const Gfx::IntRect& rect)
{
bool did_change = false;
@ -116,7 +116,7 @@ void Frame::set_viewport_rect(const Gfx::IntRect& rect)
}
}
void Frame::set_size(const Gfx::IntSize& size)
void BrowsingContext::set_size(const Gfx::IntSize& size)
{
if (m_size == size)
return;
@ -130,7 +130,7 @@ void Frame::set_size(const Gfx::IntSize& size)
client->frame_did_set_viewport_rect(viewport_rect());
}
void Frame::set_viewport_scroll_offset(const Gfx::IntPoint& offset)
void BrowsingContext::set_viewport_scroll_offset(const Gfx::IntPoint& offset)
{
if (m_viewport_scroll_offset == offset)
return;
@ -140,14 +140,14 @@ void Frame::set_viewport_scroll_offset(const Gfx::IntPoint& offset)
client->frame_did_set_viewport_rect(viewport_rect());
}
void Frame::set_needs_display(const Gfx::IntRect& rect)
void BrowsingContext::set_needs_display(const Gfx::IntRect& rect)
{
if (!viewport_rect().intersects(rect))
return;
if (is_main_frame()) {
if (is_top_level()) {
if (m_page)
m_page->client().page_did_invalidate(to_main_frame_rect(rect));
m_page->client().page_did_invalidate(to_top_level_rect(rect));
return;
}
@ -155,7 +155,7 @@ void Frame::set_needs_display(const Gfx::IntRect& rect)
host_element()->layout_node()->set_needs_display();
}
void Frame::scroll_to_anchor(const String& fragment)
void BrowsingContext::scroll_to_anchor(const String& fragment)
{
if (!document())
return;
@ -190,18 +190,18 @@ void Frame::scroll_to_anchor(const String& fragment)
m_page->client().page_did_request_scroll_into_view(enclosing_int_rect(float_rect));
}
Gfx::IntRect Frame::to_main_frame_rect(const Gfx::IntRect& a_rect)
Gfx::IntRect BrowsingContext::to_top_level_rect(const Gfx::IntRect& a_rect)
{
auto rect = a_rect;
rect.set_location(to_main_frame_position(a_rect.location()));
rect.set_location(to_top_level_position(a_rect.location()));
return rect;
}
Gfx::IntPoint Frame::to_main_frame_position(const Gfx::IntPoint& a_position)
Gfx::IntPoint BrowsingContext::to_top_level_position(const Gfx::IntPoint& a_position)
{
auto position = a_position;
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
if (ancestor->is_main_frame())
if (ancestor->is_top_level())
break;
if (!ancestor->host_element())
return {};
@ -212,7 +212,7 @@ Gfx::IntPoint Frame::to_main_frame_position(const Gfx::IntPoint& a_position)
return position;
}
void Frame::set_cursor_position(DOM::Position position)
void BrowsingContext::set_cursor_position(DOM::Position position)
{
if (m_cursor_position == position)
return;
@ -228,7 +228,7 @@ void Frame::set_cursor_position(DOM::Position position)
reset_cursor_blink_cycle();
}
String Frame::selected_text() const
String BrowsingContext::selected_text() const
{
StringBuilder builder;
if (!m_document)
@ -275,29 +275,29 @@ String Frame::selected_text() const
return builder.to_string();
}
void Frame::register_viewport_client(ViewportClient& client)
void BrowsingContext::register_viewport_client(ViewportClient& client)
{
auto result = m_viewport_clients.set(&client);
VERIFY(result == AK::HashSetResult::InsertedNewEntry);
}
void Frame::unregister_viewport_client(ViewportClient& client)
void BrowsingContext::unregister_viewport_client(ViewportClient& client)
{
bool was_removed = m_viewport_clients.remove(&client);
VERIFY(was_removed);
}
void Frame::register_frame_nesting(URL const& url)
void BrowsingContext::register_frame_nesting(URL const& url)
{
m_frame_nesting_levels.ensure(url)++;
}
bool Frame::is_frame_nesting_allowed(URL const& url) const
bool BrowsingContext::is_frame_nesting_allowed(URL const& url) const
{
return m_frame_nesting_levels.get(url).value_or(0) < 3;
}
bool Frame::increment_cursor_position_offset()
bool BrowsingContext::increment_cursor_position_offset()
{
if (!m_cursor_position.increment_offset())
return false;
@ -305,7 +305,7 @@ bool Frame::increment_cursor_position_offset()
return true;
}
bool Frame::decrement_cursor_position_offset()
bool BrowsingContext::decrement_cursor_position_offset()
{
if (!m_cursor_position.decrement_offset())
return false;

View File

@ -21,11 +21,11 @@
namespace Web {
class Frame : public TreeNode<Frame> {
class BrowsingContext : public TreeNode<BrowsingContext> {
public:
static NonnullRefPtr<Frame> create_subframe(DOM::Element& host_element, Frame& main_frame) { return adopt_ref(*new Frame(host_element, main_frame)); }
static NonnullRefPtr<Frame> create(Page& page) { return adopt_ref(*new Frame(page)); }
~Frame();
static NonnullRefPtr<BrowsingContext> create_nested(DOM::Element& host_element, BrowsingContext& top_level_browsing_context) { return adopt_ref(*new BrowsingContext(host_element, top_level_browsing_context)); }
static NonnullRefPtr<BrowsingContext> create(Page& page) { return adopt_ref(*new BrowsingContext(page)); }
~BrowsingContext();
class ViewportClient {
public:
@ -35,8 +35,8 @@ public:
void register_viewport_client(ViewportClient&);
void unregister_viewport_client(ViewportClient&);
bool is_main_frame() const { return this == &m_main_frame; }
bool is_focused_frame() const;
bool is_top_level() const { return this == &m_top_level_browsing_context; }
bool is_focused_context() const;
const DOM::Document* document() const { return m_document; }
DOM::Document* document() { return m_document; }
@ -63,14 +63,14 @@ public:
void scroll_to_anchor(const String&);
Frame& main_frame() { return m_main_frame; }
const Frame& main_frame() const { return m_main_frame; }
BrowsingContext& top_level_browsing_context() { return m_top_level_browsing_context; }
BrowsingContext const& top_level_browsing_context() const { return m_top_level_browsing_context; }
DOM::Element* host_element() { return m_host_element; }
const DOM::Element* host_element() const { return m_host_element; }
Gfx::IntPoint to_main_frame_position(const Gfx::IntPoint&);
Gfx::IntRect to_main_frame_rect(const Gfx::IntRect&);
Gfx::IntPoint to_top_level_position(const Gfx::IntPoint&);
Gfx::IntRect to_top_level_rect(const Gfx::IntRect&);
const DOM::Position& cursor_position() const { return m_cursor_position; }
void set_cursor_position(DOM::Position);
@ -90,15 +90,15 @@ public:
HashMap<URL, size_t> const& frame_nesting_levels() const { return m_frame_nesting_levels; }
private:
explicit Frame(DOM::Element& host_element, Frame& main_frame);
explicit Frame(Page&);
explicit BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context);
explicit BrowsingContext(Page&);
void reset_cursor_blink_cycle();
void setup();
WeakPtr<Page> m_page;
Frame& m_main_frame;
BrowsingContext& m_top_level_browsing_context;
FrameLoader m_loader;
EventHandler m_event_handler;

View File

@ -12,8 +12,8 @@
#include <LibWeb/DOM/Text.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Layout/LayoutPosition.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Page/EditEventHandler.h>
#include <LibWeb/Page/Frame.h>
namespace Web {

View File

@ -13,7 +13,7 @@ namespace Web {
class EditEventHandler {
public:
explicit EditEventHandler(Frame& frame)
explicit EditEventHandler(BrowsingContext& frame)
: m_frame(frame)
{
}
@ -25,7 +25,7 @@ public:
virtual void handle_insert(DOM::Position, u32 code_point);
private:
Frame& m_frame;
BrowsingContext& m_frame;
};
}

View File

@ -14,8 +14,8 @@
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/UIEvents/EventNames.h>
#include <LibWeb/UIEvents/MouseEvent.h>
@ -87,7 +87,7 @@ static Gfx::IntPoint compute_mouse_event_offset(const Gfx::IntPoint& position, c
};
}
EventHandler::EventHandler(Badge<Frame>, Frame& frame)
EventHandler::EventHandler(Badge<BrowsingContext>, BrowsingContext& frame)
: m_frame(frame)
, m_edit_event_handler(make<EditEventHandler>(frame))
{
@ -158,7 +158,7 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
if (result.layout_node && result.layout_node->dom_node()) {
RefPtr<DOM::Node> node = result.layout_node->dom_node();
if (is<HTML::HTMLIFrameElement>(*node)) {
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).content_frame())
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).nested_browsing_context())
return subframe->event_handler().handle_mouseup(position.translated(compute_mouse_event_offset({}, *result.layout_node)), button, modifiers);
return false;
}
@ -202,13 +202,13 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
return false;
if (is<HTML::HTMLIFrameElement>(*node)) {
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).content_frame())
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).nested_browsing_context())
return subframe->event_handler().handle_mousedown(position.translated(compute_mouse_event_offset({}, *result.layout_node)), button, modifiers);
return false;
}
if (auto* page = m_frame.page())
page->set_focused_frame({}, m_frame);
page->set_focused_browsing_context({}, m_frame);
auto offset = compute_mouse_event_offset(position, *result.layout_node);
node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mousedown, offset.x(), offset.y(), position.x(), position.y()));
@ -222,7 +222,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
auto& image_element = downcast<HTML::HTMLImageElement>(*node);
auto image_url = image_element.document().complete_url(image_element.src());
if (auto* page = m_frame.page())
page->client().page_did_request_image_context_menu(m_frame.to_main_frame_position(position), image_url, "", modifiers, image_element.bitmap());
page->client().page_did_request_image_context_menu(m_frame.to_top_level_position(position), image_url, "", modifiers, image_element.bitmap());
return true;
}
@ -237,7 +237,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
auto anchor = href.substring_view(1, href.length() - 1);
m_frame.scroll_to_anchor(anchor);
} else {
if (m_frame.is_main_frame()) {
if (m_frame.is_top_level()) {
if (auto* page = m_frame.page())
page->client().page_did_click_link(url, link->target(), modifiers);
} else {
@ -247,7 +247,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
}
} else if (button == GUI::MouseButton::Right) {
if (auto* page = m_frame.page())
page->client().page_did_request_link_context_menu(m_frame.to_main_frame_position(position), url, link->target(), modifiers);
page->client().page_did_request_link_context_menu(m_frame.to_top_level_position(position), url, link->target(), modifiers);
} else if (button == GUI::MouseButton::Middle) {
if (auto* page = m_frame.page())
page->client().page_did_middle_click_link(url, link->target(), modifiers);
@ -262,7 +262,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
}
} else if (button == GUI::MouseButton::Right) {
if (auto* page = m_frame.page())
page->client().page_did_request_context_menu(m_frame.to_main_frame_position(position));
page->client().page_did_request_context_menu(m_frame.to_top_level_position(position));
}
}
return true;
@ -299,7 +299,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
RefPtr<DOM::Node> node = result.layout_node->dom_node();
if (node && is<HTML::HTMLIFrameElement>(*node)) {
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).content_frame())
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).nested_browsing_context())
return subframe->event_handler().handle_mousemove(position.translated(compute_mouse_event_offset({}, *result.layout_node)), buttons, modifiers);
return false;
}
@ -340,7 +340,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
if (hovered_node_changed) {
RefPtr<HTML::HTMLElement> hovered_html_element = document.hovered_node() ? document.hovered_node()->enclosing_html_element_with_attribute(HTML::AttributeNames::title) : nullptr;
if (hovered_html_element && !hovered_html_element->title().is_null()) {
page->client().page_did_enter_tooltip_area(m_frame.to_main_frame_position(position), hovered_html_element->title());
page->client().page_did_enter_tooltip_area(m_frame.to_top_level_position(position), hovered_html_element->title());
} else {
page->client().page_did_leave_tooltip_area();
}

View File

@ -17,11 +17,11 @@
namespace Web {
class Frame;
class BrowsingContext;
class EventHandler {
public:
explicit EventHandler(Badge<Frame>, Frame&);
explicit EventHandler(Badge<BrowsingContext>, BrowsingContext&);
~EventHandler();
bool handle_mouseup(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
@ -42,7 +42,7 @@ private:
Layout::InitialContainingBlockBox* layout_root();
const Layout::InitialContainingBlockBox* layout_root() const;
Frame& m_frame;
BrowsingContext& m_frame;
bool m_in_mouse_selection { false };

View File

@ -5,7 +5,7 @@
*/
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Page/Page.h>
namespace Web {
@ -13,38 +13,38 @@ namespace Web {
Page::Page(PageClient& client)
: m_client(client)
{
m_main_frame = Frame::create(*this);
m_top_level_browsing_context = BrowsingContext::create(*this);
}
Page::~Page()
{
}
Frame& Page::focused_frame()
BrowsingContext& Page::focused_context()
{
if (m_focused_frame)
return *m_focused_frame;
return main_frame();
if (m_focused_context)
return *m_focused_context;
return top_level_browsing_context();
}
void Page::set_focused_frame(Badge<EventHandler>, Frame& frame)
void Page::set_focused_browsing_context(Badge<EventHandler>, BrowsingContext& browsing_context)
{
m_focused_frame = frame.make_weak_ptr();
m_focused_context = browsing_context.make_weak_ptr();
}
void Page::load(const URL& url)
{
main_frame().loader().load(url, FrameLoader::Type::Navigation);
top_level_browsing_context().loader().load(url, FrameLoader::Type::Navigation);
}
void Page::load(const LoadRequest& request)
{
main_frame().loader().load(request, FrameLoader::Type::Navigation);
top_level_browsing_context().loader().load(request, FrameLoader::Type::Navigation);
}
void Page::load_html(const StringView& html, const URL& url)
{
main_frame().loader().load_html(html, url);
top_level_browsing_context().loader().load_html(html, url);
}
Gfx::Palette Page::palette() const
@ -59,27 +59,27 @@ Gfx::IntRect Page::screen_rect() const
bool Page::handle_mousewheel(const Gfx::IntPoint& position, unsigned button, unsigned modifiers, int wheel_delta)
{
return main_frame().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta);
return top_level_browsing_context().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta);
}
bool Page::handle_mouseup(const Gfx::IntPoint& position, unsigned button, unsigned modifiers)
{
return main_frame().event_handler().handle_mouseup(position, button, modifiers);
return top_level_browsing_context().event_handler().handle_mouseup(position, button, modifiers);
}
bool Page::handle_mousedown(const Gfx::IntPoint& position, unsigned button, unsigned modifiers)
{
return main_frame().event_handler().handle_mousedown(position, button, modifiers);
return top_level_browsing_context().event_handler().handle_mousedown(position, button, modifiers);
}
bool Page::handle_mousemove(const Gfx::IntPoint& position, unsigned buttons, unsigned modifiers)
{
return main_frame().event_handler().handle_mousemove(position, buttons, modifiers);
return top_level_browsing_context().event_handler().handle_mousemove(position, buttons, modifiers);
}
bool Page::handle_keydown(KeyCode key, unsigned modifiers, u32 code_point)
{
return focused_frame().event_handler().handle_keydown(key, modifiers, code_point);
return focused_context().event_handler().handle_keydown(key, modifiers, code_point);
}
}

View File

@ -33,13 +33,13 @@ public:
PageClient& client() { return m_client; }
const PageClient& client() const { return m_client; }
Web::Frame& main_frame() { return *m_main_frame; }
const Web::Frame& main_frame() const { return *m_main_frame; }
Web::BrowsingContext& top_level_browsing_context() { return *m_top_level_browsing_context; }
const Web::BrowsingContext& top_level_browsing_context() const { return *m_top_level_browsing_context; }
Web::Frame& focused_frame();
const Web::Frame& focused_frame() const { return const_cast<Page*>(this)->focused_frame(); }
Web::BrowsingContext& focused_context();
const Web::BrowsingContext& focused_context() const { return const_cast<Page*>(this)->focused_context(); }
void set_focused_frame(Badge<EventHandler>, Frame&);
void set_focused_browsing_context(Badge<EventHandler>, BrowsingContext&);
void load(const URL&);
void load(const LoadRequest&);
@ -59,8 +59,8 @@ public:
private:
PageClient& m_client;
RefPtr<Frame> m_main_frame;
WeakPtr<Frame> m_focused_frame;
RefPtr<BrowsingContext> m_top_level_browsing_context;
WeakPtr<BrowsingContext> m_focused_context;
};
class PageClient {
@ -68,7 +68,7 @@ public:
virtual bool is_multi_process() const = 0;
virtual Gfx::Palette palette() const = 0;
virtual Gfx::IntRect screen_rect() const = 0;
virtual void page_did_set_document_in_main_frame(DOM::Document*) { }
virtual void page_did_set_document_in_top_level_browsing_context(DOM::Document*) { }
virtual void page_did_change_title(const String&) { }
virtual void page_did_start_loading(const URL&) { }
virtual void page_did_finish_loading(const URL&) { }

View File

@ -20,7 +20,7 @@
#include <LibWeb/Dump.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <WebContent/ClientConnection.h>
#include <WebContent/PageHost.h>
#include <WebContent/WebContentClientEndpoint.h>
@ -171,19 +171,19 @@ void ClientConnection::key_down(i32 key, unsigned int modifiers, u32 code_point)
void ClientConnection::debug_request(const String& request, const String& argument)
{
if (request == "dump-dom-tree") {
if (auto* doc = page().main_frame().document())
if (auto* doc = page().top_level_browsing_context().document())
Web::dump_tree(*doc);
}
if (request == "dump-layout-tree") {
if (auto* doc = page().main_frame().document()) {
if (auto* doc = page().top_level_browsing_context().document()) {
if (auto* icb = doc->layout_node())
Web::dump_tree(*icb);
}
}
if (request == "dump-style-sheets") {
if (auto* doc = page().main_frame().document()) {
if (auto* doc = page().top_level_browsing_context().document()) {
for (auto& sheet : doc->style_sheets().sheets()) {
Web::dump_sheet(sheet);
}
@ -197,7 +197,7 @@ void ClientConnection::debug_request(const String& request, const String& argume
if (request == "set-line-box-borders") {
bool state = argument == "on";
m_page_host->set_should_show_line_box_borders(state);
page().main_frame().set_needs_display(page().main_frame().viewport_rect());
page().top_level_browsing_context().set_needs_display(page().top_level_browsing_context().viewport_rect());
}
if (request == "clear-cache") {
@ -211,14 +211,14 @@ void ClientConnection::debug_request(const String& request, const String& argume
void ClientConnection::get_source()
{
if (auto* doc = page().main_frame().document()) {
if (auto* doc = page().top_level_browsing_context().document()) {
async_did_get_source(doc->url(), doc->source());
}
}
void ClientConnection::js_console_initialize()
{
if (auto* document = page().main_frame().document()) {
if (auto* document = page().top_level_browsing_context().document()) {
auto interpreter = document->interpreter().make_weak_ptr();
if (m_interpreter.ptr() == interpreter.ptr())
return;

View File

@ -10,7 +10,7 @@
#include <LibGfx/SystemTheme.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/Page/BrowsingContext.h>
#include <WebContent/WebContentClientEndpoint.h>
namespace WebContent {
@ -48,7 +48,7 @@ void PageHost::set_palette_impl(const Gfx::PaletteImpl& impl)
Web::Layout::InitialContainingBlockBox* PageHost::layout_root()
{
auto* document = page().main_frame().document();
auto* document = page().top_level_browsing_context().document();
if (!document)
return nullptr;
return document->layout_node();
@ -73,7 +73,7 @@ void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target)
void PageHost::set_viewport_rect(const Gfx::IntRect& rect)
{
page().main_frame().set_viewport_rect(rect);
page().top_level_browsing_context().set_viewport_rect(rect);
}
void PageHost::page_did_invalidate(const Gfx::IntRect& content_rect)