forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble.cc
54 lines (44 loc) · 1.66 KB
/
bubble.cc
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
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/strings/utf_string_conversions.h"
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace shell {
struct BubbleConfig {
base::string16 label;
views::View* anchor_view;
views::BubbleBorder::Arrow arrow;
};
class ExampleBubbleDialogDelegateView : public views::BubbleDialogDelegateView {
public:
explicit ExampleBubbleDialogDelegateView(const BubbleConfig& config);
~ExampleBubbleDialogDelegateView() override;
void Init() override {
SetLayoutManager(std::make_unique<views::FillLayout>());
views::Label* label = new views::Label(label_);
AddChildView(label);
}
private:
base::string16 label_;
};
ExampleBubbleDialogDelegateView::ExampleBubbleDialogDelegateView(
const BubbleConfig& config)
: BubbleDialogDelegateView(config.anchor_view, config.arrow),
label_(config.label) {}
ExampleBubbleDialogDelegateView::~ExampleBubbleDialogDelegateView() = default;
void CreatePointyBubble(views::View* anchor_view) {
BubbleConfig config;
config.label = base::ASCIIToUTF16("Pointy Dialog Bubble");
config.anchor_view = anchor_view;
config.arrow = views::BubbleBorder::TOP_LEFT;
ExampleBubbleDialogDelegateView* bubble =
new ExampleBubbleDialogDelegateView(config);
views::BubbleDialogDelegateView::CreateBubble(bubble)->Show();
}
} // namespace shell
} // namespace ash