Commit 988002c2 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Fix Mac Task Manager issues.

This reverts commit bb269b0e and
attempts to solve the original issue in a different manner.

That commit attempted to solve the problem of column header labels
being cut off (https://crbug.com/1109129) by not setting a maximum
column width. That caused the issue of, when the window is re-opened,
that all the columns split the width of the table view. That means
that, for a large window, lots of space is wasted on columns with
small-width data, and no space is left for the "Task" column.

That commit also switched the autoresize style to "sequential". That
was meant to ensure that the "Task" column got the extra space when
the window was resized, but in fact it forces the *last* column to
get the extra space. I suppose "reverse sequential" was intended,
but reverting things is easier.

This CL fixes the problem by adjusting the maximum size to be at
least as large as the labels.

Bug: 1109129, 1134831
Change-Id: I4452fa2256ec05ce6cca9fbe1fee38df79eddbab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2447099
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813803}
parent 45d07239
......@@ -287,9 +287,12 @@ NSString* ColumnIdentifier(int id) {
[[NSTableView alloc] initWithFrame:NSMakeRect(0, 0, 400, 200)]);
[tableView setAllowsColumnReordering:NO];
[tableView setAllowsMultipleSelection:YES];
// No autosaving, since column identifiers are IDS_ values which are not
// stable. TODO(avi): Would it be worth it to find stable identifiers so that
// we could use autosaving?
[tableView setAutosaveTableColumns:NO];
[tableView
setColumnAutoresizingStyle:NSTableViewSequentialColumnAutoresizingStyle];
setColumnAutoresizingStyle:NSTableViewUniformColumnAutoresizingStyle];
[tableView setDoubleAction:@selector(tableWasDoubleClicked:)];
[tableView setFocusRingType:NSFocusRingTypeNone];
[tableView setIntercellSpacing:NSMakeSize(0, 0)];
......@@ -308,14 +311,17 @@ NSString* ColumnIdentifier(int id) {
base::scoped_nsobject<NSTableColumn> column([[NSTableColumn alloc]
initWithIdentifier:ColumnIdentifier(columnData.id)]);
NSTableHeaderCell* headerCell = [column.get() headerCell];
id dataCell = [column.get() dataCell];
NSTextAlignment textAlignment = (columnData.align == ui::TableColumn::LEFT)
? NSLeftTextAlignment
: NSRightTextAlignment;
[[column.get() headerCell]
setStringValue:l10n_util::GetNSStringWithFixup(columnData.id)];
[[column.get() headerCell] setAlignment:textAlignment];
[[column.get() dataCell] setAlignment:textAlignment];
NSString* columnTitle = l10n_util::GetNSStringWithFixup(columnData.id);
[headerCell setStringValue:columnTitle];
[headerCell setAlignment:textAlignment];
[dataCell setAlignment:textAlignment];
const CGFloat smallSystemFontSize = [NSFont smallSystemFontSize];
NSFont* font = nil;
......@@ -325,7 +331,7 @@ NSString* ColumnIdentifier(int id) {
} else {
font = [NSFont systemFontOfSize:smallSystemFontSize];
}
[[column.get() dataCell] setFont:font];
[dataCell setFont:font];
[column.get() setHidden:!columnData.default_visibility];
[column.get() setEditable:NO];
......@@ -337,8 +343,20 @@ NSString* ColumnIdentifier(int id) {
[column.get() setSortDescriptorPrototype:sortDescriptor.get()];
[column.get() setMinWidth:columnData.min_width];
if (columnData.max_width > 0)
[column.get() setMaxWidth:columnData.max_width];
// If there is no specified max width, use a reasonable value of 1.5x the min
// width, but make sure that the max width is big enough to actually show the
// entire column title.
const int kTitleMargin = 40; // Space for the arrow, etc.
int maxWidth = columnData.max_width;
if (maxWidth <= 0)
maxWidth = 3 * columnData.min_width / 2;
int columnTitleWidth =
[columnTitle
sizeWithAttributes:@{NSFontAttributeName : [headerCell font]}]
.width +
kTitleMargin;
maxWidth = std::max(maxWidth, columnTitleWidth);
[column.get() setMaxWidth:maxWidth];
[column.get() setResizingMask:NSTableColumnAutoresizingMask |
NSTableColumnUserResizingMask];
......
......@@ -27,7 +27,7 @@ struct TableColumnData {
float percent;
// min and max widths used for Mac's implementation and are ignored on Views.
// If |max_width| is -1, it is unset.
// If |max_width| is -1, a value of 1.5 * |min_width| will be used.
int min_width;
int max_width;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment