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