📄 render_replaced.cpp
字号:
/** * This file is part of the HTML widget for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * Copyright (C) 2000 Dirk Mueller (mueller@kde.org) * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */#include "render_replaced.h"#include "render_arena.h"#include "render_canvas.h"#include "render_line.h"#include <assert.h>#include <qwidget.h>#include <qpainter.h>#include <qevent.h>#include <qapplication.h>#include "khtml_ext.h"#include "khtmlview.h"#include "xml/dom2_eventsimpl.h"#include "khtml_part.h"#include "xml/dom_docimpl.h" // ### remove dependency#include "xml/dom_position.h"#include <kdebug.h>using namespace khtml;using namespace DOM;RenderReplaced::RenderReplaced(DOM::NodeImpl* node) : RenderBox(node){ // init RenderObject attributes setReplaced(true); m_intrinsicWidth = 200; m_intrinsicHeight = 150;}bool RenderReplaced::shouldPaint(PaintInfo& i, int& _tx, int& _ty){ if (i.phase != PaintActionForeground && i.phase != PaintActionOutline && i.phase != PaintActionSelection) return false; if (!shouldPaintWithinRoot(i)) return false; // if we're invisible or haven't received a layout yet, then just bail. if (style()->visibility() != VISIBLE || m_y <= -500000) return false; int tx = _tx + m_x; int ty = _ty + m_y; // Early exit if the element touches the edges. int os = 2*maximalOutlineSize(i.phase); if ((tx >= i.r.x() + i.r.width() + os) || (tx + m_width <= i.r.x() - os)) return false; if ((ty >= i.r.y() + i.r.height() + os) || (ty + m_height <= i.r.y() - os)) return false; return true;}void RenderReplaced::calcMinMaxWidth(){ KHTMLAssert( !minMaxKnown());#ifdef DEBUG_LAYOUT kdDebug( 6040 ) << "RenderReplaced::calcMinMaxWidth() known=" << minMaxKnown() << endl;#endif int width = calcReplacedWidth() + paddingLeft() + paddingRight() + borderLeft() + borderRight(); if ( style()->width().isPercent() || style()->height().isPercent() ) { m_minWidth = 0; m_maxWidth = width; } else m_minWidth = m_maxWidth = width; setMinMaxKnown();}short RenderReplaced::lineHeight( bool, bool ) const{ return height()+marginTop()+marginBottom();}short RenderReplaced::baselinePosition( bool, bool ) const{ return height()+marginTop()+marginBottom();}bool RenderReplaced::canHaveChildren() const{ // We should not really be a RenderContainer subclass. return false;}long RenderReplaced::caretMinOffset() const { return 0; }// Returns 1 since a replaced element can have the caret positioned // at its beginning (0), or at its end (1).long RenderReplaced::caretMaxOffset() const { return 1; }unsigned long RenderReplaced::caretMaxRenderedOffset() const{ return 1; }Position RenderReplaced::positionForCoordinates(int _x, int _y){ InlineBox *box = inlineBoxWrapper(); if (!box) return Position(element(), 0); RootInlineBox *root = box->root(); int absx, absy; containingBlock()->absolutePosition(absx, absy); int top = absy + root->topOverflow(); int bottom = root->nextRootBox() ? absy + root->nextRootBox()->topOverflow() : absy + root->bottomOverflow(); if (_y < top) return Position(element(), caretMinOffset()); // coordinates are above if (_y >= bottom) return Position(element(), caretMaxOffset()); // coordinates are below if (element()) { if (_x <= absx + xPos() + (width() / 2)) return Position(element(), 0); return Position(element(), 1); } return RenderBox::positionForCoordinates(_x, _y);}// -----------------------------------------------------------------------------RenderWidget::RenderWidget(DOM::NodeImpl* node) : RenderReplaced(node), m_deleteWidget(false){#if KWIQ QOBJECT_TYPE(RenderWidget);#endif m_widget = 0; // a replaced element doesn't support being anonymous assert(node); m_view = node->getDocument()->view(); // this is no real reference counting, its just there // to make sure that we're not deleted while we're recursed // in an eventFilter of the widget ref();}void RenderWidget::detach(){ remove(); if ( m_widget ) { if ( m_view ) m_view->removeChild( m_widget ); m_widget->removeEventFilter( this ); m_widget->setMouseTracking( false ); } RenderArena* arena = renderArena(); if (m_inlineBoxWrapper) { if (!documentBeingDestroyed()) m_inlineBoxWrapper->remove(); m_inlineBoxWrapper->detach(arena); } setNode(0); deref(arena);}RenderWidget::~RenderWidget(){ KHTMLAssert( refCount() <= 0 ); if (m_deleteWidget) { delete m_widget; }}void RenderWidget::resizeWidget( QWidget *widget, int w, int h ){#if !APPLE_CHANGES || KWIQ // ugly hack to limit the maximum size of the widget (as X11 has problems if it's bigger) h = QMIN( h, 3072 ); w = QMIN( w, 2000 );#endif if (element() && (widget->width() != w || widget->height() != h)) { RenderArena *arena = ref(); element()->ref(); widget->resize( w, h ); element()->deref(); deref(arena); }}void RenderWidget::setQWidget(QWidget *widget, bool deleteWidget){ if (widget != m_widget) { if (m_widget) { m_widget->removeEventFilter(this); disconnect( m_widget, SIGNAL( destroyed()), this, SLOT( slotWidgetDestructed())); if (m_deleteWidget) { delete m_widget; } m_widget = 0; } m_widget = widget; if (m_widget) { connect( m_widget, SIGNAL( destroyed()), this, SLOT( slotWidgetDestructed())); m_widget->installEventFilter(this); // if we've already received a layout, apply the calculated space to the // widget immediately, but we have to have really been full constructed (with a non-null // style pointer). if (!needsLayout() && style()) { resizeWidget( m_widget, m_width-borderLeft()-borderRight()-paddingLeft()-paddingRight(), m_height-borderLeft()-borderRight()-paddingLeft()-paddingRight() ); } else setPos(xPos(), -500000);#if APPLE_CHANGES if (style()) { if (style()->visibility() != VISIBLE) m_widget->hide(); else m_widget->show(); }#endif } m_view->addChild( m_widget, -500000, 0 ); } m_deleteWidget = deleteWidget;}void RenderWidget::layout( ){ KHTMLAssert( needsLayout() ); KHTMLAssert( minMaxKnown() );#if !APPLE_CHANGES || KWIQ // kwiq: relevant? if ( m_widget ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -