From: Daniel Carl Date: Sun, 7 May 2017 12:21:27 +0000 (+0200) Subject: Set hint css vie web content manager #349. X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=3b9bf50b4cbcf5b4b78cec47fe2454ba6493aa59;p=vimb.git Set hint css vie web content manager #349. Add the hint css direct to webkit instead of manipulating the DOM to add a style node. By the way the default style was removed from config.def.h into src/scripts directory so that the css is minified during compilation. --- diff --git a/src/Makefile b/src/Makefile index 50e267d..f60d2ce 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,6 +4,7 @@ include $(BASEDIR)/config.mk SUBDIRS = webextension OBJ = $(patsubst %.c, %.o, $(wildcard *.c)) JSFILES = $(wildcard scripts/*.js) +CSSFILES = $(wildcard scripts/*.css) all: vimb $(SUBDIRS:%=%.subdir-all) @@ -22,10 +23,10 @@ config.h: @echo create $@ from config.def.h $(Q)cp config.def.h $@ -scripts/scripts.h: $(JSFILES) +scripts/scripts.h: $(JSFILES) $(CSSFILES) $(Q)$(RM) $@ - @echo "create $@ from *.js" - $(Q)for file in $(JSFILES); do \ + @echo "create $@ from *.{css,js}" + $(Q)for file in $(JSFILES) $(CSSFILES); do \ ./scripts/js2h.sh $$file >> $@; \ done diff --git a/src/config.def.h b/src/config.def.h index 0e82137..44f9351 100644 --- a/src/config.def.h +++ b/src/config.def.h @@ -52,35 +52,3 @@ #define SETTING_HOME_PAGE "about:blank" #define MAXIMUM_HINTS 500 - -/* CSS style use on creating hints. This might also be averrules by css out of - * $XDG_CONFIG_HOME/vimb/style.css file. */ -#define HINT_CSS "#_hintContainer{\ -position:static\ -}\ -._hintLabel{\ --webkit-transform:translate(-4px,-4px);\ -position:absolute;\ -z-index:100000;\ -font:bold .8em monospace;\ -color:#000;\ -background-color:#fff;\ -margin:0;\ -padding:0px 1px;\ -border:1px solid #444;\ -opacity:0.7\ -}\ -._hintElem{\ -background-color:#ff0 !important;\ -color:#000 !important;\ -transition:all 0 !important;\ -transition-delay:all 0 !important\ -}\ -._hintElem._hintFocus{\ -background-color:#8f0 !important\ -}\ -._hintLabel._hintFocus{\ -z-index:100001;\ -opacity:1\ -}" - diff --git a/src/scripts/hints.css b/src/scripts/hints.css new file mode 100644 index 0000000..c061121 --- /dev/null +++ b/src/scripts/hints.css @@ -0,0 +1,28 @@ +#_hintContainer{ + position:static +} +._hintLabel{ + -webkit-transform:translate(-4px,-4px); + background-color:#fff; + border:1px solid #444; + color:#000; + font:bold .8em monospace; + margin:0; + opacity:0.7; + padding:0px 1px; + position:absolute; + z-index:100000 +} +._hintElem{ + background-color:#ff0 !important; + color:#000 !important; + transition-delay:all 0 !important; + transition:all 0 !important +} +._hintElem._hintFocus{ + background-color:#8f0 !important +} +._hintLabel._hintFocus{ + opacity:1; + z-index:10000 +} diff --git a/src/scripts/hints.js b/src/scripts/hints.js index 80c5df2..eeef5b7 100644 --- a/src/scripts/hints.js +++ b/src/scripts/hints.js @@ -197,9 +197,6 @@ var hints = Object.freeze((function(){ if (doc.body) { doc.body.appendChild(hDiv); } - /* create the default style sheet */ - createStyle(doc); - docs.push({ doc: doc, start: start, @@ -318,18 +315,6 @@ var hints = Object.freeze((function(){ return [doc.defaultView.scrollX, doc.defaultView.scrollY]; } - function createStyle(doc) { - if (doc.hasStyle) { - return; - } - var e = doc.createElement("style"); - /* HINT_CSS is replaces by the contents of the HINT_CSS constant from config.h */ - e.innerHTML = "HINT_CSS"; - doc.head.appendChild(e); - /* prevent us from adding the style multiple times */ - doc.hasStyle = true; - } - function focus(back) { var idx = validHints.indexOf(activeHint); /* previous active hint not found */ diff --git a/src/scripts/js2h.sh b/src/scripts/js2h.sh index 4a50c12..ce38d9d 100755 --- a/src/scripts/js2h.sh +++ b/src/scripts/js2h.sh @@ -13,13 +13,13 @@ if [ ! -r "$FILE" ]; then exit 1 fi -# Remove the path and .js file extension and turn all chars to upper case to -# get the constant name. -CONSTANT=$(echo "$FILE" | sed 's:.*/::g' | sed 's:^\(.*\).\(js\):\2_\1:g' | tr a-z A-Z) +# Put file extension and _ before file name, turn all to upper case to get the +# constant name. +CONSTANT=$(echo "$FILE" | sed 's:.*/::g' | sed 's:^\(.*\).\(css\|js\):\2_\1:g' | tr a-z A-Z) # minify the script cat $FILE | \ -# removove single line comments +# remove single line comments sed -e 's|^//.*$||g' | \ # remove linebreaks tr '\n\r' ' ' | \ @@ -32,8 +32,7 @@ sed -e 's:/\*[^*]*\*/::g' \ # ecaspe sed -e 's|\\x20| |g' \ -e 's|\\|\\\\|g' \ - -e 's|"|\\"|g' \ - -e 's|HINT_CSS|" HINT_CSS "|' | \ + -e 's|"|\\"|g' | \ # write opener with the starting and ending quote char sed -e "1s/^/#define $CONSTANT \"/" \ -e '$s/$/"\n/' diff --git a/src/setting.c b/src/setting.c index 0df1881..54e9b18 100644 --- a/src/setting.c +++ b/src/setting.c @@ -657,6 +657,14 @@ static int user_style(Client *c, const char *name, DataType type, void *value, v webkit_user_content_manager_remove_all_style_sheets(ucm); } + /* Inject the global styles with author level to allow restyling by user + * style sheets. */ + style = webkit_user_style_sheet_new(CSS_HINTS, + WEBKIT_USER_CONTENT_INJECT_TOP_FRAME, + WEBKIT_USER_STYLE_LEVEL_AUTHOR, NULL, NULL); + webkit_user_content_manager_add_style_sheet(ucm, style); + webkit_user_style_sheet_unref(style); + return CMD_SUCCESS; }