OLD | NEW |
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 l10n_util::GetStringUTF8(IDS_TOOLTIP_RELOAD), | 138 l10n_util::GetStringUTF8(IDS_TOOLTIP_RELOAD), |
139 GTK_STOCK_REFRESH)); | 139 GTK_STOCK_REFRESH)); |
140 | 140 |
141 home_.reset(BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, | 141 home_.reset(BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, |
142 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME), | 142 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME), |
143 GTK_STOCK_HOME)); | 143 GTK_STOCK_HOME)); |
144 gtk_util::SetButtonTriggersNavigation(home_->widget()); | 144 gtk_util::SetButtonTriggersNavigation(home_->widget()); |
145 SetUpDragForHomeButton(); | 145 SetUpDragForHomeButton(); |
146 | 146 |
147 // Group the start, omnibox, and go button into an hbox. | 147 // Group the start, omnibox, and go button into an hbox. |
148 GtkWidget* omnibox_hbox_ = gtk_hbox_new(FALSE, 0); | 148 GtkWidget* location_hbox = gtk_hbox_new(FALSE, 0); |
149 star_.reset(BuildStarButton(l10n_util::GetStringUTF8(IDS_TOOLTIP_STAR))); | 149 star_.reset(BuildStarButton(l10n_util::GetStringUTF8(IDS_TOOLTIP_STAR))); |
150 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), star_->widget(), FALSE, FALSE, 0); | 150 gtk_box_pack_start(GTK_BOX(location_hbox), star_->widget(), FALSE, FALSE, 0); |
151 | 151 |
152 location_bar_->Init(); | 152 location_bar_->Init(); |
153 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), location_bar_->widget(), TRUE, | 153 gtk_box_pack_start(GTK_BOX(location_hbox), location_bar_->widget(), TRUE, |
154 TRUE, 0); | 154 TRUE, 0); |
155 | 155 |
156 go_.reset(new GoButtonGtk(location_bar_.get(), browser_)); | 156 go_.reset(new GoButtonGtk(location_bar_.get(), browser_)); |
157 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), go_->widget(), FALSE, FALSE, 0); | 157 gtk_box_pack_start(GTK_BOX(location_hbox), go_->widget(), FALSE, FALSE, 0); |
158 | 158 |
159 gtk_box_pack_start(GTK_BOX(toolbar_), omnibox_hbox_, TRUE, TRUE, 0); | 159 g_signal_connect(location_hbox, "expose-event", |
| 160 G_CALLBACK(OnLocationHboxExpose), this); |
| 161 gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox, TRUE, TRUE, 0); |
160 | 162 |
161 // Group the menu buttons together in an hbox. | 163 // Group the menu buttons together in an hbox. |
162 GtkWidget* menus_hbox_ = gtk_hbox_new(FALSE, 0); | 164 GtkWidget* menus_hbox_ = gtk_hbox_new(FALSE, 0); |
163 GtkWidget* page_menu = BuildToolbarMenuButton( | 165 GtkWidget* page_menu = BuildToolbarMenuButton( |
164 l10n_util::GetStringUTF8(IDS_PAGEMENU_TOOLTIP), | 166 l10n_util::GetStringUTF8(IDS_PAGEMENU_TOOLTIP), |
165 &page_menu_button_); | 167 &page_menu_button_); |
166 page_menu_image_ = gtk_image_new_from_pixbuf( | 168 page_menu_image_ = gtk_image_new_from_pixbuf( |
167 theme_provider_->GetRTLEnabledPixbufNamed(IDR_MENU_PAGE)); | 169 theme_provider_->GetRTLEnabledPixbufNamed(IDR_MENU_PAGE)); |
168 gtk_container_add(GTK_CONTAINER(page_menu), page_menu_image_); | 170 gtk_container_add(GTK_CONTAINER(page_menu), page_menu_image_); |
169 page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); | 171 page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 toolbar->window_->tabstrip()->GetTabStripOriginForWidget(widget); | 429 toolbar->window_->tabstrip()->GetTabStripOriginForWidget(widget); |
428 toolbar->background_ninebox_->RenderTopCenterStrip( | 430 toolbar->background_ninebox_->RenderTopCenterStrip( |
429 cr, tabstrip_origin.x(), tabstrip_origin.y(), | 431 cr, tabstrip_origin.x(), tabstrip_origin.y(), |
430 e->area.x + e->area.width - tabstrip_origin.x()); | 432 e->area.x + e->area.width - tabstrip_origin.x()); |
431 cairo_destroy(cr); | 433 cairo_destroy(cr); |
432 | 434 |
433 return FALSE; // Allow subwidgets to paint. | 435 return FALSE; // Allow subwidgets to paint. |
434 } | 436 } |
435 | 437 |
436 // static | 438 // static |
| 439 gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, |
| 440 GdkEventExpose* e, |
| 441 BrowserToolbarGtk* toolbar) { |
| 442 if (toolbar->theme_provider_->UseGtkTheme()) { |
| 443 // To get the proper look surrounding the location bar, we fake out the |
| 444 // theme engine into drawing a button. We fake out GTK by constructing a |
| 445 // box that's from the top left corner of the bookmark button to the bottom |
| 446 // right of the go button and fill it with a button's box (or the opposite |
| 447 // if in RTL mode). |
| 448 GtkWidget* star = toolbar->star_->widget(); |
| 449 GtkWidget* left = NULL; |
| 450 GtkWidget* right = NULL; |
| 451 if (gtk_widget_get_direction(star) == |
| 452 GTK_TEXT_DIR_LTR) { |
| 453 left = toolbar->star_->widget(); |
| 454 right = toolbar->go_->widget(); |
| 455 } else { |
| 456 left = toolbar->go_->widget(); |
| 457 right = toolbar->star_->widget(); |
| 458 } |
| 459 |
| 460 gint x = left->allocation.x; |
| 461 gint y = left->allocation.y; |
| 462 gint width = (right->allocation.x - left->allocation.x) + |
| 463 right->allocation.width; |
| 464 gint height = (right->allocation.y - left->allocation.y) + |
| 465 right->allocation.height; |
| 466 |
| 467 gtk_paint_box(star->style, location_hbox->window, |
| 468 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, |
| 469 location_hbox, "button", |
| 470 x, y, width, height); |
| 471 } |
| 472 |
| 473 return FALSE; |
| 474 } |
| 475 |
| 476 // static |
437 void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, | 477 void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, |
438 BrowserToolbarGtk* toolbar) { | 478 BrowserToolbarGtk* toolbar) { |
439 int tag = -1; | 479 int tag = -1; |
440 if (button == toolbar->reload_->widget()) | 480 if (button == toolbar->reload_->widget()) |
441 tag = IDC_RELOAD; | 481 tag = IDC_RELOAD; |
442 else if (toolbar->home_.get() && button == toolbar->home_->widget()) | 482 else if (toolbar->home_.get() && button == toolbar->home_->widget()) |
443 tag = IDC_HOME; | 483 tag = IDC_HOME; |
444 else if (button == toolbar->star_->widget()) | 484 else if (button == toolbar->star_->widget()) |
445 tag = IDC_STAR; | 485 tag = IDC_STAR; |
446 | 486 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 break; | 570 break; |
531 } | 571 } |
532 } | 572 } |
533 | 573 |
534 void BrowserToolbarGtk::InitNineBox() { | 574 void BrowserToolbarGtk::InitNineBox() { |
535 // TODO(estade): use |profile_|? | 575 // TODO(estade): use |profile_|? |
536 background_ninebox_.reset(new NineBox( | 576 background_ninebox_.reset(new NineBox( |
537 browser_->profile()->GetThemeProvider(), | 577 browser_->profile()->GetThemeProvider(), |
538 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); | 578 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); |
539 } | 579 } |
OLD | NEW |