Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLTableCellElement.cpp

Issue 2518163002: [css-tables] Fix divide-by-zero resulting from 32-bit overflow (Closed)
Patch Set: update wpt -expected.txt and span-attribute.html but not -expected.txt Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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, 2010 Apple Inc. All rights reserved. 7 * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
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 16 matching lines...) Expand all
27 #include "core/CSSPropertyNames.h" 27 #include "core/CSSPropertyNames.h"
28 #include "core/CSSValueKeywords.h" 28 #include "core/CSSValueKeywords.h"
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/dom/Attribute.h" 30 #include "core/dom/Attribute.h"
31 #include "core/dom/ElementTraversal.h" 31 #include "core/dom/ElementTraversal.h"
32 #include "core/html/HTMLTableElement.h" 32 #include "core/html/HTMLTableElement.h"
33 #include "core/html/parser/HTMLParserIdioms.h" 33 #include "core/html/parser/HTMLParserIdioms.h"
34 #include "core/layout/LayoutTableCell.h" 34 #include "core/layout/LayoutTableCell.h"
35 35
36 using namespace std; 36 using namespace std;
37 using namespace std;
38 37
39 namespace blink { 38 namespace blink {
40 39
41 // Rowspan: match Firefox's limit of 65,534. Edge has a higher limit, at
42 // least 2^17.
43 // Colspan: Firefox uses a limit of 1,000 for colspan and resets the value to 1.
44 // TODO(dgrogan): Determine Edge's colspan limit.
45 static const unsigned maxColSpan = 8190;
46 static const unsigned maxRowSpan = 65534;
47
48 using namespace HTMLNames; 40 using namespace HTMLNames;
49 41
50 inline HTMLTableCellElement::HTMLTableCellElement(const QualifiedName& tagName, 42 inline HTMLTableCellElement::HTMLTableCellElement(const QualifiedName& tagName,
51 Document& document) 43 Document& document)
52 : HTMLTablePartElement(tagName, document) {} 44 : HTMLTablePartElement(tagName, document) {}
53 45
54 DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLTableCellElement) 46 DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLTableCellElement)
55 47
56 unsigned HTMLTableCellElement::colSpan() const { 48 unsigned HTMLTableCellElement::colSpan() const {
57 const AtomicString& colSpanValue = fastGetAttribute(colspanAttr); 49 const AtomicString& colSpanValue = fastGetAttribute(colspanAttr);
58 unsigned value = 0; 50 unsigned value = 0;
59 if (colSpanValue.isEmpty() || 51 if (colSpanValue.isEmpty() ||
60 !parseHTMLNonNegativeInteger(colSpanValue, value)) 52 !parseHTMLNonNegativeInteger(colSpanValue, value))
61 return 1; 53 return 1;
62 return max(1u, min(value, maxColSpan)); 54 return max(1u, min(value, maxColSpan()));
63 } 55 }
64 56
65 unsigned HTMLTableCellElement::rowSpan() const { 57 unsigned HTMLTableCellElement::rowSpan() const {
66 const AtomicString& rowSpanValue = fastGetAttribute(rowspanAttr); 58 const AtomicString& rowSpanValue = fastGetAttribute(rowspanAttr);
67 unsigned value = 0; 59 unsigned value = 0;
68 if (rowSpanValue.isEmpty() || 60 if (rowSpanValue.isEmpty() ||
69 !parseHTMLNonNegativeInteger(rowSpanValue, value)) 61 !parseHTMLNonNegativeInteger(rowSpanValue, value))
70 return 1; 62 return 1;
71 return max(1u, min(value, maxRowSpan)); 63 return max(1u, min(value, maxRowSpan()));
72 } 64 }
73 65
74 int HTMLTableCellElement::cellIndex() const { 66 int HTMLTableCellElement::cellIndex() const {
75 if (!isHTMLTableRowElement(parentElement())) 67 if (!isHTMLTableRowElement(parentElement()))
76 return -1; 68 return -1;
77 69
78 int index = 0; 70 int index = 0;
79 for (const HTMLTableCellElement* element = 71 for (const HTMLTableCellElement* element =
80 Traversal<HTMLTableCellElement>::previousSibling(*this); 72 Traversal<HTMLTableCellElement>::previousSibling(*this);
81 element; 73 element;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 105 }
114 } else { 106 } else {
115 HTMLTablePartElement::collectStyleForPresentationAttribute(name, value, 107 HTMLTablePartElement::collectStyleForPresentationAttribute(name, value,
116 style); 108 style);
117 } 109 }
118 } 110 }
119 111
120 void HTMLTableCellElement::parseAttribute(const QualifiedName& name, 112 void HTMLTableCellElement::parseAttribute(const QualifiedName& name,
121 const AtomicString& oldValue, 113 const AtomicString& oldValue,
122 const AtomicString& value) { 114 const AtomicString& value) {
123 if (name == rowspanAttr) { 115 if (name == rowspanAttr || name == colspanAttr) {
124 if (layoutObject() && layoutObject()->isTableCell())
125 toLayoutTableCell(layoutObject())->colSpanOrRowSpanChanged();
126 } else if (name == colspanAttr) {
127 if (layoutObject() && layoutObject()->isTableCell()) 116 if (layoutObject() && layoutObject()->isTableCell())
128 toLayoutTableCell(layoutObject())->colSpanOrRowSpanChanged(); 117 toLayoutTableCell(layoutObject())->colSpanOrRowSpanChanged();
129 } else { 118 } else {
130 HTMLTablePartElement::parseAttribute(name, oldValue, value); 119 HTMLTablePartElement::parseAttribute(name, oldValue, value);
131 } 120 }
132 } 121 }
133 122
134 const StylePropertySet* 123 const StylePropertySet*
135 HTMLTableCellElement::additionalPresentationAttributeStyle() { 124 HTMLTableCellElement::additionalPresentationAttributeStyle() {
136 if (HTMLTableElement* table = findParentTable()) 125 if (HTMLTableElement* table = findParentTable())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 157
169 const AtomicString& HTMLTableCellElement::headers() const { 158 const AtomicString& HTMLTableCellElement::headers() const {
170 return fastGetAttribute(headersAttr); 159 return fastGetAttribute(headersAttr);
171 } 160 }
172 161
173 void HTMLTableCellElement::setRowSpan(unsigned n) { 162 void HTMLTableCellElement::setRowSpan(unsigned n) {
174 setUnsignedIntegralAttribute(rowspanAttr, n); 163 setUnsignedIntegralAttribute(rowspanAttr, n);
175 } 164 }
176 165
177 } // namespace blink 166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698