mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Port addition of css for split marker
This commit is contained in:
parent
38836de4e1
commit
67f3422438
@ -1361,20 +1361,6 @@ def secure_web_page(qwebpage_or_qwebsettings):
|
|||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def secure_webengine(view_or_page_or_settings, for_viewer=False):
|
|
||||||
s = view_or_page_or_settings.settings() if hasattr(view_or_page_or_settings, 'settings') else view_or_page_or_settings
|
|
||||||
a = s.setAttribute
|
|
||||||
a(s.PluginsEnabled, False)
|
|
||||||
if not for_viewer:
|
|
||||||
a(s.JavascriptEnabled, False)
|
|
||||||
s.setUnknownUrlSchemePolicy(s.DisallowUnknownUrlSchemes)
|
|
||||||
a(s.JavascriptCanOpenWindows, False)
|
|
||||||
a(s.JavascriptCanAccessClipboard, False)
|
|
||||||
a(s.LocalContentCanAccessFileUrls, False) # ensure javascript cannot read from local files
|
|
||||||
a(s.AllowWindowActivationFromJavaScript, False)
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
empty_model = QStringListModel([''])
|
empty_model = QStringListModel([''])
|
||||||
empty_index = empty_model.index(0)
|
empty_index = empty_model.index(0)
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||||||
# live css
|
# live css
|
||||||
# check that clicking on both internal and external links works
|
# check that clicking on both internal and external links works
|
||||||
# check all buttons in preview panel
|
# check all buttons in preview panel
|
||||||
# pass user stylesheet with css for split
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import textwrap
|
import textwrap
|
||||||
@ -321,8 +320,6 @@ class WebPage(QWebEnginePage):
|
|||||||
self.bridge = Bridge(self)
|
self.bridge = Bridge(self)
|
||||||
self.setWebChannel(c, QWebEngineScript.ApplicationWorld)
|
self.setWebChannel(c, QWebEngineScript.ApplicationWorld)
|
||||||
c.registerObject('bridge', self.bridge)
|
c.registerObject('bridge', self.bridge)
|
||||||
# TODO: Implement this
|
|
||||||
# css = '[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }'
|
|
||||||
|
|
||||||
def javaScriptConsoleMessage(self, level, msg, linenumber, source_id):
|
def javaScriptConsoleMessage(self, level, msg, linenumber, source_id):
|
||||||
prints('%s:%s: %s' % (source_id, linenumber, msg))
|
prints('%s:%s: %s' % (source_id, linenumber, msg))
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
# globals: CSSRule
|
# globals: CSSRule
|
||||||
from __python__ import bound_methods, hash_literals
|
from __python__ import bound_methods, hash_literals
|
||||||
|
|
||||||
|
from elementmaker import E
|
||||||
|
|
||||||
def is_hidden(elem):
|
def is_hidden(elem):
|
||||||
while elem:
|
while elem:
|
||||||
if (elem.style and (elem.style.visibility is 'hidden' or elem.style.display is 'none')):
|
if (elem.style and (elem.style.visibility is 'hidden' or elem.style.display is 'none')):
|
||||||
@ -18,7 +20,8 @@ def is_block(elem):
|
|||||||
|
|
||||||
def in_table(elem):
|
def in_table(elem):
|
||||||
while elem:
|
while elem:
|
||||||
if elem.tagName?.toLowerCase() is 'table':
|
tn = elem.tagName.toLowerCase() if elem.tagName else ''
|
||||||
|
if tn is 'table':
|
||||||
return True
|
return True
|
||||||
elem = elem.parentNode
|
elem = elem.parentNode
|
||||||
return False
|
return False
|
||||||
@ -162,8 +165,12 @@ def get_style_properties(style, all_properties, node_style, is_ancestor):
|
|||||||
i = 0
|
i = 0
|
||||||
properties = v'[]'
|
properties = v'[]'
|
||||||
while i < style.length:
|
while i < style.length:
|
||||||
property = style.item(i)?.toLowerCase()
|
property = style.item(i)
|
||||||
|
if property:
|
||||||
|
property = property.toLowerCase()
|
||||||
val = style.getPropertyValue(property)
|
val = style.getPropertyValue(property)
|
||||||
|
else:
|
||||||
|
val = None
|
||||||
if property and val and (not is_ancestor or INHERITED_PROPS[property]):
|
if property and val and (not is_ancestor or INHERITED_PROPS[property]):
|
||||||
properties.push(v'[property, val, style.getPropertyPriority(property), get_color(property, val)]')
|
properties.push(v'[property, val, style.getPropertyPriority(property), get_color(property, val)]')
|
||||||
if not all_properties.hasOwnProperty(property):
|
if not all_properties.hasOwnProperty(property):
|
||||||
@ -248,7 +255,11 @@ class PreviewIntegration:
|
|||||||
self.in_split_mode = False
|
self.in_split_mode = False
|
||||||
if window is window.top:
|
if window is window.top:
|
||||||
setTimeout(self.connect_channel, 10)
|
setTimeout(self.connect_channel, 10)
|
||||||
window.document.body.addEventListener('click', self.onclick, True)
|
document.body.addEventListener('click', self.onclick, True)
|
||||||
|
document.body.appendChild(E.style(
|
||||||
|
type='text/css',
|
||||||
|
'[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }'
|
||||||
|
))
|
||||||
|
|
||||||
def go_to_line(self, lnum):
|
def go_to_line(self, lnum):
|
||||||
for node in document.querySelectorAll(f'[data-lnum="{lnum}"]'):
|
for node in document.querySelectorAll(f'[data-lnum="{lnum}"]'):
|
||||||
@ -326,7 +337,7 @@ class PreviewIntegration:
|
|||||||
# Find the closest containing link, if any
|
# Find the closest containing link, if any
|
||||||
href = tn = ''
|
href = tn = ''
|
||||||
while e and e != document.body and e != document and (tn is not 'a' or not href):
|
while e and e != document.body and e != document and (tn is not 'a' or not href):
|
||||||
tn = e.tagName?.toLowerCase()
|
tn = e.tagName.toLowerCase() if e.tagName else ''
|
||||||
href = e.getAttribute('href')
|
href = e.getAttribute('href')
|
||||||
e = e.parentNode
|
e = e.parentNode
|
||||||
self.bridge.request_sync(tn, href, JSON.stringify(address))
|
self.bridge.request_sync(tn, href, JSON.stringify(address))
|
||||||
@ -345,7 +356,8 @@ class PreviewIntegration:
|
|||||||
target = None
|
target = None
|
||||||
i = 0
|
i = 0
|
||||||
for node in document.querySelectorAll(f'[data-lnum="{sourceline}"]'):
|
for node in document.querySelectorAll(f'[data-lnum="{sourceline}"]'):
|
||||||
if node.tagName?.toLowerCase() is not tags[i]:
|
tn = node.tagName.toLowerCase() if node.tagName else ''
|
||||||
|
if tn is not tags[i]:
|
||||||
return JSON.stringify(None)
|
return JSON.stringify(None)
|
||||||
i += 1
|
i += 1
|
||||||
target = node
|
target = node
|
||||||
@ -358,8 +370,9 @@ class PreviewIntegration:
|
|||||||
css = get_matched_css(target, is_ancestor, all_properties)
|
css = get_matched_css(target, is_ancestor, all_properties)
|
||||||
# We want to show the Matched CSS rules header even if no rules matched
|
# We want to show the Matched CSS rules header even if no rules matched
|
||||||
if css.length > 0 or not is_ancestor:
|
if css.length > 0 or not is_ancestor:
|
||||||
|
tn = target.tagName.toLowerCase() if target.tagName else ''
|
||||||
ans.nodes.push({
|
ans.nodes.push({
|
||||||
'name':target.tagName?.toLowerCase(),
|
'name': tn,
|
||||||
'css': css, 'is_ancestor': is_ancestor,
|
'css': css, 'is_ancestor': is_ancestor,
|
||||||
'sourceline': target.getAttribute('data-lnum')
|
'sourceline': target.getAttribute('data-lnum')
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user