mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 22:55:23 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user