Last Comment Bug 839443 - API for helping get all CSS property names
: API for helping get all CSS property names
Status: RESOLVED FIXED
: dev-doc-complete
Product: Core
Classification: Components
Component: CSS Parsing and Computation (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla22
Assigned To: Boris Zbarsky [:bz]
:
Mentors:
Depends on:
Blocks: 874074 839458 851410 870845 893965
  Show dependency treegraph
 
Reported: 2013-02-08 03:39 PST by Michael Ratcliffe [:miker] [:mratcliffe]
Modified: 2013-07-16 12:05 PDT (History)
2 users (show)
bzbarsky: in‑testsuite?
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Add an API for getting our supported CSS property names in inspector code. (5.54 KB, patch)
2013-03-13 20:39 PDT, Boris Zbarsky [:bz]
no flags Details | Diff | Splinter Review
Add an API for getting our supported CSS property names in inspector code. (6.26 KB, patch)
2013-03-13 20:41 PDT, Boris Zbarsky [:bz]
dbaron: review+
Details | Diff | Splinter Review

Description Michael Ratcliffe [:miker] [:mratcliffe] 2013-02-08 03:39:09 PST
At the moment in our computed style view (DevTools) we currently iterate the computed styled of document.body in order to get the list of possible property names.

An API to get this list would be much tidier than using this hack, an array would be fine.

I would suggest domUtils.getCSSPropertyNames()
Comment 1 Boris Zbarsky [:bz] 2013-02-10 15:37:57 PST
So the API I'm thinking of looks something like this:

  const unsigned long EXCLUDE_SHORTHANDS = (1<<0);
  const unsigned long INCLUDE_ALIASES = (1<<1);
  void getCSSPropertyNames([optional] in unsigned long aFlags,
			   [optional] out unsigned long aCount,
			   [retval, array, size_is(aCount)] out wstring aProps);

One question: For properties that are controlled by a pref, should the API return them always, or only when enabled?  Or should it be possible to use another flag to control that behavior (and if so, what should the default be)?
Comment 2 Michael Ratcliffe [:miker] [:mratcliffe] 2013-02-11 05:58:12 PST
(In reply to Boris Zbarsky (:bz) from comment #1)
> One question: For properties that are controlled by a pref, should the API
> return them always, or only when enabled?

I think that only when enabled makes the most sense.
Comment 3 Boris Zbarsky [:bz] 2013-03-13 20:39:02 PDT
Created attachment 724759 [details] [diff] [review]
Add an API for getting our supported CSS property names in inspector code.
Comment 4 Boris Zbarsky [:bz] 2013-03-13 20:41:40 PDT
Created attachment 724762 [details] [diff] [review]
Add an API for getting our supported CSS property names in inspector code.
Comment 5 David Baron :dbaron: ⌚️UTC-7 (review requests must explain patch) 2013-03-13 22:58:47 PDT
Comment on attachment 724762 [details] [diff] [review]
Add an API for getting our supported CSS property names in inspector code.

>+#define DO_PROP(_prop)                                                  \
>+  PR_BEGIN_MACRO                                                        \
>+    nsCSSProperty cssProp = nsCSSProperty(_prop);                       \
>+    if (nsCSSProps::IsEnabled(cssProp)) {                               \
>+      props[propCount] =                                                \
>+        ToNewUnicode(nsDependentCString(kCSSRawProperties[_prop]));     \
>+      if (!props[propCount]) {                                          \
>+        NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(propCount, props);        \
>+        return NS_ERROR_OUT_OF_MEMORY;                                  \
>+      }                                                                 \

You don't need to handle OOM here; it's ToNewUnicode (which has a null check that's no longer needed) -> AllocateStringCopy -> nsMemory::Alloc -> NS_Alloc

>+      ++propCount;                                                      \
>+    }                                                                   \
>+  PR_END_MACRO
>+
>+  // prop is the property id we're considering; propCount is how many properties
>+  // we've put into props so far.
>+  uint32_t prop = 0, propCount = 0;
>+  for ( ; prop < eCSSProperty_COUNT_no_shorthands; ++prop) {
>+    if (!nsCSSProps::PropHasFlags(nsCSSProperty(prop),
>+                                  CSS_PROPERTY_PARSE_INACCESSIBLE)) {

I tend to think inspector might want these, in some cases at least.  (Though perhaps not; it would be nice if not.)

r=dbaron
Comment 6 Boris Zbarsky [:bz] 2013-03-14 11:03:31 PDT
> You don't need to handle OOM here

Ah, excellent.
Comment 8 Ryan VanderMeulen [:RyanVM] 2013-03-15 05:04:36 PDT
https://hg.mozilla.org/mozilla-central/rev/a3fcc4ba944c
Comment 9 Sebastian Zartner [:sebo] 2013-04-22 12:40:21 PDT
This should be documented at https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/inIDOMUtils.

Sebastian

Note You need to log in before you can comment on or make changes to this bug.