void TouchCaret::SetTouchFramePos(const nsRect& aCaretRect) { nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell); if (!presShell) { return; } mozilla::dom::Element* touchCaretElement = presShell->GetTouchCaretElement(); if (!touchCaretElement) { return; } // Convert aOrigin to CSS pixels. nsRefPtr<nsPresContext> presContext = presShell->GetPresContext(); int32_t x = presContext->AppUnitsToIntCSSPixels(aCaretRect.Center().x); int32_t y = presContext->AppUnitsToIntCSSPixels(aCaretRect.y); int32_t padding = presContext->AppUnitsToIntCSSPixels(aCaretRect.height); nsAutoString styleStr; styleStr.AppendLiteral("left: "); styleStr.AppendInt(x); styleStr.AppendLiteral("px; top: "); styleStr.AppendInt(y); styleStr.AppendLiteral("px; padding-top: "); styleStr.AppendInt(padding); styleStr.AppendLiteral("px;"); TOUCHCARET_LOG("Set style: %s", NS_ConvertUTF16toUTF8(styleStr).get()); touchCaretElement->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr, true); }
static void SetFramePos(dom::Element* aElement, const nsRect& aCaretRect) { if (!aElement) { return; } nsAutoString styleStr; styleStr.AppendLiteral("left: "); styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aCaretRect.Center().x)); styleStr.AppendLiteral("px; top: "); styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aCaretRect.y)); styleStr.AppendLiteral("px; padding-top: "); styleStr.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(aCaretRect.height)); styleStr.AppendLiteral("px;"); SELECTIONCARETS_LOG_STATIC("Set style: %s", NS_ConvertUTF16toUTF8(styleStr).get()); aElement->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleStr, true); }