app_info_dialog_views.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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/layout_constants.h" 22#include "ui/views/widget/widget.h" 23 24void ShowAppInfoDialog(AppListControllerDelegate* app_list_controller_delegate, 25 Profile* profile, 26 const extensions::Extension* app) { 27 gfx::NativeWindow app_list_window = 28 app_list_controller_delegate->GetAppListWindow(); 29 DCHECK(app_list_window); 30 gfx::Rect app_list_bounds = app_list_controller_delegate->GetAppListBounds(); 31 32 views::View* app_info_view = new AppInfoDialog(app_list_window, profile, app); 33 views::Widget* dialog_widget = AppListDialogContentsView::CreateDialogWidget( 34 app_list_window, 35 app_list_bounds, 36 new AppListDialogContentsView(app_list_controller_delegate, 37 app_info_view)); 38 dialog_widget->Show(); 39} 40 41AppInfoDialog::AppInfoDialog(gfx::NativeWindow parent_window, 42 Profile* profile, 43 const extensions::Extension* app) 44 : dialog_header_(NULL), dialog_body_(NULL), dialog_footer_(NULL) { 45 views::BoxLayout* layout = 46 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 47 SetLayoutManager(layout); 48 49 const int kHorizontalSeparatorHeight = 1; 50 dialog_header_ = new AppInfoHeaderPanel(profile, app); 51 dialog_header_->SetBorder(views::Border::CreateSolidSidedBorder( 52 0, 0, kHorizontalSeparatorHeight, 0, app_list::kDialogSeparatorColor)); 53 54 dialog_footer_ = new AppInfoFooterPanel(parent_window, profile, app); 55 dialog_footer_->SetBorder(views::Border::CreateSolidSidedBorder( 56 kHorizontalSeparatorHeight, 0, 0, 0, app_list::kDialogSeparatorColor)); 57 if (!dialog_footer_->has_children()) { 58 // If there are no controls in the footer, don't add it to the dialog. 59 delete dialog_footer_; 60 dialog_footer_ = NULL; 61 } 62 63 // Make a vertically stacked view of all the panels we want to display in the 64 // dialog. 65 views::View* dialog_body_contents = new views::View(); 66 dialog_body_contents->SetLayoutManager( 67 new views::BoxLayout(views::BoxLayout::kVertical, 68 views::kButtonHEdgeMarginNew, 69 views::kPanelVertMargin, 70 views::kUnrelatedControlVerticalSpacing)); 71 dialog_body_contents->AddChildView(new AppInfoSummaryPanel(profile, app)); 72 dialog_body_contents->AddChildView(new AppInfoPermissionsPanel(profile, app)); 73 74 // Clip the scrollable view so that the scrollbar appears. As long as this 75 // is larger than the height of the dialog, it will be resized to the dialog's 76 // actual height. 77 // TODO(sashab): Add ClipHeight() as a parameter-less method to 78 // views::ScrollView() to mimic this behaviour. 79 const int kMaxDialogHeight = 1000; 80 dialog_body_ = new views::ScrollView(); 81 dialog_body_->ClipHeightTo(kMaxDialogHeight, kMaxDialogHeight); 82 dialog_body_->SetContents(dialog_body_contents); 83 84 AddChildView(dialog_header_); 85 86 AddChildView(dialog_body_); 87 layout->SetFlexForView(dialog_body_, 1); 88 89 if (dialog_footer_) 90 AddChildView(dialog_footer_); 91} 92 93AppInfoDialog::~AppInfoDialog() { 94} 95