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

Unified Diff: third_party/WebKit/Source/core/html/HTMLElement.cpp

Issue 2528673003: Rework the "rules for parsing dimension values" implementation (Closed)
Patch Set: Rebase; clarify comment. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLElement.cpp b/third_party/WebKit/Source/core/html/HTMLElement.cpp
index 186767c0b519af66abeb52ddc85f67597204b816..dc111efdf26c3a4e791a864020d1225e547fcfa6 100644
--- a/third_party/WebKit/Source/core/html/HTMLElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLElement.cpp
@@ -51,6 +51,7 @@
#include "core/frame/Settings.h"
#include "core/frame/UseCounter.h"
#include "core/html/HTMLBRElement.h"
+#include "core/html/HTMLDimension.h"
#include "core/html/HTMLFormElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLMenuElement.h"
@@ -902,43 +903,24 @@ void HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged(
void HTMLElement::addHTMLLengthToStyle(MutableStylePropertySet* style,
CSSPropertyID propertyID,
- const String& value) {
- // FIXME: This function should not spin up the CSS parser, but should instead
- // just figure out the correct length unit and make the appropriate parsed
- // value.
-
- // strip attribute garbage..
- StringImpl* v = value.impl();
- if (v) {
- unsigned length = 0;
-
- while (length < v->length() && (*v)[length] <= ' ')
- length++;
-
- for (; length < v->length(); length++) {
- UChar cc = (*v)[length];
- if (cc > '9')
- break;
- if (cc < '0') {
- if (cc == '%' || cc == '*') {
- if (propertyID == CSSPropertyWidth)
- UseCounter::count(document(),
- UseCounter::HTMLElementDeprecatedWidth);
- length++;
- }
- if (cc != '.')
- break;
- }
- }
-
- if (length != v->length()) {
- addPropertyToPresentationAttributeStyle(style, propertyID,
- v->substring(0, length));
- return;
- }
+ const String& value,
+ AllowPercentage allowPercentage) {
+ HTMLDimension dimension;
+ if (!parseDimensionValue(value, dimension))
+ return;
+ if (propertyID == CSSPropertyWidth &&
+ (dimension.isPercentage() || dimension.isRelative())) {
+ UseCounter::count(document(), UseCounter::HTMLElementDeprecatedWidth);
}
-
- addPropertyToPresentationAttributeStyle(style, propertyID, value);
+ if (dimension.isRelative())
+ return;
+ if (dimension.isPercentage() && allowPercentage != AllowPercentageValues)
+ return;
+ CSSPrimitiveValue::UnitType unit =
+ dimension.isPercentage() ? CSSPrimitiveValue::UnitType::Percentage
+ : CSSPrimitiveValue::UnitType::Pixels;
+ addPropertyToPresentationAttributeStyle(style, propertyID, dimension.value(),
+ unit);
}
static RGBA32 parseColorStringWithCrazyLegacyRules(const String& colorString) {
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLElement.h ('k') | third_party/WebKit/Source/core/html/HTMLTableElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698