forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshelf_tooltip_bubble.cc
81 lines (66 loc) · 2.89 KB
/
shelf_tooltip_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
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
// Copyright 2018 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 "ash/shelf/shelf_tooltip_bubble.h"
#include "ash/system/tray/tray_constants.h"
#include "ui/aura/window.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
namespace ash {
// Tooltip layout constants.
// Shelf item tooltip height.
const int kTooltipHeight = 24;
// The maximum width of the tooltip bubble. Borrowed the value from
// ash/tooltip/tooltip_controller.cc
const int kTooltipMaxWidth = 250;
// Shelf item tooltip internal text margins.
const int kTooltipTopBottomMargin = 4;
const int kTooltipLeftRightMargin = 8;
// The offset for the tooltip bubble - making sure that the bubble is spaced
// with a fixed gap. The gap is accounted for by the transparent arrow in the
// bubble and an additional 1px padding for the shelf item views.
const int kArrowTopBottomOffset = 1;
const int kArrowLeftRightOffset = 1;
ShelfTooltipBubble::ShelfTooltipBubble(views::View* anchor,
ShelfAlignment alignment,
SkColor background_color,
const base::string16& text)
: ShelfBubble(anchor, alignment, background_color) {
set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin));
set_close_on_deactivate(false);
SetCanActivate(false);
set_accept_events(false);
set_shadow(views::BubbleBorder::NO_ASSETS);
SetLayoutManager(std::make_unique<views::FillLayout>());
views::Label* label = new views::Label(text);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
ui::NativeTheme* theme = anchor->GetWidget()->GetNativeTheme();
SkColor theme_background_color =
theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground);
set_color(theme_background_color);
label->SetEnabledColor(
theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipText));
label->SetBackgroundColor(theme_background_color);
AddChildView(label);
gfx::Insets insets(kArrowTopBottomOffset, kArrowLeftRightOffset);
// Adjust the anchor location for asymmetrical borders of shelf item.
if (anchor->border())
insets += anchor->border()->GetInsets();
insets += gfx::Insets(-kBubblePaddingHorizontalBottom);
set_anchor_view_insets(insets);
CreateBubble();
}
gfx::Size ShelfTooltipBubble::CalculatePreferredSize() const {
const gfx::Size size = BubbleDialogDelegateView::CalculatePreferredSize();
const int kTooltipMinHeight = kTooltipHeight - 2 * kTooltipTopBottomMargin;
return gfx::Size(std::min(size.width(), kTooltipMaxWidth),
std::max(size.height(), kTooltipMinHeight));
}
bool ShelfTooltipBubble::ShouldCloseOnPressDown() {
// Let the manager close us.
return true;
}
bool ShelfTooltipBubble::ShouldCloseOnMouseExit() {
return true;
}
} // namespace ash