gtk/bubble: Refactor BubbleAcceleratorsGtk class.
- Add begin() and end() accessors to easy iterate through accelerators in the same manner of STL containers.
BUG=None
TEST=open a bubble on chrome (e.g, bookmark bubble). Make sure ctrl-w and escape
still works.
R=evan@chromium.org
Review URL: http://codereview.chromium.org/7358001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92444 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.cc b/chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.cc
index 44136869..6403256 100644
--- a/chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.cc
+++ b/chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.cc
@@ -15,7 +15,7 @@
// after discussion over which accelerators should be addressed in
// bubbles. For a complete listing of accelerators that are used
// in chrome consult accelerators_gtk.cc
-struct BubbleAcceleratorGtk BubbleAcceleratorGtkTable[] = {
+const BubbleAcceleratorGtk kAcceleratorMap[] = {
// Tab/window controls.
{ GDK_w, GDK_CONTROL_MASK },
@@ -25,10 +25,12 @@
} // namespace
-BubbleAcceleratorGtkList BubbleAcceleratorsGtk::GetList() {
- BubbleAcceleratorGtkList accelerators;
- for (size_t i = 0; i < arraysize(BubbleAcceleratorGtkTable); ++i)
- accelerators.push_back(BubbleAcceleratorGtkTable[i]);
+// static
+BubbleAcceleratorsGtk::const_iterator BubbleAcceleratorsGtk::begin() {
+ return &kAcceleratorMap[0];
+}
- return accelerators;
+// static
+BubbleAcceleratorsGtk::const_iterator BubbleAcceleratorsGtk::end() {
+ return &kAcceleratorMap[arraysize(kAcceleratorMap)];
}
diff --git a/chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.h b/chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.h
index 158e242..41e5398 100644
--- a/chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.h
+++ b/chrome/browser/ui/gtk/bubble/bubble_accelerators_gtk.h
@@ -9,8 +9,6 @@
#include <gdk/gdktypes.h>
#include <glib.h>
-#include <vector>
-
#include "base/basictypes.h"
struct BubbleAcceleratorGtk {
@@ -18,19 +16,17 @@
GdkModifierType modifier_type;
};
-typedef std::vector<struct BubbleAcceleratorGtk>
- BubbleAcceleratorGtkList;
-
// This class contains a list of accelerators that a BubbleGtk is expected to
// either catch and respond to or catch and forward to the root browser window.
// This list is expected to be a subset of the accelerators that are handled by
// the root browser window, but the specific accelerators to be handled has not
-// yet been fully specified. The common use case for this class has code that
-// uses it needing the entire list and not needing extra processing, so the only
-// get method gives you the entire list.
+// yet been fully specified.
class BubbleAcceleratorsGtk {
public:
- static BubbleAcceleratorGtkList GetList();
+ typedef const BubbleAcceleratorGtk* const_iterator;
+
+ static const_iterator begin();
+ static const_iterator end();
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(BubbleAcceleratorsGtk);
diff --git a/chrome/browser/ui/gtk/bubble/bubble_gtk.cc b/chrome/browser/ui/gtk/bubble/bubble_gtk.cc
index cc096a7..c017d05 100644
--- a/chrome/browser/ui/gtk/bubble/bubble_gtk.cc
+++ b/chrome/browser/ui/gtk/bubble/bubble_gtk.cc
@@ -113,15 +113,11 @@
gtk_window_set_resizable(GTK_WINDOW(window_), FALSE);
// Attach all of the accelerators to the bubble.
- BubbleAcceleratorGtkList acceleratorList =
- BubbleAcceleratorsGtk::GetList();
- for (BubbleAcceleratorGtkList::const_iterator iter =
- acceleratorList.begin();
- iter != acceleratorList.end();
- ++iter) {
+ for (BubbleAcceleratorsGtk::const_iterator i(BubbleAcceleratorsGtk::begin());
+ i != BubbleAcceleratorsGtk::end(); ++i) {
gtk_accel_group_connect(accel_group_,
- iter->keyval,
- iter->modifier_type,
+ i->keyval,
+ i->modifier_type,
GtkAccelFlags(0),
g_cclosure_new(G_CALLBACK(&OnGtkAcceleratorThunk),
this,