From 5d164c4ebacff4e8520fab746571ec87cc226a6f Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Thu, 20 May 2021 17:22:32 +0900 Subject: [PATCH] Fixed sidebar show option is not applied properly when it's changed fix https://github.com/brave/brave-browser/issues/15958 When sidebar show option context menu gets visible or hidden, view's mouse entered/exited callback is called even if mouse is still in the view. Because of this, newly changed option is not applied well. --- .../views/sidebar/sidebar_container_view.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/browser/ui/views/sidebar/sidebar_container_view.cc b/browser/ui/views/sidebar/sidebar_container_view.cc index 7daf09b1db34..9084076b525e 100644 --- a/browser/ui/views/sidebar/sidebar_container_view.cc +++ b/browser/ui/views/sidebar/sidebar_container_view.cc @@ -175,12 +175,27 @@ bool SidebarContainerView::ShouldShowSidebar() const { } void SidebarContainerView::OnMouseEntered(const ui::MouseEvent& event) { + const auto show_option = GetSidebarService(browser_)->GetSidebarShowOption(); + const bool autohide_sidebar = + show_option == ShowSidebarOption::kShowOnMouseOver || + show_option == ShowSidebarOption::kShowOnClick; + + // When user select to non-autohide option like "Never" option, + // hide timer is scheduled but this view can get mouse event when context + // menu is hidden. In this case, this should not be cancelled. + if (!autohide_sidebar) + return; + // Cancel hide schedule when mouse entered again quickly. - if (sidebar_hide_timer_.IsRunning()) - sidebar_hide_timer_.Stop(); + sidebar_hide_timer_.Stop(); } void SidebarContainerView::OnMouseExited(const ui::MouseEvent& event) { + // When context menu is shown, this view can get this exited callback. + // In that case, ignore this callback because mouse is still in this view. + if (IsMouseHovered()) + return; + const auto show_option = GetSidebarService(browser_)->GetSidebarShowOption(); const bool autohide_sidebar = show_option == ShowSidebarOption::kShowOnMouseOver ||