Skip to content

Commit

Permalink
Added pulse interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nullhook committed Oct 18, 2022
1 parent 05f4c58 commit 7f52c9d
Show file tree
Hide file tree
Showing 16 changed files with 625 additions and 1 deletion.
6 changes: 6 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ source_set("ui") {
"webui/speedreader/speedreader_panel_handler_impl.h",
"webui/speedreader/speedreader_panel_ui.cc",
"webui/speedreader/speedreader_panel_ui.h",
"webui/tooltip_ui/tooltip_ui.cc",
"webui/tooltip_ui/tooltip_ui.h",
]

if (is_win) {
Expand Down Expand Up @@ -552,6 +554,10 @@ source_set("ui") {
"views/location_bar/brave_star_view.h",
"views/profiles/brave_avatar_toolbar_button.cc",
"views/profiles/brave_avatar_toolbar_button.h",
"views/pulsing_block/pulsing_block_view.cc",
"views/pulsing_block/pulsing_block_view.h",
"views/pulsing_block/tooltip_webui_bubble_view.cc",
"views/pulsing_block/tooltip_webui_bubble_view.h",
"views/tabs/brave_new_tab_button.cc",
"views/tabs/brave_new_tab_button.h",
"views/tabs/brave_tab_search_button.cc",
Expand Down
24 changes: 24 additions & 0 deletions browser/ui/views/frame/brave_browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "brave/browser/ui/views/location_bar/brave_location_bar_view.h"
#include "brave/browser/ui/views/sidebar/sidebar_container_view.h"
#include "brave/browser/ui/views/tabs/features.h"
#include "brave/browser/ui/views/pulsing_block/pulsing_block_view.h"
#include "brave/browser/ui/views/toolbar/bookmark_button.h"
#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h"
#include "brave/browser/ui/views/toolbar/wallet_button.h"
Expand All @@ -37,6 +38,7 @@
#include "chrome/common/pref_names.h"
#include "extensions/buildflags/buildflags.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/compositor/layer.h"
#include "ui/events/event_observer.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/event_monitor.h"
Expand Down Expand Up @@ -215,6 +217,28 @@ BraveBrowserView::BraveBrowserView(std::unique_ptr<Browser> browser)
}
}

void BraveBrowserView::AddedToWidget() {
BrowserView::AddedToWidget();
// we must call all new views once BraveBrowserView is added to widget
fade_animator_ = std::make_unique<views::WidgetFadeAnimator>(frame_);
fade_animator_->set_fade_out_duration(base::Milliseconds(1000));
pulsing_block_view_ =
AddChildView(std::make_unique<views::PulsingBlockView>(browser()));
// the position here should be an object to anchor on and responsive when the
// browser resizes
pulsing_block_view_->SetPosition({750, 26});
// start_delay_timer_.Start(
// FROM_HERE,
// base::Milliseconds(5000),
// this,
// &BraveBrowserView::DoAnimate
// );

// if (frame_) {
// frame_->SetOpacity(0.8f);
// }
}

void BraveBrowserView::OnPreferenceChanged(const std::string& pref_name) {
if (pref_name == kTabsSearchShow) {
UpdateSearchTabsButtonState();
Expand Down
13 changes: 12 additions & 1 deletion browser/ui/views/frame/brave_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "brave/components/brave_vpn/buildflags/buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "ui/views/animation/animation_builder.h"
#include "ui/views/animation/widget_fade_animator.h"

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/ui/views/toolbar/brave_vpn_panel_controller.h"
Expand All @@ -38,6 +40,10 @@ namespace sidebar {
class SidebarBrowserTest;
} // namespace sidebar

namespace views {
class PulsingBlockView;
} // namespace views

class BraveBrowser;
class ContentsLayoutManager;
class SidebarContainerView;
Expand Down Expand Up @@ -78,7 +84,7 @@ class BraveBrowserView : public BrowserView {
#endif

views::View* sidebar_host_view() { return sidebar_host_view_; }

void AddedToWidget() override;
private:
class TabCyclingEventHandler;
friend class WindowClosingConfirmBrowserTest;
Expand Down Expand Up @@ -109,6 +115,11 @@ class BraveBrowserView : public BrowserView {
sidebar::Sidebar* InitSidebar() override;
void UpdateSideBarHorizontalAlignment();

raw_ptr<views::PulsingBlockView> pulsing_block_view_ = nullptr;
std::unique_ptr<views::WidgetFadeAnimator> fade_animator_;
base::RepeatingTimer start_delay_timer_;
void DoAnimate() { fade_animator_->FadeOut(); }

raw_ptr<SidebarContainerView> sidebar_container_view_ = nullptr;
raw_ptr<views::View> sidebar_host_view_ = nullptr;
raw_ptr<views::View> vertical_tabs_container_ = nullptr;
Expand Down
97 changes: 97 additions & 0 deletions browser/ui/views/pulsing_block/pulsing_block_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.

#include "brave/browser/ui/views/pulsing_block/pulsing_block_view.h"

#include <stddef.h>
#include <vector>

#include "base/check_op.h"
#include "base/rand_util.h"
#include "cc/paint/paint_shader.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "ui/compositor/layer.h"
// #include "ui/compositor/layer_animation_element.h"
// #include "ui/compositor/layer_animation_sequence.h"
// #include "ui/compositor/layer_animator.h"
#include "ui/gfx/canvas.h"
// #include "ui/gfx/geometry/transform.h"
#include "ui/gfx/geometry/transform_util.h"
#include "ui/views/animation/animation_builder.h"
// #include "ui/views/animation/animation_sequence_block.h"
#include "brave/components/constants/webui_url_constants.h"
#include "chrome/browser/profiles/profile.h"
#include "components/grit/brave_components_strings.h"
#include "ui/views/background.h"
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"

namespace {
const base::TimeDelta kPulsingDuration = base::Milliseconds(1000);

const SkColor kBlockColor = SkColorSetRGB(52, 172, 224);
SkColor4f colors[] = {{0.66, 0.10, 0.47, 1.f}, {0.22, 0.17, 0.81, 1.f}};
SkScalar positions[] = {0.0, 0.65, 1.0};
SkPoint pts[] = {{0, 0}, {60, 60}};
auto kBraveGradient = cc::PaintShader::MakeLinearGradient(pts,
colors,
positions,
3,
SkTileMode::kClamp);

void SchedulePulsingAnimation(ui::Layer* layer) {
DCHECK(layer);

const gfx::Rect local_bounds(layer->bounds().size());
views::AnimationBuilder()
.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET)
.Repeatedly()
.SetDuration(kPulsingDuration)
.SetTransform(layer,
gfx::GetScaleTransform(local_bounds.CenterPoint(), 0.7f),
gfx::Tween::EASE_IN)
.At(kPulsingDuration)
.SetDuration(kPulsingDuration)
.SetTransform(layer,
gfx::GetScaleTransform(local_bounds.CenterPoint(), 1.0f),
gfx::Tween::EASE_OUT);
}
} // namespace

namespace views {
PulsingBlockView::PulsingBlockView(Browser* browser) : browser_(browser) {
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
SetSize({60, 60});
SchedulePulsingAnimation(layer());
}

PulsingBlockView::~PulsingBlockView() = default;

void PulsingBlockView::AddedToWidget() {
if (!tooltip_webui_bubble_manager_) {
tooltip_webui_bubble_manager_ = std::make_unique<TooltipWebUIBubbleManager>(
this, browser_->profile(), GURL(kTooltipURL), IDS_BRAVE_SHIELDS);
}

tooltip_webui_bubble_manager_->ShowBubble();
}

void PulsingBlockView::OnPaint(gfx::Canvas* canvas) {
cc::PaintFlags flags;
flags.setColor(kBlockColor);
flags.setAntiAlias(true);
flags.setStyle(cc::PaintFlags::kStroke_Style);
flags.setShader(kBraveGradient);
flags.setStrokeWidth(2.f);
canvas->DrawCircle(GetContentsBounds().CenterPoint(), 28.f, flags);
flags.setStrokeWidth(5.f);
canvas->DrawCircle(GetContentsBounds().CenterPoint(), 20.f, flags);
}
} // namespace views
44 changes: 44 additions & 0 deletions browser/ui/views/pulsing_block/pulsing_block_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef BRAVE_BROWSER_UI_VIEWS_PULSING_BLOCK_PULSING_BLOCK_VIEW_H_
#define BRAVE_BROWSER_UI_VIEWS_PULSING_BLOCK_PULSING_BLOCK_VIEW_H_

#include <memory>

#include "base/compiler_specific.h"
#include "base/timer/timer.h"
#include "brave/browser/ui/views/pulsing_block/tooltip_webui_bubble_view.h"
#include "chrome/browser/ui/browser.h"
#include "ui/views/view.h"

namespace gfx {
class Size;
}

namespace views {
// PulsingBlockView shows a pulsing white circle via layer animation.
class PulsingBlockView : public views::View {
public:
explicit PulsingBlockView(Browser* browser);

PulsingBlockView(const PulsingBlockView&) = delete;
PulsingBlockView& operator=(const PulsingBlockView&) = delete;

~PulsingBlockView() override;

private:
// views::View overrides:
void OnPaint(gfx::Canvas* canvas) override;
void AddedToWidget() override;

base::OneShotTimer start_delay_timer_;
raw_ptr<Browser> browser_;
std::unique_ptr<TooltipWebUIBubbleManager> tooltip_webui_bubble_manager_;
};

} // namespace views

#endif // BRAVE_BROWSER_UI_VIEWS_PULSING_BLOCK_PULSING_BLOCK_VIEW_H_
Loading

0 comments on commit 7f52c9d

Please sign in to comment.