why is "hbox" width property a string not an int

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

why is "hbox" width property a string not an int

Unread post by thosrtanner » 2017-10-28, 10:54

I suspect this is in firefox as well, but looking at the specs on mdm (https://developer.mozilla.org/en-US/doc ... erty/width), it suggests that the width property (not attribute) is an integer, which it very clearly isn't, it's a string, which means I need to convert it to an integer if I want to do calculations with it.

I was wondering why this was the case

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: why is "hbox" width property a string not an int

Unread post by Moonchild » 2017-10-29, 06:58

The attributes are strings, which is what you'd normally work with, not the properties.

Can you provide a code example?
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: why is "hbox" width property a string not an int

Unread post by thosrtanner » 2017-10-29, 11:05

Something along the lines of this:

Code: Select all

    let elem = document.getElementByID("something that is an hbox");
    console.log(elem.width, elem.clientWidth);
produces (e.g.)

Code: Select all

     "150", 150
Its a little unclear to me, because attributes that are boolean (e.g. box.setAttribute("collapsed", "true")) correspond to properties that are actual booleans (true/false). For instance, that would result in

Code: Select all

console.log(hbox.getAttribute("collapsed"), hbox.collapsed)
producing

Code: Select all

"true", true
, which is different to the way the 'integer' properties work.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: why is "hbox" width property a string not an int

Unread post by Moonchild » 2017-10-29, 21:08

I'm pretty sure this is correctly implemented, so I verified this with a little test on a XUL window (the about box).
It returns an int on hbox.width -- so it's correct.

Make sure you're querying and setting attributes/properties on the correct element.

e.g., using the following in the about box:

Code: Select all

  let elem = document.getElementById("PMclientBox");
  console.log(elem.width);
  console.log(elem.height);
  console.log(elem);
Results in:

Code: Select all

552
""
<hbox id="PMclientBox">
hbox doesn't have a height, vbox doesn't have a width; if you mix the two up and set/query a "width" on a "vbox", then it will almost certainly be returned as a string (since you created the new property).
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: why is "hbox" width property a string not an int

Unread post by thosrtanner » 2017-10-30, 08:41

Well, that's strange. My XUL says this:

Code: Select all

          <hbox id="inforss.newsbox1"
                flex="1"
                style="position:relative; overflow:hidden;"
                draggable="false"
                ondragstart="return false"
                ondragover="bar_observer.on_drag_over(event)"
                ondrop="bar_observer.on_drop(event)"
                onmouseover="inforssHeadlineDisplay.pauseScrolling(false)"
                onmouseout="inforssHeadlineDisplay.pauseScrolling(true)"/>
Which I thought might be the issue, but adding a width="0" didn't fix it.

It is attached to the status bar if that is in any way related.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35473
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: why is "hbox" width property a string not an int

Unread post by Moonchild » 2017-10-30, 12:26

I think "flex=1" is your culprit. If you make an hbox flexible, its intrinsic width becomes undefined (since it'll flex to fill the space).
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: why is "hbox" width property a string not an int

Unread post by thosrtanner » 2017-10-30, 16:59

Admittedly the flex seems rather pointless on a display element where the code is manually setting the width.

However, I got rid of the flex and setting style.width to a number of pixels, and it still does that. Even setting the width property to an integer in the browser console ends up with a string.

Locked