Commit 6702fd7e authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

DevTools: Inactive highlight color in CodeMirror

We emulate the correct text selection colors for CodeMirror, but we were
awlays displaying the active colors even when the window was not focused

Bug: none
Change-Id: Idaf4983ef758a6e66479244b641b3e0245b13ded
Reviewed-on: https://chromium-review.googlesource.com/671533Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521426}
parent 8229631e
...@@ -221,6 +221,18 @@ String DevToolsHost::getSelectionForegroundColor() { ...@@ -221,6 +221,18 @@ String DevToolsHost::getSelectionForegroundColor() {
return LayoutTheme::GetTheme().ActiveSelectionForegroundColor().Serialized(); return LayoutTheme::GetTheme().ActiveSelectionForegroundColor().Serialized();
} }
String DevToolsHost::getInactiveSelectionBackgroundColor() {
return LayoutTheme::GetTheme()
.InactiveSelectionBackgroundColor()
.Serialized();
}
String DevToolsHost::getInactiveSelectionForegroundColor() {
return LayoutTheme::GetTheme()
.InactiveSelectionForegroundColor()
.Serialized();
}
bool DevToolsHost::isUnderTest() { bool DevToolsHost::isUnderTest() {
return client_ && client_->IsUnderTest(); return client_ && client_->IsUnderTest();
} }
......
...@@ -68,6 +68,8 @@ class CORE_EXPORT DevToolsHost final : public ScriptWrappable { ...@@ -68,6 +68,8 @@ class CORE_EXPORT DevToolsHost final : public ScriptWrappable {
String getSelectionBackgroundColor(); String getSelectionBackgroundColor();
String getSelectionForegroundColor(); String getSelectionForegroundColor();
String getInactiveSelectionBackgroundColor();
String getInactiveSelectionForegroundColor();
bool isUnderTest(); bool isUnderTest();
bool isHostedMode(); bool isHostedMode();
......
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
DOMString getSelectionBackgroundColor(); DOMString getSelectionBackgroundColor();
DOMString getSelectionForegroundColor(); DOMString getSelectionForegroundColor();
DOMString getInactiveSelectionBackgroundColor();
DOMString getInactiveSelectionForegroundColor();
boolean isUnderTest(); boolean isUnderTest();
boolean isHostedMode(); boolean isHostedMode();
......
...@@ -343,6 +343,22 @@ ...@@ -343,6 +343,22 @@
return DevToolsHost.getSelectionForegroundColor(); return DevToolsHost.getSelectionForegroundColor();
} }
/**
* @override
* @return {string}
*/
getInactiveSelectionBackgroundColor() {
return DevToolsHost.getInactiveSelectionBackgroundColor();
}
/**
* @override
* @return {string}
*/
getInactiveSelectionForegroundColor() {
return DevToolsHost.getInactiveSelectionForegroundColor();
}
/** /**
* @override * @override
* @return {string} * @return {string}
......
...@@ -257,6 +257,16 @@ DevToolsHost.getSelectionBackgroundColor = function() {}; ...@@ -257,6 +257,16 @@ DevToolsHost.getSelectionBackgroundColor = function() {};
*/ */
DevToolsHost.getSelectionForegroundColor = function() {}; DevToolsHost.getSelectionForegroundColor = function() {};
/**
* @return {string}
*/
DevToolsHost.getInactiveSelectionBackgroundColor = function() {};
/**
* @return {string}
*/
DevToolsHost.getInactiveSelectionForegroundColor = function() {};
/** /**
* @return {boolean} * @return {boolean}
*/ */
......
...@@ -64,6 +64,22 @@ Host.InspectorFrontendHostStub = class { ...@@ -64,6 +64,22 @@ Host.InspectorFrontendHostStub = class {
return '#ffffff'; return '#ffffff';
} }
/**
* @override
* @return {string}
*/
getInactiveSelectionBackgroundColor() {
return '#c9c8c8';
}
/**
* @override
* @return {string}
*/
getInactiveSelectionForegroundColor() {
return '#323232';
}
/** /**
* @override * @override
* @return {string} * @return {string}
......
...@@ -126,6 +126,16 @@ InspectorFrontendHostAPI.prototype = { ...@@ -126,6 +126,16 @@ InspectorFrontendHostAPI.prototype = {
*/ */
getSelectionForegroundColor() {}, getSelectionForegroundColor() {},
/**
* @return {string}
*/
getInactiveSelectionBackgroundColor() {},
/**
* @return {string}
*/
getInactiveSelectionForegroundColor() {},
/** /**
* Requests inspected page to be placed atop of the inspector frontend with specified bounds. * Requests inspected page to be placed atop of the inspector frontend with specified bounds.
* @param {{x: number, y: number, width: number, height: number}} bounds * @param {{x: number, y: number, width: number, height: number}} bounds
......
...@@ -94,22 +94,36 @@ TextEditor.CodeMirrorUtils.pullLines = function(codeMirror, linesCount) { ...@@ -94,22 +94,36 @@ TextEditor.CodeMirrorUtils.pullLines = function(codeMirror, linesCount) {
TextEditor.CodeMirrorUtils.appendThemeStyle = function(element) { TextEditor.CodeMirrorUtils.appendThemeStyle = function(element) {
if (UI.themeSupport.hasTheme()) if (UI.themeSupport.hasTheme())
return; return;
var backgroundColor = InspectorFrontendHost.getSelectionBackgroundColor(); var backgroundColor = InspectorFrontendHost.getSelectionBackgroundColor();
var backgroundColorRule =
backgroundColor ? '.CodeMirror .CodeMirror-selected { background-color: ' + backgroundColor + ';}' : '';
var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor();
var foregroundColorRule = foregroundColor ? var inactiveBackgroundColor = InspectorFrontendHost.getInactiveSelectionBackgroundColor();
'.CodeMirror .CodeMirror-selectedtext:not(.CodeMirror-persist-highlight) { color: ' + foregroundColor + var inactiveForegroundColor = InspectorFrontendHost.getInactiveSelectionForegroundColor();
'!important;}' :
'';
var selectionRule = (foregroundColor && backgroundColor) ?
'.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: ' +
backgroundColor + '; color: ' + foregroundColor + ' !important }' :
'';
var style = createElement('style'); var style = createElement('style');
if (foregroundColorRule || backgroundColorRule) style.textContent = `
style.textContent = backgroundColorRule + foregroundColorRule + selectionRule; .CodeMirror .CodeMirror-selected {
background-color: ${inactiveBackgroundColor};
}
.CodeMirror .CodeMirror-selectedtext:not(.CodeMirror-persist-highlight) {
color: ${inactiveForegroundColor} !important;
}
.CodeMirror-focused .CodeMirror-selected {
background-color: ${backgroundColor};
}
.CodeMirror-focused .CodeMirror-selectedtext:not(.CodeMirror-persist-highlight) {
color: ${foregroundColor} !important;
}
.CodeMirror .CodeMirror-line::selection,
.CodeMirror .CodeMirror-line > span::selection,
.CodeMirror .CodeMirror-line > span > span::selection {
background: ${backgroundColor};
color: ${foregroundColor} !important;
}
`;
element.appendChild(style); element.appendChild(style);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment