add padding to account for fullscreen mode

This commit is contained in:
Daniel Micay 2019-08-20 12:23:38 -04:00
parent 4fad395606
commit be2439be65
4 changed files with 28 additions and 1 deletions

View File

@ -1,8 +1,12 @@
body, canvas {
body, canvas, #padding {
padding: 0;
margin: 0;
}
#padding {
background: black;
}
.textLayer {
position: absolute;
left: 0;

View File

@ -7,6 +7,7 @@
<script src="pdf.js"></script>
</head>
<body>
<div id="padding"></div>
<canvas id="content"></canvas>
<div id="text" class="textLayer"></div>
<script src="viewer.js"></script>

View File

@ -189,6 +189,15 @@ function isTextSelected() {
return window.getSelection().toString() !== "";
}
function updateInset() {
const padding = document.getElementById("padding");
const windowInsetTop = channel.getWindowInsetTop() / window.devicePixelRatio + "px";
padding.style.paddingTop = windowInsetTop;
textLayerDiv.style.top = windowInsetTop;
}
updateInset();
pdfjsLib.getDocument("https://localhost/placeholder.pdf").promise.then(function(newDoc) {
pdfDoc = newDoc;
channel.setNumPages(pdfDoc.numPages);

View File

@ -91,6 +91,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
private int mZoomLevel = 2;
private int mDocumentOrientationDegrees;
private int mDocumentState;
private int windowInsetTop;
private List<CharSequence> mDocumentProperties;
private InputStream mInputStream;
@ -99,6 +100,11 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
private Toast mToast;
private class Channel {
@JavascriptInterface
public int getWindowInsetTop() {
return windowInsetTop;
}
@JavascriptInterface
public int getPage() {
return mPage;
@ -147,6 +153,13 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
setContentView(R.layout.webview);
mWebView = findViewById(R.id.webview);
mWebView.setOnApplyWindowInsetsListener((view, insets) -> {
windowInsetTop = insets.getSystemWindowInsetTop();
mWebView.evaluateJavascript("updateInset()", null);
return insets;
});
final WebSettings settings = mWebView.getSettings();
settings.setAllowContentAccess(false);
settings.setAllowFileAccess(false);