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

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

Issue 10834106: Implement Keybinding for script badges. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 1887 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() { 1898 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() {
1899 const ExtensionSet* extensions = owner_->browser()->profile()-> 1899 const ExtensionSet* extensions = owner_->browser()->profile()->
1900 GetExtensionService()->extensions(); 1900 GetExtensionService()->extensions();
1901 const Extension* extension = 1901 const Extension* extension =
1902 extensions->GetByID(page_action_->extension_id()); 1902 extensions->GetByID(page_action_->extension_id());
1903 window_ = owner_->browser()->window()->GetNativeWindow(); 1903 window_ = owner_->browser()->window()->GetNativeWindow();
1904 1904
1905 extensions::CommandService* command_service = 1905 extensions::CommandService* command_service =
1906 extensions::CommandServiceFactory::GetForProfile( 1906 extensions::CommandServiceFactory::GetForProfile(
1907 owner_->browser()->profile()); 1907 owner_->browser()->profile());
1908 extensions::Command command; 1908
1909 extensions::Command command_page_action;
1909 if (command_service->GetPageActionCommand( 1910 if (command_service->GetPageActionCommand(
1910 extension->id(), 1911 extension->id(),
1911 extensions::CommandService::ACTIVE_ONLY, 1912 extensions::CommandService::ACTIVE_ONLY,
1912 &command, 1913 &command_page_action,
1913 NULL)) { 1914 NULL)) {
1914 // Found the browser action shortcut command, register it. 1915 // Found the page action shortcut command, register it.
1915 keybinding_.reset(new ui::AcceleratorGtk( 1916 page_action_keybinding_.reset(new ui::AcceleratorGtk(
Evan Stade 2012/08/02 17:23:28 why is there no easier way of doing this, e.g. a c
1916 command.accelerator().key_code(), 1917 command_page_action.accelerator().key_code(),
1917 command.accelerator().IsShiftDown(), 1918 command_page_action.accelerator().IsShiftDown(),
1918 command.accelerator().IsCtrlDown(), 1919 command_page_action.accelerator().IsCtrlDown(),
1919 command.accelerator().IsAltDown())); 1920 command_page_action.accelerator().IsAltDown()));
1921 }
1920 1922
1923 extensions::Command command_script_badge;
1924 if (command_service->GetScriptBadgeCommand(
1925 extension->id(),
1926 extensions::CommandService::ACTIVE_ONLY,
1927 &command_script_badge,
1928 NULL)) {
1929 // Found the script badge shortcut command, register it.
1930 script_badge_keybinding_.reset(new ui::AcceleratorGtk(
1931 command_script_badge.accelerator().key_code(),
1932 command_script_badge.accelerator().IsShiftDown(),
1933 command_script_badge.accelerator().IsCtrlDown(),
1934 command_script_badge.accelerator().IsAltDown()));
1935 }
1936
1937 if (page_action_keybinding_.get() || script_badge_keybinding_.get()) {
1921 accel_group_ = gtk_accel_group_new(); 1938 accel_group_ = gtk_accel_group_new();
1922 gtk_window_add_accel_group(window_, accel_group_); 1939 gtk_window_add_accel_group(window_, accel_group_);
1923 1940
1924 gtk_accel_group_connect( 1941 if (page_action_keybinding_.get()) {
1925 accel_group_, 1942 gtk_accel_group_connect(
1926 keybinding_->GetGdkKeyCode(), 1943 accel_group_,
1927 keybinding_->gdk_modifier_type(), 1944 page_action_keybinding_->GetGdkKeyCode(),
1928 GtkAccelFlags(0), 1945 page_action_keybinding_->gdk_modifier_type(),
1929 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); 1946 GtkAccelFlags(0),
1947 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL));
1948 }
1949 if (script_badge_keybinding_.get()) {
1950 gtk_accel_group_connect(
1951 accel_group_,
1952 script_badge_keybinding_->GetGdkKeyCode(),
1953 script_badge_keybinding_->gdk_modifier_type(),
1954 GtkAccelFlags(0),
1955 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL));
1956 }
1930 1957
1931 // Since we've added an accelerator, we'll need to unregister it before 1958 // Since we've added an accelerator, we'll need to unregister it before
1932 // the window is closed, so we listen for the window being closed. 1959 // the window is closed, so we listen for the window being closed.
1933 registrar_.Add(this, 1960 registrar_.Add(this,
1934 chrome::NOTIFICATION_WINDOW_CLOSED, 1961 chrome::NOTIFICATION_WINDOW_CLOSED,
1935 content::Source<GtkWindow>(window_)); 1962 content::Source<GtkWindow>(window_));
1936 } 1963 }
1937 } 1964 }
1938 1965
1939 void LocationBarViewGtk::PageActionViewGtk::OnIconChanged( 1966 void LocationBarViewGtk::PageActionViewGtk::OnIconChanged(
1940 const ExtensionAction::IconAnimation& animation) { 1967 const ExtensionAction::IconAnimation& animation) {
1941 UpdateVisibility(owner_->GetWebContents(), current_url_); 1968 UpdateVisibility(owner_->GetWebContents(), current_url_);
1942 } 1969 }
1943 1970
1944 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { 1971 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() {
1945 if (accel_group_) { 1972 if (accel_group_) {
1946 gtk_accel_group_disconnect_key( 1973 if (page_action_keybinding_.get()) {
1947 accel_group_, 1974 gtk_accel_group_disconnect_key(
1948 keybinding_.get()->GetGdkKeyCode(), 1975 accel_group_,
1949 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); 1976 page_action_keybinding_->GetGdkKeyCode(),
1977 static_cast<GdkModifierType>(
1978 page_action_keybinding_->modifiers()));
1979 }
1980 if (script_badge_keybinding_.get()) {
1981 gtk_accel_group_disconnect_key(
1982 accel_group_,
1983 script_badge_keybinding_->GetGdkKeyCode(),
1984 static_cast<GdkModifierType>(
1985 script_badge_keybinding_->modifiers()));
1986 }
1950 gtk_window_remove_accel_group(window_, accel_group_); 1987 gtk_window_remove_accel_group(window_, accel_group_);
1951 g_object_unref(accel_group_); 1988 g_object_unref(accel_group_);
1952 accel_group_ = NULL; 1989 accel_group_ = NULL;
1953 keybinding_.reset(NULL); 1990 page_action_keybinding_.reset(NULL);
1991 script_badge_keybinding_.reset(NULL);
1954 } 1992 }
1955 } 1993 }
1956 1994
1957 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( 1995 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed(
1958 GtkWidget* sender, 1996 GtkWidget* sender,
1959 GdkEventButton* event) { 1997 GdkEventButton* event) {
1960 TabContents* tab_contents = owner_->GetTabContents(); 1998 TabContents* tab_contents = owner_->GetTabContents();
1961 if (!tab_contents) 1999 if (!tab_contents)
1962 return TRUE; 2000 return TRUE;
1963 2001
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2050 } 2088 }
2051 2089
2052 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( 2090 void LocationBarViewGtk::PageActionViewGtk::InspectPopup(
2053 ExtensionAction* action) { 2091 ExtensionAction* action) {
2054 ExtensionPopupGtk::Show( 2092 ExtensionPopupGtk::Show(
2055 action->GetPopupUrl(current_tab_id_), 2093 action->GetPopupUrl(current_tab_id_),
2056 owner_->browser_, 2094 owner_->browser_,
2057 event_box_.get(), 2095 event_box_.get(),
2058 ExtensionPopupGtk::SHOW_AND_INSPECT); 2096 ExtensionPopupGtk::SHOW_AND_INSPECT);
2059 } 2097 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698