diff --git a/app/renderer/components/bookmarks/bookmarksToolbar.js b/app/renderer/components/bookmarks/bookmarksToolbar.js
index 4fae66b055f..071df7557d2 100644
--- a/app/renderer/components/bookmarks/bookmarksToolbar.js
+++ b/app/renderer/components/bookmarks/bookmarksToolbar.js
@@ -154,7 +154,7 @@ class BookmarksToolbar extends React.Component {
// used in renderer
props.showOnlyFavicon = bookmarkUtil.showOnlyFavicon()
props.showFavicon = bookmarkUtil.showFavicon()
- props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused()) &&
+ props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused(state)) &&
!isWindows
props.visibleBookmarks = bookmarks.visibleBookmarks
props.hiddenBookmarks = bookmarks.hiddenBookmarks
diff --git a/app/renderer/components/frame/frame.js b/app/renderer/components/frame/frame.js
index 26be02a572e..4cdf39333c5 100644
--- a/app/renderer/components/frame/frame.js
+++ b/app/renderer/components/frame/frame.js
@@ -182,7 +182,7 @@ class Frame extends React.Component {
}
onPropsChanged (prevProps = {}) {
- if (this.props.isActive && !prevProps.isActive && isFocused()) {
+ if (this.props.isActive && !prevProps.isActive && this.props.isFocused) {
windowActions.setFocusedFrame(this.props.location, this.props.tabId)
}
}
@@ -885,6 +885,7 @@ class Frame extends React.Component {
props.location = location
props.tabId = tabId
props.showMessageBox = tabMessageBoxState.hasMessageBoxDetail(state, tabId)
+ props.isFocused = isFocused(state)
// used in other functions
props.frameKey = ownProps.frameKey
diff --git a/app/renderer/components/main/main.js b/app/renderer/components/main/main.js
index 14294044d7d..f18190e3fca 100644
--- a/app/renderer/components/main/main.js
+++ b/app/renderer/components/main/main.js
@@ -530,11 +530,12 @@ class Main extends React.Component {
const activeOrigin = !activeFrame.isEmpty() ? urlUtil.getOrigin(activeFrame.get('location')) : null
const widevinePanelDetail = currentWindow.get('widevinePanelDetail', Immutable.Map())
const loginRequiredDetails = basicAuthState.getLoginRequiredDetail(state, activeTabId)
+ const focused = isFocused(state)
const props = {}
// used in renderer
props.isFullScreen = activeFrame.get('isFullScreen', false)
- props.isMaximized = isMaximized() || isFullScreen()
+ props.isMaximized = isMaximized(state) || isFullScreen(state)
props.captionButtonsVisible = isWindows
props.showContextMenu = currentWindow.has('contextMenuDetail')
props.showPopupWindow = currentWindow.has('popupWindowDetail')
@@ -554,10 +555,10 @@ class Main extends React.Component {
props.showNoScript = currentWindow.getIn(['ui', 'noScriptInfo', 'isVisible']) &&
urlUtil.getOrigin(activeFrame.get('location'))
props.showReleaseNotes = currentWindow.getIn(['ui', 'releaseNotes', 'isVisible'])
- props.showCheckDefault = isFocused() && defaultBrowserState.shouldDisplayDialog(state)
+ props.showCheckDefault = focused && defaultBrowserState.shouldDisplayDialog(state)
props.showUpdate = updateState.isUpdateVisible(state)
props.showBookmarksToolbar = getSetting(settings.SHOW_BOOKMARKS_TOOLBAR)
- props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused())
+ props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, focused)
props.isSinglePage = nonPinnedFrames.size <= tabsPerPage
props.showTabPages = nonPinnedFrames.size > tabsPerPage
props.showNotificationBar = activeOrigin && state.get('notifications').filter((item) =>
diff --git a/app/renderer/components/navigation/buttons/windowCaptionButtons.js b/app/renderer/components/navigation/buttons/windowCaptionButtons.js
index 1f00573010f..20cf075214e 100644
--- a/app/renderer/components/navigation/buttons/windowCaptionButtons.js
+++ b/app/renderer/components/navigation/buttons/windowCaptionButtons.js
@@ -13,7 +13,7 @@ const windowActions = require('../../../../../js/actions/windowActions')
// Utils
const locale = require('../../../../../js/l10n')
-const {getCurrentWindowId, isMaximized, isFullScreen} = require('../../../currentWindow')
+const {getCurrentWindowId} = require('../../../currentWindow')
const cx = require('../../../../../js/lib/classSet')
class WindowCaptionButtons extends ImmutableComponent {
@@ -26,26 +26,27 @@ class WindowCaptionButtons extends ImmutableComponent {
}
get maximizeTitle () {
- return this.props.windowMaximized
+ return this.props.windowMaximizedFullScreen
? 'windowCaptionButtonRestore'
: 'windowCaptionButtonMaximize'
}
- onMinimizeClick (e) {
+ onMinimizeClick () {
windowActions.shouldMinimize(getCurrentWindowId())
}
- onMaximizeClick (e) {
- if (isFullScreen()) {
+ onMaximizeClick () {
+ const currentWindowId = getCurrentWindowId()
+ if (this.props.windowFullScreen) {
// If full screen, toggle full screen status and restore window (make smaller)
- windowActions.shouldExitFullScreen(getCurrentWindowId())
- if (isMaximized()) windowActions.shouldUnmaximize(getCurrentWindowId())
+ windowActions.shouldExitFullScreen(currentWindowId)
+ if (this.props.windowMaximized) windowActions.shouldUnmaximize(currentWindowId)
return false
}
- return (!isMaximized()) ? windowActions.shouldMaximize(getCurrentWindowId()) : windowActions.shouldUnmaximize(getCurrentWindowId())
+ return (!this.props.windowMaximized) ? windowActions.shouldMaximize(currentWindowId) : windowActions.shouldUnmaximize(currentWindowId)
}
- onCloseClick (e) {
+ onCloseClick () {
appActions.closeWindow(getCurrentWindowId())
}
@@ -60,7 +61,7 @@ class WindowCaptionButtons extends ImmutableComponent {
const props = { tabIndex: -1 }
return
@@ -69,7 +70,7 @@ class WindowCaptionButtons extends ImmutableComponent {
{...props}
className={cx({
normalizeButton: true,
- fullscreen: this.props.windowMaximized,
+ fullscreen: this.props.windowMaximizedFullScreen,
captionButton: true,
minimize: true
})}
@@ -81,7 +82,7 @@ class WindowCaptionButtons extends ImmutableComponent {
{...props}
className={cx({
normalizeButton: true,
- fullscreen: this.props.windowMaximized,
+ fullscreen: this.props.windowMaximizedFullScreen,
captionButton: true,
maximize: true
})}
@@ -97,7 +98,7 @@ class WindowCaptionButtons extends ImmutableComponent {
{...props}
className={cx({
normalizeButton: true,
- fullscreen: this.props.windowMaximized,
+ fullscreen: this.props.windowMaximizedFullScreen,
captionButton: true,
close: true
})}
diff --git a/app/renderer/components/navigation/navigator.js b/app/renderer/components/navigation/navigator.js
index 1bf9ed95895..e5559488bd8 100644
--- a/app/renderer/components/navigation/navigator.js
+++ b/app/renderer/components/navigation/navigator.js
@@ -116,6 +116,8 @@ class Navigator extends React.Component {
})
.filter((browserAction) => browserAction)
.toList()
+ const fullScreen = isFullScreen(state)
+ const maximized = isMaximized(state)
const props = {}
// used in renderer
@@ -123,14 +125,16 @@ class Navigator extends React.Component {
props.shieldsDown = !braverySettings.shieldsUp
props.shieldEnabled = braveShieldsEnabled(activeFrame)
props.menuBarVisible = menuBarState.isMenuBarVisible(currentWindow)
- props.isMaximized = isMaximized() || isFullScreen()
+ props.isMaximizedFullScreen = maximized || fullScreen
+ props.isMaximized = maximized
+ props.isFullScreen = fullScreen
props.isCaptionButton = isWindows && !props.menuBarVisible
props.activeTabShowingMessageBox = activeTabShowingMessageBox
props.extensionBrowserActions = extensionBrowserActions
props.showBrowserActions = !activeTabShowingMessageBox &&
extensionBrowserActions &&
extensionBrowserActions.size > 0
- props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused())
+ props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused(state))
props.isCounterEnabled = getSetting(settings.BLOCKED_COUNT_BADGE) &&
props.totalBlocks &&
props.shieldEnabled
@@ -154,7 +158,11 @@ class Navigator extends React.Component {
this.props.menuBarVisible
?
-
+
: null
}
@@ -165,7 +173,7 @@ class Navigator extends React.Component {
>
@@ -228,7 +236,12 @@ class Navigator extends React.Component {
{
this.props.isCaptionButton
- ?
+ ?
: null
}
diff --git a/app/renderer/components/tabs/tabs.js b/app/renderer/components/tabs/tabs.js
index dce931ee2da..09b138aae54 100644
--- a/app/renderer/components/tabs/tabs.js
+++ b/app/renderer/components/tabs/tabs.js
@@ -147,7 +147,7 @@ class Tabs extends React.Component {
props.partOfFullPageSet = currentTabs.size === tabsPerTabPage
props.onNextPage = currentTabs.size >= tabsPerTabPage && totalPages > pageIndex + 1
props.onPreviousPage = pageIndex > 0
- props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused())
+ props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused(state))
// used in other functions
props.fixTabWidth = currentWindow.getIn(['ui', 'tabs', 'fixTabWidth'])
diff --git a/app/renderer/currentWindow.js b/app/renderer/currentWindow.js
index 25cf4760e02..5231fbb8757 100644
--- a/app/renderer/currentWindow.js
+++ b/app/renderer/currentWindow.js
@@ -1,21 +1,23 @@
-const appStoreRenderer = require('../../js/stores/appStoreRenderer')
-const windowState = require('../common/state/windowState')
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+const windowState = require('../common/state/windowState')
let currentWindowId = -1
let currentWindow = null
-const isMaximized = () => {
- const win = windowState.getByWindowId(appStoreRenderer.state, currentWindowId)
- return win && win.get('state') === 'maximized'
+const isMaximized = (state) => {
+ const win = windowState.getByWindowId(state, currentWindowId)
+ return (win && win.get('state') === 'maximized') || false
}
-const isFullScreen = () => {
- const win = windowState.getByWindowId(appStoreRenderer.state, currentWindowId)
- return win && win.get('state') === 'fullscreen'
+const isFullScreen = (state) => {
+ const win = windowState.getByWindowId(state, currentWindowId)
+ return (win && win.get('state') === 'fullscreen') || false
}
-const isFocused = () => {
- const win = windowState.getByWindowId(appStoreRenderer.state, currentWindowId)
+const isFocused = (state) => {
+ const win = windowState.getByWindowId(state, currentWindowId)
return (win && win.get('focused')) || false
}
diff --git a/test/unit/app/renderer/currentWindowTest.js b/test/unit/app/renderer/currentWindowTest.js
new file mode 100644
index 00000000000..ae5da95f8ee
--- /dev/null
+++ b/test/unit/app/renderer/currentWindowTest.js
@@ -0,0 +1,85 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* global describe, it, before */
+const Immutable = require('immutable')
+const assert = require('assert')
+const currentWindow = require('../../../../app/renderer/currentWindow')
+
+describe('currentWindow unit test', function () {
+ const windowId = 1
+ const state = Immutable.fromJS({
+ windows: [
+ {
+ windowId: windowId
+ }
+ ]
+ })
+
+ before(function () {
+ currentWindow.setWindowId(windowId)
+ })
+
+ describe('isMaximized', function () {
+ it('null case', function () {
+ const result = currentWindow.isMaximized(state, 2)
+ assert.equal(result, false)
+ })
+
+ it('false case', function () {
+ const newState = state.setIn(['windows', 0, 'state'], 'test')
+ const result = currentWindow.isMaximized(newState, windowId)
+ assert.equal(result, false)
+ })
+
+ it('true case', function () {
+ const newState = state.setIn(['windows', 0, 'state'], 'maximized')
+ const result = currentWindow.isMaximized(newState, windowId)
+ assert.equal(result, true)
+ })
+ })
+
+ describe('isFullScreen', function () {
+ it('null case', function () {
+ const result = currentWindow.isFullScreen(state, 2)
+ assert.equal(result, false)
+ })
+
+ it('false case', function () {
+ const newState = state.setIn(['windows', 0, 'state'], 'test')
+ const result = currentWindow.isFullScreen(newState, windowId)
+ assert.equal(result, false)
+ })
+
+ it('true case', function () {
+ const newState = state.setIn(['windows', 0, 'state'], 'fullscreen')
+ const result = currentWindow.isFullScreen(newState, windowId)
+ assert.equal(result, true)
+ })
+ })
+
+ describe('isFocused', function () {
+ it('null case', function () {
+ const result = currentWindow.isFocused(state, 2)
+ assert.equal(result, false)
+ })
+
+ it('not provided', function () {
+ const result = currentWindow.isFocused(state, windowId)
+ assert.equal(result, false)
+ })
+
+ it('false case', function () {
+ const newState = state.setIn(['windows', 0, 'focused'], false)
+ const result = currentWindow.isFocused(newState, windowId)
+ assert.equal(result, false)
+ })
+
+ it('true case', function () {
+ const newState = state.setIn(['windows', 0, 'focused'], true)
+ const result = currentWindow.isFocused(newState, windowId)
+ assert.equal(result, true)
+ })
+ })
+})