Skip to content

Commit

Permalink
WIP Adding copy/paste commands #52
Browse files Browse the repository at this point in the history
AFAIK pasting inside a Godot input text makes the application freezing.
  • Loading branch information
Lecrapouille committed Apr 21, 2024
1 parent c9fca57 commit 84a533b
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
14 changes: 14 additions & 0 deletions addons/gdcef/demos/2D/CEF.gd
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ func _input(event):
if event.keycode == KEY_S:
# Will call the callback 'on_html_content_requested'
current_browser.request_html_content()
# FIXME copy()/paste() inside a Godot text entry will freeze the application
# https://github.com/chromiumembedded/cef/issues/3117
#if event.keycode == KEY_C:
# current_browser.copy()
#elif event.keycode == KEY_V:
# current_browser.paste()
#elif event.keycode == KEY_X:
# current_browser.cut()
#elif event.keycode == KEY_DELETE:
# current_browser.delete()
#elif event.keycode == KEY_Z:
# current_browser.undo()
#elif event.shift_pressed && event.keycode == KEY_Z:
# current_browser.redo()
else:
current_browser.set_key_pressed(
event.unicode if event.unicode != 0 else event.keycode,
Expand Down
7 changes: 7 additions & 0 deletions addons/gdcef/gdcef/src/browser_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ void GDBrowserView::leftMouseDown()
evt.modifiers = m_mouse_event_modifiers;

m_browser->GetHost()->SendMouseClickEvent(evt, btn, false, m_left_click_count);

// Copy selected text
// FIXME https://github.com/chromiumembedded/cef/issues/3117
//if ((m_left_click_count > 1) && m_browser->GetMainFrame())
//{
// m_browser->GetMainFrame()->Copy();
//}
}

//------------------------------------------------------------------------------
Expand Down
96 changes: 96 additions & 0 deletions addons/gdcef/gdcef/src/gdbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ void GDBrowserView::_bind_methods()
ClassDB::bind_method(D_METHOD("is_loaded"), &GDBrowserView::loaded);
ClassDB::bind_method(D_METHOD("reload"), &GDBrowserView::reload);
ClassDB::bind_method(D_METHOD("stop_loading"), &GDBrowserView::stopLoading);
ClassDB::bind_method(D_METHOD("copy"), &GDBrowserView::copy);
ClassDB::bind_method(D_METHOD("paste"), &GDBrowserView::paste);
ClassDB::bind_method(D_METHOD("undo"), &GDBrowserView::undo);
ClassDB::bind_method(D_METHOD("redo"), &GDBrowserView::redo);
ClassDB::bind_method(D_METHOD("request_html_content"), &GDBrowserView::requestHtmlContent);
ClassDB::bind_method(D_METHOD("execute_javascript"), &GDBrowserView::executeJavaScript);
ClassDB::bind_method(D_METHOD("has_previous_page"), &GDBrowserView::canNavigateBackward);
Expand Down Expand Up @@ -383,6 +387,98 @@ void GDBrowserView::stopLoading()
m_browser->StopLoad();
}

//------------------------------------------------------------------------------
// FIXME https://github.com/chromiumembedded/cef/issues/3117
void GDBrowserView::copy() const
{
BROWSER_DEBUG();

if (m_browser && m_browser->GetMainFrame())
{
m_browser->GetMainFrame()->Copy();
}
else
{
BROWSER_ERROR("copy failed");
}
}

//------------------------------------------------------------------------------
// FIXME https://github.com/chromiumembedded/cef/issues/3117
void GDBrowserView::paste() const
{
BROWSER_DEBUG();

if (m_browser && m_browser->GetMainFrame())
{
m_browser->GetMainFrame()->Paste();
}
else
{
BROWSER_ERROR("paste failed");
}
}

//------------------------------------------------------------------------------
void GDBrowserView::cut() const
{
BROWSER_DEBUG();

if (m_browser && m_browser->GetMainFrame())
{
m_browser->GetMainFrame()->Cut();
}
else
{
BROWSER_ERROR("cut failed");
}
}

//------------------------------------------------------------------------------
void GDBrowserView::delete_() const
{
BROWSER_DEBUG();

if (m_browser && m_browser->GetMainFrame())
{
m_browser->GetMainFrame()->Delete();
}
else
{
BROWSER_ERROR("delete failed");
}
}

//------------------------------------------------------------------------------
void GDBrowserView::undo() const
{
BROWSER_DEBUG();

if (m_browser && m_browser->GetMainFrame())
{
m_browser->GetMainFrame()->Undo();
}
else
{
BROWSER_ERROR("undo failed");
}
}

//------------------------------------------------------------------------------
void GDBrowserView::redo() const
{
BROWSER_DEBUG();

if (m_browser && m_browser->GetMainFrame())
{
m_browser->GetMainFrame()->Redo();
}
else
{
BROWSER_ERROR("redo failed");
}
}

//------------------------------------------------------------------------------
void GDBrowserView::requestHtmlContent()
{
Expand Down
31 changes: 31 additions & 0 deletions addons/gdcef/gdcef/src/gdbrowser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,37 @@ class GDBrowserView : public godot::Node
// -------------------------------------------------------------------------
bool reload() const;

// -------------------------------------------------------------------------
//! \brief Execute copy the selected text in the clipboard.
// -------------------------------------------------------------------------
void copy() const;

// -------------------------------------------------------------------------
//! \brief Execute the paste from the clipboard content.
//! FIXME https://github.com/chromiumembedded/cef/issues/3117
// -------------------------------------------------------------------------
void paste() const;

// -------------------------------------------------------------------------
//! \brief Execute cut the selected text.
// -------------------------------------------------------------------------
void cut() const;

// -------------------------------------------------------------------------
//! \brief Execute cut the selected text.
// -------------------------------------------------------------------------
void delete_() const;

// -------------------------------------------------------------------------
//! \brief Undo action.
// -------------------------------------------------------------------------
void undo() const;

// -------------------------------------------------------------------------
//! \brief Redo action.
// -------------------------------------------------------------------------
void redo() const;

// -------------------------------------------------------------------------
//! \brief Request the HTML content of the page. The result is given by the
//! Godot callback
Expand Down

0 comments on commit 84a533b

Please sign in to comment.