summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--app/gtk_util.h2
-rw-r--r--base/base.gypi8
-rw-r--r--base/gtk_util.cc49
-rw-r--r--base/gtk_util.h21
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc1
-rw-r--r--chrome/browser/gtk/certificate_manager.cc1
-rw-r--r--chrome/browser/gtk/certificate_viewer.cc1
-rw-r--r--chrome/browser/gtk/gtk_util.cc38
-rw-r--r--chrome/browser/gtk/gtk_util.h7
-rw-r--r--chrome/browser/gtk/keyword_editor_view.cc1
-rw-r--r--chrome/browser/gtk/menu_gtk.cc1
-rw-r--r--chrome/browser/gtk/options/cookies_view.cc1
-rw-r--r--chrome/browser/gtk/options/general_page_gtk.cc1
-rw-r--r--chrome/browser/renderer_host/gtk_im_context_wrapper.cc1
-rw-r--r--gfx/canvas_skia_linux.cc33
-rw-r--r--views/controls/menu/native_menu_gtk.cc22
16 files changed, 90 insertions, 98 deletions
diff --git a/app/gtk_util.h b/app/gtk_util.h
index 089e901..51b9a06 100644
--- a/app/gtk_util.h
+++ b/app/gtk_util.h
@@ -6,6 +6,8 @@
#define APP_GTK_UTIL_H_
#include <stdint.h>
+#include <string>
+
typedef struct _GtkWidget GtkWidget;
namespace gtk_util {
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_
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 54ab66e..52dbdb8 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -12,6 +12,7 @@
#include "app/clipboard/clipboard.h"
#include "app/clipboard/scoped_clipboard_writer.h"
#include "app/l10n_util.h"
+#include "base/gtk_util.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
diff --git a/chrome/browser/gtk/certificate_manager.cc b/chrome/browser/gtk/certificate_manager.cc
index 4c52f8e..51d1c7b 100644
--- a/chrome/browser/gtk/certificate_manager.cc
+++ b/chrome/browser/gtk/certificate_manager.cc
@@ -14,6 +14,7 @@
#include "app/gtk_signal.h"
#include "app/l10n_util.h"
#include "app/l10n_util_collator.h"
+#include "base/gtk_util.h"
#include "base/i18n/time_formatting.h"
#include "base/nss_util.h"
#include "chrome/browser/browser_process.h"
diff --git a/chrome/browser/gtk/certificate_viewer.cc b/chrome/browser/gtk/certificate_viewer.cc
index 7a041c2..c1e98d4 100644
--- a/chrome/browser/gtk/certificate_viewer.cc
+++ b/chrome/browser/gtk/certificate_viewer.cc
@@ -13,6 +13,7 @@
#include <vector>
#include "app/l10n_util.h"
+#include "base/gtk_util.h"
#include "base/i18n/time_formatting.h"
#include "base/nss_util.h"
#include "base/scoped_ptr.h"
diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc
index 62f1af0..e417d19 100644
--- a/chrome/browser/gtk/gtk_util.cc
+++ b/chrome/browser/gtk/gtk_util.cc
@@ -14,6 +14,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "app/x11_util.h"
+#include "base/gtk_util.h"
#include "base/i18n/rtl.h"
#include "base/linux_util.h"
#include "base/logging.h"
@@ -449,43 +450,6 @@ GtkWidget* CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget,
return centering_vbox;
}
-namespace {
-
-// Common implementation of ConvertAcceleratorsFromWindowsStyle() and
-// RemoveWindowsStyleAccelerators().
-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(label[i]);
- ++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, "");
-}
-
bool IsScreenComposited() {
GdkScreen* screen = gdk_screen_get_default();
return gdk_screen_is_composited(screen) == TRUE;
diff --git a/chrome/browser/gtk/gtk_util.h b/chrome/browser/gtk/gtk_util.h
index 3954729..7fed9e4 100644
--- a/chrome/browser/gtk/gtk_util.h
+++ b/chrome/browser/gtk/gtk_util.h
@@ -137,13 +137,6 @@ void InitRCStyles();
GtkWidget* CenterWidgetInHBox(GtkWidget* hbox, GtkWidget* widget,
bool pack_at_end, int padding);
-// 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);
-
// Returns true if the screen is composited, false otherwise.
bool IsScreenComposited();
diff --git a/chrome/browser/gtk/keyword_editor_view.cc b/chrome/browser/gtk/keyword_editor_view.cc
index 9a2eab5..e18b7e4 100644
--- a/chrome/browser/gtk/keyword_editor_view.cc
+++ b/chrome/browser/gtk/keyword_editor_view.cc
@@ -7,6 +7,7 @@
#include <string>
#include "app/l10n_util.h"
+#include "base/gtk_util.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/gtk/accessible_widget_helper_gtk.h"
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc
index d38b505..e8c856b 100644
--- a/chrome/browser/gtk/menu_gtk.cc
+++ b/chrome/browser/gtk/menu_gtk.cc
@@ -11,6 +11,7 @@
#include "app/menus/button_menu_item_model.h"
#include "app/menus/menu_model.h"
#include "app/resource_bundle.h"
+#include "base/gtk_util.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/message_loop.h"
diff --git a/chrome/browser/gtk/options/cookies_view.cc b/chrome/browser/gtk/options/cookies_view.cc
index bdefa04..bc171d2 100644
--- a/chrome/browser/gtk/options/cookies_view.cc
+++ b/chrome/browser/gtk/options/cookies_view.cc
@@ -9,6 +9,7 @@
#include <string>
#include "app/l10n_util.h"
+#include "base/gtk_util.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "chrome/browser/cookies_tree_model.h"
diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc
index d2f240b..b522561 100644
--- a/chrome/browser/gtk/options/general_page_gtk.cc
+++ b/chrome/browser/gtk/options/general_page_gtk.cc
@@ -9,6 +9,7 @@
#include "app/l10n_util.h"
#include "base/callback.h"
+#include "base/gtk_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/custom_home_pages_table_model.h"
#include "chrome/browser/gtk/accessible_widget_helper_gtk.h"
diff --git a/chrome/browser/renderer_host/gtk_im_context_wrapper.cc b/chrome/browser/renderer_host/gtk_im_context_wrapper.cc
index 4b7f7ad..35a6698 100644
--- a/chrome/browser/renderer_host/gtk_im_context_wrapper.cc
+++ b/chrome/browser/renderer_host/gtk_im_context_wrapper.cc
@@ -10,6 +10,7 @@
#include <algorithm>
#include "app/l10n_util.h"
+#include "base/gtk_util.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/third_party/icu/icu_utf.h"
diff --git a/gfx/canvas_skia_linux.cc b/gfx/canvas_skia_linux.cc
index 7c8c6c7..d63f9b4 100644
--- a/gfx/canvas_skia_linux.cc
+++ b/gfx/canvas_skia_linux.cc
@@ -10,6 +10,7 @@
#include <pango/pangocairo.h>
#include "base/logging.h"
+#include "base/gtk_util.h"
#include "base/utf_string_conversions.h"
#include "gfx/font.h"
#include "gfx/gtk_util.h"
@@ -87,36 +88,6 @@ static void UpdateCairoFontOptions() {
g_free(rgba_style);
}
-// TODO(sky): this is a copy of the one in gtk_util. It needs to be moved to a
-// common place.
-// 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
namespace gfx {
@@ -194,7 +165,7 @@ static void SetupPangoLayout(PangoLayout* layout,
g_free(escaped_text);
} else if (flags & gfx::Canvas::HIDE_PREFIX) {
// Remove the ampersand character.
- utf8 = ConvertAmperstandsTo(utf8, "");
+ utf8 = gtk_util::RemoveWindowsStyleAccelerators(utf8);
pango_layout_set_text(layout, utf8.data(), utf8.size());
} else {
pango_layout_set_text(layout, utf8.data(), utf8.size());
diff --git a/views/controls/menu/native_menu_gtk.cc b/views/controls/menu/native_menu_gtk.cc
index 43718f3..a89fa63 100644
--- a/views/controls/menu/native_menu_gtk.cc
+++ b/views/controls/menu/native_menu_gtk.cc
@@ -9,6 +9,7 @@
#include <string>
#include "app/menus/menu_model.h"
+#include "base/gtk_util.h"
#include "base/i18n/rtl.h"
#include "base/keyboard_code_conversion_gtk.h"
#include "base/keyboard_codes.h"
@@ -38,25 +39,6 @@ struct Position {
views::Menu2::Alignment alignment;
};
-std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
- std::string ret;
- ret.reserve(label.length());
- for (size_t i = 0; i < label.length(); ++i) {
- if ('&' == label[i]) {
- if (i + 1 < label.length() && '&' == label[i + 1]) {
- ret.push_back(label[i]);
- ++i;
- } else {
- ret.push_back('_');
- }
- } else {
- ret.push_back(label[i]);
- }
- }
-
- return ret;
-}
-
// Returns true if the menu item type specified can be executed as a command.
bool MenuTypeCanExecute(menus::MenuModel::ItemType type) {
return type == menus::MenuModel::TYPE_COMMAND ||
@@ -291,7 +273,7 @@ GtkWidget* NativeMenuGtk::AddMenuItemAt(int index,
GtkRadioMenuItem* radio_group,
GtkAccelGroup* accel_group) {
GtkWidget* menu_item = NULL;
- std::string label = ConvertAcceleratorsFromWindowsStyle(UTF16ToUTF8(
+ std::string label = gtk_util::ConvertAcceleratorsFromWindowsStyle(UTF16ToUTF8(
model_->GetLabelAt(index)));
menus::MenuModel::ItemType type = model_->GetTypeAt(index);