1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2024-11-24 08:02:15 +02:00

Added context menu to change the color mode in MiniBrowser

This commit is contained in:
Salvador Díaz Fau 2024-05-02 17:38:03 +02:00
parent d5bfa05d39
commit 08012881e0
4 changed files with 98 additions and 44 deletions

View File

@ -41,25 +41,29 @@ const
MINIBROWSER_HOMEPAGE = 'https://www.google.com';
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS = MENU_ID_USER_FIRST + 1;
MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS = MENU_ID_USER_FIRST + 2;
MINIBROWSER_CONTEXTMENU_COPYHTML = MENU_ID_USER_FIRST + 3;
MINIBROWSER_CONTEXTMENU_JSWRITEDOC = MENU_ID_USER_FIRST + 4;
MINIBROWSER_CONTEXTMENU_JSPRINTDOC = MENU_ID_USER_FIRST + 5;
MINIBROWSER_CONTEXTMENU_SHOWRESPONSE = MENU_ID_USER_FIRST + 6;
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS = MENU_ID_USER_FIRST + 7;
MINIBROWSER_CONTEXTMENU_COPYFRAMENAMES = MENU_ID_USER_FIRST + 8;
MINIBROWSER_CONTEXTMENU_SAVEPREFERENCES = MENU_ID_USER_FIRST + 9;
MINIBROWSER_CONTEXTMENU_COPYALLTEXT = MENU_ID_USER_FIRST + 10;
MINIBROWSER_CONTEXTMENU_TAKESNAPSHOT = MENU_ID_USER_FIRST + 11;
MINIBROWSER_CONTEXTMENU_GETNAVIGATION = MENU_ID_USER_FIRST + 12;
MINIBROWSER_CONTEXTMENU_MUTEAUDIO = MENU_ID_USER_FIRST + 13;
MINIBROWSER_CONTEXTMENU_UNMUTEAUDIO = MENU_ID_USER_FIRST + 14;
MINIBROWSER_CONTEXTMENU_INCZOOM = MENU_ID_USER_FIRST + 15;
MINIBROWSER_CONTEXTMENU_DECZOOM = MENU_ID_USER_FIRST + 16;
MINIBROWSER_CONTEXTMENU_RESETZOOM = MENU_ID_USER_FIRST + 17;
MINIBROWSER_CONTEXTMENU_EXITFULLSCREEN = MENU_ID_USER_FIRST + 18;
MINIBROWSER_CONTEXTMENU_BROWSERINFO = MENU_ID_USER_FIRST + 19;
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS = MENU_ID_USER_FIRST + 1;
MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS = MENU_ID_USER_FIRST + 2;
MINIBROWSER_CONTEXTMENU_COPYHTML = MENU_ID_USER_FIRST + 3;
MINIBROWSER_CONTEXTMENU_JSWRITEDOC = MENU_ID_USER_FIRST + 4;
MINIBROWSER_CONTEXTMENU_JSPRINTDOC = MENU_ID_USER_FIRST + 5;
MINIBROWSER_CONTEXTMENU_SHOWRESPONSE = MENU_ID_USER_FIRST + 6;
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS = MENU_ID_USER_FIRST + 7;
MINIBROWSER_CONTEXTMENU_COPYFRAMENAMES = MENU_ID_USER_FIRST + 8;
MINIBROWSER_CONTEXTMENU_SAVEPREFERENCES = MENU_ID_USER_FIRST + 9;
MINIBROWSER_CONTEXTMENU_COPYALLTEXT = MENU_ID_USER_FIRST + 10;
MINIBROWSER_CONTEXTMENU_TAKESNAPSHOT = MENU_ID_USER_FIRST + 11;
MINIBROWSER_CONTEXTMENU_GETNAVIGATION = MENU_ID_USER_FIRST + 12;
MINIBROWSER_CONTEXTMENU_MUTEAUDIO = MENU_ID_USER_FIRST + 13;
MINIBROWSER_CONTEXTMENU_UNMUTEAUDIO = MENU_ID_USER_FIRST + 14;
MINIBROWSER_CONTEXTMENU_INCZOOM = MENU_ID_USER_FIRST + 15;
MINIBROWSER_CONTEXTMENU_DECZOOM = MENU_ID_USER_FIRST + 16;
MINIBROWSER_CONTEXTMENU_RESETZOOM = MENU_ID_USER_FIRST + 17;
MINIBROWSER_CONTEXTMENU_EXITFULLSCREEN = MENU_ID_USER_FIRST + 18;
MINIBROWSER_CONTEXTMENU_BROWSERINFO = MENU_ID_USER_FIRST + 19;
MINIBROWSER_CONTEXTMENU_COLORSCHEME = MENU_ID_USER_FIRST + 20;
MINIBROWSER_CONTEXTMENU_COLORSCHEMESYSTEM = MENU_ID_USER_FIRST + 21;
MINIBROWSER_CONTEXTMENU_COLORSCHEMELIGHT = MENU_ID_USER_FIRST + 22;
MINIBROWSER_CONTEXTMENU_COLORSCHEMEDARK = MENU_ID_USER_FIRST + 23;
DEVTOOLS_SCREENSHOT_MSGID = 1001;
DEVTOOLS_MHTML_MSGID = 1002;
@ -397,6 +401,8 @@ end;
procedure TMiniBrowserFrm.Chromium1BeforeContextMenu(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
var
TempModel: ICefMenuModel;
begin
if Chromium1.IsSameBrowser(browser) then
begin
@ -442,6 +448,18 @@ begin
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_EXITFULLSCREEN, 'Exit fullscreen');
end;
model.AddSeparator;
TempModel := model.AddSubMenu(MINIBROWSER_CONTEXTMENU_COLORSCHEME, 'Color scheme');
TempModel.AddCheckItem(MINIBROWSER_CONTEXTMENU_COLORSCHEMESYSTEM, 'System');
TempModel.AddCheckItem(MINIBROWSER_CONTEXTMENU_COLORSCHEMELIGHT, 'Light');
TempModel.AddCheckItem(MINIBROWSER_CONTEXTMENU_COLORSCHEMEDARK, 'Dark');
case Chromium1.ChromeColorSchemeMode of
CEF_COLOR_VARIANT_LIGHT : TempModel.setChecked(MINIBROWSER_CONTEXTMENU_COLORSCHEMELIGHT, True);
CEF_COLOR_VARIANT_DARK : TempModel.setChecked(MINIBROWSER_CONTEXTMENU_COLORSCHEMEDARK, True);
else TempModel.setChecked(MINIBROWSER_CONTEXTMENU_COLORSCHEMESYSTEM, True);
end;
end
else
model.AddItem(MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS, 'Show DevTools');
@ -639,6 +657,15 @@ begin
FPendingMsgID := DEVTOOLS_BROWSERINFO_MSGID;
Chromium1.ExecuteDevToolsMethod(0, 'Browser.getVersion', nil);
end;
MINIBROWSER_CONTEXTMENU_COLORSCHEMELIGHT :
Chromium1.SetChromeColorScheme(CEF_COLOR_VARIANT_LIGHT, 0);
MINIBROWSER_CONTEXTMENU_COLORSCHEMEDARK :
Chromium1.SetChromeColorScheme(CEF_COLOR_VARIANT_DARK, 0);
MINIBROWSER_CONTEXTMENU_COLORSCHEMESYSTEM :
Chromium1.SetChromeColorScheme(CEF_COLOR_VARIANT_SYSTEM, 0);
end
else
case commandId of

View File

@ -118,11 +118,11 @@ object MiniBrowserFrm: TMiniBrowserFrm
TabOrder = 1
object URLCbx: TComboBox
Left = 0
Height = 21
Height = 22
Top = 3
Width = 978
Anchors = [akTop, akLeft, akRight, akBottom]
ItemHeight = 13
ItemHeight = 14
ItemIndex = 0
Items.Strings = (
'https://www.google.com'

View File

@ -32,25 +32,29 @@ const
MINIBROWSER_HOMEPAGE = 'https://www.google.com';
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS = MENU_ID_USER_FIRST + 1;
MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS = MENU_ID_USER_FIRST + 2;
MINIBROWSER_CONTEXTMENU_COPYHTML = MENU_ID_USER_FIRST + 3;
MINIBROWSER_CONTEXTMENU_JSWRITEDOC = MENU_ID_USER_FIRST + 4;
MINIBROWSER_CONTEXTMENU_JSPRINTDOC = MENU_ID_USER_FIRST + 5;
MINIBROWSER_CONTEXTMENU_SHOWRESPONSE = MENU_ID_USER_FIRST + 6;
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS = MENU_ID_USER_FIRST + 7;
MINIBROWSER_CONTEXTMENU_COPYFRAMENAMES = MENU_ID_USER_FIRST + 8;
MINIBROWSER_CONTEXTMENU_SAVEPREFERENCES = MENU_ID_USER_FIRST + 9;
MINIBROWSER_CONTEXTMENU_COPYALLTEXT = MENU_ID_USER_FIRST + 10;
MINIBROWSER_CONTEXTMENU_TAKESNAPSHOT = MENU_ID_USER_FIRST + 11;
MINIBROWSER_CONTEXTMENU_GETNAVIGATION = MENU_ID_USER_FIRST + 12;
MINIBROWSER_CONTEXTMENU_MUTEAUDIO = MENU_ID_USER_FIRST + 13;
MINIBROWSER_CONTEXTMENU_UNMUTEAUDIO = MENU_ID_USER_FIRST + 14;
MINIBROWSER_CONTEXTMENU_INCZOOM = MENU_ID_USER_FIRST + 15;
MINIBROWSER_CONTEXTMENU_DECZOOM = MENU_ID_USER_FIRST + 16;
MINIBROWSER_CONTEXTMENU_RESETZOOM = MENU_ID_USER_FIRST + 17;
MINIBROWSER_CONTEXTMENU_EXITFULLSCREEN = MENU_ID_USER_FIRST + 18;
MINIBROWSER_CONTEXTMENU_BROWSERINFO = MENU_ID_USER_FIRST + 19;
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS = MENU_ID_USER_FIRST + 1;
MINIBROWSER_CONTEXTMENU_HIDEDEVTOOLS = MENU_ID_USER_FIRST + 2;
MINIBROWSER_CONTEXTMENU_COPYHTML = MENU_ID_USER_FIRST + 3;
MINIBROWSER_CONTEXTMENU_JSWRITEDOC = MENU_ID_USER_FIRST + 4;
MINIBROWSER_CONTEXTMENU_JSPRINTDOC = MENU_ID_USER_FIRST + 5;
MINIBROWSER_CONTEXTMENU_SHOWRESPONSE = MENU_ID_USER_FIRST + 6;
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS = MENU_ID_USER_FIRST + 7;
MINIBROWSER_CONTEXTMENU_COPYFRAMENAMES = MENU_ID_USER_FIRST + 8;
MINIBROWSER_CONTEXTMENU_SAVEPREFERENCES = MENU_ID_USER_FIRST + 9;
MINIBROWSER_CONTEXTMENU_COPYALLTEXT = MENU_ID_USER_FIRST + 10;
MINIBROWSER_CONTEXTMENU_TAKESNAPSHOT = MENU_ID_USER_FIRST + 11;
MINIBROWSER_CONTEXTMENU_GETNAVIGATION = MENU_ID_USER_FIRST + 12;
MINIBROWSER_CONTEXTMENU_MUTEAUDIO = MENU_ID_USER_FIRST + 13;
MINIBROWSER_CONTEXTMENU_UNMUTEAUDIO = MENU_ID_USER_FIRST + 14;
MINIBROWSER_CONTEXTMENU_INCZOOM = MENU_ID_USER_FIRST + 15;
MINIBROWSER_CONTEXTMENU_DECZOOM = MENU_ID_USER_FIRST + 16;
MINIBROWSER_CONTEXTMENU_RESETZOOM = MENU_ID_USER_FIRST + 17;
MINIBROWSER_CONTEXTMENU_EXITFULLSCREEN = MENU_ID_USER_FIRST + 18;
MINIBROWSER_CONTEXTMENU_BROWSERINFO = MENU_ID_USER_FIRST + 19;
MINIBROWSER_CONTEXTMENU_COLORSCHEME = MENU_ID_USER_FIRST + 20;
MINIBROWSER_CONTEXTMENU_COLORSCHEMESYSTEM = MENU_ID_USER_FIRST + 21;
MINIBROWSER_CONTEXTMENU_COLORSCHEMELIGHT = MENU_ID_USER_FIRST + 22;
MINIBROWSER_CONTEXTMENU_COLORSCHEMEDARK = MENU_ID_USER_FIRST + 23;
DEVTOOLS_SCREENSHOT_MSGID = 1001;
DEVTOOLS_MHTML_MSGID = 1002;
@ -473,7 +477,9 @@ end;
procedure TMiniBrowserFrm.Chromium1BeforeContextMenu(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
const params: ICefContextMenuParams; const model: ICefMenuModel);
var
TempModel: ICefMenuModel;
begin
if Chromium1.IsSameBrowser(browser) then
begin
@ -518,7 +524,19 @@ begin
begin
model.AddSeparator;
model.AddItem(MINIBROWSER_CONTEXTMENU_EXITFULLSCREEN, 'Exit fullscreen');
end;
end;
model.AddSeparator;
TempModel := model.AddSubMenu(MINIBROWSER_CONTEXTMENU_COLORSCHEME, 'Color scheme');
TempModel.AddCheckItem(MINIBROWSER_CONTEXTMENU_COLORSCHEMESYSTEM, 'System');
TempModel.AddCheckItem(MINIBROWSER_CONTEXTMENU_COLORSCHEMELIGHT, 'Light');
TempModel.AddCheckItem(MINIBROWSER_CONTEXTMENU_COLORSCHEMEDARK, 'Dark');
case Chromium1.ChromeColorSchemeMode of
CEF_COLOR_VARIANT_LIGHT : TempModel.setChecked(MINIBROWSER_CONTEXTMENU_COLORSCHEMELIGHT, True);
CEF_COLOR_VARIANT_DARK : TempModel.setChecked(MINIBROWSER_CONTEXTMENU_COLORSCHEMEDARK, True);
else TempModel.setChecked(MINIBROWSER_CONTEXTMENU_COLORSCHEMESYSTEM, True);
end;
end
else
model.AddItem(MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS, 'Show DevTools');
@ -716,7 +734,16 @@ begin
begin
FPendingMsgID := DEVTOOLS_BROWSERINFO_MSGID;
Chromium1.ExecuteDevToolsMethod(0, 'Browser.getVersion', nil);
end;
end;
MINIBROWSER_CONTEXTMENU_COLORSCHEMELIGHT :
Chromium1.SetChromeColorScheme(CEF_COLOR_VARIANT_LIGHT, 0);
MINIBROWSER_CONTEXTMENU_COLORSCHEMEDARK :
Chromium1.SetChromeColorScheme(CEF_COLOR_VARIANT_DARK, 0);
MINIBROWSER_CONTEXTMENU_COLORSCHEMESYSTEM :
Chromium1.SetChromeColorScheme(CEF_COLOR_VARIANT_SYSTEM, 0);
end
else
case commandId of

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 590,
"InternalVersion" : 591,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "124.3.1"
}