OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (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 |
28 * 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. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/html/ime/InputMethodContext.h" | 32 #include "core/html/ime/InputMethodContext.h" |
33 | 33 |
34 #include "core/dom/Text.h" | |
34 #include "core/editing/InputMethodController.h" | 35 #include "core/editing/InputMethodController.h" |
35 #include "core/html/ime/Composition.h" | 36 #include "core/html/ime/Composition.h" |
36 #include "core/page/Frame.h" | 37 #include "core/page/Frame.h" |
37 | 38 |
38 namespace WebCore { | 39 namespace WebCore { |
39 | 40 |
40 PassOwnPtr<InputMethodContext> InputMethodContext::create(HTMLElement* element) | 41 PassOwnPtr<InputMethodContext> InputMethodContext::create(HTMLElement* element) |
41 { | 42 { |
42 return adoptPtr(new InputMethodContext(element)); | 43 return adoptPtr(new InputMethodContext(element)); |
43 } | 44 } |
44 | 45 |
45 InputMethodContext::InputMethodContext(HTMLElement* element) | 46 InputMethodContext::InputMethodContext(HTMLElement* element) |
46 : m_composition(0) | 47 : m_composition(Composition::create(this)) |
47 , m_element(element) | 48 , m_element(element) |
48 { | 49 { |
49 ScriptWrappable::init(this); | 50 ScriptWrappable::init(this); |
50 } | 51 } |
51 | 52 |
52 InputMethodContext::~InputMethodContext() | 53 InputMethodContext::~InputMethodContext() |
53 { | 54 { |
54 } | 55 } |
55 | 56 |
56 Composition* InputMethodContext::composition() const | 57 Composition* InputMethodContext::composition() const |
57 { | 58 { |
58 // FIXME: Implement this. This should lazily update the composition object | |
59 // here. | |
60 return m_composition.get(); | 59 return m_composition.get(); |
61 } | 60 } |
62 | 61 |
63 String InputMethodContext::locale() const | 62 String InputMethodContext::locale() const |
64 { | 63 { |
65 // FIXME: Implement this. | 64 // FIXME: Implement this. |
66 return emptyString(); | 65 return emptyString(); |
67 } | 66 } |
68 | 67 |
69 HTMLElement* InputMethodContext::target() const | 68 HTMLElement* InputMethodContext::target() const |
70 { | 69 { |
71 return m_element; | 70 return m_element; |
72 } | 71 } |
73 | 72 |
74 void InputMethodContext::confirmComposition() | 73 void InputMethodContext::confirmComposition() |
75 { | 74 { |
76 Frame* frame = m_element->document().frame(); | 75 if (hasFocus()) |
77 if (!frame) | 76 m_element->document().frame()->inputMethodController().confirmCompositio nAndResetState(); |
tkent
2013/09/11 08:10:55
nit: We had better have a helper function to get a
kochi
2013/09/11 08:32:00
Done.
Added inputMethodController() helper functi
| |
78 return; | |
79 | |
80 const Element* element = frame->document()->focusedElement(); | |
81 if (!element || !element->isHTMLElement() || m_element != toHTMLElement(elem ent)) | |
82 return; | |
83 | |
84 frame->inputMethodController().confirmCompositionAndResetState(); | |
85 } | 77 } |
86 | 78 |
87 void InputMethodContext::setCaretRectangle(Node* anchor, int x, int y, int w, in t h) | 79 void InputMethodContext::setCaretRectangle(Node* anchor, int x, int y, int w, in t h) |
88 { | 80 { |
89 // FIXME: Implement this. | 81 // FIXME: Implement this. |
90 } | 82 } |
91 | 83 |
92 void InputMethodContext::setExclusionRectangle(Node* anchor, int x, int y, int w , int h) | 84 void InputMethodContext::setExclusionRectangle(Node* anchor, int x, int y, int w , int h) |
93 { | 85 { |
94 // FIXME: Implement this. | 86 // FIXME: Implement this. |
95 } | 87 } |
96 | 88 |
89 bool InputMethodContext::hasFocus() const | |
90 { | |
91 Frame* frame = m_element->document().frame(); | |
92 if (!frame) | |
93 return false; | |
94 | |
95 const Element* element = frame->document()->focusedElement(); | |
96 return element && element->isHTMLElement() && m_element == toHTMLElement(ele ment); | |
97 } | |
98 | |
99 String InputMethodContext::getCompositionText() const | |
100 { | |
101 if (!hasFocus()) | |
102 return emptyString(); | |
103 | |
104 Text* text = m_element->document().frame()->inputMethodController().composit ionNode(); | |
105 | |
106 return text ? text->wholeText() : emptyString(); | |
107 } | |
108 | |
109 CompositionUnderline InputMethodContext::getSelectedSegment() const | |
110 { | |
111 CompositionUnderline underline; | |
112 if (!hasFocus()) | |
113 return underline; | |
114 | |
115 const InputMethodController& controller = m_element->document().frame()->inp utMethodController(); | |
116 if (!controller.hasComposition()) | |
117 return underline; | |
118 | |
119 Vector<CompositionUnderline> underlines = controller.customCompositionUnderl ines(); | |
120 for (size_t i = 0; i < underlines.size(); ++i) { | |
121 if (underlines[i].thick) | |
122 return underlines[i]; | |
123 } | |
124 | |
125 // When no underline information is available while composition exists, | |
126 // build a CompositionUnderline whose element is the whole composition. | |
127 underline.endOffset = controller.compositionEnd() - controller.compositionSt art(); | |
128 return underline; | |
129 | |
130 } | |
131 | |
132 int InputMethodContext::getSelectionStart() const | |
133 { | |
134 return getSelectedSegment().startOffset; | |
135 } | |
136 | |
137 int InputMethodContext::getSelectionEnd() const | |
138 { | |
139 return getSelectedSegment().endOffset; | |
140 } | |
141 | |
142 const Vector<unsigned>& InputMethodContext::getSegments() | |
143 { | |
144 m_segments.clear(); | |
145 if (!hasFocus()) | |
146 return m_segments; | |
147 const InputMethodController& controller = m_element->document().frame()->inp utMethodController(); | |
148 if (!controller.hasComposition()) | |
149 return m_segments; | |
150 | |
151 Vector<CompositionUnderline> underlines = controller.customCompositionUnderl ines(); | |
152 if (!underlines.size()) { | |
153 m_segments.append(0); | |
154 } else { | |
155 for (size_t i = 0; i < underlines.size(); ++i) | |
156 m_segments.append(underlines[i].startOffset); | |
157 } | |
158 | |
159 return m_segments; | |
160 } | |
161 | |
97 } // namespace WebCore | 162 } // namespace WebCore |
OLD | NEW |