Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / apps / app_info_dialog_views.cc
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.
4
5 #include "chrome/browser/ui/views/apps/app_info_dialog_views.h"
6
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"
17
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();
24 }
25
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);
37
38   app_description_label =
39       new views::Label(base::UTF8ToUTF16(app_->description()));
40   app_description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
41
42   // Layout controls
43   views::GridLayout* layout = views::GridLayout::CreatePanel(this);
44   SetLayoutManager(layout);
45
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,
52                         0,
53                         0);
54
55   layout->StartRow(0, kHeaderColumnSetId);
56   layout->AddView(app_name_label);
57
58   layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing);
59   layout->StartRow(0, kHeaderColumnSetId);
60   layout->AddView(app_description_label);
61 }
62
63 AppInfoView::~AppInfoView() {}
64
65 bool AppInfoView::Cancel() {
66   if (!close_callback_.is_null())
67     close_callback_.Run();
68   return true;
69 }
70
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);
76 }
77
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);
82   }
83   return views::DialogDelegateView::GetDialogButtonLabel(button);
84 }
85
86 int AppInfoView::GetDialogButtons() const {
87   return ui::DIALOG_BUTTON_CANCEL;
88 }
89
90 bool AppInfoView::IsDialogButtonEnabled(ui::DialogButton button) const {
91   return true;
92 }
93
94 ui::ModalType AppInfoView::GetModalType() const {
95   return ui::MODAL_TYPE_WINDOW;
96 }
97
98 base::string16 AppInfoView::GetWindowTitle() const {
99   return l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_TITLE);
100 }