Skip to content

Commit

Permalink
Added auto closing to shields onboarding bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Dec 15, 2023
1 parent c5e3ab9 commit e8131e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions browser/ui/views/brave_help_bubble/brave_help_bubble_host_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace {
constexpr int kWidth = 60;
constexpr int kHeight = 60;

constexpr base::TimeDelta kBubbleAutoClosingIntervalInSec = base::Seconds(15);

// The points here are defined as start and end points of the gradient,
// associated with an entire rect
constexpr SkPoint kPts[] = {{0, 0}, {kWidth, kHeight}};
Expand Down Expand Up @@ -116,6 +118,11 @@ bool BraveHelpBubbleHostView::Show() {
UpdatePosition();
SetVisible(true);

bubble_auto_closing_timer_.Start(
FROM_HERE, kBubbleAutoClosingIntervalInSec,
base::BindOnce(&BraveHelpBubbleHostView::Hide,
weak_factory_.GetWeakPtr()));

if (gfx::Animation::ShouldRenderRichAnimation()) {
SchedulePulsingAnimation(layer());
}
Expand Down Expand Up @@ -205,6 +212,20 @@ void BraveHelpBubbleHostView::OnWidgetDestroying(views::Widget* widget) {
host_widget_observation_.Reset();
}

void BraveHelpBubbleHostView::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
if (help_bubble_ != widget) {
return;
}

if (active) {
// Initially, bubble is launched in inactive state.
// If user activates it explicitely, we don't need to close it by timer.
// Instead, bubble will be closed when it goes inactive state later.
bubble_auto_closing_timer_.Stop();
}
}

void BraveHelpBubbleHostView::OnTrackedElementActivated(
ui::TrackedElement* element) {
Hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <memory>
#include <string>

#include "base/timer/timer.h"
#include "brave/browser/ui/views/brave_help_bubble/brave_help_bubble_delegate_view.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/view.h"
Expand Down Expand Up @@ -47,12 +48,16 @@ class BraveHelpBubbleHostView : public views::View,
// views::WidgetObserver:
void OnWidgetBoundsChanged(views::Widget* widget, const gfx::Rect&) override;
void OnWidgetDestroying(views::Widget* widget) override;
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;

void OnTrackedElementActivated(ui::TrackedElement* element);

std::string text_;
raw_ptr<views::View> tracked_element_ = nullptr;
raw_ptr<views::Widget> help_bubble_ = nullptr;

// Bubble will be closed if user doesn't interact with it for some time.
base::OneShotTimer bubble_auto_closing_timer_;
ui::ElementTracker::Subscription activated_subscription_;
base::ScopedObservation<views::View, views::ViewObserver>
tracked_view_observation_{this};
Expand Down

0 comments on commit e8131e6

Please sign in to comment.