1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
#define CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
#import <Cocoa/Cocoa.h>
#include <vector>
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "chrome/browser/ui/task_manager/task_manager_table_model.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/models/table_model_observer.h"
@class WindowSizeAutosaver;
namespace task_manager {
class TaskManagerMac;
}
// This class is responsible for loading the task manager window and for
// managing it.
@interface TaskManagerWindowController
: NSWindowController<NSTableViewDataSource,
NSTableViewDelegate,
NSMenuDelegate> {
@private
IBOutlet NSTableView* tableView_;
IBOutlet NSButton* endProcessButton_;
task_manager::TaskManagerMac* taskManagerMac_; // weak
task_manager::TaskManagerTableModel* tableModel_; // weak
base::scoped_nsobject<WindowSizeAutosaver> size_saver_;
// These contain a permutation of [0..|tableModel_->RowCount() - 1|]. Used to
// implement sorting.
std::vector<int> viewToModelMap_;
std::vector<int> modelToViewMap_;
// Descriptor of the current sort column.
task_manager::TableSortDescriptor currentSortDescriptor_;
// Re-entrancy flag to allow meddling with the sort descriptor.
BOOL withinSortDescriptorsDidChange_;
}
// Creates and shows the task manager's window.
- (id)initWithTaskManagerMac:(task_manager::TaskManagerMac*)taskManagerMac
tableModel:(task_manager::TaskManagerTableModel*)tableModel;
// Refreshes all data in the task manager table.
- (void)reloadData;
// Gets a copy of the current sort descriptor.
- (task_manager::TableSortDescriptor)sortDescriptor;
// Sets the current sort descriptor.
- (void)setSortDescriptor:
(const task_manager::TableSortDescriptor&)sortDescriptor;
// Returns YES if the specified column is visible.
- (BOOL)visibilityOfColumnWithId:(int)columnId;
// Sets the visibility of the specified column.
- (void)setColumnWithId:(int)columnId toVisibility:(BOOL)visibility;
// Callback for "End process" button.
- (IBAction)killSelectedProcesses:(id)sender;
// Callback for double clicks on the table.
- (void)tableWasDoubleClicked:(id)sender;
@end
@interface TaskManagerWindowController (TestingAPI)
- (NSTableView*)tableViewForTesting;
- (NSButton*)endProcessButtonForTesting;
@end
namespace task_manager {
// This class runs the Task Manager on the Mac.
class TaskManagerMac : public ui::TableModelObserver,
public content::NotificationObserver,
public TableViewDelegate {
public:
// Called by the TaskManagerWindowController:
void WindowWasClosed();
NSImage* GetImageForRow(int row);
// Creates the task manager if it doesn't exist; otherwise, it activates the
// existing task manager window.
static TaskManagerTableModel* Show();
// Hides the task manager if it is showing.
static void Hide();
// Various test-only functions.
static TaskManagerMac* GetInstanceForTests() { return instance_; }
TaskManagerTableModel* GetTableModelForTests() { return table_model_.get(); }
TaskManagerWindowController* CocoaControllerForTests() {
return window_controller_;
}
private:
TaskManagerMac();
~TaskManagerMac() override;
// ui::TableModelObserver:
void OnModelChanged() override;
void OnItemsChanged(int start, int length) override;
void OnItemsAdded(int start, int length) override;
void OnItemsRemoved(int start, int length) override;
// TableViewDelegate:
bool IsColumnVisible(int column_id) const override;
void SetColumnVisibility(int column_id, bool new_visibility) override;
bool IsTableSorted() const override;
TableSortDescriptor GetSortDescriptor() const override;
void SetSortDescriptor(const TableSortDescriptor& descriptor) override;
// content::NotificationObserver overrides:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// Our model.
std::unique_ptr<TaskManagerTableModel> table_model_;
// Controller of our window, destroys itself when the task manager window
// is closed.
TaskManagerWindowController* window_controller_; // weak
content::NotificationRegistrar registrar_;
// An open task manager window. There can only be one open at a time. This
// is reset to be null when the window is closed.
static TaskManagerMac* instance_;
DISALLOW_COPY_AND_ASSIGN(TaskManagerMac);
};
} // namespace task_manager
#endif // CHROME_BROWSER_UI_COCOA_TASK_MANAGER_MAC_H_
|