Skip to main content

script/drag/
document_selection_drag.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use js::context::JSContext;
6
7use crate::dom::NodeTraits;
8use crate::dom::inputevent::HitTestResult;
9
10#[derive(JSTraceable, MallocSizeOf)]
11#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
12pub(crate) struct DocumentSelectionDragHandler;
13
14impl DocumentSelectionDragHandler {
15    pub(crate) fn still_connected(&self) -> bool {
16        true
17    }
18
19    /// Process a mouse move event on this [`DocumentSelectionDragHandler`].
20    ///
21    /// Returns `true` if the drag should continue and `false` otherwise.
22    pub(crate) fn moved(&self, cx: &mut JSContext, hit_test_result: &HitTestResult) -> bool {
23        let Some((container, offset)) = hit_test_result.dom_position_for_selection.as_ref() else {
24            return true;
25        };
26        let Some(selection) = container.owner_document().selection() else {
27            return true;
28        };
29        selection.collapse_or_extend_to_dom_position(cx, container, *offset);
30        true
31    }
32}