summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/options/options_window_view.cc
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-05 07:57:10 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-05 07:57:10 +0000
commitf861719588545d92ba979f491f4cd10cbf544016 (patch)
tree5f5a64d4ba48a8d884ee360a562fb08371404ed6 /chrome/browser/chromeos/options/options_window_view.cc
parent84aa957953cf6eb36c4e8886a28aede5fd98f748 (diff)
downloadchromium_src-f861719588545d92ba979f491f4cd10cbf544016.zip
chromium_src-f861719588545d92ba979f491f4cd10cbf544016.tar.gz
chromium_src-f861719588545d92ba979f491f4cd10cbf544016.tar.bz2
Re-land r51526
Auto-size the views version of the options dialog. This adds support for auto-sizing tab controls, adjusts the options dialog to use it and takes care of any fallout due to the new layout handling. Also fixes a couple of small bugs in the views Layout() machinery and sanitizes layouting of options pages. BUG=36497 TEST=unit tests in tabbed_pane_unittest.cc and grid_layout_unittest.cc, as well as checking the options dialog in any supported language. original issuse: http://codereview.chromium.org/2812026/show Review URL: http://codereview.chromium.org/2883022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51628 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/options/options_window_view.cc')
-rw-r--r--chrome/browser/chromeos/options/options_window_view.cc73
1 files changed, 54 insertions, 19 deletions
diff --git a/chrome/browser/chromeos/options/options_window_view.cc b/chrome/browser/chromeos/options/options_window_view.cc
index d284ce3..4535e8b 100644
--- a/chrome/browser/chromeos/options/options_window_view.cc
+++ b/chrome/browser/chromeos/options/options_window_view.cc
@@ -35,6 +35,48 @@
namespace chromeos {
///////////////////////////////////////////////////////////////////////////////
+// GtkPreferencePageHost
+//
+// Hosts a GTK preference page and takes care of sizing it appropriately.
+//
+class GtkPreferencePageHost : public views::NativeViewHost {
+ public:
+ explicit GtkPreferencePageHost(GtkWidget* widget);
+
+ private:
+ // views::View overrides:
+ virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
+ virtual gfx::Size GetPreferredSize();
+
+ GtkWidget* widget_;
+
+ DISALLOW_COPY_AND_ASSIGN(GtkPreferencePageHost);
+};
+
+GtkPreferencePageHost::GtkPreferencePageHost(GtkWidget* widget)
+ : widget_(widget) {
+ set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
+}
+
+void GtkPreferencePageHost::ViewHierarchyChanged(bool is_add,
+ View* parent,
+ View* child) {
+ NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
+ if (is_add && child == this)
+ Attach(widget_);
+}
+
+gfx::Size GtkPreferencePageHost::GetPreferredSize() {
+ // We need to show the widget and its children since otherwise containers like
+ // gtk_box don't compute the correct size.
+ gtk_widget_show_all(widget_);
+ GtkRequisition requisition = { 0, 0 };
+ gtk_widget_size_request(GTK_WIDGET(widget_), &requisition);
+ GtkRequisition& size(widget_->requisition);
+ return gfx::Size(size.width, size.height);
+}
+
+///////////////////////////////////////////////////////////////////////////////
// OptionsWindowView
//
// The contents of the Options dialog window.
@@ -214,9 +256,9 @@ void OptionsWindowView::Layout() {
}
gfx::Size OptionsWindowView::GetPreferredSize() {
- return gfx::Size(views::Window::GetLocalizedContentsSize(
- IDS_OPTIONS_DIALOG_WIDTH_CHARS,
- IDS_OPTIONS_DIALOG_HEIGHT_LINES));
+ gfx::Size size(tabs_->GetPreferredSize());
+ size.Enlarge(2 * kDialogPadding, 2 * kDialogPadding);
+ return size;
}
void OptionsWindowView::ViewHierarchyChanged(bool is_add,
@@ -263,29 +305,23 @@ void OptionsWindowView::Init() {
l10n_util::GetString(IDS_OPTIONS_INTERNET_TAB_LABEL),
internet_page, false);
- views::NativeViewHost* general_page_view = new views::NativeViewHost();
- general_page_view->set_background(views::Background::CreateSolidBackground(
- SK_ColorWHITE));
tabs_->AddTabAtIndex(tab_index++,
l10n_util::GetString(IDS_OPTIONS_GENERAL_TAB_LABEL),
- general_page_view, false);
- general_page_view->Attach(general_page_.get_page_widget());
+ new GtkPreferencePageHost(
+ general_page_.get_page_widget()),
+ false);
- views::NativeViewHost* content_page_view = new views::NativeViewHost();
- content_page_view->set_background(views::Background::CreateSolidBackground(
- SK_ColorWHITE));
tabs_->AddTabAtIndex(tab_index++,
l10n_util::GetString(IDS_OPTIONS_CONTENT_TAB_LABEL),
- content_page_view, false);
- content_page_view->Attach(content_page_.get_page_widget());
+ new GtkPreferencePageHost(
+ content_page_.get_page_widget()),
+ false);
- views::NativeViewHost* advanced_page_view = new views::NativeViewHost();
- advanced_page_view->set_background(views::Background::CreateSolidBackground(
- SK_ColorWHITE));
tabs_->AddTabAtIndex(tab_index++,
l10n_util::GetString(IDS_OPTIONS_ADVANCED_TAB_LABEL),
- advanced_page_view, false);
- advanced_page_view->Attach(advanced_page_.get_page_widget());
+ new GtkPreferencePageHost(
+ advanced_page_.get_page_widget()),
+ false);
DCHECK(tabs_->GetTabCount() == OPTIONS_PAGE_COUNT);
@@ -344,4 +380,3 @@ void ShowOptionsWindow(OptionsPage page,
OptionsWindowView::instance_->ShowOptionsPage(page, highlight_group);
}
-