Skip to content

Commit da273e9

Browse files
committed
Fix scrollbars showing under Chrome on Linux
1 parent 6c7b47c commit da273e9

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/document2svg.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ var document2svg = (function (util, browser, documentHelper, mediaQueryHelper, x
4040
attributes.externalResourcesRequired = true;
4141
};
4242

43+
var workAroundChromeShowingScrollbarsUnderLinuxIfHtmlIsOverflowScroll = function () {
44+
return '<style scoped="">html::-webkit-scrollbar { display: none; }</style>';
45+
};
46+
4347
var serializeAttributes = function (attributes) {
4448
var keys = Object.keys(attributes);
4549
if (!keys.length) {
@@ -67,6 +71,7 @@ var document2svg = (function (util, browser, documentHelper, mediaQueryHelper, x
6771
' height="' + size.height + '"' +
6872
' font-size="' + size.rootFontSize + '"' +
6973
'>' +
74+
workAroundChromeShowingScrollbarsUnderLinuxIfHtmlIsOverflowScroll() +
7075
'<foreignObject' + serializeAttributes(attributes) + '>' +
7176
xhtml +
7277
'</foreignObject>' +

test/fixtures/testScaled50PercentWithJs.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* External webfont
1515
* External background image
1616
* :active and :hover style
17+
* Scollbar shown on Chrome under Linux when html element is set to overflow: scoll
1718
1819
Together with external parameters:
1920
* Zooming
@@ -56,6 +57,7 @@
5657
img:focus {
5758
opacity: 1;
5859
}
60+
html { overflow-y: scroll; }
5961
</style>
6062
</head>
6163
<body class="teST">

test/specs/Document2SvgSpec.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe("Document to SVG conversion", function () {
5656
document2svg.getSvgForDocument(doc, aRenderSize(), defaultZoomLevel).then(function (svgCode) {
5757
expect(svgCode).toMatch(new RegExp(
5858
'<svg xmlns="http://www.w3.org/2000/svg" .*>' +
59+
'.*' +
5960
'<foreignObject .*>' +
6061
'<html xmlns="http://www.w3.org/1999/xhtml">' +
6162
'<head>' +
@@ -83,6 +84,7 @@ describe("Document to SVG conversion", function () {
8384
canonicalXML = svgCode.replace(/ +\/>/, '/>');
8485
expect(canonicalXML).toMatch(new RegExp(
8586
'<svg xmlns="http://www.w3.org/2000/svg" .*>' +
87+
'.*' +
8688
'<foreignObject .*>' +
8789
'<html xmlns="http://www.w3.org/1999/xhtml">' +
8890
'<head>' +
@@ -107,6 +109,7 @@ describe("Document to SVG conversion", function () {
107109
document2svg.getSvgForDocument(doc, aRenderSize(123, 987, 200, 1000, 2, 7), defaultZoomLevel).then(function (svgCode) {
108110
expect(svgCode).toMatch(new RegExp(
109111
'<svg xmlns="http://www.w3.org/2000/svg" width="123" height="987"[^>]*>' +
112+
'.*' +
110113
'<foreignObject x="-2" y="-7" width="200" height="1000".*>' +
111114
'<html xmlns="http://www.w3.org/1999/xhtml">' +
112115
'<head>' +
@@ -132,6 +135,7 @@ describe("Document to SVG conversion", function () {
132135
document2svg.getSvgForDocument(doc, aRenderSize(123, 987, 12, 99), zoomFactor).then(function (svgCode) {
133136
expect(svgCode).toMatch(new RegExp(
134137
'<svg xmlns="http://www.w3.org/2000/svg" width="123" height="987"[^>]*>' +
138+
'.*' +
135139
'<foreignObject x="0" y="0" width="12" height="99" transform="scale\\(10\\)".*>' +
136140
'<html xmlns="http://www.w3.org/1999/xhtml">' +
137141
'<head>' +
@@ -168,6 +172,7 @@ describe("Document to SVG conversion", function () {
168172
document2svg.getSvgForDocument(doc, aRenderSizeWithRootFontSize('42px'), defaultZoomLevel).then(function (svgCode) {
169173
expect(svgCode).toMatch(new RegExp(
170174
'<svg xmlns="http://www.w3.org/2000/svg" [^>]*font-size="42px"[^>]*>' +
175+
'.*' +
171176
'<foreignObject .*>' +
172177
'<html xmlns="http://www.w3.org/1999/xhtml"[^>]*>' +
173178
'<head>' +
@@ -250,7 +255,7 @@ describe("Document to SVG conversion", function () {
250255
});
251256
});
252257

253-
it("should not work around WebKit's EM media query issue", function (done) {
258+
it("should not work around EM media query if no issue exists", function (done) {
254259
var doc = document.implementation.createHTMLDocument("");
255260
setUpNeedsEmWorkaroundToReturn(false);
256261

@@ -260,6 +265,24 @@ describe("Document to SVG conversion", function () {
260265
done();
261266
});
262267
});
268+
269+
it("should hide scrollbars on Chrome under Linux", function (done) {
270+
var doc = document.implementation.createHTMLDocument("");
271+
doc.body.innerHTML = "Test content";
272+
273+
document2svg.getSvgForDocument(doc, aRenderSize(), defaultZoomLevel).then(function (svgCode) {
274+
expect(svgCode).toMatch(new RegExp(
275+
'<svg xmlns="http://www.w3.org/2000/svg" .*>' +
276+
'<style scoped="">html::-webkit-scrollbar { display: none; }</style>' +
277+
'<foreignObject .*>' +
278+
'.*' +
279+
'</foreignObject>' +
280+
'</svg>'
281+
));
282+
283+
done();
284+
});
285+
});
263286
});
264287

265288
describe("drawDocumentAsSvg", function () {

0 commit comments

Comments
 (0)