Merge branch 'popover-bounds-trouble' into 'main'

textview: Give the magnifier correct coordinates

Closes #5695

See merge request GNOME/gtk!5716
This commit is contained in:
Matthias Clasen 2023-03-24 22:59:05 +00:00
commit 81e61b9abf
3 changed files with 58 additions and 11 deletions

View File

@ -20,6 +20,7 @@
#include "gtkmagnifierprivate.h"
#include "gtkwidgetprivate.h"
#include "gtksnapshot.h"
#include "gtkcssboxesprivate.h"
enum {
PROP_INSPECTED = 1,
@ -105,10 +106,23 @@ gtk_magnifier_snapshot (GtkWidget *widget,
{
GtkMagnifier *magnifier = GTK_MAGNIFIER (widget);
double width, height, paintable_width, paintable_height;
GtkWidget *inspected;
GtkCssBoxes boxes;
const graphene_rect_t *content_rect;
const graphene_rect_t *border_rect;
graphene_point_t offset;
if (gtk_widget_paintable_get_widget (GTK_WIDGET_PAINTABLE (magnifier->paintable)) == NULL)
inspected = gtk_widget_paintable_get_widget (GTK_WIDGET_PAINTABLE (magnifier->paintable));
if (inspected == NULL)
return;
gtk_css_boxes_init (&boxes, inspected);
content_rect = gtk_css_boxes_get_content_rect (&boxes);
border_rect = gtk_css_boxes_get_border_rect (&boxes);
offset.x = content_rect->origin.x - border_rect->origin.x;
offset.y = content_rect->origin.y - border_rect->origin.y;
width = gtk_widget_get_width (widget);
height = gtk_widget_get_height (widget);
paintable_width = gdk_paintable_get_intrinsic_width (magnifier->paintable);
@ -121,8 +135,8 @@ gtk_magnifier_snapshot (GtkWidget *widget,
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2, height / 2));
gtk_snapshot_scale (snapshot, magnifier->magnification, magnifier->magnification);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (
- CLAMP (magnifier->x, 0, paintable_width),
- CLAMP (magnifier->y, 0, paintable_height)));
- CLAMP (magnifier->x + offset.x, 0, paintable_width),
- CLAMP (magnifier->y + offset.y, 0, paintable_height)));
gdk_paintable_snapshot (magnifier->paintable, snapshot, paintable_width, paintable_height);
gtk_snapshot_restore (snapshot);

View File

@ -443,16 +443,38 @@ create_popup_layout (GtkPopover *popover)
GtkWidget *parent;
GtkCssStyle *style;
GtkBorder shadow_width;
GtkNative *native;
double nx, ny;
graphene_rect_t bounds;
parent = gtk_widget_get_parent (GTK_WIDGET (popover));
gtk_widget_get_surface_allocation (parent, &rect);
native = gtk_widget_get_native (parent);
if (priv->has_pointing_to)
{
rect.x += priv->pointing_to.x;
rect.y += priv->pointing_to.y;
rect.width = priv->pointing_to.width;
rect.height = priv->pointing_to.height;
graphene_matrix_t transform;
graphene_rect_t pointing_to = GRAPHENE_RECT_INIT (priv->pointing_to.x,
priv->pointing_to.y,
priv->pointing_to.width,
priv->pointing_to.height);
if (!gtk_widget_compute_transform (parent, GTK_WIDGET (native), &transform))
graphene_matrix_init_identity (&transform);
graphene_matrix_transform_bounds (&transform, &pointing_to, &bounds);
}
else
{
if (!gtk_widget_compute_bounds (parent, GTK_WIDGET (native), &bounds))
g_warning ("Failed to compute bounds");
}
gtk_native_get_surface_transform (native, &nx, &ny);
rect.x = (int) floor (bounds.origin.x + nx);
rect.y = (int) floor (bounds.origin.y + ny);
rect.width = (int) ceilf (bounds.size.width);
rect.width = (int) ceilf (bounds.size.height);
style = gtk_css_node_get_style (gtk_widget_get_css_node (GTK_WIDGET (priv->contents_widget)));
gtk_css_shadow_value_get_extents (style->background->box_shadow, &shadow_width);

View File

@ -131,15 +131,26 @@ gtk_text_handle_present_surface (GtkTextHandle *handle)
GdkRectangle rect;
GtkRequisition req;
GtkWidget *parent;
GtkNative *native;
graphene_point_t point = GRAPHENE_POINT_INIT (handle->pointing_to.x, handle->pointing_to.y);
graphene_point_t transformed;
double nx, ny;
gtk_widget_get_preferred_size (widget, NULL, &req);
gtk_text_handle_get_padding (handle, &handle->border);
parent = gtk_widget_get_parent (widget);
gtk_widget_get_surface_allocation (parent, &rect);
rect.x += handle->pointing_to.x;
rect.y += handle->pointing_to.y + handle->pointing_to.height - handle->border.top;
native = gtk_widget_get_native (parent);
gtk_native_get_surface_transform (native, &nx, &ny);
if (!gtk_widget_compute_point (parent, GTK_WIDGET (native),
&point, &transformed))
transformed = point;
rect.x = (int)(transformed.x + nx);
rect.y = (int)(transformed.y + ny) + handle->pointing_to.height - handle->border.top;
rect.width = req.width - handle->border.left - handle->border.right;
rect.height = 1;