Selection should not set the cursor type to text over the explicitly set cursor type.

When tried to select some text in an area that has style
cursor:default set, cursor type changes to text cursor ignoring
the cursor style that is explicitly set.

When the cursor style is explicitly set as default(or something else),
we should not change it to text cursor no matter what we are over
or what operation we are performing (be it hovering over the text
or selecting the text).

We change the cursor type to text during selection. But if there is
an explicit cursor style set then this explicitly set cursor style
should be given priority over the text style cursor during selection.

This makes the blink behavior compatible with that of FF.
This also makes the behavior uniform within blink i.e. currently
if the area on which cursor:default is set is contenteditable, in this
particular case we do not change the cursor style to text on
selection. This should be the behavior irrespective of editability.

BUG=134999

R=eseidel, leviw, ojan, yosin

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

git-svn-id: svn://svn.chromium.org/blink/trunk@157946 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/LayoutTests/editing/caret/caret-type-for-user-select-none-expected.txt b/LayoutTests/editing/caret/caret-type-for-user-select-none-expected.txt
new file mode 100644
index 0000000..d014d0a
--- /dev/null
+++ b/LayoutTests/editing/caret/caret-type-for-user-select-none-expected.txt
@@ -0,0 +1,11 @@
+Tests whether explicitly set caret style is retained on performing text selection
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Try selecting this text by dragging the cursor. Progress cursor should be displayed while doing so.
+PASS currentCursorType is "Progress"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/editing/caret/caret-type-for-user-select-none.html b/LayoutTests/editing/caret/caret-type-for-user-select-none.html
new file mode 100644
index 0000000..5fc0d82
--- /dev/null
+++ b/LayoutTests/editing/caret/caret-type-for-user-select-none.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p id="description"></p>
+<div style="cursor:progress; border: 2px solid red;" id="test">Try selecting this text by dragging the cursor. Progress cursor should be displayed while doing so.</div>
+<div id="console"></div>
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script>
+if (window.eventSender && window.internals) {
+    description('Tests whether explicitly set caret style is retained on performing text selection');
+
+    var div = document.getElementById("test");
+    div.focus();
+
+    var y = div.offsetTop + div.offsetHeight / 2;
+
+    function leapForwardAndMove(x) {
+        eventSender.leapForward(200);
+        eventSender.mouseMoveTo(div.offsetLeft + x, y);
+    }
+
+    eventSender.dragMode = false;
+    leapForwardAndMove(div.offsetLeft + 5, y);
+    eventSender.mouseDown();
+
+    leapForwardAndMove(10);
+
+    leapForwardAndMove(div.offsetWidth - 10);
+
+    var cursorInfo = window.internals.getCurrentCursorInfo(document);
+    var currentCursorType = cursorInfo.substring(cursorInfo.indexOf('=') + 1, cursorInfo.lastIndexOf(' '));
+    shouldBeEqualToString('currentCursorType', 'Progress');
+}
+</script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/Source/core/page/EventHandler.cpp b/Source/core/page/EventHandler.cpp
index 3a76fe3..f91e478 100644
--- a/Source/core/page/EventHandler.cpp
+++ b/Source/core/page/EventHandler.cpp
@@ -1105,13 +1105,6 @@
     bool horizontalText = !style || style->isHorizontalWritingMode();
     const Cursor& iBeam = horizontalText ? iBeamCursor() : verticalTextCursor();
 
-    // During selection, use an I-beam no matter what we're over.
-    // If a drag may be starting or we're capturing mouse events for a particular node, don't treat this as a selection.
-    if (m_mousePressed && m_mouseDownMayStartSelect
-        && !m_mouseDownMayStartDrag
-        && m_frame->selection().isCaretOrRange() && !m_capturingMouseEventsNode)
-        return iBeam;
-
     if (renderer) {
         Cursor overrideCursor;
         switch (renderer->getCursor(roundedIntPoint(event.localPoint()), overrideCursor)) {
@@ -1168,6 +1161,16 @@
                     inResizer = layer->isPointInResizeControl(view->windowToContents(event.event().position()), ResizerForPointer);
             }
         }
+
+        // During selection, use an I-beam no matter what we're over.
+        // If a drag may be starting or we're capturing mouse events for a particular node, don't treat this as a selection.
+        if (m_mousePressed && m_mouseDownMayStartSelect
+            && !m_mouseDownMayStartDrag
+            && m_frame->selection().isCaretOrRange()
+            && !m_capturingMouseEventsNode) {
+            return iBeam;
+        }
+
         if ((editable || (renderer && renderer->isText() && node->canStartSelection())) && !inResizer && !scrollbar)
             return iBeam;
         return pointerCursor();