2022-05-13 13:38:41 +02: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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/native/menu_runner_views_aura.h"
|
2022-05-13 13:38:41 +02:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2022-05-13 13:38:41 +02:00
|
|
|
#include "base/strings/string_util.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
2022-05-13 13:38:41 +02:00
|
|
|
#include "ui/gfx/geometry/point.h"
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefMenuRunnerViewsAura::CefMenuRunnerViewsAura() = default;
|
2022-05-13 13:38:41 +02:00
|
|
|
|
|
|
|
bool CefMenuRunnerViewsAura::RunContextMenu(
|
|
|
|
AlloyBrowserHostImpl* browser,
|
|
|
|
CefMenuModelImpl* model,
|
|
|
|
const content::ContextMenuParams& params) {
|
|
|
|
views::Widget* widget = nullptr;
|
|
|
|
gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget;
|
|
|
|
if (browser->IsWindowless()) {
|
|
|
|
parent_widget = browser->GetWindowHandle();
|
|
|
|
if (!parent_widget) {
|
|
|
|
LOG(ERROR) << "Window handle is required for default OSR context menu.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
widget = browser->GetWindowWidget();
|
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
menu_ = std::make_unique<views::MenuRunner>(model->model(),
|
|
|
|
views::MenuRunner::CONTEXT_MENU);
|
2022-05-13 13:38:41 +02:00
|
|
|
|
|
|
|
gfx::Point screen_point = browser->GetScreenPoint(
|
|
|
|
gfx::Point(params.x, params.y), /*want_dip_coords=*/true);
|
|
|
|
|
|
|
|
menu_->RunMenuAt(widget, nullptr, gfx::Rect(screen_point, gfx::Size()),
|
|
|
|
views::MenuAnchorPosition::kTopRight, ui::MENU_SOURCE_NONE,
|
|
|
|
/*native_view_for_gestures=*/nullptr, parent_widget);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefMenuRunnerViewsAura::CancelContextMenu() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (menu_) {
|
2022-05-13 13:38:41 +02:00
|
|
|
menu_->Cancel();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-05-13 13:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefMenuRunnerViewsAura::FormatLabel(std::u16string& label) {
|
|
|
|
// Remove the accelerator indicator (&) from label strings.
|
|
|
|
const std::u16string::value_type replace[] = {u'&', 0};
|
|
|
|
return base::ReplaceChars(label, replace, std::u16string(), &label);
|
|
|
|
}
|