IntSize DrawingBuffer::adjustSize(const IntSize& desiredSize, const IntSize& curSize, int maxTextureSize) { IntSize adjustedSize = desiredSize; // Clamp if the desired size is greater than the maximum texture size for the device. if (adjustedSize.height() > maxTextureSize) adjustedSize.setHeight(maxTextureSize); if (adjustedSize.width() > maxTextureSize) adjustedSize.setWidth(maxTextureSize); return adjustedSize; }
static inline IntSize outsetSizeForBlur(float stdDeviation) { unsigned kernelSizeX = 0; unsigned kernelSizeY = 0; FEGaussianBlur::calculateUnscaledKernelSize(kernelSizeX, kernelSizeY, stdDeviation, stdDeviation); IntSize outset; // We take the half kernel size and multiply it with three, because we run box blur three times. outset.setWidth(3 * kernelSizeX * 0.5f); outset.setHeight(3 * kernelSizeY * 0.5f); return outset; }
ViewportAttributes computeViewportAttributes(ViewportArguments args, int desktopWidth, int deviceWidth, int deviceHeight, float devicePixelRatio, IntSize visibleViewport) { #if PLATFORM(IOS) // FIXME: This should probably be fixed elsewhere on iOS. iOS may only use computeViewportAttributes for tests. CGSize screenSize = wkGetViewportScreenSize(); visibleViewport.setWidth(screenSize.width); visibleViewport.setHeight(screenSize.height); #endif FloatSize initialViewportSize = convertToUserSpace(visibleViewport, devicePixelRatio); FloatSize deviceSize = convertToUserSpace(FloatSize(deviceWidth, deviceHeight), devicePixelRatio); return args.resolve(initialViewportSize, deviceSize, desktopWidth); }
void clampImageBufferSizeToViewport(FrameView* frameView, IntSize& size) { if (!frameView) return; int viewWidth = frameView->visibleWidth(); int viewHeight = frameView->visibleHeight(); if (size.width() > viewWidth) size.setWidth(viewWidth); if (size.height() > viewHeight) size.setHeight(viewHeight); }
void ScrollView::setScrollOffset(const IntPoint& offset) { int horizontalOffset = offset.x(); int verticalOffset = offset.y(); if (constrainsScrollingToContentEdge()) { horizontalOffset = max(min(horizontalOffset, contentsWidth() - visibleWidth()), 0); verticalOffset = max(min(verticalOffset, contentsHeight() - visibleHeight()), 0); } IntSize newOffset = m_scrollOffset; newOffset.setWidth(horizontalOffset - m_scrollOrigin.x()); newOffset.setHeight(verticalOffset - m_scrollOrigin.y()); scrollTo(newOffset); }
PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float sh) const { FloatSize unscaledSize(sw, sh); IntSize scaledSize; if (m_canvas) scaledSize = m_canvas->convertLogicalToDevice(unscaledSize); else scaledSize = IntSize(static_cast<int>(ceilf(sw)), static_cast<int>(ceilf(sh))); if (scaledSize.width() < 1) scaledSize.setWidth(1); if (scaledSize.height() < 1) scaledSize.setHeight(1); return createEmptyImageData(scaledSize); }
PassRefPtr<ImageData> CanvasRenderingContext2D::createImageData(float sw, float sh, ExceptionCode& ec) const { ec = 0; if (!isfinite(sw) || !isfinite(sh)) { ec = NOT_SUPPORTED_ERR; return 0; } FloatSize unscaledSize(sw, sh); IntSize scaledSize = canvas()->convertLogicalToDevice(unscaledSize); if (scaledSize.width() < 1) scaledSize.setWidth(1); if (scaledSize.height() < 1) scaledSize.setHeight(1); return createEmptyImageData(scaledSize); }
void clampImageBufferSizeToViewport(RenderObject* object, IntSize& size) { if (!object || !object->isRenderView()) return; RenderView* view = static_cast<RenderView*>(object); if (!view->frameView()) return; int viewWidth = view->frameView()->visibleWidth(); int viewHeight = view->frameView()->visibleHeight(); if (size.width() > viewWidth) size.setWidth(viewWidth); if (size.height() > viewHeight) size.setHeight(viewHeight); }
void RenderTheme::adjustRadioStyleUsingFallbackTheme(RenderStyle* style, Element*) const { // If the width and height are both specified, then we have nothing to do. if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto()) return; IntSize size = WebKit::Platform::current()->fallbackThemeEngine()->getSize(WebKit::WebFallbackThemeEngine::PartRadio); float zoomLevel = style->effectiveZoom(); size.setWidth(size.width() * zoomLevel); size.setHeight(size.height() * zoomLevel); setSizeIfAuto(style, size); // padding - not honored by WinIE, needs to be removed. style->resetPadding(); // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme) // for now, we will not honor it. style->resetBorder(); }
IntSize ScrollAnchor::computeAdjustment() const { // The anchor node can report fractional positions, but it is DIP-snapped when // painting (crbug.com/610805), so we must round the offsets to determine the // visual delta. If we scroll by the delta in LayoutUnits, the snapping of the // anchor node may round differently from the snapping of the scroll position. // (For example, anchor moving from 2.4px -> 2.6px is really 2px -> 3px, so we // should scroll by 1px instead of 0.2px.) This is true regardless of whether // the ScrollableArea actually uses fractional scroll positions. IntSize delta = roundedIntSize(computeRelativeOffset(m_anchorObject, m_scroller, m_corner)) - roundedIntSize(m_savedRelativeOffset); // Only adjust on the block layout axis. if (scrollerLayoutBox(m_scroller)->isHorizontalWritingMode()) delta.setWidth(0); else delta.setHeight(0); return delta; }
IntSize FEGaussianBlur::calculateUnscaledKernelSize(const FloatPoint& std) { ASSERT(std.x() >= 0 && std.y() >= 0); IntSize kernelSize; // Limit the kernel size to 1000. A bigger radius won't make a big difference for the result image but // inflates the absolute paint rect to much. This is compatible with Firefox' behavior. if (std.x()) { int size = std::max<unsigned>(2, static_cast<unsigned>(floorf(std.x() * gaussianKernelFactor() + 0.5f))); kernelSize.setWidth(std::min(size, gMaxKernelSize)); } if (std.y()) { int size = std::max<unsigned>(2, static_cast<unsigned>(floorf(std.y() * gaussianKernelFactor() + 0.5f))); kernelSize.setHeight(std::min(size, gMaxKernelSize)); } return kernelSize; }
void ScrollView::valueChanged(Scrollbar* scrollbar) { // Figure out if we really moved. IntSize newOffset = m_scrollOffset; if (scrollbar) { if (scrollbar->orientation() == HorizontalScrollbar) newOffset.setWidth(scrollbar->value()); else if (scrollbar->orientation() == VerticalScrollbar) newOffset.setHeight(scrollbar->value()); } IntSize scrollDelta = newOffset - m_scrollOffset; if (scrollDelta == IntSize()) return; m_scrollOffset = newOffset; if (scrollbarsSuppressed()) return; scrollContents(scrollDelta); }
void ScrollView::ScrollViewPrivate::valueChanged(Scrollbar* bar) { // Figure out if we really moved. IntSize newOffset = m_scrollOffset; if (bar) { if (bar == m_hBar) newOffset.setWidth(bar->value()); else if (bar == m_vBar) newOffset.setHeight(bar->value()); } IntSize scrollDelta = newOffset - m_scrollOffset; if (scrollDelta == IntSize()) return; m_scrollOffset = newOffset; if (m_scrollbarsSuppressed) return; static_cast<FrameView*>(m_view)->frame()->sendScrollEvent(); scrollBackingStore(scrollDelta); }
void Gradient::adjustParametersForTiledDrawing(IntSize& size, FloatRect& srcRect) { if (m_radial) return; if (srcRect.isEmpty()) return; if (m_p0.x() == m_p1.x()) { size.setWidth(1); srcRect.setWidth(1); srcRect.setX(0); return; } if (m_p0.y() != m_p1.y()) return; size.setHeight(1); srcRect.setHeight(1); srcRect.setY(0); }
static void adjustmentChanged(GtkAdjustment* adjustment, gpointer _that) { ScrollView* that = reinterpret_cast<ScrollView*>(_that); // Figure out if we really moved. IntSize newOffset = that->scrollOffset(); if (adjustment == that->m_horizontalAdjustment) newOffset.setWidth(static_cast<int>(gtk_adjustment_get_value(adjustment))); else if (adjustment == that->m_verticalAdjustment) newOffset.setHeight(static_cast<int>(gtk_adjustment_get_value(adjustment))); IntSize scrollDelta = newOffset - that->scrollOffset(); if (scrollDelta == IntSize()) return; that->setScrollOffset(newOffset); if (that->scrollbarsSuppressed()) return; that->scrollContents(scrollDelta); }
IntRect ScrollbarThemeWx::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool) { // FIXME: Handling this case is needed when there are two sets of arrow buttons // on Mac, one at the top and one at the bottom. if (part == ForwardButtonStartPart) return IntRect(); IntSize size = buttonSize(scrollbar); int x, y; if (scrollbar->orientation() == HorizontalScrollbar) { #ifdef __WXMAC__ size.setWidth(size.width() + cMacButtonOverlap); #endif x = scrollbar->x() + scrollbar->width() - size.width(); y = scrollbar->y(); } else { x = scrollbar->x(); #ifdef __WXMAC__ size.setHeight(size.height() + cMacButtonOverlap); #endif y = scrollbar->y() + scrollbar->height() - size.height(); } return IntRect(x, y, size.width(), size.height()); }
DragImageRef WebDragClient::createDragImageForLink(KURL& url, const String& inLabel, Frame* frame) { // This is more or less an exact match for the Mac OS X code. const Font* labelFont; const Font* urlFont; if (frame->settings() && frame->settings()->fontRenderingMode() == AlternateRenderingMode) { static const Font alternateRenderingModeLabelFont = dragLabelFont(DRAG_LINK_LABEL_FONT_SIZE, true, AlternateRenderingMode); static const Font alternateRenderingModeURLFont = dragLabelFont(DRAG_LINK_URL_FONT_SIZE, false, AlternateRenderingMode); labelFont = &alternateRenderingModeLabelFont; urlFont = &alternateRenderingModeURLFont; } else { static const Font normalRenderingModeLabelFont = dragLabelFont(DRAG_LINK_LABEL_FONT_SIZE, true, NormalRenderingMode); static const Font normalRenderingModeURLFont = dragLabelFont(DRAG_LINK_URL_FONT_SIZE, false, NormalRenderingMode); labelFont = &normalRenderingModeLabelFont; urlFont = &normalRenderingModeURLFont; } bool drawURLString = true; bool clipURLString = false; bool clipLabelString = false; String urlString = url.string(); String label = inLabel; if (label.isEmpty()) { drawURLString = false; label = urlString; } //First step in drawing the link drag image width TextRun labelRun(label.impl()); TextRun urlRun(urlString.impl()); IntSize labelSize(labelFont->width(labelRun), labelFont->ascent() + labelFont->descent()); if (labelSize.width() > MAX_DRAG_LABEL_STRING_WIDTH){ labelSize.setWidth(MAX_DRAG_LABEL_STRING_WIDTH); clipLabelString = true; } IntSize urlStringSize; IntSize imageSize(labelSize.width() + DRAG_LABEL_BORDER_X * 2, labelSize.height() + DRAG_LABEL_BORDER_Y * 2); if (drawURLString) { urlStringSize.setWidth(urlFont->width(urlRun)); urlStringSize.setHeight(urlFont->ascent() + urlFont->descent()); imageSize.setHeight(imageSize.height() + urlStringSize.height()); if (urlStringSize.width() > MAX_DRAG_LABEL_STRING_WIDTH) { imageSize.setWidth(MAX_DRAG_LABEL_WIDTH); clipURLString = true; } else { imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()) + DRAG_LABEL_BORDER_X * 2); } } // We now know how big the image needs to be, so we create and // fill the background HBITMAP image = 0; HDC dc = GetDC(0); HDC workingDC = CreateCompatibleDC(dc); if (!workingDC) { ReleaseDC(0, dc); return 0; } PlatformGraphicsContext* contextRef; image = allocImage(workingDC, imageSize, &contextRef); if (!image) { DeleteDC(workingDC); ReleaseDC(0, dc); return 0; } ::SelectObject(workingDC, image); GraphicsContext context(contextRef); // On Mac alpha is {0.7, 0.7, 0.7, 0.8}, however we can't control alpha // for drag images on win, so we use 1 static const Color backgroundColor(140, 140, 140); static const IntSize radii(DRAG_LABEL_RADIUS, DRAG_LABEL_RADIUS); IntRect rect(0, 0, imageSize.width(), imageSize.height()); context.fillRoundedRect(rect, radii, radii, radii, radii, backgroundColor, DeviceColorSpace); // Draw the text static const Color topColor(0, 0, 0, 255); //original alpha = 0.75 static const Color bottomColor(255, 255, 255, 127); //original alpha = 0.5 if (drawURLString) { if (clipURLString) urlString = StringTruncator::rightTruncate(urlString, imageSize.width() - (DRAG_LABEL_BORDER_X * 2.0f), *urlFont, false); IntPoint textPos(DRAG_LABEL_BORDER_X, imageSize.height() - (DRAG_LABEL_BORDER_Y_OFFSET + urlFont->descent())); WebCoreDrawDoubledTextAtPoint(context, urlString, textPos, *urlFont, topColor, bottomColor); } if (clipLabelString) label = StringTruncator::rightTruncate(label, imageSize.width() - (DRAG_LABEL_BORDER_X * 2.0f), *labelFont, false); IntPoint textPos(DRAG_LABEL_BORDER_X, DRAG_LABEL_BORDER_Y + labelFont->pixelSize()); WebCoreDrawDoubledTextAtPoint(context, label, textPos, *labelFont, topColor, bottomColor); deallocContext(contextRef); DeleteDC(workingDC); ReleaseDC(0, dc); return image; }
PassOwnPtr<DragImage> DragImage::create(const KURL& url, const String& inLabel, const FontDescription& systemFont, float deviceScaleFactor) { const Font labelFont = deriveDragLabelFont(kDragLinkLabelFontSize, FontWeightBold, systemFont); const Font urlFont = deriveDragLabelFont(kDragLinkUrlFontSize, FontWeightNormal, systemFont); FontCachePurgePreventer fontCachePurgePreventer; bool drawURLString = true; bool clipURLString = false; bool clipLabelString = false; String urlString = url.string(); String label = inLabel.stripWhiteSpace(); if (label.isEmpty()) { drawURLString = false; label = urlString; } // First step is drawing the link drag image width. TextRun labelRun(label.impl()); TextRun urlRun(urlString.impl()); IntSize labelSize(labelFont.width(labelRun), labelFont.fontMetrics().ascent() + labelFont.fontMetrics().descent()); if (labelSize.width() > kMaxDragLabelStringWidth) { labelSize.setWidth(kMaxDragLabelStringWidth); clipLabelString = true; } IntSize urlStringSize; IntSize imageSize(labelSize.width() + kDragLabelBorderX * 2, labelSize.height() + kDragLabelBorderY * 2); if (drawURLString) { urlStringSize.setWidth(urlFont.width(urlRun)); urlStringSize.setHeight(urlFont.fontMetrics().ascent() + urlFont.fontMetrics().descent()); imageSize.setHeight(imageSize.height() + urlStringSize.height()); if (urlStringSize.width() > kMaxDragLabelStringWidth) { imageSize.setWidth(kMaxDragLabelWidth); clipURLString = true; } else imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()) + kDragLabelBorderX * 2); } // We now know how big the image needs to be, so we create and // fill the background IntSize scaledImageSize = imageSize; scaledImageSize.scale(deviceScaleFactor); OwnPtr<ImageBuffer> buffer(ImageBuffer::create(scaledImageSize)); if (!buffer) return nullptr; buffer->context()->scale(FloatSize(deviceScaleFactor, deviceScaleFactor)); const float DragLabelRadius = 5; const IntSize radii(DragLabelRadius, DragLabelRadius); IntRect rect(IntPoint(), imageSize); const Color backgroundColor(140, 140, 140); buffer->context()->fillRoundedRect(rect, radii, radii, radii, radii, backgroundColor); // Draw the text if (drawURLString) { if (clipURLString) urlString = StringTruncator::centerTruncate(urlString, imageSize.width() - (kDragLabelBorderX * 2.0f), urlFont, StringTruncator::EnableRoundingHacks); IntPoint textPos(kDragLabelBorderX, imageSize.height() - (kLabelBorderYOffset + urlFont.fontMetrics().descent())); TextRun textRun(urlString); buffer->context()->drawText(urlFont, TextRunPaintInfo(textRun), textPos); } if (clipLabelString) label = StringTruncator::rightTruncate(label, imageSize.width() - (kDragLabelBorderX * 2.0f), labelFont, StringTruncator::EnableRoundingHacks); bool hasStrongDirectionality; TextRun textRun = textRunWithDirectionality(label, hasStrongDirectionality); IntPoint textPos(kDragLabelBorderX, kDragLabelBorderY + labelFont.fontDescription().computedPixelSize()); if (hasStrongDirectionality && textRun.direction() == RTL) { float textWidth = urlFont.width(textRun); int availableWidth = imageSize.width() - kDragLabelBorderX * 2; textPos.setX(availableWidth - ceilf(textWidth)); } buffer->context()->drawBidiText(urlFont, TextRunPaintInfo(textRun), textPos); RefPtr<Image> image = buffer->copyImage(); return DragImage::create(image.get(), DoNotRespectImageOrientation, deviceScaleFactor); }
void CCHeadsUpDisplay::draw() { GraphicsContext3D* context = m_layerRenderer->context(); if (!m_hudTexture) m_hudTexture = ManagedTexture::create(m_layerRenderer->renderSurfaceTextureManager()); // Use a fullscreen texture only if we need to... IntSize hudSize; if (settings().showPlatformLayerTree) { hudSize.setWidth(min(2048, m_layerRenderer->viewportWidth())); hudSize.setHeight(min(2048, m_layerRenderer->viewportHeight())); } else { hudSize.setWidth(512); hudSize.setHeight(128); } if (!m_hudTexture->reserve(hudSize, GraphicsContext3D::RGBA)) return; // Render pixels into the texture. PlatformCanvas canvas; canvas.resize(hudSize); { PlatformCanvas::Painter painter(&canvas, PlatformCanvas::Painter::GrayscaleText); drawHudContents(painter.context(), hudSize); } // Upload to GL. { PlatformCanvas::AutoLocker locker(&canvas); m_hudTexture->bindTexture(context, m_layerRenderer->renderSurfaceTextureAllocator()); bool uploadedViaMap = false; if (m_useMapSubForUploads) { Extensions3DChromium* extensions = static_cast<Extensions3DChromium*>(context->getExtensions()); uint8_t* pixelDest = static_cast<uint8_t*>(extensions->mapTexSubImage2DCHROMIUM(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, hudSize.width(), hudSize.height(), GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, Extensions3DChromium::WRITE_ONLY)); if (pixelDest) { uploadedViaMap = true; memcpy(pixelDest, locker.pixels(), hudSize.width() * hudSize.height() * 4); extensions->unmapTexSubImage2DCHROMIUM(pixelDest); } } if (!uploadedViaMap) { GLC(context, context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, canvas.size().width(), canvas.size().height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, locker.pixels())); } } // Draw the HUD onto the default render surface. const Program* program = m_layerRenderer->headsUpDisplayProgram(); ASSERT(program && program->initialized()); GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0)); m_hudTexture->bindTexture(context, m_layerRenderer->renderSurfaceTextureAllocator()); GLC(context, context->useProgram(program->program())); GLC(context, context->uniform1i(program->fragmentShader().samplerLocation(), 0)); TransformationMatrix matrix; matrix.translate3d(hudSize.width() * 0.5, hudSize.height() * 0.5, 0); m_layerRenderer->drawTexturedQuad(matrix, hudSize.width(), hudSize.height(), 1.0f, m_layerRenderer->sharedGeometryQuad(), program->vertexShader().matrixLocation(), program->fragmentShader().alphaLocation(), -1); m_hudTexture->unreserve(); }
DragImageRef createDragImageForLink(URL& url, const String& inLabel, FontRenderingMode fontRenderingMode) { // This is more or less an exact match for the Mac OS X code. const Font* labelFont; const Font* urlFont; FontCachePurgePreventer fontCachePurgePreventer; if (fontRenderingMode == AlternateRenderingMode) { static const Font alternateRenderingModeLabelFont = dragLabelFont(DragLinkLabelFontsize, true, AlternateRenderingMode); static const Font alternateRenderingModeURLFont = dragLabelFont(DragLinkUrlFontSize, false, AlternateRenderingMode); labelFont = &alternateRenderingModeLabelFont; urlFont = &alternateRenderingModeURLFont; } else { static const Font normalRenderingModeLabelFont = dragLabelFont(DragLinkLabelFontsize, true, NormalRenderingMode); static const Font normalRenderingModeURLFont = dragLabelFont(DragLinkUrlFontSize, false, NormalRenderingMode); labelFont = &normalRenderingModeLabelFont; urlFont = &normalRenderingModeURLFont; } bool drawURLString = true; bool clipURLString = false; bool clipLabelString = false; String urlString = url.string(); String label = inLabel; if (label.isEmpty()) { drawURLString = false; label = urlString; } // First step in drawing the link drag image width. TextRun labelRun(label.impl()); TextRun urlRun(urlString.impl()); IntSize labelSize(labelFont->width(labelRun), labelFont->fontMetrics().ascent() + labelFont->fontMetrics().descent()); if (labelSize.width() > MaxDragLabelStringWidth) { labelSize.setWidth(MaxDragLabelStringWidth); clipLabelString = true; } IntSize urlStringSize; IntSize imageSize(labelSize.width() + DragLabelBorderX * 2, labelSize.height() + DragLabelBorderY * 2); if (drawURLString) { urlStringSize.setWidth(urlFont->width(urlRun)); urlStringSize.setHeight(urlFont->fontMetrics().ascent() + urlFont->fontMetrics().descent()); imageSize.setHeight(imageSize.height() + urlStringSize.height()); if (urlStringSize.width() > MaxDragLabelStringWidth) { imageSize.setWidth(MaxDragLabelWidth); clipURLString = true; } else imageSize.setWidth(std::max(labelSize.width(), urlStringSize.width()) + DragLabelBorderX * 2); } // We now know how big the image needs to be, so we create and // fill the background HWndDC dc(0); auto workingDC = adoptGDIObject(::CreateCompatibleDC(dc)); if (!workingDC) return 0; PlatformGraphicsContext* contextRef; auto image = allocImage(workingDC.get(), imageSize, &contextRef); if (!image) return 0; ::SelectObject(workingDC.get(), image.get()); GraphicsContext context(contextRef); // On Mac alpha is {0.7, 0.7, 0.7, 0.8}, however we can't control alpha // for drag images on win, so we use 1 static const Color backgroundColor(140, 140, 140); static const IntSize radii(DragLabelRadius, DragLabelRadius); IntRect rect(0, 0, imageSize.width(), imageSize.height()); context.fillRoundedRect(FloatRoundedRect(rect, radii, radii, radii, radii), backgroundColor, ColorSpaceDeviceRGB); // Draw the text static const Color topColor(0, 0, 0, 255); // original alpha = 0.75 static const Color bottomColor(255, 255, 255, 127); // original alpha = 0.5 if (drawURLString) { if (clipURLString) urlString = StringTruncator::rightTruncate(urlString, imageSize.width() - (DragLabelBorderX * 2.0f), *urlFont, StringTruncator::EnableRoundingHacks); IntPoint textPos(DragLabelBorderX, imageSize.height() - (LabelBorderYOffset + urlFont->fontMetrics().descent())); WebCoreDrawDoubledTextAtPoint(context, urlString, textPos, *urlFont, topColor, bottomColor); } if (clipLabelString) label = StringTruncator::rightTruncate(label, imageSize.width() - (DragLabelBorderX * 2.0f), *labelFont, StringTruncator::EnableRoundingHacks); IntPoint textPos(DragLabelBorderX, DragLabelBorderY + labelFont->pixelSize()); WebCoreDrawDoubledTextAtPoint(context, label, textPos, *labelFont, topColor, bottomColor); deallocContext(contextRef); return image.leak(); }
IntSize ScrollableArea::totalContentsSize() const { IntSize totalContentsSize = contentsSize(); totalContentsSize.setHeight(totalContentsSize.height() + headerHeight() + footerHeight()); return totalContentsSize; }
void ChromeClient::widgetSizeChanged(const IntSize& oldWidgetSize, IntSize newSize) { #if USE(ACCELERATED_COMPOSITING) AcceleratedCompositingContext* compositingContext = m_webView->priv->acceleratedCompositingContext.get(); if (compositingContext->enabled()) { m_webView->priv->acceleratedCompositingContext->resizeRootLayer(newSize); return; } #endif // Grow the backing store by at least 1.5 times the current size. This prevents // lots of unnecessary allocations during an opaque resize. WidgetBackingStore* backingStore = m_webView->priv->backingStore.get(); if (backingStore && oldWidgetSize == newSize) return; if (backingStore) { const IntSize& oldSize = backingStore->size(); if (newSize.width() > oldSize.width()) newSize.setWidth(std::max(newSize.width(), static_cast<int>(oldSize.width() * 1.5))); if (newSize.height() > oldSize.height()) newSize.setHeight(std::max(newSize.height(), static_cast<int>(oldSize.height() * 1.5))); } // If we did not have a backing store before or if the backing store is growing, we need // to reallocate a new one and set it up so that we don't see artifacts while resizing. if (!backingStore || newSize.width() > backingStore->size().width() || newSize.height() > backingStore->size().height()) { OwnPtr<WidgetBackingStore> newBackingStore = createBackingStore(GTK_WIDGET(m_webView), newSize); RefPtr<cairo_t> cr = adoptRef(cairo_create(newBackingStore->cairoSurface())); clearEverywhereInBackingStore(m_webView, cr.get()); // Now we copy the old backing store image over the new cleared surface to prevent // annoying flashing as the widget grows. We do the "real" paint in a timeout // since we don't want to block resizing too long. if (backingStore) { cairo_set_source_surface(cr.get(), backingStore->cairoSurface(), 0, 0); cairo_rectangle(cr.get(), 0, 0, backingStore->size().width(), backingStore->size().height()); cairo_fill(cr.get()); } m_webView->priv->backingStore = newBackingStore.release(); backingStore = m_webView->priv->backingStore.get(); } else if (oldWidgetSize.width() < newSize.width() || oldWidgetSize.height() < newSize.height()) { // The widget is growing, but we did not need to create a new backing store. // We should clear any old data outside of the old widget region. RefPtr<cairo_t> cr = adoptRef(cairo_create(backingStore->cairoSurface())); clipOutOldWidgetArea(cr.get(), oldWidgetSize, newSize); clearEverywhereInBackingStore(m_webView, cr.get()); } // We need to force a redraw and ignore the framerate cap. m_lastDisplayTime = 0; m_dirtyRegion.unite(IntRect(IntPoint(), backingStore->size())); // WebCore timers by default have a lower priority which leads to more artifacts when opaque // resize is on, thus we use g_timeout_add here to force a higher timeout priority. if (!m_repaintSoonSourceId) m_repaintSoonSourceId = g_timeout_add(0, reinterpret_cast<GSourceFunc>(repaintEverythingSoonTimeout), this); }
void RenderTheme::paintSliderTicks(RenderObject* o, const PaintInfo& paintInfo, const IntRect& rect) { Node* node = o->node(); if (!node) return; HTMLInputElement* input = node->toInputElement(); if (!input) return; HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list()); if (!dataList) return; double min = input->minimum(); double max = input->maximum(); ControlPart part = o->style()->appearance(); // We don't support ticks on alternate sliders like MediaVolumeSliders. if (part != SliderHorizontalPart && part != SliderVerticalPart) return; bool isHorizontal = part == SliderHorizontalPart; IntSize thumbSize; RenderObject* thumbRenderer = input->sliderThumbElement()->renderer(); if (thumbRenderer) { RenderStyle* thumbStyle = thumbRenderer->style(); int thumbWidth = thumbStyle->width().intValue(); int thumbHeight = thumbStyle->height().intValue(); thumbSize.setWidth(isHorizontal ? thumbWidth : thumbHeight); thumbSize.setHeight(isHorizontal ? thumbHeight : thumbWidth); } IntSize tickSize = sliderTickSize(); float zoomFactor = o->style()->effectiveZoom(); FloatRect tickRect; int tickRegionSideMargin = 0; int tickRegionWidth = 0; IntRect trackBounds; RenderObject* trackRenderer = input->sliderTrackElement()->renderer(); // We can ignoring transforms because transform is handled by the graphics context. if (trackRenderer) trackBounds = trackRenderer->absoluteBoundingBoxRectIgnoringTransforms(); IntRect sliderBounds = o->absoluteBoundingBoxRectIgnoringTransforms(); // Make position relative to the transformed ancestor element. trackBounds.setX(trackBounds.x() - sliderBounds.x() + rect.x()); trackBounds.setY(trackBounds.y() - sliderBounds.y() + rect.y()); if (isHorizontal) { tickRect.setWidth(floor(tickSize.width() * zoomFactor)); tickRect.setHeight(floor(tickSize.height() * zoomFactor)); tickRect.setY(floor(rect.y() + rect.height() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor)); tickRegionSideMargin = trackBounds.x() + (thumbSize.width() - tickSize.width() * zoomFactor) / 2.0; tickRegionWidth = trackBounds.width() - thumbSize.width(); } else { tickRect.setWidth(floor(tickSize.height() * zoomFactor)); tickRect.setHeight(floor(tickSize.width() * zoomFactor)); tickRect.setX(floor(rect.x() + rect.width() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor)); tickRegionSideMargin = trackBounds.y() + (thumbSize.width() - tickSize.width() * zoomFactor) / 2.0; tickRegionWidth = trackBounds.height() - thumbSize.width(); } RefPtr<HTMLCollection> options = dataList->options(); GraphicsContextStateSaver stateSaver(*paintInfo.context); paintInfo.context->setFillColor(o->style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB); for (unsigned i = 0; Node* node = options->item(i); i++) { ASSERT(node->hasTagName(optionTag)); HTMLOptionElement* optionElement = toHTMLOptionElement(node); String value = optionElement->value(); if (!input->isValidValue(value)) continue; double parsedValue = parseToDoubleForNumberType(input->sanitizeValue(value)); double tickFraction = (parsedValue - min) / (max - min); double tickRatio = isHorizontal && o->style()->isLeftToRightDirection() ? tickFraction : 1.0 - tickFraction; double tickPosition = round(tickRegionSideMargin + tickRegionWidth * tickRatio); if (isHorizontal) tickRect.setX(tickPosition); else tickRect.setY(tickPosition); paintInfo.context->fillRect(tickRect); } }
void ChromeClientJS::widgetSizeChanged(const IntSize& oldWidgetSize, IntSize newSize) { webkitTrace(); MainFrame& frame = (m_view->m_private->mainFrame->coreFrame()->mainFrame()); if(frame.view()) { frame.view()->resize(newSize.width(),newSize.height()); frame.view()->adjustViewSize(); if(frame.view()->needsLayout()) frame.view()->layout(); } if (m_view->m_private->acceleratedContext && m_view->m_private->acceleratedContext->enabled()) { m_view->m_private->acceleratedContext->resizeRootLayer(newSize); return; } if (m_view->m_private->backingStore && oldWidgetSize == newSize) return; if (m_view->m_private->backingStore) { const IntSize& oldSize = m_view->m_private->backingStore->size(); if (newSize.width() > oldSize.width()) newSize.setWidth(std::max(newSize.width(), static_cast<int>(oldSize.width() * 1.5))); if (newSize.height() > oldSize.height()) newSize.setHeight(std::max(newSize.height(), static_cast<int>(oldSize.height() * 1.5))); } // If we did not have a backing store before or if the backing store is growing, we need // to reallocate a new one and set it up so that we don't see artifacts while resizing. if (!m_view->m_private->backingStore || newSize.width() > m_view->m_private->backingStore->size().width() || newSize.height() > m_view->m_private->backingStore->size().height()) { SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, newSize.width(), newSize.height(), 32, //SDL_HWSURFACE | SDL_HWPALETTE 0x00FF0000, /* Rmask */ 0x0000FF00, /* Gmask */ 0x000000FF, /* Bmask */ 0xFF000000); /* Amask */ PassOwnPtr<WidgetBackingStore> newBackingStore = WebCore::WidgetBackingStoreCairo::create(surface, newSize); RefPtr<cairo_t> cr = adoptRef(cairo_create(newBackingStore->cairoSurface())); clearEverywhereInBackingStore(m_view, cr.get()); // Now we copy the old backing store image over the new cleared surface to prevent // annoying flashing as the widget grows. We do the "real" paint in a timeout // since we don't want to block resizing too long. if (m_view->m_private->backingStore) { cairo_set_source_surface(cr.get(), m_view->m_private->backingStore->cairoSurface(), 0, 0); cairo_rectangle(cr.get(), 0, 0, m_view->m_private->backingStore->size().width(), m_view->m_private->backingStore->size().height()); cairo_fill(cr.get()); } m_view->m_private->backingStore = newBackingStore; } else if (oldWidgetSize.width() < newSize.width() || oldWidgetSize.height() < newSize.height()) { // The widget is growing, but we did not need to create a new backing store. // We should clear any old data outside of the old widget region. RefPtr<cairo_t> cr = adoptRef(cairo_create(m_view->m_private->backingStore->cairoSurface())); clipOutOldWidgetArea(cr.get(), oldWidgetSize, newSize); clearEverywhereInBackingStore(m_view, cr.get()); } // We need to force a redraw and ignore the framerate cap. m_lastDisplayTime = 0; m_dirtyRegion.unite(IntRect(IntPoint(), m_view->m_private->backingStore->size())); // WebCore timers by default have a lower priority which leads to more artifacts when opaque // resize is on emscripten_async_call((void (*)(void *))(&repaintEverythingSoonTimeout), this, 0); }