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

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

Issue 9705098: Add Extension Keybinding test for page actions and port the PageAction keybindings to GTK (second a… (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"
41 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h" 42 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h"
42 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" 43 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h"
43 #include "chrome/browser/ui/gtk/first_run_bubble.h" 44 #include "chrome/browser/ui/gtk/first_run_bubble.h"
44 #include "chrome/browser/ui/gtk/gtk_util.h" 45 #include "chrome/browser/ui/gtk/gtk_util.h"
45 #include "chrome/browser/ui/gtk/nine_box.h" 46 #include "chrome/browser/ui/gtk/nine_box.h"
46 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" 47 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h"
47 #include "chrome/browser/ui/gtk/rounded_window.h" 48 #include "chrome/browser/ui/gtk/rounded_window.h"
48 #include "chrome/browser/ui/gtk/theme_service_gtk.h" 49 #include "chrome/browser/ui/gtk/theme_service_gtk.h"
49 #include "chrome/browser/ui/gtk/view_id_util.h" 50 #include "chrome/browser/ui/gtk/view_id_util.h"
50 #include "chrome/browser/ui/omnibox/location_bar_util.h" 51 #include "chrome/browser/ui/omnibox/location_bar_util.h"
51 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 52 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
52 #include "chrome/common/chrome_notification_types.h" 53 #include "chrome/common/chrome_notification_types.h"
53 #include "chrome/common/extensions/extension.h" 54 #include "chrome/common/extensions/extension.h"
54 #include "chrome/common/extensions/extension_action.h" 55 #include "chrome/common/extensions/extension_action.h"
55 #include "chrome/common/extensions/extension_resource.h" 56 #include "chrome/common/extensions/extension_resource.h"
56 #include "chrome/common/pref_names.h" 57 #include "chrome/common/pref_names.h"
57 #include "content/public/browser/navigation_entry.h" 58 #include "content/public/browser/navigation_entry.h"
58 #include "content/public/browser/notification_service.h" 59 #include "content/public/browser/notification_service.h"
59 #include "content/public/browser/web_contents.h" 60 #include "content/public/browser/web_contents.h"
60 #include "grit/generated_resources.h" 61 #include "grit/generated_resources.h"
61 #include "grit/theme_resources.h" 62 #include "grit/theme_resources.h"
62 #include "grit/theme_resources_standard.h" 63 #include "grit/theme_resources_standard.h"
63 #include "net/base/net_util.h" 64 #include "net/base/net_util.h"
65 #include "ui/base/accelerators/accelerator_gtk.h"
64 #include "ui/base/dragdrop/gtk_dnd_util.h" 66 #include "ui/base/dragdrop/gtk_dnd_util.h"
65 #include "ui/base/gtk/gtk_hig_constants.h" 67 #include "ui/base/gtk/gtk_hig_constants.h"
66 #include "ui/base/l10n/l10n_util.h" 68 #include "ui/base/l10n/l10n_util.h"
67 #include "ui/base/resource/resource_bundle.h" 69 #include "ui/base/resource/resource_bundle.h"
68 #include "ui/gfx/canvas_skia_paint.h" 70 #include "ui/gfx/canvas_skia_paint.h"
69 #include "ui/gfx/font.h" 71 #include "ui/gfx/font.h"
70 #include "ui/gfx/gtk_util.h" 72 #include "ui/gfx/gtk_util.h"
71 #include "ui/gfx/image/image.h" 73 #include "ui/gfx/image/image.h"
72 #include "webkit/glue/window_open_disposition.h" 74 #include "webkit/glue/window_open_disposition.h"
73 75
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 page_action_views_[i]->widget(), FALSE, FALSE, 0); 667 page_action_views_[i]->widget(), FALSE, FALSE, 0);
666 } 668 }
667 content::NotificationService::current()->Notify( 669 content::NotificationService::current()->Notify(
668 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 670 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
669 content::Source<LocationBar>(this), 671 content::Source<LocationBar>(this),
670 content::NotificationService::NoDetails()); 672 content::NotificationService::NoDetails());
671 } 673 }
672 674
673 WebContents* contents = GetWebContents(); 675 WebContents* contents = GetWebContents();
674 if (!page_action_views_.empty() && contents) { 676 if (!page_action_views_.empty() && contents) {
675 GURL url = GURL(toolbar_model_->GetText()); 677 GURL url = browser()->GetSelectedWebContents()->GetURL();
676 678
677 for (size_t i = 0; i < page_action_views_.size(); i++) { 679 for (size_t i = 0; i < page_action_views_.size(); i++) {
678 page_action_views_[i]->UpdateVisibility( 680 page_action_views_[i]->UpdateVisibility(
679 toolbar_model_->input_in_progress() ? NULL : contents, url); 681 toolbar_model_->input_in_progress() ? NULL : contents, url);
680 } 682 }
681 } 683 }
682 684
683 // If there are no visible page actions, hide the hbox too, so that it does 685 // If there are no visible page actions, hide the hbox too, so that it does
684 // not affect the padding in the location bar. 686 // not affect the padding in the location bar.
685 gtk_widget_set_visible(page_action_hbox_.get(), 687 gtk_widget_set_visible(page_action_hbox_.get(),
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 //////////////////////////////////////////////////////////////////////////////// 1431 ////////////////////////////////////////////////////////////////////////////////
1430 // LocationBarViewGtk::PageActionViewGtk 1432 // LocationBarViewGtk::PageActionViewGtk
1431 1433
1432 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( 1434 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk(
1433 LocationBarViewGtk* owner, 1435 LocationBarViewGtk* owner,
1434 ExtensionAction* page_action) 1436 ExtensionAction* page_action)
1435 : owner_(NULL), 1437 : owner_(NULL),
1436 page_action_(page_action), 1438 page_action_(page_action),
1437 last_icon_pixbuf_(NULL), 1439 last_icon_pixbuf_(NULL),
1438 tracker_(this), 1440 tracker_(this),
1441 current_tab_id_(-1),
1442 window_(NULL),
1443 accel_group_(NULL),
1439 preview_enabled_(false) { 1444 preview_enabled_(false) {
1440 event_box_.Own(gtk_event_box_new()); 1445 event_box_.Own(gtk_event_box_new());
1441 gtk_widget_set_size_request(event_box_.get(), 1446 gtk_widget_set_size_request(event_box_.get(),
1442 Extension::kPageActionIconMaxSize, 1447 Extension::kPageActionIconMaxSize,
1443 Extension::kPageActionIconMaxSize); 1448 Extension::kPageActionIconMaxSize);
1444 1449
1445 // Make the event box not visible so it does not paint a background. 1450 // Make the event box not visible so it does not paint a background.
1446 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); 1451 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE);
1447 g_signal_connect(event_box_.get(), "button-press-event", 1452 g_signal_connect(event_box_.get(), "button-press-event",
1448 G_CALLBACK(&OnButtonPressedThunk), this); 1453 G_CALLBACK(&OnButtonPressedThunk), this);
1449 g_signal_connect_after(event_box_.get(), "expose-event", 1454 g_signal_connect_after(event_box_.get(), "expose-event",
1450 G_CALLBACK(OnExposeEventThunk), this); 1455 G_CALLBACK(OnExposeEventThunk), this);
1456 g_signal_connect(event_box_.get(), "realize",
1457 G_CALLBACK(OnRealizeThunk), this);
1451 1458
1452 image_.Own(gtk_image_new()); 1459 image_.Own(gtk_image_new());
1453 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); 1460 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get());
1454 1461
1455 const Extension* extension = owner->browser()->profile()-> 1462 const Extension* extension = owner->browser()->profile()->
1456 GetExtensionService()->GetExtensionById(page_action->extension_id(), 1463 GetExtensionService()->GetExtensionById(page_action->extension_id(),
1457 false); 1464 false);
1458 DCHECK(extension); 1465 DCHECK(extension);
1459 1466
1460 // Load all the icons declared in the manifest. This is the contents of the 1467 // Load all the icons declared in the manifest. This is the contents of the
1461 // icons array, plus the default_icon property, if any. 1468 // icons array, plus the default_icon property, if any.
1462 std::vector<std::string> icon_paths(*page_action->icon_paths()); 1469 std::vector<std::string> icon_paths(*page_action->icon_paths());
1463 if (!page_action_->default_icon_path().empty()) 1470 if (!page_action_->default_icon_path().empty())
1464 icon_paths.push_back(page_action_->default_icon_path()); 1471 icon_paths.push_back(page_action_->default_icon_path());
1465 1472
1466 for (std::vector<std::string>::iterator iter = icon_paths.begin(); 1473 for (std::vector<std::string>::iterator iter = icon_paths.begin();
1467 iter != icon_paths.end(); ++iter) { 1474 iter != icon_paths.end(); ++iter) {
1468 tracker_.LoadImage(extension, extension->GetResource(*iter), 1475 tracker_.LoadImage(extension, extension->GetResource(*iter),
1469 gfx::Size(Extension::kPageActionIconMaxSize, 1476 gfx::Size(Extension::kPageActionIconMaxSize,
1470 Extension::kPageActionIconMaxSize), 1477 Extension::kPageActionIconMaxSize),
1471 ImageLoadingTracker::DONT_CACHE); 1478 ImageLoadingTracker::DONT_CACHE);
1472 } 1479 }
1473 1480
1474 // We set the owner last of all so that we can determine whether we are in 1481 // We set the owner last of all so that we can determine whether we are in
1475 // the process of initializing this class or not. 1482 // the process of initializing this class or not.
1476 owner_ = owner; 1483 owner_ = owner;
1477 } 1484 }
1478 1485
1479 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { 1486 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() {
1487 DisconnectPageActionAccelerator();
1488
1480 image_.Destroy(); 1489 image_.Destroy();
1481 event_box_.Destroy(); 1490 event_box_.Destroy();
1482 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); 1491 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end();
1483 ++iter) { 1492 ++iter) {
1484 g_object_unref(iter->second); 1493 g_object_unref(iter->second);
1485 } 1494 }
1486 if (last_icon_pixbuf_) 1495 if (last_icon_pixbuf_)
1487 g_object_unref(last_icon_pixbuf_); 1496 g_object_unref(last_icon_pixbuf_);
1488 } 1497 }
1489 1498
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 if (owner_) 1595 if (owner_)
1587 owner_->UpdatePageActions(); 1596 owner_->UpdatePageActions();
1588 } 1597 }
1589 1598
1590 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { 1599 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() {
1591 GdkEventButton event = {}; 1600 GdkEventButton event = {};
1592 event.button = 1; 1601 event.button = 1;
1593 OnButtonPressed(widget(), &event); 1602 OnButtonPressed(widget(), &event);
1594 } 1603 }
1595 1604
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);
tommi (sloooow) - chröme 2012/03/16 13:13:08 nit: DCHECK_EQ
1610 DisconnectPageActionAccelerator();
1611 }
1612
1596 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( 1613 void LocationBarViewGtk::PageActionViewGtk::InspectPopup(
1597 ExtensionAction* action) { 1614 ExtensionAction* action) {
1598 ShowPopup(true); 1615 ShowPopup(true);
1599 } 1616 }
1600 1617
1601 bool LocationBarViewGtk::PageActionViewGtk::ShowPopup(bool devtools) { 1618 bool LocationBarViewGtk::PageActionViewGtk::ShowPopup(bool devtools) {
1602 if (!page_action_->HasPopup(current_tab_id_)) 1619 if (!page_action_->HasPopup(current_tab_id_))
1603 return false; 1620 return false;
1604 1621
1605 ExtensionPopupGtk::Show( 1622 ExtensionPopupGtk::Show(
1606 page_action_->GetPopupUrl(current_tab_id_), 1623 page_action_->GetPopupUrl(current_tab_id_),
1607 owner_->browser_, 1624 owner_->browser_,
1608 event_box_.get(), 1625 event_box_.get(),
1609 devtools); 1626 devtools);
1610 return true; 1627 return true;
1611 } 1628 }
1612 1629
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
1613 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( 1685 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed(
1614 GtkWidget* sender, 1686 GtkWidget* sender,
1615 GdkEventButton* event) { 1687 GdkEventButton* event) {
1616 Profile* profile = owner_->browser()->profile(); 1688 Profile* profile = owner_->browser()->profile();
1617 if (event->button != 3) { 1689 if (event->button != 3) {
1618 if (!ShowPopup(false)) { 1690 if (!ShowPopup(false)) {
1619 ExtensionService* service = profile->GetExtensionService(); 1691 ExtensionService* service = profile->GetExtensionService();
1620 service->browser_event_router()->PageActionExecuted(profile, 1692 service->browser_event_router()->PageActionExecuted(profile,
1621 page_action_->extension_id(), page_action_->id(), current_tab_id_, 1693 page_action_->extension_id(), page_action_->id(), current_tab_id_,
1622 current_url_.spec(), event->button); 1694 current_url_.spec(), event->button);
(...skipping 29 matching lines...) Expand all
1652 std::string badge_text = page_action_->GetBadgeText(tab_id); 1724 std::string badge_text = page_action_->GetBadgeText(tab_id);
1653 if (badge_text.empty()) 1725 if (badge_text.empty())
1654 return FALSE; 1726 return FALSE;
1655 1727
1656 gfx::CanvasSkiaPaint canvas(event, false); 1728 gfx::CanvasSkiaPaint canvas(event, false);
1657 GtkAllocation allocation; 1729 GtkAllocation allocation;
1658 gtk_widget_get_allocation(widget, &allocation); 1730 gtk_widget_get_allocation(widget, &allocation);
1659 page_action_->PaintBadge(&canvas, gfx::Rect(allocation), tab_id); 1731 page_action_->PaintBadge(&canvas, gfx::Rect(allocation), tab_id);
1660 return FALSE; 1732 return FALSE;
1661 } 1733 }
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