layout/tables/SpanningCellSorter.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 // vim:cindent:ts=4:et:sw=4:
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef SpanningCellSorter_h
michael@0 8 #define SpanningCellSorter_h
michael@0 9
michael@0 10 /*
michael@0 11 * Code to sort cells by their colspan, used by BasicTableLayoutStrategy.
michael@0 12 */
michael@0 13
michael@0 14 #include "pldhash.h"
michael@0 15 #include "nsDebug.h"
michael@0 16 #include "StackArena.h"
michael@0 17
michael@0 18 class nsIPresShell;
michael@0 19
michael@0 20 /**
michael@0 21 * The SpanningCellSorter is responsible for accumulating lists of cells
michael@0 22 * with colspans so that those cells can later be enumerated, sorted
michael@0 23 * from lowest number of columns spanned to highest. It does not use a
michael@0 24 * stable sort (in fact, it currently reverses).
michael@0 25 */
michael@0 26 class MOZ_STACK_CLASS SpanningCellSorter {
michael@0 27 public:
michael@0 28 SpanningCellSorter();
michael@0 29 ~SpanningCellSorter();
michael@0 30
michael@0 31 struct Item {
michael@0 32 int32_t row, col;
michael@0 33 Item *next;
michael@0 34 };
michael@0 35
michael@0 36 /**
michael@0 37 * Add a cell to the sorter. Returns false on out of memory.
michael@0 38 * aColSpan is the number of columns spanned, and aRow/aCol are the
michael@0 39 * position of the cell in the table (for GetCellInfoAt).
michael@0 40 */
michael@0 41 bool AddCell(int32_t aColSpan, int32_t aRow, int32_t aCol);
michael@0 42
michael@0 43 /**
michael@0 44 * Get the next *list* of cells. Each list contains all the cells
michael@0 45 * for a colspan value, and the lists are given in order from lowest
michael@0 46 * to highest colspan. The colspan value is filled in to *aColSpan.
michael@0 47 */
michael@0 48 Item* GetNext(int32_t *aColSpan);
michael@0 49 private:
michael@0 50
michael@0 51 enum State { ADDING, ENUMERATING_ARRAY, ENUMERATING_HASH, DONE };
michael@0 52 State mState;
michael@0 53
michael@0 54 // store small colspans in an array for fast sorting and
michael@0 55 // enumeration, and large colspans in a hash table
michael@0 56
michael@0 57 enum { ARRAY_BASE = 2 };
michael@0 58 enum { ARRAY_SIZE = 8 };
michael@0 59 Item *mArray[ARRAY_SIZE];
michael@0 60 int32_t SpanToIndex(int32_t aSpan) { return aSpan - ARRAY_BASE; }
michael@0 61 int32_t IndexToSpan(int32_t aIndex) { return aIndex + ARRAY_BASE; }
michael@0 62 bool UseArrayForSpan(int32_t aSpan) {
michael@0 63 NS_ASSERTION(SpanToIndex(aSpan) >= 0, "cell without colspan");
michael@0 64 return SpanToIndex(aSpan) < ARRAY_SIZE;
michael@0 65 }
michael@0 66
michael@0 67 PLDHashTable mHashTable;
michael@0 68 struct HashTableEntry : public PLDHashEntryHdr {
michael@0 69 int32_t mColSpan;
michael@0 70 Item *mItems;
michael@0 71 };
michael@0 72
michael@0 73 static const PLDHashTableOps HashTableOps;
michael@0 74
michael@0 75 static PLDHashNumber
michael@0 76 HashTableHashKey(PLDHashTable *table, const void *key);
michael@0 77 static bool
michael@0 78 HashTableMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
michael@0 79 const void *key);
michael@0 80
michael@0 81 static PLDHashOperator
michael@0 82 FillSortedArray(PLDHashTable *table, PLDHashEntryHdr *hdr,
michael@0 83 uint32_t number, void *arg);
michael@0 84
michael@0 85 static int SortArray(const void *a, const void *b, void *closure);
michael@0 86
michael@0 87 /* state used only during enumeration */
michael@0 88 uint32_t mEnumerationIndex; // into mArray or mSortedHashTable
michael@0 89 HashTableEntry **mSortedHashTable;
michael@0 90
michael@0 91 /*
michael@0 92 * operator new is forbidden since we use the pres shell's stack
michael@0 93 * memory, which much be pushed and popped at points matching a
michael@0 94 * push/pop on the C++ stack.
michael@0 95 */
michael@0 96 void* operator new(size_t sz) CPP_THROW_NEW { return nullptr; }
michael@0 97 };
michael@0 98
michael@0 99 #endif

mercurial