views: Show menu on window's content view

This commit is contained in:
Cheng Zhao 2018-03-06 16:00:18 +09:00
Родитель 9c7854aef6
Коммит 413fdc6f0d
1 изменённых файлов: 3 добавлений и 6 удалений

Просмотреть файл

@ -24,19 +24,16 @@ MenuViews::MenuViews(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
void MenuViews::PopupAt(BrowserWindow* window,
int x, int y, int positioning_item,
const base::Closure& callback) {
NativeWindow* native_window = static_cast<NativeWindow*>(window->window());
auto* native_window = static_cast<NativeWindowViews*>(window->window());
if (!native_window)
return;
auto* web_contents = native_window->inspectable_web_contents();
if (!web_contents)
return;
// (-1, -1) means showing on mouse location.
gfx::Point location;
if (x == -1 || y == -1) {
location = display::Screen::GetScreen()->GetCursorScreenPoint();
} else {
auto* view = web_contents->GetView()->GetWebView();
views::View* view = native_window; // the instance is also its content view
gfx::Point origin = view->bounds().origin();
location = gfx::Point(origin.x() + x, origin.y() + y);
}
@ -53,7 +50,7 @@ void MenuViews::PopupAt(BrowserWindow* window,
menu_runners_[window_id] = std::unique_ptr<MenuRunner>(new MenuRunner(
model(), flags, close_callback));
menu_runners_[window_id]->RunMenuAt(
static_cast<NativeWindowViews*>(window->window())->widget(),
native_window->widget(),
NULL,
gfx::Rect(location, gfx::Size()),
views::MENU_ANCHOR_TOPLEFT,