/////////////////////////////////////////////////////////////////////////////
// Author: Steven Lamerton
// Copyright: (c) 2013 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "webview_chromium.h"
//#if CEF_API == 3
#include "webview_chromium.h"
#include <wx/webview.h>
#include <wx/filesys.h>
#include <wx/msw/private.h>
#ifdef __VISUALC__
#pragma warning(push)
#pragma warning(disable:4100)
#endif
#include <include/cef_app.h>
#include <include/cef_browser.h>
#include <include/cef_string_visitor.h>
#include <include/cef_version.h>
#include "include/cef_sandbox_win.h"
#ifdef __VISUALC__
#pragma warning(pop)
#endif
extern const char wxWebViewBackendChromium[] = "wxWebViewChromium";
wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewChromium, wxWebView);
bool wxWebViewChromium::Create(wxWindow* parent,
wxWindowID id,
const wxString& url,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
if (!wxControl::Create(parent, id, pos, size, style,
wxDefaultValidator, name))
{
return false;
}
m_historyLoadingFromList = false;
m_historyEnabled = true;
m_historyPosition = -1;
m_zoomLevel = wxWEBVIEW_ZOOM_MEDIUM;
CefBrowserSettings browsersettings;
CefWindowInfo info;
m_clientHandler = new ClientHandler();
m_clientHandler->SetWebView(this);
#ifdef __WXMSW__
// Initialize window info to the defaults for a child window
info.SetAsChild(GetHWND(), wxGetClientRect(this->GetHWND()));
#endif
// Creat the new child browser window, we do this async as we use a multi
// threaded message loop
#if CHROME_VERSION_BUILD >= 1650
CefBrowserHost::CreateBrowser(info, static_cast<CefRefPtr<CefClient>>(m_clientHandler),
url.ToStdString(), browsersettings, NULL);
#else
CefBrowserHost::CreateBrowser(info, static_cast<CefRefPtr<CefClient>>(m_clientHandler),
url.ToStdString(), browsersettings);
#endif
this->Bind(wxEVT_SIZE, &wxWebViewChromium::OnSize, this);
return true;
}
wxWebViewChromium::~wxWebViewChromium()
{
//Shutdown();
#if CHROME_VERSION_BUILD < 2078
CefRefPtr<CefBrowser> browser = m_clientHandler->GetBrowser();
if (browser.get()) {
// Let the browser window know we are about to destroy it.
browser->GetHost()->ParentWindowWillClose();
}
#endif
}
void wxWebViewChromium::OnSize(wxSizeEvent& event)
{
wxSize size = GetClientSize();
#ifdef __WXMSW__
if(m_clientHandler && m_clientHandler->GetBrowser() && m_clientHandler->GetBrowser()->GetHost())
{
HWND handle = m_clientHandler->GetBrowser()->GetHost()->GetWindowHandle();
if(handle)
{
HDWP hdwp = BeginDeferWindowPos(1);
hdwp = DeferWindowPos(hdwp, handle, NULL, 0, 0,
size.GetWidth(), size.GetHeight(), SWP_NOZORDER);
EndDeferWindowPos(hdwp);
}
}
#endif
event.Skip();
}
void wxWebViewChromium::SetPageSource(const wxString& pageSource)
{
m_pageSource = pageSource;
}
void wxWebViewChromium::SetPageText(const wxString& pageText)
{
m_pageText = pageText;
}
void* wxWebViewChromium::GetNativeBackend() const
{
return m_clientHandler->GetBrowser();
}
bool wxWebViewChromium::CanGoForward() const
{
if(m_historyEnabled)
return m_historyPosition != static_cast<int>(m_historyList.size()) - 1;
else
return false;
}
bool wxWebViewChromium::CanGoBack() const
{
if(m_historyEnabled)
return m_historyPosition > 0;
else
return false;
}
void wxWebViewChromium::LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item)
{
int pos = -1;
for(unsigned int i = 0; i < m_historyList.size(); i++)
{
//We compare the actual pointers to find the correct �
评论2
最新资源