app_info_dialog_views.cc revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
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/bind.h"
8#include "base/memory/scoped_ptr.h"
9#include "base/metrics/histogram.h"
10#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
11#include "chrome/browser/ui/views/app_list/app_list_dialog_container.h"
12#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.h"
13#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_header_panel.h"
14#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_panel.h"
15#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.h"
16#include "extensions/common/extension.h"
17#include "extensions/common/manifest.h"
18#include "ui/app_list/app_list_constants.h"
19#include "ui/gfx/geometry/rect.h"
20#include "ui/gfx/geometry/size.h"
21#include "ui/views/border.h"
22#include "ui/views/controls/scroll_view.h"
23#include "ui/views/layout/box_layout.h"
24#include "ui/views/layout/layout_constants.h"
25#include "ui/views/widget/widget.h"
26#include "ui/views/window/dialog_delegate.h"
27
28void ShowAppInfoDialog(gfx::NativeWindow parent,
29                       const gfx::Rect& bounds,
30                       Profile* profile,
31                       const extensions::Extension* app,
32                       const base::Closure& close_callback) {
33  UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialogOpenedForType",
34                            app->GetType(),
35                            extensions::Manifest::NUM_LOAD_TYPES);
36  UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialogOpenedForLocation",
37                            app->location(),
38                            extensions::Manifest::NUM_LOCATIONS);
39
40  views::View* app_info_view = new AppInfoDialog(parent, profile, app);
41  views::Widget* dialog_widget = views::DialogDelegate::CreateDialogWidget(
42      new AppListDialogContainer(app_info_view, close_callback), NULL, parent);
43  dialog_widget->SetBounds(bounds);
44  dialog_widget->Show();
45}
46
47AppInfoDialog::AppInfoDialog(gfx::NativeWindow parent_window,
48                             Profile* profile,
49                             const extensions::Extension* app)
50    : dialog_header_(NULL), dialog_body_(NULL), dialog_footer_(NULL) {
51  views::BoxLayout* layout =
52      new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
53  SetLayoutManager(layout);
54
55  const int kHorizontalSeparatorHeight = 1;
56  dialog_header_ = new AppInfoHeaderPanel(profile, app);
57  dialog_header_->SetBorder(views::Border::CreateSolidSidedBorder(
58      0, 0, kHorizontalSeparatorHeight, 0, app_list::kDialogSeparatorColor));
59
60  dialog_footer_ = new AppInfoFooterPanel(parent_window, profile, app);
61  dialog_footer_->SetBorder(views::Border::CreateSolidSidedBorder(
62      kHorizontalSeparatorHeight, 0, 0, 0, app_list::kDialogSeparatorColor));
63  if (!dialog_footer_->has_children()) {
64    // If there are no controls in the footer, don't add it to the dialog.
65    delete dialog_footer_;
66    dialog_footer_ = NULL;
67  }
68
69  // Make a vertically stacked view of all the panels we want to display in the
70  // dialog.
71  views::View* dialog_body_contents = new views::View();
72  dialog_body_contents->SetLayoutManager(
73      new views::BoxLayout(views::BoxLayout::kVertical,
74                           views::kButtonHEdgeMarginNew,
75                           views::kPanelVertMargin,
76                           views::kUnrelatedControlVerticalSpacing));
77  dialog_body_contents->AddChildView(new AppInfoSummaryPanel(profile, app));
78  dialog_body_contents->AddChildView(new AppInfoPermissionsPanel(profile, app));
79
80  // Clip the scrollable view so that the scrollbar appears. As long as this
81  // is larger than the height of the dialog, it will be resized to the dialog's
82  // actual height.
83  // TODO(sashab): Add ClipHeight() as a parameter-less method to
84  // views::ScrollView() to mimic this behaviour.
85  const int kMaxDialogHeight = 1000;
86  dialog_body_ = new views::ScrollView();
87  dialog_body_->ClipHeightTo(kMaxDialogHeight, kMaxDialogHeight);
88  dialog_body_->SetContents(dialog_body_contents);
89
90  AddChildView(dialog_header_);
91
92  AddChildView(dialog_body_);
93  layout->SetFlexForView(dialog_body_, 1);
94
95  if (dialog_footer_)
96    AddChildView(dialog_footer_);
97}
98
99AppInfoDialog::~AppInfoDialog() {
100}
101