2016-01-19 21:09:01 +01:00
|
|
|
// Copyright 2016 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/views/menu_runner_views.h"
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "libcef/browser/views/browser_view_impl.h"
|
|
|
|
|
|
|
|
CefMenuRunnerViews::CefMenuRunnerViews(CefBrowserViewImpl* browser_view)
|
2017-05-17 11:29:28 +02:00
|
|
|
: browser_view_(browser_view) {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
bool CefMenuRunnerViews::RunContextMenu(
|
2020-09-22 21:54:02 +02:00
|
|
|
AlloyBrowserHostImpl* browser,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefMenuModelImpl* model,
|
|
|
|
const content::ContextMenuParams& params) {
|
|
|
|
CefRefPtr<CefWindow> window = browser_view_->GetWindow();
|
|
|
|
if (!window)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CefPoint screen_point(params.x, params.y);
|
|
|
|
browser_view_->ConvertPointToScreen(screen_point);
|
|
|
|
|
|
|
|
window->ShowMenu(model, screen_point, CEF_MENU_ANCHOR_TOPRIGHT);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefMenuRunnerViews::CancelContextMenu() {
|
|
|
|
CefRefPtr<CefWindow> window = browser_view_->GetWindow();
|
|
|
|
if (window)
|
|
|
|
window->CancelMenu();
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
bool CefMenuRunnerViews::FormatLabel(std::u16string& label) {
|
2016-01-19 21:09:01 +01:00
|
|
|
// Remove the accelerator indicator (&) from label strings.
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string::value_type replace[] = {L'&', 0};
|
|
|
|
return base::ReplaceChars(label, replace, std::u16string(), &label);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|