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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc

Issue 9814031: views/bookmarks: Convert BookmarkEditorView from Menu2 API to MenuModelApdater/MenuRunner API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win 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
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_editor_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/views/bookmarks/bookmark_editor_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/bookmarks/bookmark_utils.h" 14 #include "chrome/browser/bookmarks/bookmark_utils.h"
15 #include "chrome/browser/history/history.h" 15 #include "chrome/browser/history/history.h"
16 #include "chrome/browser/net/url_fixer_upper.h" 16 #include "chrome/browser/net/url_fixer_upper.h"
17 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
21 #include "grit/chromium_strings.h" 21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
23 #include "grit/locale_settings.h" 23 #include "grit/locale_settings.h"
24 #include "net/base/net_util.h" 24 #include "net/base/net_util.h"
25 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/views/background.h" 26 #include "ui/views/background.h"
27 #include "ui/views/controls/button/text_button.h" 27 #include "ui/views/controls/button/text_button.h"
28 #include "ui/views/controls/label.h" 28 #include "ui/views/controls/label.h"
29 #include "ui/views/controls/menu/menu_2.h" 29 #include "ui/views/controls/menu/menu_model_adapter.h"
30 #include "ui/views/controls/menu/menu_runner.h"
30 #include "ui/views/controls/textfield/textfield.h" 31 #include "ui/views/controls/textfield/textfield.h"
31 #include "ui/views/controls/tree/tree_view.h" 32 #include "ui/views/controls/tree/tree_view.h"
32 #include "ui/views/focus/focus_manager.h" 33 #include "ui/views/focus/focus_manager.h"
33 #include "ui/views/layout/grid_layout.h" 34 #include "ui/views/layout/grid_layout.h"
34 #include "ui/views/layout/layout_constants.h" 35 #include "ui/views/layout/layout_constants.h"
35 #include "ui/views/widget/widget.h" 36 #include "ui/views/widget/widget.h"
36 37
37 using views::GridLayout; 38 using views::GridLayout;
38 39
39 namespace { 40 namespace {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 281 }
281 282
282 void BookmarkEditorView::ShowContextMenuForView(views::View* source, 283 void BookmarkEditorView::ShowContextMenuForView(views::View* source,
283 const gfx::Point& point) { 284 const gfx::Point& point) {
284 DCHECK(source == tree_view_); 285 DCHECK(source == tree_view_);
285 if (!tree_view_->GetSelectedNode()) 286 if (!tree_view_->GetSelectedNode())
286 return; 287 return;
287 running_menu_for_root_ = 288 running_menu_for_root_ =
288 (tree_model_->GetParent(tree_view_->GetSelectedNode()) == 289 (tree_model_->GetParent(tree_view_->GetSelectedNode()) ==
289 tree_model_->GetRoot()); 290 tree_model_->GetRoot());
290 #if defined(USE_AURA) 291
291 NOTIMPLEMENTED(); 292 views::MenuModelAdapter adapter(GetMenuModel());
292 #else 293 context_menu_runner_.reset(new views::MenuRunner(adapter.CreateMenu()));
293 if (!context_menu_contents_.get()) { 294
294 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); 295 if (context_menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(),
295 context_menu_contents_->AddItemWithStringId(IDS_EDIT, IDS_EDIT); 296 NULL, gfx::Rect(point, gfx::Size()), views::MenuItemView::TOPRIGHT,
296 context_menu_contents_->AddItemWithStringId(IDS_DELETE, IDS_DELETE); 297 views::MenuRunner::HAS_MNEMONICS) == views::MenuRunner::MENU_DELETED)
297 context_menu_contents_->AddItemWithStringId( 298 return;
298 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM,
299 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM);
300 context_menu_.reset(new views::Menu2(context_menu_contents_.get()));
301 }
302 context_menu_->RunContextMenuAt(point);
303 #endif
304 } 299 }
305 300
306 void BookmarkEditorView::Init() { 301 void BookmarkEditorView::Init() {
307 bb_model_ = profile_->GetBookmarkModel(); 302 bb_model_ = profile_->GetBookmarkModel();
308 DCHECK(bb_model_); 303 DCHECK(bb_model_);
309 bb_model_->AddObserver(this); 304 bb_model_->AddObserver(this);
310 305
311 title_tf_.set_parent_owned(false); 306 title_tf_.set_parent_owned(false);
312 307
313 string16 title; 308 string16 title;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // Do this first, otherwise when we invoke SetModel with the real one 455 // Do this first, otherwise when we invoke SetModel with the real one
461 // tree_view will try to invoke something on the model we just deleted. 456 // tree_view will try to invoke something on the model we just deleted.
462 tree_view_->SetModel(NULL); 457 tree_view_->SetModel(NULL);
463 458
464 EditorNode* root_node = CreateRootNode(); 459 EditorNode* root_node = CreateRootNode();
465 tree_model_.reset(new EditorTreeModel(root_node)); 460 tree_model_.reset(new EditorTreeModel(root_node));
466 461
467 tree_view_->SetModel(tree_model_.get()); 462 tree_view_->SetModel(tree_model_.get());
468 tree_view_->SetController(this); 463 tree_view_->SetController(this);
469 464
470 #if !defined(USE_AURA) 465 context_menu_runner_.reset();
471 context_menu_.reset();
472 #endif
473 466
474 if (parent()) 467 if (parent())
475 ExpandAndSelect(); 468 ExpandAndSelect();
476 } 469 }
477 470
478 GURL BookmarkEditorView::GetInputURL() const { 471 GURL BookmarkEditorView::GetInputURL() const {
479 if (details_.GetNodeType() == BookmarkNode::FOLDER) 472 if (details_.GetNodeType() == BookmarkNode::FOLDER)
480 return GURL(); 473 return GURL();
481 return URLFixerUpper::FixupURL(UTF16ToUTF8(url_tf_->text()), std::string()); 474 return URLFixerUpper::FixupURL(UTF16ToUTF8(url_tf_->text()), std::string());
482 } 475 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 BookmarkExpandedStateTracker::Nodes* expanded_nodes) { 655 BookmarkExpandedStateTracker::Nodes* expanded_nodes) {
663 if (!tree_view_->IsExpanded(editor_node)) 656 if (!tree_view_->IsExpanded(editor_node))
664 return; 657 return;
665 658
666 if (editor_node->value != 0) // The root is 0 659 if (editor_node->value != 0) // The root is 0
667 expanded_nodes->insert(bb_model_->GetNodeByID(editor_node->value)); 660 expanded_nodes->insert(bb_model_->GetNodeByID(editor_node->value));
668 for (int i = 0; i < editor_node->child_count(); ++i) 661 for (int i = 0; i < editor_node->child_count(); ++i)
669 UpdateExpandedNodes(editor_node->GetChild(i), expanded_nodes); 662 UpdateExpandedNodes(editor_node->GetChild(i), expanded_nodes);
670 } 663 }
671 664
665 ui::SimpleMenuModel* BookmarkEditorView::GetMenuModel() {
666 if (!context_menu_model_.get()) {
667 context_menu_model_.reset(new ui::SimpleMenuModel(this));
668 context_menu_model_->AddItemWithStringId(IDS_EDIT, IDS_EDIT);
669 context_menu_model_->AddItemWithStringId(IDS_DELETE, IDS_DELETE);
670 context_menu_model_->AddItemWithStringId(
671 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM,
672 IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM);
673 }
674 return context_menu_model_.get();
675 }
676
672 void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node, 677 void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node,
673 const string16& title) { 678 const string16& title) {
674 if (!title.empty()) 679 if (!title.empty())
675 ui::TreeNodeModel<EditorNode>::SetTitle(node, title); 680 ui::TreeNodeModel<EditorNode>::SetTitle(node, title);
676 } 681 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_editor_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698