Source/WebCore/ChangeLog

 12012-06-29 Dominic Mazzoni <dmazzoni@google.com>
 2
 3 Should be possible to focus elements within canvas fallback content
 4 https://bugs.webkit.org/show_bug.cgi?id=87898
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Patches isFocusable in dom/Node.cpp and html/HTMLFormControlElement.cpp
 9 to make elements focusable if they're a descendent of a canvas element
 10 if they would otherwise have been focusable but just didn't have
 11 a renderer. Adds a bit to ElementRareData to efficiently keep track
 12 of elements in a canvas subtree.
 13
 14 Test: fast/canvas/fallback-content.html
 15
 16 * dom/Element.cpp:
 17 (WebCore::Element::attach):
 18 (WebCore::Element::detach):
 19 (WebCore::Element::setIsInCanvasSubtree):
 20 (WebCore):
 21 (WebCore::Element::isInCanvasSubtree):
 22 * dom/Element.h:
 23 (Element):
 24 * dom/ElementRareData.h:
 25 (ElementRareData):
 26 (WebCore::ElementRareData::ElementRareData):
 27 * dom/Node.cpp:
 28 (WebCore::Node::isFocusable):
 29 * html/HTMLCanvasElement.cpp:
 30 (WebCore::HTMLCanvasElement::attach):
 31 (WebCore):
 32 * html/HTMLCanvasElement.h:
 33 (HTMLCanvasElement):
 34 * html/HTMLFormControlElement.cpp:
 35 (WebCore::HTMLFormControlElement::isFocusable):
 36
1372012-06-29 Brady Eidson <beidson@apple.com>
238
339 Build fix - These should not be executable!
121568

Source/WebCore/dom/Element.cpp

@@void Element::attach()
935935 createRendererIfNeeded();
936936 StyleResolverParentPusher parentPusher(this);
937937
 938 if (parentElement() && parentElement()->isInCanvasSubtree())
 939 setIsInCanvasSubtree(true);
 940
938941 // When a shadow root exists, it does the work of attaching the children.
939942 if (ElementShadow* shadow = this->shadow()) {
940943 parentPusher.push();

@@void Element::detach()
973976 RenderWidget::suspendWidgetHierarchyUpdates();
974977 unregisterNamedFlowContentNode();
975978 cancelFocusAppearanceUpdate();
976  if (hasRareData())
 979 if (hasRareData()) {
 980 setIsInCanvasSubtree(false);
977981 elementRareData()->resetComputedStyle();
 982 }
978983
979984 if (ElementShadow* shadow = this->shadow()) {
980985 detachChildrenIfNeeded();

@@bool Element::styleAffectedByEmpty() con
16691674 return hasRareData() && elementRareData()->m_styleAffectedByEmpty;
16701675}
16711676
 1677void Element::setIsInCanvasSubtree(bool isInCanvasSubtree)
 1678{
 1679 ElementRareData* data = ensureElementRareData();
 1680 data->m_isInCanvasSubtree = isInCanvasSubtree;
 1681}
 1682
 1683bool Element::isInCanvasSubtree() const
 1684{
 1685 return hasRareData() && elementRareData()->m_isInCanvasSubtree;
 1686}
 1687
16721688AtomicString Element::computeInheritedLanguage() const
16731689{
16741690 const Node* n = this;
121409

Source/WebCore/dom/Element.h

@@public:
281281 void setStyleAffectedByEmpty();
282282 bool styleAffectedByEmpty() const;
283283
 284 void setIsInCanvasSubtree(bool);
 285 bool isInCanvasSubtree() const;
 286
284287 AtomicString computeInheritedLanguage() const;
285288
286289 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
121409

Source/WebCore/dom/ElementRareData.h

@@public:
7272 OwnPtr<ElementShadow> m_shadow;
7373 OwnPtr<NamedNodeMap> m_attributeMap;
7474
75  bool m_styleAffectedByEmpty;
 75 bool m_styleAffectedByEmpty : 1;
 76 bool m_isInCanvasSubtree : 1;
7677
7778 IntSize m_savedLayerScrollOffset;
7879

@@inline ElementRareData::ElementRareData(
9091 : NodeRareData()
9192 , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
9293 , m_styleAffectedByEmpty(false)
 94 , m_isInCanvasSubtree(false)
9395#if ENABLE(FULLSCREEN_API)
9496 , m_containsFullScreenElement(false)
9597#endif
121409

Source/WebCore/dom/Node.cpp

@@bool Node::isFocusable() const
905905 // If the node is in a display:none tree it might say it needs style recalc but
906906 // the whole document is actually up to date.
907907 ASSERT(!document()->childNeedsStyleRecalc());
908 
 908
 909 // Elements in canvas fallback content are not rendered, but they are allowed to be
 910 // focusable as long as their canvas is displayed and visible.
 911 if (isElementNode() && toElement(this)->isInCanvasSubtree()) {
 912 const Element* e = toElement(this);
 913 while (e && !e->hasLocalName(canvasTag))
 914 e = e->parentElement();
 915 ASSERT(e);
 916 return e->renderer() && e->renderer()->style()->visibility() == VISIBLE;
 917 }
 918
909919 // FIXME: Even if we are not visible, we might have a child that is visible.
910920 // Hyatt wants to fix that some day with a "has visible content" flag or the like.
911921 if (!renderer() || renderer()->style()->visibility() != VISIBLE)
121409

Source/WebCore/html/HTMLCanvasElement.cpp

@@RenderObject* HTMLCanvasElement::createR
135135 return HTMLElement::createRenderer(arena, style);
136136}
137137
 138void HTMLCanvasElement::attach()
 139{
 140 setIsInCanvasSubtree(true);
 141 HTMLElement::attach();
 142}
 143
138144void HTMLCanvasElement::addObserver(CanvasObserver* observer)
139145{
140146 m_observers.add(observer);
121409

Source/WebCore/html/HTMLCanvasElement.h

@@private:
142142
143143 virtual void parseAttribute(const Attribute&) OVERRIDE;
144144 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
 145 virtual void attach();
145146
146147 void reset();
147148
121409

Source/WebCore/html/HTMLFormControlElement.cpp

@@bool HTMLFormControlElement::supportsFoc
312312
313313bool HTMLFormControlElement::isFocusable() const
314314{
315  if (!renderer() || !renderer()->isBox() || toRenderBox(renderer())->size().isEmpty())
 315 if (renderer() && (!renderer()->isBox() || toRenderBox(renderer())->size().isEmpty()))
316316 return false;
317317 // HTMLElement::isFocusable handles visibility and calls suportsFocus which
318318 // will cover the disabled case.
121409

LayoutTests/ChangeLog

 12012-06-29 Dominic Mazzoni <dmazzoni@google.com>
 2
 3 Should be possible to focus elements within canvas fallback content
 4 https://bugs.webkit.org/show_bug.cgi?id=87898
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * fast/canvas/fallback-content-expected.txt: Added.
 9 * fast/canvas/fallback-content.html: Added.
 10
1112012-06-29 Tony Chang <tony@chromium.org>
212
313 [GTK] Enable CSS grid layout LayoutTests on GTK+
121568

LayoutTests/fast/canvas/fallback-content-expected.txt

 1Link Button
 2Focusable
 3This test makes sure that focusable elements in canvas fallback content are focusable.
 4
 5On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 6
 7
 8link1 should be focusable.
 9PASS document.activeElement == element is true
 10
 11button1 should be focusable.
 12PASS document.activeElement == element is true
 13
 14text1 should be focusable.
 15PASS document.activeElement == element is true
 16
 17checkbox1 should be focusable.
 18PASS document.activeElement == element is true
 19
 20radio1 should be focusable.
 21PASS document.activeElement == element is true
 22
 23submit1 should be focusable.
 24PASS document.activeElement == element is true
 25
 26combobox1 should be focusable.
 27PASS document.activeElement == element is true
 28
 29listbox1 should be focusable.
 30PASS document.activeElement == element is true
 31
 32focusable1 should be focusable.
 33PASS document.activeElement == element is true
 34
 35link2 should be focusable.
 36PASS document.activeElement == element is true
 37
 38button2 should be focusable.
 39PASS document.activeElement == element is true
 40
 41text2 should be focusable.
 42PASS document.activeElement == element is true
 43
 44checkbox2 should be focusable.
 45PASS document.activeElement == element is true
 46
 47radio2 should be focusable.
 48PASS document.activeElement == element is true
 49
 50submit2 should be focusable.
 51PASS document.activeElement == element is true
 52
 53combobox2 should be focusable.
 54PASS document.activeElement == element is true
 55
 56listbox2 should be focusable.
 57PASS document.activeElement == element is true
 58
 59focusable2 should be focusable.
 60PASS document.activeElement == element is true
 61
 62linkInHiddenCanvas should not be focusable.
 63PASS document.activeElement == previousFocusedElement is true
 64
 65PASS successfullyParsed is true
 66
 67TEST COMPLETE
 68
0

LayoutTests/fast/canvas/fallback-content.html

 1<!DOCTYPE HTML>
 2<html>
 3<body>
 4<script src="../js/resources/js-test-pre.js"></script>
 5
 6<div>
 7 <a id="link1" href="#">Link</a>
 8 <button id="button1">Button</button>
 9 <input id="text1" type="text">
 10 <input id="checkbox1" type="checkbox">
 11 <input id="radio1" type="radio">
 12 <input id="submit1" type="submit">
 13 <select id="combobox1"><option>1<option>2</select>
 14 <select id="listbox1" multiple><option>1<option>2</select>
 15 <div id="focusable1" tabindex="0">Focusable</div>
 16</div>
 17
 18<canvas id="myCanvas" width="300" height="300">
 19 <a id="link2" href="#">Link</a>
 20 <button id="button2">Button</button>
 21 <input id="text2" type="text">
 22 <input id="checkbox2" type="checkbox">
 23 <input id="radio2" type="radio">
 24 <input id="submit2" type="submit">
 25 <select id="combobox2"><option>1<option>2</select>
 26 <select id="listbox2" multiple><option>1<option>2</select>
 27 <div id="focusable2" tabindex="0">Focusable</div>
 28</canvas>
 29
 30<canvas hidden id="hiddenCanvas" width="300" height="300">
 31 <a id="linkInHiddenCanvas" href="#">Link</a>
 32</canvas>
 33
 34<div id="console"></div>
 35<script>
 36description("This test makes sure that focusable elements in canvas fallback content are focusable.");
 37
 38if (window.layoutTestController)
 39 window.layoutTestController.dumpAsText();
 40
 41var element;
 42function checkFocusable(id) {
 43 debug(id + " should be focusable.");
 44 element = document.getElementById(id);
 45 element.focus();
 46 shouldBe("document.activeElement == element", "true");
 47 debug("");
 48}
 49
 50checkFocusable("link1");
 51checkFocusable("button1");
 52checkFocusable("text1");
 53checkFocusable("checkbox1");
 54checkFocusable("radio1");
 55checkFocusable("submit1");
 56checkFocusable("combobox1");
 57checkFocusable("listbox1");
 58checkFocusable("focusable1");
 59
 60checkFocusable("link2");
 61checkFocusable("button2");
 62checkFocusable("text2");
 63checkFocusable("checkbox2");
 64checkFocusable("radio2");
 65checkFocusable("submit2");
 66checkFocusable("combobox2");
 67checkFocusable("listbox2");
 68checkFocusable("focusable2");
 69
 70var previousFocusedElement;
 71function checkNotFocusable(id) {
 72 debug(id + " should not be focusable.");
 73 previousFocusedElement = document.activeElement;
 74 element = document.getElementById(id);
 75 element.focus();
 76 shouldBe("document.activeElement == previousFocusedElement", "true");
 77 debug("");
 78}
 79
 80checkNotFocusable("linkInHiddenCanvas");
 81
 82</script>
 83
 84<script src="../js/resources/js-test-post.js"></script>
 85</body>
 86</html>
0