Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
      3  *           (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  *
     20  */
     21 
     22 #ifndef RenderTextControl_h
     23 #define RenderTextControl_h
     24 
     25 #include "RenderBlock.h"
     26 
     27 namespace WebCore {
     28 
     29 class VisibleSelection;
     30 class TextControlInnerElement;
     31 class TextControlInnerTextElement;
     32 
     33 class RenderTextControl : public RenderBlock {
     34 public:
     35     virtual ~RenderTextControl();
     36 
     37     bool wasChangedSinceLastChangeEvent() const { return m_wasChangedSinceLastChangeEvent; }
     38     void setChangedSinceLastChangeEvent(bool wasChangedSinceLastChangeEvent) { m_wasChangedSinceLastChangeEvent = wasChangedSinceLastChangeEvent; }
     39 
     40     bool lastChangeWasUserEdit() const { return m_lastChangeWasUserEdit; }
     41     void setLastChangeWasUserEdit(bool lastChangeWasUserEdit);
     42 
     43     int selectionStart();
     44     int selectionEnd();
     45     void setSelectionStart(int);
     46     void setSelectionEnd(int);
     47     void select();
     48     void setSelectionRange(int start, int end);
     49     VisibleSelection selection(int start, int end) const;
     50 
     51     virtual void subtreeHasChanged();
     52     String text();
     53     String textWithHardLineBreaks();
     54     void selectionChanged(bool userTriggered);
     55 
     56     VisiblePosition visiblePositionForIndex(int index);
     57     int indexForVisiblePosition(const VisiblePosition&);
     58 
     59     void updatePlaceholderVisibility(bool, bool);
     60 
     61 protected:
     62     RenderTextControl(Node*, bool);
     63 
     64     int scrollbarThickness() const;
     65     void adjustInnerTextStyle(const RenderStyle* startStyle, RenderStyle* textBlockStyle) const;
     66     void setInnerTextValue(const String&);
     67 
     68     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
     69 
     70     void createSubtreeIfNeeded(TextControlInnerElement* innerBlock);
     71     void hitInnerTextElement(HitTestResult&, int x, int y, int tx, int ty);
     72     void forwardEvent(Event*);
     73 
     74     int textBlockWidth() const;
     75     int textBlockHeight() const;
     76 
     77     virtual int preferredContentWidth(float charWidth) const = 0;
     78     virtual void adjustControlHeightBasedOnLineHeight(int lineHeight) = 0;
     79     virtual void cacheSelection(int start, int end) = 0;
     80     virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0;
     81     virtual RenderStyle* textBaseStyle() const = 0;
     82 
     83     virtual void updateFromElement();
     84     virtual void calcHeight();
     85 
     86     friend class TextIterator;
     87     HTMLElement* innerTextElement() const;
     88 
     89     bool m_placeholderVisible;
     90 
     91 private:
     92     virtual const char* renderName() const { return "RenderTextControl"; }
     93     virtual bool isTextControl() const { return true; }
     94     virtual bool hasControlClip() const { return false; }
     95     virtual IntRect controlClipRect(int tx, int ty) const;
     96     virtual void calcPrefWidths();
     97     virtual void removeLeftoverAnonymousBlock(RenderBlock*) { }
     98     virtual bool canHaveChildren() const { return false; }
     99     virtual bool avoidsFloats() const { return true; }
    100     void setInnerTextStyle(PassRefPtr<RenderStyle>);
    101 
    102     virtual void addFocusRingRects(Vector<IntRect>&, int tx, int ty);
    103 
    104     virtual bool canBeProgramaticallyScrolled(bool) const { return true; }
    105 
    106     String finishText(Vector<UChar>&) const;
    107 
    108     bool m_wasChangedSinceLastChangeEvent;
    109     bool m_lastChangeWasUserEdit;
    110     RefPtr<TextControlInnerTextElement> m_innerText;
    111 };
    112 
    113 inline RenderTextControl* toRenderTextControl(RenderObject* object)
    114 {
    115     ASSERT(!object || object->isTextControl());
    116     return static_cast<RenderTextControl*>(object);
    117 }
    118 
    119 inline const RenderTextControl* toRenderTextControl(const RenderObject* object)
    120 {
    121     ASSERT(!object || object->isTextControl());
    122     return static_cast<const RenderTextControl*>(object);
    123 }
    124 
    125 // This will catch anyone doing an unnecessary cast.
    126 void toRenderTextControl(const RenderTextControl*);
    127 
    128 } // namespace WebCore
    129 
    130 #endif // RenderTextControl_h
    131