app_info_dialog_views.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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/app_info_dialog_views.h"
6
7#include "base/memory/scoped_ptr.h"
8#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
9#include "chrome/browser/ui/views/app_list/app_list_dialog_contents_view.h"
10#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.h"
11#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_header_panel.h"
12#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_panel.h"
13#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.h"
14#include "chrome/browser/ui/views/constrained_window_views.h"
15#include "ui/app_list/app_list_constants.h"
16#include "ui/gfx/geometry/rect.h"
17#include "ui/gfx/geometry/size.h"
18#include "ui/views/border.h"
19#include "ui/views/controls/scroll_view.h"
20#include "ui/views/layout/box_layout.h"
21#include "ui/views/layout/grid_layout.h"
22#include "ui/views/layout/layout_constants.h"
23#include "ui/views/widget/widget.h"
24
25void ShowAppInfoDialog(AppListControllerDelegate* app_list_controller_delegate,
26                       Profile* profile,
27                       const extensions::Extension* app) {
28  gfx::NativeWindow app_list_window =
29      app_list_controller_delegate->GetAppListWindow();
30  DCHECK(app_list_window);
31  gfx::Rect app_list_bounds = app_list_controller_delegate->GetAppListBounds();
32
33  views::View* app_info_view = new AppInfoDialog(app_list_window, profile, app);
34  views::Widget* dialog_widget = AppListDialogContentsView::CreateDialogWidget(
35      app_list_window,
36      app_list_bounds,
37      new AppListDialogContentsView(app_list_controller_delegate,
38                                    app_info_view));
39  dialog_widget->Show();
40}
41
42AppInfoDialog::AppInfoDialog(gfx::NativeWindow parent_window,
43                             Profile* profile,
44                             const extensions::Extension* app)
45    : dialog_header_(NULL), dialog_body_(NULL), dialog_footer_(NULL) {
46  views::GridLayout* layout = new views::GridLayout(this);
47  SetLayoutManager(layout);
48
49  // Create one column that fills the whole dialog.
50  int kColumnSetId = 1;
51  views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId);
52  column_set->AddColumn(views::GridLayout::FILL,
53                        views::GridLayout::FILL,
54                        1,  // Stretch the column to the width of the dialog.
55                        views::GridLayout::USE_PREF,
56                        0,
57                        0);
58
59  const int kHorizontalSeparatorHeight = 1;
60  dialog_header_ = new AppInfoHeaderPanel(profile, app);
61  dialog_header_->SetBorder(views::Border::CreateSolidSidedBorder(
62      0, 0, kHorizontalSeparatorHeight, 0, app_list::kDialogSeparatorColor));
63
64  dialog_footer_ = new AppInfoFooterPanel(parent_window, profile, app);
65  dialog_footer_->SetBorder(views::Border::CreateSolidSidedBorder(
66      kHorizontalSeparatorHeight, 0, 0, 0, app_list::kDialogSeparatorColor));
67  if (!dialog_footer_->has_children()) {
68    // If there are no controls in the footer, don't add it to the dialog.
69    delete dialog_footer_;
70    dialog_footer_ = NULL;
71  }
72
73  // Make a vertically stacked view of all the panels we want to display in the
74  // dialog.
75  views::View* dialog_body_contents = new views::View();
76  dialog_body_contents->SetLayoutManager(
77      new views::BoxLayout(views::BoxLayout::kVertical,
78                           views::kButtonHEdgeMarginNew,
79                           views::kPanelVertMargin,
80                           views::kUnrelatedControlVerticalSpacing));
81  dialog_body_contents->AddChildView(new AppInfoSummaryPanel(profile, app));
82  dialog_body_contents->AddChildView(new AppInfoPermissionsPanel(profile, app));
83
84  // Clip the scrollable view so that the scrollbar appears. As long as this
85  // is larger than the height of the dialog, it will be resized to the dialog's
86  // actual height.
87  // TODO(sashab): Add ClipHeight() as a parameter-less method to
88  // views::ScrollView() to mimic this behaviour.
89  const int kMaxDialogHeight = 1000;
90  dialog_body_ = new views::ScrollView();
91  dialog_body_->ClipHeightTo(kMaxDialogHeight, kMaxDialogHeight);
92  dialog_body_->SetContents(dialog_body_contents);
93
94  layout->StartRow(0, kColumnSetId);
95  layout->AddView(dialog_header_);
96
97  layout->StartRow(1, kColumnSetId);
98  layout->AddView(dialog_body_);
99
100  if (dialog_footer_) {
101    layout->StartRow(0, kColumnSetId);
102    layout->AddView(dialog_footer_);
103  }
104}
105
106AppInfoDialog::~AppInfoDialog() {
107}
108