khtml_caret_p.h

来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 1,110 行 · 第 1/3 页

H
1,110
字号
  friend class EditableCaretBoxIterator;  friend class EditableCharacterIterator;};/** * Iterates over the editable inner elements of a caret line box. * * The incrementor will traverse all caret boxes according to the associated * linear document's caret advance policy. In contrast to \c CaretBoxIterator * this iterator only regards caret boxes which are editable. * * @author Leo Savernik * @internal * @since 3.3 */class EditableCaretBoxIterator : public CaretBoxIterator {  KHTMLPart *m_part;  bool adjacent;  CaretAdvancePolicy advpol;	// caret advance policypublic:  /** initializes a new iterator from the given line iterator,   * beginning with the given caret box iterator, if specified   */  EditableCaretBoxIterator(LineIterator &lit, bool fromEnd = false,  		CaretBoxIterator *it = 0)  		: CaretBoxIterator(it ? *it : (fromEnd ? (*lit)->end() : (*lit)->preBegin())),                m_part(lit.lines->m_part), adjacent(false),                advpol(lit.lines->advancePolicy())  {    if (!it) {      if (fromEnd) --*this; else ++*this;    }  }  /** empty constructor. Use only to copy another iterator into this one.   */  EditableCaretBoxIterator() {}  /** returns @p true when the current caret box is adjacent to the   * previously iterated caret box, i. e. no intervening caret boxes.   */  bool isAdjacent() const { return adjacent; }  /** increments the iterator to point to the next editable caret box.   */  EditableCaretBoxIterator &operator ++() { advance(false); return *this; }  /** decrements the iterator to point to the previous editable caret box.   */  EditableCaretBoxIterator &operator --() { advance(true); return *this; }  /** advances to the editable caret box to come   * @param toBegin true, move towards beginning, false, move towards end.   */  void advance(bool toBegin);protected:  /** finds out if the given box is editable.   * @param boxit iterator to given caret box   * @param fromEnd true when advancing towards the beginning   * @return @p true if box is editable   */  bool isEditable(const CaretBoxIterator &boxit, bool fromEnd);};/** * Iterates through the editable lines of a document. * * This iterator, opposing to @p LineIterator, only regards editable lines. * Additionally, this iterator enforces the caret advance policy. * * The iterator can be compared to normal LineIterators, especially to * @ref LinearDocument::preBegin and @ref LinearDocument::end * * The line iterator becomes invalid when the associated LinearDocument object * is destroyed. * @since 3.2 * @internal * @author Leo Savernik */class EditableLineIterator : public LineIterator {public:  /** Initializes a new iterator.   *   * The iterator is set to the first following editable line or to the   * end if no editable line follows.   * @param it a line iterator to initialize this from   * @param fromEnd @p true, traverse towards the beginning in search of an   *	editable line   */  EditableLineIterator(const LineIterator &it, bool fromEnd = false)  		: LineIterator(it)  {    if (!cbl) return;    if (!isEditable(*this)) advance(fromEnd);  }  /** empty constructor.   *   * Only use if you want to copy another iterator onto it later.   */  EditableLineIterator() {}  /** seek next line   *   * Guaranteed to crash if beyond beginning/end of document.   */  EditableLineIterator &operator ++() { advance(false); return *this; }  /** seek previous line.   *   * Guaranteed to crash if beyond beginning/end of document.   */  EditableLineIterator &operator --() { advance(true); return *this; }  /** advances to the line to come.   * @param toBegin true, move to previous line, false, move to next line.   */  void advance(bool toBegin);protected:  /** finds out if the current line is editable.   *   * @param it check caret box line iterator points to   * @return @p true if line is editable   */  bool isEditable(LineIterator &it)  {    EditableCaretBoxIterator fbit = it;    return fbit != (*it)->end();  }};/** Represents a render table as a linear list of rows. * * This iterator abstracts from table sections and treats tables as a linear * representation of all rows they contain. * @author Leo Savernik * @internal * @since 3.2 */class TableRowIterator {protected:  TableSectionIterator sec;	// current section  int index;			// index of row within sectionpublic:  /** Constructs a new iterator.   * @param table table to iterate through.   * @param fromEnd @p true to iterate towards the beginning   * @param row pointer to row to start with, 0 starts at the first/last   *	row.   */  TableRowIterator(RenderTable *table, bool fromEnd = false,  		RenderTableSection::RowStruct *row = 0);  /** Constructs a new iterator.   * @param section table section to begin with   * @param index index within table section   */  TableRowIterator(RenderTableSection *section, int index)  	: sec(section), index(index)  {}  /** empty constructor. This must be assigned another iterator before it is   * useable.   */  TableRowIterator() {}  /** returns the current table row.   * @return the row or 0 if the end of the table has been reached.   */  RenderTableSection::RowStruct *operator *()  {    if (!*sec) return 0;    return &(*sec)->grid[index];  }  /** advances to the next row   */  TableRowIterator &operator ++();  /** advances to the previous row   */  TableRowIterator &operator --();protected:};/** Iterates through the editable lines of a document, in a topological order. * * The differences between this and the EditableLineIterator lies in the way * lines are inquired. While the latter steps through the lines in document * order, the former takes into consideration ergonomics. * * This is especially useful for tables. EditableLineIterator traverses all * table cells from left to right, top to bottom, while this one will * actually snap to the cell in the right position, and traverse only * upwards/downwards, thus providing a more intuitive navigation. * * @author Leo Savernik * @internal * @since 3.2 */class ErgonomicEditableLineIterator : public EditableLineIterator {protected:  int xCoor;		// x-coordinate to determine cell positionpublic:  /** Initializes a new ergonomic editable line iterator from the given one.   * @param it line iterator   * @param x absolute x-coordinate for cell determination   */  ErgonomicEditableLineIterator(const LineIterator &it, int x)  	: EditableLineIterator(it), xCoor(x) {}  /** Constructs an uninitialized iterator which must be assigned a line iterator before   * it can be used.   */  ErgonomicEditableLineIterator() {}  /** seek next line.   *   * The next line will be one that is visually situated below this line.   */  ErgonomicEditableLineIterator &operator ++();  /** seek previous line.   *   * The previous line will be one that is visually situated above this line.   */  ErgonomicEditableLineIterator &operator --();protected:  /** determines the topologically next render object.   * @param oldCell table cell the original object was under.   * @param newObject object to determine whether and which transition   *	between cells is to be handled. It does not have to be an object in the correct   *	topological cell, a simple delivery from an editable line iterator suffices.   * @param toBegin if @p true, iterate towards the beginning   */  void determineTopologicalElement(RenderTableCell *oldCell,  		RenderObject *newObject, bool toBegin);  /** initializes the iterator to point to the first previous/following editable   * line.   * @param newBlock take this as base block.   * @param toBegin @p true, iterate towards beginning.   */  void calcAndStoreNewLine(RenderBlock *newBlock, bool toBegin);};/** * Provides iterating through the document in terms of characters. Only the * editable characters are regarded. * * This iterator represents the document, which is structured as a tree itself, * as a linear stream of characters. */class EditableCharacterIterator {protected:  EditableLineIterator _it;  EditableCaretBoxIterator ebit;  long _offset;		// offset within current caret box.  int _char;  bool _end:1;		// true when end of document has been reachedpublic:  /** empty constructor.   *   * Only use if you want to assign another iterator as no fields will   * be initialized.   */  EditableCharacterIterator() {}  /** constructs a new iterator from the given linear document.   *   * @param ld linear representation of document.   */  EditableCharacterIterator(LinearDocument *ld)  		: _it(ld->current()),                ebit(_it, false, &_it.currentCaretBox()),      		_offset(_it.currentModifiedOffset()), _char(-1), _end(false)  {    // ### temporary fix for illegal nodes    if (_it == ld->end()) { _end = true; return; }    initFirstChar();  }  /** returns the current character, or -1 if not on a text node, or beyond   * the end.   */  int chr() const { return _char; }  /** returns the current character as a unicode symbol, substituting   * a blank for a non-text node.   */  QChar operator *() const { return QChar(_char >= 0 ? _char : ' '); }  /** returns true when the end of the document has been reached.   */  bool isEnd() const { return _end; }  /** returns the current offset   */  long offset() const { return _offset; }  /** returns the current render object.   */  RenderObject *renderer() const { return (*ebit)->object(); }  /** returns the current caret box.   *   * Will crash if beyond end.   */  CaretBox *caretBox() const { return *ebit; }  /** returns the current inline box.   *   * May be 0 if the current element has none, or if the end has been reached.   * Therefore, do *not* use this to test for the end condition, use node()   * instead.   */  InlineBox *inlineBox() const { return (*ebit)->inlineBox(); }  /** returns whether the current line box represents the outside of its   * render object.   *///  bool boxIsOutside() const { return _it.isOutside(); }  /** moves to the next editable character.   */  EditableCharacterIterator &operator ++();  /** moves to the previous editable character.   */  EditableCharacterIterator &operator --();protected:  /** initializes the _char member by reading the character at the current   * offset, peeking ahead as necessary.   */  void initFirstChar();  /** reads ahead the next node and updates the data structures accordingly   */  void peekNext()  {    EditableCaretBoxIterator copy = ebit;    ++copy;    if (copy == (*_it)->end()) { _char = -1; return; }    CaretBox *box = *copy;    InlineBox *b = box->inlineBox();    if (b && !box->isOutside() && b->isInlineTextBox())      _char = static_cast<RenderText *>(b->object())->str->s[b->minOffset()].unicode();    else      _char = -1;  }  /** reads ahead the previous node and updates the data structures accordingly   */  void peekPrev()  {    --ebit;  }};}/*namespace khtml*/#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?