OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) | 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) |
3 * (C) 1997 Torben Weis (weis@kde.org) | 3 * (C) 1997 Torben Weis (weis@kde.org) |
4 * (C) 1998 Waldo Bastian (bastian@kde.org) | 4 * (C) 1998 Waldo Bastian (bastian@kde.org) |
5 * (C) 1999 Lars Knoll (knoll@kde.org) | 5 * (C) 1999 Lars Knoll (knoll@kde.org) |
6 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 6 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. | 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. |
8 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 8 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 if (inColSpan) | 245 if (inColSpan) |
246 c.inColSpan = true; | 246 c.inColSpan = true; |
247 } | 247 } |
248 m_cCol++; | 248 m_cCol++; |
249 cSpan -= currentSpan; | 249 cSpan -= currentSpan; |
250 inColSpan = true; | 250 inColSpan = true; |
251 } | 251 } |
252 cell->setCol(table()->effColToCol(col)); | 252 cell->setCol(table()->effColToCol(col)); |
253 } | 253 } |
254 | 254 |
255 void RenderTableSection::populateSpanningRowsHeightFromCell(RenderTableCell* cel l, struct SpanningRowsHeight& spanningRowsHeight) | |
256 { | |
257 const unsigned rowSpan = cell->rowSpan(); | |
258 const unsigned rowIndex = cell->rowIndex(); | |
259 | |
260 spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing = cell->logicalHe ightForRowSizing(); | |
261 | |
262 spanningRowsHeight.rowHeight.resize(rowSpan); | |
263 spanningRowsHeight.totalRowsHeight = 0; | |
264 for (unsigned row = 0; row < rowSpan; row++) { | |
265 unsigned actualRow = row + rowIndex; | |
266 spanningRowsHeight.rowHeight[row] = m_rowPos[actualRow + 1] - m_rowPos[a ctualRow] - borderSpacingForRow(actualRow); | |
267 spanningRowsHeight.totalRowsHeight += spanningRowsHeight.rowHeight[row]; | |
268 spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing -= borderSpac ingForRow(actualRow); | |
269 } | |
270 // We don't span the following row so its border-spacing (if any) should be included. | |
271 spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing += borderSpacingF orRow(rowIndex + rowSpan - 1); | |
272 } | |
273 | |
274 void RenderTableSection::distributeExtraRowSpanHeightToPercentRows(RenderTableCe ll* cell, int totalPercent, int& extraRowSpanningHeight, Vector<int>& rowsHeight ) | |
275 { | |
276 if (!extraRowSpanningHeight || !totalPercent) | |
277 return; | |
278 | |
279 const unsigned rowSpan = cell->rowSpan(); | |
280 const unsigned rowIndex = cell->rowIndex(); | |
281 int percent = min(totalPercent, 100); | |
282 const int tableHeight = m_rowPos[m_grid.size()] + extraRowSpanningHeight; | |
283 | |
284 // we are doing here as per FF. Extra spanning height would be distributed O nly in first percent height rows | |
Julien - ping for review
2013/07/18 18:19:30
Nit: I would turn the first sentence as:
// Our a
a.suchit
2013/07/20 14:57:23
Done.
| |
285 // those total percent is 100. Other percent rows would be uneffected even e xtra spanning height is remain. | |
286 int accumulatedPositionIncrease = 0; | |
287 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) { | |
288 if (percent > 0 && extraRowSpanningHeight > 0) { | |
289 if (m_grid[row].logicalHeight.isPercent()) { | |
290 int toAdd = (tableHeight * m_grid[row].logicalHeight.percent() / 100) - rowsHeight[row - rowIndex]; | |
Julien - ping for review
2013/07/18 18:19:30
Note that this is wrong if we have a percentage ab
a.suchit
2013/07/20 14:57:23
Done.
| |
291 | |
292 toAdd = min(toAdd, extraRowSpanningHeight); | |
293 accumulatedPositionIncrease += toAdd; | |
294 extraRowSpanningHeight -= toAdd; | |
295 percent -= m_grid[row].logicalHeight.percent(); | |
296 } | |
297 } | |
298 m_rowPos[row + 1] += accumulatedPositionIncrease; | |
299 } | |
300 } | |
301 | |
302 void RenderTableSection::distributeExtraRowSpanHeightToAutoRows(RenderTableCell* cell, int totalAutoRowsHeight, int& extraRowSpanningHeight, Vector<int>& rowsHe ight) | |
303 { | |
304 if (!extraRowSpanningHeight || !totalAutoRowsHeight) | |
305 return; | |
306 | |
307 const unsigned rowSpan = cell->rowSpan(); | |
308 const unsigned rowIndex = cell->rowIndex(); | |
309 int accumulatedPositionIncrease = 0; | |
310 int remainder = 0; | |
311 | |
312 // Extra height distributed in auto spanning rows based on their weightage i n spanning cell. | |
Julien - ping for review
2013/07/18 18:19:30
weightage is an Indian English word, let's use wei
a.suchit
2013/07/20 14:57:23
Done.
| |
313 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) { | |
314 if (m_grid[row].logicalHeight.isAuto()) { | |
315 accumulatedPositionIncrease += (extraRowSpanningHeight * rowsHeight[ row - rowIndex]) / totalAutoRowsHeight; | |
316 remainder += (extraRowSpanningHeight * rowsHeight[row - rowIndex]) % totalAutoRowsHeight; | |
317 | |
318 // While whole extra spanning height is distributing in auto spannin g rows, rational parts remains | |
319 // in every integer division. So accumulating all remainder part in integer division and when total remainder | |
320 // is equvalent to divisor then 1 unit increased in row position. | |
Julien - ping for review
2013/07/18 18:19:30
I would simplify this comment (which took me a whi
a.suchit
2013/07/20 14:57:23
Done.
| |
321 if (remainder >= totalAutoRowsHeight) { | |
322 remainder -= totalAutoRowsHeight; | |
323 accumulatedPositionIncrease++; | |
324 } | |
325 } | |
326 m_rowPos[row + 1] += accumulatedPositionIncrease; | |
327 } | |
328 | |
329 ASSERT(!remainder); | |
330 | |
331 extraRowSpanningHeight -= accumulatedPositionIncrease; | |
332 } | |
333 | |
334 void RenderTableSection::distributeExtraRowSpanHeightToRemainingRows(RenderTable Cell* cell, int totalRemainingRowsHeight, int& extraRowSpanningHeight, Vector<in t>& rowsHeight) | |
335 { | |
336 if (!extraRowSpanningHeight || !totalRemainingRowsHeight) | |
337 return; | |
338 | |
339 const unsigned rowSpan = cell->rowSpan(); | |
340 const unsigned rowIndex = cell->rowIndex(); | |
341 int accumulatedPositionIncrease = 0; | |
342 int remainder = 0; | |
343 | |
344 // Extra height distribution in remaining spanning rows based on their weigh tage in spanning cell. | |
345 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) { | |
346 if (!m_grid[row].logicalHeight.isPercent()) { | |
347 accumulatedPositionIncrease += (extraRowSpanningHeight * rowsHeight[ row - rowIndex]) / totalRemainingRowsHeight; | |
348 remainder += (extraRowSpanningHeight * rowsHeight[row - rowIndex]) % totalRemainingRowsHeight; | |
349 | |
350 // While whole extra spanning height is distributing in remaining sp anning rows, rational parts remains | |
351 // in every integer division. So accumulating all remainder part in integer division and when total remainder | |
352 // is equvalent to divisor then 1 unit increased in row position. | |
353 if (remainder >= totalRemainingRowsHeight) { | |
354 remainder -= totalRemainingRowsHeight; | |
355 accumulatedPositionIncrease++; | |
356 } | |
357 } | |
358 m_rowPos[row + 1] += accumulatedPositionIncrease; | |
359 } | |
360 | |
361 ASSERT(!remainder); | |
362 | |
363 extraRowSpanningHeight -= accumulatedPositionIncrease; | |
364 } | |
365 | |
255 // Distribute rowSpan cell height in rows those comes in rowSpan cell based on t he ratio of row's height if | 366 // Distribute rowSpan cell height in rows those comes in rowSpan cell based on t he ratio of row's height if |
256 // 1. RowSpan cell height is greater then the total height of rows in rowSpan ce ll | 367 // 1. RowSpan cell height is greater then the total height of rows in rowSpan ce ll |
257 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells) | 368 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells) |
258 { | 369 { |
259 ASSERT(rowSpanCells.size()); | 370 ASSERT(rowSpanCells.size()); |
260 | 371 |
261 // FIXME: For now, we handle the first rowspan cell in the table but this is wrong. | 372 // FIXME: For now, we handle the first rowspan cell in the table but this is wrong. |
262 RenderTableCell* cell = rowSpanCells[0]; | 373 RenderTableCell* cell = rowSpanCells[0]; |
263 | 374 |
264 unsigned rowSpan = cell->rowSpan(); | 375 unsigned rowSpan = cell->rowSpan(); |
265 unsigned rowIndex = cell->rowIndex(); | |
266 int initialPos = m_rowPos[rowIndex + rowSpan]; | |
267 | 376 |
268 int totalRowsHeight = 0; | 377 struct SpanningRowsHeight spanningRowsHeight; |
269 int rowSpanCellHeight = cell->logicalHeightForRowSizing(); | |
270 Vector<int> rowsHeight(rowSpan); | |
271 | 378 |
272 // Getting height of rows in current rowSpan cell, getting total height of r ows and adjusting rowSpan cell height with border spacing. | 379 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight); |
273 for (unsigned row = 0; row < rowSpan; row++) { | |
274 unsigned actualRow = row + rowIndex; | |
275 rowsHeight[row] = m_rowPos[actualRow + 1] - m_rowPos[actualRow] - border SpacingForRow(actualRow); | |
276 totalRowsHeight += rowsHeight[row]; | |
277 rowSpanCellHeight -= borderSpacingForRow(actualRow); | |
278 } | |
279 rowSpanCellHeight += borderSpacingForRow(rowIndex + rowSpan - 1); | |
280 | 380 |
281 if (!totalRowsHeight || rowSpanCellHeight <= totalRowsHeight) | 381 if (!spanningRowsHeight.totalRowsHeight || spanningRowsHeight.spanningCellHe ightIgnoringBorderSpacing <= spanningRowsHeight.totalRowsHeight) |
282 return; | 382 return; |
283 | 383 |
284 // Recalculating the height of rows based on rowSpan cell height if rowSpan cell height is more than total height of rows. | 384 unsigned rowIndex = cell->rowIndex(); |
285 int remainingHeight = rowSpanCellHeight; | 385 int totalPercent = 0; |
386 int totalAutoRowsHeight = 0; | |
387 int totalRemainingRowsHeight = spanningRowsHeight.totalRowsHeight; | |
286 | 388 |
389 // Calculate total percentage, total auto rows height and total rows height except percent rows. | |
287 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) { | 390 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) { |
288 int rowHeight = (rowSpanCellHeight * rowsHeight[row - rowIndex]) / total RowsHeight; | 391 if (m_grid[row].logicalHeight.isPercent()) { |
289 remainingHeight -= rowHeight; | 392 totalPercent += m_grid[row].logicalHeight.percent(); |
290 m_rowPos[row + 1] = m_rowPos[row] + rowHeight + borderSpacingForRow(row) ; | 393 totalRemainingRowsHeight -= spanningRowsHeight.rowHeight[row - rowIn dex]; |
394 } else if (m_grid[row].logicalHeight.isAuto()) { | |
395 totalAutoRowsHeight += spanningRowsHeight.rowHeight[row - rowIndex]; | |
396 } | |
291 } | 397 } |
292 // Remaining height added in the last row under rowSpan cell | 398 |
293 m_rowPos[rowIndex + rowSpan] += remainingHeight; | 399 int initialPos = m_rowPos[rowIndex + rowSpan]; |
400 int extraRowSpanningHeight = spanningRowsHeight.spanningCellHeightIgnoringBo rderSpacing - spanningRowsHeight.totalRowsHeight; | |
401 | |
402 distributeExtraRowSpanHeightToPercentRows(cell, totalPercent, extraRowSpanni ngHeight, spanningRowsHeight.rowHeight); | |
403 distributeExtraRowSpanHeightToAutoRows(cell, totalAutoRowsHeight, extraRowSp anningHeight, spanningRowsHeight.rowHeight); | |
404 distributeExtraRowSpanHeightToRemainingRows(cell, totalRemainingRowsHeight, extraRowSpanningHeight, spanningRowsHeight.rowHeight); | |
405 | |
406 ASSERT(!extraRowSpanningHeight); | |
294 | 407 |
295 // Getting total changed height in the table | 408 // Getting total changed height in the table |
296 unsigned changedHeight = changedHeight = m_rowPos[rowIndex + rowSpan] - init ialPos; | 409 unsigned changedHeight = m_rowPos[rowIndex + rowSpan] - initialPos; |
297 | 410 |
298 if (changedHeight) { | 411 if (changedHeight) { |
299 unsigned totalRows = m_grid.size(); | 412 unsigned totalRows = m_grid.size(); |
300 | 413 |
301 // Apply changed height by rowSpan cells to rows present at the end of t he table | 414 // Apply changed height by rowSpan cells to rows present at the end of t he table |
302 for (unsigned row = rowIndex + rowSpan + 1; row <= totalRows; row++) | 415 for (unsigned row = rowIndex + rowSpan + 1; row <= totalRows; row++) |
303 m_rowPos[row] += changedHeight; | 416 m_rowPos[row] += changedHeight; |
304 } | 417 } |
305 } | 418 } |
306 | 419 |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1516 if (!style()->isLeftToRightDirection()) | 1629 if (!style()->isLeftToRightDirection()) |
1517 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing); | 1630 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing); |
1518 else | 1631 else |
1519 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont alBorderSpacing); | 1632 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont alBorderSpacing); |
1520 | 1633 |
1521 cell->setLogicalLocation(cellLocation); | 1634 cell->setLogicalLocation(cellLocation); |
1522 view()->addLayoutDelta(oldCellLocation - cell->location()); | 1635 view()->addLayoutDelta(oldCellLocation - cell->location()); |
1523 } | 1636 } |
1524 | 1637 |
1525 } // namespace WebCore | 1638 } // namespace WebCore |
OLD | NEW |