app_info_dialog_views.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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 "base/metrics/histogram.h" 9#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 10#include "chrome/browser/ui/views/app_list/app_list_dialog_contents_view.h" 11#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.h" 12#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_header_panel.h" 13#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_panel.h" 14#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.h" 15#include "chrome/browser/ui/views/constrained_window_views.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 27void ShowAppInfoDialog(AppListControllerDelegate* app_list_controller_delegate, 28 Profile* profile, 29 const extensions::Extension* app) { 30 UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialogOpenedForType", 31 app->GetType(), 32 extensions::Manifest::NUM_LOAD_TYPES); 33 UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialogOpenedForLocation", 34 app->location(), 35 extensions::Manifest::NUM_LOCATIONS); 36 37 gfx::NativeWindow app_list_window = 38 app_list_controller_delegate->GetAppListWindow(); 39 DCHECK(app_list_window); 40 gfx::Rect app_list_bounds = app_list_controller_delegate->GetAppListBounds(); 41 42 views::View* app_info_view = new AppInfoDialog(app_list_window, profile, app); 43 views::Widget* dialog_widget = AppListDialogContentsView::CreateDialogWidget( 44 app_list_window, 45 app_list_bounds, 46 new AppListDialogContentsView(app_list_controller_delegate, 47 app_info_view)); 48 dialog_widget->Show(); 49} 50 51AppInfoDialog::AppInfoDialog(gfx::NativeWindow parent_window, 52 Profile* profile, 53 const extensions::Extension* app) 54 : dialog_header_(NULL), dialog_body_(NULL), dialog_footer_(NULL) { 55 views::BoxLayout* layout = 56 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); 57 SetLayoutManager(layout); 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 AddChildView(dialog_header_); 95 96 AddChildView(dialog_body_); 97 layout->SetFlexForView(dialog_body_, 1); 98 99 if (dialog_footer_) 100 AddChildView(dialog_footer_); 101} 102 103AppInfoDialog::~AppInfoDialog() { 104} 105