| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_ |
| 6 #define CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_ | 6 #define CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <gtk/gtk.h> | 9 #include "chrome/browser/ui/gtk/task_manager_gtk.h" |
| 10 | 10 // TODO(msw): remove this file once all includes have been updated. |
| 11 #include <string> | |
| 12 | |
| 13 #include "app/gtk_signal.h" | |
| 14 #include "base/scoped_ptr.h" | |
| 15 #include "chrome/browser/task_manager/task_manager.h" | |
| 16 #include "grit/generated_resources.h" | |
| 17 | |
| 18 #if defined(TOOLKIT_VIEWS) | |
| 19 namespace gfx { | |
| 20 class Point; | |
| 21 } | |
| 22 #endif | |
| 23 | |
| 24 class TaskManagerGtk : public TaskManagerModelObserver { | |
| 25 public: | |
| 26 TaskManagerGtk(); | |
| 27 virtual ~TaskManagerGtk(); | |
| 28 | |
| 29 // TaskManagerModelObserver | |
| 30 virtual void OnModelChanged(); | |
| 31 virtual void OnItemsChanged(int start, int length); | |
| 32 virtual void OnItemsAdded(int start, int length); | |
| 33 virtual void OnItemsRemoved(int start, int length); | |
| 34 | |
| 35 // Creates the task manager if it doesn't exist; otherwise, it activates the | |
| 36 // existing task manager window. | |
| 37 static void Show(); | |
| 38 | |
| 39 private: | |
| 40 class ContextMenuController; | |
| 41 friend class ContextMenuController; | |
| 42 | |
| 43 // Initializes the task manager dialog. | |
| 44 void Init(); | |
| 45 | |
| 46 // Set |dialog_|'s initial size, using its previous size if that was saved. | |
| 47 void SetInitialDialogSize(); | |
| 48 | |
| 49 // Connects the ctrl-w accelerator to the dialog. | |
| 50 void ConnectAccelerators(); | |
| 51 | |
| 52 // Sets up the treeview widget. | |
| 53 void CreateTaskManagerTreeview(); | |
| 54 | |
| 55 // Returns the model data for a given |row| and |col_id|. | |
| 56 std::string GetModelText(int row, int col_id); | |
| 57 | |
| 58 // Retrieves the resource icon from the model for |row|. | |
| 59 GdkPixbuf* GetModelIcon(int row); | |
| 60 | |
| 61 // Sets the treeview row data. |row| is an index into the model and |iter| | |
| 62 // is the current position in the treeview. | |
| 63 void SetRowDataFromModel(int row, GtkTreeIter* iter); | |
| 64 | |
| 65 // Queries the treeview for the selected rows, and kills those processes. | |
| 66 void KillSelectedProcesses(); | |
| 67 | |
| 68 // Opens the context menu used to select the task manager columns. | |
| 69 #if defined(TOOLKIT_VIEWS) | |
| 70 void ShowContextMenu(const gfx::Point& point); | |
| 71 #else | |
| 72 void ShowContextMenu(); | |
| 73 #endif | |
| 74 | |
| 75 // Opens about:memory in a new foreground tab. | |
| 76 void OnLinkActivated(); | |
| 77 | |
| 78 // Compare implementation used for sorting columns. | |
| 79 gint CompareImpl(GtkTreeModel* tree_model, GtkTreeIter* a, | |
| 80 GtkTreeIter* b, int id); | |
| 81 | |
| 82 // Response signal handler that notifies us of dialog destruction. | |
| 83 CHROMEGTK_CALLBACK_0(TaskManagerGtk, void, OnDestroy); | |
| 84 | |
| 85 // Response signal handler that notifies us of dialog responses. | |
| 86 CHROMEGTK_CALLBACK_1(TaskManagerGtk, void, OnResponse, gint); | |
| 87 | |
| 88 // Realize signal handler to set the page column's initial size. | |
| 89 CHROMEG_CALLBACK_0(TaskManagerGtk, void, OnTreeViewRealize, GtkTreeView*); | |
| 90 | |
| 91 // Changed signal handler that is sent when the treeview selection changes. | |
| 92 CHROMEG_CALLBACK_0(TaskManagerGtk, void, OnSelectionChanged, | |
| 93 GtkTreeSelection*); | |
| 94 | |
| 95 // row-activated handler that foregrounds a process on activation (e.g., | |
| 96 // double-click). | |
| 97 CHROMEGTK_CALLBACK_2(TaskManagerGtk, void, OnRowActivated, | |
| 98 GtkTreePath*, GtkTreeViewColumn*); | |
| 99 | |
| 100 // button-release-event handler that opens the right-click context menu. | |
| 101 CHROMEGTK_CALLBACK_1(TaskManagerGtk, gboolean, OnButtonReleaseEvent, | |
| 102 GdkEventButton*); | |
| 103 | |
| 104 // Handles an accelerator being pressed. | |
| 105 CHROMEG_CALLBACK_3(TaskManagerGtk, gboolean, OnGtkAccelerator, | |
| 106 GtkAccelGroup*, GObject*, guint, GdkModifierType); | |
| 107 | |
| 108 // Page sorting callback. | |
| 109 static gint ComparePage(GtkTreeModel* model, GtkTreeIter* a, | |
| 110 GtkTreeIter* b, gpointer task_manager) { | |
| 111 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 112 CompareImpl(model, a, b, IDS_TASK_MANAGER_PAGE_COLUMN); | |
| 113 } | |
| 114 | |
| 115 // Shared memory sorting callback. | |
| 116 static gint CompareSharedMemory(GtkTreeModel* model, GtkTreeIter* a, | |
| 117 GtkTreeIter* b, gpointer task_manager) { | |
| 118 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 119 CompareImpl(model, a, b, IDS_TASK_MANAGER_SHARED_MEM_COLUMN); | |
| 120 } | |
| 121 | |
| 122 // Private memory sorting callback. | |
| 123 static gint ComparePrivateMemory(GtkTreeModel* model, GtkTreeIter* a, | |
| 124 GtkTreeIter* b, gpointer task_manager) { | |
| 125 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 126 CompareImpl(model, a, b, IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN); | |
| 127 } | |
| 128 | |
| 129 // Javascript memory sorting callback. | |
| 130 static gint CompareV8Memory(GtkTreeModel* model, GtkTreeIter* a, | |
| 131 GtkTreeIter* b, gpointer task_manager) { | |
| 132 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 133 CompareImpl(model, a, b, | |
| 134 IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN); | |
| 135 } | |
| 136 | |
| 137 // CPU sorting callback. | |
| 138 static gint CompareCPU(GtkTreeModel* model, GtkTreeIter* a, | |
| 139 GtkTreeIter* b, gpointer task_manager) { | |
| 140 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 141 CompareImpl(model, a, b, IDS_TASK_MANAGER_CPU_COLUMN); | |
| 142 } | |
| 143 | |
| 144 // Network sorting callback. | |
| 145 static gint CompareNetwork(GtkTreeModel* model, GtkTreeIter* a, | |
| 146 GtkTreeIter* b, gpointer task_manager) { | |
| 147 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 148 CompareImpl(model, a, b, IDS_TASK_MANAGER_NET_COLUMN); | |
| 149 } | |
| 150 | |
| 151 // Process ID sorting callback. | |
| 152 static gint CompareProcessID(GtkTreeModel* model, GtkTreeIter* a, | |
| 153 GtkTreeIter* b, gpointer task_manager) { | |
| 154 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 155 CompareImpl(model, a, b, IDS_TASK_MANAGER_PROCESS_ID_COLUMN); | |
| 156 } | |
| 157 | |
| 158 // WebCore Image Cache sorting callback. | |
| 159 static gint CompareWebCoreImageCache(GtkTreeModel* model, GtkTreeIter* a, | |
| 160 GtkTreeIter* b, gpointer task_manager) { | |
| 161 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 162 CompareImpl(model, a, b, IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN); | |
| 163 } | |
| 164 | |
| 165 // WebCore Scripts Cache sorting callback. | |
| 166 static gint CompareWebCoreScriptsCache(GtkTreeModel* model, GtkTreeIter* a, | |
| 167 GtkTreeIter* b, | |
| 168 gpointer task_manager) { | |
| 169 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 170 CompareImpl(model, a, b, IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN); | |
| 171 } | |
| 172 | |
| 173 // WebCore CSS Cache sorting callback. | |
| 174 static gint CompareWebCoreCssCache(GtkTreeModel* model, GtkTreeIter* a, | |
| 175 GtkTreeIter* b, gpointer task_manager) { | |
| 176 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 177 CompareImpl(model, a, b, IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN); | |
| 178 } | |
| 179 | |
| 180 // Sqlite memory sorting callback. | |
| 181 static gint CompareSqliteMemoryUsed(GtkTreeModel* model, GtkTreeIter* a, | |
| 182 GtkTreeIter* b, gpointer task_manager) { | |
| 183 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 184 CompareImpl(model, a, b, IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN); | |
| 185 } | |
| 186 | |
| 187 // Goats Teleported sorting callback. | |
| 188 static gint CompareGoatsTeleported(GtkTreeModel* model, GtkTreeIter* a, | |
| 189 GtkTreeIter* b, gpointer task_manager) { | |
| 190 return reinterpret_cast<TaskManagerGtk*>(task_manager)-> | |
| 191 CompareImpl(model, a, b, IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN); | |
| 192 } | |
| 193 | |
| 194 // The task manager. | |
| 195 TaskManager* task_manager_; | |
| 196 | |
| 197 // Our model. | |
| 198 TaskManagerModel* model_; | |
| 199 | |
| 200 // The task manager dialog window. | |
| 201 GtkWidget* dialog_; | |
| 202 | |
| 203 // The treeview that contains the process list. | |
| 204 GtkWidget* treeview_; | |
| 205 | |
| 206 // The list of processes. | |
| 207 GtkListStore* process_list_; | |
| 208 GtkTreeModel* process_list_sort_; | |
| 209 | |
| 210 // The number of processes in |process_list_|. | |
| 211 int process_count_; | |
| 212 | |
| 213 // The id of the |dialog_| destroy signal handler. | |
| 214 gulong destroy_handler_id_; | |
| 215 | |
| 216 // The context menu controller. | |
| 217 scoped_ptr<ContextMenuController> menu_controller_; | |
| 218 | |
| 219 GtkAccelGroup* accel_group_; | |
| 220 | |
| 221 // An open task manager window. There can only be one open at a time. This | |
| 222 // is reset to NULL when the window is closed. | |
| 223 static TaskManagerGtk* instance_; | |
| 224 | |
| 225 // We edit the selection in the OnSelectionChanged handler, and we use this | |
| 226 // variable to prevent ourselves from handling further changes that we | |
| 227 // ourselves caused. | |
| 228 bool ignore_selection_changed_; | |
| 229 | |
| 230 DISALLOW_COPY_AND_ASSIGN(TaskManagerGtk); | |
| 231 }; | |
| 232 | 11 |
| 233 #endif // CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_ | 12 #endif // CHROME_BROWSER_GTK_TASK_MANAGER_GTK_H_ |
| OLD | NEW |