diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-21 16:21:37 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-21 16:21:37 +0000 |
commit | 538813c1332b409aae3f9a05921fddb6e6734bb5 (patch) | |
tree | 719c0cda9cffbf2c0e02d36ff5690c30719f79ca | |
parent | dd74b4d035de7833e5085f94a960ac1787edf0d3 (diff) | |
download | chromium_src-538813c1332b409aae3f9a05921fddb6e6734bb5.zip chromium_src-538813c1332b409aae3f9a05921fddb6e6734bb5.tar.gz chromium_src-538813c1332b409aae3f9a05921fddb6e6734bb5.tar.bz2 |
Task Manager for OS X: Set up columns, show rows.
This is more work-in-progress for the OS X task manager. The table header is complete (the right columns are there, and right-clicking the header gives a column-selection context menu just like in e.g. Task Manager), and the rows data is displayed. However, all the metrics (memory, cpu, etc) seem to be all wrong. Because of this and because too much stuff is still unimplemented (favicons in rows, the "kill process" button, the link, etc), I won't commit the change to MainMenu.xib, so users still won't be able to open this dialog.
BUG=13156
TEST=Connect view->task manager to first responder's commandDispatch:, set the menu item to "enabled", and give the menu item the tag 40005. Now opening the task manager should actually display data. Right-clicking the table header should show a functional menu that lets you select which columns to display. Clicking a column header should not select the column, double-clicking an item should not edit it. Also, when resizing the task manager, stuff should now behave in a sane way.
Review URL: http://codereview.chromium.org/208043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26687 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/nibs/TaskManager.xib | 94 | ||||
-rw-r--r-- | chrome/browser/cocoa/task_manager_mac.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/task_manager_mac.mm | 167 | ||||
-rw-r--r-- | chrome/browser/gtk/task_manager_gtk.cc | 2 |
4 files changed, 211 insertions, 60 deletions
diff --git a/chrome/app/nibs/TaskManager.xib b/chrome/app/nibs/TaskManager.xib index 375598e..ec1dd9e 100644 --- a/chrome/app/nibs/TaskManager.xib +++ b/chrome/app/nibs/TaskManager.xib @@ -8,7 +8,7 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="2"/> + <integer value="3"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -50,7 +50,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSScrollView" id="69694332"> <reference key="NSNextResponder" ref="1006"/> - <int key="NSvFlags">268</int> + <int key="NSvFlags">274</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSClipView" id="591559926"> @@ -87,16 +87,16 @@ <int key="NSCellFlags">75628032</int> <int key="NSCellFlags2">0</int> <string key="NSContents"/> - <object class="NSFont" key="NSSupport" id="26"> + <object class="NSFont" key="NSSupport"> <string key="NSName">LucidaGrande</string> <double key="NSSize">1.100000e+01</double> <int key="NSfFlags">3100</int> </object> - <object class="NSColor" key="NSBackgroundColor" id="685047776"> + <object class="NSColor" key="NSBackgroundColor"> <int key="NSColorSpace">3</int> <bytes key="NSWhite">MC4zMzMzMzI5OQA</bytes> </object> - <object class="NSColor" key="NSTextColor" id="990616000"> + <object class="NSColor" key="NSTextColor"> <int key="NSColorSpace">6</int> <string key="NSCatalogName">System</string> <string key="NSColorName">headerTextColor</string> @@ -137,32 +137,6 @@ <bool key="NSIsEditable">YES</bool> <reference key="NSTableView" ref="573715149"/> </object> - <object class="NSTableColumn" id="95821798"> - <double key="NSWidth">3.160000e+02</double> - <double key="NSMinWidth">4.000000e+01</double> - <double key="NSMaxWidth">1.000000e+03</double> - <object class="NSTableHeaderCell" key="NSHeaderCell"> - <int key="NSCellFlags">75628032</int> - <int key="NSCellFlags2">0</int> - <string key="NSContents"/> - <reference key="NSSupport" ref="26"/> - <reference key="NSBackgroundColor" ref="685047776"/> - <reference key="NSTextColor" ref="990616000"/> - </object> - <object class="NSTextFieldCell" key="NSDataCell" id="137828506"> - <int key="NSCellFlags">337772096</int> - <int key="NSCellFlags2">2048</int> - <string key="NSContents">Text Cell</string> - <reference key="NSSupport" ref="746983650"/> - <reference key="NSControlView" ref="573715149"/> - <reference key="NSBackgroundColor" ref="456292161"/> - <reference key="NSTextColor" ref="1040882968"/> - </object> - <int key="NSResizingMask">3</int> - <bool key="NSIsResizeable">YES</bool> - <bool key="NSIsEditable">YES</bool> - <reference key="NSTableView" ref="573715149"/> - </object> </object> <double key="NSIntercellSpacingWidth">3.000000e+00</double> <double key="NSIntercellSpacingHeight">2.000000e+00</double> @@ -180,7 +154,7 @@ </object> </object> <double key="NSRowHeight">1.700000e+01</double> - <int key="NSTvFlags">-700448768</int> + <int key="NSTvFlags">1388314624</int> <int key="NSColumnAutoresizingStyle">4</int> <int key="NSDraggingSourceMaskForLocal">15</int> <int key="NSDraggingSourceMaskForNonLocal">0</int> @@ -243,7 +217,7 @@ </object> <object class="NSTextField" id="976181670"> <reference key="NSNextResponder" ref="1006"/> - <int key="NSvFlags">268</int> + <int key="NSvFlags">292</int> <string key="NSFrame">{{17, 22}, {77, 17}}</string> <reference key="NSSuperview" ref="1006"/> <bool key="NSEnabled">YES</bool> @@ -274,7 +248,7 @@ <reference key="NSSuperview" ref="369147393"/> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="1069566772"> - <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags">604110336</int> <int key="NSCellFlags2">134217728</int> <string key="NSContents">^IDS_TASK_MANAGER_KILL</string> <reference key="NSSupport" ref="746983650"/> @@ -333,6 +307,22 @@ </object> <int key="connectionID">21</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">tableView_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="573715149"/> + </object> + <int key="connectionID">22</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">dataSource</string> + <reference key="source" ref="573715149"/> + <reference key="destination" ref="1001"/> + </object> + <int key="connectionID">23</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -411,7 +401,6 @@ <object class="NSMutableArray" key="children"> <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="694001717"/> - <reference ref="95821798"/> </object> <reference key="parent" ref="69694332"/> </object> @@ -430,20 +419,6 @@ <reference key="parent" ref="573715149"/> </object> <object class="IBObjectRecord"> - <int key="objectID">9</int> - <reference key="object" ref="95821798"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="137828506"/> - </object> - <reference key="parent" ref="573715149"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">10</int> - <reference key="object" ref="137828506"/> - <reference key="parent" ref="95821798"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">11</int> <reference key="object" ref="517523641"/> <reference key="parent" ref="694001717"/> @@ -510,7 +485,6 @@ <string>1.NSWindowTemplate.visibleAtLaunch</string> <string>1.WindowOrigin</string> <string>1.editorWindowContentRectSynchronizationRect</string> - <string>10.IBPluginDependency</string> <string>11.IBPluginDependency</string> <string>12.IBPluginDependency</string> <string>13.IBPluginDependency</string> @@ -525,16 +499,15 @@ <string>6.IBPluginDependency</string> <string>7.IBPluginDependency</string> <string>8.IBPluginDependency</string> - <string>9.IBPluginDependency</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{63, 495}, {480, 270}}</string> + <string>{{363, 406}, {480, 270}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{63, 495}, {480, 270}}</string> + <string>{{363, 406}, {480, 270}}</string> <integer value="1"/> <string>{196, 240}</string> <string>{{357, 418}, {480, 270}}</string> @@ -552,8 +525,6 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> </object> </object> <object class="NSMutableDictionary" key="unlocalizedProperties"> @@ -576,7 +547,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">21</int> + <int key="maxID">23</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -670,8 +641,19 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSWindow</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/nswindow_local_state.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">TaskManagerWindowController</string> <string key="superclassName">NSWindowController</string> + <object class="NSMutableDictionary" key="outlets"> + <string key="NS.key.0">tableView_</string> + <string key="NS.object.0">NSTableView</string> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">browser/cocoa/task_manager_mac.h</string> diff --git a/chrome/browser/cocoa/task_manager_mac.h b/chrome/browser/cocoa/task_manager_mac.h index dbf34f9..46d0455 100644 --- a/chrome/browser/cocoa/task_manager_mac.h +++ b/chrome/browser/cocoa/task_manager_mac.h @@ -12,10 +12,16 @@ // This class is responsible for loading the task manager window and for // managing it. @interface TaskManagerWindowController : NSWindowController { + @private + IBOutlet NSTableView* tableView_; + TaskManagerModel* model_; // weak } // Creates and shows the task manager's window. -- (id)init; +- (id)initWithModel:(TaskManagerModel*)model; + +// Refreshes all data in the task manager table. +- (void)reloadData; @end // This class listens to task changed events sent by chrome. diff --git a/chrome/browser/cocoa/task_manager_mac.mm b/chrome/browser/cocoa/task_manager_mac.mm index b282dad..1016f97 100644 --- a/chrome/browser/cocoa/task_manager_mac.mm +++ b/chrome/browser/cocoa/task_manager_mac.mm @@ -7,23 +7,180 @@ #include <algorithm> #include <vector> +#include "app/l10n_util_mac.h" #include "base/mac_util.h" +#include "base/sys_string_conversions.h" +#include "grit/generated_resources.h" + +// TODO(thakis): Autoremember window size/pos (and selected columns?) +// TODO(thakis): Link that opens about:memory +// TODO(thakis): Activate button iff something is selected, hook it up +// TODO(thakis): Column sort comparator +// TODO(thakis): Clicking column header doesn't sort +// TODO(thakis): Double-clicking a row seems to do something on win/linux +// TODO(thakis): On window close, stop updating +// TODO(thakis): Favicons in rows +// TODO(thakis): Default sort column +// TODO(thakis): Metrics are all wrong (some fixed when about:memory lands?) + +@interface TaskManagerWindowController (Private) +- (void)addColumnWithId:(int)columnId visible:(BOOL)isVisible; +- (void)setUpTableColumns; +- (void)setUpTableHeaderContextMenu; +- (void)toggleColumn:(id)sender; +@end //////////////////////////////////////////////////////////////////////////////// // TaskManagerWindowController implementation: @implementation TaskManagerWindowController -- (id)init { +- (id)initWithModel:(TaskManagerModel*)model { NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"TaskManager" ofType:@"nib"]; if ((self = [super initWithWindowNibPath:nibpath owner:self])) { + model_ = model; [[self window] makeKeyAndOrderFront:self]; } return self; } +- (void)reloadData { + [tableView_ reloadData]; +} + +- (void)awakeFromNib { + [self setUpTableColumns]; + [self setUpTableHeaderContextMenu]; +} + +// Adds a column which has the given string id as title. |isVisible| specifies +// if the column is initially visible. +- (void)addColumnWithId:(int)columnId visible:(BOOL)isVisible { + scoped_nsobject<NSTableColumn> column([[NSTableColumn alloc] + initWithIdentifier:[NSNumber numberWithInt:columnId]]); + + NSTextAlignment textAlignment = columnId == IDS_TASK_MANAGER_PAGE_COLUMN ? + NSLeftTextAlignment : NSRightTextAlignment; + + [[column.get() headerCell] + setStringValue:l10n_util::GetNSStringWithFixup(columnId)]; + [[column.get() headerCell] setAlignment:textAlignment]; + [[column.get() dataCell] setAlignment:textAlignment]; + + [column.get() setHidden:!isVisible]; + [column.get() setEditable:NO]; + [tableView_ addTableColumn:column.get()]; +} + +// Adds all the task manager's columns to the table. +- (void)setUpTableColumns { + for (NSTableColumn* column in [tableView_ tableColumns]) + [tableView_ removeTableColumn:column]; + [self addColumnWithId:IDS_TASK_MANAGER_PAGE_COLUMN visible:YES]; + [self addColumnWithId:IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN visible:YES]; + [self addColumnWithId:IDS_TASK_MANAGER_SHARED_MEM_COLUMN visible:NO]; + [self addColumnWithId:IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN visible:NO]; + [self addColumnWithId:IDS_TASK_MANAGER_CPU_COLUMN visible:YES]; + [self addColumnWithId:IDS_TASK_MANAGER_NET_COLUMN visible:YES]; + [self addColumnWithId:IDS_TASK_MANAGER_PROCESS_ID_COLUMN visible:NO]; + [self addColumnWithId:IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN visible:NO]; +} + +// Creates a context menu for the table header that allows the user to toggle +// which columns should be shown and which should be hidden (like e.g. +// Task Manager.app's table header context menu). +- (void)setUpTableHeaderContextMenu { + scoped_nsobject<NSMenu> contextMenu( + [[NSMenu alloc] initWithTitle:@"Task Manager context menu"]); + for (NSTableColumn* column in [tableView_ tableColumns]) { + NSMenuItem* item = [contextMenu.get() + addItemWithTitle:[[column headerCell] stringValue] + action:@selector(toggleColumn:) + keyEquivalent:@""]; + [item setTarget:self]; + [item setRepresentedObject:column]; + [item setState:[column isHidden] ? NSOffState : NSOnState]; + } + [[tableView_ headerView] setMenu:contextMenu.get()]; +} + +// Callback for the table header context menu. Toggles visibility of the table +// column associated with the clicked menu item. +- (void)toggleColumn:(id)item { + DCHECK([item isKindOfClass:[NSMenuItem class]]); + if (![item isKindOfClass:[NSMenuItem class]]) + return; + + NSTableColumn* column = [item representedObject]; + DCHECK(column); + NSInteger oldState = [item state]; + NSInteger newState = oldState == NSOnState ? NSOffState : NSOnState; + [column setHidden:newState == NSOffState]; + [item setState:newState]; + [tableView_ sizeToFit]; + [tableView_ setNeedsDisplay]; +} + +@end + +@implementation TaskManagerWindowController (NSTableDataSource) + +- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { + DCHECK(tableView == tableView_ || tableView_ == nil); + return model_->ResourceCount(); +} + +- (NSString*)modelTextForRow:(int)row column:(int)columnId { + switch (columnId) { + case IDS_TASK_MANAGER_PAGE_COLUMN: // Process + return base::SysWideToNSString(model_->GetResourceTitle(row)); + + case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: // Memory + if (!model_->IsResourceFirstInGroup(row)) + return @""; + return base::SysWideToNSString(model_->GetResourcePrivateMemory(row)); + + case IDS_TASK_MANAGER_SHARED_MEM_COLUMN: // Memory + if (!model_->IsResourceFirstInGroup(row)) + return @""; + return base::SysWideToNSString(model_->GetResourceSharedMemory(row)); + + case IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN: // Memory + if (!model_->IsResourceFirstInGroup(row)) + return @""; + return base::SysWideToNSString(model_->GetResourcePhysicalMemory(row)); + + case IDS_TASK_MANAGER_CPU_COLUMN: // CPU + if (!model_->IsResourceFirstInGroup(row)) + return @""; + return base::SysWideToNSString(model_->GetResourceCPUUsage(row)); + + case IDS_TASK_MANAGER_NET_COLUMN: // Net + return base::SysWideToNSString(model_->GetResourceNetworkUsage(row)); + + case IDS_TASK_MANAGER_PROCESS_ID_COLUMN: // Process ID + if (!model_->IsResourceFirstInGroup(row)) + return @""; + return base::SysWideToNSString(model_->GetResourceProcessId(row)); + + case IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN: // Goats Teleported! + return base::SysWideToNSString(model_->GetResourceGoatsTeleported(row)); + + default: + return base::SysWideToNSString( + model_->GetResourceStatsValue(row, columnId)); + } +} + +- (id)tableView:(NSTableView*)tableView + objectValueForTableColumn:(NSTableColumn*)tableColumn + row:(NSInteger)rowIndex { + return [self modelTextForRow:rowIndex + column:[[tableColumn identifier] intValue]]; +} + @end //////////////////////////////////////////////////////////////////////////////// @@ -32,7 +189,9 @@ TaskManagerMac::TaskManagerMac() : task_manager_(TaskManager::GetInstance()), model_(TaskManager::GetInstance()->model()) { - window_controller_.reset([[TaskManagerWindowController alloc] init]); + window_controller_.reset( + [[TaskManagerWindowController alloc] initWithModel:model_]); + model_->AddObserver(this); } // static @@ -47,15 +206,19 @@ TaskManagerMac::~TaskManagerMac() { // TaskManagerMac, TaskManagerModelObserver implementation: void TaskManagerMac::OnModelChanged() { + [window_controller_.get() reloadData]; } void TaskManagerMac::OnItemsChanged(int start, int length) { + [window_controller_.get() reloadData]; } void TaskManagerMac::OnItemsAdded(int start, int length) { + [window_controller_.get() reloadData]; } void TaskManagerMac::OnItemsRemoved(int start, int length) { + [window_controller_.get() reloadData]; } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/gtk/task_manager_gtk.cc b/chrome/browser/gtk/task_manager_gtk.cc index 4532a03..d0a29c0 100644 --- a/chrome/browser/gtk/task_manager_gtk.cc +++ b/chrome/browser/gtk/task_manager_gtk.cc @@ -348,7 +348,7 @@ void TaskManagerGtk::Init() { gtk_window_set_type_hint(GTK_WINDOW(dialog_), GDK_WINDOW_TYPE_HINT_NORMAL); // The response button should not be sensitive when the dialog is first opened - // because the selecetion is initially empty. + // because the selection is initially empty. gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), kTaskManagerResponseKill, FALSE); |