Home | History | Annotate | Download | only in app_info_dialog
      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 
     25 void 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 
     42 AppInfoDialog::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 
     68   // Make a vertically stacked view of all the panels we want to display in the
     69   // dialog.
     70   views::View* dialog_body_contents = new views::View();
     71   dialog_body_contents->SetLayoutManager(
     72       new views::BoxLayout(views::BoxLayout::kVertical,
     73                            views::kButtonHEdgeMarginNew,
     74                            views::kPanelVertMargin,
     75                            views::kUnrelatedControlVerticalSpacing));
     76   dialog_body_contents->AddChildView(new AppInfoSummaryPanel(profile, app));
     77   dialog_body_contents->AddChildView(new AppInfoPermissionsPanel(profile, app));
     78 
     79   // Clip the scrollable view so that the scrollbar appears. As long as this
     80   // is larger than the height of the dialog, it will be resized to the dialog's
     81   // actual height.
     82   // TODO(sashab): Add ClipHeight() as a parameter-less method to
     83   // views::ScrollView() to mimic this behaviour.
     84   const int kMaxDialogHeight = 1000;
     85   dialog_body_ = new views::ScrollView();
     86   dialog_body_->ClipHeightTo(kMaxDialogHeight, kMaxDialogHeight);
     87   dialog_body_->SetContents(dialog_body_contents);
     88 
     89   layout->StartRow(0, kColumnSetId);
     90   layout->AddView(dialog_header_);
     91 
     92   layout->StartRow(1, kColumnSetId);
     93   layout->AddView(dialog_body_);
     94 
     95   layout->StartRow(0, kColumnSetId);
     96   layout->AddView(dialog_footer_);
     97 }
     98 
     99 AppInfoDialog::~AppInfoDialog() {
    100 }
    101