OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/location_bar_view_gtk.h" | 5 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 //////////////////////////////////////////////////////////////////////////////// | 1050 //////////////////////////////////////////////////////////////////////////////// |
1051 // LocationBarViewGtk::PageActionViewGtk | 1051 // LocationBarViewGtk::PageActionViewGtk |
1052 | 1052 |
1053 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 1053 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
1054 LocationBarViewGtk* owner, Profile* profile, | 1054 LocationBarViewGtk* owner, Profile* profile, |
1055 ExtensionAction* page_action) | 1055 ExtensionAction* page_action) |
1056 : owner_(owner), | 1056 : owner_(owner), |
1057 profile_(profile), | 1057 profile_(profile), |
1058 page_action_(page_action), | 1058 page_action_(page_action), |
1059 last_icon_pixbuf_(NULL), | 1059 last_icon_pixbuf_(NULL), |
| 1060 tracker_(this), |
1060 preview_enabled_(false) { | 1061 preview_enabled_(false) { |
1061 event_box_.Own(gtk_event_box_new()); | 1062 event_box_.Own(gtk_event_box_new()); |
1062 gtk_widget_set_size_request(event_box_.get(), | 1063 gtk_widget_set_size_request(event_box_.get(), |
1063 Extension::kPageActionIconMaxSize, | 1064 Extension::kPageActionIconMaxSize, |
1064 Extension::kPageActionIconMaxSize); | 1065 Extension::kPageActionIconMaxSize); |
1065 | 1066 |
1066 // Make the event box not visible so it does not paint a background. | 1067 // Make the event box not visible so it does not paint a background. |
1067 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | 1068 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
1068 g_signal_connect(event_box_.get(), "button-press-event", | 1069 g_signal_connect(event_box_.get(), "button-press-event", |
1069 G_CALLBACK(&OnButtonPressedThunk), this); | 1070 G_CALLBACK(&OnButtonPressedThunk), this); |
1070 g_signal_connect_after(event_box_.get(), "expose-event", | 1071 g_signal_connect_after(event_box_.get(), "expose-event", |
1071 G_CALLBACK(OnExposeEventThunk), this); | 1072 G_CALLBACK(OnExposeEventThunk), this); |
1072 | 1073 |
1073 image_.Own(gtk_image_new()); | 1074 image_.Own(gtk_image_new()); |
1074 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); | 1075 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
1075 | 1076 |
1076 Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 1077 Extension* extension = profile->GetExtensionsService()->GetExtensionById( |
1077 page_action->extension_id(), false); | 1078 page_action->extension_id(), false); |
1078 DCHECK(extension); | 1079 DCHECK(extension); |
1079 | 1080 |
1080 // Load all the icons declared in the manifest. This is the contents of the | 1081 // Load all the icons declared in the manifest. This is the contents of the |
1081 // icons array, plus the default_icon property, if any. | 1082 // icons array, plus the default_icon property, if any. |
1082 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 1083 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
1083 if (!page_action_->default_icon_path().empty()) | 1084 if (!page_action_->default_icon_path().empty()) |
1084 icon_paths.push_back(page_action_->default_icon_path()); | 1085 icon_paths.push_back(page_action_->default_icon_path()); |
1085 | 1086 |
1086 tracker_ = new ImageLoadingTracker(this, icon_paths.size()); | |
1087 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 1087 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
1088 iter != icon_paths.end(); ++iter) { | 1088 iter != icon_paths.end(); ++iter) { |
1089 tracker_->PostLoadImageTask( | 1089 tracker_.LoadImage(extension->GetResource(*iter), |
1090 extension->GetResource(*iter), | 1090 gfx::Size(Extension::kPageActionIconMaxSize, |
1091 gfx::Size(Extension::kPageActionIconMaxSize, | 1091 Extension::kPageActionIconMaxSize)); |
1092 Extension::kPageActionIconMaxSize)); | |
1093 } | 1092 } |
1094 } | 1093 } |
1095 | 1094 |
1096 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { | 1095 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { |
1097 if (tracker_) | |
1098 tracker_->StopTrackingImageLoad(); | |
1099 image_.Destroy(); | 1096 image_.Destroy(); |
1100 event_box_.Destroy(); | 1097 event_box_.Destroy(); |
1101 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); | 1098 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); |
1102 ++iter) { | 1099 ++iter) { |
1103 g_object_unref(iter->second); | 1100 g_object_unref(iter->second); |
1104 } | 1101 } |
1105 if (last_icon_pixbuf_) | 1102 if (last_icon_pixbuf_) |
1106 g_object_unref(last_icon_pixbuf_); | 1103 g_object_unref(last_icon_pixbuf_); |
1107 } | 1104 } |
1108 | 1105 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 gtk_widget_hide_all(event_box_.get()); | 1168 gtk_widget_hide_all(event_box_.get()); |
1172 | 1169 |
1173 if (visible != old_visible) { | 1170 if (visible != old_visible) { |
1174 NotificationService::current()->Notify( | 1171 NotificationService::current()->Notify( |
1175 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1172 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
1176 Source<ExtensionAction>(page_action_), | 1173 Source<ExtensionAction>(page_action_), |
1177 Details<TabContents>(contents)); | 1174 Details<TabContents>(contents)); |
1178 } | 1175 } |
1179 } | 1176 } |
1180 | 1177 |
1181 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded(SkBitmap* image, | 1178 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( |
1182 size_t index) { | 1179 SkBitmap* image, ExtensionResource resource, int index) { |
1183 // We loaded icons()->size() icons, plus one extra if the page action had | 1180 // We loaded icons()->size() icons, plus one extra if the page action had |
1184 // a default icon. | 1181 // a default icon. |
1185 size_t total_icons = page_action_->icon_paths()->size(); | 1182 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
1186 if (!page_action_->default_icon_path().empty()) | 1183 if (!page_action_->default_icon_path().empty()) |
1187 total_icons++; | 1184 total_icons++; |
1188 DCHECK(index < total_icons); | 1185 DCHECK(index < total_icons); |
1189 | 1186 |
1190 // Map the index of the loaded image back to its name. If we ever get an | 1187 // Map the index of the loaded image back to its name. If we ever get an |
1191 // index greater than the number of icons, it must be the default icon. | 1188 // index greater than the number of icons, it must be the default icon. |
1192 if (image) { | 1189 if (image) { |
1193 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(image); | 1190 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(image); |
1194 if (index < page_action_->icon_paths()->size()) | 1191 if (index < static_cast<int>(page_action_->icon_paths()->size())) |
1195 pixbufs_[page_action_->icon_paths()->at(index)] = pixbuf; | 1192 pixbufs_[page_action_->icon_paths()->at(index)] = pixbuf; |
1196 else | 1193 else |
1197 pixbufs_[page_action_->default_icon_path()] = pixbuf; | 1194 pixbufs_[page_action_->default_icon_path()] = pixbuf; |
1198 } | 1195 } |
1199 | 1196 |
1200 // If we are done, release the tracker. | |
1201 if (index == (total_icons - 1)) | |
1202 tracker_ = NULL; | |
1203 | |
1204 owner_->UpdatePageActions(); | 1197 owner_->UpdatePageActions(); |
1205 } | 1198 } |
1206 | 1199 |
1207 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { | 1200 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { |
1208 GdkEvent event; | 1201 GdkEvent event; |
1209 event.button.button = 1; | 1202 event.button.button = 1; |
1210 OnButtonPressed(widget(), &event); | 1203 OnButtonPressed(widget(), &event); |
1211 } | 1204 } |
1212 | 1205 |
1213 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 1206 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 | 1254 |
1262 std::string badge_text = page_action_->GetBadgeText(tab_id); | 1255 std::string badge_text = page_action_->GetBadgeText(tab_id); |
1263 if (badge_text.empty()) | 1256 if (badge_text.empty()) |
1264 return FALSE; | 1257 return FALSE; |
1265 | 1258 |
1266 gfx::CanvasPaint canvas(event, false); | 1259 gfx::CanvasPaint canvas(event, false); |
1267 gfx::Rect bounding_rect(widget->allocation); | 1260 gfx::Rect bounding_rect(widget->allocation); |
1268 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); | 1261 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); |
1269 return FALSE; | 1262 return FALSE; |
1270 } | 1263 } |
OLD | NEW |