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

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