return selection_mode_ == SelectionMode::CARET;
}
-void SelectionControllerEfl::SetControlsTemporarilyHidden(
- bool value,
- bool from_custom_scroll_callback) {
+void SelectionControllerEfl::SetControlsTemporarilyHidden(bool value,
+ bool set_forcefully) {
TRACE_EVENT1("selection,efl", __PRETTY_FUNCTION__,
"controls are hidden:", value);
if (controls_temporarily_hidden_ == value)
// Make sure to show selection controls only when no finger
// is left touching the screen.
if (!value && rwhva_->event_handler()->pointer_state().GetPointerCount() &&
- !from_custom_scroll_callback) {
+ !set_forcefully) {
return;
}
controls_temporarily_hidden_ = value;
}
void SelectionControllerEfl::TriggerOnSelectionChange() {
+ triggered_selection_change_ = true;
OnSelectionChanged(start_selection_, end_selection_);
}
void SelectionControllerEfl::OnSelectionChanged(
const gfx::SelectionBound& start, const gfx::SelectionBound& end) {
if (start_selection_ == start && end_selection_ == end &&
- selection_change_reason_ != Reason::RequestedByContextMenu)
+ !triggered_selection_change_)
return;
if (selection_change_reason_ != Reason::HandleDragged)
bool show = (selection_change_reason_ != Reason::Irrelevant) && !finger_down;
UpdateSelectionDataAndShow(
truncated_start, truncated_end, show);
+ triggered_selection_change_ = false;
selection_change_reason_ = Reason::Irrelevant;
// In case of the selected text contains only line break and no other
// characters, we should use caret selection mode.
- if (GetSelectionEditable() && !handle_being_dragged_ &&
+ if (GetSelectionEditable() && !handle_being_dragged_ && rwhva_ &&
rwhva_->GetSelectedText() == (u"\n")) {
rwhva_->offscreen_helper()->MoveCaret(
selection_data_->GetLeftRect().origin());
HideHandleAndContextMenu();
ClearSelection();
}
+
+ if (selection_change_reason_ == Reason::CaretModeForced) {
+ is_caret_mode_forced_ = false;
+ selection_change_reason_ = Reason::Irrelevant;
+ }
}
void SelectionControllerEfl::UpdateSelectionData(const std::u16string& text) {
return false;
}
- if (selection_changed ||
- selection_change_reason_ == Reason::RequestedByContextMenu) {
+ if (selection_changed || triggered_selection_change_)
ShowHandleAndContextMenuIfRequired();
- }
return true;
}
selection_change_reason_ = saved_reason;
ShowContextMenu();
}
+
+ // In order to keep selection controlls showing up,
+ // Reason::CaretModeForced should be used as a reason of selection change.
+ if (is_caret_mode_forced_)
+ selection_change_reason_ = Reason::CaretModeForced;
return;
}
input_handle_->Hide();
bool SelectionControllerEfl::HandleLongPressEvent(
const gfx::Point& touch_point,
const content::ContextMenuParams& params) {
-
if (params.is_editable) {
// If one long press on an empty form, do not enter selection mode.
// Instead, context menu will be shown if needed for clipboard actions.
params_.link_url.spec(),
params_.link_url.spec());
}
- 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")));
}
-#endif
}
#if BUILDFLAG(IS_TIZEN)
if (IsMobileProfile() && params_.is_draggable &&
menu_controller->webview_->GetSelectionController();
if (menu_controller->popup_ && selection_controller &&
- selection_controller->GetSelectionStatus())
+ selection_controller->GetSelectionStatus() &&
+ !selection_controller->IsCaretMode()) {
evas_object_show(menu_controller->popup_);
+ }
menu_controller->restore_timer_ = nullptr;