The RenderWidgetHostView might not be available when showing menu
This commit is contained in:
parent
bc61f2eafa
commit
d04ae88426
1 changed files with 5 additions and 6 deletions
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
#include "atom/browser/native_window_views.h"
|
#include "atom/browser/native_window_views.h"
|
||||||
#include "atom/browser/unresponsive_suppressor.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"
|
#include "ui/display/screen.h"
|
||||||
|
|
||||||
using views::MenuRunner;
|
using views::MenuRunner;
|
||||||
|
@ -25,19 +26,17 @@ void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item,
|
||||||
NativeWindow* native_window = static_cast<NativeWindow*>(window->window());
|
NativeWindow* native_window = static_cast<NativeWindow*>(window->window());
|
||||||
if (!native_window)
|
if (!native_window)
|
||||||
return;
|
return;
|
||||||
content::WebContents* web_contents = native_window->web_contents();
|
auto* web_contents = native_window->inspectable_web_contents();
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
content::RenderWidgetHostView* view = web_contents->GetRenderWidgetHostView();
|
|
||||||
if (!view)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// (-1, -1) means showing on mouse location.
|
// (-1, -1) means showing on mouse location.
|
||||||
gfx::Point location;
|
gfx::Point location;
|
||||||
if (x == -1 || y == -1) {
|
if (x == -1 || y == -1) {
|
||||||
location = display::Screen::GetScreen()->GetCursorScreenPoint();
|
location = display::Screen::GetScreen()->GetCursorScreenPoint();
|
||||||
} else {
|
} 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);
|
location = gfx::Point(origin.x() + x, origin.y() + y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue