Skip to content

Commit

Permalink
Modify to create a Screen object for each window
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed May 7, 2018
1 parent f9f209b commit a47b59d
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 79 deletions.
2 changes: 1 addition & 1 deletion docs/Browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2018/05/05 19:03:05
on 2018/05/07 23:55:19

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/Screen.html
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2018/05/05 19:03:05
on 2018/05/07 23:55:20

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/ScreenConfig.html
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2018/05/05 19:03:05
on 2018/05/07 23:55:20

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/Window.html
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2018/05/05 19:03:05
on 2018/05/07 23:55:20

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/WindowConfig.html
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2018/05/05 19:03:05
on 2018/05/07 23:55:20

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/classes.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2018/05/05 19:03:05
on 2018/05/07 23:55:19

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ <h4 class="modal-title">Search results</h4>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>

on 2018/05/05 19:03:05
on 2018/05/07 23:55:19

using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/quicksearch.html

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const ContentManager = require('./window/content')
const WindowConfig = require('./window/config')
const { newWindow, openWindow } = require('./window/opening')
const ScreenConfig = require('./screen/config')
const Screen = require('./screen')
const BrowserOptions = require('./options')
const defaultConfig = require('./default')

class Browser {

constructor (browserConfig) {
const { windowConfig, screenConfig, options } = newConfig(browserConfig)

this.windowConfig = windowConfig
this.screenConfig = screenConfig
this.options = options
Expand Down Expand Up @@ -62,9 +62,8 @@ function newConfig (browserConfig) {
}

const screenConfig = new ScreenConfig(config.screenConfig)
const screen = new Screen(screenConfig)

config.windowConfig.screen = screen
config.windowConfig.screenConfig = screenConfig
const windowConfig = new WindowConfig(config.windowConfig)

const options = new BrowserOptions(config.options)
Expand Down
5 changes: 4 additions & 1 deletion src/window/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { readonly, writable, replaceable, method } = ConfigBase
const defaultConfig = require('./default')
const defaultNumber = require('default-number')
const { EventEmitter } = require('events')
const Screen = require('../screen')

class WindowConfig extends ConfigBase {

Expand All @@ -23,8 +24,10 @@ class WindowConfig extends ConfigBase {
}

defineAccessors () {
this.$private.screen = new Screen(this.$private.screenConfig)

return {
screen: (p, key) => readonly({
screenConfig: (p, key) => readonly({
get: () => p[key]
}),

Expand Down
3 changes: 1 addition & 2 deletions src/window/default.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict'

const ScreenConfig = require('../screen/config')
const Screen = require('../screen')

module.exports = {
screen: new Screen(new ScreenConfig()),
screenConfig: new ScreenConfig(),

top: 0,
left: 0,
Expand Down
5 changes: 3 additions & 2 deletions test/unit/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ describe('browser', () => {
const screen0 = window0.screen
const screen1 = window1.screen

expect(window0).not.equal(window1)
expect(screen0).to.equal(screen1)
expect(window0).to.not.equal(window1)
expect(screen0).to.not.equal(screen1)

const windowConfig0 = browser.getConfig(window0)
const windowConfig1 = browser.getConfig(window1)
Expand All @@ -181,6 +181,7 @@ describe('browser', () => {
expect(window1.outerWidth).to.equal(1500)

screenConfig0.width = 3000
expect(screenConfig0.width).to.equal(3000)
expect(screenConfig1.width).to.equal(3000)
expect(screen0.width).to.equal(3000)
expect(screen1.width).to.equal(3000)
Expand Down
79 changes: 36 additions & 43 deletions test/unit/window/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
const expect = require('chai').expect
const WindowConfig = require('../../../src/window/config')
const ScreenConfig = require('../../../src/screen/config')
const Screen = require('../../../src/screen')

describe('window/config', () => {

describe('constructor', () => {

it('Should create WindowConfig object with no argument', () => {
const windowConfig = new WindowConfig()
expect(windowConfig.screen).to.be.an.instanceof(Screen)
expect(windowConfig.screenConfig).to.be.an.instanceof(ScreenConfig)
expect(windowConfig.top).to.equal(0)
expect(windowConfig.left).to.equal(0)
expect(windowConfig.width).to.equal(1024)
Expand Down Expand Up @@ -69,10 +68,8 @@ describe('window/config', () => {
screenConfig.availRight = 0
screenConfig.availBottom = 0

const screen = new Screen(screenConfig)

const windowConfig = new WindowConfig({
screen, left: 10, top: 20, width: 500, height: 400,
screenConfig, left: 10, top: 20, width: 500, height: 400,
frame: {
edgeSize: { top: 11, left: 3, right: 4, bottom: 39 },
minSize: { width: 30, height: 50 },
Expand All @@ -91,13 +88,13 @@ describe('window/config', () => {
closed: true, isFrameWindow: true,
})

expect(windowConfig.screen).to.equal(screen)
expect(windowConfig.screen.width).to.equal(1280)
expect(windowConfig.screen.height).to.equal(1024)
expect(windowConfig.screen.availWidth).to.equal(1280)
expect(windowConfig.screen.availHeight).to.equal(1001)
expect(windowConfig.screen.availLeft).to.equal(0)
expect(windowConfig.screen.availTop).to.equal(23)
expect(windowConfig.screenConfig).to.equal(screenConfig)
expect(windowConfig.screenConfig.width).to.equal(1280)
expect(windowConfig.screenConfig.height).to.equal(1024)
expect(windowConfig.screenConfig.availTop).to.equal(23)
expect(windowConfig.screenConfig.availLeft).to.equal(0)
expect(windowConfig.screenConfig.availRight).to.equal(0)
expect(windowConfig.screenConfig.availBottom).to.equal(0)

expect(windowConfig.top).to.equal(20)
expect(windowConfig.left).to.equal(10)
Expand Down Expand Up @@ -171,10 +168,8 @@ describe('window/config', () => {
screenConfig.availRight = 0
screenConfig.availBottom = 0

const screen = new Screen(screenConfig)

const windowConfig0 = new WindowConfig({
screen, left: 10, top: 20, width: 500, height: 400,
screenConfig, left: 10, top: 20, width: 500, height: 400,
frame: {
edgeSize: { top: 11, left: 3, right: 4, bottom: 39 },
minSize: { width: 30, height: 50 },
Expand All @@ -195,13 +190,13 @@ describe('window/config', () => {

const windowConfig = new WindowConfig(windowConfig0)

expect(windowConfig.screen).to.equal(screen)
expect(windowConfig.screen.width).to.equal(1280)
expect(windowConfig.screen.height).to.equal(1024)
expect(windowConfig.screen.availWidth).to.equal(1280)
expect(windowConfig.screen.availHeight).to.equal(1001)
expect(windowConfig.screen.availLeft).to.equal(0)
expect(windowConfig.screen.availTop).to.equal(23)
expect(windowConfig.screenConfig).to.equal(screenConfig)
expect(windowConfig.screenConfig.width).to.equal(1280)
expect(windowConfig.screenConfig.height).to.equal(1024)
expect(windowConfig.screenConfig.availTop).to.equal(23)
expect(windowConfig.screenConfig.availLeft).to.equal(0)
expect(windowConfig.screenConfig.availRight).to.equal(0)
expect(windowConfig.screenConfig.availBottom).to.equal(0)

expect(windowConfig.top).to.equal(20)
expect(windowConfig.left).to.equal(10)
Expand Down Expand Up @@ -269,16 +264,15 @@ describe('window/config', () => {

describe('property accessors', () => {
const screenConfig = new ScreenConfig()
const screen = new Screen(screenConfig)
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })

it('Should not change .screen', () => {
const screen2 = new Screen(screenConfig)
expect(screen2).not.to.equal(screen)
it('Should not change .screenConfig', () => {
const screenConfig2 = new ScreenConfig()
expect(screenConfig2).not.to.equal(screenConfig)

windowConfig.screen = screen2
expect(windowConfig.screen).to.equal(screen)
expect(windowConfig.screen).not.to.equal(screen2)
windowConfig.screenConfig = screenConfig2
expect(windowConfig.screenConfig).to.equal(screenConfig)
expect(windowConfig.screenConfig).not.to.equal(screenConfig2)
})

it('Should change .top/.left/.width/.height', () => {
Expand Down Expand Up @@ -413,10 +407,9 @@ describe('window/config', () => {

describe('property restrictions', () => {
const screenConfig = new ScreenConfig()
const screen = new Screen(screenConfig)

it('Should use .frame.edgeSize.* when .isFrameWindow is true', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
expect(windowConfig.isFrameWindow).to.be.true

expect(windowConfig.edgeSize.width).to.equal(0)
Expand Down Expand Up @@ -502,7 +495,7 @@ describe('window/config', () => {
})

it('Should use .frame.minSize.* when .isFrameWindow is true', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
expect(windowConfig.isFrameWindow).to.be.true

expect(windowConfig.minSize.width).to.equal(0)
Expand Down Expand Up @@ -545,7 +538,7 @@ describe('window/config', () => {

it('Should use .frame.minOpeningSize.* when .isFrameWindow is true' +
'', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
expect(windowConfig.isFrameWindow).to.be.true

expect(windowConfig.minOpeningSize.width).to.equal(0)
Expand Down Expand Up @@ -588,7 +581,7 @@ describe('window/config', () => {

it('Should use .frame.minResizableSize.* when .isFrameWindow is true' +
'', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
expect(windowConfig.isFrameWindow).to.be.true

expect(windowConfig.minResizableSize.width).to.equal(0)
Expand Down Expand Up @@ -630,7 +623,7 @@ describe('window/config', () => {
})

it('Should use .frame.openingShift.* when .isFrameWindow is true', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
expect(windowConfig.isFrameWindow).to.be.true

expect(windowConfig.openingShift.x).to.equal(0)
Expand Down Expand Up @@ -673,7 +666,7 @@ describe('window/config', () => {
})

it('Should use .popup.edgeSize.* when .isFrameWindow is true', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
windowConfig.isFrameWindow = false
expect(windowConfig.isFrameWindow).to.be.false

Expand Down Expand Up @@ -760,7 +753,7 @@ describe('window/config', () => {
})

it('Should use .popup.minSize.* when .isFrameWindow is true', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
windowConfig.isFrameWindow = false
expect(windowConfig.isFrameWindow).to.be.false

Expand Down Expand Up @@ -804,7 +797,7 @@ describe('window/config', () => {

it('Should use .popup.minOpeningSize.* when .isFrameWindow is true' +
'', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
windowConfig.isFrameWindow = false
expect(windowConfig.isFrameWindow).to.be.false

Expand Down Expand Up @@ -848,7 +841,7 @@ describe('window/config', () => {

it('Should use .popup.minResizableSize.* when .isFrameWindow is true' +
'', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
windowConfig.isFrameWindow = false
expect(windowConfig.isFrameWindow).to.be.false

Expand Down Expand Up @@ -891,7 +884,7 @@ describe('window/config', () => {
})

it('Should use .popup.openingShift.* when .isFrameWindow is true', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })
windowConfig.isFrameWindow = false
expect(windowConfig.isFrameWindow).to.be.false

Expand Down Expand Up @@ -934,7 +927,7 @@ describe('window/config', () => {
})

it('Should limit .width/.height with .minSize', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })

expect(windowConfig.minSize.width).to.equal(0)
expect(windowConfig.minSize.height).to.equal(0)
Expand Down Expand Up @@ -967,7 +960,7 @@ describe('window/config', () => {
})

it('Should limit .zoom with .minZoom and .maxZoom', () => {
const windowConfig = new WindowConfig({ screen })
const windowConfig = new WindowConfig({ screenConfig })

expect(windowConfig.zoom).to.equal(1)
expect(windowConfig.minZoom).to.equal(0.25)
Expand Down
Loading

0 comments on commit a47b59d

Please sign in to comment.