Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / components / renderer_context_menu / views / toolkit_delegate_views.cc
blob8dcaaf9267ff30804229854a88bbdbfb7ccb418b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/renderer_context_menu/views/toolkit_delegate_views.h"
7 #include "ui/gfx/geometry/rect.h"
8 #include "ui/views/controls/menu/menu_item_view.h"
9 #include "ui/views/controls/menu/menu_model_adapter.h"
10 #include "ui/views/controls/menu/menu_runner.h"
12 ToolkitDelegateViews::ToolkitDelegateViews() : menu_view_(NULL) {}
14 ToolkitDelegateViews::~ToolkitDelegateViews() {}
16 void ToolkitDelegateViews::RunMenuAt(views::Widget* parent,
17 const gfx::Point& point,
18 ui::MenuSourceType type) {
19 views::MenuAnchorPosition anchor_position =
20 (type == ui::MENU_SOURCE_TOUCH ||
21 type == ui::MENU_SOURCE_TOUCH_EDIT_MENU)
22 ? views::MENU_ANCHOR_BOTTOMCENTER
23 : views::MENU_ANCHOR_TOPLEFT;
24 ignore_result(menu_runner_->RunMenuAt(
25 parent, NULL, gfx::Rect(point, gfx::Size()), anchor_position, type));
28 void ToolkitDelegateViews::Init(ui::SimpleMenuModel* menu_model) {
29 menu_adapter_.reset(new views::MenuModelAdapter(menu_model));
30 menu_view_ = menu_adapter_->CreateMenu();
31 menu_runner_.reset(new views::MenuRunner(
32 menu_view_,
33 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
36 void ToolkitDelegateViews::Cancel() {
37 DCHECK(menu_runner_.get());
38 menu_runner_->Cancel();
41 void ToolkitDelegateViews::UpdateMenuItem(int command_id,
42 bool enabled,
43 bool hidden,
44 const base::string16& title) {
45 views::MenuItemView* item = menu_view_->GetMenuItemByID(command_id);
46 if (!item)
47 return;
49 item->SetEnabled(enabled);
50 item->SetTitle(title);
51 item->SetVisible(!hidden);
53 views::MenuItemView* parent = item->GetParentMenuItem();
54 if (!parent)
55 return;
57 parent->ChildrenChanged();