Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/browser/gtk/options/options_layout_gtk.cc

Issue 1969006: Fix 18949 on GTK ("Options" window does not fit a small display). (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: Update based on evan's comments of patch set 4 and sync with trunk Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/options/options_layout_gtk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/options/options_layout_gtk.h" 5 #include "chrome/browser/gtk/options/options_layout_gtk.h"
6 6
7 #include "chrome/browser/gtk/gtk_util.h" 7 #include "chrome/browser/gtk/gtk_util.h"
8 8
9 OptionsLayoutBuilderGtk::OptionsLayoutBuilderGtk() { 9 // If the height of screen is equal or shorter than this, we will use
10 // a more compact option layout.
11 const int kCompactScreenHeight = 600;
12
13 // Default option layout builder follows GNOME HIG, which uses header and
14 // spacing to group options.
15 class DefaultOptionsLayoutBuilderGtk : public OptionsLayoutBuilderGtk {
16 public:
17 explicit DefaultOptionsLayoutBuilderGtk();
18
19 void AddOptionGroup(const std::string& title, GtkWidget* content,
20 bool expandable);
21 void AddWidget(GtkWidget* content, bool expandable);
22 private:
23 DISALLOW_COPY_AND_ASSIGN(DefaultOptionsLayoutBuilderGtk);
24 };
25
26 DefaultOptionsLayoutBuilderGtk::DefaultOptionsLayoutBuilderGtk() {
10 page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing); 27 page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing);
11 gtk_container_set_border_width(GTK_CONTAINER(page_), 28 gtk_container_set_border_width(GTK_CONTAINER(page_),
12 gtk_util::kContentAreaBorder); 29 gtk_util::kContentAreaBorder);
13 } 30 }
14 31
15 void OptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title, 32 void DefaultOptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title,
16 GtkWidget* content, 33 GtkWidget* content,
17 bool expandable) { 34 bool expandable) {
18 GtkWidget* title_label = gtk_util::CreateBoldLabel(title); 35 GtkWidget* title_label = gtk_util::CreateBoldLabel(title);
19 36
20 GtkWidget* group = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); 37 GtkWidget* group = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
21 gtk_box_pack_start(GTK_BOX(group), title_label, FALSE, FALSE, 0); 38 gtk_box_pack_start(GTK_BOX(group), title_label, FALSE, FALSE, 0);
22 gtk_container_add(GTK_CONTAINER(group), gtk_util::IndentWidget(content)); 39 gtk_container_add(GTK_CONTAINER(group), gtk_util::IndentWidget(content));
23 40
24 AddWidget(group, expandable); 41 AddWidget(group, expandable);
25 } 42 }
26 43
27 void OptionsLayoutBuilderGtk::AddWidget(GtkWidget* content, bool expandable) { 44 void DefaultOptionsLayoutBuilderGtk::AddWidget(GtkWidget* content,
45 bool expandable) {
28 gtk_box_pack_start(GTK_BOX(page_), content, expandable, expandable, 0); 46 gtk_box_pack_start(GTK_BOX(page_), content, expandable, expandable, 0);
29 } 47 }
48
49 // Compact layout builder uses table to layout label and content horizontally.
50 class CompactOptionsLayoutBuilderGtk : public OptionsLayoutBuilderGtk {
51 public:
52 explicit CompactOptionsLayoutBuilderGtk();
53
54 void AddOptionGroup(const std::string& title, GtkWidget* content,
55 bool expandable);
56 void AddWidget(GtkWidget* content, bool expandable);
57 private:
58 GtkWidget *table_;
59 guint row_;
60
61 DISALLOW_COPY_AND_ASSIGN(CompactOptionsLayoutBuilderGtk);
62 };
63
64 CompactOptionsLayoutBuilderGtk::CompactOptionsLayoutBuilderGtk() {
65 row_ = 0;
66 table_ = NULL;
67
68 page_ = gtk_vbox_new(FALSE, gtk_util::kContentAreaSpacing);
69 gtk_container_set_border_width(GTK_CONTAINER(page_),
70 gtk_util::kContentAreaBorder);
71 }
72
73 void CompactOptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title,
74 GtkWidget* content,
75 bool expandable) {
76 if (!table_) {
77 // Create a new table to contain option groups
78 table_ = gtk_table_new(0, 2, FALSE);
79 gtk_table_set_col_spacing(GTK_TABLE(table_), 0, gtk_util::kLabelSpacing);
80 gtk_table_set_row_spacings(GTK_TABLE(table_),
81 gtk_util::kContentAreaSpacing);
82
83 gtk_container_set_border_width(GTK_CONTAINER(table_),
84 gtk_util::kContentAreaBorder);
85 gtk_box_pack_start(GTK_BOX(page_), table_, TRUE, TRUE, 0);
86 }
87
88 GtkWidget* title_label = gtk_util::CreateBoldLabel(title);
89
90 gtk_table_resize(GTK_TABLE(table_), row_ + 1, 2);
91 gtk_misc_set_alignment(GTK_MISC(title_label), 1, 0);
92
93 gtk_table_attach(GTK_TABLE(table_), title_label,
94 0, 1, row_, row_ + 1,
95 GTK_FILL, GTK_FILL,
96 0, 0);
97 gtk_table_attach(GTK_TABLE(table_), content,
98 1, 2, row_, row_ + 1,
99 expandable ?
100 GTK_FILL : GtkAttachOptions(GTK_FILL | GTK_EXPAND),
101 GTK_FILL,
102 0, 0);
103 row_++;
104 }
105
106 void CompactOptionsLayoutBuilderGtk::AddWidget(GtkWidget* content,
107 bool expandable) {
108 gtk_box_pack_start(GTK_BOX(page_), content, expandable, expandable, 0);
109
110 // Let AddOptionGroup create a new table and append after this widget
111 table_ = NULL;
112 }
113
114 OptionsLayoutBuilderGtk* OptionsLayoutBuilderGtk::Create() {
115 return new DefaultOptionsLayoutBuilderGtk();
116 }
117
118 OptionsLayoutBuilderGtk*
119 OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout() {
120 gint screen_height = gdk_screen_get_height(gdk_screen_get_default());
121 if (screen_height <= kCompactScreenHeight)
122 return new CompactOptionsLayoutBuilderGtk();
123 else
124 return new DefaultOptionsLayoutBuilderGtk();
125 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/options/options_layout_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698