| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), go_->widget(), FALSE, FALSE, 0); | 147 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), go_->widget(), FALSE, FALSE, 0); |
| 148 | 148 |
| 149 gtk_box_pack_start(GTK_BOX(toolbar_), omnibox_hbox_, TRUE, TRUE, 0); | 149 gtk_box_pack_start(GTK_BOX(toolbar_), omnibox_hbox_, TRUE, TRUE, 0); |
| 150 | 150 |
| 151 // Group the menu buttons together in an hbox. | 151 // Group the menu buttons together in an hbox. |
| 152 GtkWidget* menus_hbox_ = gtk_hbox_new(FALSE, 0); | 152 GtkWidget* menus_hbox_ = gtk_hbox_new(FALSE, 0); |
| 153 GtkWidget* page_menu = BuildToolbarMenuButton(IDR_MENU_PAGE, | 153 GtkWidget* page_menu = BuildToolbarMenuButton(IDR_MENU_PAGE, |
| 154 l10n_util::GetStringUTF8(IDS_PAGEMENU_TOOLTIP), | 154 l10n_util::GetStringUTF8(IDS_PAGEMENU_TOOLTIP), |
| 155 &page_menu_button_); | 155 &page_menu_button_); |
| 156 page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); | 156 page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); |
| 157 g_signal_connect(page_menu_->widget(), "motion-notify-event", |
| 158 G_CALLBACK(OnPageAppMenuMouseMotion), this); |
| 159 g_signal_connect(page_menu_->widget(), "move-current", |
| 160 G_CALLBACK(OnPageAppMenuMoveCurrent), this); |
| 157 gtk_box_pack_start(GTK_BOX(menus_hbox_), page_menu, FALSE, FALSE, 0); | 161 gtk_box_pack_start(GTK_BOX(menus_hbox_), page_menu, FALSE, FALSE, 0); |
| 158 | 162 |
| 159 GtkWidget* chrome_menu = BuildToolbarMenuButton(IDR_MENU_CHROME, | 163 GtkWidget* chrome_menu = BuildToolbarMenuButton(IDR_MENU_CHROME, |
| 160 l10n_util::GetStringFUTF8(IDS_APPMENU_TOOLTIP, | 164 l10n_util::GetStringFUTF8(IDS_APPMENU_TOOLTIP, |
| 161 WideToUTF16(l10n_util::GetString(IDS_PRODUCT_NAME))), | 165 WideToUTF16(l10n_util::GetString(IDS_PRODUCT_NAME))), |
| 162 &app_menu_button_); | 166 &app_menu_button_); |
| 163 app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); | 167 app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); |
| 168 g_signal_connect(app_menu_->widget(), "motion-notify-event", |
| 169 G_CALLBACK(OnPageAppMenuMouseMotion), this); |
| 170 g_signal_connect(app_menu_->widget(), "move-current", |
| 171 G_CALLBACK(OnPageAppMenuMoveCurrent), this); |
| 164 gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0); | 172 gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0); |
| 165 | 173 |
| 166 gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0); | 174 gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0); |
| 167 | 175 |
| 168 // Force all the CustomDrawButtons to load the correct rendering style. | 176 // Force all the CustomDrawButtons to load the correct rendering style. |
| 169 UserChangedTheme(); | 177 UserChangedTheme(); |
| 170 | 178 |
| 171 gtk_widget_show_all(toolbar_); | 179 gtk_widget_show_all(toolbar_); |
| 172 | 180 |
| 173 if (show_home_button_.GetValue()) { | 181 if (show_home_button_.GetValue()) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, | 378 gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, |
| 371 NULL, 0, GDK_ACTION_COPY); | 379 NULL, 0, GDK_ACTION_COPY); |
| 372 GtkDndUtil::SetDestTargetListFromCodeMask(home_->widget(), | 380 GtkDndUtil::SetDestTargetListFromCodeMask(home_->widget(), |
| 373 GtkDndUtil::X_CHROME_TEXT_PLAIN | | 381 GtkDndUtil::X_CHROME_TEXT_PLAIN | |
| 374 GtkDndUtil::X_CHROME_TEXT_URI_LIST); | 382 GtkDndUtil::X_CHROME_TEXT_URI_LIST); |
| 375 | 383 |
| 376 g_signal_connect(home_->widget(), "drag-data-received", | 384 g_signal_connect(home_->widget(), "drag-data-received", |
| 377 G_CALLBACK(OnDragDataReceived), this); | 385 G_CALLBACK(OnDragDataReceived), this); |
| 378 } | 386 } |
| 379 | 387 |
| 388 void BrowserToolbarGtk::ChangeActiveMenu(GtkWidget* active_menu, |
| 389 guint timestamp) { |
| 390 MenuGtk* old_menu; |
| 391 MenuGtk* new_menu; |
| 392 GtkWidget* relevant_button; |
| 393 if (active_menu == app_menu_->widget()) { |
| 394 old_menu = app_menu_.get(); |
| 395 new_menu = page_menu_.get(); |
| 396 relevant_button = page_menu_button_.get(); |
| 397 } else { |
| 398 old_menu = page_menu_.get(); |
| 399 new_menu = app_menu_.get(); |
| 400 relevant_button = app_menu_button_.get(); |
| 401 } |
| 402 |
| 403 old_menu->Cancel(); |
| 404 gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(relevant_button), |
| 405 GTK_STATE_ACTIVE); |
| 406 new_menu->Popup(relevant_button, 0, timestamp); |
| 407 } |
| 408 |
| 380 // static | 409 // static |
| 381 gboolean BrowserToolbarGtk::OnToolbarExpose(GtkWidget* widget, | 410 gboolean BrowserToolbarGtk::OnToolbarExpose(GtkWidget* widget, |
| 382 GdkEventExpose* e, | 411 GdkEventExpose* e, |
| 383 BrowserToolbarGtk* toolbar) { | 412 BrowserToolbarGtk* toolbar) { |
| 384 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 413 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
| 385 cairo_rectangle(cr, e->area.x, e->area.y, e->area.width, e->area.height); | 414 cairo_rectangle(cr, e->area.x, e->area.y, e->area.width, e->area.height); |
| 386 cairo_clip(cr); | 415 cairo_clip(cr); |
| 387 // The toolbar is supposed to blend in with the active tab, so we have to pass | 416 // The toolbar is supposed to blend in with the active tab, so we have to pass |
| 388 // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the | 417 // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the |
| 389 // tab strip. | 418 // tab strip. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 483 |
| 455 bool url_is_newtab = url.spec() == chrome::kChromeUINewTabURL; | 484 bool url_is_newtab = url.spec() == chrome::kChromeUINewTabURL; |
| 456 toolbar->profile_->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, | 485 toolbar->profile_->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, |
| 457 url_is_newtab); | 486 url_is_newtab); |
| 458 if (!url_is_newtab) { | 487 if (!url_is_newtab) { |
| 459 toolbar->profile_->GetPrefs()->SetString(prefs::kHomePage, | 488 toolbar->profile_->GetPrefs()->SetString(prefs::kHomePage, |
| 460 UTF8ToWide(url.spec())); | 489 UTF8ToWide(url.spec())); |
| 461 } | 490 } |
| 462 } | 491 } |
| 463 | 492 |
| 493 // static |
| 494 gboolean BrowserToolbarGtk::OnPageAppMenuMouseMotion(GtkWidget* menu, |
| 495 GdkEventMotion* event, BrowserToolbarGtk* toolbar) { |
| 496 if (gtk_util::WidgetContainsCursor(menu == toolbar->app_menu_->widget() ? |
| 497 toolbar->page_menu_button_.get() : |
| 498 toolbar->app_menu_button_.get())) { |
| 499 toolbar->ChangeActiveMenu(menu, event->time); |
| 500 return TRUE; |
| 501 } |
| 502 |
| 503 return FALSE; |
| 504 } |
| 505 |
| 506 // static |
| 507 void BrowserToolbarGtk::OnPageAppMenuMoveCurrent(GtkWidget* menu, |
| 508 GtkMenuDirectionType dir, BrowserToolbarGtk* toolbar) { |
| 509 GtkWidget* active_item = GTK_MENU_SHELL(menu)->active_menu_item; |
| 510 |
| 511 switch (dir) { |
| 512 case GTK_MENU_DIR_CHILD: |
| 513 // The move is going to open a submenu; don't override default behavior. |
| 514 if (active_item && gtk_menu_item_get_submenu(GTK_MENU_ITEM(active_item))) |
| 515 break; |
| 516 // Fall through. |
| 517 case GTK_MENU_DIR_PARENT: |
| 518 toolbar->ChangeActiveMenu(menu, gtk_get_current_event_time()); |
| 519 // This signal doesn't have a return value; we have to manually stop its |
| 520 // propagation. |
| 521 g_signal_stop_emission_by_name(menu, "move-current"); |
| 522 default: |
| 523 break; |
| 524 } |
| 525 } |
| 526 |
| 464 void BrowserToolbarGtk::InitNineBox() { | 527 void BrowserToolbarGtk::InitNineBox() { |
| 465 // TODO(estade): use |profile_|? | 528 // TODO(estade): use |profile_|? |
| 466 background_ninebox_.reset(new NineBox( | 529 background_ninebox_.reset(new NineBox( |
| 467 browser_->profile()->GetThemeProvider(), | 530 browser_->profile()->GetThemeProvider(), |
| 468 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); | 531 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); |
| 469 } | 532 } |
| OLD | NEW |