| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EditingState_h | 5 #ifndef EditingState_h |
| 6 #define EditingState_h | 6 #define EditingState_h |
| 7 | 7 |
| 8 #include "wtf/Allocator.h" | 8 #include "wtf/Allocator.h" |
| 9 #include "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
| 10 #include "wtf/Noncopyable.h" | 10 #include "wtf/Noncopyable.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 // Abort the editing command if the specified expression is true. | 55 // Abort the editing command if the specified expression is true. |
| 56 #define ABORT_EDITING_COMMAND_IF(expr) \ | 56 #define ABORT_EDITING_COMMAND_IF(expr) \ |
| 57 do { \ | 57 do { \ |
| 58 if (expr) { \ | 58 if (expr) { \ |
| 59 editingState->abort(); \ | 59 editingState->abort(); \ |
| 60 return; \ | 60 return; \ |
| 61 } \ | 61 } \ |
| 62 } while (false) | 62 } while (false) |
| 63 | 63 |
| 64 #if ENABLE(ASSERT) | 64 #if DCHECK_IS_ON() |
| 65 // This class is inspired by |NoExceptionStateAssertionChecker|. | 65 // This class is inspired by |NoExceptionStateAssertionChecker|. |
| 66 class NoEditingAbortChecker final { | 66 class NoEditingAbortChecker final { |
| 67 STACK_ALLOCATED(); | 67 STACK_ALLOCATED(); |
| 68 WTF_MAKE_NONCOPYABLE(NoEditingAbortChecker); | 68 WTF_MAKE_NONCOPYABLE(NoEditingAbortChecker); |
| 69 public: | 69 public: |
| 70 NoEditingAbortChecker(const char* file, int line); | 70 NoEditingAbortChecker(const char* file, int line); |
| 71 ~NoEditingAbortChecker(); | 71 ~NoEditingAbortChecker(); |
| 72 | 72 |
| 73 EditingState* editingState() { return &m_editingState; } | 73 EditingState* editingState() { return &m_editingState; } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 EditingState m_editingState; | 76 EditingState m_editingState; |
| 77 const char* const m_file; | 77 const char* const m_file; |
| 78 int const m_line; | 78 int const m_line; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // If a function with EditingState* argument should not be aborted, | 81 // If a function with EditingState* argument should not be aborted, |
| 82 // ASSERT_NO_EDITING_ABORT should be specified. | 82 // ASSERT_NO_EDITING_ABORT should be specified. |
| 83 // fooFunc(...., ASSERT_NO_EDITING_ABORT); | 83 // fooFunc(...., ASSERT_NO_EDITING_ABORT); |
| 84 // It causes an assertion failure If ENABLE(ASSERT) and the function was aborted | 84 // It causes an assertion failure If DCHECK_IS_ON() and the function was aborted |
| 85 // unexpectedly. | 85 // unexpectedly. |
| 86 #define ASSERT_NO_EDITING_ABORT (NoEditingAbortChecker(__FILE__, __LINE__).editi
ngState()) | 86 #define ASSERT_NO_EDITING_ABORT (NoEditingAbortChecker(__FILE__, __LINE__).editi
ngState()) |
| 87 #else | 87 #else |
| 88 #define ASSERT_NO_EDITING_ABORT (IgnorableEditingAbortState().editingState()) | 88 #define ASSERT_NO_EDITING_ABORT (IgnorableEditingAbortState().editingState()) |
| 89 #endif | 89 #endif |
| 90 | 90 |
| 91 } // namespace blink | 91 } // namespace blink |
| 92 | 92 |
| 93 #endif // EditingState_h | 93 #endif // EditingState_h |
| OLD | NEW |