Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 268402

Summary: [Forms] FormText links do not erase focus ring
Product: [Eclipse Project] Platform Reporter: Grant Gayed <grant_gayed>
Component: User AssistanceAssignee: Chris Goldthorpe <cgold>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: bhunt, cgold, cocoakevin, contact, Curtis_Windatt, eclipse.felipe, markus.kell.r, remy.suen, skovatch
Version: 3.5   
Target Milestone: 3.7 M5   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
Fix
none
Fix 2 none

Description Grant Gayed CLA 2009-03-12 14:26:55 EDT
I20090310-0100

- open an eclipse project's META-INF/MANIFEST.MF
- tab through the controls and note that no focus ring is shown when focus is on links like "Dependencies" and "Runtime" (it can be inferred that these links do have focus because their texts are shown in eclipse's status line at the very bottom)
  -> on other platforms each link within a Link (eg.- "eclipse.org" and "SWT" in ControlExample) take and show focus independently
Comment 1 Scott Kovatch CLA 2009-04-22 00:34:44 EDT
The focus is now being drawn but it doesn't erase when focus leaves the link. Then, when focus returns to the link it redraws and makes the focus darker.
Comment 2 Kevin Barnes CLA 2009-06-24 15:49:20 EDT
Those aren't Link widgets, they're FormText objects.
Comment 3 Kevin Barnes CLA 2009-06-25 17:02:31 EDT
my test case (requires org.eclipse.ui.forms):

	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);

		FormText text = new FormText(shell, SWT.NONE);
		text.setText("<form>" +
				"<li style=\"image\"><a href=\"one\">one</a></li>" +
				"<li style=\"image\"><a href=\"two\">two</a></li>" +
				"<li style=\"image\"><a href=\"one\">three</a></li>" +
				"<li style=\"image\"><a href=\"one\">four</a></li>" +
				"<li style=\"image\"><a href=\"one\">five</a></li>" +
				"</form>", true, false);
		text.pack();
		
		
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
Comment 4 Kevin Barnes CLA 2009-06-25 17:23:44 EDT
Same bug happens on carbon. 
When the link text is selected, GC.drawFocus is called. When it's unselected, GC.drawRectangle() is called to cover the focus ring. Problem is that on mac the focus ring is more than one pixel so it isn't getting covered.
Comment 5 Benjamin Cabé CLA 2009-06-25 17:30:46 EDT
Kevin, any reason you're reassigning to PDE/UI ? It's very likely a Forms (Platform/UA) issue, no?..
Comment 6 Kevin Barnes CLA 2009-06-25 21:11:22 EDT
didn't realize there was a difference.
Comment 7 Remy Suen CLA 2009-10-27 13:55:52 EDT
This bug is killing me eyes on Windows XP. Halp! ;_;
Comment 8 Chris Goldthorpe CLA 2010-04-19 16:57:21 EDT
What platforms are people seeing the non erasure of the focus ring on? I just tried XP and did not see it.
Comment 9 Markus Keller CLA 2010-04-21 13:58:02 EDT
I only saw it on the Mac (Cocoa, probably also Carbon). WinXP looks fine for me.

The problem is in TextSegment#paintFocus(GC, Color, Color, boolean, Rectangle) and probably other similar places. The assumption that gc.drawRectangle(..) can be used to revert gc.drawFocus(..) is not valid on the Mac.

I quickly hacked FormText#paintFocusTransfer(..) like this, and that solved the issue (but that's not to say that I want you to release this hack):

//			oldLink.paintFocus(gc, bg, fg, false, null);
			Rectangle r = oldLink.getBounds();
			redraw(r.x, r.y, r.width, r.height, true);
			update();
Comment 10 Markus Keller CLA 2010-09-03 03:24:09 EDT
Created attachment 178123 [details]
Fix

(In reply to comment #9)
Actually, I think this is the correct way to fix this bug. Here's a patch.
Comment 11 Remy Suen CLA 2010-10-25 08:34:10 EDT
Any chance of getting this fixed in 3.7?
Comment 12 Chris Goldthorpe CLA 2010-10-26 13:04:29 EDT
Yes, I will work on getting Markus's patch into the next milestone.
Comment 13 Markus Keller CLA 2010-10-26 14:49:55 EDT
*** Bug 234300 has been marked as a duplicate of this bug. ***
Comment 14 Markus Keller CLA 2010-10-26 15:06:24 EDT
Created attachment 181759 [details]
Fix 2

The fix in FormText was OK, but bounds calculation of wrapped paragraphs was also screwed, so the first fix didn't work in all cases (can e.g. be seen on the Overview page of the plugin.xml editor).

Even with this fix, we still have problems with:
- mouse hovering over links (link becomes darker and darker, was OK in 3.6.1)
- jumpy text when you select it (already broken in 3.6.1)
Comment 15 Chris Goldthorpe CLA 2010-12-15 13:27:19 EST
Markus's patch does fix the focus problem on Mac and I did not see any regressions on other platforms when testing. 

Patch committed to HEAD, Fixed.