📄 rootinlinebox.cpp
字号:
/* * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */#include "config.h"#include "RootInlineBox.h"#include "BidiResolver.h"#include "ChromeClient.h"#include "Document.h"#include "EllipsisBox.h"#include "Frame.h"#include "GraphicsContext.h"#include "HitTestResult.h"#include "Page.h"#include "RenderArena.h"#include "RenderBlock.h"using namespace std;namespace WebCore { typedef WTF::HashMap<const RootInlineBox*, EllipsisBox*> EllipsisBoxMap;static EllipsisBoxMap* gEllipsisBoxMap = 0;void* RootInlineBox::Overflow::operator new(size_t sz, RenderArena* renderArena) throw(){ return renderArena->allocate(sz);}void RootInlineBox::Overflow::operator delete(void* ptr, size_t sz){ // Stash size where destroy can find it. *(size_t *)ptr = sz;}void RootInlineBox::Overflow::destroy(RenderArena* renderArena){ delete this; // Recover the size left there for us by operator delete and free the memory. renderArena->free(*(size_t *)this, this);}void RootInlineBox::destroy(RenderArena* arena){ if (m_overflow) m_overflow->destroy(arena); detachEllipsisBox(arena); InlineFlowBox::destroy(arena);}void RootInlineBox::detachEllipsisBox(RenderArena* arena){ if (m_hasEllipsisBox) { EllipsisBox* box = gEllipsisBoxMap->take(this); box->setParent(0); box->destroy(arena); m_hasEllipsisBox = false; }}int RootInlineBox::height() const{ const Font& font = renderer()->style(m_firstLine)->font(); int result = font.height(); bool strictMode = renderer()->document()->inStrictMode(); if (!strictMode && !hasTextChildren() && !boxModelObject()->hasHorizontalBordersOrPadding()) { int bottom = bottomOverflow(); if (y() + result > bottom) result = bottom - y(); } return result;}RenderLineBoxList* RootInlineBox::rendererLineBoxes() const{ return block()->lineBoxes();}void RootInlineBox::clearTruncation(){ if (m_hasEllipsisBox) { detachEllipsisBox(renderer()->renderArena()); InlineFlowBox::clearTruncation(); }}bool RootInlineBox::canAccommodateEllipsis(bool ltr, int blockEdge, int lineBoxEdge, int ellipsisWidth){ // First sanity-check the unoverflowed width of the whole line to see if there is sufficient room. int delta = ltr ? lineBoxEdge - blockEdge : blockEdge - lineBoxEdge; if (width() - delta < ellipsisWidth) return false; // Next iterate over all the line boxes on the line. If we find a replaced element that intersects // then we refuse to accommodate the ellipsis. Otherwise we're ok. return InlineFlowBox::canAccommodateEllipsis(ltr, blockEdge, ellipsisWidth);}void RootInlineBox::placeEllipsis(const AtomicString& ellipsisStr, bool ltr, int blockEdge, int ellipsisWidth, InlineBox* markupBox){ // Create an ellipsis box. EllipsisBox* ellipsisBox = new (renderer()->renderArena()) EllipsisBox(renderer(), ellipsisStr, this, ellipsisWidth - (markupBox ? markupBox->width() : 0), height(), y(), !prevRootBox(), markupBox); if (!gEllipsisBoxMap) gEllipsisBoxMap = new EllipsisBoxMap(); gEllipsisBoxMap->add(this, ellipsisBox); m_hasEllipsisBox = true; if (ltr && (x() + width() + ellipsisWidth) <= blockEdge) { ellipsisBox->m_x = x() + width(); return; } // Now attempt to find the nearest glyph horizontally and place just to the right (or left in RTL) // of that glyph. Mark all of the objects that intersect the ellipsis box as not painting (as being // truncated). bool foundBox = false; ellipsisBox->m_x = placeEllipsisBox(ltr, blockEdge, ellipsisWidth, foundBox);}int RootInlineBox::placeEllipsisBox(bool ltr, int blockEdge, int ellipsisWidth, bool& foundBox){ int result = InlineFlowBox::placeEllipsisBox(ltr, blockEdge, ellipsisWidth, foundBox); if (result == -1) result = ltr ? blockEdge - ellipsisWidth : blockEdge; return result;}void RootInlineBox::paintEllipsisBox(RenderObject::PaintInfo& paintInfo, int tx, int ty) const{ if (m_hasEllipsisBox && renderer()->shouldPaintWithinRoot(paintInfo) && renderer()->style()->visibility() == VISIBLE && paintInfo.phase == PaintPhaseForeground) ellipsisBox()->paint(paintInfo, tx, ty);}#if PLATFORM(MAC)void RootInlineBox::addHighlightOverflow(){ Frame* frame = renderer()->document()->frame(); if (!frame) return; Page* page = frame->page(); if (!page) return; // Highlight acts as a selection inflation. FloatRect rootRect(0, selectionTop(), width(), selectionHeight()); IntRect inflatedRect = enclosingIntRect(page->chrome()->client()->customHighlightRect(renderer()->node(), renderer()->style()->highlight(), rootRect)); setHorizontalOverflowPositions(min(leftOverflow(), inflatedRect.x()), max(rightOverflow(), inflatedRect.right())); setVerticalOverflowPositions(min(topOverflow(), inflatedRect.y()), max(bottomOverflow(), inflatedRect.bottom()));}void RootInlineBox::paintCustomHighlight(RenderObject::PaintInfo& paintInfo, int tx, int ty, const AtomicString& highlightType){ if (!renderer()->shouldPaintWithinRoot(paintInfo) || renderer()->style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseForeground) return; Frame* frame = renderer()->document()->frame(); if (!frame) return; Page* page = frame->page(); if (!page) return; // Get the inflated rect so that we can properly hit test. FloatRect rootRect(tx + x(), ty + selectionTop(), width(), selectionHeight()); FloatRect inflatedRect = page->chrome()->client()->customHighlightRect(renderer()->node(), highlightType, rootRect); if (inflatedRect.intersects(paintInfo.rect)) page->chrome()->client()->paintCustomHighlight(renderer()->node(), highlightType, rootRect, rootRect, false, true);}#endifvoid RootInlineBox::paint(RenderObject::PaintInfo& paintInfo, int tx, int ty){ InlineFlowBox::paint(paintInfo, tx, ty); paintEllipsisBox(paintInfo, tx, ty);#if PLATFORM(MAC) RenderStyle* styleToUse = renderer()->style(m_firstLine); if (styleToUse->highlight() != nullAtom && !paintInfo.context->paintingDisabled()) paintCustomHighlight(paintInfo, tx, ty, styleToUse->highlight());#endif}bool RootInlineBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty){ if (m_hasEllipsisBox && visibleToHitTesting()) { if (ellipsisBox()->nodeAtPoint(request, result, x, y, tx, ty)) { renderer()->updateHitTestResult(result, IntPoint(x - tx, y - ty)); return true; } } return InlineFlowBox::nodeAtPoint(request, result, x, y, tx, ty);}void RootInlineBox::adjustPosition(int dx, int dy){ InlineFlowBox::adjustPosition(dx, dy); if (m_overflow) { m_overflow->m_topOverflow += dy; m_overflow->m_bottomOverflow += dy; m_overflow->m_selectionTop += dy; m_overflow->m_selectionBottom += dy; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -