Source/WebCore/ChangeLog

 12012-08-02 Keishi Hattori <keishi@webkit.org>
 2
 3 Add keyboard support for color suggestion popup
 4 https://bugs.webkit.org/show_bug.cgi?id=93069
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This adds support for keyboard inside the color suggestion popup. Tab
 9 and arrow keys work now.
 10
 11 No new tests. Covered in platform/chromium/fast/forms/color/color-suggestion-picker-appearance.html.
 12
 13 * Resources/colorSuggestionPicker.css:
 14 (.color-swatch):
 15 (.color-swatch:focus):
 16 * Resources/colorSuggestionPicker.js:
 17 (ColorPicker):
 18 (ColorPicker.prototype._layout):
 19 (ColorPicker.prototype.selectColorAtIndex): Selects color at index.
 20 (ColorPicker.prototype._handleMouseMove): Set focus to the swatch under the mouse cursor.
 21 (ColorPicker.prototype._handleKeyDown): Move focused element on arrow keys.
 22 (ColorPicker.prototype._handleMouseDown): Prevents blur on click.
 23
1242012-08-03 Jan Keromnes <janx@linux.com>
225
326 Web Inspector: Make textModel private to textEditor

Source/WebCore/Resources/colorSuggestionPicker.css

@@body {
4444 width: 20px;
4545 height: 20px;
4646 margin: 1px;
 47 padding: 0;
4748 border: 1px solid #e0e0e0;
 49 box-sizing: content-box;
4850}
4951
50 .color-swatch:hover {
 52.color-swatch:focus {
5153 border: 1px solid #000000;
52  margin: 1px;
 54 outline: none;
5355}
5456
5557.color-swatch-container {

Source/WebCore/Resources/colorSuggestionPicker.js

@@function ColorPicker(element, config) {
144144 this._config = config;
145145 if (this._config.values.length === 0)
146146 this._config.values = DefaultColorPalette;
 147 this._container = null;
147148 this._layout();
 149 document.body.addEventListener("keydown", bind(this._handleKeyDown, this));
 150 this._element.addEventListener("mousemove", bind(this._handleMouseMove, this));
 151 this._element.addEventListener("mousedown", bind(this._handleMouseDown, this));
148152}
149153
150154var SwatchBorderBoxWidth = 24; // keep in sync with CSS

@@ColorPicker.prototype._layout = function() {
156160 var container = createElement("div", "color-swatch-container");
157161 container.addEventListener("click", bind(this._handleSwatchClick, this), false);
158162 for (var i = 0; i < this._config.values.length; ++i) {
159  var swatch = createElement("div", "color-swatch");
 163 var swatch = createElement("button", "color-swatch");
 164 swatch.tabIndex = 0;
 165 swatch.dataset.index = i;
160166 swatch.dataset.value = this._config.values[i];
161167 swatch.title = this._config.values[i];
162168 swatch.style.backgroundColor = this._config.values[i];

@@ColorPicker.prototype._layout = function() {
171177 var otherButton = createElement("button", "other-color", this._config.otherColorLabel);
172178 otherButton.addEventListener("click", chooseOtherColor, false);
173179 this._element.appendChild(otherButton);
 180 this._container = container;
 181 this._otherButton = otherButton;
174182 var elementWidth = this._element.offsetWidth;
175183 var elementHeight = this._element.offsetHeight;
176184 if (window.frameElement) {

@@ColorPicker.prototype._layout = function() {
181189 }
182190};
183191
 192ColorPicker.prototype.selectColorAtIndex = function(index) {
 193 index = Math.max(Math.min(this._container.childNodes.length - 1, index), 0);
 194 this._container.childNodes[index].focus();
 195};
 196
 197ColorPicker.prototype._handleMouseMove = function(event) {
 198 if (event.target.classList.contains("color-swatch"))
 199 event.target.focus();
 200};
 201
 202ColorPicker.prototype._handleMouseDown = function(event) {
 203 // Prevent blur.
 204 if (event.target.classList.contains("color-swatch"))
 205 event.preventDefault();
 206};
 207
 208ColorPicker.prototype._handleKeyDown = function(event) {
 209 var key = event.keyIdentifier;
 210 if (key === "U+001B") // ESC
 211 handleCancel();
 212 else if (key == "Left" || key == "Up" || key == "Right" || key == "Down") {
 213 var selectedElement = document.activeElement;
 214 var index = 0;
 215 if (selectedElement.classList.contains("other-color")) {
 216 if (key != "Right" && key != "Up")
 217 return;
 218 index = this._container.childNodes.length - 1;
 219 } else if (selectedElement.classList.contains("color-swatch")) {
 220 index = parseInt(selectedElement.dataset.index, 10);
 221 switch (key) {
 222 case "Left":
 223 index--;
 224 break;
 225 case "Right":
 226 index++;
 227 break;
 228 case "Up":
 229 index -= SwatchesPerRow;
 230 break;
 231 case "Down":
 232 index += SwatchesPerRow;
 233 break;
 234 }
 235 if (index > this._container.childNodes.length - 1) {
 236 this._otherButton.focus();
 237 return;
 238 }
 239 }
 240 this.selectColorAtIndex(index);
 241 }
 242 event.preventDefault();
 243};
 244
184245ColorPicker.prototype._handleSwatchClick = function(event) {
185246 if (event.target.classList.contains("color-swatch"))
186247 submitValue(event.target.dataset.value);

LayoutTests/ChangeLog

 12012-08-03 Keishi Hattori <keishi@webkit.org>
 2
 3 Add keyboard support for color suggestion popup
 4 https://bugs.webkit.org/show_bug.cgi?id=93069
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * platform/chromium-mac/platform/chromium/fast/forms/color/color-suggestion-picker-appearance-expected.png:
 9 * platform/chromium/TestExpectations:
 10 * platform/chromium/fast/forms/color/color-suggestion-picker-appearance.html:
 11
1122012-08-03 Zan Dobersek <zandobersek@gmail.com>
213
314 Unreviewed GTK gardening, adding text failure expectations for 20 MathML

LayoutTests/platform/chromium-mac/platform/chromium/fast/forms/color/color-suggestion-picker-appearance-expected.png

a668e3f1eeb63d0b19dc280f839e16df

48488bf57db12cc35b115116addfce6b

LayoutTests/platform/chromium/TestExpectations

@@BUGWK87652 SKIP : http/tests/appcache/load-from-appcache-defer-resume-crash.html
33063306// A few pixels off from the baseline, added by r118567.
33073307BUGWK87653 WIN LINUX : compositing/geometry/composited-in-columns.html = IMAGE+TEXT
33083308
3309 BUGWK92444 : platform/chromium/fast/forms/color/color-suggestion-picker-appearance.html = PASS TEXT
 3309BUGWK92444 : platform/chromium/fast/forms/color/color-suggestion-picker-appearance.html = PASS TEXT IMAGE
33103310
33113311// Fails with a mismatch in $("menulist").selectedIndex
33123312BUGWK87748 MAC : fast/forms/select/optgroup-clicking.html = TEXT

LayoutTests/platform/chromium/fast/forms/color/color-suggestion-picker-appearance.html

@@if (window.eventSender)
3434var pickerWindow = document.getElementById('mock-page-popup').contentWindow;
3535pickerWindow.onresize = function() {
3636 console.log(pickerWindow.pagePopupController);
 37 pickerWindow.focus();
 38 eventSender.keyDown('downArrow');
 39 eventSender.keyDown('downArrow');
 40 eventSender.keyDown('downArrow');
 41 eventSender.keyDown('leftArrow');
 42 eventSender.keyDown('upArrow');
 43 eventSender.keyDown('rightArrow');
3744 setTimeout(function() {testRunner.notifyDone();}, 0);
3845}
3946</script>