Closed Bug 727765 Opened 13 years ago Closed 12 years ago

[Page Thumbnails] thumbnails sometimes have a black border at the right

Categories

(Firefox :: Tabbed Browser, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 22

People

(Reporter: ttaubert, Assigned: ttaubert)

References

Details

Attachments

(6 files, 7 obsolete files)

662.84 KB, image/png
Details
82 bytes, text/html
Details
63 bytes, text/html
Details
483.47 KB, image/png
Details
12.00 KB, patch
jaws
: review+
Details | Diff | Splinter Review
8.73 KB, patch
jaws
: review+
Details | Diff | Splinter Review
We need to take any kind of scrollbar into account when capturing screenshots.
Assignee: nobody → raymond
Status: NEW → ASSIGNED
Attached patch v1 (obsolete) — Splinter Review
This patch should detect when the vertical and horizontal scrollbars appear and then remove the scrollbar width if needed.
Attachment #615291 - Flags: review?(ttaubert)
When exactly and why do scrollbars cause a black border?
Attached patch v2 (obsolete) — Splinter Review
(In reply to Dão Gottwald [:dao] from comment #2) > When exactly and why do scrollbars cause a black border? In order to draw the window content to a canvas, we would need to width and height of the content. We are using the innerWidth and innerHeight from the contentWindow but that would include the scrollbars if they appear, and the ctx.drawWindow couldn't the scrollbars because they are not part of the dom content. I have updated the code to use document.body.clientHeight/Width which should exclude the scrollbars. However, not all content has document.body so innerHeight/Width would be used in that case.
Attachment #615291 - Attachment is obsolete: true
Attachment #615608 - Flags: review?(ttaubert)
Attachment #615291 - Flags: review?(ttaubert)
I know that we've had the same problems with Panorama and Asa once showed me a newtab page with multiple thumbnails having a block border at the right. Alas, I'm unable to come up with a manual test right now... Raymond, can you please write a test for this? So that we can be sure this problem actually exists and we fixed it. We will probably need some combination of a specific page size and browser window size. browser/components/thumbnails/test/head.js contains all the functions you need to capture a thumbnail for a given page and how to check the pixel colors.
Attached image Manual test screenshot
For manual tests, I have created two html pages: one with scrollbars (style="overflow: scroll;") and one without. You can see the screenshot that there is a light grey bar appears on the right on the one with scrollbar. If you don't see that, you would need to enlarge the window and it would appear.
Attachment #622278 - Attachment description: Test with scrollbars → Test page with scrollbars
Attached patch v3 (obsolete) — Splinter Review
Added tests
Attachment #615608 - Attachment is obsolete: true
Attachment #622313 - Flags: review?(ttaubert)
Attachment #615608 - Flags: review?(ttaubert)
Comment on attachment 622313 [details] [diff] [review] v3 After applying this patch, browser/components/tabview/test/browser_tabview_bug594958.js fails and investigating now
Attachment #622313 - Flags: review?(ttaubert)
Attached patch v3 (obsolete) — Splinter Review
Attachment #622313 - Attachment is obsolete: true
Comment on attachment 622329 [details] [diff] [review] v3 I have spent some time trying to figure out why this patch affects browser/components/tabview/test/browser_tabview_bug594958.js, however, I couldn't find a connection between capturing code in PageThumbs and drawing canvas code in TabView. However, if I delay the checking of checkUrl(test) in browser_tabview_bug594958, the tests pass. Therefore, it might be a timing issue. diff --git a/browser/components/tabview/test/browser_tabview_bug594958.js b/browser/components/tabview/test/browser_tabview_bug594958.js --- a/browser/components/tabview/test/browser_tabview_bug594958.js +++ b/browser/components/tabview/test/browser_tabview_bug594958.js @@ -56,17 +56,17 @@ function test() { let browser = tab.linkedBrowser; browser.addEventListener("load", function onLoad(event) { browser.removeEventListener("load", onLoad, true); let tabItem = tab._tabViewTabItem; tabItem.addSubscriber("updated", function onUpdated() { tabItem.removeSubscriber("updated", onUpdated); - checkUrl(test); + setTimeout(function() { checkUrl(test); }, 1000); }); }, true); browser.loadURI(test.url); } @Tim: do you see any reasons what cause the problem?
Comment on attachment 622329 [details] [diff] [review] v3 Review of attachment 622329 [details] [diff] [review]: ----------------------------------------------------------------- ::: browser/components/thumbnails/PageThumbs.jsm @@ +177,5 @@ > * @param aWindow The content window. > * @return An array containing width, height and scale. > */ > _determineCropSize: function PageThumbs_determineCropSize(aWindow) { > + let body = aWindow.document.body; This should better be |let body = aWindow.document && aWindow.document.body| ::: browser/components/thumbnails/test/Makefile.in @@ +20,4 @@ > head.js \ > background_red.html \ > background_red_redirect.sjs \ > + with_scrollbars.html \ capture_with_scrollbars.html might be a better name for that. ::: browser/components/thumbnails/test/browser_thumbnails_bug727765.js @@ +1,1 @@ > +const URL = "http://mochi.test:8888/browser/browser/components/thumbnails/" + We're missing the public license header here. @@ +1,5 @@ > +const URL = "http://mochi.test:8888/browser/browser/components/thumbnails/" + > + "test/with_scrollbars.html"; > + > +/** > + * These tests ensure that thumbnails don't have right border created by scrollbar. Nit: "right borders" @@ +9,5 @@ > + yield addTab(URL); > + // Wait until the thumbnail's file has been written. > + yield whenFileExists(URL); > + // Check the thumbnail color of the bottom right pixel. > + yield checkThumbnailColor(URL, 255, 0, 0, "It has a red thumbnail with no border on the right"); Better: "we have a red thumbnail..." @@ +12,5 @@ > + // Check the thumbnail color of the bottom right pixel. > + yield checkThumbnailColor(URL, 255, 0, 0, "It has a red thumbnail with no border on the right"); > +} > + > +function whenFileExists(aURL) { This is now the third test that needs this function (also _storage.js and _redirect.js). We should move that to head.js and include the |file.fileSize| check from _storage.js.
(In reply to Raymond Lee [:raymondlee] from comment #11) > @Tim: do you see any reasons what cause the problem? So, interestingly, if you insert: > let foo = win.document.body.clientWidth; before this line here: http://mxr.mozilla.org/mozilla-central/source/browser/components/tabview/tabitems.js#1458 then window.innerWidth will return a different value. This is probably because accessing clientWidth flushes pending layout changes - which is a resize of the window in this case.
Attached patch v4 (obsolete) — Splinter Review
Updated the patch based on #comment 12
Attachment #622329 - Attachment is obsolete: true
(In reply to Tim Taubert [:ttaubert] from comment #13) > (In reply to Raymond Lee [:raymondlee] from comment #11) > > @Tim: do you see any reasons what cause the problem? > > So, interestingly, if you insert: > > > let foo = win.document.body.clientWidth; > > before this line here: > > http://mxr.mozilla.org/mozilla-central/source/browser/components/tabview/ > tabitems.js#1458 > > then window.innerWidth will return a different value. This is probably > because accessing clientWidth flushes pending layout changes - which is a > resize of the window in this case. Although the clientWidth would trigger layout changes, it still doesn't fix the issues browser_tabview_bug594958.js. I am still not able to figure out the root cause :S
Unfortunately this bug stalled 5 months ago - what is missing to bring it to review? (Here's a screenshot from the current Aurora Windows build)
Tim, Raymond, is the screenshot in Thomas' attachment the same issue as this bug? If so, I was just going to report this. It's a rather glaring bug. Are either of you able to dig further into it?
(In reply to Asa Dotzler [:asa] from comment #17) > Tim, Raymond, is the screenshot in Thomas' attachment the same issue as this > bug? If so, I was just going to report this. It's a rather glaring bug. Are > either of you able to dig further into it? Yes, this looks exactly like this bug. I won't have time to investigate this... Raymond?
Status: ASSIGNED → NEW
Depends on: 672474
Stealing.
Assignee: raymond → ttaubert
Attachment #626868 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Comment on attachment 713361 [details] [diff] [review] part 1 - use nsIDOMWindowUtils.getScrollbarWidth() to avoid black borders at the right Tiny fix. The session store code added to head.js is because of the asynchronous read of sessionstore.js that somehow makes single tests fail (sometimes).
Attachment #713361 - Flags: review?(jwein)
Attachment #713361 - Attachment description: use nsIDOMWindowUtils.getScrollbarWidth() to avoid black borders at the right → part 1 - use nsIDOMWindowUtils.getScrollbarWidth() to avoid black borders at the right
browser_tabview_bug594958.js failed horribly on try (I have no idea why) and I didn't want to spend much time on fixing that. I remember that the test is quite old and very hacky/flaky. If we let Panorama use PageThumbs, we can remove the test as it doesn't apply anymore and we can remove a whole bunch of custom canvas/screenshot code as well.
Attachment #713861 - Flags: review?(jAwS)
Attachment #713361 - Flags: review?(jAwS) → review+
Comment on attachment 713861 [details] [diff] [review] part 2 - let Panorama use PageThumbs to draw screenshots to TabCanvases Review of attachment 713861 [details] [diff] [review]: ----------------------------------------------------------------- ::: browser/components/thumbnails/PageThumbs.jsm @@ +144,5 @@ > let [sw, sh, scale] = this._determineCropSize(aWindow, aCanvas); > let ctx = aCanvas.getContext("2d"); > > // Scale the canvas accordingly. > + ctx.save(); Is this (and the ctx.restore) fixing a known bug?
Attachment #713861 - Flags: review?(jAwS) → review+
(In reply to Jared Wein [:jaws] from comment #22) > > let [sw, sh, scale] = this._determineCropSize(aWindow, aCanvas); > > let ctx = aCanvas.getContext("2d"); > > > > // Scale the canvas accordingly. > > + ctx.save(); > > Is this (and the ctx.restore) fixing a known bug? It's fixing a bug I didn't know of until Panorama as the first client re-using a canvas came around :)
Currently trying to figure out some weird Windows orange that I can't reproduce of course :( https://tbpl.mozilla.org/?tree=Try&rev=736e540fa67a
Blocks: 631593
Blocks: 759704
Ok, I just pushed it to try subtracting the horizontal scrollbar's height and it works on Windows now, too. Looks like we need another API for that, yay! I'm going to file a bug. https://tbpl.mozilla.org/?tree=Try&rev=e48638c31063
Depends on: 845010
Minor change to PageThumbs.jsm in part 1: getScrollbarWidth() doesn't exist anymore - we now use getScrollbarSize(). That means we also decrease the available space when having vertical scrollbars.
Attachment #713361 - Attachment is obsolete: true
Attachment #718336 - Flags: review?(jAwS)
Comment on attachment 718336 [details] [diff] [review] part 1 - use nsIDOMWindowUtils.getScrollbarSize() to avoid black borders at the right >+ let sw = aWindow.innerWidth - sbWidth.value; Doesn't this always subtract the scrollbar width on the right side even if the scrollbar is on the left, i.e. in RTL content?
(In reply to Dão Gottwald [:dao] from comment #27) > Doesn't this always subtract the scrollbar width on the right side even if > the scrollbar is on the left, i.e. in RTL content? The available width does decrease for LTR and RTL but you're right that the black border would not be prevented on the left for RTL mode. Basically, PageThumbs._determineCropSize() just needs to return an offsetX as well. > if (isRTL && sw < availableWidth) { > offsetX = sbWidth.value + (availableWidth - sw); > } That's an easy thing to do (thank you for catching this, btw) but the harder part is detecting the RTL mode. We want to avoid black borders and therefore don't care if the page is RTL but if the whole browser UI is RTL, right? I guess we can do it like this? http://mxr.mozilla.org/mozilla-central/source/browser/components/places/content/browserPlacesViews.js#715
(In reply to Tim Taubert [:ttaubert] from comment #28) > don't care if the page is RTL but if the whole browser UI is RTL, right? I'm not sure, I would expect that the content direction matters.
(In reply to Dão Gottwald [:dao] from comment #30) > (In reply to Tim Taubert [:ttaubert] from comment #28) > > don't care if the page is RTL but if the whole browser UI is RTL, right? > > I'm not sure, I would expect that the content direction matters. Yeah I just figured that, too. The offsetX needs to include the scrollbar width if the UI is in RTL mode. If the content page is in RTL mode we need to add (availableWidth - sw) to offsetX so that the thumbnail is right-aligned. So those are two separate steps.
So... even sites like aljazeera.net (and a couple others I tested) are really hard to determine as RTL. They use some tables with align=right, text-align:right, text-direction:rtl on some specific elements, etc. The <body>'s computed style is definitely not RTL. I think it should be sufficient if we only focus on not having black borders on the left?
(In reply to Tim Taubert [:ttaubert] from comment #32) > So... even sites like aljazeera.net (and a couple others I tested) are > really hard to determine as RTL. They use some tables with align=right, > text-align:right, text-direction:rtl on some specific elements, etc. The > <body>'s computed style is definitely not RTL. aljazeera.net also has the scrollbar on the right, even with the UI direction being RTL, so this seems like a case we /shouldn't/ detect as RTL here.
(In reply to Dão Gottwald [:dao] from comment #34) > aljazeera.net also has the scrollbar on the right, even with the UI > direction being RTL, so this seems like a case we /shouldn't/ detect as RTL > here. But that's only because our browser UI isn't RTL, right? In Arabic locales it should be on the left. So there's that difference between the browser UI and the page we're viewing.
I set intl.uidirection.en to rtl, opened a new window, loaded aljazeera.net and the scrollbar was on the right.
Ok, that is strange. Do we ever have scrollbars on the left for RTL pages? I have a left scrollbar for about:config (which is probably just a scrollbux) but not for any of the Arabic news sites (and RTL test cases) I tried. Is this something the operating system locale needs to support?
(In reply to Tim Taubert [:ttaubert] from comment #37) > Ok, that is strange. Do we ever have scrollbars on the left for RTL pages? I > have a left scrollbar for about:config (which is probably just a scrollbux) > but not for any of the Arabic news sites (and RTL test cases) I tried. Is > this something the operating system locale needs to support? Maybe Ehsan knows.
We don't currently put the scrollbar on the left for any pages.
Comment on attachment 718378 [details] [diff] [review] part 3 - adjust left offset when capturing thumbnails in RTL locales Can you add a comment saying that we put scrollbars on the right even for RTL content?
Attachment #718378 - Attachment is obsolete: true
Attachment #718378 - Flags: review?(dao)
Comment on attachment 718336 [details] [diff] [review] part 1 - use nsIDOMWindowUtils.getScrollbarSize() to avoid black borders at the right Review of attachment 718336 [details] [diff] [review]: ----------------------------------------------------------------- ::: toolkit/components/thumbnails/PageThumbs.jsm @@ +240,5 @@ > _determineCropSize: function PageThumbs_determineCropSize(aWindow, aCanvas) { > + let utils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) > + .getInterface(Ci.nsIDOMWindowUtils); > + let sbWidth = {}, sbHeight = {}; > + utils.getScrollbarSize(true, sbWidth, sbHeight); The previous version of this patch did not force a layout flush. Why the change?
Attachment #718336 - Flags: review?(jAwS) → review+
(In reply to Dão Gottwald [:dao] from comment #40) > Can you add a comment saying that we put scrollbars on the right even for > RTL content? Yes, will do.
(In reply to Jared Wein [:jaws] from comment #41) > > + let sbWidth = {}, sbHeight = {}; > > + utils.getScrollbarSize(true, sbWidth, sbHeight); > > The previous version of this patch did not force a layout flush. Why the > change? Thanks for spotting this. I think I changed this will trying to fix the intermittent Windows orange. I'll push it to try with flush=false to see if the tests are still green and if so I'll land that because I think that's what we prefer anyway.
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 22
Depends on: 971592
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: