dynamic set' ignores background-color on tbody-nodes

95 views
Skip to first unread message

m.meier

unread,
Mar 25, 2011, 8:40:46 AM3/25/11
to tkhtml3
Hello,

i need to goup table-rows with 'tdata' -tags so that i can select a
bunch of rows an mark them.
(like in an tablelist-widget)

But tkhtml seems to ignore ' background-color' on tbody-tags.

Here the sample code

# test.tcl
-------------------------------------------------------------------------------

# # #
# 'dynamic set' ignores background-color on tbody-nodes
#

set data "

<html><head>
<style type=\"text/css\">

tbody:hover { background-color:green; color:red; }
</style>

</head><body>
<table border=\"1\">
<tbody>
<TR><TD>column1-1</TD></TR>
<TR><TD>column1-2</TD></TR>
</tbody>
<tbody>
<TR><TD>column2-1</TD></TR>
<TR><TD>column2-2</TD></TR>
</tbody>
</table>
</body></html>
"

package require Tkhtml


proc htmlStyleHandler {id data} {
.h style $data
}


html .h

grid .h -sticky nesw

.h handler script style htmlStyleHandler

.h parse -final $data


set nodes [.h node]

# Find the first 'tbody'-node and set 'dynamic set hover'
set node {}
while { [llength $nodes] } {

set node [lindex $nodes 0]
set nodes [lreplace $nodes 0 0]

if { [$node tag] == "tbody" } {
$node dynamic set hover
break
}

set nodes [concat $nodes [$node children]]
}
#
----------------------------------------------------------------------------------------

m.meier

unread,
Apr 11, 2011, 11:29:28 AM4/11/11
to tkhtml3
Hello,

the problem could be fixed if the function HtmlComputedValuesInit
would be changed to the following code.
But I'm not sure why
"HtmlColor *cBackgroundColor; /* 'background-color' */"
is not in the
/* INHERITED PROPERTIES START HERE */
block in
struct HtmlComputedValues
.

Here the Code (see the 20110411-part)



-----------------------------------------------------
void
HtmlComputedValuesInit(pTree, pNode, pParent, p)
HtmlTree *pTree;
HtmlNode *pNode; /* Node to use for LOG blocks */
HtmlNode *pParent; /* Node to inherit properties
from */
HtmlComputedValuesCreator *p;
{
HtmlComputedValues *pValues = &p->values;
char *values = (char *)pValues;

unsigned int iCopyMask = 0;
int iCopyBytes = 0;
HtmlComputedValuesCreator *pPrototype;

if (0 == pParent) {
pParent = HtmlNodeParent(pNode);
}

/* Copy non-inherited values from the prototype creator object. If
* there is no parent node, then this is all there is to do.
*/
pPrototype = getPrototypeCreator(pTree, &iCopyMask, &iCopyBytes);
memcpy(p, pPrototype, sizeof(HtmlComputedValuesCreator));
p->pTree = pTree;
p->pParent = pParent;
p->pNode = pNode;

/* Copy property values that are inherited by default from the
* properties of the parent node, if there is one.
*/
if (pParent) {
int nBytes = sizeof(HtmlComputedValues) - iCopyBytes;
char *pvalues = (char *)((HtmlElementNode *)pParent)-
>pPropertyValues;
HtmlComputedValues *pParentValues = (HtmlComputedValues
*)pValues;
memcpy(&values[iCopyBytes], &pvalues[iCopyBytes], nBytes);
memcpy(&p->fontKey, pValues->fFont->pKey,
sizeof(HtmlFontKey));
pValues->mask =
(pValues->mask & iCopyMask) | (pParentValues->mask & !
iCopyMask);
#if 20110411
/* inherit background from parent */
p->values.cBackgroundColor->nRef++;
decrementColorRef(pTree, p->values.cBackgroundColor );

p->values.cBackgroundColor = ((HtmlElementNode *)pParent)-
>pPropertyValues->cBackgroundColor;
#endif
}

p->values.cColor->nRef++;
p->values.cBackgroundColor->nRef++;
HtmlImageRef(p->values.imListStyleImage);

assert(!p->values.cBorderTopColor);
assert(!p->values.cBorderRightColor);
assert(!p->values.cBorderBottomColor);
assert(!p->values.cBorderLeftColor);
assert(!p->values.cOutlineColor);
}
------------------------------------------------------------------







jemptymethod

unread,
Apr 12, 2011, 6:40:38 AM4/12/11
to tkhtml3
On Apr 11, 11:29 am, "m.meier" <me...@fuh-e.de> wrote:
> Hello,
>
> the problem could be fixed if the function HtmlComputedValuesInit
> would be changed to the following code.
> But I'm not sure why
> "HtmlColor *cBackgroundColor;      /* 'background-color' */"
> is not in the
>     /* INHERITED PROPERTIES START HERE */
> block in
> struct HtmlComputedValues
> .
>
> Here the Code (see the 20110411-part)

Excellent! If you've compiled your code and it runs on your system,
if you haven't already, you might want to clone the tkhmtl fossil
repo, commit your changes, and even push them. I can try to be more
help with this facet of things than with C code, though not until
April 20th or so (I'm preparing for a tech presentation on an entirely
different topic next Tues April 19).

Perhaps it is of no interest to you, but there is also an issue with
CSS min-width not being applied.

Matthias Meier

unread,
Apr 13, 2011, 4:36:42 AM4/13/11
to tkh...@googlegroups.com
jemptymethod schrieb:

As I'm not an css-expert I'm not sure if it is realy an bug, that 'background-color' of a child is not
inherited from it's parent (like 'color' is)
In my opinion it is - but I would like to hear some experts.

If it is considered as a bug, i will commit my changes (respectively move 'background-color'
to the /* INHERITED PROPERTIES START HERE */ - block in the HtmlComputedValues struct.

Matthias


jemptymethod

unread,
Apr 13, 2011, 5:00:43 AM4/13/11
to tkhtml3
On Apr 13, 4:36 am, Matthias Meier <Me...@FuH-E.de> wrote:
>
> As I'm not an css-expert I'm not sure if it is realy an bug, that 'background-color' of a child is not
> inherited from it's parent (like 'color' is)
> In my opinion it is - but I would like to hear some experts.
>
> If it is considered as a bug, i will commit my changes (respectively move 'background-color'
> to the  /* INHERITED PROPERTIES START HERE */ - block in the HtmlComputedValues struct.

Maybe we should ask on stackoverflow about whether its a CSS bug?

jemptymethod

unread,
Apr 13, 2011, 5:44:14 AM4/13/11
to tkhtml3
Have you tried the HTML above in other browsers? Because I just tried
it in IE, Chrome, FF, Opera and Safari, and it does *not* work the way
you seem to intend in any of those.

I'm no CSS/style guru, but typically when I need to set background
colors within tables, I do so on the TR element. Indeed, adding hover
to the mix, this would seem to be what is required; google for 'css
tbody hover' and you will all the examples feature css such as: "tbody
tr:hover { background: ...."

Sorry but upon deeper consideration I would not be inclined to accept
this as a bug until you can demonstrate the HTML/CSS that works in
other browsers, that does not work with TkHTML/Hv3. Or am I missing
something?

Matthias Meier

unread,
Apr 13, 2011, 6:47:23 AM4/13/11
to tkh...@googlegroups.com
jemptymethod schrieb:

>> set data "
>>
>> <html><head>
>> <style type=\"text/css\">
>>
>> tbody:hover { background-color:green; color:red; }
>> </style>
>>
>> </head><body>
>> <table border=\"1\">
>> <tbody>
>> <TR><TD>column1-1</TD></TR>
>> <TR><TD>column1-2</TD></TR>
>> </tbody>
>> <tbody>
>> <TR><TD>column2-1</TD></TR>
>> <TR><TD>column2-2</TD></TR>
>> </tbody>
>> </table>
>> </body></html>
>
> Have you tried the HTML above in other browsers? Because I just tried
> it in IE, Chrome, FF, Opera and Safari, and it does *not* work the way
> you seem to intend in any of those.

Yes, I tested the html in SeaMonkey 1.1.2 and Firefox 3.6.6 and it works the way I expect.
(Both rows in one <tbody> are 'highlighted' as the mouse is over one row)
(You have to remove the '\"' in the tcl-code: '<style type=\"text/css\">' --> '<style type="text/css">'


IE 6.0 and IE 8.0 seem to ignore the "tbody:hover ..."


Matthias Meier

unread,
Apr 13, 2011, 7:26:12 AM4/13/11
to tkh...@googlegroups.com
jemptymethod schrieb:


> Have you tried the HTML above in other browsers? Because I just tried
> it in IE, Chrome, FF, Opera and Safari, and it does *not* work the way
> you seem to intend in any of those.

':hover' seems not to work well in IE - there are some articles about this problem on the web.
Im my tests i got in only working on links (<a href=...)

See also:

http://hackprogrammer.blogspot.com/2008/09/ie8-css-hover-not-working.html
http://www.xs4all.nl/~peterned/csshover.html
http://www.daniweb.com/web-development/web-design/html-and-css/threads/315415


Matthias Meier

unread,
May 2, 2011, 11:46:05 AM5/2/11
to tkh...@googlegroups.com

As i sugested in the quoted earlier post and because i could not think of any reason why background-color should not be inerited, i moved now the 'background-color-property' to the "INHERITED PROPERTIES START HERE"-block in htmlprop.h.

I tried to 'push' my changes but i got an error:


fossil push
...
Error: not authorized to write

How do i get my changes uploaded?

Matthias


jemptymethod schrieb:


> On Apr 11, 11:29 am, "m.meier" <me...@fuh-e.de> wrote:
>> Hello,
>>
>> the problem could be fixed if the function HtmlComputedValuesInit
>> would be changed to the following code.
>> But I'm not sure why
>> "HtmlColor *cBackgroundColor; /* 'background-color' */"
>> is not in the
>> /* INHERITED PROPERTIES START HERE */
>> block in
>> struct HtmlComputedValues
>> .
>>
>> Here the Code (see the 20110411-part)
>
> Excellent! If you've compiled your code and it runs on your system,
> if you haven't already, you might want to clone the tkhmtl fossil
> repo, commit your changes, and even push them. I can try to be more
> help with this facet of things than with C code, though not until
> April 20th or so (I'm preparing for a tech presentation on an entirely
> different topic next Tues April 19).

--
Mit freundlichen Gr��en

Matthias Meier
FuH Entwicklungsgesellschaft mbH
Gesch�ftsf�hrer Carola Fornoff und J�rg-Friedrich Sch�ner
HRB Freiburg 701203, UID DE255007372
Hauptstr. 4, D-79224 Umkirch
Tel +49 7665 93288-0, Fax -150

Dan

unread,
May 2, 2011, 12:10:39 PM5/2/11
to tkhtml3

Technically I don't think it is an inherited property (see
the CSS 2.1 spec). The default value for background-color
is "transparent".

Really, tkhtml should be changed to render the tbody element.

Matthias Meier

unread,
May 3, 2011, 2:49:45 AM5/3/11
to tkh...@googlegroups.com
I checked the CSS 2.1 spec and I think you're right:

As it is written on http://www.w3.org/TR/CSS21/colors.html
'background-color' is not inherited. (seems still strange to me - but thats the way it is)

But i also found a 'workaround' I can live with:

Just changed the syle from

tbody:hover { background-color:green; color:red; }

to

tbody:hover * { background-color:green; color:red; }


Thanks for all help!
Matthias

Dan schrieb:

Reply all
Reply to author
Forward
0 new messages