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