2019-04-19 17:19:57 +08:00
|
|
|
|
#include "browser_box.h"
|
|
|
|
|
#include "browser/multi_browser_form.h"
|
|
|
|
|
#include "browser/multi_browser_manager.h"
|
|
|
|
|
#include "taskbar/taskbar_manager.h"
|
|
|
|
|
|
|
|
|
|
using namespace ui;
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
BrowserBox::BrowserBox(std::string id)
|
|
|
|
|
{
|
|
|
|
|
taskbar_item_ = nullptr;
|
|
|
|
|
browser_form_ = nullptr;
|
|
|
|
|
cef_control_ = nullptr;
|
|
|
|
|
browser_id_ = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MultiBrowserForm* BrowserBox::GetBrowserForm() const
|
|
|
|
|
{
|
|
|
|
|
ASSERT(NULL != browser_form_);
|
|
|
|
|
ASSERT(::IsWindow(browser_form_->GetHWND()));
|
|
|
|
|
return browser_form_;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-22 12:21:38 +08:00
|
|
|
|
nim_comp::CefControlBase* BrowserBox::GetCefControl()
|
2019-04-19 17:19:57 +08:00
|
|
|
|
{
|
|
|
|
|
return cef_control_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::wstring& BrowserBox::GetTitle()
|
|
|
|
|
{
|
|
|
|
|
return title_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::InitBrowserBox(const std::wstring &url)
|
|
|
|
|
{
|
2019-09-22 12:21:38 +08:00
|
|
|
|
cef_control_ = static_cast<nim_comp::CefControlBase*>(FindSubControl(L"cef_control"));
|
2019-04-19 17:19:57 +08:00
|
|
|
|
cef_control_->AttachBeforeContextMenu(nbase::Bind(&BrowserBox::OnBeforeMenu, this, std::placeholders::_1, std::placeholders::_2));
|
|
|
|
|
cef_control_->AttachMenuCommand(nbase::Bind(&BrowserBox::OnMenuCommand, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
|
|
|
|
cef_control_->AttachTitleChange(nbase::Bind(&BrowserBox::OnTitleChange, this, std::placeholders::_1));
|
|
|
|
|
cef_control_->AttachUrlChange(nbase::Bind(&BrowserBox::OnUrlChange, this, std::placeholders::_1));
|
|
|
|
|
cef_control_->AttachLinkClick(nbase::Bind(&BrowserBox::OnLinkClick, this, std::placeholders::_1));
|
|
|
|
|
cef_control_->AttachBeforeNavigate(nbase::Bind(&BrowserBox::OnBeforeNavigate, this, std::placeholders::_1, std::placeholders::_2));
|
|
|
|
|
cef_control_->AttachLoadingStateChange(nbase::Bind(&BrowserBox::OnLoadingStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
|
|
|
|
cef_control_->AttachLoadStart(nbase::Bind(&BrowserBox::OnLoadStart, this));
|
|
|
|
|
cef_control_->AttachLoadEnd(nbase::Bind(&BrowserBox::OnLoadEnd, this, std::placeholders::_1));
|
|
|
|
|
cef_control_->AttachLoadError(nbase::Bind(&BrowserBox::OnLoadError, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD>ҳ
|
|
|
|
|
std::wstring html_path = url;
|
|
|
|
|
if (html_path.empty())
|
2019-09-20 16:27:58 +08:00
|
|
|
|
html_path = nbase::win32::GetCurrentModuleDirectory() + L"resources\\themes\\default\\cef\\cef.html";
|
2019-04-19 17:19:57 +08:00
|
|
|
|
|
|
|
|
|
cef_control_->LoadURL(html_path);
|
|
|
|
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ
|
|
|
|
|
if ((GetWindowExStyle(m_pWindow->GetHWND()) & WS_EX_LAYERED) != 0)
|
|
|
|
|
{
|
|
|
|
|
taskbar_item_ = new TaskbarTabItem(this);
|
|
|
|
|
if (taskbar_item_)
|
|
|
|
|
taskbar_item_->Init(url, browser_id_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Box<6F><78>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ʱ<EFBFBD>ѽ<EFBFBD><D1BD><EFBFBD>ת<EFBFBD>Ƹ<EFBFBD>Cef<65>ؼ<EFBFBD>
|
|
|
|
|
this->AttachSetFocus([this](ui::EventArgs* param)->bool
|
|
|
|
|
{
|
|
|
|
|
cef_control_->SetFocus();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::UninitBrowserBox()
|
|
|
|
|
{
|
|
|
|
|
MultiBrowserManager::GetInstance()->RemoveBorwserBox(browser_id_, this);
|
|
|
|
|
|
|
|
|
|
if (taskbar_item_)
|
|
|
|
|
taskbar_item_->UnInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui::Control* BrowserBox::CreateControl(const std::wstring& pstrClass)
|
|
|
|
|
{
|
|
|
|
|
if (pstrClass == L"CefControl")
|
|
|
|
|
{
|
2019-09-22 12:21:38 +08:00
|
|
|
|
if (nim_comp::CefManager::GetInstance()->IsEnableOffsetRender())
|
|
|
|
|
return new nim_comp::CefControl;
|
2019-04-19 17:19:57 +08:00
|
|
|
|
else
|
2019-09-22 12:21:38 +08:00
|
|
|
|
return new nim_comp::CefNativeControl;
|
2019-04-19 17:19:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskbarTabItem* BrowserBox::GetTaskbarItem()
|
|
|
|
|
{
|
|
|
|
|
return taskbar_item_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::SetWindow(Window* pManager, Box* pParent, bool bInit)
|
|
|
|
|
{
|
|
|
|
|
browser_form_ = dynamic_cast<MultiBrowserForm*>(pManager);
|
|
|
|
|
ASSERT(NULL != browser_form_);
|
|
|
|
|
|
|
|
|
|
__super::SetWindow(pManager, pParent, bInit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::SetInternVisible(bool bVisible /*= true*/)
|
|
|
|
|
{
|
|
|
|
|
Control::SetInternVisible(bVisible);
|
|
|
|
|
if (m_items.empty()) return;
|
|
|
|
|
for (auto it = m_items.begin(); it != m_items.end(); it++) {
|
|
|
|
|
(*it)->SetInternVisible(bVisible);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::Invalidate()
|
|
|
|
|
{
|
|
|
|
|
__super::Invalidate();
|
|
|
|
|
|
|
|
|
|
if (taskbar_item_)
|
|
|
|
|
taskbar_item_->InvalidateTab();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::SetPos(UiRect rc)
|
|
|
|
|
{
|
|
|
|
|
__super::SetPos(rc);
|
|
|
|
|
|
|
|
|
|
if (taskbar_item_)
|
|
|
|
|
taskbar_item_->InvalidateTab();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::OnBeforeMenu(CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BrowserBox::OnMenuCommand(CefRefPtr<CefContextMenuParams> params, int command_id, CefContextMenuHandler::EventFlags event_flags)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::OnTitleChange(const std::wstring& title)
|
|
|
|
|
{
|
|
|
|
|
title_ = title;
|
|
|
|
|
browser_form_->SetTabItemName(nbase::UTF8ToUTF16(browser_id_), title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::OnUrlChange(const std::wstring& url)
|
|
|
|
|
{
|
|
|
|
|
url_ = url;
|
|
|
|
|
browser_form_->SetURL(browser_id_, url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BrowserBox::OnLinkClick(const std::wstring& url)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CefRequestHandler::ReturnValue BrowserBox::OnBeforeNavigate(CefRefPtr<CefRequest> request, bool is_redirect)
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>RV_CANCEL<45>ضϵ<D8B6><CFB5><EFBFBD>
|
|
|
|
|
return RV_CONTINUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::OnLoadingStateChange(bool isLoading, bool canGoBack, bool canGoForward)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::OnLoadStart()
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::OnLoadEnd(int httpStatusCode)
|
|
|
|
|
{
|
|
|
|
|
// ע<><D7A2>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩǰ<E1B9A9>˵<EFBFBD><CBB5><EFBFBD>
|
2019-09-22 12:21:38 +08:00
|
|
|
|
cef_control_->RegisterCppFunc(L"ShowMessageBox", ToWeakCallback([](const std::string& params, nim_comp::ReportResultFunction callback) {
|
2019-04-19 17:19:57 +08:00
|
|
|
|
MessageBoxA(NULL, params.c_str(), "<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> JavaScript <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ", MB_OK);
|
|
|
|
|
callback(false, R"({ "message": "Success." })");
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowserBox::OnLoadError(CefLoadHandler::ErrorCode errorCode, const CefString& errorText, const CefString& failedUrl)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|