Skip to content

Commit

Permalink
Updated sidebar add bubble hide logic
Browse files Browse the repository at this point in the history
fix brave/brave-browser#21156

Hide this bubble when user moves out from add button when this button
is launched by mouse hover. By hovering, user can't use bubble as
it'll be hidden quickly. That bubble acts like tooltip.
Instead, user should click the add button to use that bubble.
Bubble that launched by button click will get hidden
only when user clicks outside of bubble explicitely.
  • Loading branch information
simonhong committed Aug 30, 2022
1 parent 034762a commit d21cfff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 16 additions & 3 deletions browser/ui/views/sidebar/sidebar_item_add_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void SidebarItemAddButton::OnButtonPressed() {
if (timer_.IsRunning())
timer_.Stop();

add_item_bubble_shown_by_click_ = true;

DoShowBubble();
}

Expand All @@ -50,6 +52,11 @@ void SidebarItemAddButton::OnMouseExited(const ui::MouseEvent& event) {
SidebarButtonView::OnMouseExited(event);
// Don't show bubble if user goes outo from add item quickly.
timer_.Stop();

if (!add_item_bubble_shown_by_click_ && IsBubbleVisible()) {
DCHECK(add_item_bubble_widget_);
add_item_bubble_widget_->Close();
}
}

void SidebarItemAddButton::OnGestureEvent(ui::GestureEvent* event) {
Expand All @@ -71,13 +78,18 @@ void SidebarItemAddButton::AddedToWidget() {
}

void SidebarItemAddButton::OnWidgetDestroying(views::Widget* widget) {
DCHECK_EQ(add_item_bubble_widget_, widget);
add_item_bubble_widget_ = nullptr;
add_item_bubble_shown_by_click_ = false;
observation_.Reset();
}

void SidebarItemAddButton::ShowBubbleWithDelay() {
if (IsBubbleVisible())
return;

DCHECK(!add_item_bubble_shown_by_click_);

if (timer_.IsRunning())
timer_.Stop();

Expand All @@ -87,10 +99,11 @@ void SidebarItemAddButton::ShowBubbleWithDelay() {
}

void SidebarItemAddButton::DoShowBubble() {
auto* bubble = views::BubbleDialogDelegateView::CreateBubble(
DCHECK(!add_item_bubble_widget_);
add_item_bubble_widget_ = views::BubbleDialogDelegateView::CreateBubble(
new SidebarAddItemBubbleDelegateView(browser_, this));
observation_.Observe(bubble);
bubble->Show();
observation_.Observe(add_item_bubble_widget_);
add_item_bubble_widget_->Show();
}

bool SidebarItemAddButton::IsBubbleVisible() const {
Expand Down
3 changes: 3 additions & 0 deletions browser/ui/views/sidebar/sidebar_item_add_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SidebarItemAddButton : public SidebarButtonView,
void OnButtonPressed();

raw_ptr<BraveBrowser> browser_ = nullptr;
raw_ptr<views::Widget> add_item_bubble_widget_ = nullptr;
// true when bubble is shown by add item button press. Otherwise, false.
bool add_item_bubble_shown_by_click_ = false;
base::OneShotTimer timer_;
base::CallbackListSubscription on_enabled_changed_subscription_;
base::ScopedObservation<views::Widget, views::WidgetObserver> observation_{
Expand Down

0 comments on commit d21cfff

Please sign in to comment.