diff options
-rw-r--r-- | Base/home/anon/www/iframe-subframe.html | 2 | ||||
-rw-r--r-- | Base/home/anon/www/iframe.html | 6 | ||||
-rw-r--r-- | Base/home/anon/www/welcome.html | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/ElementFactory.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/HTMLIFrameElement.cpp | 96 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/HTMLIFrameElement.h | 57 | ||||
-rw-r--r-- | Libraries/LibWeb/Frame.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibWeb/Frame.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutFrame.cpp | 88 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutFrame.h | 57 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutNode.h | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutReplaced.h | 1 |
13 files changed, 321 insertions, 0 deletions
diff --git a/Base/home/anon/www/iframe-subframe.html b/Base/home/anon/www/iframe-subframe.html new file mode 100644 index 0000000000..b6f6111027 --- /dev/null +++ b/Base/home/anon/www/iframe-subframe.html @@ -0,0 +1,2 @@ +This is inside the frame! +<img src=90s-bg.png> diff --git a/Base/home/anon/www/iframe.html b/Base/home/anon/www/iframe.html new file mode 100644 index 0000000000..6b07d626f0 --- /dev/null +++ b/Base/home/anon/www/iframe.html @@ -0,0 +1,6 @@ +<body> + <p>This page has an iframe in it + <p>Cool huh? + <iframe width=300 height=200 src="iframe-subframe.html" style="border: 1px solid #444"></iframe> + <p><b>this text is after the iframe</b> +</body> diff --git a/Base/home/anon/www/welcome.html b/Base/home/anon/www/welcome.html index 5c6b5b081b..cfbaca3176 100644 --- a/Base/home/anon/www/welcome.html +++ b/Base/home/anon/www/welcome.html @@ -28,6 +28,7 @@ span#ua { <p>Your user agent is: <b><span id="ua"></span></b></p> <p>Some small test pages:</p> <ul> + <li><a href="iframe.html">iframe</a></li> <li><a href="many-buggies.html">many buggies</a></li> <li><a href="palette.html">system palette color css extension</a></li> <li><a href="inline-block-link.html">link inside display: inline-block</a></li> diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 02b98b3133..f81bb46086 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -48,6 +48,7 @@ set(SOURCES DOM/HTMLHeadingElement.cpp DOM/HTMLHRElement.cpp DOM/HTMLHtmlElement.cpp + DOM/HTMLIFrameElement.cpp DOM/HTMLImageElement.cpp DOM/HTMLInputElement.cpp DOM/HTMLLinkElement.cpp @@ -70,6 +71,7 @@ set(SOURCES Layout/LayoutBreak.cpp Layout/LayoutCanvas.cpp Layout/LayoutDocument.cpp + Layout/LayoutFrame.cpp Layout/LayoutImage.cpp Layout/LayoutInline.cpp Layout/LayoutListItem.cpp diff --git a/Libraries/LibWeb/DOM/ElementFactory.cpp b/Libraries/LibWeb/DOM/ElementFactory.cpp index bb4f13fa00..38fe0f4048 100644 --- a/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -36,6 +36,7 @@ #include <LibWeb/DOM/HTMLHeadElement.h> #include <LibWeb/DOM/HTMLHeadingElement.h> #include <LibWeb/DOM/HTMLHtmlElement.h> +#include <LibWeb/DOM/HTMLIFrameElement.h> #include <LibWeb/DOM/HTMLImageElement.h> #include <LibWeb/DOM/HTMLInputElement.h> #include <LibWeb/DOM/HTMLLinkElement.h> @@ -76,6 +77,8 @@ NonnullRefPtr<Element> create_element(Document& document, const FlyString& tag_n return adopt(*new HTMLInputElement(document, lowercase_tag_name)); if (lowercase_tag_name == "br") return adopt(*new HTMLBRElement(document, lowercase_tag_name)); + if (lowercase_tag_name == "iframe") + return adopt(*new HTMLIFrameElement(document, lowercase_tag_name)); if (lowercase_tag_name == "h1" || lowercase_tag_name == "h2" || lowercase_tag_name == "h3" diff --git a/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp b/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp new file mode 100644 index 0000000000..aab32ea2b5 --- /dev/null +++ b/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 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. + */ + +#include <LibCore/ElapsedTimer.h> +#include <LibGUI/Button.h> +#include <LibGUI/TextBox.h> +#include <LibWeb/DOM/Document.h> +#include <LibWeb/DOM/Event.h> +#include <LibWeb/DOM/HTMLFormElement.h> +#include <LibWeb/DOM/HTMLIFrameElement.h> +#include <LibWeb/Dump.h> +#include <LibWeb/Frame.h> +#include <LibWeb/Layout/LayoutFrame.h> +#include <LibWeb/Layout/LayoutWidget.h> +#include <LibWeb/Loader/ResourceLoader.h> +#include <LibWeb/PageView.h> +#include <LibWeb/Parser/HTMLDocumentParser.h> + +namespace Web { + +HTMLIFrameElement::HTMLIFrameElement(Document& document, const FlyString& tag_name) + : HTMLElement(document, tag_name) +{ + m_hosted_frame = Frame::create_subframe(); +} + +HTMLIFrameElement::~HTMLIFrameElement() +{ +} + +RefPtr<LayoutNode> HTMLIFrameElement::create_layout_node(const StyleProperties* parent_style) const +{ + auto style = document().style_resolver().resolve_style(*this, parent_style); + return adopt(*new LayoutFrame(*this, move(style))); +} + +void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& value) +{ + HTMLElement::parse_attribute(name, value); + + if (name == HTML::AttributeNames::src) { + load_src(value); + return; + } +} + +void HTMLIFrameElement::load_src(const String& value) +{ + dbg() << "Loading iframe document from " << value; + auto url = document().complete_url(value); + if (!url.is_valid()) { + dbg() << "Actually no I'm not, because the URL is not valid :("; + return; + } + + ResourceLoader::the().load_sync( + url, + [&](auto& data, auto& headers) { + (void)headers; + auto html_source = String::copy(data); + HTMLDocumentParser parser(html_source, "utf-8"); + parser.run(url); + m_hosted_frame->set_document(&parser.document()); + + dbg() << "The hosted frame now has this DOM:"; + dump_tree(*m_hosted_frame->document()); + }, + [&](auto& error) { + dbg() << "<iframe> failed to load: " << error; + }); +} + +} diff --git a/Libraries/LibWeb/DOM/HTMLIFrameElement.h b/Libraries/LibWeb/DOM/HTMLIFrameElement.h new file mode 100644 index 0000000000..0a209e2f3f --- /dev/null +++ b/Libraries/LibWeb/DOM/HTMLIFrameElement.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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. + */ + +#pragma once + +#include <LibWeb/DOM/HTMLElement.h> + +namespace Web { + +class HTMLIFrameElement : public HTMLElement { +public: + HTMLIFrameElement(Document&, const FlyString& tag_name); + virtual ~HTMLIFrameElement() override; + + virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override; + + Frame* hosted_frame() { return m_hosted_frame; } + const Frame* hosted_frame() const { return m_hosted_frame; } + + virtual void parse_attribute(const FlyString& name, const String& value) override; + +private: + void load_src(const String&); + + RefPtr<Frame> m_hosted_frame; +}; + +template<> +inline bool is<HTMLIFrameElement>(const Node& node) +{ + return is<Element>(node) && to<Element>(node).tag_name().equals_ignoring_case("iframe"); +} + +} diff --git a/Libraries/LibWeb/Frame.cpp b/Libraries/LibWeb/Frame.cpp index e1d93354e5..3e72cacb99 100644 --- a/Libraries/LibWeb/Frame.cpp +++ b/Libraries/LibWeb/Frame.cpp @@ -32,6 +32,10 @@ namespace Web { +Frame::Frame() +{ +} + Frame::Frame(PageView& page_view) : m_page_view(page_view.make_weak_ptr()) { diff --git a/Libraries/LibWeb/Frame.h b/Libraries/LibWeb/Frame.h index 9d30cdf8a1..eda008379b 100644 --- a/Libraries/LibWeb/Frame.h +++ b/Libraries/LibWeb/Frame.h @@ -41,6 +41,7 @@ class PageView; class Frame : public TreeNode<Frame> { public: + static NonnullRefPtr<Frame> create_subframe() { return adopt(*new Frame); } static NonnullRefPtr<Frame> create(PageView& page_view) { return adopt(*new Frame(page_view)); } ~Frame(); @@ -64,6 +65,7 @@ public: void did_scroll(Badge<PageView>); private: + Frame(); explicit Frame(PageView&); WeakPtr<PageView> m_page_view; diff --git a/Libraries/LibWeb/Layout/LayoutFrame.cpp b/Libraries/LibWeb/Layout/LayoutFrame.cpp new file mode 100644 index 0000000000..288eac3648 --- /dev/null +++ b/Libraries/LibWeb/Layout/LayoutFrame.cpp @@ -0,0 +1,88 @@ +/* + * 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. + */ + +#include <LibGUI/Painter.h> +#include <LibGUI/ScrollBar.h> +#include <LibGUI/Widget.h> +#include <LibGfx/Font.h> +#include <LibGfx/StylePainter.h> +#include <LibWeb/DOM/Document.h> +#include <LibWeb/Frame.h> +#include <LibWeb/Layout/LayoutDocument.h> +#include <LibWeb/Layout/LayoutFrame.h> +#include <LibWeb/PageView.h> + +namespace Web { + +LayoutFrame::LayoutFrame(const Element& element, NonnullRefPtr<StyleProperties> style) + : LayoutReplaced(element, move(style)) +{ +} + +LayoutFrame::~LayoutFrame() +{ +} + +void LayoutFrame::layout(LayoutMode layout_mode) +{ + set_has_intrinsic_width(true); + set_has_intrinsic_height(true); + // FIXME: Do proper error checking, etc. + bool ok; + set_intrinsic_width(node().attribute(HTML::AttributeNames::width).to_int(ok)); + set_intrinsic_height(node().attribute(HTML::AttributeNames::height).to_int(ok)); + + LayoutReplaced::layout(layout_mode); +} + +void LayoutFrame::render(RenderingContext& context) +{ + LayoutReplaced::render(context); + + context.painter().save(); + auto old_viewport_rect = context.viewport_rect(); + + context.painter().add_clip_rect(enclosing_int_rect(rect())); + context.painter().translate(x(), y()); + + context.set_viewport_rect({ {}, node().hosted_frame()->size() }); + node().hosted_frame()->document()->layout_node()->render(context); + + context.set_viewport_rect(old_viewport_rect); + context.painter().restore(); +} + +void LayoutFrame::did_set_rect() +{ + LayoutReplaced::did_set_rect(); + + ASSERT(node().hosted_frame()); + node().hosted_frame()->set_size(Gfx::Size(rect().width(), rect().height())); + + node().hosted_frame()->document()->layout(); +} + +} diff --git a/Libraries/LibWeb/Layout/LayoutFrame.h b/Libraries/LibWeb/Layout/LayoutFrame.h new file mode 100644 index 0000000000..d7e2015f68 --- /dev/null +++ b/Libraries/LibWeb/Layout/LayoutFrame.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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. + */ + +#pragma once + +#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/DOM/HTMLIFrameElement.h> + +namespace Web { + +class LayoutFrame final : public LayoutReplaced { +public: + LayoutFrame(const Element&, NonnullRefPtr<StyleProperties>); + virtual ~LayoutFrame() override; + + virtual void render(RenderingContext&) override; + virtual void layout(LayoutMode) override; + + const HTMLIFrameElement& node() const { return static_cast<const HTMLIFrameElement&>(LayoutReplaced::node()); } + HTMLIFrameElement& node() { return static_cast<HTMLIFrameElement&>(LayoutReplaced::node()); } + +private: + virtual bool is_frame() const final { return true; } + virtual const char* class_name() const override { return "LayoutFrame"; } + virtual void did_set_rect() override; +}; + +template<> +inline bool is<LayoutFrame>(const LayoutNode& node) +{ + return node.is_frame(); +} + +} diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/LayoutNode.h index 8c31244e9c..dc46e6019b 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/LayoutNode.h @@ -60,6 +60,7 @@ public: bool is_anonymous() const { return !m_node; } const Node* node() const { return m_node; } + Node* node() { return const_cast<Node*>(m_node); } Document& document(); const Document& document() const; @@ -87,6 +88,7 @@ public: virtual bool is_block() const { return false; } virtual bool is_replaced() const { return false; } virtual bool is_widget() const { return false; } + virtual bool is_frame() const { return false; } virtual bool is_image() const { return false; } virtual bool is_canvas() const { return false; } virtual bool is_box() const { return false; } diff --git a/Libraries/LibWeb/Layout/LayoutReplaced.h b/Libraries/LibWeb/Layout/LayoutReplaced.h index 99450b3a79..f3e9669f3b 100644 --- a/Libraries/LibWeb/Layout/LayoutReplaced.h +++ b/Libraries/LibWeb/Layout/LayoutReplaced.h @@ -37,6 +37,7 @@ public: virtual ~LayoutReplaced() override; const Element& node() const { return to<Element>(*LayoutNode::node()); } + Element& node() { return to<Element>(*LayoutNode::node()); } virtual bool is_replaced() const final { return true; } |