Skip to content

Commit

Permalink
Merge pull request #27841 from brave/fix_resize_cursor_side_panel
Browse files Browse the repository at this point in the history
Fixed cursor is not changed to resize when hovered to sidebar resize area
  • Loading branch information
simonhong authored Feb 27, 2025
2 parents fdc8ea8 + f9d9a72 commit 8355412
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions browser/ui/views/side_panel/brave_side_panel_resize_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "brave/browser/ui/views/frame/brave_browser_view.h"
#include "brave/browser/ui/views/side_panel/brave_side_panel.h"
#include "build/build_config.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/views/controls/resize_area.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
Expand All @@ -18,6 +20,32 @@
#include "ui/views/view_constants_aura.h"
#endif

#if BUILDFLAG(IS_MAC)
namespace {

// Subclassed to clear resize cursor when goes out. On macOS, it seems
// widget doesn't clear current cursor(resize) when mouse goes out in some
// specific situation unexpectedly. Because of that, cursor is not changed when
// mouse moves in. Widget doesn't update its cursor if requested one is same
// with previous one. Maybe this problem happens because it's located above
// WebView.
class CustomResizeArea : public views::ResizeArea {
METADATA_HEADER(CustomResizeArea, views::ResizeArea)
public:
using ResizeArea::ResizeArea;

void OnMouseExited(const ui::MouseEvent& event) override {
ResizeArea::OnMouseExited(event);
GetWidget()->SetCursor(ui::Cursor());
}
};

BEGIN_METADATA(CustomResizeArea)
END_METADATA

} // namespace
#endif

SidePanelResizeWidget::SidePanelResizeWidget(
BraveSidePanel* panel,
BraveBrowserView* browser_view,
Expand All @@ -38,8 +66,13 @@ SidePanelResizeWidget::SidePanelResizeWidget(
params.activatable = views::Widget::InitParams::Activatable::kNo;
widget_->Init(std::move(params));

auto resize_area = std::make_unique<views::ResizeArea>(resize_area_delegate);
widget_->SetContentsView(std::move(resize_area));
#if BUILDFLAG(IS_MAC)
widget_->SetContentsView(
std::make_unique<CustomResizeArea>(resize_area_delegate));
#else
widget_->SetContentsView(
std::make_unique<views::ResizeArea>(resize_area_delegate));
#endif

#if defined(USE_AURA)
widget_->GetNativeView()->SetProperty(views::kHostViewKey,
Expand Down

0 comments on commit 8355412

Please sign in to comment.