Handle the case of document stylesheets with null cssrules (caused by cross-origin security policies)

This commit is contained in:
Kovid Goyal 2016-12-24 11:05:44 +05:30
parent a35f1b7d26
commit 344864a807
3 changed files with 20 additions and 19 deletions

Binary file not shown.

View File

@ -85,15 +85,16 @@ class PagedDisplay
tmp.style.position = 'absolute' tmp.style.position = 'absolute'
document.body.appendChild(tmp) document.body.appendChild(tmp)
for sheet in document.styleSheets for sheet in document.styleSheets
for rule in sheet.rules if sheet.rules
if rule.type == CSSRule.PAGE_RULE for rule in sheet.rules
for prop in ['left', 'top', 'bottom', 'right'] if rule.type == CSSRule.PAGE_RULE
val = rule.style.getPropertyValue('margin-'+prop) for prop in ['left', 'top', 'bottom', 'right']
if val val = rule.style.getPropertyValue('margin-'+prop)
tmp.style.height = val if val
pxval = parseInt(window.getComputedStyle(tmp).height) tmp.style.height = val
if not isNaN(pxval) pxval = parseInt(window.getComputedStyle(tmp).height)
this.document_margins[prop] = pxval if not isNaN(pxval)
this.document_margins[prop] = pxval
document.body.removeChild(tmp) document.body.removeChild(tmp)
if this.document_margins.left is null if this.document_margins.left is null
val = parseInt(window.getComputedStyle(document.body).marginLeft) val = parseInt(window.getComputedStyle(document.body).marginLeft)
@ -232,14 +233,15 @@ class PagedDisplay
# Convert page-breaks to column-breaks # Convert page-breaks to column-breaks
for sheet in document.styleSheets for sheet in document.styleSheets
for rule in sheet.rules if sheet.rules
if rule.type == CSSRule.STYLE_RULE for rule in sheet.rules
for prop in ['page-break-before', 'page-break-after', 'page-break-inside'] if rule.type == CSSRule.STYLE_RULE
val = rule.style.getPropertyValue(prop) for prop in ['page-break-before', 'page-break-after', 'page-break-inside']
if val val = rule.style.getPropertyValue(prop)
cprop = '-webkit-column-' + prop.substr(5) if val
priority = rule.style.getPropertyPriority(prop) cprop = '-webkit-column-' + prop.substr(5)
rule.style.setProperty(cprop, val, priority) priority = rule.style.getPropertyPriority(prop)
rule.style.setProperty(cprop, val, priority)
if first_layout if first_layout
# Because of a bug in webkit column mode, svg elements defined with # Because of a bug in webkit column mode, svg elements defined with

View File

@ -214,7 +214,7 @@ get_matched_css = (node, is_ancestor, all_properties) ->
node_style = window.getComputedStyle(node) node_style = window.getComputedStyle(node)
for sheet, sheet_index in document.styleSheets for sheet, sheet_index in document.styleSheets
if sheet.disabled if sheet.disabled or not sheet.cssRules
continue continue
process_rules(node, sheet.cssRules, [], sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans) process_rules(node, sheet.cssRules, [], sheet, sheet_index, matching_selectors, all_properties, node_style, is_ancestor, ans)
@ -354,4 +354,3 @@ class PreviewIntegration
window.calibre_preview_integration = new PreviewIntegration() window.calibre_preview_integration = new PreviewIntegration()
window.onload = window.calibre_preview_integration.onload window.onload = window.calibre_preview_integration.onload