Skip to content

Commit

Permalink
Make ParsekeyVector return false when it takes multiple keys or speci…
Browse files Browse the repository at this point in the history
…al keys.

#codehealth

PiperOrigin-RevId: 498136009
  • Loading branch information
hiroyuki-komatsu committed Dec 28, 2022
1 parent 7ec82c9 commit 4866060
Show file tree
Hide file tree
Showing 26 changed files with 59 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# Declaration of package_group for visibility managing.

load("//:build_defs.bzl", "select_mozc")
load("//tools/build_defs:stubs.bzl", "bzl_library")
load("//bazel:stubs.bzl", "bzl_library")

package(default_visibility = [
"//:__subpackages__",
Expand Down Expand Up @@ -113,8 +113,8 @@ bzl_library(
visibility = ["//:__subpackages__"],
deps = [
":config_bzl",
"//bazel:stubs.bzl",
"//devtools/build_cleaner/skylark:build_defs_lib",
"//tools/build_defs:stubs.bzl",
"//tools/build_rules/android_cc_test:def",
"@build_bazel_rules_apple//apple:apple_binary",
"@build_bazel_rules_apple//apple:macos",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load("//tools/build_defs:stubs.bzl", "bzl_library")
load("//bazel:stubs.bzl", "bzl_library")

bzl_library(
name = "stubs_bzl",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load("//tools/build_defs:stubs.bzl", "bzl_library")
load("//bazel:stubs.bzl", "bzl_library")

bzl_library(
name = "def_bzl",
Expand Down
File renamed without changes.
26 changes: 13 additions & 13 deletions src/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ cc_(library|binary|test) wrappers to add :macro dependency.
depending on it.
"""

load("//tools/build_defs:build_cleaner.bzl", "register_extension_info")
load("//tools/build_defs:stubs.bzl", "pytype_strict_binary", "pytype_strict_library")
load("//tools/build_rules/android_cc_test:def.bzl", "android_cc_test")
load("//bazel:stubs.bzl", "register_extension_info")
load("//bazel:stubs.bzl", "pytype_strict_binary", "pytype_strict_library")
load("//bazel:stubs.bzl", "android_cc_test")
load("//:config.bzl", "BRANDING", "MACOS_BUNDLE_ID_PREFIX", "MACOS_MIN_OS_VER")
load("@build_bazel_rules_apple//apple:apple_binary.bzl", "apple_binary")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application", "macos_bundle")
Expand Down Expand Up @@ -407,15 +407,15 @@ def select_mozc(
Generated select statement.
"""
return select({
"//tools/cc_target_os:android": _get_value([android, client, default]),
"//tools/cc_target_os:apple": _get_value([ios, client, default]),
"//tools/cc_target_os:chromiumos": _get_value([chromiumos, client, default]),
"//tools/cc_target_os:darwin": _get_value([macos, ios, client, default]),
"//tools/cc_target_os:wasm": _get_value([wasm, client, default]),
"//tools/cc_target_os:windows": _get_value([windows, client, default]),
"//tools/cc_target_os:linux": _get_value([linux, client, default]),
"//tools/cc_target_os:oss_android": _get_value([oss_android, oss, android, client, default]),
"//tools/cc_target_os:oss_linux": _get_value([oss_linux, oss, linux, client, default]),
"//tools/cc_target_os:oss_macos": _get_value([oss_macos, oss, macos, ios, client, default]),
"//bazel/cc_target_os:android": _get_value([android, client, default]),
"//bazel/cc_target_os:apple": _get_value([ios, client, default]),
"//bazel/cc_target_os:chromiumos": _get_value([chromiumos, client, default]),
"//bazel/cc_target_os:darwin": _get_value([macos, ios, client, default]),
"//bazel/cc_target_os:wasm": _get_value([wasm, client, default]),
"//bazel/cc_target_os:windows": _get_value([windows, client, default]),
"//bazel/bazel/cc_target_os:linux": _get_value([linux, client, default]),
"//bazel/bazel/cc_target_os:oss_android": _get_value([oss_android, oss, android, client, default]),
"//bazel/bazel/cc_target_os:oss_linux": _get_value([oss_linux, oss, linux, client, default]),
"//bazel/bazel/cc_target_os:oss_macos": _get_value([oss_macos, oss, macos, ios, client, default]),
"//conditions:default": default,
})
8 changes: 8 additions & 0 deletions src/composer/key_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ bool KeyParser::ParseKeyVector(const std::vector<std::string> &keys,

for (const std::string &key : keys) {
if (Util::CharsLen(key) == 1) {
if (key_event->has_key_code()) {
// Multiple keys are not supported.
return false;
}
key_event->set_key_code(Util::Utf8ToUcs4(key));
continue;
}
Expand All @@ -212,6 +216,10 @@ bool KeyParser::ParseKeyVector(const std::vector<std::string> &keys,
continue;
}
if (const auto &it = specials.find(lower_key); it != specials.end()) {
if (key_event->has_special_key()) {
// Multiple special keys are not supported.
return false;
}
key_event->set_special_key(it->second);
continue;
}
Expand Down
21 changes: 19 additions & 2 deletions src/composer/key_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,30 @@ TEST(KeyParserTest, Combination) {

EXPECT_TRUE(KeyParser::ParseKey("rightalt On", &key_event));
EXPECT_EQ(key_event.special_key(), KeyEvent::ON);
EXPECT_EQ(KeyEvent::RIGHT_ALT | KeyEvent::ALT,
KeyEventUtil::GetModifiers(key_event));
EXPECT_EQ(KeyEventUtil::GetModifiers(key_event),
KeyEvent::RIGHT_ALT | KeyEvent::ALT);

EXPECT_TRUE(KeyParser::ParseKey("SHIFT on a", &key_event));
EXPECT_EQ(key_event.key_code(), 'a');
EXPECT_EQ(key_event.special_key(), KeyEvent::ON);
EXPECT_EQ(KeyEventUtil::GetModifiers(key_event), KeyEvent::SHIFT);

EXPECT_TRUE(KeyParser::ParseKey("alt a", &key_event));
EXPECT_EQ(key_event.key_code(), 'a');
EXPECT_FALSE(key_event.has_special_key());
EXPECT_EQ(KeyEventUtil::GetModifiers(key_event), KeyEvent::ALT);

// meta and hyper are identical to alt.
EXPECT_TRUE(KeyParser::ParseKey("a meta hyper", &key_event));
EXPECT_EQ(key_event.key_code(), 'a');
EXPECT_FALSE(key_event.has_special_key());
EXPECT_EQ(KeyEventUtil::GetModifiers(key_event), KeyEvent::ALT);

// multiple keys are not supported.
EXPECT_FALSE(KeyParser::ParseKey("a alt z", &key_event));

// multiple special keys are not supported.
EXPECT_FALSE(KeyParser::ParseKey("muhenkan backspace", &key_event));
}

} // namespace mozc
2 changes: 1 addition & 1 deletion src/converter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load("//tools/build_defs:stubs.bzl", "bzl_library")
load("//bazel:stubs.bzl", "bzl_library")
load(
"//:build_defs.bzl",
"cc_binary_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/data/version/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# Description: Version configuration for Google Japanese Input

load("//data/version:mozc_version_template.bzl", "BUILD", "MAJOR", "MINOR", "REVISION_MACOS")
load("//tools/build_defs:stubs.bzl", "bzl_library")
load("//bazel:stubs.bzl", "bzl_library")
load("@build_bazel_rules_apple//apple:versioning.bzl", "apple_bundle_version")

exports_files(
Expand Down
2 changes: 1 addition & 1 deletion src/data_manager/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load("//tools/build_defs:stubs.bzl", "bzl_library")
load("//bazel:stubs.bzl", "bzl_library")
load(
"//:build_defs.bzl",
"cc_binary_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/about_dialog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"macos_qt_application_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/administration_dialog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"qt_moc_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ load(
"cc_library_mozc",
)
load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_library_mozc",
"qt_moc_mozc",
"qt_rcc_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/config_dialog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"macos_qt_application_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dictionary_tool/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"macos_qt_application_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/error_message_dialog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"macos_qt_application_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/post_install_dialog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"macos_qt_application_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/set_default_dialog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"macos_qt_application_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tool/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
load("//:build_defs.bzl", "cc_library_mozc", "select_mozc")
load("//:config.bzl", "BRANDING")
load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"macos_qt_application_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/gui/word_register_dialog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_binary_mozc",
"cc_qt_library_mozc",
"macos_qt_application_mozc",
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load("//tools/build_defs:stubs.bzl", "jspb_proto_library")
load("//bazel:stubs.bzl", "jspb_proto_library")

package(default_visibility = [
"//:__subpackages__",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/qt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ load(
"cc_library_mozc",
)
load(
"//tools/build_defs:qt.bzl",
"//bazel/tools/build_defs:qt.bzl",
"cc_qt_library_mozc",
"qt_moc_mozc",
)
Expand Down

0 comments on commit 4866060

Please sign in to comment.