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

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

Issue 1936913002: [CSS] Accept 8 (#RRGGBBAA) and 4 (#RGBA) value hex colors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add quirks mode fastParseColorInternal() test cases. Created 4 years, 7 months 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. (http://www.torchmo bile.com/) 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 // An empty string doesn't apply a color. (One containing only whitespace do es, which is why this check occurs before stripping.) 918 // An empty string doesn't apply a color. (One containing only whitespace do es, which is why this check occurs before stripping.)
919 if (attributeValue.isEmpty()) 919 if (attributeValue.isEmpty())
920 return; 920 return;
921 921
922 String colorString = attributeValue.stripWhiteSpace(); 922 String colorString = attributeValue.stripWhiteSpace();
923 923
924 // "transparent" doesn't apply a color either. 924 // "transparent" doesn't apply a color either.
925 if (equalIgnoringCase(colorString, "transparent")) 925 if (equalIgnoringCase(colorString, "transparent"))
926 return; 926 return;
927 927
928 // If the string is a named CSS color or a 3/6-digit hex color, use that. 928 Color color;
929 Color parsedColor;
930 if (!parsedColor.setFromString(colorString))
931 parsedColor.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
932 929
933 style->setProperty(propertyID, cssValuePool().createColorValue(parsedColor.r gb())); 930 // If the string is a 3/6-digit hex color or a named CSS color, use that. Ap ply legacy rules otherwise. Note color.setFromString()
931 // accepts 4/8-digit hex color, so restrict its use with length checks here to support legacy HTML attributes.
932
933 bool success = false;
934 if ((colorString.length() == 4 || colorString.length() == 7) && colorString[ 0] == '#')
935 success = color.setFromString(colorString);
936 if (!success)
937 success = color.setNamedColor(colorString);
938 if (!success)
939 color.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
940
941 style->setProperty(propertyID, cssValuePool().createColorValue(color.rgb())) ;
934 } 942 }
935 943
936 bool HTMLElement::isInteractiveContent() const 944 bool HTMLElement::isInteractiveContent() const
937 { 945 {
938 return false; 946 return false;
939 } 947 }
940 948
941 HTMLMenuElement* HTMLElement::assignedContextMenu() const 949 HTMLMenuElement* HTMLElement::assignedContextMenu() const
942 { 950 {
943 if (HTMLMenuElement* menu = contextMenu()) 951 if (HTMLMenuElement* menu = contextMenu())
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 #ifndef NDEBUG 1045 #ifndef NDEBUG
1038 1046
1039 // For use in the debugger 1047 // For use in the debugger
1040 void dumpInnerHTML(blink::HTMLElement*); 1048 void dumpInnerHTML(blink::HTMLElement*);
1041 1049
1042 void dumpInnerHTML(blink::HTMLElement* element) 1050 void dumpInnerHTML(blink::HTMLElement* element)
1043 { 1051 {
1044 printf("%s\n", element->innerHTML().ascii().data()); 1052 printf("%s\n", element->innerHTML().ascii().data());
1045 } 1053 }
1046 #endif 1054 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698