void Scrollbar::setFrameRect(const IntRect& rect) { // Get our window resizer rect and see if we overlap. Adjust to avoid the overlap // if necessary. IntRect adjustedRect(rect); if (parent()) { bool overlapsResizer = false; ScrollView* view = parent(); IntRect resizerRect = view->convertFromContainingWindow(view->windowResizerRect()); if (rect.intersects(resizerRect)) { if (orientation() == HorizontalScrollbar) { int overlap = rect.right() - resizerRect.x(); if (overlap > 0 && resizerRect.right() >= rect.right()) { adjustedRect.setWidth(rect.width() - overlap); overlapsResizer = true; } } else { int overlap = rect.bottom() - resizerRect.y(); if (overlap > 0 && resizerRect.bottom() >= rect.bottom()) { adjustedRect.setHeight(rect.height() - overlap); overlapsResizer = true; } } } if (overlapsResizer != m_overlapsResizer) { m_overlapsResizer = overlapsResizer; view->adjustScrollbarsAvoidingResizerCount(m_overlapsResizer ? 1 : -1); } } Widget::setFrameRect(adjustedRect); }
void PlatformScrollbar::setRect(const IntRect& rect) { // Get our window resizer rect and see if we overlap. Adjust to avoid the overlap // if necessary. IntRect adjustedRect(rect); if (parent() && parent()->isFrameView()) { bool overlapsResizer = false; FrameView* view = static_cast<FrameView*>(parent()); IntRect resizerRect = view->windowResizerRect(); resizerRect.setLocation(view->convertFromContainingWindow(resizerRect.location())); if (rect.intersects(resizerRect)) { if (orientation() == HorizontalScrollbar) { int overlap = rect.right() - resizerRect.x(); if (overlap > 0 && resizerRect.right() >= rect.right()) { adjustedRect.setWidth(rect.width() - overlap); overlapsResizer = true; } } else { int overlap = rect.bottom() - resizerRect.y(); if (overlap > 0 && resizerRect.bottom() >= rect.bottom()) { adjustedRect.setHeight(rect.height() - overlap); overlapsResizer = true; } } } if (overlapsResizer != m_overlapsResizer) { m_overlapsResizer = overlapsResizer; view->adjustOverlappingScrollbarCount(m_overlapsResizer ? 1 : -1); } } setFrameGeometry(adjustedRect); }
bool RenderThemeSafari::paintMenuListButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r) { IntRect bounds = IntRect(r.x() + o->style()->borderLeftWidth(), r.y() + o->style()->borderTopWidth(), r.width() - o->style()->borderLeftWidth() - o->style()->borderRightWidth(), r.height() - o->style()->borderTopWidth() - o->style()->borderBottomWidth()); // Draw the gradients to give the styled popup menu a button appearance paintMenuListButtonGradients(o, paintInfo, bounds); // Since we actually know the size of the control here, we restrict the font scale to make sure the arrow will fit vertically in the bounds float fontScale = min(o->style()->fontSize() / baseFontSize, bounds.height() / baseArrowHeight); float centerY = bounds.y() + bounds.height() / 2.0f; float arrowHeight = baseArrowHeight * fontScale; float arrowWidth = baseArrowWidth * fontScale; float leftEdge = bounds.right() - arrowPaddingRight - arrowWidth; if (bounds.width() < arrowWidth + arrowPaddingLeft) return false; paintInfo.context->save(); paintInfo.context->setFillColor(o->style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB); paintInfo.context->setStrokeColor(NoStroke, ColorSpaceDeviceRGB); FloatPoint arrow[3]; arrow[0] = FloatPoint(leftEdge, centerY - arrowHeight / 2.0f); arrow[1] = FloatPoint(leftEdge + arrowWidth, centerY - arrowHeight / 2.0f); arrow[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY + arrowHeight / 2.0f); // Draw the arrow paintInfo.context->drawConvexPolygon(3, arrow, true); Color leftSeparatorColor(0, 0, 0, 40); Color rightSeparatorColor(255, 255, 255, 40); // FIXME: Should the separator thickness and space be scaled up by fontScale? int separatorSpace = 2; int leftEdgeOfSeparator = static_cast<int>(leftEdge - arrowPaddingLeft); // FIXME: Round? // Draw the separator to the left of the arrows paintInfo.context->setStrokeThickness(1.0f); paintInfo.context->setStrokeStyle(SolidStroke); paintInfo.context->setStrokeColor(leftSeparatorColor, ColorSpaceDeviceRGB); paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator, bounds.y()), IntPoint(leftEdgeOfSeparator, bounds.bottom())); paintInfo.context->setStrokeColor(rightSeparatorColor, ColorSpaceDeviceRGB); paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.y()), IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.bottom())); paintInfo.context->restore(); return false; }
void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, ImageBufferData& data, const IntSize& size) { ASSERT(cairo_surface_get_type(data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE); unsigned char* dataDst = cairo_image_surface_get_data(data.m_surface); ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); int originx = sourceRect.x(); int destx = destPoint.x() + sourceRect.x(); ASSERT(destx >= 0); ASSERT(destx < size.width()); ASSERT(originx >= 0); ASSERT(originx <= sourceRect.right()); int endx = destPoint.x() + sourceRect.right(); ASSERT(endx <= size.width()); int numColumns = endx - destx; int originy = sourceRect.y(); int desty = destPoint.y() + sourceRect.y(); ASSERT(desty >= 0); ASSERT(desty < size.height()); ASSERT(originy >= 0); ASSERT(originy <= sourceRect.bottom()); int endy = destPoint.y() + sourceRect.bottom(); ASSERT(endy <= size.height()); int numRows = endy - desty; unsigned srcBytesPerRow = 4 * source->width(); int stride = cairo_image_surface_get_stride(data.m_surface); unsigned char* srcRows = source->data()->data()->data() + originy * srcBytesPerRow + originx * 4; for (int y = 0; y < numRows; ++y) { unsigned* row = reinterpret_cast<unsigned*>(dataDst + stride * (y + desty)); for (int x = 0; x < numColumns; x++) { int basex = x * 4; unsigned* pixel = row + x + destx; Color pixelColor(srcRows[basex], srcRows[basex + 1], srcRows[basex + 2], srcRows[basex + 3]); if (multiplied == Unmultiplied) *pixel = premultipliedARGBFromColor(pixelColor); else *pixel = pixelColor.rgb(); } srcRows += srcBytesPerRow; } }
void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) { ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); int originx = sourceRect.x(); int destx = destPoint.x() + sourceRect.x(); ASSERT(destx >= 0); ASSERT(destx < m_size.width()); ASSERT(originx >= 0); ASSERT(originx <= sourceRect.right()); int endx = destPoint.x() + sourceRect.right(); ASSERT(endx <= m_size.width()); int numColumns = endx - destx; int originy = sourceRect.y(); int desty = destPoint.y() + sourceRect.y(); ASSERT(desty >= 0); ASSERT(desty < m_size.height()); ASSERT(originy >= 0); ASSERT(originy <= sourceRect.bottom()); int endy = destPoint.y() + sourceRect.bottom(); ASSERT(endy <= m_size.height()); int numRows = endy - desty; unsigned srcBytesPerRow = 4 * source->width(); bool isPainting = m_data.m_painter->isActive(); if (isPainting) m_data.m_painter->end(); QImage image = m_data.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32); unsigned char* srcRows = source->data()->data()->data() + originy * srcBytesPerRow + originx * 4; for (int y = 0; y < numRows; ++y) { quint32* scanLine = reinterpret_cast<quint32*>(image.scanLine(y + desty)); for (int x = 0; x < numColumns; x++) { int basex = x * 4; scanLine[x + destx] = reinterpret_cast<quint32*>(srcRows + basex)[0]; } srcRows += srcBytesPerRow; } m_data.m_pixmap = QPixmap::fromImage(image); if (isPainting) m_data.m_painter->begin(&m_data.m_pixmap); }
void GraphicsContext::addRoundedRectClip(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight) { if (paintingDisabled()) return; // Need sufficient width and height to contain these curves. Sanity check our // corner radii and our width/height values to make sure the curves can all fit. if (static_cast<unsigned>(rect.width()) < static_cast<unsigned>(topLeft.width()) + static_cast<unsigned>(topRight.width()) || static_cast<unsigned>(rect.width()) < static_cast<unsigned>(bottomLeft.width()) + static_cast<unsigned>(bottomRight.width()) || static_cast<unsigned>(rect.height()) < static_cast<unsigned>(topLeft.height()) + static_cast<unsigned>(bottomLeft.height()) || static_cast<unsigned>(rect.height()) < static_cast<unsigned>(topRight.height()) + static_cast<unsigned>(bottomRight.height())) return; // Clip to our rect. clip(rect); // OK, the curves can fit. CGContextRef context = platformContext(); // Add the four ellipses to the path. Technically this really isn't good enough, since we could end up // not clipping the other 3/4 of the ellipse we don't care about. We're relying on the fact that for // normal use cases these ellipses won't overlap one another (or when they do the curvature of one will // be subsumed by the other). CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.y(), topLeft.width() * 2, topLeft.height() * 2)); CGContextAddEllipseInRect(context, CGRectMake(rect.right() - topRight.width() * 2, rect.y(), topRight.width() * 2, topRight.height() * 2)); CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.bottom() - bottomLeft.height() * 2, bottomLeft.width() * 2, bottomLeft.height() * 2)); CGContextAddEllipseInRect(context, CGRectMake(rect.right() - bottomRight.width() * 2, rect.bottom() - bottomRight.height() * 2, bottomRight.width() * 2, bottomRight.height() * 2)); // Now add five rects (one for each edge rect in between the rounded corners and one for the interior). CGContextAddRect(context, CGRectMake(rect.x() + topLeft.width(), rect.y(), rect.width() - topLeft.width() - topRight.width(), max(topLeft.height(), topRight.height()))); CGContextAddRect(context, CGRectMake(rect.x() + bottomLeft.width(), rect.bottom() - max(bottomLeft.height(), bottomRight.height()), rect.width() - bottomLeft.width() - bottomRight.width(), max(bottomLeft.height(), bottomRight.height()))); CGContextAddRect(context, CGRectMake(rect.x(), rect.y() + topLeft.height(), max(topLeft.width(), bottomLeft.width()), rect.height() - topLeft.height() - bottomLeft.height())); CGContextAddRect(context, CGRectMake(rect.right() - max(topRight.width(), bottomRight.width()), rect.y() + topRight.height(), max(topRight.width(), bottomRight.width()), rect.height() - topRight.height() - bottomRight.height())); CGContextAddRect(context, CGRectMake(rect.x() + max(topLeft.width(), bottomLeft.width()), rect.y() + max(topLeft.height(), topRight.height()), rect.width() - max(topLeft.width(), bottomLeft.width()) - max(topRight.width(), bottomRight.width()), rect.height() - max(topLeft.height(), topRight.height()) - max(bottomLeft.height(), bottomRight.height()))); CGContextClip(context); }
// Computes the distance from a point outside a rect to the nearest edge of the rect. static IntSize distanceToRect(const IntPoint& point, const IntRect& rect) { int dx = 0, dy = 0; if (point.x() < rect.x()) dx = point.x() - rect.x(); else if (rect.right() < point.x()) dx = point.x() - rect.right(); if (point.y() < rect.y()) dy = point.y() - rect.y(); else if (rect.bottom() < point.y()) dy = point.y() - rect.bottom(); return IntSize(dx, dy); }
void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, const SkBitmap& bitmap, const IntSize& size) { ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); int originX = sourceRect.x(); int destX = destPoint.x() + sourceRect.x(); ASSERT(destX >= 0); ASSERT(destX < size.width()); ASSERT(originX >= 0); ASSERT(originX < sourceRect.right()); int endX = destPoint.x() + sourceRect.right(); ASSERT(endX <= size.width()); int numColumns = endX - destX; int originY = sourceRect.y(); int destY = destPoint.y() + sourceRect.y(); ASSERT(destY >= 0); ASSERT(destY < size.height()); ASSERT(originY >= 0); ASSERT(originY < sourceRect.bottom()); int endY = destPoint.y() + sourceRect.bottom(); ASSERT(endY <= size.height()); int numRows = endY - destY; ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); SkAutoLockPixels bitmapLock(bitmap); unsigned srcBytesPerRow = 4 * source->width(); const unsigned char* srcRow = source->data()->data()->data() + originY * srcBytesPerRow + originX * 4; for (int y = 0; y < numRows; ++y) { uint32_t* destRow = bitmap.getAddr32(destX, destY + y); for (int x = 0; x < numColumns; ++x) { const unsigned char* srcPixel = &srcRow[x * 4]; if (multiplied == Unmultiplied) destRow[x] = SkPreMultiplyARGB(srcPixel[3], srcPixel[0], srcPixel[1], srcPixel[2]); else destRow[x] = SkPackARGB32(srcPixel[3], srcPixel[0], srcPixel[1], srcPixel[2]); } srcRow += srcBytesPerRow; } }
void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) { ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); int originx = sourceRect.x(); int destx = destPoint.x() + sourceRect.x(); ASSERT(destx >= 0); ASSERT(destx < m_size.width()); ASSERT(originx >= 0); ASSERT(originx <= sourceRect.right()); int endx = destPoint.x() + sourceRect.right(); ASSERT(endx <= m_size.width()); int numColumns = endx - destx; int originy = sourceRect.y(); int desty = destPoint.y() + sourceRect.y(); ASSERT(desty >= 0); ASSERT(desty < m_size.height()); ASSERT(originy >= 0); ASSERT(originy <= sourceRect.bottom()); int endy = destPoint.y() + sourceRect.bottom(); ASSERT(endy <= m_size.height()); int numRows = endy - desty; unsigned srcBytesPerRow = 4 * source->width(); unsigned destBytesPerRow = 4 * m_size.width(); unsigned char* srcRows = source->data()->data().data() + originy * srcBytesPerRow + originx * 4; unsigned char* destRows = reinterpret_cast<unsigned char*>(m_data) + desty * destBytesPerRow + destx * 4; for (int y = 0; y < numRows; ++y) { for (int x = 0; x < numColumns; x++) { int basex = x * 4; unsigned char alpha = srcRows[basex + 3]; if (alpha != 255) { destRows[basex] = (srcRows[basex] * alpha + 254) / 255; destRows[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255; destRows[basex + 2] = (srcRows[basex + 2] * alpha + 254) / 255; destRows[basex + 3] = alpha; } else { reinterpret_cast<uint32_t*>(destRows + basex)[0] = reinterpret_cast<uint32_t*>(srcRows + basex)[0]; } } destRows += destBytesPerRow; srcRows += srcBytesPerRow; } }
void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) { ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); int originx = sourceRect.x(); int destx = destPoint.x() + sourceRect.x(); ASSERT(destx >= 0); ASSERT(destx < m_size.width()); ASSERT(originx >= 0); ASSERT(originx < sourceRect.right()); int endx = destPoint.x() + sourceRect.right(); ASSERT(endx <= m_size.width()); int numColumns = endx - destx; int originy = sourceRect.y(); int desty = destPoint.y() + sourceRect.y(); ASSERT(desty >= 0); ASSERT(desty < m_size.height()); ASSERT(originy >= 0); ASSERT(originy < sourceRect.bottom()); int endy = destPoint.y() + sourceRect.bottom(); ASSERT(endy <= m_size.height()); int numRows = endy - desty; const SkBitmap& bitmap = *context()->platformContext()->bitmap(); ASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); SkAutoLockPixels bitmapLock(bitmap); unsigned srcBytesPerRow = 4 * source->width(); const unsigned char* srcRow = source->data()->data().data() + originy * srcBytesPerRow + originx * 4; for (int y = 0; y < numRows; ++y) { uint32_t* destRow = bitmap.getAddr32(destx, desty + y); for (int x = 0; x < numColumns; ++x) { const unsigned char* srcPixel = &srcRow[x * 4]; destRow[x] = SkPreMultiplyARGB(srcPixel[3], srcPixel[0], srcPixel[1], srcPixel[2]); } srcRow += srcBytesPerRow; } }
PassRefPtr<ImageData> ImageBufferData::getImageData(const IntRect& rect, const IntSize& size, VGImageFormat format) const { ASSERT(m_surface); PassRefPtr<ImageData> result = ImageData::create(rect.width(), rect.height()); unsigned char* data = result->data()->data()->data(); // If this copy operation won't fill all of the pixels in the target image, // paint it black in order to avoid random uninitialized pixel garbage. if (rect.x() < 0 || rect.y() < 0 || (rect.right()) > size.width() || (rect.bottom()) > size.height()) memset(data, 0, result->data()->length()); if (!m_tiledImage) m_surface->makeCurrent(); // OpenVG ignores pixels that are out of bounds, so we can just // call vgReadPixels() without any further safety assurances. if (m_surface->isCurrent()) { vgReadPixels(data, rect.width() * 4, format, rect.x(), rect.y(), rect.width(), rect.height()); } else { vgGetImageSubData(m_tiledImage->tile(0, 0), data, rect.width() * 4, format, rect.x(), rect.y(), rect.width(), rect.height()); } ASSERT_VG_NO_ERROR(); return result; }
// Draws a filled rectangle with a stroked border. void GraphicsContext::drawRect(const IntRect& rect) { // FIXME: this function does not handle patterns and gradients // like drawPath does, it probably should. if (paintingDisabled()) return; CGContextRef context = platformContext(); CGContextFillRect(context, rect); if (strokeStyle() != NoStroke) { // We do a fill of four rects to simulate the stroke of a border. Color oldFillColor = fillColor(); if (oldFillColor != strokeColor()) setCGFillColor(context, strokeColor(), strokeColorSpace()); CGRect rects[4] = { FloatRect(rect.x(), rect.y(), rect.width(), 1), FloatRect(rect.x(), rect.bottom() - 1, rect.width(), 1), FloatRect(rect.x(), rect.y() + 1, 1, rect.height() - 2), FloatRect(rect.right() - 1, rect.y() + 1, 1, rect.height() - 2) }; CGContextFillRects(context, rects, 4); if (oldFillColor != strokeColor()) setCGFillColor(context, oldFillColor, fillColorSpace()); } }
bool IntRect::intersects(const IntRect &other) const { // Checking emptiness handles negative widths as well as zero. return !isEmpty() && !other.isEmpty() && x() < other.right() && other.x() < right() && y() < other.bottom() && other.y() < bottom(); }
// Draws a filled rectangle with a stroked border. void GraphicsContext::drawRect(const IntRect& rect) { if (paintingDisabled()) return; CGContextRef context = platformContext(); if (fillColor().alpha()) CGContextFillRect(context, rect); if (strokeStyle() != NoStroke && strokeColor().alpha()) { // We do a fill of four rects to simulate the stroke of a border. Color oldFillColor = fillColor(); if (oldFillColor != strokeColor()) setCGFillColor(context, strokeColor()); CGRect rects[4] = { FloatRect(rect.x(), rect.y(), rect.width(), 1), FloatRect(rect.x(), rect.bottom() - 1, rect.width(), 1), FloatRect(rect.x(), rect.y() + 1, 1, rect.height() - 2), FloatRect(rect.right() - 1, rect.y() + 1, 1, rect.height() - 2) }; CGContextFillRects(context, rects, 4); if (oldFillColor != strokeColor()) setCGFillColor(context, oldFillColor); } }
void ImageBufferData::putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, VGImageFormat format) { ASSERT(m_surface); ASSERT(sourceRect.width() > 0); ASSERT(sourceRect.height() > 0); // We expect the sourceRect to be a subset of the given source image. ASSERT(sourceRect.x() >= 0); ASSERT(sourceRect.y() >= 0); ASSERT(sourceRect.right() <= source->width()); ASSERT(sourceRect.bottom() <= source->height()); // The target origin point is the combined offset of sourceRect.location() // and destPoint. int destx = destPoint.x() + sourceRect.x(); int desty = destPoint.y() + sourceRect.y(); ASSERT(destx >= 0); ASSERT(desty >= 0); ASSERT(destx + sourceRect.width() <= size.width()); ASSERT(desty + sourceRect.height() <= size.height()); unsigned const char* data = source->data()->data()->data(); int dataOffset = (sourceRect.y() * source->width() * 4) + (sourceRect.x() * 4); m_surface->makeCurrent(); vgWritePixels(data + dataOffset, source->width() * 4, format, destx, desty, sourceRect.width(), sourceRect.height()); ASSERT_VG_NO_ERROR(); }
static gboolean webkit_web_view_popup_menu_handler(GtkWidget* widget) { static const int contextMenuMargin = 1; // The context menu event was generated from the keyboard, so show the context menu by the current selection. Page* page = core(webView_s); FrameView* view = page->mainFrame()->view(); Position start = page->mainFrame()->selection()->selection().start(); Position end = page->mainFrame()->selection()->selection().end(); int rightAligned = FALSE; IntPoint location; if (!start.node() || !end.node()) location = IntPoint(rightAligned ? view->contentsWidth() - contextMenuMargin : contextMenuMargin, contextMenuMargin); else { RenderObject* renderer = start.node()->renderer(); if (!renderer) return FALSE; // Calculate the rect of the first line of the selection (cribbed from -[WebCoreFrameBridge firstRectForDOMRange:]). int extraWidthToEndOfLine = 0; InlineBox* startInlineBox; int startCaretOffset; start.getInlineBoxAndOffset(DOWNSTREAM, startInlineBox, startCaretOffset); IntRect startCaretRect = renderer->localCaretRect(startInlineBox, startCaretOffset, &extraWidthToEndOfLine); InlineBox* endInlineBox; int endCaretOffset; end.getInlineBoxAndOffset(UPSTREAM, endInlineBox, endCaretOffset); IntRect endCaretRect = renderer->localCaretRect(endInlineBox, endCaretOffset); IntRect firstRect; if (startCaretRect.y() == endCaretRect.y()) firstRect = IntRect(MIN(startCaretRect.x(), endCaretRect.x()), startCaretRect.y(), abs(endCaretRect.x() - startCaretRect.x()), MAX(startCaretRect.height(), endCaretRect.height())); else firstRect = IntRect(startCaretRect.x(), startCaretRect.y(), startCaretRect.width() + extraWidthToEndOfLine, startCaretRect.height()); location = IntPoint(rightAligned ? firstRect.right() : firstRect.x(), firstRect.bottom()); } int x, y; gdk_window_get_origin(GTK_WIDGET(view->root()->hostWindow()->platformWindow())->window, &x, &y); // FIXME: The IntSize(0, -1) is a hack to get the hit-testing to result in the selected element. // Ideally we'd have the position of a context menu event be separate from its target node. location = view->contentsToWindow(location) + IntSize(0, -1); IntPoint global = location + IntSize(x, y); PlatformMouseEvent event(location, global, NoButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time()); return false;//webkit_web_view_forward_context_menu_event(WEBKIT_WEB_VIEW(widget), event); }
bool PlatformScrollbar::thumbUnderMouse() { // Construct a rect. IntRect thumb = thumbRect(); thumb.move(-x(), -y()); int begin = (m_orientation == HorizontalScrollbar) ? thumb.x() : thumb.y(); int end = (m_orientation == HorizontalScrollbar) ? thumb.right() : thumb.bottom(); return (begin <= m_pressedPos && m_pressedPos < end); }
bool PlatformScrollbar::thumbUnderMouse() { // Construct a rect. IntRect thumb = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &m_opt, QStyle::SC_ScrollBarSlider, 0); thumb.move(-m_opt.rect.x(), -m_opt.rect.y()); int begin = (m_orientation == HorizontalScrollbar) ? thumb.x() : thumb.y(); int end = (m_orientation == HorizontalScrollbar) ? thumb.right() : thumb.bottom(); return (begin <= m_pressedPos && m_pressedPos < end); }
void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color) { if (paintingDisabled() || !color.alpha()) return; CGContextRef context = platformContext(); Color oldFillColor = fillColor(); if (oldFillColor != color) setCGFillColor(context, color); // Add the four ellipses to the path. Technically this really isn't good enough, since we could end up // not clipping the other 3/4 of the ellipse we don't care about. We're relying on the fact that for // normal use cases these ellipses won't overlap one another (or when they do the curvature of one will // be subsumed by the other). CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.y(), topLeft.width() * 2, topLeft.height() * 2)); CGContextAddEllipseInRect(context, CGRectMake(rect.right() - topRight.width() * 2, rect.y(), topRight.width() * 2, topRight.height() * 2)); CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.bottom() - bottomLeft.height() * 2, bottomLeft.width() * 2, bottomLeft.height() * 2)); CGContextAddEllipseInRect(context, CGRectMake(rect.right() - bottomRight.width() * 2, rect.bottom() - bottomRight.height() * 2, bottomRight.width() * 2, bottomRight.height() * 2)); // Now add five rects (one for each edge rect in between the rounded corners and one for the interior). CGContextAddRect(context, CGRectMake(rect.x() + topLeft.width(), rect.y(), rect.width() - topLeft.width() - topRight.width(), max(topLeft.height(), topRight.height()))); CGContextAddRect(context, CGRectMake(rect.x() + bottomLeft.width(), rect.bottom() - max(bottomLeft.height(), bottomRight.height()), rect.width() - bottomLeft.width() - bottomRight.width(), max(bottomLeft.height(), bottomRight.height()))); CGContextAddRect(context, CGRectMake(rect.x(), rect.y() + topLeft.height(), max(topLeft.width(), bottomLeft.width()), rect.height() - topLeft.height() - bottomLeft.height())); CGContextAddRect(context, CGRectMake(rect.right() - max(topRight.width(), bottomRight.width()), rect.y() + topRight.height(), max(topRight.width(), bottomRight.width()), rect.height() - topRight.height() - bottomRight.height())); CGContextAddRect(context, CGRectMake(rect.x() + max(topLeft.width(), bottomLeft.width()), rect.y() + max(topLeft.height(), topRight.height()), rect.width() - max(topLeft.width(), bottomLeft.width()) - max(topRight.width(), bottomRight.width()), rect.height() - max(topLeft.height(), topRight.height()) - max(bottomLeft.height(), bottomRight.height()))); CGContextFillPath(context); if (oldFillColor != color) setCGFillColor(context, oldFillColor); }
void RootInlineBox::addHighlightOverflow() { // Highlight acts as a selection inflation. FloatRect rootRect(0, selectionTop(), width(), selectionHeight()); IntRect inflatedRect = enclosingIntRect(object()->document()->frame()->customHighlightLineRect(object()->style()->highlight(), rootRect)); m_leftOverflow = min(m_leftOverflow, inflatedRect.x()); m_rightOverflow = max(m_rightOverflow, inflatedRect.right()); m_topOverflow = min(m_topOverflow, inflatedRect.y()); m_bottomOverflow = max(m_bottomOverflow, inflatedRect.bottom()); }
void PluginView::invalidateRect(const IntRect& rect) { if (m_isWindowed) { RECT invalidRect = { rect.x(), rect.y(), rect.right(), rect.bottom() }; ::InvalidateRect(platformPluginWidget(), &invalidRect, false); return; } invalidateWindowlessPluginRect(rect); }
bool RenderThemeChromiumSkia::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& rect) { // Make a thumb similar to the scrollbar thumb. const bool hovered = isHovered(o) || toRenderSlider(o->parent())->inDragMode(); const int midx = rect.x() + rect.width() / 2; const int midy = rect.y() + rect.height() / 2; const bool vertical = (o->style()->appearance() == SliderThumbVerticalPart); SkCanvas* const canvas = i.context->platformContext()->canvas(); const SkColor thumbLightGrey = SkColorSetARGB(0xff, 0xf4, 0xf2, 0xef); const SkColor thumbDarkGrey = SkColorSetARGB(0xff, 0xea, 0xe5, 0xe0); SkPaint paint; paint.setColor(hovered ? SK_ColorWHITE : thumbLightGrey); SkIRect skrect; if (vertical) skrect.set(rect.x(), rect.y(), midx + 1, rect.bottom()); else skrect.set(rect.x(), rect.y(), rect.right(), midy + 1); canvas->drawIRect(skrect, paint); paint.setColor(hovered ? thumbLightGrey : thumbDarkGrey); if (vertical) skrect.set(midx + 1, rect.y(), rect.right(), rect.bottom()); else skrect.set(rect.x(), midy + 1, rect.right(), rect.bottom()); canvas->drawIRect(skrect, paint); const SkColor borderDarkGrey = SkColorSetARGB(0xff, 0x9d, 0x96, 0x8e); paint.setColor(borderDarkGrey); drawBox(canvas, rect, paint); if (rect.height() > 10 && rect.width() > 10) { drawHorizLine(canvas, midx - 2, midx + 2, midy, paint); drawHorizLine(canvas, midx - 2, midx + 2, midy - 3, paint); drawHorizLine(canvas, midx - 2, midx + 2, midy + 3, paint); } return false; }
HRESULT STDMETHODCALLTYPE WebScrollBar::frameGeometry( /* [retval][out] */ RECT* bounds) { if (!bounds) return E_POINTER; IntRect rect = m_scrollBar->frameGeometry(); bounds->left = rect.x(); bounds->right = rect.right(); bounds->top = rect.y(); bounds->bottom = rect.bottom(); return S_OK; }
void ScrollbarThemeBal::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part) { context->save(); context->drawRect(rect); context->fillRect(rect, Color::gray); bool start = (part == BackButtonStartPart); if (start) { if (scrollbar->orientation() == HorizontalScrollbar) { context->drawLine(IntPoint(rect.right(), rect.y()), IntPoint(rect.x(), (rect.bottom() + rect.y())/2)); context->drawLine(IntPoint(rect.right(), rect.bottom()), IntPoint(rect.x(), (rect.bottom() + rect.y())/2)); } else { context->drawLine(IntPoint(rect.x(), rect.bottom()), IntPoint((rect.x() + rect.right())/2, rect.y())); context->drawLine(IntPoint(rect.right(), rect.bottom()), IntPoint((rect.x() + rect.right())/2, rect.y())); } } else { if (scrollbar->orientation() == HorizontalScrollbar) { context->drawLine(IntPoint(rect.x(), rect.y()), IntPoint(rect.right(), (rect.bottom() + rect.y())/2)); context->drawLine(IntPoint(rect.x(), rect.bottom()), IntPoint(rect.right(), (rect.bottom() + rect.y())/2)); } else { context->drawLine(IntPoint(rect.x(), rect.y()), IntPoint((rect.x() + rect.right())/2, rect.bottom())); context->drawLine(IntPoint(rect.right(), rect.y()), IntPoint((rect.x() + rect.right())/2, rect.bottom())); } } context->restore(); }
static IntPoint dragLocForSelectionDrag(Frame* src) { IntRect draggingRect = enclosingIntRect(src->visibleSelectionRect()); int xpos = draggingRect.right(); xpos = draggingRect.x() < xpos ? draggingRect.x() : xpos; int ypos = draggingRect.bottom(); #if PLATFORM(MAC) // Deal with flipped coordinates on Mac ypos = draggingRect.y() > ypos ? draggingRect.y() : ypos; #else ypos = draggingRect.y() < ypos ? draggingRect.y() : ypos; #endif return IntPoint(xpos, ypos); }
HRESULT STDMETHODCALLTYPE DOMHTMLInputElement::rectOnScreen( /* [retval][out] */ LPRECT rect) { rect->left = rect->top = rect->right = rect->bottom = 0; RenderObject* renderer = m_element->renderer(); FrameView* view = m_element->document()->view(); if (!renderer || !view) return E_FAIL; IntRect coreRect = renderer->absoluteBoundingBoxRect(); coreRect.setLocation(view->contentsToWindow(coreRect.location())); rect->left = coreRect.x(); rect->top = coreRect.y(); rect->right = coreRect.right(); rect->bottom = coreRect.bottom(); return S_OK; }
int PlatformScrollbar::pixelPosToRangeValue(int pos) const { int thumbLen = thumbLength(); IntRect track = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &m_opt, QStyle::SC_ScrollBarGroove, 0); int thumbMin, thumbMax; if (m_orientation == HorizontalScrollbar) { thumbMin = track.x(); thumbMax = track.right() - thumbLen + 1; } else { thumbMin = track.y(); thumbMax = track.bottom() - thumbLen + 1; } return QStyle::sliderValueFromPosition(0, m_totalSize - m_visibleSize, pos - thumbMin, thumbMax - thumbMin, m_opt.upsideDown); }
void IntRect::intersect(const IntRect &other) { int l = max(x(), other.x()); int t = max(y(), other.y()); int r = min(right(), other.right()); int b = min(bottom(), other.bottom()); // Return a clean empty rectangle for non-intersecting cases. if (l >= r || t >= b) { l = 0; t = 0; r = 0; b = 0; } m_location.setX(l); m_location.setY(t); m_size.setWidth(r - l); m_size.setHeight(b - t); }
void IntRect::unite(const IntRect& other) { // Handle empty special cases first. if (other.isEmpty()) return; if (isEmpty()) { *this = other; return; } int l = min(x(), other.x()); int t = min(y(), other.y()); int r = max(right(), other.right()); int b = max(bottom(), other.bottom()); m_location.setX(l); m_location.setY(t); m_size.setWidth(r - l); m_size.setHeight(b - t); }
static bool isRectInDirection(FocusDirection direction, const IntRect& curRect, const IntRect& targetRect) { IntPoint center(targetRect.center()); int targetMiddle = isHorizontalMove(direction) ? center.x() : center.y(); switch (direction) { case FocusDirectionLeft: return targetMiddle < curRect.x(); case FocusDirectionRight: return targetMiddle > curRect.right(); case FocusDirectionUp: return targetMiddle < curRect.y(); case FocusDirectionDown: return targetMiddle > curRect.bottom(); default: ASSERT_NOT_REACHED(); } return false; }