Bug 1260283 - Implement new console output frontend behind a pref. r=bgrins

MozReview-Commit-ID: Kl0G7lEFatj
This commit is contained in:
Lin Clark 2016-04-29 13:17:00 -07:00
Родитель 02fc0e20ae
Коммит 4800071c32
1 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -9,6 +9,7 @@ const {
DOM: dom,
PropTypes
} = require("devtools/client/shared/vendor/react");
const ReactDOM = require("devtools/client/shared/vendor/react-dom");
const { connect } = require("devtools/client/shared/vendor/react-redux");
const MessageContainer = createFactory(require("devtools/client/webconsole/new-console-output/components/message-container").MessageContainer);
@ -16,6 +17,27 @@ const MessageContainer = createFactory(require("devtools/client/webconsole/new-c
const ConsoleOutput = createClass({
displayName: "ConsoleOutput",
propTypes: {
jsterm: PropTypes.object.isRequired,
// This function is created in mergeProps
openVariablesView: PropTypes.func.isRequired
},
componentWillUpdate() {
// @TODO Move this to a parent component.
let node = ReactDOM.findDOMNode(this).parentNode.parentNode.parentNode;
if (node.lastChild) {
this.shouldScrollBottom = isScrolledToBottom(node.lastChild, node);
}
},
componentDidUpdate() {
if (this.shouldScrollBottom) {
let node = ReactDOM.findDOMNode(this).parentNode.parentNode.parentNode;
node.scrollTop = node.scrollHeight;
}
},
render() {
let messageNodes = this.props.messages.map(function(message) {
return (
@ -28,6 +50,13 @@ const ConsoleOutput = createClass({
}
});
function isScrolledToBottom(outputNode, scrollNode) {
let lastNodeHeight = outputNode.lastChild ?
outputNode.lastChild.clientHeight : 0;
return scrollNode.scrollTop + scrollNode.clientHeight >=
scrollNode.scrollHeight - lastNodeHeight / 2;
}
function mapStateToProps(state) {
return {
messages: state.messages