Commit 68185b3d authored by mohsen@chromium.org's avatar mohsen@chromium.org

Consistent fading behavior for touch editing handles

The general rule is that touch editing handles should fade out when they
are dismissed, unless handles and text are moving relative to each
other. So, handles fade out except in following cases, in which they
disappear almost immediately (i.e. they fade out super quickly):
- When handle is dragged out of content view. In this case it should
  actually scroll the contents, but that's a separate issue (see
  crbug.com/269003);
- When starting touch scrolling or gesture navigation.

BUG=313561

Review URL: https://codereview.chromium.org/138033014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245610 0039d316-1c4b-4281-b951-d872f2087c98
parent dce44ec8
......@@ -2546,7 +2546,7 @@ bool RenderWidgetHostViewAura::CanFocus() {
void RenderWidgetHostViewAura::OnCaptureLost() {
host_->LostCapture();
if (touch_editing_client_)
touch_editing_client_->EndTouchEditing();
touch_editing_client_->EndTouchEditing(false);
}
void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) {
......@@ -3061,7 +3061,7 @@ void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus,
host_->SetInputMethodActive(false);
if (touch_editing_client_)
touch_editing_client_->EndTouchEditing();
touch_editing_client_->EndTouchEditing(false);
// If we lose the focus while fullscreen, close the window; Pepper Flash
// won't do it for us (unlike NPAPI Flash). However, we do not close the
......
......@@ -120,8 +120,9 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
// Tells the client to start showing touch editing handles.
virtual void StartTouchEditing() = 0;
// Notifies the client that touch editing is no longer needed.
virtual void EndTouchEditing() = 0;
// Notifies the client that touch editing is no longer needed. |quick|
// determines whether the handles should fade out quickly or slowly.
virtual void EndTouchEditing(bool quick) = 0;
// Notifies the client that the selection bounds need to be updated.
virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
......
......@@ -62,7 +62,7 @@ void TouchEditableImplAura::UpdateEditingController() {
if (touch_selection_controller_)
touch_selection_controller_->SelectionChanged();
} else {
EndTouchEditing();
EndTouchEditing(false);
}
}
......@@ -105,13 +105,15 @@ void TouchEditableImplAura::StartTouchEditing() {
touch_selection_controller_->SelectionChanged();
}
void TouchEditableImplAura::EndTouchEditing() {
void TouchEditableImplAura::EndTouchEditing(bool quick) {
if (touch_selection_controller_) {
if (touch_selection_controller_->IsHandleDragInProgress())
if (touch_selection_controller_->IsHandleDragInProgress()) {
touch_selection_controller_->SelectionChanged();
else
} else {
touch_selection_controller_->HideHandles(quick);
touch_selection_controller_.reset();
}
}
}
void TouchEditableImplAura::OnSelectionOrCursorChanged(const gfx::Rect& anchor,
......@@ -131,7 +133,7 @@ bool TouchEditableImplAura::HandleInputEvent(const ui::Event* event) {
return false;
if (!event->IsGestureEvent()) {
EndTouchEditing();
EndTouchEditing(false);
return false;
}
......@@ -175,7 +177,7 @@ bool TouchEditableImplAura::HandleInputEvent(const ui::Event* event) {
handles_hidden_due_to_scroll_ = false;
if (touch_selection_controller_)
handles_hidden_due_to_scroll_ = true;
EndTouchEditing();
EndTouchEditing(true);
break;
case ui::ET_GESTURE_SCROLL_END:
// Scroll has ended, but we might still be in overscroll animation.
......@@ -287,7 +289,7 @@ void TouchEditableImplAura::OpenContextMenu(const gfx::Point& anchor) {
ConvertPointFromScreen(&point);
RenderWidgetHost* host = rwhva_->GetRenderWidgetHost();
host->Send(new ViewMsg_ShowContextMenu(host->GetRoutingID(), point));
EndTouchEditing();
EndTouchEditing(false);
}
bool TouchEditableImplAura::IsCommandIdChecked(int command_id) const {
......@@ -352,7 +354,7 @@ void TouchEditableImplAura::ExecuteCommand(int command_id, int event_flags) {
NOTREACHED();
break;
}
EndTouchEditing();
EndTouchEditing(false);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -374,7 +376,7 @@ void TouchEditableImplAura::Cleanup() {
rwhva_ = NULL;
}
text_input_type_ = ui::TEXT_INPUT_TYPE_NONE;
touch_selection_controller_.reset();
EndTouchEditing(true);
handles_hidden_due_to_scroll_ = false;
scroll_in_progress_ = false;
overscroll_in_progress_ = false;
......
......@@ -43,7 +43,7 @@ class CONTENT_EXPORT TouchEditableImplAura
// Overridden from RenderWidgetHostViewAura::TouchEditingClient.
virtual void StartTouchEditing() OVERRIDE;
virtual void EndTouchEditing() OVERRIDE;
virtual void EndTouchEditing(bool quick) OVERRIDE;
virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
const gfx::Rect& focus) OVERRIDE;
virtual void OnTextInputTypeChanged(ui::TextInputType type) OVERRIDE;
......
......@@ -1405,7 +1405,7 @@ void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) {
void WebContentsViewAura::ShowContextMenu(const ContextMenuParams& params) {
if (touch_editable_)
touch_editable_->EndTouchEditing();
touch_editable_->EndTouchEditing(false);
if (delegate_) {
delegate_->ShowContextMenu(params);
// WARNING: we may have been deleted during the call to ShowContextMenu().
......@@ -1436,7 +1436,7 @@ void WebContentsViewAura::StartDragging(
}
if (touch_editable_)
touch_editable_->EndTouchEditing();
touch_editable_->EndTouchEditing(false);
ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider();
PrepareDragData(drop_data, provider, web_contents_);
......
......@@ -74,6 +74,10 @@ class UI_BASE_EXPORT TouchSelectionController {
// Returns true if the user is currently dragging one of the handles.
virtual bool IsHandleDragInProgress() = 0;
// Hides visible handles. According to the value of |quick|, handles might
// fade out quickly or slowly.
virtual void HideHandles(bool quick) = 0;
};
class UI_BASE_EXPORT TouchSelectionControllerFactory {
......
......@@ -16,6 +16,7 @@
#include "ui/gfx/screen.h"
#include "ui/gfx/size.h"
#include "ui/views/corewm/shadow_types.h"
#include "ui/views/corewm/window_animations.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/public/masked_window_targeter.h"
......@@ -57,6 +58,8 @@ const int kSelectionHandleVertPadding = 20;
const int kContextMenuTimoutMs = 200;
const int kSelectionHandleQuickFadeDurationMs = 50;
// Creates a widget to host SelectionHandleView.
views::Widget* CreateTouchSelectionPopupWidget(
gfx::NativeView context,
......@@ -154,6 +157,7 @@ class TouchSelectionControllerImpl::EditingHandleView
}
virtual ~EditingHandleView() {
SetWidgetVisible(false, false);
}
// Overridden from views::WidgetDelegateView:
......@@ -228,14 +232,23 @@ class TouchSelectionControllerImpl::EditingHandleView
return widget_->IsVisible();
}
void SetWidgetVisible(bool visible) {
void SetWidgetVisible(bool visible, bool quick) {
if (widget_->IsVisible() == visible)
return;
if (visible)
if (visible) {
corewm::SetWindowShowAnimationDuration(
widget_->GetNativeView(),
base::TimeDelta::FromMilliseconds(
quick ? kSelectionHandleQuickFadeDurationMs : 0));
widget_->Show();
else
} else {
corewm::SetWindowHideAnimationDuration(
widget_->GetNativeView(),
base::TimeDelta::FromMilliseconds(
quick ? kSelectionHandleQuickFadeDurationMs : 0));
widget_->Hide();
}
}
void SetSelectionRectInScreen(const gfx::Rect& rect) {
gfx::Size image_size = GetHandleImageSize();
......@@ -375,13 +388,13 @@ void TouchSelectionControllerImpl::SelectionChanged() {
// Check if there is any selection at all.
if (screen_pos_1 == screen_pos_2) {
selection_handle_1_->SetWidgetVisible(false);
selection_handle_2_->SetWidgetVisible(false);
selection_handle_1_->SetWidgetVisible(false, false);
selection_handle_2_->SetWidgetVisible(false, false);
SetHandleSelectionRect(cursor_handle_.get(), r1, screen_rect_1);
return;
}
cursor_handle_->SetWidgetVisible(false);
cursor_handle_->SetWidgetVisible(false, false);
SetHandleSelectionRect(selection_handle_1_.get(), r1, screen_rect_1);
SetHandleSelectionRect(selection_handle_2_.get(), r2, screen_rect_2);
}
......@@ -391,6 +404,12 @@ bool TouchSelectionControllerImpl::IsHandleDragInProgress() {
return !!dragging_handle_;
}
void TouchSelectionControllerImpl::HideHandles(bool quick) {
selection_handle_1_->SetWidgetVisible(false, quick);
selection_handle_2_->SetWidgetVisible(false, quick);
cursor_handle_->SetWidgetVisible(false, quick);
}
void TouchSelectionControllerImpl::SetDraggingHandle(
EditingHandleView* handle) {
dragging_handle_ = handle;
......@@ -440,7 +459,7 @@ void TouchSelectionControllerImpl::SetHandleSelectionRect(
EditingHandleView* handle,
const gfx::Rect& rect,
const gfx::Rect& rect_in_screen) {
handle->SetWidgetVisible(client_view_->GetBounds().Contains(rect));
handle->SetWidgetVisible(client_view_->GetBounds().Contains(rect), false);
if (handle->IsWidgetVisible())
handle->SetSelectionRectInScreen(rect_in_screen);
}
......
......@@ -32,6 +32,7 @@ class VIEWS_EXPORT TouchSelectionControllerImpl
// TextSelectionController.
virtual void SelectionChanged() OVERRIDE;
virtual bool IsHandleDragInProgress() OVERRIDE;
virtual void HideHandles(bool quick) OVERRIDE;
private:
friend class TouchSelectionControllerImplTest;
......
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