summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/bookmark_context_menu.cc
blob: cdd778a556bde834013801a15aa0daa9a7ff5a0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/views/bookmark_context_menu.h"

#include "app/l10n_util.h"
#include "base/i18n/rtl.h"
#include "chrome/browser/profile.h"
#include "chrome/common/notification_service.h"
#include "grit/generated_resources.h"
#include "views/controls/menu/menu_item_view.h"

////////////////////////////////////////////////////////////////////////////////
// BookmarkContextMenu, public:

BookmarkContextMenu::BookmarkContextMenu(
    gfx::NativeWindow parent_window,
    Profile* profile,
    PageNavigator* page_navigator,
    const BookmarkNode* parent,
    const std::vector<const BookmarkNode*>& selection)
    : ALLOW_THIS_IN_INITIALIZER_LIST(
          controller_(new BookmarkContextMenuControllerViews(parent_window,
              this, profile, page_navigator, parent, selection))),
      parent_window_(parent_window),
      ALLOW_THIS_IN_INITIALIZER_LIST(menu_(new views::MenuItemView(this))),
      observer_(NULL) {
  controller_->BuildMenu();
}

BookmarkContextMenu::~BookmarkContextMenu() {
}

void BookmarkContextMenu::RunMenuAt(const gfx::Point& point) {
  NotificationService::current()->Notify(
      NotificationType::BOOKMARK_CONTEXT_MENU_SHOWN,
      Source<BookmarkContextMenu>(this),
      NotificationService::NoDetails());
  // width/height don't matter here.
  views::MenuItemView::AnchorPosition anchor = base::i18n::IsRTL() ?
      views::MenuItemView::TOPRIGHT : views::MenuItemView::TOPLEFT;
  menu_->RunMenuAt(parent_window_, NULL, gfx::Rect(point.x(), point.y(), 0, 0),
                   anchor, true);
}

////////////////////////////////////////////////////////////////////////////////
// BookmarkContextMenu, views::MenuDelegate implementation:

void BookmarkContextMenu::ExecuteCommand(int command_id) {
  controller_->ExecuteCommand(command_id);
}

bool BookmarkContextMenu::IsItemChecked(int command_id) const {
  return controller_->IsItemChecked(command_id);
}

bool BookmarkContextMenu::IsCommandEnabled(int command_id) const {
  return controller_->IsCommandEnabled(command_id);
}

bool BookmarkContextMenu::ShouldCloseAllMenusOnExecute(int id) {
  return id != IDS_BOOKMARK_BAR_REMOVE;
}

////////////////////////////////////////////////////////////////////////////////
// BookmarkContextMenu, BookmarkContextMenuControllerViewsDelegate
// implementation:

void BookmarkContextMenu::CloseMenu() {
  menu_->Cancel();
}

void BookmarkContextMenu::AddItem(int command_id) {
  menu_->AppendMenuItemWithLabel(command_id, l10n_util::GetString(command_id));
}

void BookmarkContextMenu::AddItemWithStringId(int command_id, int string_id) {
  menu_->AppendMenuItemWithLabel(command_id, l10n_util::GetString(string_id));
}

void BookmarkContextMenu::AddSeparator() {
  menu_->AppendSeparator();
}

void BookmarkContextMenu::AddCheckboxItem(int command_id) {
  menu_->AppendMenuItem(command_id, l10n_util::GetString(command_id),
                        views::MenuItemView::CHECKBOX);
}

void BookmarkContextMenu::WillRemoveBookmarks(
    const std::vector<const BookmarkNode*>& bookmarks) {
  if (observer_)
    observer_->WillRemoveBookmarks(bookmarks);
}

void BookmarkContextMenu::DidRemoveBookmarks() {
  if (observer_)
    observer_->DidRemoveBookmarks();
}