PassRefPtrWillBeRawPtr<HTMLElement> HTMLTableElement::createTBody() { RefPtrWillBeRawPtr<HTMLTableSectionElement> body = HTMLTableSectionElement::create(tbodyTag, document()); Node* referenceElement = lastBody() ? lastBody()->nextSibling() : 0; insertBefore(body, referenceElement); return body.release(); }
HTMLTableSectionElement* HTMLTableElement::createTBody() { HTMLTableSectionElement* body = HTMLTableSectionElement::create(tbodyTag, document()); Node* referenceElement = lastBody() ? lastBody()->nextSibling() : 0; insertBefore(body, referenceElement); return body; }
HTMLTableRowElement* HTMLTableElement::insertRow( int index, ExceptionState& exceptionState) { if (index < -1) { exceptionState.throwDOMException( IndexSizeError, "The index provided (" + String::number(index) + ") is less than -1."); return nullptr; } HTMLTableRowElement* lastRow = nullptr; HTMLTableRowElement* row = nullptr; if (index == -1) { lastRow = HTMLTableRowsCollection::lastRow(*this); } else { for (int i = 0; i <= index; ++i) { row = HTMLTableRowsCollection::rowAfter(*this, lastRow); if (!row) { if (i != index) { exceptionState.throwDOMException( IndexSizeError, "The index provided (" + String::number(index) + ") is greater than the number of rows in the table (" + String::number(i) + ")."); return nullptr; } break; } lastRow = row; } } ContainerNode* parent; if (lastRow) { parent = row ? row->parentNode() : lastRow->parentNode(); } else { parent = lastBody(); if (!parent) { HTMLTableSectionElement* newBody = HTMLTableSectionElement::create(tbodyTag, document()); HTMLTableRowElement* newRow = HTMLTableRowElement::create(document()); newBody->appendChild(newRow, exceptionState); appendChild(newBody, exceptionState); return newRow; } } HTMLTableRowElement* newRow = HTMLTableRowElement::create(document()); parent->insertBefore(newRow, row, exceptionState); return newRow; }
PassRefPtrWillBeRawPtr<HTMLElement> HTMLTableElement::insertRow(int index, ExceptionState& exceptionState) { if (index < -1) { exceptionState.throwDOMException(IndexSizeError, "The index provided (" + String::number(index) + ") is less than -1."); return nullptr; } RefPtrWillBeRawPtr<Node> protectFromMutationEvents(this); RefPtrWillBeRawPtr<HTMLTableRowElement> lastRow = nullptr; RefPtrWillBeRawPtr<HTMLTableRowElement> row = nullptr; if (index == -1) lastRow = HTMLTableRowsCollection::lastRow(*this); else { for (int i = 0; i <= index; ++i) { row = HTMLTableRowsCollection::rowAfter(*this, lastRow.get()); if (!row) { if (i != index) { exceptionState.throwDOMException(IndexSizeError, "The index provided (" + String::number(index) + ") is greater than the number of rows in the table (" + String::number(i) + ")."); return nullptr; } break; } lastRow = row; } } RefPtrWillBeRawPtr<ContainerNode> parent; if (lastRow) parent = row ? row->parentNode() : lastRow->parentNode(); else { parent = lastBody(); if (!parent) { RefPtrWillBeRawPtr<HTMLTableSectionElement> newBody = HTMLTableSectionElement::create(tbodyTag, document()); RefPtrWillBeRawPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document()); newBody->appendChild(newRow, exceptionState); appendChild(newBody.release(), exceptionState); return newRow.release(); } } RefPtrWillBeRawPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document()); parent->insertBefore(newRow, row.get(), exceptionState); return newRow.release(); }