From c2a5c655726f0bd3e9cedfead71c4b0173a59f05 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 29 Dec 2015 21:39:16 -0800 Subject: [PATCH] Remove dead code from engine/platform Highlights include: - A Base64 encoder/decoder - A JSON encoder/decoder - A JPEG and a PNG encoder --- sky/engine/core/rendering/RenderObject.cpp | 1 - sky/engine/platform/AsyncMethodRunner.h | 135 --- sky/engine/platform/BUILD.gn | 29 - sky/engine/platform/CheckedInt.h | 818 ------------------ sky/engine/platform/Clock.cpp | 94 -- sky/engine/platform/Clock.h | 63 -- sky/engine/platform/ClockTest.cpp | 60 -- sky/engine/platform/ColorSuggestion.h | 51 -- sky/engine/platform/ContentType.cpp | 93 -- sky/engine/platform/ContentType.h | 49 -- sky/engine/platform/DateComponents.cpp | 714 --------------- sky/engine/platform/DateComponents.h | 215 ----- .../platform/EventDispatchForbiddenScope.h | 74 -- sky/engine/platform/HostWindow.h | 50 -- sky/engine/platform/JSONValues.cpp | 528 ----------- sky/engine/platform/JSONValues.h | 319 ------- sky/engine/platform/KeyboardCodes.h | 557 ------------ sky/engine/platform/MIMETypeRegistry.cpp | 46 - sky/engine/platform/MIMETypeRegistry.h | 44 - sky/engine/platform/ParsingUtilities.h | 83 -- sky/engine/platform/RefCountedSupplement.h | 75 -- sky/engine/platform/ScriptForbiddenScope.cpp | 55 -- sky/engine/platform/ScriptForbiddenScope.h | 34 - .../platform/SharedBufferChunkReader.cpp | 149 ---- sky/engine/platform/SharedBufferChunkReader.h | 73 -- sky/engine/platform/Supplementable.h | 199 ----- sky/engine/platform/WindowsKeyboardCodes.h | 320 ------- sky/engine/platform/graphics/Image.cpp | 1 - sky/engine/platform/graphics/ImageBuffer.cpp | 51 -- sky/engine/platform/graphics/ImageBuffer.h | 3 - .../image-encoders/skia/JPEGImageEncoder.cpp | 214 ----- .../image-encoders/skia/JPEGImageEncoder.h | 54 -- .../image-encoders/skia/PNGImageEncoder.cpp | 131 --- .../image-encoders/skia/PNGImageEncoder.h | 51 -- sky/engine/wtf/BUILD.gn | 2 - sky/engine/wtf/TypeTraits.h | 19 - sky/engine/wtf/text/Base64.cpp | 239 ----- sky/engine/wtf/text/Base64.h | 90 -- 38 files changed, 5783 deletions(-) delete mode 100644 sky/engine/platform/AsyncMethodRunner.h delete mode 100644 sky/engine/platform/CheckedInt.h delete mode 100644 sky/engine/platform/Clock.cpp delete mode 100644 sky/engine/platform/Clock.h delete mode 100644 sky/engine/platform/ClockTest.cpp delete mode 100644 sky/engine/platform/ColorSuggestion.h delete mode 100644 sky/engine/platform/ContentType.cpp delete mode 100644 sky/engine/platform/ContentType.h delete mode 100644 sky/engine/platform/DateComponents.cpp delete mode 100644 sky/engine/platform/DateComponents.h delete mode 100644 sky/engine/platform/EventDispatchForbiddenScope.h delete mode 100644 sky/engine/platform/HostWindow.h delete mode 100644 sky/engine/platform/JSONValues.cpp delete mode 100644 sky/engine/platform/JSONValues.h delete mode 100644 sky/engine/platform/KeyboardCodes.h delete mode 100644 sky/engine/platform/MIMETypeRegistry.cpp delete mode 100644 sky/engine/platform/MIMETypeRegistry.h delete mode 100644 sky/engine/platform/ParsingUtilities.h delete mode 100644 sky/engine/platform/RefCountedSupplement.h delete mode 100644 sky/engine/platform/ScriptForbiddenScope.cpp delete mode 100644 sky/engine/platform/ScriptForbiddenScope.h delete mode 100644 sky/engine/platform/SharedBufferChunkReader.cpp delete mode 100644 sky/engine/platform/SharedBufferChunkReader.h delete mode 100644 sky/engine/platform/Supplementable.h delete mode 100644 sky/engine/platform/WindowsKeyboardCodes.h delete mode 100644 sky/engine/platform/image-encoders/skia/JPEGImageEncoder.cpp delete mode 100644 sky/engine/platform/image-encoders/skia/JPEGImageEncoder.h delete mode 100644 sky/engine/platform/image-encoders/skia/PNGImageEncoder.cpp delete mode 100644 sky/engine/platform/image-encoders/skia/PNGImageEncoder.h delete mode 100644 sky/engine/wtf/text/Base64.cpp delete mode 100644 sky/engine/wtf/text/Base64.h diff --git a/sky/engine/core/rendering/RenderObject.cpp b/sky/engine/core/rendering/RenderObject.cpp index 2ffbf3b8a45..cb76d2fd863 100644 --- a/sky/engine/core/rendering/RenderObject.cpp +++ b/sky/engine/core/rendering/RenderObject.cpp @@ -39,7 +39,6 @@ #include "sky/engine/core/rendering/RenderTheme.h" #include "sky/engine/core/rendering/RenderView.h" #include "sky/engine/core/rendering/style/ShadowList.h" -#include "sky/engine/platform/JSONValues.h" #include "sky/engine/platform/Partitions.h" #include "sky/engine/platform/TraceEvent.h" #include "sky/engine/platform/geometry/TransformState.h" diff --git a/sky/engine/platform/AsyncMethodRunner.h b/sky/engine/platform/AsyncMethodRunner.h deleted file mode 100644 index 48623f610b1..00000000000 --- a/sky/engine/platform/AsyncMethodRunner.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2013 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_ASYNCMETHODRUNNER_H_ -#define SKY_ENGINE_PLATFORM_ASYNCMETHODRUNNER_H_ - -#include "sky/engine/platform/Timer.h" -#include "sky/engine/wtf/FastAllocBase.h" -#include "sky/engine/wtf/Noncopyable.h" - -namespace blink { - -template -class AsyncMethodRunner final { - WTF_MAKE_NONCOPYABLE(AsyncMethodRunner); - WTF_MAKE_FAST_ALLOCATED; -public: - typedef void (TargetClass::*TargetMethod)(); - - AsyncMethodRunner(TargetClass* object, TargetMethod method) - : m_timer(this, &AsyncMethodRunner::fired) - , m_object(object) - , m_method(method) - , m_suspended(false) - , m_runWhenResumed(false) - { - } - - // Schedules to run the method asynchronously. Do nothing if it's already - // scheduled. If it's suspended, remember to schedule to run the method when - // resume() is called. - void runAsync() - { - if (m_suspended) { - ASSERT(!m_timer.isActive()); - m_runWhenResumed = true; - return; - } - - // FIXME: runAsync should take a tracked_objects::Location and pass it to timer here. - if (!m_timer.isActive()) - m_timer.startOneShot(0, FROM_HERE); - } - - // If it's scheduled to run the method, cancel it and remember to schedule - // it again when resume() is called. - void suspend() - { - if (m_suspended) - return; - m_suspended = true; - - if (!m_timer.isActive()) - return; - - m_timer.stop(); - m_runWhenResumed = true; - } - - // Resumes pending method run. - void resume() - { - if (!m_suspended) - return; - m_suspended = false; - - if (!m_runWhenResumed) - return; - - m_runWhenResumed = false; - // FIXME: resume should take a tracked_objects::Location and pass it to timer here. - m_timer.startOneShot(0, FROM_HERE); - } - - void stop() - { - if (m_suspended) { - ASSERT(!m_timer.isActive()); - m_runWhenResumed = false; - m_suspended = false; - return; - } - - ASSERT(!m_runWhenResumed); - if (m_timer.isActive()) - m_timer.stop(); - } - - bool isActive() const - { - return m_timer.isActive(); - } - -private: - void fired(Timer >*) { (m_object->*m_method)(); } - - Timer > m_timer; - - TargetClass* m_object; - TargetMethod m_method; - - bool m_suspended; - bool m_runWhenResumed; -}; - -} - -#endif // SKY_ENGINE_PLATFORM_ASYNCMETHODRUNNER_H_ diff --git a/sky/engine/platform/BUILD.gn b/sky/engine/platform/BUILD.gn index a2d4e7aba21..33077613242 100644 --- a/sky/engine/platform/BUILD.gn +++ b/sky/engine/platform/BUILD.gn @@ -64,24 +64,10 @@ source_set("platform") { visibility += [ "//sky/*" ] sources = [ - "AsyncMethodRunner.h", "CalculationValue.h", - "CheckedInt.h", - "Clock.cpp", - "Clock.h", - "ColorSuggestion.h", - "ContentType.cpp", - "ContentType.h", - "DateComponents.cpp", - "DateComponents.h", "Decimal.cpp", "Decimal.h", - "EventDispatchForbiddenScope.h", "FloatConversion.h", - "HostWindow.h", - "JSONValues.cpp", - "JSONValues.h", - "KeyboardCodes.h", "Language.cpp", "Language.h", "LayoutTestSupport.cpp", @@ -97,11 +83,8 @@ source_set("platform") { "LengthSize.h", "Logging.cpp", "Logging.h", - "MIMETypeRegistry.cpp", - "MIMETypeRegistry.h", "NotImplemented.cpp", "NotImplemented.h", - "ParsingUtilities.h", "Partitions.cpp", "Partitions.h", "PlatformExport.h", @@ -109,23 +92,16 @@ source_set("platform") { "PlatformThreadData.h", "PurgeableVector.cpp", "PurgeableVector.h", - "RefCountedSupplement.h", - "ScriptForbiddenScope.cpp", - "ScriptForbiddenScope.h", "SharedBuffer.cpp", "SharedBuffer.h", - "SharedBufferChunkReader.cpp", - "SharedBufferChunkReader.h", "SharedTimer.cpp", "SharedTimer.h", - "Supplementable.h", "ThreadTimers.cpp", "ThreadTimers.h", "Timer.cpp", "Timer.h", "TraceEvent.h", "WebThread.cpp", - "WindowsKeyboardCodes.h", "animation/AnimationUtilities.h", "animation/AnimationValue.h", "animation/KeyframeValueList.cpp", @@ -391,10 +367,6 @@ source_set("platform") { "image-decoders/jpeg/JPEGImageDecoder.h", "image-decoders/png/PNGImageDecoder.cpp", "image-decoders/png/PNGImageDecoder.h", - "image-encoders/skia/JPEGImageEncoder.cpp", - "image-encoders/skia/JPEGImageEncoder.h", - "image-encoders/skia/PNGImageEncoder.cpp", - "image-encoders/skia/PNGImageEncoder.h", "mojo/data_pipe.cc", "mojo/data_pipe.h", "text/BidiCharacterRun.cpp", @@ -551,7 +523,6 @@ test("platform_unittests") { output_name = "sky_platform_unittests" sources = [ - "ClockTest.cpp", "DecimalTest.cpp", "LayoutUnitTest.cpp", "PurgeableVectorTest.cpp", diff --git a/sky/engine/platform/CheckedInt.h b/sky/engine/platform/CheckedInt.h deleted file mode 100644 index aa8b65d762f..00000000000 --- a/sky/engine/platform/CheckedInt.h +++ /dev/null @@ -1,818 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* Provides checked integers, detecting integer overflow and divide-by-0. */ - -// Necessary modifications are made to the original CheckedInt.h file when -// incorporating it into WebKit: -// 1) Comment out #define MOZ_CHECKEDINT_ENABLE_MOZ_ASSERTS -// 2) Comment out #include "mozilla/StandardInteger.h" -// 3) Define MOZ_DELETE -// 4) Change namespace mozilla to namespace blink - -#ifndef SKY_ENGINE_PLATFORM_CHECKEDINT_H_ -#define SKY_ENGINE_PLATFORM_CHECKEDINT_H_ - -/* - * Build options. Comment out these #defines to disable the corresponding - * optional feature. Disabling features may be useful for code using - * CheckedInt outside of Mozilla (e.g. WebKit) - */ - -// Enable usage of MOZ_STATIC_ASSERT to check for unsupported types. -// If disabled, static asserts are replaced by regular assert(). -// #define MOZ_CHECKEDINT_ENABLE_MOZ_ASSERTS - -/* - * End of build options - */ - -#ifdef MOZ_CHECKEDINT_ENABLE_MOZ_ASSERTS -# include "mozilla/Assertions.h" -#else -# ifndef MOZ_STATIC_ASSERT -# include -# define MOZ_STATIC_ASSERT(cond, reason) assert((cond) && reason) -# define MOZ_ASSERT(cond, reason) assert((cond) && reason) -# endif -#endif - -// #include "mozilla/StandardInteger.h" - -#ifndef MOZ_DELETE -#define MOZ_DELETE -#endif - -#include - -namespace blink { - -namespace detail { - -/* - * Step 1: manually record supported types - * - * What's nontrivial here is that there are different families of integer - * types: basic integer types and stdint types. It is merrily undefined which - * types from one family may be just typedefs for a type from another family. - * - * For example, on GCC 4.6, aside from the basic integer types, the only other - * type that isn't just a typedef for some of them, is int8_t. - */ - -struct UnsupportedType {}; - -template -struct IsSupportedPass2 -{ - static const bool value = false; -}; - -template -struct IsSupported -{ - static const bool value = IsSupportedPass2::value; -}; - -template<> -struct IsSupported -{ static const bool value = true; }; - -template<> -struct IsSupported -{ static const bool value = true; }; - -template<> -struct IsSupported -{ static const bool value = true; }; - -template<> -struct IsSupported -{ static const bool value = true; }; - -template<> -struct IsSupported -{ static const bool value = true; }; - -template<> -struct IsSupported -{ static const bool value = true; }; - -template<> -struct IsSupported -{ static const bool value = true; }; - -template<> -struct IsSupported -{ static const bool value = true; }; - - -template<> -struct IsSupportedPass2 -{ static const bool value = true; }; - -template<> -struct IsSupportedPass2 -{ static const bool value = true; }; - -template<> -struct IsSupportedPass2 -{ static const bool value = true; }; - -template<> -struct IsSupportedPass2 -{ static const bool value = true; }; - -template<> -struct IsSupportedPass2 -{ static const bool value = true; }; - -template<> -struct IsSupportedPass2 -{ static const bool value = true; }; - -template<> -struct IsSupportedPass2 -{ static const bool value = true; }; - -template<> -struct IsSupportedPass2 -{ static const bool value = true; }; - - -/* - * Step 2: some integer-traits kind of stuff. - */ - -template -struct StdintTypeForSizeAndSignedness -{}; - -template<> -struct StdintTypeForSizeAndSignedness<1, true> -{ typedef int8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<1, false> -{ typedef uint8_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, true> -{ typedef int16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<2, false> -{ typedef uint16_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, true> -{ typedef int32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<4, false> -{ typedef uint32_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, true> -{ typedef int64_t Type; }; - -template<> -struct StdintTypeForSizeAndSignedness<8, false> -{ typedef uint64_t Type; }; - -template -struct UnsignedType -{ - typedef typename StdintTypeForSizeAndSignedness::Type Type; -}; - -template -struct IsSigned -{ - static const bool value = IntegerType(-1) <= IntegerType(0); -}; - -template -struct TwiceBiggerType -{ - typedef typename StdintTypeForSizeAndSignedness< - sizeof(IntegerType) * 2, - IsSigned::value - >::Type Type; -}; - -template -struct TwiceBiggerType -{ - typedef UnsupportedType Type; -}; - -template -struct PositionOfSignBit -{ - static const size_t value = CHAR_BIT * sizeof(IntegerType) - 1; -}; - -template -struct MinValue -{ - private: - typedef typename UnsignedType::Type UnsignedIntegerType; - static const size_t PosOfSignBit = PositionOfSignBit::value; - - public: - // Bitwise ops may return a larger type, that's why we cast explicitly. - // In C++, left bit shifts on signed values is undefined by the standard - // unless the shifted value is representable. - // Notice that signed-to-unsigned conversions are always well-defined in - // the standard as the value congruent to 2**n, as expected. By contrast, - // unsigned-to-signed is only well-defined if the value is representable. - static const IntegerType value = - IsSigned::value - ? IntegerType(UnsignedIntegerType(1) << PosOfSignBit) - : IntegerType(0); -}; - -template -struct MaxValue -{ - // Tricksy, but covered by the unit test. - // Relies heavily on the type of MinValue::value - // being IntegerType. - static const IntegerType value = ~MinValue::value; -}; - -/* - * Step 3: Implement the actual validity checks. - * - * Ideas taken from IntegerLib, code different. - */ - -template -inline bool -HasSignBit(T x) -{ - // In C++, right bit shifts on negative values is undefined by the standard. - // Notice that signed-to-unsigned conversions are always well-defined in the - // standard, as the value congruent modulo 2**n as expected. By contrast, - // unsigned-to-signed is only well-defined if the value is representable. - return bool(typename UnsignedType::Type(x) - >> PositionOfSignBit::value); -} - -// Bitwise ops may return a larger type, so it's good to use this inline -// helper guaranteeing that the result is really of type T. -template -inline T -BinaryComplement(T x) -{ - return ~x; -} - -template::value, - bool IsUSigned = IsSigned::value> -struct DoesRangeContainRange -{ -}; - -template -struct DoesRangeContainRange -{ - static const bool value = sizeof(T) >= sizeof(U); -}; - -template -struct DoesRangeContainRange -{ - static const bool value = sizeof(T) > sizeof(U); -}; - -template -struct DoesRangeContainRange -{ - static const bool value = false; -}; - -template::value, - bool IsUSigned = IsSigned::value, - bool DoesTRangeContainURange = DoesRangeContainRange::value> -struct IsInRangeImpl {}; - -template -struct IsInRangeImpl -{ - static bool run(U) - { - return true; - } -}; - -template -struct IsInRangeImpl -{ - static bool run(U x) - { - return x <= MaxValue::value && x >= MinValue::value; - } -}; - -template -struct IsInRangeImpl -{ - static bool run(U x) - { - return x <= MaxValue::value; - } -}; - -template -struct IsInRangeImpl -{ - static bool run(U x) - { - return sizeof(T) > sizeof(U) || x <= U(MaxValue::value); - } -}; - -template -struct IsInRangeImpl -{ - static bool run(U x) - { - return sizeof(T) >= sizeof(U) - ? x >= 0 - : x >= 0 && x <= U(MaxValue::value); - } -}; - -template -inline bool -IsInRange(U x) -{ - return IsInRangeImpl::run(x); -} - -template -inline bool -IsAddValid(T x, T y) -{ - // Addition is valid if the sign of x+y is equal to either that of x or that - // of y. Since the value of x+y is undefined if we have a signed type, we - // compute it using the unsigned type of the same size. - // Beware! These bitwise operations can return a larger integer type, - // if T was a small type like int8_t, so we explicitly cast to T. - - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux + uy; - return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (result ^ y)))) - : BinaryComplement(x) >= y; -} - -template -inline bool -IsSubValid(T x, T y) -{ - // Subtraction is valid if either x and y have same sign, or x-y and x have - // same sign. Since the value of x-y is undefined if we have a signed type, - // we compute it using the unsigned type of the same size. - typename UnsignedType::Type ux = x; - typename UnsignedType::Type uy = y; - typename UnsignedType::Type result = ux - uy; - - return IsSigned::value - ? HasSignBit(BinaryComplement(T((result ^ x) & (x ^ y)))) - : x >= y; -} - -template::value, - bool TwiceBiggerTypeIsSupported = - IsSupported::Type>::value> -struct IsMulValidImpl {}; - -template -struct IsMulValidImpl -{ - static bool run(T x, T y) - { - typedef typename TwiceBiggerType::Type TwiceBiggerType; - TwiceBiggerType product = TwiceBiggerType(x) * TwiceBiggerType(y); - return IsInRange(product); - } -}; - -template -struct IsMulValidImpl -{ - static bool run(T x, T y) - { - const T max = MaxValue::value; - const T min = MinValue::value; - - if (x == 0 || y == 0) - return true; - - if (x > 0) { - return y > 0 - ? x <= max / y - : y >= min / x; - } - - // If we reach this point, we know that x < 0. - return y > 0 - ? x >= min / y - : y >= max / x; - } -}; - -template -struct IsMulValidImpl -{ - static bool run(T x, T y) - { - return y == 0 || x <= MaxValue::value / y; - } -}; - -template -inline bool -IsMulValid(T x, T y) -{ - return IsMulValidImpl::run(x, y); -} - -template -inline bool -IsDivValid(T x, T y) -{ - // Keep in mind that in the signed case, min/-1 is invalid because abs(min)>max. - return y != 0 && - !(IsSigned::value && x == MinValue::value && y == T(-1)); -} - -// This is just to shut up msvc warnings about negating unsigned ints. -template::value> -struct OppositeIfSignedImpl -{ - static T run(T x) { return -x; } -}; -template -struct OppositeIfSignedImpl -{ - static T run(T x) { return x; } -}; -template -inline T -OppositeIfSigned(T x) -{ - return OppositeIfSignedImpl::run(x); -} - -} // namespace detail - - -/* - * Step 4: Now define the CheckedInt class. - */ - -/** - * @class CheckedInt - * @brief Integer wrapper class checking for integer overflow and other errors - * @param T the integer type to wrap. Can be any type among the following: - * - any basic integer type such as |int| - * - any stdint type such as |int8_t| - * - * This class implements guarded integer arithmetic. Do a computation, check - * that isValid() returns true, you then have a guarantee that no problem, such - * as integer overflow, happened during this computation, and you can call - * value() to get the plain integer value. - * - * The arithmetic operators in this class are guaranteed not to raise a signal - * (e.g. in case of a division by zero). - * - * For example, suppose that you want to implement a function that computes - * (x+y)/z, that doesn't crash if z==0, and that reports on error (divide by - * zero or integer overflow). You could code it as follows: - @code - bool computeXPlusYOverZ(int x, int y, int z, int *result) - { - CheckedInt checkedResult = (CheckedInt(x) + y) / z; - if (checkedResult.isValid()) { - *result = checkedResult.value(); - return true; - } else { - return false; - } - } - @endcode - * - * Implicit conversion from plain integers to checked integers is allowed. The - * plain integer is checked to be in range before being casted to the - * destination type. This means that the following lines all compile, and the - * resulting CheckedInts are correctly detected as valid or invalid: - * @code - // 1 is of type int, is found to be in range for uint8_t, x is valid - CheckedInt x(1); - // -1 is of type int, is found not to be in range for uint8_t, x is invalid - CheckedInt x(-1); - // -1 is of type int, is found to be in range for int8_t, x is valid - CheckedInt x(-1); - // 1000 is of type int16_t, is found not to be in range for int8_t, - // x is invalid - CheckedInt x(int16_t(1000)); - // 3123456789 is of type uint32_t, is found not to be in range for int32_t, - // x is invalid - CheckedInt x(uint32_t(3123456789)); - * @endcode - * Implicit conversion from - * checked integers to plain integers is not allowed. As shown in the - * above example, to get the value of a checked integer as a normal integer, - * call value(). - * - * Arithmetic operations between checked and plain integers is allowed; the - * result type is the type of the checked integer. - * - * Checked integers of different types cannot be used in the same arithmetic - * expression. - * - * There are convenience typedefs for all stdint types, of the following form - * (these are just 2 examples): - @code - typedef CheckedInt CheckedInt32; - typedef CheckedInt CheckedUint16; - @endcode - */ -template -class CheckedInt -{ - protected: - T mValue; - bool mIsValid; - - template - CheckedInt(U value, bool isValid) : mValue(value), mIsValid(isValid) - { - MOZ_STATIC_ASSERT(detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } - - public: - /** - * Constructs a checked integer with given @a value. The checked integer is - * initialized as valid or invalid depending on whether the @a value - * is in range. - * - * This constructor is not explicit. Instead, the type of its argument is a - * separate template parameter, ensuring that no conversion is performed - * before this constructor is actually called. As explained in the above - * documentation for class CheckedInt, this constructor checks that its - * argument is valid. - */ - template - CheckedInt(U value) - : mValue(T(value)), - mIsValid(detail::IsInRange(value)) - { - MOZ_STATIC_ASSERT(detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } - - /** Constructs a valid checked integer with initial value 0 */ - CheckedInt() : mValue(0), mIsValid(true) - { - MOZ_STATIC_ASSERT(detail::IsSupported::value, - "This type is not supported by CheckedInt"); - } - - /** @returns the actual value */ - T value() const - { - MOZ_ASSERT(mIsValid, "Invalid checked integer (division by zero or integer overflow)"); - return mValue; - } - - /** - * @returns true if the checked integer is valid, i.e. is not the result - * of an invalid operation or of an operation involving an invalid checked - * integer - */ - bool isValid() const - { - return mIsValid; - } - - template - friend CheckedInt operator +(const CheckedInt& lhs, - const CheckedInt& rhs); - template - CheckedInt& operator +=(U rhs); - template - friend CheckedInt operator -(const CheckedInt& lhs, - const CheckedInt &rhs); - template - CheckedInt& operator -=(U rhs); - template - friend CheckedInt operator *(const CheckedInt& lhs, - const CheckedInt &rhs); - template - CheckedInt& operator *=(U rhs); - template - friend CheckedInt operator /(const CheckedInt& lhs, - const CheckedInt &rhs); - template - CheckedInt& operator /=(U rhs); - - CheckedInt operator -() const - { - // Circumvent msvc warning about - applied to unsigned int. - // if we're unsigned, the only valid case anyway is 0 - // in which case - is a no-op. - T result = detail::OppositeIfSigned(mValue); - /* Help the compiler perform RVO (return value optimization). */ - return CheckedInt(result, - mIsValid && detail::IsSubValid(T(0), - mValue)); - } - - /** - * @returns true if the left and right hand sides are valid - * and have the same value. - * - * Note that these semantics are the reason why we don't offer - * a operator!=. Indeed, we'd want to have a!=b be equivalent to !(a==b) - * but that would mean that whenever a or b is invalid, a!=b - * is always true, which would be very confusing. - * - * For similar reasons, operators <, >, <=, >= would be very tricky to - * specify, so we just avoid offering them. - * - * Notice that these == semantics are made more reasonable by these facts: - * 1. a==b implies equality at the raw data level - * (the converse is false, as a==b is never true among invalids) - * 2. This is similar to the behavior of IEEE floats, where a==b - * means that a and b have the same value *and* neither is NaN. - */ - bool operator ==(const CheckedInt& other) const - { - return mIsValid && other.mIsValid && mValue == other.mValue; - } - - /** prefix ++ */ - CheckedInt& operator++() - { - *this += 1; - return *this; - } - - /** postfix ++ */ - CheckedInt operator++(int) - { - CheckedInt tmp = *this; - *this += 1; - return tmp; - } - - /** prefix -- */ - CheckedInt& operator--() - { - *this -= 1; - return *this; - } - - /** postfix -- */ - CheckedInt operator--(int) - { - CheckedInt tmp = *this; - *this -= 1; - return tmp; - } - - private: - /** - * The !=, <, <=, >, >= operators are disabled: - * see the comment on operator==. - */ - template - bool operator !=(U other) const MOZ_DELETE; - template - bool operator <(U other) const MOZ_DELETE; - template - bool operator <=(U other) const MOZ_DELETE; - template - bool operator >(U other) const MOZ_DELETE; - template - bool operator >=(U other) const MOZ_DELETE; -}; - -#define MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(NAME, OP) \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, \ - const CheckedInt &rhs) \ -{ \ - if (!detail::Is##NAME##Valid(lhs.mValue, rhs.mValue)) \ - return CheckedInt(0, false); \ - \ - return CheckedInt(lhs.mValue OP rhs.mValue, \ - lhs.mIsValid && rhs.mIsValid); \ -} - -MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Add, +) -MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Sub, -) -MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Mul, *) -MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR(Div, /) - -#undef MOZ_CHECKEDINT_BASIC_BINARY_OPERATOR - -// Implement castToCheckedInt(x), making sure that -// - it allows x to be either a CheckedInt or any integer type -// that can be casted to T -// - if x is already a CheckedInt, we just return a reference to it, -// instead of copying it (optimization) - -namespace detail { - -template -struct CastToCheckedIntImpl -{ - typedef CheckedInt ReturnType; - static CheckedInt run(U u) { return u; } -}; - -template -struct CastToCheckedIntImpl > -{ - typedef const CheckedInt& ReturnType; - static const CheckedInt& run(const CheckedInt& u) { return u; } -}; - -} // namespace detail - -template -inline typename detail::CastToCheckedIntImpl::ReturnType -castToCheckedInt(U u) -{ - return detail::CastToCheckedIntImpl::run(u); -} - -#define MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(OP, COMPOUND_OP) \ -template \ -template \ -CheckedInt& CheckedInt::operator COMPOUND_OP(U rhs) \ -{ \ - *this = *this OP castToCheckedInt(rhs); \ - return *this; \ -} \ -template \ -inline CheckedInt operator OP(const CheckedInt &lhs, U rhs) \ -{ \ - return lhs OP castToCheckedInt(rhs); \ -} \ -template \ -inline CheckedInt operator OP(U lhs, const CheckedInt &rhs) \ -{ \ - return castToCheckedInt(lhs) OP rhs; \ -} - -MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(+, +=) -MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(*, *=) -MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(-, -=) -MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS(/, /=) - -#undef MOZ_CHECKEDINT_CONVENIENCE_BINARY_OPERATORS - -template -inline bool -operator ==(const CheckedInt &lhs, U rhs) -{ - return lhs == castToCheckedInt(rhs); -} - -template -inline bool -operator ==(U lhs, const CheckedInt &rhs) -{ - return castToCheckedInt(lhs) == rhs; -} - -// Convenience typedefs. -typedef CheckedInt CheckedInt8; -typedef CheckedInt CheckedUint8; -typedef CheckedInt CheckedInt16; -typedef CheckedInt CheckedUint16; -typedef CheckedInt CheckedInt32; -typedef CheckedInt CheckedUint32; -typedef CheckedInt CheckedInt64; -typedef CheckedInt CheckedUint64; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_CHECKEDINT_H_ diff --git a/sky/engine/platform/Clock.cpp b/sky/engine/platform/Clock.cpp deleted file mode 100644 index 6f94f629efb..00000000000 --- a/sky/engine/platform/Clock.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -#include "sky/engine/platform/Clock.h" - -#include "sky/engine/wtf/CurrentTime.h" - -namespace blink { - -Clock::Clock() - : m_running(false) - , m_rate(1) - , m_offset(0) -{ - m_startTime = m_lastTime = now(); -} - -void Clock::setCurrentTime(double time) -{ - m_startTime = m_lastTime = now(); - m_offset = time; -} - -double Clock::currentTime() const -{ - return currentDelta() + m_offset; -} - -void Clock::setPlayRate(double rate) -{ - m_offset += currentDelta(); - m_lastTime = m_startTime = now(); - m_rate = rate; -} - -void Clock::start() -{ - if (m_running) - return; - - m_lastTime = m_startTime = now(); - m_running = true; -} - -void Clock::stop() -{ - if (!m_running) - return; - - m_offset += currentDelta(); - m_lastTime = m_startTime = now(); - m_running = false; -} - -double Clock::now() const -{ - return WTF::currentTime(); -} - -double Clock::currentDelta() const -{ - if (m_running) - m_lastTime = now(); - return (m_lastTime - m_startTime) * m_rate; -} - -PassOwnPtr Clock::create() -{ - return adoptPtr(new Clock()); -} - -} // namespace blink diff --git a/sky/engine/platform/Clock.h b/sky/engine/platform/Clock.h deleted file mode 100644 index e0704478f3a..00000000000 --- a/sky/engine/platform/Clock.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2011 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 SKY_ENGINE_PLATFORM_CLOCK_H_ -#define SKY_ENGINE_PLATFORM_CLOCK_H_ - -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/PassOwnPtr.h" -#include "sky/engine/wtf/RefCounted.h" - -namespace blink { - -class PLATFORM_EXPORT Clock { -public: - static PassOwnPtr create(); - - void setCurrentTime(double); - double currentTime() const; - - void setPlayRate(double); - double playRate() const { return m_rate; } - - void start(); - void stop(); - bool isRunning() const { return m_running; } - -private: - Clock(); - double now() const; - double currentDelta() const; - - bool m_running; - double m_rate; - double m_offset; - double m_startTime; - mutable double m_lastTime; -}; - -} - -#endif // SKY_ENGINE_PLATFORM_CLOCK_H_ diff --git a/sky/engine/platform/ClockTest.cpp b/sky/engine/platform/ClockTest.cpp deleted file mode 100644 index e3be8974940..00000000000 --- a/sky/engine/platform/ClockTest.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2013 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 "sky/engine/platform/Clock.h" - -#include "sky/engine/wtf/OwnPtr.h" - -#include - -using blink::Clock; - -namespace { - -TEST(Clock, StartStop) -{ - OwnPtr clock = Clock::create(); - EXPECT_FALSE(clock->isRunning()); - clock->start(); - EXPECT_TRUE(clock->isRunning()); - clock->stop(); - EXPECT_FALSE(clock->isRunning()); -} - -TEST(Clock, SetCurrentTimeThenStartStop) -{ - OwnPtr clock = Clock::create(); - clock->setCurrentTime(10.0); - clock->start(); - clock->stop(); - EXPECT_TRUE(clock->currentTime() >= 10.0); -} - -} // namespace diff --git a/sky/engine/platform/ColorSuggestion.h b/sky/engine/platform/ColorSuggestion.h deleted file mode 100644 index 46bbb670b47..00000000000 --- a/sky/engine/platform/ColorSuggestion.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2013 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_COLORSUGGESTION_H_ -#define SKY_ENGINE_PLATFORM_COLORSUGGESTION_H_ - -#include "sky/engine/platform/graphics/Color.h" -#include "sky/engine/wtf/text/WTFString.h" - -namespace blink { - -struct ColorSuggestion { - Color color; - String label; - - ColorSuggestion(const Color& colorValue, const String& label) - : color(colorValue) - , label(label) - { } -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_COLORSUGGESTION_H_ diff --git a/sky/engine/platform/ContentType.cpp b/sky/engine/platform/ContentType.cpp deleted file mode 100644 index 7bb5caeff82..00000000000 --- a/sky/engine/platform/ContentType.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. - * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) - * Copyright (C) 2009 Google 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 "sky/engine/platform/ContentType.h" - -namespace blink { - -ContentType::ContentType(const String& contentType) - : m_type(contentType) -{ -} - -String ContentType::parameter(const String& parameterName) const -{ - String parameterValue; - String strippedType = m_type.stripWhiteSpace(); - - // a MIME type can have one or more "param=value" after a semi-colon, and separated from each other by semi-colons - size_t semi = strippedType.find(';'); - if (semi != kNotFound) { - size_t start = strippedType.find(parameterName, semi + 1, false); - if (start != kNotFound) { - start = strippedType.find('=', start + parameterName.length()); - if (start != kNotFound) { - size_t quote = strippedType.find('\"', start + 1); - size_t end = strippedType.find('\"', start + 2); - if (quote != kNotFound && end != kNotFound) { - start = quote; - } else { - end = strippedType.find(';', start + 1); - if (end == kNotFound) - end = strippedType.length(); - } - parameterValue = strippedType.substring(start + 1, end - (start + 1)).stripWhiteSpace(); - } - } - } - - return parameterValue; -} - -String ContentType::type() const -{ - String strippedType = m_type.stripWhiteSpace(); - - // "type" can have parameters after a semi-colon, strip them - size_t semi = strippedType.find(';'); - if (semi != kNotFound) - strippedType = strippedType.left(semi).stripWhiteSpace(); - - return strippedType; -} - -Vector ContentType::codecs() const -{ - String codecsParameter = parameter("codecs"); - - if (codecsParameter.isEmpty()) - return Vector(); - - Vector codecs; - codecsParameter.split(',', codecs); - for (size_t i = 0; i < codecs.size(); ++i) - codecs[i] = codecs[i].simplifyWhiteSpace(); - - return codecs; -} - -} // namespace blink diff --git a/sky/engine/platform/ContentType.h b/sky/engine/platform/ContentType.h deleted file mode 100644 index 4faa995d839..00000000000 --- a/sky/engine/platform/ContentType.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. - * Copyright (C) 2009 Google 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 SKY_ENGINE_PLATFORM_CONTENTTYPE_H_ -#define SKY_ENGINE_PLATFORM_CONTENTTYPE_H_ - -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/text/WTFString.h" - -namespace blink { - -class PLATFORM_EXPORT ContentType { -public: - explicit ContentType(const String& type); - - String parameter(const String& parameterName) const; - String type() const; - Vector codecs() const; - const String& raw() const { return m_type; } -private: - String m_type; -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_CONTENTTYPE_H_ diff --git a/sky/engine/platform/DateComponents.cpp b/sky/engine/platform/DateComponents.cpp deleted file mode 100644 index 4a48380a5ab..00000000000 --- a/sky/engine/platform/DateComponents.cpp +++ /dev/null @@ -1,714 +0,0 @@ -/* - * Copyright (C) 2009 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 "sky/engine/platform/DateComponents.h" - -#include -#include "sky/engine/wtf/ASCIICType.h" -#include "sky/engine/wtf/DateMath.h" -#include "sky/engine/wtf/MathExtras.h" -#include "sky/engine/wtf/text/WTFString.h" - -namespace blink { - -// HTML5 specification defines minimum week of year is one. -const int DateComponents::minimumWeekNumber = 1; - -// HTML5 specification defines maximum week of year is 53. -const int DateComponents::maximumWeekNumber = 53; - -static const int maximumMonthInMaximumYear = 8; // This is September, since months are 0 based. -static const int maximumDayInMaximumMonth = 13; -static const int maximumWeekInMaximumYear = 37; // The week of 275760-09-13 - -static const int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - -// 'month' is 0-based. -static int maxDayOfMonth(int year, int month) -{ - if (month != 1) // February? - return daysInMonth[month]; - return isLeapYear(year) ? 29 : 28; -} - -// 'month' is 0-based. -static int dayOfWeek(int year, int month, int day) -{ - int shiftedMonth = month + 2; - // 2:January, 3:Feburuary, 4:March, ... - - // Zeller's congruence - if (shiftedMonth <= 3) { - shiftedMonth += 12; - year--; - } - // 4:March, ..., 14:January, 15:February - - int highYear = year / 100; - int lowYear = year % 100; - // We add 6 to make the result Sunday-origin. - int result = (day + 13 * shiftedMonth / 5 + lowYear + lowYear / 4 + highYear / 4 + 5 * highYear + 6) % 7; - return result; -} - -int DateComponents::weekDay() const -{ - return dayOfWeek(m_year, m_month, m_monthDay); -} - -int DateComponents::maxWeekNumberInYear() const -{ - int day = dayOfWeek(m_year, 0, 1); // January 1. - return day == Thursday || (day == Wednesday && isLeapYear(m_year)) ? maximumWeekNumber : maximumWeekNumber - 1; -} - -static unsigned countDigits(const String& src, unsigned start) -{ - unsigned index = start; - for (; index < src.length(); ++index) { - if (!isASCIIDigit(src[index])) - break; - } - return index - start; -} - -// Very strict integer parser. Do not allow leading or trailing whitespace unlike charactersToIntStrict(). -static bool toInt(const String& src, unsigned parseStart, unsigned parseLength, int& out) -{ - if (parseStart + parseLength > src.length() || !parseLength) - return false; - int value = 0; - unsigned current = parseStart; - unsigned end = current + parseLength; - - // We don't need to handle negative numbers for ISO 8601. - for (; current < end; ++current) { - if (!isASCIIDigit(src[current])) - return false; - int digit = src[current] - '0'; - if (value > (INT_MAX - digit) / 10) // Check for overflow. - return false; - value = value * 10 + digit; - } - out = value; - return true; -} - -bool DateComponents::parseYear(const String& src, unsigned start, unsigned& end) -{ - unsigned digitsLength = countDigits(src, start); - // Needs at least 4 digits according to the standard. - if (digitsLength < 4) - return false; - int year; - if (!toInt(src, start, digitsLength, year)) - return false; - if (year < minimumYear() || year > maximumYear()) - return false; - m_year = year; - end = start + digitsLength; - return true; -} - -static bool withinHTMLDateLimits(int year, int month) -{ - if (year < DateComponents::minimumYear()) - return false; - if (year < DateComponents::maximumYear()) - return true; - return month <= maximumMonthInMaximumYear; -} - -static bool withinHTMLDateLimits(int year, int month, int monthDay) -{ - if (year < DateComponents::minimumYear()) - return false; - if (year < DateComponents::maximumYear()) - return true; - if (month < maximumMonthInMaximumYear) - return true; - return monthDay <= maximumDayInMaximumMonth; -} - -static bool withinHTMLDateLimits(int year, int month, int monthDay, int hour, int minute, int second, int millisecond) -{ - if (year < DateComponents::minimumYear()) - return false; - if (year < DateComponents::maximumYear()) - return true; - if (month < maximumMonthInMaximumYear) - return true; - if (monthDay < maximumDayInMaximumMonth) - return true; - if (monthDay > maximumDayInMaximumMonth) - return false; - // (year, month, monthDay) = (maximumYear, maximumMonthInMaximumYear, maximumDayInMaximumMonth) - return !hour && !minute && !second && !millisecond; -} - -bool DateComponents::addDay(int dayDiff) -{ - ASSERT(m_monthDay); - - int day = m_monthDay + dayDiff; - if (day > maxDayOfMonth(m_year, m_month)) { - day = m_monthDay; - int year = m_year; - int month = m_month; - int maxDay = maxDayOfMonth(year, month); - for (; dayDiff > 0; --dayDiff) { - ++day; - if (day > maxDay) { - day = 1; - ++month; - if (month >= 12) { // month is 0-origin. - month = 0; - ++year; - } - maxDay = maxDayOfMonth(year, month); - } - } - if (!withinHTMLDateLimits(year, month, day)) - return false; - m_year = year; - m_month = month; - } else if (day < 1) { - int month = m_month; - int year = m_year; - day = m_monthDay; - for (; dayDiff < 0; ++dayDiff) { - --day; - if (day < 1) { - --month; - if (month < 0) { - month = 11; - --year; - } - day = maxDayOfMonth(year, month); - } - } - if (!withinHTMLDateLimits(year, month, day)) - return false; - m_year = year; - m_month = month; - } else { - if (!withinHTMLDateLimits(m_year, m_month, day)) - return false; - } - m_monthDay = day; - return true; -} - -bool DateComponents::addMinute(int minute) -{ - // This function is used to adjust timezone offset. So m_year, m_month, - // m_monthDay have values between the lower and higher limits. - ASSERT(withinHTMLDateLimits(m_year, m_month, m_monthDay)); - - int carry; - // minute can be negative or greater than 59. - minute += m_minute; - if (minute > 59) { - carry = minute / 60; - minute = minute % 60; - } else if (minute < 0) { - carry = (59 - minute) / 60; - minute += carry * 60; - carry = -carry; - ASSERT(minute >= 0 && minute <= 59); - } else { - if (!withinHTMLDateLimits(m_year, m_month, m_monthDay, m_hour, minute, m_second, m_millisecond)) - return false; - m_minute = minute; - return true; - } - - int hour = m_hour + carry; - if (hour > 23) { - carry = hour / 24; - hour = hour % 24; - } else if (hour < 0) { - carry = (23 - hour) / 24; - hour += carry * 24; - carry = -carry; - ASSERT(hour >= 0 && hour <= 23); - } else { - if (!withinHTMLDateLimits(m_year, m_month, m_monthDay, hour, minute, m_second, m_millisecond)) - return false; - m_minute = minute; - m_hour = hour; - return true; - } - if (!addDay(carry)) - return false; - if (!withinHTMLDateLimits(m_year, m_month, m_monthDay, hour, minute, m_second, m_millisecond)) - return false; - m_minute = minute; - m_hour = hour; - return true; -} - -// Parses a timezone part, and adjust year, month, monthDay, hour, minute, second, millisecond. -bool DateComponents::parseTimeZone(const String& src, unsigned start, unsigned& end) -{ - if (start >= src.length()) - return false; - unsigned index = start; - if (src[index] == 'Z') { - end = index + 1; - return true; - } - - bool minus; - if (src[index] == '+') - minus = false; - else if (src[index] == '-') - minus = true; - else - return false; - ++index; - - int hour; - int minute; - if (!toInt(src, index, 2, hour) || hour < 0 || hour > 23) - return false; - index += 2; - - if (index >= src.length() || src[index] != ':') - return false; - ++index; - - if (!toInt(src, index, 2, minute) || minute < 0 || minute > 59) - return false; - index += 2; - - if (minus) { - hour = -hour; - minute = -minute; - } - - // Subtract the timezone offset. - if (!addMinute(-(hour * 60 + minute))) - return false; - end = index; - return true; -} - -bool DateComponents::parseMonth(const String& src, unsigned start, unsigned& end) -{ - unsigned index; - if (!parseYear(src, start, index)) - return false; - if (index >= src.length() || src[index] != '-') - return false; - ++index; - - int month; - if (!toInt(src, index, 2, month) || month < 1 || month > 12) - return false; - --month; - if (!withinHTMLDateLimits(m_year, month)) - return false; - m_month = month; - end = index + 2; - m_type = Month; - return true; -} - -bool DateComponents::parseDate(const String& src, unsigned start, unsigned& end) -{ - unsigned index; - if (!parseMonth(src, start, index)) - return false; - // '-' and 2-digits are needed. - if (index + 2 >= src.length()) - return false; - if (src[index] != '-') - return false; - ++index; - - int day; - if (!toInt(src, index, 2, day) || day < 1 || day > maxDayOfMonth(m_year, m_month)) - return false; - if (!withinHTMLDateLimits(m_year, m_month, day)) - return false; - m_monthDay = day; - end = index + 2; - m_type = Date; - return true; -} - -bool DateComponents::parseWeek(const String& src, unsigned start, unsigned& end) -{ - unsigned index; - if (!parseYear(src, start, index)) - return false; - - // 4 characters ('-' 'W' digit digit) are needed. - if (index + 3 >= src.length()) - return false; - if (src[index] != '-') - return false; - ++index; - if (src[index] != 'W') - return false; - ++index; - - int week; - if (!toInt(src, index, 2, week) || week < minimumWeekNumber || week > maxWeekNumberInYear()) - return false; - if (m_year == maximumYear() && week > maximumWeekInMaximumYear) - return false; - m_week = week; - end = index + 2; - m_type = Week; - return true; -} - -bool DateComponents::parseTime(const String& src, unsigned start, unsigned& end) -{ - int hour; - if (!toInt(src, start, 2, hour) || hour < 0 || hour > 23) - return false; - unsigned index = start + 2; - if (index >= src.length()) - return false; - if (src[index] != ':') - return false; - ++index; - - int minute; - if (!toInt(src, index, 2, minute) || minute < 0 || minute > 59) - return false; - index += 2; - - int second = 0; - int millisecond = 0; - // Optional second part. - // Do not return with false because the part is optional. - if (index + 2 < src.length() && src[index] == ':') { - if (toInt(src, index + 1, 2, second) && second >= 0 && second <= 59) { - index += 3; - - // Optional fractional second part. - if (index < src.length() && src[index] == '.') { - unsigned digitsLength = countDigits(src, index + 1); - if (digitsLength > 0) { - ++index; - bool ok; - if (digitsLength == 1) { - ok = toInt(src, index, 1, millisecond); - millisecond *= 100; - } else if (digitsLength == 2) { - ok = toInt(src, index, 2, millisecond); - millisecond *= 10; - } else { // digitsLength >= 3 - ok = toInt(src, index, 3, millisecond); - } - ASSERT_UNUSED(ok, ok); - index += digitsLength; - } - } - } - } - m_hour = hour; - m_minute = minute; - m_second = second; - m_millisecond = millisecond; - end = index; - m_type = Time; - return true; -} - -bool DateComponents::parseDateTimeLocal(const String& src, unsigned start, unsigned& end) -{ - unsigned index; - if (!parseDate(src, start, index)) - return false; - if (index >= src.length()) - return false; - if (src[index] != 'T') - return false; - ++index; - if (!parseTime(src, index, end)) - return false; - if (!withinHTMLDateLimits(m_year, m_month, m_monthDay, m_hour, m_minute, m_second, m_millisecond)) - return false; - m_type = DateTimeLocal; - return true; -} - -bool DateComponents::parseDateTime(const String& src, unsigned start, unsigned& end) -{ - unsigned index; - if (!parseDate(src, start, index)) - return false; - if (index >= src.length()) - return false; - if (src[index] != 'T') - return false; - ++index; - if (!parseTime(src, index, index)) - return false; - if (!parseTimeZone(src, index, end)) - return false; - if (!withinHTMLDateLimits(m_year, m_month, m_monthDay, m_hour, m_minute, m_second, m_millisecond)) - return false; - m_type = DateTime; - return true; -} - -static inline double positiveFmod(double value, double divider) -{ - double remainder = fmod(value, divider); - return remainder < 0 ? remainder + divider : remainder; -} - -void DateComponents::setMillisecondsSinceMidnightInternal(double msInDay) -{ - ASSERT(msInDay >= 0 && msInDay < msPerDay); - m_millisecond = static_cast(fmod(msInDay, msPerSecond)); - double value = std::floor(msInDay / msPerSecond); - m_second = static_cast(fmod(value, secondsPerMinute)); - value = std::floor(value / secondsPerMinute); - m_minute = static_cast(fmod(value, minutesPerHour)); - m_hour = static_cast(value / minutesPerHour); -} - -bool DateComponents::setMillisecondsSinceEpochForDateInternal(double ms) -{ - m_year = msToYear(ms); - int yearDay = dayInYear(ms, m_year); - m_month = monthFromDayInYear(yearDay, isLeapYear(m_year)); - m_monthDay = dayInMonthFromDayInYear(yearDay, isLeapYear(m_year)); - return true; -} - -bool DateComponents::setMillisecondsSinceEpochForDate(double ms) -{ - m_type = Invalid; - if (!std::isfinite(ms)) - return false; - if (!setMillisecondsSinceEpochForDateInternal(round(ms))) - return false; - if (!withinHTMLDateLimits(m_year, m_month, m_monthDay)) - return false; - m_type = Date; - return true; -} - -bool DateComponents::setMillisecondsSinceEpochForDateTime(double ms) -{ - m_type = Invalid; - if (!std::isfinite(ms)) - return false; - ms = round(ms); - setMillisecondsSinceMidnightInternal(positiveFmod(ms, msPerDay)); - if (!setMillisecondsSinceEpochForDateInternal(ms)) - return false; - if (!withinHTMLDateLimits(m_year, m_month, m_monthDay, m_hour, m_minute, m_second, m_millisecond)) - return false; - m_type = DateTime; - return true; -} - -bool DateComponents::setMillisecondsSinceEpochForDateTimeLocal(double ms) -{ - // Internal representation of DateTimeLocal is the same as DateTime except m_type. - if (!setMillisecondsSinceEpochForDateTime(ms)) - return false; - m_type = DateTimeLocal; - return true; -} - -bool DateComponents::setMillisecondsSinceEpochForMonth(double ms) -{ - m_type = Invalid; - if (!std::isfinite(ms)) - return false; - if (!setMillisecondsSinceEpochForDateInternal(round(ms))) - return false; - if (!withinHTMLDateLimits(m_year, m_month)) - return false; - m_type = Month; - return true; -} - -bool DateComponents::setMillisecondsSinceMidnight(double ms) -{ - m_type = Invalid; - if (!std::isfinite(ms)) - return false; - setMillisecondsSinceMidnightInternal(positiveFmod(round(ms), msPerDay)); - m_type = Time; - return true; -} - -bool DateComponents::setMonthsSinceEpoch(double months) -{ - if (!std::isfinite(months)) - return false; - months = round(months); - double doubleMonth = positiveFmod(months, 12); - double doubleYear = 1970 + (months - doubleMonth) / 12; - if (doubleYear < minimumYear() || maximumYear() < doubleYear) - return false; - int year = static_cast(doubleYear); - int month = static_cast(doubleMonth); - if (!withinHTMLDateLimits(year, month)) - return false; - m_year = year; - m_month = month; - m_type = Month; - return true; -} - -// Offset from January 1st to Monday of the ISO 8601's first week. -// ex. If January 1st is Friday, such Monday is 3 days later. Returns 3. -static int offsetTo1stWeekStart(int year) -{ - int offsetTo1stWeekStart = 1 - dayOfWeek(year, 0, 1); - if (offsetTo1stWeekStart <= -4) - offsetTo1stWeekStart += 7; - return offsetTo1stWeekStart; -} - -bool DateComponents::setMillisecondsSinceEpochForWeek(double ms) -{ - m_type = Invalid; - if (!std::isfinite(ms)) - return false; - ms = round(ms); - - m_year = msToYear(ms); - if (m_year < minimumYear() || m_year > maximumYear()) - return false; - - int yearDay = dayInYear(ms, m_year); - int offset = offsetTo1stWeekStart(m_year); - if (yearDay < offset) { - // The day belongs to the last week of the previous year. - m_year--; - if (m_year <= minimumYear()) - return false; - m_week = maxWeekNumberInYear(); - } else { - m_week = ((yearDay - offset) / 7) + 1; - if (m_week > maxWeekNumberInYear()) { - m_year++; - m_week = 1; - } - if (m_year > maximumYear() || (m_year == maximumYear() && m_week > maximumWeekInMaximumYear)) - return false; - } - m_type = Week; - return true; -} - -double DateComponents::millisecondsSinceEpochForTime() const -{ - ASSERT(m_type == Time || m_type == DateTime || m_type == DateTimeLocal); - return ((m_hour * minutesPerHour + m_minute) * secondsPerMinute + m_second) * msPerSecond + m_millisecond; -} - -double DateComponents::millisecondsSinceEpoch() const -{ - switch (m_type) { - case Date: - return dateToDaysFrom1970(m_year, m_month, m_monthDay) * msPerDay; - case DateTime: - case DateTimeLocal: - return dateToDaysFrom1970(m_year, m_month, m_monthDay) * msPerDay + millisecondsSinceEpochForTime(); - case Month: - return dateToDaysFrom1970(m_year, m_month, 1) * msPerDay; - case Time: - return millisecondsSinceEpochForTime(); - case Week: - return (dateToDaysFrom1970(m_year, 0, 1) + offsetTo1stWeekStart(m_year) + (m_week - 1) * 7) * msPerDay; - case Invalid: - break; - } - ASSERT_NOT_REACHED(); - return invalidMilliseconds(); -} - -double DateComponents::monthsSinceEpoch() const -{ - ASSERT(m_type == Month); - return (m_year - 1970) * 12 + m_month; -} - -String DateComponents::toStringForTime(SecondFormat format) const -{ - ASSERT(m_type == DateTime || m_type == DateTimeLocal || m_type == Time); - SecondFormat effectiveFormat = format; - if (m_millisecond) - effectiveFormat = Millisecond; - else if (format == None && m_second) - effectiveFormat = Second; - - switch (effectiveFormat) { - default: - ASSERT_NOT_REACHED(); - // Fallback to None. - case None: - return String::format("%02d:%02d", m_hour, m_minute); - case Second: - return String::format("%02d:%02d:%02d", m_hour, m_minute, m_second); - case Millisecond: - return String::format("%02d:%02d:%02d.%03d", m_hour, m_minute, m_second, m_millisecond); - } -} - -String DateComponents::toString(SecondFormat format) const -{ - switch (m_type) { - case Date: - return String::format("%04d-%02d-%02d", m_year, m_month + 1, m_monthDay); - case DateTime: - return String::format("%04d-%02d-%02dT", m_year, m_month + 1, m_monthDay) - + toStringForTime(format) + String("Z"); - case DateTimeLocal: - return String::format("%04d-%02d-%02dT", m_year, m_month + 1, m_monthDay) - + toStringForTime(format); - case Month: - return String::format("%04d-%02d", m_year, m_month + 1); - case Time: - return toStringForTime(format); - case Week: - return String::format("%04d-W%02d", m_year, m_week); - case Invalid: - break; - } - ASSERT_NOT_REACHED(); - return String("(Invalid DateComponents)"); -} - -} // namespace blink diff --git a/sky/engine/platform/DateComponents.h b/sky/engine/platform/DateComponents.h deleted file mode 100644 index 8a59dd14430..00000000000 --- a/sky/engine/platform/DateComponents.h +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2009 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_DATECOMPONENTS_H_ -#define SKY_ENGINE_PLATFORM_DATECOMPONENTS_H_ - -#include -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/Forward.h" -#include "sky/engine/wtf/unicode/Unicode.h" - -namespace blink { - -// A DateComponents instance represents one of the following date and time combinations: -// * Month type: year-month -// * Date type: year-month-day -// * Week type: year-week -// * Time type: hour-minute-second-millisecond -// * DateTime or DateTimeLocal type: year-month-day hour-minute-second-millisecond -class PLATFORM_EXPORT DateComponents { -public: - DateComponents() - : m_millisecond(0) - , m_second(0) - , m_minute(0) - , m_hour(0) - , m_monthDay(0) - , m_month(0) - , m_year(0) - , m_week(0) - , m_type(Invalid) - { - } - - enum Type { - Invalid, - Date, - DateTime, - DateTimeLocal, - Month, - Time, - Week, - }; - - int millisecond() const { return m_millisecond; } - int second() const { return m_second; } - int minute() const { return m_minute; } - int hour() const { return m_hour; } - int monthDay() const { return m_monthDay; } - int weekDay() const; - int month() const { return m_month; } - int fullYear() const { return m_year; } - int week() const { return m_week; } - Type type() const { return m_type; } - - enum SecondFormat { - None, // Suppress the second part and the millisecond part if they are 0. - Second, // Always show the second part, and suppress the millisecond part if it is 0. - Millisecond // Always show the second part and the millisecond part. - }; - - // Returns an ISO 8601 representation for this instance. - // The format argument is valid for DateTime, DateTimeLocal, and Time types. - String toString(SecondFormat format = None) const; - - // parse*() and setMillisecondsSince*() functions are initializers for an - // DateComponents instance. If these functions return false, the instance - // might be invalid. - - // The following six functions parse the input 'src' whose length is - // 'length', and updates some fields of this instance. The parsing starts at - // src[start] and examines characters before src[length]. - // 'src' must be non-null. The 'src' string doesn't need to be - // null-terminated. - // The functions return true if the parsing succeeds, and set 'end' to the - // next index after the last consumed. Extra leading characters cause parse - // failures, and the trailing extra characters don't cause parse failures. - - // Sets year and month. - bool parseMonth(const String&, unsigned start, unsigned& end); - // Sets year, month and monthDay. - bool parseDate(const String&, unsigned start, unsigned& end); - // Sets year and week. - bool parseWeek(const String&, unsigned start, unsigned& end); - // Sets hour, minute, second and millisecond. - bool parseTime(const String&, unsigned start, unsigned& end); - // Sets year, month, monthDay, hour, minute, second and millisecond. - bool parseDateTimeLocal(const String&, unsigned start, unsigned& end); - // Sets year, month, monthDay, hour, minute, second and millisecond, and adjusts timezone. - bool parseDateTime(const String&, unsigned start, unsigned& end); - - // The following setMillisecondsSinceEpochFor*() functions take - // the number of milliseconds since 1970-01-01 00:00:00.000 UTC as - // the argument, and update all fields for the corresponding - // DateComponents type. The functions return true if it succeeds, and - // false if they fail. - - // For Date type. Updates m_year, m_month and m_monthDay. - bool setMillisecondsSinceEpochForDate(double ms); - // For DateTime type. Updates m_year, m_month, m_monthDay, m_hour, m_minute, m_second and m_millisecond. - bool setMillisecondsSinceEpochForDateTime(double ms); - // For DateTimeLocal type. Updates m_year, m_month, m_monthDay, m_hour, m_minute, m_second and m_millisecond. - bool setMillisecondsSinceEpochForDateTimeLocal(double ms); - // For Month type. Updates m_year and m_month. - bool setMillisecondsSinceEpochForMonth(double ms); - // For Week type. Updates m_year and m_week. - bool setMillisecondsSinceEpochForWeek(double ms); - - // For Time type. Updates m_hour, m_minute, m_second and m_millisecond. - bool setMillisecondsSinceMidnight(double ms); - - // Another initializer for Month type. Updates m_year and m_month. - bool setMonthsSinceEpoch(double months); - - // Returns the number of milliseconds from 1970-01-01 00:00:00 UTC. - // For a DateComponents initialized with parseDateTimeLocal(), - // millisecondsSinceEpoch() returns a value for UTC timezone. - double millisecondsSinceEpoch() const; - // Returns the number of months from 1970-01. - // Do not call this for types other than Month. - double monthsSinceEpoch() const; - static inline double invalidMilliseconds() { return std::numeric_limits::quiet_NaN(); } - - // Minimum and maxmimum limits for setMillisecondsSince*(), - // setMonthsSinceEpoch(), millisecondsSinceEpoch(), and monthsSinceEpoch(). - static inline double minimumDate() { return -62135596800000.0; } // 0001-01-01T00:00Z - static inline double minimumDateTime() { return -62135596800000.0; } // ditto. - static inline double minimumMonth() { return (1 - 1970) * 12.0 + 1 - 1; } // 0001-01 - static inline double minimumTime() { return 0; } // 00:00:00.000 - static inline double minimumWeek() { return -62135596800000.0; } // 0001-01-01, the first Monday of 0001. - static inline double maximumDate() { return 8640000000000000.0; } // 275760-09-13T00:00Z - static inline double maximumDateTime() { return 8640000000000000.0; } // ditto. - static inline double maximumMonth() { return (275760 - 1970) * 12.0 + 9 - 1; } // 275760-09 - static inline double maximumTime() { return 86399999; } // 23:59:59.999 - static inline double maximumWeek() { return 8639999568000000.0; } // 275760-09-08, the Monday of the week including 275760-09-13. - - // HTML5 uses ISO-8601 format with year >= 1. Gregorian calendar started in - // 1582. However, we need to support 0001-01-01 in Gregorian calendar rule. - static inline int minimumYear() { return 1; } - // Date in ECMAScript can't represent dates later than 275760-09-13T00:00Z. - // So, we have the same upper limit in HTML5 date/time types. - static inline int maximumYear() { return 275760; } - static const int minimumWeekNumber; - static const int maximumWeekNumber; - -private: - // Returns the maximum week number in this DateComponents's year. - // The result is either of 52 and 53. - int maxWeekNumberInYear() const; - bool parseYear(const String&, unsigned start, unsigned& end); - bool addDay(int); - bool addMinute(int); - bool parseTimeZone(const String&, unsigned start, unsigned& end); - // Helper for millisecondsSinceEpoch(). - double millisecondsSinceEpochForTime() const; - // Helpers for setMillisecondsSinceEpochFor*(). - bool setMillisecondsSinceEpochForDateInternal(double ms); - void setMillisecondsSinceMidnightInternal(double ms); - // Helper for toString(). - String toStringForTime(SecondFormat) const; - - // m_weekDay values - enum { - Sunday = 0, - Monday, - Tuesday, - Wednesday, - Thursday, - Friday, - Saturday, - }; - - int m_millisecond; // 0 - 999 - int m_second; - int m_minute; - int m_hour; - int m_monthDay; // 1 - 31 - int m_month; // 0:January - 11:December - int m_year; // 1582 - - int m_week; // 1 - 53 - - Type m_type; -}; - - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_DATECOMPONENTS_H_ diff --git a/sky/engine/platform/EventDispatchForbiddenScope.h b/sky/engine/platform/EventDispatchForbiddenScope.h deleted file mode 100644 index e62310548b4..00000000000 --- a/sky/engine/platform/EventDispatchForbiddenScope.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SKY_ENGINE_PLATFORM_EVENTDISPATCHFORBIDDENSCOPE_H_ -#define SKY_ENGINE_PLATFORM_EVENTDISPATCHFORBIDDENSCOPE_H_ - -#include "sky/engine/wtf/MainThread.h" -#include "sky/engine/wtf/TemporaryChange.h" - -namespace blink { - -#if ENABLE(ASSERT) - -class EventDispatchForbiddenScope { -public: - EventDispatchForbiddenScope() - { - if (!isMainThread()) - return; - ++s_count; - } - - ~EventDispatchForbiddenScope() - { - if (!isMainThread()) - return; - ASSERT(s_count); - --s_count; - } - - static bool isEventDispatchForbidden() - { - if (!isMainThread()) - return false; - return s_count; - } - - class AllowUserAgentEvents { - public: - AllowUserAgentEvents() - : m_change(s_count, 0) - { - } - - ~AllowUserAgentEvents() - { - ASSERT(!s_count); - } - - TemporaryChange m_change; - }; - -private: - static unsigned s_count; -}; - -#else - -class EventDispatchForbiddenScope { -public: - EventDispatchForbiddenScope() { } - - class AllowUserAgentEvents { - public: - AllowUserAgentEvents() { } - }; -}; - -#endif // ENABLE(ASSERT) - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_EVENTDISPATCHFORBIDDENSCOPE_H_ diff --git a/sky/engine/platform/HostWindow.h b/sky/engine/platform/HostWindow.h deleted file mode 100644 index 745b34e8d14..00000000000 --- a/sky/engine/platform/HostWindow.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2008 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 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 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 SKY_ENGINE_PLATFORM_HOSTWINDOW_H_ -#define SKY_ENGINE_PLATFORM_HOSTWINDOW_H_ - -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/FastAllocBase.h" -#include "sky/engine/wtf/Noncopyable.h" - -namespace blink { -class IntRect; - -class PLATFORM_EXPORT HostWindow { - WTF_MAKE_NONCOPYABLE(HostWindow); WTF_MAKE_FAST_ALLOCATED; -public: - HostWindow() { } - virtual ~HostWindow() { } - - // Methods for doing coordinate conversions to screen coordinates. - virtual IntRect rootViewToScreen(const IntRect&) const = 0; - - virtual void scheduleVisualUpdate() = 0; -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_HOSTWINDOW_H_ diff --git a/sky/engine/platform/JSONValues.cpp b/sky/engine/platform/JSONValues.cpp deleted file mode 100644 index 6f0164863e4..00000000000 --- a/sky/engine/platform/JSONValues.cpp +++ /dev/null @@ -1,528 +0,0 @@ -/* - * Copyright (C) 2010 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 "sky/engine/platform/JSONValues.h" - -#include "sky/engine/platform/Decimal.h" -#include "sky/engine/wtf/MathExtras.h" -#include "sky/engine/wtf/text/StringBuilder.h" - -namespace blink { - -namespace { - -const char* const nullString = "null"; -const char* const trueString = "true"; -const char* const falseString = "false"; - -inline bool escapeChar(UChar c, StringBuilder* dst) -{ - switch (c) { - case '\b': dst->appendLiteral("\\b"); break; - case '\f': dst->appendLiteral("\\f"); break; - case '\n': dst->appendLiteral("\\n"); break; - case '\r': dst->appendLiteral("\\r"); break; - case '\t': dst->appendLiteral("\\t"); break; - case '\\': dst->appendLiteral("\\\\"); break; - case '"': dst->appendLiteral("\\\""); break; - default: - return false; - } - return true; -} - -inline void doubleQuoteString(const String& str, StringBuilder* dst) -{ - dst->append('"'); - for (unsigned i = 0; i < str.length(); ++i) { - UChar c = str[i]; - if (!escapeChar(c, dst)) { - if (c < 32 || c > 126 || c == '<' || c == '>') { - // 1. Escaping <, > to prevent script execution. - // 2. Technically, we could also pass through c > 126 as UTF8, but this - // is also optional. It would also be a pain to implement here. - unsigned symbol = static_cast(c); - String symbolCode = String::format("\\u%04X", symbol); - dst->append(symbolCode); - } else { - dst->append(c); - } - } - } - dst->append('"'); -} - -void writeIndent(int depth, StringBuilder* output) -{ - for (int i = 0; i < depth; ++i) - output->appendLiteral(" "); -} - -} // anonymous namespace - -bool JSONValue::asBoolean(bool*) const -{ - return false; -} - -bool JSONValue::asNumber(double*) const -{ - return false; -} - -bool JSONValue::asNumber(long*) const -{ - return false; -} - -bool JSONValue::asNumber(int*) const -{ - return false; -} - -bool JSONValue::asNumber(unsigned long*) const -{ - return false; -} - -bool JSONValue::asNumber(unsigned*) const -{ - return false; -} - -bool JSONValue::asString(String*) const -{ - return false; -} - -bool JSONValue::asValue(RefPtr* output) -{ - *output = this; - return true; -} - -bool JSONValue::asObject(RefPtr*) -{ - return false; -} - -bool JSONValue::asArray(RefPtr*) -{ - return false; -} - -PassRefPtr JSONValue::asObject() -{ - return nullptr; -} - -PassRefPtr JSONValue::asArray() -{ - return nullptr; -} - -String JSONValue::toJSONString() const -{ - StringBuilder result; - result.reserveCapacity(512); - writeJSON(&result); - return result.toString(); -} - -String JSONValue::toPrettyJSONString() const -{ - StringBuilder result; - result.reserveCapacity(512); - prettyWriteJSON(&result); - return result.toString(); -} - -void JSONValue::writeJSON(StringBuilder* output) const -{ - ASSERT(m_type == TypeNull); - output->append(nullString, 4); -} - -void JSONValue::prettyWriteJSON(StringBuilder* output) const -{ - prettyWriteJSONInternal(output, 0); - output->append('\n'); -} - -void JSONValue::prettyWriteJSONInternal(StringBuilder* output, int depth) const -{ - writeJSON(output); -} - -bool JSONBasicValue::asBoolean(bool* output) const -{ - if (type() != TypeBoolean) - return false; - *output = m_boolValue; - return true; -} - -bool JSONBasicValue::asNumber(double* output) const -{ - if (type() != TypeNumber) - return false; - *output = m_doubleValue; - return true; -} - -bool JSONBasicValue::asNumber(long* output) const -{ - if (type() != TypeNumber) - return false; - *output = static_cast(m_doubleValue); - return true; -} - -bool JSONBasicValue::asNumber(int* output) const -{ - if (type() != TypeNumber) - return false; - *output = static_cast(m_doubleValue); - return true; -} - -bool JSONBasicValue::asNumber(unsigned long* output) const -{ - if (type() != TypeNumber) - return false; - *output = static_cast(m_doubleValue); - return true; -} - -bool JSONBasicValue::asNumber(unsigned* output) const -{ - if (type() != TypeNumber) - return false; - *output = static_cast(m_doubleValue); - return true; -} - -void JSONBasicValue::writeJSON(StringBuilder* output) const -{ - ASSERT(type() == TypeBoolean || type() == TypeNumber); - if (type() == TypeBoolean) { - if (m_boolValue) - output->append(trueString, 4); - else - output->append(falseString, 5); - } else if (type() == TypeNumber) { - if (!std::isfinite(m_doubleValue)) { - output->append(nullString, 4); - return; - } - output->append(Decimal::fromDouble(m_doubleValue).toString()); - } -} - -bool JSONString::asString(String* output) const -{ - *output = m_stringValue; - return true; -} - -void JSONString::writeJSON(StringBuilder* output) const -{ - ASSERT(type() == TypeString); - doubleQuoteString(m_stringValue, output); -} - -JSONObjectBase::~JSONObjectBase() -{ -} - -bool JSONObjectBase::asObject(RefPtr* output) -{ - COMPILE_ASSERT(sizeof(JSONObject) == sizeof(JSONObjectBase), cannot_cast); - *output = static_cast(this); - return true; -} - -PassRefPtr JSONObjectBase::asObject() -{ - return openAccessors(); -} - -void JSONObjectBase::setBoolean(const String& name, bool value) -{ - setValue(name, JSONBasicValue::create(value)); -} - -void JSONObjectBase::setNumber(const String& name, double value) -{ - setValue(name, JSONBasicValue::create(value)); -} - -void JSONObjectBase::setString(const String& name, const String& value) -{ - setValue(name, JSONString::create(value)); -} - -void JSONObjectBase::setValue(const String& name, PassRefPtr value) -{ - ASSERT(value); - if (m_data.set(name, value).isNewEntry) - m_order.append(name); -} - -void JSONObjectBase::setObject(const String& name, PassRefPtr value) -{ - ASSERT(value); - if (m_data.set(name, value).isNewEntry) - m_order.append(name); -} - -void JSONObjectBase::setArray(const String& name, PassRefPtr value) -{ - ASSERT(value); - if (m_data.set(name, value).isNewEntry) - m_order.append(name); -} - -JSONObject* JSONObjectBase::openAccessors() -{ - COMPILE_ASSERT(sizeof(JSONObject) == sizeof(JSONObjectBase), cannot_cast); - return static_cast(this); -} - -JSONObjectBase::iterator JSONObjectBase::find(const String& name) -{ - return m_data.find(name); -} - -JSONObjectBase::const_iterator JSONObjectBase::find(const String& name) const -{ - return m_data.find(name); -} - -bool JSONObjectBase::getBoolean(const String& name, bool* output) const -{ - RefPtr value = get(name); - if (!value) - return false; - return value->asBoolean(output); -} - -bool JSONObjectBase::getString(const String& name, String* output) const -{ - RefPtr value = get(name); - if (!value) - return false; - return value->asString(output); -} - -PassRefPtr JSONObjectBase::getObject(const String& name) const -{ - RefPtr value = get(name); - if (!value) - return nullptr; - return value->asObject(); -} - -PassRefPtr JSONObjectBase::getArray(const String& name) const -{ - RefPtr value = get(name); - if (!value) - return nullptr; - return value->asArray(); -} - -PassRefPtr JSONObjectBase::get(const String& name) const -{ - Dictionary::const_iterator it = m_data.find(name); - if (it == m_data.end()) - return nullptr; - return it->value; -} - -void JSONObjectBase::remove(const String& name) -{ - m_data.remove(name); - for (size_t i = 0; i < m_order.size(); ++i) { - if (m_order[i] == name) { - m_order.remove(i); - break; - } - } -} - -void JSONObjectBase::writeJSON(StringBuilder* output) const -{ - output->append('{'); - for (size_t i = 0; i < m_order.size(); ++i) { - Dictionary::const_iterator it = m_data.find(m_order[i]); - ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end()); - if (i) - output->append(','); - doubleQuoteString(it->key, output); - output->append(':'); - it->value->writeJSON(output); - } - output->append('}'); -} - -void JSONObjectBase::prettyWriteJSONInternal(StringBuilder* output, int depth) const -{ - output->appendLiteral("{\n"); - for (size_t i = 0; i < m_order.size(); ++i) { - Dictionary::const_iterator it = m_data.find(m_order[i]); - ASSERT_WITH_SECURITY_IMPLICATION(it != m_data.end()); - if (i) - output->appendLiteral(",\n"); - writeIndent(depth + 1, output); - doubleQuoteString(it->key, output); - output->appendLiteral(": "); - it->value->prettyWriteJSONInternal(output, depth + 1); - } - output->append('\n'); - writeIndent(depth, output); - output->append('}'); -} - -JSONObjectBase::JSONObjectBase() - : JSONValue(TypeObject) - , m_data() - , m_order() -{ -} - -JSONArrayBase::~JSONArrayBase() -{ -} - -bool JSONArrayBase::asArray(RefPtr* output) -{ - COMPILE_ASSERT(sizeof(JSONArrayBase) == sizeof(JSONArray), cannot_cast); - *output = static_cast(this); - return true; -} - -PassRefPtr JSONArrayBase::asArray() -{ - COMPILE_ASSERT(sizeof(JSONArrayBase) == sizeof(JSONArray), cannot_cast); - return static_cast(this); -} - -void JSONArrayBase::writeJSON(StringBuilder* output) const -{ - output->append('['); - for (Vector >::const_iterator it = m_data.begin(); it != m_data.end(); ++it) { - if (it != m_data.begin()) - output->append(','); - (*it)->writeJSON(output); - } - output->append(']'); -} - -void JSONArrayBase::prettyWriteJSONInternal(StringBuilder* output, int depth) const -{ - output->append('['); - bool lastIsArrayOrObject = false; - for (Vector >::const_iterator it = m_data.begin(); it != m_data.end(); ++it) { - bool isArrayOrObject = (*it)->type() == JSONValue::TypeObject || (*it)->type() == JSONValue::TypeArray; - if (it == m_data.begin()) { - if (isArrayOrObject) { - output->append('\n'); - writeIndent(depth + 1, output); - } - } else { - output->append(','); - if (lastIsArrayOrObject) { - output->append('\n'); - writeIndent(depth + 1, output); - } else { - output->append(' '); - } - } - (*it)->prettyWriteJSONInternal(output, depth + 1); - lastIsArrayOrObject = isArrayOrObject; - } - if (lastIsArrayOrObject) { - output->append('\n'); - writeIndent(depth, output); - } - output->append(']'); -} - -JSONArrayBase::JSONArrayBase() - : JSONValue(TypeArray) - , m_data() -{ -} - -void JSONArrayBase::pushBoolean(bool value) -{ - m_data.append(JSONBasicValue::create(value)); -} - -void JSONArrayBase::pushInt(int value) -{ - m_data.append(JSONBasicValue::create(value)); -} - -void JSONArrayBase::pushNumber(double value) -{ - m_data.append(JSONBasicValue::create(value)); -} - -void JSONArrayBase::pushString(const String& value) -{ - m_data.append(JSONString::create(value)); -} - -void JSONArrayBase::pushValue(PassRefPtr value) -{ - ASSERT(value); - m_data.append(value); -} - -void JSONArrayBase::pushObject(PassRefPtr value) -{ - ASSERT(value); - m_data.append(value); -} - -void JSONArrayBase::pushArray(PassRefPtr value) -{ - ASSERT(value); - m_data.append(value); -} - -PassRefPtr JSONArrayBase::get(size_t index) -{ - ASSERT_WITH_SECURITY_IMPLICATION(index < m_data.size()); - return m_data[index]; -} - -} // namespace blink diff --git a/sky/engine/platform/JSONValues.h b/sky/engine/platform/JSONValues.h deleted file mode 100644 index 4f634a35e25..00000000000 --- a/sky/engine/platform/JSONValues.h +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (C) 2009 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_JSONVALUES_H_ -#define SKY_ENGINE_PLATFORM_JSONVALUES_H_ - -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/Forward.h" -#include "sky/engine/wtf/HashMap.h" -#include "sky/engine/wtf/RefCounted.h" -#include "sky/engine/wtf/Vector.h" -#include "sky/engine/wtf/text/StringHash.h" -#include "sky/engine/wtf/text/WTFString.h" - -namespace blink { - -class JSONArray; -class JSONObject; - -class PLATFORM_EXPORT JSONValue : public RefCounted { -public: - static const int maxDepth = 1000; - - JSONValue() : m_type(TypeNull) { } - virtual ~JSONValue() { } - - static PassRefPtr null() - { - return adoptRef(new JSONValue()); - } - - typedef enum { - TypeNull = 0, - TypeBoolean, - TypeNumber, - TypeString, - TypeObject, - TypeArray - } Type; - - Type type() const { return m_type; } - - bool isNull() const { return m_type == TypeNull; } - - virtual bool asBoolean(bool* output) const; - virtual bool asNumber(double* output) const; - virtual bool asNumber(long* output) const; - virtual bool asNumber(int* output) const; - virtual bool asNumber(unsigned long* output) const; - virtual bool asNumber(unsigned* output) const; - virtual bool asString(String* output) const; - virtual bool asValue(RefPtr* output); - virtual bool asObject(RefPtr* output); - virtual bool asArray(RefPtr* output); - virtual PassRefPtr asObject(); - virtual PassRefPtr asArray(); - - String toJSONString() const; - String toPrettyJSONString() const; - virtual void writeJSON(StringBuilder* output) const; - virtual void prettyWriteJSON(StringBuilder* output) const; - -protected: - explicit JSONValue(Type type) : m_type(type) { } - virtual void prettyWriteJSONInternal(StringBuilder* output, int depth) const; - -private: - friend class JSONObjectBase; - friend class JSONArrayBase; - - Type m_type; -}; - -class PLATFORM_EXPORT JSONBasicValue : public JSONValue { -public: - - static PassRefPtr create(bool value) - { - return adoptRef(new JSONBasicValue(value)); - } - - static PassRefPtr create(int value) - { - return adoptRef(new JSONBasicValue(value)); - } - - static PassRefPtr create(double value) - { - return adoptRef(new JSONBasicValue(value)); - } - - virtual bool asBoolean(bool* output) const override; - virtual bool asNumber(double* output) const override; - virtual bool asNumber(long* output) const override; - virtual bool asNumber(int* output) const override; - virtual bool asNumber(unsigned long* output) const override; - virtual bool asNumber(unsigned* output) const override; - - virtual void writeJSON(StringBuilder* output) const override; - -private: - explicit JSONBasicValue(bool value) : JSONValue(TypeBoolean), m_boolValue(value) { } - explicit JSONBasicValue(int value) : JSONValue(TypeNumber), m_doubleValue((double)value) { } - explicit JSONBasicValue(double value) : JSONValue(TypeNumber), m_doubleValue(value) { } - - union { - bool m_boolValue; - double m_doubleValue; - }; -}; - -class PLATFORM_EXPORT JSONString : public JSONValue { -public: - static PassRefPtr create(const String& value) - { - return adoptRef(new JSONString(value)); - } - - static PassRefPtr create(const char* value) - { - return adoptRef(new JSONString(value)); - } - - virtual bool asString(String* output) const override; - - virtual void writeJSON(StringBuilder* output) const override; - -private: - explicit JSONString(const String& value) : JSONValue(TypeString), m_stringValue(value) { } - explicit JSONString(const char* value) : JSONValue(TypeString), m_stringValue(value) { } - - String m_stringValue; -}; - -class PLATFORM_EXPORT JSONObjectBase : public JSONValue { -private: - typedef HashMap > Dictionary; - -public: - typedef Dictionary::iterator iterator; - typedef Dictionary::const_iterator const_iterator; - - virtual PassRefPtr asObject() override; - JSONObject* openAccessors(); - - virtual void writeJSON(StringBuilder* output) const override; - -protected: - virtual ~JSONObjectBase(); - - virtual bool asObject(RefPtr* output) override; - - void setBoolean(const String& name, bool); - void setNumber(const String& name, double); - void setString(const String& name, const String&); - void setValue(const String& name, PassRefPtr); - void setObject(const String& name, PassRefPtr); - void setArray(const String& name, PassRefPtr); - - iterator find(const String& name); - const_iterator find(const String& name) const; - bool getBoolean(const String& name, bool* output) const; - template bool getNumber(const String& name, T* output) const - { - RefPtr value = get(name); - if (!value) - return false; - return value->asNumber(output); - } - bool getString(const String& name, String* output) const; - PassRefPtr getObject(const String& name) const; - PassRefPtr getArray(const String& name) const; - PassRefPtr get(const String& name) const; - - void remove(const String& name); - - virtual void prettyWriteJSONInternal(StringBuilder* output, int depth) const override; - - iterator begin() { return m_data.begin(); } - iterator end() { return m_data.end(); } - const_iterator begin() const { return m_data.begin(); } - const_iterator end() const { return m_data.end(); } - - int size() const { return m_data.size(); } - -protected: - JSONObjectBase(); - -private: - Dictionary m_data; - Vector m_order; -}; - -class PLATFORM_EXPORT JSONObject : public JSONObjectBase { -public: - static PassRefPtr create() - { - return adoptRef(new JSONObject()); - } - - using JSONObjectBase::asObject; - - using JSONObjectBase::setBoolean; - using JSONObjectBase::setNumber; - using JSONObjectBase::setString; - using JSONObjectBase::setValue; - using JSONObjectBase::setObject; - using JSONObjectBase::setArray; - - using JSONObjectBase::find; - using JSONObjectBase::getBoolean; - using JSONObjectBase::getNumber; - using JSONObjectBase::getString; - using JSONObjectBase::getObject; - using JSONObjectBase::getArray; - using JSONObjectBase::get; - - using JSONObjectBase::remove; - - using JSONObjectBase::begin; - using JSONObjectBase::end; - - using JSONObjectBase::size; -}; - - -class PLATFORM_EXPORT JSONArrayBase : public JSONValue { -public: - typedef Vector >::iterator iterator; - typedef Vector >::const_iterator const_iterator; - - virtual PassRefPtr asArray() override; - - unsigned length() const { return m_data.size(); } - - virtual void writeJSON(StringBuilder* output) const override; - -protected: - virtual ~JSONArrayBase(); - - virtual bool asArray(RefPtr* output) override; - - void pushBoolean(bool); - void pushInt(int); - void pushNumber(double); - void pushString(const String&); - void pushValue(PassRefPtr); - void pushObject(PassRefPtr); - void pushArray(PassRefPtr); - - PassRefPtr get(size_t index); - - virtual void prettyWriteJSONInternal(StringBuilder* output, int depth) const override; - - iterator begin() { return m_data.begin(); } - iterator end() { return m_data.end(); } - const_iterator begin() const { return m_data.begin(); } - const_iterator end() const { return m_data.end(); } - -protected: - JSONArrayBase(); - -private: - Vector > m_data; -}; - -class PLATFORM_EXPORT JSONArray : public JSONArrayBase { -public: - static PassRefPtr create() - { - return adoptRef(new JSONArray()); - } - - using JSONArrayBase::asArray; - - using JSONArrayBase::pushBoolean; - using JSONArrayBase::pushInt; - using JSONArrayBase::pushNumber; - using JSONArrayBase::pushString; - using JSONArrayBase::pushValue; - using JSONArrayBase::pushObject; - using JSONArrayBase::pushArray; - - using JSONArrayBase::get; - - using JSONArrayBase::begin; - using JSONArrayBase::end; -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_JSONVALUES_H_ diff --git a/sky/engine/platform/KeyboardCodes.h b/sky/engine/platform/KeyboardCodes.h deleted file mode 100644 index 7e2ad2b6ea9..00000000000 --- a/sky/engine/platform/KeyboardCodes.h +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (c) 2008, 2009, Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_KEYBOARDCODES_H_ -#define SKY_ENGINE_PLATFORM_KEYBOARDCODES_H_ - -#include "sky/engine/platform/WindowsKeyboardCodes.h" - -namespace blink { - -enum { - // VKEY_LBUTTON (01) Left mouse button - // VKEY_RBUTTON (02) Right mouse button - // VKEY_CANCEL (03) Control-break processing - // VKEY_MBUTTON (04) Middle mouse button (three-button mouse) - // VKEY_XBUTTON1 (05) - // VKEY_XBUTTON2 (06) - - // VKEY_BACK (08) BACKSPACE key - VKEY_BACK = VK_BACK, - - // VKEY_TAB (09) TAB key - VKEY_TAB = VK_TAB, - - // VKEY_CLEAR (0C) CLEAR key - VKEY_CLEAR = VK_CLEAR, - - // VKEY_RETURN (0D) - VKEY_RETURN = VK_RETURN, - - // VKEY_SHIFT (10) SHIFT key - VKEY_SHIFT = VK_SHIFT, - - // VKEY_CONTROL (11) CTRL key - VKEY_CONTROL = VK_CONTROL, - - // VKEY_MENU (12) ALT key - VKEY_MENU = VK_MENU, - - // VKEY_PAUSE (13) PAUSE key - VKEY_PAUSE = VK_PAUSE, - - // VKEY_CAPITAL (14) CAPS LOCK key - VKEY_CAPITAL = VK_CAPITAL, - - // VKEY_KANA (15) Input Method Editor (IME) Kana mode - VKEY_KANA = VK_KANA, - - // VKEY_HANGUEL (15) IME Hanguel mode (maintained for compatibility, use VKEY_HANGUL) - // VKEY_HANGUL (15) IME Hangul mode - VKEY_HANGUL = VK_HANGUL, - - // VKEY_JUNJA (17) IME Junja mode - VKEY_JUNJA = VK_JUNJA, - - // VKEY_FINAL (18) IME final mode - VKEY_FINAL = VK_FINAL, - - // VKEY_HANJA (19) IME Hanja mode - VKEY_HANJA = VK_HANJA, - - // VKEY_KANJI (19) IME Kanji mode - VKEY_KANJI = VK_KANJI, - - // VKEY_ESCAPE (1B) ESC key - VKEY_ESCAPE = VK_ESCAPE, - - // VKEY_CONVERT (1C) IME convert - VKEY_CONVERT = VK_CONVERT, - - // VKEY_NONCONVERT (1D) IME nonconvert - VKEY_NONCONVERT = VK_NONCONVERT, - - // VKEY_ACCEPT (1E) IME accept - VKEY_ACCEPT = VK_ACCEPT, - - // VKEY_MODECHANGE (1F) IME mode change request - VKEY_MODECHANGE = VK_MODECHANGE, - - // VKEY_SPACE (20) SPACEBAR - VKEY_SPACE = VK_SPACE, - - // VKEY_PRIOR (21) PAGE UP key - VKEY_PRIOR = VK_PRIOR, - - // VKEY_NEXT (22) PAGE DOWN key - VKEY_NEXT = VK_NEXT, - - // VKEY_END (23) END key - VKEY_END = VK_END, - - // VKEY_HOME (24) HOME key - VKEY_HOME = VK_HOME, - - // VKEY_LEFT (25) LEFT ARROW key - VKEY_LEFT = VK_LEFT, - - // VKEY_UP (26) UP ARROW key - VKEY_UP = VK_UP, - - // VKEY_RIGHT (27) RIGHT ARROW key - VKEY_RIGHT = VK_RIGHT, - - // VKEY_DOWN (28) DOWN ARROW key - VKEY_DOWN = VK_DOWN, - - // VKEY_SELECT (29) SELECT key - VKEY_SELECT = VK_SELECT, - - // VKEY_PRINT (2A) PRINT key - VKEY_PRINT = VK_PRINT, - - // VKEY_EXECUTE (2B) EXECUTE key - VKEY_EXECUTE = VK_EXECUTE, - - // VKEY_SNAPSHOT (2C) PRINT SCREEN key - VKEY_SNAPSHOT = VK_SNAPSHOT, - - // VKEY_INSERT (2D) INS key - VKEY_INSERT = VK_INSERT, - - // VKEY_DELETE (2E) DEL key - VKEY_DELETE = VK_DELETE, - - // VKEY_HELP (2F) HELP key - VKEY_HELP = VK_HELP, - - // (30) 0 key - VKEY_0 = '0', - - // (31) 1 key - VKEY_1 = '1', - - // (32) 2 key - VKEY_2 = '2', - - // (33) 3 key - VKEY_3 = '3', - - // (34) 4 key - VKEY_4 = '4', - - // (35) 5 key, - - VKEY_5 = '5', - - // (36) 6 key - VKEY_6 = '6', - - // (37) 7 key - VKEY_7 = '7', - - // (38) 8 key - VKEY_8 = '8', - - // (39) 9 key - VKEY_9 = '9', - - // (41) A key - VKEY_A = 'A', - - // (42) B key - VKEY_B = 'B', - - // (43) C key - VKEY_C = 'C', - - // (44) D key - VKEY_D = 'D', - - // (45) E key - VKEY_E = 'E', - - // (46) F key - VKEY_F = 'F', - - // (47) G key - VKEY_G = 'G', - - // (48) H key - VKEY_H = 'H', - - // (49) I key - VKEY_I = 'I', - - // (4A) J key - VKEY_J = 'J', - - // (4B) K key - VKEY_K = 'K', - - // (4C) L key - VKEY_L = 'L', - - // (4D) M key - VKEY_M = 'M', - - // (4E) N key - VKEY_N = 'N', - - // (4F) O key - VKEY_O = 'O', - - // (50) P key - VKEY_P = 'P', - - // (51) Q key - VKEY_Q = 'Q', - - // (52) R key - VKEY_R = 'R', - - // (53) S key - VKEY_S = 'S', - - // (54) T key - VKEY_T = 'T', - - // (55) U key - VKEY_U = 'U', - - // (56) V key - VKEY_V = 'V', - - // (57) W key - VKEY_W = 'W', - - // (58) X key - VKEY_X = 'X', - - // (59) Y key - VKEY_Y = 'Y', - - // (5A) Z key - VKEY_Z = 'Z', - - // VKEY_LWIN (5B) Left Windows key (Microsoft Natural keyboard) - VKEY_LWIN = VK_LWIN, - - // VKEY_RWIN (5C) Right Windows key (Natural keyboard) - VKEY_RWIN = VK_RWIN, - - // VKEY_APPS (5D) Applications key (Natural keyboard) - VKEY_APPS = VK_APPS, - - // VKEY_SLEEP (5F) Computer Sleep key - VKEY_SLEEP = VK_SLEEP, - - // VKEY_NUMPAD0 (60) Numeric keypad 0 key - VKEY_NUMPAD0 = VK_NUMPAD0, - - // VKEY_NUMPAD1 (61) Numeric keypad 1 key - VKEY_NUMPAD1 = VK_NUMPAD1, - - // VKEY_NUMPAD2 (62) Numeric keypad 2 key - VKEY_NUMPAD2 = VK_NUMPAD2, - - // VKEY_NUMPAD3 (63) Numeric keypad 3 key - VKEY_NUMPAD3 = VK_NUMPAD3, - - // VKEY_NUMPAD4 (64) Numeric keypad 4 key - VKEY_NUMPAD4 = VK_NUMPAD4, - - // VKEY_NUMPAD5 (65) Numeric keypad 5 key - VKEY_NUMPAD5 = VK_NUMPAD5, - - // VKEY_NUMPAD6 (66) Numeric keypad 6 key - VKEY_NUMPAD6 = VK_NUMPAD6, - - // VKEY_NUMPAD7 (67) Numeric keypad 7 key - VKEY_NUMPAD7 = VK_NUMPAD7, - - // VKEY_NUMPAD8 (68) Numeric keypad 8 key - VKEY_NUMPAD8 = VK_NUMPAD8, - - // VKEY_NUMPAD9 (69) Numeric keypad 9 key - VKEY_NUMPAD9 = VK_NUMPAD9, - - // VKEY_MULTIPLY (6A) Multiply key - VKEY_MULTIPLY = VK_MULTIPLY, - - // VKEY_ADD (6B) Add key - VKEY_ADD = VK_ADD, - - // VKEY_SEPARATOR (6C) Separator key - VKEY_SEPARATOR = VK_SEPARATOR, - - // VKEY_SUBTRACT (6D) Subtract key - VKEY_SUBTRACT = VK_SUBTRACT, - - // VKEY_DECIMAL (6E) Decimal key - VKEY_DECIMAL = VK_DECIMAL, - - // VKEY_DIVIDE (6F) Divide key - VKEY_DIVIDE = VK_DIVIDE, - - // VKEY_F1 (70) F1 key - VKEY_F1 = VK_F1, - - // VKEY_F2 (71) F2 key - VKEY_F2 = VK_F2, - - // VKEY_F3 (72) F3 key - VKEY_F3 = VK_F3, - - // VKEY_F4 (73) F4 key - VKEY_F4 = VK_F4, - - // VKEY_F5 (74) F5 key - VKEY_F5 = VK_F5, - - // VKEY_F6 (75) F6 key - VKEY_F6 = VK_F6, - - // VKEY_F7 (76) F7 key - VKEY_F7 = VK_F7, - - // VKEY_F8 (77) F8 key - VKEY_F8 = VK_F8, - - // VKEY_F9 (78) F9 key - VKEY_F9 = VK_F9, - - // VKEY_F10 (79) F10 key - VKEY_F10 = VK_F10, - - // VKEY_F11 (7A) F11 key - VKEY_F11 = VK_F11, - - // VKEY_F12 (7B) F12 key - VKEY_F12 = VK_F12, - - // VKEY_F13 (7C) F13 key - VKEY_F13 = VK_F13, - - // VKEY_F14 (7D) F14 key - VKEY_F14 = VK_F14, - - // VKEY_F15 (7E) F15 key - VKEY_F15 = VK_F15, - - // VKEY_F16 (7F) F16 key - VKEY_F16 = VK_F16, - - // VKEY_F17 (80H) F17 key - VKEY_F17 = VK_F17, - - // VKEY_F18 (81H) F18 key - VKEY_F18 = VK_F18, - - // VKEY_F19 (82H) F19 key - VKEY_F19 = VK_F19, - - // VKEY_F20 (83H) F20 key - VKEY_F20 = VK_F20, - - // VKEY_F21 (84H) F21 key - VKEY_F21 = VK_F21, - - // VKEY_F22 (85H) F22 key - VKEY_F22 = VK_F22, - - // VKEY_F23 (86H) F23 key - VKEY_F23 = VK_F23, - - // VKEY_F24 (87H) F24 key - VKEY_F24 = VK_F24, - - // VKEY_NUMLOCK (90) NUM LOCK key - VKEY_NUMLOCK = VK_NUMLOCK, - - // VKEY_SCROLL (91) SCROLL LOCK key - VKEY_SCROLL = VK_SCROLL, - - // VKEY_LSHIFT (A0) Left SHIFT key - VKEY_LSHIFT = VK_LSHIFT, - - // VKEY_RSHIFT (A1) Right SHIFT key - VKEY_RSHIFT = VK_RSHIFT, - - // VKEY_LCONTROL (A2) Left CONTROL key - VKEY_LCONTROL = VK_LCONTROL, - - // VKEY_RCONTROL (A3) Right CONTROL key - VKEY_RCONTROL = VK_RCONTROL, - - // VKEY_LMENU (A4) Left MENU key - VKEY_LMENU = VK_LMENU, - - // VKEY_RMENU (A5) Right MENU key - VKEY_RMENU = VK_RMENU, - - // VKEY_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key - VKEY_BROWSER_BACK = VK_BROWSER_BACK, - - // VKEY_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key - VKEY_BROWSER_FORWARD = VK_BROWSER_FORWARD, - - // VKEY_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key - VKEY_BROWSER_REFRESH = VK_BROWSER_REFRESH, - - // VKEY_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key - VKEY_BROWSER_STOP = VK_BROWSER_STOP, - - // VKEY_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key - VKEY_BROWSER_SEARCH = VK_BROWSER_SEARCH, - - // VKEY_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key - VKEY_BROWSER_FAVORITES = VK_BROWSER_FAVORITES, - - // VKEY_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key - VKEY_BROWSER_HOME = VK_BROWSER_HOME, - - // VKEY_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key - VKEY_VOLUME_MUTE = VK_VOLUME_MUTE, - - // VKEY_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key - VKEY_VOLUME_DOWN = VK_VOLUME_DOWN, - - // VKEY_VOLUME_UP (AF) Windows 2000/XP: Volume Up key - VKEY_VOLUME_UP = VK_VOLUME_UP, - - // VKEY_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key - VKEY_MEDIA_NEXT_TRACK = VK_MEDIA_NEXT_TRACK, - - // VKEY_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key - VKEY_MEDIA_PREV_TRACK = VK_MEDIA_PREV_TRACK, - - // VKEY_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key - VKEY_MEDIA_STOP = VK_MEDIA_STOP, - - // VKEY_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key - VKEY_MEDIA_PLAY_PAUSE = VK_MEDIA_PLAY_PAUSE, - - // VKEY_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key - VKEY_MEDIA_LAUNCH_MAIL = 0xB4, - - // VKEY_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key - VKEY_MEDIA_LAUNCH_MEDIA_SELECT = 0xB5, - - // VKEY_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key - VKEY_MEDIA_LAUNCH_APP1 = 0xB6, - - // VKEY_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key - VKEY_MEDIA_LAUNCH_APP2 = 0xB7, - - // VKEY_OEM_1 (BA) Used for miscellaneous characters, it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ',:' key - VKEY_OEM_1 = VK_OEM_1, - - // VKEY_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key - VKEY_OEM_PLUS = VK_OEM_PLUS, - - // VKEY_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key - VKEY_OEM_COMMA = VK_OEM_COMMA, - - // VKEY_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key - VKEY_OEM_MINUS = VK_OEM_MINUS, - - // VKEY_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key - VKEY_OEM_PERIOD = VK_OEM_PERIOD, - - // VKEY_OEM_2 (BF) Used for miscellaneous characters, it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key - VKEY_OEM_2 = VK_OEM_2, - - // VKEY_OEM_3 (C0) Used for miscellaneous characters, it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key - VKEY_OEM_3 = VK_OEM_3, - - // VKEY_OEM_4 (DB) Used for miscellaneous characters, it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key - VKEY_OEM_4 = VK_OEM_4, - - // VKEY_OEM_5 (DC) Used for miscellaneous characters, it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key - VKEY_OEM_5 = VK_OEM_5, - - // VKEY_OEM_6 (DD) Used for miscellaneous characters, it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key - VKEY_OEM_6 = VK_OEM_6, - - // VKEY_OEM_7 (DE) Used for miscellaneous characters, it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key - VKEY_OEM_7 = VK_OEM_7, - - // VKEY_OEM_8 (DF) Used for miscellaneous characters, it can vary by keyboard. - VKEY_OEM_8 = VK_OEM_8, - - // VKEY_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard - VKEY_OEM_102 = VK_OEM_102, - - // VKEY_OEM_103 (E3) GTV KEYCODE_MEDIA_REWIND - VKEY_OEM_103 = 0xE3, - - // VKEY_OEM_104 (E4) GTV KEYCODE_MEDIA_FAST_FORWARD - VKEY_OEM_104 = 0xE4, - - // VKEY_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key - VKEY_PROCESSKEY = VK_PROCESSKEY, - - // VKEY_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VKEY_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP - VKEY_PACKET = VK_PACKET, - - // VKEY_ATTN (F6) Attn key - VKEY_ATTN = VK_ATTN, - - // VKEY_CRSEL (F7) CrSel key - VKEY_CRSEL = VK_CRSEL, - - // VKEY_EXSEL (F8) ExSel key - VKEY_EXSEL = VK_EXSEL, - - // VKEY_EREOF (F9) Erase EOF key - VKEY_EREOF = VK_EREOF, - - // VKEY_PLAY (FA) Play key - VKEY_PLAY = VK_PLAY, - - // VKEY_ZOOM (FB) Zoom key - VKEY_ZOOM = VK_ZOOM, - - // VKEY_NONAME (FC) Reserved for future use - VKEY_NONAME = VK_NONAME, - - // VKEY_PA1 (FD) PA1 key - VKEY_PA1 = VK_PA1, - - // VKEY_OEM_CLEAR (FE) Clear key - VKEY_OEM_CLEAR = VK_OEM_CLEAR, - - VKEY_UNKNOWN = 0 -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_KEYBOARDCODES_H_ diff --git a/sky/engine/platform/MIMETypeRegistry.cpp b/sky/engine/platform/MIMETypeRegistry.cpp deleted file mode 100644 index 6babce06c19..00000000000 --- a/sky/engine/platform/MIMETypeRegistry.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2008, 2009, Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 "sky/engine/platform/MIMETypeRegistry.h" - -#include "sky/engine/wtf/text/CString.h" - -namespace blink { - -bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType) -{ - if (equalIgnoringCase(mimeType, "image/jpeg") || equalIgnoringCase(mimeType, "image/png")) - return true; - if (equalIgnoringCase(mimeType, "image/webp")) - return true; - return false; -} - -} // namespace blink diff --git a/sky/engine/platform/MIMETypeRegistry.h b/sky/engine/platform/MIMETypeRegistry.h deleted file mode 100644 index dac28b95999..00000000000 --- a/sky/engine/platform/MIMETypeRegistry.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 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 SKY_ENGINE_PLATFORM_MIMETYPEREGISTRY_H_ -#define SKY_ENGINE_PLATFORM_MIMETYPEREGISTRY_H_ - -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/HashSet.h" -#include "sky/engine/wtf/text/StringHash.h" -#include "sky/engine/wtf/text/WTFString.h" - -namespace blink { - -class PLATFORM_EXPORT MIMETypeRegistry { -public: - // Check to see if a mime type is suitable for being encoded. - static bool isSupportedImageMIMETypeForEncoding(const String& mimeType); -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_MIMETYPEREGISTRY_H_ diff --git a/sky/engine/platform/ParsingUtilities.h b/sky/engine/platform/ParsingUtilities.h deleted file mode 100644 index 39266731616..00000000000 --- a/sky/engine/platform/ParsingUtilities.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2013 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_PARSINGUTILITIES_H_ -#define SKY_ENGINE_PLATFORM_PARSINGUTILITIES_H_ - -template -bool skipExactly(const CharType*& position, const CharType* end, CharType delimiter) -{ - if (position < end && *position == delimiter) { - ++position; - return true; - } - return false; -} - -template -bool skipExactly(const CharType*& position, const CharType* end) -{ - if (position < end && characterPredicate(*position)) { - ++position; - return true; - } - return false; -} - -template -void skipUntil(const CharType*& position, const CharType* end, CharType delimiter) -{ - while (position < end && *position != delimiter) - ++position; -} - -template -void skipUntil(const CharType*& position, const CharType* end) -{ - while (position < end && !characterPredicate(*position)) - ++position; -} - -template -void skipWhile(const CharType*& position, const CharType* end) -{ - while (position < end && characterPredicate(*position)) - ++position; -} - -template -void reverseSkipWhile(const CharType*& position, const CharType* start) -{ - while (position >= start && characterPredicate(*position)) - --position; -} - -#endif // SKY_ENGINE_PLATFORM_PARSINGUTILITIES_H_ - diff --git a/sky/engine/platform/RefCountedSupplement.h b/sky/engine/platform/RefCountedSupplement.h deleted file mode 100644 index 7d60b4cef0b..00000000000 --- a/sky/engine/platform/RefCountedSupplement.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 Google, 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 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 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 SKY_ENGINE_PLATFORM_REFCOUNTEDSUPPLEMENT_H_ -#define SKY_ENGINE_PLATFORM_REFCOUNTEDSUPPLEMENT_H_ - -#include "sky/engine/platform/Supplementable.h" -#include "sky/engine/wtf/RefCounted.h" -#include "sky/engine/wtf/RefPtr.h" - -namespace blink { - -#if !ENABLE(OILPAN) -template -class RefCountedSupplement : public RefCounted { -public: - typedef RefCountedSupplement ThisType; - - virtual ~RefCountedSupplement() { } - - class Wrapper final : public Supplement { - public: - explicit Wrapper(PassRefPtr wrapped) : m_wrapped(wrapped) { } - virtual ~Wrapper() { } -#if ENABLE(SECURITY_ASSERT) - virtual bool isRefCountedWrapper() const override { return true; } -#endif - ThisType* wrapped() const { return m_wrapped.get(); } - - private: - - RefPtr m_wrapped; - }; - - static void provideTo(Supplementable& host, const char* key, PassRefPtr supplement) - { - host.provideSupplement(key, adoptPtr(new Wrapper(supplement))); - } - - static ThisType* from(Supplementable& host, const char* key) - { - Supplement* found = static_cast*>(host.requireSupplement(key)); - if (!found) - return 0; - ASSERT_WITH_SECURITY_IMPLICATION(found->isRefCountedWrapper()); - return static_cast(found)->wrapped(); - } -}; -#endif - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_REFCOUNTEDSUPPLEMENT_H_ diff --git a/sky/engine/platform/ScriptForbiddenScope.cpp b/sky/engine/platform/ScriptForbiddenScope.cpp deleted file mode 100644 index 9dbec1d9393..00000000000 --- a/sky/engine/platform/ScriptForbiddenScope.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sky/engine/platform/ScriptForbiddenScope.h" - -#include "sky/engine/wtf/Assertions.h" -#include "sky/engine/wtf/MainThread.h" - -namespace blink { - -static unsigned s_scriptForbiddenCount = 0; - -ScriptForbiddenScope::ScriptForbiddenScope() -{ - ASSERT(isMainThread()); - ++s_scriptForbiddenCount; -} - -ScriptForbiddenScope::~ScriptForbiddenScope() -{ - ASSERT(isMainThread()); - ASSERT(s_scriptForbiddenCount); - --s_scriptForbiddenCount; -} - -void ScriptForbiddenScope::enter() -{ - ASSERT(isMainThread()); - ++s_scriptForbiddenCount; -} - -void ScriptForbiddenScope::exit() -{ - ASSERT(isMainThread()); - ASSERT(s_scriptForbiddenCount); - --s_scriptForbiddenCount; -} - -bool ScriptForbiddenScope::isScriptForbidden() -{ - return isMainThread() && s_scriptForbiddenCount; -} - -ScriptForbiddenScope::AllowUserAgentScript::AllowUserAgentScript() - : m_change(s_scriptForbiddenCount, 0) -{ -} - -ScriptForbiddenScope::AllowUserAgentScript::~AllowUserAgentScript() -{ - ASSERT(!s_scriptForbiddenCount); -} - -} // namespace blink diff --git a/sky/engine/platform/ScriptForbiddenScope.h b/sky/engine/platform/ScriptForbiddenScope.h deleted file mode 100644 index 2e3cf06dc9f..00000000000 --- a/sky/engine/platform/ScriptForbiddenScope.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SKY_ENGINE_PLATFORM_SCRIPTFORBIDDENSCOPE_H_ -#define SKY_ENGINE_PLATFORM_SCRIPTFORBIDDENSCOPE_H_ - -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/Assertions.h" -#include "sky/engine/wtf/TemporaryChange.h" - -namespace blink { - -class PLATFORM_EXPORT ScriptForbiddenScope { -public: - ScriptForbiddenScope(); - ~ScriptForbiddenScope(); - - class PLATFORM_EXPORT AllowUserAgentScript { - public: - AllowUserAgentScript(); - ~AllowUserAgentScript(); - private: - TemporaryChange m_change; - }; - - static void enter(); - static void exit(); - static bool isScriptForbidden(); -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_SCRIPTFORBIDDENSCOPE_H_ diff --git a/sky/engine/platform/SharedBufferChunkReader.cpp b/sky/engine/platform/SharedBufferChunkReader.cpp deleted file mode 100644 index b331d7cb48c..00000000000 --- a/sky/engine/platform/SharedBufferChunkReader.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2011 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 "sky/engine/platform/SharedBufferChunkReader.h" - -#include "sky/engine/platform/SharedBuffer.h" - -namespace blink { - -SharedBufferChunkReader::SharedBufferChunkReader(SharedBuffer* buffer, const Vector& separator) - : m_buffer(buffer) - , m_bufferPosition(0) - , m_segment(0) - , m_segmentLength(0) - , m_segmentIndex(0) - , m_reachedEndOfFile(false) - , m_separator(separator) - , m_separatorIndex(0) -{ -} - -SharedBufferChunkReader::SharedBufferChunkReader(SharedBuffer* buffer, const char* separator) - : m_buffer(buffer) - , m_bufferPosition(0) - , m_segment(0) - , m_segmentLength(0) - , m_segmentIndex(0) - , m_reachedEndOfFile(false) - , m_separatorIndex(0) -{ - setSeparator(separator); -} - -void SharedBufferChunkReader::setSeparator(const Vector& separator) -{ - m_separator = separator; -} - -void SharedBufferChunkReader::setSeparator(const char* separator) -{ - m_separator.clear(); - m_separator.append(separator, strlen(separator)); -} - -bool SharedBufferChunkReader::nextChunk(Vector& chunk, bool includeSeparator) -{ - if (m_reachedEndOfFile) - return false; - - chunk.clear(); - while (true) { - while (m_segmentIndex < m_segmentLength) { - char currentCharacter = m_segment[m_segmentIndex++]; - if (currentCharacter != m_separator[m_separatorIndex]) { - if (m_separatorIndex > 0) { - ASSERT_WITH_SECURITY_IMPLICATION(m_separatorIndex <= m_separator.size()); - chunk.append(m_separator.data(), m_separatorIndex); - m_separatorIndex = 0; - } - chunk.append(currentCharacter); - continue; - } - m_separatorIndex++; - if (m_separatorIndex == m_separator.size()) { - if (includeSeparator) - chunk.appendVector(m_separator); - m_separatorIndex = 0; - return true; - } - } - - // Read the next segment. - m_segmentIndex = 0; - m_bufferPosition += m_segmentLength; - m_segmentLength = m_buffer->getSomeData(m_segment, m_bufferPosition); - if (!m_segmentLength) { - m_reachedEndOfFile = true; - if (m_separatorIndex > 0) - chunk.append(m_separator.data(), m_separatorIndex); - return !chunk.isEmpty(); - } - } - ASSERT_NOT_REACHED(); - return false; -} - -String SharedBufferChunkReader::nextChunkAsUTF8StringWithLatin1Fallback(bool includeSeparator) -{ - Vector data; - if (!nextChunk(data, includeSeparator)) - return String(); - - return data.size() ? String::fromUTF8WithLatin1Fallback(data.data(), data.size()) : emptyString(); -} - -size_t SharedBufferChunkReader::peek(Vector& data, size_t requestedSize) -{ - data.clear(); - if (requestedSize <= m_segmentLength - m_segmentIndex) { - data.append(m_segment + m_segmentIndex, requestedSize); - return requestedSize; - } - - size_t readBytesCount = m_segmentLength - m_segmentIndex; - data.append(m_segment + m_segmentIndex, readBytesCount); - - size_t bufferPosition = m_bufferPosition + m_segmentLength; - const char* segment = 0; - while (size_t segmentLength = m_buffer->getSomeData(segment, bufferPosition)) { - if (requestedSize <= readBytesCount + segmentLength) { - data.append(segment, requestedSize - readBytesCount); - readBytesCount += (requestedSize - readBytesCount); - break; - } - data.append(segment, segmentLength); - readBytesCount += segmentLength; - bufferPosition += segmentLength; - } - return readBytesCount; -} - -} diff --git a/sky/engine/platform/SharedBufferChunkReader.h b/sky/engine/platform/SharedBufferChunkReader.h deleted file mode 100644 index 46eb503bca9..00000000000 --- a/sky/engine/platform/SharedBufferChunkReader.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2011 Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_SHAREDBUFFERCHUNKREADER_H_ -#define SKY_ENGINE_PLATFORM_SHAREDBUFFERCHUNKREADER_H_ - -#include "sky/engine/platform/PlatformExport.h" -#include "sky/engine/wtf/Vector.h" -#include "sky/engine/wtf/text/WTFString.h" - -namespace blink { - -class SharedBuffer; - -class PLATFORM_EXPORT SharedBufferChunkReader { -public: - SharedBufferChunkReader(SharedBuffer*, const Vector& separator); - SharedBufferChunkReader(SharedBuffer*, const char* separator); - - void setSeparator(const Vector&); - void setSeparator(const char*); - - // Returns false when the end of the buffer was reached. - bool nextChunk(Vector& data, bool includeSeparator = false); - - // Returns a null string when the end of the buffer has been reached. - String nextChunkAsUTF8StringWithLatin1Fallback(bool includeSeparator = false); - - // Reads size bytes at the current location in the buffer, without changing the buffer position. - // Returns the number of bytes read. That number might be less than the specified size if the end of the buffer was reached. - size_t peek(Vector&, size_t); - -private: - SharedBuffer* m_buffer; - size_t m_bufferPosition; - const char* m_segment; - size_t m_segmentLength; - size_t m_segmentIndex; - bool m_reachedEndOfFile; - Vector m_separator; - size_t m_separatorIndex; -}; - -} - -#endif // SKY_ENGINE_PLATFORM_SHAREDBUFFERCHUNKREADER_H_ diff --git a/sky/engine/platform/Supplementable.h b/sky/engine/platform/Supplementable.h deleted file mode 100644 index 52479ab34ad..00000000000 --- a/sky/engine/platform/Supplementable.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2012 Google, 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 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 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 SKY_ENGINE_PLATFORM_SUPPLEMENTABLE_H_ -#define SKY_ENGINE_PLATFORM_SUPPLEMENTABLE_H_ - -#include "sky/engine/platform/heap/Handle.h" -#include "sky/engine/wtf/Assertions.h" -#include "sky/engine/wtf/HashMap.h" -#include "sky/engine/wtf/OwnPtr.h" -#include "sky/engine/wtf/PassOwnPtr.h" - -#if ENABLE(ASSERT) -#include "sky/engine/wtf/Threading.h" -#endif - -namespace blink { - -// What you should know about Supplementable and Supplement -// ======================================================== -// Supplementable and Supplement instances are meant to be thread local. They -// should only be accessed from within the thread that created them. The -// 2 classes are not designed for safe access from another thread. Violating -// this design assumption can result in memory corruption and unpredictable -// behavior. -// -// What you should know about the Supplement keys -// ============================================== -// The Supplement is expected to use the same const char* string instance -// as its key. The Supplementable's SupplementMap will use the address of the -// string as the key and not the characters themselves. Hence, 2 strings with -// the same characters will be treated as 2 different keys. -// -// In practice, it is recommended that Supplements implements a static method -// for returning its key to use. For example: -// -// class MyClass : public Supplement { -// ... -// static const char* supplementName(); -// } -// -// const char* MyClass::supplementName() -// { -// return "MyClass"; -// } -// -// An example of the using the key: -// -// MyClass* MyClass::from(MySupplementable* host) -// { -// return reinterpret_cast(Supplement::from(host, supplementName())); -// } -// -// What you should know about thread checks -// ======================================== -// When assertion is enabled this class performs thread-safety check so that -// provideTo and from happen on the same thread. If you want to provide -// some value for Workers this thread check may not work very well though, -// since in most case you'd provide the value while worker preparation is -// being done on the main thread, even before the worker thread is started. -// If that's the case you can explicitly call reattachThread() when the -// Supplementable object is passed to the final destination thread (i.e. -// worker thread). Please be extremely careful to use the method though, -// as randomly calling the method could easily cause racy condition. -// -// Note that reattachThread() does nothing if assertion is not enabled. -// - -template -class SupplementBase; - -template -class SupplementableBase; - -template -struct SupplementableTraits; - -template -struct SupplementableTraits { - typedef PassOwnPtr > SupplementArgumentType; - typedef HashMap >, PtrHash > SupplementMap; -}; - -template -class SupplementTracing; - -template<> -class SupplementTracing { -public: - virtual ~SupplementTracing() { } -}; - -template -class SupplementBase : public SupplementTracing { -public: -#if ENABLE(SECURITY_ASSERT) - virtual bool isRefCountedWrapper() const { return false; } -#endif - - static void provideTo(SupplementableBase& host, const char* key, typename SupplementableTraits::SupplementArgumentType supplement) - { - host.provideSupplement(key, supplement); - } - - static SupplementBase* from(SupplementableBase& host, const char* key) - { - return host.requireSupplement(key); - } - - static SupplementBase* from(SupplementableBase* host, const char* key) - { - return host ? host->requireSupplement(key) : 0; - } -}; - -// Helper class for implementing Supplementable, HeapSupplementable, and -// PersistentHeapSupplementable. -template -class SupplementableBase { -public: - void provideSupplement(const char* key, typename SupplementableTraits::SupplementArgumentType supplement) - { - ASSERT(m_threadId == currentThread()); - ASSERT(!this->m_supplements.get(key)); - this->m_supplements.set(key, supplement); - } - - void removeSupplement(const char* key) - { - ASSERT(m_threadId == currentThread()); - this->m_supplements.remove(key); - } - - SupplementBase* requireSupplement(const char* key) - { - ASSERT(m_threadId == currentThread()); - return this->m_supplements.get(key); - } - - void reattachThread() - { -#if ENABLE(ASSERT) - m_threadId = currentThread(); -#endif - } - - // We have a trace method in the SupplementableBase class to ensure we have - // the vtable at the first word of the object. However we don't trace the - // m_supplements here, but in the partially specialized template subclasses - // since we only want to trace it for garbage collected classes. - - // FIXME: Oilpan: Make private and remove this ignore once PersistentHeapSupplementable is removed again. -protected: - typename SupplementableTraits::SupplementMap m_supplements; - -#if ENABLE(ASSERT) -protected: - SupplementableBase() : m_threadId(currentThread()) { } - -private: - ThreadIdentifier m_threadId; -#endif -}; - - -template -class Supplement : public SupplementBase { }; - -// This class is used to make an off-heap class supplementable with off-heap -// supplements (Supplement). -template -class Supplementable : public SupplementableBase { -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_SUPPLEMENTABLE_H_ diff --git a/sky/engine/platform/WindowsKeyboardCodes.h b/sky/engine/platform/WindowsKeyboardCodes.h deleted file mode 100644 index 237b91670f9..00000000000 --- a/sky/engine/platform/WindowsKeyboardCodes.h +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (C) 2010 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 INC. AND ITS CONTRIBUTORS "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 INC. OR ITS 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 VK_UNKNOWN - -#define VK_UNKNOWN 0 - -// Left mouse button -// Right mouse button -// Control-break processing -// Middle mouse button (three-button mouse) -// VK_XBUTTON1 (05) -// VK_XBUTTON2 (06) - -#ifndef VK_BACK -#define VK_BACK 0x08 -#endif -#ifndef VK_TAB -#define VK_TAB 0x09 -#endif -#ifndef VK_CLEAR -#define VK_CLEAR 0x0C -#endif -#ifndef VK_RETURN -#define VK_RETURN 0x0D -#endif -#ifndef VK_SHIFT -#define VK_SHIFT 0x10 -#endif -#ifndef VK_CONTROL -#define VK_CONTROL 0x11 // CTRL key -#endif -#ifndef VK_MENU -#define VK_MENU 0x12 // ALT key -#endif -#ifndef VK_PAUSE -#define VK_PAUSE 0x13 // PAUSE key -#endif -#ifndef VK_CAPITAL -#define VK_CAPITAL 0x14 // CAPS LOCK key -#endif -#ifndef VK_KANA -#define VK_KANA 0x15 // Input Method Editor (IME) Kana mode -#endif -#ifndef VK_HANGUL -#define VK_HANGUL 0x15 // IME Hangul mode -#endif -#ifndef VK_JUNJA -#define VK_JUNJA 0x17 // IME Junja mode -#endif -#ifndef VK_FINAL -#define VK_FINAL 0x18 // IME final mode -#endif -#ifndef VK_HANJA -#define VK_HANJA 0x19 // IME Hanja mode -#endif -#ifndef VK_KANJI -#define VK_KANJI 0x19 // IME Kanji mode -#endif -#ifndef VK_ESCAPE -#define VK_ESCAPE 0x1B // ESC key -#endif -#ifndef VK_CONVERT -#define VK_CONVERT 0x1C // IME convert -#endif -#ifndef VK_NONCONVERT -#define VK_NONCONVERT 0x1D // IME nonconvert -#endif -#ifndef VK_ACCEPT -#define VK_ACCEPT 0x1E // IME accept -#endif -#ifndef VK_MODECHANGE -#define VK_MODECHANGE 0x1F // IME mode change request -#endif -#ifndef VK_SPACE -#define VK_SPACE 0x20 // SPACE key -#endif -#ifndef VK_PRIOR -#define VK_PRIOR 0x21 // PAGE UP key -#endif -#ifndef VK_NEXT -#define VK_NEXT 0x22 // PAGE DOWN key -#endif -#ifndef VK_END -#define VK_END 0x23 // END key -#endif -#ifndef VK_HOME -#define VK_HOME 0x24 // HOME key -#endif -#ifndef VK_LEFT -#define VK_LEFT 0x25 // LEFT ARROW key -#endif -#ifndef VK_UP -#define VK_UP 0x26 // UP ARROW key -#endif -#ifndef VK_RIGHT -#define VK_RIGHT 0x27 // RIGHT ARROW key -#endif -#ifndef VK_DOWN -#define VK_DOWN 0x28 // DOWN ARROW key -#endif -#ifndef VK_SELECT -#define VK_SELECT 0x29 // SELECT key -#endif -#ifndef VK_PRINT -#define VK_PRINT 0x2A // PRINT key -#endif -#ifndef VK_EXECUTE -#define VK_EXECUTE 0x2B // EXECUTE key -#endif -#ifndef VK_SNAPSHOT -#define VK_SNAPSHOT 0x2C // PRINT SCREEN key -#endif -#ifndef VK_INSERT -#define VK_INSERT 0x2D // INS key -#endif -#ifndef VK_DELETE -#define VK_DELETE 0x2E // DEL key -#endif -#ifndef VK_HELP -#define VK_HELP 0x2F // HELP key -#endif - -#define VK_0 0x30 -#define VK_1 0x31 -#define VK_2 0x32 -#define VK_3 0x33 -#define VK_4 0x34 -#define VK_5 0x35 -#define VK_6 0x36 -#define VK_7 0x37 -#define VK_8 0x38 -#define VK_9 0x39 -#define VK_A 0x41 -#define VK_B 0x42 -#define VK_C 0x43 -#define VK_D 0x44 -#define VK_E 0x45 -#define VK_F 0x46 -#define VK_G 0x47 -#define VK_H 0x48 -#define VK_I 0x49 -#define VK_J 0x4A -#define VK_K 0x4B -#define VK_L 0x4C -#define VK_M 0x4D -#define VK_N 0x4E -#define VK_O 0x4F -#define VK_P 0x50 -#define VK_Q 0x51 -#define VK_R 0x52 -#define VK_S 0x53 -#define VK_T 0x54 -#define VK_U 0x55 -#define VK_V 0x56 -#define VK_W 0x57 -#define VK_X 0x58 -#define VK_Y 0x59 -#define VK_Z 0x5A - -#define VK_LWIN 0x5B // Left Windows key (Microsoft Natural keyboard) - -#define VK_RWIN 0x5C // Right Windows key (Natural keyboard) - -#define VK_APPS 0x5D // Applications key (Natural keyboard) - -#define VK_SLEEP 0x5F // Computer Sleep key - -// Num pad keys -#define VK_NUMPAD0 0x60 -#define VK_NUMPAD1 0x61 -#define VK_NUMPAD2 0x62 -#define VK_NUMPAD3 0x63 -#define VK_NUMPAD4 0x64 -#define VK_NUMPAD5 0x65 -#define VK_NUMPAD6 0x66 -#define VK_NUMPAD7 0x67 -#define VK_NUMPAD8 0x68 -#define VK_NUMPAD9 0x69 -#define VK_MULTIPLY 0x6A -#define VK_ADD 0x6B -#define VK_SEPARATOR 0x6C -#define VK_SUBTRACT 0x6D -#define VK_DECIMAL 0x6E -#define VK_DIVIDE 0x6F - -#define VK_F1 0x70 -#define VK_F2 0x71 -#define VK_F3 0x72 -#define VK_F4 0x73 -#define VK_F5 0x74 -#define VK_F6 0x75 -#define VK_F7 0x76 -#define VK_F8 0x77 -#define VK_F9 0x78 -#define VK_F10 0x79 -#define VK_F11 0x7A -#define VK_F12 0x7B -#define VK_F13 0x7C -#define VK_F14 0x7D -#define VK_F15 0x7E -#define VK_F16 0x7F -#define VK_F17 0x80 -#define VK_F18 0x81 -#define VK_F19 0x82 -#define VK_F20 0x83 -#define VK_F21 0x84 -#define VK_F22 0x85 -#define VK_F23 0x86 -#define VK_F24 0x87 - -#define VK_NUMLOCK 0x90 -#define VK_SCROLL 0x91 -#define VK_LSHIFT 0xA0 -#define VK_RSHIFT 0xA1 -#define VK_LCONTROL 0xA2 -#define VK_RCONTROL 0xA3 -#define VK_LMENU 0xA4 -#define VK_RMENU 0xA5 - -#define VK_BROWSER_BACK 0xA6 // Windows 2000/XP: Browser Back key -#define VK_BROWSER_FORWARD 0xA7 // Windows 2000/XP: Browser Forward key -#define VK_BROWSER_REFRESH 0xA8 // Windows 2000/XP: Browser Refresh key -#define VK_BROWSER_STOP 0xA9 // Windows 2000/XP: Browser Stop key -#define VK_BROWSER_SEARCH 0xAA // Windows 2000/XP: Browser Search key -#define VK_BROWSER_FAVORITES 0xAB // Windows 2000/XP: Browser Favorites key -#define VK_BROWSER_HOME 0xAC // Windows 2000/XP: Browser Start and Home key -#define VK_VOLUME_MUTE 0xAD // Windows 2000/XP: Volume Mute key -#define VK_VOLUME_DOWN 0xAE // Windows 2000/XP: Volume Down key -#define VK_VOLUME_UP 0xAF // Windows 2000/XP: Volume Up key -#define VK_MEDIA_NEXT_TRACK 0xB0 // Windows 2000/XP: Next Track key -#define VK_MEDIA_PREV_TRACK 0xB1 // Windows 2000/XP: Previous Track key -#define VK_MEDIA_STOP 0xB2 // Windows 2000/XP: Stop Media key -#define VK_MEDIA_PLAY_PAUSE 0xB3 // Windows 2000/XP: Play/Pause Media key -#define VK_MEDIA_LAUNCH_MAIL 0xB4 // Windows 2000/XP: Start Mail key -#define VK_MEDIA_LAUNCH_MEDIA_SELECT 0xB5 // Windows 2000/XP: Select Media key -#define VK_MEDIA_LAUNCH_APP1 0xB6 // VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key -#define VK_MEDIA_LAUNCH_APP2 0xB7 // VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key - -// VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key -#define VK_OEM_1 0xBA - -// Windows 2000/XP: For any country/region, the '+' key -#define VK_OEM_PLUS 0xBB - -// Windows 2000/XP: For any country/region, the ',' key -#define VK_OEM_COMMA 0xBC - -// Windows 2000/XP: For any country/region, the '-' key -#define VK_OEM_MINUS 0xBD - -// Windows 2000/XP: For any country/region, the '.' key -#define VK_OEM_PERIOD 0xBE - -// VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key -#define VK_OEM_2 0xBF - -// VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key -#define VK_OEM_3 0xC0 - -// VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key -#define VK_OEM_4 0xDB - -// VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key -#define VK_OEM_5 0xDC - -// VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key -#define VK_OEM_6 0xDD - -// VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key -#define VK_OEM_7 0xDE - -// VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard. -#define VK_OEM_8 0xDF - -// VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard -#define VK_OEM_102 0xE2 - -// Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key -#define VK_PROCESSKEY 0xE5 - -// Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP -#define VK_PACKET 0xE7 - -#define VK_ATTN 0xF6 // Attn key -#define VK_CRSEL 0xF7 // CrSel key -#define VK_EXSEL 0xF8 // ExSel key -#define VK_EREOF 0xF9 // Erase EOF key -#define VK_PLAY 0xFA // Play key -#define VK_ZOOM 0xFB // Zoom key - -#define VK_NONAME 0xFC // Reserved for future use - -#define VK_PA1 0xFD // VK_PA1 (FD) PA1 key - -#define VK_OEM_CLEAR 0xFE // Clear key - -#endif // VK_UNKNOWN diff --git a/sky/engine/platform/graphics/Image.cpp b/sky/engine/platform/graphics/Image.cpp index a4d0d859aea..61209631dd7 100644 --- a/sky/engine/platform/graphics/Image.cpp +++ b/sky/engine/platform/graphics/Image.cpp @@ -27,7 +27,6 @@ #include "sky/engine/platform/graphics/Image.h" #include "sky/engine/platform/Length.h" -#include "sky/engine/platform/MIMETypeRegistry.h" #include "sky/engine/platform/SharedBuffer.h" #include "sky/engine/platform/TraceEvent.h" #include "sky/engine/platform/geometry/FloatPoint.h" diff --git a/sky/engine/platform/graphics/ImageBuffer.cpp b/sky/engine/platform/graphics/ImageBuffer.cpp index dbfa19b2acc..709b511011a 100644 --- a/sky/engine/platform/graphics/ImageBuffer.cpp +++ b/sky/engine/platform/graphics/ImageBuffer.cpp @@ -32,9 +32,6 @@ #include "sky/engine/platform/graphics/ImageBuffer.h" -#include "platform/image-encoders/skia/JPEGImageEncoder.h" -#include "platform/image-encoders/skia/PNGImageEncoder.h" -#include "sky/engine/platform/MIMETypeRegistry.h" #include "sky/engine/platform/geometry/IntRect.h" #include "sky/engine/platform/graphics/BitmapImage.h" #include "sky/engine/platform/graphics/GraphicsContext.h" @@ -48,7 +45,6 @@ #include "sky/engine/public/platform/WebGraphicsContext3DProvider.h" #include "sky/engine/wtf/MathExtras.h" #include "sky/engine/wtf/Vector.h" -#include "sky/engine/wtf/text/Base64.h" #include "sky/engine/wtf/text/WTFString.h" #include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/effects/SkTableColorFilter.h" @@ -307,51 +303,4 @@ void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, c context()->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); } -template -static bool encodeImage(T& source, const String& mimeType, const double* quality, Vector* output) -{ - Vector* encodedImage = reinterpret_cast*>(output); - - if (mimeType == "image/jpeg") { - int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; - if (quality && *quality >= 0.0 && *quality <= 1.0) - compressionQuality = static_cast(*quality * 100 + 0.5); - if (!JPEGImageEncoder::encode(source, compressionQuality, encodedImage)) - return false; - } else { - if (!PNGImageEncoder::encode(source, encodedImage)) - return false; - ASSERT(mimeType == "image/png"); - } - - return true; -} - -String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const -{ - ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); - - Vector encodedImage; - if (!isSurfaceValid() || !encodeImage(m_surface->bitmap(), mimeType, quality, &encodedImage)) - return "data:,"; - Vector base64Data; - base64Encode(encodedImage, base64Data); - - return "data:" + mimeType + ";base64," + base64Data; -} - -String ImageDataToDataURL(const ImageDataBuffer& imageData, const String& mimeType, const double* quality) -{ - ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); - - Vector encodedImage; - if (!encodeImage(imageData, mimeType, quality, &encodedImage)) - return "data:,"; - - Vector base64Data; - base64Encode(encodedImage, base64Data); - - return "data:" + mimeType + ";base64," + base64Data; -} - } // namespace blink diff --git a/sky/engine/platform/graphics/ImageBuffer.h b/sky/engine/platform/graphics/ImageBuffer.h index fdb4ce38529..6bf5243b576 100644 --- a/sky/engine/platform/graphics/ImageBuffer.h +++ b/sky/engine/platform/graphics/ImageBuffer.h @@ -101,7 +101,6 @@ public: void putByteArray(Multiply, Uint8ClampedArray*, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint); - String toDataURL(const String& mimeType, const double* quality = 0) const; AffineTransform baseTransform() const { return AffineTransform(); } void transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace); WebLayer* platformLayer() const; @@ -137,8 +136,6 @@ struct ImageDataBuffer { RefPtr m_data; }; -String PLATFORM_EXPORT ImageDataToDataURL(const ImageDataBuffer&, const String& mimeType, const double* quality); - } // namespace blink #endif // SKY_ENGINE_PLATFORM_GRAPHICS_IMAGEBUFFER_H_ diff --git a/sky/engine/platform/image-encoders/skia/JPEGImageEncoder.cpp b/sky/engine/platform/image-encoders/skia/JPEGImageEncoder.cpp deleted file mode 100644 index 0fc1d44ae42..00000000000 --- a/sky/engine/platform/image-encoders/skia/JPEGImageEncoder.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) 2010, Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 "platform/image-encoders/skia/JPEGImageEncoder.h" - -#include "sky/engine/platform/geometry/IntSize.h" -#include "sky/engine/platform/graphics/ImageBuffer.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "third_party/skia/include/core/SkColorPriv.h" -extern "C" { -#include -#include // jpeglib.h needs stdio.h FILE -#include "jpeglib.h" -} - -namespace blink { - -struct JPEGOutputBuffer : public jpeg_destination_mgr { - Vector* output; - Vector buffer; -}; - -static void prepareOutput(j_compress_ptr cinfo) -{ - JPEGOutputBuffer* out = static_cast(cinfo->dest); - const size_t internalBufferSize = 8192; - out->buffer.resize(internalBufferSize); - out->next_output_byte = out->buffer.data(); - out->free_in_buffer = out->buffer.size(); -} - -static boolean writeOutput(j_compress_ptr cinfo) -{ - JPEGOutputBuffer* out = static_cast(cinfo->dest); - out->output->append(out->buffer.data(), out->buffer.size()); - out->next_output_byte = out->buffer.data(); - out->free_in_buffer = out->buffer.size(); - return TRUE; -} - -static void finishOutput(j_compress_ptr cinfo) -{ - JPEGOutputBuffer* out = static_cast(cinfo->dest); - const size_t size = out->buffer.size() - out->free_in_buffer; - out->output->append(out->buffer.data(), size); -} - -static void handleError(j_common_ptr common) -{ - jmp_buf* jumpBufferPtr = static_cast(common->client_data); - longjmp(*jumpBufferPtr, -1); -} - -static void preMultipliedBGRAtoRGB(const unsigned char* pixels, unsigned pixelCount, unsigned char* output) -{ - const SkPMColor* input = reinterpret_cast_ptr(pixels); - for (; pixelCount-- > 0; ++input) { - *output++ = SkGetPackedR32(*input); - *output++ = SkGetPackedG32(*input); - *output++ = SkGetPackedB32(*input); - } -} - -static void RGBAtoRGB(const unsigned char* pixels, unsigned pixelCount, unsigned char* output) -{ - for (; pixelCount-- > 0; pixels += 4) { - // Do source-over composition on black. - unsigned char alpha = pixels[3]; - if (alpha != 255) { - *output++ = SkMulDiv255Round(pixels[0], alpha); - *output++ = SkMulDiv255Round(pixels[1], alpha); - *output++ = SkMulDiv255Round(pixels[2], alpha); - } else { - *output++ = pixels[0]; - *output++ = pixels[1]; - *output++ = pixels[2]; - } - } -} - -static void disableSubsamplingForHighQuality(jpeg_compress_struct* cinfo, int quality) -{ - if (quality < 100) - return; - - for (int i = 0; i < MAX_COMPONENTS; ++i) { - cinfo->comp_info[i].h_samp_factor = 1; - cinfo->comp_info[i].v_samp_factor = 1; - } -} - -static bool encodePixels(IntSize imageSize, unsigned char* inputPixels, bool premultiplied, int quality, Vector* output) -{ - JPEGOutputBuffer destination; - destination.output = output; - Vector row; - - jpeg_compress_struct cinfo; - jpeg_error_mgr error; - cinfo.err = jpeg_std_error(&error); - error.error_exit = handleError; - jmp_buf jumpBuffer; - cinfo.client_data = &jumpBuffer; - - if (setjmp(jumpBuffer)) { - jpeg_destroy_compress(&cinfo); - return false; - } - - jpeg_create_compress(&cinfo); - cinfo.dest = &destination; - cinfo.dest->init_destination = prepareOutput; - cinfo.dest->empty_output_buffer = writeOutput; - cinfo.dest->term_destination = finishOutput; - - imageSize.clampNegativeToZero(); - cinfo.image_height = imageSize.height(); - cinfo.image_width = imageSize.width(); - -#if defined(JCS_EXTENSIONS) - if (premultiplied) { - cinfo.in_color_space = SK_B32_SHIFT ? JCS_EXT_RGBX : JCS_EXT_BGRX; - - cinfo.input_components = 4; - - jpeg_set_defaults(&cinfo); - jpeg_set_quality(&cinfo, quality, TRUE); - disableSubsamplingForHighQuality(&cinfo, quality); - jpeg_start_compress(&cinfo, TRUE); - - unsigned char* pixels = inputPixels; - const size_t pixelRowStride = cinfo.image_width * 4; - while (cinfo.next_scanline < cinfo.image_height) { - jpeg_write_scanlines(&cinfo, &pixels, 1); - pixels += pixelRowStride; - } - - jpeg_finish_compress(&cinfo); - jpeg_destroy_compress(&cinfo); - return true; - } -#endif - - cinfo.in_color_space = JCS_RGB; - cinfo.input_components = 3; - - void (*extractRowRGB)(const unsigned char*, unsigned, unsigned char* output); - extractRowRGB = &RGBAtoRGB; - if (premultiplied) - extractRowRGB = &preMultipliedBGRAtoRGB; - - jpeg_set_defaults(&cinfo); - jpeg_set_quality(&cinfo, quality, TRUE); - disableSubsamplingForHighQuality(&cinfo, quality); - jpeg_start_compress(&cinfo, TRUE); - - unsigned char* pixels = inputPixels; - row.resize(cinfo.image_width * cinfo.input_components); - const size_t pixelRowStride = cinfo.image_width * 4; - while (cinfo.next_scanline < cinfo.image_height) { - JSAMPLE* rowData = row.data(); - extractRowRGB(pixels, cinfo.image_width, rowData); - jpeg_write_scanlines(&cinfo, &rowData, 1); - pixels += pixelRowStride; - } - - jpeg_finish_compress(&cinfo); - jpeg_destroy_compress(&cinfo); - return true; -} - -bool JPEGImageEncoder::encode(const SkBitmap& bitmap, int quality, Vector* output) -{ - SkAutoLockPixels bitmapLock(bitmap); - - if (bitmap.colorType() != kN32_SkColorType || !bitmap.getPixels()) - return false; // Only support 32 bit/pixel skia bitmaps. - - return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast(bitmap.getPixels()), true, quality, output); -} - -bool JPEGImageEncoder::encode(const ImageDataBuffer& imageData, int quality, Vector* output) -{ - return encodePixels(imageData.size(), imageData.data(), false, quality, output); -} - -} // namespace blink diff --git a/sky/engine/platform/image-encoders/skia/JPEGImageEncoder.h b/sky/engine/platform/image-encoders/skia/JPEGImageEncoder.h deleted file mode 100644 index 93e75cc6f19..00000000000 --- a/sky/engine/platform/image-encoders/skia/JPEGImageEncoder.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2010, Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_IMAGE_ENCODERS_SKIA_JPEGIMAGEENCODER_H_ -#define SKY_ENGINE_PLATFORM_IMAGE_ENCODERS_SKIA_JPEGIMAGEENCODER_H_ - -#include "sky/engine/wtf/Vector.h" - -class SkBitmap; - -namespace blink { - -struct ImageDataBuffer; - -class JPEGImageEncoder { -public: - // Encode the input data with a compression quality in [0-100]. - static bool encode(const SkBitmap&, int quality, Vector*); - static bool encode(const ImageDataBuffer&, int quality, Vector*); - - // For callers: provide a reasonable compression quality default. - enum Quality { DefaultCompressionQuality = 92 }; -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_IMAGE_ENCODERS_SKIA_JPEGIMAGEENCODER_H_ diff --git a/sky/engine/platform/image-encoders/skia/PNGImageEncoder.cpp b/sky/engine/platform/image-encoders/skia/PNGImageEncoder.cpp deleted file mode 100644 index ac0d33027b9..00000000000 --- a/sky/engine/platform/image-encoders/skia/PNGImageEncoder.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2010, Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 "platform/image-encoders/skia/PNGImageEncoder.h" - -#include "sky/engine/platform/geometry/IntSize.h" -#include "sky/engine/platform/graphics/ImageBuffer.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "third_party/skia/include/core/SkColorPriv.h" -#include "third_party/skia/include/core/SkUnPreMultiply.h" -extern "C" { -#include "png.h" -} - -namespace blink { - -static void writeOutput(png_structp png, png_bytep data, png_size_t size) -{ - static_cast*>(png_get_io_ptr(png))->append(data, size); -} - -static void preMultipliedBGRAtoRGBA(const void* pixels, int pixelCount, unsigned char* output) -{ - static const SkUnPreMultiply::Scale* scale = SkUnPreMultiply::GetScaleTable(); - const SkPMColor* input = static_cast(pixels); - - for (; pixelCount-- > 0; ++input) { - const unsigned alpha = SkGetPackedA32(*input); - if ((alpha != 0) && (alpha != 255)) { - *output++ = SkUnPreMultiply::ApplyScale(scale[alpha], SkGetPackedR32(*input)); - *output++ = SkUnPreMultiply::ApplyScale(scale[alpha], SkGetPackedG32(*input)); - *output++ = SkUnPreMultiply::ApplyScale(scale[alpha], SkGetPackedB32(*input)); - *output++ = alpha; - } else { - *output++ = SkGetPackedR32(*input); - *output++ = SkGetPackedG32(*input); - *output++ = SkGetPackedB32(*input); - *output++ = alpha; - } - } -} - -static bool encodePixels(IntSize imageSize, unsigned char* inputPixels, bool premultiplied, Vector* output) -{ - imageSize.clampNegativeToZero(); - Vector row; - - png_struct* png = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); - png_info* info = png_create_info_struct(png); - if (!png || !info || setjmp(png_jmpbuf(png))) { - png_destroy_write_struct(png ? &png : 0, info ? &info : 0); - return false; - } - - // Optimize compression for speed. - // The parameters are the same as what libpng uses by default for RGB and RGBA images, except: - // - the zlib compression level is 3 instead of 6, to avoid the lazy Ziv-Lempel match searching; - // - the delta filter is 1 ("sub") instead of 5 ("all"), to reduce the filter computations. - // The zlib memory level (8) and strategy (Z_FILTERED) will be set inside libpng. - // - // Avoid the zlib strategies Z_HUFFMAN_ONLY or Z_RLE. - // Although they are the fastest for poorly-compressible images (e.g. photographs), - // they are very slow for highly-compressible images (e.g. text, drawings or business graphics). - png_set_compression_level(png, 3); - png_set_filter(png, PNG_FILTER_TYPE_BASE, PNG_FILTER_SUB); - - png_set_write_fn(png, output, writeOutput, 0); - png_set_IHDR(png, info, imageSize.width(), imageSize.height(), - 8, PNG_COLOR_TYPE_RGB_ALPHA, 0, 0, 0); - png_write_info(png, info); - - unsigned char* pixels = inputPixels; - row.resize(imageSize.width() * sizeof(SkPMColor)); - const size_t pixelRowStride = imageSize.width() * 4; - for (int y = 0; y < imageSize.height(); ++y) { - if (premultiplied) { - preMultipliedBGRAtoRGBA(pixels, imageSize.width(), row.data()); - png_write_row(png, row.data()); - } else - png_write_row(png, pixels); - pixels += pixelRowStride; - } - - png_write_end(png, info); - png_destroy_write_struct(&png, &info); - return true; -} - -bool PNGImageEncoder::encode(const SkBitmap& bitmap, Vector* output) -{ - SkAutoLockPixels bitmapLock(bitmap); - - if (bitmap.colorType() != kN32_SkColorType || !bitmap.getPixels()) - return false; // Only support 32 bit/pixel skia bitmaps. - - return encodePixels(IntSize(bitmap.width(), bitmap.height()), static_cast(bitmap.getPixels()), true, output); -} - -bool PNGImageEncoder::encode(const ImageDataBuffer& imageData, Vector* output) -{ - return encodePixels(imageData.size(), imageData.data(), false, output); -} - -} // namespace blink diff --git a/sky/engine/platform/image-encoders/skia/PNGImageEncoder.h b/sky/engine/platform/image-encoders/skia/PNGImageEncoder.h deleted file mode 100644 index 579b9520076..00000000000 --- a/sky/engine/platform/image-encoders/skia/PNGImageEncoder.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2010, Google 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: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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 SKY_ENGINE_PLATFORM_IMAGE_ENCODERS_SKIA_PNGIMAGEENCODER_H_ -#define SKY_ENGINE_PLATFORM_IMAGE_ENCODERS_SKIA_PNGIMAGEENCODER_H_ - -#include "sky/engine/wtf/Vector.h" - -class SkBitmap; - -namespace blink { - -struct ImageDataBuffer; - -// Interface for encoding PNG data. This is a wrapper around libpng. -class PNGImageEncoder { -public: - static bool encode(const SkBitmap&, Vector* output); - static bool encode(const ImageDataBuffer&, Vector* output); -}; - -} // namespace blink - -#endif // SKY_ENGINE_PLATFORM_IMAGE_ENCODERS_SKIA_PNGIMAGEENCODER_H_ diff --git a/sky/engine/wtf/BUILD.gn b/sky/engine/wtf/BUILD.gn index 6416f08816b..7c4fb4d4b31 100644 --- a/sky/engine/wtf/BUILD.gn +++ b/sky/engine/wtf/BUILD.gn @@ -173,8 +173,6 @@ component("wtf") { "text/AtomicString.cpp", "text/AtomicString.h", "text/AtomicStringHash.h", - "text/Base64.cpp", - "text/Base64.h", "text/CString.cpp", "text/CString.h", "text/IntegerToStringConversion.h", diff --git a/sky/engine/wtf/TypeTraits.h b/sky/engine/wtf/TypeTraits.h index 253b69e2597..cf58ffb9f3b 100644 --- a/sky/engine/wtf/TypeTraits.h +++ b/sky/engine/wtf/TypeTraits.h @@ -290,23 +290,4 @@ namespace WTF { } // namespace WTF -namespace blink { - -class JSONValue; - -} // namespace blink - -namespace WTF { - - // FIXME: Disable pointer conversion checking against JSONValue. - // The current CodeGeneratorInspector.py generates code which upcasts to JSONValue from undefined types. - template class IsPointerConvertible { - public: - enum { - Value = true - }; - }; - -} // namespace WTF - #endif // SKY_ENGINE_WTF_TYPETRAITS_H_ diff --git a/sky/engine/wtf/text/Base64.cpp b/sky/engine/wtf/text/Base64.cpp deleted file mode 100644 index 9822e2708d3..00000000000 --- a/sky/engine/wtf/text/Base64.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - Copyright (C) 2000-2001 Dawit Alemayehu - Copyright (C) 2006 Alexey Proskuryakov - Copyright (C) 2007, 2008 Apple Inc. All rights reserved. - Copyright (C) 2010 Patrick Gansterer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License (LGPL) - version 2 as published by the Free Software Foundation. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - This code is based on the java implementation in HTTPClient - package by Ronald Tschalär Copyright (C) 1996-1999. -*/ - -#include "sky/engine/wtf/text/Base64.h" - -#include -#include "sky/engine/wtf/StringExtras.h" - -namespace WTF { - -static const char base64EncMap[64] = { - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, - 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, - 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, - 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F -}; - -static const char base64DecMap[128] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, - 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, - 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, - 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -String base64Encode(const char* data, unsigned length, Base64EncodePolicy policy) -{ - Vector result; - base64Encode(data, length, result, policy); - return String(result.data(), result.size()); -} - -void base64Encode(const char* data, unsigned len, Vector& out, Base64EncodePolicy policy) -{ - out.clear(); - if (!len) - return; - - // If the input string is pathologically large, just return nothing. - // Note: Keep this in sync with the "outLength" computation below. - // Rather than being perfectly precise, this is a bit conservative. - const unsigned maxInputBufferSize = UINT_MAX / 77 * 76 / 4 * 3 - 2; - if (len > maxInputBufferSize) - return; - - unsigned sidx = 0; - unsigned didx = 0; - - unsigned outLength = ((len + 2) / 3) * 4; - - // Deal with the 76 character per line limit specified in RFC 2045. - bool insertLFs = (policy == Base64InsertLFs && outLength > 76); - if (insertLFs) - outLength += ((outLength - 1) / 76); - - int count = 0; - out.grow(outLength); - - // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion - if (len > 1) { - while (sidx < len - 2) { - if (insertLFs) { - if (count && !(count % 76)) - out[didx++] = '\n'; - count += 4; - } - out[didx++] = base64EncMap[(data[sidx] >> 2) & 077]; - out[didx++] = base64EncMap[((data[sidx + 1] >> 4) & 017) | ((data[sidx] << 4) & 077)]; - out[didx++] = base64EncMap[((data[sidx + 2] >> 6) & 003) | ((data[sidx + 1] << 2) & 077)]; - out[didx++] = base64EncMap[data[sidx + 2] & 077]; - sidx += 3; - } - } - - if (sidx < len) { - if (insertLFs && (count > 0) && !(count % 76)) - out[didx++] = '\n'; - - out[didx++] = base64EncMap[(data[sidx] >> 2) & 077]; - if (sidx < len - 1) { - out[didx++] = base64EncMap[((data[sidx + 1] >> 4) & 017) | ((data[sidx] << 4) & 077)]; - out[didx++] = base64EncMap[(data[sidx + 1] << 2) & 077]; - } else - out[didx++] = base64EncMap[(data[sidx] << 4) & 077]; - } - - // Add padding - while (didx < out.size()) { - out[didx] = '='; - ++didx; - } -} - -bool base64Decode(const Vector& in, Vector& out, CharacterMatchFunctionPtr shouldIgnoreCharacter, Base64DecodePolicy policy) -{ - out.clear(); - - // If the input string is pathologically large, just return nothing. - if (in.size() > UINT_MAX) - return false; - - return base64Decode(in.data(), in.size(), out, shouldIgnoreCharacter, policy); -} - -template -static inline bool base64DecodeInternal(const T* data, unsigned length, Vector& out, CharacterMatchFunctionPtr shouldIgnoreCharacter, Base64DecodePolicy policy) -{ - out.clear(); - if (!length) - return true; - - out.grow(length); - - unsigned equalsSignCount = 0; - unsigned outLength = 0; - bool hadError = false; - for (unsigned idx = 0; idx < length; ++idx) { - unsigned ch = data[idx]; - if (ch == '=') { - ++equalsSignCount; - // There should never be more than 2 padding characters. - if (policy == Base64ValidatePadding && equalsSignCount > 2) { - hadError = true; - break; - } - } else if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ch == '+' || ch == '/') { - if (equalsSignCount) { - hadError = true; - break; - } - out[outLength++] = base64DecMap[ch]; - } else if (!shouldIgnoreCharacter || !shouldIgnoreCharacter(ch)) { - hadError = true; - break; - } - } - - if (outLength < out.size()) - out.shrink(outLength); - - if (hadError) - return false; - - if (!outLength) - return !equalsSignCount; - - // There should be no padding if length is a multiple of 4. - // We use (outLength + equalsSignCount) instead of length because we don't want to account for ignored characters. - if (policy == Base64ValidatePadding && equalsSignCount && (outLength + equalsSignCount) % 4) - return false; - - // Valid data is (n * 4 + [0,2,3]) characters long. - if ((outLength % 4) == 1) - return false; - - // 4-byte to 3-byte conversion - outLength -= (outLength + 3) / 4; - if (!outLength) - return false; - - unsigned sidx = 0; - unsigned didx = 0; - if (outLength > 1) { - while (didx < outLength - 2) { - out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003)); - out[didx + 1] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017)); - out[didx + 2] = (((out[sidx + 2] << 6) & 255) | (out[sidx + 3] & 077)); - sidx += 4; - didx += 3; - } - } - - if (didx < outLength) - out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003)); - - if (++didx < outLength) - out[didx] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017)); - - if (outLength < out.size()) - out.shrink(outLength); - - return true; -} - -bool base64Decode(const char* data, unsigned length, Vector& out, CharacterMatchFunctionPtr shouldIgnoreCharacter, Base64DecodePolicy policy) -{ - return base64DecodeInternal(reinterpret_cast(data), length, out, shouldIgnoreCharacter, policy); -} - -bool base64Decode(const UChar* data, unsigned length, Vector& out, CharacterMatchFunctionPtr shouldIgnoreCharacter, Base64DecodePolicy policy) -{ - return base64DecodeInternal(data, length, out, shouldIgnoreCharacter, policy); -} - -bool base64Decode(const String& in, Vector& out, CharacterMatchFunctionPtr shouldIgnoreCharacter, Base64DecodePolicy policy) -{ - if (in.isEmpty()) - return base64DecodeInternal(0, 0, out, shouldIgnoreCharacter, policy); - if (in.is8Bit()) - return base64DecodeInternal(in.characters8(), in.length(), out, shouldIgnoreCharacter, policy); - return base64DecodeInternal(in.characters16(), in.length(), out, shouldIgnoreCharacter, policy); -} - -} // namespace WTF diff --git a/sky/engine/wtf/text/Base64.h b/sky/engine/wtf/text/Base64.h deleted file mode 100644 index 3e77340de26..00000000000 --- a/sky/engine/wtf/text/Base64.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2006 Alexey Proskuryakov - * Copyright (C) 2010 Patrick Gansterer - * - * 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 SKY_ENGINE_WTF_TEXT_BASE64_H_ -#define SKY_ENGINE_WTF_TEXT_BASE64_H_ - -#include "sky/engine/wtf/Vector.h" -#include "sky/engine/wtf/WTFExport.h" -#include "sky/engine/wtf/text/CString.h" -#include "sky/engine/wtf/text/WTFString.h" - -namespace WTF { - -enum Base64EncodePolicy { - Base64DoNotInsertLFs, - Base64InsertLFs -}; - -enum Base64DecodePolicy { - Base64DoNotValidatePadding, - Base64ValidatePadding -}; - -WTF_EXPORT void base64Encode(const char*, unsigned, Vector&, Base64EncodePolicy = Base64DoNotInsertLFs); -WTF_EXPORT void base64Encode(const Vector&, Vector&, Base64EncodePolicy = Base64DoNotInsertLFs); -WTF_EXPORT void base64Encode(const CString&, Vector&, Base64EncodePolicy = Base64DoNotInsertLFs); -WTF_EXPORT String base64Encode(const char*, unsigned, Base64EncodePolicy = Base64DoNotInsertLFs); -WTF_EXPORT String base64Encode(const Vector&, Base64EncodePolicy = Base64DoNotInsertLFs); -WTF_EXPORT String base64Encode(const CString&, Base64EncodePolicy = Base64DoNotInsertLFs); - -WTF_EXPORT bool base64Decode(const String&, Vector&, CharacterMatchFunctionPtr shouldIgnoreCharacter = 0, Base64DecodePolicy = Base64DoNotValidatePadding); -WTF_EXPORT bool base64Decode(const Vector&, Vector&, CharacterMatchFunctionPtr shouldIgnoreCharacter = 0, Base64DecodePolicy = Base64DoNotValidatePadding); -WTF_EXPORT bool base64Decode(const char*, unsigned, Vector&, CharacterMatchFunctionPtr shouldIgnoreCharacter = 0, Base64DecodePolicy = Base64DoNotValidatePadding); -WTF_EXPORT bool base64Decode(const UChar*, unsigned, Vector&, CharacterMatchFunctionPtr shouldIgnoreCharacter = 0, Base64DecodePolicy = Base64DoNotValidatePadding); - -inline void base64Encode(const Vector& in, Vector& out, Base64EncodePolicy policy) -{ - base64Encode(in.data(), in.size(), out, policy); -} - -inline void base64Encode(const CString& in, Vector& out, Base64EncodePolicy policy) -{ - base64Encode(in.data(), in.length(), out, policy); -} - -inline String base64Encode(const Vector& in, Base64EncodePolicy policy) -{ - return base64Encode(in.data(), in.size(), policy); -} - -inline String base64Encode(const CString& in, Base64EncodePolicy policy) -{ - return base64Encode(in.data(), in.length(), policy); -} - -} // namespace WTF - -using WTF::Base64EncodePolicy; -using WTF::Base64DoNotInsertLFs; -using WTF::Base64InsertLFs; -using WTF::Base64DecodePolicy; -using WTF::Base64DoNotValidatePadding; -using WTF::Base64ValidatePadding; -using WTF::base64Encode; -using WTF::base64Decode; - -#endif // SKY_ENGINE_WTF_TEXT_BASE64_H_