1 // Copyright 2014 The Chromium Embedded Framework Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be found
3 // in the LICENSE file.
4
5 #include "libcef/browser/native/menu_runner_linux.h"
6
7 #include "libcef/browser/alloy/alloy_browser_host_impl.h"
8
9 #include "base/compiler_specific.h"
10 #include "base/strings/string_util.h"
11 #include "ui/gfx/geometry/point.h"
12
CefMenuRunnerLinux()13 CefMenuRunnerLinux::CefMenuRunnerLinux() {}
14
RunContextMenu(AlloyBrowserHostImpl * browser,CefMenuModelImpl * model,const content::ContextMenuParams & params)15 bool CefMenuRunnerLinux::RunContextMenu(
16 AlloyBrowserHostImpl* browser,
17 CefMenuModelImpl* model,
18 const content::ContextMenuParams& params) {
19 menu_.reset(
20 new views::MenuRunner(model->model(), views::MenuRunner::CONTEXT_MENU));
21
22 const gfx::Point& screen_point =
23 browser->GetScreenPoint(gfx::Point(params.x, params.y));
24
25 views::Widget* parent_widget = nullptr;
26 if (!browser->IsWindowless())
27 parent_widget = browser->GetWindowWidget();
28
29 menu_->RunMenuAt(parent_widget, nullptr, gfx::Rect(screen_point, gfx::Size()),
30 views::MenuAnchorPosition::kTopRight, ui::MENU_SOURCE_NONE);
31
32 return true;
33 }
34
CancelContextMenu()35 void CefMenuRunnerLinux::CancelContextMenu() {
36 if (menu_)
37 menu_->Cancel();
38 }
39
FormatLabel(std::u16string & label)40 bool CefMenuRunnerLinux::FormatLabel(std::u16string& label) {
41 // Remove the accelerator indicator (&) from label strings.
42 const std::u16string::value_type replace[] = {u'&', 0};
43 return base::ReplaceChars(label, replace, std::u16string(), &label);
44 }
45