--- old/src/java.desktop/windows/native/libawt/windows/awt_TextArea.cpp 2016-03-13 02:36:19.579433000 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_TextArea.cpp 2016-03-13 02:36:19.307297000 +0530 @@ -225,31 +225,18 @@ /* * We consume WM_MOUSEMOVE while the left mouse button is pressed, - * so we have to simulate autoscrolling when mouse is moved outside - * of the client area. + * so we have to simulate selection autoscrolling when mouse is moved + * outside of the client area. */ POINT p; RECT r; - BOOL bScrollLeft = FALSE; - BOOL bScrollRight = FALSE; - BOOL bScrollUp = FALSE; BOOL bScrollDown = FALSE; p.x = msg->pt.x; p.y = msg->pt.y; VERIFY(::GetClientRect(GetHWnd(), &r)); - if (p.x < 0) { - bScrollLeft = TRUE; - p.x = 0; - } else if (p.x > r.right) { - bScrollRight = TRUE; - p.x = r.right - 1; - } - if (p.y < 0) { - bScrollUp = TRUE; - p.y = 0; - } else if (p.y > r.bottom) { + if (p.y > r.bottom) { bScrollDown = TRUE; p.y = r.bottom - 1; } @@ -269,32 +256,7 @@ EditSetSel(cr); } - - if (bScrollLeft == TRUE || bScrollRight == TRUE) { - SCROLLINFO si; - memset(&si, 0, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; - - VERIFY(::GetScrollInfo(GetHWnd(), SB_HORZ, &si)); - if (bScrollLeft == TRUE) { - si.nPos = si.nPos - si.nPage / 2; - si.nPos = max(si.nMin, si.nPos); - } else if (bScrollRight == TRUE) { - si.nPos = si.nPos + si.nPage / 2; - si.nPos = min(si.nPos, si.nMax); - } - /* - * Okay to use 16-bit position since RichEdit control adjusts - * its scrollbars so that their range is always 16-bit. - */ - DASSERT(abs(si.nPos) < 0x8000); - SendMessage(WM_HSCROLL, - MAKEWPARAM(SB_THUMBPOSITION, LOWORD(si.nPos))); - } - if (bScrollUp == TRUE) { - SendMessage(EM_LINESCROLL, 0, -1); - } else if (bScrollDown == TRUE) { + if (bScrollDown == TRUE) { SendMessage(EM_LINESCROLL, 0, 1); } delete msg; --- old/src/java.desktop/windows/native/libawt/windows/awt_TextField.cpp 2016-03-13 02:36:20.111699000 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_TextField.cpp 2016-03-13 02:36:19.891589000 +0530 @@ -157,27 +157,12 @@ /* * We consume WM_MOUSEMOVE while the left mouse button is pressed, - * so we have to simulate autoscrolling when mouse is moved outside - * of the client area. + * so we have to simulate selection autoscrolling when mouse is moved + * outside of the client area. */ POINT p; - RECT r; - BOOL bScrollLeft = FALSE; - BOOL bScrollRight = FALSE; - BOOL bScrollUp = FALSE; - BOOL bScrollDown = FALSE; - p.x = msg->pt.x; p.y = msg->pt.y; - VERIFY(::GetClientRect(GetHWnd(), &r)); - - if (p.x < 0) { - bScrollLeft = TRUE; - p.x = 0; - } else if (p.x > r.right) { - bScrollRight = TRUE; - p.x = r.right - 1; - } LONG lCurPos = EditGetCharFromPos(p); if (GetStartSelectionPos() != -1 && @@ -193,32 +178,6 @@ EditSetSel(cr); } - - if (bScrollLeft == TRUE || bScrollRight == TRUE) { - SCROLLINFO si; - memset(&si, 0, sizeof(si)); - si.cbSize = sizeof(si); - si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; - - SendMessage(EM_SHOWSCROLLBAR, SB_HORZ, TRUE); - VERIFY(::GetScrollInfo(GetHWnd(), SB_HORZ, &si)); - SendMessage(EM_SHOWSCROLLBAR, SB_HORZ, FALSE); - - if (bScrollLeft == TRUE) { - si.nPos = si.nPos - si.nPage / 2; - si.nPos = max(si.nMin, si.nPos); - } else if (bScrollRight == TRUE) { - si.nPos = si.nPos + si.nPage / 2; - si.nPos = min(si.nPos, si.nMax); - } - /* - * Okay to use 16-bit position since RichEdit control adjusts - * its scrollbars so that their range is always 16-bit. - */ - DASSERT(abs(si.nPos) < 0x8000); - SendMessage(WM_HSCROLL, - MAKEWPARAM(SB_THUMBPOSITION, LOWORD(si.nPos))); - } delete msg; return mrConsume; } else if (msg->message == WM_KEYDOWN) { --- old/test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java 2016-03-13 02:36:20.635961000 +0530 +++ new/test/java/awt/TextField/ScrollSelectionTest/ScrollSelectionTest.java 2016-03-13 02:36:20.407847000 +0530 @@ -23,23 +23,17 @@ /* test - @bug 4118621 - @summary tests that selected text isn't scrolled when there is enough room. - @author prs: area=TextField + @bug 4118621 8149636 + @summary Test the selection scrolling in TextField. @run applet/manual=yesno ScrollSelectionTest.html */ -/** - * ScrollSelectionTest.java - * - * summary: tests that selected text isn't scrolled when there is enough room. - */ - import java.applet.Applet; import java.awt.Dialog; import java.awt.Frame; import java.awt.TextField; import java.awt.TextArea; +import java.awt.FlowLayout; public class ScrollSelectionTest extends Applet { @@ -51,15 +45,23 @@ { tf.setText("abcdefghijklmnopqrstuvwxyz"); frame.add(tf); + frame.setLayout(new FlowLayout()); tf.select(0, 20); String[] instructions = { - "INSTRUCTIONS:", + "INSTRUCTIONS: There are 2 Tests", + "Test1: Text visibility with Scroll", "This is a test for a win32 specific problem", - "If you see all the letters from 'a' to 'z' and", + "If you see all the letters from 'a' to 'z' and", "letters from 'a' to 't' are selected then test passes.", - "You may have to activate the frame to see the selection" - + " highlighted (e.g. by clicking on frame's title)." + "You may have to activate the frame to see the selection", + "highlighted (e.g. by clicking on frame's title).", + ".", + "Test2: Flicker with selection scroll", + "Mouse press on the TextField text.", + "Move mouse towards left or right with selecting text.", + "Move mouse away outside the bounds of TextField.", + "No flicker should be observed.", }; Sysout.createDialogWithInstructions( instructions ); @@ -67,11 +69,11 @@ public void start () { - setSize (300,300); + setSize (300, 500); setVisible(true); frame.setVisible(true); - frame.setBounds (400, 0, 300, 300); + frame.setBounds (400, 0, 400, 300); }// start() --- /dev/null 2016-03-13 02:29:30.092247000 +0530 +++ new/test/java/awt/TextArea/OverScrollTest/OverScrollTest.java 2016-03-13 02:36:20.924105000 +0530 @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + @test + @bug 8149636 + @summary TextArea over scrolls to right when selecting text towards right. + @requires os.family == "windows" + @run main OverScrollTest + */ + +import java.awt.Frame; +import java.awt.FlowLayout; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.TextArea; +import java.awt.event.InputEvent; + +public class OverScrollTest { + Frame mainFrame; + TextArea textArea; + Robot robot; + + OverScrollTest() { + mainFrame = new Frame(); + mainFrame.setSize(400, 200); + mainFrame.setLocation(200, 200); + mainFrame.setLayout(new FlowLayout()); + + textArea = new TextArea(2, 10); + textArea.setSize(300, 100); + textArea.setText("123456 789123"); + mainFrame.add(textArea); + mainFrame.setVisible(true); + textArea.requestFocusInWindow(); + + try { + robot = new Robot(); + robot.setAutoWaitForIdle(true); + } catch (Exception ex) { + dispose(); + System.exit(0); + throw new RuntimeException("Robot Creation Failed"); + } + } + + public void dispose() { + if (mainFrame != null) { + mainFrame.dispose(); + } + } + + public void performTest() { + Point loc = textArea.getLocationOnScreen(); + Rectangle textAreaBounds = new Rectangle(); + textArea.getBounds(textAreaBounds); + + // Move mouse at center in first row of TextArea. + robot.mouseMove(loc.x + textAreaBounds.width / 2, loc.y + 5); + + // Perform selection by scrolling to right from end of char sequence. + robot.mousePress(InputEvent.BUTTON1_MASK); + for (int i = 0; i < textAreaBounds.width; i += 15) { + robot.mouseMove(i + loc.x + textAreaBounds.width / 2, loc.y + 5); + robot.delay(10); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.waitForIdle(); + + // Perform double click on beginning word of TextArea + robot.mouseMove(loc.x + 5, loc.y + 5); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.delay(100); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.delay(100); + robot.waitForIdle(); + + if (!textArea.getSelectedText().contains("123456")) { + dispose(); + throw new RuntimeException ("TextArea over scrolled towards right" + + "Expected selected text should contain: '123456'"); + } + } + + public static void main(String argv[]) throws RuntimeException { + OverScrollTest test = new OverScrollTest(); + test.performTest(); + test.dispose(); + } +} --- /dev/null 2016-03-13 02:29:30.092247000 +0530 +++ new/test/java/awt/TextField/OverScrollTest/OverScrollTest.java 2016-03-13 02:36:21.408346999 +0530 @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + @test + @bug 8149636 + @summary TextField over scrolls to right when selecting text towards right. + @requires os.family == "windows" + @run main OverScrollTest + */ + +import java.awt.Frame; +import java.awt.FlowLayout; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.TextField; +import java.awt.event.InputEvent; + +public class OverScrollTest { + Frame mainFrame; + TextField textField; + Robot robot; + + OverScrollTest() { + mainFrame = new Frame(); + mainFrame.setSize(400, 200); + mainFrame.setLocation(200, 200); + mainFrame.setLayout(new FlowLayout()); + + textField = new TextField(8); + textField.setSize(300, 100); + textField.setText("123456 789123"); + mainFrame.add(textField); + mainFrame.setVisible(true); + textField.requestFocusInWindow(); + + try { + robot = new Robot(); + robot.setAutoWaitForIdle(true); + } catch (Exception ex) { + dispose(); + System.exit(0); + throw new RuntimeException("Robot Creation Failed"); + } + } + + public void dispose() { + if (mainFrame != null) { + mainFrame.dispose(); + } + } + + public void performTest() { + Point loc = textField.getLocationOnScreen(); + Rectangle textFieldBounds = new Rectangle(); + textField.getBounds(textFieldBounds); + + // Move mouse at center in first row of TextField. + robot.mouseMove(loc.x + textFieldBounds.width / 2, loc.y + 5); + + // Perform selection by scrolling to right from end of char sequence. + robot.mousePress(InputEvent.BUTTON1_MASK); + for (int i = 0; i < textFieldBounds.width; i += 15) { + robot.mouseMove(i + loc.x + textFieldBounds.width / 2, loc.y + 5); + robot.delay(10); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.waitForIdle(); + + // Perform double click on beginning word of TextField + robot.mouseMove(loc.x + 5, loc.y + 5); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.delay(100); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + robot.delay(100); + robot.waitForIdle(); + + if (!textField.getSelectedText().contains("123456")) { + dispose(); + throw new RuntimeException ("TextField over scrolled towards right" + + "Expected selected text should contain: '123456'"); + } + } + + public static void main(String argv[]) throws RuntimeException { + OverScrollTest test = new OverScrollTest(); + test.performTest(); + test.dispose(); + } +}