Skip to content

Commit

Permalink
Remove adaptive captcha notification animation
Browse files Browse the repository at this point in the history
  • Loading branch information
emerick committed Oct 15, 2024
1 parent 2b86317 commit e5a63d9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 107 deletions.
82 changes: 4 additions & 78 deletions browser/ui/views/brave_tooltips/brave_tooltip_popup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/compositor/layer.h"
#include "ui/display/screen.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/insets.h"
Expand Down Expand Up @@ -63,8 +61,7 @@ constexpr int kCornerRadius = 7;
namespace brave_tooltips {

BraveTooltipPopup::BraveTooltipPopup(std::unique_ptr<BraveTooltip> tooltip)
: tooltip_(std::move(tooltip)),
animation_(std::make_unique<gfx::LinearAnimation>(this)) {
: tooltip_(std::move(tooltip)) {
CreatePopup();

NotifyAccessibilityEvent(ax::mojom::Event::kAlert, true);
Expand All @@ -73,8 +70,6 @@ BraveTooltipPopup::BraveTooltipPopup(std::unique_ptr<BraveTooltip> tooltip)
if (screen) {
screen->AddObserver(this);
}

FadeIn();
}

BraveTooltipPopup::~BraveTooltipPopup() {
Expand All @@ -97,7 +92,7 @@ void BraveTooltipPopup::Close() {
delegate->OnTooltipClose(tooltip_->id());
}

FadeOut();
CloseWidget();
}

void BraveTooltipPopup::CloseWidget() {
Expand All @@ -112,7 +107,7 @@ void BraveTooltipPopup::OnOkButtonPressed() {
delegate->OnTooltipOkButtonPressed(tooltip_->id());
}

FadeOut();
Close();
}

void BraveTooltipPopup::OnCancelButtonPressed() {
Expand All @@ -127,7 +122,7 @@ void BraveTooltipPopup::OnCancelButtonPressed() {
delegate->OnTooltipCancelButtonPressed(tooltip_->id());
}

FadeOut();
Close();
}

void BraveTooltipPopup::set_normalized_display_coordinates(double x, double y) {
Expand Down Expand Up @@ -230,35 +225,6 @@ void BraveTooltipPopup::OnWidgetBoundsChanged(views::Widget* widget,
widget_origin_ = new_bounds.origin();
}

void BraveTooltipPopup::AnimationEnded(const gfx::Animation* animation) {
UpdateAnimation();

switch (animation_state_) {
case AnimationState::kIdle: {
break;
}

case AnimationState::kFadeIn: {
animation_state_ = AnimationState::kIdle;
break;
}

case AnimationState::kFadeOut: {
animation_state_ = AnimationState::kIdle;
CloseWidget();
break;
}
}
}

void BraveTooltipPopup::AnimationProgressed(const gfx::Animation* animation) {
UpdateAnimation();
}

void BraveTooltipPopup::AnimationCanceled(const gfx::Animation* animation) {
UpdateAnimation();
}

///////////////////////////////////////////////////////////////////////////////

void BraveTooltipPopup::CreatePopup() {
Expand Down Expand Up @@ -369,7 +335,6 @@ void BraveTooltipPopup::CreateWidgetView() {

widget->Init(std::move(params));

widget->SetOpacity(0.0);
widget->ShowInactive();
}

Expand All @@ -386,45 +351,6 @@ void BraveTooltipPopup::CloseWidgetView() {
GetWidget()->CloseNow();
}

void BraveTooltipPopup::FadeIn() {
animation_state_ = AnimationState::kFadeIn;
animation_->SetDuration(base::Milliseconds(fade_duration_));
StartAnimation();
}

void BraveTooltipPopup::FadeOut() {
animation_state_ = AnimationState::kFadeOut;
animation_->SetDuration(base::Milliseconds(fade_duration_));
StartAnimation();
}

void BraveTooltipPopup::StartAnimation() {
animation_->Start();

UpdateAnimation();

DCHECK(animation_->is_animating());
}

void BraveTooltipPopup::UpdateAnimation() {
DCHECK_NE(animation_state_, AnimationState::kIdle);

if (!IsWidgetValid()) {
return;
}

const double value = gfx::Tween::CalculateValue(
animation_state_ == AnimationState::kFadeOut ? gfx::Tween::EASE_IN
: gfx::Tween::EASE_OUT,
animation_->GetCurrentValue());

if (animation_state_ == AnimationState::kFadeIn) {
GetWidget()->SetOpacity(gfx::Tween::FloatValueBetween(value, 0.0f, 1.0f));
} else if (animation_state_ == AnimationState::kFadeOut) {
GetWidget()->SetOpacity(gfx::Tween::FloatValueBetween(value, 1.0f, 0.0f));
}
}

bool BraveTooltipPopup::IsWidgetValid() const {
return GetWidget() && !GetWidget()->IsClosed();
}
Expand Down
25 changes: 0 additions & 25 deletions browser/ui/views/brave_tooltips/brave_tooltip_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
#include "brave/browser/ui/views/brave_tooltips/brave_tooltip_view.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/display/display_observer.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/shadow_util.h"
#include "ui/gfx/shadow_value.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_observer.h"

namespace gfx {
class LinearAnimation;
class Point;
class Rect;
class Size;
Expand Down Expand Up @@ -56,7 +54,6 @@ class BraveTooltipView;
// constructor). Finally, the tooltip is closed.
class BraveTooltipPopup : public views::WidgetDelegateView,
public views::WidgetObserver,
public gfx::AnimationDelegate,
public display::DisplayObserver {
METADATA_HEADER(BraveTooltipPopup, views::WidgetDelegateView)
public:
Expand Down Expand Up @@ -113,11 +110,6 @@ class BraveTooltipPopup : public views::WidgetDelegateView,
void OnWidgetBoundsChanged(views::Widget* widget,
const gfx::Rect& new_bounds) override;

// AnimationDelegate:
void AnimationEnded(const gfx::Animation* animation) override;
void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationCanceled(const gfx::Animation* animation) override;

private:
void CreatePopup();

Expand All @@ -133,12 +125,6 @@ class BraveTooltipPopup : public views::WidgetDelegateView,

bool IsWidgetValid() const;

void StartAnimation();
void UpdateAnimation();

void FadeIn();
void FadeOut();

std::unique_ptr<BraveTooltip> tooltip_;

raw_ptr<BraveTooltipView> tooltip_view_ = nullptr;
Expand All @@ -151,17 +137,6 @@ class BraveTooltipPopup : public views::WidgetDelegateView,
int display_work_area_inset_x_ = -13;
int display_work_area_inset_y_ = 18;

int fade_duration_ = 200;

enum class AnimationState {
kIdle,
kFadeIn,
kFadeOut,
};

const std::unique_ptr<gfx::LinearAnimation> animation_;
AnimationState animation_state_ = AnimationState::kIdle;

base::ScopedObservation<views::Widget, views::WidgetObserver>
widget_observation_{this};
};
Expand Down
4 changes: 0 additions & 4 deletions browser/ui/views/brave_tooltips/brave_tooltips_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ TEST_F(BraveTooltipsTest, OkButtonPressed) {

ClickButton(tooltip_popup->ok_button_for_testing());

tooltip_popup->Close();

mock_tooltip_delegate_.WaitForWidgetDestroyedNotification();

tooltip_popup.release();
Expand All @@ -102,8 +100,6 @@ TEST_F(BraveTooltipsTest, CancelButtonPressed) {

ClickButton(tooltip_popup->cancel_button_for_testing());

tooltip_popup->Close();

mock_tooltip_delegate_.WaitForWidgetDestroyedNotification();

tooltip_popup.release();
Expand Down

0 comments on commit e5a63d9

Please sign in to comment.