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
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_NETWORK_NETWORK_INFO_BUBBLE_H_
#define ASH_SYSTEM_NETWORK_NETWORK_INFO_BUBBLE_H_
#include <string>
#include "ash/ash_export.h"
#include "base/memory/weak_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/widget/widget.h"
namespace ash {
// This class encapsulates the logic to find and show the IP addresses and mac
// addresses of the default network and available network technologies.
class ASH_EXPORT NetworkInfoBubble : public views::BubbleDialogDelegateView {
METADATA_HEADER(NetworkInfoBubble, views::BubbleDialogDelegateView)
public:
// This class declares the interface that should be implemented by any class
// that intends to instantiate NetworkInfoBubble.
class Delegate {
public:
Delegate() = default;
virtual ~Delegate() = default;
// Used to determine whether the info bubble should include the mac
// addresses of the ethernet, WiFi, and cellular devices.
virtual bool ShouldIncludeDeviceAddresses() = 0;
// Used to notify the delegate that the bubble is destructing.
virtual void OnInfoBubbleDestroyed() = 0;
};
NetworkInfoBubble(base::WeakPtr<Delegate> delegate, views::View* anchor);
NetworkInfoBubble(const NetworkInfoBubble&) = delete;
NetworkInfoBubble& operator=(const NetworkInfoBubble&) = delete;
~NetworkInfoBubble() override;
private:
friend class NetworkInfoBubbleTest;
// Used for testing. This is 1 because view IDs should not be 0.
static constexpr int kNetworkInfoBubbleLabelViewId = 1;
// views::View:
gfx::Size CalculatePreferredSize(
const views::SizeBounds& available_size) const override;
void OnMouseExited(const ui::MouseEvent& event) override;
// views::OnBeforeBubbleWidgetInit:
void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
views::Widget* widget) const override;
// Computes the text to be shown in the info bubble. The text will be
// comprised of the IP addresses, if available, as well as the mac addresses
// for the ethernet, WiFi, and cellular devices.
std::u16string ComputeInfoText();
// The container for info labels.
raw_ptr<views::View> label_container_ = nullptr;
base::WeakPtr<Delegate> delegate_;
};
} // namespace ash
#endif // ASH_SYSTEM_NETWORK_NETWORK_INFO_BUBBLE_H_
|