int LayoutTextControl::textBlockLogicalWidth() const { Element* innerEditor = innerEditorElement(); ASSERT(innerEditor); LayoutUnit unitWidth = logicalWidth() - borderAndPaddingLogicalWidth(); if (innerEditor->layoutObject()) unitWidth -= innerEditor->layoutBox()->paddingStart() + innerEditor->layoutBox()->paddingEnd(); return unitWidth.toInt(); }
void MediaControls::notifyPanelWidthChanged(const LayoutUnit& newWidth) { // Don't bother to do any work if this matches the most recent panel // width, since we're called after layout. // Note that this code permits a bad frame on resize, since it is // run after the relayout / paint happens. It would be great to improve // this, but it would be even greater to move this code entirely to // JS and fix it there. m_panelWidth = newWidth.toInt(); // Adjust for effective zoom. if (!m_panel->layoutObject() || !m_panel->layoutObject()->style()) return; m_panelWidth = ceil(m_panelWidth / m_panel->layoutObject()->style()->effectiveZoom()); m_panelWidthChangedTimer.startOneShot(0, BLINK_FROM_HERE); }
LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) const { int sPos = std::max(startPos - m_start, 0); int ePos = std::min(endPos - m_start, (int)m_len); if (sPos > ePos) return LayoutRect(); FontCachePurgePreventer fontCachePurgePreventer; LayoutUnit selTop = root().selectionTop(); LayoutUnit selHeight = root().selectionHeight(); const ComputedStyle& styleToUse = getLineLayoutItem().styleRef(isFirstLineStyle()); const Font& font = styleToUse.font(); StringBuilder charactersWithHyphen; bool respectHyphen = ePos == m_len && hasHyphen(); TextRun textRun = constructTextRun(styleToUse, respectHyphen ? &charactersWithHyphen : 0); LayoutPoint startingPoint = LayoutPoint(logicalLeft(), selTop); LayoutRect r; if (sPos || ePos != static_cast<int>(m_len)) { r = LayoutRect(enclosingIntRect(font.selectionRectForText( textRun, FloatPoint(startingPoint), selHeight.toInt(), sPos, ePos))); } else { // Avoid computing the font width when the entire line box is selected as an // optimization. r = LayoutRect(enclosingIntRect( LayoutRect(startingPoint, LayoutSize(m_logicalWidth, selHeight)))); } LayoutUnit logicalWidth = r.width(); if (r.x() > logicalRight()) logicalWidth = LayoutUnit(); else if (r.maxX() > logicalRight()) logicalWidth = logicalRight() - r.x(); LayoutPoint topPoint; LayoutUnit width; LayoutUnit height; if (isHorizontal()) { topPoint = LayoutPoint(r.x(), selTop); width = logicalWidth; height = selHeight; if (hasWrappedSelectionNewline()) { if (!isLeftToRightDirection()) topPoint.setX(LayoutUnit(topPoint.x() - newlineSpaceWidth())); width += newlineSpaceWidth(); } } else { topPoint = LayoutPoint(selTop, r.x()); width = selHeight; height = logicalWidth; // TODO(wkorman): RTL text embedded in top-to-bottom text can create // bottom-to-top situations. Add tests and ensure we handle correctly. if (hasWrappedSelectionNewline()) height += newlineSpaceWidth(); } return LayoutRect(topPoint, LayoutSize(width, height)); }