File indexing completed on 2024-11-10 09:38:55

0001 /**
0002  * This file is part of the DOM implementation for KDE.
0003  *
0004  * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  *
0021  */
0022 #include "render_br.h"
0023 
0024 using namespace khtml;
0025 using DOM::Position;
0026 
0027 RenderBR::RenderBR(DOM::NodeImpl *node)
0028     : RenderText(node, new DOM::DOMStringImpl(QChar('\n')))
0029 {
0030     m_hasReturn = true;
0031 }
0032 
0033 RenderBR::~RenderBR()
0034 {
0035 }
0036 
0037 long RenderBR::caretMinOffset() const
0038 {
0039     return 0;
0040 }
0041 
0042 long RenderBR::caretMaxOffset() const
0043 {
0044     return 1;
0045 }
0046 
0047 unsigned long RenderBR::caretMaxRenderedOffset() const
0048 {
0049     return 1;
0050 }
0051 
0052 RenderPosition RenderBR::positionForCoordinates(int /*_x*/, int /*_y*/)
0053 {
0054     return RenderPosition(element(), 0);
0055 }
0056 
0057 #if 0
0058 void RenderBR::caretPos(int offset, int flags, int &_x, int &_y, int &width, int &height) const
0059 {
0060     RenderText::caretPos(offset, flags, _x, _y, width, height);
0061     return;
0062 #if 0
0063     if (previousSibling() && !previousSibling()->isBR() && !previousSibling()->isFloating()) {
0064         int offset = 0;
0065         if (previousSibling()->isText()) {
0066             offset = static_cast<RenderText *>(previousSibling())->maxOffset();
0067         }
0068 
0069         // FIXME: this won't return a big width in override mode (LS)
0070         previousSibling()->caretPos(offset, override, _x, _y, width, height);
0071         return;
0072     }
0073 
0074     int absx, absy;
0075     absolutePosition(absx, absy);
0076     if (absx == -1) {
0077         // we don't know out absolute position, and there is no point returning
0078         // just a relative one
0079         _x = _y = -1;
0080     } else {
0081         _x += absx;
0082         _y += absy;
0083     }
0084     height = RenderText::verticalPositionHint(false);
0085     width = override ? height / 2 : 1;
0086 #endif
0087 }
0088 #endif
0089 
0090 FindSelectionResult RenderBR::checkSelectionPoint(int _x, int _y, int _tx, int _ty, DOM::NodeImpl *&node, int &offset, SelPointState &state)
0091 {
0092     // Simply take result of previous one
0093     RenderText *prev = static_cast<RenderText *>(previousSibling());
0094     if (!prev || !prev->isText() || !prev->firstTextBox() || prev->isBR()) {
0095         prev = this;
0096     }
0097 
0098     //qCDebug(KHTML_LOG) << "delegated to " << prev->renderName() << "@" << prev;
0099     return prev->RenderText::checkSelectionPoint(_x, _y, _tx, _ty, node, offset, state);
0100 }
0101 
0102 InlineBox *RenderBR::inlineBox(long /*offset*/)
0103 {
0104     return firstTextBox();
0105 }