2007-01-13 01:04:56 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
// vim:cindent:ts=4:et:sw=4:
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-01-13 01:04:56 +00:00
|
|
|
|
2013-11-15 02:49:29 +00:00
|
|
|
#ifndef SpanningCellSorter_h
|
|
|
|
#define SpanningCellSorter_h
|
|
|
|
|
2007-01-13 01:04:56 +00:00
|
|
|
/*
|
|
|
|
* Code to sort cells by their colspan, used by BasicTableLayoutStrategy.
|
|
|
|
*/
|
|
|
|
|
2015-09-16 03:49:53 +00:00
|
|
|
#include "PLDHashTable.h"
|
2010-04-10 20:09:38 +00:00
|
|
|
#include "nsDebug.h"
|
2012-05-04 00:14:02 +00:00
|
|
|
#include "StackArena.h"
|
2010-04-10 20:09:38 +00:00
|
|
|
|
2007-01-13 01:04:56 +00:00
|
|
|
/**
|
|
|
|
* The SpanningCellSorter is responsible for accumulating lists of cells
|
|
|
|
* with colspans so that those cells can later be enumerated, sorted
|
|
|
|
* from lowest number of columns spanned to highest. It does not use a
|
|
|
|
* stable sort (in fact, it currently reverses).
|
|
|
|
*/
|
2013-04-12 03:20:45 +00:00
|
|
|
class MOZ_STACK_CLASS SpanningCellSorter {
|
2007-01-13 01:04:56 +00:00
|
|
|
public:
|
2012-07-15 04:20:24 +00:00
|
|
|
SpanningCellSorter();
|
2007-01-13 01:04:56 +00:00
|
|
|
~SpanningCellSorter();
|
|
|
|
|
|
|
|
struct Item {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t row, col;
|
2007-01-13 01:04:56 +00:00
|
|
|
Item *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a cell to the sorter. Returns false on out of memory.
|
|
|
|
* aColSpan is the number of columns spanned, and aRow/aCol are the
|
|
|
|
* position of the cell in the table (for GetCellInfoAt).
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
bool AddCell(int32_t aColSpan, int32_t aRow, int32_t aCol);
|
2007-01-13 01:04:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the next *list* of cells. Each list contains all the cells
|
|
|
|
* for a colspan value, and the lists are given in order from lowest
|
|
|
|
* to highest colspan. The colspan value is filled in to *aColSpan.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
Item* GetNext(int32_t *aColSpan);
|
2007-01-13 01:04:56 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
enum State { ADDING, ENUMERATING_ARRAY, ENUMERATING_HASH, DONE };
|
|
|
|
State mState;
|
|
|
|
|
|
|
|
// store small colspans in an array for fast sorting and
|
|
|
|
// enumeration, and large colspans in a hash table
|
|
|
|
|
|
|
|
enum { ARRAY_BASE = 2 };
|
|
|
|
enum { ARRAY_SIZE = 8 };
|
|
|
|
Item *mArray[ARRAY_SIZE];
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t SpanToIndex(int32_t aSpan) { return aSpan - ARRAY_BASE; }
|
|
|
|
int32_t IndexToSpan(int32_t aIndex) { return aIndex + ARRAY_BASE; }
|
|
|
|
bool UseArrayForSpan(int32_t aSpan) {
|
2007-01-13 01:04:56 +00:00
|
|
|
NS_ASSERTION(SpanToIndex(aSpan) >= 0, "cell without colspan");
|
|
|
|
return SpanToIndex(aSpan) < ARRAY_SIZE;
|
|
|
|
}
|
|
|
|
|
2015-05-19 23:46:17 +00:00
|
|
|
PLDHashTable mHashTable;
|
2007-01-13 01:04:56 +00:00
|
|
|
struct HashTableEntry : public PLDHashEntryHdr {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mColSpan;
|
2007-01-13 01:04:56 +00:00
|
|
|
Item *mItems;
|
|
|
|
};
|
|
|
|
|
2013-11-19 02:51:48 +00:00
|
|
|
static const PLDHashTableOps HashTableOps;
|
2007-01-13 01:04:56 +00:00
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PLDHashNumber
|
2007-01-13 01:04:56 +00:00
|
|
|
HashTableHashKey(PLDHashTable *table, const void *key);
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2007-01-13 01:04:56 +00:00
|
|
|
HashTableMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
|
|
|
|
const void *key);
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PLDHashOperator
|
2007-01-13 01:04:56 +00:00
|
|
|
FillSortedArray(PLDHashTable *table, PLDHashEntryHdr *hdr,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t number, void *arg);
|
2007-01-13 01:04:56 +00:00
|
|
|
|
|
|
|
static int SortArray(const void *a, const void *b, void *closure);
|
|
|
|
|
|
|
|
/* state used only during enumeration */
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mEnumerationIndex; // into mArray or mSortedHashTable
|
2007-01-13 01:04:56 +00:00
|
|
|
HashTableEntry **mSortedHashTable;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* operator new is forbidden since we use the pres shell's stack
|
|
|
|
* memory, which much be pushed and popped at points matching a
|
|
|
|
* push/pop on the C++ stack.
|
|
|
|
*/
|
2012-07-30 14:20:58 +00:00
|
|
|
void* operator new(size_t sz) CPP_THROW_NEW { return nullptr; }
|
2007-01-13 01:04:56 +00:00
|
|
|
};
|
|
|
|
|
2013-11-15 02:49:29 +00:00
|
|
|
#endif
|