Skip to content

Commit

Permalink
Add support for double click events in CEF (Fixes #2963, PR #3040)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd authored Aug 15, 2023
1 parent 86f3344 commit 0daf588
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Client/cefweb/CWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void CWebView::InjectMouseMove(int iPosX, int iPosY)
m_vecMousePosition.y = iPosY;
}

void CWebView::InjectMouseDown(eWebBrowserMouseButton mouseButton)
void CWebView::InjectMouseDown(eWebBrowserMouseButton mouseButton, int count)
{
if (!m_pWebView)
return;
Expand All @@ -355,7 +355,7 @@ void CWebView::InjectMouseDown(eWebBrowserMouseButton mouseButton)
// Save mouse button states
m_mouseButtonStates[static_cast<int>(mouseButton)] = true;

m_pWebView->GetHost()->SendMouseClickEvent(mouseEvent, static_cast<CefBrowserHost::MouseButtonType>(mouseButton), false, 1);
m_pWebView->GetHost()->SendMouseClickEvent(mouseEvent, static_cast<CefBrowserHost::MouseButtonType>(mouseButton), false, count);
}

void CWebView::InjectMouseUp(eWebBrowserMouseButton mouseButton)
Expand Down
2 changes: 1 addition & 1 deletion Client/cefweb/CWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CWebView : public CWebViewInterface,
bool GetProperty(const SString& strKey, SString& outProperty);

void InjectMouseMove(int iPosX, int iPosY);
void InjectMouseDown(eWebBrowserMouseButton mouseButton);
void InjectMouseDown(eWebBrowserMouseButton mouseButton, int count);
void InjectMouseUp(eWebBrowserMouseButton mouseButton);
void InjectMouseWheel(int iScrollVert, int iScrollHorz);
void InjectKeyboardEvent(const CefKeyEvent& keyEvent);
Expand Down
21 changes: 18 additions & 3 deletions Client/gui/CGUIWebBrowser_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CGUIWebBrowser_Impl::CGUIWebBrowser_Impl(CGUI_Impl* pGUI, CGUIElement* pParent)
// Apply browser events
m_pWindow->subscribeEvent(CEGUI::Window::EventMouseButtonDown, CEGUI::Event::Subscriber(&CGUIWebBrowser_Impl::Event_MouseButtonDown, this));
m_pWindow->subscribeEvent(CEGUI::Window::EventMouseButtonUp, CEGUI::Event::Subscriber(&CGUIWebBrowser_Impl::Event_MouseButtonUp, this));
m_pWindow->subscribeEvent(CEGUI::Window::EventMouseDoubleClick, CEGUI::Event::Subscriber(&CGUIWebBrowser_Impl::Event_MouseDoubleClick, this));
m_pWindow->subscribeEvent(CEGUI::Window::EventMouseMove, CEGUI::Event::Subscriber(&CGUIWebBrowser_Impl::Event_MouseMove, this));
m_pWindow->subscribeEvent(CEGUI::Window::EventMouseWheel, CEGUI::Event::Subscriber(&CGUIWebBrowser_Impl::Event_MouseWheel, this));
m_pWindow->subscribeEvent(CEGUI::Window::EventActivated, CEGUI::Event::Subscriber(&CGUIWebBrowser_Impl::Event_Activated, this));
Expand Down Expand Up @@ -158,11 +159,11 @@ bool CGUIWebBrowser_Impl::Event_MouseButtonDown(const CEGUI::EventArgs& e)
const CEGUI::MouseEventArgs& args = reinterpret_cast<const CEGUI::MouseEventArgs&>(e);

if (args.button == CEGUI::MouseButton::LeftButton)
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT);
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT, 1);
else if (args.button == CEGUI::MouseButton::MiddleButton)
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE);
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE, 1);
else if (args.button == CEGUI::MouseButton::RightButton)
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT);
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT, 1);

return true;
}
Expand All @@ -181,6 +182,20 @@ bool CGUIWebBrowser_Impl::Event_MouseButtonUp(const CEGUI::EventArgs& e)
return true;
}

bool CGUIWebBrowser_Impl::Event_MouseDoubleClick(const CEGUI::EventArgs& e)
{
const CEGUI::MouseEventArgs& args = reinterpret_cast<const CEGUI::MouseEventArgs&>(e);

if (args.button == CEGUI::MouseButton::LeftButton)
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_LEFT, 2);
else if (args.button == CEGUI::MouseButton::MiddleButton)
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_MIDDLE, 2);
else if (args.button == CEGUI::MouseButton::RightButton)
m_pWebView->InjectMouseDown(eWebBrowserMouseButton::BROWSER_MOUSEBUTTON_RIGHT, 2);

return true;
}

bool CGUIWebBrowser_Impl::Event_MouseMove(const CEGUI::EventArgs& e)
{
const CEGUI::MouseEventArgs& args = reinterpret_cast<const CEGUI::MouseEventArgs&>(e);
Expand Down
1 change: 1 addition & 0 deletions Client/gui/CGUIWebBrowser_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CGUIWebBrowser_Impl : public CGUIWebBrowser, public CGUIElement_Impl
protected:
bool Event_MouseButtonDown(const CEGUI::EventArgs& e);
bool Event_MouseButtonUp(const CEGUI::EventArgs& e);
bool Event_MouseDoubleClick(const CEGUI::EventArgs& e);
bool Event_MouseWheel(const CEGUI::EventArgs& e);
bool Event_MouseMove(const CEGUI::EventArgs& e);
bool Event_Activated(const CEGUI::EventArgs& e);
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientWebBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ void CClientWebBrowser::InjectMouseMove(int iPosX, int iPosY)
m_pWebView->InjectMouseMove(iPosX, iPosY);
}

void CClientWebBrowser::InjectMouseDown(eWebBrowserMouseButton mouseButton)
void CClientWebBrowser::InjectMouseDown(eWebBrowserMouseButton mouseButton, int count)
{
m_pWebView->InjectMouseDown(mouseButton);
m_pWebView->InjectMouseDown(mouseButton, count);
}

void CClientWebBrowser::InjectMouseUp(eWebBrowserMouseButton mouseButton)
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientWebBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa
bool GetProperty(const SString& strKey, SString& outValue);

void InjectMouseMove(int iPosX, int iPosY);
void InjectMouseDown(eWebBrowserMouseButton mouseButton);
void InjectMouseDown(eWebBrowserMouseButton mouseButton, int count);
void InjectMouseUp(eWebBrowserMouseButton mouseButton);
void InjectMouseWheel(int iScrollVert, int iScrollHorz);

Expand Down
10 changes: 6 additions & 4 deletions Client/mods/deathmatch/logic/luadefs/CLuaBrowserDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,19 @@ int CLuaBrowserDefs::InjectBrowserMouseMove(lua_State* luaVM)

int CLuaBrowserDefs::InjectBrowserMouseDown(lua_State* luaVM)
{
// bool injectBrowserMouseDown ( browser webBrowser, string mouseButton )
CClientWebBrowser* pWebBrowser;
eWebBrowserMouseButton mouseButton;
// bool injectBrowserMouseDown ( browser webBrowser, string mouseButton [ , bool doubleClick = false ] )
CClientWebBrowser* pWebBrowser{};
eWebBrowserMouseButton mouseButton{};
bool doubleClick{};

CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pWebBrowser);
argStream.ReadEnumString(mouseButton);
argStream.ReadBool(doubleClick, false);

if (!argStream.HasErrors())
{
pWebBrowser->InjectMouseDown(mouseButton);
pWebBrowser->InjectMouseDown(mouseButton, doubleClick ? 2 : 1);
lua_pushboolean(luaVM, true);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/core/CWebViewInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CWebViewInterface
virtual bool GetProperty(const SString& strKey, SString& outProperty) = 0;

virtual void InjectMouseMove(int iPosX, int iPosY) = 0;
virtual void InjectMouseDown(eWebBrowserMouseButton mouseButton) = 0;
virtual void InjectMouseDown(eWebBrowserMouseButton mouseButton, int count) = 0;
virtual void InjectMouseUp(eWebBrowserMouseButton mouseButton) = 0;
virtual void InjectMouseWheel(int iScrollVert, int iScrollHorz) = 0;

Expand Down

0 comments on commit 0daf588

Please sign in to comment.