diff --git a/atom/browser/api/atom_api_browser_window.h b/atom/browser/api/atom_api_browser_window.h index 7b1307922cda..5f9610f3a3c2 100644 --- a/atom/browser/api/atom_api_browser_window.h +++ b/atom/browser/api/atom_api_browser_window.h @@ -118,27 +118,4 @@ class BrowserWindow : public TopLevelWindow, } // namespace atom -namespace mate { - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - atom::NativeWindow** out) { - // null would be tranfered to NULL. - if (val->IsNull()) { - *out = NULL; - return true; - } - - atom::api::BrowserWindow* window; - if (!Converter::FromV8(isolate, val, &window)) - return false; - *out = window->window(); - return true; - } -}; - -} // namespace mate - #endif // ATOM_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_ diff --git a/atom/browser/api/atom_api_menu.h b/atom/browser/api/atom_api_menu.h index 2770742ce287..53c7927689a5 100644 --- a/atom/browser/api/atom_api_menu.h +++ b/atom/browser/api/atom_api_menu.h @@ -8,7 +8,7 @@ #include #include -#include "atom/browser/api/atom_api_browser_window.h" +#include "atom/browser/api/atom_api_top_level_window.h" #include "atom/browser/api/trackable_object.h" #include "atom/browser/ui/atom_menu_model.h" #include "base/callback.h" @@ -54,7 +54,7 @@ class Menu : public mate::TrackableObject, void ExecuteCommand(int command_id, int event_flags) override; void MenuWillShow(ui::SimpleMenuModel* source) override; - virtual void PopupAt(BrowserWindow* window, + virtual void PopupAt(TopLevelWindow* window, int x, int y, int positioning_item, diff --git a/atom/browser/api/atom_api_menu_mac.h b/atom/browser/api/atom_api_menu_mac.h index 5b4816ea8462..fb575cfcbaec 100644 --- a/atom/browser/api/atom_api_menu_mac.h +++ b/atom/browser/api/atom_api_menu_mac.h @@ -22,7 +22,7 @@ class MenuMac : public Menu { protected: MenuMac(v8::Isolate* isolate, v8::Local wrapper); - void PopupAt(BrowserWindow* window, + void PopupAt(TopLevelWindow* window, int x, int y, int positioning_item, diff --git a/atom/browser/api/atom_api_menu_mac.mm b/atom/browser/api/atom_api_menu_mac.mm index cc08fa531509..fe077e347608 100644 --- a/atom/browser/api/atom_api_menu_mac.mm +++ b/atom/browser/api/atom_api_menu_mac.mm @@ -9,8 +9,6 @@ #include "base/mac/scoped_sending_event.h" #include "base/message_loop/message_loop.h" #include "base/strings/sys_string_conversions.h" -#include "brightray/browser/inspectable_web_contents.h" -#include "brightray/browser/inspectable_web_contents_view.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" @@ -27,7 +25,7 @@ MenuMac::MenuMac(v8::Isolate* isolate, v8::Local wrapper) weak_factory_(this) { } -void MenuMac::PopupAt(BrowserWindow* window, +void MenuMac::PopupAt(TopLevelWindow* window, int x, int y, int positioning_item, const base::Closure& callback) { NativeWindow* native_window = window->window(); diff --git a/atom/browser/api/atom_api_menu_views.cc b/atom/browser/api/atom_api_menu_views.cc index 52d2fb726c9c..1060964a297b 100644 --- a/atom/browser/api/atom_api_menu_views.cc +++ b/atom/browser/api/atom_api_menu_views.cc @@ -6,8 +6,6 @@ #include "atom/browser/native_window_views.h" #include "atom/browser/unresponsive_suppressor.h" -#include "brightray/browser/inspectable_web_contents.h" -#include "brightray/browser/inspectable_web_contents_view.h" #include "ui/display/screen.h" using views::MenuRunner; @@ -19,7 +17,7 @@ namespace api { MenuViews::MenuViews(v8::Isolate* isolate, v8::Local wrapper) : Menu(isolate, wrapper), weak_factory_(this) {} -void MenuViews::PopupAt(BrowserWindow* window, +void MenuViews::PopupAt(TopLevelWindow* window, int x, int y, int positioning_item, diff --git a/atom/browser/api/atom_api_menu_views.h b/atom/browser/api/atom_api_menu_views.h index 31d7d48db8e4..e5b93a3cfa0b 100644 --- a/atom/browser/api/atom_api_menu_views.h +++ b/atom/browser/api/atom_api_menu_views.h @@ -21,7 +21,7 @@ class MenuViews : public Menu { MenuViews(v8::Isolate* isolate, v8::Local wrapper); protected: - void PopupAt(BrowserWindow* window, + void PopupAt(TopLevelWindow* window, int x, int y, int positioning_item, diff --git a/atom/browser/api/atom_api_top_level_window.cc b/atom/browser/api/atom_api_top_level_window.cc index 0ee8c228ed2f..87cc03540edd 100644 --- a/atom/browser/api/atom_api_top_level_window.cc +++ b/atom/browser/api/atom_api_top_level_window.cc @@ -9,6 +9,7 @@ #include "atom/browser/api/atom_api_browser_view.h" #include "atom/browser/api/atom_api_menu.h" +#include "atom/browser/api/atom_api_web_contents.h" #include "atom/common/color_util.h" #include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/file_path_converter.h" diff --git a/atom/browser/api/atom_api_top_level_window.h b/atom/browser/api/atom_api_top_level_window.h index 2022bca62840..caba53c0e0f0 100644 --- a/atom/browser/api/atom_api_top_level_window.h +++ b/atom/browser/api/atom_api_top_level_window.h @@ -229,4 +229,27 @@ class TopLevelWindow : public mate::TrackableObject, } // namespace atom +namespace mate { + +template<> +struct Converter { + static bool FromV8(v8::Isolate* isolate, + v8::Local val, + atom::NativeWindow** out) { + // null would be tranfered to NULL. + if (val->IsNull()) { + *out = NULL; + return true; + } + + atom::api::TopLevelWindow* window; + if (!Converter::FromV8(isolate, val, &window)) + return false; + *out = window->window(); + return true; + } +}; + +} // namespace mate + #endif // ATOM_BROWSER_API_ATOM_API_TOP_LEVEL_WINDOW_H_ diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index eab8184efe6c..ddce950290fd 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -1,6 +1,6 @@ 'use strict' -const {BrowserWindow, MenuItem, webContents} = require('electron') +const {TopLevelWindow, MenuItem, webContents} = require('electron') const EventEmitter = require('events').EventEmitter const v8Util = process.atomBinding('v8_util') const bindings = process.atomBinding('menu') @@ -26,7 +26,7 @@ const delegate = { executeCommand: (menu, event, id) => { const command = menu.commandsMap[id] if (!command) return - command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents()) + command.click(event, TopLevelWindow.getFocusedWindow(), webContents.getFocusedWebContents()) }, menuWillShow: (menu) => { // Ensure radio groups have at least one menu item seleted @@ -61,14 +61,14 @@ Menu.prototype.popup = function (options) { if (typeof positioningItem !== 'number') positioningItem = -1 // find which window to use - const wins = BrowserWindow.getAllWindows() + const wins = TopLevelWindow.getAllWindows() if (!wins || wins.indexOf(window) === -1) { - window = BrowserWindow.getFocusedWindow() + window = TopLevelWindow.getFocusedWindow() if (!window && wins && wins.length > 0) { window = wins[0] } if (!window) { - throw new Error(`Cannot open Menu without a BrowserWindow present`) + throw new Error(`Cannot open Menu without a TopLevelWindow present`) } } @@ -77,7 +77,7 @@ Menu.prototype.popup = function (options) { } Menu.prototype.closePopup = function (window) { - if (window && window.constructor !== BrowserWindow) { + if (window instanceof TopLevelWindow) { this.closePopupAt(window.id) } else { // Passing -1 (invalid) would make closePopupAt close the all menu runners @@ -148,7 +148,7 @@ Menu.setApplicationMenu = function (menu) { menu._callMenuWillShow() bindings.setApplicationMenu(menu) } else { - const windows = BrowserWindow.getAllWindows() + const windows = TopLevelWindow.getAllWindows() return windows.map(w => w.setMenu(menu)) } } diff --git a/lib/browser/api/top-level-window.js b/lib/browser/api/top-level-window.js index 9745fec9b74b..d798314e96fd 100644 --- a/lib/browser/api/top-level-window.js +++ b/lib/browser/api/top-level-window.js @@ -17,4 +17,8 @@ TopLevelWindow.prototype._init = function () { } } +TopLevelWindow.getFocusedWindow = () => { + return TopLevelWindow.getAllWindows().find((win) => win.isFocused()) +} + module.exports = TopLevelWindow