diff options
author | amanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-09 17:49:17 +0000 |
---|---|---|
committer | amanda@chromium.org <amanda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-09 17:49:17 +0000 |
commit | c595e11774ed9c3dc18f1f8ce614a47c71179bcb (patch) | |
tree | c03581c2d4367725266f6cdac8617bf34b206e37 /webkit/pending | |
parent | 7e177a51211929a435d29e27dd28f15a5a9a306e (diff) | |
download | chromium_src-c595e11774ed9c3dc18f1f8ce614a47c71179bcb.zip chromium_src-c595e11774ed9c3dc18f1f8ce614a47c71179bcb.tar.gz chromium_src-c595e11774ed9c3dc18f1f8ce614a47c71179bcb.tar.bz2 |
Adjust mac project to accommodate http://codereview.chromium.org/6368,
remove files from pending that are no longer referred to by any platform.
Review URL: http://codereview.chromium.org/6388
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3107 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/pending')
-rw-r--r-- | webkit/pending/GraphicsContext.cpp | 501 | ||||
-rw-r--r-- | webkit/pending/GraphicsContext.h | 368 | ||||
-rw-r--r-- | webkit/pending/HTMLAnchorElement.cpp | 504 | ||||
-rw-r--r-- | webkit/pending/HTMLLinkElement.cpp | 403 | ||||
-rw-r--r-- | webkit/pending/HTMLLinkElement.h | 119 | ||||
-rw-r--r-- | webkit/pending/Image.h | 177 | ||||
-rw-r--r-- | webkit/pending/String.cpp | 845 | ||||
-rw-r--r-- | webkit/pending/StringImpl.cpp | 1051 | ||||
-rw-r--r-- | webkit/pending/StringImpl.h | 282 |
9 files changed, 0 insertions, 4250 deletions
diff --git a/webkit/pending/GraphicsContext.cpp b/webkit/pending/GraphicsContext.cpp deleted file mode 100644 index 19a1862..0000000 --- a/webkit/pending/GraphicsContext.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/* - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "GraphicsContext.h" - -#include "BidiResolver.h" -#include "Generator.h" -#include "GraphicsContextPrivate.h" -#include "Font.h" -#include "NotImplemented.h" - -using namespace std; - -namespace WebCore { - -class TextRunIterator { -public: - TextRunIterator() - : m_textRun(0) - , m_offset(0) - { - } - - TextRunIterator(const TextRun* textRun, unsigned offset) - : m_textRun(textRun) - , m_offset(offset) - { - } - - TextRunIterator(const TextRunIterator& other) - : m_textRun(other.m_textRun) - , m_offset(other.m_offset) - { - } - - unsigned offset() const { return m_offset; } - void increment() { m_offset++; } - bool atEnd() const { return !m_textRun || m_offset >= m_textRun->length(); } - UChar current() const { return (*m_textRun)[m_offset]; } - WTF::Unicode::Direction direction() const { return atEnd() ? WTF::Unicode::OtherNeutral : WTF::Unicode::direction(current()); } - - bool operator==(const TextRunIterator& other) - { - return m_offset == other.m_offset && m_textRun == other.m_textRun; - } - - bool operator!=(const TextRunIterator& other) { return !operator==(other); } - -private: - const TextRun* m_textRun; - int m_offset; -}; - -GraphicsContextPrivate* GraphicsContext::createGraphicsContextPrivate() -{ - return new GraphicsContextPrivate; -} - -void GraphicsContext::destroyGraphicsContextPrivate(GraphicsContextPrivate* deleteMe) -{ - delete deleteMe; -} - -void GraphicsContext::save() -{ - if (paintingDisabled()) - return; - - m_common->stack.append(m_common->state); - - savePlatformState(); -} - -void GraphicsContext::restore() -{ - if (paintingDisabled()) - return; - - if (m_common->stack.isEmpty()) { - LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); - return; - } - m_common->state = m_common->stack.last(); - m_common->stack.removeLast(); - - restorePlatformState(); -} - -const Font& GraphicsContext::font() const -{ - return m_common->state.font; -} - -void GraphicsContext::setFont(const Font& aFont) -{ - m_common->state.font = aFont; - setPlatformFont(aFont); -} - -void GraphicsContext::setStrokeThickness(float thickness) -{ - m_common->state.strokeThickness = thickness; - setPlatformStrokeThickness(thickness); -} - -void GraphicsContext::setStrokeStyle(const StrokeStyle& style) -{ - m_common->state.strokeStyle = style; - setPlatformStrokeStyle(style); -} - -void GraphicsContext::setStrokeColor(const Color& color) -{ - m_common->state.strokeColorSpace = SolidColorSpace; - m_common->state.strokeColor = color; - setPlatformStrokeColor(color); -} - -void GraphicsContext::setShadow(const IntSize& size, int blur, const Color& color) -{ - m_common->state.shadowSize = size; - m_common->state.shadowBlur = blur; - m_common->state.shadowColor = color; - setPlatformShadow(size, blur, color); -} - -void GraphicsContext::clearShadow() -{ - m_common->state.shadowSize = IntSize(); - m_common->state.shadowBlur = 0; - m_common->state.shadowColor = Color(); - clearPlatformShadow(); -} - -bool GraphicsContext::getShadow(IntSize& size, int& blur, Color& color) const -{ - size = m_common->state.shadowSize; - blur = m_common->state.shadowBlur; - color = m_common->state.shadowColor; - - return color.isValid() && color.alpha() && (blur || size.width() || size.height()); -} - -float GraphicsContext::strokeThickness() const -{ - return m_common->state.strokeThickness; -} - -StrokeStyle GraphicsContext::strokeStyle() const -{ - return m_common->state.strokeStyle; -} - -Color GraphicsContext::strokeColor() const -{ - return m_common->state.strokeColor; -} - -WindRule GraphicsContext::fillRule() const -{ - return m_common->state.fillRule; -} - -void GraphicsContext::setFillRule(WindRule fillRule) -{ - m_common->state.fillRule = fillRule; -} - -void GraphicsContext::setFillColor(const Color& color) -{ - m_common->state.fillColorSpace = SolidColorSpace; - m_common->state.fillColor = color; - setPlatformFillColor(color); -} - -Color GraphicsContext::fillColor() const -{ - return m_common->state.fillColor; -} - -void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern) -{ - ASSERT(pattern); - if (!pattern) { - setStrokeColor(Color::black); - return; - } - m_common->state.strokeColorSpace = PatternColorSpace; - m_common->state.strokePattern = pattern; - setPlatformStrokePattern(m_common->state.strokePattern.get()); -} - -void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern) -{ - ASSERT(pattern); - if (!pattern) { - setFillColor(Color::black); - return; - } - m_common->state.fillColorSpace = PatternColorSpace; - m_common->state.fillPattern = pattern; - setPlatformFillPattern(m_common->state.fillPattern.get()); -} - -void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient) -{ - ASSERT(gradient); - if (!gradient) { - setStrokeColor(Color::black); - return; - } - m_common->state.strokeColorSpace = GradientColorSpace; - m_common->state.strokeGradient = gradient; - setPlatformStrokeGradient(m_common->state.strokeGradient.get()); -} - -void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient) -{ - ASSERT(gradient); - if (!gradient) { - setFillColor(Color::black); - return; - } - m_common->state.fillColorSpace = GradientColorSpace; - m_common->state.fillGradient = gradient; - setPlatformFillGradient(m_common->state.fillGradient.get()); -} - -bool GraphicsContext::updatingControlTints() const -{ - return m_common->m_updatingControlTints; -} - -void GraphicsContext::setUpdatingControlTints(bool b) -{ - setPaintingDisabled(b); - m_common->m_updatingControlTints = b; -} - -void GraphicsContext::setPaintingDisabled(bool f) -{ - m_common->state.paintingDisabled = f; -} - -bool GraphicsContext::paintingDisabled() const -{ - return m_common->state.paintingDisabled; -} - -void GraphicsContext::drawImage(Image* image, const IntPoint& p, CompositeOperator op) -{ - drawImage(image, p, IntRect(0, 0, -1, -1), op); -} - -void GraphicsContext::drawImage(Image* image, const IntRect& r, CompositeOperator op, bool useLowQualityScale) -{ - drawImage(image, r, IntRect(0, 0, -1, -1), op, useLowQualityScale); -} - -void GraphicsContext::drawImage(Image* image, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op) -{ - drawImage(image, IntRect(dest, srcRect.size()), srcRect, op); -} - -void GraphicsContext::drawImage(Image* image, const IntRect& dest, const IntRect& srcRect, CompositeOperator op, bool useLowQualityScale) -{ - drawImage(image, FloatRect(dest), srcRect, op, useLowQualityScale); -} - -void GraphicsContext::drawText(const TextRun& run, const IntPoint& point, int from, int to) -{ - if (paintingDisabled()) - return; - - font().drawText(this, run, point, from, to); -} - -void GraphicsContext::drawBidiText(const TextRun& run, const FloatPoint& point) -{ - if (paintingDisabled()) - return; - - BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; - WTF::Unicode::Direction paragraphDirection = run.ltr() ? WTF::Unicode::LeftToRight : WTF::Unicode::RightToLeft; - - bidiResolver.setStatus(BidiStatus(paragraphDirection, paragraphDirection, paragraphDirection, new BidiContext(run.ltr() ? 0 : 1, paragraphDirection, run.directionalOverride()))); - - bidiResolver.setPosition(TextRunIterator(&run, 0)); - bidiResolver.createBidiRunsForLine(TextRunIterator(&run, run.length())); - - if (!bidiResolver.runCount()) - return; - - FloatPoint currPoint = point; - BidiCharacterRun* bidiRun = bidiResolver.firstRun(); - while (bidiRun) { - - TextRun subrun = run; - subrun.setText(run.data(bidiRun->start()), bidiRun->stop() - bidiRun->start()); - subrun.setRTL(bidiRun->level() % 2); - subrun.setDirectionalOverride(bidiRun->dirOverride(false)); - - font().drawText(this, subrun, currPoint); - - bidiRun = bidiRun->next(); - // FIXME: Have Font::drawText return the width of what it drew so that we don't have to re-measure here. - if (bidiRun) - currPoint.move(font().floatWidth(subrun), 0.f); - } - - bidiResolver.deleteRuns(); -} - -void GraphicsContext::drawHighlightForText(const TextRun& run, const IntPoint& point, int h, const Color& backgroundColor, int from, int to) -{ - if (paintingDisabled()) - return; - - fillRect(font().selectionRectForText(run, point, h, from, to), backgroundColor); -} - -void GraphicsContext::initFocusRing(int width, int offset) -{ - if (paintingDisabled()) - return; - clearFocusRing(); - - m_common->m_focusRingWidth = width; - m_common->m_focusRingOffset = offset; -} - -void GraphicsContext::clearFocusRing() -{ - m_common->m_focusRingRects.clear(); -} - -IntRect GraphicsContext::focusRingBoundingRect() -{ - IntRect result = IntRect(0, 0, 0, 0); - - const Vector<IntRect>& rects = focusRingRects(); - unsigned rectCount = rects.size(); - for (unsigned i = 0; i < rectCount; i++) - result.unite(rects[i]); - - return result; -} - -void GraphicsContext::addFocusRingRect(const IntRect& rect) -{ - if (paintingDisabled() || rect.isEmpty()) - return; - m_common->m_focusRingRects.append(rect); -} - -int GraphicsContext::focusRingWidth() const -{ - return m_common->m_focusRingWidth; -} - -int GraphicsContext::focusRingOffset() const -{ - return m_common->m_focusRingOffset; -} - -const Vector<IntRect>& GraphicsContext::focusRingRects() const -{ - return m_common->m_focusRingRects; -} - -void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op, bool useLowQualityScale) -{ - if (paintingDisabled() || !image) - return; - - float tsw = src.width(); - float tsh = src.height(); - float tw = dest.width(); - float th = dest.height(); - - if (tsw == -1) - tsw = image->width(); - if (tsh == -1) - tsh = image->height(); - - if (tw == -1) - tw = image->width(); - if (th == -1) - th = image->height(); - - if (useLowQualityScale) { - save(); - setImageInterpolationQuality(InterpolationNone); - } - image->draw(this, FloatRect(dest.location(), FloatSize(tw, th)), FloatRect(src.location(), FloatSize(tsw, tsh)), op); - if (useLowQualityScale) - restore(); -} - -void GraphicsContext::drawTiledImage(Image* image, const IntRect& rect, const IntPoint& srcPoint, const IntSize& tileSize, CompositeOperator op) -{ - if (paintingDisabled() || !image) - return; - - image->drawTiled(this, rect, srcPoint, tileSize, op); -} - -void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const IntRect& srcRect, Image::TileRule hRule, Image::TileRule vRule, CompositeOperator op) -{ - if (paintingDisabled() || !image) - return; - - if (hRule == Image::StretchTile && vRule == Image::StretchTile) - // Just do a scale. - return drawImage(image, dest, srcRect, op); - - image->drawTiled(this, dest, srcRect, hRule, vRule, op); -} - -void GraphicsContext::addRoundedRectClip(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, - const IntSize& bottomLeft, const IntSize& bottomRight) -{ - if (paintingDisabled()) - return; - - clip(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight)); -} - -void GraphicsContext::clipOutRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, - const IntSize& bottomLeft, const IntSize& bottomRight) -{ - if (paintingDisabled()) - return; - - clipOut(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight)); -} - -int GraphicsContext::textDrawingMode() -{ - return m_common->state.textDrawingMode; -} - -void GraphicsContext::setTextDrawingMode(int mode) -{ - m_common->state.textDrawingMode = mode; - if (paintingDisabled()) - return; - setPlatformTextDrawingMode(mode); -} - -void GraphicsContext::fillRect(const FloatRect& rect, Generator& generator) -{ - if (paintingDisabled()) - return; - generator.fill(this, rect); -} - -#if !PLATFORM(CG) -// Implement this if you want to go ahead and push the drawing mode into your native context -// immediately. -void GraphicsContext::setPlatformTextDrawingMode(int mode) -{ -} -#endif - -#if !PLATFORM(QT) && !PLATFORM(CAIRO) && !PLATFORM(SKIA) -void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle&) -{ -} -#endif - -#if !PLATFORM(QT) -void GraphicsContext::setPlatformFont(const Font&) -{ -} -#endif - -} diff --git a/webkit/pending/GraphicsContext.h b/webkit/pending/GraphicsContext.h deleted file mode 100644 index e6cdc8f..0000000 --- a/webkit/pending/GraphicsContext.h +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef GraphicsContext_h -#define GraphicsContext_h - -#include "FloatRect.h" -#include "Image.h" -#include "IntRect.h" -#include "Path.h" -#include "TextDirection.h" -#include <wtf/Noncopyable.h> -#include <wtf/Platform.h> - -#if PLATFORM(CG) -typedef struct CGContext PlatformGraphicsContext; -#elif PLATFORM(CAIRO) -typedef struct _cairo PlatformGraphicsContext; -#elif PLATFORM(QT) -QT_BEGIN_NAMESPACE -class QPainter; -QT_END_NAMESPACE -typedef QPainter PlatformGraphicsContext; -#elif PLATFORM(WX) -class wxGCDC; -class wxWindowDC; - -// wxGraphicsContext allows us to support Path, etc. -// but on some platforms, e.g. Linux, it requires fairly -// new software. -#if USE(WXGC) -// On OS X, wxGCDC is just a typedef for wxDC, so use wxDC explicitly to make -// the linker happy. -#ifdef __APPLE__ - class wxDC; - typedef wxDC PlatformGraphicsContext; -#else - typedef wxGCDC PlatformGraphicsContext; -#endif -#else - typedef wxWindowDC PlatformGraphicsContext; -#endif -#elif PLATFORM(SKIA) -typedef class PlatformContextSkia PlatformGraphicsContext; -#else -typedef void PlatformGraphicsContext; -#endif - -#if PLATFORM(GTK) -typedef struct _GdkDrawable GdkDrawable; -typedef struct _GdkEventExpose GdkEventExpose; -#endif - -#if PLATFORM(WIN) -typedef struct HDC__* HDC; -#if !PLATFORM(CG) -// UInt8 is defined in CoreFoundation/CFBase.h -typedef unsigned char UInt8; -#endif -#endif - -#if PLATFORM(QT) && defined(Q_WS_WIN) -#include <windows.h> -#endif - -namespace WebCore { - - const int cMisspellingLineThickness = 3; - const int cMisspellingLinePatternWidth = 4; - const int cMisspellingLinePatternGapWidth = 1; - - class AffineTransform; - class Font; - class Generator; - class Gradient; - class GraphicsContextPrivate; - class GraphicsContextPlatformPrivate; - class ImageBuffer; - class KURL; - class Path; - class Pattern; - class TextRun; - - // These bits can be ORed together for a total of 8 possible text drawing modes. - const int cTextInvisible = 0; - const int cTextFill = 1; - const int cTextStroke = 2; - const int cTextClip = 4; - - enum StrokeStyle { - NoStroke, - SolidStroke, - DottedStroke, - DashedStroke - }; - - enum InterpolationQuality { - InterpolationDefault, - InterpolationNone, - InterpolationLow, - InterpolationMedium, - InterpolationHigh - }; - - class GraphicsContext : Noncopyable { - public: - GraphicsContext(PlatformGraphicsContext*); - ~GraphicsContext(); - - PlatformGraphicsContext* platformContext() const; - - const Font& font() const; - void setFont(const Font&); - - float strokeThickness() const; - void setStrokeThickness(float); - StrokeStyle strokeStyle() const; - void setStrokeStyle(const StrokeStyle& style); - Color strokeColor() const; - void setStrokeColor(const Color&); - void setStrokePattern(PassRefPtr<Pattern>); - void setStrokeGradient(PassRefPtr<Gradient>); - - WindRule fillRule() const; - void setFillRule(WindRule); - Color fillColor() const; - void setFillColor(const Color&); - void setFillPattern(PassRefPtr<Pattern>); - void setFillGradient(PassRefPtr<Gradient>); - - void save(); - void restore(); - - // These draw methods will do both stroking and filling. - void drawRect(const IntRect&); - void drawLine(const IntPoint&, const IntPoint&); - void drawEllipse(const IntRect&); - void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false); - - void drawPath(); - void fillPath(); - void strokePath(); - - // Arc drawing (used by border-radius in CSS) just supports stroking at the moment. - void strokeArc(const IntRect&, int startAngle, int angleSpan); - - void fillRect(const FloatRect&); - void fillRect(const FloatRect&, const Color&); - void fillRect(const FloatRect&, Generator&); - void fillRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color&); - - void clearRect(const FloatRect&); - - void strokeRect(const FloatRect&); - void strokeRect(const FloatRect&, float lineWidth); - - void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver); - void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false); - void drawImage(Image*, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver); - void drawImage(Image*, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false); - void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1), - CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false); - void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize, - CompositeOperator = CompositeSourceOver); - void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, - Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile, - CompositeOperator = CompositeSourceOver); - - void setImageInterpolationQuality(InterpolationQuality); - InterpolationQuality imageInterpolationQuality() const; - - void clip(const FloatRect&); - void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight); - void addInnerRoundedRectClip(const IntRect&, int thickness); - void clipOut(const IntRect&); - void clipOutEllipseInRect(const IntRect&); - void clipOutRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight); - void clipToImageBuffer(const FloatRect&, const ImageBuffer*); - - int textDrawingMode(); - void setTextDrawingMode(int); - - void drawText(const TextRun&, const IntPoint&, int from = 0, int to = -1); - void drawBidiText(const TextRun&, const FloatPoint&); - void drawHighlightForText(const TextRun&, const IntPoint&, int h, const Color& backgroundColor, int from = 0, int to = -1); - - FloatRect roundToDevicePixels(const FloatRect&); - - void drawLineForText(const IntPoint&, int width, bool printing); - void drawLineForMisspellingOrBadGrammar(const IntPoint&, int width, bool grammar); - - bool paintingDisabled() const; - void setPaintingDisabled(bool); - - bool updatingControlTints() const; - void setUpdatingControlTints(bool); - - void beginTransparencyLayer(float opacity); - void endTransparencyLayer(); - - void setShadow(const IntSize&, int blur, const Color&); - bool getShadow(IntSize&, int&, Color&) const; - void clearShadow(); - - void initFocusRing(int width, int offset); - void addFocusRingRect(const IntRect&); - void drawFocusRing(const Color&); - void clearFocusRing(); - IntRect focusRingBoundingRect(); - - void setLineCap(LineCap); - void setLineJoin(LineJoin); - void setMiterLimit(float); - - void setAlpha(float); - - void setCompositeOperation(CompositeOperator); - - void beginPath(); - void addPath(const Path&); - - void clip(const Path&); - void clipOut(const Path&); - - void scale(const FloatSize&); - void rotate(float angleInRadians); - void translate(float x, float y); - IntPoint origin(); - - void setURLForRect(const KURL&, const IntRect&); - - void concatCTM(const AffineTransform&); - AffineTransform getCTM() const; - - void setUseAntialiasing(bool = true); - -#if PLATFORM(WIN) - GraphicsContext(HDC, bool hasAlpha = false); // FIXME: To be removed. - bool inTransparencyLayer() const; - HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); // The passed in rect is used to create a bitmap for compositing inside transparency layers. - void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); // The passed in HDC should be the one handed back by getWindowsContext. - - class WindowsBitmap : public Noncopyable { - public: - WindowsBitmap(HDC, IntSize); - ~WindowsBitmap(); - - HDC hdc() const { return m_hdc; } - UInt8* buffer() const { return m_bitmapBuffer; } - unsigned bufferLength() const { return m_bitmapBufferLength; } - IntSize size() const { return m_size; } - unsigned bytesPerRow() const { return m_bytesPerRow; } - - private: - HDC m_hdc; - HBITMAP m_bitmap; - UInt8* m_bitmapBuffer; - unsigned m_bitmapBufferLength; - IntSize m_size; - unsigned m_bytesPerRow; - }; - - WindowsBitmap* createWindowsBitmap(IntSize); - // The bitmap should be non-premultiplied. - void drawWindowsBitmap(WindowsBitmap*, const IntPoint&); -#endif - -#if PLATFORM(QT) && defined(Q_WS_WIN) - HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); - void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); -#endif - -#if PLATFORM(QT) - bool inTransparencyLayer() const; - PlatformPath* currentPath(); -#endif - -#if PLATFORM(GTK) - void setGdkExposeEvent(GdkEventExpose*); - GdkDrawable* gdkDrawable() const; - GdkEventExpose* gdkExposeEvent() const; -#endif - -#if PLATFORM(SKIA) - /** platform-specific factory method to return a bitmap graphicscontext, - called by <canvas> when we need to draw offscreen. The caller is - responsible for deleting the pointer. - */ - static GraphicsContext* createOffscreenContext(int width, int height); - - /** Called with a context returned by createOffscreenContext. Draw the underlying - bitmap to the current context. Similar to drawImage(), but this hides how - to extract the bitmap from ctx from the portable code. - If srcRect is NULL, it is assumed that we want to draw the entire bitmap represented - by the GraphicsContext. - */ - void drawOffscreenContext(GraphicsContext* ctx, const WebCore::FloatRect*, const WebCore::FloatRect&); - - /** Return the clip bounds in local coordinates. It can be an approximation, as long as - the returned bounds completely enclose the actual clip. - */ - FloatRect getClipLocalBounds() const; - FloatRect getBoundingBoxForCurrentPath(bool includStroke = false) const; - - /** Determines if a given point is contained in a path stroked with the current style - */ - bool strokeContains(const Path&, const FloatPoint&) const; - - // FIXME: This hack should be removed. - void setShouldDelete(bool should_delete); -#endif - - private: - void savePlatformState(); - void restorePlatformState(); - - void setPlatformTextDrawingMode(int); - void setPlatformFont(const Font& font); - - void setPlatformStrokeColor(const Color&); - void setPlatformStrokePattern(Pattern*); - void setPlatformStrokeGradient(Gradient*); - void setPlatformStrokeStyle(const StrokeStyle&); - void setPlatformStrokeThickness(float); - - void setPlatformFillColor(const Color&); - void setPlatformFillPattern(Pattern*); - void setPlatformFillGradient(Gradient*); - - void setPlatformShadow(const IntSize&, int blur, const Color&); - void clearPlatformShadow(); - - int focusRingWidth() const; - int focusRingOffset() const; - const Vector<IntRect>& focusRingRects() const; - - static GraphicsContextPrivate* createGraphicsContextPrivate(); - static void destroyGraphicsContextPrivate(GraphicsContextPrivate*); - - GraphicsContextPrivate* m_common; - GraphicsContextPlatformPrivate* m_data; // Deprecated; m_commmon can just be downcasted. To be removed. - }; - -} // namespace WebCore - -#endif // GraphicsContext_h diff --git a/webkit/pending/HTMLAnchorElement.cpp b/webkit/pending/HTMLAnchorElement.cpp deleted file mode 100644 index 3289189..0000000 --- a/webkit/pending/HTMLAnchorElement.cpp +++ /dev/null @@ -1,504 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved. - * (C) 2006 Graham Dennis (graham.dennis@gmail.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "HTMLAnchorElement.h" - -#include "CSSHelper.h" -#include "DNS.h" -#include "Document.h" -#include "Event.h" -#include "EventHandler.h" -#include "EventNames.h" -#include "Frame.h" -#include "FrameLoader.h" -#include "FrameLoaderClient.h" -#include "HTMLImageElement.h" -#include "HTMLNames.h" -#include "KeyboardEvent.h" -#include "MouseEvent.h" -#include "MutationEvent.h" -#include "RenderFlow.h" -#include "RenderImage.h" -#include "ResourceRequest.h" -#include "SelectionController.h" -#include "Settings.h" -#include "UIEvent.h" - -namespace WebCore { - -using namespace HTMLNames; -using namespace EventNames; - -HTMLAnchorElement::HTMLAnchorElement(Document* doc) - : HTMLElement(aTag, doc) - , m_rootEditableElementForSelectionOnMouseDown(0) - , m_wasShiftKeyDownOnMouseDown(false) -{ -} - -HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) - , m_rootEditableElementForSelectionOnMouseDown(0) - , m_wasShiftKeyDownOnMouseDown(false) -{ -} - -HTMLAnchorElement::~HTMLAnchorElement() -{ -} - -bool HTMLAnchorElement::supportsFocus() const -{ - if (isContentEditable()) - return HTMLElement::supportsFocus(); - return isFocusable() || (isLink() && document() && !document()->haveStylesheetsLoaded()); -} - -bool HTMLAnchorElement::isFocusable() const -{ - if (isContentEditable()) - return HTMLElement::isFocusable(); - - // FIXME: Even if we are not visible, we might have a child that is visible. - // Dave wants to fix that some day with a "has visible content" flag or the like. - if (!(isLink() && renderer() && renderer()->style()->visibility() == VISIBLE)) - return false; - - return true; -} - -bool HTMLAnchorElement::isMouseFocusable() const -{ - return false; -} - -bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const -{ - if (!isFocusable()) - return false; - - if (!document()->frame()) - return false; - - if (!document()->frame()->eventHandler()->tabsToLinks(event)) - return false; - - // Before calling absoluteRects, check for the common case where the renderer - // or one of the continuations is non-empty, since this is a faster check and - // almost always returns true. - for (RenderObject* r = renderer(); r; r = r->continuation()) - if (r->width() > 0 && r->height() > 0) - return true; - - Vector<IntRect> rects; - int x, y; - renderer()->absolutePosition(x, y); - renderer()->absoluteRects(rects, x, y); - size_t n = rects.size(); - for (size_t i = 0; i < n; ++i) - if (!rects[i].isEmpty()) - return true; - - return false; -} - -void HTMLAnchorElement::defaultEventHandler(Event* evt) -{ - // React on clicks and on keypresses. - // Don't make this KEYUP_EVENT again, it makes khtml follow links it shouldn't, - // when pressing Enter in the combo. - if (isLink() && (evt->type() == clickEvent || (evt->type() == keydownEvent && focused()))) { - MouseEvent* e = 0; - if (evt->type() == clickEvent && evt->isMouseEvent()) - e = static_cast<MouseEvent*>(evt); - - KeyboardEvent* k = 0; - if (evt->type() == keydownEvent && evt->isKeyboardEvent()) - k = static_cast<KeyboardEvent*>(evt); - - if (e && e->button() == RightButton) { - HTMLElement::defaultEventHandler(evt); - return; - } - - // If the link is editable, then we need to check the settings to see whether or not to follow the link - if (isContentEditable()) { - EditableLinkBehavior editableLinkBehavior = EditableLinkDefaultBehavior; - if (Settings* settings = document()->settings()) - editableLinkBehavior = settings->editableLinkBehavior(); - - switch (editableLinkBehavior) { - // Always follow the link (Safari 2.0 behavior) - default: - case EditableLinkDefaultBehavior: - case EditableLinkAlwaysLive: - break; - - case EditableLinkNeverLive: - HTMLElement::defaultEventHandler(evt); - return; - - // If the selection prior to clicking on this link resided in the same editable block as this link, - // and the shift key isn't pressed, we don't want to follow the link - case EditableLinkLiveWhenNotFocused: - if (e && !e->shiftKey() && m_rootEditableElementForSelectionOnMouseDown == rootEditableElement()) { - HTMLElement::defaultEventHandler(evt); - return; - } - break; - - // Only follow the link if the shift key is down (WinIE/Firefox behavior) - case EditableLinkOnlyLiveWithShiftKey: - if (e && !e->shiftKey()) { - HTMLElement::defaultEventHandler(evt); - return; - } - break; - } - } - - if (k) { - if (k->keyIdentifier() != "Enter") { - HTMLElement::defaultEventHandler(evt); - return; - } - evt->setDefaultHandled(); - dispatchSimulatedClick(evt); - return; - } - - String url = parseURL(getAttribute(hrefAttr)); - - ASSERT(evt->target()); - ASSERT(evt->target()->toNode()); - if (evt->target()->toNode()->hasTagName(imgTag)) { - HTMLImageElement* img = static_cast<HTMLImageElement*>(evt->target()->toNode()); - if (img && img->isServerMap()) { - RenderImage* r = static_cast<RenderImage*>(img->renderer()); - if (r && e) { - int absx, absy; - r->absolutePosition(absx, absy); - int x = e->pageX() - absx; - int y = e->pageY() - absy; - url += "?"; - url += String::number(x); - url += ","; - url += String::number(y); - } else { - evt->setDefaultHandled(); - HTMLElement::defaultEventHandler(evt); - return; - } - } - } - - if (!evt->defaultPrevented() && document()->frame()) - document()->frame()->loader()->urlSelected(document()->completeURL(url), getAttribute(targetAttr), evt, false, true); - - evt->setDefaultHandled(); - } else if (isLink() && isContentEditable()) { - // This keeps track of the editable block that the selection was in (if it was in one) just before the link was clicked - // for the LiveWhenNotFocused editable link behavior - if (evt->type() == mousedownEvent && evt->isMouseEvent() && static_cast<MouseEvent*>(evt)->button() != RightButton && document()->frame() && document()->frame()->selection()) { - MouseEvent* e = static_cast<MouseEvent*>(evt); - - m_rootEditableElementForSelectionOnMouseDown = document()->frame()->selection()->rootEditableElement(); - m_wasShiftKeyDownOnMouseDown = e && e->shiftKey(); - } else if (evt->type() == mouseoverEvent) { - // These are cleared on mouseover and not mouseout because their values are needed for drag events, but these happen - // after mouse out events. - m_rootEditableElementForSelectionOnMouseDown = 0; - m_wasShiftKeyDownOnMouseDown = false; - } - } - - HTMLElement::defaultEventHandler(evt); -} - -void HTMLAnchorElement::setActive(bool down, bool pause) -{ - if (isContentEditable()) { - EditableLinkBehavior editableLinkBehavior = EditableLinkDefaultBehavior; - if (Settings* settings = document()->settings()) - editableLinkBehavior = settings->editableLinkBehavior(); - - switch(editableLinkBehavior) { - default: - case EditableLinkDefaultBehavior: - case EditableLinkAlwaysLive: - break; - - case EditableLinkNeverLive: - return; - - // Don't set the link to be active if the current selection is in the same editable block as - // this link - case EditableLinkLiveWhenNotFocused: - if (down && document()->frame() && document()->frame()->selection() && - document()->frame()->selection()->rootEditableElement() == rootEditableElement()) - return; - break; - - case EditableLinkOnlyLiveWithShiftKey: - return; - } - - } - - ContainerNode::setActive(down, pause); -} - -void HTMLAnchorElement::parseMappedAttribute(MappedAttribute *attr) -{ - if (attr->name() == hrefAttr) { - bool wasLink = isLink(); - setIsLink(!attr->isNull()); - if (wasLink != isLink()) - setChanged(); - if (isLink() && document()->isDNSPrefetchEnabled()) { - String value = attr->value(); - if (protocolIs(value, "http") || protocolIs(value, "https") || value.startsWith("//")) - prefetchDNS(document()->completeURL(value).host()); - } - } else if (attr->name() == nameAttr || - attr->name() == titleAttr || - attr->name() == relAttr) { - // Do nothing. - } else - HTMLElement::parseMappedAttribute(attr); -} - -void HTMLAnchorElement::accessKeyAction(bool sendToAnyElement) -{ - // send the mouse button events if the caller specified sendToAnyElement - dispatchSimulatedClick(0, sendToAnyElement); -} - -bool HTMLAnchorElement::isURLAttribute(Attribute *attr) const -{ - return attr->name() == hrefAttr; -} - -bool HTMLAnchorElement::canStartSelection() const -{ - // FIXME: We probably want this same behavior in SVGAElement too - if (!isLink()) - return HTMLElement::canStartSelection(); - return isContentEditable(); -} - -String HTMLAnchorElement::accessKey() const -{ - return getAttribute(accesskeyAttr); -} - -void HTMLAnchorElement::setAccessKey(const String &value) -{ - setAttribute(accesskeyAttr, value); -} - -String HTMLAnchorElement::charset() const -{ - return getAttribute(charsetAttr); -} - -void HTMLAnchorElement::setCharset(const String &value) -{ - setAttribute(charsetAttr, value); -} - -String HTMLAnchorElement::coords() const -{ - return getAttribute(coordsAttr); -} - -void HTMLAnchorElement::setCoords(const String &value) -{ - setAttribute(coordsAttr, value); -} - -KURL HTMLAnchorElement::href() const -{ - return document()->completeURL(getAttribute(hrefAttr)); -} - -void HTMLAnchorElement::setHref(const String &value) -{ - setAttribute(hrefAttr, value); -} - -String HTMLAnchorElement::hreflang() const -{ - return getAttribute(hreflangAttr); -} - -void HTMLAnchorElement::setHreflang(const String &value) -{ - setAttribute(hreflangAttr, value); -} - -String HTMLAnchorElement::name() const -{ - return getAttribute(nameAttr); -} - -void HTMLAnchorElement::setName(const String &value) -{ - setAttribute(nameAttr, value); -} - -String HTMLAnchorElement::rel() const -{ - return getAttribute(relAttr); -} - -void HTMLAnchorElement::setRel(const String &value) -{ - setAttribute(relAttr, value); -} - -String HTMLAnchorElement::rev() const -{ - return getAttribute(revAttr); -} - -void HTMLAnchorElement::setRev(const String &value) -{ - setAttribute(revAttr, value); -} - -String HTMLAnchorElement::shape() const -{ - return getAttribute(shapeAttr); -} - -void HTMLAnchorElement::setShape(const String &value) -{ - setAttribute(shapeAttr, value); -} - -short HTMLAnchorElement::tabIndex() const -{ - return Element::tabIndex(); -} - -String HTMLAnchorElement::target() const -{ - return getAttribute(targetAttr); -} - -void HTMLAnchorElement::setTarget(const String &value) -{ - setAttribute(targetAttr, value); -} - -String HTMLAnchorElement::type() const -{ - return getAttribute(typeAttr); -} - -void HTMLAnchorElement::setType(const String &value) -{ - setAttribute(typeAttr, value); -} - -String HTMLAnchorElement::hash() const -{ - return "#" + href().ref(); -} - -String HTMLAnchorElement::host() const -{ - return href().host(); -} - -String HTMLAnchorElement::hostname() const -{ - const KURL& url = href(); - if (url.port() == 0) - return url.host(); - return url.host() + ":" + String::number(url.port()); -} - -String HTMLAnchorElement::pathname() const -{ - return href().path(); -} - -String HTMLAnchorElement::port() const -{ - return String::number(href().port()); -} - -String HTMLAnchorElement::protocol() const -{ - return href().protocol() + ":"; -} - -String HTMLAnchorElement::search() const -{ - return href().query(); -} - -String HTMLAnchorElement::text() const -{ - return innerText(); -} - -String HTMLAnchorElement::toString() const -{ - return href().string(); -} - -bool HTMLAnchorElement::isLiveLink() const -{ - if (!isLink()) - return false; - if (!isContentEditable()) - return true; - - EditableLinkBehavior editableLinkBehavior = EditableLinkDefaultBehavior; - if (Settings* settings = document()->settings()) - editableLinkBehavior = settings->editableLinkBehavior(); - - switch(editableLinkBehavior) { - default: - case EditableLinkDefaultBehavior: - case EditableLinkAlwaysLive: - return true; - - case EditableLinkNeverLive: - return false; - - // Don't set the link to be live if the current selection is in the same editable block as - // this link or if the shift key is down - case EditableLinkLiveWhenNotFocused: - return m_wasShiftKeyDownOnMouseDown || m_rootEditableElementForSelectionOnMouseDown != rootEditableElement(); - - case EditableLinkOnlyLiveWithShiftKey: - return m_wasShiftKeyDownOnMouseDown; - } -} - -} diff --git a/webkit/pending/HTMLLinkElement.cpp b/webkit/pending/HTMLLinkElement.cpp deleted file mode 100644 index 893f15d..0000000 --- a/webkit/pending/HTMLLinkElement.cpp +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "HTMLLinkElement.h" - -#include "CSSHelper.h" -#include "CachedCSSStyleSheet.h" -#include "DNS.h" -#include "DocLoader.h" -#include "Document.h" -#include "Frame.h" -#include "FrameLoader.h" -#include "FrameLoaderClient.h" -#include "FrameTree.h" -#include "HTMLNames.h" -#include "MediaList.h" -#include "MediaQueryEvaluator.h" -#include "Page.h" -#include "Settings.h" - -namespace WebCore { - -using namespace HTMLNames; - -HTMLLinkElement::HTMLLinkElement(Document *doc) - : HTMLElement(linkTag, doc) - , m_cachedSheet(0) - , m_disabledState(0) - , m_loading(false) - , m_alternate(false) - , m_isStyleSheet(false) - , m_isIcon(false) - , m_isDNSPrefetch(false) - , m_createdByParser(false) -{ -} - -HTMLLinkElement::~HTMLLinkElement() -{ - if (m_cachedSheet) { - m_cachedSheet->removeClient(this); - if (m_loading && !isDisabled() && !isAlternate()) - document()->removePendingSheet(); - } -} - -void HTMLLinkElement::setDisabledState(bool _disabled) -{ - int oldDisabledState = m_disabledState; - m_disabledState = _disabled ? 2 : 1; - if (oldDisabledState != m_disabledState) { - // If we change the disabled state while the sheet is still loading, then we have to - // perform three checks: - if (isLoading()) { - // Check #1: If the sheet becomes disabled while it was loading, and if it was either - // a main sheet or a sheet that was previously enabled via script, then we need - // to remove it from the list of pending sheets. - if (m_disabledState == 2 && (!m_alternate || oldDisabledState == 1)) - document()->removePendingSheet(); - - // Check #2: An alternate sheet becomes enabled while it is still loading. - if (m_alternate && m_disabledState == 1) - document()->addPendingSheet(); - - // Check #3: A main sheet becomes enabled while it was still loading and - // after it was disabled via script. It takes really terrible code to make this - // happen (a double toggle for no reason essentially). This happens on - // virtualplastic.net, which manages to do about 12 enable/disables on only 3 - // sheets. :) - if (!m_alternate && m_disabledState == 1 && oldDisabledState == 2) - document()->addPendingSheet(); - - // If the sheet is already loading just bail. - return; - } - - // Load the sheet, since it's never been loaded before. - if (!m_sheet && m_disabledState == 1) - process(); - else - document()->updateStyleSelector(); // Update the style selector. - } -} - -StyleSheet* HTMLLinkElement::sheet() const -{ - return m_sheet.get(); -} - -void HTMLLinkElement::parseMappedAttribute(MappedAttribute *attr) -{ - if (attr->name() == relAttr) { - tokenizeRelAttribute(attr->value(), m_isStyleSheet, m_alternate, m_isIcon); - process(); - } else if (attr->name() == hrefAttr) { - m_url = document()->completeURL(parseURL(attr->value())).string(); - process(); - } else if (attr->name() == typeAttr) { - m_type = attr->value(); - process(); - } else if (attr->name() == mediaAttr) { - m_media = attr->value().string().lower(); - process(); - } else if (attr->name() == disabledAttr) { - setDisabledState(!attr->isNull()); - } else { - if (attr->name() == titleAttr && m_sheet) - m_sheet->setTitle(attr->value()); - HTMLElement::parseMappedAttribute(attr); - } -} - -void HTMLLinkElement::tokenizeRelAttribute(const AtomicString& rel, bool& styleSheet, bool& alternate, bool& icon) -{ - styleSheet = false; - icon = false; - alternate = false; - if (equalIgnoringCase(rel, "stylesheet")) - styleSheet = true; - else if (equalIgnoringCase(rel, "icon") || equalIgnoringCase(rel, "shortcut icon")) - icon = true; - else if (equalIgnoringCase(rel, "alternate stylesheet") || equalIgnoringCase(rel, "stylesheet alternate")) { - styleSheet = true; - alternate = true; - } else { - // Tokenize the rel attribute and set bits based on specific keywords that we find. - String relString = rel.string(); - relString.replace('\n', ' '); - Vector<String> list; - relString.split(' ', list); - Vector<String>::const_iterator end = list.end(); - for (Vector<String>::const_iterator it = list.begin(); it != end; ++it) { - if (equalIgnoringCase(*it, "stylesheet")) - styleSheet = true; - else if (equalIgnoringCase(*it, "alternate")) - alternate = true; - else if (equalIgnoringCase(*it, "icon")) - icon = true; - } - } -} - -void HTMLLinkElement::process() -{ - if (!inDocument()) - return; - - String type = m_type.lower(); - - // IE extension: location of small icon for locationbar / bookmarks - // We'll record this URL per document, even if we later only use it in top level frames - if (m_isIcon && !m_url.isEmpty()) - document()->setIconURL(m_url, type); - - if (m_isDNSPrefetch && !m_url.isEmpty()) - prefetchDNS(KURL(m_url).host()); - - // Stylesheet - // This was buggy and would incorrectly match <link rel="alternate">, which has a different specified meaning. -dwh - if (m_disabledState != 2 && m_isStyleSheet && document()->frame()) { - // no need to load style sheets which aren't for the screen output - // ### there may be in some situations e.g. for an editor or script to manipulate - // also, don't load style sheets for standalone documents - MediaQueryEvaluator allEval(true); - MediaQueryEvaluator screenEval("screen", true); - MediaQueryEvaluator printEval("print", true); - RefPtr<MediaList> media = MediaList::createAllowingDescriptionSyntax(m_media); - if (allEval.eval(media.get()) || screenEval.eval(media.get()) || printEval.eval(media.get())) { - - // Add ourselves as a pending sheet, but only if we aren't an alternate - // stylesheet. Alternate stylesheets don't hold up render tree construction. - if (!isAlternate()) - document()->addPendingSheet(); - - String chset = getAttribute(charsetAttr); - if (chset.isEmpty() && document()->frame()) - chset = document()->frame()->loader()->encoding(); - - if (m_cachedSheet) { - if (m_loading) - document()->removePendingSheet(); - m_cachedSheet->removeClient(this); - } - m_loading = true; - m_cachedSheet = document()->docLoader()->requestCSSStyleSheet(m_url, chset); - if (m_cachedSheet) - m_cachedSheet->addClient(this); - else if (!isAlternate()) { // request may have been denied if stylesheet is local and document is remote. - m_loading = false; - document()->removePendingSheet(); - } - } - } else if (m_sheet) { - // we no longer contain a stylesheet, e.g. perhaps rel or type was changed - m_sheet = 0; - document()->updateStyleSelector(); - } -} - -void HTMLLinkElement::insertedIntoDocument() -{ - HTMLElement::insertedIntoDocument(); - document()->addStyleSheetCandidateNode(this, m_createdByParser); - process(); -} - -void HTMLLinkElement::removedFromDocument() -{ - HTMLElement::removedFromDocument(); - - // FIXME: It's terrible to do a synchronous update of the style selector just because a <style> or <link> element got removed. - if (document()->renderer()) { - document()->removeStyleSheetCandidateNode(this); - document()->updateStyleSelector(); - } -} - -void HTMLLinkElement::finishParsingChildren() -{ - m_createdByParser = false; - HTMLElement::finishParsingChildren(); -} - -void HTMLLinkElement::setCSSStyleSheet(const String& url, const String& charset, const CachedCSSStyleSheet* sheet) -{ - m_sheet = CSSStyleSheet::create(this, url, charset); - - bool strictParsing = !document()->inCompatMode(); - bool enforceMIMEType = strictParsing; - - // Check to see if we should enforce the MIME type of the CSS resource in strict mode. - // Running in iWeb 2 is one example of where we don't want to - <rdar://problem/6099748> - if (enforceMIMEType && document()->page() && !document()->page()->settings()->enforceCSSMIMETypeInStrictMode()) - enforceMIMEType = false; - - m_sheet->parseString(sheet->sheetText(enforceMIMEType), strictParsing); - m_sheet->setTitle(title()); - - RefPtr<MediaList> media = MediaList::createAllowingDescriptionSyntax(m_media); - m_sheet->setMedia(media.get()); - - m_loading = false; - m_sheet->checkLoaded(); -} - -bool HTMLLinkElement::isLoading() const -{ - if (m_loading) - return true; - if (!m_sheet) - return false; - return static_cast<CSSStyleSheet *>(m_sheet.get())->isLoading(); -} - -bool HTMLLinkElement::sheetLoaded() -{ - if (!isLoading() && !isDisabled() && !isAlternate()) { - document()->removePendingSheet(); - return true; - } - return false; -} - -bool HTMLLinkElement::isURLAttribute(Attribute *attr) const -{ - return attr->name() == hrefAttr; -} - -bool HTMLLinkElement::disabled() const -{ - return !getAttribute(disabledAttr).isNull(); -} - -void HTMLLinkElement::setDisabled(bool disabled) -{ - setAttribute(disabledAttr, disabled ? "" : 0); -} - -String HTMLLinkElement::charset() const -{ - return getAttribute(charsetAttr); -} - -void HTMLLinkElement::setCharset(const String& value) -{ - setAttribute(charsetAttr, value); -} - -KURL HTMLLinkElement::href() const -{ - return document()->completeURL(getAttribute(hrefAttr)); -} - -void HTMLLinkElement::setHref(const String& value) -{ - setAttribute(hrefAttr, value); -} - -String HTMLLinkElement::hreflang() const -{ - return getAttribute(hreflangAttr); -} - -void HTMLLinkElement::setHreflang(const String& value) -{ - setAttribute(hreflangAttr, value); -} - -String HTMLLinkElement::media() const -{ - return getAttribute(mediaAttr); -} - -void HTMLLinkElement::setMedia(const String& value) -{ - setAttribute(mediaAttr, value); -} - -String HTMLLinkElement::rel() const -{ - return getAttribute(relAttr); -} - -void HTMLLinkElement::setRel(const String& value) -{ - setAttribute(relAttr, value); -} - -String HTMLLinkElement::rev() const -{ - return getAttribute(revAttr); -} - -void HTMLLinkElement::setRev(const String& value) -{ - setAttribute(revAttr, value); -} - -String HTMLLinkElement::target() const -{ - return getAttribute(targetAttr); -} - -void HTMLLinkElement::setTarget(const String& value) -{ - setAttribute(targetAttr, value); -} - -String HTMLLinkElement::type() const -{ - return getAttribute(typeAttr); -} - -void HTMLLinkElement::setType(const String& value) -{ - setAttribute(typeAttr, value); -} - -void HTMLLinkElement::getSubresourceAttributeStrings(Vector<String>& urls) const -{ - if (m_isIcon) { - urls.append(href().string()); - return; - } - - if (!m_isStyleSheet) - return; - - // Append the URL of this link element. - urls.append(href().string()); - - // Walk the URLs linked by the linked-to stylesheet. - HashSet<String> styleURLs; - StyleSheet* styleSheet = const_cast<HTMLLinkElement*>(this)->sheet(); - if (styleSheet) - styleSheet->addSubresourceURLStrings(styleURLs, href()); - - HashSet<String>::iterator end = styleURLs.end(); - for (HashSet<String>::iterator i = styleURLs.begin(); i != end; ++i) - urls.append(*i); -} - -} diff --git a/webkit/pending/HTMLLinkElement.h b/webkit/pending/HTMLLinkElement.h deleted file mode 100644 index 9e58c18..0000000 --- a/webkit/pending/HTMLLinkElement.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2008 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef HTMLLinkElement_h -#define HTMLLinkElement_h - -#include "CSSStyleSheet.h" -#include "CachedResourceClient.h" -#include "HTMLElement.h" - -namespace WebCore { - -class CachedCSSStyleSheet; -class KURL; - -class HTMLLinkElement : public HTMLElement, public CachedResourceClient { -public: - HTMLLinkElement(Document*); - ~HTMLLinkElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } - - bool disabled() const; - void setDisabled(bool); - - String charset() const; - void setCharset(const String&); - - KURL href() const; - void setHref(const String&); - - String hreflang() const; - void setHreflang(const String&); - - String media() const; - void setMedia(const String&); - - String rel() const; - void setRel(const String&); - - String rev() const; - void setRev(const String&); - - virtual String target() const; - void setTarget(const String&); - - String type() const; - void setType(const String&); - - StyleSheet* sheet() const; - - // overload from HTMLElement - virtual void parseMappedAttribute(MappedAttribute*); - - void process(); - - virtual void insertedIntoDocument(); - virtual void removedFromDocument(); - - // from CachedResourceClient - virtual void setCSSStyleSheet(const String &url, const String& charset, const CachedCSSStyleSheet* sheet); - bool isLoading() const; - virtual bool sheetLoaded(); - - bool isAlternate() const { return m_disabledState == 0 && m_alternate; } - bool isDisabled() const { return m_disabledState == 2; } - bool isEnabledViaScript() const { return m_disabledState == 1; } - bool isIcon() const { return m_isIcon; } - - int disabledState() { return m_disabledState; } - void setDisabledState(bool _disabled); - - virtual bool isURLAttribute(Attribute*) const; - - static void tokenizeRelAttribute(const AtomicString& value, bool& stylesheet, bool& alternate, bool& icon); - - virtual void getSubresourceAttributeStrings(Vector<String>&) const; - - void setCreatedByParser(bool createdByParser) { m_createdByParser = createdByParser; } - virtual void finishParsingChildren(); - -protected: - CachedCSSStyleSheet* m_cachedSheet; - RefPtr<CSSStyleSheet> m_sheet; - String m_url; - String m_type; - String m_media; - int m_disabledState; // 0=unset(default), 1=enabled via script, 2=disabled - bool m_loading; - bool m_alternate; - bool m_isStyleSheet; - bool m_isIcon; - bool m_isDNSPrefetch; - bool m_createdByParser; -}; - -} //namespace - -#endif diff --git a/webkit/pending/Image.h b/webkit/pending/Image.h deleted file mode 100644 index 82611f6..0000000 --- a/webkit/pending/Image.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef Image_h -#define Image_h - -#include "Color.h" -#include "GraphicsTypes.h" -#include "ImageSource.h" -#include <wtf/RefPtr.h> -#include <wtf/PassRefPtr.h> -#include "SharedBuffer.h" - -#if PLATFORM(MAC) -#ifdef __OBJC__ -@class NSImage; -#else -class NSImage; -#endif -#endif - -#if PLATFORM(CG) -struct CGContext; -#endif - -#if PLATFORM(WIN) -typedef struct tagSIZE SIZE; -typedef SIZE* LPSIZE; -typedef struct HBITMAP__ *HBITMAP; -#endif - -#if PLATFORM(SKIA) -class NativeImageSkia; -#endif - -#if PLATFORM(QT) -#include <QPixmap> -#endif - -namespace WebCore { - -class AffineTransform; -class FloatPoint; -class FloatRect; -class FloatSize; -class GraphicsContext; -class IntRect; -class IntSize; -class SharedBuffer; -class String; - -// This class gets notified when an image creates or destroys decoded frames and when it advances animation frames. -class ImageObserver; - -class Image : public RefCounted<Image> { - friend class GeneratedImage; - friend class GraphicsContext; -public: - virtual ~Image(); - - static PassRefPtr<Image> create(ImageObserver* = 0); - static PassRefPtr<Image> loadPlatformResource(const char* name); - static bool supportsType(const String&); - - virtual bool isBitmapImage() const { return false; } - - // Derived classes should override this if they can assure that - // the image contains only resources from its own security origin. - virtual bool hasSingleSecurityOrigin() const { return false; } - - static Image* nullImage(); - bool isNull() const; - - // These are only used for SVGImage right now - virtual void setContainerSize(const IntSize&) { } - virtual bool usesContainerSize() const { return false; } - virtual bool hasRelativeWidth() const { return false; } - virtual bool hasRelativeHeight() const { return false; } - - virtual IntSize size() const = 0; - IntRect rect() const; - int width() const; - int height() const; - - bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived); - virtual bool dataChanged(bool allDataReceived) { return false; } - - virtual void destroyDecodedData(bool incremental = false) = 0; - virtual unsigned decodedSize() const = 0; - - SharedBuffer* data() { return m_data.get(); } - - // It may look unusual that there is no start animation call as public API. This is because - // we start and stop animating lazily. Animation begins whenever someone draws the image. It will - // automatically pause once all observers no longer want to render the image anywhere. - virtual void stopAnimation() {} - virtual void resetAnimation() {} - - // Typically the CachedImage that owns us. - ImageObserver* imageObserver() const { return m_imageObserver; } - - enum TileRule { StretchTile, RoundTile, RepeatTile }; - - virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; } - -#if PLATFORM(MAC) - // Accessors for native image formats. - virtual NSImage* getNSImage() { return 0; } - virtual CFDataRef getTIFFRepresentation() { return 0; } -#endif - -#if PLATFORM(CG) - virtual CGImageRef getCGImageRef() { return 0; } -#endif - -#if PLATFORM(WIN) - virtual bool getHBITMAP(HBITMAP) { return false; } - virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE) { return false; } -#endif - -protected: - Image(ImageObserver* = 0); - - static void fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, CompositeOperator op); - -#if PLATFORM(WIN) - virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, CompositeOperator) { } -#endif - virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator) = 0; - void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, CompositeOperator); - void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator); - - // Supporting tiled drawing - virtual bool mayFillWithSolidColor() const { return false; } - virtual Color solidColor() const { return Color(); } - - virtual void startAnimation() { } - - virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform, - const FloatPoint& phase, CompositeOperator, const FloatRect& destRect); -#if PLATFORM(CG) - // These are private to CG. Ideally they would be only in the .cpp file, but the callback requires access - // to the private function nativeImageForCurrentFrame() - static void drawPatternCallback(void* info, CGContext*); -#endif - -protected: - RefPtr<SharedBuffer> m_data; // The encoded raw data for the image. - ImageObserver* m_imageObserver; -}; - -} - -#endif diff --git a/webkit/pending/String.cpp b/webkit/pending/String.cpp deleted file mode 100644 index fe079cd..0000000 --- a/webkit/pending/String.cpp +++ /dev/null @@ -1,845 +0,0 @@ -/* - * (C) 1999 Lars Knoll (knoll@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "PlatformString.h" - -#include "CString.h" -#include "FloatConversion.h" -#include "StringBuffer.h" -#include "TextEncoding.h" -#include <kjs/dtoa.h> -#include <limits> -#include <stdarg.h> -#include <wtf/ASCIICType.h> -#include <wtf/StringExtras.h> -#include <wtf/Vector.h> -#include <wtf/unicode/Unicode.h> -#include <wtf/unicode/UTF8.h> - -#if USE(JSC) -using KJS::Identifier; -using KJS::UString; -#endif - -using namespace WTF; -using namespace WTF::Unicode; - -namespace WebCore { - -String::String(const UChar* str, unsigned len) -{ - if (!str) - return; - m_impl = StringImpl::create(str, len); -} - -String::String(const UChar* str) -{ - if (!str) - return; - - int len = 0; - while (str[len] != UChar(0)) - len++; - - m_impl = StringImpl::create(str, len); -} - -String::String(const char* str) -{ - if (!str) - return; - m_impl = StringImpl::create(str); -} - -String::String(const char* str, unsigned length) -{ - if (!str) - return; - m_impl = StringImpl::create(str, length); -} - -void String::append(const String& str) -{ - // FIXME: This is extremely inefficient. So much so that we might want to take this - // out of String's API. We can make it better by optimizing the case where exactly - // one String is pointing at this StringImpl, but even then it's going to require a - // call to fastMalloc every single time. - if (str.m_impl) { - if (m_impl) { - StringBuffer buffer(m_impl->length() + str.length()); - memcpy(buffer.characters(), m_impl->characters(), m_impl->length() * sizeof(UChar)); - memcpy(buffer.characters() + m_impl->length(), str.characters(), str.length() * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); - } else - m_impl = str.m_impl; - } -} - -void String::append(char c) -{ - // FIXME: This is extremely inefficient. So much so that we might want to take this - // out of String's API. We can make it better by optimizing the case where exactly - // one String is pointing at this StringImpl, but even then it's going to require a - // call to fastMalloc every single time. - if (m_impl) { - StringBuffer buffer(m_impl->length() + 1); - memcpy(buffer.characters(), m_impl->characters(), m_impl->length() * sizeof(UChar)); - buffer[m_impl->length()] = c; - m_impl = StringImpl::adopt(buffer); - } else - m_impl = StringImpl::create(&c, 1); -} - -void String::append(UChar c) -{ - // FIXME: This is extremely inefficient. So much so that we might want to take this - // out of String's API. We can make it better by optimizing the case where exactly - // one String is pointing at this StringImpl, but even then it's going to require a - // call to fastMalloc every single time. - if (m_impl) { - StringBuffer buffer(m_impl->length() + 1); - memcpy(buffer.characters(), m_impl->characters(), m_impl->length() * sizeof(UChar)); - buffer[m_impl->length()] = c; - m_impl = StringImpl::adopt(buffer); - } else - m_impl = StringImpl::create(&c, 1); -} - -String operator+(const String& a, const String& b) -{ - if (a.isEmpty()) - return b; - if (b.isEmpty()) - return a; - String c = a; - c += b; - return c; -} - -String operator+(const String& s, const char* cs) -{ - return s + String(cs); -} - -String operator+(const char* cs, const String& s) -{ - return String(cs) + s; -} - -void String::insert(const String& str, unsigned pos) -{ - if (str.isEmpty()) { - if (str.isNull()) - return; - if (isNull()) - m_impl = str.impl(); - return; - } - insert(str.characters(), str.length(), pos); -} - -void String::append(const UChar* charactersToAppend, unsigned lengthToAppend) -{ - if (!m_impl) { - if (!charactersToAppend) - return; - m_impl = StringImpl::create(charactersToAppend, lengthToAppend); - return; - } - - if (!lengthToAppend) - return; - - ASSERT(charactersToAppend); - StringBuffer buffer(length() + lengthToAppend); - memcpy(buffer.characters(), characters(), length() * sizeof(UChar)); - memcpy(buffer.characters() + length(), charactersToAppend, lengthToAppend * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); -} - -void String::insert(const UChar* charactersToInsert, unsigned lengthToInsert, unsigned position) -{ - if (position >= length()) { - append(charactersToInsert, lengthToInsert); - return; - } - - ASSERT(m_impl); - - if (!lengthToInsert) - return; - - ASSERT(charactersToInsert); - StringBuffer buffer(length() + lengthToInsert); - memcpy(buffer.characters(), characters(), position * sizeof(UChar)); - memcpy(buffer.characters() + position, charactersToInsert, lengthToInsert * sizeof(UChar)); - memcpy(buffer.characters() + position + lengthToInsert, characters() + position, (length() - position) * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); -} - -UChar String::operator[](unsigned i) const -{ - if (!m_impl || i >= m_impl->length()) - return 0; - return m_impl->characters()[i]; -} - -UChar32 String::characterStartingAt(unsigned i) const -{ - if (!m_impl || i >= m_impl->length()) - return 0; - return m_impl->characterStartingAt(i); -} - -unsigned String::length() const -{ - if (!m_impl) - return 0; - return m_impl->length(); -} - -void String::truncate(unsigned position) -{ - if (position >= length()) - return; - StringBuffer buffer(position); - memcpy(buffer.characters(), characters(), position * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); -} - -void String::remove(unsigned position, int lengthToRemove) -{ - if (lengthToRemove <= 0) - return; - if (position >= length()) - return; - if (static_cast<unsigned>(lengthToRemove) > length() - position) - lengthToRemove = length() - position; - StringBuffer buffer(length() - lengthToRemove); - memcpy(buffer.characters(), characters(), position * sizeof(UChar)); - memcpy(buffer.characters() + position, characters() + position + lengthToRemove, - (length() - lengthToRemove - position) * sizeof(UChar)); - m_impl = StringImpl::adopt(buffer); -} - -String String::substring(unsigned pos, unsigned len) const -{ - if (!m_impl) - return String(); - return m_impl->substring(pos, len); -} - -String String::lower() const -{ - if (!m_impl) - return String(); - return m_impl->lower(); -} - -String String::upper() const -{ - if (!m_impl) - return String(); - return m_impl->upper(); -} - -String String::stripWhiteSpace() const -{ - if (!m_impl) - return String(); - return m_impl->stripWhiteSpace(); -} - -String String::simplifyWhiteSpace() const -{ - if (!m_impl) - return String(); - return m_impl->simplifyWhiteSpace(); -} - -String String::foldCase() const -{ - if (!m_impl) - return String(); - return m_impl->foldCase(); -} - -bool String::percentage(int& result) const -{ - if (!m_impl || !m_impl->length()) - return false; - - if ((*m_impl)[m_impl->length() - 1] != '%') - return false; - - result = charactersToIntStrict(m_impl->characters(), m_impl->length() - 1); - return true; -} - -const UChar* String::characters() const -{ - if (!m_impl) - return 0; - return m_impl->characters(); -} - -const UChar* String::charactersWithNullTermination() -{ - if (!m_impl) - return 0; - if (m_impl->hasTerminatingNullCharacter()) - return m_impl->characters(); - m_impl = StringImpl::createWithTerminatingNullCharacter(*m_impl); - return m_impl->characters(); -} - -String String::format(const char *format, ...) -{ -#if PLATFORM(QT) - // Use QString::vsprintf to avoid the locale dependent formatting of vsnprintf. - // https://bugs.webkit.org/show_bug.cgi?id=18994 - va_list args; - va_start(args, format); - - QString buffer; - buffer.vsprintf(format, args); - - va_end(args); - - return buffer; -#else - va_list args; - va_start(args, format); - - Vector<char, 256> buffer; - - // Do the format once to get the length. -#if COMPILER(MSVC) - int result = _vscprintf(format, args); -#else - char ch; - int result = vsnprintf(&ch, 1, format, args); - // We need to call va_end() and then va_start() again here, as the - // contents of args is undefined after the call to vsnprintf - // according to http://man.cx/snprintf(3) - // - // Not calling va_end/va_start here happens to work on lots of - // systems, but fails e.g. on 64bit Linux. - va_end(args); - va_start(args, format); -#endif - - if (result == 0) - return String(""); - if (result < 0) - return String(); - unsigned len = result; - buffer.grow(len + 1); - - // Now do the formatting again, guaranteed to fit. - vsnprintf(buffer.data(), buffer.size(), format, args); - - va_end(args); - - return StringImpl::create(buffer.data(), len); -#endif -} - -String String::number(int n) -{ - return String::format("%d", n); -} - -String String::number(unsigned n) -{ - return String::format("%u", n); -} - -String String::number(long n) -{ - return String::format("%ld", n); -} - -String String::number(unsigned long n) -{ - return String::format("%lu", n); -} - -String String::number(long long n) -{ -#if PLATFORM(WIN_OS) - return String::format("%I64i", n); -#else - return String::format("%lli", n); -#endif -} - -String String::number(unsigned long long n) -{ -#if PLATFORM(WIN_OS) - return String::format("%I64u", n); -#else - return String::format("%llu", n); -#endif -} - -String String::number(double n) -{ - return String::format("%.6lg", n); -} - -int String::toIntStrict(bool* ok, int base) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0; - } - return m_impl->toIntStrict(ok, base); -} - -unsigned String::toUIntStrict(bool* ok, int base) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0; - } - return m_impl->toUIntStrict(ok, base); -} - -int64_t String::toInt64Strict(bool* ok, int base) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0; - } - return m_impl->toInt64Strict(ok, base); -} - -uint64_t String::toUInt64Strict(bool* ok, int base) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0; - } - return m_impl->toUInt64Strict(ok, base); -} - -int String::toInt(bool* ok) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0; - } - return m_impl->toInt(ok); -} - -unsigned String::toUInt(bool* ok) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0; - } - return m_impl->toUInt(ok); -} - -int64_t String::toInt64(bool* ok) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0; - } - return m_impl->toInt64(ok); -} - -uint64_t String::toUInt64(bool* ok) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0; - } - return m_impl->toUInt64(ok); -} - -double String::toDouble(bool* ok) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0.0; - } - return m_impl->toDouble(ok); -} - -float String::toFloat(bool* ok) const -{ - if (!m_impl) { - if (ok) - *ok = false; - return 0.0f; - } - return m_impl->toFloat(ok); -} - -String String::copy() const -{ - if (!m_impl) - return String(); - return m_impl->copy(); -} - -bool String::isEmpty() const -{ - return !m_impl || !m_impl->length(); -} - -Length* String::toCoordsArray(int& len) const -{ - return m_impl ? m_impl->toCoordsArray(len) : 0; -} - -Length* String::toLengthArray(int& len) const -{ - return m_impl ? m_impl->toLengthArray(len) : 0; -} - -void String::split(const String& separator, bool allowEmptyEntries, Vector<String>& result) const -{ - result.clear(); - - int startPos = 0; - int endPos; - while ((endPos = find(separator, startPos)) != -1) { - if (allowEmptyEntries || startPos != endPos) - result.append(substring(startPos, endPos - startPos)); - startPos = endPos + separator.length(); - } - if (allowEmptyEntries || startPos != static_cast<int>(length())) - result.append(substring(startPos)); -} - -void String::split(const String& separator, Vector<String>& result) const -{ - return split(separator, false, result); -} - -void String::split(UChar separator, bool allowEmptyEntries, Vector<String>& result) const -{ - result.clear(); - - int startPos = 0; - int endPos; - while ((endPos = find(separator, startPos)) != -1) { - if (allowEmptyEntries || startPos != endPos) - result.append(substring(startPos, endPos - startPos)); - startPos = endPos + 1; - } - if (allowEmptyEntries || startPos != static_cast<int>(length())) - result.append(substring(startPos)); -} - -void String::split(UChar separator, Vector<String>& result) const -{ - return split(String(&separator, 1), false, result); -} - -#ifndef NDEBUG -Vector<char> String::ascii() const -{ - if (m_impl) - return m_impl->ascii(); - - const char* nullMsg = "(null impl)"; - Vector<char, 2048> buffer; - for (int i = 0; nullMsg[i]; ++i) - buffer.append(nullMsg[i]); - - buffer.append('\0'); - return buffer; -} -#endif - -CString String::latin1() const -{ - return Latin1Encoding().encode(characters(), length(), QuestionMarksForUnencodables); -} - -CString String::utf8() const -{ - return UTF8Encoding().encode(characters(), length(), QuestionMarksForUnencodables); -} - -String String::fromUTF8(const char* string, size_t size) -{ - if (!string) - return String(); - return UTF8Encoding().decode(string, size); -} - -String String::fromUTF8(const char* string) -{ - if (!string) - return String(); - return UTF8Encoding().decode(string, strlen(string)); -} - -#if USE(JSC) -String::String(const Identifier& str) -{ - if (str.isNull()) - return; - m_impl = StringImpl::create(str.data(), str.size()); -} - -String::String(const UString& str) -{ - if (str.isNull()) - return; - m_impl = StringImpl::create(str.data(), str.size()); -} - -String::operator UString() const -{ - if (!m_impl) - return UString(); - return UString(m_impl->characters(), m_impl->length()); -} -#endif - -// String Operations - -static bool isCharacterAllowedInBase(UChar c, int base) -{ - if (c > 0x7F) - return false; - if (isASCIIDigit(c)) - return c - '0' < base; - if (isASCIIAlpha(c)) { - if (base > 36) - base = 36; - return (c >= 'a' && c < 'a' + base - 10) - || (c >= 'A' && c < 'A' + base - 10); - } - return false; -} - -template <typename IntegralType> -static inline IntegralType toIntegralType(const UChar* data, size_t length, bool* ok, int base) -{ - static const IntegralType integralMax = std::numeric_limits<IntegralType>::max(); - static const bool isSigned = std::numeric_limits<IntegralType>::is_signed; - const IntegralType maxMultiplier = integralMax / base; - - IntegralType value = 0; - bool isOk = false; - bool isNegative = false; - - if (!data) - goto bye; - - // skip leading whitespace - while (length && isSpaceOrNewline(*data)) { - length--; - data++; - } - - if (isSigned && length && *data == '-') { - length--; - data++; - isNegative = true; - } else if (length && *data == '+') { - length--; - data++; - } - - if (!length || !isCharacterAllowedInBase(*data, base)) - goto bye; - - while (length && isCharacterAllowedInBase(*data, base)) { - length--; - IntegralType digitValue; - UChar c = *data; - if (isASCIIDigit(c)) - digitValue = c - '0'; - else if (c >= 'a') - digitValue = c - 'a' + 10; - else - digitValue = c - 'A' + 10; - - if (value > maxMultiplier || (value == maxMultiplier && digitValue > (integralMax % base) + isNegative)) - goto bye; - - value = base * value + digitValue; - data++; - } - -#if COMPILER(MSVC) -#pragma warning(push, 0) -#pragma warning(disable:4146) -#endif - - if (isNegative) - value = -value; - -#if COMPILER(MSVC) -#pragma warning(pop) -#endif - - // skip trailing space - while (length && isSpaceOrNewline(*data)) { - length--; - data++; - } - - if (!length) - isOk = true; -bye: - if (ok) - *ok = isOk; - return isOk ? value : 0; -} - -static unsigned lengthOfCharactersAsInteger(const UChar* data, size_t length) -{ - size_t i = 0; - - // Allow leading spaces. - for (; i != length; ++i) { - if (!isSpaceOrNewline(data[i])) - break; - } - - // Allow sign. - if (i != length && (data[i] == '+' || data[i] == '-')) - ++i; - - // Allow digits. - for (; i != length; ++i) { - if (!Unicode::isDigit(data[i])) - break; - } - - return i; -} - -int charactersToIntStrict(const UChar* data, size_t length, bool* ok, int base) -{ - return toIntegralType<int>(data, length, ok, base); -} - -unsigned charactersToUIntStrict(const UChar* data, size_t length, bool* ok, int base) -{ - return toIntegralType<unsigned>(data, length, ok, base); -} - -int64_t charactersToInt64Strict(const UChar* data, size_t length, bool* ok, int base) -{ - return toIntegralType<int64_t>(data, length, ok, base); -} - -uint64_t charactersToUInt64Strict(const UChar* data, size_t length, bool* ok, int base) -{ - return toIntegralType<uint64_t>(data, length, ok, base); -} - -int charactersToInt(const UChar* data, size_t length, bool* ok) -{ - return toIntegralType<int>(data, lengthOfCharactersAsInteger(data, length), ok, 10); -} - -unsigned charactersToUInt(const UChar* data, size_t length, bool* ok) -{ - return toIntegralType<unsigned>(data, lengthOfCharactersAsInteger(data, length), ok, 10); -} - -int64_t charactersToInt64(const UChar* data, size_t length, bool* ok) -{ - return toIntegralType<int64_t>(data, lengthOfCharactersAsInteger(data, length), ok, 10); -} - -uint64_t charactersToUInt64(const UChar* data, size_t length, bool* ok) -{ - return toIntegralType<uint64_t>(data, lengthOfCharactersAsInteger(data, length), ok, 10); -} - -double charactersToDouble(const UChar* data, size_t length, bool* ok) -{ - if (!length) { - if (ok) - *ok = false; - return 0.0; - } - - Vector<char, 256> bytes(length + 1); - for (unsigned i = 0; i < length; ++i) - bytes[i] = data[i] < 0x7F ? data[i] : '?'; - bytes[length] = '\0'; - char* end; -#if USE(JSC) - double val = KJS::strtod(bytes.data(), &end); -#elif USE(V8) - double val = strtod(bytes.data(), &end); -#endif - if (ok) - *ok = (end == 0 || *end == '\0'); - return val; -} - -float charactersToFloat(const UChar* data, size_t length, bool* ok) -{ - // FIXME: This will return ok even when the string fits into a double but not a float. - return narrowPrecisionToFloat(charactersToDouble(data, length, ok)); -} - -PassRefPtr<SharedBuffer> utf8Buffer(const String& string) -{ - // Allocate a buffer big enough to hold all the characters. - const int length = string.length(); - Vector<char> buffer(length * 3); - - // Convert to runs of 8-bit characters. - char* p = buffer.data(); - const UChar* d = string.characters(); - ConversionResult result = convertUTF16ToUTF8(&d, d + length, &p, p + buffer.size(), true); - if (result != conversionOK) - return 0; - - buffer.shrink(p - buffer.data()); - return SharedBuffer::adoptVector(buffer); -} - -} // namespace WebCore - -#ifndef NDEBUG -// For debugging only -- leaks memory -WebCore::String* string(const char* s) -{ - return new WebCore::String(s); -} -#endif diff --git a/webkit/pending/StringImpl.cpp b/webkit/pending/StringImpl.cpp deleted file mode 100644 index 83fb984..0000000 --- a/webkit/pending/StringImpl.cpp +++ /dev/null @@ -1,1051 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * (C) 1999 Antti Koivisto (koivisto@kde.org) - * (C) 2001 Dirk Mueller ( mueller@kde.org ) - * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. - * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" -#include "StringImpl.h" - -#include "AtomicString.h" -#include "CString.h" -#include "CharacterNames.h" -#include "FloatConversion.h" -#include "Length.h" -#include "StringBuffer.h" -#include "StringHash.h" -#include "TextBreakIterator.h" -#include "TextEncoding.h" -#include <kjs/dtoa.h> -#include <kjs/identifier.h> -#include <wtf/Assertions.h> -#include <wtf/unicode/Unicode.h> - -using namespace WTF; -using namespace Unicode; - -#if USE(JSC) -using KJS::Identifier; -using KJS::UString; -#endif - -namespace WebCore { - -static inline UChar* newUCharVector(unsigned n) -{ - return static_cast<UChar*>(fastMalloc(sizeof(UChar) * n)); -} - -static inline void deleteUCharVector(const UChar* p) -{ - fastFree(const_cast<UChar*>(p)); -} - -// This constructor is used only to create the empty string. -StringImpl::StringImpl() - : m_length(0) - , m_data(0) - , m_hash(0) - , m_inTable(false) - , m_hasTerminatingNullCharacter(false) -{ -} - -// This is one of the most common constructors, but it's also used for the copy() -// operation. Because of that, it's the one constructor that doesn't assert the -// length is non-zero, since we support copying the empty string. -inline StringImpl::StringImpl(const UChar* characters, unsigned length) - : m_length(length) - , m_hash(0) - , m_inTable(false) - , m_hasTerminatingNullCharacter(false) -{ - UChar* data = newUCharVector(length); - memcpy(data, characters, length * sizeof(UChar)); - m_data = data; -} - -inline StringImpl::StringImpl(const StringImpl& str, WithTerminatingNullCharacter) - : m_length(str.m_length) - , m_hash(str.m_hash) - , m_inTable(false) - , m_hasTerminatingNullCharacter(true) -{ - UChar* data = newUCharVector(str.m_length + 1); - memcpy(data, str.m_data, str.m_length * sizeof(UChar)); - data[str.m_length] = 0; - m_data = data; -} - -inline StringImpl::StringImpl(const char* characters, unsigned length) - : m_length(length) - , m_hash(0) - , m_inTable(false) - , m_hasTerminatingNullCharacter(false) -{ - ASSERT(characters); - ASSERT(length); - - UChar* data = newUCharVector(length); - for (unsigned i = 0; i != length; ++i) { - unsigned char c = characters[i]; - data[i] = c; - } - m_data = data; -} - -inline StringImpl::StringImpl(UChar* characters, unsigned length, AdoptBuffer) - : m_length(length) - , m_data(characters) - , m_hash(0) - , m_inTable(false) - , m_hasTerminatingNullCharacter(false) -{ - ASSERT(characters); - ASSERT(length); -} - -// This constructor is only for use by AtomicString. -StringImpl::StringImpl(const UChar* characters, unsigned length, unsigned hash) - : m_length(length) - , m_hash(hash) - , m_inTable(true) - , m_hasTerminatingNullCharacter(false) -{ - ASSERT(hash); - ASSERT(characters); - ASSERT(length); - - UChar* data = newUCharVector(length); - memcpy(data, characters, length * sizeof(UChar)); - m_data = data; -} - -// This constructor is only for use by AtomicString. -StringImpl::StringImpl(const char* characters, unsigned length, unsigned hash) - : m_length(length) - , m_hash(hash) - , m_inTable(true) - , m_hasTerminatingNullCharacter(false) -{ - ASSERT(hash); - ASSERT(characters); - ASSERT(length); - - UChar* data = newUCharVector(length); - for (unsigned i = 0; i != length; ++i) { - unsigned char c = characters[i]; - data[i] = c; - } - m_data = data; -} - -StringImpl::~StringImpl() -{ - if (m_inTable) - AtomicString::remove(this); - deleteUCharVector(m_data); -} - -StringImpl* StringImpl::empty() -{ - static StringImpl* e = new StringImpl; - return e; -} - -bool StringImpl::containsOnlyWhitespace() -{ - // FIXME: The definition of whitespace here includes a number of characters - // that are not whitespace from the point of view of RenderText; I wonder if - // that's a problem in practice. - for (unsigned i = 0; i < m_length; i++) - if (!isASCIISpace(m_data[i])) - return false; - return true; -} - -PassRefPtr<StringImpl> StringImpl::substring(unsigned pos, unsigned len) -{ - if (pos >= m_length) - return empty(); - if (len > m_length - pos) - len = m_length - pos; - return create(m_data + pos, len); -} - -UChar32 StringImpl::characterStartingAt(unsigned i) -{ - if (U16_IS_SINGLE(m_data[i])) - return m_data[i]; - if (i + 1 < m_length && U16_IS_LEAD(m_data[i]) && U16_IS_TRAIL(m_data[i + 1])) - return U16_GET_SUPPLEMENTARY(m_data[i], m_data[i + 1]); - return 0; -} - -static Length parseLength(const UChar* data, unsigned length) -{ - if (length == 0) - return Length(1, Relative); - - unsigned i = 0; - while (i < length && isSpaceOrNewline(data[i])) - ++i; - if (i < length && (data[i] == '+' || data[i] == '-')) - ++i; - while (i < length && Unicode::isDigit(data[i])) - ++i; - - bool ok; - int r = charactersToIntStrict(data, i, &ok); - - /* Skip over any remaining digits, we are not that accurate (5.5% => 5%) */ - while (i < length && (Unicode::isDigit(data[i]) || data[i] == '.')) - ++i; - - /* IE Quirk: Skip any whitespace (20 % => 20%) */ - while (i < length && isSpaceOrNewline(data[i])) - ++i; - - if (ok) { - if (i < length) { - UChar next = data[i]; - if (next == '%') - return Length(static_cast<double>(r), Percent); - if (next == '*') - return Length(r, Relative); - } - return Length(r, Fixed); - } else { - if (i < length) { - UChar next = data[i]; - if (next == '*') - return Length(1, Relative); - if (next == '%') - return Length(1, Relative); - } - } - return Length(0, Relative); -} - -Length StringImpl::toLength() -{ - return parseLength(m_data, m_length); -} - -static int countCharacter(StringImpl* string, UChar character) -{ - int count = 0; - int length = string->length(); - for (int i = 0; i < length; ++i) - count += (*string)[i] == character; - return count; -} - -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; -} - -Length* StringImpl::toLengthArray(int& len) -{ - RefPtr<StringImpl> str = simplifyWhiteSpace(); - if (!str->length()) { - len = 1; - return 0; - } - - 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; - } - - ASSERT(i == len - 1); - - /* IE Quirk: If the last comma is the last char skip it and reduce len by one */ - if (str->length()-pos > 0) - r[i] = parseLength(str->characters() + pos, str->length() - pos); - else - len--; - - return r; -} - -bool StringImpl::isLower() -{ - // Do a faster loop for the case where all the characters are ASCII. - bool allLower = true; - UChar ored = 0; - for (unsigned i = 0; i < m_length; i++) { - UChar c = m_data[i]; - allLower = allLower && isASCIILower(c); - ored |= c; - } - if (!(ored & ~0x7F)) - return allLower; - - // Do a slower check for cases that include non-ASCII characters. - allLower = true; - unsigned i = 0; - while (i < m_length) { - UChar32 character; - U16_NEXT(m_data, i, m_length, character) - allLower = allLower && Unicode::isLower(character); - } - return allLower; -} - -PassRefPtr<StringImpl> StringImpl::lower() -{ - StringBuffer data(m_length); - int32_t length = m_length; - - // Do a faster loop for the case where all the characters are ASCII. - UChar ored = 0; - for (int i = 0; i < length; i++) { - UChar c = m_data[i]; - ored |= c; - data[i] = toASCIILower(c); - } - if (!(ored & ~0x7F)) - return adopt(data); - - // Do a slower implementation for cases that include non-ASCII characters. - bool error; - int32_t realLength = Unicode::toLower(data.characters(), length, m_data, m_length, &error); - if (!error && realLength == length) - return adopt(data); - data.resize(realLength); - Unicode::toLower(data.characters(), realLength, m_data, m_length, &error); - if (error) - return this; - return adopt(data); -} - -PassRefPtr<StringImpl> StringImpl::upper() -{ - bool error; - int32_t length = Unicode::toUpper(0, 0, m_data, m_length, &error); - StringBuffer data(length); - Unicode::toUpper(data.characters(), length, m_data, m_length, &error); - if (error) - return this; - return adopt(data); -} - -PassRefPtr<StringImpl> StringImpl::secure(UChar aChar) -{ - int length = m_length; - StringBuffer data(length); - for (int i = 0; i < length; ++i) - data[i] = aChar; - return adopt(data); -} - -PassRefPtr<StringImpl> StringImpl::foldCase() -{ - StringBuffer data(m_length); - int32_t length = m_length; - - // Do a faster loop for the case where all the characters are ASCII. - UChar ored = 0; - for (int i = 0; i < length; i++) { - UChar c = m_data[i]; - ored |= c; - data[i] = toASCIILower(c); - } - if (!(ored & ~0x7F)) - return adopt(data); - - // Do a slower implementation for cases that include non-ASCII characters. - bool error; - int32_t realLength = Unicode::foldCase(data.characters(), length, m_data, m_length, &error); - if (!error && realLength == length) - return adopt(data); - data.resize(realLength); - Unicode::foldCase(data.characters(), realLength, m_data, m_length, &error); - if (error) - return this; - return adopt(data); -} - -PassRefPtr<StringImpl> StringImpl::stripWhiteSpace() -{ - if (!m_length) - return empty(); - - unsigned start = 0; - unsigned end = m_length - 1; - - // skip white space from start - while (start <= end && isSpaceOrNewline(m_data[start])) - start++; - - // only white space - if (start > end) - return empty(); - - // skip white space from end - while (end && isSpaceOrNewline(m_data[end])) - end--; - - return create(m_data + start, end + 1 - start); -} - -PassRefPtr<StringImpl> StringImpl::simplifyWhiteSpace() -{ - StringBuffer data(m_length); - - const UChar* from = m_data; - const UChar* fromend = from + m_length; - int outc = 0; - - UChar* to = data.characters(); - - while (true) { - while (from != fromend && isSpaceOrNewline(*from)) - from++; - while (from != fromend && !isSpaceOrNewline(*from)) - to[outc++] = *from++; - if (from != fromend) - to[outc++] = ' '; - else - break; - } - - if (outc > 0 && to[outc - 1] == ' ') - outc--; - - data.shrink(outc); - - return adopt(data); -} - -PassRefPtr<StringImpl> StringImpl::capitalize(UChar previous) -{ - StringBuffer stringWithPrevious(m_length + 1); - stringWithPrevious[0] = previous == noBreakSpace ? ' ' : previous; - for (unsigned i = 1; i < m_length + 1; i++) { - // Replace   with a real space since ICU no longer treats   as a word separator. - if (m_data[i - 1] == noBreakSpace) - stringWithPrevious[i] = ' '; - else - stringWithPrevious[i] = m_data[i - 1]; - } - - TextBreakIterator* boundary = wordBreakIterator(stringWithPrevious.characters(), m_length + 1); - if (!boundary) - return this; - - StringBuffer data(m_length); - - int32_t endOfWord; - int32_t startOfWord = textBreakFirst(boundary); - for (endOfWord = textBreakNext(boundary); endOfWord != TextBreakDone; startOfWord = endOfWord, endOfWord = textBreakNext(boundary)) { - if (startOfWord != 0) // Ignore first char of previous string - data[startOfWord - 1] = m_data[startOfWord - 1] == noBreakSpace ? noBreakSpace : toTitleCase(stringWithPrevious[startOfWord]); - for (int i = startOfWord + 1; i < endOfWord; i++) - data[i - 1] = m_data[i - 1]; - } - - return adopt(data); -} - -int StringImpl::toIntStrict(bool* ok, int base) -{ - return charactersToIntStrict(m_data, m_length, ok, base); -} - -unsigned StringImpl::toUIntStrict(bool* ok, int base) -{ - return charactersToUIntStrict(m_data, m_length, ok, base); -} - -int64_t StringImpl::toInt64Strict(bool* ok, int base) -{ - return charactersToInt64Strict(m_data, m_length, ok, base); -} - -uint64_t StringImpl::toUInt64Strict(bool* ok, int base) -{ - return charactersToUInt64Strict(m_data, m_length, ok, base); -} - -int StringImpl::toInt(bool* ok) -{ - return charactersToInt(m_data, m_length, ok); -} - -unsigned StringImpl::toUInt(bool* ok) -{ - return charactersToUInt(m_data, m_length, ok); -} - -int64_t StringImpl::toInt64(bool* ok) -{ - return charactersToInt64(m_data, m_length, ok); -} - -uint64_t StringImpl::toUInt64(bool* ok) -{ - return charactersToUInt64(m_data, m_length, ok); -} - -double StringImpl::toDouble(bool* ok) -{ - return charactersToDouble(m_data, m_length, ok); -} - -float StringImpl::toFloat(bool* ok) -{ - return charactersToFloat(m_data, m_length, ok); -} - -static bool equal(const UChar* a, const char* b, int length) -{ - ASSERT(length >= 0); - while (length--) { - unsigned char bc = *b++; - if (*a++ != bc) - return false; - } - return true; -} - -static bool equalIgnoringCase(const UChar* a, const char* b, int length) -{ - ASSERT(length >= 0); - while (length--) { - unsigned char bc = *b++; - if (foldCase(*a++) != foldCase(bc)) - return false; - } - return true; -} - -static inline bool equalIgnoringCase(const UChar* a, const UChar* b, int length) -{ - ASSERT(length >= 0); - return umemcasecmp(a, b, length) == 0; -} - -int StringImpl::find(const char* chs, int index, bool caseSensitive) -{ - if (!chs || index < 0) - return -1; - - int chsLength = strlen(chs); - int n = m_length - index; - if (n < 0) - return -1; - n -= chsLength - 1; - if (n <= 0) - return -1; - - const char* chsPlusOne = chs + 1; - int chsLengthMinusOne = chsLength - 1; - - const UChar* ptr = m_data + index - 1; - if (caseSensitive) { - UChar c = *chs; - do { - if (*++ptr == c && equal(ptr + 1, chsPlusOne, chsLengthMinusOne)) - return m_length - chsLength - n + 1; - } while (--n); - } else { - UChar lc = Unicode::foldCase(*chs); - do { - if (Unicode::foldCase(*++ptr) == lc && equalIgnoringCase(ptr + 1, chsPlusOne, chsLengthMinusOne)) - return m_length - chsLength - n + 1; - } while (--n); - } - - return -1; -} - -int StringImpl::find(UChar c, int start) -{ - return WebCore::find(m_data, m_length, c, start); -} - -int StringImpl::find(StringImpl* str, int index, bool caseSensitive) -{ - /* - We use a simple trick for efficiency's sake. Instead of - comparing strings, we compare the sum of str with that of - a part of this string. Only if that matches, we call memcmp - or ucstrnicmp. - */ - ASSERT(str); - if (index < 0) - index += m_length; - int lstr = str->m_length; - int lthis = m_length - index; - if ((unsigned)lthis > m_length) - return -1; - int delta = lthis - lstr; - if (delta < 0) - return -1; - - const UChar* uthis = m_data + index; - const UChar* ustr = str->m_data; - unsigned hthis = 0; - unsigned hstr = 0; - if (caseSensitive) { - for (int i = 0; i < lstr; i++) { - hthis += uthis[i]; - hstr += ustr[i]; - } - int i = 0; - while (1) { - if (hthis == hstr && memcmp(uthis + i, ustr, lstr * sizeof(UChar)) == 0) - return index + i; - if (i == delta) - return -1; - hthis += uthis[i + lstr]; - hthis -= uthis[i]; - i++; - } - } else { - for (int i = 0; i < lstr; i++ ) { - hthis += toASCIILower(uthis[i]); - hstr += toASCIILower(ustr[i]); - } - int i = 0; - while (1) { - if (hthis == hstr && equalIgnoringCase(uthis + i, ustr, lstr)) - return index + i; - if (i == delta) - return -1; - hthis += toASCIILower(uthis[i + lstr]); - hthis -= toASCIILower(uthis[i]); - i++; - } - } -} - -int StringImpl::reverseFind(UChar c, int index) -{ - return WebCore::reverseFind(m_data, m_length, c, index); -} - -int StringImpl::reverseFind(StringImpl* str, int index, bool caseSensitive) -{ - /* - See StringImpl::find() for explanations. - */ - ASSERT(str); - int lthis = m_length; - if (index < 0) - index += lthis; - - int lstr = str->m_length; - int delta = lthis - lstr; - if ( index < 0 || index > lthis || delta < 0 ) - return -1; - if ( index > delta ) - index = delta; - - const UChar *uthis = m_data; - const UChar *ustr = str->m_data; - unsigned hthis = 0; - unsigned hstr = 0; - int i; - if (caseSensitive) { - for ( i = 0; i < lstr; i++ ) { - hthis += uthis[index + i]; - hstr += ustr[i]; - } - i = index; - while (1) { - if (hthis == hstr && memcmp(uthis + i, ustr, lstr * sizeof(UChar)) == 0) - return i; - if (i == 0) - return -1; - i--; - hthis -= uthis[i + lstr]; - hthis += uthis[i]; - } - } else { - for (i = 0; i < lstr; i++) { - hthis += toASCIILower(uthis[index + i]); - hstr += toASCIILower(ustr[i]); - } - i = index; - while (1) { - if (hthis == hstr && equalIgnoringCase(uthis + i, ustr, lstr) ) - return i; - if (i == 0) - return -1; - i--; - hthis -= toASCIILower(uthis[i + lstr]); - hthis += toASCIILower(uthis[i]); - } - } - - // Should never get here. - return -1; -} - -bool StringImpl::endsWith(StringImpl* m_data, bool caseSensitive) -{ - ASSERT(m_data); - int start = m_length - m_data->m_length; - if (start >= 0) - return (find(m_data, start, caseSensitive) == start); - return false; -} - -PassRefPtr<StringImpl> StringImpl::replace(UChar oldC, UChar newC) -{ - if (oldC == newC) - return this; - unsigned i; - for (i = 0; i != m_length; ++i) - if (m_data[i] == oldC) - break; - if (i == m_length) - return this; - - StringBuffer data(m_length); - for (i = 0; i != m_length; ++i) { - UChar ch = m_data[i]; - if (ch == oldC) - ch = newC; - data[i] = ch; - } - return adopt(data); -} - -PassRefPtr<StringImpl> StringImpl::replace(unsigned position, unsigned lengthToReplace, StringImpl* str) -{ - position = min(position, length()); - lengthToReplace = min(lengthToReplace, length() - position); - unsigned lengthToInsert = str ? str->length() : 0; - if (!lengthToReplace && !lengthToInsert) - return this; - StringBuffer buffer(length() - lengthToReplace + lengthToInsert); - memcpy(buffer.characters(), characters(), position * sizeof(UChar)); - if (str) - memcpy(buffer.characters() + position, str->characters(), lengthToInsert * sizeof(UChar)); - memcpy(buffer.characters() + position + lengthToInsert, characters() + position + lengthToReplace, - (length() - position - lengthToReplace) * sizeof(UChar)); - return adopt(buffer); -} - -PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, StringImpl* replacement) -{ - if (!replacement) - return this; - - int repStrLength = replacement->length(); - int srcSegmentStart = 0; - int matchCount = 0; - - // Count the matches - while ((srcSegmentStart = find(pattern, srcSegmentStart)) >= 0) { - ++matchCount; - ++srcSegmentStart; - } - - // If we have 0 matches, we don't have to do any more work - if (!matchCount) - return this; - - StringBuffer data(m_length - matchCount + (matchCount * repStrLength)); - - // Construct the new data - int srcSegmentEnd; - int srcSegmentLength; - srcSegmentStart = 0; - int dstOffset = 0; - - while ((srcSegmentEnd = find(pattern, srcSegmentStart)) >= 0) { - srcSegmentLength = srcSegmentEnd - srcSegmentStart; - memcpy(data.characters() + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); - dstOffset += srcSegmentLength; - memcpy(data.characters() + dstOffset, replacement->m_data, repStrLength * sizeof(UChar)); - dstOffset += repStrLength; - srcSegmentStart = srcSegmentEnd + 1; - } - - srcSegmentLength = m_length - srcSegmentStart; - memcpy(data.characters() + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); - - ASSERT(dstOffset + srcSegmentLength == static_cast<int>(data.length())); - - return adopt(data); -} - -PassRefPtr<StringImpl> StringImpl::replace(StringImpl* pattern, StringImpl* replacement) -{ - if (!pattern || !replacement) - return this; - - int patternLength = pattern->length(); - if (!patternLength) - return this; - - int repStrLength = replacement->length(); - int srcSegmentStart = 0; - int matchCount = 0; - - // Count the matches - while ((srcSegmentStart = find(pattern, srcSegmentStart)) >= 0) { - ++matchCount; - srcSegmentStart += patternLength; - } - - // If we have 0 matches, we don't have to do any more work - if (!matchCount) - return this; - - StringBuffer data(m_length + matchCount * (repStrLength - patternLength)); - - // Construct the new data - int srcSegmentEnd; - int srcSegmentLength; - srcSegmentStart = 0; - int dstOffset = 0; - - while ((srcSegmentEnd = find(pattern, srcSegmentStart)) >= 0) { - srcSegmentLength = srcSegmentEnd - srcSegmentStart; - memcpy(data.characters() + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); - dstOffset += srcSegmentLength; - memcpy(data.characters() + dstOffset, replacement->m_data, repStrLength * sizeof(UChar)); - dstOffset += repStrLength; - srcSegmentStart = srcSegmentEnd + patternLength; - } - - srcSegmentLength = m_length - srcSegmentStart; - memcpy(data.characters() + dstOffset, m_data + srcSegmentStart, srcSegmentLength * sizeof(UChar)); - - ASSERT(dstOffset + srcSegmentLength == static_cast<int>(data.length())); - - return adopt(data); -} - -bool equal(StringImpl* a, StringImpl* b) -{ - return StringHash::equal(a, b); -} - -bool equal(StringImpl* a, const char* b) -{ - if (!a) - return !b; - if (!b) - return !a; - - unsigned length = a->length(); - const UChar* as = a->characters(); - for (unsigned i = 0; i != length; ++i) { - unsigned char bc = b[i]; - if (!bc) - return false; - if (as[i] != bc) - return false; - } - - return !b[length]; -} - -bool equalIgnoringCase(StringImpl* a, StringImpl* b) -{ - return CaseFoldingHash::equal(a, b); -} - -bool equalIgnoringCase(StringImpl* a, const char* b) -{ - if (!a) - return !b; - if (!b) - return !a; - - unsigned length = a->length(); - const UChar* as = a->characters(); - - // Do a faster loop for the case where all the characters are ASCII. - UChar ored = 0; - bool equal = true; - for (unsigned i = 0; i != length; ++i) { - char bc = b[i]; - if (!bc) - return false; - UChar ac = as[i]; - ored |= ac; - equal = equal && (toASCIILower(ac) == toASCIILower(bc)); - } - - // Do a slower implementation for cases that include non-ASCII characters. - if (ored & ~0x7F) { - equal = true; - for (unsigned i = 0; i != length; ++i) { - unsigned char bc = b[i]; - equal = equal && (foldCase(as[i]) == foldCase(bc)); - } - } - - return equal && !b[length]; -} - -Vector<char> StringImpl::ascii() -{ - Vector<char> buffer(m_length + 1); - for (unsigned i = 0; i != m_length; ++i) { - UChar c = m_data[i]; - if ((c >= 0x20 && c < 0x7F) || c == 0x00) - buffer[i] = c; - else - buffer[i] = '?'; - } - buffer[m_length] = '\0'; - return buffer; -} - -WTF::Unicode::Direction StringImpl::defaultWritingDirection() -{ - for (unsigned i = 0; i < m_length; ++i) { - WTF::Unicode::Direction charDirection = WTF::Unicode::direction(m_data[i]); - if (charDirection == WTF::Unicode::LeftToRight) - return WTF::Unicode::LeftToRight; - if (charDirection == WTF::Unicode::RightToLeft || charDirection == WTF::Unicode::RightToLeftArabic) - return WTF::Unicode::RightToLeft; - } - return WTF::Unicode::LeftToRight; -} - -// This is a hot function because it's used when parsing HTML. -PassRefPtr<StringImpl> StringImpl::createStrippingNullCharacters(const UChar* characters, unsigned length) -{ - ASSERT(characters); - ASSERT(length); - - // Optimize for the case where there are no Null characters by quickly - // searching for nulls, and then using StringImpl::create, which will - // memcpy the whole buffer. This is faster than assigning character by - // character during the loop. - - // Fast case. - int foundNull = 0; - for (unsigned i = 0; !foundNull && i < length; i++) { - int c = characters[i]; // more efficient than using UChar here (at least on Intel Mac OS) - foundNull |= !c; - } - if (!foundNull) - return StringImpl::create(characters, length); - - // Slow case. - StringBuffer strippedCopy(length); - unsigned strippedLength = 0; - for (unsigned i = 0; i < length; i++) { - if (int c = characters[i]) - strippedCopy[strippedLength++] = c; - } - ASSERT(strippedLength < length); // Only take the slow case when stripping. - strippedCopy.shrink(strippedLength); - return adopt(strippedCopy); -} - -PassRefPtr<StringImpl> StringImpl::adopt(StringBuffer& buffer) -{ - unsigned length = buffer.length(); - if (length == 0) - return empty(); - return adoptRef(new StringImpl(buffer.release(), length, AdoptBuffer())); -} - -PassRefPtr<StringImpl> StringImpl::adopt(Vector<UChar>& vector) -{ - size_t size = vector.size(); - if (size == 0) - return empty(); - return adoptRef(new StringImpl(vector.releaseBuffer(), size, AdoptBuffer())); -} - -PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned length) -{ - if (!characters || !length) - return empty(); - return adoptRef(new StringImpl(characters, length)); -} - -PassRefPtr<StringImpl> StringImpl::create(const char* characters, unsigned length) -{ - if (!characters || !length) - return empty(); - return adoptRef(new StringImpl(characters, length)); -} - -PassRefPtr<StringImpl> StringImpl::create(const char* string) -{ - if (!string) - return empty(); - unsigned length = strlen(string); - if (!length) - return empty(); - return adoptRef(new StringImpl(string, length)); -} - -PassRefPtr<StringImpl> StringImpl::createWithTerminatingNullCharacter(const StringImpl& string) -{ - return adoptRef(new StringImpl(string, WithTerminatingNullCharacter())); -} - -PassRefPtr<StringImpl> StringImpl::copy() -{ - return adoptRef(new StringImpl(m_data, m_length)); -} - -} // namespace WebCore diff --git a/webkit/pending/StringImpl.h b/webkit/pending/StringImpl.h deleted file mode 100644 index bf3ceca..0000000 --- a/webkit/pending/StringImpl.h +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (C) 1999 Lars Knoll (knoll@kde.org) - * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#ifndef StringImpl_h -#define StringImpl_h - -#include <limits.h> -#include <wtf/ASCIICType.h> -#include <wtf/Forward.h> -#include <wtf/RefCounted.h> -#include <wtf/Vector.h> -#include <wtf/unicode/Unicode.h> - -#if PLATFORM(CF) -typedef const struct __CFString * CFStringRef; -#endif - -#ifdef __OBJC__ -@class NSString; -#endif - -namespace WebCore { - -class AtomicString; -class StringBuffer; - -struct CStringTranslator; -struct HashAndCharactersTranslator; -struct Length; -struct StringHash; -struct UCharBufferTranslator; - -class StringImpl : public RefCounted<StringImpl> { - friend class AtomicString; - friend struct CStringTranslator; - friend struct HashAndCharactersTranslator; - friend struct UCharBufferTranslator; -private: - StringImpl(); - StringImpl(const UChar*, unsigned length); - StringImpl(const char*, unsigned length); - - struct AdoptBuffer { }; - StringImpl(UChar*, unsigned length, AdoptBuffer); - - struct WithTerminatingNullCharacter { }; - StringImpl(const StringImpl&, WithTerminatingNullCharacter); - - // For AtomicString. - StringImpl(const UChar*, unsigned length, unsigned hash); - StringImpl(const char*, unsigned length, unsigned hash); - -public: - ~StringImpl(); - - static PassRefPtr<StringImpl> create(const UChar*, unsigned length); - static PassRefPtr<StringImpl> create(const char*, unsigned length); - static PassRefPtr<StringImpl> create(const char*); - - static PassRefPtr<StringImpl> createWithTerminatingNullCharacter(const StringImpl&); - - static PassRefPtr<StringImpl> createStrippingNullCharacters(const UChar*, unsigned length); - static PassRefPtr<StringImpl> adopt(StringBuffer&); - static PassRefPtr<StringImpl> adopt(Vector<UChar>&); - - const UChar* characters() { return m_data; } - unsigned length() { return m_length; } - - bool hasTerminatingNullCharacter() { return m_hasTerminatingNullCharacter; } - - unsigned hash() { if (m_hash == 0) m_hash = computeHash(m_data, m_length); return m_hash; } - static unsigned computeHash(const UChar*, unsigned len); - static unsigned computeHash(const char*); - - // Makes a deep copy. Helpful only if you need to use a String on another thread. - // Since StringImpl objects are immutable, there's no other reason to make a copy. - PassRefPtr<StringImpl> copy(); - - PassRefPtr<StringImpl> substring(unsigned pos, unsigned len = UINT_MAX); - - UChar operator[](unsigned i) { ASSERT(i < m_length); return m_data[i]; } - UChar32 characterStartingAt(unsigned); - - Length toLength(); - - bool containsOnlyWhitespace(); - - int toIntStrict(bool* ok = 0, int base = 10); - unsigned toUIntStrict(bool* ok = 0, int base = 10); - int64_t toInt64Strict(bool* ok = 0, int base = 10); - uint64_t toUInt64Strict(bool* ok = 0, int base = 10); - - int toInt(bool* ok = 0); // ignores trailing garbage - unsigned toUInt(bool* ok = 0); // ignores trailing garbage - int64_t toInt64(bool* ok = 0); // ignores trailing garbage - uint64_t toUInt64(bool* ok = 0); // ignores trailing garbage - - double toDouble(bool* ok = 0); - float toFloat(bool* ok = 0); - - Length* toCoordsArray(int& len); - Length* toLengthArray(int& len); - bool isLower(); - PassRefPtr<StringImpl> lower(); - PassRefPtr<StringImpl> upper(); - PassRefPtr<StringImpl> secure(UChar aChar); - PassRefPtr<StringImpl> capitalize(UChar previousCharacter); - PassRefPtr<StringImpl> foldCase(); - - PassRefPtr<StringImpl> stripWhiteSpace(); - PassRefPtr<StringImpl> simplifyWhiteSpace(); - - int find(const char*, int index = 0, bool caseSensitive = true); - int find(UChar, int index = 0); - int find(StringImpl*, int index, bool caseSensitive = true); - - int reverseFind(UChar, int index); - int reverseFind(StringImpl*, int index, bool caseSensitive = true); - - bool startsWith(StringImpl* m_data, bool caseSensitive = true) { return find(m_data, 0, caseSensitive) == 0; } - bool endsWith(StringImpl*, bool caseSensitive = true); - - PassRefPtr<StringImpl> replace(UChar, UChar); - PassRefPtr<StringImpl> replace(UChar, StringImpl*); - PassRefPtr<StringImpl> replace(StringImpl*, StringImpl*); - PassRefPtr<StringImpl> replace(unsigned index, unsigned len, StringImpl*); - - static StringImpl* empty(); - - Vector<char> ascii(); - - WTF::Unicode::Direction defaultWritingDirection(); - -#if PLATFORM(CF) - CFStringRef createCFString(); -#endif -#ifdef __OBJC__ - operator NSString*(); -#endif - -private: - unsigned m_length; - const UChar* m_data; - mutable unsigned m_hash; - bool m_inTable; - bool m_hasTerminatingNullCharacter; -}; - -bool equal(StringImpl*, StringImpl*); -bool equal(StringImpl*, const char*); -inline bool equal(const char* a, StringImpl* b) { return equal(b, a); } - -bool equalIgnoringCase(StringImpl*, StringImpl*); -bool equalIgnoringCase(StringImpl*, const char*); -inline bool equalIgnoringCase(const char* a, StringImpl* b) { return equalIgnoringCase(b, a); } - -// Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's -// or anything like that. -const unsigned phi = 0x9e3779b9U; - -// Paul Hsieh's SuperFastHash -// http://www.azillionmonkeys.com/qed/hash.html -inline unsigned StringImpl::computeHash(const UChar* data, unsigned length) -{ - unsigned hash = phi; - - // Main loop. - for (unsigned pairCount = length >> 1; pairCount; pairCount--) { - hash += data[0]; - unsigned tmp = (data[1] << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2; - hash += hash >> 11; - } - - // Handle end case. - if (length & 1) { - hash += data[0]; - hash ^= hash << 11; - hash += hash >> 17; - } - - // Force "avalanching" of final 127 bits. - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 2; - hash += hash >> 15; - hash ^= hash << 10; - - // This avoids ever returning a hash code of 0, since that is used to - // signal "hash not computed yet", using a value that is likely to be - // effectively the same as 0 when the low bits are masked. - hash |= !hash << 31; - - return hash; -} - -// Paul Hsieh's SuperFastHash -// http://www.azillionmonkeys.com/qed/hash.html -inline unsigned StringImpl::computeHash(const char* data) -{ - // This hash is designed to work on 16-bit chunks at a time. But since the normal case - // (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they - // were 16-bit chunks, which should give matching results - - unsigned hash = phi; - - // Main loop - for (;;) { - unsigned char b0 = data[0]; - if (!b0) - break; - unsigned char b1 = data[1]; - if (!b1) { - hash += b0; - hash ^= hash << 11; - hash += hash >> 17; - break; - } - hash += b0; - unsigned tmp = (b1 << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2; - hash += hash >> 11; - } - - // Force "avalanching" of final 127 bits. - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 2; - hash += hash >> 15; - hash ^= hash << 10; - - // This avoids ever returning a hash code of 0, since that is used to - // signal "hash not computed yet", using a value that is likely to be - // effectively the same as 0 when the low bits are masked. - hash |= !hash << 31; - - return hash; -} - -static inline bool isSpaceOrNewline(UChar c) -{ - // Use isASCIISpace() for basic Latin-1. - // This will include newlines, which aren't included in Unicode DirWS. - return c <= 0x7F ? WTF::isASCIISpace(c) : WTF::Unicode::direction(c) == WTF::Unicode::WhiteSpaceNeutral; -} - -} - -namespace WTF { - - // WebCore::StringHash is the default hash for StringImpl* and RefPtr<StringImpl> - template<typename T> struct DefaultHash; - template<> struct DefaultHash<WebCore::StringImpl*> { - typedef WebCore::StringHash Hash; - }; - template<> struct DefaultHash<RefPtr<WebCore::StringImpl> > { - typedef WebCore::StringHash Hash; - }; - -} - -#endif |