[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

Changeset 37863 in webkit


Ignore:
Timestamp:
Oct 24, 2008, 2:12:45 PM (16 years ago)
Author:
adele@apple.com
Message:

WebCore:

2008-10-24 Adele Peterson <adele@apple.com>

Reviewed by Sam Weinig.

WebCore part of fix for <rdar://problem/5839256> FILE CONTROL: multi-file upload.

This change adds support for multiple file selection in an <input type="file"> control when the "multiple" attribute is used.
This is consistent with the direction HTML5 will be going in the future.

The initial implementation here will show "n files" as the text next to the control when multiple files are selected. You can view
the individual files in a tooltip for now. Improvements to this control will come later.

Web developers will be able to access the FileList from the HTMLInputElement element, where they can get a base name and a size for each file.
These FileList Files can also be sent in an XMLHTTPRequest.

  • manual-tests/post-multi-file-upload.html: Added.
  • manual-tests/resources/multiFileResources: Added.
  • manual-tests/resources/multiFileResources/post-echo-and-notify-done.cgi: Added.
  • manual-tests/resources/multiFileResources/testFile1.html: Added.
  • manual-tests/resources/multiFileResources/testFile2.html: Added.
  • manual-tests/resources/multiFileResources/testFile3.html: Added.
  • WebCore.base.exp: Added support to export the new "chooseFilenames" method to be used in WebKit.
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::parseMappedAttribute): Add support for the multiple attribute. (WebCore::HTMLInputElement::value): Added comments. The HTML5 spec says that value shouldn't apply for the file upload control, but we don't want to break the behavior for existing websites that may rely on this. (WebCore::HTMLInputElement::setValue): ditto. (WebCore::HTMLInputElement::setValueFromRenderer): This is no longer used for file upload controls. setFileListFromRenderer is used instead. (WebCore::HTMLInputElement::setFileListFromRenderer): Added.
  • html/HTMLInputElement.h:
  • page/Chrome.cpp: (WebCore::Chrome::setToolTip): Show a tooltip with the file name list for the multi-file upload control.
  • page/DragController.cpp: (WebCore::DragController::concludeDrag): Updated to support multiple files.
  • platform/FileChooser.cpp: Add support for maintaining a list of file paths that can be retrieved by the renderer. (WebCore::FileChooser::FileChooser): (WebCore::FileChooser::create): (WebCore::FileChooser::clear): (WebCore::FileChooser::chooseFile): (WebCore::FileChooser::chooseFiles): (WebCore::FileChooser::chooseIcon):
  • platform/FileChooser.h: (WebCore::FileChooser::filePaths): (WebCore::FileChooser::allowsMultipleFiles):
  • platform/graphics/Icon.h:
  • platform/graphics/mac/IconMac.mm: (WebCore::Icon::newIconForFiles): Returns a generic icon for multiple files.
  • platform/graphics/gtk/IconGtk.cpp: (WebCore::Icon::newIconForFiles): stubbed out.
  • platform/graphics/qt/IconQt.cpp: (WebCore::Icon::newIconForFiles): ditto.
  • platform/graphics/win/IconWin.cpp: (WebCore::Icon::newIconForFiles): ditto.
  • platform/gtk/FileChooserGtk.cpp: (WebCore::FileChooser::basenameForWidth): Updated to deal with new filenames vector.
  • platform/mac/FileChooserMac.mm: (WebCore::FileChooser::basenameForWidth): ditto.
  • platform/qt/FileChooserQt.cpp: (WebCore::FileChooser::openFileChooser): (WebCore::FileChooser::basenameForWidth):
  • platform/win/FileChooserWin.cpp: (WebCore::FileChooser::basenameForWidth):
  • platform/network/mac/FormDataStreamMac.mm: (WebCore::disassociateStreamWithResourceHandle): Removed unnecessary assertion. This can get hit when connectionDidFinishLoading and cancel both get called for the same ResourceHandle. This getting called twice has no negative effect.
  • rendering/RenderFileUploadControl.cpp: (WebCore::RenderFileUploadControl::valueChanged): Calls setFileListFromRenderer. (WebCore::RenderFileUploadControl::allowsMultipleFiles): Added. (WebCore::RenderFileUploadControl::updateFromElement): Uses the new filenames call from FileChooser. (WebCore::RenderFileUploadControl::receiveDroppedFiles): Updated to support multiple files.
  • rendering/RenderFileUploadControl.h:

WebKit/mac:

2008-10-24 Adele Peterson <adele@apple.com>

Reviewed by Sam Weinig.

WebKit part of fix for <rdar://problem/5839256> FILE CONTROL: multi-file upload.

  • WebCoreSupport/WebChromeClient.mm: (WebChromeClient::runOpenPanel): (-[WebOpenPanelResultListener chooseFilenames:]):
  • WebView/WebUIDelegate.h:
Location:
trunk
Files:
6 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r37858 r37863  
     12008-10-24  Adele Peterson  <adele@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        WebCore part of fix for <rdar://problem/5839256> FILE CONTROL: multi-file upload.
     6
     7        This change adds support for multiple file selection in an <input type="file"> control when the "multiple" attribute is used.
     8        This is consistent with the direction HTML5 will be going in the future.
     9
     10        The initial implementation here will show "n files" as the text next to the control when multiple files are selected.  You can view
     11        the individual files in a tooltip for now.  Improvements to this control will come later. 
     12
     13        Web developers will be able to access the FileList from the HTMLInputElement element, where they can get a base name and a size for each file. 
     14        These FileList Files can also be sent in an XMLHTTPRequest.
     15
     16        * manual-tests/post-multi-file-upload.html: Added.
     17        * manual-tests/resources/multiFileResources: Added.
     18        * manual-tests/resources/multiFileResources/post-echo-and-notify-done.cgi: Added.
     19        * manual-tests/resources/multiFileResources/testFile1.html: Added.
     20        * manual-tests/resources/multiFileResources/testFile2.html: Added.
     21        * manual-tests/resources/multiFileResources/testFile3.html: Added.
     22
     23        * WebCore.base.exp: Added support to export the new "chooseFilenames" method to be used in WebKit.
     24
     25        * html/HTMLInputElement.cpp:
     26        (WebCore::HTMLInputElement::parseMappedAttribute): Add support for the multiple attribute.
     27        (WebCore::HTMLInputElement::value): Added comments.  The HTML5 spec says that value shouldn't apply for the file upload control,
     28        but we don't want to break the behavior for existing websites that may rely on this.
     29        (WebCore::HTMLInputElement::setValue): ditto.
     30        (WebCore::HTMLInputElement::setValueFromRenderer): This is no longer used for file upload controls. setFileListFromRenderer is used instead.
     31        (WebCore::HTMLInputElement::setFileListFromRenderer): Added.
     32        * html/HTMLInputElement.h:
     33
     34        * page/Chrome.cpp: (WebCore::Chrome::setToolTip): Show a tooltip with the file name list for the multi-file upload control.
     35
     36        * page/DragController.cpp: (WebCore::DragController::concludeDrag): Updated to support multiple files.
     37
     38        * platform/FileChooser.cpp: Add support for maintaining a list of file paths that can be retrieved by the renderer.
     39        (WebCore::FileChooser::FileChooser):
     40        (WebCore::FileChooser::create):
     41        (WebCore::FileChooser::clear):
     42        (WebCore::FileChooser::chooseFile):
     43        (WebCore::FileChooser::chooseFiles):
     44        (WebCore::FileChooser::chooseIcon):
     45        * platform/FileChooser.h:
     46        (WebCore::FileChooser::filePaths):
     47        (WebCore::FileChooser::allowsMultipleFiles):
     48
     49        * platform/graphics/Icon.h:
     50        * platform/graphics/mac/IconMac.mm: (WebCore::Icon::newIconForFiles): Returns a generic icon for multiple files.
     51        * platform/graphics/gtk/IconGtk.cpp: (WebCore::Icon::newIconForFiles): stubbed out.
     52        * platform/graphics/qt/IconQt.cpp: (WebCore::Icon::newIconForFiles): ditto.
     53        * platform/graphics/win/IconWin.cpp: (WebCore::Icon::newIconForFiles): ditto.
     54
     55        * platform/gtk/FileChooserGtk.cpp: (WebCore::FileChooser::basenameForWidth):  Updated to deal with new filenames vector.
     56        * platform/mac/FileChooserMac.mm: (WebCore::FileChooser::basenameForWidth): ditto.
     57        * platform/qt/FileChooserQt.cpp:
     58        (WebCore::FileChooser::openFileChooser):
     59        (WebCore::FileChooser::basenameForWidth):
     60        * platform/win/FileChooserWin.cpp: (WebCore::FileChooser::basenameForWidth):
     61
     62        * platform/network/mac/FormDataStreamMac.mm: (WebCore::disassociateStreamWithResourceHandle):
     63        Removed unnecessary assertion.  This can get hit when connectionDidFinishLoading and cancel
     64        both get called for the same ResourceHandle.  This getting called twice has no negative effect.
     65
     66        * rendering/RenderFileUploadControl.cpp:
     67        (WebCore::RenderFileUploadControl::valueChanged):  Calls setFileListFromRenderer.
     68        (WebCore::RenderFileUploadControl::allowsMultipleFiles):  Added.
     69        (WebCore::RenderFileUploadControl::updateFromElement):  Uses the new filenames call from FileChooser.
     70        (WebCore::RenderFileUploadControl::receiveDroppedFiles):  Updated to support multiple files.
     71        * rendering/RenderFileUploadControl.h:
     72
    1732008-10-23  Peter Kasting  <pkasting@google.com>
    274
  • trunk/WebCore/WebCore.base.exp

    r37848 r37863  
    140140__ZN7WebCore11EditCommand7unapplyEv
    141141__ZN7WebCore11FileChooser10chooseFileERKNS_6StringE
     142__ZN7WebCore11FileChooser11chooseFilesERKN3WTF6VectorINS_6StringELm0EEE
    142143__ZN7WebCore11FileChooserD1Ev
    143144__ZN7WebCore11FrameLoader11completeURLERKNS_6StringE
     
    875876__ZNK7WebCore9TimerBase8isActiveEv
    876877__ZTVN7WebCore12ChromeClientE
     878__ZTVN7WebCore17FileChooserClientE
    877879_filenameByFixingIllegalCharacters
    878880_hasCaseInsensitiveSubstring
  • trunk/WebCore/html/HTMLInputElement.cpp

    r37589 r37863  
    699699               attr->name() == minAttr ||
    700700               attr->name() == maxAttr ||
    701                attr->name() == precisionAttr) {
     701               attr->name() == multipleAttr ||
     702               attr->name() == precisionAttr)
    702703        setChanged();
    703     } else
     704    else
    704705        HTMLFormControlElementWithState::parseMappedAttribute(attr);
    705706}
     
    951952String HTMLInputElement::value() const
    952953{
     954    // The HTML5 spec (as of the 10/24/08 working draft) says that the value attribute isn't applicable to the file upload control
     955    // but we don't want to break existing websites, who may be relying on being able to get the file name as a value.
    953956    if (inputType() == FILE) {
    954957        if (!m_fileList->isEmpty())
     
    10001003{
    10011004    // For security reasons, we don't allow setting the filename, but we do allow clearing it.
     1005    // The HTML5 spec (as of the 10/24/08 working draft) says that the value attribute isn't applicable to the file upload control
     1006    // but we don't want to break existing websites, who may be relying on this method to clear things.
    10021007    if (inputType() == FILE && !value.isEmpty())
    10031008        return;
     
    10371042    ASSERT(value == constrainValue(value) || constrainValue(value).isEmpty());
    10381043
     1044    // File upload controls will always use setFileListFromRenderer.
     1045    ASSERT (inputType() != FILE);
     1046
    10391047    if (isTextField())
    10401048        updatePlaceholderVisibility();
    10411049   
    1042     if (inputType() == FILE) {
    1043         m_fileList->clear();
    1044         m_fileList->append(File::create(value));
    1045     } else {
    1046         // Workaround for bug where trailing \n is included in the result of textContent.
    1047         // The assert macro above may also be simplified to:  value == constrainValue(value)
    1048         // http://bugs.webkit.org/show_bug.cgi?id=9661
    1049         if (value == "\n")
    1050             m_value = "";
    1051         else
    1052             m_value = value;
    1053     }
     1050    // Workaround for bug where trailing \n is included in the result of textContent.
     1051    // The assert macro above may also be simplified to:  value == constrainValue(value)
     1052    // http://bugs.webkit.org/show_bug.cgi?id=9661
     1053    if (value == "\n")
     1054        m_value = "";
     1055    else
     1056        m_value = value;
    10541057
    10551058    setValueMatchesRenderer();
     
    10571060    // Fire the "input" DOM event.
    10581061    dispatchEventForType(inputEvent, true, false);
     1062}
     1063
     1064void HTMLInputElement::setFileListFromRenderer(const Vector<String>& paths)
     1065{
     1066    m_fileList->clear();
     1067    int size = paths.size();
     1068    for (int i = 0; i < size; i++)
     1069        m_fileList->append(File::create(paths[i]));
     1070
     1071    setValueMatchesRenderer();
    10591072}
    10601073
  • trunk/WebCore/html/HTMLInputElement.h

    r37793 r37863  
    109109
    110110    void setValueFromRenderer(const String&);
     111    void setFileListFromRenderer(const Vector<String>&);
    111112
    112113    virtual bool saveState(String& value) const;
  • trunk/WebCore/page/Chrome.cpp

    r37628 r37863  
    2525#include "DNS.h"
    2626#include "Document.h"
     27#include "FileList.h"
    2728#include "FloatRect.h"
    2829#include "Frame.h"
     
    351352    }
    352353
    353     // Lastly we'll consider a tooltip for element with "title" attribute
     354    // Next we'll consider a tooltip for element with "title" attribute
    354355    if (toolTip.isEmpty())
    355356        toolTip = result.title();
    356357
     358    // Lastly, for <input type="file"> that allow multiple files, we'll consider a tooltip for the selected filenames
     359    if (toolTip.isEmpty()) {
     360        if (Node* node = result.innerNonSharedNode()) {
     361            if (node->hasTagName(inputTag)) {
     362                HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
     363                if (input->inputType() == HTMLInputElement::FILE) {
     364                    FileList* files = input->files();
     365                    unsigned listSize = files->length();
     366                    if (files && listSize > 1) {
     367                        Vector<UChar> names;
     368                        for (size_t i = 0; i < listSize; ++i) {
     369                            append(names, files->item(i)->fileName());
     370                            if (i != listSize - 1)
     371                                names.append('\n');
     372                        }
     373                        toolTip = String::adopt(names);
     374                    }
     375                }
     376            }
     377        }
     378    }
     379   
    357380    m_client->setToolTip(toolTip);
    358381}
  • trunk/WebCore/page/DragController.cpp

    r37534 r37863  
    381381            return false;
    382382       
    383         // Only take the first filename as <input type="file" /> can only accept one
    384         renderer->receiveDroppedFile(filenames[0]);
     383        renderer->receiveDroppedFiles(filenames);
    385384        return true;
    386385    }
  • trunk/WebCore/platform/FileChooser.cpp

    r30875 r37863  
    3636inline FileChooser::FileChooser(FileChooserClient* client, const String& filename)
    3737    : m_client(client)
    38     , m_filename(filename)
    3938    , m_icon(chooseIcon(filename))
    4039{
     40    m_filenames.append(filename);
    4141}
    4242
     
    5252void FileChooser::clear()
    5353{
    54     m_filename = String();
    55     m_icon = chooseIcon(m_filename);
     54    m_filenames.clear();
     55    m_icon = 0;
    5656}
    5757
    5858void FileChooser::chooseFile(const String& filename)
    5959{
    60     if (m_filename == filename)
     60    if (m_filenames.size() == 1 && m_filenames[0] == filename)
    6161        return;
    62     m_filename = filename;
     62    m_filenames.clear();
     63    m_filenames.append(filename);
    6364    m_icon = chooseIcon(filename);
     65    if (m_client)
     66        m_client->valueChanged();
     67}
     68
     69void FileChooser::chooseFiles(const Vector<String>& filenames)
     70{
     71    m_filenames = filenames;
     72    m_icon = chooseIcon(filenames);
    6473    if (m_client)
    6574        m_client->valueChanged();
     
    7180}
    7281
     82PassRefPtr<Icon> FileChooser::chooseIcon(Vector<String> filenames)
     83{
     84    if (filenames.size() == 1)
     85        return Icon::newIconForFile(filenames[0]);
     86    return Icon::newIconForFiles(filenames);
    7387}
     88
     89}
  • trunk/WebCore/platform/FileChooser.h

    r30875 r37863  
    3232
    3333#include "PlatformString.h"
     34#include <wtf/Vector.h>
    3435
    3536namespace WebCore {
     
    4344    virtual ~FileChooserClient() { }
    4445    virtual void valueChanged() = 0;
     46    virtual bool allowsMultipleFiles() = 0;
    4547};
    4648
     
    6062    void openFileChooser(Document*);
    6163
    62     const String& filename() const { return m_filename; }
     64    const Vector<String>& filenames() const { return m_filenames; }
    6365    String basenameForWidth(const Font&, int width) const;
    6466
     
    6769    void clear(); // for use by client; does not call valueChanged
    6870
    69     void chooseFile(const String& filename);
     71    void chooseFile(const String& path);
     72    void chooseFiles(const Vector<String>& paths);
     73   
     74    bool allowsMultipleFiles() const { return m_client ? m_client->allowsMultipleFiles() : false; }
    7075
    7176private:
    72     FileChooser(FileChooserClient*, const String& initialFilename);
     77    FileChooser(FileChooserClient*, const String& initialfilename);
    7378    static PassRefPtr<Icon> chooseIcon(const String& filename);
     79    static PassRefPtr<Icon> chooseIcon(Vector<String> filenames);
    7480
    7581    FileChooserClient* m_client;
    76     String m_filename;
     82    Vector<String> m_filenames;
    7783    RefPtr<Icon> m_icon;
    7884};
  • trunk/WebCore/platform/graphics/Icon.h

    r37776 r37863  
    2525#include <wtf/RefCounted.h>
    2626#include <wtf/Forward.h>
     27#include <wtf/Vector.h>
    2728
    2829#if PLATFORM(MAC)
     
    5253public:
    5354    static PassRefPtr<Icon> newIconForFile(const String& filename);
     55    static PassRefPtr<Icon> newIconForFiles(const Vector<String>& filenames);
     56
    5457    ~Icon();
    5558
  • trunk/WebCore/platform/graphics/gtk/IconGtk.cpp

    r37679 r37863  
    104104}
    105105
     106PassRefPtr<Icon> Icon::newIconForFiles(const Vector<String>& filenames)
     107{
     108    //FIXME: Implement this
     109    return 0;
     110}
     111
    106112void Icon::paint(GraphicsContext* context, const IntRect& rect)
    107113{
  • trunk/WebCore/platform/graphics/mac/IconMac.mm

    r34544 r37863  
    5454}
    5555
     56PassRefPtr<Icon> Icon::newIconForFiles(const Vector<String>& filenames)
     57{
     58    if (filenames.isEmpty())
     59        return 0;
     60
     61    NSImage* image = [NSImage imageNamed:NSImageNameMultipleDocuments];
     62    if (!image)
     63        return 0;
     64
     65    return adoptRef(new Icon(image));
     66}
     67
    5668void Icon::paint(GraphicsContext* context, const IntRect& rect)
    5769{
  • trunk/WebCore/platform/graphics/qt/IconQt.cpp

    r34544 r37863  
    4949}
    5050
     51PassRefPtr<Icon> Icon::newIconForFiles(const Vector<String>& filenames)
     52{
     53    //FIXME: Implement this
     54    return 0;
     55}
     56
    5157void Icon::paint(GraphicsContext* ctx, const IntRect& rect)
    5258{
  • trunk/WebCore/platform/graphics/win/IconWin.cpp

    r34544 r37863  
    5151}
    5252
     53PassRefPtr<Icon> Icon::newIconForFiles(const Vector<String>& filenames)
     54{
     55    //FIXME: Implement this
     56    return 0;
     57}
     58
    5359void Icon::paint(GraphicsContext* context, const IntRect& r)
    5460{
  • trunk/WebCore/platform/gtk/FileChooserGtk.cpp

    r37610 r37863  
    8585    String string = fileButtonNoFileSelectedLabel();
    8686
    87     if (!m_filename.isEmpty()) {
    88         gchar* systemFilename = filenameFromString(m_filename);
     87    if (m_filenames.size() == 1) {
     88        gchar* systemFilename = filenameFromString(m_filenames[0]);
    8989        gchar* systemBasename = g_path_get_basename(systemFilename);
    9090        g_free(systemFilename);
    9191        stringByAdoptingFileSystemRepresentation(systemBasename, string);
    92     }
     92    } else if (m_filenames.size() > 1)
     93        return StringTruncator::rightTruncate(String::number(m_filenames.size()) + " files", width, font, false);
    9394
    9495    return StringTruncator::centerTruncate(string, width, font, false);
  • trunk/WebCore/platform/mac/FileChooserMac.mm

    r30875 r37863  
    5959
    6060    String strToTruncate;
    61     if (m_filename.isEmpty())
     61    if (m_filenames.isEmpty())
    6262        strToTruncate = fileButtonNoFileSelectedLabel();
     63    else if (m_filenames.size() == 1)
     64        strToTruncate = [[NSFileManager defaultManager] displayNameAtPath:(m_filenames[0])];
    6365    else
    64         strToTruncate = [[NSFileManager defaultManager] displayNameAtPath:m_filename];
     66        return StringTruncator::rightTruncate(String::number(m_filenames.size()) + " files", width, font, false);
    6567
    6668    return StringTruncator::centerTruncate(strToTruncate, width, font, false);
  • trunk/WebCore/platform/network/mac/FormDataStreamMac.mm

    r37616 r37863  
    8484        return;
    8585
    86     ASSERT(getStreamResourceHandleMap().contains((CFReadStreamRef)stream));
    8786    getStreamResourceHandleMap().remove((CFReadStreamRef)stream);
    8887}
  • trunk/WebCore/platform/qt/FileChooserQt.cpp

    r30875 r37863  
    4343        return;
    4444
    45     QString f = fl->chooseFile(m_filename);
     45    QString f = fl->chooseFile(m_filenames[0]);
    4646    if (!f.isEmpty())
    4747        chooseFile(f);
     
    5151{
    5252    QFontMetrics fm(f.font());
    53     return fm.elidedText(m_filename, Qt::ElideLeft, width);
     53    return fm.elidedText(m_filenames[0], Qt::ElideLeft, width);
    5454}
    5555
  • trunk/WebCore/platform/win/FileChooserWin.cpp

    r37276 r37863  
    8181
    8282    String string;
    83     if (m_filename.isEmpty())
     83    if (m_filenames.isEmpty())
    8484        string = fileButtonNoFileSelectedLabel();
    85     else {
    86         String tmpFilename = m_filename;
     85    else if (m_filenames.size() == 1) {
     86        String tmpFilename = m_filenames[0];
    8787        LPTSTR basename = PathFindFileName(tmpFilename.charactersWithNullTermination());
    8888        string = String(basename);
    89     }
     89    } else
     90        return StringTruncator::rightTruncate(String::number(m_filenames.size()) + " files", width, font, false);
    9091
    9192    return StringTruncator::centerTruncate(string, width, font, false);
  • trunk/WebCore/rendering/RenderFileUploadControl.cpp

    r37637 r37863  
    2222#include "RenderFileUploadControl.h"
    2323
     24#include "FileList.h"
    2425#include "FrameView.h"
    2526#include "GraphicsContext.h"
     
    8788
    8889    HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(node());
    89     inputElement->setValueFromRenderer(fileChooser->filename());
     90    inputElement->setFileListFromRenderer(fileChooser->filenames());
    9091    inputElement->onChange();
    9192 
     
    9596}
    9697
     98bool RenderFileUploadControl::allowsMultipleFiles()
     99{
     100    HTMLInputElement* input = static_cast<HTMLInputElement*>(node());
     101    return !input->getAttribute(multipleAttr).isNull();
     102}
     103
    97104void RenderFileUploadControl::click()
    98105{
     
    103110{
    104111    HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(node());
    105 
     112    ASSERT(inputElement->inputType() == HTMLInputElement::FILE);
     113   
    106114    if (!m_button) {
    107115        m_button = new HTMLFileUploadInnerButtonElement(document(), inputElement);
     
    121129    m_button->setDisabled(!theme()->isEnabled(this));
    122130
    123     // This only supports clearing out the filename, but that's OK because for
     131    // This only supports clearing out the files, but that's OK because for
    124132    // security reasons that's the only change the DOM is allowed to make.
    125     if (inputElement->value().isEmpty() && !m_fileChooser->filename().isEmpty()) {
     133    FileList* files = inputElement->files();
     134    ASSERT(files);
     135    if (files && files->isEmpty() && !m_fileChooser->filenames().isEmpty()) {
    126136        m_fileChooser->clear();
    127137        repaint();
     
    252262}
    253263
    254 void RenderFileUploadControl::receiveDroppedFile(const String& filename)
    255 {
    256     m_fileChooser->chooseFile(filename);
     264void RenderFileUploadControl::receiveDroppedFiles(const Vector<String>& paths)
     265{
     266    if (allowsMultipleFiles())
     267        m_fileChooser->chooseFiles(paths);
     268    else
     269        m_fileChooser->chooseFile(paths[0]);
    257270}
    258271
  • trunk/WebCore/rendering/RenderFileUploadControl.h

    r37637 r37863  
    4848    void valueChanged();
    4949   
    50     void receiveDroppedFile(const String&);
     50    void receiveDroppedFiles(const Vector<String>&);
    5151
    5252    String buttonValue();
    5353    String fileTextValue();
     54   
     55    bool allowsMultipleFiles();
    5456
    5557protected:
  • trunk/WebKit/mac/ChangeLog

    r37848 r37863  
     12008-10-24  Adele Peterson  <adele@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        WebKit part of fix for <rdar://problem/5839256> FILE CONTROL: multi-file upload.
     6
     7        * WebCoreSupport/WebChromeClient.mm:
     8        (WebChromeClient::runOpenPanel):
     9        (-[WebOpenPanelResultListener chooseFilenames:]):
     10        * WebView/WebUIDelegate.h:
     11
    1122008-10-24  Timothy Hatcher  <timothy@apple.com>
    213
  • trunk/WebKit/mac/WebCoreSupport/WebChromeClient.mm

    r37371 r37863  
    5959#import <WebCore/WindowFeatures.h>
    6060#import <wtf/PassRefPtr.h>
     61#import <wtf/Vector.h>
    6162
    6263@interface NSView (WebNSViewDetails)
     
    547548{
    548549    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     550    BOOL allowMultipleFiles = chooser->allowsMultipleFiles();
    549551    WebOpenPanelResultListener *listener = [[WebOpenPanelResultListener alloc] initWithChooser:chooser];
    550     CallUIDelegate(m_webView, @selector(webView:runOpenPanelForFileButtonWithResultListener:), listener);
     552    id delegate = [m_webView UIDelegate];
     553    if ([delegate respondsToSelector:@selector(webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:)])
     554        CallUIDelegate(m_webView, @selector(webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:), listener, allowMultipleFiles);
     555    else
     556        CallUIDelegate(m_webView, @selector(webView:runOpenPanelForFileButtonWithResultListener:), listener);
    551557    [listener release];
    552558    END_BLOCK_OBJC_EXCEPTIONS;
     
    659665}
    660666
     667- (void)chooseFilenames:(NSArray *)filenames
     668{
     669    ASSERT(_chooser);
     670    if (!_chooser)
     671        return;
     672    int count = [filenames count];
     673    Vector<String> names(count);
     674    for (int i = 0; i < count; i++)
     675        names[i] = [filenames objectAtIndex:i];
     676    _chooser->chooseFiles(names);
     677    _chooser->deref();
     678    _chooser = 0;
     679}
     680
    661681@end
  • trunk/WebKit/mac/WebView/WebUIDelegate.h

    r37474 r37863  
    130130
    131131/*!
     132    @method chooseFilenames:
     133    @abstract Call this method to return an array of filenames from the file open panel.
     134    @param fileNames
     135*/
     136- (void)chooseFilenames:(NSArray *)fileNames AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
     137
     138/*!
    132139    @method cancel
    133140    @abstract Call this method to indicate that the file open panel was cancelled.
     
    403410*/
    404411- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener;
     412
     413/*!
     414    @method webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles
     415    @abstract Display a file open panel for a file input control that may allow multiple files to be selected.
     416    @param sender The WebView sending the delegate method.
     417    @param resultListener The object to call back with the results.
     418    @param allowMultipleFiles YES if the open panel should allow myltiple files to be selected, NO if not.
     419    @discussion This method is passed a callback object instead of giving a return
     420    value so that it can be handled with a sheet.
     421*/
     422- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener allowMultipleFiles:(BOOL)allowMultipleFiles WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_AFTER_WEBKIT_VERSION_3_1);
    405423
    406424/*!
Note: See TracChangeset for help on using the changeset viewer.