Closed Bug 380364 Opened 18 years ago Closed 18 years ago

when I right click on tinderbox, I get "Search Google for <tr></tr>"

Categories

(Core :: DOM: Serializers, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: moco, Assigned: codedread)

References

()

Details

(Keywords: regression, testcase)

Attachments

(6 files, 2 obsolete files)

when I right click on tinderbox, I get "Search Google for <tr></tr>"

steps to reproduce:

1) go to http://tinderbox.mozilla.org/showbuilds.cgi?tree=Firefox
2) right click

here comes a screen shot.
actually, you may need to try to right click on a name in "Guilty" column first.

but once in this state, right clicking anywhere on tinderbox seems to cause the problem.
Attached image screen shot of the bug
note, I'm using my own trunk, debug build:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a5pre) Gecko/20070510 Minefield/3.0a5pre

This seems like a regression with window.getSelection(). The browser uses it to get the selected text and generate the context menu. With a trunk build, after clicking on an empty space in the "guilty" column, running "javascript:alert(window.getSelection())" gives me "<tr></tr>", while on a branch build it gives me a blank string.
Keywords: regression
I also see this on Linux (20070510 nightly trunk build), not just on tinderbox but on other pages as well. Seems to be triggered by "selecting" an empty table cell, as Gavin already noted. Selecting non-empty cells leads to: Search Google for "<tr></tr>..." (replace the dots with the beginning of the cell contents).
OS: Windows XP → All
Hardware: PC → All
Attached file simple testcase
Trivial testcase to reproduce the bug: left click on the space between "A" and "B", then right click to get context menu
Regression range: 2007-03-27-04-trunk (ok) - 2007-03-28-04-trunk (bug)

Looking at the checkins in this range points to the fix for bug 236546 as a likely regression cause, so marking as blocking and updating component accordingly.
Assignee: nobody → dom-to-text
Blocks: 236546
Component: General → DOM to Text Conversion
Keywords: testcase
Product: Firefox → Core
QA Contact: general
Yep, this is a regression of bug 236546.

Question:  Why is the branch behavior such that left-clicking an empty table cell causes the string selection to be an empty string?  Is this desired behavior?
Status: NEW → ASSIGNED
Assignee: dom-to-text → codedread
Status: ASSIGNED → NEW
This is also happening on CNN.com's latest news headline links
Attached patch First attempt at patch (obsolete) — Splinter Review
This patch ensures that the only time we inject <tr></tr> tags is in an HTML serialization.  This works as expected for HTML, but for the XHTML test case.  In XHTML table cell selection, it appears that mMimeType in nsDocumentEncoder is set to "text/plain".  Does anyone know why?
Clarification (due to typo):  This patch works for HTML, but not for XHTML.

Shouldn't the MIME type of an XHTML be set to "application/xhtml+xml" or at least "text/html" instead of "text/plain" ?
Comment on attachment 265634 [details] [diff] [review]
First attempt at patch

>Index: nsDocumentEncoder.cpp
>===================================================================
>RCS file: /cvsroot/mozilla/content/base/src/nsDocumentEncoder.cpp,v
>retrieving revision 1.120
>diff -u -8 -p -r1.120 nsDocumentEncoder.cpp
>--- nsDocumentEncoder.cpp	27 Mar 2007 15:10:23 -0000	1.120
>+++ nsDocumentEncoder.cpp	22 May 2007 05:42:22 -0000
>@@ -900,46 +900,49 @@ nsDocumentEncoder::EncodeToString(nsAStr
>     PRInt32 i, count = 0;
> 
>     rv = mSelection->GetRangeCount(&count);
>     NS_ENSURE_SUCCESS(rv, rv);
> 
>     nsCOMPtr<nsIDOMNode> node, prevNode;
>     nsCOMPtr<nsIContent> content;
>     PRBool bTableCellsFound = PR_FALSE;
>+    PRBool bIsHTML = mMimeType.Equals(NS_LITERAL_STRING("text/html")) || 
>+                     mMimeType.Equals(NS_LITERAL_STRING("application/xhtml+xml"));

I don't think our encoder code knows anything about XHTML yet, so it should be ok to just deal with text/html here. Note that this mimetype isn't representing the mimetype of the data we're encoding, it represents the mimetype of the output we're creating, and we don't have an XHTML encoder yet that I know of.

r+sr=jst with that changed.
Attachment #265634 - Flags: superreview+
Attachment #265634 - Flags: review+
jst, i checked through this a little, it seems that for XHTML documents, the Mime Type of the nsSelection is being set to text/plain because of the following line in nsHTMLCopyEncoder::SetSelection():

  if (!htmlDoc || mDocument->IsCaseSensitive())
    mIsTextWidget = PR_TRUE;

In this case, for XHTML documents, mDocument->IsCaseSensitive() is true.  Looks like bzbarsky made this change a few years ago:

http://bonsai.mozilla.org/cvsview2.cgi?diff_mode=context&whitespace_mode=show&root=/cvsroot&subdir=mozilla/content/base/src&command=DIFF_FRAMESET&file=nsDocumentEncoder.cpp&rev2=1.102&rev1=1.101

I'm tempted to remove this condition, but I have no idea why it was made (can't seem to figure out how to get a Bug # from it).

Btw, I also wondered if overriding nsDocumentEncoder::EncodeToString() in nsHTMLCopyEncoder would be a better idea instead of checking the Mime Type like that.
> Note that this mimetype isn't representing
> the mimetype of the data we're encoding, it 
> represents the mimetype of the output we're 
> creating, and we don't have an XHTML encoder 
> yet that I know of

Can't we just create HTML output from XHTML selections?  
Ok, here's bzbarsky's change: http://bonsai.mozilla.org/cvslog.cgi?file=mozilla/content/base/src/nsDocumentEncoder.cpp&rev=1.102 and it deals with Bug 270145
Attached patch Patch with jst's comments (obsolete) — Splinter Review
Updated with jst's comments
Attachment #265634 - Attachment is obsolete: true
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
> Can't we just create HTML output from XHTML selections?  

No.  Some XHTML documents can create DOMs that cannot be serialized as HTML.  So this patch is probably the way to go.

Is there a reason the patch doesn't use EqualsLiteral()?
> Is there a reason the patch doesn't use EqualsLiteral()?

Yes, the reason is ignorance on my part ;)

I notice that other sections of the code use LowerCaseEqualsLiteral(), that probably should be the real fix.  I'm confused by the process - if the Bug is marekd "RESOLVED FIXED", can I still submit a patch for it?
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attachment #265756 - Attachment is obsolete: true
Status: REOPENED → ASSIGNED
Comment on attachment 265759 [details] [diff] [review]
Uses LowerCaseEqualsLiteral()

You probably want a diff against the current trunk (with the previous patch checked in), right?  And yes, just putting this followup on this bug is fine.  Thanks for doing it!
Boris - the patch never was checked in, I erroneously marked it as "FIXED" earlier.  This patch still needs to be applied, and it is against the current trunk.
Ah, ok.  That last patch should be good to go then -- it looks good to me, and the r+sr=jst probably stands.
Whiteboard: [checkin needed]
Ok, but I need someone else to check it in, I don't have that power...
That's what the [checkin needed] marker in the status whiteboard is for - some people regularly search for that and check in patches that need checking in. Alternatively, you can find someone on IRC to land this for you.
This code is more generic so is less likely to go wrong if someone changes the way the encoders work or even implements a new encoder.
Comment on attachment 265860 [details] [diff] [review]
My take on the fix

This should work too, r+sr=jst for this one as well.
Attachment #265860 - Flags: superreview+
Attachment #265860 - Flags: review+
Ok, it looks like the last patch by Neil was checked in apparently.  Do I just resolve the bug and mark it Fixed?
Yes (I'm doing that now), this was probably just an oversight.

Fixed with Neil's patch in:

mozilla/content/base/src/nsDocumentEncoder.cpp 	1.121   (2007-05-25 13:47)
Status: ASSIGNED → RESOLVED
Closed: 18 years ago18 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: