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_panel.h"
6
7 #include "chrome/browser/ui/browser_navigator.h"
8 #include "chrome/browser/ui/browser_navigator_params.h"
9 #include "chrome/browser/ui/views/apps/app_info_dialog/app_info_label.h"
10 #include "chrome/browser/ui/views/chrome_layout_provider.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/box_layout.h"
15 #include "ui/views/widget/widget.h"
16 #include "url/gurl.h"
17
18 namespace {
19
20 // The spacing between the key and the value labels in the Details section.
21 const int kSpacingBetweenKeyAndStartOfValue = 3;
22 }
23
AppInfoPanel(Profile * profile,const extensions::Extension * app)24 AppInfoPanel::AppInfoPanel(Profile* profile, const extensions::Extension* app)
25 : profile_(profile), app_(app) {
26 }
27
~AppInfoPanel()28 AppInfoPanel::~AppInfoPanel() {
29 }
30
Close()31 void AppInfoPanel::Close() {
32 GetWidget()->Close();
33 }
34
OpenLink(const GURL & url)35 void AppInfoPanel::OpenLink(const GURL& url) {
36 DCHECK(!url.is_empty());
37 NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK);
38 Navigate(¶ms);
39 }
40
CreateHeading(const base::string16 & text) const41 std::unique_ptr<views::Label> AppInfoPanel::CreateHeading(
42 const base::string16& text) const {
43 auto label = std::make_unique<AppInfoLabel>(text);
44 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
45 ui::ResourceBundle::MediumFont));
46 return label;
47 }
48
CreateVerticalStack(int child_spacing) const49 std::unique_ptr<views::View> AppInfoPanel::CreateVerticalStack(
50 int child_spacing) const {
51 auto vertically_stacked_view = std::make_unique<views::View>();
52 vertically_stacked_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
53 views::BoxLayout::Orientation::kVertical, gfx::Insets(), child_spacing));
54 return vertically_stacked_view;
55 }
56
CreateVerticalStack() const57 std::unique_ptr<views::View> AppInfoPanel::CreateVerticalStack() const {
58 return CreateVerticalStack(ChromeLayoutProvider::Get()->GetDistanceMetric(
59 views::DISTANCE_RELATED_CONTROL_VERTICAL));
60 }
61
CreateHorizontalStack(int child_spacing) const62 std::unique_ptr<views::View> AppInfoPanel::CreateHorizontalStack(
63 int child_spacing) const {
64 auto vertically_stacked_view = std::make_unique<views::View>();
65 vertically_stacked_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
66 views::BoxLayout::Orientation::kHorizontal, gfx::Insets(),
67 child_spacing));
68 return vertically_stacked_view;
69 }
70
CreateKeyValueField(std::unique_ptr<views::View> key,std::unique_ptr<views::View> value) const71 std::unique_ptr<views::View> AppInfoPanel::CreateKeyValueField(
72 std::unique_ptr<views::View> key,
73 std::unique_ptr<views::View> value) const {
74 auto horizontal_stack =
75 CreateHorizontalStack(kSpacingBetweenKeyAndStartOfValue);
76 horizontal_stack->AddChildView(std::move(key));
77 horizontal_stack->AddChildView(std::move(value));
78 return horizontal_stack;
79 }
80