// Sets the image height and width to fit the alt text. Returns true if the // image size changed. bool RenderImage::setImageSizeForAltText(CachedImage* newImage /* = 0 */) { IntSize imageSize; if (newImage && newImage->image()) imageSize = imageSizeForError(newImage); else if (!m_altText.isEmpty() || newImage) { // If we'll be displaying either text or an image, add a little padding. imageSize = IntSize(paddingWidth, paddingHeight); } // we have an alt and the user meant it (its not a text we invented) if (!m_altText.isEmpty()) { FontCachePurgePreventer fontCachePurgePreventer; const Font& font = style()->font(); IntSize textSize(min(font.width(RenderBlock::constructTextRun(this, font, m_altText, style())), maxAltTextWidth), min(font.fontMetrics().height(), maxAltTextHeight)); imageSize = imageSize.expandedTo(textSize); } if (imageSize == intrinsicSize()) return false; setIntrinsicSize(imageSize); return true; }
bool EGLImageLayerWebKitThread::createImageIfNeeded(const IntSize& size) { // We use a texture rather than a renderbuffer as the basis of the FBO and EGLImage, // since the EGLImage will be used as a texture on the compositing thread in the end. if (!m_frontBufferTexture) { glGenTextures(1, &m_frontBufferTexture); glBindTexture(GL_TEXTURE_2D, m_frontBufferTexture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } if (!m_fbo) glGenFramebuffers(1, &m_fbo); if (!m_image || size != m_size) { IntSize fboSize = size; // Imagination-specific fix static bool isImaginationHardware = std::strstr(reinterpret_cast<const char*>(glGetString(GL_RENDERER)), "PowerVR SGX"); if (isImaginationHardware) fboSize = fboSize.expandedTo(IntSize(16, 16)); glBindTexture(GL_TEXTURE_2D, m_frontBufferTexture); glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fboSize.width(), fboSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_frontBufferTexture, 0); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; if (glGetError() != GL_NO_ERROR) return false; // The sibling is orphaned after glTexImage2D, recreate the image. if (m_image) m_garbage.append(m_image); m_image = eglCreateImageKHR(BlackBerry::Platform::Graphics::eglDisplay(), eglGetCurrentContext(), EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)m_frontBufferTexture, 0); if (!m_image) return false; m_size = size; } return true; }
IntPoint VisualViewport::clampDocumentOffsetAtScale(const IntPoint& offset, float scale) { if (!mainFrame() || !mainFrame()->view()) return IntPoint(); FrameView* view = mainFrame()->view(); FloatSize scaledSize(m_size); scaledSize.scale(1 / scale); IntSize visualViewportMax = flooredIntSize(FloatSize(contentsSize()) - scaledSize); IntSize max = view->maximumScrollOffsetInt() + visualViewportMax; IntSize min = view->minimumScrollOffsetInt(); // VisualViewportMin should be (0, 0) IntSize clamped = toIntSize(offset); clamped = clamped.shrunkTo(max); clamped = clamped.expandedTo(min); return IntPoint(clamped); }
// Sets the image height and width to fit the alt text. Returns true if the // image size changed. ImageSizeChangeType RenderImage::setImageSizeForAltText(CachedImage* newImage /* = 0 */) { IntSize imageSize; if (newImage && newImage->imageForRenderer(this)) imageSize = imageSizeForError(newImage); else if (!m_altText.isEmpty() || newImage) { // If we'll be displaying either text or an image, add a little padding. imageSize = IntSize(paddingWidth, paddingHeight); } // we have an alt and the user meant it (its not a text we invented) if (!m_altText.isEmpty()) { const FontCascade& font = style().fontCascade(); IntSize paddedTextSize(paddingWidth + std::min(ceilf(font.width(RenderBlock::constructTextRun(this, font, m_altText, style()))), maxAltTextWidth), paddingHeight + std::min(font.fontMetrics().height(), maxAltTextHeight)); imageSize = imageSize.expandedTo(paddedTextSize); } if (imageSize == intrinsicSize()) return ImageSizeChangeNone; setIntrinsicSize(imageSize); return ImageSizeChangeForAltText; }