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

Side by Side 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 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved. 4 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved.
5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved.
6 * (http://www.torchmobile.com/) 6 * (http://www.torchmobile.com/)
7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 7 * Copyright (C) 2011 Motorola Mobility. 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "core/dom/shadow/ElementShadow.h" 44 #include "core/dom/shadow/ElementShadow.h"
45 #include "core/dom/shadow/FlatTreeTraversal.h" 45 #include "core/dom/shadow/FlatTreeTraversal.h"
46 #include "core/dom/shadow/ShadowRoot.h" 46 #include "core/dom/shadow/ShadowRoot.h"
47 #include "core/editing/EditingUtilities.h" 47 #include "core/editing/EditingUtilities.h"
48 #include "core/editing/serializers/Serialization.h" 48 #include "core/editing/serializers/Serialization.h"
49 #include "core/events/EventListener.h" 49 #include "core/events/EventListener.h"
50 #include "core/events/KeyboardEvent.h" 50 #include "core/events/KeyboardEvent.h"
51 #include "core/frame/Settings.h" 51 #include "core/frame/Settings.h"
52 #include "core/frame/UseCounter.h" 52 #include "core/frame/UseCounter.h"
53 #include "core/html/HTMLBRElement.h" 53 #include "core/html/HTMLBRElement.h"
54 #include "core/html/HTMLDimension.h"
54 #include "core/html/HTMLFormElement.h" 55 #include "core/html/HTMLFormElement.h"
55 #include "core/html/HTMLInputElement.h" 56 #include "core/html/HTMLInputElement.h"
56 #include "core/html/HTMLMenuElement.h" 57 #include "core/html/HTMLMenuElement.h"
57 #include "core/html/HTMLTemplateElement.h" 58 #include "core/html/HTMLTemplateElement.h"
58 #include "core/html/parser/HTMLParserIdioms.h" 59 #include "core/html/parser/HTMLParserIdioms.h"
59 #include "core/layout/LayoutBoxModelObject.h" 60 #include "core/layout/LayoutBoxModelObject.h"
60 #include "core/layout/LayoutObject.h" 61 #include "core/layout/LayoutObject.h"
61 #include "core/page/SpatialNavigation.h" 62 #include "core/page/SpatialNavigation.h"
62 #include "core/svg/SVGSVGElement.h" 63 #include "core/svg/SVGSVGElement.h"
63 #include "platform/Language.h" 64 #include "platform/Language.h"
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 elementToAdjust = FlatTreeTraversal::parentElement(*elementToAdjust)) { 896 elementToAdjust = FlatTreeTraversal::parentElement(*elementToAdjust)) {
896 if (elementAffectsDirectionality(elementToAdjust)) { 897 if (elementAffectsDirectionality(elementToAdjust)) {
897 toHTMLElement(elementToAdjust)->calculateAndAdjustDirectionality(); 898 toHTMLElement(elementToAdjust)->calculateAndAdjustDirectionality();
898 return; 899 return;
899 } 900 }
900 } 901 }
901 } 902 }
902 903
903 void HTMLElement::addHTMLLengthToStyle(MutableStylePropertySet* style, 904 void HTMLElement::addHTMLLengthToStyle(MutableStylePropertySet* style,
904 CSSPropertyID propertyID, 905 CSSPropertyID propertyID,
905 const String& value) { 906 const String& value,
906 // FIXME: This function should not spin up the CSS parser, but should instead 907 AllowPercentage allowPercentage) {
907 // just figure out the correct length unit and make the appropriate parsed 908 HTMLDimension dimension;
908 // value. 909 if (!parseDimensionValue(value, dimension))
909 910 return;
910 // strip attribute garbage.. 911 if (propertyID == CSSPropertyWidth &&
911 StringImpl* v = value.impl(); 912 (dimension.isPercentage() || dimension.isRelative())) {
912 if (v) { 913 UseCounter::count(document(), UseCounter::HTMLElementDeprecatedWidth);
913 unsigned length = 0;
914
915 while (length < v->length() && (*v)[length] <= ' ')
916 length++;
917
918 for (; length < v->length(); length++) {
919 UChar cc = (*v)[length];
920 if (cc > '9')
921 break;
922 if (cc < '0') {
923 if (cc == '%' || cc == '*') {
924 if (propertyID == CSSPropertyWidth)
925 UseCounter::count(document(),
926 UseCounter::HTMLElementDeprecatedWidth);
927 length++;
928 }
929 if (cc != '.')
930 break;
931 }
932 }
933
934 if (length != v->length()) {
935 addPropertyToPresentationAttributeStyle(style, propertyID,
936 v->substring(0, length));
937 return;
938 }
939 } 914 }
940 915 if (dimension.isRelative())
941 addPropertyToPresentationAttributeStyle(style, propertyID, value); 916 return;
917 if (dimension.isPercentage() && allowPercentage != AllowPercentageValues)
918 return;
919 CSSPrimitiveValue::UnitType unit =
920 dimension.isPercentage() ? CSSPrimitiveValue::UnitType::Percentage
921 : CSSPrimitiveValue::UnitType::Pixels;
922 addPropertyToPresentationAttributeStyle(style, propertyID, dimension.value(),
923 unit);
942 } 924 }
943 925
944 static RGBA32 parseColorStringWithCrazyLegacyRules(const String& colorString) { 926 static RGBA32 parseColorStringWithCrazyLegacyRules(const String& colorString) {
945 // Per spec, only look at the first 128 digits of the string. 927 // Per spec, only look at the first 128 digits of the string.
946 const size_t maxColorLength = 128; 928 const size_t maxColorLength = 128;
947 // We'll pad the buffer with two extra 0s later, so reserve two more than the 929 // We'll pad the buffer with two extra 0s later, so reserve two more than the
948 // max. 930 // max.
949 Vector<char, maxColorLength + 2> digitBuffer; 931 Vector<char, maxColorLength + 2> digitBuffer;
950 932
951 size_t i = 0; 933 size_t i = 0;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 1184
1203 #ifndef NDEBUG 1185 #ifndef NDEBUG
1204 1186
1205 // For use in the debugger 1187 // For use in the debugger
1206 void dumpInnerHTML(blink::HTMLElement*); 1188 void dumpInnerHTML(blink::HTMLElement*);
1207 1189
1208 void dumpInnerHTML(blink::HTMLElement* element) { 1190 void dumpInnerHTML(blink::HTMLElement* element) {
1209 printf("%s\n", element->innerHTML().ascii().data()); 1191 printf("%s\n", element->innerHTML().ascii().data());
1210 } 1192 }
1211 #endif 1193 #endif
OLDNEW
« 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