Skip to content

Commit

Permalink
aura: Add flag to indicate if a drag session is started with touch or…
Browse files Browse the repository at this point in the history
… mouse.

BUG=114755


Review URL: https://chromiumcodereview.appspot.com/11368072

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166278 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
varunjain@chromium.org committed Nov 6, 2012
1 parent 6e3edb4 commit 589b089
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 38 deletions.
11 changes: 7 additions & 4 deletions ash/drag_drop/drag_drop_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ DragDropController::~DragDropController() {
drag_image_.reset();
}

int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
aura::RootWindow* root_window,
const gfx::Point& root_location,
int operation) {
int DragDropController::StartDragAndDrop(
const ui::OSExchangeData& data,
aura::RootWindow* root_window,
aura::Window* source_window,
const gfx::Point& root_location,
int operation,
ui::DragDropTypes::DragEventSource source) {
DCHECK(!IsDragDropInProgress());

drag_drop_tracker_.reset(new DragDropTracker);
Expand Down
11 changes: 7 additions & 4 deletions ash/drag_drop/drag_drop_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ class ASH_EXPORT DragDropController
}

// Overridden from aura::client::DragDropClient:
virtual int StartDragAndDrop(const ui::OSExchangeData& data,
aura::RootWindow* root_window,
const gfx::Point& root_location,
int operation) OVERRIDE;
virtual int StartDragAndDrop(
const ui::OSExchangeData& data,
aura::RootWindow* root_window,
aura::Window* source_window,
const gfx::Point& root_location,
int operation,
ui::DragDropTypes::DragEventSource source) OVERRIDE;
virtual void DragUpdate(aura::Window* target,
const ui::LocatedEvent& event) OVERRIDE;
virtual void Drop(aura::Window* target,
Expand Down
6 changes: 4 additions & 2 deletions ash/drag_drop/drag_drop_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ class TestDragDropController : public internal::DragDropController {
private:
int StartDragAndDrop(const ui::OSExchangeData& data,
aura::RootWindow* root_window,
aura::Window* source_window,
const gfx::Point& location,
int operation) OVERRIDE {
int operation,
ui::DragDropTypes::DragEventSource source) OVERRIDE {
drag_start_received_ = true;
data.GetString(&drag_string_);
return DragDropController::StartDragAndDrop(
data, root_window, location, operation);
data, root_window, source_window, location, operation, source);
}

void DragUpdate(aura::Window* target,
Expand Down
5 changes: 4 additions & 1 deletion chrome/browser/download/download_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,14 @@ void DragDownload(const DownloadItem* download,
return;

gfx::Point location = gfx::Screen::GetScreenFor(view)->GetCursorScreenPoint();
// TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below.
aura::client::GetDragDropClient(root_window)->StartDragAndDrop(
data,
root_window,
view,
location,
ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK);
ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK,
ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
#else // We are on WIN without AURA
// We cannot use Widget::RunShellDrag on WIN since the |view| is backed by a
// TabContentsViewWin, not a NativeWidgetWin.
Expand Down
7 changes: 5 additions & 2 deletions chrome/browser/ui/views/bookmarks/bookmark_drag_drop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ void DragBookmarks(Profile* profile,
ui::DragDropTypes::DRAG_MOVE |
ui::DragDropTypes::DRAG_LINK;
views::Widget* widget = views::Widget::GetWidgetForNativeView(view);
// TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below.
if (widget) {
widget->RunShellDrag(NULL, data, gfx::Point(), operation);
widget->RunShellDrag(NULL, data, gfx::Point(), operation,
ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
} else {
// We hit this case when we're using WebContentsViewWin or
// WebContentsViewAura, instead of TabContentsViewViews.
views::RunShellDrag(view, data, gfx::Point(), operation);
views::RunShellDrag(view, data, gfx::Point(), operation,
ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
}

MessageLoop::current()->SetNestableTasksAllowed(was_nested);
Expand Down
4 changes: 3 additions & 1 deletion content/browser/web_contents/web_contents_view_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,13 @@ void WebContentsViewAura::StartDragging(
// always start from a mouse-event (e.g. a touch or gesture event could
// initiate the drag). The location information should be carried over from
// webkit. http://crbug.com/114754
// TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below.
gfx::Point location(
gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint());
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop(
data, root_window, location, ConvertFromWeb(operations));
data, root_window, GetContentNativeView(), location,
ConvertFromWeb(operations), ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
}

// Bail out immediately if the contents view window is gone. Note that it is
Expand Down
5 changes: 4 additions & 1 deletion ui/aura/client/drag_drop_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define UI_AURA_CLIENT_DRAG_DROP_CLIENT_H_

#include "ui/aura/aura_export.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/gfx/native_widget_types.h"

namespace gfx {
Expand All @@ -32,8 +33,10 @@ class AURA_EXPORT DragDropClient {
// RootWindow's coordinate system.
virtual int StartDragAndDrop(const ui::OSExchangeData& data,
aura::RootWindow* root_window,
aura::Window* source_window,
const gfx::Point& root_location,
int operation) = 0;
int operation,
ui::DragDropTypes::DragEventSource source) = 0;

// Called when mouse is dragged during a drag and drop.
virtual void DragUpdate(aura::Window* target,
Expand Down
5 changes: 5 additions & 0 deletions ui/base/dragdrop/drag_drop_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class UI_EXPORT DragDropTypes {
DRAG_LINK = 1 << 2
};

enum DragEventSource {
DRAG_EVENT_SOURCE_MOUSE,
DRAG_EVENT_SOURCE_TOUCH,
};

#if defined(OS_WIN)
static uint32 DragOperationToDropEffect(int drag_operation);
static int DropEffectToDragOperation(uint32 effect);
Expand Down
4 changes: 3 additions & 1 deletion ui/views/controls/menu/menu_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,9 @@ void MenuController::StartDrag(SubmenuView* source,
StopScrolling();
int drag_ops = item->GetDelegate()->GetDragOperations(item);
drag_in_progress_ = true;
item->GetWidget()->RunShellDrag(NULL, data, widget_loc, drag_ops);
// TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below.
item->GetWidget()->RunShellDrag(NULL, data, widget_loc, drag_ops,
ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
drag_in_progress_ = false;

if (GetActiveInstance() == this) {
Expand Down
5 changes: 3 additions & 2 deletions ui/views/drag_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ namespace views {
void RunShellDrag(gfx::NativeView view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) {
int operation,
ui::DragDropTypes::DragEventSource source) {
#if defined(USE_AURA)
gfx::Point root_location(location);
aura::RootWindow* root_window = view->GetRootWindow();
aura::Window::ConvertPointToTarget(view, root_window, &root_location);
if (aura::client::GetDragDropClient(root_window)) {
aura::client::GetDragDropClient(root_window)->StartDragAndDrop(
data, root_window, root_location, operation);
data, root_window, view, root_location, operation, source);
}
#elif defined(OS_WIN)
scoped_refptr<ui::DragSource> drag_source(new ui::DragSource);
Expand Down
8 changes: 5 additions & 3 deletions ui/views/drag_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef UI_VIEWS_DRAG_UTILS_H_
#define UI_VIEWS_DRAG_UTILS_H_

#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/views_export.h"

Expand All @@ -23,9 +24,10 @@ class Widget;

// Starts a drag operation. This blocks until the drag operation completes.
VIEWS_EXPORT void RunShellDrag(gfx::NativeView view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation);
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation,
ui::DragDropTypes::DragEventSource source);

// Returns a canvas that can be used to draw the drag image. Caller owns the
// returned object. |widget| is Widget hosting the view being dragged.
Expand Down
13 changes: 9 additions & 4 deletions ui/views/view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1962,8 +1962,10 @@ bool View::ProcessMouseDragged(const ui::MouseEvent& event,
ExceededDragThreshold(drag_info->start_pt - event.location())) {
if (!drag_controller_ ||
drag_controller_->CanStartDragForView(
this, drag_info->start_pt, event.location()))
DoDrag(event, drag_info->start_pt);
this, drag_info->start_pt, event.location())) {
DoDrag(event, drag_info->start_pt,
ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
}
} else {
if (OnMouseDragged(event))
return true;
Expand Down Expand Up @@ -2131,7 +2133,9 @@ void View::UpdateTooltip() {

// Drag and drop ---------------------------------------------------------------

bool View::DoDrag(const ui::LocatedEvent& event, const gfx::Point& press_pt) {
bool View::DoDrag(const ui::LocatedEvent& event,
const gfx::Point& press_pt,
ui::DragDropTypes::DragEventSource source) {
#if !defined(OS_MACOSX)
int drag_operations = GetDragOperations(press_pt);
if (drag_operations == ui::DragDropTypes::DRAG_NONE)
Expand All @@ -2144,7 +2148,8 @@ bool View::DoDrag(const ui::LocatedEvent& event, const gfx::Point& press_pt) {
// the RootView can detect it and avoid calling us back.
gfx::Point widget_location(event.location());
ConvertPointToWidget(this, &widget_location);
GetWidget()->RunShellDrag(this, data, widget_location, drag_operations);
GetWidget()->RunShellDrag(this, data, widget_location, drag_operations,
source);
return true;
#else
return false;
Expand Down
5 changes: 4 additions & 1 deletion ui/views/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/events/event.h"
#include "ui/base/events/event_target.h"
Expand Down Expand Up @@ -1338,7 +1339,9 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// supported drag operations. When done, OnDragDone is invoked. |press_pt| is
// in the view's coordinate system.
// Returns true if a drag was started.
bool DoDrag(const ui::LocatedEvent& event, const gfx::Point& press_pt);
bool DoDrag(const ui::LocatedEvent& event,
const gfx::Point& press_pt,
ui::DragDropTypes::DragEventSource source);

//////////////////////////////////////////////////////////////////////////////

Expand Down
3 changes: 2 additions & 1 deletion ui/views/widget/desktop_native_widget_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ bool DesktopNativeWidgetAura::IsAccessibleWidget() const {
void DesktopNativeWidgetAura::RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) {
int operation,
ui::DragDropTypes::DragEventSource source) {
}

void DesktopNativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) {
Expand Down
3 changes: 2 additions & 1 deletion ui/views/widget/desktop_native_widget_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
virtual void RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) OVERRIDE;
int operation,
ui::DragDropTypes::DragEventSource source) OVERRIDE;
virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
Expand Down
5 changes: 3 additions & 2 deletions ui/views/widget/native_widget_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,9 @@ bool NativeWidgetAura::IsAccessibleWidget() const {
void NativeWidgetAura::RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) {
views::RunShellDrag(window_, data, location, operation);
int operation,
ui::DragDropTypes::DragEventSource source) {
views::RunShellDrag(window_, data, location, operation, source);
}

void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) {
Expand Down
3 changes: 2 additions & 1 deletion ui/views/widget/native_widget_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual void RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) OVERRIDE;
int operation,
ui::DragDropTypes::DragEventSource source) OVERRIDE;
virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
Expand Down
3 changes: 2 additions & 1 deletion ui/views/widget/native_widget_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget {
virtual void RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) = 0;
int operation,
ui::DragDropTypes::DragEventSource source) = 0;
virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0;
virtual void SetCursor(gfx::NativeCursor cursor) = 0;
virtual void ClearNativeFocus() = 0;
Expand Down
5 changes: 3 additions & 2 deletions ui/views/widget/native_widget_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,9 @@ bool NativeWidgetWin::IsAccessibleWidget() const {
void NativeWidgetWin::RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) {
views::RunShellDrag(NULL, data, location, operation);
int operation,
ui::DragDropTypes::DragEventSource source) {
views::RunShellDrag(NULL, data, location, operation, source);
}

void NativeWidgetWin::SchedulePaintInRect(const gfx::Rect& rect) {
Expand Down
3 changes: 2 additions & 1 deletion ui/views/widget/native_widget_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class VIEWS_EXPORT NativeWidgetWin : public internal::NativeWidgetPrivate,
virtual void RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) OVERRIDE;
int operation,
ui::DragDropTypes::DragEventSource source) OVERRIDE;
virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
Expand Down
5 changes: 3 additions & 2 deletions ui/views/widget/widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,10 @@ InputMethod* Widget::GetInputMethod() {
void Widget::RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation) {
int operation,
ui::DragDropTypes::DragEventSource source) {
dragged_view_ = view;
native_widget_->RunShellDrag(view, data, location, operation);
native_widget_->RunShellDrag(view, data, location, operation, source);
// If the view is removed during the drag operation, dragged_view_ is set to
// NULL.
if (view && dragged_view_ == view) {
Expand Down
3 changes: 2 additions & 1 deletion ui/views/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
void RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation);
int operation,
ui::DragDropTypes::DragEventSource source);

// Returns the view that requested the current drag operation via
// RunShellDrag(), or NULL if there is no such view or drag operation.
Expand Down

0 comments on commit 589b089

Please sign in to comment.