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

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

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

Powered by Google App Engine
This is Rietveld 408576698