- RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>(
- web_contents_.GetRenderWidgetHostView());
- if ((params_.media_type != ContextMenuDataMediaType::kImage &&
- !params_.selection_text.empty()) ||
- (params_.is_editable &&
- (rwhva && rwhva->offscreen_helper()->HasSelectableText()))) {
- AddItemToProposedList(EWK_CONTEXT_MENU_ITEM_TYPE_ACTION, EWK_CONTEXT_MENU_ITEM_TAG_SELECT_WORD,
- std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SELECT_ABB")));
- AddItemToProposedList(EWK_CONTEXT_MENU_ITEM_TYPE_ACTION, EWK_CONTEXT_MENU_ITEM_TAG_SELECT_ALL,
- std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SELECT_ALL_ABB")));
-#if BUILDFLAG(IS_TIZEN)
- if (!params_.is_editable && !params_.selection_text.empty()) {
- // TODO: IDS_WEBVIEW_OPT_SHARE should be added for all po files.
- AddItemToProposedList(EWK_CONTEXT_MENU_ITEM_TYPE_ACTION,
- EWK_CONTEXT_MENU_ITEM_TAG_SHARE,
- dgettext("WebKit", "IDS_WEBVIEW_OPT_SHARE"));
+ if (params_.is_editable) {
+ RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>(
+ web_contents_.GetRenderWidgetHostView());
+ const SelectionControllerEfl* controller =
+ webview_->GetSelectionController();
+ bool should_add_select_and_select_all =
+ (!controller) ? true : !controller->IsCaretModeForced();
+
+ if (rwhva && rwhva->offscreen_helper()->HasSelectableText() &&
+ should_add_select_and_select_all) {
+ if (params_.selection_text.empty() &&
+ params_.input_field_type !=
+ blink::mojom::ContextMenuDataInputFieldType::kPassword) {
+ AddItemToProposedList(
+ EWK_CONTEXT_MENU_ITEM_TYPE_ACTION,
+ EWK_CONTEXT_MENU_ITEM_TAG_SELECT_WORD,
+ std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SELECT_ABB")));
+ }
+
+ // This is a tricky way to check if everything in the editable field is
+ // selected, because there is no other known way.
+ //
+ // * params_.selection_text contains selected text
+ // * rwhva->GetSelectedText() contains selected
+ // text and some text around selection
+ //
+ // If both strings are the same length, it means that the selection has
+ // no more text around it, so everything is already selected.
+ //
+ // There is also one more issue with this hack: if the last character of
+ // textarea is '\n', there will be additional '\n' reported in selection
+ // with surrounding characters, which isn't reported in selection text
+ // from params_. This means that lengths aren't equal, so normal length
+ // check won't work.
+ //
+ // To work around this, we assume that everything is already selected if
+ // selection with surroundings is one character longer than selection,
+ // and that last character is '\n'.
+ size_t surroundings_length = rwhva->GetSelectedText().length();
+ size_t selection_length = params_.selection_text.length();
+ char16_t surroundings_last_char =
+ rwhva->GetSelectedText()[surroundings_length - 1];
+
+ if (surroundings_length != selection_length &&
+ !(surroundings_length == selection_length + 1 &&
+ surroundings_last_char == '\n')) {
+ AddItemToProposedList(
+ EWK_CONTEXT_MENU_ITEM_TYPE_ACTION,
+ EWK_CONTEXT_MENU_ITEM_TAG_SELECT_ALL,
+ std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SELECT_ALL_ABB")));
+ }
+ }
+ } else {
+ if (params_.media_type != ContextMenuDataMediaType::kImage &&
+ is_text_selection_) {
+ AddItemToProposedList(
+ EWK_CONTEXT_MENU_ITEM_TYPE_ACTION,
+ EWK_CONTEXT_MENU_ITEM_TAG_SELECT_ALL,
+ std::string(dgettext("WebKit", "IDS_WEBVIEW_OPT_SELECT_ALL_ABB")));