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

Side by Side Diff: chrome/browser/views/task_manager_view.cc

Issue 140044: Reorganize the way the task manager is constructed.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/frame/browser_view.cc ('k') | chrome/chrome.gyp » ('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/task_manager.h" 5 #include "chrome/browser/task_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/table_model_observer.h" 8 #include "app/table_model_observer.h"
9 #include "base/stats_table.h" 9 #include "base/stats_table.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
11 #include "chrome/browser/browser_list.h" 11 #include "chrome/browser/browser_list.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/browser_window.h" 13 #include "chrome/browser/browser_window.h"
14 #include "chrome/browser/views/browser_dialogs.h"
14 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
15 #include "chrome/common/pref_service.h" 16 #include "chrome/common/pref_service.h"
16 #include "grit/chromium_strings.h" 17 #include "grit/chromium_strings.h"
17 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
19 #include "views/accelerator.h" 20 #include "views/accelerator.h"
20 #include "views/background.h" 21 #include "views/background.h"
21 #include "views/controls/button/native_button.h" 22 #include "views/controls/button/native_button.h"
22 #include "views/controls/link.h" 23 #include "views/controls/link.h"
23 #include "views/controls/menu/menu.h" 24 #include "views/controls/menu/menu.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 void TaskManagerTableModel::OnItemsAdded(int start, int length) { 152 void TaskManagerTableModel::OnItemsAdded(int start, int length) {
152 if (observer_) 153 if (observer_)
153 observer_->OnItemsAdded(start, length); 154 observer_->OnItemsAdded(start, length);
154 } 155 }
155 156
156 void TaskManagerTableModel::OnItemsRemoved(int start, int length) { 157 void TaskManagerTableModel::OnItemsRemoved(int start, int length) {
157 if (observer_) 158 if (observer_)
158 observer_->OnItemsRemoved(start, length); 159 observer_->OnItemsRemoved(start, length);
159 } 160 }
160 161
161 //////////////////////////////////////////////////////////////////////////////// 162 // The Task manager UI container.
162 // TaskManagerViewImpl class 163 class TaskManagerView : public views::View,
163 // 164 public views::ButtonListener,
164 // The view containing the different widgets. 165 public views::DialogDelegate,
165 // 166 public views::TableViewObserver,
166 //////////////////////////////////////////////////////////////////////////////// 167 public views::LinkController,
168 public views::ContextMenuController,
169 public views::Menu::Delegate {
170 public:
171 TaskManagerView();
172 virtual ~TaskManagerView();
167 173
168 class TaskManagerViewImpl : public TaskManagerView, 174 // Shows the Task manager window, or re-activates an existing one.
169 public views::View, 175 static void Show();
170 public views::ButtonListener,
171 public views::DialogDelegate,
172 public views::TableViewObserver,
173 public views::LinkController,
174 public views::ContextMenuController,
175 public views::Menu::Delegate {
176 public:
177 TaskManagerViewImpl(TaskManager* task_manager,
178 TaskManagerModel* model);
179 virtual ~TaskManagerViewImpl();
180 176
181 void Init(); 177 // views::View
182 virtual void Layout(); 178 virtual void Layout();
183 virtual gfx::Size GetPreferredSize(); 179 virtual gfx::Size GetPreferredSize();
184 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, 180 virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
185 views::View* child); 181 views::View* child);
186 182
187 // TaskManagerView
188 virtual void GetSelection(std::vector<int>* selection);
189 virtual void GetFocused(std::vector<int>* focused);
190 virtual void OpenWindow();
191 virtual void ActivateWindow();
192 virtual void CloseWindow();
193
194 // ButtonListener implementation. 183 // ButtonListener implementation.
195 virtual void ButtonPressed(views::Button* sender); 184 virtual void ButtonPressed(views::Button* sender);
196 185
197 // views::DialogDelegate 186 // views::DialogDelegate
198 virtual bool CanResize() const; 187 virtual bool CanResize() const;
199 virtual bool CanMaximize() const; 188 virtual bool CanMaximize() const;
200 virtual bool ExecuteWindowsCommand(int command_id); 189 virtual bool ExecuteWindowsCommand(int command_id);
201 virtual std::wstring GetWindowTitle() const; 190 virtual std::wstring GetWindowTitle() const;
202 virtual std::wstring GetWindowName() const; 191 virtual std::wstring GetWindowName() const;
203 virtual int GetDialogButtons() const; 192 virtual int GetDialogButtons() const;
(...skipping 15 matching lines...) Expand all
219 208
220 // Menu::Delegate 209 // Menu::Delegate
221 virtual void ShowContextMenu(views::View* source, 210 virtual void ShowContextMenu(views::View* source,
222 int x, 211 int x,
223 int y, 212 int y,
224 bool is_mouse_gesture); 213 bool is_mouse_gesture);
225 virtual bool IsItemChecked(int id) const; 214 virtual bool IsItemChecked(int id) const;
226 virtual void ExecuteCommand(int id); 215 virtual void ExecuteCommand(int id);
227 216
228 private: 217 private:
218 // Creates the child controls.
219 void Init();
220
229 // Initializes the state of the always-on-top setting as the window is shown. 221 // Initializes the state of the always-on-top setting as the window is shown.
230 void InitAlwaysOnTopState(); 222 void InitAlwaysOnTopState();
231 223
224 // Activates the tab associated with the focused row.
225 void ActivateFocusedTab();
226
232 // Adds an always on top item to the window's system menu. 227 // Adds an always on top item to the window's system menu.
233 void AddAlwaysOnTopSystemMenuItem(); 228 void AddAlwaysOnTopSystemMenuItem();
234 229
235 // Restores saved always on top state from a previous session. 230 // Restores saved always on top state from a previous session.
236 bool GetSavedAlwaysOnTopState(bool* always_on_top) const; 231 bool GetSavedAlwaysOnTopState(bool* always_on_top) const;
237 232
238 views::NativeButton* kill_button_; 233 views::NativeButton* kill_button_;
239 views::Link* about_memory_link_; 234 views::Link* about_memory_link_;
240 views::GroupTableView* tab_table_; 235 views::GroupTableView* tab_table_;
241 236
242 TaskManager* task_manager_; 237 TaskManager* task_manager_;
243 238
244 TaskManagerModel* model_; 239 TaskManagerModel* model_;
245 240
246 // all possible columns, not necessarily visible 241 // all possible columns, not necessarily visible
247 std::vector<TableColumn> columns_; 242 std::vector<TableColumn> columns_;
248 243
249 scoped_ptr<TaskManagerTableModel> table_model_; 244 scoped_ptr<TaskManagerTableModel> table_model_;
250 245
251 // True when the Task Manager window should be shown on top of other windows. 246 // True when the Task Manager window should be shown on top of other windows.
252 bool is_always_on_top_; 247 bool is_always_on_top_;
253 248
254 // We need to own the text of the menu, the Windows API does not copy it. 249 // We need to own the text of the menu, the Windows API does not copy it.
255 std::wstring always_on_top_menu_text_; 250 std::wstring always_on_top_menu_text_;
256 251
257 DISALLOW_COPY_AND_ASSIGN(TaskManagerViewImpl); 252 // An open Task manager window. There can only be one open at a time. This
253 // is reset to NULL when the window is closed.
254 static TaskManagerView* instance_;
255
256 DISALLOW_COPY_AND_ASSIGN(TaskManagerView);
258 }; 257 };
259 258
260 TaskManagerViewImpl::TaskManagerViewImpl(TaskManager* task_manager, 259 // static
261 TaskManagerModel* model) 260 TaskManagerView* TaskManagerView::instance_ = NULL;
262 : task_manager_(task_manager), 261
263 model_(model), 262
263 TaskManagerView::TaskManagerView()
264 : task_manager_(TaskManager::GetInstance()),
265 model_(TaskManager::GetInstance()->model()),
264 is_always_on_top_(false) { 266 is_always_on_top_(false) {
265 Init(); 267 Init();
266 } 268 }
267 269
268 TaskManagerViewImpl::~TaskManagerViewImpl() { 270 TaskManagerView::~TaskManagerView() {
269 // Delete child views now, while our table model still exists. 271 // Delete child views now, while our table model still exists.
270 RemoveAllChildViews(true); 272 RemoveAllChildViews(true);
271 273
272 // Prevent the table from accessing the model as part of its destruction, as 274 // Prevent the table from accessing the model as part of its destruction, as
273 // the model might already be destroyed. 275 // the model might already be destroyed.
274 tab_table_->SetModel(NULL); 276 tab_table_->SetModel(NULL);
275 } 277 }
276 278
277 void TaskManagerViewImpl::Init() { 279 void TaskManagerView::Init() {
278 table_model_.reset(new TaskManagerTableModel(model_)); 280 table_model_.reset(new TaskManagerTableModel(model_));
279 281
280 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN, 282 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN,
281 TableColumn::LEFT, -1, 1)); 283 TableColumn::LEFT, -1, 1));
282 columns_.back().sortable = true; 284 columns_.back().sortable = true;
283 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, 285 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN,
284 TableColumn::RIGHT, -1, 0)); 286 TableColumn::RIGHT, -1, 0));
285 columns_.back().sortable = true; 287 columns_.back().sortable = true;
286 columns_.push_back(TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, 288 columns_.push_back(TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN,
287 TableColumn::RIGHT, -1, 0)); 289 TableColumn::RIGHT, -1, 0));
288 columns_.back().sortable = true; 290 columns_.back().sortable = true;
289 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, 291 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN,
290 TableColumn::RIGHT, -1, 0)); 292 TableColumn::RIGHT, -1, 0));
291 columns_.back().sortable = true; 293 columns_.back().sortable = true;
292 columns_.push_back(TableColumn(IDS_TASK_MANAGER_CPU_COLUMN, 294 columns_.push_back(TableColumn(IDS_TASK_MANAGER_CPU_COLUMN,
293 TableColumn::RIGHT, -1, 0)); 295 TableColumn::RIGHT, -1, 0));
294 columns_.back().sortable = true; 296 columns_.back().sortable = true;
295 columns_.push_back(TableColumn(IDS_TASK_MANAGER_NET_COLUMN, 297 columns_.push_back(TableColumn(IDS_TASK_MANAGER_NET_COLUMN,
296 TableColumn::RIGHT, -1, 0)); 298 TableColumn::RIGHT, -1, 0));
297 columns_.back().sortable = true; 299 columns_.back().sortable = true;
298 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, 300 columns_.push_back(TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN,
299 TableColumn::RIGHT, -1, 0)); 301 TableColumn::RIGHT, -1, 0));
300 columns_.back().sortable = true; 302 columns_.back().sortable = true;
301 303
302 tab_table_ = new views::GroupTableView(table_model_.get(), columns_, 304 tab_table_ = new views::GroupTableView(table_model_.get(), columns_,
303 views::ICON_AND_TEXT, false, true, 305 views::ICON_AND_TEXT, false, true,
304 true); 306 true);
305 tab_table_->SetParentOwned(false);
306 307
307 // Hide some columns by default 308 // Hide some columns by default
308 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, false); 309 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROCESS_ID_COLUMN, false);
309 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false); 310 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false);
310 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false); 311 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false);
311 312
312 UpdateStatsCounters(); 313 UpdateStatsCounters();
313 TableColumn col(kGoatsTeleportedColumn, L"Goats Teleported", 314 TableColumn col(kGoatsTeleportedColumn, L"Goats Teleported",
314 TableColumn::RIGHT, -1, 0); 315 TableColumn::RIGHT, -1, 0);
315 col.sortable = true; 316 col.sortable = true;
316 columns_.push_back(col); 317 columns_.push_back(col);
317 tab_table_->AddColumn(col); 318 tab_table_->AddColumn(col);
318 tab_table_->SetObserver(this); 319 tab_table_->SetObserver(this);
319 SetContextMenuController(this); 320 SetContextMenuController(this);
320 kill_button_ = new views::NativeButton( 321 kill_button_ = new views::NativeButton(
321 this, l10n_util::GetString(IDS_TASK_MANAGER_KILL)); 322 this, l10n_util::GetString(IDS_TASK_MANAGER_KILL));
322 kill_button_->AddAccelerator(views::Accelerator('E', false, false, false)); 323 kill_button_->AddAccelerator(views::Accelerator('E', false, false, false));
323 kill_button_->SetAccessibleKeyboardShortcut(L"E"); 324 kill_button_->SetAccessibleKeyboardShortcut(L"E");
324 about_memory_link_ = new views::Link( 325 about_memory_link_ = new views::Link(
325 l10n_util::GetString(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK)); 326 l10n_util::GetString(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
326 about_memory_link_->SetController(this); 327 about_memory_link_->SetController(this);
327 328
328 // Makes sure our state is consistent. 329 // Makes sure our state is consistent.
329 OnSelectionChanged(); 330 OnSelectionChanged();
330 } 331 }
331 332
332 void TaskManagerViewImpl::UpdateStatsCounters() { 333 void TaskManagerView::UpdateStatsCounters() {
333 StatsTable* stats = StatsTable::current(); 334 StatsTable* stats = StatsTable::current();
334 if (stats != NULL) { 335 if (stats != NULL) {
335 int max = stats->GetMaxCounters(); 336 int max = stats->GetMaxCounters();
336 // skip the first row (it's header data) 337 // skip the first row (it's header data)
337 for (int i = 1; i < max; i++) { 338 for (int i = 1; i < max; i++) {
338 const char* row = stats->GetRowName(i); 339 const char* row = stats->GetRowName(i);
339 if (row != NULL && row[0] != '\0' && !tab_table_->HasColumn(i)) { 340 if (row != NULL && row[0] != '\0' && !tab_table_->HasColumn(i)) {
340 // TODO(erikkay): Use l10n to get display names for stats. Right 341 // TODO(erikkay): Use l10n to get display names for stats. Right
341 // now we're just displaying the internal counter name. Perhaps 342 // now we're just displaying the internal counter name. Perhaps
342 // stat names not in the string table would be filtered out. 343 // stat names not in the string table would be filtered out.
343 // TODO(erikkay): Width is hard-coded right now, so many column 344 // TODO(erikkay): Width is hard-coded right now, so many column
344 // names are clipped. 345 // names are clipped.
345 TableColumn col(i, ASCIIToWide(row), TableColumn::RIGHT, 90, 0); 346 TableColumn col(i, ASCIIToWide(row), TableColumn::RIGHT, 90, 0);
346 col.sortable = true; 347 col.sortable = true;
347 columns_.push_back(col); 348 columns_.push_back(col);
348 tab_table_->AddColumn(col); 349 tab_table_->AddColumn(col);
349 } 350 }
350 } 351 }
351 } 352 }
352 } 353 }
353 354
354 void TaskManagerViewImpl::ViewHierarchyChanged(bool is_add, 355 void TaskManagerView::ViewHierarchyChanged(bool is_add,
355 views::View* parent, 356 views::View* parent,
356 views::View* child) { 357 views::View* child) {
357 // Since we want the Kill button and the Memory Details link to show up in 358 // Since we want the Kill button and the Memory Details link to show up in
358 // the same visual row as the close button, which is provided by the 359 // the same visual row as the close button, which is provided by the
359 // framework, we must add the buttons to the non-client view, which is the 360 // framework, we must add the buttons to the non-client view, which is the
360 // parent of this view. Similarly, when we're removed from the view 361 // parent of this view. Similarly, when we're removed from the view
361 // hierarchy, we must take care to clean up those items as well. 362 // hierarchy, we must take care to clean up those items as well.
362 if (child == this) { 363 if (child == this) {
363 if (is_add) { 364 if (is_add) {
364 parent->AddChildView(kill_button_); 365 parent->AddChildView(kill_button_);
365 parent->AddChildView(about_memory_link_); 366 parent->AddChildView(about_memory_link_);
366 AddChildView(tab_table_); 367 AddChildView(tab_table_);
367 } else { 368 } else {
368 parent->RemoveChildView(kill_button_); 369 parent->RemoveChildView(kill_button_);
369 parent->RemoveChildView(about_memory_link_); 370 parent->RemoveChildView(about_memory_link_);
370 } 371 }
371 } 372 }
372 } 373 }
373 374
374 void TaskManagerViewImpl::Layout() { 375 void TaskManagerView::Layout() {
375 // kPanelHorizMargin is too big. 376 // kPanelHorizMargin is too big.
376 const int kTableButtonSpacing = 12; 377 const int kTableButtonSpacing = 12;
377 378
378 gfx::Size size = kill_button_->GetPreferredSize(); 379 gfx::Size size = kill_button_->GetPreferredSize();
379 int prefered_width = size.width(); 380 int prefered_width = size.width();
380 int prefered_height = size.height(); 381 int prefered_height = size.height();
381 382
382 tab_table_->SetBounds(x() + kPanelHorizMargin, 383 tab_table_->SetBounds(x() + kPanelHorizMargin,
383 y() + kPanelVertMargin, 384 y() + kPanelVertMargin,
384 width() - 2 * kPanelHorizMargin, 385 width() - 2 * kPanelHorizMargin,
(...skipping 14 matching lines...) Expand all
399 // center between the two buttons horizontally, and line up with 400 // center between the two buttons horizontally, and line up with
400 // bottom of buttons vertically. 401 // bottom of buttons vertically.
401 int link_y_offset = std::max(0, prefered_height - link_prefered_height) / 2; 402 int link_y_offset = std::max(0, prefered_height - link_prefered_height) / 2;
402 about_memory_link_->SetBounds( 403 about_memory_link_->SetBounds(
403 x() + kPanelHorizMargin, 404 x() + kPanelHorizMargin,
404 y_buttons + prefered_height - link_prefered_height - link_y_offset, 405 y_buttons + prefered_height - link_prefered_height - link_y_offset,
405 link_prefered_width, 406 link_prefered_width,
406 link_prefered_height); 407 link_prefered_height);
407 } 408 }
408 409
409 gfx::Size TaskManagerViewImpl::GetPreferredSize() { 410 gfx::Size TaskManagerView::GetPreferredSize() {
410 return gfx::Size(kDefaultWidth, kDefaultHeight); 411 return gfx::Size(kDefaultWidth, kDefaultHeight);
411 } 412 }
412 413
413 void TaskManagerViewImpl::GetSelection(std::vector<int>* selection) { 414 // static
414 DCHECK(selection); 415 void TaskManagerView::Show() {
415 for (views::TableSelectionIterator iter = tab_table_->SelectionBegin(); 416 if (instance_) {
416 iter != tab_table_->SelectionEnd(); ++iter) { 417 // If there's a Task manager window open already, just activate it.
417 // The TableView returns the selection starting from the end. 418 instance_->window()->Activate();
418 selection->insert(selection->begin(), *iter); 419 } else {
420 instance_ = new TaskManagerView;
421 views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_);
422 instance_->InitAlwaysOnTopState();
423 instance_->model_->StartUpdating();
424 instance_->window()->Show();
419 } 425 }
420 } 426 }
421 427
422 void TaskManagerViewImpl::GetFocused(std::vector<int>* focused) { 428 // ButtonListener implementation.
423 DCHECK(focused); 429 void TaskManagerView::ButtonPressed(views::Button* sender) {
424 int row_count = tab_table_->RowCount(); 430 DCHECK(sender == kill_button_);
425 for (int i = 0; i < row_count; ++i) { 431 for (views::TableSelectionIterator iter = tab_table_->SelectionBegin();
426 // The TableView returns the selection starting from the end. 432 iter != tab_table_->SelectionEnd(); ++iter) {
427 if (tab_table_->ItemHasTheFocus(i)) 433 task_manager_->KillProcess(*iter);
428 focused->insert(focused->begin(), i);
429 } 434 }
430 } 435 }
431 436
432 void TaskManagerViewImpl::OpenWindow() {
433 DCHECK(!window());
434 views::Window::CreateChromeWindow(NULL, gfx::Rect(), this);
435 InitAlwaysOnTopState();
436 model_->StartUpdating();
437 window()->Show();
438 }
439
440 void TaskManagerViewImpl::ActivateWindow() {
441 DCHECK(window());
442 window()->Activate();
443 }
444
445 void TaskManagerViewImpl::CloseWindow() {
446 if (!window())
447 return;
448 // TODO(phajdan.jr): Destroy the window, not just hide it.
449 window()->HideWindow();
450 }
451
452 // ButtonListener implementation.
453 void TaskManagerViewImpl::ButtonPressed(views::Button* sender) {
454 if (sender == kill_button_)
455 task_manager_->KillSelectedProcesses();
456 }
457
458 // DialogDelegate implementation. 437 // DialogDelegate implementation.
459 bool TaskManagerViewImpl::CanResize() const { 438 bool TaskManagerView::CanResize() const {
460 return true; 439 return true;
461 } 440 }
462 441
463 bool TaskManagerViewImpl::CanMaximize() const { 442 bool TaskManagerView::CanMaximize() const {
464 return true; 443 return true;
465 } 444 }
466 445
467 bool TaskManagerViewImpl::ExecuteWindowsCommand(int command_id) { 446 bool TaskManagerView::ExecuteWindowsCommand(int command_id) {
468 if (command_id == IDC_ALWAYS_ON_TOP) { 447 if (command_id == IDC_ALWAYS_ON_TOP) {
469 is_always_on_top_ = !is_always_on_top_; 448 is_always_on_top_ = !is_always_on_top_;
470 449
471 // Change the menu check state. 450 // Change the menu check state.
472 HMENU system_menu = GetSystemMenu(GetWindow()->GetNativeWindow(), FALSE); 451 HMENU system_menu = GetSystemMenu(GetWindow()->GetNativeWindow(), FALSE);
473 MENUITEMINFO menu_info; 452 MENUITEMINFO menu_info;
474 memset(&menu_info, 0, sizeof(MENUITEMINFO)); 453 memset(&menu_info, 0, sizeof(MENUITEMINFO));
475 menu_info.cbSize = sizeof(MENUITEMINFO); 454 menu_info.cbSize = sizeof(MENUITEMINFO);
476 BOOL r = GetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP, 455 BOOL r = GetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP,
477 FALSE, &menu_info); 456 FALSE, &menu_info);
(...skipping 11 matching lines...) Expand all
489 DictionaryValue* window_preferences = 468 DictionaryValue* window_preferences =
490 g_browser_process->local_state()->GetMutableDictionary( 469 g_browser_process->local_state()->GetMutableDictionary(
491 GetWindowName().c_str()); 470 GetWindowName().c_str());
492 window_preferences->SetBoolean(L"always_on_top", is_always_on_top_); 471 window_preferences->SetBoolean(L"always_on_top", is_always_on_top_);
493 } 472 }
494 return true; 473 return true;
495 } 474 }
496 return false; 475 return false;
497 } 476 }
498 477
499 std::wstring TaskManagerViewImpl::GetWindowTitle() const { 478 std::wstring TaskManagerView::GetWindowTitle() const {
500 return l10n_util::GetString(IDS_TASK_MANAGER_TITLE); 479 return l10n_util::GetString(IDS_TASK_MANAGER_TITLE);
501 } 480 }
502 481
503 std::wstring TaskManagerViewImpl::GetWindowName() const { 482 std::wstring TaskManagerView::GetWindowName() const {
504 return prefs::kTaskManagerWindowPlacement; 483 return prefs::kTaskManagerWindowPlacement;
505 } 484 }
506 485
507 int TaskManagerViewImpl::GetDialogButtons() const { 486 int TaskManagerView::GetDialogButtons() const {
508 return MessageBoxFlags::DIALOGBUTTON_NONE; 487 return MessageBoxFlags::DIALOGBUTTON_NONE;
509 } 488 }
510 489
511 void TaskManagerViewImpl::WindowClosing() { 490 void TaskManagerView::WindowClosing() {
491 // Now that the window is closed, we can allow a new one to be opened.
492 instance_ = NULL;
512 task_manager_->OnWindowClosed(); 493 task_manager_->OnWindowClosed();
513 } 494 }
514 495
515 void TaskManagerViewImpl::DeleteDelegate() { 496 void TaskManagerView::DeleteDelegate() {
516 ReleaseWindow(); 497 ReleaseWindow();
517 } 498 }
518 499
519 views::View* TaskManagerViewImpl::GetContentsView() { 500 views::View* TaskManagerView::GetContentsView() {
520 return this; 501 return this;
521 } 502 }
522 503
523 // views::TableViewObserver implementation. 504 // views::TableViewObserver implementation.
524 void TaskManagerViewImpl::OnSelectionChanged() { 505 void TaskManagerView::OnSelectionChanged() {
525 kill_button_->SetEnabled(!task_manager_->BrowserProcessIsSelected() && 506 bool selection_contains_browser_process = false;
507 for (views::TableSelectionIterator iter = tab_table_->SelectionBegin();
508 iter != tab_table_->SelectionEnd(); ++iter) {
509 if (task_manager_->IsBrowserProcess(*iter)) {
510 selection_contains_browser_process = true;
511 break;
512 }
513 }
514 kill_button_->SetEnabled(!selection_contains_browser_process &&
526 tab_table_->SelectedRowCount() > 0); 515 tab_table_->SelectedRowCount() > 0);
527 } 516 }
528 517
529 void TaskManagerViewImpl::OnDoubleClick() { 518 void TaskManagerView::OnDoubleClick() {
530 task_manager_->ActivateFocusedTab(); 519 ActivateFocusedTab();
531 } 520 }
532 521
533 void TaskManagerViewImpl::OnKeyDown(unsigned short virtual_keycode) { 522 void TaskManagerView::OnKeyDown(unsigned short virtual_keycode) {
534 if (virtual_keycode == VK_RETURN) 523 if (virtual_keycode == VK_RETURN)
535 task_manager_->ActivateFocusedTab(); 524 ActivateFocusedTab();
536 } 525 }
537 526
538 // views::LinkController implementation 527 // views::LinkController implementation
539 void TaskManagerViewImpl::LinkActivated(views::Link* source, 528 void TaskManagerView::LinkActivated(views::Link* source, int event_flags) {
540 int event_flags) {
541 DCHECK(source == about_memory_link_); 529 DCHECK(source == about_memory_link_);
542 Browser* browser = BrowserList::GetLastActive(); 530 Browser* browser = BrowserList::GetLastActive();
543 DCHECK(browser); 531 DCHECK(browser);
544 browser->OpenURL(GURL("about:memory"), GURL(), NEW_FOREGROUND_TAB, 532 browser->OpenURL(GURL("about:memory"), GURL(), NEW_FOREGROUND_TAB,
545 PageTransition::LINK); 533 PageTransition::LINK);
546 // In case the browser window is minimzed, show it. If this is an application 534 // In case the browser window is minimzed, show it. If this is an application
547 // or popup, we can only have one tab, hence we need to process this in a 535 // or popup, we can only have one tab, hence we need to process this in a
548 // tabbed browser window. Currently, |browser| is pointing to the application, 536 // tabbed browser window. Currently, |browser| is pointing to the application,
549 // popup window. Therefore, we have to retrieve the last active tab again, 537 // popup window. Therefore, we have to retrieve the last active tab again,
550 // since a new window has been used. 538 // since a new window has been used.
551 if (browser->type() & Browser::TYPE_APP_POPUP) { 539 if (browser->type() & Browser::TYPE_APP_POPUP) {
552 browser = BrowserList::GetLastActive(); 540 browser = BrowserList::GetLastActive();
553 DCHECK(browser); 541 DCHECK(browser);
554 } 542 }
555 browser->window()->Show(); 543 browser->window()->Show();
556 } 544 }
557 545
558 void TaskManagerViewImpl::ShowContextMenu(views::View* source, 546 void TaskManagerView::ShowContextMenu(views::View* source, int x, int y,
559 int x, 547 bool is_mouse_gesture) {
560 int y,
561 bool is_mouse_gesture) {
562 UpdateStatsCounters(); 548 UpdateStatsCounters();
563 scoped_ptr<views::Menu> menu(views::Menu::Create( 549 scoped_ptr<views::Menu> menu(views::Menu::Create(
564 this, views::Menu::TOPLEFT, source->GetWidget()->GetNativeView())); 550 this, views::Menu::TOPLEFT, source->GetWidget()->GetNativeView()));
565 for (std::vector<TableColumn>::iterator i = 551 for (std::vector<TableColumn>::iterator i =
566 columns_.begin(); i != columns_.end(); ++i) { 552 columns_.begin(); i != columns_.end(); ++i) {
567 menu->AppendMenuItem(i->id, i->title, views::Menu::CHECKBOX); 553 menu->AppendMenuItem(i->id, i->title, views::Menu::CHECKBOX);
568 } 554 }
569 menu->RunMenuAt(x, y); 555 menu->RunMenuAt(x, y);
570 } 556 }
571 557
572 bool TaskManagerViewImpl::IsItemChecked(int id) const { 558 bool TaskManagerView::IsItemChecked(int id) const {
573 return tab_table_->IsColumnVisible(id); 559 return tab_table_->IsColumnVisible(id);
574 } 560 }
575 561
576 void TaskManagerViewImpl::ExecuteCommand(int id) { 562 void TaskManagerView::ExecuteCommand(int id) {
577 tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id)); 563 tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id));
578 } 564 }
579 565
580 void TaskManagerViewImpl::InitAlwaysOnTopState() { 566 void TaskManagerView::InitAlwaysOnTopState() {
581 is_always_on_top_ = false; 567 is_always_on_top_ = false;
582 if (GetSavedAlwaysOnTopState(&is_always_on_top_)) 568 if (GetSavedAlwaysOnTopState(&is_always_on_top_))
583 window()->SetIsAlwaysOnTop(is_always_on_top_); 569 window()->SetIsAlwaysOnTop(is_always_on_top_);
584 AddAlwaysOnTopSystemMenuItem(); 570 AddAlwaysOnTopSystemMenuItem();
585 } 571 }
586 572
587 void TaskManagerViewImpl::AddAlwaysOnTopSystemMenuItem() { 573 void TaskManagerView::ActivateFocusedTab() {
574 int row_count = tab_table_->RowCount();
575 for (int i = 0; i < row_count; ++i) {
576 if (tab_table_->ItemHasTheFocus(i)) {
577 task_manager_->ActivateProcess(i);
578 break;
579 }
580 }
581 }
582
583 void TaskManagerView::AddAlwaysOnTopSystemMenuItem() {
588 // The Win32 API requires that we own the text. 584 // The Win32 API requires that we own the text.
589 always_on_top_menu_text_ = l10n_util::GetString(IDS_ALWAYS_ON_TOP); 585 always_on_top_menu_text_ = l10n_util::GetString(IDS_ALWAYS_ON_TOP);
590 586
591 // Let's insert a menu to the window. 587 // Let's insert a menu to the window.
592 HMENU system_menu = ::GetSystemMenu(GetWindow()->GetNativeWindow(), FALSE); 588 HMENU system_menu = ::GetSystemMenu(GetWindow()->GetNativeWindow(), FALSE);
593 int index = ::GetMenuItemCount(system_menu) - 1; 589 int index = ::GetMenuItemCount(system_menu) - 1;
594 if (index < 0) { 590 if (index < 0) {
595 // Paranoia check. 591 // Paranoia check.
596 NOTREACHED(); 592 NOTREACHED();
597 index = 0; 593 index = 0;
(...skipping 10 matching lines...) Expand all
608 menu_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE; 604 menu_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE;
609 menu_info.fType = MFT_STRING; 605 menu_info.fType = MFT_STRING;
610 menu_info.fState = MFS_ENABLED; 606 menu_info.fState = MFS_ENABLED;
611 if (is_always_on_top_) 607 if (is_always_on_top_)
612 menu_info.fState |= MFS_CHECKED; 608 menu_info.fState |= MFS_CHECKED;
613 menu_info.wID = IDC_ALWAYS_ON_TOP; 609 menu_info.wID = IDC_ALWAYS_ON_TOP;
614 menu_info.dwTypeData = const_cast<wchar_t*>(always_on_top_menu_text_.c_str()); 610 menu_info.dwTypeData = const_cast<wchar_t*>(always_on_top_menu_text_.c_str());
615 ::InsertMenuItem(system_menu, index, TRUE, &menu_info); 611 ::InsertMenuItem(system_menu, index, TRUE, &menu_info);
616 } 612 }
617 613
618 bool TaskManagerViewImpl::GetSavedAlwaysOnTopState(bool* always_on_top) const { 614 bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top) const {
619 if (!g_browser_process->local_state()) 615 if (!g_browser_process->local_state())
620 return false; 616 return false;
621 617
622 const DictionaryValue* dictionary = 618 const DictionaryValue* dictionary =
623 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str()); 619 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str());
624 return dictionary && 620 return dictionary &&
625 dictionary->GetBoolean(L"always_on_top", always_on_top) && always_on_top; 621 dictionary->GetBoolean(L"always_on_top", always_on_top) && always_on_top;
626 } 622 }
627 623
628 } // namespace 624 } // namespace
629 625
630 void TaskManager::CreateView() { 626 namespace browser {
631 DCHECK(!view_); 627
632 view_ = new TaskManagerViewImpl(this, model_.get()); 628 // Declared in browser_dialogs.h so others don't need to depend on our header.
629 void ShowTaskManager() {
630 TaskManagerView::Show();
633 } 631 }
632
633 } // namespace browser
634
OLDNEW
« no previous file with comments | « chrome/browser/views/frame/browser_view.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698