From d04ae8842664ef66ce6508219ef52c329830c4bb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 1 Jan 2018 19:33:08 +0900 Subject: [PATCH] The RenderWidgetHostView might not be available when showing menu --- atom/browser/api/atom_api_menu_views.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/atom_api_menu_views.cc b/atom/browser/api/atom_api_menu_views.cc index 6bfc850e45f5..ced1cb31d8df 100644 --- a/atom/browser/api/atom_api_menu_views.cc +++ b/atom/browser/api/atom_api_menu_views.cc @@ -6,7 +6,8 @@ #include "atom/browser/native_window_views.h" #include "atom/browser/unresponsive_suppressor.h" -#include "content/public/browser/render_widget_host_view.h" +#include "brightray/browser/inspectable_web_contents.h" +#include "brightray/browser/inspectable_web_contents_view.h" #include "ui/display/screen.h" using views::MenuRunner; @@ -25,19 +26,17 @@ void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item, NativeWindow* native_window = static_cast(window->window()); if (!native_window) return; - content::WebContents* web_contents = native_window->web_contents(); + auto* web_contents = native_window->inspectable_web_contents(); if (!web_contents) return; - content::RenderWidgetHostView* view = web_contents->GetRenderWidgetHostView(); - if (!view) - return; // (-1, -1) means showing on mouse location. gfx::Point location; if (x == -1 || y == -1) { location = display::Screen::GetScreen()->GetCursorScreenPoint(); } else { - gfx::Point origin = view->GetViewBounds().origin(); + auto* view = web_contents->GetView()->GetWebView(); + gfx::Point origin = view->bounds().origin(); location = gfx::Point(origin.x() + x, origin.y() + y); }