Task Manager: Remove goat teleporter.
[chromium-blink-merge.git] / chrome / browser / ui / views / task_manager_view.cc
blob3983d5e6f72a7f9dc954e1f42c0cb06ad2d0c651
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/task_manager/task_manager.h"
7 #include "base/compiler_specific.h"
8 #include "base/metrics/stats_table.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/app/chrome_command_ids.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/host_desktop.h"
18 #include "chrome/browser/ui/views/browser_dialogs.h"
19 #include "chrome/common/pref_names.h"
20 #include "chrome/grit/chromium_strings.h"
21 #include "chrome/grit/generated_resources.h"
22 #include "ui/base/accelerators/accelerator.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/models/simple_menu_model.h"
25 #include "ui/base/models/table_model.h"
26 #include "ui/base/models/table_model_observer.h"
27 #include "ui/events/event_constants.h"
28 #include "ui/events/keycodes/keyboard_codes.h"
29 #include "ui/gfx/canvas.h"
30 #include "ui/views/context_menu_controller.h"
31 #include "ui/views/controls/button/label_button.h"
32 #include "ui/views/controls/link.h"
33 #include "ui/views/controls/link_listener.h"
34 #include "ui/views/controls/menu/menu_runner.h"
35 #include "ui/views/controls/table/table_grouper.h"
36 #include "ui/views/controls/table/table_view.h"
37 #include "ui/views/controls/table/table_view_observer.h"
38 #include "ui/views/layout/layout_constants.h"
39 #include "ui/views/widget/widget.h"
40 #include "ui/views/window/dialog_delegate.h"
42 #if defined(USE_ASH)
43 #include "ash/shelf/shelf_util.h"
44 #include "ash/wm/window_util.h"
45 #include "grit/ash_resources.h"
46 #endif
48 #if defined(OS_WIN)
49 #include "chrome/browser/shell_integration.h"
50 #include "ui/base/win/shell.h"
51 #include "ui/views/win/hwnd_util.h"
52 #endif
54 namespace {
56 ////////////////////////////////////////////////////////////////////////////////
57 // TaskManagerTableModel class
58 ////////////////////////////////////////////////////////////////////////////////
60 class TaskManagerTableModel
61 : public ui::TableModel,
62 public views::TableGrouper,
63 public TaskManagerModelObserver {
64 public:
65 explicit TaskManagerTableModel(TaskManagerModel* model)
66 : model_(model),
67 observer_(NULL) {
68 model_->AddObserver(this);
71 virtual ~TaskManagerTableModel() {
72 model_->RemoveObserver(this);
75 // TableModel overrides:
76 virtual int RowCount() OVERRIDE;
77 virtual base::string16 GetText(int row, int column) OVERRIDE;
78 virtual gfx::ImageSkia GetIcon(int row) OVERRIDE;
79 virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
80 virtual int CompareValues(int row1, int row2, int column_id) OVERRIDE;
82 // TableGrouper overrides:
83 virtual void GetGroupRange(int model_index,
84 views::GroupRange* range) OVERRIDE;
86 // TaskManagerModelObserver overrides:
87 virtual void OnModelChanged() OVERRIDE;
88 virtual void OnItemsChanged(int start, int length) OVERRIDE;
89 virtual void OnItemsAdded(int start, int length) OVERRIDE;
90 virtual void OnItemsRemoved(int start, int length) OVERRIDE;
92 private:
93 TaskManagerModel* model_;
94 ui::TableModelObserver* observer_;
96 DISALLOW_COPY_AND_ASSIGN(TaskManagerTableModel);
99 int TaskManagerTableModel::RowCount() {
100 return model_->ResourceCount();
103 base::string16 TaskManagerTableModel::GetText(int row, int col_id) {
104 return model_->GetResourceById(row, col_id);
107 gfx::ImageSkia TaskManagerTableModel::GetIcon(int row) {
108 return model_->GetResourceIcon(row);
111 void TaskManagerTableModel::SetObserver(ui::TableModelObserver* observer) {
112 observer_ = observer;
115 int TaskManagerTableModel::CompareValues(int row1, int row2, int column_id) {
116 return model_->CompareValues(row1, row2, column_id);
119 void TaskManagerTableModel::GetGroupRange(int model_index,
120 views::GroupRange* range) {
121 TaskManagerModel::GroupRange range_pair =
122 model_->GetGroupRangeForResource(model_index);
123 range->start = range_pair.first;
124 range->length = range_pair.second;
127 void TaskManagerTableModel::OnModelChanged() {
128 if (observer_)
129 observer_->OnModelChanged();
132 void TaskManagerTableModel::OnItemsChanged(int start, int length) {
133 if (observer_)
134 observer_->OnItemsChanged(start, length);
137 void TaskManagerTableModel::OnItemsAdded(int start, int length) {
138 if (observer_)
139 observer_->OnItemsAdded(start, length);
142 void TaskManagerTableModel::OnItemsRemoved(int start, int length) {
143 if (observer_)
144 observer_->OnItemsRemoved(start, length);
147 // The Task manager UI container.
148 class TaskManagerView : public views::ButtonListener,
149 public views::DialogDelegateView,
150 public views::TableViewObserver,
151 public views::LinkListener,
152 public views::ContextMenuController,
153 public ui::SimpleMenuModel::Delegate {
154 public:
155 explicit TaskManagerView(chrome::HostDesktopType desktop_type);
156 virtual ~TaskManagerView();
158 // Shows the Task manager window, or re-activates an existing one.
159 static void Show(Browser* browser);
161 // views::View:
162 virtual void Layout() OVERRIDE;
163 virtual gfx::Size GetPreferredSize() const OVERRIDE;
164 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
165 virtual void ViewHierarchyChanged(
166 const ViewHierarchyChangedDetails& details) OVERRIDE;
168 // views::ButtonListener:
169 virtual void ButtonPressed(views::Button* sender,
170 const ui::Event& event) OVERRIDE;
172 // views::DialogDelegateView:
173 virtual bool CanResize() const OVERRIDE;
174 virtual bool CanMaximize() const OVERRIDE;
175 virtual bool ExecuteWindowsCommand(int command_id) OVERRIDE;
176 virtual base::string16 GetWindowTitle() const OVERRIDE;
177 virtual std::string GetWindowName() const OVERRIDE;
178 virtual int GetDialogButtons() const OVERRIDE;
179 virtual void WindowClosing() OVERRIDE;
180 virtual bool UseNewStyleForThisDialog() const OVERRIDE;
182 // views::TableViewObserver:
183 virtual void OnSelectionChanged() OVERRIDE;
184 virtual void OnDoubleClick() OVERRIDE;
185 virtual void OnKeyDown(ui::KeyboardCode keycode) OVERRIDE;
187 // views::LinkListener:
188 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
190 // Called by the column picker to pick up any new stat counters that
191 // may have appeared since last time.
192 void UpdateStatsCounters();
194 // views::ContextMenuController:
195 virtual void ShowContextMenuForView(views::View* source,
196 const gfx::Point& point,
197 ui::MenuSourceType source_type) OVERRIDE;
199 // ui::SimpleMenuModel::Delegate:
200 virtual bool IsCommandIdChecked(int id) const OVERRIDE;
201 virtual bool IsCommandIdEnabled(int id) const OVERRIDE;
202 virtual bool GetAcceleratorForCommandId(
203 int command_id,
204 ui::Accelerator* accelerator) OVERRIDE;
205 virtual void ExecuteCommand(int id, int event_flags) OVERRIDE;
207 private:
208 // Creates the child controls.
209 void Init();
211 // Initializes the state of the always-on-top setting as the window is shown.
212 void InitAlwaysOnTopState();
214 // Activates the tab associated with the focused row.
215 void ActivateFocusedTab();
217 // Restores saved always on top state from a previous session.
218 bool GetSavedAlwaysOnTopState(bool* always_on_top) const;
220 views::LabelButton* kill_button_;
221 views::Link* about_memory_link_;
222 views::TableView* tab_table_;
223 views::View* tab_table_parent_;
225 TaskManager* task_manager_;
227 TaskManagerModel* model_;
229 // all possible columns, not necessarily visible
230 std::vector<ui::TableColumn> columns_;
232 scoped_ptr<TaskManagerTableModel> table_model_;
234 // True when the Task Manager window should be shown on top of other windows.
235 bool is_always_on_top_;
237 // The host desktop type this task manager belongs to.
238 const chrome::HostDesktopType desktop_type_;
240 // We need to own the text of the menu, the Windows API does not copy it.
241 base::string16 always_on_top_menu_text_;
243 // An open Task manager window. There can only be one open at a time. This
244 // is reset to NULL when the window is closed.
245 static TaskManagerView* instance_;
247 scoped_ptr<views::MenuRunner> menu_runner_;
249 DISALLOW_COPY_AND_ASSIGN(TaskManagerView);
252 // static
253 TaskManagerView* TaskManagerView::instance_ = NULL;
256 TaskManagerView::TaskManagerView(chrome::HostDesktopType desktop_type)
257 : kill_button_(NULL),
258 about_memory_link_(NULL),
259 tab_table_(NULL),
260 tab_table_parent_(NULL),
261 task_manager_(TaskManager::GetInstance()),
262 model_(TaskManager::GetInstance()->model()),
263 is_always_on_top_(false),
264 desktop_type_(desktop_type) {
265 Init();
268 TaskManagerView::~TaskManagerView() {
269 // Delete child views now, while our table model still exists.
270 RemoveAllChildViews(true);
273 void TaskManagerView::Init() {
274 table_model_.reset(new TaskManagerTableModel(model_));
276 // Page column has no header label.
277 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN,
278 ui::TableColumn::LEFT, -1, 1));
279 columns_.back().sortable = true;
280 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN,
281 ui::TableColumn::LEFT, -1, 0));
282 columns_.back().sortable = true;
283 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN,
284 ui::TableColumn::RIGHT, -1, 0));
285 columns_.back().sortable = true;
286 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN,
287 ui::TableColumn::RIGHT, -1, 0));
288 columns_.back().sortable = true;
289 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN,
290 ui::TableColumn::RIGHT, -1, 0));
291 columns_.back().sortable = true;
292 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_CPU_COLUMN,
293 ui::TableColumn::RIGHT, -1, 0));
294 columns_.back().sortable = true;
295 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_NET_COLUMN,
296 ui::TableColumn::RIGHT, -1, 0));
297 columns_.back().sortable = true;
298 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN,
299 ui::TableColumn::RIGHT, -1, 0));
300 columns_.back().sortable = true;
301 #if defined(OS_WIN)
302 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN,
303 ui::TableColumn::RIGHT, -1, 0));
304 columns_.back().sortable = true;
305 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_USER_HANDLES_COLUMN,
306 ui::TableColumn::RIGHT, -1, 0));
307 columns_.back().sortable = true;
308 #endif
309 columns_.push_back(ui::TableColumn(
310 IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN,
311 ui::TableColumn::RIGHT, -1, 0));
312 columns_.back().sortable = true;
313 columns_.push_back(ui::TableColumn(
314 IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN,
315 ui::TableColumn::RIGHT, -1, 0));
316 columns_.back().sortable = true;
317 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN,
318 ui::TableColumn::RIGHT, -1, 0));
319 columns_.back().sortable = true;
320 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN,
321 ui::TableColumn::RIGHT, -1, 0));
322 columns_.back().sortable = true;
323 columns_.push_back(ui::TableColumn(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN,
324 ui::TableColumn::RIGHT, -1, 0));
325 columns_.back().sortable = true;
326 columns_.push_back(ui::TableColumn(
327 IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN,
328 ui::TableColumn::RIGHT, -1, 0));
329 columns_.back().sortable = true;
330 columns_.push_back(
331 ui::TableColumn(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN,
332 ui::TableColumn::RIGHT, -1, 0));
333 columns_.back().sortable = true;
335 tab_table_ = new views::TableView(
336 table_model_.get(), columns_, views::ICON_AND_TEXT, false);
337 tab_table_->SetGrouper(table_model_.get());
339 // Hide some columns by default
340 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, false);
341 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN, false);
342 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, false);
343 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN,
344 false);
345 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN,
346 false);
347 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN,
348 false);
349 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN,
350 false);
351 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN,
352 false);
353 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN,
354 false);
355 tab_table_->SetColumnVisibility(
356 IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN, false);
357 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, false);
358 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_USER_HANDLES_COLUMN, false);
360 UpdateStatsCounters();
361 tab_table_->SetObserver(this);
362 tab_table_->set_context_menu_controller(this);
363 set_context_menu_controller(this);
364 kill_button_ = new views::LabelButton(this,
365 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
366 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
367 about_memory_link_ = new views::Link(
368 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
369 about_memory_link_->set_listener(this);
371 // Makes sure our state is consistent.
372 OnSelectionChanged();
374 ui::Accelerator ctrl_w(ui::VKEY_W, ui::EF_CONTROL_DOWN);
375 AddAccelerator(ctrl_w);
378 void TaskManagerView::UpdateStatsCounters() {
379 base::StatsTable* stats = base::StatsTable::current();
380 if (stats != NULL) {
381 int max = stats->GetMaxCounters();
382 // skip the first row (it's header data)
383 for (int i = 1; i < max; i++) {
384 const char* row = stats->GetRowName(i);
385 if (row != NULL && row[0] != '\0' && !tab_table_->HasColumn(i)) {
386 // TODO(erikkay): Use l10n to get display names for stats. Right
387 // now we're just displaying the internal counter name. Perhaps
388 // stat names not in the string table would be filtered out.
389 ui::TableColumn col;
390 col.id = i;
391 col.title = base::ASCIIToUTF16(row);
392 col.alignment = ui::TableColumn::RIGHT;
393 // TODO(erikkay): Width is hard-coded right now, so many column
394 // names are clipped.
395 col.width = 90;
396 col.sortable = true;
397 columns_.push_back(col);
398 tab_table_->AddColumn(col);
404 void TaskManagerView::ViewHierarchyChanged(
405 const ViewHierarchyChangedDetails& details) {
406 // Since we want the Kill button and the Memory Details link to show up in
407 // the same visual row as the close button, which is provided by the
408 // framework, we must add the buttons to the non-client view, which is the
409 // parent of this view. Similarly, when we're removed from the view
410 // hierarchy, we must take care to clean up those items as well.
411 if (details.child == this) {
412 if (details.is_add) {
413 details.parent->AddChildView(about_memory_link_);
414 details.parent->AddChildView(kill_button_);
415 tab_table_parent_ = tab_table_->CreateParentIfNecessary();
416 AddChildView(tab_table_parent_);
417 } else {
418 details.parent->RemoveChildView(kill_button_);
419 details.parent->RemoveChildView(about_memory_link_);
424 void TaskManagerView::Layout() {
425 gfx::Size size = kill_button_->GetPreferredSize();
426 gfx::Rect parent_bounds = parent()->GetContentsBounds();
427 const int horizontal_margin = views::kPanelHorizMargin;
428 const int vertical_margin = views::kButtonVEdgeMargin;
429 int x = width() - size.width() - horizontal_margin;
430 int y_buttons = parent_bounds.bottom() - size.height() - vertical_margin;
431 kill_button_->SetBounds(x, y_buttons, size.width(), size.height());
433 size = about_memory_link_->GetPreferredSize();
434 about_memory_link_->SetBounds(
435 horizontal_margin,
436 y_buttons + (kill_button_->height() - size.height()) / 2,
437 size.width(), size.height());
439 gfx::Rect rect = GetLocalBounds();
440 rect.Inset(horizontal_margin, views::kPanelVertMargin);
441 rect.Inset(0, 0, 0,
442 kill_button_->height() + views::kUnrelatedControlVerticalSpacing);
443 tab_table_parent_->SetBoundsRect(rect);
446 gfx::Size TaskManagerView::GetPreferredSize() const {
447 return gfx::Size(460, 270);
450 bool TaskManagerView::AcceleratorPressed(const ui::Accelerator& accelerator) {
451 DCHECK_EQ(ui::VKEY_W, accelerator.key_code());
452 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers());
453 GetWidget()->Close();
454 return true;
457 // static
458 void TaskManagerView::Show(Browser* browser) {
459 // In ash we can come here through the ChromeShellDelegate. If there is no
460 // browser window at that time of the call, browser could be passed as NULL.
461 const chrome::HostDesktopType desktop_type =
462 browser ? browser->host_desktop_type() : chrome::HOST_DESKTOP_TYPE_ASH;
464 if (instance_) {
465 // If there's a Task manager window open already, just activate it.
466 instance_->GetWidget()->Activate();
467 return;
469 instance_ = new TaskManagerView(desktop_type);
470 gfx::NativeWindow window =
471 browser ? browser->window()->GetNativeWindow() : NULL;
472 #if defined(USE_ASH)
473 if (!window)
474 window = ash::wm::GetActiveWindow();
475 #endif
476 DialogDelegate::CreateDialogWidget(instance_, window, NULL);
477 instance_->InitAlwaysOnTopState();
478 instance_->model_->StartUpdating();
479 #if defined(OS_WIN)
480 // Set the app id for the task manager to the app id of its parent browser. If
481 // no parent is specified, the app id will default to that of the initial
482 // process.
483 if (browser) {
484 ui::win::SetAppIdForWindow(
485 ShellIntegration::GetChromiumModelIdForProfile(
486 browser->profile()->GetPath()),
487 views::HWNDForWidget(instance_->GetWidget()));
489 #endif
490 instance_->GetWidget()->Show();
492 // Set the initial focus to the list of tasks.
493 views::FocusManager* focus_manager = instance_->GetFocusManager();
494 if (focus_manager)
495 focus_manager->SetFocusedView(instance_->tab_table_);
497 #if defined(USE_ASH)
498 gfx::NativeWindow native_window = instance_->GetWidget()->GetNativeWindow();
499 ash::SetShelfItemDetailsForDialogWindow(
500 native_window, IDR_ASH_SHELF_ICON_TASK_MANAGER, native_window->title());
501 #endif
504 // ButtonListener implementation.
505 void TaskManagerView::ButtonPressed(
506 views::Button* sender,
507 const ui::Event& event) {
508 typedef ui::ListSelectionModel::SelectedIndices SelectedIndices;
509 DCHECK_EQ(kill_button_, sender);
510 SelectedIndices selection(tab_table_->selection_model().selected_indices());
511 for (SelectedIndices::const_reverse_iterator i = selection.rbegin();
512 i != selection.rend(); ++i) {
513 task_manager_->KillProcess(*i);
517 // DialogDelegate implementation.
518 bool TaskManagerView::CanResize() const {
519 return true;
522 bool TaskManagerView::CanMaximize() const {
523 return true;
526 bool TaskManagerView::ExecuteWindowsCommand(int command_id) {
527 return false;
530 base::string16 TaskManagerView::GetWindowTitle() const {
531 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE);
534 std::string TaskManagerView::GetWindowName() const {
535 return prefs::kTaskManagerWindowPlacement;
538 int TaskManagerView::GetDialogButtons() const {
539 return ui::DIALOG_BUTTON_NONE;
542 void TaskManagerView::WindowClosing() {
543 // Now that the window is closed, we can allow a new one to be opened.
544 // (WindowClosing comes in asynchronously from the call to Close() and we
545 // may have already opened a new instance).
546 if (instance_ == this)
547 instance_ = NULL;
548 task_manager_->OnWindowClosed();
551 bool TaskManagerView::UseNewStyleForThisDialog() const {
552 return false;
555 // views::TableViewObserver implementation.
556 void TaskManagerView::OnSelectionChanged() {
557 const ui::ListSelectionModel::SelectedIndices& selection(
558 tab_table_->selection_model().selected_indices());
559 bool selection_contains_browser_process = false;
560 for (size_t i = 0; i < selection.size(); ++i) {
561 if (task_manager_->IsBrowserProcess(selection[i])) {
562 selection_contains_browser_process = true;
563 break;
566 kill_button_->SetEnabled(!selection_contains_browser_process &&
567 !selection.empty());
570 void TaskManagerView::OnDoubleClick() {
571 ActivateFocusedTab();
574 void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode) {
575 if (keycode == ui::VKEY_RETURN)
576 ActivateFocusedTab();
579 void TaskManagerView::LinkClicked(views::Link* source, int event_flags) {
580 DCHECK_EQ(about_memory_link_, source);
581 task_manager_->OpenAboutMemory(desktop_type_);
584 void TaskManagerView::ShowContextMenuForView(views::View* source,
585 const gfx::Point& point,
586 ui::MenuSourceType source_type) {
587 UpdateStatsCounters();
588 ui::SimpleMenuModel menu_model(this);
589 for (std::vector<ui::TableColumn>::iterator i(columns_.begin());
590 i != columns_.end(); ++i) {
591 menu_model.AddCheckItem(i->id, l10n_util::GetStringUTF16(i->id));
593 menu_runner_.reset(
594 new views::MenuRunner(&menu_model, views::MenuRunner::CONTEXT_MENU));
595 if (menu_runner_->RunMenuAt(GetWidget(),
596 NULL,
597 gfx::Rect(point, gfx::Size()),
598 views::MENU_ANCHOR_TOPLEFT,
599 source_type) == views::MenuRunner::MENU_DELETED) {
600 return;
604 bool TaskManagerView::IsCommandIdChecked(int id) const {
605 return tab_table_->IsColumnVisible(id);
608 bool TaskManagerView::IsCommandIdEnabled(int id) const {
609 return true;
612 bool TaskManagerView::GetAcceleratorForCommandId(
613 int command_id,
614 ui::Accelerator* accelerator) {
615 return false;
618 void TaskManagerView::ExecuteCommand(int id, int event_flags) {
619 tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id));
622 void TaskManagerView::InitAlwaysOnTopState() {
623 is_always_on_top_ = false;
624 if (GetSavedAlwaysOnTopState(&is_always_on_top_))
625 GetWidget()->SetAlwaysOnTop(is_always_on_top_);
628 void TaskManagerView::ActivateFocusedTab() {
629 const int active_row = tab_table_->selection_model().active();
630 if (active_row != -1)
631 task_manager_->ActivateProcess(active_row);
634 bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top) const {
635 if (!g_browser_process->local_state())
636 return false;
638 const base::DictionaryValue* dictionary =
639 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str());
640 return dictionary &&
641 dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top;
644 } // namespace
646 namespace chrome {
648 // Declared in browser_dialogs.h so others don't need to depend on our header.
649 void ShowTaskManager(Browser* browser) {
650 TaskManagerView::Show(browser);
653 } // namespace chrome