Commit b1b8ac5a authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[VK] Don't show emoji menu item in context menu for certain input types.

We shouldn't show the emoji menu item in the render view context menu
for "number", "tel" and "other" (dates, time, checkboxes etc.) input
types.

We deliberately implement this as a blacklist (don't show for these
input types) instead of a whitelist (only show for these input types),
since not being able to enter emoji when you should be able to is much
more frustrating than having an extraneous emoji item.

Note that this permits emoji on "password" fields, but apparently that
could be a thing.

Bug: 865199
Change-Id: I7b2b977f435cee0c4f98c357187b45d90a08ecfc
Reviewed-on: https://chromium-review.googlesource.com/1142851Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577098}
parent c37f2d0f
...@@ -516,6 +516,19 @@ void OnProfileCreated(const GURL& link_url, ...@@ -516,6 +516,19 @@ void OnProfileCreated(const GURL& link_url,
} }
} }
bool DoesInputFieldTypeSupportEmoji(
blink::WebContextMenuData::InputFieldType text_input_type) {
// Disable emoji for input types that definitely do not support emoji.
switch (text_input_type) {
case blink::WebContextMenuData::kInputFieldTypeNumber:
case blink::WebContextMenuData::kInputFieldTypeTelephone:
case blink::WebContextMenuData::kInputFieldTypeOther:
return false;
default:
return true;
}
}
} // namespace } // namespace
// static // static
...@@ -1447,7 +1460,9 @@ void RenderViewContextMenu::AppendEditableItems() { ...@@ -1447,7 +1460,9 @@ void RenderViewContextMenu::AppendEditableItems() {
AppendSearchProvider(); AppendSearchProvider();
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
} }
if (params_.misspelled_word.empty() && ui::IsEmojiPanelSupported()) { if (params_.misspelled_word.empty() &&
DoesInputFieldTypeSupportEmoji(params_.input_field_type) &&
ui::IsEmojiPanelSupported()) {
menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_EMOJI, menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_EMOJI,
IDS_CONTENT_CONTEXT_EMOJI); IDS_CONTENT_CONTEXT_EMOJI);
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
......
...@@ -145,10 +145,14 @@ struct WebContextMenuData { ...@@ -145,10 +145,14 @@ struct WebContextMenuData {
enum InputFieldType { enum InputFieldType {
// Not an input field. // Not an input field.
kInputFieldTypeNone, kInputFieldTypeNone,
// type = text, tel, search, number, email, url // type = text, search, email, url
kInputFieldTypePlainText, kInputFieldTypePlainText,
// type = password // type = password
kInputFieldTypePassword, kInputFieldTypePassword,
// type = number
kInputFieldTypeNumber,
// type = tel
kInputFieldTypeTelephone,
// type = <etc.> // type = <etc.>
kInputFieldTypeOther, kInputFieldTypeOther,
kInputFieldTypeLast = kInputFieldTypeOther kInputFieldTypeLast = kInputFieldTypeOther
......
...@@ -448,6 +448,10 @@ bool ContextMenuController::ShowContextMenu(LocalFrame* frame, ...@@ -448,6 +448,10 @@ bool ContextMenuController::ShowContextMenu(LocalFrame* frame,
if (auto* input = ToHTMLInputElementOrNull(result.InnerNode())) { if (auto* input = ToHTMLInputElementOrNull(result.InnerNode())) {
if (input->type() == InputTypeNames::password) if (input->type() == InputTypeNames::password)
data.input_field_type = WebContextMenuData::kInputFieldTypePassword; data.input_field_type = WebContextMenuData::kInputFieldTypePassword;
else if (input->type() == InputTypeNames::number)
data.input_field_type = WebContextMenuData::kInputFieldTypeNumber;
else if (input->type() == InputTypeNames::tel)
data.input_field_type = WebContextMenuData::kInputFieldTypeTelephone;
else if (input->IsTextField()) else if (input->IsTextField())
data.input_field_type = WebContextMenuData::kInputFieldTypePlainText; data.input_field_type = WebContextMenuData::kInputFieldTypePlainText;
else else
......
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