Commit 3f14bed1 authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

Convert tables in keycode_converter to constexpr.

Currently, it is not constexpr, so may not be built on compile time.
Actually, no-op editing of the keycode_converter.cc sometimes
triggers static initializer check.

Specifically, DomKey used in the tables is not constexpr aware,
so this CL makes the change.

BUG=1137426
TEST=Built on mac-rel bot. Made sure no static initializer check error.

Change-Id: Ib2d070c0cc29c725d4b7a0df000940685086d570
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462978
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816557}
parent 9c43debc
...@@ -79,6 +79,9 @@ class DomKey { ...@@ -79,6 +79,9 @@ class DomKey {
"suspicious representation change"); "suspicious representation change");
public: public:
// Following block is a technique to add inlined constant with C++14
// compatible way. These can be replaced with inline constexpr after
// C++17 support.
enum InvalidKey : Base { NONE = 0 }; enum InvalidKey : Base { NONE = 0 };
// |dom_key_data.inc| describes the non-printable DomKey values, and is // |dom_key_data.inc| describes the non-printable DomKey values, and is
// included here to create constants for them in the DomKey:: scope. // included here to create constants for them in the DomKey:: scope.
...@@ -91,14 +94,14 @@ class DomKey { ...@@ -91,14 +94,14 @@ class DomKey {
#undef DOM_KEY_UNI #undef DOM_KEY_UNI
// Create a DomKey, with the undefined-value sentinel DomKey::NONE. // Create a DomKey, with the undefined-value sentinel DomKey::NONE.
DomKey() : value_(NONE) {} constexpr DomKey() = default;
// Create a DomKey from an encoded integer value. This is implicit so // Create a DomKey from an encoded integer value. This is implicit so
// that DomKey::NAME constants don't need to be explicitly converted // that DomKey::NAME constants don't need to be explicitly converted
// to DomKey. // to DomKey.
DomKey(Base value) : value_(value) { // After switching to C++17, this can be replaced by inline constexpr,
DCHECK(value == 0 || IsValid()) << value; // so can be private. On runtime, FromBase is preferred.
} constexpr DomKey(Base value) : value_(value) {}
// Factory that returns a DomKey for the specified value. Returns nullopt if // Factory that returns a DomKey for the specified value. Returns nullopt if
// |value| is not a valid value (or NONE). // |value| is not a valid value (or NONE).
...@@ -161,7 +164,7 @@ class DomKey { ...@@ -161,7 +164,7 @@ class DomKey {
private: private:
static bool IsValidValue(Base value) { return (value & TYPE_MASK) != 0; } static bool IsValidValue(Base value) { return (value & TYPE_MASK) != 0; }
Base value_; Base value_ = NONE;
}; };
} // namespace ui } // namespace ui
......
...@@ -44,7 +44,7 @@ inline constexpr uint32_t CodeIfOnKeyboardPage(uint32_t usage) { ...@@ -44,7 +44,7 @@ inline constexpr uint32_t CodeIfOnKeyboardPage(uint32_t usage) {
#else #else
#error Unsupported platform #error Unsupported platform
#endif #endif
#define DOM_CODE_DECLARATION const KeycodeMapEntry kDomCodeMappings[] = #define DOM_CODE_DECLARATION constexpr KeycodeMapEntry kDomCodeMappings[] =
#include "ui/events/keycodes/dom/dom_code_data.inc" #include "ui/events/keycodes/dom/dom_code_data.inc"
#undef DOM_CODE #undef DOM_CODE
#undef DOM_CODE_DECLARATION #undef DOM_CODE_DECLARATION
...@@ -55,7 +55,7 @@ struct DomKeyMapEntry { ...@@ -55,7 +55,7 @@ struct DomKeyMapEntry {
const char* string; const char* string;
}; };
#define DOM_KEY_MAP_DECLARATION const DomKeyMapEntry kDomKeyMappings[] = #define DOM_KEY_MAP_DECLARATION constexpr DomKeyMapEntry kDomKeyMappings[] =
#define DOM_KEY_UNI(key, id, value) {DomKey::id, key} #define DOM_KEY_UNI(key, id, value) {DomKey::id, key}
#define DOM_KEY_MAP(key, id, value) {DomKey::id, key} #define DOM_KEY_MAP(key, id, value) {DomKey::id, key}
#include "ui/events/keycodes/dom/dom_key_data.inc" #include "ui/events/keycodes/dom/dom_key_data.inc"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment