Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / apps / app_info_dialog / app_info_panel.cc
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 "ui/base/resource/resource_bundle.h"
9 #include "ui/views/controls/label.h"
10 #include "ui/views/layout/box_layout.h"
11 #include "ui/views/layout/layout_constants.h"
12 #include "ui/views/widget/widget.h"
13 #include "url/gurl.h"
14
15 namespace {
16
17 // The spacing between the key and the value labels in the Details section.
18 const int kSpacingBetweenKeyAndStartOfValue = 3;
19 }
20
21 AppInfoPanel::AppInfoPanel(Profile* profile, const extensions::Extension* app)
22     : profile_(profile), app_(app) {
23 }
24
25 AppInfoPanel::~AppInfoPanel() {
26 }
27
28 void AppInfoPanel::Close() {
29   GetWidget()->Close();
30 }
31
32 void AppInfoPanel::OpenLink(const GURL& url) {
33   DCHECK(!url.is_empty());
34   chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK);
35   chrome::Navigate(&params);
36 }
37
38 views::Label* AppInfoPanel::CreateHeading(const base::string16& text) const {
39   views::Label* label = new views::Label(text);
40   label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
41   label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
42       ui::ResourceBundle::MediumFont));
43   return label;
44 }
45
46 views::View* AppInfoPanel::CreateVerticalStack(int child_spacing) const {
47   views::View* vertically_stacked_view = new views::View();
48   vertically_stacked_view->SetLayoutManager(
49       new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, child_spacing));
50   return vertically_stacked_view;
51 }
52
53 views::View* AppInfoPanel::CreateVerticalStack() const {
54   return CreateVerticalStack(views::kRelatedControlVerticalSpacing);
55 }
56
57 views::View* AppInfoPanel::CreateHorizontalStack(int child_spacing) const {
58   views::View* vertically_stacked_view = new views::View();
59   vertically_stacked_view->SetLayoutManager(
60       new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, child_spacing));
61   return vertically_stacked_view;
62 }
63
64 views::View* AppInfoPanel::CreateKeyValueField(views::View* key,
65                                                views::View* value) const {
66   views::View* horizontal_stack =
67       CreateHorizontalStack(kSpacingBetweenKeyAndStartOfValue);
68   horizontal_stack->AddChildView(key);
69   horizontal_stack->AddChildView(value);
70   return horizontal_stack;
71 }