Skip to content

Commit

Permalink
DevTools: Focus indicators in Toolbars
Browse files Browse the repository at this point in the history
This patch adds a light gray background to buttons and comboboxes. It adds a default focus ring to checkboxes. These only appear when an item is focused via keyboard.

http://i.imgur.com/E6j7851.gif

BUG=706699

Review-Url: https://codereview.chromium.org/2741863002
Cr-Commit-Position: refs/heads/master@{#461007}
  • Loading branch information
JoelEinbinder authored and Commit bot committed Mar 31, 2017
1 parent 1179da2 commit cd06845
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
1 change: 0 additions & 1 deletion front_end/elements/ClassesPaneWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Elements.ClassesPaneWidget = class extends UI.Widget {
for (var i = 0; i < keys.length; ++i) {
var className = keys[i];
var label = UI.CheckboxLabel.create(className, classes.get(className));
label.visualizeFocus = true;
label.classList.add('monospace');
label.checkboxElement.addEventListener('click', this._onClick.bind(this, className), false);
this._classesContainer.appendChild(label);
Expand Down
16 changes: 8 additions & 8 deletions front_end/ui/UIUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ UI._focusChanged = function(event) {
var document = event.target && event.target.ownerDocument;
var element = document ? document.deepActiveElement() : null;
UI.Widget.focusWidgetForNode(element);
if (!UI._keyboardFocus)
return;
element.setAttribute('data-keyboard-focus', 'true');
element.addEventListener('blur', () => element.removeAttribute('data-keyboard-focus'), {once: true, capture: true});
};

/**
Expand Down Expand Up @@ -1183,6 +1187,10 @@ UI.initializeUIUtils = function(document, themeSetting) {
document.defaultView.addEventListener('focus', UI._windowFocused.bind(UI, document), false);
document.defaultView.addEventListener('blur', UI._windowBlurred.bind(UI, document), false);
document.addEventListener('focus', UI._focusChanged.bind(UI), true);
document.addEventListener('keydown', event => {
UI._keyboardFocus = true;
document.defaultView.requestAnimationFrame(() => UI._keyboardFocus = false);
}, true);

if (!UI.themeSupport)
UI.themeSupport = new UI.ThemeSupport(themeSetting);
Expand Down Expand Up @@ -1371,14 +1379,6 @@ UI.CheckboxLabel = class extends HTMLLabelElement {
this.checkboxElement.classList.add('dt-checkbox-themed');
this.checkboxElement.style.borderColor = color;
}

/**
* @param {boolean} focus
* @this {Element}
*/
set visualizeFocus(focus) {
this.checkboxElement.classList.toggle('dt-checkbox-visualize-focus', focus);
}
};

(function() {
Expand Down
2 changes: 1 addition & 1 deletion front_end/ui/checkboxTextLabel.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ input {
flex-shrink: 0;
}

input.dt-checkbox-visualize-focus:focus {
input:focus {
outline: auto 5px -webkit-focus-ring-color;
}

Expand Down
19 changes: 19 additions & 0 deletions front_end/ui/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ select.toolbar-item {
padding: 0 13px 0 5px;
margin-right: -10px;
position: relative;
height: 22px;
margin-top: 2px;
margin-bottom: 2px;
}

select.toolbar-item[data-keyboard-focus="true"]:focus {
background: rgba(0, 0, 0, 0.08);
border-radius: 2px;
}

/* Input */
Expand Down Expand Up @@ -269,6 +277,17 @@ select.toolbar-item {
background-color: rgb(163, 163, 163);
}

.toolbar-button[data-keyboard-focus="true"]:focus::after {
position: absolute;
top: 2px;
bottom: 2px;
left: 2px;
right: 2px;
background-color: rgba(0, 0, 0, 0.08);
border-radius: 2px;
content: "";
}

.toolbar-shadow.floating {
flex-direction: column;
height: auto;
Expand Down

0 comments on commit cd06845

Please sign in to comment.