Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "core/editing/InputMethodController.h" | 27 #include "core/editing/InputMethodController.h" |
| 28 | 28 |
| 29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
| 30 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
| 31 #include "core/dom/Text.h" | 31 #include "core/dom/Text.h" |
| 32 #include "core/editing/EditingUtilities.h" | 32 #include "core/editing/EditingUtilities.h" |
| 33 #include "core/editing/Editor.h" | 33 #include "core/editing/Editor.h" |
| 34 #include "core/editing/commands/TypingCommand.h" | 34 #include "core/editing/commands/TypingCommand.h" |
| 35 #include "core/editing/markers/DocumentMarkerController.h" | 35 #include "core/editing/markers/DocumentMarkerController.h" |
| 36 #include "core/events/CompositionEvent.h" | 36 #include "core/events/CompositionEvent.h" |
| 37 #include "core/events/InputEvent.h" | |
| 37 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
| 38 #include "core/html/HTMLTextAreaElement.h" | 39 #include "core/html/HTMLTextAreaElement.h" |
| 39 #include "core/input/EventHandler.h" | 40 #include "core/input/EventHandler.h" |
| 40 #include "core/layout/LayoutObject.h" | 41 #include "core/layout/LayoutObject.h" |
| 41 #include "core/layout/LayoutTheme.h" | 42 #include "core/layout/LayoutTheme.h" |
| 42 #include "core/page/ChromeClient.h" | 43 #include "core/page/ChromeClient.h" |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 46 InputMethodController::SelectionOffsetsScope::SelectionOffsetsScope(InputMethodC ontroller* inputMethodController) | 47 InputMethodController::SelectionOffsetsScope::SelectionOffsetsScope(InputMethodC ontroller* inputMethodController) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 clear(); | 150 clear(); |
| 150 return true; | 151 return true; |
| 151 } | 152 } |
| 152 | 153 |
| 153 // Select the text that will be deleted or replaced. | 154 // Select the text that will be deleted or replaced. |
| 154 selectComposition(); | 155 selectComposition(); |
| 155 | 156 |
| 156 if (frame().selection().isNone()) | 157 if (frame().selection().isNone()) |
| 157 return false; | 158 return false; |
| 158 | 159 |
| 160 if (RuntimeEnabledFeatures::inputEventEnabled()) { | |
|
dtapuska
2016/03/01 21:49:51
This seems to be a repeated pattern in this class.
| |
| 161 if (Element* target = frame().document()->focusedElement()) { | |
| 162 // Dispatch 'beforeinput' before CompositionEvent | |
| 163 RefPtrWillBeRawPtr<InputEvent> beforeInputEvent = InputEvent::create BeforeInput("insertText", text); | |
|
chongz
2016/03/01 20:41:10
https://developer.mozilla.org/en-US/docs/Web/API/D
| |
| 164 DispatchEventResult dispatchResult = target->dispatchEvent(beforeInp utEvent); | |
| 165 if (dispatchResult != DispatchEventResult::NotCanceled) | |
| 166 return false; | |
| 167 } | |
| 168 } | |
| 169 | |
| 159 dispatchCompositionEndEvent(frame(), text); | 170 dispatchCompositionEndEvent(frame(), text); |
| 160 | 171 |
| 161 if (!frame().document()) | 172 if (!frame().document()) |
| 162 return false; | 173 return false; |
| 163 | 174 |
| 164 // If text is empty, then delete the old composition here. If text is | 175 // If text is empty, then delete the old composition here. If text is |
| 165 // non-empty, InsertTextCommand::input will delete the old composition with | 176 // non-empty, InsertTextCommand::input will delete the old composition with |
| 166 // an optimized replace operation. | 177 // an optimized replace operation. |
| 167 if (text.isEmpty()) | 178 if (text.isEmpty()) |
| 168 TypingCommand::deleteSelection(*frame().document(), 0); | 179 TypingCommand::deleteSelection(*frame().document(), 0); |
| 169 | 180 |
| 170 clear(); | 181 clear(); |
| 171 | 182 |
| 172 insertTextForConfirmedComposition(text); | 183 insertTextForConfirmedComposition(text); |
| 173 | 184 |
| 174 return true; | 185 return true; |
| 175 } | 186 } |
| 176 | 187 |
| 177 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior) | 188 bool InputMethodController::confirmCompositionOrInsertText(const String& text, C onfirmCompositionBehavior confirmBehavior) |
| 178 { | 189 { |
| 179 if (!hasComposition()) { | 190 if (!hasComposition()) { |
| 180 if (!text.length()) | 191 if (!text.length()) |
| 181 return false; | 192 return false; |
| 193 | |
| 194 if (RuntimeEnabledFeatures::inputEventEnabled()) { | |
| 195 if (Element* target = frame().document()->focusedElement()) { | |
| 196 // Dispatch 'beforeinput' before insertText | |
| 197 RefPtrWillBeRawPtr<InputEvent> beforeInputEvent = InputEvent::cr eateBeforeInput("insertText", text); | |
| 198 DispatchEventResult dispatchResult = target->dispatchEvent(befor eInputEvent); | |
| 199 if (dispatchResult != DispatchEventResult::NotCanceled) | |
| 200 return false; | |
| 201 } | |
| 202 } | |
| 182 editor().insertText(text, 0); | 203 editor().insertText(text, 0); |
| 183 return true; | 204 return true; |
| 184 } | 205 } |
| 185 | 206 |
| 186 if (text.length()) { | 207 if (text.length()) { |
| 187 confirmComposition(text); | 208 confirmComposition(text); |
| 188 return true; | 209 return true; |
| 189 } | 210 } |
| 190 | 211 |
| 191 if (confirmBehavior != KeepSelection) | 212 if (confirmBehavior != KeepSelection) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 // inserting the previous composition text into text nodes oddly. | 260 // inserting the previous composition text into text nodes oddly. |
| 240 // See https://bugs.webkit.org/show_bug.cgi?id=46868 | 261 // See https://bugs.webkit.org/show_bug.cgi?id=46868 |
| 241 frame().document()->updateLayoutTree(); | 262 frame().document()->updateLayoutTree(); |
| 242 | 263 |
| 243 selectComposition(); | 264 selectComposition(); |
| 244 | 265 |
| 245 if (frame().selection().isNone()) | 266 if (frame().selection().isNone()) |
| 246 return; | 267 return; |
| 247 | 268 |
| 248 if (Element* target = frame().document()->focusedElement()) { | 269 if (Element* target = frame().document()->focusedElement()) { |
| 270 if (RuntimeEnabledFeatures::inputEventEnabled()) { | |
| 271 // Dispatch 'beforeinput' before CompositionEvent | |
| 272 RefPtrWillBeRawPtr<InputEvent> beforeInputEvent = InputEvent::create BeforeInput("replaceContent", text); | |
|
chongz
2016/03/01 20:41:10
'replaceContent' is mentioned here http://w3c.gith
dtapuska
2016/03/01 21:49:51
Let us leave it with replace text for now and see
| |
| 273 DispatchEventResult dispatchResult = target->dispatchEvent(beforeInp utEvent); | |
| 274 if (dispatchResult != DispatchEventResult::NotCanceled) | |
| 275 return; | |
| 276 } | |
| 277 | |
| 249 // Dispatch an appropriate composition event to the focused node. | 278 // Dispatch an appropriate composition event to the focused node. |
| 250 // We check the composition status and choose an appropriate composition event since this | 279 // We check the composition status and choose an appropriate composition event since this |
| 251 // function is used for three purposes: | 280 // function is used for three purposes: |
| 252 // 1. Starting a new composition. | 281 // 1. Starting a new composition. |
| 253 // Send a compositionstart and a compositionupdate event when this fu nction creates | 282 // Send a compositionstart and a compositionupdate event when this fu nction creates |
| 254 // a new composition node, i.e. | 283 // a new composition node, i.e. |
| 255 // !hasComposition() && !text.isEmpty(). | 284 // !hasComposition() && !text.isEmpty(). |
| 256 // Sending a compositionupdate event at this time ensures that at lea st one | 285 // Sending a compositionupdate event at this time ensures that at lea st one |
| 257 // compositionupdate event is dispatched. | 286 // compositionupdate event is dispatched. |
| 258 // 2. Updating the existing composition node. | 287 // 2. Updating the existing composition node. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 TypingCommand::deleteSelection(*frame().document()); | 482 TypingCommand::deleteSelection(*frame().document()); |
| 454 } | 483 } |
| 455 | 484 |
| 456 DEFINE_TRACE(InputMethodController) | 485 DEFINE_TRACE(InputMethodController) |
| 457 { | 486 { |
| 458 visitor->trace(m_frame); | 487 visitor->trace(m_frame); |
| 459 visitor->trace(m_compositionRange); | 488 visitor->trace(m_compositionRange); |
| 460 } | 489 } |
| 461 | 490 |
| 462 } // namespace blink | 491 } // namespace blink |
| OLD | NEW |