File: dragging_tabs_session.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (85 lines) | stat: -rw-r--r-- 3,950 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 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_TABS_DRAGGING_DRAGGING_TABS_SESSION_H_
#define CHROME_BROWSER_UI_VIEWS_TABS_DRAGGING_DRAGGING_TABS_SESSION_H_

#include "chrome/browser/ui/views/tabs/dragging/drag_session_data.h"
#include "chrome/browser/ui/views/tabs/dragging/tab_drag_context.h"
#include "chrome/browser/ui/views/tabs/dragging/tab_strip_scroll_session.h"
#include "components/tab_groups/tab_group_id.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"

// Handles dragging tabs within a single TabDragContext on behalf of
// TabDragController.
class DraggingTabsSession final : public TabDragWithScrollManager {
 public:
  // `drag_data` is a copy of the drag configuration for the full session.
  // `attached_context` is the context in which the tabs are being dragged.
  // `offset_to_width_ratio_` is the desired x offset into the source
  // TabSlotView (e.g. 0.5 if the drag started in the center of the tab).
  // `initial_move` should be true if the drag session is beginning, and
  // the tabs have not been moved from their initial positions.
  // `point_in_screen` is the initial cursor screen position.
  explicit DraggingTabsSession(DragSessionData drag_data,
                               TabDragContext* attached_context,
                               float offset_to_width_ratio_,
                               bool initial_move,
                               gfx::Point point_in_screen);
  ~DraggingTabsSession() final;

  // TabDragWithScrollManager:
  void MoveAttached(gfx::Point point_in_screen) override;
  gfx::Rect GetEnclosingRectForDraggedTabs() override;
  gfx::Point GetLastPointInScreen() override;
  views::View* GetAttachedContext() override;
  views::ScrollView* GetScrollView() override;

 private:
  void MoveAttachedImpl(gfx::Point point_in_screen, bool just_attached);

  // Retrieves the bounds of the dragged tabs relative to the attached
  // TabDragContext. `tab_strip_point` is in the attached
  // TabDragContext's coordinate system.
  gfx::Rect GetDraggedViewTabStripBounds(gfx::Point tab_strip_point) const;

  // Returns true if the tabs were originally one after the other in
  // `source_context_`.
  bool AreTabsConsecutive() const;

  // Helper method for TabDragController::MoveAttached to precompute the tab
  // group membership of selected tabs after performing the move.
  std::optional<tab_groups::TabGroupId> CalculateGroupForDraggedTabs(
      int to_index);

  // Calculates where to position the dragged tabs, given the cursor is at
  // `point_in_screen`. Keeps the same point within the source view under the
  // cursor, unless that would push tabs outside the drag area.
  gfx::Point GetAttachedDragPoint(gfx::Point point_in_screen);

  // Data about the tabs and groups being dragged.
  const DragSessionData drag_data_;
  // The context in which `this` will drag tabs.
  const raw_ptr<TabDragContext> attached_context_;
  // This is the horizontal offset of the mouse from the leading edge of the
  // first tab where dragging began. This is used to ensure that the dragged
  // tabs are always positioned at the correct location during the drag.
  const int mouse_offset_;

  // True if MoveAttached() has never been called, and `attached_context_` is
  // the source context in which the drag originated.
  bool initial_move_;
  // The horizontal position of the mouse cursor in `attached_context_`
  // coordinates at the time of the last re-order event.
  int last_move_attached_context_loc_;

  gfx::Point last_point_in_screen_;

  // the scrolling session that handles scrolling when the tabs are dragged
  // to the scrollable regions of the tab_strip.
  std::unique_ptr<TabStripScrollSession> tab_strip_scroll_session_ = nullptr;
};

#endif  // CHROME_BROWSER_UI_VIEWS_TABS_DRAGGING_DRAGGING_TABS_SESSION_H_