| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "sky/engine/config.h" | |
| 32 #include "sky/engine/core/html/ime/InputMethodContext.h" | |
| 33 | |
| 34 #include "sky/engine/core/dom/Document.h" | |
| 35 #include "sky/engine/core/dom/Text.h" | |
| 36 #include "sky/engine/core/editing/InputMethodController.h" | |
| 37 #include "sky/engine/core/events/Event.h" | |
| 38 #include "sky/engine/core/frame/LocalFrame.h" | |
| 39 | |
| 40 namespace blink { | |
| 41 | |
| 42 PassOwnPtr<InputMethodContext> InputMethodContext::create(HTMLElement* element) | |
| 43 { | |
| 44 return adoptPtr(new InputMethodContext(element)); | |
| 45 } | |
| 46 | |
| 47 InputMethodContext::InputMethodContext(HTMLElement* element) | |
| 48 : m_element(element) | |
| 49 { | |
| 50 } | |
| 51 | |
| 52 InputMethodContext::~InputMethodContext() | |
| 53 { | |
| 54 } | |
| 55 | |
| 56 String InputMethodContext::locale() const | |
| 57 { | |
| 58 // FIXME: Implement this. | |
| 59 return emptyString(); | |
| 60 } | |
| 61 | |
| 62 HTMLElement* InputMethodContext::target() const | |
| 63 { | |
| 64 return m_element; | |
| 65 } | |
| 66 | |
| 67 unsigned InputMethodContext::compositionStartOffset() | |
| 68 { | |
| 69 if (hasFocus()) | |
| 70 return inputMethodController().compositionStart(); | |
| 71 return 0; | |
| 72 } | |
| 73 | |
| 74 unsigned InputMethodContext::compositionEndOffset() | |
| 75 { | |
| 76 if (hasFocus()) | |
| 77 return inputMethodController().compositionEnd(); | |
| 78 return 0; | |
| 79 } | |
| 80 | |
| 81 void InputMethodContext::confirmComposition() | |
| 82 { | |
| 83 if (hasFocus()) | |
| 84 inputMethodController().confirmCompositionAndResetState(); | |
| 85 } | |
| 86 | |
| 87 bool InputMethodContext::hasFocus() const | |
| 88 { | |
| 89 LocalFrame* frame = m_element->document().frame(); | |
| 90 if (!frame) | |
| 91 return false; | |
| 92 | |
| 93 const Element* element = frame->document()->focusedElement(); | |
| 94 return element && element->isHTMLElement() && m_element == toHTMLElement(ele
ment); | |
| 95 } | |
| 96 | |
| 97 CompositionUnderline InputMethodContext::selectedSegment() const | |
| 98 { | |
| 99 CompositionUnderline underline; | |
| 100 if (!hasFocus()) | |
| 101 return underline; | |
| 102 | |
| 103 const InputMethodController& controller = inputMethodController(); | |
| 104 if (!controller.hasComposition()) | |
| 105 return underline; | |
| 106 | |
| 107 Vector<CompositionUnderline> underlines = controller.customCompositionUnderl
ines(); | |
| 108 for (size_t i = 0; i < underlines.size(); ++i) { | |
| 109 if (underlines[i].thick) | |
| 110 return underlines[i]; | |
| 111 } | |
| 112 | |
| 113 // When no underline information is available while composition exists, | |
| 114 // build a CompositionUnderline whose element is the whole composition. | |
| 115 underline.endOffset = controller.compositionEnd() - controller.compositionSt
art(); | |
| 116 return underline; | |
| 117 | |
| 118 } | |
| 119 | |
| 120 int InputMethodContext::selectionStart() const | |
| 121 { | |
| 122 return selectedSegment().startOffset; | |
| 123 } | |
| 124 | |
| 125 int InputMethodContext::selectionEnd() const | |
| 126 { | |
| 127 return selectedSegment().endOffset; | |
| 128 } | |
| 129 | |
| 130 const Vector<unsigned>& InputMethodContext::segments() | |
| 131 { | |
| 132 m_segments.clear(); | |
| 133 if (!hasFocus()) | |
| 134 return m_segments; | |
| 135 const InputMethodController& controller = inputMethodController(); | |
| 136 if (!controller.hasComposition()) | |
| 137 return m_segments; | |
| 138 | |
| 139 Vector<CompositionUnderline> underlines = controller.customCompositionUnderl
ines(); | |
| 140 if (!underlines.size()) { | |
| 141 m_segments.append(0); | |
| 142 } else { | |
| 143 for (size_t i = 0; i < underlines.size(); ++i) | |
| 144 m_segments.append(underlines[i].startOffset); | |
| 145 } | |
| 146 | |
| 147 return m_segments; | |
| 148 } | |
| 149 | |
| 150 InputMethodController& InputMethodContext::inputMethodController() const | |
| 151 { | |
| 152 return m_element->document().frame()->inputMethodController(); | |
| 153 } | |
| 154 | |
| 155 const AtomicString& InputMethodContext::interfaceName() const | |
| 156 { | |
| 157 return EventTargetNames::InputMethodContext; | |
| 158 } | |
| 159 | |
| 160 ExecutionContext* InputMethodContext::executionContext() const | |
| 161 { | |
| 162 return &m_element->document(); | |
| 163 } | |
| 164 | |
| 165 void InputMethodContext::dispatchCandidateWindowShowEvent() | |
| 166 { | |
| 167 dispatchEvent(Event::create(EventTypeNames::candidatewindowshow)); | |
| 168 } | |
| 169 | |
| 170 void InputMethodContext::dispatchCandidateWindowUpdateEvent() | |
| 171 { | |
| 172 dispatchEvent(Event::create(EventTypeNames::candidatewindowupdate)); | |
| 173 } | |
| 174 | |
| 175 void InputMethodContext::dispatchCandidateWindowHideEvent() | |
| 176 { | |
| 177 dispatchEvent(Event::create(EventTypeNames::candidatewindowhide)); | |
| 178 } | |
| 179 | |
| 180 } // namespace blink | |
| OLD | NEW |