Parameterize document on AtomEnvironment

This commit is contained in:
Nathan Sobo 2015-10-13 19:47:12 -06:00
parent 5941d9464a
commit 903ecca1f7
6 changed files with 28 additions and 28 deletions

View File

@ -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")

View File

@ -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

View File

@ -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 ->

View File

@ -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)

View File

@ -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()

View File

@ -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: =>