本文整理汇总了C++中FloatRect::setWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ FloatRect::setWidth方法的具体用法?C++ FloatRect::setWidth怎么用?C++ FloatRect::setWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FloatRect
的用法示例。
在下文中一共展示了FloatRect::setWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintMediaPlayButton
bool RenderThemeWinCE::paintMediaPlayButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
{
bool rc = paintButton(o, paintInfo, r);
FloatRect imRect = r;
imRect.inflate(-3);
paintInfo.context->save();
paintInfo.context->setStrokeColor(Color::black);
paintInfo.context->setFillColor(Color::black);
HTMLMediaElement* mediaElement = mediaElementParent(o->node());
bool paused = !mediaElement || mediaElement->paused();
if (paused) {
float width = imRect.width();
imRect.setWidth(width / 3.0);
paintInfo.context->fillRect(imRect);
imRect.move(2.0 * width / 3.0, 0);
paintInfo.context->fillRect(imRect);
} else {
FloatPoint pts[3] = { FloatPoint(imRect.x(), imRect.y()), FloatPoint(imRect.maxX(), (imRect.y() + imRect.maxY()) / 2.0), FloatPoint(imRect.x(), imRect.maxY()) };
paintInfo.context->drawConvexPolygon(3, pts);
}
paintInfo.context->restore();
return rc;
}
示例2: drawPattern
void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& dstRect)
{
if (m_data.m_tiledImage && context != m_context.get()) {
FloatRect src = srcRect;
if (src.width() == -1)
src.setWidth(m_data.m_tiledImage->size().width());
if (src.height() == -1)
src.setHeight(m_data.m_tiledImage->size().height());
ASSERT(context->platformContext()->activePainter());
AffineTransform phasedPatternTransform;
phasedPatternTransform.translate(phase.x(), phase.y());
phasedPatternTransform.multLeft(patternTransform);
PatternOpenVG pattern(m_data.m_tiledImage, src);
pattern.setTransformation(phasedPatternTransform);
PainterOpenVG* painter = context->platformContext()->activePainter();
PaintOpenVG currentPaint = painter->fillPaint();
CompositeOperator currentOp = painter->compositeOperation();
painter->setCompositeOperation(op);
painter->setFillPattern(pattern);
painter->drawRect(dstRect, VG_FILL_PATH);
painter->setFillPaint(currentPaint);
painter->setCompositeOperation(currentOp);
return;
}
RefPtr<Image> imageCopy = copyImage();
imageCopy->drawPattern(context, srcRect, patternTransform, phase, styleColorSpace, op, dstRect);
}
示例3: roundToDevicePixels
FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect, RoundingMode)
{
FloatRect result;
double x = frect.x();
double y = frect.y();
cairo_t* cr = platformContext()->cr();
cairo_user_to_device(cr, &x, &y);
x = round(x);
y = round(y);
cairo_device_to_user(cr, &x, &y);
result.setX(narrowPrecisionToFloat(x));
result.setY(narrowPrecisionToFloat(y));
// We must ensure width and height are at least 1 (or -1) when
// we're given float values in the range between 0 and 1 (or -1 and 0).
double width = frect.width();
double height = frect.height();
cairo_user_to_device_distance(cr, &width, &height);
if (width > -1 && width < 0)
width = -1;
else if (width > 0 && width < 1)
width = 1;
else
width = round(width);
if (height > -1 && width < 0)
height = -1;
else if (height > 0 && height < 1)
height = 1;
else
height = round(height);
cairo_device_to_user_distance(cr, &width, &height);
result.setWidth(narrowPrecisionToFloat(width));
result.setHeight(narrowPrecisionToFloat(height));
return result;
}
示例4: adjustParametersForTiledDrawing
void Gradient::adjustParametersForTiledDrawing(FloatSize& size, FloatRect& srcRect, const FloatSize& spacing)
{
if (m_radial)
return;
if (srcRect.isEmpty())
return;
if (!spacing.isZero())
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);
}
示例5: draw
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const FloatRect& srcRect, ColorSpace styleColorSpace, CompositeOperator compositeOp)
{
startAnimation();
RetainPtr<CGImageRef> image = frameAtIndex(m_currentFrame);
if (!image) // If it's too early we won't have an image yet.
return;
if (mayFillWithSolidColor()) {
fillWithSolidColor(ctxt, destRect, solidColor(), styleColorSpace, compositeOp);
return;
}
float currHeight = CGImageGetHeight(image.get());
if (currHeight <= srcRect.y())
return;
CGContextRef context = ctxt->platformContext();
ctxt->save();
bool shouldUseSubimage = false;
// If the source rect is a subportion of the image, then we compute an inflated destination rect that will hold the entire image
// and then set a clip to the portion that we want to display.
FloatRect adjustedDestRect = destRect;
FloatSize selfSize = currentFrameSize();
if (srcRect.size() != selfSize) {
CGInterpolationQuality interpolationQuality = CGContextGetInterpolationQuality(context);
// When the image is scaled using high-quality interpolation, we create a temporary CGImage
// containing only the portion we want to display. We need to do this because high-quality
// interpolation smoothes sharp edges, causing pixels from outside the source rect to bleed
// into the destination rect. See <rdar://problem/6112909>.
shouldUseSubimage = (interpolationQuality == kCGInterpolationHigh || interpolationQuality == kCGInterpolationDefault) && (srcRect.size() != destRect.size() || !ctxt->getCTM().isIdentityOrTranslationOrFlipped());
float xScale = srcRect.width() / destRect.width();
float yScale = srcRect.height() / destRect.height();
if (shouldUseSubimage) {
FloatRect subimageRect = srcRect;
float leftPadding = srcRect.x() - floorf(srcRect.x());
float topPadding = srcRect.y() - floorf(srcRect.y());
subimageRect.move(-leftPadding, -topPadding);
adjustedDestRect.move(-leftPadding / xScale, -topPadding / yScale);
subimageRect.setWidth(ceilf(subimageRect.width() + leftPadding));
adjustedDestRect.setWidth(subimageRect.width() / xScale);
subimageRect.setHeight(ceilf(subimageRect.height() + topPadding));
adjustedDestRect.setHeight(subimageRect.height() / yScale);
image.adoptCF(CGImageCreateWithImageInRect(image.get(), subimageRect));
if (currHeight < srcRect.bottom()) {
ASSERT(CGImageGetHeight(image.get()) == currHeight - CGRectIntegral(srcRect).origin.y);
adjustedDestRect.setHeight(CGImageGetHeight(image.get()) / yScale);
}
} else {
adjustedDestRect.setLocation(FloatPoint(destRect.x() - srcRect.x() / xScale, destRect.y() - srcRect.y() / yScale));
adjustedDestRect.setSize(FloatSize(selfSize.width() / xScale, selfSize.height() / yScale));
}
CGContextClipToRect(context, destRect);
}
// If the image is only partially loaded, then shrink the destination rect that we're drawing into accordingly.
if (!shouldUseSubimage && currHeight < selfSize.height())
adjustedDestRect.setHeight(adjustedDestRect.height() * currHeight / selfSize.height());
ctxt->setCompositeOperation(compositeOp);
// Flip the coords.
CGContextScaleCTM(context, 1, -1);
adjustedDestRect.setY(-adjustedDestRect.bottom());
// Adjust the color space.
image = imageWithColorSpace(image.get(), styleColorSpace);
// Draw the image.
CGContextDrawImage(context, adjustedDestRect, image.get());
ctxt->restore();
if (imageObserver())
imageObserver()->didDraw(this);
}
示例6: drawRectShadowWithTiling
void ShadowBlur::drawRectShadowWithTiling(GraphicsContext* graphicsContext, const FloatRect& shadowedRect, const RoundedIntRect::Radii& radii, const IntSize& shadowTemplateSize)
{
const float roundedRadius = ceilf(m_blurRadius);
const float twiceRadius = roundedRadius * 2;
// Size of the tiling side.
const int templateSideLength = 1;
m_layerImage = ScratchBuffer::shared().getScratchBuffer(shadowTemplateSize);
// Draw shadow into a new ImageBuffer.
GraphicsContext* shadowContext = m_layerImage->context();
shadowContext->save();
shadowContext->clearRect(FloatRect(0, 0, shadowTemplateSize.width(), shadowTemplateSize.height()));
// Draw the rectangle.
FloatRect templateRect = FloatRect(roundedRadius, roundedRadius, shadowTemplateSize.width() - twiceRadius, shadowTemplateSize.height() - twiceRadius);
Path path;
path.addRoundedRect(templateRect, radii.topLeft(), radii.topRight(), radii.bottomLeft(), radii.bottomRight());
shadowContext->setFillColor(Color(.0f, .0f, .0f, 1.f), ColorSpaceDeviceRGB);
shadowContext->fillPath(path);
// Blur the image.
{
IntRect blurRect(IntPoint(), shadowTemplateSize);
RefPtr<ByteArray> layerData = m_layerImage->getUnmultipliedImageData(blurRect);
blurLayerImage(layerData->data(), blurRect.size(), blurRect.width() * 4);
m_layerImage->putUnmultipliedImageData(layerData.get(), blurRect.size(), blurRect, IntPoint());
}
// Mask the image with the shadow color.
shadowContext->setCompositeOperation(CompositeSourceIn);
shadowContext->setFillColor(m_color, m_colorSpace);
shadowContext->fillRect(FloatRect(0, 0, shadowTemplateSize.width(), shadowTemplateSize.height()));
shadowContext->restore();
FloatRect shadowRect = shadowedRect;
shadowRect.inflate(roundedRadius); // FIXME: duplicating code with calculateLayerBoundingRect.
shadowRect.move(m_offset.width(), m_offset.height());
// Fill the internal part of the shadow.
shadowRect.inflate(-twiceRadius);
if (!shadowRect.isEmpty()) {
graphicsContext->save();
path.clear();
path.addRoundedRect(shadowRect, radii.topLeft(), radii.topRight(), radii.bottomLeft(), radii.bottomRight());
graphicsContext->setFillColor(m_color, m_colorSpace);
graphicsContext->fillPath(path);
graphicsContext->restore();
}
shadowRect.inflate(twiceRadius);
// Note that drawing the ImageBuffer is faster than creating a Image and drawing that,
// because ImageBuffer::draw() knows that it doesn't have to copy the image bits.
// Draw top side.
FloatRect tileRect = FloatRect(twiceRadius + radii.topLeft().width(), 0, templateSideLength, twiceRadius);
FloatRect destRect = tileRect;
destRect.move(shadowRect.x(), shadowRect.y());
destRect.setWidth(shadowRect.width() - radii.topLeft().width() - radii.topRight().width() - roundedRadius * 4);
graphicsContext->drawImageBuffer(m_layerImage, ColorSpaceDeviceRGB, destRect, tileRect);
// Draw the bottom side.
tileRect = FloatRect(twiceRadius + radii.bottomLeft().width(), shadowTemplateSize.height() - twiceRadius, templateSideLength, twiceRadius);
destRect = tileRect;
destRect.move(shadowRect.x(), shadowRect.y() + twiceRadius + shadowedRect.height() - shadowTemplateSize.height());
destRect.setWidth(shadowRect.width() - radii.bottomLeft().width() - radii.bottomRight().width() - roundedRadius * 4);
graphicsContext->drawImageBuffer(m_layerImage, ColorSpaceDeviceRGB, destRect, tileRect);
// Draw the right side.
tileRect = FloatRect(shadowTemplateSize.width() - twiceRadius, twiceRadius + radii.topRight().height(), twiceRadius, templateSideLength);
destRect = tileRect;
destRect.move(shadowRect.x() + twiceRadius + shadowedRect.width() - shadowTemplateSize.width(), shadowRect.y());
destRect.setHeight(shadowRect.height() - radii.topRight().height() - radii.bottomRight().height() - roundedRadius * 4);
graphicsContext->drawImageBuffer(m_layerImage, ColorSpaceDeviceRGB, destRect, tileRect);
// Draw the left side.
tileRect = FloatRect(0, twiceRadius + radii.topLeft().height(), twiceRadius, templateSideLength);
destRect = tileRect;
destRect.move(shadowRect.x(), shadowRect.y());
destRect.setHeight(shadowRect.height() - radii.topLeft().height() - radii.bottomLeft().height() - roundedRadius * 4);
graphicsContext->drawImageBuffer(m_layerImage, ColorSpaceDeviceRGB, destRect, tileRect);
// Draw the top left corner.
tileRect = FloatRect(0, 0, twiceRadius + radii.topLeft().width(), twiceRadius + radii.topLeft().height());
destRect = tileRect;
destRect.move(shadowRect.x(), shadowRect.y());
graphicsContext->drawImageBuffer(m_layerImage, ColorSpaceDeviceRGB, destRect, tileRect);
// Draw the top right corner.
tileRect = FloatRect(shadowTemplateSize.width() - twiceRadius - radii.topRight().width(), 0, twiceRadius + radii.topRight().width(),
twiceRadius + radii.topRight().height());
destRect = tileRect;
destRect.move(shadowRect.x() + shadowedRect.width() - shadowTemplateSize.width() + twiceRadius, shadowRect.y());
//.........这里部分代码省略.........
示例7: createWindow
static Frame* createWindow(Frame* openerFrame, Frame* lookupFrame, const FrameLoadRequest& request, const WindowFeatures& features, bool& created)
{
ASSERT(!features.dialog || request.frameName().isEmpty());
if (!request.frameName().isEmpty() && request.frameName() != "_blank") {
if (Frame* frame = lookupFrame->loader()->findFrameForNavigation(request.frameName(), openerFrame->document())) {
if (request.frameName() != "_self") {
if (Page* page = frame->page())
page->chrome().focus();
}
created = false;
return frame;
}
}
// Sandboxed frames cannot open new auxiliary browsing contexts.
if (openerFrame->document()->isSandboxed(SandboxPopups)) {
// FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
openerFrame->document()->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Blocked opening '" + request.resourceRequest().url().elidedString() + "' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.");
return 0;
}
// FIXME: Setting the referrer should be the caller's responsibility.
FrameLoadRequest requestWithReferrer = request;
String referrer = SecurityPolicy::generateReferrerHeader(openerFrame->document()->referrerPolicy(), request.resourceRequest().url(), openerFrame->loader()->outgoingReferrer());
if (!referrer.isEmpty())
requestWithReferrer.resourceRequest().setHTTPReferrer(referrer);
FrameLoader::addHTTPOriginIfNeeded(requestWithReferrer.resourceRequest(), openerFrame->loader()->outgoingOrigin());
if (openerFrame->settings() && !openerFrame->settings()->supportsMultipleWindows()) {
created = false;
return openerFrame->tree()->top();
}
Page* oldPage = openerFrame->page();
if (!oldPage)
return 0;
NavigationAction action(requestWithReferrer.resourceRequest());
Page* page = oldPage->chrome().client()->createWindow(openerFrame, requestWithReferrer, features, action);
if (!page)
return 0;
Frame* frame = page->mainFrame();
frame->loader()->forceSandboxFlags(openerFrame->document()->sandboxFlags());
if (request.frameName() != "_blank")
frame->tree()->setName(request.frameName());
page->chrome().setWindowFeatures(features);
// 'x' and 'y' specify the location of the window, while 'width' and 'height'
// specify the size of the viewport. We can only resize the window, so adjust
// for the difference between the window size and the viewport size.
FloatRect windowRect = page->chrome().windowRect();
FloatSize viewportSize = page->chrome().pageRect().size();
if (features.xSet)
windowRect.setX(features.x);
if (features.ySet)
windowRect.setY(features.y);
if (features.widthSet)
windowRect.setWidth(features.width + (windowRect.width() - viewportSize.width()));
if (features.heightSet)
windowRect.setHeight(features.height + (windowRect.height() - viewportSize.height()));
// Ensure non-NaN values, minimum size as well as being within valid screen area.
FloatRect newWindowRect = DOMWindow::adjustWindowRect(page, windowRect);
page->chrome().setWindowRect(newWindowRect);
page->chrome().show();
created = true;
return frame;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:77,代码来源:CreateWindow.cpp
示例8: computeTileCoverageRect
FloatRect TileController::computeTileCoverageRect(const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& visibleRect, float contentsScale) const
{
// If the page is not in a window (for example if it's in a background tab), we limit the tile coverage rect to the visible rect.
if (!m_isInWindow)
return visibleRect;
#if PLATFORM(IOS)
// FIXME: unify the iOS and Mac code.
UNUSED_PARAM(previousVisibleRect);
if (m_tileCoverage == CoverageForVisibleArea || MemoryPressureHandler::singleton().isUnderMemoryPressure())
return visibleRect;
double horizontalMargin = tileSize().width() / contentsScale;
double verticalMargin = tileSize().height() / contentsScale;
double currentTime = monotonicallyIncreasingTime();
double timeDelta = currentTime - m_velocity.lastUpdateTime;
FloatRect futureRect = visibleRect;
futureRect.setLocation(FloatPoint(
futureRect.location().x() + timeDelta * m_velocity.horizontalVelocity,
futureRect.location().y() + timeDelta * m_velocity.verticalVelocity));
if (m_velocity.horizontalVelocity) {
futureRect.setWidth(futureRect.width() + horizontalMargin);
if (m_velocity.horizontalVelocity < 0)
futureRect.setX(futureRect.x() - horizontalMargin);
}
if (m_velocity.verticalVelocity) {
futureRect.setHeight(futureRect.height() + verticalMargin);
if (m_velocity.verticalVelocity < 0)
futureRect.setY(futureRect.y() - verticalMargin);
}
if (!m_velocity.horizontalVelocity && !m_velocity.verticalVelocity) {
if (m_velocity.scaleChangeRate > 0)
return visibleRect;
futureRect.setWidth(futureRect.width() + horizontalMargin);
futureRect.setHeight(futureRect.height() + verticalMargin);
futureRect.setX(futureRect.x() - horizontalMargin / 2);
futureRect.setY(futureRect.y() - verticalMargin / 2);
}
// Can't use m_tileCacheLayer->bounds() here, because the size of the underlying platform layer
// hasn't been updated for the current commit.
IntSize contentSize = expandedIntSize(newSize);
if (futureRect.maxX() > contentSize.width())
futureRect.setX(contentSize.width() - futureRect.width());
if (futureRect.maxY() > contentSize.height())
futureRect.setY(contentSize.height() - futureRect.height());
if (futureRect.x() < 0)
futureRect.setX(0);
if (futureRect.y() < 0)
futureRect.setY(0);
return futureRect;
#else
UNUSED_PARAM(contentsScale);
// FIXME: look at how far the document can scroll in each dimension.
float coverageHorizontalSize = visibleRect.width();
float coverageVerticalSize = visibleRect.height();
bool largeVisibleRectChange = !previousVisibleRect.isEmpty() && !visibleRect.intersects(previousVisibleRect);
// Inflate the coverage rect so that it covers 2x of the visible width and 3x of the visible height.
// These values were chosen because it's more common to have tall pages and to scroll vertically,
// so we keep more tiles above and below the current area.
if (m_tileCoverage & CoverageForHorizontalScrolling && !largeVisibleRectChange)
coverageHorizontalSize *= 2;
if (m_tileCoverage & CoverageForVerticalScrolling && !largeVisibleRectChange)
coverageVerticalSize *= 3;
coverageVerticalSize += topMarginHeight() + bottomMarginHeight();
coverageHorizontalSize += leftMarginWidth() + rightMarginWidth();
// Can't use m_tileCacheLayer->bounds() here, because the size of the underlying platform layer
// hasn't been updated for the current commit.
FloatRect coverageBounds = boundsForSize(newSize);
float coverageLeft = visibleRect.x() - (coverageHorizontalSize - visibleRect.width()) / 2;
coverageLeft = std::min(coverageLeft, coverageBounds.maxX() - coverageHorizontalSize);
coverageLeft = std::max(coverageLeft, coverageBounds.x());
float coverageTop = visibleRect.y() - (coverageVerticalSize - visibleRect.height()) / 2;
coverageTop = std::min(coverageTop, coverageBounds.maxY() - coverageVerticalSize);
coverageTop = std::max(coverageTop, coverageBounds.y());
return FloatRect(coverageLeft, coverageTop, coverageHorizontalSize, coverageVerticalSize);
#endif
}
示例9: determineFilterPrimitiveSubregion
FloatRect RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(FilterEffect* effect, SVGFilter* filter)
{
FloatRect uniteRect;
FloatRect subregionBoundingBox = effect->effectBoundaries();
FloatRect subregion = subregionBoundingBox;
if (effect->filterEffectType() != FilterEffectTypeTile) {
// FETurbulence, FEImage and FEFlood don't have input effects, take the filter region as unite rect.
if (unsigned numberOfInputEffects = effect->inputEffects().size()) {
for (unsigned i = 0; i < numberOfInputEffects; ++i)
uniteRect.unite(determineFilterPrimitiveSubregion(effect->inputEffect(i), filter));
} else
uniteRect = filter->filterRegionInUserSpace();
} else {
determineFilterPrimitiveSubregion(effect->inputEffect(0), filter);
uniteRect = filter->filterRegionInUserSpace();
}
if (filter->effectBoundingBoxMode()) {
subregion = uniteRect;
// Avoid the calling of a virtual method several times.
FloatRect targetBoundingBox = filter->targetBoundingBox();
if (effect->hasX())
subregion.setX(targetBoundingBox.x() + subregionBoundingBox.x() * targetBoundingBox.width());
if (effect->hasY())
subregion.setY(targetBoundingBox.y() + subregionBoundingBox.y() * targetBoundingBox.height());
if (effect->hasWidth())
subregion.setWidth(subregionBoundingBox.width() * targetBoundingBox.width());
if (effect->hasHeight())
subregion.setHeight(subregionBoundingBox.height() * targetBoundingBox.height());
} else {
if (!effect->hasX())
subregion.setX(uniteRect.x());
if (!effect->hasY())
subregion.setY(uniteRect.y());
if (!effect->hasWidth())
subregion.setWidth(uniteRect.width());
if (!effect->hasHeight())
subregion.setHeight(uniteRect.height());
}
effect->setFilterPrimitiveSubregion(subregion);
FloatRect absoluteSubregion = filter->mapLocalRectToAbsoluteRect(subregion);
FloatSize filterResolution = filter->filterResolution();
absoluteSubregion.scale(filterResolution.width(), filterResolution.height());
// FEImage needs the unclipped subregion in absolute coordinates to determine the correct
// destination rect in combination with preserveAspectRatio.
if (effect->filterEffectType() == FilterEffectTypeImage)
reinterpret_cast<FEImage*>(effect)->setAbsoluteSubregion(absoluteSubregion);
// Clip every filter effect to the filter region.
FloatRect absoluteScaledFilterRegion = filter->filterRegion();
absoluteScaledFilterRegion.scale(filterResolution.width(), filterResolution.height());
absoluteSubregion.intersect(absoluteScaledFilterRegion);
effect->setMaxEffectRect(enclosingIntRect(absoluteSubregion));
return subregion;
}
示例10: adjustTileCoverageRect
void TileController::adjustTileCoverageRect(FloatRect& coverageRect, const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& visibleRect, float contentsScale) const
{
// If the page is not in a window (for example if it's in a background tab), we limit the tile coverage rect to the visible rect.
if (!m_isInWindow) {
coverageRect = visibleRect;
return;
}
#if PLATFORM(IOS)
// FIXME: unify the iOS and Mac code.
UNUSED_PARAM(previousVisibleRect);
if (m_tileCoverage == CoverageForVisibleArea || MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
coverageRect = visibleRect;
return;
}
double horizontalMargin = kDefaultTileSize / contentsScale;
double verticalMargin = kDefaultTileSize / contentsScale;
double currentTime = monotonicallyIncreasingTime();
double timeDelta = currentTime - m_velocity.lastUpdateTime;
FloatRect futureRect = visibleRect;
futureRect.setLocation(FloatPoint(
futureRect.location().x() + timeDelta * m_velocity.horizontalVelocity,
futureRect.location().y() + timeDelta * m_velocity.verticalVelocity));
if (m_velocity.horizontalVelocity) {
futureRect.setWidth(futureRect.width() + horizontalMargin);
if (m_velocity.horizontalVelocity < 0)
futureRect.setX(futureRect.x() - horizontalMargin);
}
if (m_velocity.verticalVelocity) {
futureRect.setHeight(futureRect.height() + verticalMargin);
if (m_velocity.verticalVelocity < 0)
futureRect.setY(futureRect.y() - verticalMargin);
}
if (!m_velocity.horizontalVelocity && !m_velocity.verticalVelocity) {
if (m_velocity.scaleChangeRate > 0) {
coverageRect = visibleRect;
return;
}
futureRect.setWidth(futureRect.width() + horizontalMargin);
futureRect.setHeight(futureRect.height() + verticalMargin);
futureRect.setX(futureRect.x() - horizontalMargin / 2);
futureRect.setY(futureRect.y() - verticalMargin / 2);
}
// Can't use m_tileCacheLayer->bounds() here, because the size of the underlying platform layer
// hasn't been updated for the current commit.
IntSize contentSize = expandedIntSize(newSize);
if (futureRect.maxX() > contentSize.width())
futureRect.setX(contentSize.width() - futureRect.width());
if (futureRect.maxY() > contentSize.height())
futureRect.setY(contentSize.height() - futureRect.height());
if (futureRect.x() < 0)
futureRect.setX(0);
if (futureRect.y() < 0)
futureRect.setY(0);
coverageRect.unite(futureRect);
return;
#else
UNUSED_PARAM(contentsScale);
// FIXME: look at how far the document can scroll in each dimension.
FloatSize coverageSize = visibleRect.size();
bool largeVisibleRectChange = !previousVisibleRect.isEmpty() && !visibleRect.intersects(previousVisibleRect);
// Inflate the coverage rect so that it covers 2x of the visible width and 3x of the visible height.
// These values were chosen because it's more common to have tall pages and to scroll vertically,
// so we keep more tiles above and below the current area.
float widthScale = 1;
float heightScale = 1;
if (m_tileCoverage & CoverageForHorizontalScrolling && !largeVisibleRectChange)
widthScale = 2;
if (m_tileCoverage & CoverageForVerticalScrolling && !largeVisibleRectChange)
heightScale = 3;
coverageSize.scale(widthScale, heightScale);
FloatRect coverageBounds = boundsForSize(newSize);
FloatRect coverage = expandRectWithinRect(visibleRect, coverageSize, coverageBounds);
LOG_WITH_STREAM(Scrolling, stream << "TileController::computeTileCoverageRect newSize=" << newSize << " mode " << m_tileCoverage << " expanded to " << coverageSize << " bounds with margin " << coverageBounds << " coverage " << coverage);
coverageRect.unite(coverage);
#endif
}
示例11: alignSelectionRectToDevicePixels
void alignSelectionRectToDevicePixels(FloatRect& rect)
{
float maxX = floorf(rect.maxX());
rect.setX(floorf(rect.x()));
rect.setWidth(roundf(maxX - rect.x()));
}
示例12: createWindow
static LocalFrame* createWindow(LocalFrame& openerFrame, LocalFrame& lookupFrame, const FrameLoadRequest& request, const WindowFeatures& features, NavigationPolicy policy, ShouldSendReferrer shouldSendReferrer, bool& created)
{
ASSERT(!features.dialog || request.frameName().isEmpty());
if (!request.frameName().isEmpty() && request.frameName() != "_blank" && policy == NavigationPolicyIgnore) {
if (LocalFrame* frame = lookupFrame.loader().findFrameForNavigation(request.frameName(), openerFrame.document())) {
if (request.frameName() != "_self")
frame->page()->focusController().setFocusedFrame(frame);
created = false;
return frame;
}
}
// Sandboxed frames cannot open new auxiliary browsing contexts.
if (openerFrame.document()->isSandboxed(SandboxPopups)) {
// FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
openerFrame.document()->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, "Blocked opening '" + request.resourceRequest().url().elidedString() + "' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.");
return 0;
}
if (openerFrame.settings() && !openerFrame.settings()->supportsMultipleWindows()) {
created = false;
return openerFrame.tree().top();
}
Page* oldPage = openerFrame.page();
if (!oldPage)
return 0;
Page* page = oldPage->chrome().client().createWindow(&openerFrame, request, features, policy, shouldSendReferrer);
if (!page)
return 0;
FrameHost* host = &page->frameHost();
ASSERT(page->mainFrame());
LocalFrame& frame = *page->mainFrame();
if (request.frameName() != "_blank")
frame.tree().setName(request.frameName());
host->chrome().setWindowFeatures(features);
// 'x' and 'y' specify the location of the window, while 'width' and 'height'
// specify the size of the viewport. We can only resize the window, so adjust
// for the difference between the window size and the viewport size.
FloatRect windowRect = host->chrome().windowRect();
FloatSize viewportSize = host->chrome().pageRect().size();
if (features.xSet)
windowRect.setX(features.x);
if (features.ySet)
windowRect.setY(features.y);
if (features.widthSet)
windowRect.setWidth(features.width + (windowRect.width() - viewportSize.width()));
if (features.heightSet)
windowRect.setHeight(features.height + (windowRect.height() - viewportSize.height()));
// Ensure non-NaN values, minimum size as well as being within valid screen area.
FloatRect newWindowRect = DOMWindow::adjustWindowRect(frame, windowRect);
host->chrome().setWindowRect(newWindowRect);
host->chrome().show(policy);
created = true;
return &frame;
}
示例13: adjustRectsForAspectRatio
void RenderSVGImage::adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& srcRect, SVGPreserveAspectRatio* aspectRatio)
{
float origDestWidth = destRect.width();
float origDestHeight = destRect.height();
if (aspectRatio->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_MEET) {
float widthToHeightMultiplier = srcRect.height() / srcRect.width();
if (origDestHeight > (origDestWidth * widthToHeightMultiplier)) {
destRect.setHeight(origDestWidth * widthToHeightMultiplier);
switch(aspectRatio->align()) {
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
destRect.setY(destRect.y() + origDestHeight / 2.0f - destRect.height() / 2.0f);
break;
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
destRect.setY(destRect.y() + origDestHeight - destRect.height());
break;
}
}
if (origDestWidth > (origDestHeight / widthToHeightMultiplier)) {
destRect.setWidth(origDestHeight / widthToHeightMultiplier);
switch(aspectRatio->align()) {
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
destRect.setX(destRect.x() + origDestWidth / 2.0f - destRect.width() / 2.0f);
break;
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
destRect.setX(destRect.x() + origDestWidth - destRect.width());
break;
}
}
} else if (aspectRatio->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE) {
float widthToHeightMultiplier = srcRect.height() / srcRect.width();
// if the destination height is less than the height of the image we'll be drawing
if (origDestHeight < (origDestWidth * widthToHeightMultiplier)) {
float destToSrcMultiplier = srcRect.width() / destRect.width();
srcRect.setHeight(destRect.height() * destToSrcMultiplier);
switch(aspectRatio->align()) {
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
srcRect.setY(destRect.y() + image()->height() / 2.0f - srcRect.height() / 2.0f);
break;
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
srcRect.setY(destRect.y() + image()->height() - srcRect.height());
break;
}
}
// if the destination width is less than the width of the image we'll be drawing
if (origDestWidth < (origDestHeight / widthToHeightMultiplier)) {
float destToSrcMultiplier = srcRect.height() / destRect.height();
srcRect.setWidth(destRect.width() * destToSrcMultiplier);
switch(aspectRatio->align()) {
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
srcRect.setX(destRect.x() + image()->width() / 2.0f - srcRect.width() / 2.0f);
break;
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
srcRect.setX(destRect.x() + image()->width() - srcRect.width());
break;
}
}
}
}
示例14: drawTiled
void Image::drawTiled(GraphicsContext& ctxt, const FloatRect& destRect, const FloatPoint& srcPoint, const FloatSize& scaledTileSize, const FloatSize& spacing, CompositeOperator op, BlendMode blendMode)
{
if (mayFillWithSolidColor()) {
fillWithSolidColor(ctxt, destRect, solidColor(), op);
return;
}
ASSERT(!isBitmapImage() || notSolidColor());
#if PLATFORM(IOS)
FloatSize intrinsicTileSize = originalSize();
#else
FloatSize intrinsicTileSize = size();
#endif
if (hasRelativeWidth())
intrinsicTileSize.setWidth(scaledTileSize.width());
if (hasRelativeHeight())
intrinsicTileSize.setHeight(scaledTileSize.height());
FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(),
scaledTileSize.height() / intrinsicTileSize.height());
FloatRect oneTileRect;
FloatSize actualTileSize(scaledTileSize.width() + spacing.width(), scaledTileSize.height() + spacing.height());
oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.width()) - actualTileSize.width(), actualTileSize.width()));
oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.height()) - actualTileSize.height(), actualTileSize.height()));
oneTileRect.setSize(scaledTileSize);
// Check and see if a single draw of the image can cover the entire area we are supposed to tile.
if (oneTileRect.contains(destRect) && !ctxt.drawLuminanceMask()) {
FloatRect visibleSrcRect;
visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
visibleSrcRect.setWidth(destRect.width() / scale.width());
visibleSrcRect.setHeight(destRect.height() / scale.height());
draw(ctxt, destRect, visibleSrcRect, op, blendMode, ImageOrientationDescription());
return;
}
#if PLATFORM(IOS)
// When using accelerated drawing on iOS, it's faster to stretch an image than to tile it.
if (ctxt.isAcceleratedContext()) {
if (size().width() == 1 && intersection(oneTileRect, destRect).height() == destRect.height()) {
FloatRect visibleSrcRect;
visibleSrcRect.setX(0);
visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
visibleSrcRect.setWidth(1);
visibleSrcRect.setHeight(destRect.height() / scale.height());
draw(ctxt, destRect, visibleSrcRect, op, BlendModeNormal, ImageOrientationDescription());
return;
}
if (size().height() == 1 && intersection(oneTileRect, destRect).width() == destRect.width()) {
FloatRect visibleSrcRect;
visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
visibleSrcRect.setY(0);
visibleSrcRect.setWidth(destRect.width() / scale.width());
visibleSrcRect.setHeight(1);
draw(ctxt, destRect, visibleSrcRect, op, BlendModeNormal, ImageOrientationDescription());
return;
}
}
#endif
// Patterned images and gradients can use lots of memory for caching when the
// tile size is large (<rdar://problem/4691859>, <rdar://problem/6239505>).
// Memory consumption depends on the transformed tile size which can get
// larger than the original tile if user zooms in enough.
#if PLATFORM(IOS)
const float maxPatternTilePixels = 512 * 512;
#else
const float maxPatternTilePixels = 2048 * 2048;
#endif
FloatRect transformedTileSize = ctxt.getCTM().mapRect(FloatRect(FloatPoint(), scaledTileSize));
float transformedTileSizePixels = transformedTileSize.width() * transformedTileSize.height();
FloatRect currentTileRect = oneTileRect;
if (transformedTileSizePixels > maxPatternTilePixels) {
GraphicsContextStateSaver stateSaver(ctxt);
ctxt.clip(destRect);
currentTileRect.shiftYEdgeTo(destRect.y());
float toY = currentTileRect.y();
while (toY < destRect.maxY()) {
currentTileRect.shiftXEdgeTo(destRect.x());
float toX = currentTileRect.x();
while (toX < destRect.maxX()) {
FloatRect toRect(toX, toY, currentTileRect.width(), currentTileRect.height());
FloatRect fromRect(toFloatPoint(currentTileRect.location() - oneTileRect.location()), currentTileRect.size());
fromRect.scale(1 / scale.width(), 1 / scale.height());
draw(ctxt, toRect, fromRect, op, BlendModeNormal, ImageOrientationDescription());
toX += currentTileRect.width();
currentTileRect.shiftXEdgeTo(oneTileRect.x());
}
toY += currentTileRect.height();
currentTileRect.shiftYEdgeTo(oneTileRect.y());
}
return;
}
AffineTransform patternTransform = AffineTransform().scaleNonUniform(scale.width(), scale.height());
//.........这里部分代码省略.........
示例15: transformRect
void SVGPreserveAspectRatio::transformRect(FloatRect& destRect, FloatRect& srcRect)
{
if (m_align == SVG_PRESERVEASPECTRATIO_NONE)
return;
FloatSize imageSize = srcRect.size();
float origDestWidth = destRect.width();
float origDestHeight = destRect.height();
switch (m_meetOrSlice) {
case SVGPreserveAspectRatio::SVG_MEETORSLICE_UNKNOWN:
break;
case SVGPreserveAspectRatio::SVG_MEETORSLICE_MEET: {
float widthToHeightMultiplier = srcRect.height() / srcRect.width();
if (origDestHeight > origDestWidth * widthToHeightMultiplier) {
destRect.setHeight(origDestWidth * widthToHeightMultiplier);
switch (m_align) {
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
destRect.setY(destRect.y() + origDestHeight / 2 - destRect.height() / 2);
break;
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
destRect.setY(destRect.y() + origDestHeight - destRect.height());
break;
default:
break;
}
}
if (origDestWidth > origDestHeight / widthToHeightMultiplier) {
destRect.setWidth(origDestHeight / widthToHeightMultiplier);
switch (m_align) {
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
destRect.setX(destRect.x() + origDestWidth / 2 - destRect.width() / 2);
break;
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
destRect.setX(destRect.x() + origDestWidth - destRect.width());
break;
default:
break;
}
}
break;
}
case SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE: {
float widthToHeightMultiplier = srcRect.height() / srcRect.width();
// if the destination height is less than the height of the image we'll be drawing
if (origDestHeight < origDestWidth * widthToHeightMultiplier) {
float destToSrcMultiplier = srcRect.width() / destRect.width();
srcRect.setHeight(destRect.height() * destToSrcMultiplier);
switch (m_align) {
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
srcRect.setY(srcRect.y() + imageSize.height() / 2 - srcRect.height() / 2);
break;
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
srcRect.setY(srcRect.y() + imageSize.height() - srcRect.height());
break;
default:
break;
}
}
// if the destination width is less than the width of the image we'll be drawing
if (origDestWidth < origDestHeight / widthToHeightMultiplier) {
float destToSrcMultiplier = srcRect.height() / destRect.height();
srcRect.setWidth(destRect.width() * destToSrcMultiplier);
switch (m_align) {
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
srcRect.setX(srcRect.x() + imageSize.width() / 2 - srcRect.width() / 2);
break;
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
srcRect.setX(srcRect.x() + imageSize.width() - srcRect.width());
break;
default:
break;
}
}
break;
}
}
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:93,代码来源:SVGPreserveAspectRatio.cpp