MCPcopy Create free account
hub / github.com/MediaArea/MediaInfo / InjectHTMLStyle

Method InjectHTMLStyle

Source/GUI/VCL/GUI_Main.cpp:154–183  ·  view source on GitHub ↗

Function to inject CSS styles into HTML documents to workaround GUI HTML rendering issues ---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

152//Function to inject CSS styles into HTML documents to workaround GUI HTML rendering issues
153//---------------------------------------------------------------------------
154std::wstring __fastcall TMainF::InjectHTMLStyle(const wchar_t* HTMLDocument) {
155
156 auto InsertText = [](std::wstring Text, const wchar_t* InsertPointText, const wchar_t* TextToInsert) -> std::wstring {
157 auto InsertionPoint = std::search(Text.begin(), Text.end(), InsertPointText, InsertPointText + wcslen(InsertPointText));
158 if (InsertionPoint != Text.end()) {
159 size_t InsertionPos = InsertionPoint - Text.begin() + wcslen(InsertPointText);
160 Text.insert(InsertionPos, TextToInsert);
161 }
162 return Text;
163 };
164
165 std::wstring modifiedHTML(HTMLDocument);
166 const wchar_t* StyleContent = L"";
167
168 //WebView2 Engine theme switching overrides
169 if (Prefs->Config(__T("Theme")).To_int32s()==1) //always light mode
170 StyleContent = L"<style>:root { --color-scheme: light; --border-color: navy; }</style>";
171 if (Prefs->Config(__T("Theme")).To_int32s()==2) //always dark mode
172 StyleContent = L"<style>:root { --color-scheme: dark; --border-color: blue; }</style>";
173 modifiedHTML = InsertText(modifiedHTML, L"</style>", StyleContent);
174
175 //IE Engine workarounds
176 if (TStyleManager::ActiveStyle == TStyleManager::Style[DARK_MODE_STYLE]) //app is currently in dark mode
177 StyleContent = L"<meta http-equiv='X-UA-Compatible' content='IE=edge'><style>body { background-color: #121212; color: #FFFFFF; } table { border:1px solid blue; }</style>";
178 else
179 StyleContent = L"<meta http-equiv='X-UA-Compatible' content='IE=edge'><style>table { border:1px solid navy; }</style>";
180 modifiedHTML = InsertText(modifiedHTML, L"<head>", StyleContent);
181
182 return modifiedHTML;
183}
184
185//---------------------------------------------------------------------------
186

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected