Ladybird/Qt: Adjust the Inspector context menu by the device pixel ratio

Otherwise, the context menu is very out of position on devices with a
device pixel ratio other than 1.
This commit is contained in:
Timothy Flynn 2024-03-10 22:17:35 -04:00 committed by Andreas Kling
parent b5e8f0ebfe
commit 3e1ffc03c4
Notes: sideshowbarker 2024-07-17 07:09:53 +09:00
2 changed files with 3 additions and 11 deletions

View file

@ -97,14 +97,14 @@ InspectorWidget::InspectorWidget(QWidget* tab, WebContentView& content_view)
m_edit_node_action->setText("&Edit text");
m_copy_node_action->setText("&Copy text");
m_dom_node_text_context_menu->exec(to_widget_position(position));
m_dom_node_text_context_menu->exec(m_inspector_view->map_point_to_global_position(position));
};
m_inspector_client->on_requested_dom_node_tag_context_menu = [this](auto position, auto const& tag) {
m_edit_node_action->setText(qstring_from_ak_string(MUST(String::formatted("&Edit \"{}\"", tag))));
m_copy_node_action->setText("&Copy HTML");
m_dom_node_tag_context_menu->exec(to_widget_position(position));
m_dom_node_tag_context_menu->exec(m_inspector_view->map_point_to_global_position(position));
};
m_inspector_client->on_requested_dom_node_attribute_context_menu = [this](auto position, auto const&, WebView::Attribute const& attribute) {
@ -117,7 +117,7 @@ InspectorWidget::InspectorWidget(QWidget* tab, WebContentView& content_view)
attribute.value, MAX_ATTRIBUTE_VALUE_LENGTH,
attribute.value.bytes_as_string_view().length() > MAX_ATTRIBUTE_VALUE_LENGTH ? "..."sv : ""sv))));
m_dom_node_attribute_context_menu->exec(to_widget_position(position));
m_dom_node_attribute_context_menu->exec(m_inspector_view->map_point_to_global_position(position));
};
setLayout(new QVBoxLayout);
@ -191,10 +191,4 @@ void InspectorWidget::closeEvent(QCloseEvent* event)
m_inspector_client->clear_selection();
}
QPoint InspectorWidget::to_widget_position(Gfx::IntPoint position) const
{
auto widget_position = m_inspector_view->mapTo(this, QPoint { position.x(), position.y() });
return mapToGlobal(widget_position);
}
}

View file

@ -38,8 +38,6 @@ private:
bool event(QEvent*) override;
void closeEvent(QCloseEvent*) override;
QPoint to_widget_position(Gfx::IntPoint) const;
QScreen* m_current_screen;
double m_device_pixel_ratio { 0 };