summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormohsen@chromium.org <mohsen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-17 20:44:16 +0000
committermohsen@chromium.org <mohsen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-17 20:44:16 +0000
commit68185b3d381cfe0124dbc5cbfdbcc43b8a130c80 (patch)
tree787b7d4d6ad23e94c503ee330fb408271083e109
parentdce44ec8c379bf8beba0ef45aa986a0d936b51ea (diff)
downloadchromium_src-68185b3d381cfe0124dbc5cbfdbcc43b8a130c80.zip
chromium_src-68185b3d381cfe0124dbc5cbfdbcc43b8a130c80.tar.gz
chromium_src-68185b3d381cfe0124dbc5cbfdbcc43b8a130c80.tar.bz2
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
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.cc4
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.h5
-rw-r--r--content/browser/web_contents/touch_editable_impl_aura.cc20
-rw-r--r--content/browser/web_contents/touch_editable_impl_aura.h2
-rw-r--r--content/browser/web_contents/web_contents_view_aura.cc4
-rw-r--r--ui/base/touch/touch_editing_controller.h4
-rw-r--r--ui/views/touchui/touch_selection_controller_impl.cc33
-rw-r--r--ui/views/touchui/touch_selection_controller_impl.h1
8 files changed, 50 insertions, 23 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
index e06ed4f..f0fe263 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
@@ -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
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h
index 37f5f4e..9e11115 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.h
+++ b/content/browser/renderer_host/render_widget_host_view_aura.h
@@ -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,
diff --git a/content/browser/web_contents/touch_editable_impl_aura.cc b/content/browser/web_contents/touch_editable_impl_aura.cc
index a9569df..00c69ce 100644
--- a/content/browser/web_contents/touch_editable_impl_aura.cc
+++ b/content/browser/web_contents/touch_editable_impl_aura.cc
@@ -62,7 +62,7 @@ void TouchEditableImplAura::UpdateEditingController() {
if (touch_selection_controller_)
touch_selection_controller_->SelectionChanged();
} else {
- EndTouchEditing();
+ EndTouchEditing(false);
}
}
@@ -105,12 +105,14 @@ 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();
+ }
}
}
@@ -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;
diff --git a/content/browser/web_contents/touch_editable_impl_aura.h b/content/browser/web_contents/touch_editable_impl_aura.h
index 2758702..8190b7c 100644
--- a/content/browser/web_contents/touch_editable_impl_aura.h
+++ b/content/browser/web_contents/touch_editable_impl_aura.h
@@ -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;
diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc
index 09fdb7dc..1c12260 100644
--- a/content/browser/web_contents/web_contents_view_aura.cc
+++ b/content/browser/web_contents/web_contents_view_aura.cc
@@ -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_);
diff --git a/ui/base/touch/touch_editing_controller.h b/ui/base/touch/touch_editing_controller.h
index a48a045..8be9317 100644
--- a/ui/base/touch/touch_editing_controller.h
+++ b/ui/base/touch/touch_editing_controller.h
@@ -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 {
diff --git a/ui/views/touchui/touch_selection_controller_impl.cc b/ui/views/touchui/touch_selection_controller_impl.cc
index 4f1aac4b1..11868f6 100644
--- a/ui/views/touchui/touch_selection_controller_impl.cc
+++ b/ui/views/touchui/touch_selection_controller_impl.cc
@@ -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,13 +232,22 @@ 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) {
@@ -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);
}
diff --git a/ui/views/touchui/touch_selection_controller_impl.h b/ui/views/touchui/touch_selection_controller_impl.h
index 31c9bc0..d96868d 100644
--- a/ui/views/touchui/touch_selection_controller_impl.h
+++ b/ui/views/touchui/touch_selection_controller_impl.h
@@ -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;