diff --git a/Source/Core/ElementHandle.cpp b/Source/Core/ElementHandle.cpp index 58cdbf2d4..29f7d4ef8 100644 --- a/Source/Core/ElementHandle.cpp +++ b/Source/Core/ElementHandle.cpp @@ -84,13 +84,11 @@ class ElementHandleTargetData { data.top_left.x = (!data.bottom_right.x || computed.left().type != Left::Auto); data.top_left.y = (!data.bottom_right.y || computed.top().type != Top::Auto); - const Vector2f top_left_margin = {box.GetEdge(BoxArea::Margin, BoxEdge::Left), box.GetEdge(BoxArea::Margin, BoxEdge::Top)}; - const Vector2f bottom_right_margin = {box.GetEdge(BoxArea::Margin, BoxEdge::Right), box.GetEdge(BoxArea::Margin, BoxEdge::Bottom)}; + const Vector2f distance_to_top_left = DistanceToTopLeft(); + const Vector2f distance_to_bottom_right = DistanceToBottomRight(distance_to_top_left); - drag_delta_min = Math::Max(drag_delta_min, - Vector2f{resolved_edge_margin[LEFT], resolved_edge_margin[TOP]} - data.original_position_top_left - top_left_margin); - drag_delta_max = Math::Min(drag_delta_max, - Vector2f{-resolved_edge_margin[RIGHT], -resolved_edge_margin[BOTTOM]} + data.original_position_bottom_right + bottom_right_margin); + drag_delta_min = Math::Max(drag_delta_min, Vector2f{resolved_edge_margin[LEFT], resolved_edge_margin[TOP]} - distance_to_top_left); + drag_delta_max = Math::Min(drag_delta_max, Vector2f{-resolved_edge_margin[RIGHT], -resolved_edge_margin[BOTTOM]} + distance_to_bottom_right); return data; } @@ -116,12 +114,11 @@ class ElementHandleTargetData { ResolveValueOr(computed.max_width(), containing_block.x, FLT_MAX), ResolveValueOr(computed.max_height(), containing_block.y, FLT_MAX), }; - const Vector2f bottom_right_margin = {box.GetEdge(BoxArea::Margin, BoxEdge::Right), box.GetEdge(BoxArea::Margin, BoxEdge::Bottom)}; + const Vector2f distance_to_bottom_right = DistanceToBottomRight(DistanceToTopLeft()); drag_delta_min = Math::Max(drag_delta_min, min_size - data.original_size); drag_delta_max = Math::Min(drag_delta_max, max_size - data.original_size); - drag_delta_max = Math::Min(drag_delta_max, - Vector2f{-resolved_edge_margin[RIGHT], -resolved_edge_margin[BOTTOM]} + data.original_position_bottom_right + bottom_right_margin); + drag_delta_max = Math::Min(drag_delta_max, Vector2f{-resolved_edge_margin[RIGHT], -resolved_edge_margin[BOTTOM]} + distance_to_bottom_right); return data; } @@ -201,6 +198,17 @@ class ElementHandleTargetData { }); } + Vector2f DistanceToTopLeft() const + { + return {target->GetOffsetLeft() - parent_box.GetEdge(BoxArea::Border, BoxEdge::Left), + target->GetOffsetTop() - parent_box.GetEdge(BoxArea::Border, BoxEdge::Top)}; + } + Vector2f DistanceToBottomRight(Vector2f distance_to_top_left) const + { + const Vector2f scroll_size = {target->GetParentNode()->GetScrollWidth(), target->GetParentNode()->GetScrollHeight()}; + return scroll_size - box.GetSize(BoxArea::Border) - distance_to_top_left; + } + Element* target; const ComputedValues& computed; const Box& box; diff --git a/Tests/Data/VisualTests/clip_mask.rml b/Tests/Data/VisualTests/clip_mask.rml index e57ec007f..d715d3519 100644 --- a/Tests/Data/VisualTests/clip_mask.rml +++ b/Tests/Data/VisualTests/clip_mask.rml @@ -51,16 +51,16 @@