📄 render_frames.cpp
字号:
/** * This file is part of the KDE project. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> * (C) 2000 Stefan Schimanski (1Stein@gmx.de) * * 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. * * $Id: render_frames.cpp,v 1.2 2002/01/28 04:31:02 leon Exp $ *///#define DEBUG_LAYOUT#include <assert.h>#include "qstringlist.h"#include "render_interface.h"#include "mgpoint.h"#include "mgcolor.h"#include "mgpen.h"#include "mgbrush.h"#include "mgsize.h"#include "mgrect.h"#include "mgpixmap.h"#include "mgfontmetrics.h"#include "mgpainter.h"#include "mghtmlview.h"#include "mghtml_part.h"#include "render_frames.h"#include "html_baseimpl.h"#include "htmltags.h"#include "mghtml_part.h"#include "kdebug.h"#define DEBUG_BY_XHTANG 1using namespace khtml;using namespace DOM;RenderFrameSet::RenderFrameSet( HTMLFrameSetElementImpl *frameSet, MGHTMLView *view, QList<khtml::Length> *rows, QList<khtml::Length> *cols ): RenderBox(){ // init RenderObject attributes m_inline = false; // our object is not Inline m_frameset = frameSet; m_rows = rows; m_cols = cols; m_rowHeight = 0; m_colWidth = 0; m_resizing = false; m_hSplit = -1; m_vSplit = -1; m_hSplitVar = 0; m_vSplitVar = 0; m_view = view;}RenderFrameSet::~RenderFrameSet(){ if ( m_rowHeight ) { delete [] m_rowHeight; m_rowHeight = 0; } if ( m_colWidth ) { delete [] m_colWidth; m_colWidth = 0; } delete [] m_hSplitVar; delete [] m_vSplitVar;}void RenderFrameSet::layout( ){ if ( strcmp( m_parent->renderName(), "RenderFrameSet" ) != 0 ) { m_width = m_view->visibleWidth(); m_height = m_view->visibleHeight(); }// kdDebug() << "In function: RenderFrameSet::layout" << endl; // kdDebug() << "xpos = " << m_x << ", ypos=" << m_y << endl; int remainingWidth = m_width - (m_frameset->totalCols()-1)*m_frameset->border(); if(remainingWidth<0) remainingWidth=0; int remainingHeight = m_height - (m_frameset->totalRows()-1)*m_frameset->border(); if(remainingHeight<0) remainingHeight=0; int widthAvailable = remainingWidth; int heightAvailable = remainingHeight; if(m_rowHeight) delete [] m_rowHeight; if(m_colWidth) delete [] m_colWidth; m_rowHeight = new int[m_frameset->totalRows()]; m_colWidth = new int[m_frameset->totalCols()]; int i; int totalRelative = 0; int colsRelative = 0; int rowsRelative = 0; int rowsPercent = 0; int colsPercent = 0; int remainingRelativeWidth = 0; // fixed rows first, then percent and then relative if(m_rows) { for(i = 0; i< m_frameset->totalRows(); i++) { if(m_rows->at(i)->type == Fixed || m_rows->at(i)->type == Percent) { m_rowHeight[i] = QMAX(m_rows->at(i)->width(heightAvailable), 14); if( m_rowHeight[i] > remainingHeight ) m_rowHeight[i] = remainingHeight; remainingHeight -= m_rowHeight[i]; if( m_rows->at(i)->type == Percent) rowsPercent++; if( m_rows->at(i)->type == Percent) rowsPercent++; } else if(m_rows->at(i)->type == Relative) { totalRelative += m_rows->at(i)->value; rowsRelative++; } } // ### if(remainingHeight < 0) remainingHeight = 0; if ( !totalRelative && rowsRelative ) remainingRelativeWidth = remainingHeight/rowsRelative; for(i = 0; i< m_frameset->totalRows(); i++) { if(m_rows->at(i)->type == Relative) { if ( totalRelative ) m_rowHeight[i] = m_rows->at(i)->value*remainingHeight/totalRelative; else m_rowHeight[i] = remainingRelativeWidth; remainingHeight -= m_rowHeight[i]; totalRelative--; } } // support for totally broken frame declarations if(remainingHeight) { // just distribute it over all columns... int rows = m_frameset->totalRows(); if ( rowsPercent ) rows = rowsPercent; for(i = 0; i< m_frameset->totalRows(); i++) { if( !rowsPercent || m_rows->at(i)->type == Percent ) { int toAdd = remainingHeight/rows; rows--; m_rowHeight[i] += toAdd; remainingHeight -= toAdd; } } } } else m_rowHeight[0] = m_height; if(m_cols) { totalRelative = 0; remainingRelativeWidth = 0; for(i = 0; i< m_frameset->totalCols(); i++) { if(m_cols->at(i)->type == Fixed || m_cols->at(i)->type == Percent) { m_colWidth[i] = QMAX(m_cols->at(i)->width(widthAvailable), 14); if( m_colWidth[i] > remainingWidth ) m_colWidth[i] = remainingWidth; remainingWidth -= m_colWidth[i]; if( m_cols->at(i)->type == Percent) colsPercent++; } else if(m_cols->at(i)->type == Relative) { totalRelative += m_cols->at(i)->value; colsRelative++; } } // ### if(remainingWidth < 0) remainingWidth = 0; if ( !totalRelative && colsRelative ) remainingRelativeWidth = remainingWidth/colsRelative; for(i = 0; i < m_frameset->totalCols(); i++) { if(m_cols->at(i)->type == Relative) { if ( totalRelative ) m_colWidth[i] = m_cols->at(i)->value*remainingWidth/totalRelative; else m_colWidth[i] = remainingRelativeWidth; remainingWidth -= m_colWidth[i]; totalRelative--; } } // support for totally broken frame declarations if(remainingWidth) { // just distribute it over all columns... int cols = m_frameset->totalCols(); if ( colsPercent ) cols = colsPercent; for(i = 0; i< m_frameset->totalCols(); i++) { if( !colsPercent || m_cols->at(i)->type == Percent ) { int toAdd = remainingWidth/cols; cols--; m_colWidth[i] += toAdd; remainingWidth -= toAdd; } } } } else m_colWidth[0] = m_width; positionFrames(); RenderObject *child = firstChild(); if ( !child ) return; if(!m_hSplitVar && !m_vSplitVar) {// kdDebug( 6031 ) << "calculationg fixed Splitters" << endl; if(!m_vSplitVar && m_frameset->totalCols() > 1) { m_vSplitVar = new bool[m_frameset->totalCols()]; for(int i = 0; i < m_frameset->totalCols(); i++) m_vSplitVar[i] = true; } if(!m_hSplitVar && m_frameset->totalRows() > 1) { m_hSplitVar = new bool[m_frameset->totalRows()]; for(int i = 0; i < m_frameset->totalRows(); i++) m_hSplitVar[i] = true; } for(int r = 0; r < m_frameset->totalRows(); r++) { for(int c = 0; c < m_frameset->totalCols(); c++) { bool fixed = false; if ( strcmp( child->renderName(), "RenderFrameSet" ) == 0 ) fixed = static_cast<RenderFrameSet *>(child)->frameSetImpl()->noResize(); else fixed = static_cast<RenderFrame *>(child)->frameImpl()->noResize(); /* if(child->id() == ID_FRAMESET) fixed = (static_cast<HTMLFrameSetElementImpl *>(child))->noResize(); else if(child->id() == ID_FRAME) fixed = (static_cast<HTMLFrameElementImpl *>(child))->noResize(); */ if(fixed) {// kdDebug( 6031 ) << "found fixed cell " << r << "/" << c << "!" << endl; if( m_frameset->totalCols() > 1) { if(c>0) m_vSplitVar[c-1] = false; m_vSplitVar[c] = false; } if( m_frameset->totalRows() > 1) { if(r>0) m_hSplitVar[r-1] = false; m_hSplitVar[r] = false; } child = child->nextSibling(); if(!child) goto end2; }// else// kdDebug( 6031 ) << "not fixed: " << r << "/" << c << "!" << endl; } } } end2: setLayouted();}void RenderFrameSet::positionFrames(){ int r; int c; RenderObject *child = firstChild(); if ( !child ) return; // NodeImpl *child = _first; // if(!child) return; int yPos = 0; for(r = 0; r < m_frameset->totalRows(); r++) { int xPos = 0; for(c = 0; c < m_frameset->totalCols(); c++) { // HTMLElementImpl *e = static_cast<HTMLElementImpl *>(child); // kdDebug() << "In function: RenderFrameSet::positionFrames" << endl; // kdDebug() << "child is " << child->renderName() << endl; child->setPos( xPos, yPos ); //kdDebug() << "child frame at (" << xPos << "/" << yPos << ") size (" << m_colWidth[c] << "/" << m_rowHeight[r] << ")" << endl; child->setSize( m_colWidth[c], m_rowHeight[r] ); child->layout( ); xPos += m_colWidth[c] + m_frameset->border(); child = child->nextSibling(); if ( !child ) return; /* e->renderer()->setXPos(xPos); e->renderer()->setYPos(yPos); e->setWidth(colWidth[c]); e->setAvailableWidth(colWidth[c]); e->setDescent(rowHeight[r]); e->layout(); xPos += colWidth[c] + border; child = child->nextSibling(); if(!child) return; */ } yPos += m_rowHeight[r] + m_frameset->border(); }}bool RenderFrameSet::userResize( int _x, int _y, DOM::NodeImpl::MouseEventType type ){ bool res = false; if ( !m_resizing && type == DOM::NodeImpl::MouseMove || type == DOM::NodeImpl::MousePress ) {// kdDebug( 6031 ) << "mouseEvent:check" << endl; m_hSplit = -1; m_vSplit = -1; //bool resizePossible = true; // check if we're over a horizontal or vertical boundary int pos = m_colWidth[0]; for(int c = 1; c < m_frameset->totalCols(); c++) { if(_x >= pos && _x <= pos+m_frameset->border()) { if(m_vSplitVar && m_vSplitVar[c-1] == true) m_vSplit = c-1;// kdDebug( 6031 ) << "vsplit!" << endl; res = true; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -