NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / views / apps / app_info_dialog_views.cc
blob1b66ce6ea0dab4735ebaec09dc42a2fde9f6ead2
1 // Copyright 2014 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/apps/app_info_dialog_views.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/apps/app_info_dialog.h"
9 #include "chrome/browser/ui/views/constrained_window_views.h"
10 #include "extensions/common/extension.h"
11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/grid_layout.h"
15 #include "ui/views/layout/layout_constants.h"
16 #include "ui/views/widget/widget.h"
18 void ShowChromeAppInfoDialog(gfx::NativeWindow parent_window,
19 Profile* profile,
20 const extensions::Extension* app,
21 const base::Closure& close_callback) {
22 CreateBrowserModalDialogViews(new AppInfoView(profile, app, close_callback),
23 parent_window)->Show();
26 AppInfoView::AppInfoView(Profile* profile,
27 const extensions::Extension* app,
28 const base::Closure& close_callback)
29 : profile_(profile),
30 app_name_label(NULL),
31 app_description_label(NULL),
32 app_(app),
33 close_callback_(close_callback) {
34 // Create controls
35 app_name_label = new views::Label(base::UTF8ToUTF16(app_->name()));
36 app_name_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
38 app_description_label =
39 new views::Label(base::UTF8ToUTF16(app_->description()));
40 app_description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
42 // Layout controls
43 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
44 SetLayoutManager(layout);
46 static const int kHeaderColumnSetId = 0;
47 views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId);
48 column_set->AddColumn(views::GridLayout::FILL,
49 views::GridLayout::CENTER,
50 100.0f,
51 views::GridLayout::FIXED,
53 0);
55 layout->StartRow(0, kHeaderColumnSetId);
56 layout->AddView(app_name_label);
58 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing);
59 layout->StartRow(0, kHeaderColumnSetId);
60 layout->AddView(app_description_label);
63 AppInfoView::~AppInfoView() {}
65 bool AppInfoView::Cancel() {
66 if (!close_callback_.is_null())
67 close_callback_.Run();
68 return true;
71 gfx::Size AppInfoView::GetPreferredSize() {
72 static const int kDialogWidth = 360;
73 int height =
74 GetLayoutManager()->GetPreferredHeightForWidth(this, kDialogWidth);
75 return gfx::Size(kDialogWidth, height);
78 base::string16 AppInfoView::GetDialogButtonLabel(ui::DialogButton button)
79 const {
80 if (button == ui::DIALOG_BUTTON_CANCEL) {
81 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_CLOSE_BUTTON);
83 return views::DialogDelegateView::GetDialogButtonLabel(button);
86 int AppInfoView::GetDialogButtons() const {
87 return ui::DIALOG_BUTTON_CANCEL;
90 bool AppInfoView::IsDialogButtonEnabled(ui::DialogButton button) const {
91 return true;
94 ui::ModalType AppInfoView::GetModalType() const {
95 return ui::MODAL_TYPE_WINDOW;
98 base::string16 AppInfoView::GetWindowTitle() const {
99 return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_TITLE);