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"
43 #include "ash/shelf/shelf_util.h"
44 #include "ash/wm/window_util.h"
45 #include "grit/ash_resources.h"
49 #include "chrome/browser/shell_integration.h"
50 #include "ui/base/win/shell.h"
51 #include "ui/views/win/hwnd_util.h"
56 ////////////////////////////////////////////////////////////////////////////////
57 // TaskManagerTableModel class
58 ////////////////////////////////////////////////////////////////////////////////
60 class TaskManagerTableModel
61 : public ui::TableModel
,
62 public views::TableGrouper
,
63 public TaskManagerModelObserver
{
65 explicit TaskManagerTableModel(TaskManagerModel
* model
)
68 model_
->AddObserver(this);
71 ~TaskManagerTableModel() override
{ model_
->RemoveObserver(this); }
73 // TableModel overrides:
74 int RowCount() override
;
75 base::string16
GetText(int row
, int column
) override
;
76 gfx::ImageSkia
GetIcon(int row
) override
;
77 void SetObserver(ui::TableModelObserver
* observer
) override
;
78 int CompareValues(int row1
, int row2
, int column_id
) override
;
80 // TableGrouper overrides:
81 void GetGroupRange(int model_index
, views::GroupRange
* range
) override
;
83 // TaskManagerModelObserver overrides:
84 void OnModelChanged() override
;
85 void OnItemsChanged(int start
, int length
) override
;
86 void OnItemsAdded(int start
, int length
) override
;
87 void OnItemsRemoved(int start
, int length
) override
;
90 TaskManagerModel
* model_
;
91 ui::TableModelObserver
* observer_
;
93 DISALLOW_COPY_AND_ASSIGN(TaskManagerTableModel
);
96 int TaskManagerTableModel::RowCount() {
97 return model_
->ResourceCount();
100 base::string16
TaskManagerTableModel::GetText(int row
, int col_id
) {
101 return model_
->GetResourceById(row
, col_id
);
104 gfx::ImageSkia
TaskManagerTableModel::GetIcon(int row
) {
105 return model_
->GetResourceIcon(row
);
108 void TaskManagerTableModel::SetObserver(ui::TableModelObserver
* observer
) {
109 observer_
= observer
;
112 int TaskManagerTableModel::CompareValues(int row1
, int row2
, int column_id
) {
113 return model_
->CompareValues(row1
, row2
, column_id
);
116 void TaskManagerTableModel::GetGroupRange(int model_index
,
117 views::GroupRange
* range
) {
118 TaskManagerModel::GroupRange range_pair
=
119 model_
->GetGroupRangeForResource(model_index
);
120 range
->start
= range_pair
.first
;
121 range
->length
= range_pair
.second
;
124 void TaskManagerTableModel::OnModelChanged() {
126 observer_
->OnModelChanged();
129 void TaskManagerTableModel::OnItemsChanged(int start
, int length
) {
131 observer_
->OnItemsChanged(start
, length
);
134 void TaskManagerTableModel::OnItemsAdded(int start
, int length
) {
136 observer_
->OnItemsAdded(start
, length
);
139 void TaskManagerTableModel::OnItemsRemoved(int start
, int length
) {
141 observer_
->OnItemsRemoved(start
, length
);
144 // The Task Manager UI container.
145 class TaskManagerView
: public views::ButtonListener
,
146 public views::DialogDelegateView
,
147 public views::TableViewObserver
,
148 public views::LinkListener
,
149 public views::ContextMenuController
,
150 public ui::SimpleMenuModel::Delegate
{
152 explicit TaskManagerView(chrome::HostDesktopType desktop_type
);
153 ~TaskManagerView() override
;
155 // Shows the Task Manager window, or re-activates an existing one.
156 static void Show(Browser
* browser
);
158 // Hides the Task Manager if it is showing.
162 void Layout() override
;
163 gfx::Size
GetPreferredSize() const override
;
164 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
165 void ViewHierarchyChanged(
166 const ViewHierarchyChangedDetails
& details
) override
;
168 // views::ButtonListener:
169 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
171 // views::DialogDelegateView:
172 bool CanResize() const override
;
173 bool CanMaximize() const override
;
174 bool CanMinimize() const override
;
175 bool ExecuteWindowsCommand(int command_id
) override
;
176 base::string16
GetWindowTitle() const override
;
177 std::string
GetWindowName() const override
;
178 int GetDialogButtons() const override
;
179 void WindowClosing() override
;
180 bool UseNewStyleForThisDialog() const override
;
182 // views::TableViewObserver:
183 void OnSelectionChanged() override
;
184 void OnDoubleClick() override
;
185 void OnKeyDown(ui::KeyboardCode keycode
) override
;
187 // views::LinkListener:
188 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 void ShowContextMenuForView(views::View
* source
,
196 const gfx::Point
& point
,
197 ui::MenuSourceType source_type
) override
;
199 // ui::SimpleMenuModel::Delegate:
200 bool IsCommandIdChecked(int id
) const override
;
201 bool IsCommandIdEnabled(int id
) const override
;
202 bool GetAcceleratorForCommandId(int command_id
,
203 ui::Accelerator
* accelerator
) override
;
204 void ExecuteCommand(int id
, int event_flags
) override
;
207 // Creates the child controls.
210 // Initializes the state of the always-on-top setting as the window is shown.
211 void InitAlwaysOnTopState();
213 // Activates the tab associated with the focused row.
214 void ActivateFocusedTab();
216 // Restores saved always on top state from a previous session.
217 bool GetSavedAlwaysOnTopState(bool* always_on_top
) const;
219 views::LabelButton
* kill_button_
;
220 views::Link
* about_memory_link_
;
221 views::TableView
* tab_table_
;
222 views::View
* tab_table_parent_
;
224 TaskManager
* task_manager_
;
226 TaskManagerModel
* model_
;
228 // all possible columns, not necessarily visible
229 std::vector
<ui::TableColumn
> columns_
;
231 scoped_ptr
<TaskManagerTableModel
> table_model_
;
233 // True when the Task Manager window should be shown on top of other windows.
234 bool is_always_on_top_
;
236 // The host desktop type this task manager belongs to.
237 const chrome::HostDesktopType desktop_type_
;
239 // We need to own the text of the menu, the Windows API does not copy it.
240 base::string16 always_on_top_menu_text_
;
242 // An open Task manager window. There can only be one open at a time. This
243 // is reset to NULL when the window is closed.
244 static TaskManagerView
* instance_
;
246 scoped_ptr
<views::MenuRunner
> menu_runner_
;
248 DISALLOW_COPY_AND_ASSIGN(TaskManagerView
);
252 TaskManagerView
* TaskManagerView::instance_
= NULL
;
255 TaskManagerView::TaskManagerView(chrome::HostDesktopType desktop_type
)
256 : kill_button_(NULL
),
257 about_memory_link_(NULL
),
259 tab_table_parent_(NULL
),
260 task_manager_(TaskManager::GetInstance()),
261 model_(TaskManager::GetInstance()->model()),
262 is_always_on_top_(false),
263 desktop_type_(desktop_type
) {
267 TaskManagerView::~TaskManagerView() {
268 // Delete child views now, while our table model still exists.
269 RemoveAllChildViews(true);
272 void TaskManagerView::Init() {
273 table_model_
.reset(new TaskManagerTableModel(model_
));
275 // Page column has no header label.
276 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_TASK_COLUMN
,
277 ui::TableColumn::LEFT
, -1, 1));
278 columns_
.back().sortable
= true;
279 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN
,
280 ui::TableColumn::LEFT
, -1, 0));
281 columns_
.back().sortable
= true;
282 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN
,
283 ui::TableColumn::RIGHT
, -1, 0));
284 columns_
.back().sortable
= true;
285 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_SHARED_MEM_COLUMN
,
286 ui::TableColumn::RIGHT
, -1, 0));
287 columns_
.back().sortable
= true;
288 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN
,
289 ui::TableColumn::RIGHT
, -1, 0));
290 columns_
.back().sortable
= true;
291 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_CPU_COLUMN
,
292 ui::TableColumn::RIGHT
, -1, 0));
293 columns_
.back().sortable
= true;
294 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_NET_COLUMN
,
295 ui::TableColumn::RIGHT
, -1, 0));
296 columns_
.back().sortable
= true;
297 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_PROCESS_ID_COLUMN
,
298 ui::TableColumn::RIGHT
, -1, 0));
299 columns_
.back().sortable
= true;
301 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN
,
302 ui::TableColumn::RIGHT
, -1, 0));
303 columns_
.back().sortable
= true;
304 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_USER_HANDLES_COLUMN
,
305 ui::TableColumn::RIGHT
, -1, 0));
306 columns_
.back().sortable
= true;
308 columns_
.push_back(ui::TableColumn(
309 IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN
,
310 ui::TableColumn::RIGHT
, -1, 0));
311 columns_
.back().sortable
= true;
312 columns_
.push_back(ui::TableColumn(
313 IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN
,
314 ui::TableColumn::RIGHT
, -1, 0));
315 columns_
.back().sortable
= true;
316 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN
,
317 ui::TableColumn::RIGHT
, -1, 0));
318 columns_
.back().sortable
= true;
319 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN
,
320 ui::TableColumn::RIGHT
, -1, 0));
321 columns_
.back().sortable
= true;
322 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN
,
323 ui::TableColumn::RIGHT
, -1, 0));
324 columns_
.back().sortable
= true;
325 columns_
.push_back(ui::TableColumn(
326 IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN
,
327 ui::TableColumn::RIGHT
, -1, 0));
328 columns_
.back().sortable
= true;
330 ui::TableColumn(IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN
,
331 ui::TableColumn::RIGHT
, -1, 0));
332 columns_
.back().sortable
= true;
333 // TODO(port) http://crbug.com/120488 for non-Linux.
334 #if defined(OS_LINUX)
335 columns_
.push_back(ui::TableColumn(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN
,
336 ui::TableColumn::RIGHT
, -1, 0));
337 columns_
.back().sortable
= true;
340 tab_table_
= new views::TableView(
341 table_model_
.get(), columns_
, views::ICON_AND_TEXT
, false);
342 tab_table_
->SetGrouper(table_model_
.get());
344 // Hide some columns by default
345 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_PROFILE_NAME_COLUMN
, false);
346 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_SHARED_MEM_COLUMN
, false);
347 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN
, false);
348 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_IMAGE_CACHE_COLUMN
,
350 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_SCRIPTS_CACHE_COLUMN
,
352 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_WEBCORE_CSS_CACHE_COLUMN
,
354 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_VIDEO_MEMORY_COLUMN
,
356 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN
,
358 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_NACL_DEBUG_STUB_PORT_COLUMN
,
360 tab_table_
->SetColumnVisibility(
361 IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN
, false);
362 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN
, false);
363 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_USER_HANDLES_COLUMN
, false);
364 tab_table_
->SetColumnVisibility(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN
, false);
366 UpdateStatsCounters();
367 tab_table_
->SetObserver(this);
368 tab_table_
->set_context_menu_controller(this);
369 set_context_menu_controller(this);
370 kill_button_
= new views::LabelButton(this,
371 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL
));
372 kill_button_
->SetStyle(views::Button::STYLE_BUTTON
);
373 about_memory_link_
= new views::Link(
374 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK
));
375 about_memory_link_
->set_listener(this);
377 // Makes sure our state is consistent.
378 OnSelectionChanged();
380 ui::Accelerator
ctrl_w(ui::VKEY_W
, ui::EF_CONTROL_DOWN
);
381 AddAccelerator(ctrl_w
);
384 void TaskManagerView::UpdateStatsCounters() {
385 base::StatsTable
* stats
= base::StatsTable::current();
387 int max
= stats
->GetMaxCounters();
388 // skip the first row (it's header data)
389 for (int i
= 1; i
< max
; i
++) {
390 const char* row
= stats
->GetRowName(i
);
391 if (row
!= NULL
&& row
[0] != '\0' && !tab_table_
->HasColumn(i
)) {
392 // TODO(erikkay): Use l10n to get display names for stats. Right
393 // now we're just displaying the internal counter name. Perhaps
394 // stat names not in the string table would be filtered out.
397 col
.title
= base::ASCIIToUTF16(row
);
398 col
.alignment
= ui::TableColumn::RIGHT
;
399 // TODO(erikkay): Width is hard-coded right now, so many column
400 // names are clipped.
403 columns_
.push_back(col
);
404 tab_table_
->AddColumn(col
);
410 void TaskManagerView::ViewHierarchyChanged(
411 const ViewHierarchyChangedDetails
& details
) {
412 views::DialogDelegateView::ViewHierarchyChanged(details
);
413 // Since we want the Kill button and the Memory Details link to show up in
414 // the same visual row as the close button, which is provided by the
415 // framework, we must add the buttons to the non-client view, which is the
416 // parent of this view. Similarly, when we're removed from the view
417 // hierarchy, we must take care to clean up those items as well.
418 if (details
.child
== this) {
419 if (details
.is_add
) {
420 details
.parent
->AddChildView(about_memory_link_
);
421 details
.parent
->AddChildView(kill_button_
);
422 tab_table_parent_
= tab_table_
->CreateParentIfNecessary();
423 AddChildView(tab_table_parent_
);
425 details
.parent
->RemoveChildView(kill_button_
);
426 details
.parent
->RemoveChildView(about_memory_link_
);
431 void TaskManagerView::Layout() {
432 gfx::Size size
= kill_button_
->GetPreferredSize();
433 gfx::Rect parent_bounds
= parent()->GetContentsBounds();
434 const int horizontal_margin
= views::kPanelHorizMargin
;
435 const int vertical_margin
= views::kButtonVEdgeMargin
;
436 int x
= width() - size
.width() - horizontal_margin
;
437 int y_buttons
= parent_bounds
.bottom() - size
.height() - vertical_margin
;
438 kill_button_
->SetBounds(x
, y_buttons
, size
.width(), size
.height());
440 size
= about_memory_link_
->GetPreferredSize();
441 about_memory_link_
->SetBounds(
443 y_buttons
+ (kill_button_
->height() - size
.height()) / 2,
444 size
.width(), size
.height());
446 gfx::Rect rect
= GetLocalBounds();
447 rect
.Inset(horizontal_margin
, views::kPanelVertMargin
);
449 kill_button_
->height() + views::kUnrelatedControlVerticalSpacing
);
450 tab_table_parent_
->SetBoundsRect(rect
);
453 gfx::Size
TaskManagerView::GetPreferredSize() const {
454 return gfx::Size(460, 270);
457 bool TaskManagerView::AcceleratorPressed(const ui::Accelerator
& accelerator
) {
458 DCHECK_EQ(ui::VKEY_W
, accelerator
.key_code());
459 DCHECK_EQ(ui::EF_CONTROL_DOWN
, accelerator
.modifiers());
460 GetWidget()->Close();
465 void TaskManagerView::Show(Browser
* browser
) {
466 // In ash we can come here through the ChromeShellDelegate. If there is no
467 // browser window at that time of the call, browser could be passed as NULL.
468 const chrome::HostDesktopType desktop_type
=
469 browser
? browser
->host_desktop_type() : chrome::HOST_DESKTOP_TYPE_ASH
;
472 // If there's a Task manager window open already, just activate it.
473 instance_
->GetWidget()->Activate();
476 instance_
= new TaskManagerView(desktop_type
);
477 gfx::NativeWindow window
=
478 browser
? browser
->window()->GetNativeWindow() : NULL
;
481 window
= ash::wm::GetActiveWindow();
483 DialogDelegate::CreateDialogWidget(instance_
, window
, NULL
);
484 instance_
->InitAlwaysOnTopState();
485 instance_
->model_
->StartUpdating();
487 // Set the app id for the task manager to the app id of its parent browser. If
488 // no parent is specified, the app id will default to that of the initial
491 ui::win::SetAppIdForWindow(
492 ShellIntegration::GetChromiumModelIdForProfile(
493 browser
->profile()->GetPath()),
494 views::HWNDForWidget(instance_
->GetWidget()));
497 instance_
->GetWidget()->Show();
499 // Set the initial focus to the list of tasks.
500 views::FocusManager
* focus_manager
= instance_
->GetFocusManager();
502 focus_manager
->SetFocusedView(instance_
->tab_table_
);
505 gfx::NativeWindow native_window
= instance_
->GetWidget()->GetNativeWindow();
506 ash::SetShelfItemDetailsForDialogWindow(
507 native_window
, IDR_ASH_SHELF_ICON_TASK_MANAGER
, native_window
->title());
512 void TaskManagerView::Hide() {
514 instance_
->GetWidget()->Close();
517 // ButtonListener implementation.
518 void TaskManagerView::ButtonPressed(
519 views::Button
* sender
,
520 const ui::Event
& event
) {
521 typedef ui::ListSelectionModel::SelectedIndices SelectedIndices
;
522 DCHECK_EQ(kill_button_
, sender
);
523 SelectedIndices
selection(tab_table_
->selection_model().selected_indices());
524 for (SelectedIndices::const_reverse_iterator i
= selection
.rbegin();
525 i
!= selection
.rend(); ++i
) {
526 task_manager_
->KillProcess(*i
);
530 // DialogDelegate implementation.
531 bool TaskManagerView::CanResize() const {
535 bool TaskManagerView::CanMaximize() const {
539 bool TaskManagerView::CanMinimize() const {
543 bool TaskManagerView::ExecuteWindowsCommand(int command_id
) {
547 base::string16
TaskManagerView::GetWindowTitle() const {
548 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE
);
551 std::string
TaskManagerView::GetWindowName() const {
552 return prefs::kTaskManagerWindowPlacement
;
555 int TaskManagerView::GetDialogButtons() const {
556 return ui::DIALOG_BUTTON_NONE
;
559 void TaskManagerView::WindowClosing() {
560 // Now that the window is closed, we can allow a new one to be opened.
561 // (WindowClosing comes in asynchronously from the call to Close() and we
562 // may have already opened a new instance).
563 if (instance_
== this)
565 task_manager_
->OnWindowClosed();
568 bool TaskManagerView::UseNewStyleForThisDialog() const {
572 // views::TableViewObserver implementation.
573 void TaskManagerView::OnSelectionChanged() {
574 const ui::ListSelectionModel::SelectedIndices
& selection(
575 tab_table_
->selection_model().selected_indices());
576 bool selection_contains_browser_process
= false;
577 for (size_t i
= 0; i
< selection
.size(); ++i
) {
578 if (task_manager_
->IsBrowserProcess(selection
[i
])) {
579 selection_contains_browser_process
= true;
583 kill_button_
->SetEnabled(!selection_contains_browser_process
&&
587 void TaskManagerView::OnDoubleClick() {
588 ActivateFocusedTab();
591 void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode
) {
592 if (keycode
== ui::VKEY_RETURN
)
593 ActivateFocusedTab();
596 void TaskManagerView::LinkClicked(views::Link
* source
, int event_flags
) {
597 DCHECK_EQ(about_memory_link_
, source
);
598 task_manager_
->OpenAboutMemory(desktop_type_
);
601 void TaskManagerView::ShowContextMenuForView(views::View
* source
,
602 const gfx::Point
& point
,
603 ui::MenuSourceType source_type
) {
604 UpdateStatsCounters();
605 ui::SimpleMenuModel
menu_model(this);
606 for (std::vector
<ui::TableColumn
>::iterator
i(columns_
.begin());
607 i
!= columns_
.end(); ++i
) {
608 menu_model
.AddCheckItem(i
->id
, l10n_util::GetStringUTF16(i
->id
));
611 new views::MenuRunner(&menu_model
, views::MenuRunner::CONTEXT_MENU
));
612 if (menu_runner_
->RunMenuAt(GetWidget(),
614 gfx::Rect(point
, gfx::Size()),
615 views::MENU_ANCHOR_TOPLEFT
,
616 source_type
) == views::MenuRunner::MENU_DELETED
) {
621 bool TaskManagerView::IsCommandIdChecked(int id
) const {
622 return tab_table_
->IsColumnVisible(id
);
625 bool TaskManagerView::IsCommandIdEnabled(int id
) const {
629 bool TaskManagerView::GetAcceleratorForCommandId(
631 ui::Accelerator
* accelerator
) {
635 void TaskManagerView::ExecuteCommand(int id
, int event_flags
) {
636 tab_table_
->SetColumnVisibility(id
, !tab_table_
->IsColumnVisible(id
));
639 void TaskManagerView::InitAlwaysOnTopState() {
640 is_always_on_top_
= false;
641 if (GetSavedAlwaysOnTopState(&is_always_on_top_
))
642 GetWidget()->SetAlwaysOnTop(is_always_on_top_
);
645 void TaskManagerView::ActivateFocusedTab() {
646 const int active_row
= tab_table_
->selection_model().active();
647 if (active_row
!= -1)
648 task_manager_
->ActivateProcess(active_row
);
651 bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top
) const {
652 if (!g_browser_process
->local_state())
655 const base::DictionaryValue
* dictionary
=
656 g_browser_process
->local_state()->GetDictionary(GetWindowName().c_str());
658 dictionary
->GetBoolean("always_on_top", always_on_top
) && always_on_top
;
665 // Declared in browser_dialogs.h so others don't need to depend on our header.
666 void ShowTaskManager(Browser
* browser
) {
667 TaskManagerView::Show(browser
);
670 void HideTaskManager() {
671 TaskManagerView::Hide();
674 } // namespace chrome