Ladybird/Qt: Move positional device pixel ratio adjustment to a helper

The code to convert a Gfx::IntPoint to a QPoint adjusted for the device
pixel ratio is a bit of a mouthful, and will be needed outside of Tab,
so move it to a helper that can be reused.
This commit is contained in:
Timothy Flynn 2024-03-10 22:15:06 -04:00 committed by Andreas Kling
parent bc42144642
commit b5e8f0ebfe
Notes: sideshowbarker 2024-07-17 06:39:26 +09:00
3 changed files with 12 additions and 5 deletions

View File

@ -271,7 +271,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
select_dropdown_add_item(m_select_dropdown, item);
}
m_select_dropdown->exec(view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio()));
m_select_dropdown->exec(view().map_point_to_global_position(content_position));
};
QObject::connect(focus_location_editor_action, &QAction::triggered, this, &Tab::focus_location_editor);
@ -406,7 +406,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
search_selected_text_action->setVisible(false);
}
m_page_context_menu->exec(view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio()));
m_page_context_menu->exec(view().map_point_to_global_position(content_position));
};
auto* open_link_action = new QAction("&Open", this);
@ -450,7 +450,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
break;
}
m_link_context_menu->exec(view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio()));
m_link_context_menu->exec(view().map_point_to_global_position(content_position));
};
auto* open_image_action = new QAction("&Open Image", this);
@ -503,7 +503,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
m_image_context_menu_url = image_url;
m_image_context_menu_bitmap = shareable_bitmap;
m_image_context_menu->exec(view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio()));
m_image_context_menu->exec(view().map_point_to_global_position(content_position));
};
m_media_context_menu_play_icon = load_icon_from_uri("resource://icons/16x16/play.png"sv);
@ -619,7 +619,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
m_media_context_menu_controls_action->setChecked(menu.has_user_agent_controls);
m_media_context_menu_loop_action->setChecked(menu.is_looping);
auto screen_position = view().mapToGlobal(QPoint(content_position.x(), content_position.y()) / view().device_pixel_ratio());
auto screen_position = view().map_point_to_global_position(content_position);
if (menu.is_video)
m_video_context_menu->exec(screen_position);
else

View File

@ -644,6 +644,11 @@ Web::DevicePixelRect WebContentView::viewport_rect() const
return m_viewport_rect.to_type<Web::DevicePixels>();
}
QPoint WebContentView::map_point_to_global_position(Gfx::IntPoint position) const
{
return mapToGlobal(QPoint { position.x(), position.y() } / device_pixel_ratio());
}
Gfx::IntPoint WebContentView::to_content_position(Gfx::IntPoint widget_position) const
{
return widget_position.translated(max(0, horizontalScrollBar()->value()), max(0, verticalScrollBar()->value()));

View File

@ -81,6 +81,8 @@ public:
using ViewImplementation::client;
QPoint map_point_to_global_position(Gfx::IntPoint) const;
signals:
void urls_dropped(QList<QUrl> const&);