OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/location_bar_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
19 #include "chrome/browser/accessibility/accessibility_events.h" | 19 #include "chrome/browser/accessibility/accessibility_events.h" |
20 #include "chrome/browser/alternate_nav_url_fetcher.h" | 20 #include "chrome/browser/alternate_nav_url_fetcher.h" |
21 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 21 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
22 #include "chrome/browser/chrome_to_mobile_service.h" | 22 #include "chrome/browser/chrome_to_mobile_service.h" |
23 #include "chrome/browser/chrome_to_mobile_service_factory.h" | 23 #include "chrome/browser/chrome_to_mobile_service_factory.h" |
24 #include "chrome/browser/command_updater.h" | 24 #include "chrome/browser/command_updater.h" |
25 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 25 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
26 #include "chrome/browser/defaults.h" | 26 #include "chrome/browser/defaults.h" |
27 #include "chrome/browser/extensions/api/commands/extension_command_service.h" | 27 #include "chrome/browser/extensions/api/commands/extension_command_service.h" |
28 #include "chrome/browser/extensions/api/commands/extension_command_service_facto ry.h" | 28 #include "chrome/browser/extensions/api/commands/extension_command_service_facto ry.h" |
29 #include "chrome/browser/extensions/action_box_controller.h" | |
30 #include "chrome/browser/extensions/extension_browser_event_router.h" | 29 #include "chrome/browser/extensions/extension_browser_event_router.h" |
31 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
32 #include "chrome/browser/extensions/extension_tab_util.h" | 31 #include "chrome/browser/extensions/extension_tab_util.h" |
33 #include "chrome/browser/favicon/favicon_tab_helper.h" | 32 #include "chrome/browser/favicon/favicon_tab_helper.h" |
34 #include "chrome/browser/instant/instant_controller.h" | 33 #include "chrome/browser/instant/instant_controller.h" |
35 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
36 #include "chrome/browser/search_engines/template_url.h" | 35 #include "chrome/browser/search_engines/template_url.h" |
37 #include "chrome/browser/search_engines/template_url_service.h" | 36 #include "chrome/browser/search_engines/template_url_service.h" |
38 #include "chrome/browser/search_engines/template_url_service_factory.h" | 37 #include "chrome/browser/search_engines/template_url_service_factory.h" |
39 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 | 348 |
350 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s | 349 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s |
351 // size-allocate so we can do proper resizing and eliding on | 350 // size-allocate so we can do proper resizing and eliding on |
352 // |security_info_label_|. | 351 // |security_info_label_|. |
353 g_signal_connect(hbox_.get(), "size-allocate", | 352 g_signal_connect(hbox_.get(), "size-allocate", |
354 G_CALLBACK(&OnHboxSizeAllocateThunk), this); | 353 G_CALLBACK(&OnHboxSizeAllocateThunk), this); |
355 | 354 |
356 registrar_.Add(this, | 355 registrar_.Add(this, |
357 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 356 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
358 content::Source<ThemeService>(theme_service_)); | 357 content::Source<ThemeService>(theme_service_)); |
358 registrar_.Add(this, | |
359 chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED, | |
360 content::Source<Profile>(browser()->profile())); | |
361 | |
359 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, | 362 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, |
360 profile->GetPrefs(), this); | 363 profile->GetPrefs(), this); |
361 | 364 |
362 theme_service_->InitThemesFor(this); | 365 theme_service_->InitThemesFor(this); |
363 } | 366 } |
364 | 367 |
365 void LocationBarViewGtk::BuildSiteTypeArea() { | 368 void LocationBarViewGtk::BuildSiteTypeArea() { |
366 location_icon_image_ = gtk_image_new(); | 369 location_icon_image_ = gtk_image_new(); |
367 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); | 370 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); |
368 | 371 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 } | 440 } |
438 | 441 |
439 WebContents* LocationBarViewGtk::GetWebContents() const { | 442 WebContents* LocationBarViewGtk::GetWebContents() const { |
440 return browser_->GetSelectedWebContents(); | 443 return browser_->GetSelectedWebContents(); |
441 } | 444 } |
442 | 445 |
443 void LocationBarViewGtk::SetPreviewEnabledPageAction( | 446 void LocationBarViewGtk::SetPreviewEnabledPageAction( |
444 ExtensionAction *page_action, | 447 ExtensionAction *page_action, |
445 bool preview_enabled) { | 448 bool preview_enabled) { |
446 DCHECK(page_action); | 449 DCHECK(page_action); |
447 UpdatePageActions(); | 450 if (preview_enabled && !preview_enabled_actions_.count(page_action)) { |
448 for (ScopedVector<PageActionViewGtk>::iterator iter = | 451 preview_enabled_actions_.insert(page_action); |
Matt Perry
2012/05/17 00:17:24
std::set allows you to test and set simultaneously
not at google - send to devlin
2012/05/17 01:30:35
Done.
| |
449 page_action_views_.begin(); iter != page_action_views_.end(); | 452 UpdatePageActions(); |
450 ++iter) { | 453 } else if (!preview_enabled && preview_enabled_actions_.count(page_action)) { |
451 if ((*iter)->page_action() == page_action) { | 454 preview_enabled_actions_.erase(page_action); |
452 (*iter)->set_preview_enabled(preview_enabled); | 455 UpdatePageActions(); |
453 UpdatePageActions(); | |
454 return; | |
455 } | |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 GtkWidget* LocationBarViewGtk::GetPageActionWidget( | 459 GtkWidget* LocationBarViewGtk::GetPageActionWidget( |
460 ExtensionAction *page_action) { | 460 ExtensionAction *page_action) { |
461 DCHECK(page_action); | 461 DCHECK(page_action); |
462 for (ScopedVector<PageActionViewGtk>::iterator iter = | 462 for (ScopedVector<PageActionViewGtk>::iterator iter = |
463 page_action_views_.begin(); | 463 page_action_views_.begin(); |
464 iter != page_action_views_.end(); | 464 iter != page_action_views_.end(); |
465 ++iter) { | 465 ++iter) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 toolbar_model_->input_in_progress() ? NULL : web_contents); | 678 toolbar_model_->input_in_progress() ? NULL : web_contents); |
679 any_visible = (*i)->IsVisible() || any_visible; | 679 any_visible = (*i)->IsVisible() || any_visible; |
680 } | 680 } |
681 | 681 |
682 // If there are no visible content things, hide the top level box so it | 682 // If there are no visible content things, hide the top level box so it |
683 // doesn't mess with padding. | 683 // doesn't mess with padding. |
684 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); | 684 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); |
685 } | 685 } |
686 | 686 |
687 void LocationBarViewGtk::UpdatePageActions() { | 687 void LocationBarViewGtk::UpdatePageActions() { |
688 ActionBoxController::DataList page_actions; | 688 std::vector<ExtensionAction*> page_actions; |
689 | 689 |
690 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); | 690 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); |
691 if (tab_contents) { | 691 if (tab_contents) { |
692 page_actions.swap( | 692 page_actions.swap( |
693 *tab_contents->extension_action_box_controller()->GetAllBadgeData()); | 693 *tab_contents->extension_action_box_controller()->GetCurrentActions()); |
694 } | 694 } |
695 | 695 |
696 // Add page actions for any extensions which have "preview enabled" and not | |
697 // already visible. | |
698 ActionBoxController::AddMissingActions( | |
699 preview_enabled_actions_, &page_actions); | |
700 | |
696 // Initialize on the first call, or re-inialize if more extensions have been | 701 // Initialize on the first call, or re-inialize if more extensions have been |
697 // loaded or added after startup. | 702 // loaded or added after startup. |
698 if (page_actions.size() != page_action_views_.size()) { | 703 if (page_actions.size() != page_action_views_.size()) { |
699 page_action_views_.reset(); // Delete the old views (if any). | 704 page_action_views_.reset(); // Delete the old views (if any). |
700 | 705 |
701 for (size_t i = 0; i < page_actions.size(); ++i) { | 706 for (size_t i = 0; i < page_actions.size(); ++i) { |
702 page_action_views_.push_back( | 707 page_action_views_.push_back( |
703 new PageActionViewGtk(this, page_actions[i].action)); | 708 new PageActionViewGtk(this, page_actions[i])); |
704 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), | 709 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), |
705 page_action_views_[i]->widget(), FALSE, FALSE, 0); | 710 page_action_views_[i]->widget(), FALSE, FALSE, 0); |
706 } | 711 } |
707 content::NotificationService::current()->Notify( | 712 content::NotificationService::current()->Notify( |
708 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 713 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
709 content::Source<LocationBar>(this), | 714 content::Source<LocationBar>(this), |
710 content::NotificationService::NoDetails()); | 715 content::NotificationService::NoDetails()); |
711 } | 716 } |
712 | 717 |
713 WebContents* contents = GetWebContents(); | 718 WebContents* contents = GetWebContents(); |
714 if (!page_action_views_.empty() && contents) { | 719 if (!page_action_views_.empty() && contents) { |
715 GURL url = browser()->GetSelectedWebContents()->GetURL(); | 720 GURL url = browser()->GetSelectedWebContents()->GetURL(); |
716 | 721 |
717 for (size_t i = 0; i < page_action_views_.size(); i++) { | 722 for (size_t i = 0; i < page_action_views_.size(); i++) { |
718 page_action_views_[i]->UpdateVisibility( | 723 page_action_views_[i]->Update( |
719 toolbar_model_->input_in_progress() ? NULL : contents, url); | 724 toolbar_model_->input_in_progress() ? NULL : contents, url); |
720 } | 725 } |
721 } | 726 } |
722 | 727 |
723 // If there are no visible page actions, hide the hbox too, so that it does | 728 // If there are no visible page actions, hide the hbox too, so that it does |
724 // not affect the padding in the location bar. | 729 // not affect the padding in the location bar. |
725 gtk_widget_set_visible(page_action_hbox_.get(), | 730 gtk_widget_set_visible(page_action_hbox_.get(), |
726 PageActionVisibleCount() && !ShouldOnlyShowLocation()); | 731 PageActionVisibleCount() && !ShouldOnlyShowLocation()); |
727 } | 732 } |
728 | 733 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 ExtensionAction* LocationBarViewGtk::GetPageAction(size_t index) { | 776 ExtensionAction* LocationBarViewGtk::GetPageAction(size_t index) { |
772 if (index >= page_action_views_.size()) { | 777 if (index >= page_action_views_.size()) { |
773 NOTREACHED(); | 778 NOTREACHED(); |
774 return NULL; | 779 return NULL; |
775 } | 780 } |
776 | 781 |
777 return page_action_views_[index]->page_action(); | 782 return page_action_views_[index]->page_action(); |
778 } | 783 } |
779 | 784 |
780 ExtensionAction* LocationBarViewGtk::GetVisiblePageAction(size_t index) { | 785 ExtensionAction* LocationBarViewGtk::GetVisiblePageAction(size_t index) { |
781 size_t visible_index = 0; | 786 return page_action_views_[index]->page_action(); |
782 for (size_t i = 0; i < page_action_views_.size(); ++i) { | |
783 if (page_action_views_[i]->IsVisible()) { | |
784 if (index == visible_index++) | |
785 return page_action_views_[i]->page_action(); | |
786 } | |
787 } | |
788 | |
789 NOTREACHED(); | |
790 return NULL; | |
791 } | 787 } |
792 | 788 |
793 void LocationBarViewGtk::TestPageActionPressed(size_t index) { | 789 void LocationBarViewGtk::TestPageActionPressed(size_t index) { |
794 if (index >= page_action_views_.size()) { | 790 if (index >= page_action_views_.size()) { |
795 NOTREACHED(); | 791 NOTREACHED(); |
796 return; | 792 return; |
797 } | 793 } |
798 | 794 |
799 page_action_views_[index]->TestActivatePageAction(); | 795 page_action_views_[index]->TestActivatePageAction(); |
800 } | 796 } |
801 | 797 |
802 void LocationBarViewGtk::Observe(int type, | 798 void LocationBarViewGtk::Observe(int type, |
803 const content::NotificationSource& source, | 799 const content::NotificationSource& source, |
804 const content::NotificationDetails& details) { | 800 const content::NotificationDetails& details) { |
805 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 801 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
806 UpdateStarIcon(); | 802 UpdateStarIcon(); |
807 UpdateChromeToMobileIcon(); | 803 UpdateChromeToMobileIcon(); |
808 return; | 804 return; |
809 } | 805 } |
810 | 806 |
807 if (type == chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED) { | |
808 // Only update if the updated action box was for the active tab contents. | |
809 TabContentsWrapper* target_tab = | |
810 content::Details<TabContentsWrapper>(details).ptr(); | |
811 if (target_tab == GetTabContentsWrapper()) | |
812 UpdatePageActions(); | |
Evan Stade
2012/05/16 21:58:17
too much indent
not at google - send to devlin
2012/05/17 01:30:35
Done.
| |
813 return; | |
814 } | |
815 | |
811 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); | 816 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
812 | 817 |
813 if (theme_service_->UsingNativeTheme()) { | 818 if (theme_service_->UsingNativeTheme()) { |
814 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); | 819 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); |
815 | 820 |
816 GdkColor border_color = theme_service_->GetGdkColor( | 821 GdkColor border_color = theme_service_->GetGdkColor( |
817 ThemeService::COLOR_FRAME); | 822 ThemeService::COLOR_FRAME); |
818 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); | 823 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); |
819 | 824 |
820 gtk_util::UndoForceFontSize(security_info_label_); | 825 gtk_util::UndoForceFontSize(security_info_label_); |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1496 | 1501 |
1497 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 1502 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
1498 LocationBarViewGtk* owner, | 1503 LocationBarViewGtk* owner, |
1499 ExtensionAction* page_action) | 1504 ExtensionAction* page_action) |
1500 : owner_(NULL), | 1505 : owner_(NULL), |
1501 page_action_(page_action), | 1506 page_action_(page_action), |
1502 last_icon_pixbuf_(NULL), | 1507 last_icon_pixbuf_(NULL), |
1503 tracker_(this), | 1508 tracker_(this), |
1504 current_tab_id_(-1), | 1509 current_tab_id_(-1), |
1505 window_(NULL), | 1510 window_(NULL), |
1506 accel_group_(NULL), | 1511 accel_group_(NULL) { |
1507 preview_enabled_(false) { | |
1508 event_box_.Own(gtk_event_box_new()); | 1512 event_box_.Own(gtk_event_box_new()); |
1509 gtk_widget_set_size_request(event_box_.get(), | 1513 gtk_widget_set_size_request(event_box_.get(), |
1510 Extension::kPageActionIconMaxSize, | 1514 Extension::kPageActionIconMaxSize, |
1511 Extension::kPageActionIconMaxSize); | 1515 Extension::kPageActionIconMaxSize); |
1512 | 1516 |
1513 // Make the event box not visible so it does not paint a background. | 1517 // Make the event box not visible so it does not paint a background. |
1514 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | 1518 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
1515 g_signal_connect(event_box_.get(), "button-press-event", | 1519 g_signal_connect(event_box_.get(), "button-press-event", |
1516 G_CALLBACK(&OnButtonPressedThunk), this); | 1520 G_CALLBACK(&OnButtonPressedThunk), this); |
1517 g_signal_connect_after(event_box_.get(), "expose-event", | 1521 g_signal_connect_after(event_box_.get(), "expose-event", |
1518 G_CALLBACK(OnExposeEventThunk), this); | 1522 G_CALLBACK(OnExposeEventThunk), this); |
1519 g_signal_connect(event_box_.get(), "realize", | 1523 g_signal_connect(event_box_.get(), "realize", |
1520 G_CALLBACK(OnRealizeThunk), this); | 1524 G_CALLBACK(OnRealizeThunk), this); |
1521 | 1525 |
1522 image_.Own(gtk_image_new()); | 1526 image_.Own(gtk_image_new()); |
1523 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); | 1527 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
1528 gtk_widget_show_all(event_box_.get()); | |
1524 | 1529 |
1525 const Extension* extension = owner->browser()->profile()-> | 1530 const Extension* extension = owner->browser()->profile()-> |
1526 GetExtensionService()->GetExtensionById(page_action->extension_id(), | 1531 GetExtensionService()->GetExtensionById(page_action->extension_id(), |
1527 false); | 1532 false); |
1528 DCHECK(extension); | 1533 DCHECK(extension); |
1529 | 1534 |
1530 // Load all the icons declared in the manifest. This is the contents of the | 1535 // Load all the icons declared in the manifest. This is the contents of the |
1531 // icons array, plus the default_icon property, if any. | 1536 // icons array, plus the default_icon property, if any. |
1532 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 1537 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
1533 if (!page_action_->default_icon_path().empty()) | 1538 if (!page_action_->default_icon_path().empty()) |
(...skipping 18 matching lines...) Expand all Loading... | |
1552 image_.Destroy(); | 1557 image_.Destroy(); |
1553 event_box_.Destroy(); | 1558 event_box_.Destroy(); |
1554 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); | 1559 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); |
1555 ++iter) { | 1560 ++iter) { |
1556 g_object_unref(iter->second); | 1561 g_object_unref(iter->second); |
1557 } | 1562 } |
1558 if (last_icon_pixbuf_) | 1563 if (last_icon_pixbuf_) |
1559 g_object_unref(last_icon_pixbuf_); | 1564 g_object_unref(last_icon_pixbuf_); |
1560 } | 1565 } |
1561 | 1566 |
1562 bool LocationBarViewGtk::PageActionViewGtk::IsVisible() { | 1567 void LocationBarViewGtk::PageActionViewGtk::Update( |
1563 return gtk_widget_get_visible(widget()); | |
1564 } | |
1565 | |
1566 void LocationBarViewGtk::PageActionViewGtk::UpdateVisibility( | |
1567 WebContents* contents, const GURL& url) { | 1568 WebContents* contents, const GURL& url) { |
1568 // Save this off so we can pass it back to the extension when the action gets | 1569 // Save this off so we can pass it back to the extension when the action gets |
1569 // executed. See PageActionImageView::OnMousePressed. | 1570 // executed. See PageActionImageView::OnMousePressed. |
1570 current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1; | 1571 current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1; |
1571 current_url_ = url; | 1572 current_url_ = url; |
1572 | 1573 |
1573 bool visible = contents && | 1574 // Set the tooltip. |
1574 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_)); | 1575 gtk_widget_set_tooltip_text(event_box_.get(), |
1575 if (visible) { | 1576 page_action_->GetTitle(current_tab_id_).c_str()); |
1576 // Set the tooltip. | |
1577 gtk_widget_set_tooltip_text(event_box_.get(), | |
1578 page_action_->GetTitle(current_tab_id_).c_str()); | |
1579 | 1577 |
1580 // Set the image. | 1578 // Set the image. |
1581 // It can come from three places. In descending order of priority: | 1579 // It can come from three places. In descending order of priority: |
1582 // - The developer can set it dynamically by path or bitmap. It will be in | 1580 // - The developer can set it dynamically by path or bitmap. It will be in |
1583 // page_action_->GetIcon(). | 1581 // page_action_->GetIcon(). |
1584 // - The developer can set it dyanmically by index. It will be in | 1582 // - The developer can set it dyanmically by index. It will be in |
1585 // page_action_->GetIconIndex(). | 1583 // page_action_->GetIconIndex(). |
1586 // - It can be set in the manifest by path. It will be in page_action_-> | 1584 // - It can be set in the manifest by path. It will be in page_action_-> |
1587 // default_icon_path(). | 1585 // default_icon_path(). |
1588 | 1586 |
1589 // First look for a dynamically set bitmap. | 1587 // First look for a dynamically set bitmap. |
1590 SkBitmap icon = page_action_->GetIcon(current_tab_id_); | 1588 SkBitmap icon = page_action_->GetIcon(current_tab_id_); |
1591 GdkPixbuf* pixbuf = NULL; | 1589 GdkPixbuf* pixbuf = NULL; |
1592 if (!icon.isNull()) { | 1590 if (!icon.isNull()) { |
1593 if (icon.pixelRef() != last_icon_skbitmap_.pixelRef()) { | 1591 if (icon.pixelRef() != last_icon_skbitmap_.pixelRef()) { |
1594 if (last_icon_pixbuf_) | 1592 if (last_icon_pixbuf_) |
1595 g_object_unref(last_icon_pixbuf_); | 1593 g_object_unref(last_icon_pixbuf_); |
1596 last_icon_skbitmap_ = icon; | 1594 last_icon_skbitmap_ = icon; |
1597 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(&icon); | 1595 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(&icon); |
1598 } | |
1599 DCHECK(last_icon_pixbuf_); | |
1600 pixbuf = last_icon_pixbuf_; | |
1601 } else { | |
1602 // Otherwise look for a dynamically set index, or fall back to the | |
1603 // default path. | |
1604 int icon_index = page_action_->GetIconIndex(current_tab_id_); | |
1605 std::string icon_path = (icon_index < 0) ? | |
1606 page_action_->default_icon_path() : | |
1607 page_action_->icon_paths()->at(icon_index); | |
1608 if (!icon_path.empty()) { | |
1609 PixbufMap::iterator iter = pixbufs_.find(icon_path); | |
1610 if (iter != pixbufs_.end()) | |
1611 pixbuf = iter->second; | |
1612 } | |
1613 } | 1596 } |
1614 // The pixbuf might not be loaded yet. | 1597 DCHECK(last_icon_pixbuf_); |
1615 if (pixbuf) | 1598 pixbuf = last_icon_pixbuf_; |
1616 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); | 1599 } else { |
1600 // Otherwise look for a dynamically set index, or fall back to the | |
1601 // default path. | |
1602 int icon_index = page_action_->GetIconIndex(current_tab_id_); | |
1603 std::string icon_path = (icon_index < 0) ? | |
Evan Stade
2012/05/16 21:58:17
no parens
not at google - send to devlin
2012/05/17 01:30:35
Done.
| |
1604 page_action_->default_icon_path() : | |
1605 page_action_->icon_paths()->at(icon_index); | |
1606 if (!icon_path.empty()) { | |
1607 PixbufMap::iterator iter = pixbufs_.find(icon_path); | |
1608 if (iter != pixbufs_.end()) | |
1609 pixbuf = iter->second; | |
1610 } | |
1617 } | 1611 } |
1618 | 1612 // The pixbuf might not be loaded yet. |
1619 bool old_visible = IsVisible(); | 1613 if (pixbuf) |
1620 if (visible) | 1614 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
Evan Stade
2012/05/16 21:58:17
please add some more vertical space somewhere as t
not at google - send to devlin
2012/05/17 01:30:35
Done.
| |
1621 gtk_widget_show_all(event_box_.get()); | |
1622 else | |
1623 gtk_widget_hide_all(event_box_.get()); | |
1624 | |
1625 if (visible != old_visible) { | |
1626 content::NotificationService::current()->Notify( | |
1627 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | |
1628 content::Source<ExtensionAction>(page_action_), | |
1629 content::Details<WebContents>(contents)); | |
1630 } | |
1631 } | 1615 } |
1632 | 1616 |
1633 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( | 1617 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( |
1634 const gfx::Image& image, | 1618 const gfx::Image& image, |
1635 const std::string& extension_id, | 1619 const std::string& extension_id, |
1636 int index) { | 1620 int index) { |
1637 // We loaded icons()->size() icons, plus one extra if the page action had | 1621 // We loaded icons()->size() icons, plus one extra if the page action had |
1638 // a default icon. | 1622 // a default icon. |
1639 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | 1623 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
1640 if (!page_action_->default_icon_path().empty()) | 1624 if (!page_action_->default_icon_path().empty()) |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1808 GdkModifierType modifier, | 1792 GdkModifierType modifier, |
1809 void* user_data) { | 1793 void* user_data) { |
1810 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); | 1794 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); |
1811 if (!gtk_widget_get_visible(view->widget())) | 1795 if (!gtk_widget_get_visible(view->widget())) |
1812 return FALSE; | 1796 return FALSE; |
1813 | 1797 |
1814 GdkEventButton event = {}; | 1798 GdkEventButton event = {}; |
1815 event.button = 1; | 1799 event.button = 1; |
1816 return view->OnButtonPressed(view->widget(), &event); | 1800 return view->OnButtonPressed(view->widget(), &event); |
1817 } | 1801 } |
OLD | NEW |