Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert coordinates when initializing drag drop controller #17876

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion browser/ui/views/tabs/tab_drag_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@
#include "chrome/browser/ui/views/tabs/window_finder.h"
#include "ui/views/view_utils.h"

namespace {

int GetXCoordinateAdjustmentForMultiSelectedTabs(
const std::vector<TabSlotView*>& dragged_views,
int source_view_index) {
if (dragged_views.at(source_view_index)->GetTabSlotViewType() ==
TabSlotView::ViewType::kTabGroupHeader ||
source_view_index == 0) {
return 0;
}

// When selecting multiple tabs, the x coordinate is not exactly same with
// where it was pressed. Because Chromium adjust it by the width of previous
// tabs(See TabStrip::GetSizeNeededForViews() and its call sites). But we
// don't want this behavior. With this adjustment selecting multiple tabs
// without dragging make tabs or the window jump around by the amount of the
// width of other tabs. https://github.com/brave/brave-browser/issues/29465
return TabStrip::GetSizeNeededForViews(std::vector(
dragged_views.begin(), dragged_views.begin() + source_view_index));
}

} // namespace

TabDragController::TabDragController() = default;

TabDragController::~TabDragController() = default;
Expand Down Expand Up @@ -59,8 +82,10 @@ void TabDragController::Init(TabDragContext* source_context,
}

// Adjust coordinate for vertical mode.
const int x = mouse_offset.x() - GetXCoordinateAdjustmentForMultiSelectedTabs(
dragging_views, source_view_index_);
source_view_offset = mouse_offset.y();
start_point_in_screen_ = gfx::Point(mouse_offset.x(), source_view_offset);
start_point_in_screen_ = gfx::Point(x, source_view_offset);
views::View::ConvertPointToScreen(source_view, &start_point_in_screen_);

last_point_in_screen_ = start_point_in_screen_;
Expand Down Expand Up @@ -258,6 +283,9 @@ gfx::Rect TabDragController::CalculateDraggedBrowserBounds(
DCHECK(!drag_bounds->empty());
bounds.Offset(-(mouse_offset_.OffsetFromOrigin()));
bounds.Offset({-drag_bounds->front().x(), 0});
bounds.Offset({-GetXCoordinateAdjustmentForMultiSelectedTabs(
attached_views_, source_view_index_),
0});

auto* browser_view = static_cast<BraveBrowserView*>(
BrowserView::GetBrowserViewForNativeWindow(
Expand Down