• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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/views/menu_runner_views.h"
6 
7 #include "libcef/browser/alloy/alloy_browser_host_impl.h"
8 #include "libcef/browser/views/browser_view_impl.h"
9 
CefMenuRunnerViews(CefBrowserViewImpl * browser_view)10 CefMenuRunnerViews::CefMenuRunnerViews(CefBrowserViewImpl* browser_view)
11     : browser_view_(browser_view) {}
12 
RunContextMenu(AlloyBrowserHostImpl * browser,CefMenuModelImpl * model,const content::ContextMenuParams & params)13 bool CefMenuRunnerViews::RunContextMenu(
14     AlloyBrowserHostImpl* browser,
15     CefMenuModelImpl* model,
16     const content::ContextMenuParams& params) {
17   CefRefPtr<CefWindow> window = browser_view_->GetWindow();
18   if (!window)
19     return false;
20 
21   CefPoint screen_point(params.x, params.y);
22   browser_view_->ConvertPointToScreen(screen_point);
23 
24   window->ShowMenu(model, screen_point, CEF_MENU_ANCHOR_TOPRIGHT);
25   return true;
26 }
27 
CancelContextMenu()28 void CefMenuRunnerViews::CancelContextMenu() {
29   CefRefPtr<CefWindow> window = browser_view_->GetWindow();
30   if (window)
31     window->CancelMenu();
32 }
33 
FormatLabel(std::u16string & label)34 bool CefMenuRunnerViews::FormatLabel(std::u16string& label) {
35   // Remove the accelerator indicator (&) from label strings.
36   const std::u16string::value_type replace[] = {L'&', 0};
37   return base::ReplaceChars(label, replace, std::u16string(), &label);
38 }
39