Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: Source/core/html/ime/InputMethodContext.cpp

Issue 23604053: Implement Composition interface for IME API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: consistent quotation usage in layouttest html. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/ime/InputMethodContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 inputMethodController().confirmCompositionAndResetState();
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::compositionText() const
100 {
101 if (!hasFocus())
102 return emptyString();
103
104 Text* text = inputMethodController().compositionNode();
105 return text ? text->wholeText() : emptyString();
106 }
107
108 CompositionUnderline InputMethodContext::selectedSegment() const
109 {
110 CompositionUnderline underline;
111 if (!hasFocus())
112 return underline;
113
114 const InputMethodController& controller = inputMethodController();
115 if (!controller.hasComposition())
116 return underline;
117
118 Vector<CompositionUnderline> underlines = controller.customCompositionUnderl ines();
119 for (size_t i = 0; i < underlines.size(); ++i) {
120 if (underlines[i].thick)
121 return underlines[i];
122 }
123
124 // When no underline information is available while composition exists,
125 // build a CompositionUnderline whose element is the whole composition.
126 underline.endOffset = controller.compositionEnd() - controller.compositionSt art();
127 return underline;
128
129 }
130
131 int InputMethodContext::selectionStart() const
132 {
133 return selectedSegment().startOffset;
134 }
135
136 int InputMethodContext::selectionEnd() const
137 {
138 return selectedSegment().endOffset;
139 }
140
141 const Vector<unsigned>& InputMethodContext::segments()
142 {
143 m_segments.clear();
144 if (!hasFocus())
145 return m_segments;
146 const InputMethodController& controller = inputMethodController();
147 if (!controller.hasComposition())
148 return m_segments;
149
150 Vector<CompositionUnderline> underlines = controller.customCompositionUnderl ines();
151 if (!underlines.size()) {
152 m_segments.append(0);
153 } else {
154 for (size_t i = 0; i < underlines.size(); ++i)
155 m_segments.append(underlines[i].startOffset);
156 }
157
158 return m_segments;
159 }
160
161 InputMethodController& InputMethodContext::inputMethodController() const
162 {
163 return m_element->document().frame()->inputMethodController();
164 }
165
97 } // namespace WebCore 166 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/ime/InputMethodContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698