| <!doctype html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <title>CSS Regions: Adding and removing regions on mouse events</title> |
| <link rel="author" title="Mihai Balan" href="mailto:mibalan@adobe.com"> |
| <link rel="help" href="http://www.w3.org/TR/css3-regions/#the-flow-into-property"> |
| <link rel="help" href="http://www.w3.org/TR/css3-regions/#flow-from"> |
| <meta name="assert" content="Altering the region chain via DOM manipulation in response to user gestures should not change the rendering of the content inside regions"> |
| <meta name="flags" content="interact"> |
| <style> |
| body { |
| margin: 0; |
| padding: 20px; |
| } |
| p { |
| margin: 0; |
| } |
| .box { |
| width: 200px; |
| height: 200px; |
| float: left; |
| margin: 20px; |
| position: absolute; |
| } |
| .smallbox { |
| width: 200px; |
| height: 90px; |
| float: left; |
| margin: 20px; |
| position: absolute; |
| } |
| |
| #wrapper { |
| position: relative; |
| height: 240px; |
| } |
| |
| #content { |
| background-color: lightcyan; |
| top: 0; |
| left: 0; |
| } |
| #content p { |
| margin-bottom: 10px; |
| width: 100%; |
| height: 80px; |
| flow-into: flow; |
| } |
| .region { |
| flow-from: flow; |
| } |
| .region p { |
| margin-top: 100px; |
| width: 100%; |
| height: 100px; |
| background-color: red; |
| } |
| .first-region { |
| top: 0; |
| left: 33%; |
| } |
| .second-region { |
| top: 0; |
| left: 66%; |
| } |
| #result { |
| font-weight: bold; |
| } |
| .pass { |
| color: green; |
| } |
| .fail { |
| color: red; |
| } |
| |
| .clickable { |
| background-color: yellow; |
| } |
| |
| .phase0 { |
| background-color: green; |
| } |
| .phase1 { |
| background-color: seagreen; |
| } |
| .phase2 { |
| background-color: lime; |
| } |
| .phase3 { |
| background-color: lightgreen; |
| } |
| </style> |
| </head> |
| <body> |
| The test fails if you see any red, the text "FAIL" below the three rectangles below or if any of the expected results below don't happen. |
| <ol> |
| <li>Move the mouse over the yellow rectangle on the right. <strong>Expected: </strong>The green rectangle in the middle should change to a lighter green.</li> |
| <li>Click in the yellow rectangle. <strong>Expected: </strong>The green rectangle in the middle should change again to a yet lighter green.</li> |
| <li>Move the mouse out from the yellow rectangle.</li> |
| <li><strong>Expected: </strong>The color of the green rectangle should change yet again to a pale green. There should be a green text below that says "PASS".</li> |
| </ol> |
| <div id="wrapper"> |
| <div class="box" id="content"> |
| <p></p> |
| <p class="clickable"></p> |
| </div> |
| <div class="first-region region smallbox phase0"> |
| <p></p> |
| </div> |
| <div class="second-region region box"> |
| <p></p> |
| </div> |
| </div> |
| |
| <div id="result"></div> |
| <script type="text/javascript"> |
| var events = [ { |
| name: "mouseover", |
| hit: false |
| }, { |
| name: "click", |
| hit: false |
| }, { |
| name: "mouseout", |
| hit: false |
| } ], |
| target = document.querySelector("#content"), |
| callCount = 0; |
| |
| function setResult(value) { |
| var tag = document.querySelector("#result"); |
| tag.innerHTML = value; |
| tag.classList.add(value.toLowerCase()); |
| } |
| |
| function finishTest() { |
| if (window.testRunner) { |
| testRunner.notifyDone(); |
| } |
| } |
| |
| function handlerForEvent(eventName, index) { |
| return function(evt) { |
| if ((evt.target === evt.currentTarget) || (events[index].hit)) |
| return; |
| |
| callCount++; |
| events[index].hit = true; |
| |
| var nodeToRemove = document.querySelector(".first-region"), |
| nodeParent = nodeToRemove.parentNode; |
| |
| nodeParent.removeChild(nodeToRemove); |
| document.body.offsetTop; |
| |
| var newNode = document.createElement("div"); |
| newNode.classList.add("first-region", "region", "smallbox", "phase" + callCount); |
| nodeParent.insertBefore(newNode, document.querySelector(".second-region")); |
| document.body.offsetTop; |
| |
| if (callCount == 3) { |
| setResult("PASS"); |
| finishTest(); |
| } |
| } |
| } |
| |
| function runScript() { |
| if (window.testRunner) { |
| testRunner.dumpAsText(); |
| testRunner.waitUntilDone(); |
| |
| var boxLocation = document.querySelector(".second-region").getBoundingClientRect(); |
| eventSender.mouseMoveTo(boxLocation.left + 40, boxLocation.top + 50); |
| eventSender.mouseDown(); |
| eventSender.mouseUp(); |
| |
| eventSender.mouseMoveTo(boxLocation.left + boxLocation.width - 40, boxLocation.top + boxLocation.height - 40); |
| eventSender.mouseDown(); |
| eventSender.mouseUp(); |
| } |
| } |
| |
| events.forEach(function(item, index) { |
| target.addEventListener(item.name, handlerForEvent(item, index)); |
| }); |
| runScript(); |
| </script> |
| </body> |
| </html> |