Changeset 180785 in webkit


Ignore:
Timestamp:
Feb 27, 2015 3:07:03 PM (9 years ago)
Author:
enrica@apple.com
Message:

Adding support for serializing HTMLAttachment elements.
https://bugs.webkit.org/show_bug.cgi?id=142026

Reviewed by Tim Horton.

Source/WebCore:

Test: editing/pasteboard/copy-paste-attachment.html

Adding support to serialize the attachment element
and properly handle it when converting a DOM range
to NSAttributedString.

  • editing/cocoa/HTMLConverter.mm:

(HTMLConverter::_processElement):

  • editing/markup.cpp:

(WebCore::StyledMarkupAccumulator::appendCustomAttributes): Create new attribute
for attachment element when serializating.
(WebCore::StyledMarkupAccumulator::appendElement):
(WebCore::createFragmentFromMarkup): Remove the attribute from the attachment element
when creating the fragment.

  • html/HTMLAttachmentElement.cpp:

(WebCore::HTMLAttachmentElement::file): Added const to file() to
use it in appendCustonAttributes where the element is a const reference.

  • html/HTMLAttachmentElement.h:
  • html/HTMLAttributeNames.in:

LayoutTests:

  • editing/pasteboard/copy-paste-attachment-expected.txt: Added.
  • editing/pasteboard/copy-paste-attachment.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r180783 r180785  
     12015-02-27  Enrica Casucci  <enrica@apple.com>
     2
     3        Adding support for serializing HTMLAttachment elements.
     4        https://bugs.webkit.org/show_bug.cgi?id=142026
     5
     6        Reviewed by Tim Horton.
     7
     8        * editing/pasteboard/copy-paste-attachment-expected.txt: Added.
     9        * editing/pasteboard/copy-paste-attachment.html: Added.
     10
    1112015-02-27  Brady Eidson  <beidson@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r180784 r180785  
     12015-02-27  Enrica Casucci  <enrica@apple.com>
     2
     3        Adding support for serializing HTMLAttachment elements.
     4        https://bugs.webkit.org/show_bug.cgi?id=142026
     5
     6        Reviewed by Tim Horton.
     7
     8        Test: editing/pasteboard/copy-paste-attachment.html
     9
     10        Adding support to serialize the attachment element
     11        and properly handle it when converting a DOM range
     12        to NSAttributedString.
     13
     14        * editing/cocoa/HTMLConverter.mm:
     15        (HTMLConverter::_processElement):
     16        * editing/markup.cpp:
     17        (WebCore::StyledMarkupAccumulator::appendCustomAttributes): Create new attribute
     18        for attachment element when serializating.
     19        (WebCore::StyledMarkupAccumulator::appendElement):
     20        (WebCore::createFragmentFromMarkup): Remove the attribute from the attachment element
     21        when creating the fragment.
     22        * html/HTMLAttachmentElement.cpp:
     23        (WebCore::HTMLAttachmentElement::file): Added const to file() to
     24        use it in appendCustonAttributes where the element is a const reference.
     25        * html/HTMLAttachmentElement.h:
     26        * html/HTMLAttributeNames.in:
     27
    1282015-02-27  Timothy Horton  <timothy_horton@apple.com>
    229
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r179364 r180785  
    3838#import "Element.h"
    3939#import "ElementTraversal.h"
     40#import "File.h"
    4041#import "FontCascade.h"
    4142#import "Frame.h"
    4243#import "FrameLoader.h"
     44#import "HTMLAttachmentElement.h"
    4345#import "HTMLElement.h"
    4446#import "HTMLFrameElementBase.h"
     
    19621964            _addTableForElement(nil);
    19631965        _addTableCellForElement(&element);
     1966#if ENABLE(ATTACHMENT_ELEMENT)
     1967    } else if (is<HTMLAttachmentElement>(element)) {
     1968        HTMLAttachmentElement& attachment = downcast<HTMLAttachmentElement>(element);
     1969        if (attachment.file()) {
     1970            NSURL *url = [NSURL fileURLWithPath:attachment.file()->path()];
     1971            if (url)
     1972                _addAttachmentForElement(element, url, isBlockLevel, NO);
     1973        }
     1974        retval = NO;
     1975#endif
    19641976    } else if (element.hasTagName(imgTag)) {
    19651977        NSString *urlString = element.getAttribute(srcAttr);
  • trunk/Source/WebCore/editing/markup.cpp

    r179143 r180785  
    4242#include "ExceptionCode.h"
    4343#include "ExceptionCodePlaceholder.h"
     44#include "File.h"
    4445#include "Frame.h"
     46#include "HTMLAttachmentElement.h"
    4547#include "HTMLBodyElement.h"
    4648#include "HTMLDivElement.h"
     
    5254#include "URL.h"
    5355#include "MarkupAccumulator.h"
     56#include "NodeList.h"
    5457#include "Range.h"
    5558#include "RenderBlock.h"
     
    136139
    137140    void appendElement(StringBuilder& out, const Element&, bool addDisplayInline, RangeFullySelectsNode);
     141    virtual void appendCustomAttributes(StringBuilder&, const Element&, Namespaces*) override;
    138142
    139143    virtual void appendText(StringBuilder& out, const Text&) override;
     
    293297}
    294298
     299void StyledMarkupAccumulator::appendCustomAttributes(StringBuilder& out, const Element&element, Namespaces* namespaces)
     300{
     301#if ENABLE(ATTACHMENT_ELEMENT)
     302    if (!is<HTMLAttachmentElement>(element))
     303        return;
     304   
     305    const HTMLAttachmentElement& attachment = downcast<HTMLAttachmentElement>(element);
     306    if (attachment.file())
     307        appendAttribute(out, element, Attribute(webkitattachmentpathAttr, attachment.file()->path()), namespaces);
     308#else
     309    UNUSED_PARAM(out);
     310    UNUSED_PARAM(element);
     311    UNUSED_PARAM(namespaces);
     312#endif
     313}
     314
    295315void StyledMarkupAccumulator::appendElement(StringBuilder& out, const Element& element, bool addDisplayInline, RangeFullySelectsNode rangeFullySelectsNode)
    296316{
    297317    const bool documentIsHTML = element.document().isHTMLDocument();
    298318    appendOpenTag(out, element, 0);
     319
     320    appendCustomAttributes(out, element, nullptr);
    299321
    300322    const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldAnnotate() || addDisplayInline);
     
    659681    fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy);
    660682
     683#if ENABLE(ATTACHMENT_ELEMENT)
     684    // When creating a fragment we must strip the webkit-attachment-path attribute after restoring the File object.
     685    RefPtr<NodeList> nodes = fragment->getElementsByTagName("attachment");
     686    for (size_t i = 0; i < nodes->length(); ++i) {
     687        if (!is<HTMLAttachmentElement>(*nodes->item(i)))
     688            continue;
     689        HTMLAttachmentElement& element = downcast<HTMLAttachmentElement>(*nodes->item(i));
     690        element.setFile(File::create(element.fastGetAttribute(webkitattachmentpathAttr)).ptr());
     691        element.removeAttribute(webkitattachmentpathAttr);
     692    }
     693#endif
    661694    if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseURL())
    662695        completeURLs(fragment.get(), baseURL);
  • trunk/Source/WebCore/html/HTMLAttachmentElement.cpp

    r180720 r180785  
    5757}
    5858
    59 File* HTMLAttachmentElement::file()
     59File* HTMLAttachmentElement::file() const
    6060{
    6161    return m_file.get();
  • trunk/Source/WebCore/html/HTMLAttachmentElement.h

    r180601 r180785  
    3838public:
    3939    static Ref<HTMLAttachmentElement> create(const QualifiedName&, Document&);
    40 
    41     File* file();
     40    virtual bool canContainRangeEndPoint() const override { return false; }
     41    File* file() const;
    4242    void setFile(File*);
    4343
  • trunk/Source/WebCore/html/HTMLAttributeNames.in

    r177622 r180785  
    350350vspace
    351351webkitallowfullscreen
     352webkitattachmentpath
    352353width
    353354wrap
Note: See TracChangeset for help on using the changeset viewer.