Integrate IV menu hiding by click inside WebView.

This commit is contained in:
John Preston 2024-03-14 11:22:52 +04:00
parent 5c8e6c3012
commit 5c32423597
3 changed files with 43 additions and 1 deletions

View File

@ -88,6 +88,12 @@ html.custom_scroll ::-webkit-scrollbar-thumb:hover {
opacity: 1;
}
}
#menu_page_blocker {
z-index: 999;
position: fixed;
width: 100%;
height: 100%;
}
#top_shadow {
z-index: 999;
position: fixed;

View File

@ -8,6 +8,11 @@ var IV = {
var target = e.target;
var context = '';
while (target) {
if (target.id == 'menu_page_blocker') {
IV.notify({ event: 'menu_page_blocker_click' });
IV.menuShown(false);
return;
}
if (target.tagName == 'AUDIO' || target.tagName == 'VIDEO') {
return;
}
@ -599,6 +604,20 @@ var IV = {
back: function () {
window.history.back();
},
menuShown: function (shown) {
var already = document.getElementById('menu_page_blocker');
if (already && shown) {
return;
} else if (already) {
document.body.removeChild(already);
return;
} else if (!shown) {
return;
}
var blocker = document.createElement('div');
blocker.id = 'menu_page_blocker';
document.body.appendChild(blocker);
},
videos: {},
videosPlaying: {},

View File

@ -429,6 +429,10 @@ void Controller::createWebview(const QString &dataPath) {
const auto url = object.value("url").toString();
const auto context = object.value("context").toString();
processLink(url, context);
} else if (event == "menu_page_blocker_click") {
if (_menu) {
_menu->hideMenu();
}
} else if (event == u"ready"_q) {
_ready = true;
auto script = QByteArray();
@ -443,6 +447,9 @@ void Controller::createWebview(const QString &dataPath) {
if (base::take(_reloadInitialWhenReady)) {
script += reloadScript(0);
}
if (_menu) {
script += "IV.menuShown(true);";
}
if (!script.isEmpty()) {
_webview->eval(script);
}
@ -648,7 +655,7 @@ bool Controller::active() const {
}
void Controller::showJoinedTooltip() {
if (_webview) {
if (_webview && _ready) {
_webview->eval("IV.showTooltip('"
+ EscapeForScriptString(
tr::lng_action_you_joined(tr::now).toUtf8())
@ -679,6 +686,9 @@ void Controller::showMenu() {
_menu = base::make_unique_q<Ui::PopupMenu>(
_window.get(),
st::popupMenuWithIcons);
if (_webview && _ready) {
_webview->eval("IV.menuShown(true);");
}
_menu->setDestroyedCallback(crl::guard(_window.get(), [
this,
weakButton = Ui::MakeWeak(_menuToggle.data()),
@ -686,6 +696,13 @@ void Controller::showMenu() {
if (_menu == menu && weakButton) {
weakButton->setForceRippled(false);
}
if (const auto widget = _webview ? _webview->widget() : nullptr) {
InvokeQueued(widget, crl::guard(_window.get(), [=] {
if (_webview && _ready) {
_webview->eval("IV.menuShown(false);");
}
}));
}
}));
_menuToggle->setForceRippled(true);