Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Automated g4 rollback of changelist 111522388.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Bringing original changes back

*** Original change description ***

Automated g4 rollback of changelist 111352260.

*** Reason for rollback ***

Breaks Gmail

*** Original change description ***

Allow further propagation of `mousedown` event for draggable elements.

There is currently an issue when default mousedown event gets cancelled for
draggable elements.
Consider an example when you have a draggable div with some
input inside. If you click on input, it won't get focus and you won't be able
to type anything, because focus is a default ev...

***
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=111525196
  • Loading branch information
concavelenz authored and joeltine committed Jan 7, 2016
1 parent 623d4c8 commit c098440
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion closure/goog/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions closure/goog/fx/abstractdragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -1404,8 +1404,6 @@ goog.fx.DragDropItem.prototype.maybeStartDrag_ = function(event, element) {

this.startPosition_ = new goog.math.Coordinate(
event.clientX, event.clientY);

event.preventDefault();
};


Expand All @@ -1432,6 +1430,9 @@ goog.fx.DragDropItem.prototype.mouseMove_ = function(event) {
this.eventHandler_.removeAll();
this.parent_.startDrag(event, this);
}

// Prevent text selection while dragging an element.
event.preventDefault();
};


Expand Down
31 changes: 27 additions & 4 deletions closure/goog/fx/abstractdragdrop_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ goog.require('goog.math.Box');
goog.require('goog.math.Coordinate');
goog.require('goog.style');
goog.require('goog.testing.events');
goog.require('goog.testing.events.Event');
goog.require('goog.testing.jsunit');

var targets = [
Expand Down Expand Up @@ -507,6 +508,22 @@ function testScrollableContainersCalculation() {
assertEquals(container, group.targetList_[1].scrollableContainer_);
}

function testMouseDownEventDefaultAction() {
var group = new goog.fx.AbstractDragDrop();
var target = new goog.fx.AbstractDragDrop();
group.addTarget(target);
var item1 = new goog.fx.DragDropItem(document.getElementById('child1'));
group.items_.push(item1);
item1.setParent(group);
group.init();

var mousedownDefaultPrevented =
!goog.testing.events.fireMouseDownEvent(item1.element);

assertFalse('Default action of mousedown event should not be cancelled.',
mousedownDefaultPrevented);
}

// See http://b/7494613.
function testMouseUpOutsideElement() {
var group = new goog.fx.AbstractDragDrop();
Expand Down Expand Up @@ -583,14 +600,20 @@ function testMouseMove_mouseOutBeforeThreshold() {
draggedItem = item;
};

var event = {'clientX': 8, 'clientY': 10, // Drag distance is only 2
'type': goog.events.EventType.MOUSEOUT, 'target': childEl};
var event = new goog.testing.events.Event(goog.events.EventType.MOUSEOUT,
childEl);
// Drag distance is only 2.
event.clientX = 8;
event.clientY = 10;
item.mouseMove_(event);
assertEquals('DragStart should not be fired for mouseout on child element.',
null, draggedItem);

var event = {'clientX': 8, 'clientY': 10, // Drag distance is only 2
'type': goog.events.EventType.MOUSEOUT, 'target': itemEl};
var event = new goog.testing.events.Event(goog.events.EventType.MOUSEOUT,
itemEl);
// Drag distance is only 2.
event.clientX = 8;
event.clientY = 10;
item.mouseMove_(event);
assertEquals('DragStart should be fired for mouseout on main element.',
item, draggedItem);
Expand Down

0 comments on commit c098440

Please sign in to comment.