OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::WebPanel Class Referenceabstract

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/WebPanel.hpp>

Inheritance diagram for Slic3r::GUI::WebPanel:
Collaboration diagram for Slic3r::GUI::WebPanel:

Public Member Functions

 WebPanel (wxWindow *parent, const char *bridge_script)

Protected Member Functions

wxWebView * browser () const
void post_to_page (const std::string &json)
virtual std::optional< std::string > page_html ()=0
virtual bool on_page_message (const std::string &kind, const nlohmann::json &data)=0

Private Member Functions

void on_load_event (wxWebViewEvent &event)
void on_navigated (wxWebViewEvent &event)
void on_script_message (wxWebViewEvent &event)
void on_webview_recreated (wxCommandEvent &event)
void apply_theme ()
void load_page_html ()

Private Attributes

wxWebView * m_browser {nullptr}
bool m_content_loaded {false}
bool m_own_page_load {false}
bool m_content_navigated {false}

Detailed Description

Constructor & Destructor Documentation

◆ WebPanel()

Slic3r::GUI::WebPanel::WebPanel ( wxWindow * parent,
const char * bridge_script )
22 : wxPanel(parent, wxID_ANY)
23{
24 SetBackgroundColour(wxGetApp().get_window_default_clr());
25 auto* sizer = new wxBoxSizer(wxVERTICAL);
26 SetSizer(sizer);
27
28 // Never null: WebView::CreateWebView substitutes a placeholder view when no backend is available.
30 m_browser->SetBackgroundColour(GetBackgroundColour());
31 m_browser->AddUserScript(wxString::FromUTF8(WebViewHostDialog::theme_user_script()));
32 m_browser->AddUserScript(wxString::FromUTF8(WebViewHostDialog::element_defaults_user_script()));
33 m_browser->AddUserScript(wxString::FromUTF8(bridge_script));
34 m_browser->Bind(wxEVT_WEBVIEW_LOADED, &WebPanel::on_load_event, this);
35 m_browser->Bind(wxEVT_WEBVIEW_ERROR, &WebPanel::on_load_event, this);
36 m_browser->Bind(wxEVT_WEBVIEW_NAVIGATED, &WebPanel::on_navigated, this);
37 m_browser->Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &WebPanel::on_script_message, this);
38 m_browser->Bind(EVT_WEBVIEW_RECREATED, &WebPanel::on_webview_recreated, this);
39 sizer->Add(m_browser, 1, wxEXPAND);
40}
void on_script_message(wxWebViewEvent &event)
Definition WebPanel.cpp:83
void on_navigated(wxWebViewEvent &event)
Definition WebPanel.cpp:69
void on_load_event(wxWebViewEvent &event)
Definition WebPanel.cpp:42
wxWebView * m_browser
Definition WebPanel.hpp:48
void on_webview_recreated(wxCommandEvent &event)
Definition WebPanel.cpp:94
static std::string element_defaults_user_script()
Definition WebViewHostDialog.cpp:102
static std::string theme_user_script()
Definition WebViewHostDialog.cpp:93
static wxWebView * CreateWebView(wxWindow *parent, wxString const &url)
Definition WebView.cpp:313
wxString bootstrap_url()
Definition WebHosting.cpp:50

References Slic3r::GUI::web_hosting::bootstrap_url(), WebView::CreateWebView(), Slic3r::GUI::WebViewHostDialog::element_defaults_user_script(), m_browser, on_load_event(), on_navigated(), on_script_message(), on_webview_recreated(), and Slic3r::GUI::WebViewHostDialog::theme_user_script().

Referenced by Slic3r::GUI::DockPanel::DockPanel(), and Slic3r::PluginPage::PluginPage().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ apply_theme()

void Slic3r::GUI::WebPanel::apply_theme ( )
private
104{
106}
static std::string theme_apply_script()
Definition WebViewHostDialog.cpp:88
static bool RunScript(wxWebView *webView, wxString const &msg)
Definition WebView.cpp:491

References m_browser, WebView::RunScript(), and Slic3r::GUI::WebViewHostDialog::theme_apply_script().

Referenced by on_load_event(), and on_webview_recreated().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ browser()

wxWebView * Slic3r::GUI::WebPanel::browser ( ) const
inlineprotected
28{ return m_browser; }

References m_browser.

Referenced by Slic3r::GUI::DockPanel::DockPanel(), Slic3r::PluginPage::PluginPage(), and Slic3r::PluginPage::on_new_window().

Here is the caller graph for this function:

◆ load_page_html()

void Slic3r::GUI::WebPanel::load_page_html ( )
private
76{
77 if (const std::optional<std::string> html = page_html()) {
78 m_own_page_load = true;
79 m_browser->SetPage(wxString::FromUTF8(*html), web_hosting::content_base_url());
80 }
81}
bool m_own_page_load
Definition WebPanel.hpp:50
virtual std::optional< std::string > page_html()=0
wxString content_base_url()
Definition WebHosting.cpp:55

References Slic3r::GUI::web_hosting::content_base_url(), m_browser, m_own_page_load, and page_html().

Referenced by on_load_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_load_event()

void Slic3r::GUI::WebPanel::on_load_event ( wxWebViewEvent & event)
private
43{
44 const bool loaded = event.GetEventType() == wxEVT_WEBVIEW_LOADED;
45 if (!m_content_loaded) {
46 // The first bootstrap load (or its error) triggers the swap to the plugin HTML.
47 m_content_loaded = true;
49 } else if (!web_hosting::is_content_url(event.GetURL())) {
50 // Not our document (a linked page, a substituted error page), or any document on Edge, which ignores
51 // the base URL and restores SetPage content on a reload itself; either way it takes the app theme.
52 if (loaded)
54 } else if (m_own_page_load) {
55 m_own_page_load = false;
56 // The document-start theme script is fixed at creation, so re-apply the app theme.
57 if (loaded)
59 } else if (loaded && m_content_navigated) {
60 // WebKit reloads the SetPage base URL, so a committed load of it that we did not start is a
61 // reload. A failed navigation is reported against the page that stayed but never commits.
63 }
64 if (loaded)
65 m_content_navigated = false;
66 event.Skip();
67}
bool m_content_loaded
Definition WebPanel.hpp:49
void load_page_html()
Definition WebPanel.cpp:75
bool m_content_navigated
Definition WebPanel.hpp:51
void apply_theme()
Definition WebPanel.cpp:103
bool is_content_url(const wxString &url)
Definition WebHosting.cpp:60

References apply_theme(), Slic3r::GUI::web_hosting::is_content_url(), load_page_html(), m_content_loaded, m_content_navigated, and m_own_page_load.

Referenced by WebPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_navigated()

void Slic3r::GUI::WebPanel::on_navigated ( wxWebViewEvent & event)
private
70{
72 event.Skip();
73}

References Slic3r::GUI::web_hosting::is_content_url(), and m_content_navigated.

Referenced by WebPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_page_message()

virtual bool Slic3r::GUI::WebPanel::on_page_message ( const std::string & kind,
const nlohmann::json & data )
protectedpure virtual

Implemented in Slic3r::GUI::DockPanel, and Slic3r::PluginPage.

Referenced by on_script_message().

Here is the caller graph for this function:

◆ on_script_message()

void Slic3r::GUI::WebPanel::on_script_message ( wxWebViewEvent & event)
private
84{
85 const nlohmann::json payload = nlohmann::json::parse(event.GetString().utf8_string(), nullptr, false);
86 if (!payload.is_object() || payload.value("channel", std::string()) != "orca")
87 return;
88
89 const std::string kind = payload.value("kind", std::string());
90 if (!on_page_message(kind, payload.contains("data") ? payload["data"] : nlohmann::json()))
91 BOOST_LOG_TRIVIAL(warning) << "WebPanel ignored a window.orca '" << kind << "' call; this host does not support it";
92}
virtual bool on_page_message(const std::string &kind, const nlohmann::json &data)=0

References on_page_message().

Referenced by WebPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_webview_recreated()

void Slic3r::GUI::WebPanel::on_webview_recreated ( wxCommandEvent & event)
private
95{
96 SetBackgroundColour(wxGetApp().get_window_default_clr());
97 m_browser->SetBackgroundColour(GetBackgroundColour());
98 Refresh();
99 // Handled without Skip(), so WebView::RecreateAll() does not reload the plugin page.
100 apply_theme();
101}

References apply_theme(), and m_browser.

Referenced by WebPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ page_html()

virtual std::optional< std::string > Slic3r::GUI::WebPanel::page_html ( )
protectedpure virtual

Implemented in Slic3r::GUI::DockPanel, and Slic3r::PluginPage.

Referenced by load_page_html().

Here is the caller graph for this function:

◆ post_to_page()

void Slic3r::GUI::WebPanel::post_to_page ( const std::string & json)
protected
109{
110 WebView::RunScript(m_browser, wxString::Format(
111 "(function dispatch(payload, attempts) {\n"
112 " if (typeof window.__orcaDispatch === 'function') { window.__orcaDispatch(payload); return; }\n"
113 " if (attempts < 100) window.setTimeout(function() { dispatch(payload, attempts + 1); }, 25);\n"
114 "})({data: %s}, 0);",
115 wxString::FromUTF8(json)));
116}
nlohmann::json json
Definition AssembleList.cpp:42

References m_browser, and WebView::RunScript().

Referenced by Slic3r::GUI::DockPanel::push_message(), and Slic3r::PluginPage::push_message().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_browser

wxWebView* Slic3r::GUI::WebPanel::m_browser {nullptr}
private

◆ m_content_loaded

bool Slic3r::GUI::WebPanel::m_content_loaded {false}
private
49{false};

Referenced by on_load_event().

◆ m_content_navigated

bool Slic3r::GUI::WebPanel::m_content_navigated {false}
private
51{false}; // a navigation to the base URL has committed

Referenced by on_load_event(), and on_navigated().

◆ m_own_page_load

bool Slic3r::GUI::WebPanel::m_own_page_load {false}
private
50{false}; // a SetPage of the plugin HTML is in flight

Referenced by load_page_html(), and on_load_event().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/WebPanel.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/WebPanel.cpp