Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / extension_toolbar_icon_surfacing_bubble_views.cc
blobc0ddf62eafa035546cfdf7c29b4444ee32051e49
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 "chrome/grit/locale_settings.h"
9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/views/controls/button/label_button.h"
11 #include "ui/views/controls/label.h"
12 #include "ui/views/layout/grid_layout.h"
13 #include "ui/views/layout/layout_constants.h"
15 ExtensionToolbarIconSurfacingBubble::ExtensionToolbarIconSurfacingBubble(
16 views::View* anchor_view,
17 scoped_ptr<ToolbarActionsBarBubbleDelegate> delegate)
18 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
19 delegate_(delegate.Pass()),
20 acknowledged_(false) {
23 ExtensionToolbarIconSurfacingBubble::~ExtensionToolbarIconSurfacingBubble() {
26 void ExtensionToolbarIconSurfacingBubble::Show() {
27 delegate_->OnBubbleShown();
28 GetWidget()->Show();
31 void ExtensionToolbarIconSurfacingBubble::Init() {
32 views::GridLayout* layout = new views::GridLayout(this);
33 layout->SetInsets(views::kPanelVertMargin, views::kPanelHorizMargin,
34 views::kPanelVertMargin, views::kPanelHorizMargin);
35 SetLayoutManager(layout);
36 views::ColumnSet* columns = layout->AddColumnSet(0);
37 columns->AddColumn(views::GridLayout::LEADING,
38 views::GridLayout::LEADING,
40 views::GridLayout::USE_PREF,
42 0);
44 // Add a header.
45 layout->StartRow(0, 0);
46 views::Label* heading_label = new views::Label(delegate_->GetHeadingText());
47 heading_label->SetFontList(
48 ui::ResourceBundle::GetSharedInstance().GetFontList(
49 ui::ResourceBundle::MediumFont));
50 heading_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
51 layout->AddView(heading_label);
52 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing);
53 int width = views::Widget::GetLocalizedContentsWidth(
54 IDS_EXTENSION_TOOLBAR_REDESIGN_NOTIFICATION_BUBBLE_WIDTH_CHARS);
56 // Add the content string.
57 layout->StartRow(0, 0);
58 views::Label* content_label = new views::Label(delegate_->GetBodyText());
59 content_label->SetMultiLine(true);
60 content_label->SizeToFit(width);
61 content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
62 layout->AddView(content_label);
63 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing);
65 // Add a "got it" button.
66 layout->StartRow(0, 0);
67 views::LabelButton* button = new views::LabelButton(
68 this, delegate_->GetActionButtonText());
69 button->SetStyle(views::Button::STYLE_BUTTON);
70 layout->AddView(button,
73 views::GridLayout::TRAILING,
74 views::GridLayout::FILL);
77 void ExtensionToolbarIconSurfacingBubble::OnWidgetDestroying(
78 views::Widget* widget) {
79 BubbleDelegateView::OnWidgetDestroying(widget);
80 if (!acknowledged_) {
81 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS);
82 acknowledged_ = true;
86 void ExtensionToolbarIconSurfacingBubble::ButtonPressed(
87 views::Button* sender,
88 const ui::Event& event) {
89 delegate_->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE);
90 acknowledged_ = true;
91 GetWidget()->Close();