@@ -1290,14 +1290,94 @@ class MCCefBrowserClient : public CefClient, CefLifeSpanHandler, CefRequestHandl
1290
1290
if (nil == m_owner)
1291
1291
return ;
1292
1292
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
1295
1298
p_model->Clear ();
1296
1299
}
1297
1300
1298
1301
IMPLEMENT_REFCOUNTING (MCCefBrowserClient);
1299
1302
};
1300
1303
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
+
1301
1381
bool MCCefBrowserBase::Initialize ()
1302
1382
{
1303
1383
// create client and browser
@@ -1357,7 +1437,7 @@ MCCefBrowserBase::MCCefBrowserBase()
1357
1437
m_instance_id = 0 ;
1358
1438
1359
1439
m_send_advanced_messages = false ;
1360
- m_show_context_menu = false ;
1440
+ m_show_context_menu = true ;
1361
1441
m_allow_new_window = false ;
1362
1442
1363
1443
m_javascript_handlers = nil;
0 commit comments