#include "third_party/blink/renderer/core/page/drag_controller.h"
#include <memory>
#include "base/memory/scoped_refptr.h"
#include "build/build_config.h"
#include "third_party/blink/public/common/page/drag_operation.h"
#include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom-blink.h"
#include "third_party/blink/public/platform/web_common.h"
#include "third_party/blink/public/platform/web_drag_data.h"
#include "third_party/blink/renderer/core/clipboard/data_object.h"
#include "third_party/blink/renderer/core/clipboard/data_transfer.h"
#include "third_party/blink/renderer/core/clipboard/data_transfer_access_policy.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_fragment.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/node.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/editing/commands/drag_and_drop_command.h"
#include "third_party/blink/renderer/core/editing/drag_caret.h"
#include "third_party/blink/renderer/core/editing/editing_utilities.h"
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/editing/ephemeral_range.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/serializers/serialization.h"
#include "third_party/blink/renderer/core/events/text_event.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/visual_viewport.h"
#include "third_party/blink/renderer/core/html/forms/html_form_element.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_anchor_element.h"
#include "third_party/blink/renderer/core/html/html_plugin_element.h"
#include "third_party/blink/renderer/core/html/plugin_document.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/hit_test_request.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_image.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/loader/frame_load_request.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h"
#include "third_party/blink/renderer/core/loader/resource/image_resource_content.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/drag_data.h"
#include "third_party/blink/renderer/core/page/drag_image.h"
#include "third_party/blink/renderer/core/page/drag_state.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/graphics/image.h"
#include "third_party/blink/renderer/platform/graphics/image_orientation.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record_builder.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-blink.h"
#include "ui/display/screen_info.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif
namespace blink {
FormControlType;
DragOperation;
static const int kMaxOriginalImageArea = …;
static const int kLinkDragBorderInset = …;
#if BUILDFLAG(IS_ANDROID)
static const float kDragImageAlpha = 1.00f;
#else
static const float kDragImageAlpha = …;
#endif
#if DCHECK_IS_ON()
static bool DragTypeIsValid(DragSourceAction action) { … }
#endif
static WebMouseEvent CreateMouseEvent(DragData* drag_data) { … }
static DataTransfer* CreateDraggingDataTransfer(DataTransferAccessPolicy policy,
DragData* drag_data) { … }
DragController::DragController(Page* page)
: … { … }
static DocumentFragment* DocumentFragmentFromDragData(
DragData* drag_data,
LocalFrame* frame,
Range* context,
bool allow_plain_text,
DragSourceType& drag_source_type,
bool is_richly_editable_position) { … }
bool DragController::DragIsMove(FrameSelection& selection,
DragData* drag_data) { … }
void DragController::ClearDragCaret() { … }
void DragController::DragEnded() { … }
void DragController::DragExited(DragData* drag_data, LocalFrame& local_root) { … }
void DragController::PerformDrag(DragData* drag_data, LocalFrame& local_root) { … }
void DragController::MouseMovedIntoDocument(Document* new_document) { … }
DragController::Operation DragController::DragEnteredOrUpdated(
DragData* drag_data,
LocalFrame& local_root) { … }
static HTMLInputElement* AsFileInput(Node* node) { … }
static Element* ElementUnderMouse(Document* document_under_mouse,
const PhysicalOffset& point) { … }
bool DragController::TryDocumentDrag(DragData* drag_data,
DragDestinationAction action_mask,
DragOperation& drag_operation,
LocalFrame& local_root) { … }
DragOperation DragController::OperationForLoad(DragData* drag_data,
LocalFrame& local_root) { … }
static bool SetSelectionToDragCaret(LocalFrame* frame,
const SelectionInDOMTree& drag_caret,
Range*& range,
const PhysicalOffset& point) { … }
DispatchEventResult DragController::DispatchTextInputEventFor(
LocalFrame* inner_frame,
DragData* drag_data) { … }
bool DragController::ConcludeEditDrag(DragData* drag_data) { … }
bool DragController::CanProcessDrag(DragData* drag_data,
LocalFrame& local_root) { … }
static DragOperation DefaultOperationForDrag(DragOperationsMask src_op_mask) { … }
bool DragController::TryDHTMLDrag(DragData* drag_data,
DragOperation& operation,
LocalFrame& local_root) { … }
bool SelectTextInsteadOfDrag(const Node& node) { … }
Node* DragController::DraggableNode(const LocalFrame* src,
Node* start_node,
const gfx::Point& drag_origin,
SelectionDragPolicy selection_drag_policy,
DragSourceAction& drag_type) const { … }
static void PrepareDataTransferForImageDrag(LocalFrame* source,
DataTransfer* data_transfer,
Element* node,
const KURL& link_url,
const KURL& image_url,
const String& label) { … }
bool DragController::PopulateDragDataTransfer(LocalFrame* src,
const DragState& state,
const gfx::Point& drag_origin) { … }
namespace {
gfx::Point DragLocationForDHTMLDrag(const gfx::Point& mouse_dragged_point,
const gfx::Point& drag_initiation_location,
const gfx::Point& drag_image_offset,
bool is_link_image) { … }
gfx::Rect DragRectForSelectionDrag(const LocalFrame& frame) { … }
const gfx::Size MaxDragImageSize(float device_scale_factor) { … }
bool CanDragImage(const Element& element) { … }
std::unique_ptr<DragImage> DragImageForImage(
const Element& element,
float device_scale_factor,
const gfx::Size& image_element_size_in_pixels) { … }
gfx::Rect DragRectForImage(const DragImage* drag_image,
const gfx::Point& drag_initiation_location,
const gfx::Point& image_element_location,
const gfx::Size& image_element_size_in_pixels) { … }
std::unique_ptr<DragImage> DragImageForLink(const KURL& link_url,
const String& link_text,
float device_scale_factor) { … }
gfx::Rect DragRectForLink(const DragImage* link_image,
const gfx::Point& origin,
float device_scale_factor,
float page_scale_factor) { … }
}
gfx::RectF DragController::ClippedSelection(const LocalFrame& frame) { … }
std::unique_ptr<DragImage> DragController::DragImageForSelection(
LocalFrame& frame,
float opacity) { … }
namespace {
void SelectEnclosingAnchorIfContentEditable(LocalFrame* frame) { … }
std::unique_ptr<DragImage> DetermineDragImageAndRect(
gfx::Rect& drag_obj_rect,
gfx::Point& effective_drag_initiation_location,
LocalFrame* frame,
const DragState& state,
const HitTestResult& hit_test_result,
const gfx::Point& drag_initiation_location,
const gfx::Point& mouse_dragged_point) { … }
}
bool DragController::StartDrag(LocalFrame* frame,
const DragState& state,
const WebMouseEvent& drag_event,
const gfx::Point& drag_initiation_location) { … }
void DragController::DoSystemDrag(DragImage* image,
const gfx::Rect& drag_obj_rect,
const gfx::Point& drag_initiation_location,
DataTransfer* data_transfer,
LocalFrame* frame) { … }
DragOperation DragController::GetDragOperation(DragData* drag_data) { … }
bool DragController::IsCopyKeyDown(DragData* drag_data) { … }
DragState& DragController::GetDragState() { … }
void DragController::ContextDestroyed() { … }
void DragController::Trace(Visitor* visitor) const { … }
}