OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/gtk/view_id_util.h" | 5 #include "chrome/browser/gtk/view_id_util.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> |
8 | 9 |
9 #include <gtk/gtk.h> | 10 #include <gtk/gtk.h> |
10 | 11 |
| 12 #include "base/logging.h" |
| 13 |
11 namespace { | 14 namespace { |
12 | 15 |
13 const char kViewIDString[] = "__VIEW_ID__"; | 16 const char kViewIDString[] = "__VIEW_ID__"; |
14 const char kViewIDOverrideString[] = "__VIEW_ID_OVERRIDE__"; | 17 const char kViewIDOverrideString[] = "__VIEW_ID_OVERRIDE__"; |
15 | 18 |
16 struct ViewIDSearchStruct { | 19 struct ViewIDSearchStruct { |
17 ViewID id; // Input: the ID we are searching for. | 20 ViewID id; // Input: the ID we are searching for. |
18 GtkWidget* widget; // Output: the found widget, or NULL. | 21 GtkWidget* widget; // Output: the found widget, or NULL. |
19 }; | 22 }; |
20 | 23 |
(...skipping 26 matching lines...) Expand all Loading... |
47 return; | 50 return; |
48 } | 51 } |
49 | 52 |
50 // Recurse. | 53 // Recurse. |
51 if (GTK_IS_CONTAINER(widget)) { | 54 if (GTK_IS_CONTAINER(widget)) { |
52 gtk_container_foreach(GTK_CONTAINER(widget), | 55 gtk_container_foreach(GTK_CONTAINER(widget), |
53 SearchForWidgetWithViewID, data); | 56 SearchForWidgetWithViewID, data); |
54 } | 57 } |
55 } | 58 } |
56 | 59 |
| 60 const char* GetNameFromID(ViewID id) { |
| 61 switch (id) { |
| 62 case VIEW_ID_TOOLBAR: |
| 63 return "chrome-toolbar"; |
| 64 |
| 65 case VIEW_ID_BACK_BUTTON: |
| 66 return "chrome-toolbar-back-button"; |
| 67 |
| 68 case VIEW_ID_FORWARD_BUTTON: |
| 69 return "chrome-toolbar-forward-button"; |
| 70 |
| 71 case VIEW_ID_RELOAD_BUTTON: |
| 72 return "chrome-toolbar-reload-button"; |
| 73 |
| 74 case VIEW_ID_HOME_BUTTON: |
| 75 return "chrome-toolbar-home-button"; |
| 76 |
| 77 case VIEW_ID_STAR_BUTTON: |
| 78 return "chrome-toolbar-star-button"; |
| 79 |
| 80 case VIEW_ID_LOCATION_BAR: |
| 81 return "chrome-location-bar"; |
| 82 |
| 83 case VIEW_ID_GO_BUTTON: |
| 84 return "chrome-toolbar-go-button"; |
| 85 |
| 86 case VIEW_ID_PAGE_MENU: |
| 87 return "chrome-page-menu"; |
| 88 |
| 89 case VIEW_ID_APP_MENU: |
| 90 return "chrome-app-menu"; |
| 91 |
| 92 case VIEW_ID_AUTOCOMPLETE: |
| 93 return "chrome-autocomplete-edit"; |
| 94 |
| 95 case VIEW_ID_BOOKMARK_MENU: |
| 96 return "chrome-bookmark-menu"; |
| 97 |
| 98 case VIEW_ID_BOOKMARK_BAR: |
| 99 return "chrome-bookmark-bar"; |
| 100 |
| 101 case VIEW_ID_FIND_IN_PAGE_TEXT_FIELD: |
| 102 return "chrome-find-in-page-entry"; |
| 103 |
| 104 // These are never hit because the tab container uses the delegate to |
| 105 // set its ID. |
| 106 case VIEW_ID_TAB_CONTAINER: |
| 107 case VIEW_ID_TAB_CONTAINER_FOCUS_VIEW: |
| 108 default: |
| 109 NOTREACHED(); |
| 110 return NULL; |
| 111 } |
| 112 } |
| 113 |
57 } // namespace | 114 } // namespace |
58 | 115 |
59 void ViewIDUtil::SetID(GtkWidget* widget, ViewID id) { | 116 void ViewIDUtil::SetID(GtkWidget* widget, ViewID id) { |
| 117 const char* name = GetNameFromID(id); |
| 118 if (name) |
| 119 gtk_widget_set_name(widget, name); |
60 g_object_set_data(G_OBJECT(widget), kViewIDString, | 120 g_object_set_data(G_OBJECT(widget), kViewIDString, |
61 reinterpret_cast<void*>(id)); | 121 reinterpret_cast<void*>(id)); |
62 } | 122 } |
63 | 123 |
64 GtkWidget* ViewIDUtil::GetWidget(GtkWidget* root, ViewID id) { | 124 GtkWidget* ViewIDUtil::GetWidget(GtkWidget* root, ViewID id) { |
65 ViewIDSearchStruct search_struct = { id, NULL }; | 125 ViewIDSearchStruct search_struct = { id, NULL }; |
66 SearchForWidgetWithViewID(root, &search_struct); | 126 SearchForWidgetWithViewID(root, &search_struct); |
67 return search_struct.widget; | 127 return search_struct.widget; |
68 } | 128 } |
69 | 129 |
70 void ViewIDUtil::SetDelegateForWidget(GtkWidget* widget, Delegate* delegate) { | 130 void ViewIDUtil::SetDelegateForWidget(GtkWidget* widget, Delegate* delegate) { |
71 g_object_set_data(G_OBJECT(widget), kViewIDOverrideString, delegate); | 131 g_object_set_data(G_OBJECT(widget), kViewIDOverrideString, delegate); |
72 } | 132 } |
OLD | NEW |