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/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/gfx/gtk_util.h" | 9 #include "app/gfx/gtk_util.h" |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 } | 669 } |
670 | 670 |
671 //////////////////////////////////////////////////////////////////////////////// | 671 //////////////////////////////////////////////////////////////////////////////// |
672 // LocationBarViewGtk::PageActionViewGtk | 672 // LocationBarViewGtk::PageActionViewGtk |
673 | 673 |
674 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 674 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
675 LocationBarViewGtk* owner, Profile* profile, | 675 LocationBarViewGtk* owner, Profile* profile, |
676 const ExtensionAction* page_action) | 676 const ExtensionAction* page_action) |
677 : owner_(owner), | 677 : owner_(owner), |
678 profile_(profile), | 678 profile_(profile), |
679 page_action_(page_action) { | 679 page_action_(page_action), |
| 680 last_icon_skbitmap_(NULL), |
| 681 last_icon_pixbuf_(NULL) { |
680 event_box_.Own(gtk_event_box_new()); | 682 event_box_.Own(gtk_event_box_new()); |
681 // Make the event box not visible so it does not paint a background. | 683 // Make the event box not visible so it does not paint a background. |
682 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | 684 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
683 g_signal_connect(event_box_.get(), "button-press-event", | 685 g_signal_connect(event_box_.get(), "button-press-event", |
684 G_CALLBACK(&OnButtonPressed), this); | 686 G_CALLBACK(&OnButtonPressed), this); |
685 | 687 |
686 image_.Own(gtk_image_new()); | 688 image_.Own(gtk_image_new()); |
687 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); | 689 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
688 | 690 |
689 Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 691 Extension* extension = profile->GetExtensionsService()->GetExtensionById( |
(...skipping 12 matching lines...) Expand all Loading... |
702 | 704 |
703 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { | 705 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { |
704 if (tracker_) | 706 if (tracker_) |
705 tracker_->StopTrackingImageLoad(); | 707 tracker_->StopTrackingImageLoad(); |
706 image_.Destroy(); | 708 image_.Destroy(); |
707 event_box_.Destroy(); | 709 event_box_.Destroy(); |
708 for (size_t i = 0; i < pixbufs_.size(); ++i) { | 710 for (size_t i = 0; i < pixbufs_.size(); ++i) { |
709 if (pixbufs_[i]) | 711 if (pixbufs_[i]) |
710 g_object_unref(pixbufs_[i]); | 712 g_object_unref(pixbufs_[i]); |
711 } | 713 } |
| 714 if (last_icon_pixbuf_) |
| 715 g_object_unref(last_icon_pixbuf_); |
712 } | 716 } |
713 | 717 |
714 void LocationBarViewGtk::PageActionViewGtk::UpdateVisibility( | 718 void LocationBarViewGtk::PageActionViewGtk::UpdateVisibility( |
715 TabContents* contents, GURL url) { | 719 TabContents* contents, GURL url) { |
716 // Save this off so we can pass it back to the extension when the action gets | 720 // Save this off so we can pass it back to the extension when the action gets |
717 // executed. See PageActionImageView::OnMousePressed. | 721 // executed. See PageActionImageView::OnMousePressed. |
718 current_tab_id_ = ExtensionTabUtil::GetTabId(contents); | 722 current_tab_id_ = ExtensionTabUtil::GetTabId(contents); |
719 current_url_ = url; | 723 current_url_ = url; |
720 | 724 |
721 const ExtensionActionState* state = | 725 const ExtensionActionState* state = |
722 contents->GetPageActionState(page_action_); | 726 contents->GetPageActionState(page_action_); |
723 bool visible = state != NULL; | 727 bool visible = state && !state->hidden(); |
724 if (visible) { | 728 if (visible) { |
725 // Set the tooltip. | 729 // Set the tooltip. |
726 if (state->title().empty()) | 730 if (state->title().empty()) |
727 gtk_widget_set_tooltip_text(event_box_.get(), | 731 gtk_widget_set_tooltip_text(event_box_.get(), |
728 page_action_->title().c_str()); | 732 page_action_->title().c_str()); |
729 else | 733 else |
730 gtk_widget_set_tooltip_text(event_box_.get(), state->title().c_str()); | 734 gtk_widget_set_tooltip_text(event_box_.get(), state->title().c_str()); |
| 735 |
731 // Set the image. | 736 // Set the image. |
732 int index = state->icon_index(); | 737 SkBitmap* icon = state->icon(); |
733 // The image index (if not within bounds) will be set to the first image. | 738 GdkPixbuf* pixbuf = NULL; |
734 if (index < 0 || index >= static_cast<int>(pixbufs_.size())) | 739 if (icon) { |
735 index = 0; | 740 if (icon != last_icon_skbitmap_) { |
| 741 if (last_icon_pixbuf_) |
| 742 g_object_unref(last_icon_pixbuf_); |
| 743 last_icon_skbitmap_ = icon; |
| 744 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(icon); |
| 745 } |
| 746 DCHECK(last_icon_pixbuf_); |
| 747 pixbuf = last_icon_pixbuf_; |
| 748 } else { |
| 749 int index = state->icon_index(); |
| 750 // The image index (if not within bounds) will be set to the first image. |
| 751 if (index < 0 || index >= static_cast<int>(pixbufs_.size())) |
| 752 index = 0; |
| 753 pixbuf = pixbufs_[index]; |
| 754 } |
| 755 |
736 // The pixbuf might not be loaded yet. | 756 // The pixbuf might not be loaded yet. |
737 if (pixbufs_[index]) | 757 if (pixbuf) |
738 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbufs_[index]); | 758 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
739 else | 759 else |
740 visible = false; | 760 visible = false; |
741 } | 761 } |
742 | 762 |
743 if (visible) { | 763 if (visible) { |
744 gtk_widget_show_all(event_box_.get()); | 764 gtk_widget_show_all(event_box_.get()); |
745 } else { | 765 } else { |
746 gtk_widget_hide_all(event_box_.get()); | 766 gtk_widget_hide_all(event_box_.get()); |
747 } | 767 } |
748 } | 768 } |
(...skipping 14 matching lines...) Expand all Loading... |
763 LocationBarViewGtk::PageActionViewGtk* page_action_view) { | 783 LocationBarViewGtk::PageActionViewGtk* page_action_view) { |
764 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( | 784 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |
765 page_action_view->profile_, | 785 page_action_view->profile_, |
766 page_action_view->page_action_->extension_id(), | 786 page_action_view->page_action_->extension_id(), |
767 page_action_view->page_action_->id(), | 787 page_action_view->page_action_->id(), |
768 page_action_view->current_tab_id_, | 788 page_action_view->current_tab_id_, |
769 page_action_view->current_url_.spec(), | 789 page_action_view->current_url_.spec(), |
770 event->button); | 790 event->button); |
771 return true; | 791 return true; |
772 } | 792 } |
OLD | NEW |