2015-11-17 19:20:13 +01:00
|
|
|
// Copyright 2014 The Chromium Embedded Framework 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 "libcef/browser/native/menu_runner_linux.h"
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "ui/gfx/geometry/point.h"
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefMenuRunnerLinux::CefMenuRunnerLinux() {}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
bool CefMenuRunnerLinux::RunContextMenu(
|
2020-09-22 21:54:02 +02:00
|
|
|
AlloyBrowserHostImpl* browser,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefMenuModelImpl* model,
|
2015-11-17 19:20:13 +01:00
|
|
|
const content::ContextMenuParams& params) {
|
|
|
|
menu_.reset(
|
2016-01-19 21:09:01 +01:00
|
|
|
new views::MenuRunner(model->model(), views::MenuRunner::CONTEXT_MENU));
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
const gfx::Point& screen_point =
|
|
|
|
browser->GetScreenPoint(gfx::Point(params.x, params.y));
|
|
|
|
|
|
|
|
views::Widget* parent_widget = nullptr;
|
|
|
|
if (!browser->IsWindowless())
|
|
|
|
parent_widget = browser->GetWindowWidget();
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
menu_->RunMenuAt(parent_widget, nullptr, gfx::Rect(screen_point, gfx::Size()),
|
2019-04-16 16:38:48 +02:00
|
|
|
views::MenuAnchorPosition::kTopRight, ui::MENU_SOURCE_NONE);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefMenuRunnerLinux::CancelContextMenu() {
|
|
|
|
if (menu_)
|
|
|
|
menu_->Cancel();
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
bool CefMenuRunnerLinux::FormatLabel(std::u16string& label) {
|
2015-11-17 19:20:13 +01:00
|
|
|
// Remove the accelerator indicator (&) from label strings.
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string::value_type replace[] = {u'&', 0};
|
|
|
|
return base::ReplaceChars(label, replace, std::u16string(), &label);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|