0

Clean up logic and naming for services

The RenderWidgetHostViewCocoa and BridgedContentView implementations of
-validRequestorForSendType:returnType: serve the same purpose but are
written differently. Rewrite both to make them structured the same way
and to be the most clear we can make them.

Rename "return" to "accept" to clarify the direction of the flow of
data.

This is not intended to change the functionality of the method.

Bug: 385170286
Change-Id: I9f29e107f237ce77628bfde907f302d36c17c8ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6254138
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: Leonard Grey <lgrey@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1418874}
This commit is contained in:
Avi Drissman
2025-02-11 13:09:01 -08:00
committed by Chromium LUCI CQ
parent fa18b5bd00
commit af45beba85
2 changed files with 28 additions and 31 deletions
components/remote_cocoa/app_shim
content/app_shim_remote_cocoa

@ -1376,23 +1376,25 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
eventFlags:0]; eventFlags:0];
} }
// Support for Services in context menus.
// Currently we only support reading and writing plain strings.
- (id)validRequestorForSendType:(NSString*)sendType - (id)validRequestorForSendType:(NSString*)sendType
returnType:(NSString*)returnType { returnType:(NSString*)returnType {
UTType* sendUTType = ui::UTTypeForServicesType(sendType); UTType* sendUTType = ui::UTTypeForServicesType(sendType);
UTType* returnUTType = ui::UTTypeForServicesType(returnType); UTType* acceptUTType = ui::UTTypeForServicesType(returnType);
BOOL canWrite = [sendUTType isEqual:UTTypeUTF8PlainText] &&
[self selectedRange].length > 0; const BOOL hasTextInputClient = [self hasTextInputClient];
BOOL canRead = [returnUTType isEqual:UTTypeUTF8PlainText]; const BOOL canSendText = [sendUTType isEqual:UTTypeUTF8PlainText] &&
// Valid if (sendUTType, returnUTType) is either (text, nil), (nil, text), hasTextInputClient &&
// or (text, text). [self selectedRange].length > 0;
BOOL valid = const BOOL canAcceptText =
[self hasTextInputClient] && ((canWrite && (canRead || !returnUTType)) || [acceptUTType isEqual:UTTypeUTF8PlainText] && hasTextInputClient;
(canRead && (canWrite || !sendUTType)));
return valid // This is a valid requestor if the send/accept types can be fulfilled or if
? self // they are `nil` (and therefore not the wrong type).
: [super validRequestorForSendType:sendType returnType:returnType]; if ((canSendText && !acceptUTType) || (!sendUTType && canAcceptText) ||
(canSendText && canAcceptText)) {
return self;
}
return [super validRequestorForSendType:sendType returnType:returnType];
} }
// NSServicesMenuRequestor protocol // NSServicesMenuRequestor protocol

@ -2632,25 +2632,20 @@ extern NSString* NSTextInputReplacementRangeAttributeName;
- (id)validRequestorForSendType:(NSString*)sendType - (id)validRequestorForSendType:(NSString*)sendType
returnType:(NSString*)returnType { returnType:(NSString*)returnType {
UTType* sendUTType = ui::UTTypeForServicesType(sendType); UTType* sendUTType = ui::UTTypeForServicesType(sendType);
UTType* returnUTType = ui::UTTypeForServicesType(returnType); UTType* acceptUTType = ui::UTTypeForServicesType(returnType);
id requestor = nil;
BOOL sendTypeIsPlainText = [sendUTType isEqual:UTTypeUTF8PlainText];
BOOL returnTypeIsPlainText = [returnUTType isEqual:UTTypeUTF8PlainText];
BOOL hasText = !_textSelectionRange.is_empty();
BOOL takesText = _textInputType != ui::TEXT_INPUT_TYPE_NONE;
if (sendTypeIsPlainText && hasText && !returnUTType) { const BOOL canSendText = [sendUTType isEqual:UTTypeUTF8PlainText] &&
requestor = self; !_textSelectionRange.is_empty();
} else if (!sendUTType && returnTypeIsPlainText && takesText) { const BOOL canAcceptText = [acceptUTType isEqual:UTTypeUTF8PlainText] &&
requestor = self; _textInputType != ui::TEXT_INPUT_TYPE_NONE;
} else if (sendTypeIsPlainText && returnTypeIsPlainText && hasText &&
takesText) { // This is a valid requestor if the send/accept types can be fulfilled or if
requestor = self; // they are `nil` (and therefore not the wrong type).
} else { if ((canSendText && !acceptUTType) || (!sendUTType && canAcceptText) ||
requestor = (canSendText && canAcceptText)) {
[super validRequestorForSendType:sendType returnType:returnType]; return self;
} }
return requestor; return [super validRequestorForSendType:sendType returnType:returnType];
} }
- (BOOL)shouldChangeCurrentCursor { - (BOOL)shouldChangeCurrentCursor {