summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorrhashimoto@chromium.org <rhashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-21 17:05:49 +0000
committerrhashimoto@chromium.org <rhashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-21 17:05:49 +0000
commitd2ec9af2197d396716ae15da9f1e1d27e8877b4c (patch)
tree7161075c7477772cb572a826f996e2d232736e2a /ui
parent8227d054171e22971d3688b02d02d9ad548ff12f (diff)
downloadchromium_src-d2ec9af2197d396716ae15da9f1e1d27e8877b4c.zip
chromium_src-d2ec9af2197d396716ae15da9f1e1d27e8877b4c.tar.gz
chromium_src-d2ec9af2197d396716ae15da9f1e1d27e8877b4c.tar.bz2
Apply HIDE_PREFIX to Skia strings on linux without doubling underscores.
On linux, CanvasSkia::DrawStringInt() was removing ampersands (when HIDE_PREFIX flag was set) with gfx::RemoveWindowsStyleAccelerators(), which has the side effect of doubling underscores. This CL replaces the call with code that only strips ampersands (turning doubled ampersands into a single ampersand). BUG=chromium-os:15823 TEST=observe network menu with SSIDs containing underscores and ampersands Review URL: http://codereview.chromium.org/7170025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/canvas_skia_linux.cc12
-rw-r--r--ui/gfx/gtk_util.cc4
-rw-r--r--ui/gfx/skia_util.cc19
-rw-r--r--ui/gfx/skia_util.h8
-rw-r--r--ui/gfx/skia_util_unittest.cc42
-rw-r--r--ui/ui_unittests.gypi1
6 files changed, 79 insertions, 7 deletions
diff --git a/ui/gfx/canvas_skia_linux.cc b/ui/gfx/canvas_skia_linux.cc
index ae88c8e..430468e 100644
--- a/ui/gfx/canvas_skia_linux.cc
+++ b/ui/gfx/canvas_skia_linux.cc
@@ -16,6 +16,7 @@
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/platform_font_gtk.h"
#include "ui/gfx/rect.h"
+#include "ui/gfx/skia_util.h"
namespace {
@@ -162,9 +163,14 @@ static void SetupPangoLayout(PangoLayout* layout,
kAcceleratorChar, NULL);
g_free(escaped_text);
} else if (flags & gfx::Canvas::HIDE_PREFIX) {
- // Remove the ampersand character.
- utf8 = gfx::RemoveWindowsStyleAccelerators(utf8);
- pango_layout_set_text(layout, utf8.data(), utf8.size());
+ // Remove the ampersand character. A double ampersand is output as
+ // a single ampersand.
+ DCHECK_EQ(1, g_unichar_to_utf8(kAcceleratorChar, NULL));
+ const std::string accelerator_removed =
+ gfx::RemoveAcceleratorChar(utf8, static_cast<char>(kAcceleratorChar));
+
+ pango_layout_set_text(layout,
+ accelerator_removed.data(), accelerator_removed.size());
} else {
pango_layout_set_text(layout, utf8.data(), utf8.size());
}
diff --git a/ui/gfx/gtk_util.cc b/ui/gfx/gtk_util.cc
index 52b74ac..b1c7f44 100644
--- a/ui/gfx/gtk_util.cc
+++ b/ui/gfx/gtk_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -59,7 +59,7 @@ void FreePixels(guchar* pixels, gpointer data) {
// 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.
+// is needed by GTK.
std::string ConvertAmperstandsTo(const std::string& label,
const std::string& target) {
std::string ret;
diff --git a/ui/gfx/skia_util.cc b/ui/gfx/skia_util.cc
index 9f82b14..3b08273 100644
--- a/ui/gfx/skia_util.cc
+++ b/ui/gfx/skia_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -58,4 +58,21 @@ bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2) {
return (size1 == size2) && (0 == memcmp(addr1, addr2, bitmap1.getSize()));
}
+std::string RemoveAcceleratorChar(const std::string& s,
+ char accelerator_char) {
+ bool escaped = false;
+ std::string accelerator_removed;
+ accelerator_removed.reserve(s.size());
+ for (size_t i = 0; i < s.size(); ++i) {
+ if (s[i] != accelerator_char || escaped) {
+ accelerator_removed.push_back(s[i]);
+ escaped = false;
+ } else {
+ escaped = true;
+ }
+ }
+
+ return accelerator_removed;
+}
+
} // namespace gfx
diff --git a/ui/gfx/skia_util.h b/ui/gfx/skia_util.h
index 619ff37..f807979 100644
--- a/ui/gfx/skia_util.h
+++ b/ui/gfx/skia_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -6,6 +6,8 @@
#define UI_GFX_SKIA_UTIL_H_
#pragma once
+#include <string>
+
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkRect.h"
@@ -34,6 +36,10 @@ SkShader* CreateGradientShader(int start_point,
// Returns true if the two bitmaps contain the same pixels.
bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2);
+// Strip the accelerator char (typically '&') from a menu string. A
+// double accelerator char ('&&') will be converted to a single char.
+std::string RemoveAcceleratorChar(const std::string& s, char accelerator_char);
+
} // namespace gfx;
#endif // UI_GFX_SKIA_UTIL_H_
diff --git a/ui/gfx/skia_util_unittest.cc b/ui/gfx/skia_util_unittest.cc
new file mode 100644
index 0000000..a35628d
--- /dev/null
+++ b/ui/gfx/skia_util_unittest.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2011 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 "ui/gfx/skia_util.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+static const char kAcceleratorChar = '&';
+
+TEST(SkiaUtilTest, RemoveAcceleratorChar) {
+ EXPECT_TRUE(gfx::RemoveAcceleratorChar("", kAcceleratorChar).empty());
+ EXPECT_TRUE(gfx::RemoveAcceleratorChar("&", kAcceleratorChar).empty());
+ EXPECT_EQ(std::string("no accelerator"),
+ gfx::RemoveAcceleratorChar("no accelerator", kAcceleratorChar));
+ EXPECT_EQ(std::string("one accelerator"),
+ gfx::RemoveAcceleratorChar("&one accelerator", kAcceleratorChar));
+ EXPECT_EQ(std::string("one accelerator"),
+ gfx::RemoveAcceleratorChar("one &accelerator", kAcceleratorChar));
+ EXPECT_EQ(std::string("one_accelerator"),
+ gfx::RemoveAcceleratorChar("one_accelerator&", kAcceleratorChar));
+ EXPECT_EQ(std::string("two accelerators"),
+ gfx::RemoveAcceleratorChar("&two &accelerators", kAcceleratorChar));
+ EXPECT_EQ(std::string("two accelerators"),
+ gfx::RemoveAcceleratorChar("two &accelerators&", kAcceleratorChar));
+ EXPECT_EQ(std::string("two accelerators"),
+ gfx::RemoveAcceleratorChar("two& &accelerators", kAcceleratorChar));
+ EXPECT_EQ(std::string("&escaping"),
+ gfx::RemoveAcceleratorChar("&&escaping", kAcceleratorChar));
+ EXPECT_EQ(std::string("escap&ing"),
+ gfx::RemoveAcceleratorChar("escap&&ing", kAcceleratorChar));
+ EXPECT_EQ(std::string("escaping&"),
+ gfx::RemoveAcceleratorChar("escaping&&", kAcceleratorChar));
+ EXPECT_EQ(std::string("mix&ed"),
+ gfx::RemoveAcceleratorChar("&mix&&ed", kAcceleratorChar));
+ EXPECT_EQ(std::string("&mix&ed"),
+ gfx::RemoveAcceleratorChar("&&m&ix&&e&d&", kAcceleratorChar));
+ EXPECT_EQ(std::string("&m&ixed&"),
+ gfx::RemoveAcceleratorChar("&&m&&ix&ed&&", kAcceleratorChar));
+ EXPECT_EQ(std::string("m&ixed&"),
+ gfx::RemoveAcceleratorChar("&m&&ix&ed&&", kAcceleratorChar));
+}
diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi
index f226b40..3e976b4 100644
--- a/ui/ui_unittests.gypi
+++ b/ui/ui_unittests.gypi
@@ -48,6 +48,7 @@
'gfx/rect_unittest.cc',
'gfx/run_all_unittests.cc',
'gfx/skbitmap_operations_unittest.cc',
+ 'gfx/skia_util_unittest.cc',
'gfx/test_suite.cc',
'gfx/test_suite.h',
'views/rendering/border_unittest.cc',