single_tap_performed_(false),
was_scrolled_(false),
postponed_(false),
- expecting_update_(false),
+ selection_change_reason_(Reason::Irrelevant),
long_mouse_press_(false),
selection_data_(new SelectionBoxEfl(parent_view)),
start_handle_(new SelectionHandleEfl(*this, SelectionHandleEfl::HANDLE_TYPE_LEFT, parent_view)),
Clear(IsAnyHandleVisible() || postponed_);
CancelContextMenu(0);
} else if (show_after_scroll_ || postponed_) {
- ShowHandleAndContextMenuIfRequired();
+ ShowHandleAndContextMenuIfRequired(Reason::ScrollOrZoomGestureEnded);
}
}
// handling "tap" gesture.
bool finger_down = handle_being_dragged_ || long_mouse_press_;
if (start == end && GetSelectionEditable() &&
- (!expecting_update_ && !finger_down)) {
- expecting_update_ = false;
+ (selection_change_reason_ == Reason::Irrelevant && !finger_down && !scrolling_)) {
HideHandleAndContextMenu();
ClearSelection();
return;
truncated_start = ConvertRectToPixel(device_scale_factor, truncated_start);
truncated_end = ConvertRectToPixel(device_scale_factor, truncated_end);
- bool show = expecting_update_ && !finger_down;
+ bool show = (selection_change_reason_ != Reason::Irrelevant) && !finger_down;
UpdateSelectionDataAndShow(
truncated_start, truncated_end, show);
- expecting_update_ = false;
+ selection_change_reason_ = Reason::Irrelevant;
}
void SelectionControllerEfl::UpdateSelectionData(const base::string16& text) {
bool SelectionControllerEfl::UpdateSelectionDataAndShow(
const gfx::Rect& left_rect,
const gfx::Rect& right_rect,
- bool show) {
+ bool /* show */) {
DetermineSelectionMode(left_rect, right_rect);
TRACE_EVENT0("selection,efl", __PRETTY_FUNCTION__);
- if (!show && !IsSelectionValid(left_rect, right_rect)) {
+ if ((selection_change_reason_ == Reason::Irrelevant) && !IsSelectionValid(left_rect, right_rect)) {
if (!GetCaretSelectionStatus())
ClearSelection();
selection_data_->UpdateRectData(left_rect, right_rect);
return false;
}
- RenderWidgetHostViewEfl* rwhv =
- static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
- if (show_only_large_handle_ && GetCaretSelectionStatus() &&
- (rwhv && !rwhv->IsLastAvailableTextEmpty())) {
- selection_data_->UpdateRectData(left_rect, right_rect);
- ShowHandleAndContextMenuIfRequired();
- return true;
- }
- if ((selection_data_->UpdateRectData(left_rect, right_rect) &&
- IsAnyHandleVisible()) || show || postponed_) {
- show_only_large_handle_ = false;
+ if (selection_data_->UpdateRectData(left_rect, right_rect))
ShowHandleAndContextMenuIfRequired();
- }
+
return true;
}
-void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired() {
+void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired(
+ Reason explicit_reason) {
TRACE_EVENT0("selection,efl", __PRETTY_FUNCTION__);
+ Reason effective_reason = selection_change_reason_;
+ if (explicit_reason != Reason::Irrelevant)
+ effective_reason = explicit_reason;
+
if (!selection_data_->GetStatus()) {
postponed_ = true;
return;
QuerySelectionStyle();
- if (!handle_being_dragged_ && !show_only_large_handle_)
+ bool show_context_menu = effective_reason != Reason::ScrollOrZoomGestureEnded &&
+ effective_reason != Reason::Tap &&
+ effective_reason != Reason::Irrelevant;
+ if (!handle_being_dragged_ && show_context_menu)
ShowContextMenu();
return;
}
// Do not show the context menu during selection extend
- if (!handle_being_dragged_)
+ if (!handle_being_dragged_ && effective_reason != Reason::Irrelevant)
ShowContextMenu();
QuerySelectionStyle();
// FIXME : Check the text Direction later
Evas_Coord x, y;
evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
- expecting_update_ = true;
+ selection_change_reason_ = Reason::HandleDragged;
gfx::Point magnifier_point;
magnifier_point.set_x(handle->GetBasePosition().x() + x);
void SelectionControllerEfl::HandleDragEndNotification() {
show_only_large_handle_ = false;
- expecting_update_ = false;
+ selection_change_reason_ = Reason::Irrelevant;
magnifier_->Hide();
start_handle_->SetBasePosition(selection_data_->GetLeftRect().bottom_left());
end_handle_->SetBasePosition(selection_data_->GetRightRect().bottom_right());
handle_being_dragged_ = false;
- ShowHandleAndContextMenuIfRequired();
+ ShowHandleAndContextMenuIfRequired(Reason::HandleReleased);
}
void SelectionControllerEfl::GetSelectionBounds(gfx::Rect* left,
RenderWidgetHostViewEfl* rwhv =
static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
Clear();
- expecting_update_ = true;
+ selection_change_reason_ = Reason::LongPressMoved;
if (selection_data_->IsInEditField()) {
Evas_Coord x, y;
evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
void SelectionControllerEfl::HandleLongPressEndEvent() {
show_only_large_handle_ = false;
long_mouse_press_ = false;
- expecting_update_ = false;
+ selection_change_reason_ = Reason::Irrelevant;
if (scrolling_)
show_after_scroll_ = true;
- ShowHandleAndContextMenuIfRequired();
+ ShowHandleAndContextMenuIfRequired(Reason::LongPressEnded);
}
void SelectionControllerEfl::PostHandleTapGesture(bool is_content_editable) {
SetSelectionStatus(true);
SetShowOnlyLargeHandle(true);
SetSelectionEditable(true);
- expecting_update_ = true;
+ selection_change_reason_ = Reason::Tap;
} else {
SetSelectionEditable(false);
}
// for such cases. So, the equality for x and y rather than width should be tested.
if (left_rect.x() == right_rect.x() && left_rect.y() == right_rect.y() &&
!selection_data_->IsInEditField() && !handle_being_dragged_ &&
- !expecting_update_) {
+ selection_change_reason_ == Reason::Irrelevant) {
SetSelectionStatus(false);
return false;
}
{ show_only_large_handle_ = show_only_large_handle; }
bool GetShowOnlyLargeHandle() const { return show_only_large_handle_; }
+ // 'Reason' enum class enumerates all reasons that can cause
+ // text selection changes that require changes on the status
+ // of selection controls (handles and context menu).
+ enum class Reason {
+ ScrollOrZoomGestureEnded = 0,
+ HandleDragged,
+ HandleReleased,
+ LongPressMoved,
+ LongPressEnded,
+ Tap,
+ RequestedByContextMenu,
+ Irrelevant,
+ };
void SetWaitsForRendererSelectionChanges(
- bool value) { expecting_update_ = value; }
+ Reason reason) { selection_change_reason_ = reason; }
// Gesture handlers.
void HandlePostponedGesture(int x, int y, ui::EventType type);
void HandleLongPressEventPrivate(const gfx::Point& touch_point);
- void ShowHandleAndContextMenuIfRequired();
+ void ShowHandleAndContextMenuIfRequired(Reason explicit_reason = Reason::Irrelevant);
void Clear(bool show_after_scroll = false);
bool IsSelectionValid(const gfx::Rect& left_rect, const gfx::Rect& right_rect);
// behind other layer.
bool postponed_;
- // Enters a state where browser has requested a text selection
+ // Cache the reason of why browser has requested a text selection
// change to the renderer. At the next composited selection update
- // state is handled and reset.
- bool expecting_update_;
+ // the cache is handled and reset.
+ Reason selection_change_reason_;
// Saves state so that handlers and context menu is not shown when seletion change event occurs.
bool long_mouse_press_;