Skip to content

Commit

Permalink
Saves computed styles in the state
Browse files Browse the repository at this point in the history
Resolves brave#9149

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed May 30, 2017
1 parent 033b122 commit 0d4a6ba
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/browser/reducers/windowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const windowsReducer = (state, action, immutableAction) => {
case windowConstants.WINDOW_SHOULD_OPEN_DEV_TOOLS:
windows.openDevTools(action.get('windowId'))
break
case appConstants.APP_WINDOW_COMPUTED_STYLES:
state = windowState.updateComputedStyles(state, action)
break
}
return state
}
Expand Down
35 changes: 35 additions & 0 deletions app/common/constants/computedStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* 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 computedStyles = {
'bookmark-item': [
'max-width',
'padding',
'margin',
'font-size'
],
'bookmark-item-chevron': [
'margin'
],
'bookmarks-toolbar': [
'padding'
],
'default': [
'font-family'
],
'download-bar': [
'buttons',
'height',
'padding'
],
'download-item': [
'margin',
'width'
],
'navbar': [
'height'
]
}

module.exports = computedStyles
7 changes: 7 additions & 0 deletions app/common/state/windowState.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ const api = {
return state.set('windows', windows.delete(index).insert(index, windowValue))
},

updateComputedStyles: (state, action) => {
const windowIndex = api.getWindowIndexByWindowId(state, action.get('windowId'))
return state.mergeIn(['windows', windowIndex], {
computedStyles: action.get('values')
})
},

getWindows: (state) => {
state = validateState(state)
return state.get('windows')
Expand Down
4 changes: 4 additions & 0 deletions app/renderer/components/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class Window extends React.Component {

componentDidMount () {
appActions.windowReady(getCurrentWindowId())

const root = window.getComputedStyle(document.querySelector(':root'))
const maxWidth = Number.parseInt(root.getPropertyValue('--bookmark-item-max-width'), 10)
appActions.updateComputedStyles(getCurrentWindowId(), maxWidth)
}

componentWillUnmount () {
Expand Down
8 changes: 8 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,14 @@ const appActions = {
dispatch({
actionType: appConstants.APP_UPDATE_LOG_OPENED
})
},

updateComputedStyles: function (windowId, values) {
dispatch({
actionType: appConstants.APP_WINDOW_COMPUTED_STYLES,
windowId,
values
})
}

}
Expand Down
3 changes: 2 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ const appConstants = {
APP_REMOVE_PASSWORD: _, /** @param {Object} passwordDetail */
APP_REMOVE_PASSWORD_SITE: _, /** @param {Object} passwordDetail */
APP_CLEAR_PASSWORDS: _,
APP_UPDATE_LOG_OPENED: _
APP_UPDATE_LOG_OPENED: _,
APP_WINDOW_COMPUTED_STYLES: _
}

module.exports = mapValuesByKeys(appConstants)

0 comments on commit 0d4a6ba

Please sign in to comment.