summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 20:14:50 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 20:14:50 +0000
commit0ea548267d30b10c6d7f899573eb37b793c1b346 (patch)
treedddce09315c6010d047dda6ec9c29d6aa5befc36 /base
parenta0c4b343dfa64780f7395d7e3a6e8ebe853a5ec3 (diff)
downloadchromium_src-0ea548267d30b10c6d7f899573eb37b793c1b346.zip
chromium_src-0ea548267d30b10c6d7f899573eb37b793c1b346.tar.gz
chromium_src-0ea548267d30b10c6d7f899573eb37b793c1b346.tar.bz2
Moves gtk accelerator processing functions to base/gtk_util so I can
use them from views and gfx. Sorry for the new patch on this and not an update. Not sure what happened. BUG=none TEST=none Review URL: http://codereview.chromium.org/2809047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi8
-rw-r--r--base/gtk_util.cc49
-rw-r--r--base/gtk_util.h21
3 files changed, 75 insertions, 3 deletions
diff --git a/base/base.gypi b/base/base.gypi
index ba41fa5..9894dd3 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -9,9 +9,7 @@
'base_extra_target': 0,
},
'target_conditions': [
- # This part is shared between the targets defined below. Only files and
- # settings relevant for building the Win64 target should be added here.
- # All the rest should be added to the 'base' target below.
+ # This part is shared between the targets defined below.
['base_target==1', {
'sources': [
'../build/build_config.h',
@@ -93,6 +91,8 @@
'global_descriptors_posix.cc',
'global_descriptors_posix.h',
'gtest_prod_util.h',
+ 'gtk_util.cc',
+ 'gtk_util.h',
'hash_tables.h',
'histogram.cc',
'histogram.h',
@@ -319,6 +319,8 @@
[ 'OS != "linux"', {
'sources!': [
# Not automatically excluded by the *linux.cc rules.
+ 'gtk_util.cc',
+ 'gtk_util.h',
'linux_util.cc',
'setproctitle_linux.c',
'setproctitle_linux.h',
diff --git a/base/gtk_util.cc b/base/gtk_util.cc
new file mode 100644
index 0000000..79fc485
--- /dev/null
+++ b/base/gtk_util.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/gtk_util.h"
+
+namespace gtk_util {
+
+namespace {
+
+// Common implementation of ConvertAcceleratorsFromWindowsStyle() and
+// RemoveWindowsStyleAccelerators().
+// Replaces all ampersands (as used in our grd files to indicate mnemonics)
+// to |target|. Similarly any underscores get replaced with two underscores as
+// is needed by pango.
+std::string ConvertAmperstandsTo(const std::string& label,
+ const std::string& target) {
+ std::string ret;
+ ret.reserve(label.length() * 2);
+ for (size_t i = 0; i < label.length(); ++i) {
+ if ('_' == label[i]) {
+ ret.push_back('_');
+ ret.push_back('_');
+ } else if ('&' == label[i]) {
+ if (i + 1 < label.length() && '&' == label[i + 1]) {
+ ret.push_back('&');
+ ++i;
+ } else {
+ ret.append(target);
+ }
+ } else {
+ ret.push_back(label[i]);
+ }
+ }
+
+ return ret;
+}
+
+} // namespace
+
+std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
+ return ConvertAmperstandsTo(label, "_");
+}
+
+std::string RemoveWindowsStyleAccelerators(const std::string& label) {
+ return ConvertAmperstandsTo(label, "");
+}
+
+} // namespace gtk_util
diff --git a/base/gtk_util.h b/base/gtk_util.h
new file mode 100644
index 0000000..fc85db5
--- /dev/null
+++ b/base/gtk_util.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_GTK_UTIL_H_
+#define BASE_GTK_UTIL_H_
+
+#include <string>
+
+namespace gtk_util {
+
+// Change windows accelerator style to GTK style. (GTK uses _ for
+// accelerators. Windows uses & with && as an escape for &.)
+std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label);
+
+// Removes the "&" accelerators from a Windows label.
+std::string RemoveWindowsStyleAccelerators(const std::string& label);
+
+} // namespace gtk_util
+
+#endif // BASE_GTK_UTIL_H_