File: multi_contents_view_drop_target_controller.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (67 lines) | stat: -rw-r--r-- 2,774 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_MULTI_CONTENTS_VIEW_DROP_TARGET_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_MULTI_CONTENTS_VIEW_DROP_TARGET_CONTROLLER_H_

#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/ui/views/frame/multi_contents_drop_target_view.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/views/view.h"

namespace content {
struct DropData;
}  // namespace content

// `MultiContentsViewDropTargetController` is responsible for handling
// the drag-entrypoint of a single `MultiContentsView`. This includes dragging
// links,  bookmarks, or tab headers to create a split view.
// There exists one `MultiContentsViewDropTargetController` per
// `MultiContentesView`.
class MultiContentsViewDropTargetController final {
 public:
  explicit MultiContentsViewDropTargetController(
      MultiContentsDropTargetView& drop_target_view);
  ~MultiContentsViewDropTargetController();
  MultiContentsViewDropTargetController(
      const MultiContentsViewDropTargetController&) = delete;
  MultiContentsViewDropTargetController& operator=(
      const MultiContentsViewDropTargetController&) = delete;

  // Handles a drag within the web contents area.
  // `point` should be relative to the multi contents view.
  void OnWebContentsDragUpdate(const content::DropData& data,
                               const gfx::PointF& point,
                               bool is_in_split_view);
  void OnWebContentsDragExit();

 private:
  // Represents a timer for delaying when a specific drop target view is shown.
  struct DropTargetShowTimer {
    explicit DropTargetShowTimer(
        MultiContentsDropTargetView::DropSide drop_side);
    base::OneShotTimer timer;
    MultiContentsDropTargetView::DropSide drop_side;
  };

  // Starts or updates a running timer to show `target_to_show`.
  void StartOrUpdateDropTargetTimer(
      MultiContentsDropTargetView::DropSide drop_side);
  void ResetDropTargetTimer();

  // Shows the drop target that should be displayed at the end of the delay.
  void ShowTimerDelayedDropTarget();

  // This timer is used for showing the drop target a delay, and may be
  // canceled in case a drag exits the drop area before the target is shown.
  std::optional<DropTargetShowTimer> show_drop_target_timer_ = std::nullopt;

  // The view that is displayed when drags hover over the "drop" region of
  // the content area.
  const raw_ref<MultiContentsDropTargetView> drop_target_view_;
  const raw_ref<views::View> drop_target_parent_view_;
};

#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_MULTI_CONTENTS_VIEW_DROP_TARGET_CONTROLLER_H_