Modified: trunk/Source/WebKit/ChangeLog (250259 => 250260)
--- trunk/Source/WebKit/ChangeLog 2019-09-23 22:36:41 UTC (rev 250259)
+++ trunk/Source/WebKit/ChangeLog 2019-09-23 22:42:22 UTC (rev 250260)
@@ -1,3 +1,79 @@
+2019-09-23 Tim Horton <[email protected]>
+
+ macOS: <datalist> dropdown shadow is cropped, looks nothing like NSComboBox
+ https://bugs.webkit.org/show_bug.cgi?id=199350
+
+ Reviewed by Wenson Hsieh.
+
+ Improve the appearance of the macOS <datalist> dropdown, adopting the
+ roundly-cornered and backdrop-ful appearance of the current NSComboBox style.
+
+ Use the proper window shadow instead of our own inside the window, both
+ so that we match the system and so that it doesn't get clipped.
+
+ Allow vertical rubber-banding, because NSComboBox does.
+
+ Don't highlight on hover, because NSComboBox doesn't. Do use NSTableView's
+ selection mechanism instead of rolling our own for highlights driven by
+ keyboard-based navigation.
+
+ Make use of NSTableCellView, since it has some smarts around pixel alignment
+ that we don't need to duplicate (and things are blurry on 1x displays without).
+
+ Also rename some classes to make it a bit more clear what's going on:
+ WKDataListSuggestionCell -> WKDataListSuggestionView (it's a NSView, not an NSCell)
+ WKDataListSuggestionsView -> WKDataListSuggestionsController (it's not a view at all)
+
+ * Platform/spi/mac/AppKitSPI.h:
+ * UIProcess/mac/WebDataListSuggestionsDropdownMac.mm:
+ (WebKit::WebDataListSuggestionsDropdownMac::show):
+ (-[WKDataListSuggestionWindow initWithContentRect:styleMask:backing:defer:]):
+ (-[WKDataListSuggestionWindow canBecomeKeyWindow]):
+ (-[WKDataListSuggestionWindow hasKeyAppearance]):
+ (-[WKDataListSuggestionWindow shadowOptions]):
+ (-[WKDataListSuggestionView initWithFrame:]):
+ (-[WKDataListSuggestionView setText:]):
+ (-[WKDataListSuggestionView setBackgroundStyle:]):
+ (-[WKDataListSuggestionTableRowView drawSelectionInRect:]):
+ (-[WKDataListSuggestionTableView initWithElementRect:]):
+ (-[WKDataListSuggestionTableView layout]):
+ (-[WKDataListSuggestionTableView reload]):
+ (-[WKDataListSuggestionsController initWithInformation:inView:]):
+ (-[WKDataListSuggestionsController currentSelectedString]):
+ (-[WKDataListSuggestionsController updateWithInformation:]):
+ (-[WKDataListSuggestionsController moveSelectionByDirection:]):
+ (-[WKDataListSuggestionsController invalidate]):
+ (-[WKDataListSuggestionsController dropdownRectForElementRect:]):
+ (-[WKDataListSuggestionsController showSuggestionsDropdown:]):
+ (-[WKDataListSuggestionsController tableView:rowViewForRow:]):
+ (-[WKDataListSuggestionsController tableView:viewForTableColumn:row:]):
+ (-[WKDataListSuggestionCell initWithFrame:]): Deleted.
+ (-[WKDataListSuggestionCell setText:]): Deleted.
+ (-[WKDataListSuggestionCell setActive:]): Deleted.
+ (-[WKDataListSuggestionCell drawRect:]): Deleted.
+ (-[WKDataListSuggestionCell mouseEntered:]): Deleted.
+ (-[WKDataListSuggestionCell mouseExited:]): Deleted.
+ (-[WKDataListSuggestionCell acceptsFirstResponder]): Deleted.
+ (-[WKDataListSuggestionTable initWithElementRect:]): Deleted.
+ (-[WKDataListSuggestionTable setVisibleRect:]): Deleted.
+ (-[WKDataListSuggestionTable currentActiveRow]): Deleted.
+ (-[WKDataListSuggestionTable setActiveRow:]): Deleted.
+ (-[WKDataListSuggestionTable reload]): Deleted.
+ (-[WKDataListSuggestionTable acceptsFirstResponder]): Deleted.
+ (-[WKDataListSuggestionTable enclosingScrollView]): Deleted.
+ (-[WKDataListSuggestionTable removeFromSuperviewWithoutNeedingDisplay]): Deleted.
+ (-[WKDataListSuggestionsView initWithInformation:inView:]): Deleted.
+ (-[WKDataListSuggestionsView currentSelectedString]): Deleted.
+ (-[WKDataListSuggestionsView updateWithInformation:]): Deleted.
+ (-[WKDataListSuggestionsView moveSelectionByDirection:]): Deleted.
+ (-[WKDataListSuggestionsView invalidate]): Deleted.
+ (-[WKDataListSuggestionsView dropdownRectForElementRect:]): Deleted.
+ (-[WKDataListSuggestionsView showSuggestionsDropdown:]): Deleted.
+ (-[WKDataListSuggestionsView selectedRow:]): Deleted.
+ (-[WKDataListSuggestionsView numberOfRowsInTableView:]): Deleted.
+ (-[WKDataListSuggestionsView tableView:heightOfRow:]): Deleted.
+ (-[WKDataListSuggestionsView tableView:viewForTableColumn:row:]): Deleted.
+
2019-09-23 Wenson Hsieh <[email protected]>
[iOS] Drop animation when dragging images from Photos to WebKit2 Mail compose is incorrect
Modified: trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm (250259 => 250260)
--- trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm 2019-09-23 22:36:41 UTC (rev 250259)
+++ trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm 2019-09-23 22:42:22 UTC (rev 250260)
@@ -28,52 +28,31 @@
#if ENABLE(DATALIST_ELEMENT) && USE(APPKIT)
+#import "AppKitSPI.h"
#import "WebPageProxy.h"
#import <WebCore/IntRect.h>
#import <WebCore/LocalizedStrings.h>
#import <pal/spi/cocoa/NSColorSPI.h>
-static const CGFloat dropdownTopMargin = 2;
+static const CGFloat dropdownTopMargin = 3;
+static const CGFloat dropdownVerticalPadding = 4;
static const CGFloat dropdownRowHeight = 20;
-static const CGFloat dropdownShadowHeight = 5;
-static const CGFloat dropdownShadowBlurRadius = 3;
static const size_t dropdownMaxSuggestions = 6;
-static NSString * const suggestionCellReuseIdentifier = @"WKDataListSuggestionCell";
+static NSString * const suggestionCellReuseIdentifier = @"WKDataListSuggestionView";
@interface WKDataListSuggestionWindow : NSWindow
@end
-@interface WKDataListSuggestionCell : NSView {
- RetainPtr<NSTextField> _textField;
- BOOL _mouseIsOver;
- BOOL _active;
-}
+@interface WKDataListSuggestionView : NSTableCellView
+@end
-@property (nonatomic, assign) BOOL active;
-
-- (void)setText:(NSString *)text;
+@interface WKDataListSuggestionTableRowView : NSTableRowView
@end
-@interface WKDataListSuggestionTable : NSTableView {
- RetainPtr<NSScrollView> _enclosingScrollView;
- Optional<size_t> _activeRow;
-}
-
-- (id)initWithElementRect:(const WebCore::IntRect&)rect;
-- (void)setVisibleRect:(NSRect)rect;
-- (void)setActiveRow:(size_t)row;
-- (Optional<size_t>)currentActiveRow;
-- (void)reload;
+@interface WKDataListSuggestionTableView : NSTableView
@end
-@interface WKDataListSuggestionsView : NSObject<NSTableViewDataSource, NSTableViewDelegate> {
-@private
- RetainPtr<WKDataListSuggestionTable> _table;
- WebKit::WebDataListSuggestionsDropdownMac* _dropdown;
- Vector<String> _suggestions;
- NSView *_view;
- RetainPtr<NSWindow> _enclosingWindow;
-}
+@interface WKDataListSuggestionsController : NSObject<NSTableViewDataSource, NSTableViewDelegate>
- (id)initWithInformation:(WebCore::DataListSuggestionInformation&&)information inView:(NSView *)view;
- (void)showSuggestionsDropdown:(WebKit::WebDataListSuggestionsDropdownMac*)dropdown;
@@ -82,6 +61,7 @@
- (void)invalidate;
- (String)currentSelectedString;
+
@end
namespace WebKit {
@@ -106,7 +86,7 @@
return;
}
- m_dropdownUI = adoptNS([[WKDataListSuggestionsView alloc] initWithInformation:WTFMove(information) inView:m_view]);
+ m_dropdownUI = adoptNS([[WKDataListSuggestionsController alloc] initWithInformation:WTFMove(information) inView:m_view]);
[m_dropdownUI showSuggestionsDropdown:this];
}
@@ -148,78 +128,78 @@
} // namespace WebKit
-@implementation WKDataListSuggestionWindow
-@end
+@implementation WKDataListSuggestionWindow {
+ RetainPtr<NSVisualEffectView> _backdropView;
+}
-@implementation WKDataListSuggestionCell
-
-@synthesize active=_active;
-
-- (id)initWithFrame:(NSRect)frameRect
+- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingStoreType defer:(BOOL)defer
{
- if (!(self = [super initWithFrame:frameRect]))
- return self;
+ self = [super initWithContentRect:contentRect styleMask:styleMask backing:backingStoreType defer:defer];
+ if (!self)
+ return nil;
- _textField = adoptNS([[NSTextField alloc] init]);
- [_textField setEditable:NO];
- [_textField setBezeled:NO];
- [_textField setBackgroundColor:[NSColor clearColor]];
- [self addSubview:_textField.get()];
+ self.hasShadow = YES;
- [self setIdentifier:@"WKDataListSuggestionCell"];
+ _backdropView = [[NSVisualEffectView alloc] initWithFrame:contentRect];
+ [_backdropView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+ [_backdropView setMaterial:NSVisualEffectMaterialMenu];
+ [_backdropView setState:NSVisualEffectStateActive];
+ [_backdropView setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
- [self addTrackingRect:self.bounds owner:self userData:nil assumeInside:NO];
+ [self setContentView:_backdropView.get()];
return self;
}
-- (void)setText:(NSString *)text
+- (BOOL)canBecomeKeyWindow
{
- [_textField setStringValue:text];
- [_textField sizeToFit];
+ return NO;
+}
- NSRect textFieldFrame = [_textField frame];
- [_textField setFrame:NSMakeRect(0, (NSHeight(self.frame) - NSHeight(textFieldFrame)) / 2, NSWidth(textFieldFrame), NSHeight(textFieldFrame))];
-
- _mouseIsOver = NO;
- self.active = NO;
+- (BOOL)hasKeyAppearance
+{
+ return YES;
}
-- (void)setActive:(BOOL)shouldActivate
+- (NSWindowShadowOptions)shadowOptions
{
- _active = shouldActivate;
- [self setNeedsDisplay:YES];
+ return NSWindowShadowSecondaryWindow;
}
-- (void)drawRect:(NSRect)dirtyRect
+@end
+
+@implementation WKDataListSuggestionView {
+ RetainPtr<NSTextField> _textField;
+}
+
+- (id)initWithFrame:(NSRect)frameRect
{
- if (self.active) {
- [[NSColor alternateSelectedControlColor] setFill];
- [_textField setTextColor:[NSColor alternateSelectedControlTextColor]];
- } else if (_mouseIsOver) {
- [[NSColor quaternaryLabelColor] setFill];
- [_textField setTextColor:[NSColor textColor]];
- } else {
- [[NSColor controlBackgroundColor] setFill];
- [_textField setTextColor:[NSColor textColor]];
- }
+ if (!(self = [super initWithFrame:frameRect]))
+ return self;
- NSRectFill(dirtyRect);
- [super drawRect:dirtyRect];
+ _textField = adoptNS([[NSTextField alloc] initWithFrame:frameRect]);
+ self.textField = _textField.get();
+
+ [self addSubview:self.textField];
+
+ self.identifier = suggestionCellReuseIdentifier;
+ self.textField.editable = NO;
+ self.textField.bezeled = NO;
+ self.textField.font = [NSFont menuFontOfSize:0];
+ self.textField.drawsBackground = NO;
+
+ return self;
}
-- (void)mouseEntered:(NSEvent *)event
+- (void)setText:(NSString *)text
{
- [super mouseEntered:event];
- _mouseIsOver = YES;
- [self setNeedsDisplay:YES];
+ self.textField.stringValue = text;
}
-- (void)mouseExited:(NSEvent *)event
+- (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle
{
- [super mouseExited:event];
- _mouseIsOver = NO;
- [self setNeedsDisplay:YES];
+ [super setBackgroundStyle:backgroundStyle];
+ self.textField.textColor = backgroundStyle == NSBackgroundStyleLight ? [NSColor textColor] : [NSColor alternateSelectedControlTextColor];
}
- (BOOL)acceptsFirstResponder
@@ -229,16 +209,28 @@
@end
-@implementation WKDataListSuggestionTable
+@implementation WKDataListSuggestionTableRowView
+- (void)drawSelectionInRect:(NSRect)dirtyRect
+{
+ [self setEmphasized:YES];
+ [super drawSelectionInRect:dirtyRect];
+}
+
+@end
+
+@implementation WKDataListSuggestionTableView {
+ RetainPtr<NSScrollView> _enclosingScrollView;
+}
+
- (id)initWithElementRect:(const WebCore::IntRect&)rect
{
if (!(self = [super initWithFrame:NSMakeRect(0, 0, rect.width(), 0)]))
return self;
- [self setIntercellSpacing:NSZeroSize];
[self setHeaderView:nil];
- [self setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
+ [self setBackgroundColor:[NSColor clearColor]];
+ [self setIntercellSpacing:NSMakeSize(0, self.intercellSpacing.height)];
auto column = adoptNS([[NSTableColumn alloc] init]);
[column setWidth:rect.width()];
@@ -246,48 +238,24 @@
_enclosingScrollView = adoptNS([[NSScrollView alloc] init]);
[_enclosingScrollView setHasVerticalScroller:YES];
- [_enclosingScrollView setVerticalScrollElasticity:NSScrollElasticityNone];
+ [_enclosingScrollView setVerticalScrollElasticity:NSScrollElasticityAllowed];
[_enclosingScrollView setHorizontalScrollElasticity:NSScrollElasticityNone];
[_enclosingScrollView setDocumentView:self];
+ [_enclosingScrollView setDrawsBackground:NO];
+ [[_enclosingScrollView contentView] setAutomaticallyAdjustsContentInsets:NO];
+ [[_enclosingScrollView contentView] setContentInsets:NSEdgeInsetsMake(dropdownVerticalPadding, 0, dropdownVerticalPadding, 0)];
+ [[_enclosingScrollView contentView] scrollToPoint:NSMakePoint(0, -dropdownVerticalPadding)];
- auto dropShadow = adoptNS([[NSShadow alloc] init]);
- [dropShadow setShadowColor:[NSColor systemGrayColor]];
- [dropShadow setShadowOffset:NSMakeSize(0, dropdownShadowHeight)];
- [dropShadow setShadowBlurRadius:dropdownShadowBlurRadius];
- [_enclosingScrollView setWantsLayer:YES];
- [_enclosingScrollView setShadow:dropShadow.get()];
-
return self;
}
-- (void)setVisibleRect:(NSRect)rect
+- (void)layout
{
- [self setFrame:NSMakeRect(0, 0, NSWidth(rect) - dropdownShadowHeight * 2, 0)];
- [_enclosingScrollView setFrame:NSMakeRect(dropdownShadowHeight, dropdownShadowHeight, NSWidth(rect) - dropdownShadowHeight * 2, NSHeight(rect) - dropdownShadowHeight)];
+ [_enclosingScrollView setFrame:[_enclosingScrollView superview].bounds];
}
-- (Optional<size_t>)currentActiveRow
-{
- return _activeRow;
-}
-
-- (void)setActiveRow:(size_t)row
-{
- if (_activeRow) {
- WKDataListSuggestionCell *oldCell = (WKDataListSuggestionCell *)[self viewAtColumn:0 row:_activeRow.value() makeIfNecessary:NO];
- oldCell.active = NO;
- }
-
- [self scrollRowToVisible:row];
- WKDataListSuggestionCell *newCell = (WKDataListSuggestionCell *)[self viewAtColumn:0 row:row makeIfNecessary:NO];
- newCell.active = YES;
-
- _activeRow = row;
-}
-
- (void)reload
{
- _activeRow = WTF::nullopt;
[self reloadData];
}
@@ -309,24 +277,33 @@
@end
-@implementation WKDataListSuggestionsView
+@implementation WKDataListSuggestionsController {
+ WebKit::WebDataListSuggestionsDropdownMac* _dropdown;
+ Vector<String> _suggestions;
+ NSView *_presentingView;
-- (id)initWithInformation:(WebCore::DataListSuggestionInformation&&)information inView:(NSView *)view
+ RetainPtr<WKDataListSuggestionWindow> _enclosingWindow;
+ RetainPtr<WKDataListSuggestionTableView> _table;
+}
+
+- (id)initWithInformation:(WebCore::DataListSuggestionInformation&&)information inView:(NSView *)presentingView
{
if (!(self = [super init]))
return self;
- _view = view;
+ _presentingView = presentingView;
_suggestions = WTFMove(information.suggestions);
- _table = adoptNS([[WKDataListSuggestionTable alloc] initWithElementRect:information.elementRect]);
+ _table = adoptNS([[WKDataListSuggestionTableView alloc] initWithElementRect:information.elementRect]);
- _enclosingWindow = adoptNS([[WKDataListSuggestionWindow alloc] initWithContentRect:NSZeroRect styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]);
+ _enclosingWindow = adoptNS([[WKDataListSuggestionWindow alloc] initWithContentRect:NSZeroRect styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView) backing:NSBackingStoreBuffered defer:NO]);
[_enclosingWindow setReleasedWhenClosed:NO];
[_enclosingWindow setFrame:[self dropdownRectForElementRect:information.elementRect] display:YES];
+ [_enclosingWindow setTitleVisibility:NSWindowTitleHidden];
+ [_enclosingWindow setTitlebarAppearsTransparent:YES];
+ [_enclosingWindow setMovable:NO];
[_enclosingWindow setBackgroundColor:[NSColor clearColor]];
[_enclosingWindow setOpaque:NO];
- [_table setVisibleRect:[_enclosingWindow frame]];
[_table setDelegate:self];
[_table setDataSource:self];
[_table setAction:@selector(selectedRow:)];
@@ -337,10 +314,11 @@
- (String)currentSelectedString
{
- Optional<size_t> selectedRow = [_table currentActiveRow];
- if (selectedRow && selectedRow.value() < _suggestions.size())
- return _suggestions.at(selectedRow.value());
+ NSInteger selectedRow = [_table selectedRow];
+ if (selectedRow >= 0 && static_cast<size_t>(selectedRow) < _suggestions.size())
+ return _suggestions.at(selectedRow);
+
return String();
}
@@ -350,7 +328,6 @@
[_table reload];
[_enclosingWindow setFrame:[self dropdownRectForElementRect:information.elementRect] display:YES];
- [_table setVisibleRect:[_enclosingWindow frame]];
}
- (void)notifyAccessibilityClients:(NSString *)info
@@ -364,19 +341,18 @@
- (void)moveSelectionByDirection:(const String&)direction
{
size_t size = _suggestions.size();
- Optional<size_t> oldSelection = [_table currentActiveRow];
+ NSInteger oldSelection = [_table selectedRow];
size_t newSelection;
- if (oldSelection) {
- size_t oldValue = oldSelection.value();
+ if (oldSelection != -1) {
if (direction == "Up")
- newSelection = oldValue ? (oldValue - 1) : (size - 1);
+ newSelection = oldSelection ? (oldSelection - 1) : (size - 1);
else
- newSelection = (oldValue + 1) % size;
+ newSelection = (oldSelection + 1) % size;
} else
newSelection = (direction == "Up") ? (size - 1) : 0;
- [_table setActiveRow:newSelection];
+ [_table selectRowIndexes:[NSIndexSet indexSetWithIndex:newSelection] byExtendingSelection:NO];
// Notify accessibility clients of new selection.
NSString *currentSelectedString = [self currentSelectedString];
@@ -393,7 +369,7 @@
_table = nil;
- [[_view window] removeChildWindow:_enclosingWindow.get()];
+ [[_presentingView window] removeChildWindow:_enclosingWindow.get()];
[_enclosingWindow close];
_enclosingWindow = nil;
@@ -404,9 +380,10 @@
- (NSRect)dropdownRectForElementRect:(const WebCore::IntRect&)rect
{
- NSRect windowRect = [[_view window] convertRectToScreen:[_view convertRect:rect toView:nil]];
- CGFloat height = std::min(_suggestions.size(), dropdownMaxSuggestions) * dropdownRowHeight;
- return NSMakeRect(NSMinX(windowRect) - dropdownShadowHeight, NSMinY(windowRect) - height - dropdownShadowHeight - dropdownTopMargin, rect.width() + dropdownShadowHeight * 2, height + dropdownShadowHeight);
+ NSRect windowRect = [[_presentingView window] convertRectToScreen:[_presentingView convertRect:rect toView:nil]];
+ auto visibleSuggestionCount = std::min(_suggestions.size(), dropdownMaxSuggestions);
+ CGFloat height = visibleSuggestionCount * (dropdownRowHeight + [_table intercellSpacing].height) + (dropdownVerticalPadding * 2);
+ return NSMakeRect(NSMinX(windowRect), NSMinY(windowRect) - height - dropdownTopMargin, rect.width(), height);
}
- (void)showSuggestionsDropdown:(WebKit::WebDataListSuggestionsDropdownMac*)dropdown
@@ -414,7 +391,7 @@
_dropdown = dropdown;
[[_enclosingWindow contentView] addSubview:[_table enclosingScrollView]];
[_table reload];
- [[_view window] addChildWindow:_enclosingWindow.get() ordered:NSWindowAbove];
+ [[_presentingView window] addChildWindow:_enclosingWindow.get() ordered:NSWindowAbove];
[[_table enclosingScrollView] flashScrollers];
// Notify accessibility clients of datalist becoming visible.
@@ -438,21 +415,22 @@
return dropdownRowHeight;
}
+- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
+{
+ return [[[WKDataListSuggestionTableRowView alloc] init] autorelease];
+}
+
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
- WKDataListSuggestionCell *result = [tableView makeViewWithIdentifier:suggestionCellReuseIdentifier owner:self];
+ WKDataListSuggestionView *result = [tableView makeViewWithIdentifier:suggestionCellReuseIdentifier owner:self];
if (!result) {
- result = [[[WKDataListSuggestionCell alloc] initWithFrame:NSMakeRect(0, 0, tableView.frame.size.width, dropdownRowHeight)] autorelease];
+ result = [[[WKDataListSuggestionView alloc] initWithFrame:NSMakeRect(0, 0, tableView.frame.size.width, dropdownRowHeight)] autorelease];
[result setIdentifier:suggestionCellReuseIdentifier];
}
- [result setText:_suggestions.at(row)];
+ result.text = _suggestions.at(row);
- Optional<size_t> currentActiveRow = [_table currentActiveRow];
- if (currentActiveRow && static_cast<size_t>(row) == currentActiveRow.value())
- result.active = YES;
-
return result;
}