2020-01-18 05:38:21 -03: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-05-28 15:40:53 -03:00
|
|
|
|
2019-09-25 06:44:22 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-10-05 05:16:27 -03:00
|
|
|
#include <AK/URL.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/ScrollableWidget.h>
|
2020-03-07 06:32:51 -03:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-07-28 14:27:41 -03:00
|
|
|
#include <LibWeb/Page/Page.h>
|
2020-07-06 16:18:16 -03:00
|
|
|
#include <LibWeb/WebViewHooks.h>
|
2019-09-25 06:44:22 -03:00
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
namespace Web {
|
|
|
|
|
|
2020-08-17 10:58:29 -03:00
|
|
|
class InProcessWebView final
|
2020-06-08 15:31:49 -03:00
|
|
|
: public GUI::ScrollableWidget
|
2020-07-06 16:18:16 -03:00
|
|
|
, public WebViewHooks
|
2020-06-08 15:31:49 -03:00
|
|
|
, public PageClient {
|
2020-08-17 10:58:29 -03:00
|
|
|
C_OBJECT(InProcessWebView);
|
2020-06-07 09:40:38 -03:00
|
|
|
|
2019-09-25 06:44:22 -03:00
|
|
|
public:
|
2020-08-17 10:58:29 -03:00
|
|
|
virtual ~InProcessWebView() override;
|
2019-09-25 06:44:22 -03:00
|
|
|
|
2020-06-21 16:37:07 -03:00
|
|
|
void load_html(const StringView&, const URL&);
|
2020-06-06 08:02:44 -03:00
|
|
|
void load_empty_document();
|
2020-05-27 16:57:30 -03:00
|
|
|
|
2020-07-26 14:37:56 -03:00
|
|
|
DOM::Document* document();
|
|
|
|
|
const DOM::Document* document() const;
|
2020-06-06 08:02:44 -03:00
|
|
|
|
2020-07-26 14:37:56 -03:00
|
|
|
void set_document(DOM::Document*);
|
2019-09-25 06:44:22 -03:00
|
|
|
|
2019-10-13 07:34:25 -03:00
|
|
|
const LayoutDocument* layout_root() const;
|
|
|
|
|
LayoutDocument* layout_root();
|
|
|
|
|
|
2019-10-05 05:16:27 -03:00
|
|
|
void reload();
|
2020-06-06 08:02:44 -03:00
|
|
|
bool load(const URL&);
|
2019-10-05 05:16:27 -03:00
|
|
|
|
|
|
|
|
URL url() const;
|
|
|
|
|
|
2019-10-12 10:02:53 -03:00
|
|
|
void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
|
|
|
|
|
|
2019-10-17 16:36:22 -03:00
|
|
|
virtual bool accepts_focus() const override { return true; }
|
|
|
|
|
|
2020-07-03 15:54:53 -03:00
|
|
|
GUI::Action& select_all_action() { return *m_select_all_action; }
|
2020-07-03 15:35:19 -03:00
|
|
|
GUI::Action& copy_action() { return *m_copy_action; }
|
2020-07-03 15:54:53 -03:00
|
|
|
|
2020-07-03 15:35:19 -03:00
|
|
|
String selected_text() const;
|
2020-07-03 15:54:53 -03:00
|
|
|
void select_all();
|
2020-07-03 15:35:19 -03:00
|
|
|
|
2020-06-08 15:31:49 -03:00
|
|
|
private:
|
2020-08-17 10:58:29 -03:00
|
|
|
InProcessWebView();
|
2019-09-25 06:44:22 -03:00
|
|
|
|
2020-06-08 15:31:49 -03:00
|
|
|
Page& page() { return *m_page; }
|
|
|
|
|
const Page& page() const { return *m_page; }
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual void resize_event(GUI::ResizeEvent&) override;
|
|
|
|
|
virtual void paint_event(GUI::PaintEvent&) override;
|
|
|
|
|
virtual void mousemove_event(GUI::MouseEvent&) override;
|
|
|
|
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
|
|
|
|
virtual void mouseup_event(GUI::MouseEvent&) override;
|
|
|
|
|
virtual void keydown_event(GUI::KeyEvent&) override;
|
2020-05-10 16:03:37 -03:00
|
|
|
virtual void drop_event(GUI::DropEvent&) override;
|
2019-09-25 06:44:22 -03:00
|
|
|
|
2019-12-18 16:54:23 -03:00
|
|
|
virtual void did_scroll() override;
|
|
|
|
|
|
2020-06-08 15:31:49 -03:00
|
|
|
// ^Web::PageClient
|
2020-06-17 15:26:59 -03:00
|
|
|
virtual Gfx::Palette palette() const override { return GUI::ScrollableWidget::palette(); }
|
2020-06-08 15:31:49 -03:00
|
|
|
virtual void page_did_change_title(const String&) override;
|
2020-07-26 14:37:56 -03:00
|
|
|
virtual void page_did_set_document_in_main_frame(DOM::Document*) override;
|
2020-06-08 15:31:49 -03:00
|
|
|
virtual void page_did_start_loading(const URL&) override;
|
|
|
|
|
virtual void page_did_change_selection() override;
|
2020-09-10 14:25:13 -03:00
|
|
|
virtual void page_did_request_cursor_change(Gfx::StandardCursor) override;
|
2020-06-27 17:21:58 -03:00
|
|
|
virtual void page_did_request_context_menu(const Gfx::IntPoint&) override;
|
2020-07-06 15:00:56 -03:00
|
|
|
virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers) override;
|
2020-10-02 14:01:51 -03:00
|
|
|
virtual void page_did_request_image_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::Bitmap*) override;
|
2020-07-06 14:41:10 -03:00
|
|
|
virtual void page_did_click_link(const URL&, const String& target, unsigned modifiers) override;
|
|
|
|
|
virtual void page_did_middle_click_link(const URL&, const String& target, unsigned modifiers) override;
|
2020-06-10 05:57:59 -03:00
|
|
|
virtual void page_did_enter_tooltip_area(const Gfx::IntPoint&, const String&) override;
|
2020-06-08 15:31:49 -03:00
|
|
|
virtual void page_did_leave_tooltip_area() override;
|
|
|
|
|
virtual void page_did_hover_link(const URL&) override;
|
|
|
|
|
virtual void page_did_unhover_link() override;
|
2020-06-10 05:57:59 -03:00
|
|
|
virtual void page_did_invalidate(const Gfx::IntRect&) override;
|
2020-06-08 16:35:31 -03:00
|
|
|
virtual void page_did_change_favicon(const Gfx::Bitmap&) override;
|
2020-06-23 13:02:08 -03:00
|
|
|
virtual void page_did_layout() override;
|
2020-07-05 09:50:38 -03:00
|
|
|
virtual void page_did_request_scroll_into_view(const Gfx::IntRect&) override;
|
2020-09-12 06:56:13 -03:00
|
|
|
virtual void page_did_request_alert(const String&) override;
|
2020-05-27 16:57:30 -03:00
|
|
|
|
2019-09-25 06:44:22 -03:00
|
|
|
void layout_and_sync_size();
|
|
|
|
|
|
2019-10-12 10:02:53 -03:00
|
|
|
bool m_should_show_line_box_borders { false };
|
2020-06-08 15:31:49 -03:00
|
|
|
|
|
|
|
|
NonnullOwnPtr<Page> m_page;
|
2020-07-03 15:35:19 -03:00
|
|
|
|
|
|
|
|
RefPtr<GUI::Action> m_copy_action;
|
2020-07-03 15:54:53 -03:00
|
|
|
RefPtr<GUI::Action> m_select_all_action;
|
2019-09-25 06:44:22 -03:00
|
|
|
};
|
2020-03-07 06:27:02 -03:00
|
|
|
|
|
|
|
|
}
|