app_info_dialog_views.cc revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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(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(Profile* profile, const extensions::Extension* app) 43 : dialog_header_(NULL), dialog_body_(NULL), dialog_footer_(NULL) { 44 views::GridLayout* layout = new views::GridLayout(this); 45 SetLayoutManager(layout); 46 47 // Create one column that fills the whole dialog. 48 int kColumnSetId = 1; 49 views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); 50 column_set->AddColumn(views::GridLayout::FILL, 51 views::GridLayout::FILL, 52 1, // Stretch the column to the width of the dialog. 53 views::GridLayout::USE_PREF, 54 0, 55 0); 56 57 const int kHorizontalSeparatorHeight = 1; 58 dialog_header_ = new AppInfoHeaderPanel(profile, app); 59 dialog_header_->SetBorder(views::Border::CreateSolidSidedBorder( 60 0, 0, kHorizontalSeparatorHeight, 0, app_list::kDialogSeparatorColor)); 61 62 dialog_footer_ = new AppInfoFooterPanel(profile, app); 63 dialog_footer_->SetBorder(views::Border::CreateSolidSidedBorder( 64 kHorizontalSeparatorHeight, 0, 0, 0, app_list::kDialogSeparatorColor)); 65 66 // Make a vertically stacked view of all the panels we want to display in the 67 // dialog. 68 views::View* dialog_body_contents = new views::View(); 69 dialog_body_contents->SetLayoutManager( 70 new views::BoxLayout(views::BoxLayout::kVertical, 71 views::kButtonHEdgeMarginNew, 72 views::kPanelVertMargin, 73 views::kUnrelatedControlVerticalSpacing)); 74 dialog_body_contents->AddChildView(new AppInfoSummaryPanel(profile, app)); 75 dialog_body_contents->AddChildView(new AppInfoPermissionsPanel(profile, app)); 76 77 // Clip the scrollable view so that the scrollbar appears. As long as this 78 // is larger than the height of the dialog, it will be resized to the dialog's 79 // actual height. 80 // TODO(sashab): Add ClipHeight() as a parameter-less method to 81 // views::ScrollView() to mimic this behaviour. 82 const int kMaxDialogHeight = 1000; 83 dialog_body_ = new views::ScrollView(); 84 dialog_body_->ClipHeightTo(kMaxDialogHeight, kMaxDialogHeight); 85 dialog_body_->SetContents(dialog_body_contents); 86 87 layout->StartRow(0, kColumnSetId); 88 layout->AddView(dialog_header_); 89 90 layout->StartRow(1, kColumnSetId); 91 layout->AddView(dialog_body_); 92 93 layout->StartRow(0, kColumnSetId); 94 layout->AddView(dialog_footer_); 95} 96 97AppInfoDialog::~AppInfoDialog() { 98} 99