khtml_caret_p.h
来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 1,110 行 · 第 1/3 页
H
1,110 行
/** constructs a new caret box line out of the given inline flow box * @param deleter deleter which handles alloc+dealloc of the object * @param baseFlowBox basic flow box which to create a caret line box from * @param seekBox seek this box within the constructed line * @param seekOutside denoting whether position is outside of seekBox * @param seekOutsideEnd whether at the outside end of seekBox * @param iter returns an iterator that corresponds to seekBox. If no suitable * caret box exists, it will return end() * @param seekObject seek this render object within the constructed line. * It will only be regarded if \c seekBox is 0. \c iter will then point * to the first caret box whose render object matches. */ static CaretBoxLine *constructCaretBoxLine(MassDeleter<CaretBoxLine> *deleter, InlineFlowBox *baseFlowBox, InlineBox *seekBox, bool seekOutside, bool seekOutsideEnd, CaretBoxIterator &iter, RenderObject *seekObject = 0) /*KDE_NO_EXPORT*/; /** constructs a new caret box line for the given render block. * @param deleter deleter which handles alloc+dealloc of the object * @param cb render block or render replaced * @param outside true when line is to be constructed outside * @param outsideEnd true when the ending outside is meant * @param iter returns the iterator to the caret box representing the given * position for \c cb */ static CaretBoxLine *constructCaretBoxLine(MassDeleter<CaretBoxLine> *deleter, RenderBox *cb, bool outside, bool outsideEnd, CaretBoxIterator &iter) /*KDE_NO_EXPORT*/;#if DEBUG_CARETMODE > 0 void dump(QTextStream &ts, const QString &ind) const; QString information() const { QString result; QTextStream ts(&result, IO_WriteOnly); dump(ts, QString::null); return result; }#endifprotected: /** contains the seek parameters */ struct SeekBoxParams { InlineBox *box; bool outside; bool outsideEnd; bool found; RenderObject *r; // if box is 0, seek for equal render objects instead CaretBoxIterator ⁢ SeekBoxParams(InlineBox *box, bool outside, bool outsideEnd, RenderObject *obj, CaretBoxIterator &it) : box(box), outside(outside), outsideEnd(outsideEnd), found(false), r(obj), it(it) {} /** compares whether this seek box matches the given specification */ bool equalsBox(const InlineBox *box, bool outside, bool outsideEnd) const { return (this->box && this->box == box || this->r == box->object()) && this->outside == outside && (!this->outside || this->outsideEnd == outsideEnd); } /** compares whether this seek box matches the given caret box */ bool operator ==(const CaretBox *cbox) const { return equalsBox(cbox->inlineBox(), cbox->isOutside(), cbox->isOutsideEnd()); } /** checks whether this box matches the given iterator. * * On success, it sets \c found, and assigns the iterator to \c it. * @return true on match */ bool check(const CaretBoxIterator &chit) { if (*this == *chit) { Q_ASSERT(!found); found = true; it = chit; } return found; } }; /** recursively converts the given inline box into caret boxes and adds them * to this caret box line. * * It will additionally look for the caret box specified in SeekBoxParams. */ void addConvertedInlineBox(InlineBox *, SeekBoxParams &) /*KDE_NO_EXPORT*/; /** creates and adds the edge of a generic inline box * @param box inline box * @param fm font metrics of inline box * @param left true to add left edge, false to add right edge * @param rtl true if direction is rtl */ void addCreatedInlineBoxEdge(InlineBox *box, const QFontMetrics &fm, bool left, bool rtl) /*KDE_NO_EXPORT*/; /** creates and adds the edge of an inline flow box * @param flowBox inline flow box * @param fm font metrics of inline flow box * @param left true to add left edge, false to add right edge * @param rtl true if direction is rtl */ void addCreatedFlowBoxEdge(InlineFlowBox *flowBox, const QFontMetrics &fm, bool left, bool rtl) /*KDE_NO_EXPORT*/; /** creates and adds the inside of an inline flow box * @param flowBox inline flow box * @param fm font metrics of inline flow box */ void addCreatedFlowBoxInside(InlineFlowBox *flowBox, const QFontMetrics &fm) /*KDE_NO_EXPORT*/; friend class CaretBoxIterator;};typedef MassDeleter<CaretBoxLine> CaretBoxLineDeleter;inline CaretBox *CaretBoxIterator::data() const { return cbl->caret_boxes[index]; }/** * Iterates through the lines of a document. * * The line iterator becomes invalid when the associated LinearDocument object * is destroyed. * @since 3.2 * @internal * @author Leo Savernik */class LineIterator{protected: LinearDocument *lines; // associated document CaretBoxLine *cbl; // current caret box line static CaretBoxIterator currentBox; // current inline box static long currentOffset; // Note: cbl == 0 indicates a position beyond the beginning or the // end of a document. /** Default constructor, only for internal use */ LineIterator() {} /** Initializes a new iterator. * * Note: This constructor neither cares about the correctness of @p node * nor about @p offset. It is the responsibility of the caller to ensure * that both point to valid places. */ LineIterator(LinearDocument *l, DOM::NodeImpl *node, long offset);public: /** dereferences current caret box line. * * @returns the caret line box or 0 if end of document */ CaretBoxLine *operator *() const { return cbl; } /** returns the associated linear document */ LinearDocument *linearDocument() const { return lines; } /** seek next line * * Guaranteed to crash if beyond beginning/end of document. */ LineIterator &operator ++() { advance(false); return *this; } /** seek previous line. * * Guaranteed to crash if beyond beginning/end of document. */ LineIterator &operator --() { advance(true); return *this; } /** compares two iterators. The comparator actually works only for * comparing arbitrary iterators to begin() and end(). */ bool operator ==(const LineIterator &it) const { return lines == it.lines && cbl == it.cbl; } /** compares two iterators */ bool operator !=(const LineIterator &it) const { return !operator ==(it); } /** Returns whether this line represents the outside end of the containing * block. * * This result can only be relied on when isOutside is true. */ bool isOutsideEnd() { return cbl->isOutsideEnd(); } /** Tells whether the offset is meant to be outside or inside the * containing block. */ bool isOutside() const { return cbl->isOutside(); } /** advances to the line to come. * @param toBegin true, move to previous line, false, move to next line. */ void advance(bool toBegin); /** Whenever a new line iterator is created, it gets a caret box created. * For memory reasons, it's saved in a static instance, * thus making this function not thread-safe. * * This value can only be trusted immediately after having instantiated * a line iterator or one of its derivatives. * @return an iterator onto the corresponing caret box within the * line represented by the last instantiation of a line iterator, * or 0 if there was none. */ static CaretBoxIterator ¤tCaretBox() { return currentBox; } /** Whenever a new line iterator is created, it calculates a modified offset * that is to be used with respect to the current render object. * This offset can be queried with this function. * * This value can only be trusted immediately after having instantiated * a line iterator or one of its derivatives. * @return the modified offset. */ static long currentModifiedOffset() { return currentOffset; }protected: /** seeks next block. */ void nextBlock(); /** seeks previous block. */ void prevBlock(); friend class CaretBoxIterator; friend class EditableLineIterator; friend class EditableCaretBoxIterator; friend class EditableCharacterIterator; friend class LinearDocument;};/** * Represents the whole document in terms of lines. * * SGML documents are trees. But for navigation, this representation is * not practical. Therefore this class serves as a helper to represent the * document as a linear list of lines. Its usage somewhat resembles STL * semantics like begin and end as well as iterators. * * The lines itself are represented as caret line boxes. * * LinearDocument instances are not meant to be kept over the lifetime of their * associated document, but constructed from (node, offset) pairs whenever line * traversal is needed. This is because the underlying InlineFlowBox objects * may be destroyed and recreated (e. g. by resizing the window, adding/removing * elements). * * @author Leo Savernik * @since 3.2 * @internal */class LinearDocument {public: typedef LineIterator Iterator; /** * Creates a new instance, and initializes it to the line specified by * the parameters below. * * Creation will fail if @p node is invisible or defect. * @param part part within which everything is taking place. * @param node document node with which to start * @param offset zero-based offset within this node. * @param advancePolicy caret advance policy * @param baseElem base element which the caret must not advance beyond * (0 means whole document). The base element will be ignored if it * cannot serve as a base (to see if this is the case, check whether * LinearDocument::baseFlow()->element() != base) */ LinearDocument(KHTMLPart *part, DOM::NodeImpl *node, long offset, CaretAdvancePolicy advancePolicy, DOM::ElementImpl *baseElem); virtual ~LinearDocument(); /** * Tells whether this list contains any lines. * * @returns @p true if this document contains lines, @p false otherwise. Note * that an empty document contains at least one line, so this method * only returns @p false if the document could not be initialised for * some reason. */ bool isValid() const // FIXME: not yet impl'd { return true; } /** * Returns the count of lines. * * Warning: This function is expensive. Call it once and cache the value. * * FIXME: It's not implemented yet (and maybe never will) */ int count() const; /** * Returns a line iterator containing the current position as its starting * value. */ Iterator current(); /** * Returns a line iterator pointing right after the end of the document. */ const Iterator &end() const { return _end; } /** * Returns a line iterator pointing to the very last line of the document. */ Iterator preEnd(); /** * Returns a line iterator pointing to the very first line of the document. */ Iterator begin(); /** * Returns a line iterator pointing just before the very first line of the * document (this is somewhat an emulation of reverse iterators). */ const Iterator &preBegin() const { return _preBegin; } /** * Returns the current caret advance policy */ CaretAdvancePolicy advancePolicy() const { return advPol; } /** * Returns the base render object which the caret must not advance beyond. * * Note that HTML documents are usually restricted to the body element. * * @return the base render object or 0 if the whole document is valid. */ RenderObject *baseObject() const { return base; }protected: void initPreBeginIterator(); void initEndIterator();protected: CaretBoxLineDeleter cblDeleter; // mass deleter for caret box lines DOM::NodeImpl *node; long offset; Iterator _preBegin; Iterator _end; KHTMLPart *m_part; CaretAdvancePolicy advPol; RenderObject *base; friend class LineIterator; friend class EditableLineIterator; friend class ErgonomicEditableLineIterator; friend class CaretBoxIterator;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?