@@ -178,6 +178,7 @@ const PDFViewerApplication = {
178
178
_nimbusDataPromise : null ,
179
179
_caretBrowsing : null ,
180
180
_isScrolling : false ,
181
+ _idsToWatchOutPromise : null ,
181
182
182
183
// Called once when the document is loaded.
183
184
async initialize ( appConfig ) {
@@ -187,6 +188,7 @@ const PDFViewerApplication = {
187
188
if ( typeof PDFJSDev !== "undefined" && ! PDFJSDev . test ( "GENERIC" ) ) {
188
189
l10nPromise = this . externalServices . createL10n ( ) ;
189
190
if ( PDFJSDev . test ( "MOZCENTRAL" ) ) {
191
+ this . _idsToWatchOutPromise = this . externalServices . getIdsToWatchOut ( ) ;
190
192
this . _allowedGlobalEventsPromise =
191
193
this . externalServices . getGlobalEventNames ( ) ;
192
194
}
@@ -1995,6 +1997,49 @@ const PDFViewerApplication = {
1995
1997
}
1996
1998
addWindowResolutionChange ( ) ;
1997
1999
2000
+ if ( typeof PDFJSDev !== "undefined" && PDFJSDev . test ( "MOZCENTRAL" ) ) {
2001
+ // We want to track the position of some elements in order to display a
2002
+ // positioned callout.
2003
+ // If the viewer has its dimensions in some specific range, some elements
2004
+ // are either hidden or made visible (for example the print button is
2005
+ // moved from the main toolbar to the secondary one).
2006
+ this . _idsToWatchOutPromise ?. then ( ids => {
2007
+ if ( ! ids ) {
2008
+ return ;
2009
+ }
2010
+ const callback = ( ) => {
2011
+ const detail = Object . create ( null ) ;
2012
+ for ( const id of ids ) {
2013
+ detail [ id ] = document . getElementById ( id ) . getBoundingClientRect ( ) ;
2014
+ }
2015
+ eventBus . dispatch ( "updateviewermaxwidth" , {
2016
+ source : this ,
2017
+ detail,
2018
+ } ) ;
2019
+ } ;
2020
+
2021
+ // The list of sizes is based on the ones we've in viewer.css.
2022
+ const sizes = [ 900 , 840 , 750 , 690 , 560 ] ;
2023
+ for ( let i = 0 , ii = sizes . length ; i < ii ; i ++ ) {
2024
+ let mediaQueryList ;
2025
+ const size = sizes [ i ] ;
2026
+ if ( i === 0 ) {
2027
+ mediaQueryList = window . matchMedia ( `(width > ${ size } px)` ) ;
2028
+ } else if ( i === ii - 1 ) {
2029
+ mediaQueryList = window . matchMedia ( `(width <= ${ size } px)` ) ;
2030
+ } else {
2031
+ mediaQueryList = window . matchMedia (
2032
+ `(width > ${ sizes [ i + 1 ] } px) and (width <= ${ size } px)`
2033
+ ) ;
2034
+ }
2035
+ mediaQueryList . addEventListener ( "change" , callback , {
2036
+ signal,
2037
+ } ) ;
2038
+ }
2039
+ callback ( ) ;
2040
+ } ) ;
2041
+ }
2042
+
1998
2043
window . addEventListener ( "wheel" , webViewerWheel , {
1999
2044
passive : false ,
2000
2045
signal,
0 commit comments