webkit源码解读-FileList

13 篇文章 0 订阅

FileList是文件组件的表示形式,是一个包装了系列File对象的对象。里面通过vector保持多个文件对象。

class FileList : public ScriptWrappable, public RefCounted<FileList> {
public:
    // 需要用create创建该类对象
    static Ref<FileList> create()
    {   // adoptRef是RefPtr中的函数,实现管理该对象的引用问题。这些不影响理解。
        return adoptRef(*new FileList);
    }

    static Ref<FileList> create(Vector<RefPtr<File>>&& files)
    {   // adoptRef需要的是引用类型,需要要加*,WTFMove,WTF是web template framework简称,move是c++ std中提供的东西。
        return adoptRef(*new FileList(WTFMove(files)));
    }
    // 返回文件长度,简单调用vector的size实现
    unsigned length() const { return m_files.size(); }
    // 返回某个文件对象,见cpp文件
    WEBCORE_EXPORT File* item(unsigned index) const;
    // 判断文件列表是否为空,简单调用vector对象的isEmpty
    bool isEmpty() const { return m_files.isEmpty(); }
    // 返回所有文件的路径,见cpp文件
    Vector<String> paths() const;

private:
    // 不需要显示调用构造函数创建该类对象
    FileList();
    FileList(Vector<RefPtr<File>>&& files)
    // 初始化m_files变量
        : m_files(WTFMove(files))
    { }

    // FileLists can only be changed by their owners.
    friend class DataTransfer;
    friend class FileInputType;
    // 追加文件
    void append(RefPtr<File>&& file) { m_files.append(WTFMove(file)); }
    // 删除所有文件
    void clear() { m_files.clear(); }
    // 是一个类似数组的vector,里面是一系列RefPtr对象,RefPtr对象负责管理File对象的引用问题。
    Vector<RefPtr<File>> m_files;
};

FileList.cpp

namespace WebCore {

FileList::FileList()
{
}
// 返回某个文件对象
File* FileList::item(unsigned index) const
{
    if (index >= m_files.size())
        return 0;
    return m_files[index].get();
}
// 返回所有文件的路径
Vector<String> FileList::paths() const
{
    Vector<String> paths;
    for (unsigned i = 0; i < m_files.size(); ++i)
        paths.append(m_files[i]->path());
    return paths;
}

} // namespace WebCore
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值