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)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla21
People
(Reporter: raymondlee, Assigned: ttaubert)
References
Details
Attachments
(2 files, 1 obsolete file)
6.53 KB,
patch
|
roc
:
review+
|
Details | Diff | Splinter Review |
894 bytes,
patch
|
Ms2ger
:
review+
|
Details | Diff | Splinter Review |
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.
Reporter | ||
Updated•14 years ago
|
Severity: normal → enhancement
Assignee | ||
Comment 1•12 years ago
|
||
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
Assignee | ||
Updated•12 years ago
|
Summary: Provides way to get browser scrollbar's width → Provide an API to retrieve the current document's scrollbar width
Assignee | ||
Comment 2•12 years ago
|
||
Another one, just FTR:
http://mxr.mozilla.org/mozilla-central/source/browser/devtools/commandline/gcli.jsm#9279
Assignee | ||
Updated•12 years ago
|
Assignee: nobody → ttaubert
Status: NEW → ASSIGNED
Assignee | ||
Updated•12 years ago
|
Component: General → DOM
Product: Firefox → Core
Assignee | ||
Comment 3•12 years ago
|
||
Olli, I hope you're the right one to review this?
Attachment #711073 -
Flags: review?(bugs)
Comment 4•12 years ago
|
||
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.
Assignee | ||
Comment 6•12 years ago
|
||
(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.
Assignee | ||
Comment 7•12 years ago
|
||
(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.
Assignee | ||
Comment 8•12 years ago
|
||
DOMWindowUtils.getScrollbarWidth() does also throw if I try to run the code in the Scratchpad.
Comment 9•12 years ago
|
||
XUL docs don't have scrollable root, at least not by default.
Assignee | ||
Comment 10•12 years ago
|
||
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...
Assignee | ||
Comment 11•12 years ago
|
||
(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.
Assignee | ||
Comment 13•12 years ago
|
||
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.
Assignee | ||
Comment 15•12 years ago
|
||
Oh, I get it know. Thank you for explaining :)
Assignee | ||
Comment 16•12 years ago
|
||
*now
Assignee | ||
Comment 17•12 years ago
|
||
Added proposed test for floating scrollbars.
Attachment #711073 -
Attachment is obsolete: true
Attachment #711073 -
Flags: review?(roc)
Attachment #713372 -
Flags: review?(roc)
Attachment #713372 -
Flags: review?(roc) → review+
Assignee | ||
Comment 18•12 years ago
|
||
Assignee | ||
Comment 19•12 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla21
Comment 20•12 years ago
|
||
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.
Comment 22•12 years ago
|
||
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+
Assignee | ||
Comment 23•12 years ago
|
||
Assignee | ||
Comment 24•12 years ago
|
||
Updated•12 years ago
|
Keywords: dev-doc-needed
Updated•12 years ago
|
Keywords: dev-doc-needed
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•