Skip to content

Commit 8c4de1e

Browse files
committed
Uplift of #27909 (squashed) to release
1 parent 81f0e36 commit 8c4de1e

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

browser/ui/views/tabs/dragging/tab_drag_controller.cc

+60
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,66 @@ void TabDragController::DetachAndAttachToNewContext(
262262
}
263263
}
264264

265+
gfx::Rect TabDragController::CalculateNonMaximizedDraggedBrowserBounds(
266+
views::Widget* widget,
267+
const gfx::Point& point_in_screen) {
268+
// This method is called when dragging all tabs and moving window.
269+
auto bounds =
270+
TabDragControllerChromium::CalculateNonMaximizedDraggedBrowserBounds(
271+
widget, point_in_screen);
272+
#if BUILDFLAG(IS_MAC)
273+
// According to what's been observed, this only needed on Mac. Per platform,
274+
// window management mechanism is different so this could happen.
275+
if (is_showing_vertical_tabs_) {
276+
bounds.Offset(GetVerticalTabStripWidgetOffset());
277+
}
278+
#endif
279+
280+
if (is_showing_vertical_tabs_) {
281+
bounds.set_size(widget->GetTopLevelWidget()->GetRestoredBounds().size());
282+
}
283+
284+
return bounds;
285+
}
286+
287+
gfx::Rect TabDragController::CalculateDraggedBrowserBounds(
288+
TabDragContext* source,
289+
const gfx::Point& point_in_screen,
290+
std::vector<gfx::Rect>* drag_bounds) {
291+
// This method is called when creating new browser by detaching tabs and
292+
// when dragging all tabs in maximized window.
293+
auto bounds = TabDragControllerChromium::CalculateDraggedBrowserBounds(
294+
source, point_in_screen, drag_bounds);
295+
if (is_showing_vertical_tabs_) {
296+
// Revert back coordinate adjustment done by Chromium impl.
297+
bounds.set_origin(point_in_screen);
298+
299+
// Adjust coordinate so that dragged tabs are under cursor.
300+
DCHECK(!drag_bounds->empty());
301+
bounds.Offset(-(mouse_offset_.OffsetFromOrigin()));
302+
bounds.Offset({-drag_bounds->front().x(), 0});
303+
bounds.Offset({-GetXCoordinateAdjustmentForMultiSelectedTabs(
304+
attached_views_, source_view_index_),
305+
0});
306+
307+
auto* browser_view = static_cast<BraveBrowserView*>(
308+
BrowserView::GetBrowserViewForNativeWindow(
309+
GetAttachedBrowserWidget()->GetNativeWindow()));
310+
DCHECK(browser_view);
311+
312+
auto* widget_delegate_view =
313+
browser_view->vertical_tab_strip_widget_delegate_view();
314+
DCHECK(widget_delegate_view);
315+
316+
bounds.Offset(GetVerticalTabStripWidgetOffset());
317+
bounds.Offset(-widget_delegate_view->vertical_tab_strip_region_view()
318+
->GetOffsetForDraggedTab());
319+
bounds.set_size(browser_view->GetRestoredBounds().size());
320+
}
321+
322+
return bounds;
323+
}
324+
265325
[[nodiscard]] TabDragController::Liveness TabDragController::ContinueDragging(
266326
const gfx::Point& point_in_screen) {
267327
auto* browser_widget = GetAttachedBrowserWidget();

browser/ui/views/tabs/dragging/tab_drag_controller.h

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ class TabDragController : public TabDragControllerChromium {
4242
void DetachAndAttachToNewContext(ReleaseCapture release_capture,
4343
TabDragContext* target_context) override;
4444

45+
gfx::Rect CalculateNonMaximizedDraggedBrowserBounds(
46+
views::Widget* widget,
47+
const gfx::Point& point_in_screen) override;
48+
gfx::Rect CalculateDraggedBrowserBounds(
49+
TabDragContext* source,
50+
const gfx::Point& point_in_screen,
51+
std::vector<gfx::Rect>* drag_bounds) override;
4552
[[nodiscard]] Liveness ContinueDragging(
4653
const gfx::Point& point_in_screen) override;
4754

chromium_src/chrome/browser/ui/views/tabs/dragging/tab_drag_controller.cc

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616
#define TabDragController TabDragControllerChromium
1717

18+
// Wraps function calls so that they can work with a child NativeWindow as well.
19+
#define non_client_view() \
20+
non_client_view() \
21+
? source->GetWidget()->non_client_view()->frame_view() \
22+
: source->GetWidget()->GetTopLevelWidget()->non_client_view()
23+
1824
// Remove drag threshold when it's vertical tab strip
1925
#define GetHorizontalDragThreshold() \
2026
GetHorizontalDragThreshold() - \
@@ -27,6 +33,7 @@
2733

2834
#include "src/chrome/browser/ui/views/tabs/dragging/tab_drag_controller.cc"
2935

36+
#undef non_client_view
3037
#undef GetHorizontalDragThreshold
3138
#undef GetBrowserViewForNativeWindow
3239
#undef TabDragController

chromium_src/chrome/browser/ui/views/tabs/dragging/tab_drag_controller.h

+5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ using TabDragControllerBrave = TabDragController;
3131
virtual views::Widget* GetAttachedBrowserWidget
3232
#define GetLocalProcessWindow virtual GetLocalProcessWindow
3333
#define DetachAndAttachToNewContext virtual DetachAndAttachToNewContext
34+
#define CalculateNonMaximizedDraggedBrowserBounds \
35+
virtual CalculateNonMaximizedDraggedBrowserBounds
36+
#define CalculateDraggedBrowserBounds virtual CalculateDraggedBrowserBounds
3437
#define ContinueDragging virtual ContinueDragging
3538

3639
#include "src/chrome/browser/ui/views/tabs/dragging/tab_drag_controller.h" // IWYU pragma: export
3740

3841
#undef ContinueDragging
42+
#undef CalculateDraggedBrowserBounds
43+
#undef CalculateNonMaximizedDraggedBrowserBounds
3944
#undef DetachAndAttachToNewContext
4045
#undef GetLocalProcessWindow
4146
#undef GetAttachedBrowserWidget

0 commit comments

Comments
 (0)