Chromium Code Reviews| 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, 2007, 2010 Apple Inc. All rights reserv ed. | 7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserv ed. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 PassRefPtr<HTMLElement> HTMLTableRowElement::insertCell(int index, ExceptionStat e& exceptionState) | 122 PassRefPtr<HTMLElement> HTMLTableRowElement::insertCell(int index, ExceptionStat e& exceptionState) |
| 123 { | 123 { |
| 124 RefPtr<HTMLCollection> children = cells(); | 124 RefPtr<HTMLCollection> children = cells(); |
| 125 int numCells = children ? children->length() : 0; | 125 int numCells = children ? children->length() : 0; |
| 126 if (index < -1 || index > numCells) { | 126 if (index < -1 || index > numCells) { |
| 127 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(index) + ") is outside the range [-1, " + String::number(numCel ls) + "]."); | 127 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(index) + ") is outside the range [-1, " + String::number(numCel ls) + "]."); |
| 128 return nullptr; | 128 return nullptr; |
| 129 } | 129 } |
| 130 | 130 |
| 131 RefPtr<HTMLTableCellElement> cell = HTMLTableCellElement::create(tdTag, docu ment()); | 131 RefPtr<HTMLTableCellElement> cell = HTMLTableCellElement::create(tdTag, docu ment()); |
| 132 if (index < 0 || index >= numCells) | 132 if (numCells == index || index == -1) { |
| 133 appendChild(cell, exceptionState); | 133 appendChild(cell, exceptionState); |
| 134 else { | 134 } else { |
| 135 Node* n; | 135 Element* n = children->item(index); |
|
tkent
2014/05/07 01:18:23
What happens if index == -2?
Inactive
2014/05/07 01:33:20
This cannot happen, we already check for this abov
| |
| 136 if (index < 1) | |
| 137 n = firstChild(); | |
| 138 else | |
| 139 n = children->item(index); | |
| 140 insertBefore(cell, n, exceptionState); | 136 insertBefore(cell, n, exceptionState); |
| 141 } | 137 } |
| 142 return cell.release(); | 138 return cell.release(); |
| 143 } | 139 } |
| 144 | 140 |
| 145 void HTMLTableRowElement::deleteCell(int index, ExceptionState& exceptionState) | 141 void HTMLTableRowElement::deleteCell(int index, ExceptionState& exceptionState) |
| 146 { | 142 { |
| 147 RefPtr<HTMLCollection> children = cells(); | 143 RefPtr<HTMLCollection> children = cells(); |
| 148 int numCells = children ? children->length() : 0; | 144 int numCells = children ? children->length() : 0; |
| 149 if (index == -1) | 145 if (index == -1) |
| 150 index = numCells-1; | 146 index = numCells-1; |
| 151 if (index >= 0 && index < numCells) { | 147 if (index >= 0 && index < numCells) { |
| 152 RefPtr<Element> cell = children->item(index); | 148 RefPtr<Element> cell = children->item(index); |
| 153 HTMLElement::removeChild(cell.get(), exceptionState); | 149 HTMLElement::removeChild(cell.get(), exceptionState); |
| 154 } else { | 150 } else { |
| 155 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(index) + ") is outside the range [0, " + String::number(numCell s) + ")."); | 151 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(index) + ") is outside the range [0, " + String::number(numCell s) + ")."); |
| 156 } | 152 } |
| 157 } | 153 } |
| 158 | 154 |
| 159 PassRefPtr<HTMLCollection> HTMLTableRowElement::cells() | 155 PassRefPtr<HTMLCollection> HTMLTableRowElement::cells() |
| 160 { | 156 { |
| 161 return ensureCachedHTMLCollection(TRCells); | 157 return ensureCachedHTMLCollection(TRCells); |
| 162 } | 158 } |
| 163 | 159 |
| 164 } | 160 } |
| OLD | NEW |