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

Side by Side Diff: chrome/browser/views/tabs/tab.cc

Issue 500030: Factor tab context menu into a shared model and fix mac and win to use it. Im... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/tabs/tab.h" 5 #include "chrome/browser/views/tabs/tab.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/gfx/font.h" 8 #include "app/gfx/font.h"
9 #include "app/gfx/path.h" 9 #include "app/gfx/path.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "app/menus/simple_menu_model.h" 11 #include "app/menus/simple_menu_model.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/gfx/size.h" 14 #include "base/gfx/size.h"
15 #include "chrome/browser/tab_menu_model.h"
15 #include "chrome/browser/views/frame/browser_extender.h" 16 #include "chrome/browser/views/frame/browser_extender.h"
16 #include "chrome/browser/views/frame/browser_view.h" 17 #include "chrome/browser/views/frame/browser_view.h"
17 #include "chrome/browser/views/tabs/tab_strip.h" 18 #include "chrome/browser/views/tabs/tab_strip.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "views/controls/menu/menu_2.h" 20 #include "views/controls/menu/menu_2.h"
20 #include "views/widget/tooltip_manager.h" 21 #include "views/widget/tooltip_manager.h"
21 #include "views/widget/widget.h" 22 #include "views/widget/widget.h"
22 23
23 const std::string Tab::kTabClassName = "browser/tabs/Tab"; 24 const std::string Tab::kTabClassName = "browser/tabs/Tab";
24 25
25 static const SkScalar kTabCapWidth = 15; 26 static const SkScalar kTabCapWidth = 15;
26 static const SkScalar kTabTopCurveWidth = 4; 27 static const SkScalar kTabTopCurveWidth = 4;
27 static const SkScalar kTabBottomCurveWidth = 3; 28 static const SkScalar kTabBottomCurveWidth = 3;
28 29
29 class Tab::TabContextMenuContents : public menus::SimpleMenuModel, 30 class Tab::TabContextMenuContents : public menus::SimpleMenuModel::Delegate {
30 public menus::SimpleMenuModel::Delegate {
31 public: 31 public:
32 explicit TabContextMenuContents(Tab* tab) 32 explicit TabContextMenuContents(Tab* tab)
33 : ALLOW_THIS_IN_INITIALIZER_LIST(menus::SimpleMenuModel(this)), 33 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(this)),
34 tab_(tab), 34 tab_(tab),
35 last_command_(TabStripModel::CommandFirst) { 35 last_command_(TabStripModel::CommandFirst) {
36 Build(); 36 Build();
37 } 37 }
38 virtual ~TabContextMenuContents() { 38 virtual ~TabContextMenuContents() {
39 menu_->CancelMenu(); 39 menu_->CancelMenu();
40 tab_->delegate()->StopAllHighlighting(); 40 tab_->delegate()->StopAllHighlighting();
41 } 41 }
42 42
43 void RunMenuAt(const gfx::Point& point) { 43 void RunMenuAt(const gfx::Point& point) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 virtual void ExecuteCommand(int command_id) { 77 virtual void ExecuteCommand(int command_id) {
78 if (!tab_) 78 if (!tab_)
79 return; 79 return;
80 tab_->delegate()->ExecuteCommandForTab( 80 tab_->delegate()->ExecuteCommandForTab(
81 static_cast<TabStripModel::ContextMenuCommand>(command_id), 81 static_cast<TabStripModel::ContextMenuCommand>(command_id),
82 tab_); 82 tab_);
83 } 83 }
84 84
85 private: 85 private:
86 void Build() { 86 void Build() {
87 AddItemWithStringId(TabStripModel::CommandNewTab, IDS_TAB_CXMENU_NEWTAB); 87 menu_.reset(new views::Menu2(&model_));
88 AddSeparator();
89 AddItemWithStringId(TabStripModel::CommandReload, IDS_TAB_CXMENU_RELOAD);
90 AddItemWithStringId(TabStripModel::CommandDuplicate,
91 IDS_TAB_CXMENU_DUPLICATE);
92 AddCheckItemWithStringId(TabStripModel::CommandTogglePinned,
93 IDS_TAB_CXMENU_PIN_TAB);
94 AddSeparator();
95 AddItemWithStringId(TabStripModel::CommandCloseTab,
96 IDS_TAB_CXMENU_CLOSETAB);
97 AddItemWithStringId(TabStripModel::CommandCloseOtherTabs,
98 IDS_TAB_CXMENU_CLOSEOTHERTABS);
99 AddItemWithStringId(TabStripModel::CommandCloseTabsToRight,
100 IDS_TAB_CXMENU_CLOSETABSTORIGHT);
101 AddItemWithStringId(TabStripModel::CommandCloseTabsOpenedBy,
102 IDS_TAB_CXMENU_CLOSETABSOPENEDBY);
103 AddSeparator();
104 AddItemWithStringId(TabStripModel::CommandRestoreTab, IDS_RESTORE_TAB);
105 AddItemWithStringId(TabStripModel::CommandBookmarkAllTabs,
106 IDS_TAB_CXMENU_BOOKMARK_ALL_TABS);
107 menu_.reset(new views::Menu2(this));
108 } 88 }
109 89
90 TabMenuModel model_;
110 scoped_ptr<views::Menu2> menu_; 91 scoped_ptr<views::Menu2> menu_;
111 92
112 // The Tab the context menu was brought up for. Set to NULL when the menu 93 // The Tab the context menu was brought up for. Set to NULL when the menu
113 // is canceled. 94 // is canceled.
114 Tab* tab_; 95 Tab* tab_;
115 96
116 // The last command that was selected, so that we can start/stop highlighting 97 // The last command that was selected, so that we can start/stop highlighting
117 // appropriately as the user moves through the menu. 98 // appropriately as the user moves through the menu.
118 TabStripModel::ContextMenuCommand last_command_; 99 TabStripModel::ContextMenuCommand last_command_;
119 100
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 270
290 // Right end cap. 271 // Right end cap.
291 path->lineTo(w - kTabCapWidth + kTabTopCurveWidth, kTabTopCurveWidth); 272 path->lineTo(w - kTabCapWidth + kTabTopCurveWidth, kTabTopCurveWidth);
292 path->lineTo(w - kTabBottomCurveWidth, h - kTabBottomCurveWidth); 273 path->lineTo(w - kTabBottomCurveWidth, h - kTabBottomCurveWidth);
293 path->lineTo(w, h); 274 path->lineTo(w, h);
294 275
295 // Close out the path. 276 // Close out the path.
296 path->lineTo(0, h); 277 path->lineTo(0, h);
297 path->close(); 278 path->close();
298 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698