summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authormdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-15 03:59:31 +0000
committermdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-15 03:59:31 +0000
commit3969d2b5bf878d0d70f7790da335a6fb0995cb0d (patch)
tree8374e71a01b372cbc9f4fd91c99ecc350f1bbe8e /ui
parentf69545fc9c65a903c533eacf467b8945ae1e8cb2 (diff)
downloadchromium_src-3969d2b5bf878d0d70f7790da335a6fb0995cb0d.zip
chromium_src-3969d2b5bf878d0d70f7790da335a6fb0995cb0d.tar.gz
chromium_src-3969d2b5bf878d0d70f7790da335a6fb0995cb0d.tar.bz2
Linux: fix bookmarks with & in them not showing correctly in the wrench menu.
As a side effect, also fix a bug in ReplaceChars() where it would go into an infinite loop (and probably also eventually run out of memory) if the replacement string contained any of the characters to be replaced. BUG=109546 Review URL: http://codereview.chromium.org/9348106 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/linux_util.cc24
-rw-r--r--ui/gfx/linux_util.h7
2 files changed, 24 insertions, 7 deletions
diff --git a/ui/gfx/linux_util.cc b/ui/gfx/linux_util.cc
index a189233..284cd96 100644
--- a/ui/gfx/linux_util.cc
+++ b/ui/gfx/linux_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/linux_util.h"
+#include "base/string_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkUnPreMultiply.h"
#include "ui/gfx/rect.h"
@@ -20,10 +21,11 @@ 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
+// to |target|, except ampersands appearing in pairs which are replaced by
+// a single ampersand. Any underscores get replaced with two underscores as
// is needed by GTK.
-std::string ConvertAmperstandsTo(const std::string& label,
- const std::string& target) {
+std::string ConvertAmpersandsTo(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) {
@@ -69,11 +71,21 @@ double GetPangoResolution() {
}
std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
- return ConvertAmperstandsTo(label, "_");
+ return ConvertAmpersandsTo(label, "_");
}
std::string RemoveWindowsStyleAccelerators(const std::string& label) {
- return ConvertAmperstandsTo(label, "");
+ return ConvertAmpersandsTo(label, "");
+}
+
+// Replaces all ampersands in |label| with two ampersands. This effectively
+// escapes strings for later processing by ConvertAmpersandsTo(), so that
+// ConvertAmpersandsTo(EscapeWindowsStyleAccelerators(x), *) is |x| with
+// underscores doubled, making the string that appears to the user just |x|.
+std::string EscapeWindowsStyleAccelerators(const std::string& label) {
+ std::string ret;
+ ReplaceChars(label, "&", "&&", &ret);
+ return ret;
}
uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
diff --git a/ui/gfx/linux_util.h b/ui/gfx/linux_util.h
index 70d1464..142fde0 100644
--- a/ui/gfx/linux_util.h
+++ b/ui/gfx/linux_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -34,6 +34,11 @@ UI_EXPORT std::string ConvertAcceleratorsFromWindowsStyle(
// Removes the "&" accelerators from a Windows label.
UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label);
+// Escapes "&" characters by doubling them so that later calling
+// ConvertAcceleratorsFromWindowsStyle() will return the original string (except
+// with "_" characters doubled, to escape them for GTK).
+UI_EXPORT std::string EscapeWindowsStyleAccelerators(const std::string& label);
+
// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA.
// The caller is responsible for free()ing the data. If |stride| is 0, it's
// assumed to be 4 * |width|.