diff options
-rw-r--r-- | content/common/accessibility_messages.h | 17 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator.py | 6 | ||||
-rw-r--r-- | tools/json_schema_compiler/h_generator.py | 22 |
3 files changed, 26 insertions, 19 deletions
diff --git a/content/common/accessibility_messages.h b/content/common/accessibility_messages.h index 8f48ede..c86720d 100644 --- a/content/common/accessibility_messages.h +++ b/content/common/accessibility_messages.h @@ -21,14 +21,15 @@ #define IPC_MESSAGE_START AccessibilityMsgStart -IPC_ENUM_TRAITS(ui::AXEvent) -IPC_ENUM_TRAITS(ui::AXRole) - -IPC_ENUM_TRAITS(ui::AXBoolAttribute) -IPC_ENUM_TRAITS(ui::AXFloatAttribute) -IPC_ENUM_TRAITS(ui::AXIntAttribute) -IPC_ENUM_TRAITS(ui::AXIntListAttribute) -IPC_ENUM_TRAITS(ui::AXStringAttribute) +IPC_ENUM_TRAITS_MAX_VALUE(ui::AXEvent, ui::AX_EVENT_LAST) +IPC_ENUM_TRAITS_MAX_VALUE(ui::AXRole, ui::AX_ROLE_LAST) + +IPC_ENUM_TRAITS_MAX_VALUE(ui::AXBoolAttribute, ui::AX_BOOL_ATTRIBUTE_LAST) +IPC_ENUM_TRAITS_MAX_VALUE(ui::AXFloatAttribute, ui::AX_FLOAT_ATTRIBUTE_LAST) +IPC_ENUM_TRAITS_MAX_VALUE(ui::AXIntAttribute, ui::AX_INT_ATTRIBUTE_LAST) +IPC_ENUM_TRAITS_MAX_VALUE(ui::AXIntListAttribute, + ui::AX_INT_LIST_ATTRIBUTE_LAST) +IPC_ENUM_TRAITS_MAX_VALUE(ui::AXStringAttribute, ui::AX_STRING_ATTRIBUTE_LAST) IPC_STRUCT_TRAITS_BEGIN(ui::AXNodeData) IPC_STRUCT_TRAITS_MEMBER(id) diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py index 244cbda..e0e8278 100644 --- a/tools/json_schema_compiler/cpp_type_generator.py +++ b/tools/json_schema_compiler/cpp_type_generator.py @@ -59,6 +59,12 @@ class CppTypeGenerator(object): """ return '%s_NONE' % self.FollowRef(type_).unix_name.upper() + def GetEnumLastValue(self, type_): + """Gets the enum value in the given model.Property indicating the last value + for the type. + """ + return '%s_LAST' % self.FollowRef(type_).unix_name.upper() + def GetEnumValue(self, type_, enum_value): """Gets the enum value of the given model.Property of the given type. diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py index 0a2dc89..bdbd8a2 100644 --- a/tools/json_schema_compiler/h_generator.py +++ b/tools/json_schema_compiler/h_generator.py @@ -138,14 +138,18 @@ class _Generator(object): return dependency_order def _GenerateEnumDeclaration(self, enum_name, type_): - """Generate the declaration of a C++ enum. + """Generate a code object with the declaration of a C++ enum. """ c = Code() c.Sblock('enum %s {' % enum_name) c.Append(self._type_helper.GetEnumNoneValue(type_) + ',') for value in type_.enum_values: - c.Append(self._type_helper.GetEnumValue(type_, value) + ',') - return c.Eblock('};') + current_enum_string = self._type_helper.GetEnumValue(type_, value) + c.Append(current_enum_string + ',') + c.Append('%s = %s,' % ( + self._type_helper.GetEnumLastValue(type_), current_enum_string)) + c.Eblock('};') + return c def _GenerateFields(self, props): """Generates the field declarations when declaring a type. @@ -205,19 +209,15 @@ class _Generator(object): elif type_.property_type == PropertyType.ENUM: if type_.description: c.Comment(type_.description) - c.Sblock('enum %(classname)s {') - c.Append('%s,' % self._type_helper.GetEnumNoneValue(type_)) - for value in type_.enum_values: - c.Append('%s,' % self._type_helper.GetEnumValue(type_, value)) + c.Cblock(self._GenerateEnumDeclaration(classname, type_)); # Top level enums are in a namespace scope so the methods shouldn't be # static. On the other hand, those declared inline (e.g. in an object) do. maybe_static = '' if is_toplevel else 'static ' - (c.Eblock('};') - .Append() + (c.Append() .Append('%sstd::string ToString(%s as_enum);' % - (maybe_static, classname)) + (maybe_static, classname)) .Append('%s%s Parse%s(const std::string& as_string);' % - (maybe_static, classname, classname)) + (maybe_static, classname, classname)) ) elif type_.property_type in (PropertyType.CHOICES, PropertyType.OBJECT): |