Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Commit 4f916d6

Browse filesBrowse files
author
Ian Macphail
committed
[[ Bug 22544 ]] Enable text editing options in CEF context menu
This patch updates the libbrowser CEF implementation to allow the right-click context menu to be shown with standard text editing options (Cut, Copy, Paste, Select All, etc.) and spellchecking replacement suggestions.
1 parent 70380da commit 4f916d6
Copy full SHA for 4f916d6

File tree

Expand file treeCollapse file tree

1 file changed

+83
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+83
-3
lines changed

‎libbrowser/src/libbrowser_cef.cpp

Copy file name to clipboardExpand all lines: libbrowser/src/libbrowser_cef.cpp
+83-3Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,14 +1290,94 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
12901290
if (nil == m_owner)
12911291
return;
12921292

1293-
// clearing the menu model prevents the context menu from opening
1294-
if (!m_owner->GetEnableContextMenu())
1293+
extern void MCCefMenuFilterItems(CefRefPtr<CefMenuModel> p_menu);
1294+
1295+
if (m_owner->GetEnableContextMenu())
1296+
MCCefMenuFilterItems(p_model);
1297+
else
12951298
p_model->Clear();
12961299
}
12971300

12981301
IMPLEMENT_REFCOUNTING(MCCefBrowserClient);
12991302
};
13001303

1304+
void MCCefMenuFilterItems(CefRefPtr<CefMenuModel> p_menu)
1305+
{
1306+
// Remove unwanted items from the default menu,
1307+
// keeping text editing and autocorrect options
1308+
1309+
cef_menu_item_type_t t_prev_type = MENUITEMTYPE_NONE;
1310+
1311+
uindex_t t_item_count = p_menu->GetCount();
1312+
uindex_t t_index = 0;
1313+
while (t_index < t_item_count)
1314+
{
1315+
bool t_remove = false;
1316+
cef_menu_item_type_t t_type = p_menu->GetTypeAt(t_index);
1317+
if (t_type == MENUITEMTYPE_SUBMENU)
1318+
{
1319+
CefRefPtr<CefMenuModel> t_submenu;
1320+
t_submenu = p_menu->GetSubMenuAt(t_index);
1321+
MCCefMenuFilterItems(t_submenu);
1322+
// remove filtered submenu if empty
1323+
t_remove = t_submenu->GetCount() == 0;
1324+
}
1325+
else if (t_type == MENUITEMTYPE_SEPARATOR)
1326+
{
1327+
// remove separator if last item in menu was a separator
1328+
if (t_prev_type == MENUITEMTYPE_SEPARATOR)
1329+
t_remove = true;
1330+
}
1331+
else
1332+
{
1333+
int t_command_id;
1334+
t_command_id = p_menu->GetCommandIdAt(t_index);
1335+
switch (t_command_id)
1336+
{
1337+
case MENU_ID_UNDO:
1338+
case MENU_ID_REDO:
1339+
case MENU_ID_CUT:
1340+
case MENU_ID_COPY:
1341+
case MENU_ID_PASTE:
1342+
case MENU_ID_DELETE:
1343+
case MENU_ID_SELECT_ALL:
1344+
break;
1345+
1346+
case MENU_ID_SPELLCHECK_SUGGESTION_0:
1347+
case MENU_ID_SPELLCHECK_SUGGESTION_1:
1348+
case MENU_ID_SPELLCHECK_SUGGESTION_2:
1349+
case MENU_ID_SPELLCHECK_SUGGESTION_3:
1350+
case MENU_ID_SPELLCHECK_SUGGESTION_4:
1351+
case MENU_ID_NO_SPELLING_SUGGESTIONS:
1352+
case MENU_ID_ADD_TO_DICTIONARY:
1353+
break;
1354+
1355+
default:
1356+
t_remove = true;
1357+
break;
1358+
}
1359+
}
1360+
1361+
if (t_remove)
1362+
{
1363+
p_menu->RemoveAt(t_index);
1364+
t_item_count--;
1365+
}
1366+
else
1367+
{
1368+
// remember the type of this item
1369+
t_prev_type = t_type;
1370+
t_index++;
1371+
}
1372+
}
1373+
1374+
// if the last item is a separator then remove it
1375+
if (t_prev_type == MENUITEMTYPE_SEPARATOR)
1376+
{
1377+
p_menu->RemoveAt(t_item_count - 1);
1378+
}
1379+
}
1380+
13011381
bool MCCefBrowserBase::Initialize()
13021382
{
13031383
// create client and browser
@@ -1357,7 +1437,7 @@ MCCefBrowserBase::MCCefBrowserBase()
13571437
m_instance_id = 0;
13581438

13591439
m_send_advanced_messages = false;
1360-
m_show_context_menu = false;
1440+
m_show_context_menu = true;
13611441
m_allow_new_window = false;
13621442

13631443
m_javascript_handlers = nil;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.