Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: chrome/browser/ui/gtk/location_bar_view_gtk.cc

Issue 9705097: Revert 127146 - Add Extension Keybinding test for page actions and port the PageAction keybindings … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/search_engines/template_url.h" 31 #include "chrome/browser/search_engines/template_url.h"
32 #include "chrome/browser/search_engines/template_url_service.h" 32 #include "chrome/browser/search_engines/template_url_service.h"
33 #include "chrome/browser/search_engines/template_url_service_factory.h" 33 #include "chrome/browser/search_engines/template_url_service_factory.h"
34 #include "chrome/browser/ui/browser.h" 34 #include "chrome/browser/ui/browser.h"
35 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" 35 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
36 #include "chrome/browser/ui/browser_list.h" 36 #include "chrome/browser/ui/browser_list.h"
37 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 37 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
38 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" 38 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
39 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h" 39 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bubble_gtk.h"
40 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" 40 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h"
41 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
42 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h" 41 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h"
43 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" 42 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h"
44 #include "chrome/browser/ui/gtk/first_run_bubble.h" 43 #include "chrome/browser/ui/gtk/first_run_bubble.h"
45 #include "chrome/browser/ui/gtk/gtk_util.h" 44 #include "chrome/browser/ui/gtk/gtk_util.h"
46 #include "chrome/browser/ui/gtk/nine_box.h" 45 #include "chrome/browser/ui/gtk/nine_box.h"
47 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" 46 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h"
48 #include "chrome/browser/ui/gtk/rounded_window.h" 47 #include "chrome/browser/ui/gtk/rounded_window.h"
49 #include "chrome/browser/ui/gtk/theme_service_gtk.h" 48 #include "chrome/browser/ui/gtk/theme_service_gtk.h"
50 #include "chrome/browser/ui/gtk/view_id_util.h" 49 #include "chrome/browser/ui/gtk/view_id_util.h"
51 #include "chrome/browser/ui/omnibox/location_bar_util.h" 50 #include "chrome/browser/ui/omnibox/location_bar_util.h"
52 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 51 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
53 #include "chrome/common/chrome_notification_types.h" 52 #include "chrome/common/chrome_notification_types.h"
54 #include "chrome/common/extensions/extension.h" 53 #include "chrome/common/extensions/extension.h"
55 #include "chrome/common/extensions/extension_action.h" 54 #include "chrome/common/extensions/extension_action.h"
56 #include "chrome/common/extensions/extension_resource.h" 55 #include "chrome/common/extensions/extension_resource.h"
57 #include "chrome/common/pref_names.h" 56 #include "chrome/common/pref_names.h"
58 #include "content/public/browser/navigation_entry.h" 57 #include "content/public/browser/navigation_entry.h"
59 #include "content/public/browser/notification_service.h" 58 #include "content/public/browser/notification_service.h"
60 #include "content/public/browser/web_contents.h" 59 #include "content/public/browser/web_contents.h"
61 #include "grit/generated_resources.h" 60 #include "grit/generated_resources.h"
62 #include "grit/theme_resources.h" 61 #include "grit/theme_resources.h"
63 #include "grit/theme_resources_standard.h" 62 #include "grit/theme_resources_standard.h"
64 #include "net/base/net_util.h" 63 #include "net/base/net_util.h"
65 #include "ui/base/accelerators/accelerator_gtk.h"
66 #include "ui/base/dragdrop/gtk_dnd_util.h" 64 #include "ui/base/dragdrop/gtk_dnd_util.h"
67 #include "ui/base/gtk/gtk_hig_constants.h" 65 #include "ui/base/gtk/gtk_hig_constants.h"
68 #include "ui/base/l10n/l10n_util.h" 66 #include "ui/base/l10n/l10n_util.h"
69 #include "ui/base/resource/resource_bundle.h" 67 #include "ui/base/resource/resource_bundle.h"
70 #include "ui/gfx/canvas_skia_paint.h" 68 #include "ui/gfx/canvas_skia_paint.h"
71 #include "ui/gfx/font.h" 69 #include "ui/gfx/font.h"
72 #include "ui/gfx/gtk_util.h" 70 #include "ui/gfx/gtk_util.h"
73 #include "ui/gfx/image/image.h" 71 #include "ui/gfx/image/image.h"
74 #include "webkit/glue/window_open_disposition.h" 72 #include "webkit/glue/window_open_disposition.h"
75 73
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 page_action_views_[i]->widget(), FALSE, FALSE, 0); 665 page_action_views_[i]->widget(), FALSE, FALSE, 0);
668 } 666 }
669 content::NotificationService::current()->Notify( 667 content::NotificationService::current()->Notify(
670 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 668 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
671 content::Source<LocationBar>(this), 669 content::Source<LocationBar>(this),
672 content::NotificationService::NoDetails()); 670 content::NotificationService::NoDetails());
673 } 671 }
674 672
675 WebContents* contents = GetWebContents(); 673 WebContents* contents = GetWebContents();
676 if (!page_action_views_.empty() && contents) { 674 if (!page_action_views_.empty() && contents) {
677 GURL url = browser()->GetSelectedWebContents()->GetURL(); 675 GURL url = GURL(toolbar_model_->GetText());
678 676
679 for (size_t i = 0; i < page_action_views_.size(); i++) { 677 for (size_t i = 0; i < page_action_views_.size(); i++) {
680 page_action_views_[i]->UpdateVisibility( 678 page_action_views_[i]->UpdateVisibility(
681 toolbar_model_->input_in_progress() ? NULL : contents, url); 679 toolbar_model_->input_in_progress() ? NULL : contents, url);
682 } 680 }
683 } 681 }
684 682
685 // If there are no visible page actions, hide the hbox too, so that it does 683 // If there are no visible page actions, hide the hbox too, so that it does
686 // not affect the padding in the location bar. 684 // not affect the padding in the location bar.
687 gtk_widget_set_visible(page_action_hbox_.get(), 685 gtk_widget_set_visible(page_action_hbox_.get(),
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 //////////////////////////////////////////////////////////////////////////////// 1429 ////////////////////////////////////////////////////////////////////////////////
1432 // LocationBarViewGtk::PageActionViewGtk 1430 // LocationBarViewGtk::PageActionViewGtk
1433 1431
1434 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( 1432 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk(
1435 LocationBarViewGtk* owner, 1433 LocationBarViewGtk* owner,
1436 ExtensionAction* page_action) 1434 ExtensionAction* page_action)
1437 : owner_(NULL), 1435 : owner_(NULL),
1438 page_action_(page_action), 1436 page_action_(page_action),
1439 last_icon_pixbuf_(NULL), 1437 last_icon_pixbuf_(NULL),
1440 tracker_(this), 1438 tracker_(this),
1441 current_tab_id_(-1),
1442 window_(NULL),
1443 accel_group_(NULL),
1444 preview_enabled_(false) { 1439 preview_enabled_(false) {
1445 event_box_.Own(gtk_event_box_new()); 1440 event_box_.Own(gtk_event_box_new());
1446 gtk_widget_set_size_request(event_box_.get(), 1441 gtk_widget_set_size_request(event_box_.get(),
1447 Extension::kPageActionIconMaxSize, 1442 Extension::kPageActionIconMaxSize,
1448 Extension::kPageActionIconMaxSize); 1443 Extension::kPageActionIconMaxSize);
1449 1444
1450 // Make the event box not visible so it does not paint a background. 1445 // Make the event box not visible so it does not paint a background.
1451 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); 1446 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE);
1452 g_signal_connect(event_box_.get(), "button-press-event", 1447 g_signal_connect(event_box_.get(), "button-press-event",
1453 G_CALLBACK(&OnButtonPressedThunk), this); 1448 G_CALLBACK(&OnButtonPressedThunk), this);
1454 g_signal_connect_after(event_box_.get(), "expose-event", 1449 g_signal_connect_after(event_box_.get(), "expose-event",
1455 G_CALLBACK(OnExposeEventThunk), this); 1450 G_CALLBACK(OnExposeEventThunk), this);
1456 g_signal_connect(event_box_.get(), "realize",
1457 G_CALLBACK(OnRealizeThunk), this);
1458 1451
1459 image_.Own(gtk_image_new()); 1452 image_.Own(gtk_image_new());
1460 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); 1453 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get());
1461 1454
1462 const Extension* extension = owner->browser()->profile()-> 1455 const Extension* extension = owner->browser()->profile()->
1463 GetExtensionService()->GetExtensionById(page_action->extension_id(), 1456 GetExtensionService()->GetExtensionById(page_action->extension_id(),
1464 false); 1457 false);
1465 DCHECK(extension); 1458 DCHECK(extension);
1466 1459
1467 // Load all the icons declared in the manifest. This is the contents of the 1460 // Load all the icons declared in the manifest. This is the contents of the
1468 // icons array, plus the default_icon property, if any. 1461 // icons array, plus the default_icon property, if any.
1469 std::vector<std::string> icon_paths(*page_action->icon_paths()); 1462 std::vector<std::string> icon_paths(*page_action->icon_paths());
1470 if (!page_action_->default_icon_path().empty()) 1463 if (!page_action_->default_icon_path().empty())
1471 icon_paths.push_back(page_action_->default_icon_path()); 1464 icon_paths.push_back(page_action_->default_icon_path());
1472 1465
1473 for (std::vector<std::string>::iterator iter = icon_paths.begin(); 1466 for (std::vector<std::string>::iterator iter = icon_paths.begin();
1474 iter != icon_paths.end(); ++iter) { 1467 iter != icon_paths.end(); ++iter) {
1475 tracker_.LoadImage(extension, extension->GetResource(*iter), 1468 tracker_.LoadImage(extension, extension->GetResource(*iter),
1476 gfx::Size(Extension::kPageActionIconMaxSize, 1469 gfx::Size(Extension::kPageActionIconMaxSize,
1477 Extension::kPageActionIconMaxSize), 1470 Extension::kPageActionIconMaxSize),
1478 ImageLoadingTracker::DONT_CACHE); 1471 ImageLoadingTracker::DONT_CACHE);
1479 } 1472 }
1480 1473
1481 // We set the owner last of all so that we can determine whether we are in 1474 // We set the owner last of all so that we can determine whether we are in
1482 // the process of initializing this class or not. 1475 // the process of initializing this class or not.
1483 owner_ = owner; 1476 owner_ = owner;
1484 } 1477 }
1485 1478
1486 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { 1479 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() {
1487 DisconnectPageActionAccelerator();
1488
1489 image_.Destroy(); 1480 image_.Destroy();
1490 event_box_.Destroy(); 1481 event_box_.Destroy();
1491 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); 1482 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end();
1492 ++iter) { 1483 ++iter) {
1493 g_object_unref(iter->second); 1484 g_object_unref(iter->second);
1494 } 1485 }
1495 if (last_icon_pixbuf_) 1486 if (last_icon_pixbuf_)
1496 g_object_unref(last_icon_pixbuf_); 1487 g_object_unref(last_icon_pixbuf_);
1497 } 1488 }
1498 1489
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 if (owner_) 1586 if (owner_)
1596 owner_->UpdatePageActions(); 1587 owner_->UpdatePageActions();
1597 } 1588 }
1598 1589
1599 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { 1590 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() {
1600 GdkEventButton event = {}; 1591 GdkEventButton event = {};
1601 event.button = 1; 1592 event.button = 1;
1602 OnButtonPressed(widget(), &event); 1593 OnButtonPressed(widget(), &event);
1603 } 1594 }
1604 1595
1605 void LocationBarViewGtk::PageActionViewGtk::Observe(
1606 int type,
1607 const content::NotificationSource& source,
1608 const content::NotificationDetails& details) {
1609 DCHECK(type == chrome::NOTIFICATION_WINDOW_CLOSED);
1610 DisconnectPageActionAccelerator();
1611 }
1612
1613 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( 1596 void LocationBarViewGtk::PageActionViewGtk::InspectPopup(
1614 ExtensionAction* action) { 1597 ExtensionAction* action) {
1615 ShowPopup(true); 1598 ShowPopup(true);
1616 } 1599 }
1617 1600
1618 bool LocationBarViewGtk::PageActionViewGtk::ShowPopup(bool devtools) { 1601 bool LocationBarViewGtk::PageActionViewGtk::ShowPopup(bool devtools) {
1619 if (!page_action_->HasPopup(current_tab_id_)) 1602 if (!page_action_->HasPopup(current_tab_id_))
1620 return false; 1603 return false;
1621 1604
1622 ExtensionPopupGtk::Show( 1605 ExtensionPopupGtk::Show(
1623 page_action_->GetPopupUrl(current_tab_id_), 1606 page_action_->GetPopupUrl(current_tab_id_),
1624 owner_->browser_, 1607 owner_->browser_,
1625 event_box_.get(), 1608 event_box_.get(),
1626 devtools); 1609 devtools);
1627 return true; 1610 return true;
1628 } 1611 }
1629 1612
1630 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() {
1631 const ExtensionSet* extensions = owner_->browser()->profile()->
1632 GetExtensionService()->extensions();
1633 const Extension* extension =
1634 extensions->GetByID(page_action_->extension_id());
1635 window_ = owner_->browser()->window()->GetNativeHandle();
1636
1637 // Iterate through all the keybindings and see if one is assigned to the
1638 // pageAction.
1639 const std::vector<Extension::ExtensionKeybinding>& commands =
1640 extension->keybindings();
1641 for (size_t i = 0; i < commands.size(); ++i) {
1642 if (commands[i].command_name() !=
1643 extension_manifest_values::kPageActionKeybindingEvent)
1644 continue;
1645
1646 // Found the browser action shortcut command, register it.
1647 keybinding_.reset(new ui::AcceleratorGtk(
1648 commands[i].accelerator().key_code(),
1649 commands[i].accelerator().IsShiftDown(),
1650 commands[i].accelerator().IsCtrlDown(),
1651 commands[i].accelerator().IsAltDown()));
1652
1653 accel_group_ = gtk_accel_group_new();
1654 gtk_window_add_accel_group(window_, accel_group_);
1655
1656 gtk_accel_group_connect(
1657 accel_group_,
1658 keybinding_->GetGdkKeyCode(),
1659 keybinding_->gdk_modifier_type(),
1660 GtkAccelFlags(0),
1661 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL));
1662
1663 // Since we've added an accelerator, we'll need to unregister it before
1664 // the window is closed, so we listen for the window being closed.
1665 registrar_.Add(this,
1666 chrome::NOTIFICATION_WINDOW_CLOSED,
1667 content::Source<GtkWindow>(window_));
1668 break;
1669 }
1670 }
1671
1672 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() {
1673 if (accel_group_) {
1674 gtk_accel_group_disconnect_key(
1675 accel_group_,
1676 keybinding_.get()->GetGdkKeyCode(),
1677 static_cast<GdkModifierType>(keybinding_.get()->modifiers()));
1678 gtk_window_remove_accel_group(window_, accel_group_);
1679 g_object_unref(accel_group_);
1680 accel_group_ = NULL;
1681 keybinding_.reset(NULL);
1682 }
1683 }
1684
1685 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( 1613 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed(
1686 GtkWidget* sender, 1614 GtkWidget* sender,
1687 GdkEventButton* event) { 1615 GdkEventButton* event) {
1688 Profile* profile = owner_->browser()->profile(); 1616 Profile* profile = owner_->browser()->profile();
1689 if (event->button != 3) { 1617 if (event->button != 3) {
1690 if (!ShowPopup(false)) { 1618 if (!ShowPopup(false)) {
1691 ExtensionService* service = profile->GetExtensionService(); 1619 ExtensionService* service = profile->GetExtensionService();
1692 service->browser_event_router()->PageActionExecuted(profile, 1620 service->browser_event_router()->PageActionExecuted(profile,
1693 page_action_->extension_id(), page_action_->id(), current_tab_id_, 1621 page_action_->extension_id(), page_action_->id(), current_tab_id_,
1694 current_url_.spec(), event->button); 1622 current_url_.spec(), event->button);
(...skipping 29 matching lines...) Expand all
1724 std::string badge_text = page_action_->GetBadgeText(tab_id); 1652 std::string badge_text = page_action_->GetBadgeText(tab_id);
1725 if (badge_text.empty()) 1653 if (badge_text.empty())
1726 return FALSE; 1654 return FALSE;
1727 1655
1728 gfx::CanvasSkiaPaint canvas(event, false); 1656 gfx::CanvasSkiaPaint canvas(event, false);
1729 GtkAllocation allocation; 1657 GtkAllocation allocation;
1730 gtk_widget_get_allocation(widget, &allocation); 1658 gtk_widget_get_allocation(widget, &allocation);
1731 page_action_->PaintBadge(&canvas, gfx::Rect(allocation), tab_id); 1659 page_action_->PaintBadge(&canvas, gfx::Rect(allocation), tab_id);
1732 return FALSE; 1660 return FALSE;
1733 } 1661 }
1734
1735 void LocationBarViewGtk::PageActionViewGtk::OnRealize(GtkWidget* widget) {
1736 ConnectPageActionAccelerator();
1737 }
1738
1739 // static
1740 gboolean LocationBarViewGtk::PageActionViewGtk::OnGtkAccelerator(
1741 GtkAccelGroup* accel_group,
1742 GObject* acceleratable,
1743 guint keyval,
1744 GdkModifierType modifier,
1745 void* user_data) {
1746 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data);
1747 if (!gtk_widget_get_visible(view->widget()))
1748 return FALSE;
1749
1750 GdkEventButton event = {};
1751 event.button = 1;
1752 return view->OnButtonPressed(view->widget(), &event);
1753 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/location_bar_view_gtk.h ('k') | chrome/browser/ui/views/location_bar/location_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698