| 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/task_manager_gtk.h" | 5 #include "chrome/browser/gtk/task_manager_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
| 8 | 8 |
| 9 #include <algorithm> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 12 #include "base/gfx/gtk_util.h" | 13 #include "base/gfx/gtk_util.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browser_window.h" |
| 18 #include "chrome/browser/gtk/gtk_chrome_link_button.h" |
| 15 #include "chrome/browser/gtk/menu_gtk.h" | 19 #include "chrome/browser/gtk/menu_gtk.h" |
| 16 #include "chrome/common/gtk_util.h" | 20 #include "chrome/common/gtk_util.h" |
| 17 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/pref_service.h" | 22 #include "chrome/common/pref_service.h" |
| 19 #include "grit/chromium_strings.h" | 23 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 21 | 25 |
| 22 namespace { | 26 namespace { |
| 23 | 27 |
| 24 // The task manager window default size. | 28 // The task manager window default size. |
| 25 const int kDefaultWidth = 460; | 29 const int kDefaultWidth = 460; |
| 26 const int kDefaultHeight = 270; | 30 const int kDefaultHeight = 270; |
| 27 | 31 |
| 28 // The resource id for the 'End process' button. | 32 // The resource id for the 'End process' button. |
| 29 const gint kTaskManagerResponseKill = 1; | 33 const gint kTaskManagerResponseKill = 1; |
| 30 | 34 |
| 35 // The resource id for the 'Stats for nerds' link button. |
| 36 const gint kTaskManagerAboutMemoryLink = 2; |
| 37 |
| 31 enum TaskManagerColumn { | 38 enum TaskManagerColumn { |
| 32 kTaskManagerIcon, | 39 kTaskManagerIcon, |
| 33 kTaskManagerPage, | 40 kTaskManagerPage, |
| 34 kTaskManagerPhysicalMem, | 41 kTaskManagerPhysicalMem, |
| 35 kTaskManagerSharedMem, | 42 kTaskManagerSharedMem, |
| 36 kTaskManagerPrivateMem, | 43 kTaskManagerPrivateMem, |
| 37 kTaskManagerCPU, | 44 kTaskManagerCPU, |
| 38 kTaskManagerNetwork, | 45 kTaskManagerNetwork, |
| 39 kTaskManagerProcessID, | 46 kTaskManagerProcessID, |
| 40 kTaskManagerGoatsTeleported, | 47 kTaskManagerGoatsTeleported, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 void TaskManagerGtk::Init() { | 318 void TaskManagerGtk::Init() { |
| 312 dialog_ = gtk_dialog_new_with_buttons( | 319 dialog_ = gtk_dialog_new_with_buttons( |
| 313 l10n_util::GetStringUTF8(IDS_TASK_MANAGER_TITLE).c_str(), | 320 l10n_util::GetStringUTF8(IDS_TASK_MANAGER_TITLE).c_str(), |
| 314 // Task Manager window is shared between all browsers. | 321 // Task Manager window is shared between all browsers. |
| 315 NULL, | 322 NULL, |
| 316 GTK_DIALOG_NO_SEPARATOR, | 323 GTK_DIALOG_NO_SEPARATOR, |
| 317 l10n_util::GetStringUTF8(IDS_TASK_MANAGER_KILL).c_str(), | 324 l10n_util::GetStringUTF8(IDS_TASK_MANAGER_KILL).c_str(), |
| 318 kTaskManagerResponseKill, | 325 kTaskManagerResponseKill, |
| 319 NULL); | 326 NULL); |
| 320 | 327 |
| 328 GtkWidget* link = gtk_chrome_link_button_new( |
| 329 l10n_util::GetStringUTF8(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK).c_str()); |
| 330 gtk_dialog_add_action_widget(GTK_DIALOG(dialog_), link, |
| 331 kTaskManagerAboutMemoryLink); |
| 332 |
| 333 // Setting the link widget to secondary positions the button on the left side |
| 334 // of the action area (vice versa for RTL layout). |
| 335 gtk_button_box_set_child_secondary( |
| 336 GTK_BUTTON_BOX(GTK_DIALOG(dialog_)->action_area), link, TRUE); |
| 337 |
| 321 ConnectAccelerators(); | 338 ConnectAccelerators(); |
| 322 | 339 |
| 323 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), | 340 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), |
| 324 gtk_util::kContentAreaSpacing); | 341 gtk_util::kContentAreaSpacing); |
| 325 gtk_util::SetWindowIcon(GTK_WINDOW(dialog_)); | 342 gtk_util::SetWindowIcon(GTK_WINDOW(dialog_)); |
| 326 | 343 |
| 327 g_signal_connect(G_OBJECT(dialog_), "response", G_CALLBACK(OnResponse), this); | 344 g_signal_connect(G_OBJECT(dialog_), "response", G_CALLBACK(OnResponse), this); |
| 328 g_signal_connect(G_OBJECT(dialog_), "button-release-event", | 345 g_signal_connect(G_OBJECT(dialog_), "button-release-event", |
| 329 G_CALLBACK(OnButtonReleaseEvent), this); | 346 G_CALLBACK(OnButtonReleaseEvent), this); |
| 330 gtk_widget_add_events(dialog_, | 347 gtk_widget_add_events(dialog_, |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 GtkTreeSelection* selection = gtk_tree_view_get_selection( | 544 GtkTreeSelection* selection = gtk_tree_view_get_selection( |
| 528 GTK_TREE_VIEW(treeview_)); | 545 GTK_TREE_VIEW(treeview_)); |
| 529 | 546 |
| 530 // If the user has just double clicked, only one item is selected. | 547 // If the user has just double clicked, only one item is selected. |
| 531 GtkTreeModel* model; | 548 GtkTreeModel* model; |
| 532 GList* selected = gtk_tree_selection_get_selected_rows(selection, &model); | 549 GList* selected = gtk_tree_selection_get_selected_rows(selection, &model); |
| 533 int row = GetRowNumForPath(reinterpret_cast<GtkTreePath*>(selected->data)); | 550 int row = GetRowNumForPath(reinterpret_cast<GtkTreePath*>(selected->data)); |
| 534 task_manager_->ActivateProcess(row); | 551 task_manager_->ActivateProcess(row); |
| 535 } | 552 } |
| 536 | 553 |
| 554 void TaskManagerGtk::OnLinkActivated() { |
| 555 Browser* browser = BrowserList::GetLastActive(); |
| 556 DCHECK(browser); |
| 557 browser->OpenURL(GURL("about:memory"), GURL(), NEW_FOREGROUND_TAB, |
| 558 PageTransition::LINK); |
| 559 // In case the browser window is minimzed, show it. If this is an application |
| 560 // or popup, we can only have one tab, hence we need to process this in a |
| 561 // tabbed browser window. Currently, |browser| is pointing to the application, |
| 562 // popup window. Therefore, we have to retrieve the last active tab again, |
| 563 // since a new window has been used. |
| 564 if (browser->type() & Browser::TYPE_APP_POPUP) { |
| 565 browser = BrowserList::GetLastActive(); |
| 566 DCHECK(browser); |
| 567 } |
| 568 browser->window()->Show(); |
| 569 } |
| 570 |
| 537 // static | 571 // static |
| 538 void TaskManagerGtk::OnResponse(GtkDialog* dialog, gint response_id, | 572 void TaskManagerGtk::OnResponse(GtkDialog* dialog, gint response_id, |
| 539 TaskManagerGtk* task_manager) { | 573 TaskManagerGtk* task_manager) { |
| 540 if (response_id == GTK_RESPONSE_DELETE_EVENT) { | 574 if (response_id == GTK_RESPONSE_DELETE_EVENT) { |
| 541 // Store the dialog's size so we can restore it the next time it's opened. | 575 // Store the dialog's size so we can restore it the next time it's opened. |
| 542 if (g_browser_process->local_state()) { | 576 if (g_browser_process->local_state()) { |
| 543 gint x = 0, y = 0, width = 1, height = 1; | 577 gint x = 0, y = 0, width = 1, height = 1; |
| 544 gtk_window_get_position(GTK_WINDOW(dialog), &x, &y); | 578 gtk_window_get_position(GTK_WINDOW(dialog), &x, &y); |
| 545 gtk_window_get_size(GTK_WINDOW(dialog), &width, &height); | 579 gtk_window_get_size(GTK_WINDOW(dialog), &width, &height); |
| 546 | 580 |
| 547 DictionaryValue* placement_pref = | 581 DictionaryValue* placement_pref = |
| 548 g_browser_process->local_state()->GetMutableDictionary( | 582 g_browser_process->local_state()->GetMutableDictionary( |
| 549 prefs::kTaskManagerWindowPlacement); | 583 prefs::kTaskManagerWindowPlacement); |
| 550 // Note that we store left/top for consistency with Windows, but that we | 584 // Note that we store left/top for consistency with Windows, but that we |
| 551 // *don't* restore them. | 585 // *don't* restore them. |
| 552 placement_pref->SetInteger(L"left", x); | 586 placement_pref->SetInteger(L"left", x); |
| 553 placement_pref->SetInteger(L"top", y); | 587 placement_pref->SetInteger(L"top", y); |
| 554 placement_pref->SetInteger(L"right", x + width); | 588 placement_pref->SetInteger(L"right", x + width); |
| 555 placement_pref->SetInteger(L"bottom", y + height); | 589 placement_pref->SetInteger(L"bottom", y + height); |
| 556 placement_pref->SetBoolean(L"maximized", false); | 590 placement_pref->SetBoolean(L"maximized", false); |
| 557 } | 591 } |
| 558 | 592 |
| 559 instance_ = NULL; | 593 instance_ = NULL; |
| 560 delete task_manager; | 594 delete task_manager; |
| 561 } else if (response_id == kTaskManagerResponseKill) { | 595 } else if (response_id == kTaskManagerResponseKill) { |
| 562 task_manager->KillSelectedProcesses(); | 596 task_manager->KillSelectedProcesses(); |
| 597 } else if (response_id == kTaskManagerAboutMemoryLink) { |
| 598 task_manager->OnLinkActivated(); |
| 563 } | 599 } |
| 564 } | 600 } |
| 565 | 601 |
| 566 // static | 602 // static |
| 567 void TaskManagerGtk::OnSelectionChanged(GtkTreeSelection* selection, | 603 void TaskManagerGtk::OnSelectionChanged(GtkTreeSelection* selection, |
| 568 TaskManagerGtk* task_manager) { | 604 TaskManagerGtk* task_manager) { |
| 569 bool selection_contains_browser_process = false; | 605 bool selection_contains_browser_process = false; |
| 570 | 606 |
| 571 GtkTreeModel* model; | 607 GtkTreeModel* model; |
| 572 GList* paths = gtk_tree_selection_get_selected_rows(selection, &model); | 608 GList* paths = gtk_tree_selection_get_selected_rows(selection, &model); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 if (keyval == GDK_w && modifier == GDK_CONTROL_MASK) { | 653 if (keyval == GDK_w && modifier == GDK_CONTROL_MASK) { |
| 618 // The GTK_RESPONSE_DELETE_EVENT response must be sent before the widget | 654 // The GTK_RESPONSE_DELETE_EVENT response must be sent before the widget |
| 619 // is destroyed. The deleted object will receive gtk signals otherwise. | 655 // is destroyed. The deleted object will receive gtk signals otherwise. |
| 620 gtk_dialog_response(GTK_DIALOG(task_manager->dialog_), | 656 gtk_dialog_response(GTK_DIALOG(task_manager->dialog_), |
| 621 GTK_RESPONSE_DELETE_EVENT); | 657 GTK_RESPONSE_DELETE_EVENT); |
| 622 gtk_widget_destroy(task_manager->dialog_); | 658 gtk_widget_destroy(task_manager->dialog_); |
| 623 } | 659 } |
| 624 | 660 |
| 625 return TRUE; | 661 return TRUE; |
| 626 } | 662 } |
| OLD | NEW |