| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "core/rendering/RenderView.h" | 46 #include "core/rendering/RenderView.h" |
| 47 #include "platform/UserGestureIndicator.h" | 47 #include "platform/UserGestureIndicator.h" |
| 48 #include "platform/graphics/Color.h" | 48 #include "platform/graphics/Color.h" |
| 49 #include "wtf/PassOwnPtr.h" | 49 #include "wtf/PassOwnPtr.h" |
| 50 #include "wtf/text/WTFString.h" | 50 #include "wtf/text/WTFString.h" |
| 51 | 51 |
| 52 namespace WebCore { | 52 namespace WebCore { |
| 53 | 53 |
| 54 using namespace HTMLNames; | 54 using namespace HTMLNames; |
| 55 | 55 |
| 56 // Upper limit of number of datalist suggestions shown. |
| 57 static const unsigned maxSuggestions = 1000; |
| 58 // Upper limit for the length of the labels for datalist suggestions. |
| 59 static const unsigned maxSuggestionLabelLength = 1000; |
| 60 |
| 56 static bool isValidColorString(const String& value) | 61 static bool isValidColorString(const String& value) |
| 57 { | 62 { |
| 58 if (value.isEmpty()) | 63 if (value.isEmpty()) |
| 59 return false; | 64 return false; |
| 60 if (value[0] != '#') | 65 if (value[0] != '#') |
| 61 return false; | 66 return false; |
| 62 | 67 |
| 63 // We don't accept #rgb and #aarrggbb formats. | 68 // We don't accept #rgb and #aarrggbb formats. |
| 64 if (value.length() != 7) | 69 if (value.length() != 7) |
| 65 return false; | 70 return false; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 223 } |
| 219 | 224 |
| 220 bool ColorInputType::shouldShowSuggestions() const | 225 bool ColorInputType::shouldShowSuggestions() const |
| 221 { | 226 { |
| 222 if (RuntimeEnabledFeatures::dataListElementEnabled()) | 227 if (RuntimeEnabledFeatures::dataListElementEnabled()) |
| 223 return element().fastHasAttribute(listAttr); | 228 return element().fastHasAttribute(listAttr); |
| 224 | 229 |
| 225 return false; | 230 return false; |
| 226 } | 231 } |
| 227 | 232 |
| 228 Vector<Color> ColorInputType::suggestions() const | 233 Vector<ColorSuggestion> ColorInputType::suggestions() const |
| 229 { | 234 { |
| 230 Vector<Color> suggestions; | 235 Vector<ColorSuggestion> suggestions; |
| 231 if (RuntimeEnabledFeatures::dataListElementEnabled()) { | 236 if (RuntimeEnabledFeatures::dataListElementEnabled()) { |
| 232 HTMLDataListElement* dataList = element().dataList(); | 237 HTMLDataListElement* dataList = element().dataList(); |
| 233 if (dataList) { | 238 if (dataList) { |
| 234 RefPtr<HTMLCollection> options = dataList->options(); | 239 RefPtr<HTMLCollection> options = dataList->options(); |
| 235 for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement
(options->item(i)); i++) { | 240 for (unsigned i = 0; HTMLOptionElement* option = toHTMLOptionElement
(options->item(i)); i++) { |
| 236 if (!element().isValidValue(option->value())) | 241 if (!element().isValidValue(option->value())) |
| 237 continue; | 242 continue; |
| 238 Color color(option->value()); | 243 Color color(option->value()); |
| 239 if (!color.isValid()) | 244 if (!color.isValid()) |
| 240 continue; | 245 continue; |
| 241 suggestions.append(color); | 246 ColorSuggestion suggestion(color, option->label().left(maxSugges
tionLabelLength)); |
| 247 suggestions.append(suggestion); |
| 248 if (suggestions.size() >= maxSuggestions) |
| 249 break; |
| 242 } | 250 } |
| 243 } | 251 } |
| 244 } | 252 } |
| 245 return suggestions; | 253 return suggestions; |
| 246 } | 254 } |
| 247 | 255 |
| 248 } // namespace WebCore | 256 } // namespace WebCore |
| OLD | NEW |