| OLD | NEW |
| 1 // Copyright (C) 2013 Google Inc. All rights reserved. | 1 // Copyright 2011, Google Inc. |
| 2 // All rights reserved. |
| 2 // | 3 // |
| 3 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 5 // met: | 6 // met: |
| 6 // | 7 // |
| 7 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 9 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| 10 // copyright notice, this list of conditions and the following disclaimer | 11 // copyright notice, this list of conditions and the following disclaimer |
| 11 // in the documentation and/or other materials provided with the | 12 // in the documentation and/or other materials provided with the |
| 12 // distribution. | 13 // distribution. |
| 13 // * Neither the name of Google Inc. nor the names of its | 14 // * Neither the name of Google Inc. nor the names of its |
| 14 // contributors may be used to endorse or promote products derived from | 15 // contributors may be used to endorse or promote products derived from |
| 15 // this software without specific prior written permission. | 16 // this software without specific prior written permission. |
| 16 // | 17 // |
| 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 29 |
| 29 #ifndef SKY_ENGINE_PLATFORM_TEXT_TEXTRUNITERATOR_H_ | 30 #include "config.h" |
| 30 #define SKY_ENGINE_PLATFORM_TEXT_TEXTRUNITERATOR_H_ | 31 #include "bindings/core/dart/DartFormData.h" |
| 31 | 32 |
| 32 #include "sky/engine/platform/text/TextRun.h" | 33 #include "bindings/core/dart/DartBlob.h" |
| 34 #include "bindings/core/dart/DartHTMLFormElement.h" |
| 33 | 35 |
| 34 namespace blink { | 36 namespace blink { |
| 35 | 37 |
| 36 class TextRunIterator { | 38 namespace DartFormDataInternal { |
| 37 public: | 39 |
| 38 TextRunIterator() | 40 void appendCallback(Dart_NativeArguments args) |
| 39 : m_textRun(0) | 41 { |
| 40 , m_offset(0) | 42 Dart_Handle exception = 0; |
| 41 { | 43 { |
| 44 DOMFormData* receiver = DartDOMWrapper::receiver<DOMFormData>(args); |
| 45 |
| 46 DartStringAdapter name = DartUtilities::dartToString(args, 1, exception)
; |
| 47 if (exception) |
| 48 goto fail; |
| 49 |
| 50 Dart_Handle arg2 = Dart_GetNativeArgument(args, 2); |
| 51 |
| 52 if (Dart_IsString(arg2)) { |
| 53 ASSERT(Dart_GetNativeArgumentCount(args) == 3); |
| 54 |
| 55 DartStringAdapter value = DartUtilities::dartToString(arg2, exceptio
n); |
| 56 if (exception) |
| 57 goto fail; |
| 58 |
| 59 receiver->append(name, value); |
| 60 return; |
| 61 } |
| 62 |
| 63 Blob* blob = DartBlob::toNativeWithNullCheck(arg2, exception); |
| 64 if (exception) |
| 65 goto fail; |
| 66 |
| 67 if (Dart_GetNativeArgumentCount(args) == 3) { |
| 68 receiver->append(name, blob); |
| 69 return; |
| 70 } |
| 71 |
| 72 DartStringAdapter filename = DartUtilities::dartToStringWithNullCheck(ar
gs, 3, exception); |
| 73 if (exception) |
| 74 goto fail; |
| 75 |
| 76 receiver->append(name, blob, filename); |
| 77 return; |
| 42 } | 78 } |
| 43 | 79 |
| 44 TextRunIterator(const TextRun* textRun, unsigned offset) | 80 fail: |
| 45 : m_textRun(textRun) | 81 Dart_ThrowException(exception); |
| 46 , m_offset(offset) | 82 ASSERT_NOT_REACHED(); |
| 47 { | 83 } |
| 48 } | |
| 49 | 84 |
| 50 TextRunIterator(const TextRunIterator& other) | 85 } |
| 51 : m_textRun(other.m_textRun) | |
| 52 , m_offset(other.m_offset) | |
| 53 { | |
| 54 } | |
| 55 | 86 |
| 56 unsigned offset() const { return m_offset; } | 87 } |
| 57 void increment() { m_offset++; } | |
| 58 bool atEnd() const { return !m_textRun || m_offset >= m_textRun->length(); } | |
| 59 UChar current() const { return (*m_textRun)[m_offset]; } | |
| 60 WTF::Unicode::Direction direction() const { return atEnd() ? WTF::Unicode::O
therNeutral : WTF::Unicode::direction(current()); } | |
| 61 bool atParagraphSeparator() const { return current() == '\n'; } | |
| 62 | |
| 63 bool operator==(const TextRunIterator& other) | |
| 64 { | |
| 65 return m_offset == other.m_offset && m_textRun == other.m_textRun; | |
| 66 } | |
| 67 | |
| 68 bool operator!=(const TextRunIterator& other) { return !operator==(other); } | |
| 69 | |
| 70 private: | |
| 71 const TextRun* m_textRun; | |
| 72 int m_offset; | |
| 73 }; | |
| 74 | |
| 75 | |
| 76 } // namespace blink | |
| 77 | |
| 78 #endif // SKY_ENGINE_PLATFORM_TEXT_TEXTRUNITERATOR_H_ | |
| OLD | NEW |