| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/gtk/tabs/tab_gtk.h" | 5 #include "chrome/browser/gtk/tabs/tab_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
| 8 | 8 |
| 9 #include "app/gtk_dnd_util.h" | 9 #include "app/gtk_dnd_util.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "app/menus/accelerator_gtk.h" | 11 #include "app/menus/accelerator_gtk.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 return font->GetStringWidth(title); | 33 return font->GetStringWidth(title); |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 class TabGtk::ContextMenuController : public menus::SimpleMenuModel::Delegate { | 38 class TabGtk::ContextMenuController : public menus::SimpleMenuModel::Delegate { |
| 39 public: | 39 public: |
| 40 explicit ContextMenuController(TabGtk* tab) | 40 explicit ContextMenuController(TabGtk* tab) |
| 41 : tab_(tab), | 41 : tab_(tab), |
| 42 model_(this) { | 42 model_(this, tab->delegate()->IsTabPinned(tab)) { |
| 43 menu_.reset(new MenuGtk(NULL, &model_)); | 43 menu_.reset(new MenuGtk(NULL, &model_)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual ~ContextMenuController() {} | 46 virtual ~ContextMenuController() {} |
| 47 | 47 |
| 48 void RunMenu() { | 48 void RunMenu() { |
| 49 menu_->PopupAsContext(gtk_get_current_event_time()); | 49 menu_->PopupAsContext(gtk_get_current_event_time()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void Cancel() { | 52 void Cancel() { |
| 53 tab_ = NULL; | 53 tab_ = NULL; |
| 54 menu_->Cancel(); | 54 menu_->Cancel(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 // Overridden from menus::SimpleMenuModel::Delegate: | 58 // Overridden from menus::SimpleMenuModel::Delegate: |
| 59 virtual bool IsCommandIdChecked(int command_id) const { | 59 virtual bool IsCommandIdChecked(int command_id) const { |
| 60 if (!tab_ || command_id != TabStripModel::CommandTogglePinned) | 60 return false; |
| 61 return false; | |
| 62 return tab_->delegate()->IsTabPinned(tab_); | |
| 63 } | 61 } |
| 64 virtual bool IsCommandIdEnabled(int command_id) const { | 62 virtual bool IsCommandIdEnabled(int command_id) const { |
| 65 return tab_ && tab_->delegate()->IsCommandEnabledForTab( | 63 return tab_ && tab_->delegate()->IsCommandEnabledForTab( |
| 66 static_cast<TabStripModel::ContextMenuCommand>(command_id), | 64 static_cast<TabStripModel::ContextMenuCommand>(command_id), |
| 67 tab_); | 65 tab_); |
| 68 } | 66 } |
| 69 virtual bool GetAcceleratorForCommandId( | 67 virtual bool GetAcceleratorForCommandId( |
| 70 int command_id, | 68 int command_id, |
| 71 menus::Accelerator* accelerator) { | 69 menus::Accelerator* accelerator) { |
| 72 int browser_command = 0; | 70 int browser_command = 0; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 339 |
| 342 void TabGtk::SetBounds(const gfx::Rect& bounds) { | 340 void TabGtk::SetBounds(const gfx::Rect& bounds) { |
| 343 TabRendererGtk::SetBounds(bounds); | 341 TabRendererGtk::SetBounds(bounds); |
| 344 UpdateTooltipState(); | 342 UpdateTooltipState(); |
| 345 } | 343 } |
| 346 | 344 |
| 347 /////////////////////////////////////////////////////////////////////////////// | 345 /////////////////////////////////////////////////////////////////////////////// |
| 348 // TabGtk, private: | 346 // TabGtk, private: |
| 349 | 347 |
| 350 void TabGtk::ShowContextMenu() { | 348 void TabGtk::ShowContextMenu() { |
| 351 if (!menu_controller_.get()) | 349 menu_controller_.reset(new ContextMenuController(this)); |
| 352 menu_controller_.reset(new ContextMenuController(this)); | |
| 353 | 350 |
| 354 menu_controller_->RunMenu(); | 351 menu_controller_->RunMenu(); |
| 355 } | 352 } |
| 356 | 353 |
| 357 void TabGtk::ContextMenuClosed() { | 354 void TabGtk::ContextMenuClosed() { |
| 358 delegate()->StopAllHighlighting(); | 355 delegate()->StopAllHighlighting(); |
| 359 menu_controller_.reset(); | 356 menu_controller_.reset(); |
| 360 } | 357 } |
| 361 | 358 |
| 362 void TabGtk::UpdateTooltipState() { | 359 void TabGtk::UpdateTooltipState() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 gdk_event_free(last_mouse_down_); | 410 gdk_event_free(last_mouse_down_); |
| 414 last_mouse_down_ = NULL; | 411 last_mouse_down_ = NULL; |
| 415 } | 412 } |
| 416 | 413 |
| 417 // Notify the drag helper that we're done with any potential drag operations. | 414 // Notify the drag helper that we're done with any potential drag operations. |
| 418 // Clean up the drag helper, which is re-created on the next mouse press. | 415 // Clean up the drag helper, which is re-created on the next mouse press. |
| 419 delegate_->EndDrag(canceled); | 416 delegate_->EndDrag(canceled); |
| 420 | 417 |
| 421 observer_.reset(); | 418 observer_.reset(); |
| 422 } | 419 } |
| OLD | NEW |