WebCore/rendering/RenderFileUploadControl.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
       
     3  *
       
     4  * This library is free software; you can redistribute it and/or
       
     5  * modify it under the terms of the GNU Library General Public
       
     6  * License as published by the Free Software Foundation; either
       
     7  * version 2 of the License, or (at your option) any later version.
       
     8  *
       
     9  * This library is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    12  * Library General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU Library General Public License
       
    15  * along with this library; see the file COPYING.LIB.  If not, write to
       
    16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    17  * Boston, MA 02110-1301, USA.
       
    18  *
       
    19  */
       
    20 
       
    21 #ifndef RenderFileUploadControl_h
       
    22 #define RenderFileUploadControl_h
       
    23 
       
    24 #include "FileChooser.h"
       
    25 #include "RenderBlock.h"
       
    26 
       
    27 namespace WebCore {
       
    28 
       
    29 class Chrome;
       
    30 class HTMLInputElement;
       
    31     
       
    32 // Each RenderFileUploadControl contains a RenderButton (for opening the file chooser), and
       
    33 // sufficient space to draw a file icon and filename. The RenderButton has a shadow node
       
    34 // associated with it to receive click/hover events.
       
    35 
       
    36 class RenderFileUploadControl : public RenderBlock, private FileChooserClient {
       
    37 public:
       
    38     RenderFileUploadControl(HTMLInputElement*);
       
    39     virtual ~RenderFileUploadControl();
       
    40 
       
    41     virtual bool isFileUploadControl() const { return true; }
       
    42 
       
    43     void click();
       
    44 
       
    45     void receiveDroppedFiles(const Vector<String>&);
       
    46 
       
    47     String buttonValue();
       
    48     String fileTextValue() const;
       
    49     
       
    50 private:
       
    51     virtual const char* renderName() const { return "RenderFileUploadControl"; }
       
    52 
       
    53     virtual void updateFromElement();
       
    54     virtual void calcPrefWidths();
       
    55     virtual void paintObject(PaintInfo&, int tx, int ty);
       
    56 
       
    57     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
       
    58 
       
    59     virtual bool requiresForcedStyleRecalcPropagation() const { return true; }
       
    60 
       
    61     // FileChooserClient methods.
       
    62     void valueChanged();
       
    63     void repaint() { RenderBlock::repaint(); }
       
    64     bool allowsMultipleFiles();
       
    65 #if ENABLE(DIRECTORY_UPLOAD)
       
    66     bool allowsDirectoryUpload();
       
    67 #endif
       
    68     String acceptTypes();
       
    69     void chooseIconForFiles(FileChooser*, const Vector<String>&);
       
    70 
       
    71     Chrome* chrome() const;
       
    72     int maxFilenameWidth() const;
       
    73     PassRefPtr<RenderStyle> createButtonStyle(const RenderStyle* parentStyle) const;
       
    74 
       
    75     RefPtr<HTMLInputElement> m_button;
       
    76     RefPtr<FileChooser> m_fileChooser;
       
    77 };
       
    78 
       
    79 inline RenderFileUploadControl* toRenderFileUploadControl(RenderObject* object)
       
    80 {
       
    81     ASSERT(!object || object->isFileUploadControl());
       
    82     return static_cast<RenderFileUploadControl*>(object);
       
    83 }
       
    84 
       
    85 inline const RenderFileUploadControl* toRenderFileUploadControl(const RenderObject* object)
       
    86 {
       
    87     ASSERT(!object || object->isFileUploadControl());
       
    88     return static_cast<const RenderFileUploadControl*>(object);
       
    89 }
       
    90 
       
    91 // This will catch anyone doing an unnecessary cast.
       
    92 void toRenderFileUploadControl(const RenderFileUploadControl*);
       
    93 
       
    94 } // namespace WebCore
       
    95 
       
    96 #endif // RenderFileUploadControl_h