1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/extensions/extension_toolbar_icon_surfacing_bubble_views.h"
7 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h"
8 #include "grit/chromium_strings.h"
9 #include "grit/generated_resources.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/views/controls/button/label_button.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/grid_layout.h"
16 ExtensionToolbarIconSurfacingBubble::ExtensionToolbarIconSurfacingBubble(
17 views::View
* anchor_view
,
18 ToolbarActionsBarBubbleDelegate
* delegate
)
19 : views::BubbleDelegateView(anchor_view
, views::BubbleBorder::TOP_RIGHT
),
21 acknowledged_(false) {
22 delegate_
->OnToolbarActionsBarBubbleShown();
25 ExtensionToolbarIconSurfacingBubble::~ExtensionToolbarIconSurfacingBubble() {
28 void ExtensionToolbarIconSurfacingBubble::Init() {
29 views::GridLayout
* layout
= new views::GridLayout(this);
30 SetLayoutManager(layout
);
31 // Initialize a basic column set of |<padding> <content> <padding>|.
32 views::ColumnSet
* columns
= layout
->AddColumnSet(0);
33 columns
->AddPaddingColumn(0, 10);
34 columns
->AddColumn(views::GridLayout::LEADING
,
35 views::GridLayout::LEADING
,
37 views::GridLayout::USE_PREF
,
40 columns
->AddPaddingColumn(0, 10);
43 layout
->StartRow(0, 0);
44 views::Label
* heading_label
= new views::Label(
45 l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_HEADING
));
46 heading_label
->SetFontList(
47 ui::ResourceBundle::GetSharedInstance().GetFontList(
48 ui::ResourceBundle::MediumFont
));
49 heading_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
50 layout
->AddView(heading_label
);
51 layout
->AddPaddingRow(0, 10);
52 int width
= heading_label
->GetPreferredSize().width();
54 // Add the content string.
55 layout
->StartRow(0, 0);
56 views::Label
* content_label
= new views::Label(
57 l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_CONTENT
));
58 content_label
->SetMultiLine(true);
59 content_label
->SizeToFit(width
);
60 content_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
61 layout
->AddView(content_label
);
62 layout
->AddPaddingRow(0, 10);
64 // Add a "got it" button.
65 layout
->StartRow(0, 0);
66 views::LabelButton
* button
= new views::LabelButton(
67 this, l10n_util::GetStringUTF16(IDS_EXTENSION_TOOLBAR_BUBBLE_OK
));
68 button
->SetStyle(views::Button::STYLE_BUTTON
);
69 layout
->AddView(button
,
72 views::GridLayout::TRAILING
,
73 views::GridLayout::FILL
);
76 void ExtensionToolbarIconSurfacingBubble::OnWidgetDestroying(
77 views::Widget
* widget
) {
78 BubbleDelegateView::OnWidgetDestroying(widget
);
80 delegate_
->OnToolbarActionsBarBubbleClosed(
81 ToolbarActionsBarBubbleDelegate::DISMISSED
);
86 void ExtensionToolbarIconSurfacingBubble::ButtonPressed(
87 views::Button
* sender
,
88 const ui::Event
& event
) {
89 delegate_
->OnToolbarActionsBarBubbleClosed(
90 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED
);