Skip to content

Commit

Permalink
Merge pull request #123 from SWTI2014/rendering/html-table
Browse files Browse the repository at this point in the history
  • Loading branch information
rs22 committed Jun 28, 2014
2 parents 9b2bbb2 + 2cf2382 commit 90b5891
Show file tree
Hide file tree
Showing 93 changed files with 533 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ parseTextAttributesFrom: aCSSProperty into: aContext
values := Dictionary newFrom: {
'inline' -> #inline.
'inline-block' -> #inlineBlock.
'block' -> #block
'block' -> #block.
'table' -> #table.
'table-row' -> #tableRow.
'table-cell' -> #tableCell
}.
values at: aCSSProperty propertyString asLowercase
ifPresent: [:value | aContext at: #block put: value ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"class" : {
},
"instance" : {
"parseTextAttributesFrom:into:" : "rs 6/7/2014 16:39:45.066" } }
"parseTextAttributesFrom:into:" : "rs 6/28/2014 10:25:03.2" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialize-release
addDefaultStyle
| styles |
styles := Dictionary newFrom: {
'display' -> 'table'.
}.
self addStyle: (CSSStyleRule fromDictionary: styles)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rendering
addToHtmlMorph: aHtmlBlockMorph
super addToHtmlMorph: aHtmlBlockMorph.
((self attributes at: #border ifAbsent: ['0']) = '0') ifFalse: [htmlMorph addTableLines].
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
initialize-release
defaultBlockMorph
^ HtmlTableMorph
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"class" : {
},
"instance" : {
"addDefaultStyle" : "rs 6/28/2014 10:23:46.659",
"addToHtmlMorph:" : "pf 6/24/2014 21:28",
"defaultBlockMorph" : "pf 6/15/2014 13:54",
"endStyles:" : "rs 5/18/2014 14:55:25.474",
"startStyles:" : "rs 5/18/2014 14:55:12.512",
"tag" : "" } }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
test01TableShouldRenderAsHtmlTableMorph

self assert: HtmlTABLENode new getHtmlBlockMorph class equals: HtmlTableMorph
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
testing
test02TableElementsInColumnShouldHaveSameXPositions
| document table |
document := HtmlDocument new.
document parseContents:
(ReadStream on: '<table>
<tr><td>First</td><td>Second item</td></tr>
<tr><td>Third item</td><td>Fourth</td></tr>
</table>').
table := document children first getHtmlBlockMorph.
table layoutInBounds: table bounds.
self assert: table children first bounds origin x equals: table children third bounds origin x.
self assert: table children second bounds origin x equals: table children fourth bounds origin x.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
testing
test03TableElementsInRowsShouldHaveSameYPositions
| document table |
document := HtmlDocument new.
document parseContents:
(ReadStream on: '<table>
<tr><td>First</td><td>Second item</td></tr>
<tr><td>Third item</td><td>Fourth</td></tr>
</table>').
table := document children first getHtmlBlockMorph.
table layoutInBounds: table bounds.
self assert: table children first bounds origin y equals: table children second bounds origin y.
self assert: table children third bounds origin y equals: table children fourth bounds origin y.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
testing
test04TableWithUnknownTagShouldntRaiseErrors
| document |
document := HtmlDocument new.
document parseContents:
(ReadStream on: '<table border="1">
<caption>a caption for a table</caption>
<tr>
<td><i>italic text in a td cell</i></td>
</tr>
</table>').
self shouldnt: [document children first getHtmlBlockMorph] raise: Error.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"class" : {
},
"instance" : {
"test01TableShouldRenderAsHtmlTableMorph" : "pf 6/26/2014 18:43",
"test02TableElementsInColumnShouldHaveSameXPositions" : "pf 6/27/2014 00:01",
"test03TableElementsInRowsShouldHaveSameYPositions" : "pf 6/27/2014 00:01",
"test04TableWithUnknownTagShouldntRaiseErrors" : "pf 6/28/2014 09:14" } }
14 changes: 14 additions & 0 deletions packages/HTML.package/HtmlTABLENodeTest.class/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "HTML-Tests",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "HtmlTABLENodeTest",
"pools" : [
],
"super" : "TestCase",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialize-release
addDefaultStyle
| styles |
styles := Dictionary newFrom: {
'display' -> 'block'.
}.
self addStyle: (CSSStyleRule fromDictionary: styles)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rendering
addToHtmlMorph: aHtmlTableMorph
self children do: [ :ea |
ea addToHtmlMorph: aHtmlTableMorph.
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
"class" : {
},
"instance" : {
"addDefaultStyle" : "pf 6/26/2014 19:45",
"addToHtmlMorph:" : "pf 6/26/2014 19:46",
"tag" : "" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialize-release
addDefaultStyle
| styles |
styles := Dictionary newFrom: {
'display' -> 'table-cell'.
}.
self addStyle: (CSSStyleRule fromDictionary: styles)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"class" : {
},
"instance" : {
"addDefaultStyle" : "rs 6/28/2014 10:19:56.765",
"endStyles:" : "rs 5/18/2014 14:55:51.054",
"tag" : "" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
initialize-release
addDefaultStyle
| styles |
styles := Dictionary newFrom: {
'display' -> 'block'.
'font-style' -> 'italic'.
}.
self addStyle: (CSSStyleRule fromDictionary: styles)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rendering
addToHtmlMorph: aHtmlTableMorph
self children do: [ :ea |
ea addToHtmlMorph: aHtmlTableMorph.
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
"class" : {
},
"instance" : {
"addDefaultStyle" : "pf 6/26/2014 19:43",
"addToHtmlMorph:" : "pf 6/26/2014 19:46",
"tag" : "" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
initialize-release
addDefaultStyle
| styles |
styles := Dictionary newFrom: {
'display' -> 'block'.
'font-weight' -> 'bold'.
}.
self addStyle: (CSSStyleRule fromDictionary: styles)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rendering
addToHtmlMorph: aHtmlTableMorph
self children do: [ :ea |
ea addToHtmlMorph: aHtmlTableMorph.
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
"class" : {
},
"instance" : {
"addDefaultStyle" : "pf 6/26/2014 19:41",
"addToHtmlMorph:" : "pf 6/26/2014 19:46",
"tag" : "" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
initialize-release
addDefaultStyle
| styles |
styles := Dictionary newFrom: {
'display' -> 'table-cell'.
'font-weight' -> 'bold'.
}.
self addStyle: (CSSStyleRule fromDictionary: styles)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
"class" : {
},
"instance" : {
"addDefaultStyle" : "rs 6/28/2014 10:20:11.145",
"tag" : "" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialize-release
addDefaultStyle
| styles |
styles := Dictionary newFrom: {
'display' -> 'table-row'.
}.
self addStyle: (CSSStyleRule fromDictionary: styles)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"class" : {
},
"instance" : {
"addDefaultStyle" : "rs 6/28/2014 10:19:47.956",
"endStyles:" : "rs 5/18/2014 14:57:15.828",
"tag" : "" } }
2 changes: 1 addition & 1 deletion packages/HTML.package/monticello.meta/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6cfa7f32-744a-da4e-839d-2d444502bc40
f9b06da3-193a-e946-90c1-5251ff072530
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'HTML-pf.100'message 'Ref #6: Fix layout of thead, tbody, tfoot'id '366dc269-acf3-e240-85c3-c75932a5df5e'date '26 June 2014'time '7:48:24.675 pm'author 'pf'ancestors ((id 'a05f980e-75af-654f-bf17-3170ad1ff959'))stepChildren ())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'HTML-pf.101'message 'Ref #6: Use consistent value comparison in HtmlTABLENodeTest'id '6058e555-c451-5242-9be7-b26f6b0a21bd'date '27 June 2014'time '12:02:42.106 am'author 'pf'ancestors ((id '366dc269-acf3-e240-85c3-c75932a5df5e'))stepChildren ())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'HTML-pf.102'message 'Ref #6: Use consistent value comparison in HtmlTABLENodeTest'id '8bd8ce75-a8a4-454f-a719-1072328b78c1'date '27 June 2014'time '12:03:33.659 am'author 'pf'ancestors ((id '6058e555-c451-5242-9be7-b26f6b0a21bd'))stepChildren ())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'HTML-pf.103'message 'Ref #124: Add test for unknown tags'id 'd685b735-6679-1848-bac7-bfd62c25f265'date '28 June 2014'time '9:17:15.065 am'author 'pf'ancestors ((id '8bd8ce75-a8a4-454f-a719-1072328b78c1'))stepChildren ())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'HTML-pf.99'message 'Ref #6: Add tests for table'id 'a05f980e-75af-654f-bf17-3170ad1ff959'date '26 June 2014'time '6:44:53.409 pm'author 'pf'ancestors ((id '6cfa7f32-744a-da4e-839d-2d444502bc40'))stepChildren ())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'HTML-rs.104'message 'Fix default display attribute value of table nodes'id 'f9b06da3-193a-e946-90c1-5251ff072530'date '28 June 2014'time '10:27:19.621 am'author 'rs'ancestors ((id 'd685b735-6679-1848-bac7-bfd62c25f265'))stepChildren ())
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
columns: anObject

columns := anObject
self recomputeRatios: columns.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
columns

^ columns
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
layout
computeSpacePositions: aSpaceCollection in: newBreadth

| pos |

"Compute the new positions"
pos := 0.
aSpaceCollection do: [ :ea | | b |
b := (newBreadth * (ea ratio)) asInteger.
b < ea min ifTrue: [ b := ea min ].
b > ea max ifTrue: [ b := ea max ].
ea position: pos ; breadth: b.
pos := pos + b.
].
^ pos
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
initialize-release
initialize
super initialize.
columns := OrderedCollection new.
rows := OrderedCollection new.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
layout
layout: aMorph in: newBounds
"Compute the layout for the given morph based on the new bounds"
| origin x y w h |
aMorph hasSubmorphs ifFalse: [^self].
self
recomputeRatios: columns;
recomputeRatios: rows.
origin := newBounds origin asIntegerPoint.

self layoutSpace: columns in: newBounds width.
self layoutSpace: rows in: newBounds height.

aMorph submorphs do: [ :morph | | gridPosition |
gridPosition := morph valueOfProperty: #gridPosition.
gridPosition notNil ifTrue: [ | column morphBounds row |
column := columns at: gridPosition column.
row := rows at: gridPosition row.
x := column position.
y := row position.
w := column breadth.
h := row breadth.
morphBounds := (origin + (x@y)) corner: (origin + (x@y) + (w@h)).
morph layoutInBounds: morphBounds.
]
].
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
layout
layoutSpace: aSpaceCollection in: newBreadth
|pos|

pos := self computeSpacePositions: aSpaceCollection in: newBreadth.

"If still space left, iterate until done or no more resizable columns"
pos < newBreadth ifTrue: [ | n |
[ n := (aSpaceCollection select: [ :ea | ea breadth < ea max ]) size.
(pos < newBreadth) and: [n > 0]] whileTrue: [ | bsup |
bsup := ((newBreadth - pos ) / n) asInteger.
bsup <= 0 ifTrue: [ bsup := 1 ].
pos := 0.
aSpaceCollection do: [ :ea | | b |
b := ea breadth.
((pos + b < newBreadth) and: [ b < ea max ]) ifTrue: [
b := b + bsup.
b > ea max ifTrue: [ b := ea max ].
].
ea position: pos; breadth: b.
pos := pos + b.
].
].
].

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
layout
recomputeRatios: aGridSpaceCollection
"Recompute ratios based on initial breadth"
| pos totalBreadth |
totalBreadth := self totalBreadth: aGridSpaceCollection.
pos := 0.
aGridSpaceCollection do: [ :ea |
ea start: (pos = 0 ifTrue: [ 0 ] ifFalse: [ 1 / (totalBreadth / pos) ]).
ea ratio: (1 / (totalBreadth / ea breadth)).
pos := pos + ea breadth.
].
^ pos
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
rows: anObject

rows := anObject.
self recomputeRatios: rows.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
rows

^ rows
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
totalBreadth: aGridSpaceCollection
^ (aGridSpaceCollection collect: [:ea | ea breadth]) sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"class" : {
},
"instance" : {
"columns" : "pf 6/21/2014 10:25",
"columns:" : "pf 6/21/2014 10:39",
"computeSpacePositions:in:" : "pf 6/21/2014 12:14",
"initialize" : "pf 6/21/2014 10:26",
"layout:in:" : "pf 6/27/2014 00:09",
"layoutSpace:in:" : "pf 6/21/2014 12:15",
"recomputeRatios:" : "pf 6/21/2014 12:14",
"rows" : "pf 6/21/2014 10:25",
"rows:" : "pf 6/21/2014 10:40",
"totalBreadth:" : "pf 6/21/2014 10:37" } }
Loading

0 comments on commit 90b5891

Please sign in to comment.