void WMLCardElement::insertedIntoDocument() { WMLElement::insertedIntoDocument(); Document* document = this->document(); // The first card inserted into a document, is visible by default. if (!m_isVisible) { RefPtr<NodeList> nodeList = document->getElementsByTagName("card"); if (nodeList && nodeList->length() == 1 && nodeList->item(0) == this) { m_isVisible = true; // SAMSUNG_WML_FIXES+ #ifdef ANDROID_META_SUPPORT // fit wml sites directly in the screen if (Page *p = document->page()) p->settings()->setMetadataSettings("width", "device-width"); if (FrameView* frameView = document->view()) android::WebViewCore::getWebViewCore(frameView)->updateViewport(); #endif // SAMSUNG_WML_FIXES+ } } // For the WML layout tests we embed WML content in a XHTML document. Navigating to different cards // within the same deck has a different behaviour in HTML than in WML. HTML wants to "scroll to anchor" // (see FrameLoader) but WML wants a reload. Notify the root document of the layout test that we want // to mimic WML behaviour. This is rather tricky, but has been tested extensively. Usually it's not possible // at all to embed WML in HTML, it's not designed that way, we're just "abusing" it for dynamically created layout tests. if (document->page() && document->page()->mainFrame()) { Document* rootDocument = document->page()->mainFrame()->document(); if (rootDocument && rootDocument != document) rootDocument->setContainsWMLContent(true); } }
SVGFontElement* CachedFont::getSVGFontById(const String& fontName) const { RefPtr<NodeList> list = m_externalSVGDocument->getElementsByTagNameNS(SVGNames::fontTag.namespaceURI(), SVGNames::fontTag.localName()); if (!list) return 0; unsigned listLength = list->length(); if (!listLength) return 0; #ifndef NDEBUG for (unsigned i = 0; i < listLength; ++i) { ASSERT(list->item(i)); ASSERT(list->item(i)->hasTagName(SVGNames::fontTag)); } #endif if (fontName.isEmpty()) return static_cast<SVGFontElement*>(list->item(0)); for (unsigned i = 0; i < listLength; ++i) { SVGFontElement* element = static_cast<SVGFontElement*>(list->item(i)); if (element->getIdAttribute() == fontName) return element; } return 0; }
void CanvasRenderingContext2D::setFont(const String& newFont) { RefPtr<CSSMutableStyleDeclaration> tempDecl = CSSMutableStyleDeclaration::create(); CSSParser parser(!m_canvas->document()->inCompatMode()); // Use the parse mode of the canvas' document when parsing CSS. String declarationText("font: "); declarationText += newFont; parser.parseDeclaration(tempDecl.get(), declarationText); if (!tempDecl->length()) return; // The parse succeeded. state().m_unparsedFont = newFont; // Map the <canvas> font into the text style. If the font uses keywords like larger/smaller, these will work // relative to the canvas. RefPtr<RenderStyle> newStyle = RenderStyle::create(); if (m_canvas->computedStyle()) newStyle->setFontDescription(m_canvas->computedStyle()->fontDescription()); // Now map the font property into the style. CSSStyleSelector* styleSelector = m_canvas->document()->styleSelector(); styleSelector->applyPropertyToStyle(CSSPropertyFont, tempDecl->getPropertyCSSValue(CSSPropertyFont).get(), newStyle.get()); state().m_font = newStyle->font(); state().m_font.update(styleSelector->fontSelector()); state().m_realizedFont = true; }
void MediaStreamFrameController::streamGenerated(int requestId, const String& label, PassRefPtr<MediaStreamTrackList> tracksParam) { // Don't assert since the request can have been aborted as a result of embedder detachment. if (!m_requests.contains(requestId)) return; ASSERT(m_requests.get(requestId)->isGenerateStreamRequest()); ASSERT(!label.isNull()); ASSERT(tracksParam); RefPtr<MediaStreamTrackList> tracks = tracksParam; for (unsigned i = 0; i < tracks->length(); ++i) { int trackClientId = m_clients.getNextId(); RefPtr<MediaStreamTrack> track = tracks->item(i); track->associateFrameController(this, trackClientId); m_clients.add(trackClientId, track.get()); } RefPtr<GenerateStreamRequest> streamRequest = static_cast<GenerateStreamRequest*>(m_requests.get(requestId).get()); RefPtr<LocalMediaStream> generatedStream = LocalMediaStream::create(this, label, tracks.release()); m_streams.add(label, generatedStream.get()); m_requests.remove(requestId); streamRequest->successCallback()->handleEvent(generatedStream.get()); }
Length* StringImpl::toCoordsArray(int& len) { StringBuffer spacified(m_length); for (unsigned i = 0; i < m_length; i++) { UChar cc = m_data[i]; if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.')) spacified[i] = ' '; else spacified[i] = cc; } RefPtr<StringImpl> str = adopt(spacified); str = str->simplifyWhiteSpace(); len = countCharacter(str.get(), ' ') + 1; Length* r = new Length[len]; int i = 0; int pos = 0; int pos2; while ((pos2 = str->find(' ', pos)) != -1) { r[i++] = parseLength(str->characters() + pos, pos2 - pos); pos = pos2+1; } r[i] = parseLength(str->characters() + pos, str->length() - pos); ASSERT(i == len - 1); return r; }
std::unique_ptr<Length[]> newCoordsArray(const String& string, int& len) { unsigned length = string.length(); StringBuffer<UChar> spacified(length); for (unsigned i = 0; i < length; i++) { UChar cc = string[i]; if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.')) spacified[i] = ' '; else spacified[i] = cc; } RefPtr<StringImpl> str = StringImpl::adopt(spacified); str = str->simplifyWhiteSpace(); len = countCharacter(*str, ' ') + 1; auto r = std::make_unique<Length[]>(len); int i = 0; unsigned pos = 0; size_t pos2; auto upconvertedCharacters = StringView(str.get()).upconvertedCharacters(); while ((pos2 = str->find(' ', pos)) != notFound) { r[i++] = parseLength(upconvertedCharacters + pos, pos2 - pos); pos = pos2+1; } r[i] = parseLength(upconvertedCharacters + pos, str->length() - pos); ASSERT(i == len - 1); return r; }
PassRefPtr<ByteArray> getImageData(const IntRect& rect, SkCanvas* canvas, const IntSize& size) { float area = 4.0f * rect.width() * rect.height(); if (area > static_cast<float>(std::numeric_limits<int>::max())) return 0; RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4); unsigned char* data = result->data(); if (rect.x() < 0 || rect.y() < 0 || rect.maxX() > size.width() || rect.maxY() > size.height()) memset(data, 0, result->length()); unsigned destBytesPerRow = 4 * rect.width(); SkBitmap destBitmap; destBitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height(), destBytesPerRow); destBitmap.setPixels(data); SkCanvas::Config8888 config8888; if (multiplied == Premultiplied) config8888 = SkCanvas::kRGBA_Premul_Config8888; else config8888 = SkCanvas::kRGBA_Unpremul_Config8888; canvas->readPixels(&destBitmap, rect.x(), rect.y(), config8888); return result.release(); }
PassRefPtr<Text> Text::splitText(unsigned offset, ExceptionCode& ec) { ec = 0; if (this->parent()) {if (!RO_check(this->parent())) return 0;} // INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than // the number of 16-bit units in data. if (offset > length()) { ec = INDEX_SIZE_ERR; return 0; } RefPtr<StringImpl> oldStr = dataImpl(); RefPtr<Text> newText = virtualCreate(oldStr->substring(offset)); setDataImpl(oldStr->substring(0, offset)); dispatchModifiedEvent(oldStr.get()); if (parentNode()) parentNode()->insertBefore(newText.get(), nextSibling(), ec); if (ec) return 0; if (parentNode()) document()->textNodeSplit(this); if (renderer()) toRenderText(renderer())->setTextWithOffset(dataImpl(), 0, oldStr->length()); return newText.release(); }
bool InspectorStyleSheet::ensureSourceData(Node* ownerNode) { if (m_parsedStyleSheet->hasSourceData()) return true; if (!m_parsedStyleSheet->hasText()) return false; RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(ownerNode); CSSParser p; StyleRuleRangeMap ruleRangeMap; p.parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), 0, &ruleRangeMap); OwnPtr<ParsedStyleSheet::SourceData> rangesVector(new ParsedStyleSheet::SourceData()); for (unsigned i = 0, length = newStyleSheet->length(); i < length; ++i) { CSSStyleRule* rule = InspectorCSSAgent::asCSSStyleRule(newStyleSheet->item(i)); if (!rule) continue; StyleRuleRangeMap::iterator it = ruleRangeMap.find(rule); if (it != ruleRangeMap.end()) rangesVector->append(it->second); } m_parsedStyleSheet->setSourceData(rangesVector.release()); return m_parsedStyleSheet->hasSourceData(); }
void SVGRenderSupport::applyStrokeStyleToStrokeData(StrokeData* strokeData, const RenderStyle* style, const RenderObject* object) { ASSERT(strokeData); ASSERT(style); ASSERT(object); ASSERT(object->node()); ASSERT(object->node()->isSVGElement()); const SVGRenderStyle* svgStyle = style->svgStyle(); ASSERT(svgStyle); SVGLengthContext lengthContext(toSVGElement(object->node())); strokeData->setThickness(svgStyle->strokeWidth()->value(lengthContext)); strokeData->setLineCap(svgStyle->capStyle()); strokeData->setLineJoin(svgStyle->joinStyle()); strokeData->setMiterLimit(svgStyle->strokeMiterLimit()); RefPtr<SVGLengthList> dashes = svgStyle->strokeDashArray(); if (dashes->isEmpty()) return; DashArray dashArray; size_t length = dashes->length(); for (size_t i = 0; i < length; ++i) dashArray.append(dashes->at(i)->value(lengthContext)); strokeData->setLineDash(dashArray, svgStyle->strokeDashOffset()->value(lengthContext)); }
bool HTMLObjectElement::shouldAllowQuickTimeClassIdQuirk() { // This site-specific hack maintains compatibility with Mac OS X Wiki Server, // which embeds QuickTime movies using an object tag containing QuickTime's // ActiveX classid. Treat this classid as valid only if OS X Server's unique // 'generator' meta tag is present. Only apply this quirk if there is no // fallback content, which ensures the quirk will disable itself if Wiki // Server is updated to generate an alternate embed tag as fallback content. if (!document()->page() || !document()->page()->settings()->needsSiteSpecificQuirks() || hasFallbackContent() || !equalIgnoringCase(classId(), "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B")) return false; RefPtr<NodeList> metaElements = document()->getElementsByTagName(HTMLNames::metaTag.localName()); unsigned length = metaElements->length(); for (unsigned i = 0; i < length; ++i) { ASSERT(metaElements->item(i)->isHTMLElement()); HTMLMetaElement* metaElement = static_cast<HTMLMetaElement*>(metaElements->item(i)); if (equalIgnoringCase(metaElement->name(), "generator") && metaElement->content().startsWith("Mac OS X Server Web Services Server", false)) return true; } return false; }
SVGFontElement* FontResource::getSVGFontById(const String& fontName) const { RefPtr<HTMLCollection> collection = m_externalSVGDocument->getElementsByTagNameNS(SVGNames::fontTag.namespaceURI(), SVGNames::fontTag.localName()); if (!collection) return 0; unsigned collectionLength = collection->length(); if (!collectionLength) return 0; #ifndef NDEBUG for (unsigned i = 0; i < collectionLength; ++i) { ASSERT(collection->item(i)); ASSERT(isSVGFontElement(collection->item(i))); } #endif if (fontName.isEmpty()) return toSVGFontElement(collection->item(0)); for (unsigned i = 0; i < collectionLength; ++i) { SVGFontElement* element = toSVGFontElement(collection->item(i)); if (element->getIdAttribute() == fontName) return element; } return 0; }
// Lazily load a concatenated HRTF database for given subject and store it in a // local hash table to ensure quick efficient future retrievals. static PassRefPtr<AudioBus> getConcatenatedImpulseResponsesForSubject(const String& subjectName) { typedef HashMap<String, RefPtr<AudioBus>> AudioBusMap; DEFINE_THREAD_SAFE_STATIC_LOCAL(AudioBusMap, audioBusMap, new AudioBusMap()); DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, new Mutex()); MutexLocker locker(mutex); RefPtr<AudioBus> bus; AudioBusMap::iterator iterator = audioBusMap.find(subjectName); if (iterator == audioBusMap.end()) { RefPtr<AudioBus> concatenatedImpulseResponses(AudioBus::loadPlatformResource(subjectName.utf8().data(), ResponseSampleRate)); ASSERT(concatenatedImpulseResponses); if (!concatenatedImpulseResponses) return nullptr; bus = concatenatedImpulseResponses; audioBusMap.set(subjectName, bus); } else bus = iterator->value; size_t responseLength = bus->length(); size_t expectedLength = static_cast<size_t>(TotalNumberOfResponses * ResponseFrameSize); // Check number of channels and length. For now these are fixed and known. bool isBusGood = responseLength == expectedLength && bus->numberOfChannels() == 2; ASSERT(isBusGood); if (!isBusGood) return nullptr; return bus; }
bool RenderThemeGtk::paintMediaSliderTrack(const RenderObject& o, const PaintInfo& paintInfo, const IntRect& r) { HTMLMediaElement* mediaElement = parentMediaElement(o); if (!mediaElement) return false; GraphicsContext* context = paintInfo.context; context->save(); context->setStrokeStyle(NoStroke); float mediaDuration = mediaElement->duration(); float totalTrackWidth = r.width(); RenderStyle* style = &o.style(); RefPtr<TimeRanges> timeRanges = mediaElement->buffered(); for (unsigned index = 0; index < timeRanges->length(); ++index) { float start = timeRanges->start(index, IGNORE_EXCEPTION); float end = timeRanges->end(index, IGNORE_EXCEPTION); float startRatio = start / mediaDuration; float lengthRatio = (end - start) / mediaDuration; if (!lengthRatio) continue; IntRect rangeRect(r); rangeRect.setWidth(lengthRatio * totalTrackWidth); if (index) rangeRect.move(startRatio * totalTrackWidth, 0); context->fillRoundedRect(FloatRoundedRect(rangeRect, borderRadiiFromStyle(style)), style->visitedDependentColor(CSSPropertyColor), style->colorSpace()); } context->restore(); return false; }
void WMLPElement::insertedIntoDocument() { WMLElement::insertedIntoDocument(); // If not explicitly specified, the linewrap mode is identical to // the line-wrap mode of the previous paragraph in the text flow of // a card. The default mode for the first paragraph in a card is wrap. if (!m_mode.isEmpty()) return; RefPtr<NodeList> nodeList = document()->getElementsByTagName("p"); if (!nodeList) return; unsigned length = nodeList->length(); if (length < 2) return; // Assure we're the last inserted paragraph element // This only works while parsing, otherwhise this statement is never true. if (nodeList->item(length - 1) != this) return; WMLPElement* lastParagraph = static_cast<WMLPElement*>(nodeList->item(length - 2)); ASSERT(lastParagraph); String lastMode = lastParagraph->getAttribute(modeAttr); if (lastMode.isEmpty() || lastMode == "wrap") // Default value, do nothing. return; setAttribute(modeAttr, lastMode); }
void HTMLConstructionSite::insertTextNode(const String& characters, WhitespaceMode whitespaceMode) { HTMLConstructionSiteTask task; task.parent = currentNode(); if (shouldFosterParent()) findFosterSite(task); #if ENABLE(TEMPLATE_ELEMENT) if (task.parent->hasTagName(templateTag)) task.parent = toHTMLTemplateElement(task.parent.get())->content(); #endif // Strings composed entirely of whitespace are likely to be repeated. // Turn them into AtomicString so we share a single string for each. bool shouldUseAtomicString = whitespaceMode == AllWhitespace || (whitespaceMode == WhitespaceUnknown && isAllWhitespace(characters)); unsigned currentPosition = 0; unsigned lengthLimit = shouldUseLengthLimit(task.parent.get()) ? Text::defaultLengthLimit : std::numeric_limits<unsigned>::max(); // FIXME: Splitting text nodes into smaller chunks contradicts HTML5 spec, but is currently necessary // for performance, see <https://bugs.webkit.org/show_bug.cgi?id=55898>. Node* previousChild = task.nextChild ? task.nextChild->previousSibling() : task.parent->lastChild(); if (previousChild && previousChild->isTextNode()) { // FIXME: We're only supposed to append to this text node if it // was the last text node inserted by the parser. CharacterData* textNode = static_cast<CharacterData*>(previousChild); currentPosition = textNode->parserAppendData(characters, 0, lengthLimit); } while (currentPosition < characters.length()) { RefPtr<Text> textNode = Text::createWithLengthLimit(task.parent->document(), shouldUseAtomicString ? AtomicString(characters).string() : characters, currentPosition, lengthLimit); // If we have a whole string of unbreakable characters the above could lead to an infinite loop. Exceeding the length limit is the lesser evil. if (!textNode->length()) { String substring = characters.substring(currentPosition); textNode = Text::create(task.parent->document(), shouldUseAtomicString ? AtomicString(substring).string() : substring); } currentPosition += textNode->length(); ASSERT(currentPosition <= characters.length()); task.child = textNode.release(); executeTask(task); } }
bool RenderThemeGtk::paintMediaSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r) { GraphicsContext* context = paintInfo.context; context->fillRect(FloatRect(r), m_panelColor, ColorSpaceDeviceRGB); context->fillRect(FloatRect(IntRect(r.x(), r.y() + (r.height() - m_mediaSliderHeight) / 2, r.width(), m_mediaSliderHeight)), m_sliderColor, ColorSpaceDeviceRGB); RenderStyle* style = o->style(); HTMLMediaElement* mediaElement = toParentMediaElement(o); if (!mediaElement) return false; // Draw the buffered ranges. This code is highly inspired from // Chrome for the gradient code. float mediaDuration = mediaElement->duration(); RefPtr<TimeRanges> timeRanges = mediaElement->buffered(); IntRect trackRect = r; int totalWidth = trackRect.width(); trackRect.inflate(-style->borderLeftWidth()); context->save(); context->setStrokeStyle(NoStroke); for (unsigned index = 0; index < timeRanges->length(); ++index) { ExceptionCode ignoredException; float start = timeRanges->start(index, ignoredException); float end = timeRanges->end(index, ignoredException); int width = ((end - start) * totalWidth) / mediaDuration; IntRect rangeRect; if (!index) { rangeRect = trackRect; rangeRect.setWidth(width); } else { rangeRect.setLocation(IntPoint(trackRect.x() + start / mediaDuration* totalWidth, trackRect.y())); rangeRect.setSize(IntSize(width, trackRect.height())); } // Don't bother drawing empty range. if (rangeRect.isEmpty()) continue; IntPoint sliderTopLeft = rangeRect.location(); IntPoint sliderTopRight = sliderTopLeft; sliderTopRight.move(0, rangeRect.height()); RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderTopRight); Color startColor = m_panelColor; gradient->addColorStop(0.0, startColor); gradient->addColorStop(1.0, Color(startColor.red() / 2, startColor.green() / 2, startColor.blue() / 2, startColor.alpha())); context->setFillGradient(gradient); context->fillRect(rangeRect); } context->restore(); return false; }
PassRefPtr<StringImpl> RenderTextFragment::originalText() const { Node* e = node(); RefPtr<StringImpl> result = ((e && e->isTextNode()) ? static_cast<Text*>(e)->dataImpl() : contentString()); if (result && (start() > 0 || start() < result->length())) result = result->substring(start(), end()); return result.release(); }
void FEDisplacementMap::applySoftware() { FilterEffect* in = inputEffect(0); FilterEffect* in2 = inputEffect(1); ASSERT(m_xChannelSelector != CHANNEL_UNKNOWN); ASSERT(m_yChannelSelector != CHANNEL_UNKNOWN); Uint8ClampedArray* dstPixelArray = createPremultipliedImageResult(); if (!dstPixelArray) return; IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect()); RefPtr<Uint8ClampedArray> srcPixelArrayA = in->asPremultipliedImage(effectADrawingRect); IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePaintRect()); RefPtr<Uint8ClampedArray> srcPixelArrayB = in2->asUnmultipliedImage(effectBDrawingRect); ASSERT(srcPixelArrayA->length() == srcPixelArrayB->length()); Filter* filter = this->filter(); IntSize paintSize = absolutePaintRect().size(); float scaleX = filter->applyHorizontalScale(m_scale); float scaleY = filter->applyVerticalScale(m_scale); float scaleForColorX = scaleX / 255.0; float scaleForColorY = scaleY / 255.0; float scaledOffsetX = 0.5 - scaleX * 0.5; float scaledOffsetY = 0.5 - scaleY * 0.5; int stride = paintSize.width() * 4; for (int y = 0; y < paintSize.height(); ++y) { int line = y * stride; for (int x = 0; x < paintSize.width(); ++x) { int dstIndex = line + x * 4; int srcX = x + static_cast<int>(scaleForColorX * srcPixelArrayB->item(dstIndex + m_xChannelSelector - 1) + scaledOffsetX); int srcY = y + static_cast<int>(scaleForColorY * srcPixelArrayB->item(dstIndex + m_yChannelSelector - 1) + scaledOffsetY); for (unsigned channel = 0; channel < 4; ++channel) { if (srcX < 0 || srcX >= paintSize.width() || srcY < 0 || srcY >= paintSize.height()) { dstPixelArray->set(dstIndex + channel, static_cast<unsigned char>(0)); } else { unsigned char pixelValue = srcPixelArrayA->item(srcY * stride + srcX * 4 + channel); dstPixelArray->set(dstIndex + channel, pixelValue); } } } } }
static std::vector<void *> find_matching_functions (const char * str) { RefPtr<PtrArray> functions = RefPtr<PtrArray> (find_matching_functions_array (str)); std::vector<void *> result; for (int i = functions->length () - 1; i >= 0; i--) result.push_back (functions->nth (i)); return result; }
PassRefPtr<StringImpl> StringImpl::replace(StringImpl* pattern, StringImpl* replacement) { if (!pattern || !replacement) return this; unsigned patternLength = pattern->length(); if (!patternLength) return this; unsigned repStrLength = replacement->length(); size_t srcSegmentStart = 0; unsigned matchCount = 0; // Count the matches while ((srcSegmentStart = find(pattern, srcSegmentStart)) != notFound) { ++matchCount; srcSegmentStart += patternLength; } // If we have 0 matches, we don't have to do any more work if (!matchCount) return this; unsigned newSize = m_length - matchCount * patternLength; if (repStrLength && matchCount > numeric_limits<unsigned>::max() / repStrLength) CRASH(); if (newSize > (numeric_limits<unsigned>::max() - matchCount * repStrLength)) CRASH(); newSize += matchCount * repStrLength; UChar* data; RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); // Construct the new data size_t srcSegmentEnd; unsigned srcSegmentLength; srcSegmentStart = 0; unsigned dstOffset = 0; while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { srcSegmentLength = srcSegmentEnd - srcSegmentStart; memcpy(data + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); dstOffset += srcSegmentLength; memcpy(data + dstOffset, replacement->m_data, repStrLength * sizeof(UChar)); dstOffset += repStrLength; srcSegmentStart = srcSegmentEnd + patternLength; } srcSegmentLength = m_length - srcSegmentStart; memcpy(data + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); ASSERT(dstOffset + srcSegmentLength == newImpl->length()); return newImpl.release(); }
PassRefPtr<ByteArray> getImageData(const IntRect& rect, const ImageBufferData& data, const IntSize& size) { ASSERT(cairo_surface_get_type(data.m_surface) == CAIRO_SURFACE_TYPE_IMAGE); RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4); unsigned char* dataSrc = cairo_image_surface_get_data(data.m_surface); unsigned char* dataDst = result->data(); if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) > size.width() || (rect.y() + rect.height()) > size.height()) memset(dataDst, 0, result->length()); int originx = rect.x(); int destx = 0; if (originx < 0) { destx = -originx; originx = 0; } int endx = rect.maxX(); if (endx > size.width()) endx = size.width(); int numColumns = endx - originx; int originy = rect.y(); int desty = 0; if (originy < 0) { desty = -originy; originy = 0; } int endy = rect.maxY(); if (endy > size.height()) endy = size.height(); int numRows = endy - originy; int stride = cairo_image_surface_get_stride(data.m_surface); unsigned destBytesPerRow = 4 * rect.width(); unsigned char* destRows = dataDst + desty * destBytesPerRow + destx * 4; for (int y = 0; y < numRows; ++y) { unsigned* row = reinterpret_cast<unsigned*>(dataSrc + stride * (y + originy)); for (int x = 0; x < numColumns; x++) { int basex = x * 4; unsigned* pixel = row + x + originx; Color pixelColor; if (multiplied == Unmultiplied) pixelColor = colorFromPremultipliedARGB(*pixel); else pixelColor = Color(*pixel); destRows[basex] = pixelColor.red(); destRows[basex + 1] = pixelColor.green(); destRows[basex + 2] = pixelColor.blue(); destRows[basex + 3] = pixelColor.alpha(); } destRows += destBytesPerRow; } return result.release(); }
TEST(WTF, StringImplFromLiteralLoop16BitConversion) { RefPtr<StringImpl> controlString = StringImpl::create("Template Literal"); for (size_t i = 0; i < 10; ++i) { RefPtr<StringImpl> string = StringImpl::createFromLiteral("Template Literal"); ASSERT_EQ(0, memcmp(controlString->characters(), string->characters(), controlString->length() * sizeof(UChar))); ASSERT_TRUE(string->has16BitShadow()); } }
void SVGPathSegList::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*) { RefPtr<SVGPathSegList> otherList = toSVGPathSegList(other); if (length() != otherList->length()) return; byteStream(); // create |m_byteStream| if not exist. addToSVGPathByteStream(m_byteStream.get(), otherList->byteStream()); invalidateList(); }
void CString::copyBufferIfNeeded() { if (!m_buffer || m_buffer->hasOneRef()) return; RefPtr<CStringBuffer> buffer = m_buffer.release(); size_t length = buffer->length(); m_buffer = CStringBuffer::create(length); memcpy(m_buffer->mutableData(), buffer->data(), length); }
void FEBlend::apply() { if (hasResult()) return; FilterEffect* in = inputEffect(0); FilterEffect* in2 = inputEffect(1); in->apply(); in2->apply(); if (!in->hasResult() || !in2->hasResult()) return; ASSERT(m_mode > FEBLEND_MODE_UNKNOWN); ASSERT(m_mode <= FEBLEND_MODE_LIGHTEN); ByteArray* dstPixelArray = createPremultipliedImageResult(); if (!dstPixelArray) return; IntRect effectADrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect()); RefPtr<ByteArray> srcPixelArrayA = in->asPremultipliedImage(effectADrawingRect); IntRect effectBDrawingRect = requestedRegionOfInputImageData(in2->absolutePaintRect()); RefPtr<ByteArray> srcPixelArrayB = in2->asPremultipliedImage(effectBDrawingRect); // Keep synchronized with BlendModeType static const BlendType callEffect[] = {unknown, normal, multiply, screen, darken, lighten}; unsigned pixelArrayLength = srcPixelArrayA->length(); ASSERT(pixelArrayLength == srcPixelArrayB->length()); for (unsigned pixelOffset = 0; pixelOffset < pixelArrayLength; pixelOffset += 4) { unsigned char alphaA = srcPixelArrayA->get(pixelOffset + 3); unsigned char alphaB = srcPixelArrayB->get(pixelOffset + 3); for (unsigned channel = 0; channel < 3; ++channel) { unsigned char colorA = srcPixelArrayA->get(pixelOffset + channel); unsigned char colorB = srcPixelArrayB->get(pixelOffset + channel); unsigned char result = (*callEffect[m_mode])(colorA, colorB, alphaA, alphaB); dstPixelArray->set(pixelOffset + channel, result); } unsigned char alphaR = 255 - ((255 - alphaA) * (255 - alphaB)) / 255; dstPixelArray->set(pixelOffset + 3, alphaR); } }
void SVGPointList::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement* contextElement) { RefPtr<SVGPointList> otherList = toSVGPointList(other); if (length() != otherList->length()) return; for (size_t i = 0; i < length(); ++i) at(i)->setValue(at(i)->value() + otherList->at(i)->value()); }
void CString::copyBufferIfNeeded() { if (!m_buffer || m_buffer->hasOneRef()) return; RefPtr<CStringBuffer> buffer = WTFMove(m_buffer); size_t length = buffer->length(); m_buffer = CStringBuffer::createUninitialized(length); memcpy(m_buffer->mutableData(), buffer->data(), length + 1); }
WMLCardElement* WMLCardElement::determineActiveCard(Document* doc) { WMLPageState* pageState = wmlPageStateForDocument(doc); if (!pageState) return 0; RefPtr<NodeList> nodeList = doc->getElementsByTagName("card"); if (!nodeList) return 0; unsigned length = nodeList->length(); if (length < 1) return 0; // Figure out the new target card String cardName = doc->url().fragmentIdentifier(); WMLCardElement* activeCard = findNamedCardInDocument(doc, cardName); if (activeCard) { // Hide all cards - except the destination card - in document for (unsigned i = 0; i < length; ++i) { WMLCardElement* card = static_cast<WMLCardElement*>(nodeList->item(i)); if (card == activeCard) card->showCard(); else card->hideCard(); } } else { // If the target URL didn't contain a fragment identifier, activeCard // is 0, and has to be set to the first card element in the deck. activeCard = static_cast<WMLCardElement*>(nodeList->item(0)); activeCard->showCard(); } // Assure destination card is visible ASSERT(activeCard->isVisible()); ASSERT(activeCard->attached()); ASSERT(activeCard->renderer()); // Update the document title doc->setTitle(activeCard->title()); #if ENABLE(WMLSCRIPT) static_cast<WMLDocument*>(doc)->setActiveCardId(activeCard->getIDAttribute()) ; #endif // SAMSUNG_WML_FIXES+ // Set the active activeCard in the Document object static_cast<WMLDocument*>(doc)->setActiveCard(activeCard); // Set the active activeCard in the WMLPageState object //pageState->setActiveCard(activeCard); // SAMSUNG_WML_FIXES- return activeCard; }
PassRefPtr<ByteArray> ImageBuffer::getUnmultipliedImageData(const IntRect& rect) const { GraphicsContext* gc = this->context(); if (!gc) { return 0; } const SkBitmap& src = imageBufferCanvas(this)->getDevice()->accessBitmap(false); SkAutoLockPixels alp(src); if (!src.getPixels()) { return 0; } RefPtr<ByteArray> result = ByteArray::create(rect.width() * rect.height() * 4); unsigned char* data = result->data(); if (rect.x() < 0 || rect.y() < 0 || rect.maxX() > m_size.width() || rect.maxY() > m_size.height()) memset(data, 0, result->length()); int originx = rect.x(); int destx = 0; if (originx < 0) { destx = -originx; originx = 0; } int endx = rect.x() + rect.width(); if (endx > m_size.width()) endx = m_size.width(); int numColumns = endx - originx; int originy = rect.y(); int desty = 0; if (originy < 0) { desty = -originy; originy = 0; } int endy = rect.y() + rect.height(); if (endy > m_size.height()) endy = m_size.height(); int numRows = endy - originy; unsigned srcPixelsPerRow = src.rowBytesAsPixels(); unsigned destBytesPerRow = 4 * rect.width(); /// M: change process to read pixel @{ /* fix w3c pixel manipulation relative test case */ SkBitmap destBitmap; destBitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height(), destBytesPerRow); destBitmap.setPixels(data); SkCanvas* canvas = imageBufferCanvas(this); canvas->readPixels(&destBitmap, rect.x(), rect.y(), SkCanvas::kRGBA_Unpremul_Config8888); return result.release(); /// @} }