Changeset 166668 in webkit


Ignore:
Timestamp:
Apr 2, 2014 2:40:26 PM (10 years ago)
Author:
dbates@webkit.org
Message:

Move focus management API from HTMLDocument to Document
https://bugs.webkit.org/show_bug.cgi?id=131079
<rdar://problem/16220103>

Reviewed by Timothy Hatcher.

Source/WebCore:

Merged from Blink (patch by Christophe Dumez):
https://src.chromium.org/viewvc/blink?view=rev&revision=165515

Move hasFocus() and attribute activeElement from interface HTMLDocument
to DOMDocument as per section Focus management APIs of the HTML5 standard:
<http://www.whatwg.org/specs/web-apps/current-work/#focus-management-apis> (1 April 2014).

Test: fast/dom/Document/xml-document-focus.xml

  • bindings/objc/PublicDOMInterfaces.h: Moved hasFocus() and property activeElement from

interface DOMHTMLDocument to DOMDocument.

  • dom/Document.cpp:

(WebCore::Document::activeElement): Added.
(WebCore::Document::hasFocus): Added.

  • dom/Document.h:
  • dom/Document.idl:
  • html/HTMLDocument.cpp:

(WebCore::HTMLDocument::activeElement): Deleted.
(WebCore::HTMLDocument::hasFocus): Deleted.

  • html/HTMLDocument.h:
  • html/HTMLDocument.idl:

LayoutTests:

Derived from a Blink patch by Christophe Dumez:
https://src.chromium.org/viewvc/blink?view=rev&revision=165515

Made the test in <https://src.chromium.org/viewvc/blink?view=rev&revision=165515> a valid XHTML
document. Additionally taught LayoutTests/resources/{js-test, js-test-pre}.js to create actual
HTML elements so that these scripts can be used to write DRT tests in XML documents.

  • fast/dom/Document/xml-document-focus-expected.txt: Added.
  • fast/dom/Document/xml-document-focus.xml: Added.
  • resources/js-test-pre.js: Added function createHTMLElement() and modified code to use it

instead of document.createElement() so as to work around <https://bugs.webkit.org/show_bug.cgi?id=131074>.

  • resources/js-test.js: Ditto.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r166665 r166668  
     12014-04-02  Daniel Bates  <dabates@apple.com>
     2
     3        Move focus management API from HTMLDocument to Document
     4        https://bugs.webkit.org/show_bug.cgi?id=131079
     5        <rdar://problem/16220103>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        Derived from a Blink patch by Christophe Dumez:
     10        https://src.chromium.org/viewvc/blink?view=rev&revision=165515
     11
     12        Made the test in <https://src.chromium.org/viewvc/blink?view=rev&revision=165515> a valid XHTML
     13        document. Additionally taught LayoutTests/resources/{js-test, js-test-pre}.js to create actual
     14        HTML elements so that these scripts can be used to write DRT tests in XML documents.
     15
     16        * fast/dom/Document/xml-document-focus-expected.txt: Added.
     17        * fast/dom/Document/xml-document-focus.xml: Added.
     18        * resources/js-test-pre.js: Added function createHTMLElement() and modified code to use it
     19        instead of document.createElement() so as to work around <https://bugs.webkit.org/show_bug.cgi?id=131074>.
     20        * resources/js-test.js: Ditto.
     21
    1222014-04-02  Daniel Bates  <dabates@apple.com>
    223
  • trunk/LayoutTests/resources/js-test-pre.js

    r161794 r166668  
    1010
    1111(function() {
     12
     13    function createHTMLElement(tagName)
     14    {
     15        // FIXME: In an XML document, document.createElement() creates an element with a null namespace URI.
     16        // So, we need use document.createElementNS() to explicitly create an element with the specified
     17        // tag name in the HTML namespace. We can remove this function and use document.createElement()
     18        // directly once we fix <https://bugs.webkit.org/show_bug.cgi?id=131074>.
     19        if (document.createElementNS)
     20            return document.createElementNS("http://www.w3.org/1999/xhtml", tagName);
     21        return document.createElement(tagName);
     22    }
    1223
    1324    function getOrCreate(id, tagName)
     
    1728            return element;
    1829
    19         element = document.createElement(tagName);
     30        element = createHTMLElement(tagName);
    2031        element.id = id;
    2132        var refNode;
     
    3344    {
    3445        // For MSIE 6 compatibility
    35         var span = document.createElement("span");
     46        var span = createHTMLElement("span");
    3647        if (quiet)
    3748            span.innerHTML = '<p>' + msg + '</p><p>On success, you will see no "<span class="fail">FAIL</span>" messages, followed by "<span class="pass">TEST COMPLETE</span>".</p>';
     
    4859    debug = function debug(msg)
    4960    {
    50         var span = document.createElement("span");
     61        var span = createHTMLElement("span");
    5162        getOrCreate("console", "div").appendChild(span); // insert it first so XHTML knows the namespace
    5263        span.innerHTML = msg + '<br />';
     
    6980    function insertStyleSheet()
    7081    {
    71         var styleElement = document.createElement("style");
     82        var styleElement = createHTMLElement("style");
    7283        styleElement.textContent = css;
    7384        (document.head || document.documentElement).appendChild(styleElement);
  • trunk/LayoutTests/resources/js-test.js

    r163963 r166668  
    1515(function() {
    1616
     17    function createHTMLElement(tagName)
     18    {
     19        // FIXME: In an XML document, document.createElement() creates an element with a null namespace URI.
     20        // So, we need use document.createElementNS() to explicitly create an element with the specified
     21        // tag name in the HTML namespace. We can remove this function and use document.createElement()
     22        // directly once we fix <https://bugs.webkit.org/show_bug.cgi?id=131074>.
     23        if (document.createElementNS)
     24            return document.createElementNS("http://www.w3.org/1999/xhtml", tagName);
     25        return document.createElement(tagName);
     26    }
     27
    1728    function getOrCreate(id, tagName)
    1829    {
     
    2132            return element;
    2233
    23         element = document.createElement(tagName);
     34        element = createHTMLElement(tagName);
    2435        element.id = id;
    2536        var refNode;
     
    3748    {
    3849        // For MSIE 6 compatibility
    39         var span = document.createElement("span");
     50        var span = createHTMLElement("span");
    4051        if (quiet)
    4152            span.innerHTML = '<p>' + msg + '</p><p>On success, you will see no "<span class="fail">FAIL</span>" messages, followed by "<span class="pass">TEST COMPLETE</span>".</p>';
     
    5263    debug = function debug(msg)
    5364    {
    54         var span = document.createElement("span");
     65        var span = createHTMLElement("span");
    5566        getOrCreate("console", "div").appendChild(span); // insert it first so XHTML knows the namespace
    5667        span.innerHTML = msg + '<br />';
     
    7384    function insertStyleSheet()
    7485    {
    75         var styleElement = document.createElement("style");
     86        var styleElement = createHTMLElement("style");
    7687        styleElement.textContent = css;
    7788        (document.head || document.documentElement).appendChild(styleElement);
  • trunk/Source/WebCore/ChangeLog

    r166666 r166668  
     12014-04-02  Daniel Bates  <dabates@apple.com>
     2
     3        Move focus management API from HTMLDocument to Document
     4        https://bugs.webkit.org/show_bug.cgi?id=131079
     5        <rdar://problem/16220103>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        Merged from Blink (patch by Christophe Dumez):
     10        https://src.chromium.org/viewvc/blink?view=rev&revision=165515
     11
     12        Move hasFocus() and attribute activeElement from interface HTMLDocument
     13        to DOMDocument as per section Focus management APIs of the HTML5 standard:
     14        <http://www.whatwg.org/specs/web-apps/current-work/#focus-management-apis> (1 April 2014).
     15
     16        Test: fast/dom/Document/xml-document-focus.xml
     17
     18        * bindings/objc/PublicDOMInterfaces.h: Moved hasFocus() and property activeElement from
     19        interface DOMHTMLDocument to DOMDocument.
     20        * dom/Document.cpp:
     21        (WebCore::Document::activeElement): Added.
     22        (WebCore::Document::hasFocus): Added.
     23        * dom/Document.h:
     24        * dom/Document.idl:
     25        * html/HTMLDocument.cpp:
     26        (WebCore::HTMLDocument::activeElement): Deleted.
     27        (WebCore::HTMLDocument::hasFocus): Deleted.
     28        * html/HTMLDocument.h:
     29        * html/HTMLDocument.idl:
     30
    1312014-04-02  Benjamin Poulain  <benjamin@webkit.org>
    232
  • trunk/Source/WebCore/bindings/objc/PublicDOMInterfaces.h

    r165676 r166668  
    108108@property (copy) NSString *selectedStylesheetSet WEBKIT_AVAILABLE_MAC(10_5);
    109109@property (readonly, copy) NSString *lastModified WEBKIT_AVAILABLE_MAC(10_6);
     110@property (readonly, strong) DOMElement *activeElement WEBKIT_AVAILABLE_MAC(10_6);
    110111- (DOMElement *)createElement:(NSString *)tagName;
    111112- (DOMDocumentFragment *)createDocumentFragment;
     
    162163- (void)webkitCancelFullScreen WEBKIT_AVAILABLE_MAC(10_6);
    163164#endif
     165- (BOOL)hasFocus WEBKIT_AVAILABLE_MAC(10_6);
    164166@end
    165167
     
    459461@property (copy) NSString *linkColor WEBKIT_AVAILABLE_MAC(10_5);
    460462@property (copy) NSString *vlinkColor WEBKIT_AVAILABLE_MAC(10_5);
    461 @property (readonly, strong) DOMElement *activeElement WEBKIT_AVAILABLE_MAC(10_6);
    462463@property (readonly, copy) NSString *compatMode WEBKIT_AVAILABLE_MAC(10_6);
    463464- (void)captureEvents WEBKIT_AVAILABLE_MAC(10_5);
    464465- (void)releaseEvents WEBKIT_AVAILABLE_MAC(10_5);
    465466- (void)clear WEBKIT_AVAILABLE_MAC(10_6);
    466 - (BOOL)hasFocus WEBKIT_AVAILABLE_MAC(10_6);
    467467- (void)open;
    468468- (void)close;
  • trunk/Source/WebCore/dom/Document.cpp

    r166630 r166668  
    5656#include "EventFactory.h"
    5757#include "EventHandler.h"
     58#include "FocusController.h"
    5859#include "FontLoader.h"
    5960#include "FormController.h"
     
    61546155}
    61556156
     6157Element* Document::activeElement()
     6158{
     6159    updateStyleIfNeeded();
     6160    if (Element* element = treeScope().focusedElement())
     6161        return element;
     6162    return body();
     6163}
     6164
     6165bool Document::hasFocus() const
     6166{
     6167    Page* page = this->page();
     6168    if (!page || !page->focusController().isActive())
     6169        return false;
     6170    if (Frame* focusedFrame = page->focusController().focusedFrame()) {
     6171        if (focusedFrame->tree().isDescendantOf(frame()))
     6172            return true;
     6173    }
     6174    return false;
     6175}
     6176
    61566177} // namespace WebCore
  • trunk/Source/WebCore/dom/Document.h

    r166630 r166668  
    406406    }
    407407
     408    Element* activeElement();
     409    bool hasFocus() const;
     410
    408411    bool hasManifest() const;
    409412   
  • trunk/Source/WebCore/dom/Document.idl

    r164505 r166668  
    210210    // HTML 5
    211211    NodeList getElementsByClassName([Default=Undefined] optional DOMString tagname);
     212
     213    readonly attribute Element activeElement;
     214    boolean hasFocus();
    212215
    213216    readonly attribute DOMString compatMode;
  • trunk/Source/WebCore/html/HTMLDocument.cpp

    r161207 r166668  
    136136        mode = inherit;
    137137    Document::setDesignMode(mode);
    138 }
    139 
    140 Element* HTMLDocument::activeElement()
    141 {
    142     document().updateStyleIfNeeded();
    143     if (Element* element = treeScope().focusedElement())
    144         return element;
    145     return body();
    146 }
    147 
    148 bool HTMLDocument::hasFocus()
    149 {
    150     Page* page = this->page();
    151     if (!page)
    152         return false;
    153     if (!page->focusController().isActive())
    154         return false;
    155     if (Frame* focusedFrame = page->focusController().focusedFrame()) {
    156         if (focusedFrame->tree().isDescendantOf(frame()))
    157             return true;
    158     }
    159     return false;
    160138}
    161139
  • trunk/Source/WebCore/html/HTMLDocument.h

    r162180 r166668  
    5353    void setDesignMode(const String&);
    5454
    55     Element* activeElement();
    56     bool hasFocus();
    57 
    5855    const AtomicString& bgColor() const;
    5956    void setBgColor(const String&);
  • trunk/Source/WebCore/html/HTMLDocument.idl

    r160628 r166668  
    5050    readonly attribute DOMString compatMode;
    5151
    52     readonly attribute Element activeElement;
    53     boolean hasFocus();
    54 
    5552    // Deprecated attributes
    5653             [TreatNullAs=NullString] attribute DOMString bgColor;
Note: See TracChangeset for help on using the changeset viewer.