Home | History | Annotate | Download | only in rendering
      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 computePreferredLogicalWidths();
     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     void receiveDropForDirectoryUpload(const Vector<String>&);
     68 #endif
     69     String acceptTypes();
     70     void chooseIconForFiles(FileChooser*, const Vector<String>&);
     71 #if ENABLE(MEDIA_CAPTURE)
     72     String capture();
     73 #endif
     74 
     75     Chrome* chrome() const;
     76     int maxFilenameWidth() const;
     77     PassRefPtr<RenderStyle> createButtonStyle(const RenderStyle* parentStyle) const;
     78 
     79     virtual VisiblePosition positionForPoint(const IntPoint&);
     80 
     81     RefPtr<HTMLInputElement> m_button;
     82     RefPtr<FileChooser> m_fileChooser;
     83 };
     84 
     85 inline RenderFileUploadControl* toRenderFileUploadControl(RenderObject* object)
     86 {
     87     ASSERT(!object || object->isFileUploadControl());
     88     return static_cast<RenderFileUploadControl*>(object);
     89 }
     90 
     91 inline const RenderFileUploadControl* toRenderFileUploadControl(const RenderObject* object)
     92 {
     93     ASSERT(!object || object->isFileUploadControl());
     94     return static_cast<const RenderFileUploadControl*>(object);
     95 }
     96 
     97 // This will catch anyone doing an unnecessary cast.
     98 void toRenderFileUploadControl(const RenderFileUploadControl*);
     99 
    100 } // namespace WebCore
    101 
    102 #endif // RenderFileUploadControl_h
    103