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

Side by Side Diff: chrome/browser/gtk/browser_toolbar_gtk.cc

Issue 159303: Implement location only display mode (used by popup windows). (Closed)
Patch Set: fix crash Created 11 years, 5 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/browser_toolbar_gtk.h ('k') | chrome/browser/gtk/location_bar_view_gtk.h » ('j') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/browser_toolbar_gtk.h" 5 #include "chrome/browser/gtk/browser_toolbar_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 #include <X11/XF86keysym.h> 8 #include <X11/XF86keysym.h>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 29 matching lines...) Expand all
40 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
41 #include "grit/chromium_strings.h" 41 #include "grit/chromium_strings.h"
42 #include "grit/generated_resources.h" 42 #include "grit/generated_resources.h"
43 #include "grit/theme_resources.h" 43 #include "grit/theme_resources.h"
44 44
45 namespace { 45 namespace {
46 46
47 // Height of the toolbar in pixels. 47 // Height of the toolbar in pixels.
48 const int kToolbarHeight = 37; 48 const int kToolbarHeight = 37;
49 49
50 // Height of the toolbar in pixels when we only show the location bar.
51 const int kToolbarHeightLocationBarOnly = kToolbarHeight - 10;
52
50 // Interior spacing between toolbar widgets. 53 // Interior spacing between toolbar widgets.
51 const int kToolbarWidgetSpacing = 4; 54 const int kToolbarWidgetSpacing = 4;
52 55
53 // The amount of space between the bottom of the star and the top of the 56 // The amount of space between the bottom of the star and the top of the
54 // Omnibox results popup window. We want a two pixel space between the bottom 57 // Omnibox results popup window. We want a two pixel space between the bottom
55 // and the results, but have some extra space below the buttons already. 58 // and the results, but have some extra space below the buttons already.
56 const int kPopupTopMargin = 0; 59 const int kPopupTopMargin = 0;
57 60
58 // Space between the edge of the star/go button and the popup frame. We want 61 // Space between the edge of the star/go button and the popup frame. We want
59 // to leave 1 pixel on both side here so that the borders line up. 62 // to leave 1 pixel on both side here so that the borders line up.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 SetProfile(profile); 130 SetProfile(profile);
128 131
129 theme_provider_ = GtkThemeProvider::GetFrom(profile); 132 theme_provider_ = GtkThemeProvider::GetFrom(profile);
130 133
131 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); 134 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this);
132 135
133 event_box_ = gtk_event_box_new(); 136 event_box_ = gtk_event_box_new();
134 137
135 toolbar_ = gtk_hbox_new(FALSE, kToolbarWidgetSpacing); 138 toolbar_ = gtk_hbox_new(FALSE, kToolbarWidgetSpacing);
136 gtk_container_add(GTK_CONTAINER(event_box_), toolbar_); 139 gtk_container_add(GTK_CONTAINER(event_box_), toolbar_);
137 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); 140 gtk_container_set_border_width(GTK_CONTAINER(toolbar_),
138 // Demand we're always at least kToolbarHeight tall. 141 ShouldOnlyShowLocation() ? 0 : 4);
139 // -1 for width means "let GTK do its normal sizing". 142 // Force the height of the toolbar so we get the right amount of padding
140 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); 143 // above and below the location bar. -1 for width means "let GTK do its
144 // normal sizing".
145 gtk_widget_set_size_request(toolbar_, -1, ShouldOnlyShowLocation() ?
146 kToolbarHeightLocationBarOnly : kToolbarHeight);
141 g_signal_connect(toolbar_, "expose-event", 147 g_signal_connect(toolbar_, "expose-event",
142 G_CALLBACK(&OnToolbarExpose), this); 148 G_CALLBACK(&OnToolbarExpose), this);
143 149
144 // A GtkAccelGroup is not InitiallyUnowned, meaning we get a real reference 150 // A GtkAccelGroup is not InitiallyUnowned, meaning we get a real reference
145 // count starting at one. We don't want the lifetime to be managed by the 151 // count starting at one. We don't want the lifetime to be managed by the
146 // top level window, since the lifetime should be tied to the C++ object. 152 // top level window, since the lifetime should be tied to the C++ object.
147 // When we add the accelerator group, the window will take a reference, but 153 // When we add the accelerator group, the window will take a reference, but
148 // we still hold on to the original, and thus own a reference to the group. 154 // we still hold on to the original, and thus own a reference to the group.
149 accel_group_ = gtk_accel_group_new(); 155 accel_group_ = gtk_accel_group_new();
150 gtk_window_add_accel_group(top_level_window, accel_group_); 156 gtk_window_add_accel_group(top_level_window, accel_group_);
(...skipping 18 matching lines...) Expand all
169 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME), 175 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME),
170 GTK_STOCK_HOME)); 176 GTK_STOCK_HOME));
171 gtk_util::SetButtonTriggersNavigation(home_->widget()); 177 gtk_util::SetButtonTriggersNavigation(home_->widget());
172 SetUpDragForHomeButton(); 178 SetUpDragForHomeButton();
173 179
174 // Group the start, omnibox, and go button into an hbox. 180 // Group the start, omnibox, and go button into an hbox.
175 GtkWidget* location_hbox = gtk_hbox_new(FALSE, 0); 181 GtkWidget* location_hbox = gtk_hbox_new(FALSE, 0);
176 star_.reset(BuildStarButton(l10n_util::GetStringUTF8(IDS_TOOLTIP_STAR))); 182 star_.reset(BuildStarButton(l10n_util::GetStringUTF8(IDS_TOOLTIP_STAR)));
177 gtk_box_pack_start(GTK_BOX(location_hbox), star_->widget(), FALSE, FALSE, 0); 183 gtk_box_pack_start(GTK_BOX(location_hbox), star_->widget(), FALSE, FALSE, 0);
178 184
179 location_bar_->Init(); 185 location_bar_->Init(ShouldOnlyShowLocation());
180 gtk_box_pack_start(GTK_BOX(location_hbox), location_bar_->widget(), TRUE, 186 gtk_box_pack_start(GTK_BOX(location_hbox), location_bar_->widget(), TRUE,
181 TRUE, 0); 187 TRUE, 0);
182 188
183 go_.reset(new GoButtonGtk(location_bar_.get(), browser_)); 189 go_.reset(new GoButtonGtk(location_bar_.get(), browser_));
184 gtk_box_pack_start(GTK_BOX(location_hbox), go_->widget(), FALSE, FALSE, 0); 190 gtk_box_pack_start(GTK_BOX(location_hbox), go_->widget(), FALSE, FALSE, 0);
185 191
186 g_signal_connect(location_hbox, "expose-event", 192 g_signal_connect(location_hbox, "expose-event",
187 G_CALLBACK(OnLocationHboxExpose), this); 193 G_CALLBACK(OnLocationHboxExpose), this);
188 gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox, TRUE, TRUE, 0); 194 gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox, TRUE, TRUE,
195 ShouldOnlyShowLocation() ? 1 : 0);
189 196
190 // Group the menu buttons together in an hbox. 197 // Group the menu buttons together in an hbox.
191 GtkWidget* menus_hbox_ = gtk_hbox_new(FALSE, 0); 198 GtkWidget* menus_hbox_ = gtk_hbox_new(FALSE, 0);
192 GtkWidget* page_menu = BuildToolbarMenuButton( 199 GtkWidget* page_menu = BuildToolbarMenuButton(
193 l10n_util::GetStringUTF8(IDS_PAGEMENU_TOOLTIP), 200 l10n_util::GetStringUTF8(IDS_PAGEMENU_TOOLTIP),
194 &page_menu_button_); 201 &page_menu_button_);
195 page_menu_image_ = gtk_image_new_from_pixbuf( 202 page_menu_image_ = gtk_image_new_from_pixbuf(
196 theme_provider_->GetRTLEnabledPixbufNamed(IDR_MENU_PAGE)); 203 theme_provider_->GetRTLEnabledPixbufNamed(IDR_MENU_PAGE));
197 gtk_container_add(GTK_CONTAINER(page_menu), page_menu_image_); 204 gtk_container_add(GTK_CONTAINER(page_menu), page_menu_image_);
198 205
(...skipping 15 matching lines...) Expand all
214 gtk_container_add(GTK_CONTAINER(chrome_menu), app_menu_image_); 221 gtk_container_add(GTK_CONTAINER(chrome_menu), app_menu_image_);
215 app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); 222 app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_));
216 g_signal_connect(app_menu_->widget(), "motion-notify-event", 223 g_signal_connect(app_menu_->widget(), "motion-notify-event",
217 G_CALLBACK(OnPageAppMenuMouseMotion), this); 224 G_CALLBACK(OnPageAppMenuMouseMotion), this);
218 g_signal_connect(app_menu_->widget(), "move-current", 225 g_signal_connect(app_menu_->widget(), "move-current",
219 G_CALLBACK(OnPageAppMenuMoveCurrent), this); 226 G_CALLBACK(OnPageAppMenuMoveCurrent), this);
220 gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0); 227 gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0);
221 228
222 gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0); 229 gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0);
223 230
224 gtk_widget_show_all(event_box_); 231 if (ShouldOnlyShowLocation()) {
232 gtk_widget_show(event_box_);
233 gtk_widget_show(toolbar_);
234 gtk_widget_show_all(location_hbox);
235 gtk_widget_hide(star_->widget());
236 gtk_widget_hide(go_->widget());
237 } else {
238 gtk_widget_show_all(event_box_);
225 239
226 if (show_home_button_.GetValue()) { 240 if (show_home_button_.GetValue()) {
227 gtk_widget_show(home_->widget()); 241 gtk_widget_show(home_->widget());
228 } else { 242 } else {
229 gtk_widget_hide(home_->widget()); 243 gtk_widget_hide(home_->widget());
244 }
230 } 245 }
231 } 246 }
232 247
233 void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) { 248 void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) {
234 gtk_box_pack_start(GTK_BOX(box), event_box_, FALSE, FALSE, 0); 249 gtk_box_pack_start(GTK_BOX(box), event_box_, FALSE, FALSE, 0);
235 } 250 }
236 251
237 void BrowserToolbarGtk::Show() { 252 void BrowserToolbarGtk::Show() {
238 gtk_widget_show(toolbar_); 253 gtk_widget_show(toolbar_);
239 } 254 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 326 }
312 327
313 // NotificationObserver -------------------------------------------------------- 328 // NotificationObserver --------------------------------------------------------
314 329
315 void BrowserToolbarGtk::Observe(NotificationType type, 330 void BrowserToolbarGtk::Observe(NotificationType type,
316 const NotificationSource& source, 331 const NotificationSource& source,
317 const NotificationDetails& details) { 332 const NotificationDetails& details) {
318 if (type == NotificationType::PREF_CHANGED) { 333 if (type == NotificationType::PREF_CHANGED) {
319 std::wstring* pref_name = Details<std::wstring>(details).ptr(); 334 std::wstring* pref_name = Details<std::wstring>(details).ptr();
320 if (*pref_name == prefs::kShowHomeButton) { 335 if (*pref_name == prefs::kShowHomeButton) {
321 if (show_home_button_.GetValue()) { 336 if (show_home_button_.GetValue() && !ShouldOnlyShowLocation()) {
322 gtk_widget_show(home_->widget()); 337 gtk_widget_show(home_->widget());
323 } else { 338 } else {
324 gtk_widget_hide(home_->widget()); 339 gtk_widget_hide(home_->widget());
325 } 340 }
326 } 341 }
327 } else if (type == NotificationType::BROWSER_THEME_CHANGED) { 342 } else if (type == NotificationType::BROWSER_THEME_CHANGED) {
328 // Update the spacing around the menu buttons 343 // Update the spacing around the menu buttons
329 int border = theme_provider_->UseGtkTheme() ? 0 : 2; 344 int border = theme_provider_->UseGtkTheme() ? 0 : 2;
330 gtk_container_set_border_width( 345 gtk_container_set_border_width(
331 GTK_CONTAINER(page_menu_button_.get()), border); 346 GTK_CONTAINER(page_menu_button_.get()), border);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 e->area.x + e->area.width - tabstrip_origin.x()); 497 e->area.x + e->area.width - tabstrip_origin.x());
483 cairo_destroy(cr); 498 cairo_destroy(cr);
484 499
485 return FALSE; // Allow subwidgets to paint. 500 return FALSE; // Allow subwidgets to paint.
486 } 501 }
487 502
488 // static 503 // static
489 gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, 504 gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox,
490 GdkEventExpose* e, 505 GdkEventExpose* e,
491 BrowserToolbarGtk* toolbar) { 506 BrowserToolbarGtk* toolbar) {
492 if (toolbar->theme_provider_->UseGtkTheme()) { 507 if (toolbar->theme_provider_->UseGtkTheme() &&
508 !toolbar->ShouldOnlyShowLocation()) {
493 // To get the proper look surrounding the location bar, we fake out the 509 // To get the proper look surrounding the location bar, we fake out the
494 // theme engine into drawing a button. We fake out GTK by constructing a 510 // theme engine into drawing a button. We fake out GTK by constructing a
495 // box that's from the top left corner of the bookmark button to the bottom 511 // box that's from the top left corner of the bookmark button to the bottom
496 // right of the go button and fill it with a button's box (or the opposite 512 // right of the go button and fill it with a button's box (or the opposite
497 // if in RTL mode). 513 // if in RTL mode).
498 GtkWidget* star = toolbar->star_->widget(); 514 GtkWidget* star = toolbar->star_->widget();
499 GtkWidget* left = NULL; 515 GtkWidget* left = NULL;
500 GtkWidget* right = NULL; 516 GtkWidget* right = NULL;
501 if (gtk_widget_get_direction(star) == 517 if (gtk_widget_get_direction(star) ==
502 GTK_TEXT_DIR_LTR) { 518 GTK_TEXT_DIR_LTR) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 // Fall through. 629 // Fall through.
614 case GTK_MENU_DIR_PARENT: 630 case GTK_MENU_DIR_PARENT:
615 toolbar->ChangeActiveMenu(menu, gtk_get_current_event_time()); 631 toolbar->ChangeActiveMenu(menu, gtk_get_current_event_time());
616 // This signal doesn't have a return value; we have to manually stop its 632 // This signal doesn't have a return value; we have to manually stop its
617 // propagation. 633 // propagation.
618 g_signal_stop_emission_by_name(menu, "move-current"); 634 g_signal_stop_emission_by_name(menu, "move-current");
619 default: 635 default:
620 break; 636 break;
621 } 637 }
622 } 638 }
639
640 bool BrowserToolbarGtk::ShouldOnlyShowLocation() const {
641 // If we're a popup window, only show the location bar (omnibox).
642 return browser_->type() != Browser::TYPE_NORMAL;
643 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_toolbar_gtk.h ('k') | chrome/browser/gtk/location_bar_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698