Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 2009 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef DataGridColumn_h
     27 #define DataGridColumn_h
     28 
     29 #if ENABLE(DATAGRID)
     30 
     31 #include "RenderStyle.h"
     32 #include <wtf/PassRefPtr.h>
     33 #include <wtf/RefCounted.h>
     34 #include <wtf/text/AtomicString.h>
     35 
     36 namespace WebCore {
     37 
     38 class DataGridColumnList;
     39 
     40 class DataGridColumn : public RefCounted<DataGridColumn> {
     41 public:
     42     static PassRefPtr<DataGridColumn> create(const String& columnID, const String& label, const String& type, bool primary, unsigned short sortable)
     43     {
     44         return adoptRef(new DataGridColumn(columnID, label, type, primary, sortable));
     45     }
     46 
     47     const AtomicString& id() const { return m_id; }
     48     void setId(const AtomicString& id) { m_id = id; columnChanged(); }
     49 
     50     const AtomicString& label() const { return m_label; }
     51     void setLabel(const AtomicString& label) { m_label = label; columnChanged(); }
     52 
     53     const AtomicString& type() const { return m_type; }
     54     void setType(const AtomicString& type) { m_type = type; columnChanged(); }
     55 
     56     unsigned short sortable() const { return m_sortable; }
     57     void setSortable(unsigned short sortable) { m_sortable = sortable; columnChanged(); }
     58 
     59     unsigned short sortDirection() const { return m_sortDirection; }
     60     void setSortDirection(unsigned short sortDirection) { m_sortDirection = sortDirection; columnChanged(); }
     61 
     62     bool primary() const { return m_primary; }
     63     void setPrimary(bool);
     64 
     65     void setColumnList(DataGridColumnList* list)
     66     {
     67         m_columns = list;
     68         m_columnStyle = 0;
     69         m_headerStyle = 0;
     70         m_rect = IntRect();
     71     }
     72 
     73     RenderStyle* columnStyle() const { return m_columnStyle.get(); }
     74     void setColumnStyle(PassRefPtr<RenderStyle> style) { m_columnStyle = style; }
     75 
     76     RenderStyle* headerStyle() const { return m_headerStyle.get(); }
     77     void setHeaderStyle(PassRefPtr<RenderStyle> style) { m_headerStyle = style; }
     78 
     79     const IntRect& rect() const { return m_rect; }
     80     void setRect(const IntRect& rect) { m_rect = rect; }
     81 
     82 private:
     83     DataGridColumn(const String& columnID, const String& label, const String& type, bool primary, unsigned short sortable)
     84         : m_columns(0)
     85         , m_id(columnID)
     86         , m_label(label)
     87         , m_type(type)
     88         , m_primary(primary)
     89         , m_sortable(sortable)
     90         , m_sortDirection(0)
     91     {
     92     }
     93 
     94     void columnChanged();
     95 
     96     DataGridColumnList* m_columns; // Not refcounted.  The columns list will null out our reference when it goes away.
     97 
     98     AtomicString m_id;
     99     AtomicString m_label;
    100     AtomicString m_type;
    101 
    102     bool m_primary;
    103 
    104     unsigned short m_sortable;
    105     unsigned short m_sortDirection;
    106 
    107     RefPtr<RenderStyle> m_columnStyle; // The style used to render the column background behind the row cells.
    108     RefPtr<RenderStyle> m_headerStyle; // The style used to render the column header above the row cells.
    109 
    110     IntRect m_rect;
    111 };
    112 
    113 } // namespace WebCore
    114 
    115 #endif
    116 
    117 #endif // DataGridColumn_h
    118