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/browser_actions_toolbar_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 367 |
368 // The handler for when the browser action is realized. |user_data| contains a | 368 // The handler for when the browser action is realized. |user_data| contains a |
369 // pointer to the BrowserAction shown. | 369 // pointer to the BrowserAction shown. |
370 static void OnRealize(GtkWidget* widget, void* user_data) { | 370 static void OnRealize(GtkWidget* widget, void* user_data) { |
371 BrowserActionButton* button = static_cast<BrowserActionButton*>(user_data); | 371 BrowserActionButton* button = static_cast<BrowserActionButton*>(user_data); |
372 button->ConnectBrowserActionPopupAccelerator(); | 372 button->ConnectBrowserActionPopupAccelerator(); |
373 } | 373 } |
374 | 374 |
375 // Connect the accelerator for the browser action popup. | 375 // Connect the accelerator for the browser action popup. |
376 void ConnectBrowserActionPopupAccelerator() { | 376 void ConnectBrowserActionPopupAccelerator() { |
377 // Iterate through all the keybindings and see if one is assigned to the | 377 const Extension::ExtensionKeybinding* command = |
378 // browserAction. | 378 extension_->browser_action_command(); |
379 const std::vector<Extension::ExtensionKeybinding>& commands = | 379 if (command) { |
380 extension_->keybindings(); | |
381 for (size_t i = 0; i < commands.size(); ++i) { | |
382 if (commands[i].command_name() != | |
383 extension_manifest_values::kBrowserActionKeybindingEvent) | |
384 continue; | |
385 | |
386 // Found the browser action shortcut command, register it. | 380 // Found the browser action shortcut command, register it. |
387 keybinding_.reset(new ui::AcceleratorGtk( | 381 keybinding_.reset(new ui::AcceleratorGtk( |
388 commands[i].accelerator().key_code(), | 382 command->accelerator().key_code(), |
389 commands[i].accelerator().IsShiftDown(), | 383 command->accelerator().IsShiftDown(), |
390 commands[i].accelerator().IsCtrlDown(), | 384 command->accelerator().IsCtrlDown(), |
391 commands[i].accelerator().IsAltDown())); | 385 command->accelerator().IsAltDown())); |
392 | 386 |
393 gfx::NativeWindow window = | 387 gfx::NativeWindow window = |
394 toolbar_->browser()->window()->GetNativeHandle(); | 388 toolbar_->browser()->window()->GetNativeHandle(); |
395 accel_group_ = gtk_accel_group_new(); | 389 accel_group_ = gtk_accel_group_new(); |
396 gtk_window_add_accel_group(window, accel_group_); | 390 gtk_window_add_accel_group(window, accel_group_); |
397 | 391 |
398 gtk_accel_group_connect( | 392 gtk_accel_group_connect( |
399 accel_group_, | 393 accel_group_, |
400 keybinding_.get()->GetGdkKeyCode(), | 394 keybinding_.get()->GetGdkKeyCode(), |
401 keybinding_.get()->gdk_modifier_type(), | 395 keybinding_.get()->gdk_modifier_type(), |
402 GtkAccelFlags(0), | 396 GtkAccelFlags(0), |
403 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); | 397 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); |
404 | 398 |
405 // Since we've added an accelerator, we'll need to unregister it before | 399 // Since we've added an accelerator, we'll need to unregister it before |
406 // the window is closed, so we listen for the window being closed. | 400 // the window is closed, so we listen for the window being closed. |
407 registrar_.Add(this, | 401 registrar_.Add(this, |
408 chrome::NOTIFICATION_WINDOW_CLOSED, | 402 chrome::NOTIFICATION_WINDOW_CLOSED, |
409 content::Source<GtkWindow>(window)); | 403 content::Source<GtkWindow>(window)); |
410 break; | |
411 } | 404 } |
412 } | 405 } |
413 | 406 |
414 // Disconnect the accelerator for the browser action popup and delete clean up | 407 // Disconnect the accelerator for the browser action popup and delete clean up |
415 // the accelerator group registration. | 408 // the accelerator group registration. |
416 void DisconnectBrowserActionPopupAccelerator() { | 409 void DisconnectBrowserActionPopupAccelerator() { |
417 if (accel_group_) { | 410 if (accel_group_) { |
418 gfx::NativeWindow window = | 411 gfx::NativeWindow window = |
419 toolbar_->browser()->window()->GetNativeHandle(); | 412 toolbar_->browser()->window()->GetNativeHandle(); |
420 gtk_accel_group_disconnect_key( | 413 gtk_accel_group_disconnect_key( |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 | 1077 |
1085 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 1078 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
1086 event->time); | 1079 event->time); |
1087 return TRUE; | 1080 return TRUE; |
1088 } | 1081 } |
1089 | 1082 |
1090 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 1083 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
1091 if (!resize_animation_.is_animating()) | 1084 if (!resize_animation_.is_animating()) |
1092 UpdateChevronVisibility(); | 1085 UpdateChevronVisibility(); |
1093 } | 1086 } |
OLD | NEW |