void WebPopupMenuProxyGtk::showPopupMenu(const IntRect& rect, TextDirection, double /* pageScaleFactor */, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex) { populatePopupMenu(items); gtk_menu_set_active(GTK_MENU(m_popup), selectedIndex); resetTypeAheadFindState(); IntPoint menuPosition = convertWidgetPointToScreenPoint(m_webView, rect.location()); menuPosition.move(0, rect.height()); // This approach follows the one in gtkcombobox.c. GtkRequisition requisition; gtk_widget_set_size_request(m_popup, -1, -1); gtk_widget_get_preferred_size(m_popup, &requisition, nullptr); gtk_widget_set_size_request(m_popup, std::max(rect.width(), requisition.width), -1); if (int itemCount = items.size()) { GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(m_popup))); int i; GList* child; for (i = 0, child = children.get(); i < itemCount; i++, child = g_list_next(child)) { if (i > selectedIndex) break; GtkWidget* item = GTK_WIDGET(child->data); GtkRequisition itemRequisition; gtk_widget_get_preferred_size(item, &itemRequisition, nullptr); menuPosition.setY(menuPosition.y() - itemRequisition.height); } } else { // Center vertically the empty popup in the combo box area. menuPosition.setY(menuPosition.y() - rect.height() / 2); } const GdkEvent* event = m_client->currentlyProcessedMouseDownEvent() ? m_client->currentlyProcessedMouseDownEvent()->nativeEvent() : nullptr; gtk_menu_popup_for_device(GTK_MENU(m_popup), event ? gdk_event_get_device(event) : nullptr, nullptr, nullptr, [](GtkMenu*, gint* x, gint* y, gboolean* pushIn, gpointer userData) { // We can pass a pointer to the menuPosition local variable because the nested main loop ensures this is called in the function context. IntPoint* menuPosition = static_cast<IntPoint*>(userData); *x = menuPosition->x(); *y = menuPosition->y(); *pushIn = menuPosition->y() < 0; }, &menuPosition, nullptr, event && event->type == GDK_BUTTON_PRESS ? event->button.button : 1, event ? gdk_event_get_time(event) : GDK_CURRENT_TIME); // Now that the menu has a position, schedule a resize to make sure it's resized to fit vertically in the work area. gtk_widget_queue_resize(m_popup); // PopupMenu can fail to open when there is no mouse grab. // Ensure WebCore does not go into some pesky state. if (!gtk_widget_get_visible(m_popup)) { m_client->failedToShowPopupMenu(); return; } }
// This method calculates the exitPoint from the startingRect and the entryPoint into the candidate rect. // The line between those 2 points is the closest distance between the 2 rects. void entryAndExitPointsForDirection(FocusDirection direction, const IntRect& startingRect, const IntRect& potentialRect, IntPoint& exitPoint, IntPoint& entryPoint) { switch (direction) { case FocusDirectionLeft: exitPoint.setX(startingRect.x()); entryPoint.setX(potentialRect.maxX()); break; case FocusDirectionUp: exitPoint.setY(startingRect.y()); entryPoint.setY(potentialRect.maxY()); break; case FocusDirectionRight: exitPoint.setX(startingRect.maxX()); entryPoint.setX(potentialRect.x()); break; case FocusDirectionDown: exitPoint.setY(startingRect.maxY()); entryPoint.setY(potentialRect.y()); break; default: ASSERT_NOT_REACHED(); } switch (direction) { case FocusDirectionLeft: case FocusDirectionRight: if (below(startingRect, potentialRect)) { exitPoint.setY(startingRect.y()); entryPoint.setY(potentialRect.maxY()); } else if (below(potentialRect, startingRect)) { exitPoint.setY(startingRect.maxY()); entryPoint.setY(potentialRect.y()); } else { exitPoint.setY(max(startingRect.y(), potentialRect.y())); entryPoint.setY(exitPoint.y()); } break; case FocusDirectionUp: case FocusDirectionDown: if (rightOf(startingRect, potentialRect)) { exitPoint.setX(startingRect.x()); entryPoint.setX(potentialRect.maxX()); } else if (rightOf(potentialRect, startingRect)) { exitPoint.setX(startingRect.maxX()); entryPoint.setX(potentialRect.x()); } else { exitPoint.setX(max(startingRect.x(), potentialRect.x())); entryPoint.setX(exitPoint.x()); } break; default: ASSERT_NOT_REACHED(); } }
void ContextMenuController::handleContextMenuEvent(Event* event) { ASSERT(event->type() == eventNames().contextmenuEvent); if (!event->isMouseEvent()) return; MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); IntPoint point = IntPoint(mouseEvent->pageX(), mouseEvent->pageY()); HitTestResult result(point); if (Frame* frame = event->target()->toNode()->document()->frame()) { float zoomFactor = frame->pageZoomFactor(); point.setX(static_cast<int>(point.x() * zoomFactor)); point.setY(static_cast<int>(point.y() * zoomFactor)); result = frame->eventHandler()->hitTestResultAtPoint(point, false); } if (!result.innerNonSharedNode()) return; m_contextMenu.set(new ContextMenu(result)); m_contextMenu->populate(); if (m_page->inspectorController()->enabled()) m_contextMenu->addInspectElementItem(); PlatformMenuDescription customMenu = m_client->getCustomMenuFromDefaultItems(m_contextMenu.get()); m_contextMenu->setPlatformDescription(customMenu); event->setDefaultHandled(); }
IntPoint ScrollableArea::nearestActiveSnapPoint(const IntPoint& currentPosition) { if (!horizontalSnapOffsets() && !verticalSnapOffsets()) return currentPosition; if (!existingScrollAnimator()) return currentPosition; IntPoint correctedPosition = currentPosition; if (horizontalSnapOffsets()) { const auto& horizontal = *horizontalSnapOffsets(); size_t activeIndex = currentHorizontalSnapPointIndex(); if (activeIndex < horizontal.size()) correctedPosition.setX(horizontal[activeIndex].toInt()); } if (verticalSnapOffsets()) { const auto& vertical = *verticalSnapOffsets(); size_t activeIndex = currentVerticalSnapPointIndex(); if (activeIndex < vertical.size()) correctedPosition.setY(vertical[activeIndex].toInt()); } return correctedPosition; }
void DragController::doImageDrag(Element* element, const IntPoint& dragOrigin, const IntRect& rect, Clipboard* clipboard, Frame* frame, IntPoint& dragImageOffset) { IntPoint mouseDownPoint = dragOrigin; DragImageRef dragImage; IntPoint origin; Image* image = getImage(element); if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea) { IntSize originalSize = rect.size(); origin = rect.location(); dragImage = createDragImageFromImage(image); IntSize newSize; if (dragImage) { dragImage = fitDragImageToMaxSize(dragImage, maxDragImageSize()); dragImage = dissolveDragImageToFraction(dragImage, DragImageAlpha); newSize = dragImageSize(dragImage); } // Properly orient the drag image and orient it differently if it's smaller than the original float scale = newSize.width() / (float)originalSize.width(); float dx = origin.x() - mouseDownPoint.x(); dx *= scale; origin.setX((int)(dx + 0.5)); #if PLATFORM(MAC) //Compensate for accursed flipped coordinates in cocoa origin.setY(origin.y() + originalSize.height()); #endif float dy = origin.y() - mouseDownPoint.y(); dy *= scale; origin.setY((int)(dy + 0.5)); } else { dragImage = createDragImageIconForCachedImage(getCachedImage(element)); if (dragImage) origin = IntPoint(DragIconRightInset - dragImageSize(dragImage).width(), DragIconBottomInset); } dragImageOffset.setX(mouseDownPoint.x() + origin.x()); dragImageOffset.setY(mouseDownPoint.y() + origin.y()); doSystemDrag(dragImage, dragImageOffset, dragOrigin, clipboard, frame, false); deleteDragImage(dragImage); }
inline void FELighting::LightingData::topRight(int offset, IntPoint& normalVector) { int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); offset += widthMultipliedByPixelSize; int bottomLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); normalVector.setX(-(left << 1) + (center << 1) - bottomLeft + bottom); normalVector.setY(-left - (center << 1) + bottomLeft + (bottom << 1)); }
inline void FELighting::LightingData::bottomRight(int offset, IntPoint& normalVector) { int left = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); offset -= widthMultipliedByPixelSize; int topLeft = static_cast<int>(pixels->item(offset - cPixelSize + cAlphaChannelOffset)); int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); normalVector.setX(-topLeft + top - (left << 1) + (center << 1)); normalVector.setY(-topLeft - (top << 1) + left + (center << 1)); }
inline void FELighting::LightingData::leftColumn(int offset, IntPoint& normalVector) { int center = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); int right = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); offset -= widthMultipliedByPixelSize; int top = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); int topRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); offset += widthMultipliedByPixelSize << 1; int bottom = static_cast<int>(pixels->item(offset + cAlphaChannelOffset)); int bottomRight = static_cast<int>(pixels->item(offset + cPixelSize + cAlphaChannelOffset)); normalVector.setX(-top + topRight - (center << 1) + (right << 1) - bottom + bottomRight); normalVector.setY(-(top << 1) - topRight + (bottom << 1) + bottomRight); }
void RenderMathMLRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset) { RenderMathMLBlock::paint(info, paintOffset); if (info.context->paintingDisabled()) return; IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location() + contentBoxRect().location()); int startX = adjustedPaintOffset.x(); int frontWidth = lroundf(gFrontWidthEms * style()->fontSize()); int overbarWidth = roundToInt(contentLogicalWidth()) + m_overbarLeftPointShift; int baseHeight = roundToInt(contentLogicalHeight()); int rootPad = lroundf(gSpaceAboveEms * style()->fontSize()); adjustedPaintOffset.setY(adjustedPaintOffset.y() - rootPad); float radicalDipLeftPointYPos = (index() ? gRootRadicalDipLeftPointYPos : gSqrtRadicalDipLeftPointYPos) * baseHeight; FloatPoint overbarLeftPoint(startX - m_overbarLeftPointShift, adjustedPaintOffset.y()); FloatPoint bottomPoint(startX - gRadicalBottomPointXFront * frontWidth, adjustedPaintOffset.y() + baseHeight + gRadicalBottomPointLower); FloatPoint dipLeftPoint(startX - gRadicalDipLeftPointXFront * frontWidth, adjustedPaintOffset.y() + radicalDipLeftPointYPos); FloatPoint leftEnd(startX - frontWidth, dipLeftPoint.y() + gRadicalLeftEndYShiftEms * style()->fontSize()); GraphicsContextStateSaver stateSaver(*info.context); info.context->setStrokeThickness(gRadicalLineThicknessEms * style()->fontSize()); info.context->setStrokeStyle(SolidStroke); info.context->setStrokeColor(style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB); info.context->setLineJoin(MiterJoin); info.context->setMiterLimit(style()->fontSize()); Path root; root.moveTo(FloatPoint(overbarLeftPoint.x() + overbarWidth, adjustedPaintOffset.y())); // draw top root.addLineTo(overbarLeftPoint); // draw from top left corner to bottom point of radical root.addLineTo(bottomPoint); // draw from bottom point to top of left part of radical base "dip" root.addLineTo(dipLeftPoint); // draw to end root.addLineTo(leftEnd); info.context->strokePath(root); GraphicsContextStateSaver maskStateSaver(*info.context); // Build a mask to draw the thick part of the root. Path mask; mask.moveTo(overbarLeftPoint); mask.addLineTo(bottomPoint); mask.addLineTo(dipLeftPoint); mask.addLineTo(FloatPoint(2 * dipLeftPoint.x() - leftEnd.x(), 2 * dipLeftPoint.y() - leftEnd.y())); info.context->clip(mask); // Draw the thick part of the root. info.context->setStrokeThickness(gRadicalThickLineThicknessEms * style()->fontSize()); info.context->setLineCap(SquareCap); Path line; line.moveTo(bottomPoint); line.addLineTo(dipLeftPoint); info.context->strokePath(line); }
void SliderThumbElement::defaultEventHandler(Event* event) { if (!event->isMouseEvent() #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) && !event->isTouchEvent() #endif ) { HTMLDivElement::defaultEventHandler(event); return; } #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) bool isLeftButton = false; if (event->isMouseEvent()) { MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); isLeftButton = mouseEvent->button() == LeftButton; } #else MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); bool isLeftButton = mouseEvent->button() == LeftButton; #endif const AtomicString& eventType = event->type(); if (eventType == eventNames().mousedownEvent && isLeftButton #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) || eventType == eventNames().touchstartEvent #endif ) { startDragging(); return; } else if (eventType == eventNames().mouseupEvent && isLeftButton #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) || eventType == eventNames().touchendEvent || eventType == eventNames().touchcancelEvent #endif ) { stopDragging(); return; } else if (eventType == eventNames().mousemoveEvent #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) || eventType == eventNames().touchmoveEvent #endif ) { if (m_inDragMode) #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) { if (event->isMouseEvent()) { MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); #endif setPositionFromPoint(mouseEvent->absoluteLocation()); #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) } else if (event->isTouchEvent()) { TouchEvent* touchEvent = static_cast<TouchEvent*>(event); if (touchEvent->touches() && touchEvent->touches()->item(0)) { IntPoint curPoint; curPoint.setX(touchEvent->touches()->item(0)->pageX()); curPoint.setY(touchEvent->touches()->item(0)->pageY()); setPositionFromPoint(curPoint); // Tell the webview that webkit will handle the following move events event->setDefaultPrevented(true); } } } #endif return; } HTMLDivElement::defaultEventHandler(event); }
void WebPopupMenuProxyGtk::showPopupMenu(const IntRect& rect, TextDirection, double /* pageScaleFactor */, const Vector<WebPopupItem>& items, const PlatformPopupMenuData&, int32_t selectedIndex) { populatePopupMenu(items); gtk_menu_set_active(GTK_MENU(m_popup), selectedIndex); resetTypeAheadFindState(); IntPoint menuPosition = convertWidgetPointToScreenPoint(m_webView, rect.location()); menuPosition.move(0, rect.height()); // This approach follows the one in gtkcombobox.c. GtkRequisition requisition; gtk_widget_set_size_request(m_popup, -1, -1); gtk_widget_get_preferred_size(m_popup, &requisition, nullptr); gtk_widget_set_size_request(m_popup, std::max(rect.width(), requisition.width), -1); if (int itemCount = items.size()) { GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(m_popup))); int i; GList* child; for (i = 0, child = children.get(); i < itemCount; i++, child = g_list_next(child)) { if (i > selectedIndex) break; GtkWidget* item = GTK_WIDGET(child->data); GtkRequisition itemRequisition; gtk_widget_get_preferred_size(item, &itemRequisition, nullptr); menuPosition.setY(menuPosition.y() - itemRequisition.height); } } else { // Center vertically the empty popup in the combo box area. menuPosition.setY(menuPosition.y() - rect.height() / 2); } gulong unmapHandler = g_signal_connect(m_popup, "unmap", G_CALLBACK(menuUnmapped), this); const GdkEvent* event = m_client->currentlyProcessedMouseDownEvent() ? m_client->currentlyProcessedMouseDownEvent()->nativeEvent() : nullptr; gtk_menu_popup_for_device(GTK_MENU(m_popup), event ? gdk_event_get_device(event) : nullptr, nullptr, nullptr, [](GtkMenu*, gint* x, gint* y, gboolean* pushIn, gpointer userData) { // We can pass a pointer to the menuPosition local variable because the nested main loop ensures this is called in the function context. IntPoint* menuPosition = static_cast<IntPoint*>(userData); *x = menuPosition->x(); *y = menuPosition->y(); *pushIn = TRUE; }, &menuPosition, nullptr, event && event->type == GDK_BUTTON_PRESS ? event->button.button : 1, event ? gdk_event_get_time(event) : GDK_CURRENT_TIME); // Now that the menu has a position, schedule a resize to make sure it's resized to fit vertically in the work area. gtk_widget_queue_resize(m_popup); // PopupMenu can fail to open when there is no mouse grab. // Ensure WebCore does not go into some pesky state. if (!gtk_widget_get_visible(m_popup)) { m_client->failedToShowPopupMenu(); return; } // WebPageProxy expects the menu to run in a nested run loop, since it invalidates the // menu right after calling WebPopupMenuProxy::showPopupMenu(). m_runLoop = adoptGRef(g_main_loop_new(nullptr, FALSE)); // This is to suppress warnings about gdk_threads_leave and gdk_threads_enter. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" gdk_threads_leave(); g_main_loop_run(m_runLoop.get()); gdk_threads_enter(); #pragma GCC diagnostic pop m_runLoop.clear(); g_signal_handler_disconnect(m_popup, unmapHandler); if (!m_client) return; m_client->valueChangedForPopupMenu(this, m_activeItem); }
int Frame::checkOverflowScroll(OverflowScrollAction action) { Position extent = selection().selection().extent(); if (extent.isNull()) return OverflowScrollNone; RenderObject* renderer = extent.deprecatedNode()->renderer(); if (!renderer) return OverflowScrollNone; FrameView* view = this->view(); if (!view) return OverflowScrollNone; RenderBlock* containingBlock = renderer->containingBlock(); if (!containingBlock || !containingBlock->hasOverflowClip()) return OverflowScrollNone; RenderLayer* layer = containingBlock->layer(); ASSERT(layer); IntRect visibleRect = IntRect(view->scrollX(), view->scrollY(), view->visibleWidth(), view->visibleHeight()); IntPoint position = m_overflowAutoScrollPos; if (visibleRect.contains(position.x(), position.y())) return OverflowScrollNone; int scrollType = 0; int deltaX = 0; int deltaY = 0; IntPoint selectionPosition; // This constant will make the selection draw a little bit beyond the edge of the visible area. // This prevents a visual glitch, in that you can fail to select a portion of a character that // is being rendered right at the edge of the visible rectangle. // FIXME: This probably needs improvement, and may need to take the font size into account. static const int scrollBoundsAdjustment = 3; // FIXME: Make a small buffer at the end of a visible rectangle so that autoscrolling works // even if the visible extends to the limits of the screen. if (position.x() < visibleRect.x()) { scrollType |= OverflowScrollLeft; if (action == PerformOverflowScroll) { deltaX -= static_cast<int>(m_overflowAutoScrollDelta); selectionPosition.setX(view->scrollX() - scrollBoundsAdjustment); } } else if (position.x() > visibleRect.maxX()) { scrollType |= OverflowScrollRight; if (action == PerformOverflowScroll) { deltaX += static_cast<int>(m_overflowAutoScrollDelta); selectionPosition.setX(view->scrollX() + view->visibleWidth() + scrollBoundsAdjustment); } } if (position.y() < visibleRect.y()) { scrollType |= OverflowScrollUp; if (action == PerformOverflowScroll) { deltaY -= static_cast<int>(m_overflowAutoScrollDelta); selectionPosition.setY(view->scrollY() - scrollBoundsAdjustment); } } else if (position.y() > visibleRect.maxY()) { scrollType |= OverflowScrollDown; if (action == PerformOverflowScroll) { deltaY += static_cast<int>(m_overflowAutoScrollDelta); selectionPosition.setY(view->scrollY() + view->visibleHeight() + scrollBoundsAdjustment); } } Ref<Frame> protectedThis(*this); if (action == PerformOverflowScroll && (deltaX || deltaY)) { layer->scrollToOffset(layer->scrollOffset() + IntSize(deltaX, deltaY)); // Handle making selection. VisiblePosition visiblePosition(renderer->positionForPoint(selectionPosition, nullptr)); if (visiblePosition.isNotNull()) { VisibleSelection visibleSelection = selection().selection(); visibleSelection.setExtent(visiblePosition); if (selection().granularity() != CharacterGranularity) visibleSelection.expandUsingGranularity(selection().granularity()); if (selection().shouldChangeSelection(visibleSelection)) selection().setSelection(visibleSelection); } m_overflowAutoScrollDelta *= 1.02f; // Accelerate the scroll } return scrollType; }
void RenderMathMLRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset) { RenderMathMLBlock::paint(info, paintOffset); if (info.context->paintingDisabled()) return; if (!firstChild() || !lastChild()) return; IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location()); RenderBoxModelObject* baseWrapper = toRenderBoxModelObject(lastChild()); int baseHeight = baseWrapper->pixelSnappedOffsetHeight(); // default to the font size in pixels if we're empty if (!baseHeight) baseHeight = style()->fontSize(); int overbarWidth = baseWrapper->pixelSnappedOffsetWidth(); int indexWidth = 0; RenderObject* current = firstChild(); while (current != lastChild()) { if (current->isBoxModelObject()) { RenderBoxModelObject* box = toRenderBoxModelObject(current); indexWidth += box->pixelSnappedOffsetWidth(); } current = current->nextSibling(); } int frontWidth = static_cast<int>(style()->fontSize() * gFrontWidthEms); int overbarLeftPointShift = 0; // Base height above which the shape of the root changes int thresholdHeight = static_cast<int>(gThresholdBaseHeightEms * style()->fontSize()); if (baseHeight > thresholdHeight && thresholdHeight) { float shift = (baseHeight - thresholdHeight) / static_cast<float>(thresholdHeight); if (shift > 1.) shift = 1.0f; overbarLeftPointShift = static_cast<int>(gRadicalBottomPointXFront * frontWidth * shift); } overbarWidth += overbarLeftPointShift; int rootPad = static_cast<int>(gRootPaddingEms * style()->fontSize()); int startX = adjustedPaintOffset.x() + indexWidth + gRadicalLeftExtra + style()->paddingLeft().value() - rootPad; adjustedPaintOffset.setY(adjustedPaintOffset.y() + style()->paddingTop().value() - rootPad); FloatPoint overbarLeftPoint(startX - overbarLeftPointShift, adjustedPaintOffset.y()); FloatPoint bottomPoint(startX - gRadicalBottomPointXFront * frontWidth, adjustedPaintOffset.y() + baseHeight + gRadicalBottomPointLower); FloatPoint dipLeftPoint(startX - gRadicalDipLeftPointXFront * frontWidth, adjustedPaintOffset.y() + gRadicalDipLeftPointYPos * baseHeight); FloatPoint leftEnd(startX - frontWidth, dipLeftPoint.y() + gRadicalLeftEndYShiftEms * style()->fontSize()); GraphicsContextStateSaver stateSaver(*info.context); info.context->setStrokeThickness(gRadicalLineThicknessEms * style()->fontSize()); info.context->setStrokeStyle(SolidStroke); info.context->setStrokeColor(style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB); info.context->setLineJoin(MiterJoin); info.context->setMiterLimit(style()->fontSize()); Path root; root.moveTo(FloatPoint(overbarLeftPoint.x() + overbarWidth, adjustedPaintOffset.y())); // draw top root.addLineTo(overbarLeftPoint); // draw from top left corner to bottom point of radical root.addLineTo(bottomPoint); // draw from bottom point to top of left part of radical base "dip" root.addLineTo(dipLeftPoint); // draw to end root.addLineTo(leftEnd); info.context->strokePath(root); GraphicsContextStateSaver maskStateSaver(*info.context); // Build a mask to draw the thick part of the root. Path mask; mask.moveTo(overbarLeftPoint); mask.addLineTo(bottomPoint); mask.addLineTo(dipLeftPoint); mask.addLineTo(FloatPoint(2 * dipLeftPoint.x() - leftEnd.x(), 2 * dipLeftPoint.y() - leftEnd.y())); info.context->clip(mask); // Draw the thick part of the root. info.context->setStrokeThickness(gRadicalThickLineThicknessEms * style()->fontSize()); info.context->setLineCap(SquareCap); Path line; line.moveTo(bottomPoint); line.addLineTo(dipLeftPoint); info.context->strokePath(line); }
// SDL ttf implementation may be lighter ??? void Font::drawSimpleText(BIGraphicsContext* context, const TextRun& run, const TextStyle& style, const FloatPoint& point) const { WebCore::Color text_color = context->strokeColor(); BINativeImage* text_surface; IntRect dst_rect; IntPoint intPoint; static int oldx = 0; int text_width, text_height; bool init = false; int numSpaces = 0; int padPerSpace = 0; FloatPoint wordPoint(point); // Process normal, bold, italic styles if (m_fontDescription.italic()) { if (m_fontDescription.bold()) { // Bold && italic d->m_ttfFont->style = FT_STYLE_BOLD | FT_STYLE_ITALIC; d->flushCache(d->m_ttfFont); } else { // Only italic d->m_ttfFont->style = FT_STYLE_ITALIC; d->flushCache(d->m_ttfFont); } } else if (m_fontDescription.bold()) { // Only bold d->m_ttfFont->style = FT_STYLE_BOLD; d->flushCache(d->m_ttfFont); } else { d->m_ttfFont->style = FT_STYLE_NORMAL; d->flushCache(d->m_ttfFont); } // Draw font int wordSize = run.length() - run.from(); UChar word[wordSize]; copyTextRunTo(run, word); for (int i = 0; i <= wordSize; i++) { if (Font::treatAsSpace(word[i])) numSpaces++;; } if (numSpaces == 0) padPerSpace = 0; else padPerSpace = static_cast<int> (ceil(style.padding() / numSpaces)); UChar text[wordSize + 1]; int j = 0; for (int i = 0; i <= wordSize; i++) { if (Font::treatAsSpace(word[i]) || i == wordSize) { text[j] = ' '; text[++j] = '\0'; d->sizeUnicode(d->m_ttfFont, text, &text_width, &text_height); text_surface = d->renderUnicodeBlended(d->m_ttfFont, text, text_color, context->alphaLayer()); if (text_surface) { intPoint.setX(static_cast<uint16_t> (wordPoint.x())); intPoint.setY(static_cast<uint16_t> (wordPoint.y()) - ascent()); dst_rect.setX(0); dst_rect.setY(0); dst_rect.setWidth(text_surface->size().width()); dst_rect.setHeight(text_surface->size().height()); getBIGraphicsDevice()->copy(*(context->widget()), *text_surface, dst_rect, intPoint, context->alphaLayer()); delete text_surface; } wordPoint = wordPoint + FloatSize(padPerSpace + text_width,0); j = 0; } else { text[j] = word[i]; j++; } } }