diff --git a/spec/atom-environment-spec.coffee b/spec/atom-environment-spec.coffee index 032349381..5150540bc 100644 --- a/spec/atom-environment-spec.coffee +++ b/spec/atom-environment-spec.coffee @@ -213,7 +213,7 @@ describe "AtomEnvironment", -> describe "::unloadEditorWindow()", -> it "saves the serialized state of the window so it can be deserialized after reload", -> - atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window}) + atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window, document}) spyOn(atomEnvironment, 'saveStateSync') workspaceState = atomEnvironment.workspace.serialize() @@ -231,7 +231,7 @@ describe "AtomEnvironment", -> describe "::destroy()", -> it "unsubscribes from all buffers", -> - atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window}) + atomEnvironment = new AtomEnvironment({applicationDelegate: atom.applicationDelegate, window, document}) waitsForPromise -> atomEnvironment.workspace.open("sample.js") diff --git a/spec/jasmine-test-runner.coffee b/spec/jasmine-test-runner.coffee index 00a2dcdd0..173936133 100644 --- a/spec/jasmine-test-runner.coffee +++ b/spec/jasmine-test-runner.coffee @@ -18,7 +18,7 @@ module.exports = ({logFile, headless, testPaths, buildAtomEnvironment}) -> applicationDelegate = new ApplicationDelegate() applicationDelegate.setRepresentedFilename = -> applicationDelegate.setWindowDocumentEdited = -> - window.atom = buildAtomEnvironment({applicationDelegate, window}) + window.atom = buildAtomEnvironment({applicationDelegate, window, document}) require './spec-helper' disableFocusMethods() if process.env.JANKY_SHA1 or process.env.CI diff --git a/spec/window-event-handler-spec.coffee b/spec/window-event-handler-spec.coffee index 655dc149c..3148942b4 100644 --- a/spec/window-event-handler-spec.coffee +++ b/spec/window-event-handler-spec.coffee @@ -18,7 +18,7 @@ describe "WindowEventHandler", -> loadSettings.initialPath = initialPath loadSettings atom.project.destroy() - windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate, window}) + windowEventHandler = new WindowEventHandler({atomEnvironment: atom, applicationDelegate: atom.applicationDelegate, window, document}) projectPath = atom.project.getPaths()[0] afterEach -> diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index c116f777b..85e54d292 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -101,7 +101,7 @@ class AtomEnvironment extends Model # Call .loadOrCreate instead constructor: (params={}) -> - {@applicationDelegate, @window} = params + {@applicationDelegate, @window, @document} = params @state = {version: @constructor.version} @@ -472,9 +472,9 @@ class AtomEnvironment extends Model setFullScreen: (fullScreen=false) -> @applicationDelegate.setWindowFullScreen(fullScreen) if fullScreen - document.body.classList.add("fullscreen") + @document.body.classList.add("fullscreen") else - document.body.classList.remove("fullscreen") + @document.body.classList.remove("fullscreen") # Extended: Toggle the full screen state of the current window. toggleFullScreen: -> @@ -587,13 +587,13 @@ class AtomEnvironment extends Model @themes.loadBaseStylesheets() @setBodyPlatformClass() - document.head.appendChild(@styles.buildStylesElement()) + @document.head.appendChild(@styles.buildStylesElement()) @packages.loadPackages() workspaceElement = @views.getView(@workspace) @keymaps.defaultTarget = workspaceElement - document.querySelector(@workspaceParentSelectorctor).appendChild(workspaceElement) + @document.querySelector(@workspaceParentSelectorctor).appendChild(workspaceElement) @watchProjectPath() @@ -652,7 +652,7 @@ class AtomEnvironment extends Model window.onerror = @previousWindowErrorHandler installWindowEventHandler: -> - @windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate, @window}) + @windowEventHandler = new WindowEventHandler({atomEnvironment: this, @applicationDelegate, @window, @document}) uninstallWindowEventHandler: -> @windowEventHandler?.unsubscribe() @@ -817,16 +817,16 @@ class AtomEnvironment extends Model @disposables.add(@applicationDelegate.onUpdateAvailable(@updateAvailable.bind(this))) setBodyPlatformClass: -> - document.body.classList.add("platform-#{process.platform}") + @document.body.classList.add("platform-#{process.platform}") setAutoHideMenuBar: (autoHide) -> @applicationDelegate.setAutoHideWindowMenuBar(autoHide) @applicationDelegate.setWindowMenuBarVisibility(not autoHide) dispatchApplicationMenuCommand: (command, arg) -> - activeElement = document.activeElement + activeElement = @document.activeElement # Use the workspace element if body has focus - if activeElement is document.body and workspaceElement = @views.getView(@workspace) + if activeElement is @document.body and workspaceElement = @views.getView(@workspace) activeElement = workspaceElement @commands.dispatch(activeElement, command, arg) diff --git a/src/initialize-application-window.coffee b/src/initialize-application-window.coffee index 71dac6898..44bec588e 100644 --- a/src/initialize-application-window.coffee +++ b/src/initialize-application-window.coffee @@ -16,7 +16,7 @@ process.env.NODE_ENV ?= 'production' unless devMode AtomEnvironment = require './atom-environment' ApplicationDelegate = require './application-delegate' -window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate, window}) +window.atom = new AtomEnvironment({applicationDelegate: new ApplicationDelegate, window, document}) atom.displayWindow() atom.loadStateSync() diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index cf5a957ca..18191ccaa 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -6,7 +6,7 @@ listen = require './delegated-listener' # Handles low-level events related to the @window. module.exports = class WindowEventHandler - constructor: ({@atomEnvironment, @applicationDelegate, @window}) -> + constructor: ({@atomEnvironment, @applicationDelegate, @window, @document}) -> @reloadRequested = false @subscriptions = new CompositeDisposable @@ -15,12 +15,12 @@ class WindowEventHandler @addEventListener(@window, 'focus', @handleWindowFocus) @addEventListener(@window, 'blur', @handleWindowBlur) - @addEventListener(document, 'keydown', @handleDocumentKeydown) - @addEventListener(document, 'drop', @handleDocumentDrop) - @addEventListener(document, 'dragover', @handleDocumentDragover) - @addEventListener(document, 'contextmenu', @handleDocumentContextmenu) - @subscriptions.add listen(document, 'click', 'a', @handleLinkClick) - @subscriptions.add listen(document, 'submit', 'form', @handleFormSubmit) + @addEventListener(@document, 'keydown', @handleDocumentKeydown) + @addEventListener(@document, 'drop', @handleDocumentDrop) + @addEventListener(@document, 'dragover', @handleDocumentDragover) + @addEventListener(@document, 'contextmenu', @handleDocumentContextmenu) + @subscriptions.add listen(@document, 'click', 'a', @handleLinkClick) + @subscriptions.add listen(@document, 'submit', 'form', @handleFormSubmit) @subscriptions.add @atomEnvironment.commands.add @window, 'window:toggle-full-screen': @handleWindowToggleFullScreen @@ -32,7 +32,7 @@ class WindowEventHandler @subscriptions.add @atomEnvironment.commands.add @window, '@window:toggle-menu-bar': @handleWindowToggleMenuBar - @subscriptions.add @atomEnvironment.commands.add document, + @subscriptions.add @atomEnvironment.commands.add @document, 'core:focus-next': @handleFocusNext 'core:focus-previous': @handleFocusPrevious @@ -42,7 +42,7 @@ class WindowEventHandler # `.native-key-bindings` class. handleNativeKeybindings: -> bindCommandToAction = (command, action) => - @addEventListener document, command, (event) => + @addEventListener @document, command, (event) => if event.target.webkitMatchesSelector('.native-key-bindings') @applicationDelegate.getCurrentWindow().webContents[action]() @@ -81,14 +81,14 @@ class WindowEventHandler event.dataTransfer.dropEffect = 'none' eachTabIndexedElement: (callback) -> - for element in document.querySelectorAll('[tabindex]') + for element in @document.querySelectorAll('[tabindex]') continue if element.disabled continue unless element.tabIndex >= 0 callback(element, element.tabIndex) return handleFocusNext: => - focusedTabIndex = document.activeElement.tabIndex ? -Infinity + focusedTabIndex = @document.activeElement.tabIndex ? -Infinity nextElement = null nextTabIndex = Infinity @@ -109,7 +109,7 @@ class WindowEventHandler lowestElement.focus() handleFocusPrevious: => - focusedTabIndex = document.activeElement.tabIndex ? Infinity + focusedTabIndex = @document.activeElement.tabIndex ? Infinity previousElement = null previousTabIndex = -Infinity @@ -130,10 +130,10 @@ class WindowEventHandler highestElement.focus() handleWindowFocus: -> - document.body.classList.remove('is-blurred') + @document.body.classList.remove('is-blurred') handleWindowBlur: => - document.body.classList.add('is-blurred') + @document.body.classList.add('is-blurred') @atomEnvironment.storeDefaultWindowDimensions() handleWindowBeforeunload: =>