Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef InputMethodController_h | 26 #ifndef InputMethodController_h |
| 27 #define InputMethodController_h | 27 #define InputMethodController_h |
| 28 | 28 |
| 29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
| 30 #include "core/dom/Range.h" | |
| 30 #include "core/editing/CompositionUnderline.h" | 31 #include "core/editing/CompositionUnderline.h" |
| 31 #include "core/editing/EphemeralRange.h" | 32 #include "core/editing/EphemeralRange.h" |
| 32 #include "core/editing/PlainTextRange.h" | 33 #include "core/editing/PlainTextRange.h" |
| 33 #include "platform/heap/Handle.h" | 34 #include "platform/heap/Handle.h" |
| 34 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 class Editor; | 39 class Editor; |
| 39 class LocalFrame; | 40 class LocalFrame; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 66 // Inserts the text that is being composed or specified non-empty text and | 67 // Inserts the text that is being composed or specified non-empty text and |
| 67 // returns true. | 68 // returns true. |
| 68 bool confirmCompositionOrInsertText(const String& text, ConfirmCompositionBe havior); | 69 bool confirmCompositionOrInsertText(const String& text, ConfirmCompositionBe havior); |
| 69 // Deletes the existing composition text. | 70 // Deletes the existing composition text. |
| 70 void cancelComposition(); | 71 void cancelComposition(); |
| 71 void cancelCompositionIfSelectionIsInvalid(); | 72 void cancelCompositionIfSelectionIsInvalid(); |
| 72 EphemeralRange compositionEphemeralRange() const; | 73 EphemeralRange compositionEphemeralRange() const; |
| 73 PassRefPtrWillBeRawPtr<Range> compositionRange() const; | 74 PassRefPtrWillBeRawPtr<Range> compositionRange() const; |
| 74 | 75 |
| 75 // getting international text input composition state (for use by InlineText Box) | 76 // getting international text input composition state (for use by InlineText Box) |
| 76 Text* compositionNode() const { return m_compositionNode.get(); } | 77 bool isCompositionNode(const Node*); |
| 77 unsigned compositionStart() const { return m_compositionStart; } | 78 unsigned compositionStart() const { return m_compositionRange.get() ? m_comp ositionRange->startOffset() : 0; } |
| 78 unsigned compositionEnd() const { return m_compositionEnd; } | 79 unsigned compositionEnd() const { return m_compositionRange.get() ? m_compos itionRange->endOffset() : 0; } |
| 79 bool compositionUsesCustomUnderlines() const { return !m_customCompositionUn derlines.isEmpty(); } | 80 bool compositionUsesCustomUnderlines() const { return !m_customCompositionUn derlines.empty(); } |
| 80 const Vector<CompositionUnderline>& customCompositionUnderlines() const { re turn m_customCompositionUnderlines; } | 81 // TODO: This method is called only by WebViewImpl::compositionUnderlines(). |
|
yosin_UTC9
2015/08/31 01:35:40
nit: s/TODO/TODO(aelias)/
| |
| 82 // WebViewImpl::compositionUnderlines() is called only by tests. | |
| 83 // Underlines are associated with a specific node, and composition | |
| 84 // region can cover multiple nodes now. This method does not really | |
| 85 // make sense since it does not specify a node explicitly. To be | |
| 86 // compatible with current tests this method just returns the underlines | |
| 87 // for the start node. This method and WebViewImpl::compositionUnderlines() | |
| 88 // should be removed once we re-write relevant tests. | |
| 89 const Vector<CompositionUnderline>& customCompositionUnderlines() const; | |
| 90 const Vector<CompositionUnderline>* customCompositionUnderlines(const Node*) const; | |
| 81 | 91 |
| 82 void clear(); | 92 void clear(); |
| 83 | 93 |
| 84 PlainTextRange getSelectionOffsets() const; | 94 PlainTextRange getSelectionOffsets() const; |
| 85 // Returns true if setting selection to specified offsets, otherwise false. | 95 // Returns true if setting selection to specified offsets, otherwise false. |
| 86 bool setEditableSelectionOffsets(const PlainTextRange&); | 96 bool setEditableSelectionOffsets(const PlainTextRange&); |
| 87 void extendSelectionAndDelete(int before, int after); | 97 void extendSelectionAndDelete(int before, int after); |
| 88 | 98 |
| 89 private: | 99 private: |
| 90 class SelectionOffsetsScope { | 100 class SelectionOffsetsScope { |
| 91 WTF_MAKE_NONCOPYABLE(SelectionOffsetsScope); | 101 WTF_MAKE_NONCOPYABLE(SelectionOffsetsScope); |
| 92 STACK_ALLOCATED(); | 102 STACK_ALLOCATED(); |
| 93 public: | 103 public: |
| 94 explicit SelectionOffsetsScope(InputMethodController*); | 104 explicit SelectionOffsetsScope(InputMethodController*); |
| 95 ~SelectionOffsetsScope(); | 105 ~SelectionOffsetsScope(); |
| 96 private: | 106 private: |
| 97 RawPtrWillBeMember<InputMethodController> m_inputMethodController; | 107 RawPtrWillBeMember<InputMethodController> m_inputMethodController; |
| 98 const PlainTextRange m_offsets; | 108 const PlainTextRange m_offsets; |
| 99 }; | 109 }; |
| 100 friend class SelectionOffsetsScope; | 110 friend class SelectionOffsetsScope; |
| 101 | 111 |
| 102 RawPtrWillBeMember<LocalFrame> m_frame; | 112 RawPtrWillBeMember<LocalFrame> m_frame; |
| 103 RefPtrWillBeMember<Text> m_compositionNode; | 113 RefPtrWillBeMember<Range> m_compositionRange; |
| 104 // We don't use PlainTextRange which is immutable, for composition range. | 114 typedef std::map<const Node*, std::pair<RefPtrWillBeMember<Node>, Vector<Com positionUnderline>>> NodeUnderlinesMap; |
|
yosin_UTC9
2015/08/31 01:35:40
nit: We should use WTF::HashMap. Both, key(const N
yosin_UTC9
2015/08/31 01:35:40
I think we should have struct with DEFINE_TRACE()
| |
| 105 unsigned m_compositionStart; | 115 mutable NodeUnderlinesMap m_customCompositionUnderlines; |
| 106 unsigned m_compositionEnd; | 116 bool m_isExistingText; |
| 107 // startOffset and endOffset of CompositionUnderline are based on | |
| 108 // m_compositionNode. | |
| 109 Vector<CompositionUnderline> m_customCompositionUnderlines; | |
| 110 | 117 |
| 111 explicit InputMethodController(LocalFrame&); | 118 explicit InputMethodController(LocalFrame&); |
| 112 | 119 |
| 113 Editor& editor() const; | 120 Editor& editor() const; |
| 114 LocalFrame& frame() const | 121 LocalFrame& frame() const |
| 115 { | 122 { |
| 116 ASSERT(m_frame); | 123 ASSERT(m_frame); |
| 117 return *m_frame; | 124 return *m_frame; |
| 118 } | 125 } |
| 119 | 126 |
| 120 bool insertTextForConfirmedComposition(const String& text); | 127 bool insertTextForConfirmedComposition(const String& text); |
| 121 void selectComposition() const; | 128 void selectComposition() const; |
| 122 enum FinishCompositionMode { ConfirmComposition, CancelComposition }; | 129 enum FinishCompositionMode { ConfirmComposition, CancelComposition }; |
| 123 // Returns true if composition exists. | 130 // Returns true if composition exists. |
| 124 bool finishComposition(const String&, FinishCompositionMode); | 131 bool finishComposition(const String&, FinishCompositionMode); |
| 125 bool setSelectionOffsets(const PlainTextRange&); | 132 bool setSelectionOffsets(const PlainTextRange&); |
| 126 }; | 133 }; |
| 127 | 134 |
| 128 } // namespace blink | 135 } // namespace blink |
| 129 | 136 |
| 130 #endif // InputMethodController_h | 137 #endif // InputMethodController_h |
| OLD | NEW |