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

Side by Side Diff: chrome/browser/ui/gtk/bookmarks/bookmark_sub_menu_model_gtk.cc

Issue 10316013: linux: Move linux_util.h from gfx/ to ui/base/gtk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: LinuxUtilTest -> MenuLabelAcceleratorTest Created 8 years, 7 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/bookmarks/bookmark_sub_menu_model_gtk.h" 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_sub_menu_model_gtk.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/event_disposition.h" 12 #include "chrome/browser/event_disposition.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" 15 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h"
16 #include "chrome/browser/ui/gtk/menu_gtk.h" 16 #include "chrome/browser/ui/gtk/menu_gtk.h"
17 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
18 #include "ui/base/gtk/menu_label_accelerator_util.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/gfx/linux_util.h"
20 20
21 using content::OpenURLParams; 21 using content::OpenURLParams;
22 using content::PageNavigator; 22 using content::PageNavigator;
23 23
24 // Per chrome/app/chrome_command_ids.h, values < 4000 are for "dynamic menu 24 // Per chrome/app/chrome_command_ids.h, values < 4000 are for "dynamic menu
25 // items". We only use one command id for all the bookmarks, because we handle 25 // items". We only use one command id for all the bookmarks, because we handle
26 // bookmark item activations directly. So we pick a suitably large random value 26 // bookmark item activations directly. So we pick a suitably large random value
27 // and use that to avoid accidental conflicts with other dynamic items. 27 // and use that to avoid accidental conflicts with other dynamic items.
28 static const int kBookmarkItemCommandId = 1759; 28 static const int kBookmarkItemCommandId = 1759;
29 29
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void BookmarkNodeMenuModel::PopulateMenu() { 68 void BookmarkNodeMenuModel::PopulateMenu() {
69 DCHECK(submenus_.empty()); 69 DCHECK(submenus_.empty());
70 for (int i = 0; i < node_->child_count(); ++i) { 70 for (int i = 0; i < node_->child_count(); ++i) {
71 const BookmarkNode* child = node_->GetChild(i); 71 const BookmarkNode* child = node_->GetChild(i);
72 if (child->is_folder()) { 72 if (child->is_folder()) {
73 AddSubMenuForNode(child); 73 AddSubMenuForNode(child);
74 } else { 74 } else {
75 // Ironically the label will end up getting converted back to UTF8 later. 75 // Ironically the label will end up getting converted back to UTF8 later.
76 // We need to escape any Windows-style "&" characters since they will be 76 // We need to escape any Windows-style "&" characters since they will be
77 // converted in MenuGtk outside of our control here. 77 // converted in MenuGtk outside of our control here.
78 const string16 label = UTF8ToUTF16(gfx::EscapeWindowsStyleAccelerators( 78 const string16 label = UTF8ToUTF16(ui::EscapeWindowsStyleAccelerators(
79 bookmark_utils::BuildMenuLabelFor(child))); 79 bookmark_utils::BuildMenuLabelFor(child)));
80 // No command id. We override ActivatedAt below to handle activations. 80 // No command id. We override ActivatedAt below to handle activations.
81 AddItem(kBookmarkItemCommandId, label); 81 AddItem(kBookmarkItemCommandId, label);
82 const SkBitmap& node_icon = model_->GetFavicon(child); 82 const SkBitmap& node_icon = model_->GetFavicon(child);
83 if (node_icon.width() > 0) 83 if (node_icon.width() > 0)
84 SetIcon(GetItemCount() - 1, node_icon); 84 SetIcon(GetItemCount() - 1, node_icon);
85 // TODO(mdm): set up an observer to watch for icon load events and set 85 // TODO(mdm): set up an observer to watch for icon load events and set
86 // the icons in response. 86 // the icons in response.
87 } 87 }
88 } 88 }
89 } 89 }
90 90
91 void BookmarkNodeMenuModel::AddSubMenuForNode(const BookmarkNode* node) { 91 void BookmarkNodeMenuModel::AddSubMenuForNode(const BookmarkNode* node) {
92 DCHECK(node->is_folder()); 92 DCHECK(node->is_folder());
93 // Ironically the label will end up getting converted back to UTF8 later. 93 // Ironically the label will end up getting converted back to UTF8 later.
94 // We need to escape any Windows-style "&" characters since they will be 94 // We need to escape any Windows-style "&" characters since they will be
95 // converted in MenuGtk outside of our control here. 95 // converted in MenuGtk outside of our control here.
96 const string16 label = UTF8ToUTF16(gfx::EscapeWindowsStyleAccelerators( 96 const string16 label = UTF8ToUTF16(ui::EscapeWindowsStyleAccelerators(
97 bookmark_utils::BuildMenuLabelFor(node))); 97 bookmark_utils::BuildMenuLabelFor(node)));
98 // Don't pass in the delegate, if any. Bookmark submenus don't need one. 98 // Don't pass in the delegate, if any. Bookmark submenus don't need one.
99 BookmarkNodeMenuModel* submenu = 99 BookmarkNodeMenuModel* submenu =
100 new BookmarkNodeMenuModel(NULL, model_, node, page_navigator_); 100 new BookmarkNodeMenuModel(NULL, model_, node, page_navigator_);
101 // No command id. Nothing happens if you click on the submenu itself. 101 // No command id. Nothing happens if you click on the submenu itself.
102 AddSubMenu(kBookmarkItemCommandId, label, submenu); 102 AddSubMenu(kBookmarkItemCommandId, label, submenu);
103 submenus_.push_back(submenu); 103 submenus_.push_back(submenu);
104 } 104 }
105 105
106 void BookmarkNodeMenuModel::NavigateToMenuItem( 106 void BookmarkNodeMenuModel::NavigateToMenuItem(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 220
221 bool BookmarkSubMenuModel::IsVisibleAt(int index) const { 221 bool BookmarkSubMenuModel::IsVisibleAt(int index) const {
222 // We don't want the delegate interfering with bookmark items. 222 // We don't want the delegate interfering with bookmark items.
223 return index >= fixed_items_ || SimpleMenuModel::IsVisibleAt(index); 223 return index >= fixed_items_ || SimpleMenuModel::IsVisibleAt(index);
224 } 224 }
225 225
226 // static 226 // static
227 bool BookmarkSubMenuModel::IsBookmarkItemCommandId(int command_id) { 227 bool BookmarkSubMenuModel::IsBookmarkItemCommandId(int command_id) {
228 return command_id == kBookmarkItemCommandId; 228 return command_id == kBookmarkItemCommandId;
229 } 229 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu_gtk.cc ('k') | chrome/browser/ui/gtk/certificate_viewer_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698