LibWeb+UI: Add tooltip overriding and use it for <video> tags

This call is used to inform the chrome that it should display a tooltip
now and avoid any hovering timers. This is used by <video> tags to
display the volume percentage when it is changed.
This commit is contained in:
circl
2024-07-02 16:48:57 +02:00
committed by Andreas Kling
parent 0f7623dd83
commit ceb9c3b797
11 changed files with 79 additions and 5 deletions

View File

@@ -99,6 +99,24 @@ WebContentView::WebContentView(QWidget* window, WebContentOptions const& web_con
update_cursor(cursor);
};
on_request_tooltip_override = [this](auto position, auto const& tooltip) {
m_tooltip_override = true;
if (m_tooltip_hover_timer.isActive())
m_tooltip_hover_timer.stop();
auto tooltip_without_carriage_return = tooltip.contains("\r"sv)
? tooltip.replace("\r\n"sv, "\n"sv, ReplaceMode::All).replace("\r"sv, "\n"sv, ReplaceMode::All)
: tooltip;
QToolTip::showText(
mapToGlobal(QPoint(position.x(), position.y())),
qstring_from_ak_string(tooltip_without_carriage_return),
this);
};
on_stop_tooltip_override = [this]() {
m_tooltip_override = false;
};
on_enter_tooltip_area = [this](auto const& tooltip) {
m_tooltip_text = tooltip.contains("\r"sv)
? tooltip.replace("\r\n"sv, "\n"sv, ReplaceMode::All).replace("\r"sv, "\n"sv, ReplaceMode::All)
@@ -332,9 +350,11 @@ void WebContentView::keyReleaseEvent(QKeyEvent* event)
void WebContentView::mouseMoveEvent(QMouseEvent* event)
{
if (QToolTip::isVisible())
QToolTip::hideText();
m_tooltip_hover_timer.start(600);
if (!m_tooltip_override) {
if (QToolTip::isVisible())
QToolTip::hideText();
m_tooltip_hover_timer.start(600);
}
enqueue_native_event(Web::MouseEvent::Type::MouseMove, *event);
}