1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/options/settings_page_view.h"
#include "skia/ext/skia_utils_gtk.h"
#include "views/controls/label.h"
#include "views/fill_layout.h"
#include "views/widget/widget_gtk.h"
namespace chromeos {
SettingsPageView::SettingsPageView(Profile* profile)
: OptionsPageView(profile) {
SetLayoutManager(new views::FillLayout());
}
GtkWidget* SettingsPageView::WrapInGtkWidget() {
views::WidgetGtk* widget =
new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD);
widget->Init(NULL, gfx::Rect());
widget->SetContentsView(this);
// Set to a solid background with the same color as the widget's bg color.
GtkStyle* window_style = gtk_widget_get_style(widget->GetNativeView());
set_background(views::Background::CreateSolidBackground(
skia::GdkColorToSkColor(window_style->bg[GTK_STATE_NORMAL])));
widget->Show();
// Removing the widget from the container results in unref'ing the widget. We
// need to ref here otherwise the removal deletes the widget. The caller ends
// up taking ownership.
g_object_ref(widget->GetNativeView());
GtkWidget* parent = gtk_widget_get_parent(widget->GetNativeView());
gtk_container_remove(GTK_CONTAINER(parent), widget->GetNativeView());
return widget->GetNativeView();
}
////////////////////////////////////////////////////////////////////////////////
// SettingsPageSection
SettingsPageSection::SettingsPageSection(Profile* profile, int title_msg_id)
: OptionsPageView(profile),
title_msg_id_(title_msg_id),
// Using 1000 so that it does not clash with ids defined in subclasses.
single_column_view_set_id_(1000),
double_column_view_set_id_(1001) {
}
void SettingsPageSection::InitControlLayout() {
GridLayout* layout = new GridLayout(this);
SetLayoutManager(layout);
int single_column_layout_id = 0;
ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id);
column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
GridLayout::USE_PREF, 0, 0);
int inset_column_layout_id = 1;
column_set = layout->AddColumnSet(inset_column_layout_id);
column_set->AddPaddingColumn(0, kUnrelatedControlHorizontalSpacing);
column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1,
GridLayout::USE_PREF, 0, 0);
layout->StartRow(0, single_column_layout_id);
views::Label* title_label = new views::Label(
l10n_util::GetString(title_msg_id_));
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
gfx::Font title_font =
rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD);
title_label->SetFont(title_font);
layout->AddView(title_label);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, inset_column_layout_id);
views::View* contents = new views::View;
GridLayout* child_layout = new GridLayout(contents);
contents->SetLayoutManager(child_layout);
column_set = child_layout->AddColumnSet(single_column_view_set_id_);
column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
GridLayout::USE_PREF, 0, 0);
column_set = child_layout->AddColumnSet(double_column_view_set_id_);
column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
GridLayout::USE_PREF, 0, 0);
column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
GridLayout::USE_PREF, 0, 0);
InitContents(child_layout);
layout->AddView(contents);
}
} // namespace chromeos
|