Closed Bug 672474 Opened 14 years ago Closed 12 years ago

Provide an API to retrieve the current document's scrollbar width

Categories

(Core :: DOM: Core & HTML, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla21

People

(Reporter: raymondlee, Assigned: ttaubert)

References

Details

Attachments

(2 files, 1 obsolete file)

It would be nice to have a way to get the width of browser scrollbars. When taking a screenshot of a tab, we want to get the width of vertical and horizontal scrollbars so we can remove them from screenshot.
Severity: normal → enhancement
Panorama needs this, the thumbnail service needs it and here's two more places where we use a quite bad hack to work around the lack of a proper API: http://mxr.mozilla.org/mozilla-central/source/browser/devtools/webconsole/AutocompletePopup.jsm#366 http://mxr.mozilla.org/mozilla-central/source/browser/devtools/shared/DeveloperToolbar.jsm#765
Hardware: x86 → All
Summary: Provides way to get browser scrollbar's width → Provide an API to retrieve the current document's scrollbar width
Assignee: nobody → ttaubert
Status: NEW → ASSIGNED
Component: General → DOM
Product: Firefox → Core
Olli, I hope you're the right one to review this?
Attachment #711073 - Flags: review?(bugs)
Comment on attachment 711073 [details] [diff] [review] add nsIDOMWindowUtils.getScrollbarWidth(aFlushLayout) Looks ok to me, but scrollbar handling is more roc's stuff. One nit, nsIPresShell *presShell -> nsIPresShell* presShell
Attachment #711073 - Flags: review?(bugs) → review?(roc)
Comment on attachment 711073 [details] [diff] [review] add nsIDOMWindowUtils.getScrollbarWidth(aFlushLayout) Review of attachment 711073 [details] [diff] [review]: ----------------------------------------------------------------- The actual code looks OK. ::: dom/tests/mochitest/general/test_domWindowUtils_scrollbarWidth.html @@ +22,5 @@ > + is(utils.getScrollbarWidth(false), 0, > + "getScrollbarWidth returns zero with a vertical scrollbar w/o flushing"); > + > + ok(utils.getScrollbarWidth(true) > 0, > + "getScrollbarWidth returns non-zero with a vertical scrollbar with flushing"); I'm afraid this test will fail on B2G/Android (maybe other platforms later) where disappearing scrollbars are used. Try doing something like an overflow:scroll float element containing a single child of known width. The float element should then get the width of the child plus the width of a scrollbar; you can use that to figure out what a scrollbar width should be.
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #5) > I'm afraid this test will fail on B2G/Android (maybe other platforms later) > where disappearing scrollbars are used. Good point. > Try doing something like an overflow:scroll float element containing a > single child of known width. The float element should then get the width of > the child plus the width of a scrollbar; you can use that to figure out what > a scrollbar width should be. Ok, will do, thanks! BTW, is there any reason this patch might not work with XUL documents / windows? presShell->GetRootScrollFrameAsScrollable() does not seem to return a valid scrollFrame.
(In reply to Tim Taubert [:ttaubert] from comment #6) > BTW, is there any reason this patch might not work with XUL documents / > windows? presShell->GetRootScrollFrameAsScrollable() does not seem to > return a valid scrollFrame. I have a ChromeWindow instance, to be specific.
DOMWindowUtils.getScrollbarWidth() does also throw if I try to run the code in the Scratchpad.
XUL docs don't have scrollable root, at least not by default.
There are a couple of API clients that would actually rather need to pass a specific DOMElement like a <xul:richlistbox> and get its scrollbar width, if any. I think it would make sense to add DOMWindowUtils.getScrollbarWidthForElement(nsIDOMElement aElement, bool aFlush)? Is it possible to retrieve an nsIScrollableFrame from a given DOMElement? I think the <xul:scrollbox> is actually injected by XBL...
(In reply to Robert O'Callahan (:roc) (Mozilla Corporation) from comment #5) > > + is(utils.getScrollbarWidth(false), 0, > > + "getScrollbarWidth returns zero with a vertical scrollbar w/o flushing"); > > + > > + ok(utils.getScrollbarWidth(true) > 0, > > + "getScrollbarWidth returns non-zero with a vertical scrollbar with flushing"); > > I'm afraid this test will fail on B2G/Android (maybe other platforms later) > where disappearing scrollbars are used. > > Try doing something like an overflow:scroll float element containing a > single child of known width. The float element should then get the width of > the child plus the width of a scrollbar; you can use that to figure out what > a scrollbar width should be. Wait, how does that work if I'm trying to get the root frame's scrollbar width? There's no way I can make such a test for a root's scrollbar, right?
You can assume all scrollbars have the same width.
Blocks: 727765
But wouldn't .getScrollbarWidth() always return 0 if the root doesn't have scrollbars?
I'm suggesting using the float trick to figure out if the platform uses disappearing scrollbars or not. Once you know that, you can skip the part of your test that assumes scrollbars have width.
Oh, I get it know. Thank you for explaining :)
*now
Added proposed test for floating scrollbars.
Attachment #711073 - Attachment is obsolete: true
Attachment #711073 - Flags: review?(roc)
Attachment #713372 - Flags: review?(roc)
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla21
No longer blocks: 631593
Comment on attachment 713372 [details] [diff] [review] add nsIDOMWindowUtils.getScrollbarWidth(aFlushLayout) Review of attachment 713372 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/base/nsDOMWindowUtils.cpp @@ +1450,5 @@ > + > + nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow); > + NS_ENSURE_STATE(window); > + > + nsCOMPtr<nsIDocument> doc(do_QueryInterface(window->GetExtantDocument())); For future reference, this is what GetExtantDoc() is for.
Thanks for the hint.
Attachment #714358 - Flags: review?(Ms2ger)
Comment on attachment 714358 [details] [diff] [review] followup to use GetExtantDoc() Review of attachment 714358 [details] [diff] [review]: ----------------------------------------------------------------- Thanks!
Attachment #714358 - Flags: review?(Ms2ger) → review+
Depends on: 845010
Keywords: dev-doc-needed
Keywords: dev-doc-needed
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: