1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_USER_EDUCATION_BROWSER_HELP_BUBBLE_EVENT_RELAY_H_
#define CHROME_BROWSER_UI_VIEWS_USER_EDUCATION_BROWSER_HELP_BUBBLE_EVENT_RELAY_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "build/build_config.h"
#include "components/user_education/views/help_bubble_event_relay.h"
#include "components/user_education/views/help_bubble_view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
#if USE_AURA
#include "ui/events/event_handler.h"
#endif
// Observes the primary window when a help bubble is anchored to a non-focusable
// secondary window that goes away with user interaction (such as an autofill
// bubble or a hover card), and allows the help bubble to properly handle events
// without itself becoming focused. Not necessary for bubbles that disappear on
// loss of focus because help bubbles already pin their anchor widgets in place.
class WindowHelpBubbleEventRelay : public user_education::HelpBubbleEventRelay,
public views::WidgetObserver {
public:
explicit WindowHelpBubbleEventRelay(views::Widget* source_widget);
~WindowHelpBubbleEventRelay() override;
// HelpBubbleEventRelay:
bool ShouldHelpBubbleProcessEvents() const override;
bool ShouldUnHoverOnMouseExit() const override;
protected:
// Called on destruction and when the target widget goes away.
// Call in derived destructors; safe to call multiple times.
virtual void Release();
views::Widget* source_widget() { return source_widget_; }
private:
// ui::WidgetObserver:
void OnWidgetDestroying(views::Widget* widget) override;
raw_ptr<views::Widget> source_widget_;
base::ScopedObservation<views::Widget, views::WidgetObserver>
widget_observation_{this};
};
#if USE_AURA
// Aura implementation of WindowHelpBubbleEventRelay.
class WindowHelpBubbleEventRelayAura : public WindowHelpBubbleEventRelay,
public ui::EventHandler {
public:
explicit WindowHelpBubbleEventRelayAura(views::Widget* source_widget);
~WindowHelpBubbleEventRelayAura() override;
private:
// ui::EventHandler:
void OnEvent(ui::Event* event) override;
// WindowHelpBubbleEventHandler:
void Release() override;
};
#elif BUILDFLAG(IS_MAC)
// Aura implementation of WindowHelpBubbleEventRelay.
class WindowHelpBubbleEventRelayMac : public WindowHelpBubbleEventRelay {
public:
explicit WindowHelpBubbleEventRelayMac(views::Widget* source_widget);
~WindowHelpBubbleEventRelayMac() override;
// WindowHelpBubbleEventRelay:
void Release() override;
private:
class Delegate;
std::unique_ptr<Delegate> delegate_;
};
#endif // BUILDFLAG(IS_MAC)
// Creates a platform-appropriate help bubble event processor for a help bubble
// that should be forwarded events from the widget behind it.
std::unique_ptr<WindowHelpBubbleEventRelay> CreateWindowHelpBubbleEventRelay(
views::Widget* source_widget);
#endif // CHROME_BROWSER_UI_VIEWS_USER_EDUCATION_BROWSER_HELP_BUBBLE_EVENT_RELAY_H_
|