From b91a6a24cc44c7bbc2d61abc0ecb6d60b7160e6c Mon Sep 17 00:00:00 2001 From: roytam1 Date: Wed, 19 Jan 2022 09:57:42 +0800 Subject: [PATCH] import changes from `dev' branch of rmottola/Arctic-Fox: - Bug 1001637 - Make math tables implement the nsIAccessibleTable interface. r=surkov (ebbb4325d6) - Bug 1149118 - Expose radio group with the correct role on OS X, r=surkov (4d4a95735c) - Bug 1113153 - use 'paragraph' role for paragraphs only, introduce 'text' role for small text containers, r=marcoz (14c4fa5881) - Bug 1175164 - Do not expose MathML semantics element in the accessibility tree. r=surkov (3945ae0367) - Bug 930843 part.1 Add test for checking isTrust attribute value of DOMActivate event r=smaug (14a49dd447) - Bug 930843 part.2 NS_UI_ACTIVATE event should be trusted event even if it's caused by an untrusted event r=smaug (e0af6165b5) - Bug 1156315 - Call DispatchInputEvent in more places on OS X. r=dvander (e24f42c09f) - Bug 1186015 part.1 Rename nsIMEContext to mozilla::widget::IMEContext r=jimm (077bf6e772) - Bug 1186015 part.2 Rename nsIMM32Handler to mozilla::widget::IMMHandler r=jimm+m_kato (a2098e33b5) - Bug 1184533 Rewrite range check in aOffset of nsIMM32Handler::GetCharacterRectOfSelectedTextAt() r=emk (fb68bc3c56) - Bug 555642 part.1 nsCaret should have a way to override the caret visible state for hiding caret temporarily and nsEditor should hide caret if composition string doesn't have caret information r=roc (9de4aa366c) - Bug 1171847 Remove unnecessary ',' in logging code in nsTextStore::Initialize() r=m_kato (78d0d43625) - Bug 1181714 nsTextStore should store previous focused document manager until new document manager actually gets focus r=m_kato (fd7e820af2) - Bug 1176950 nsTextStore should keep storing locked content until NOTIFY_IME_OF_COMPOSITION_UPDATE is notified r=emk (0a12349575) - Bug 1137539 part.1 Implement TSFStaticSink::IsGoogleJapaneseInputActive() r=emk (68d1f9a0ec) - Bug 1137539 part.2 Implement TSFStaticSink::IsATOKActive() r=emk (51a4208bfa) - Bug 1137539 part.3 Implement TSFStaticSink::IsFreeChangJieActive() r=emk (affbb81b96) - Bug 1137539 part.4 Implement TSFStaticSink::IsEasyChangjeiActive() r=emk (abd3e674b6) - Bug 1186014 Rename nsTextStore to mozilla::widget::TSFTextStore r=jimm+m_kato (ca63351f94) - Bug 1187351 TSFTextStore should forget modified range at notifying TSF of layout change since GetTextExt() shouldn't return TS_E_NOLAYOUT after that r=emk (48878793e0) - Bg 1187367 TSFTextStore shouldn't destroy native caret for ATOK until notifying TSF of layout change r=emk (a2a4022d15) - Bug 1187566 TSFTextStore::Content should compute mMinTextModified Offset only with the latest composition string and original composition string, and also the hack should be enabled on Win10 r=emk (1368885efe) - Bug 1050644 part.1 Add methods to check whether the active TIP is Chinese TIP which deosn't show candidate window in e10s mode r=emk (1b783e682e) - Bug 1050644 part.2 Hack ITextStoreACP::GetTextExt()'s offset for some Chinese TIPs of MS r=emk (c05cec10ce) - Bug 1187579 Enable TSF in e10s mode r=m_kato (1ae106231a) - Bug 555642 part.2 IME handlers on Windows shouldn't append caret range if the caret is in the target clause which doesn't have specific style r=m_kato (88bae2c8da) - Bug 1196124 Fix mismatch of printf style string and following arguments of MOZ_LOG() in IMMHandler::GetCharacterRectOfSelectedTextAt() r=m_kato (0f6debd0d3) - Bug 90712 Cancel composition when Enter key message isn't consumed by IME r=m_kato (0febdb1fd9) - pointer style (6c984274cd) - Bug 1177268 - implement aria-rowcount/index and aria-colcount/index, r=marcoz (92ac300374) - Bug 1153135 - Return possibility PEN working while APZC is enabled. r=jimm (8bc77ff84f) - Bug 1171073 - Suppress content scrolling issue on 64-bit platforms. r=kats (62db0dead3) - Bug 1121946, Implement e10 cursor drag feedback on Windows, r=jmathies (6e8218d202) - Bug 1144650 - Don't dispatch touch-based mouse events when APZ is handling touch. r=jimm (53ebea0d90) - Bug 1163056 - InkCollector activation at first PEN event. r=jimm (b28e0ee58b) - Bug 895274 part.3 Make the enum of event messages a named enum IGNORE IDL r=smaug (32e04a4e90) - spacing (b9249221dc) - Bug 1182966 - Part 3: Add some final annotations to DomainSet. r=mrbkap (3455822e89) - Bug 1050122 - Part 1: Enable Nuwa on debug builds, and kill it if the preference is false. r=khuey (46685a7bf3) - Bug 1146229: Remove calling convention modifier from local variable. r=surkov (e5f4b6e5d5) - bug 1168932 - Implement ProxyCreated and ProxyDestroyed to update mozAccessibles r=tbsaunde (77a007fa21) - Bug 1169701 - Fire native OS X accessibility events for proxied accessibles r=tbsaunde (c4847135a8) - bug 1172523 - fire useful text change events for proxies r=lsock (85b7f995b8) - remove spurious file (229c787360) - bug 1171117 - Fix cairo to build on iOS. r=jrmuizel (45709c8fe3) - Bug 963738 - Annotate XPCNativeMember, r=terrence (d1afdde52b) - Bug 1148383 - Add testcase for previously fixed object metadata issue r=terrence (2c1b762cba) - Bug 1149797 - Update browser jstests to treat ecma_6/extensions tests as 1.8, so that let is interpreted as a statement and not as an expression. r=bustage in a CLOSED TREE (ac6127d6bc) - Bug 1150858 - Unwrap the correct object in ArrayBuffer.transfer (r=sfink) (cf67906802) - Bug 1150380 - IonMonkey: MIPS: Fix JitRuntime::generateProfilerExitFrameTailStub. r=rankov (eeac49ddce) - use RootedValue for POW as in 1135708 (34c1c3d191) - Bug 1196648: IonMonkey - Don't run the lazy link stub for asmjs to jit fastpath, r=nbp (686d495371) - Bug 1121947, Implement e10 cursor drag feedback on Mac, r=smaug (f48df2d1) - and sync widget/TextEvents.h and TextRange.h with AF. --- accessible/atk/AccessibleWrap.cpp | 9 + accessible/base/ARIAMap.cpp | 2 +- accessible/base/MarkupMap.h | 28 +- accessible/base/Platform.h | 5 + accessible/base/Role.h | 42 +- accessible/base/RoleMap.h | 43 +- accessible/base/nsAccUtils.cpp | 21 + accessible/base/nsAccUtils.h | 2 + accessible/base/nsAccessibilityService.cpp | 38 +- accessible/base/nsCoreUtils.cpp | 8 +- accessible/base/nsCoreUtils.h | 13 +- accessible/generic/ARIAGridAccessible-inl.h | 24 +- accessible/generic/ARIAGridAccessible.cpp | 43 +- accessible/generic/ARIAGridAccessible.h | 26 +- accessible/generic/Accessible.cpp | 10 + accessible/generic/Accessible.h | 2 + accessible/generic/HyperTextAccessible.cpp | 9 +- accessible/generic/OuterDocAccessible.h | 1 + accessible/html/HTMLTableAccessible.cpp | 45 +- accessible/html/HTMLTableAccessible.h | 2 + accessible/interfaces/nsIAccessibleRole.idl | 42 +- accessible/ipc/DocAccessibleParent.cpp | 17 + accessible/ipc/DocAccessibleParent.h | 5 + accessible/ipc/PDocAccessible.ipdl | 2 + accessible/mac/AccessibleWrap.h | 8 + accessible/mac/AccessibleWrap.mm | 136 +- accessible/mac/Platform.mm | 44 +- accessible/mac/moz.build | 1 + accessible/mac/mozAccessible.h | 9 +- accessible/mac/mozAccessible.mm | 20 +- accessible/other/Platform.cpp | 6 + .../mochitest/attributes/test_obj_group.html | 11 + .../tests/mochitest/elm/test_HTMLSpec.html | 12 +- .../tests/mochitest/elm/test_MathMLSpec.html | 26 +- accessible/tests/mochitest/role.js | 5 +- .../tests/mochitest/role/test_aria.html | 8 +- .../tests/mochitest/role/test_general.html | 6 +- accessible/tests/mochitest/table.js | 29 +- accessible/tests/mochitest/table/a11y.ini | 1 + .../tests/mochitest/table/test_mtable.html | 128 ++ .../table/test_struct_ariatreegrid.html | 3 +- .../tests/mochitest/tree/test_aria_list.html | 2 +- .../tree/test_aria_presentation.html | 4 +- .../tests/mochitest/tree/test_dockids.html | 6 +- .../tests/mochitest/tree/test_formctrl.xul | 2 +- .../mochitest/tree/test_invalid_img.xhtml | 2 +- .../tests/mochitest/tree/test_txtcntr.html | 4 +- .../mochitest/treeupdate/test_textleaf.html | 10 +- accessible/windows/msaa/Platform.cpp | 6 + accessible/xpcom/xpcAccessibleTable.cpp | 2 +- accessible/xul/XULFormControlAccessible.cpp | 2 +- b2g/app/B2GLoader.cpp | 7 + b2g/app/b2g.js | 2 - .../components/shell/nsMacShellService.cpp | 3 +- caps/DomainPolicy.h | 4 +- dom/base/Element.cpp | 9 +- dom/base/FragmentOrElement.cpp | 2 + dom/base/nsContentUtils.cpp | 41 +- dom/base/nsContentUtils.h | 16 +- dom/base/nsCopySupport.cpp | 19 +- dom/base/nsCopySupport.h | 6 +- dom/base/nsDOMWindowUtils.cpp | 43 +- dom/base/nsFocusManager.cpp | 60 +- dom/base/nsFocusManager.h | 6 +- dom/base/nsGkAtomList.h | 4 + dom/base/nsGlobalWindow.cpp | 14 +- dom/base/nsGlobalWindow.h | 5 +- dom/base/nsGlobalWindowCommands.cpp | 8 +- dom/base/nsPIDOMWindow.h | 8 +- dom/base/nsScriptElement.cpp | 6 +- dom/events/AnimationEvent.cpp | 2 +- dom/events/BeforeAfterKeyboardEvent.cpp | 3 +- dom/events/ClipboardEvent.cpp | 2 +- dom/events/CompositionEvent.cpp | 3 +- dom/events/DataTransfer.cpp | 4 +- dom/events/DragEvent.cpp | 3 +- dom/events/Event.cpp | 22 +- dom/events/Event.h | 2 +- dom/events/EventListenerManager.cpp | 136 +- dom/events/EventListenerManager.h | 54 +- dom/events/EventStateManager.cpp | 71 +- dom/events/EventStateManager.h | 9 +- dom/events/IMEStateManager.cpp | 2 +- dom/events/InputEvent.cpp | 4 +- dom/events/InternalMutationEvent.h | 2 +- dom/events/KeyboardEvent.cpp | 7 +- dom/events/MouseEvent.cpp | 5 +- dom/events/MouseScrollEvent.cpp | 4 +- dom/events/MutationEvent.cpp | 2 +- dom/events/NotifyPaintEvent.cpp | 8 +- dom/events/NotifyPaintEvent.h | 8 +- dom/events/PointerEvent.cpp | 3 +- dom/events/SimpleGestureEvent.cpp | 3 +- dom/events/TextComposition.cpp | 8 +- dom/events/TextComposition.h | 8 +- dom/events/TouchEvent.cpp | 3 +- dom/events/TransitionEvent.cpp | 2 +- dom/events/UIEvent.cpp | 2 +- dom/events/WheelEvent.cpp | 3 +- dom/events/WheelHandlingHelper.cpp | 2 + dom/events/XULCommandEvent.cpp | 3 +- dom/events/test/mochitest.ini | 1 + dom/events/test/test_dom_activate_event.html | 89 ++ dom/html/HTMLButtonElement.cpp | 9 +- dom/html/HTMLButtonElement.h | 2 +- dom/html/HTMLFieldSetElement.cpp | 2 +- dom/html/HTMLFieldSetElement.h | 2 +- dom/html/HTMLFormElement.cpp | 6 +- dom/html/HTMLInputElement.cpp | 14 +- dom/html/HTMLInputElement.h | 2 +- dom/html/HTMLLabelElement.cpp | 3 + dom/html/HTMLObjectElement.cpp | 2 + dom/html/HTMLSelectElement.cpp | 2 +- dom/html/HTMLSelectElement.h | 2 +- dom/html/HTMLTextAreaElement.cpp | 2 +- dom/html/HTMLTextAreaElement.h | 2 +- dom/html/nsGenericHTMLElement.cpp | 6 +- dom/html/nsGenericHTMLElement.h | 4 +- dom/html/nsIFormControl.h | 4 +- dom/interfaces/base/nsIDOMWindowUtils.idl | 2 - dom/ipc/PBrowser.ipdl | 3 +- dom/ipc/TabParent.cpp | 6 +- dom/ipc/TabParent.h | 2 +- dom/plugins/base/nsPluginInstanceOwner.cpp | 19 +- dom/smil/TimeEvent.cpp | 2 +- dom/smil/nsSMILTimedElement.cpp | 11 +- dom/smil/nsSMILTimedElement.h | 4 +- editor/libeditor/IMETextTxn.cpp | 9 +- editor/libeditor/nsEditor.cpp | 29 + editor/libeditor/nsEditor.h | 8 + editor/libeditor/nsEditorEventListener.cpp | 2 + editor/libeditor/nsPlaintextEditor.cpp | 11 +- editor/libeditor/nsPlaintextEditor.h | 4 +- gfx/cairo/cairo/src/cairo-quartz-font.c | 12 +- gfx/cairo/cairo/src/cairo-quartz-image.h | 5 + gfx/cairo/cairo/src/cairo-quartz-surface.c | 7 + gfx/cairo/cairo/src/cairo-quartz.h | 8 +- gfx/cairo/cairo/src/moz.build | 2 +- gfx/layers/apz/src/APZCTreeManager.cpp | 2 + gfx/layers/apz/util/APZCCallbackHelper.cpp | 2 +- gfx/layers/apz/util/APZCCallbackHelper.h | 2 +- ipc/glue/ProcessUtils_linux.cpp | 9 + js/src/asmjs/AsmJSModule.cpp | 6 + js/src/devtools/rootAnalysis/annotations.js | 5 + .../tests/basic/testArrayBufferTransfer.js | 6 + js/src/jit-test/tests/gc/bug-1148383.js | 19 + js/src/jit-test/tests/ion/bug1196648.js | 18 + js/src/jit/BaselineJIT.cpp | 15 + js/src/jit/BaselineJIT.h | 4 + js/src/jit/mips32/Trampoline-mips32.cpp | 4 +- js/src/tests/browser.js | 4 + js/src/tests/ecma_6/Class/shell.js | 4 +- js/src/tests/ecma_6/extensions/shell.js | 5 + js/src/vm/ArrayBufferObject.cpp | 4 +- js/src/vm/Interpreter.cpp | 5 +- .../gtest/TestAccessibleCaretEventHub.cpp | 8 +- layout/base/nsCaret.cpp | 26 +- layout/base/nsCaret.h | 30 +- layout/base/nsPresShell.cpp | 18 +- layout/generic/nsFrameSetFrame.cpp | 2 + layout/generic/nsSelection.cpp | 3 +- layout/style/nsAnimationManager.cpp | 2 +- layout/style/nsAnimationManager.h | 3 +- layout/xul/nsButtonBoxFrame.cpp | 3 + layout/xul/nsImageBoxFrame.cpp | 6 +- layout/xul/nsResizerFrame.cpp | 3 + layout/xul/nsScrollBoxFrame.cpp | 3 + layout/xul/nsScrollbarButtonFrame.cpp | 2 + layout/xul/nsSliderFrame.cpp | 3 + layout/xul/nsSplitterFrame.cpp | 7 +- layout/xul/nsTitleBarFrame.cpp | 3 + modules/libpref/init/all.js | 4 + widget/BasicEvents.h | 50 +- widget/ContentCache.cpp | 6 +- widget/ContentCache.h | 2 +- widget/ContentEvents.h | 18 +- widget/EventForwards.h | 8 +- widget/IMEData.h | 6 +- widget/InputData.cpp | 26 +- widget/MiscEvents.h | 4 +- widget/MouseEvents.h | 16 +- widget/TextEventDispatcher.cpp | 8 +- widget/TextEventDispatcher.h | 4 +- widget/TextEvents.h | 26 +- widget/TextRange.h | 24 +- widget/TouchEvents.h | 6 +- widget/cocoa/TextInputHandler.mm | 4 +- widget/cocoa/nsChildView.h | 2 +- widget/cocoa/nsChildView.mm | 79 +- widget/gonk/nsAppShell.cpp | 4 +- widget/gtk/IMContextWrapper.cpp | 4 +- widget/gtk/nsDragService.cpp | 2 +- widget/gtk/nsWindow.cpp | 4 +- widget/gtk/nsWindow.h | 4 +- widget/nsBaseDragService.cpp | 21 +- widget/nsBaseDragService.h | 4 + widget/nsGUIEventIPC.h | 19 + .../{nsIMM32Handler.cpp => IMMHandler.cpp} | 1411 +++++++++-------- .../{nsIMM32Handler.h => IMMHandler.h} | 86 +- widget/windows/KeyboardLayout.cpp | 3 +- .../{nsTextStore.cpp => TSFTextStore.cpp} | 1384 +++++++++------- .../windows/{nsTextStore.h => TSFTextStore.h} | 125 +- widget/windows/WinIMEHandler.cpp | 151 +- widget/windows/WinUtils.cpp | 22 +- widget/windows/WinUtils.h | 3 +- widget/windows/moz.build | 4 +- widget/windows/nsNativeDragTarget.cpp | 36 +- widget/windows/nsNativeDragTarget.h | 6 +- widget/windows/nsWindow.cpp | 124 +- widget/windows/nsWindow.h | 16 +- 210 files changed, 3609 insertions(+), 2238 deletions(-) create mode 100644 accessible/tests/mochitest/table/test_mtable.html create mode 100644 dom/events/test/test_dom_activate_event.html create mode 100644 js/src/jit-test/tests/gc/bug-1148383.js create mode 100644 js/src/jit-test/tests/ion/bug1196648.js rename widget/windows/{nsIMM32Handler.cpp => IMMHandler.cpp} (66%) rename widget/windows/{nsIMM32Handler.h => IMMHandler.h} (85%) rename widget/windows/{nsTextStore.cpp => TSFTextStore.cpp} (78%) rename widget/windows/{nsTextStore.h => TSFTextStore.h} (89%) diff --git a/accessible/atk/AccessibleWrap.cpp b/accessible/atk/AccessibleWrap.cpp index 5a5bd7fea0..ab0cd6b577 100644 --- a/accessible/atk/AccessibleWrap.cpp +++ b/accessible/atk/AccessibleWrap.cpp @@ -1426,6 +1426,15 @@ MaiAtkObject::FireStateChangeEvent(uint64_t aState, bool aEnabled) } } +void +a11y::ProxyTextChangeEvent(ProxyAccessible* aTarget, const nsString& aStr, + int32_t aStart, uint32_t aLen, bool aIsInsert, + bool aFromUser) +{ + MaiAtkObject* atkObj = MAI_ATK_OBJECT(GetWrapperFor(aTarget)); + atkObj->FireTextChangeEvent(aStr, aStart, aLen, aIsInsert, aFromUser); +} + #define OLD_TEXT_INSERTED "text_changed::insert" #define OLD_TEXT_REMOVED "text_changed::delete" static const char* oldTextChangeStrings[2][2] = { diff --git a/accessible/base/ARIAMap.cpp b/accessible/base/ARIAMap.cpp index cb285c4d3a..5a970c6993 100644 --- a/accessible/base/ARIAMap.cpp +++ b/accessible/base/ARIAMap.cpp @@ -478,7 +478,7 @@ static nsRoleMapEntry sWAIRoleMaps[] = }, { // radiogroup &nsGkAtoms::radiogroup, - roles::GROUPING, + roles::RADIO_GROUP, kUseMapRole, eNoValue, eNoAction, diff --git a/accessible/base/MarkupMap.h b/accessible/base/MarkupMap.h index c2a1d8560d..7eba4680b4 100644 --- a/accessible/base/MarkupMap.h +++ b/accessible/base/MarkupMap.h @@ -103,6 +103,10 @@ MARKUPMAP(li, New_HTMLListitem, 0) +MARKUPMAP(map, + nullptr, + roles::TEXT_CONTAINER) + MARKUPMAP(math, New_HyperText, roles::MATHML_MATH) @@ -205,22 +209,22 @@ MARKUPMAP(mmultiscripts_, roles::MATHML_MULTISCRIPTS) MARKUPMAP(mtable_, - New_HyperText, + New_HTMLTableAccessible, roles::MATHML_TABLE, AttrFromDOM(align, align), AttrFromDOM(columnlines_, columnlines_), AttrFromDOM(rowlines_, rowlines_)) MARKUPMAP(mlabeledtr_, - New_HyperText, + New_HTMLTableRowAccessible, roles::MATHML_LABELED_ROW) MARKUPMAP(mtr_, - New_HyperText, + New_HTMLTableRowAccessible, roles::MATHML_TABLE_ROW) MARKUPMAP(mtd_, - New_HyperText, + New_HTMLTableCellAccessible, roles::MATHML_CELL) MARKUPMAP(maction_, @@ -233,18 +237,6 @@ MARKUPMAP(merror_, New_HyperText, roles::MATHML_ERROR) -MARKUPMAP(semantics_, - New_HyperText, - roles::MATHML_SEMANTICS) - -MARKUPMAP(annotation_, - New_HyperText, - roles::MATHML_ANNOTATION) - -MARKUPMAP(annotation_xml_, - New_HyperText, - roles::MATHML_XML_ANNOTATION) - MARKUPMAP(mstack_, New_HyperText, roles::MATHML_STACK, @@ -304,6 +296,10 @@ MARKUPMAP(output, roles::SECTION, Attr(live, polite)) +MARKUPMAP(p, + nullptr, + roles::PARAGRAPH) + MARKUPMAP(progress, New_HTMLProgress, 0) diff --git a/accessible/base/Platform.h b/accessible/base/Platform.h index 01d33a81a4..62c88b894c 100644 --- a/accessible/base/Platform.h +++ b/accessible/base/Platform.h @@ -6,6 +6,8 @@ #include +class nsString; + namespace mozilla { namespace a11y { @@ -70,6 +72,9 @@ void ProxyEvent(ProxyAccessible* aTarget, uint32_t aEventType); void ProxyStateChangeEvent(ProxyAccessible* aTarget, uint64_t aState, bool aEnabled); void ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset); +void ProxyTextChangeEvent(ProxyAccessible* aTarget, const nsString& aStr, + int32_t aStart, uint32_t aLen, bool aIsInsert, + bool aFromUser); } // namespace a11y } // namespace mozilla diff --git a/accessible/base/Role.h b/accessible/base/Role.h index 928668a6ad..dab6c53079 100644 --- a/accessible/base/Role.h +++ b/accessible/base/Role.h @@ -926,57 +926,53 @@ enum Role { */ MATHML_ERROR = 157, - /** - * A MathML semantics annotation element (semantics in MathML). - */ - MATHML_SEMANTICS = 158, - - /** - * A MathML annotation (annotation in MathML). - */ - MATHML_ANNOTATION = 159, - - /** - * A MathML XML annotation (annotation-xml in MathML). - */ - MATHML_XML_ANNOTATION = 160, - /** * A MathML stacked (rows of numbers) element (mstack in MathML). */ - MATHML_STACK = 161, + MATHML_STACK = 158, /** * A MathML long division element (mlongdiv in MathML). */ - MATHML_LONG_DIVISION = 162, + MATHML_LONG_DIVISION = 159, /** * A MathML stack group (msgroup in MathML). */ - MATHML_STACK_GROUP = 163, + MATHML_STACK_GROUP = 160, /** * A MathML stack row (msrow in MathML). */ - MATHML_STACK_ROW = 164, + MATHML_STACK_ROW = 161, /** * MathML carries, borrows, or crossouts for a row (mscarries in MathML). */ - MATHML_STACK_CARRIES = 165, + MATHML_STACK_CARRIES = 162, /** * A MathML carry, borrow, or crossout for a column (mscarry in MathML). */ - MATHML_STACK_CARRY = 166, + MATHML_STACK_CARRY = 163, /** * A MathML line in a stack (msline in MathML). */ - MATHML_STACK_LINE = 167, + MATHML_STACK_LINE = 164, - LAST_ROLE = MATHML_STACK_LINE + /** + * A group containing radio buttons + */ + RADIO_GROUP = 165, + + /** + * A text container exposing brief amount of information. See related + * TEXT_CONTAINER role. + */ + TEXT = 166, + + LAST_ROLE = TEXT }; } // namespace role diff --git a/accessible/base/RoleMap.h b/accessible/base/RoleMap.h index e58bafcc26..aedca120f2 100644 --- a/accessible/base/RoleMap.h +++ b/accessible/base/RoleMap.h @@ -754,7 +754,7 @@ ROLE(TERMINAL, ROLE(TEXT_CONTAINER, "text container", - ATK_ROLE_TEXT, + ATK_ROLE_SECTION, NSAccessibilityGroupRole, USE_ROLE_STRING, IA2_ROLE_TEXT_FRAME, @@ -1280,30 +1280,6 @@ ROLE(MATHML_ERROR, IA2_ROLE_UNKNOWN, eNoNameRule) -ROLE(MATHML_SEMANTICS, - "mathml semantics", - ATK_ROLE_UNKNOWN, - NSAccessibilityUnknownRole, - 0, - IA2_ROLE_UNKNOWN, - eNoNameRule) - -ROLE(MATHML_ANNOTATION, - "mathml annotation", - ATK_ROLE_UNKNOWN, - NSAccessibilityUnknownRole, - 0, - IA2_ROLE_UNKNOWN, - eNoNameRule) - -ROLE(MATHML_XML_ANNOTATION, - "mathml xml annotation", - ATK_ROLE_UNKNOWN, - NSAccessibilityUnknownRole, - 0, - IA2_ROLE_UNKNOWN, - eNoNameRule) - ROLE(MATHML_STACK, "mathml stack", ATK_ROLE_UNKNOWN, @@ -1359,3 +1335,20 @@ ROLE(MATHML_STACK_LINE, 0, IA2_ROLE_UNKNOWN, eNoNameRule) + +ROLE(RADIO_GROUP, + "grouping", + ATK_ROLE_PANEL, + NSAccessibilityRadioGroupRole, + ROLE_SYSTEM_GROUPING, + ROLE_SYSTEM_GROUPING, + eNoNameRule) + +ROLE(TEXT, + "text", + ATK_ROLE_STATIC, + NSAccessibilityGroupRole, + USE_ROLE_STRING, + IA2_ROLE_TEXT_FRAME, + eNameFromSubtreeIfReqRule) + diff --git a/accessible/base/nsAccUtils.cpp b/accessible/base/nsAccUtils.cpp index aae2bc449f..dc7d222bdc 100644 --- a/accessible/base/nsAccUtils.cpp +++ b/accessible/base/nsAccUtils.cpp @@ -242,6 +242,27 @@ nsAccUtils::IsARIASelected(Accessible* aAccessible) nsGkAtoms::_true, eCaseMatters); } +Accessible* +nsAccUtils::TableFor(Accessible* aRow) +{ + if (aRow) { + Accessible* table = aRow->Parent(); + if (table) { + roles::Role tableRole = table->Role(); + if (tableRole == roles::GROUPING) { // if there's a rowgroup. + table = table->Parent(); + if (table) + tableRole = table->Role(); + } + + return tableRole == roles::TABLE || tableRole == roles::TREE_TABLE ? + table : nullptr; + } + } + + return nullptr; +} + HyperTextAccessible* nsAccUtils::GetTextContainer(nsINode* aNode) { diff --git a/accessible/base/nsAccUtils.h b/accessible/base/nsAccUtils.h index 9cd57c1406..57676b90a2 100644 --- a/accessible/base/nsAccUtils.h +++ b/accessible/base/nsAccUtils.h @@ -134,6 +134,8 @@ public: */ static HyperTextAccessible* GetTextContainer(nsINode* aNode); + static Accessible* TableFor(Accessible* aRow); + /** * Return true if the DOM node of given accessible has aria-selected="true" * attribute. diff --git a/accessible/base/nsAccessibilityService.cpp b/accessible/base/nsAccessibilityService.cpp index 429855f395..dcafd48db9 100644 --- a/accessible/base/nsAccessibilityService.cpp +++ b/accessible/base/nsAccessibilityService.cpp @@ -196,6 +196,18 @@ static Accessible* New_HTMLOutput(nsIContent* aContent, Accessible* aContext) static Accessible* New_HTMLProgress(nsIContent* aContent, Accessible* aContext) { return new HTMLProgressMeterAccessible(aContent, aContext->Document()); } +static Accessible* +New_HTMLTableAccessible(nsIContent* aContent, Accessible* aContext) + { return new HTMLTableAccessible(aContent, aContext->Document()); } + +static Accessible* +New_HTMLTableRowAccessible(nsIContent* aContent, Accessible* aContext) + { return new HTMLTableRowAccessible(aContent, aContext->Document()); } + +static Accessible* +New_HTMLTableCellAccessible(nsIContent* aContent, Accessible* aContext) + { return new HTMLTableCellAccessible(aContent, aContext->Document()); } + static Accessible* New_HTMLTableHeaderCell(nsIContent* aContent, Accessible* aContext) { @@ -1074,11 +1086,12 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode, } if (!newAcc && content->IsHTMLElement()) { // HTML accessibles - bool isARIATableOrCell = roleMapEntry && - (roleMapEntry->accTypes & (eTableCell | eTable)); + bool isARIATablePart = roleMapEntry && + (roleMapEntry->accTypes & (eTableCell | eTableRow | eTable)); - if (!isARIATableOrCell || + if (!isARIATablePart || frame->AccessibleType() == eHTMLTableCellType || + frame->AccessibleType() == eHTMLTableRowType || frame->AccessibleType() == eHTMLTableType) { // Prefer to use markup to decide if and what kind of accessible to create, const MarkupMapInfo* markupMap = @@ -1090,13 +1103,17 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode, newAcc = CreateAccessibleByFrameType(frame, content, aContext); } - // In case of ARIA grids use grid-specific classes if it's not native table - // based. - if (isARIATableOrCell && (!newAcc || newAcc->IsGenericHyperText())) { + // In case of ARIA grid or table use table-specific classes if it's not + // native table based. + if (isARIATablePart && (!newAcc || newAcc->IsGenericHyperText())) { if ((roleMapEntry->accTypes & eTableCell)) { if (aContext->IsTableRow()) newAcc = new ARIAGridCellAccessibleWrap(content, document); + } else if (roleMapEntry->IsOfType(eTableRow)) { + if (aContext->IsTable()) + newAcc = new ARIARowAccessible(content, document); + } else if (roleMapEntry->IsOfType(eTable)) { newAcc = new ARIAGridAccessibleWrap(content, document); } @@ -1173,12 +1190,15 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode, newAcc = markupMap->new_func(content, aContext); // Fall back to text when encountering Content MathML. - if (!newAcc && !content->IsAnyOfMathMLElements(nsGkAtoms::mpadded_, + if (!newAcc && !content->IsAnyOfMathMLElements(nsGkAtoms::annotation_, + nsGkAtoms::annotation_xml_, + nsGkAtoms::mpadded_, nsGkAtoms::mphantom_, nsGkAtoms::maligngroup_, nsGkAtoms::malignmark_, - nsGkAtoms::mspace_)) { - newAcc = new HyperTextAccessible(content, document); + nsGkAtoms::mspace_, + nsGkAtoms::semantics_)) { + newAcc = new HyperTextAccessible(content, document); } } } diff --git a/accessible/base/nsCoreUtils.cpp b/accessible/base/nsCoreUtils.cpp index 4e9b2001c4..251964eecc 100644 --- a/accessible/base/nsCoreUtils.cpp +++ b/accessible/base/nsCoreUtils.cpp @@ -118,11 +118,11 @@ nsCoreUtils::DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj, } void -nsCoreUtils::DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY, +nsCoreUtils::DispatchMouseEvent(EventMessage aMessage, int32_t aX, int32_t aY, nsIContent *aContent, nsIFrame *aFrame, nsIPresShell *aPresShell, nsIWidget *aRootWidget) { - WidgetMouseEvent event(true, aEventType, aRootWidget, + WidgetMouseEvent event(true, aMessage, aRootWidget, WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal); event.refPoint = LayoutDeviceIntPoint(aX, aY); @@ -137,14 +137,14 @@ nsCoreUtils::DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY, } void -nsCoreUtils::DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY, +nsCoreUtils::DispatchTouchEvent(EventMessage aMessage, int32_t aX, int32_t aY, nsIContent* aContent, nsIFrame* aFrame, nsIPresShell* aPresShell, nsIWidget* aRootWidget) { if (!dom::TouchEvent::PrefEnabled()) return; - WidgetTouchEvent event(true, aEventType, aRootWidget); + WidgetTouchEvent event(true, aMessage, aRootWidget); event.time = PR_IntervalNow(); diff --git a/accessible/base/nsCoreUtils.h b/accessible/base/nsCoreUtils.h index 85efe80636..2e1593bed6 100644 --- a/accessible/base/nsCoreUtils.h +++ b/accessible/base/nsCoreUtils.h @@ -6,6 +6,7 @@ #ifndef nsCoreUtils_h_ #define nsCoreUtils_h_ +#include "mozilla/EventForwards.h" #include "nsIContent.h" #include "nsIDocument.h" // for GetShell() #include "nsIPresShell.h" @@ -49,7 +50,7 @@ public: /** * Send mouse event to the given element. * - * @param aEventType [in] an event type (see BasicEvents.h for constants) + * @param aMessage [in] an event message (see EventForwards.h) * @param aX [in] x coordinate in dev pixels * @param aY [in] y coordinate in dev pixels * @param aContent [in] the element @@ -57,14 +58,15 @@ public: * @param aPresShell [in] the presshell for the element * @param aRootWidget [in] the root widget of the element */ - static void DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY, + static void DispatchMouseEvent(mozilla::EventMessage aMessage, + int32_t aX, int32_t aY, nsIContent *aContent, nsIFrame *aFrame, nsIPresShell *aPresShell, nsIWidget *aRootWidget); /** * Send a touch event with a single touch point to the given element. * - * @param aEventType [in] an event type (see BasicEvents.h for constants) + * @param aMessage [in] an event message (see EventForwards.h) * @param aX [in] x coordinate in dev pixels * @param aY [in] y coordinate in dev pixels * @param aContent [in] the element @@ -72,7 +74,8 @@ public: * @param aPresShell [in] the presshell for the element * @param aRootWidget [in] the root widget of the element */ - static void DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY, + static void DispatchTouchEvent(mozilla::EventMessage aMessage, + int32_t aX, int32_t aY, nsIContent* aContent, nsIFrame* aFrame, nsIPresShell* aPresShell, nsIWidget* aRootWidget); @@ -223,7 +226,7 @@ public: * attribute or wrong value then false is returned. */ static bool GetUIntAttr(nsIContent *aContent, nsIAtom *aAttr, - int32_t *aUInt); + int32_t* aUInt); /** * Returns language for the given node. diff --git a/accessible/generic/ARIAGridAccessible-inl.h b/accessible/generic/ARIAGridAccessible-inl.h index a502aa600e..bb2bc9705b 100644 --- a/accessible/generic/ARIAGridAccessible-inl.h +++ b/accessible/generic/ARIAGridAccessible-inl.h @@ -10,35 +10,15 @@ #include "ARIAGridAccessible.h" #include "AccIterator.h" +#include "nsAccUtils.h" namespace mozilla { namespace a11y { -inline Accessible* -ARIAGridCellAccessible::TableFor(Accessible* aRow) const -{ - if (aRow) { - Accessible* table = aRow->Parent(); - if (table) { - roles::Role tableRole = table->Role(); - if (tableRole == roles::GROUPING) { // if there's a rowgroup. - table = table->Parent(); - if (table) - tableRole = table->Role(); - } - - return tableRole == roles::TABLE || tableRole == roles::TREE_TABLE ? - table : nullptr; - } - } - - return nullptr; -} - inline int32_t ARIAGridCellAccessible::RowIndexFor(Accessible* aRow) const { - Accessible* table = TableFor(aRow); + Accessible* table = nsAccUtils::TableFor(aRow); if (table) { int32_t rowIdx = 0; Accessible* row = nullptr; diff --git a/accessible/generic/ARIAGridAccessible.cpp b/accessible/generic/ARIAGridAccessible.cpp index 1aed0e6b99..8473436362 100644 --- a/accessible/generic/ARIAGridAccessible.cpp +++ b/accessible/generic/ARIAGridAccessible.cpp @@ -485,6 +485,34 @@ ARIAGridAccessible::SetARIASelected(Accessible* aAccessible, return NS_OK; } + +//////////////////////////////////////////////////////////////////////////////// +// ARIARowAccessible +//////////////////////////////////////////////////////////////////////////////// + +ARIARowAccessible:: + ARIARowAccessible(nsIContent* aContent, DocAccessible* aDoc) : + AccessibleWrap(aContent, aDoc) +{ + mGenericTypes |= eTableRow; +} + +NS_IMPL_ISUPPORTS_INHERITED0(ARIARowAccessible, Accessible) + +GroupPos +ARIARowAccessible::GroupPosition() +{ + int32_t count = 0, index = 0; + if (nsCoreUtils::GetUIntAttr(nsAccUtils::TableFor(this)->GetContent(), + nsGkAtoms::aria_rowcount, &count) && + nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_rowindex, &index)) { + return GroupPos(0, index, count); + } + + return AccessibleWrap::GroupPosition(); +} + + //////////////////////////////////////////////////////////////////////////////// // ARIAGridCellAccessible //////////////////////////////////////////////////////////////////////////////// @@ -508,7 +536,7 @@ NS_IMPL_ISUPPORTS_INHERITED0(ARIAGridCellAccessible, HyperTextAccessible) TableAccessible* ARIAGridCellAccessible::Table() const { - Accessible* table = TableFor(Row()); + Accessible* table = nsAccUtils::TableFor(Row()); return table ? table->AsTable() : nullptr; } @@ -613,3 +641,16 @@ ARIAGridCellAccessible::NativeAttributes() return attributes.forget(); } + +GroupPos +ARIAGridCellAccessible::GroupPosition() +{ + int32_t count = 0, index = 0; + if (nsCoreUtils::GetUIntAttr(Table()->AsAccessible()->GetContent(), + nsGkAtoms::aria_colcount, &count) && + nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_colindex, &index)) { + return GroupPos(0, index, count); + } + + return GroupPos(); +} diff --git a/accessible/generic/ARIAGridAccessible.h b/accessible/generic/ARIAGridAccessible.h index 7c56084898..c9a36cc6ef 100644 --- a/accessible/generic/ARIAGridAccessible.h +++ b/accessible/generic/ARIAGridAccessible.h @@ -73,6 +73,24 @@ protected: }; +/** + * Accessible for ARIA row. + */ +class ARIARowAccessible : public AccessibleWrap +{ +public: + ARIARowAccessible(nsIContent* aContent, DocAccessible* aDoc); + + NS_DECL_ISUPPORTS_INHERITED + + // Accessible + virtual mozilla::a11y::GroupPos GroupPosition() override; + +protected: + virtual ~ARIARowAccessible() {} +}; + + /** * Accessible for ARIA gridcell and rowheader/columnheader. */ @@ -88,6 +106,7 @@ public: virtual TableCellAccessible* AsTableCell() override { return this; } virtual void ApplyARIAState(uint64_t* aState) const override; virtual already_AddRefed NativeAttributes() override; + virtual mozilla::a11y::GroupPos GroupPosition() override; protected: virtual ~ARIAGridCellAccessible() {} @@ -98,14 +117,9 @@ protected: Accessible* Row() const { Accessible* row = Parent(); - return row && row->Role() == roles::ROW ? row : nullptr; + return row && row->IsTableRow() ? row : nullptr; } - /** - * Return a table for the given row. - */ - Accessible* TableFor(Accessible* aRow) const; - /** * Return index of the given row. */ diff --git a/accessible/generic/Accessible.cpp b/accessible/generic/Accessible.cpp index 8d6287e4f5..71afd5aa64 100644 --- a/accessible/generic/Accessible.cpp +++ b/accessible/generic/Accessible.cpp @@ -864,6 +864,16 @@ Accessible::HandleAccEvent(AccEvent* aEvent) ipcDoc->SendEvent(id, event->GetCaretOffset()); break; } + case nsIAccessibleEvent::EVENT_TEXT_INSERTED: + case nsIAccessibleEvent::EVENT_TEXT_REMOVED: { + AccTextChangeEvent* event = downcast_accEvent(aEvent); + ipcDoc->SendTextChangeEvent(id, event->ModifiedText(), + event->GetStartOffset(), + event->GetLength(), + event->IsTextInserted(), + event->IsFromUserInput()); + break; + } default: ipcDoc->SendEvent(id, aEvent->GetEventType()); } diff --git a/accessible/generic/Accessible.h b/accessible/generic/Accessible.h index 03e9e7c03d..88050de28e 100644 --- a/accessible/generic/Accessible.h +++ b/accessible/generic/Accessible.h @@ -82,6 +82,8 @@ enum ENameValueFlag { struct GroupPos { GroupPos() : level(0), posInSet(0), setSize(0) { } + GroupPos(int32_t aLevel, int32_t aPosInSet, int32_t aSetSize) : + level(aLevel), posInSet(aPosInSet), setSize(aSetSize) { } int32_t level; int32_t posInSet; diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp index b3e1b1f837..abaadfcad1 100644 --- a/accessible/generic/HyperTextAccessible.cpp +++ b/accessible/generic/HyperTextAccessible.cpp @@ -63,12 +63,11 @@ HyperTextAccessible::NativeRole() if (r != roles::NOTHING) return r; - // Treat block frames as paragraphs - nsIFrame *frame = GetFrame(); - if (frame && frame->GetType() == nsGkAtoms::blockFrame) - return roles::PARAGRAPH; + nsIFrame* frame = GetFrame(); + if (frame && frame->GetType() == nsGkAtoms::inlineFrame) + return roles::TEXT; - return roles::TEXT_CONTAINER; // In ATK this works + return roles::TEXT_CONTAINER; } uint64_t diff --git a/accessible/generic/OuterDocAccessible.h b/accessible/generic/OuterDocAccessible.h index 02b4559413..5d0489a1be 100644 --- a/accessible/generic/OuterDocAccessible.h +++ b/accessible/generic/OuterDocAccessible.h @@ -52,6 +52,7 @@ Accessible::AsOuterDoc() { return IsOuterDoc() ? static_cast(this) : nullptr; } + } // namespace a11y } // namespace mozilla diff --git a/accessible/html/HTMLTableAccessible.cpp b/accessible/html/HTMLTableAccessible.cpp index e6ae5d43a2..d14b48c9a4 100644 --- a/accessible/html/HTMLTableAccessible.cpp +++ b/accessible/html/HTMLTableAccessible.cpp @@ -60,6 +60,9 @@ NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableCellAccessible, HyperTextAccessible) role HTMLTableCellAccessible::NativeRole() { + if (mContent->IsMathMLElement(nsGkAtoms::mtd_)) { + return roles::MATHML_CELL; + } return roles::CELL; } @@ -140,6 +143,19 @@ HTMLTableCellAccessible::NativeAttributes() return attributes.forget(); } +GroupPos +HTMLTableCellAccessible::GroupPosition() +{ + int32_t count = 0, index = 0; + if (nsCoreUtils::GetUIntAttr(Table()->AsAccessible()->GetContent(), + nsGkAtoms::aria_colcount, &count) && + nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_colindex, &index)) { + return GroupPos(0, index, count); + } + + return HyperTextAccessibleWrap::GroupPosition(); +} + //////////////////////////////////////////////////////////////////////////////// // HTMLTableCellAccessible: TableCellAccessible implementation @@ -148,8 +164,7 @@ HTMLTableCellAccessible::Table() const { Accessible* parent = const_cast(this); while ((parent = parent->Parent())) { - roles::Role role = parent->Role(); - if (role == roles::TABLE || role == roles::TREE_TABLE) + if (parent->IsTable()) return parent->AsTable(); } @@ -349,9 +364,27 @@ NS_IMPL_ISUPPORTS_INHERITED0(HTMLTableRowAccessible, Accessible) role HTMLTableRowAccessible::NativeRole() { + if (mContent->IsMathMLElement(nsGkAtoms::mtr_)) { + return roles::MATHML_TABLE_ROW; + } else if (mContent->IsMathMLElement(nsGkAtoms::mlabeledtr_)) { + return roles::MATHML_LABELED_ROW; + } return roles::ROW; } +GroupPos +HTMLTableRowAccessible::GroupPosition() +{ + int32_t count = 0, index = 0; + if (nsCoreUtils::GetUIntAttr(nsAccUtils::TableFor(this)->GetContent(), + nsGkAtoms::aria_rowcount, &count) && + nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_rowindex, &index)) { + return GroupPos(0, index, count); + } + + return AccessibleWrap::GroupPosition(); +} + //////////////////////////////////////////////////////////////////////////////// // HTMLTableAccessible //////////////////////////////////////////////////////////////////////////////// @@ -384,6 +417,9 @@ HTMLTableAccessible::CacheChildren() role HTMLTableAccessible::NativeRole() { + if (mContent->IsMathMLElement(nsGkAtoms::mtable_)) { + return roles::MATHML_TABLE; + } return roles::TABLE; } @@ -421,6 +457,11 @@ HTMLTableAccessible::NativeAttributes() { nsCOMPtr attributes = AccessibleWrap::NativeAttributes(); + + if (mContent->IsMathMLElement(nsGkAtoms::mtable_)) { + GetAccService()->MarkupAttributes(mContent, attributes); + } + if (IsProbablyLayoutTable()) { nsAutoString unused; attributes->SetStringProperty(NS_LITERAL_CSTRING("layout-guess"), diff --git a/accessible/html/HTMLTableAccessible.h b/accessible/html/HTMLTableAccessible.h index 47f6602cb7..5bef8e00d4 100644 --- a/accessible/html/HTMLTableAccessible.h +++ b/accessible/html/HTMLTableAccessible.h @@ -33,6 +33,7 @@ public: virtual uint64_t NativeState() override; virtual uint64_t NativeInteractiveState() const override; virtual already_AddRefed NativeAttributes() override; + virtual mozilla::a11y::GroupPos GroupPosition() override; // TableCellAccessible virtual TableAccessible* Table() const override; @@ -89,6 +90,7 @@ public: // Accessible virtual a11y::role NativeRole() override; + virtual mozilla::a11y::GroupPos GroupPosition() override; protected: virtual ~HTMLTableRowAccessible() { } diff --git a/accessible/interfaces/nsIAccessibleRole.idl b/accessible/interfaces/nsIAccessibleRole.idl index 6862b1407e..d27676bd31 100644 --- a/accessible/interfaces/nsIAccessibleRole.idl +++ b/accessible/interfaces/nsIAccessibleRole.idl @@ -8,7 +8,7 @@ /** * Defines cross platform (Gecko) roles. */ -[scriptable, uuid(55581ec3-ba6e-4805-8108-260ed34cdcbb)] +[scriptable, uuid(da0c7824-147c-11e5-917c-60a44c717042)] interface nsIAccessibleRole : nsISupports { /** @@ -920,53 +920,49 @@ interface nsIAccessibleRole : nsISupports */ const unsigned long ROLE_MATHML_ERROR = 157; - /** - * A MathML semantics annotation element (semantics in MathML). - */ - const unsigned long ROLE_MATHML_SEMANTICS = 158; - - /** - * A MathML annotation (annotation in MathML). - */ - const unsigned long ROLE_MATHML_ANNOTATION = 159; - - /** - * A MathML XML annotation (annotation-xml in MathML). - */ - const unsigned long ROLE_MATHML_XML_ANNOTATION = 160; - /** * A MathML stacked (rows of numbers) element (mstack in MathML). */ - const unsigned long ROLE_MATHML_STACK = 161; + const unsigned long ROLE_MATHML_STACK = 158; /** * A MathML long division element (mlongdiv in MathML). */ - const unsigned long ROLE_MATHML_LONG_DIVISION = 162; + const unsigned long ROLE_MATHML_LONG_DIVISION = 159; /** * A MathML stack group (msgroup in MathML). */ - const unsigned long ROLE_MATHML_STACK_GROUP = 163; + const unsigned long ROLE_MATHML_STACK_GROUP = 160; /** * A MathML stack row (msrow in MathML). */ - const unsigned long ROLE_MATHML_STACK_ROW = 164; + const unsigned long ROLE_MATHML_STACK_ROW = 161; /** * MathML carries, borrows, or crossouts for a row (mscarries in MathML). */ - const unsigned long ROLE_MATHML_STACK_CARRIES = 165; + const unsigned long ROLE_MATHML_STACK_CARRIES = 162; /** * A MathML carry, borrow, or crossout for a column (mscarry in MathML). */ - const unsigned long ROLE_MATHML_STACK_CARRY = 166; + const unsigned long ROLE_MATHML_STACK_CARRY = 163; /** * A MathML line in a stack (msline in MathML). */ - const unsigned long ROLE_MATHML_STACK_LINE = 167; + const unsigned long ROLE_MATHML_STACK_LINE = 164; + + /** + * A group containing radio buttons + */ + const unsigned long ROLE_RADIO_GROUP = 165; + + /** + * A text container exposing brief amount of information. See related + * TEXT_CONTAINER role. + */ + const unsigned long ROLE_TEXT = 166; }; diff --git a/accessible/ipc/DocAccessibleParent.cpp b/accessible/ipc/DocAccessibleParent.cpp index 83cb04c47f..2fdecb7ef3 100644 --- a/accessible/ipc/DocAccessibleParent.cpp +++ b/accessible/ipc/DocAccessibleParent.cpp @@ -165,6 +165,23 @@ DocAccessibleParent::RecvCaretMoveEvent(const uint64_t& aID, const int32_t& aOff return true; } +bool +DocAccessibleParent::RecvTextChangeEvent(const uint64_t& aID, + const nsString& aStr, + const int32_t& aStart, + const uint32_t& aLen, + const bool& aIsInsert, + const bool& aFromUser) +{ + ProxyAccessible* target = GetAccessible(aID); + if (!target) + return false; + + ProxyTextChangeEvent(target, aStr, aStart, aLen, aIsInsert, aFromUser); + + return true; +} + bool DocAccessibleParent::RecvBindChildDoc(PDocAccessibleParent* aChildDoc, const uint64_t& aID) { diff --git a/accessible/ipc/DocAccessibleParent.h b/accessible/ipc/DocAccessibleParent.h index ee9ea6ea4e..e2ed9a4f88 100644 --- a/accessible/ipc/DocAccessibleParent.h +++ b/accessible/ipc/DocAccessibleParent.h @@ -55,6 +55,11 @@ public: virtual bool RecvCaretMoveEvent(const uint64_t& aID, const int32_t& aOffset) override final; + virtual bool RecvTextChangeEvent(const uint64_t& aID, const nsString& aStr, + const int32_t& aStart, const uint32_t& aLen, + const bool& aIsInsert, + const bool& aFromUser) override; + virtual bool RecvBindChildDoc(PDocAccessibleParent* aChildDoc, const uint64_t& aID) override; void Unbind() { diff --git a/accessible/ipc/PDocAccessible.ipdl b/accessible/ipc/PDocAccessible.ipdl index ff51826c69..cde80a9bc1 100644 --- a/accessible/ipc/PDocAccessible.ipdl +++ b/accessible/ipc/PDocAccessible.ipdl @@ -59,6 +59,8 @@ parent: HideEvent(uint64_t aRootID); StateChangeEvent(uint64_t aID, uint64_t aState, bool aEnabled); CaretMoveEvent(uint64_t aID, int32_t aOffset); + TextChangeEvent(uint64_t aID, nsString aStr, int32_t aStart, uint32_t aLen, + bool aIsInsert, bool aFromUser); /* * Tell the parent document to bind the existing document as a new child diff --git a/accessible/mac/AccessibleWrap.h b/accessible/mac/AccessibleWrap.h index 0191228a51..40d443b1ce 100644 --- a/accessible/mac/AccessibleWrap.h +++ b/accessible/mac/AccessibleWrap.h @@ -108,6 +108,14 @@ private: bool mNativeInited; }; +#if defined(__OBJC__) + void FireNativeEvent(mozAccessible* aNativeAcc, uint32_t aEventType); +#else + void FireNativeEvent(id aNativeAcc, uint32_t aEventType); +#endif + +Class GetTypeFromRole(roles::Role aRole); + } // namespace a11y } // namespace mozilla diff --git a/accessible/mac/AccessibleWrap.mm b/accessible/mac/AccessibleWrap.mm index ccc2f9400f..74537a8629 100644 --- a/accessible/mac/AccessibleWrap.mm +++ b/accessible/mac/AccessibleWrap.mm @@ -15,6 +15,7 @@ #import "mozHTMLAccessible.h" #import "mozTextAccessible.h" +using namespace mozilla; using namespace mozilla::a11y; AccessibleWrap:: @@ -33,8 +34,10 @@ AccessibleWrap::GetNativeObject() { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; - if (!mNativeInited && !mNativeObject && !IsDefunct() && !AncestorIsFlat()) - mNativeObject = [[GetNativeType() alloc] initWithAccessible:this]; + if (!mNativeInited && !mNativeObject && !IsDefunct() && !AncestorIsFlat()) { + uintptr_t accWrap = reinterpret_cast(this); + mNativeObject = [[GetNativeType() alloc] initWithAccessible:accWrap]; + } mNativeInited = true; @@ -59,51 +62,7 @@ AccessibleWrap::GetNativeType () if (IsXULTabpanels()) return [mozPaneAccessible class]; - roles::Role role = Role(); - switch (role) { - case roles::PUSHBUTTON: - case roles::SPLITBUTTON: - case roles::TOGGLE_BUTTON: - { - // if this button may show a popup, let's make it of the popupbutton type. - return HasPopup() ? [mozPopupButtonAccessible class] : - [mozButtonAccessible class]; - } - - case roles::PAGETAB: - return [mozButtonAccessible class]; - - case roles::CHECKBUTTON: - return [mozCheckboxAccessible class]; - - case roles::HEADING: - return [mozHeadingAccessible class]; - - case roles::PAGETABLIST: - return [mozTabsAccessible class]; - - case roles::ENTRY: - case roles::STATICTEXT: - case roles::CAPTION: - case roles::ACCEL_LABEL: - case roles::PASSWORD_TEXT: - // normal textfield (static or editable) - return [mozTextAccessible class]; - - case roles::TEXT_LEAF: - return [mozTextLeafAccessible class]; - - case roles::LINK: - return [mozLinkAccessible class]; - - case roles::COMBOBOX: - return [mozPopupButtonAccessible class]; - - default: - return [mozAccessible class]; - } - - return nil; + return GetTypeFromRole(Role()); NS_OBJC_END_TRY_ABORT_BLOCK_NIL; } @@ -153,18 +112,7 @@ AccessibleWrap::HandleAccEvent(AccEvent* aEvent) if (!nativeAcc) return NS_ERROR_FAILURE; - switch (eventType) { - case nsIAccessibleEvent::EVENT_FOCUS: - [nativeAcc didReceiveFocus]; - break; - case nsIAccessibleEvent::EVENT_VALUE_CHANGE: - [nativeAcc valueDidChange]; - break; - case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED: - case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED: - [nativeAcc selectedTextDidChange]; - break; - } + FireNativeEvent(nativeAcc, eventType); return NS_OK; @@ -274,3 +222,73 @@ AccessibleWrap::AncestorIsFlat() // no parent was flat return false; } + +void +a11y::FireNativeEvent(mozAccessible* aNativeAcc, uint32_t aEventType) +{ + NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + + switch (aEventType) { + case nsIAccessibleEvent::EVENT_FOCUS: + [aNativeAcc didReceiveFocus]; + break; + case nsIAccessibleEvent::EVENT_VALUE_CHANGE: + [aNativeAcc valueDidChange]; + break; + case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED: + case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED: + [aNativeAcc selectedTextDidChange]; + break; + } + + NS_OBJC_END_TRY_ABORT_BLOCK; +} + +Class +a11y::GetTypeFromRole(roles::Role aRole) +{ + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; + + switch (aRole) { + case roles::COMBOBOX: + case roles::PUSHBUTTON: + case roles::SPLITBUTTON: + case roles::TOGGLE_BUTTON: + { + return [mozButtonAccessible class]; + } + + case roles::PAGETAB: + return [mozButtonAccessible class]; + + case roles::CHECKBUTTON: + return [mozCheckboxAccessible class]; + + case roles::HEADING: + return [mozHeadingAccessible class]; + + case roles::PAGETABLIST: + return [mozTabsAccessible class]; + + case roles::ENTRY: + case roles::STATICTEXT: + case roles::CAPTION: + case roles::ACCEL_LABEL: + case roles::PASSWORD_TEXT: + // normal textfield (static or editable) + return [mozTextAccessible class]; + + case roles::TEXT_LEAF: + return [mozTextLeafAccessible class]; + + case roles::LINK: + return [mozLinkAccessible class]; + + default: + return [mozAccessible class]; + } + + return nil; + + NS_OBJC_END_TRY_ABORT_BLOCK_NIL; +} diff --git a/accessible/mac/Platform.mm b/accessible/mac/Platform.mm index 8503159818..ee0bd6a508 100644 --- a/accessible/mac/Platform.mm +++ b/accessible/mac/Platform.mm @@ -7,6 +7,7 @@ #import #include "Platform.h" +#include "ProxyAccessible.h" #include "nsAppShell.h" @@ -34,31 +35,64 @@ PlatformShutdown() } void -ProxyCreated(ProxyAccessible*, uint32_t) +ProxyCreated(ProxyAccessible* aProxy, uint32_t) { + // Pass in dummy state for now as retrieving proxy state requires IPC. + Class type = GetTypeFromRole(aProxy->Role()); + uintptr_t accWrap = reinterpret_cast(aProxy) | IS_PROXY; + mozAccessible* mozWrapper = [[type alloc] initWithAccessible:accWrap]; + aProxy->SetWrapper(reinterpret_cast(mozWrapper)); } void -ProxyDestroyed(ProxyAccessible*) +ProxyDestroyed(ProxyAccessible* aProxy) { + mozAccessible* wrapper = + reinterpret_cast(aProxy->GetWrapper()); + [wrapper expire]; + [wrapper release]; + aProxy->SetWrapper(0); } void -ProxyEvent(ProxyAccessible*, uint32_t) +ProxyEvent(ProxyAccessible* aProxy, uint32_t aEventType) { + // ignore everything but focus-changed, value-changed, caret and selection + // events for now. + if (aEventType != nsIAccessibleEvent::EVENT_FOCUS && + aEventType != nsIAccessibleEvent::EVENT_VALUE_CHANGE && + aEventType != nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED && + aEventType != nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED) + return; + + mozAccessible* wrapper = + reinterpret_cast(aProxy->GetWrapper()); + if (wrapper) + FireNativeEvent(wrapper, aEventType); } void -ProxyStateChangeEvent(ProxyAccessible*, uint64_t, bool) +ProxyStateChangeEvent(ProxyAccessible* aProxy, uint64_t, bool) { + // mac doesn't care about state change events } void ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset) { + mozAccessible* wrapper = + reinterpret_cast(aTarget->GetWrapper()); + if (wrapper) + [wrapper selectedTextDidChange]; } + +void +ProxyTextChangeEvent(ProxyAccessible*, const nsString&, int32_t, uint32_t, + bool, bool) +{ } -} +} // namespace a11y +} // namespace mozilla @interface GeckoNSApplication(a11y) -(void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute; diff --git a/accessible/mac/moz.build b/accessible/mac/moz.build index 8a831e0afa..7f1a866920 100644 --- a/accessible/mac/moz.build +++ b/accessible/mac/moz.build @@ -30,6 +30,7 @@ LOCAL_INCLUDES += [ '/accessible/base', '/accessible/generic', '/accessible/html', + '/accessible/ipc', '/accessible/xul', '/layout/generic', '/layout/xul', diff --git a/accessible/mac/mozAccessible.h b/accessible/mac/mozAccessible.h index fe9ee9db4e..ddb2737271 100644 --- a/accessible/mac/mozAccessible.h +++ b/accessible/mac/mozAccessible.h @@ -57,11 +57,14 @@ static const uintptr_t IS_PROXY = 1; mozilla::a11y::role mRole; } -// return the Accessible for this mozAccessible. -- (mozilla::a11y::AccessibleWrap*) getGeckoAccessible; +// return the Accessible for this mozAccessible if it exists. +- (mozilla::a11y::AccessibleWrap*)getGeckoAccessible; + +// return the ProxyAccessible for this mozAccessible if it exists. +- (mozilla::a11y::ProxyAccessible*)getProxyAccessible; // inits with the gecko owner. -- (id)initWithAccessible:(mozilla::a11y::AccessibleWrap*)geckoParent; +- (id)initWithAccessible:(uintptr_t)aGeckoObj; // our accessible parent (AXParent) - (id )parent; diff --git a/accessible/mac/mozAccessible.mm b/accessible/mac/mozAccessible.mm index e66016918b..db971be153 100644 --- a/accessible/mac/mozAccessible.mm +++ b/accessible/mac/mozAccessible.mm @@ -99,15 +99,18 @@ ConvertToNSArray(nsTArray& aArray) @implementation mozAccessible -- (id)initWithAccessible:(AccessibleWrap*)geckoAccessible +- (id)initWithAccessible:(uintptr_t)aGeckoAccessible { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; if ((self = [super init])) { - mGeckoAccessible = reinterpret_cast(geckoAccessible); - mRole = geckoAccessible->Role(); + mGeckoAccessible = aGeckoAccessible; + if (aGeckoAccessible & IS_PROXY) + mRole = [self getProxyAccessible]->Role(); + else + mRole = [self getGeckoAccessible]->Role(); } - + return self; NS_OBJC_END_TRY_ABORT_BLOCK_NIL; @@ -132,6 +135,15 @@ ConvertToNSArray(nsTArray& aArray) return reinterpret_cast(mGeckoAccessible); } +- (mozilla::a11y::ProxyAccessible*)getProxyAccessible +{ + // Check if mGeckoAccessible points at a proxy + if (!(mGeckoAccessible & IS_PROXY)) + return nil; + + return reinterpret_cast(mGeckoAccessible & ~IS_PROXY); +} + #pragma mark - - (BOOL)accessibilityIsIgnored diff --git a/accessible/other/Platform.cpp b/accessible/other/Platform.cpp index 5e09e1cea6..78eceeaf6e 100644 --- a/accessible/other/Platform.cpp +++ b/accessible/other/Platform.cpp @@ -43,3 +43,9 @@ void a11y::ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset) { } + +void +a11y::ProxyTextChangeEvent(ProxyAccessible*, const nsString&, int32_t, uint32_t, + bool, bool) +{ +} diff --git a/accessible/tests/mochitest/attributes/test_obj_group.html b/accessible/tests/mochitest/attributes/test_obj_group.html index 64afbfcc7e..28f45ad4b8 100644 --- a/accessible/tests/mochitest/attributes/test_obj_group.html +++ b/accessible/tests/mochitest/attributes/test_obj_group.html @@ -186,6 +186,11 @@ testGroupAttrs("combo1_opt3", 3, 4); testGroupAttrs("combo1_opt4", 4, 4); + ////////////////////////////////////////////////////////////////////////// + // ARIA table + testGroupAttrs("table_cell", 3, 4); + testGroupAttrs("table_row", 2, 2); + // Test that group position information updates after deleting node. testGroupAttrs("tree4_ti1", 1, 2, 1); testGroupAttrs("tree4_ti2", 2, 2, 1); @@ -442,5 +447,11 @@ + +
+
+
cell
+
+
diff --git a/accessible/tests/mochitest/elm/test_HTMLSpec.html b/accessible/tests/mochitest/elm/test_HTMLSpec.html index 8b52ed66bc..a3b7c5911f 100644 --- a/accessible/tests/mochitest/elm/test_HTMLSpec.html +++ b/accessible/tests/mochitest/elm/test_HTMLSpec.html @@ -70,7 +70,7 @@ interfaces: [ nsIAccessibleText, nsIAccessibleHyperText ], children: [ { - role: ROLE_TEXT_CONTAINER, + role: ROLE_TEXT, children: [ { role: ROLE_TEXT_LEAF } ] } ] @@ -81,7 +81,7 @@ // HTML:address obj = { - todo_role: ROLE_PARAGRAPH, + role: ROLE_TEXT_CONTAINER, interfaces: [ nsIAccessibleText, nsIAccessibleHyperText ], }; testElm("address", obj); @@ -188,7 +188,7 @@ testElm("blockquote", obj); ////////////////////////////////////////////////////////////////////////// - // HTML:br + // HTML:br contained by paragraph obj = { role: ROLE_PARAGRAPH, @@ -1062,7 +1062,7 @@ // HTML:pre obj = { - role: ROLE_PARAGRAPH, + role: ROLE_TEXT_CONTAINER, interfaces: [ nsIAccessibleText, nsIAccessibleHyperText ] }; testElm("pre", obj); @@ -1087,7 +1087,7 @@ // HTML:q obj = { - role: ROLE_TEXT_CONTAINER, + role: ROLE_TEXT, interfaces: [ nsIAccessibleText, nsIAccessibleHyperText ], children: [ { role: ROLE_STATICTEXT }, // left quote @@ -1233,7 +1233,7 @@ // HTML:time obj = { - role: ROLE_TEXT_CONTAINER, + role: ROLE_TEXT, attributes: { "xml-roles": "time", "datetime": "2001-05-15 19:00" }, interfaces: [ nsIAccessibleText, nsIAccessibleHyperText ] }; diff --git a/accessible/tests/mochitest/elm/test_MathMLSpec.html b/accessible/tests/mochitest/elm/test_MathMLSpec.html index e7799d91aa..acbf7ba8d0 100644 --- a/accessible/tests/mochitest/elm/test_MathMLSpec.html +++ b/accessible/tests/mochitest/elm/test_MathMLSpec.html @@ -267,28 +267,10 @@ testElm("merror", obj); ////////////////////////////////////////////////////////////////////////// - // semantics - - obj = { - role: ROLE_MATHML_SEMANTICS, - }; - testElm("semantics", obj); - - ////////////////////////////////////////////////////////////////////////// - // annotation - - obj = { - role: ROLE_MATHML_ANNOTATION, - }; - testElm("annotation", obj); - - ////////////////////////////////////////////////////////////////////////// - // annotation-xml - - obj = { - role: ROLE_MATHML_XML_ANNOTATION, - }; - testElm("annotation-xml", obj); + // semantics, annotation, annotation-xml + ok(!isAccessible("semantics"), "semantics should not have accessible"); + ok(!isAccessible("annotation"), "annotation should not have accessible"); + ok(!isAccessible("annotation-xml"), "annotation-xml should not have accessible"); ////////////////////////////////////////////////////////////////////////// // mstack diff --git a/accessible/tests/mochitest/role.js b/accessible/tests/mochitest/role.js index 99524c1747..cd44f93731 100644 --- a/accessible/tests/mochitest/role.js +++ b/accessible/tests/mochitest/role.js @@ -68,9 +68,6 @@ const ROLE_MATHML_TABLE_ROW = nsIAccessibleRole.ROLE_MATHML_TABLE_ROW; const ROLE_MATHML_CELL = nsIAccessibleRole.ROLE_MATHML_CELL; const ROLE_MATHML_ACTION = nsIAccessibleRole.ROLE_MATHML_ACTION; const ROLE_MATHML_ERROR = nsIAccessibleRole.ROLE_MATHML_ERROR; -const ROLE_MATHML_SEMANTICS = nsIAccessibleRole.ROLE_MATHML_SEMANTICS; -const ROLE_MATHML_ANNOTATION = nsIAccessibleRole.ROLE_MATHML_ANNOTATION; -const ROLE_MATHML_XML_ANNOTATION = nsIAccessibleRole.ROLE_MATHML_XML_ANNOTATION; const ROLE_MATHML_STACK = nsIAccessibleRole.ROLE_MATHML_STACK; const ROLE_MATHML_LONG_DIVISION = nsIAccessibleRole.ROLE_MATHML_LONG_DIVISION; const ROLE_MATHML_STACK_GROUP = nsIAccessibleRole.ROLE_MATHML_STACK_GROUP; @@ -96,6 +93,7 @@ const ROLE_PROGRESSBAR = nsIAccessibleRole.ROLE_PROGRESSBAR; const ROLE_PROPERTYPAGE = nsIAccessibleRole.ROLE_PROPERTYPAGE; const ROLE_PUSHBUTTON = nsIAccessibleRole.ROLE_PUSHBUTTON; const ROLE_RADIOBUTTON = nsIAccessibleRole.ROLE_RADIOBUTTON; +const ROLE_RADIO_GROUP = nsIAccessibleRole.ROLE_RADIO_GROUP; const ROLE_RADIO_MENU_ITEM = nsIAccessibleRole.ROLE_RADIO_MENU_ITEM; const ROLE_RICH_OPTION = nsIAccessibleRole.ROLE_RICH_OPTION; const ROLE_ROW = nsIAccessibleRole.ROLE_ROW; @@ -110,6 +108,7 @@ const ROLE_STATUSBAR = nsIAccessibleRole.ROLE_STATUSBAR; const ROLE_SWITCH = nsIAccessibleRole.ROLE_SWITCH; const ROLE_TABLE = nsIAccessibleRole.ROLE_TABLE; const ROLE_TERM = nsIAccessibleRole.ROLE_TERM; +const ROLE_TEXT = nsIAccessibleRole.ROLE_TEXT; const ROLE_TEXT_CONTAINER = nsIAccessibleRole.ROLE_TEXT_CONTAINER; const ROLE_TEXT_LEAF = nsIAccessibleRole.ROLE_TEXT_LEAF; const ROLE_TOGGLE_BUTTON = nsIAccessibleRole.ROLE_TOGGLE_BUTTON; diff --git a/accessible/tests/mochitest/role/test_aria.html b/accessible/tests/mochitest/role/test_aria.html index 76c6809790..8e04f380bf 100644 --- a/accessible/tests/mochitest/role/test_aria.html +++ b/accessible/tests/mochitest/role/test_aria.html @@ -39,7 +39,7 @@ testRole("aria_list", ROLE_LIST); testRole("aria_listbox", ROLE_LISTBOX); testRole("aria_listitem", ROLE_LISTITEM); - testRole("aria_log", ROLE_TEXT_CONTAINER); // weak role + testRole("aria_log", ROLE_TEXT); // weak role testRole("aria_marquee", ROLE_ANIMATION); testRole("aria_math", ROLE_FLAT_EQUATION); testRole("aria_menu", ROLE_MENUPOPUP); @@ -48,10 +48,10 @@ testRole("aria_menuitemcheckbox", ROLE_CHECK_MENU_ITEM); testRole("aria_menuitemradio", ROLE_RADIO_MENU_ITEM); testRole("aria_note", ROLE_NOTE); - testRole("aria_presentation", ROLE_TEXT_CONTAINER); // weak role + testRole("aria_presentation", ROLE_TEXT); // weak role testRole("aria_progressbar", ROLE_PROGRESSBAR); testRole("aria_radio", ROLE_RADIOBUTTON); - testRole("aria_radiogroup", ROLE_GROUPING); + testRole("aria_radiogroup", ROLE_RADIO_GROUP); testRole("aria_region", ROLE_PANE); testRole("aria_row", ROLE_ROW); testRole("aria_rowheader", ROLE_ROWHEADER); @@ -66,7 +66,7 @@ testRole("aria_tablist", ROLE_PAGETABLIST); testRole("aria_tabpanel", ROLE_PROPERTYPAGE); testRole("aria_textbox", ROLE_ENTRY); - testRole("aria_timer", ROLE_TEXT_CONTAINER); // weak role + testRole("aria_timer", ROLE_TEXT); // weak role testRole("aria_toolbar", ROLE_TOOLBAR); testRole("aria_tooltip", ROLE_TOOLTIP); testRole("aria_tree", ROLE_OUTLINE); diff --git a/accessible/tests/mochitest/role/test_general.html b/accessible/tests/mochitest/role/test_general.html index 72c8244766..40f5224825 100644 --- a/accessible/tests/mochitest/role/test_general.html +++ b/accessible/tests/mochitest/role/test_general.html @@ -67,9 +67,9 @@ testRole("definitiondescription", ROLE_DEFINITION); // Has click, mousedown or mouseup listeners. - testRole("span1", ROLE_TEXT_CONTAINER); - testRole("span2", ROLE_TEXT_CONTAINER); - testRole("span3", ROLE_TEXT_CONTAINER); + testRole("span1", ROLE_TEXT); + testRole("span2", ROLE_TEXT); + testRole("span3", ROLE_TEXT); // Test role of listbox inside combobox testRole("listbox1", ROLE_COMBOBOX_LIST); diff --git a/accessible/tests/mochitest/table.js b/accessible/tests/mochitest/table.js index 5bd37bd12e..d6b0452803 100644 --- a/accessible/tests/mochitest/table.js +++ b/accessible/tests/mochitest/table.js @@ -27,6 +27,13 @@ const kNoColumnHeader = 0; const kListboxColumnHeader = 1; const kTreeColumnHeader = 2; +/** + * Constants to define table type. + */ +const kTable = 0; +const kTreeTable = 1; +const kMathTable = 2; + /** * Test table structure and related methods. * @@ -37,10 +44,11 @@ const kTreeColumnHeader = 2; * arranged into the list. * @param aCaption [in] caption text if any * @param aSummary [in] summary text if any - * @param aIsTreeTable [in] specifies whether given table is tree table + * @param aTableType [in] specifies the table type. + * @param aRowRoles [in] array of row roles. */ function testTableStruct(aIdentifier, aCellsArray, aColHeaderType, - aCaption, aSummary, aIsTreeTable) + aCaption, aSummary, aTableType, aRowRoles) { var tableNode = getNode(aIdentifier); var isGrid = tableNode.getAttribute("role") == "grid" || @@ -52,9 +60,19 @@ function testTableStruct(aIdentifier, aCellsArray, aColHeaderType, // Test table accessible tree. var tableObj = { - role: aIsTreeTable ? ROLE_TREE_TABLE : ROLE_TABLE, children: [] }; + switch (aTableType) { + case kTable: + tableObj.role = ROLE_TABLE; + break; + case kTreeTable: + tableObj.role = ROLE_TREE_TABLE; + break; + case kMathTable: + tableObj.role = ROLE_MATHML_TABLE; + break; + } // caption accessible handling if (aCaption) { @@ -99,7 +117,7 @@ function testTableStruct(aIdentifier, aCellsArray, aColHeaderType, // rows and cells accessibles for (var rowIdx = 0; rowIdx < rowCount; rowIdx++) { var rowObj = { - role: ROLE_ROW, + role: aRowRoles ? aRowRoles[rowIdx] : ROLE_ROW, children: [] }; @@ -109,7 +127,8 @@ function testTableStruct(aIdentifier, aCellsArray, aColHeaderType, var role = ROLE_NOTHING; switch (celltype) { case kDataCell: - role = (isGrid ? ROLE_GRID_CELL : ROLE_CELL); + role = (aTableType == kMathTable ? ROLE_MATHML_CELL : + (isGrid ? ROLE_GRID_CELL : ROLE_CELL)); break; case kRowHeaderCell: role = ROLE_ROWHEADER; diff --git a/accessible/tests/mochitest/table/a11y.ini b/accessible/tests/mochitest/table/a11y.ini index 20800d7585..bfd6995a76 100644 --- a/accessible/tests/mochitest/table/a11y.ini +++ b/accessible/tests/mochitest/table/a11y.ini @@ -9,6 +9,7 @@ [test_indexes_table.html] [test_indexes_tree.xul] [test_layoutguess.html] +[test_mtable.html] [test_sels_ariagrid.html] [test_sels_listbox.xul] [test_sels_table.html] diff --git a/accessible/tests/mochitest/table/test_mtable.html b/accessible/tests/mochitest/table/test_mtable.html new file mode 100644 index 0000000000..37ea8af50d --- /dev/null +++ b/accessible/tests/mochitest/table/test_mtable.html @@ -0,0 +1,128 @@ + + + + MathML table tests + + + + + + + + + + + +

+ +
+  
+ + + + + + 1 + + + 0 + + + + + 0 + + + 1 + + + + + + + + 1 x 3 + + + + + 2 x 2 + + + 1 x 1 + + + + + 1 x 1 + + + + + + + 1 + label + + + + + + diff --git a/accessible/tests/mochitest/table/test_struct_ariatreegrid.html b/accessible/tests/mochitest/table/test_struct_ariatreegrid.html index 5f5ae6e82b..7c97adb9ba 100644 --- a/accessible/tests/mochitest/table/test_struct_ariatreegrid.html +++ b/accessible/tests/mochitest/table/test_struct_ariatreegrid.html @@ -28,7 +28,8 @@ [kDataCell, kDataCell, kDataCell] ]; - testTableStruct("treegrid", cellsArray, kNoColumnHeader, "", "", true); + testTableStruct("treegrid", cellsArray, kNoColumnHeader, "", "", + kTreeTable); SimpleTest.finish(); } diff --git a/accessible/tests/mochitest/tree/test_aria_list.html b/accessible/tests/mochitest/tree/test_aria_list.html index fa0b6592a9..b53962709a 100644 --- a/accessible/tests/mochitest/tree/test_aria_list.html +++ b/accessible/tests/mochitest/tree/test_aria_list.html @@ -35,7 +35,7 @@ role: ROLE_LIST, children: [ { // li - role: ROLE_PARAGRAPH, + role: ROLE_TEXT_CONTAINER, children: [ { // li text leaf role: ROLE_TEXT_LEAF, diff --git a/accessible/tests/mochitest/tree/test_aria_presentation.html b/accessible/tests/mochitest/tree/test_aria_presentation.html index f108339ba7..2ac1f1ed3f 100644 --- a/accessible/tests/mochitest/tree/test_aria_presentation.html +++ b/accessible/tests/mochitest/tree/test_aria_presentation.html @@ -73,10 +73,10 @@ // Presentation list, expose generic accesisble for list items. tree = { SECTION: [ // container - { PARAGRAPH: [ // li generic accessible inside 'presentation' role + { TEXT_CONTAINER: [ // li generic accessible inside 'presentation' role { TEXT_LEAF: [ ] } // li text ] }, - { PARAGRAPH: [ // li generic accessible inside 'none' role + { TEXT_CONTAINER: [ // li generic accessible inside 'none' role { TEXT_LEAF: [ ] } // li text ] } ] }; diff --git a/accessible/tests/mochitest/tree/test_dockids.html b/accessible/tests/mochitest/tree/test_dockids.html index da78149e83..d8d3abd63a 100644 --- a/accessible/tests/mochitest/tree/test_dockids.html +++ b/accessible/tests/mochitest/tree/test_dockids.html @@ -20,15 +20,15 @@ { var tree = { DOCUMENT: [ - { PARAGRAPH: [ // head - { PARAGRAPH: [ // link + { TEXT_CONTAINER: [ // head + { TEXT_CONTAINER: [ // link { STATICTEXT: [] }, // generated content { STATICTEXT: [] } // generated content ] } ] }, { TEXT_LEAF: [ ] }, // body text { ENTRY: [ ] }, // input under document element - { PARAGRAPH: [ // link under document element + { TEXT_CONTAINER: [ // link under document element { TEXT_LEAF: [ ] }, // link content { STATICTEXT: [ ] }, // generated content { STATICTEXT: [ ] } // generated content diff --git a/accessible/tests/mochitest/tree/test_formctrl.xul b/accessible/tests/mochitest/tree/test_formctrl.xul index afdcd01a32..34dc3795eb 100644 --- a/accessible/tests/mochitest/tree/test_formctrl.xul +++ b/accessible/tests/mochitest/tree/test_formctrl.xul @@ -39,7 +39,7 @@ // radiogroup accTree = { - role: ROLE_GROUPING, + role: ROLE_RADIO_GROUP, children: [ { role: ROLE_RADIOBUTTON, diff --git a/accessible/tests/mochitest/tree/test_invalid_img.xhtml b/accessible/tests/mochitest/tree/test_invalid_img.xhtml index 14ada63224..2079c86ee7 100644 --- a/accessible/tests/mochitest/tree/test_invalid_img.xhtml +++ b/accessible/tests/mochitest/tree/test_invalid_img.xhtml @@ -20,7 +20,7 @@ document.getElementsByTagName("img")[0].firstChild.data = "2"; var accTree = { - role: ROLE_TEXT_CONTAINER, + role: ROLE_TEXT, children: [ { role: ROLE_TEXT_LEAF } ] }; testAccessibleTree("the_img", accTree); diff --git a/accessible/tests/mochitest/tree/test_txtcntr.html b/accessible/tests/mochitest/tree/test_txtcntr.html index a9d61af3cf..54e42b7f37 100644 --- a/accessible/tests/mochitest/tree/test_txtcntr.html +++ b/accessible/tests/mochitest/tree/test_txtcntr.html @@ -120,7 +120,7 @@ children: [] }, { // abbr tag - role: ROLE_TEXT_CONTAINER, + role: ROLE_TEXT, name: "accessibility", children: [ { // text leaf with actual text @@ -150,7 +150,7 @@ children: [] }, { // acronym tag - role: ROLE_TEXT_CONTAINER, + role: ROLE_TEXT, name: "personal computer", children: [ { // text leaf with actual text diff --git a/accessible/tests/mochitest/treeupdate/test_textleaf.html b/accessible/tests/mochitest/treeupdate/test_textleaf.html index 0a8f006b37..33a3d8cdc3 100644 --- a/accessible/tests/mochitest/treeupdate/test_textleaf.html +++ b/accessible/tests/mochitest/treeupdate/test_textleaf.html @@ -84,7 +84,7 @@ } } - function removeTextData(aID) + function removeTextData(aID, aRole) { this.containerNode = getNode(aID); this.textNode = this.containerNode.firstChild; @@ -96,7 +96,7 @@ this.invoke = function removeTextData_invoke() { var tree = { - role: ROLE_PARAGRAPH, + role: aRole, children: [ { role: ROLE_TEXT_LEAF, @@ -112,7 +112,7 @@ this.finalCheck = function removeTextData_finalCheck() { var tree = { - role: ROLE_PARAGRAPH, + role: aRole, children: [] }; testAccessibleTree(this.containerNode, tree); @@ -147,8 +147,8 @@ gQueue.push(new setOnClickNRoleAttrs("span")); // text data removal of text node should remove its text accessible - gQueue.push(new removeTextData("p")); - gQueue.push(new removeTextData("pre")); + gQueue.push(new removeTextData("p", ROLE_PARAGRAPH)); + gQueue.push(new removeTextData("pre", ROLE_TEXT_CONTAINER)); gQueue.invoke(); // SimpleTest.finish() will be called in the end } diff --git a/accessible/windows/msaa/Platform.cpp b/accessible/windows/msaa/Platform.cpp index 40c7365141..b2b0aa5455 100644 --- a/accessible/windows/msaa/Platform.cpp +++ b/accessible/windows/msaa/Platform.cpp @@ -68,3 +68,9 @@ void a11y::ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset) { } + +void +a11y::ProxyTextChangeEvent(ProxyAccessible*, const nsString&, int32_t, uint32_t, + bool, bool) +{ +} diff --git a/accessible/xpcom/xpcAccessibleTable.cpp b/accessible/xpcom/xpcAccessibleTable.cpp index 32be582852..aa6ee8f764 100644 --- a/accessible/xpcom/xpcAccessibleTable.cpp +++ b/accessible/xpcom/xpcAccessibleTable.cpp @@ -268,7 +268,7 @@ xpcAccessibleTable::GetSelectedCells(nsIArray** aSelectedCells) if (!Intl()) return NS_ERROR_FAILURE; - NS_IMETHODIMP rv = NS_OK; + nsresult rv = NS_OK; nsCOMPtr selCells = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); diff --git a/accessible/xul/XULFormControlAccessible.cpp b/accessible/xul/XULFormControlAccessible.cpp index 8eb104e2a1..b5b52e5771 100644 --- a/accessible/xul/XULFormControlAccessible.cpp +++ b/accessible/xul/XULFormControlAccessible.cpp @@ -472,7 +472,7 @@ XULRadioGroupAccessible:: role XULRadioGroupAccessible::NativeRole() { - return roles::GROUPING; + return roles::RADIO_GROUP; } uint64_t diff --git a/b2g/app/B2GLoader.cpp b/b2g/app/B2GLoader.cpp index 8846ac794e..cf2eb08dff 100644 --- a/b2g/app/B2GLoader.cpp +++ b/b2g/app/B2GLoader.cpp @@ -219,6 +219,13 @@ RunProcesses(int argc, const char *argv[], FdArray& aReservedFds) aReservedFds); } + // Reap zombie child process. + struct sigaction sa; + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGCHLD, &sa, nullptr); + // The b2g process int childPid = pid; XRE_ProcLoaderClientInit(childPid, parentSock, aReservedFds); diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 18b2319208..bdd0ea85d5 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -732,13 +732,11 @@ pref("hal.processPriorityManager.gonk.notifyLowMemUnderKB", 14336); // blocked on a poll(), and this pref has no effect.) pref("gonk.systemMemoryPressureRecoveryPollMS", 5000); -#ifndef DEBUG // Enable pre-launching content processes for improved startup time // (hiding latency). pref("dom.ipc.processPrelaunch.enabled", true); // Wait this long before pre-launching a new subprocess. pref("dom.ipc.processPrelaunch.delayMs", 5000); -#endif pref("dom.ipc.reuse_parent_app", false); diff --git a/browser/components/shell/nsMacShellService.cpp b/browser/components/shell/nsMacShellService.cpp index 0ad2e71676..a141e1c735 100644 --- a/browser/components/shell/nsMacShellService.cpp +++ b/browser/components/shell/nsMacShellService.cpp @@ -24,7 +24,6 @@ #include "nsIDocShell.h" #include "nsILoadContext.h" - #include #include @@ -91,7 +90,7 @@ nsMacShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers) return NS_ERROR_FAILURE; } } - + return NS_OK; } diff --git a/caps/DomainPolicy.h b/caps/DomainPolicy.h index fd3d3cb440..12e126de4b 100644 --- a/caps/DomainPolicy.h +++ b/caps/DomainPolicy.h @@ -33,7 +33,7 @@ enum DomainSetType{ SUPER_WHITELIST }; -class DomainSet : public nsIDomainSet +class DomainSet final : public nsIDomainSet { public: NS_DECL_ISUPPORTS @@ -51,7 +51,7 @@ protected: DomainSetType mType; }; -class DomainPolicy : public nsIDomainPolicy +class DomainPolicy final : public nsIDomainPolicy { public: NS_DECL_ISUPPORTS diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 41a9edcd3a..d057df7bc5 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -3037,7 +3037,9 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) if (shell) { // single-click nsEventStatus status = nsEventStatus_eIgnore; - InternalUIEvent actEvent(mouseEvent->mFlags.mIsTrusted, NS_UI_ACTIVATE); + // DOMActive event should be trusted since the activation is actually + // occurred even if the cause is an untrusted click event. + InternalUIEvent actEvent(true, NS_UI_ACTIVATE, mouseEvent); actEvent.detail = 1; rv = shell->HandleDOMEventWithTarget(this, &actEvent, &status); @@ -3053,9 +3055,10 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) if (aVisitor.mEvent->originalTarget == this) { nsAutoString target; GetLinkTarget(target); + const InternalUIEvent* activeEvent = aVisitor.mEvent->AsUIEvent(); + MOZ_ASSERT(activeEvent); nsContentUtils::TriggerLink(this, aVisitor.mPresContext, absURI, target, - true, true, - aVisitor.mEvent->mFlags.mIsTrusted); + true, true, activeEvent->IsTrustable()); aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault; } } diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index e44be965e3..8df3097dae 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -833,6 +833,8 @@ nsIContent::PreHandleEvent(EventChainPreVisitor& aVisitor) } } break; + default: + break; } if (stopEvent) { diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 9630549b60..e700a80233 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -671,9 +671,9 @@ nsContentUtils::InitializeModifierStrings() static bool ShouldAddEventToStringEventTable(const EventNameMapping& aMapping) { - switch(aMapping.mId) { -#define ID_TO_EVENT(name_, id_, type_, struct_) \ - case id_: return nsGkAtoms::on##name_ == aMapping.mAtom; + switch(aMapping.mMessage) { +#define ID_TO_EVENT(name_, message_, type_, struct_) \ + case message_: return nsGkAtoms::on##name_ == aMapping.mAtom; #include "mozilla/EventNameList.h" #undef ID_TO_EVENT default: @@ -688,8 +688,8 @@ nsContentUtils::InitializeEventTable() { NS_ASSERTION(!sStringEventTable, "EventTable already initialized!"); static const EventNameMapping eventArray[] = { -#define EVENT(name_, _id, _type, _class) \ - { nsGkAtoms::on##name_, _id, _type, _class }, +#define EVENT(name_, _message, _type, _class) \ + { nsGkAtoms::on##name_, _type, _message, _class }, #define WINDOW_ONLY_EVENT EVENT #define NON_IDL_EVENT EVENT #include "mozilla/EventNameList.h" @@ -725,9 +725,9 @@ nsContentUtils::InitializeTouchEventTable() if (!sEventTableInitialized && sAtomEventTable && sStringEventTable) { sEventTableInitialized = true; static const EventNameMapping touchEventArray[] = { -#define EVENT(name_, _id, _type, _class) -#define TOUCH_EVENT(name_, _id, _type, _class) \ - { nsGkAtoms::on##name_, _id, _type, _class }, +#define EVENT(name_, _message, _type, _class) +#define TOUCH_EVENT(name_, _message, _type, _class) \ + { nsGkAtoms::on##name_, _type, _message, _class }, #include "mozilla/EventNameList.h" #undef TOUCH_EVENT #undef EVENT @@ -3667,13 +3667,13 @@ nsContentUtils::IsEventAttributeName(nsIAtom* aName, int32_t aType) } // static -uint32_t -nsContentUtils::GetEventId(nsIAtom* aName) +EventMessage +nsContentUtils::GetEventMessage(nsIAtom* aName) { if (aName) { EventNameMapping mapping; if (sAtomEventTable->Get(aName, &mapping)) { - return mapping.mId; + return mapping.mMessage; } } @@ -3692,14 +3692,15 @@ nsContentUtils::GetEventClassID(const nsAString& aName) } nsIAtom* -nsContentUtils::GetEventIdAndAtom(const nsAString& aName, - mozilla::EventClassID aEventClassID, - uint32_t* aEventID) +nsContentUtils::GetEventMessageAndAtom(const nsAString& aName, + mozilla::EventClassID aEventClassID, + EventMessage* aEventMessage) { EventNameMapping mapping; if (sStringEventTable->Get(aName, &mapping)) { - *aEventID = mapping.mEventClassID == aEventClassID ? mapping.mId : - NS_USER_DEFINED_EVENT; + *aEventMessage = + mapping.mEventClassID == aEventClassID ? mapping.mMessage : + NS_USER_DEFINED_EVENT; return mapping.mAtom; } @@ -3712,11 +3713,11 @@ nsContentUtils::GetEventIdAndAtom(const nsAString& aName, } } - *aEventID = NS_USER_DEFINED_EVENT; + *aEventMessage = NS_USER_DEFINED_EVENT; nsCOMPtr atom = NS_AtomizeMainThread(NS_LITERAL_STRING("on") + aName); sUserDefinedEvents->AppendObject(atom); mapping.mAtom = atom; - mapping.mId = NS_USER_DEFINED_EVENT; + mapping.mMessage = NS_USER_DEFINED_EVENT; mapping.mType = EventNameType_None; mapping.mEventClassID = eBasicEventClass; sStringEventTable->Put(aName, mapping); @@ -7657,7 +7658,7 @@ nsContentUtils::SendKeyEvent(nsCOMPtr aWidget, if (!aWidget) return NS_ERROR_FAILURE; - int32_t msg; + EventMessage msg; if (aType.EqualsLiteral("keydown")) msg = NS_KEY_DOWN; else if (aType.EqualsLiteral("keyup")) @@ -7770,7 +7771,7 @@ nsContentUtils::SendMouseEvent(nsCOMPtr aPresShell, if (!widget) return NS_ERROR_FAILURE; - int32_t msg; + EventMessage msg; bool contextMenuKey = false; if (aType.EqualsLiteral("mousedown")) msg = NS_MOUSE_BUTTON_DOWN; diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index ecef01185a..7bcf0786c9 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -165,8 +165,8 @@ struct EventNameMapping // This holds pointers to nsGkAtoms members, and is therefore safe as a // non-owning reference. nsIAtom* MOZ_NON_OWNING_REF mAtom; - uint32_t mId; int32_t mType; + mozilla::EventMessage mMessage; mozilla::EventClassID mEventClassID; }; @@ -1138,13 +1138,13 @@ public: static bool IsEventAttributeName(nsIAtom* aName, int32_t aType); /** - * Return the event id for the event with the given name. The name is the - * event name with the 'on' prefix. Returns NS_USER_DEFINED_EVENT if the + * Return the event message for the event with the given name. The name is + * the event name with the 'on' prefix. Returns NS_USER_DEFINED_EVENT if the * event doesn't match a known event name. * * @param aName the event name to look up */ - static uint32_t GetEventId(nsIAtom* aName); + static mozilla::EventMessage GetEventMessage(nsIAtom* aName); /** * Return the EventClassID for the event with the given name. The name is the @@ -1156,7 +1156,7 @@ public: static mozilla::EventClassID GetEventClassID(const nsAString& aName); /** - * Return the event id and atom for the event with the given name. + * Return the event message and atom for the event with the given name. * The name is the event name *without* the 'on' prefix. * Returns NS_USER_DEFINED_EVENT on the aEventID if the * event doesn't match a known event name in the category. @@ -1164,9 +1164,9 @@ public: * @param aName the event name to look up * @param aEventClassID only return event id for aEventClassID */ - static nsIAtom* GetEventIdAndAtom(const nsAString& aName, - mozilla::EventClassID aEventClassID, - uint32_t* aEventID); + static nsIAtom* GetEventMessageAndAtom(const nsAString& aName, + mozilla::EventClassID aEventClassID, + mozilla::EventMessage* aEventMessage); /** * Used only during traversal of the XPCOM graph by the cycle diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index 3d07f34191..9752c65aaa 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -625,14 +625,18 @@ IsSelectionInsideRuby(nsISelection* aSelection) } bool -nsCopySupport::FireClipboardEvent(int32_t aType, int32_t aClipboardType, nsIPresShell* aPresShell, - nsISelection* aSelection, bool* aActionTaken) +nsCopySupport::FireClipboardEvent(EventMessage aEventMessage, + int32_t aClipboardType, + nsIPresShell* aPresShell, + nsISelection* aSelection, + bool* aActionTaken) { if (aActionTaken) { *aActionTaken = false; } - NS_ASSERTION(aType == NS_CUT || aType == NS_COPY || aType == NS_PASTE, + NS_ASSERTION(aEventMessage == NS_CUT || aEventMessage == NS_COPY || + aEventMessage == NS_PASTE, "Invalid clipboard event type"); nsCOMPtr presShell = aPresShell; @@ -688,10 +692,11 @@ nsCopySupport::FireClipboardEvent(int32_t aType, int32_t aClipboardType, nsIPres nsRefPtr clipboardData; if (chromeShell || Preferences::GetBool("dom.event.clipboardevents.enabled", true)) { clipboardData = - new DataTransfer(piWindow, aType, aType == NS_PASTE, aClipboardType); + new DataTransfer(piWindow, aEventMessage, aEventMessage == NS_PASTE, + aClipboardType); nsEventStatus status = nsEventStatus_eIgnore; - InternalClipboardEvent evt(true, aType); + InternalClipboardEvent evt(true, aEventMessage); evt.clipboardData = clipboardData; EventDispatcher::Dispatch(content, presShell->GetPresContext(), &evt, nullptr, &status); @@ -702,7 +707,7 @@ nsCopySupport::FireClipboardEvent(int32_t aType, int32_t aClipboardType, nsIPres // No need to do anything special during a paste. Either an event listener // took care of it and cancelled the event, or the caller will handle it. // Return true to indicate that the event wasn't cancelled. - if (aType == NS_PASTE) { + if (aEventMessage == NS_PASTE) { // Clear and mark the clipboardData as readonly. This prevents someone // from reading the clipboard contents after the paste event has fired. if (clipboardData) { @@ -742,7 +747,7 @@ nsCopySupport::FireClipboardEvent(int32_t aType, int32_t aClipboardType, nsIPres // when cutting non-editable content, do nothing // XXX this is probably the wrong editable flag to check - if (aType != NS_CUT || content->IsEditable()) { + if (aEventMessage != NS_CUT || content->IsEditable()) { // get the data from the selection if any bool isCollapsed; sel->GetIsCollapsed(&isCollapsed); diff --git a/dom/base/nsCopySupport.h b/dom/base/nsCopySupport.h index 222134c259..b7f1ed77b7 100644 --- a/dom/base/nsCopySupport.h +++ b/dom/base/nsCopySupport.h @@ -6,7 +6,7 @@ #ifndef nsCopySupport_h__ #define nsCopySupport_h__ -#include "nscore.h" +#include "mozilla/EventForwards.h" class nsINode; class nsISelection; @@ -64,7 +64,7 @@ class nsCopySupport /** * Fires a cut, copy or paste event, on the given presshell, depending - * on the value of aType, which should be either NS_CUT, NS_COPY or + * on the value of aEventMessage, which should be either NS_CUT, NS_COPY or * NS_PASTE, and perform the default copy action if the event was not * cancelled. * @@ -88,7 +88,7 @@ class nsCopySupport * * If the event is cancelled or an error occurs, false will be returned. */ - static bool FireClipboardEvent(int32_t aType, + static bool FireClipboardEvent(mozilla::EventMessage aEventMessage, int32_t aClipboardType, nsIPresShell* aPresShell, nsISelection* aSelection, diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index c770f4d88e..fec562ab24 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -698,7 +698,7 @@ nsDOMWindowUtils::SendPointerEventCommon(const nsAString& aType, return NS_ERROR_FAILURE; } - int32_t msg; + EventMessage msg; if (aType.EqualsLiteral("pointerdown")) { msg = NS_POINTER_DOWN; } else if (aType.EqualsLiteral("pointerup")) { @@ -977,7 +977,7 @@ nsDOMWindowUtils::SendTouchEventCommon(const nsAString& aType, if (!widget) { return NS_ERROR_NULL_POINTER; } - int32_t msg; + EventMessage msg; if (aType.EqualsLiteral("touchstart")) { msg = NS_TOUCH_START; } else if (aType.EqualsLiteral("touchmove")) { @@ -1312,7 +1312,7 @@ nsDOMWindowUtils::SendSimpleGestureEvent(const nsAString& aType, if (!widget) return NS_ERROR_FAILURE; - int32_t msg; + EventMessage msg; if (aType.EqualsLiteral("MozSwipeGestureStart")) msg = NS_SIMPLE_GESTURE_SWIPE_START; else if (aType.EqualsLiteral("MozSwipeGestureUpdate")) @@ -1931,13 +1931,28 @@ nsDOMWindowUtils::SendQueryContentEvent(uint32_t aType, return NS_ERROR_FAILURE; } - if (aType != NS_QUERY_SELECTED_TEXT && - aType != NS_QUERY_TEXT_CONTENT && - aType != NS_QUERY_CARET_RECT && - aType != NS_QUERY_TEXT_RECT && - aType != NS_QUERY_EDITOR_RECT && - aType != NS_QUERY_CHARACTER_AT_POINT) { - return NS_ERROR_INVALID_ARG; + EventMessage message; + switch (aType) { + case QUERY_SELECTED_TEXT: + message = NS_QUERY_SELECTED_TEXT; + break; + case QUERY_TEXT_CONTENT: + message = NS_QUERY_TEXT_CONTENT; + break; + case QUERY_CARET_RECT: + message = NS_QUERY_CARET_RECT; + break; + case QUERY_TEXT_RECT: + message = NS_QUERY_TEXT_RECT; + break; + case QUERY_EDITOR_RECT: + message = NS_QUERY_EDITOR_RECT; + break; + case QUERY_CHARACTER_AT_POINT: + message = NS_QUERY_CHARACTER_AT_POINT; + break; + default: + return NS_ERROR_INVALID_ARG; } nsCOMPtr targetWidget = widget; @@ -1946,7 +1961,7 @@ nsDOMWindowUtils::SendQueryContentEvent(uint32_t aType, bool useNativeLineBreak = !(aAdditionalFlags & QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK); - if (aType == QUERY_CHARACTER_AT_POINT) { + if (message == NS_QUERY_CHARACTER_AT_POINT) { // Looking for the widget at the point. WidgetQueryContentEvent dummyEvent(true, NS_QUERY_CONTENT_STATE, widget); dummyEvent.mUseNativeLineBreak = useNativeLineBreak; @@ -1973,10 +1988,10 @@ nsDOMWindowUtils::SendQueryContentEvent(uint32_t aType, pt += widget->WidgetToScreenOffset() - targetWidget->WidgetToScreenOffset(); - WidgetQueryContentEvent queryEvent(true, aType, targetWidget); + WidgetQueryContentEvent queryEvent(true, message, targetWidget); InitEvent(queryEvent, &pt); - switch (aType) { + switch (message) { case NS_QUERY_TEXT_CONTENT: queryEvent.InitForQueryTextContent(aOffset, aLength, useNativeLineBreak); break; @@ -2046,7 +2061,7 @@ nsDOMWindowUtils::SendContentCommandEvent(const nsAString& aType, if (!widget) return NS_ERROR_FAILURE; - int32_t msg; + EventMessage msg; if (aType.EqualsLiteral("cut")) msg = NS_CONTENT_COMMAND_CUT; else if (aType.EqualsLiteral("copy")) diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index f8065bbf4b..5c69dbc44a 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -97,25 +97,29 @@ PRLogModuleInfo* gFocusNavigationLog; struct nsDelayedBlurOrFocusEvent { - nsDelayedBlurOrFocusEvent(uint32_t aType, + nsDelayedBlurOrFocusEvent(EventMessage aEventMessage, nsIPresShell* aPresShell, nsIDocument* aDocument, EventTarget* aTarget) - : mType(aType), - mPresShell(aPresShell), - mDocument(aDocument), - mTarget(aTarget) { } + : mPresShell(aPresShell) + , mDocument(aDocument) + , mTarget(aTarget) + , mEventMessage(aEventMessage) + { + } nsDelayedBlurOrFocusEvent(const nsDelayedBlurOrFocusEvent& aOther) - : mType(aOther.mType), - mPresShell(aOther.mPresShell), - mDocument(aOther.mDocument), - mTarget(aOther.mTarget) { } + : mPresShell(aOther.mPresShell) + , mDocument(aOther.mDocument) + , mTarget(aOther.mTarget) + , mEventMessage(aOther.mEventMessage) + { + } - uint32_t mType; nsCOMPtr mPresShell; nsCOMPtr mDocument; nsCOMPtr mTarget; + EventMessage mEventMessage; }; inline void ImplCycleCollectionUnlink(nsDelayedBlurOrFocusEvent& aField) @@ -1035,11 +1039,11 @@ nsFocusManager::FireDelayedEvents(nsIDocument* aDocument) mDelayedBlurFocusEvents.RemoveElementAt(i); --i; } else if (!aDocument->EventHandlingSuppressed()) { - uint32_t type = mDelayedBlurFocusEvents[i].mType; + EventMessage message = mDelayedBlurFocusEvents[i].mEventMessage; nsCOMPtr target = mDelayedBlurFocusEvents[i].mTarget; nsCOMPtr presShell = mDelayedBlurFocusEvents[i].mPresShell; mDelayedBlurFocusEvents.RemoveElementAt(i); - SendFocusOrBlurEvent(type, presShell, aDocument, target, 0, false); + SendFocusOrBlurEvent(message, presShell, aDocument, target, 0, false); --i; } } @@ -1947,15 +1951,20 @@ nsFocusManager::Focus(nsPIDOMWindow* aWindow, class FocusBlurEvent : public nsRunnable { public: - FocusBlurEvent(nsISupports* aTarget, uint32_t aType, + FocusBlurEvent(nsISupports* aTarget, EventMessage aEventMessage, nsPresContext* aContext, bool aWindowRaised, bool aIsRefocus) - : mTarget(aTarget), mType(aType), mContext(aContext), - mWindowRaised(aWindowRaised), mIsRefocus(aIsRefocus) {} + : mTarget(aTarget) + , mContext(aContext) + , mEventMessage(aEventMessage) + , mWindowRaised(aWindowRaised) + , mIsRefocus(aIsRefocus) + { + } NS_IMETHOD Run() { - InternalFocusEvent event(true, mType); + InternalFocusEvent event(true, mEventMessage); event.mFlags.mBubbles = false; event.fromRaise = mWindowRaised; event.isRefocus = mIsRefocus; @@ -1963,14 +1972,14 @@ public: } nsCOMPtr mTarget; - uint32_t mType; nsRefPtr mContext; + EventMessage mEventMessage; bool mWindowRaised; bool mIsRefocus; }; void -nsFocusManager::SendFocusOrBlurEvent(uint32_t aType, +nsFocusManager::SendFocusOrBlurEvent(EventMessage aEventMessage, nsIPresShell* aPresShell, nsIDocument* aDocument, nsISupports* aTarget, @@ -1978,7 +1987,8 @@ nsFocusManager::SendFocusOrBlurEvent(uint32_t aType, bool aWindowRaised, bool aIsRefocus) { - NS_ASSERTION(aType == NS_FOCUS_CONTENT || aType == NS_BLUR_CONTENT, + NS_ASSERTION(aEventMessage == NS_FOCUS_CONTENT || + aEventMessage == NS_BLUR_CONTENT, "Wrong event type for SendFocusOrBlurEvent"); nsCOMPtr eventTarget = do_QueryInterface(aTarget); @@ -2001,7 +2011,7 @@ nsFocusManager::SendFocusOrBlurEvent(uint32_t aType, for (uint32_t i = mDelayedBlurFocusEvents.Length(); i > 0; --i) { // if this event was already queued, remove it and append it to the end - if (mDelayedBlurFocusEvents[i - 1].mType == aType && + if (mDelayedBlurFocusEvents[i - 1].mEventMessage == aEventMessage && mDelayedBlurFocusEvents[i - 1].mPresShell == aPresShell && mDelayedBlurFocusEvents[i - 1].mDocument == aDocument && mDelayedBlurFocusEvents[i - 1].mTarget == eventTarget) { @@ -2010,23 +2020,25 @@ nsFocusManager::SendFocusOrBlurEvent(uint32_t aType, } mDelayedBlurFocusEvents.AppendElement( - nsDelayedBlurOrFocusEvent(aType, aPresShell, aDocument, eventTarget)); + nsDelayedBlurOrFocusEvent(aEventMessage, aPresShell, + aDocument, eventTarget)); return; } #ifdef ACCESSIBILITY nsAccessibilityService* accService = GetAccService(); if (accService) { - if (aType == NS_FOCUS_CONTENT) + if (aEventMessage == NS_FOCUS_CONTENT) { accService->NotifyOfDOMFocus(aTarget); - else + } else { accService->NotifyOfDOMBlur(aTarget); + } } #endif if (!dontDispatchEvent) { nsContentUtils::AddScriptRunner( - new FocusBlurEvent(aTarget, aType, aPresShell->GetPresContext(), + new FocusBlurEvent(aTarget, aEventMessage, aPresShell->GetPresContext(), aWindowRaised, aIsRefocus)); } } diff --git a/dom/base/nsFocusManager.h b/dom/base/nsFocusManager.h index e0e9fb1f00..73fa2e9cf0 100644 --- a/dom/base/nsFocusManager.h +++ b/dom/base/nsFocusManager.h @@ -280,12 +280,12 @@ protected: /** * Fires a focus or blur event at aTarget. * - * aType should be either NS_FOCUS_CONTENT or NS_BLUR_CONTENT. For blur - * events, aFocusMethod should normally be non-zero. + * aEventMessage should be either NS_FOCUS_CONTENT or NS_BLUR_CONTENT. + * For blur events, aFocusMethod should normally be non-zero. * * aWindowRaised should only be true if called from WindowRaised. */ - void SendFocusOrBlurEvent(uint32_t aType, + void SendFocusOrBlurEvent(mozilla::EventMessage aEventMessage, nsIPresShell* aPresShell, nsIDocument* aDocument, nsISupports* aTarget, diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index e8821a0071..d018a60709 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -2252,6 +2252,8 @@ GK_ATOM(aria_atomic, "aria-atomic") GK_ATOM(aria_autocomplete, "aria-autocomplete") GK_ATOM(aria_busy, "aria-busy") GK_ATOM(aria_checked, "aria-checked") +GK_ATOM(aria_colcount, "aria-colcount") +GK_ATOM(aria_colindex, "aria-colindex") GK_ATOM(aria_controls, "aria-controls") GK_ATOM(aria_describedby, "aria-describedby") GK_ATOM(aria_disabled, "aria-disabled") @@ -2276,6 +2278,8 @@ GK_ATOM(aria_pressed, "aria-pressed") GK_ATOM(aria_readonly, "aria-readonly") GK_ATOM(aria_relevant, "aria-relevant") GK_ATOM(aria_required, "aria-required") +GK_ATOM(aria_rowcount, "aria-rowcount") +GK_ATOM(aria_rowindex, "aria-rowindex") GK_ATOM(aria_selected, "aria-selected") GK_ATOM(aria_setsize, "aria-setsize") GK_ATOM(aria_sort, "aria-sort") diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 9d212abdbb..fcfb0535b0 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -3050,7 +3050,7 @@ nsGlobalWindow::PreHandleEvent(EventChainPreVisitor& aVisitor) { NS_PRECONDITION(IsInnerWindow(), "PreHandleEvent is used on outer window!?"); static uint32_t count = 0; - uint32_t msg = aVisitor.mEvent->mMessage; + EventMessage msg = aVisitor.mEvent->mMessage; aVisitor.mCanHandle = true; aVisitor.mForceContentDispatch = true; //FIXME! Bug 329119 @@ -14280,7 +14280,7 @@ nsGlobalWindow::GetIsPrerendered() #ifdef MOZ_B2G void -nsGlobalWindow::EnableNetworkEvent(uint32_t aType) +nsGlobalWindow::EnableNetworkEvent(EventMessage aEventMessage) { MOZ_ASSERT(IsInnerWindow()); @@ -14305,7 +14305,7 @@ nsGlobalWindow::EnableNetworkEvent(uint32_t aType) return; } - switch (aType) { + switch (aEventMessage) { case NS_NETWORK_UPLOAD_EVENT: if (!mNetworkUploadObserverEnabled) { mNetworkUploadObserverEnabled = true; @@ -14318,11 +14318,13 @@ nsGlobalWindow::EnableNetworkEvent(uint32_t aType) os->AddObserver(mObserver, NS_NETWORK_ACTIVITY_BLIP_DOWNLOAD_TOPIC, false); } break; + default: + break; } } void -nsGlobalWindow::DisableNetworkEvent(uint32_t aType) +nsGlobalWindow::DisableNetworkEvent(EventMessage aEventMessage) { MOZ_ASSERT(IsInnerWindow()); @@ -14331,7 +14333,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType) return; } - switch (aType) { + switch (aEventMessage) { case NS_NETWORK_UPLOAD_EVENT: if (mNetworkUploadObserverEnabled) { mNetworkUploadObserverEnabled = false; @@ -14344,6 +14346,8 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType) os->RemoveObserver(mObserver, NS_NETWORK_ACTIVITY_BLIP_DOWNLOAD_TOPIC); } break; + default: + break; } } #endif // MOZ_B2G diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index da984dee9c..3d59b7ae44 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -664,8 +664,9 @@ public: #ifdef MOZ_B2G // Inner windows only. - virtual void EnableNetworkEvent(uint32_t aType) override; - virtual void DisableNetworkEvent(uint32_t aType) override; + virtual void EnableNetworkEvent(mozilla::EventMessage aEventMessage) override; + virtual void DisableNetworkEvent( + mozilla::EventMessage aEventMessage) override; #endif // MOZ_B2G virtual nsresult SetArguments(nsIArray* aArguments) override; diff --git a/dom/base/nsGlobalWindowCommands.cpp b/dom/base/nsGlobalWindowCommands.cpp index 4b10868e71..59c5b45496 100644 --- a/dom/base/nsGlobalWindowCommands.cpp +++ b/dom/base/nsGlobalWindowCommands.cpp @@ -526,16 +526,16 @@ nsClipboardCommand::DoCommand(const char *aCommandName, nsISupports *aContext) nsCOMPtr presShell = docShell->GetPresShell(); NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - int32_t eventType = NS_COPY; + EventMessage eventMessage = NS_COPY; if (strcmp(aCommandName, "cmd_cut") == 0) { - eventType = NS_CUT; + eventMessage = NS_CUT; } else if (strcmp(aCommandName, "cmd_paste") == 0) { - eventType = NS_PASTE; + eventMessage = NS_PASTE; } bool actionTaken = false; bool notCancelled = - nsCopySupport::FireClipboardEvent(eventType, + nsCopySupport::FireClipboardEvent(eventMessage, nsIClipboard::kGlobalClipboard, presShell, nullptr, &actionTaken); diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 816574dc68..97ab3f6e78 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -63,8 +63,8 @@ enum UIStateChangeType }; #define NS_PIDOMWINDOW_IID \ -{ 0x2485d4d7, 0xf7cb, 0x481e, \ - { 0x9c, 0x89, 0xb2, 0xa8, 0x12, 0x67, 0x7f, 0x97 } } +{ 0x052e675a, 0xacd3, 0x48d1, \ + { 0x8a, 0xcd, 0xbf, 0xff, 0xbd, 0x24, 0x4c, 0xed } } class nsPIDOMWindow : public nsIDOMWindowInternal { @@ -635,7 +635,7 @@ public: * * Inner windows only. */ - virtual void EnableNetworkEvent(uint32_t aType) = 0; + virtual void EnableNetworkEvent(mozilla::EventMessage aEventMessage) = 0; /** * Tell the window that it should stop to listen to the network event of the @@ -643,7 +643,7 @@ public: * * Inner windows only. */ - virtual void DisableNetworkEvent(uint32_t aType) = 0; + virtual void DisableNetworkEvent(mozilla::EventMessage aEventMessage) = 0; #endif // MOZ_B2G /** diff --git a/dom/base/nsScriptElement.cpp b/dom/base/nsScriptElement.cpp index 40e44f1440..ef7ec836f0 100644 --- a/dom/base/nsScriptElement.cpp +++ b/dom/base/nsScriptElement.cpp @@ -59,10 +59,10 @@ nsScriptElement::ScriptEvaluated(nsresult aResult, nsContentUtils::GetContextForContent(cont); nsEventStatus status = nsEventStatus_eIgnore; - uint32_t type = NS_SUCCEEDED(aResult) ? NS_LOAD : NS_LOAD_ERROR; - WidgetEvent event(true, type); + EventMessage message = NS_SUCCEEDED(aResult) ? NS_LOAD : NS_LOAD_ERROR; + WidgetEvent event(true, message); // Load event doesn't bubble. - event.mFlags.mBubbles = (type != NS_LOAD); + event.mFlags.mBubbles = (message != NS_LOAD); EventDispatcher::Dispatch(cont, presContext, &event, nullptr, &status); } diff --git a/dom/events/AnimationEvent.cpp b/dom/events/AnimationEvent.cpp index 6267137267..4c54aaa051 100644 --- a/dom/events/AnimationEvent.cpp +++ b/dom/events/AnimationEvent.cpp @@ -15,7 +15,7 @@ AnimationEvent::AnimationEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalAnimationEvent* aEvent) : Event(aOwner, aPresContext, - aEvent ? aEvent : new InternalAnimationEvent(false, 0)) + aEvent ? aEvent : new InternalAnimationEvent(false, NS_EVENT_NULL)) { if (aEvent) { mEventIsInternal = false; diff --git a/dom/events/BeforeAfterKeyboardEvent.cpp b/dom/events/BeforeAfterKeyboardEvent.cpp index 736e9edb07..18c914019d 100644 --- a/dom/events/BeforeAfterKeyboardEvent.cpp +++ b/dom/events/BeforeAfterKeyboardEvent.cpp @@ -17,7 +17,8 @@ BeforeAfterKeyboardEvent::BeforeAfterKeyboardEvent( InternalBeforeAfterKeyboardEvent* aEvent) : KeyboardEvent(aOwner, aPresContext, aEvent ? aEvent : - new InternalBeforeAfterKeyboardEvent(false, 0, + new InternalBeforeAfterKeyboardEvent(false, + NS_EVENT_NULL, nullptr)) { MOZ_ASSERT(mEvent->mClass == eBeforeAfterKeyboardEventClass, diff --git a/dom/events/ClipboardEvent.cpp b/dom/events/ClipboardEvent.cpp index 37d4148d64..192e4b9a48 100644 --- a/dom/events/ClipboardEvent.cpp +++ b/dom/events/ClipboardEvent.cpp @@ -16,7 +16,7 @@ ClipboardEvent::ClipboardEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalClipboardEvent* aEvent) : Event(aOwner, aPresContext, - aEvent ? aEvent : new InternalClipboardEvent(false, 0)) + aEvent ? aEvent : new InternalClipboardEvent(false, NS_EVENT_NULL)) { if (aEvent) { mEventIsInternal = false; diff --git a/dom/events/CompositionEvent.cpp b/dom/events/CompositionEvent.cpp index 0216c97818..fd4c042cfc 100644 --- a/dom/events/CompositionEvent.cpp +++ b/dom/events/CompositionEvent.cpp @@ -15,7 +15,8 @@ CompositionEvent::CompositionEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetCompositionEvent* aEvent) : UIEvent(aOwner, aPresContext, - aEvent ? aEvent : new WidgetCompositionEvent(false, 0, nullptr)) + aEvent ? aEvent : + new WidgetCompositionEvent(false, NS_EVENT_NULL, nullptr)) { NS_ASSERTION(mEvent->mClass == eCompositionEventClass, "event type mismatch"); diff --git a/dom/events/DataTransfer.cpp b/dom/events/DataTransfer.cpp index 772d9a3792..bbea2f2b73 100644 --- a/dom/events/DataTransfer.cpp +++ b/dom/events/DataTransfer.cpp @@ -155,9 +155,9 @@ DataTransfer::Constructor(const GlobalObject& aGlobal, return nullptr; } - uint32_t eventType = nsContentUtils::GetEventId(eventTypeAtom); + EventMessage eventMessage = nsContentUtils::GetEventMessage(eventTypeAtom); nsRefPtr transfer = new DataTransfer(aGlobal.GetAsSupports(), - eventType, aIsExternal, + eventMessage, aIsExternal, -1); return transfer.forget(); } diff --git a/dom/events/DragEvent.cpp b/dom/events/DragEvent.cpp index 7ebb10b0c6..948e14f438 100644 --- a/dom/events/DragEvent.cpp +++ b/dom/events/DragEvent.cpp @@ -16,7 +16,8 @@ DragEvent::DragEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetDragEvent* aEvent) : MouseEvent(aOwner, aPresContext, - aEvent ? aEvent : new WidgetDragEvent(false, 0, nullptr)) + aEvent ? aEvent : + new WidgetDragEvent(false, NS_EVENT_NULL, nullptr)) { if (aEvent) { mEventIsInternal = false; diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index 209e551e66..db15b6e9be 100644 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -106,7 +106,7 @@ Event::ConstructorInit(EventTarget* aOwner, ... } */ - mEvent = new WidgetEvent(false, 0); + mEvent = new WidgetEvent(false, NS_EVENT_NULL); mEvent->time = PR_Now(); } @@ -563,8 +563,8 @@ Event::SetEventType(const nsAString& aEventTypeArg) if (mIsMainThreadEvent) { mEvent->typeString.Truncate(); mEvent->userType = - nsContentUtils::GetEventIdAndAtom(aEventTypeArg, mEvent->mClass, - &(mEvent->mMessage)); + nsContentUtils::GetEventMessageAndAtom(aEventTypeArg, mEvent->mClass, + &(mEvent->mMessage)); } else { mEvent->userType = nullptr; mEvent->mMessage = NS_USER_DEFINED_EVENT; @@ -726,6 +726,8 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) abuse = openControlled; } break; + default: + break; } } break; @@ -740,6 +742,8 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) abuse = openControlled; } break; + default: + break; } } break; @@ -757,6 +761,8 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) case NS_XUL_COMMAND: abuse = openControlled; break; + default: + break; } } break; @@ -785,6 +791,8 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) abuse = openControlled; } break; + default: + break; } } break; @@ -801,6 +809,8 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) abuse = openControlled; } break; + default: + break; } } break; @@ -832,6 +842,8 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) abuse = openControlled; } break; + default: + break; } } break; @@ -851,6 +863,8 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) abuse = openControlled; } break; + default: + break; } } break; @@ -1038,7 +1052,7 @@ Event::GetOffsetCoords(nsPresContext* aPresContext, // logic for handling user-defined events). // static const char* -Event::GetEventName(uint32_t aEventType) +Event::GetEventName(EventMessage aEventType) { switch(aEventType) { #define ID_TO_EVENT(name_, _id, _type, _struct) \ diff --git a/dom/events/Event.h b/dom/events/Event.h index 35a58c8327..84eb2be499 100644 --- a/dom/events/Event.h +++ b/dom/events/Event.h @@ -124,7 +124,7 @@ public: static void Shutdown(); - static const char* GetEventName(uint32_t aEventType); + static const char* GetEventName(EventMessage aEventType); static CSSIntPoint GetClientCoords(nsPresContext* aPresContext, WidgetEvent* aEvent, LayoutDeviceIntPoint aPoint, diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index c34d6113cb..f0cd748e0b 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -52,11 +52,11 @@ namespace mozilla { using namespace dom; using namespace hal; -#define EVENT_TYPE_EQUALS(ls, type, userType, typeString, allEvents) \ - ((ls->mEventType == type && \ - (ls->mEventType != NS_USER_DEFINED_EVENT || \ - (mIsMainThreadELM && ls->mTypeAtom == userType) || \ - (!mIsMainThreadELM && ls->mTypeString.Equals(typeString)))) || \ +#define EVENT_TYPE_EQUALS(ls, message, userType, typeString, allEvents) \ + ((ls->mEventMessage == message && \ + (ls->mEventMessage != NS_USER_DEFINED_EVENT || \ + (mIsMainThreadELM && ls->mTypeAtom == userType) || \ + (!mIsMainThreadELM && ls->mTypeString.Equals(typeString)))) || \ (allEvents && ls->mAllEvents)) static const uint32_t kAllMutationBits = @@ -69,7 +69,7 @@ static const uint32_t kAllMutationBits = NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED; static uint32_t -MutationBitForEventType(uint32_t aEventType) +MutationBitForEventType(EventMessage aEventType) { switch (aEventType) { case NS_MUTATION_SUBTREEMODIFIED: @@ -94,8 +94,9 @@ MutationBitForEventType(uint32_t aEventType) uint32_t EventListenerManager::sMainThreadCreatedCount = 0; -EventListenerManager::EventListenerManager(EventTarget* aTarget) - : mMayHavePaintEventListener(false) +EventListenerManagerBase::EventListenerManagerBase() + : mNoListenerForEvent(NS_EVENT_NULL) + , mMayHavePaintEventListener(false) , mMayHaveMutationListeners(false) , mMayHaveCapturingListeners(false) , mMayHaveSystemGroupListeners(false) @@ -106,7 +107,13 @@ EventListenerManager::EventListenerManager(EventTarget* aTarget) , mMayHaveInputOrCompositionEventListener(false) , mClearingListeners(false) , mIsMainThreadELM(NS_IsMainThread()) - , mNoListenerForEvent(0) +{ + static_assert(sizeof(EventListenerManagerBase) == sizeof(uint32_t), + "Keep the size of EventListenerManagerBase size compact!"); +} + +EventListenerManager::EventListenerManager(EventTarget* aTarget) + : EventListenerManagerBase() , mTarget(aTarget) { NS_ASSERTION(aTarget, "unexpected null pointer"); @@ -215,15 +222,17 @@ EventListenerManager::GetTargetAsInnerWindow() const void EventListenerManager::AddEventListenerInternal( const EventListenerHolder& aListenerHolder, - uint32_t aType, + EventMessage aEventMessage, nsIAtom* aTypeAtom, const nsAString& aTypeString, const EventListenerFlags& aFlags, bool aHandler, bool aAllEvents) { - MOZ_ASSERT((NS_IsMainThread() && aType && aTypeAtom) || // Main thread - (!NS_IsMainThread() && aType && !aTypeString.IsEmpty()) || // non-main-thread + MOZ_ASSERT(// Main thread + (NS_IsMainThread() && aEventMessage && aTypeAtom) || + // non-main-thread + (!NS_IsMainThread() && aEventMessage && !aTypeString.IsEmpty()) || aAllEvents, "Missing type"); // all-events listener if (!aListenerHolder || mClearingListeners) { @@ -241,7 +250,7 @@ EventListenerManager::AddEventListenerInternal( // mListener == aListenerHolder is the last one, since it can be a bit slow. if (listener->mListenerIsHandler == aHandler && listener->mFlags == aFlags && - EVENT_TYPE_EQUALS(listener, aType, aTypeAtom, aTypeString, + EVENT_TYPE_EQUALS(listener, aEventMessage, aTypeAtom, aTypeString, aAllEvents) && listener->mListener == aListenerHolder) { return; @@ -254,8 +263,7 @@ EventListenerManager::AddEventListenerInternal( listener = aAllEvents ? mListeners.InsertElementAt(0) : mListeners.AppendElement(); listener->mListener = aListenerHolder; - MOZ_ASSERT(aType < PR_UINT16_MAX); - listener->mEventType = aType; + listener->mEventMessage = aEventMessage; listener->mTypeString = aTypeString; listener->mTypeAtom = aTypeAtom; listener->mFlags = aFlags; @@ -284,13 +292,14 @@ EventListenerManager::AddEventListenerInternal( mMayHaveCapturingListeners = true; } - if (aType == NS_AFTERPAINT) { + if (aEventMessage == NS_AFTERPAINT) { mMayHavePaintEventListener = true; nsPIDOMWindow* window = GetInnerWindowForTarget(); if (window) { window->SetHasPaintEventListeners(); } - } else if (aType >= NS_MUTATION_START && aType <= NS_MUTATION_END) { + } else if (aEventMessage >= NS_MUTATION_START && + aEventMessage <= NS_MUTATION_END) { // For mutation listeners, we need to update the global bit on the DOM window. // Otherwise we won't actually fire the mutation event. mMayHaveMutationListeners = true; @@ -301,11 +310,11 @@ EventListenerManager::AddEventListenerInternal( if (doc) { doc->WarnOnceAbout(nsIDocument::eMutationEvent); } - // If aType is NS_MUTATION_SUBTREEMODIFIED, we need to listen all + // If aEventMessage is NS_MUTATION_SUBTREEMODIFIED, we need to listen all // mutations. nsContentUtils::HasMutationListeners relies on this. - window->SetMutationListeners((aType == NS_MUTATION_SUBTREEMODIFIED) ? - kAllMutationBits : - MutationBitForEventType(aType)); + window->SetMutationListeners( + (aEventMessage == NS_MUTATION_SUBTREEMODIFIED) ? + kAllMutationBits : MutationBitForEventType(aEventMessage)); } } else if (aTypeAtom == nsGkAtoms::ondeviceorientation) { EnableDevice(NS_DEVICE_ORIENTATION); @@ -343,7 +352,8 @@ EventListenerManager::AddEventListenerInternal( if (window && !aFlags.mInSystemGroup) { window->SetHasTouchEventListeners(); } - } else if (aType >= NS_POINTER_EVENT_START && aType <= NS_POINTER_LOST_CAPTURE) { + } else if (aEventMessage >= NS_POINTER_EVENT_START && + aEventMessage <= NS_POINTER_LOST_CAPTURE) { nsPIDOMWindow* window = GetInnerWindowForTarget(); if (aTypeAtom == nsGkAtoms::onpointerenter || aTypeAtom == nsGkAtoms::onpointerleave) { @@ -372,8 +382,8 @@ EventListenerManager::AddEventListenerInternal( window->SetHasMouseEnterLeaveEventListeners(); } #ifdef MOZ_GAMEPAD - } else if (aType >= NS_GAMEPAD_START && - aType <= NS_GAMEPAD_END) { + } else if (aEventMessage >= NS_GAMEPAD_START && + aEventMessage <= NS_GAMEPAD_END) { nsPIDOMWindow* window = GetInnerWindowForTarget(); if (window) { window->SetHasGamepadEventListener(); @@ -411,9 +421,9 @@ EventListenerManager::AddEventListenerInternal( } bool -EventListenerManager::IsDeviceType(uint32_t aType) +EventListenerManager::IsDeviceType(EventMessage aEventMessage) { - switch (aType) { + switch (aEventMessage) { case NS_DEVICE_ORIENTATION: case NS_DEVICE_MOTION: case NS_DEVICE_LIGHT: @@ -427,14 +437,14 @@ EventListenerManager::IsDeviceType(uint32_t aType) } void -EventListenerManager::EnableDevice(uint32_t aType) +EventListenerManager::EnableDevice(EventMessage aEventMessage) { nsCOMPtr window = GetTargetAsInnerWindow(); if (!window) { return; } - switch (aType) { + switch (aEventMessage) { case NS_DEVICE_ORIENTATION: window->EnableDeviceSensor(SENSOR_ORIENTATION); break; @@ -457,14 +467,14 @@ EventListenerManager::EnableDevice(uint32_t aType) } void -EventListenerManager::DisableDevice(uint32_t aType) +EventListenerManager::DisableDevice(EventMessage aEventMessage) { nsCOMPtr window = GetTargetAsInnerWindow(); if (!window) { return; } - switch (aType) { + switch (aEventMessage) { case NS_DEVICE_ORIENTATION: window->DisableDeviceSensor(SENSOR_ORIENTATION); break; @@ -489,13 +499,13 @@ EventListenerManager::DisableDevice(uint32_t aType) void EventListenerManager::RemoveEventListenerInternal( const EventListenerHolder& aListenerHolder, - uint32_t aType, + EventMessage aEventMessage, nsIAtom* aUserType, const nsAString& aTypeString, const EventListenerFlags& aFlags, bool aAllEvents) { - if (!aListenerHolder || !aType || mClearingListeners) { + if (!aListenerHolder || !aEventMessage || mClearingListeners) { return; } @@ -503,16 +513,16 @@ EventListenerManager::RemoveEventListenerInternal( uint32_t count = mListeners.Length(); uint32_t typeCount = 0; - bool deviceType = IsDeviceType(aType); + bool deviceType = IsDeviceType(aEventMessage); #ifdef MOZ_B2G - bool timeChangeEvent = (aType == NS_MOZ_TIME_CHANGE_EVENT); - bool networkEvent = (aType == NS_NETWORK_UPLOAD_EVENT || - aType == NS_NETWORK_DOWNLOAD_EVENT); + bool timeChangeEvent = (aEventMessage == NS_MOZ_TIME_CHANGE_EVENT); + bool networkEvent = (aEventMessage == NS_NETWORK_UPLOAD_EVENT || + aEventMessage == NS_NETWORK_DOWNLOAD_EVENT); #endif // MOZ_B2G for (uint32_t i = 0; i < count; ++i) { listener = &mListeners.ElementAt(i); - if (EVENT_TYPE_EQUALS(listener, aType, aUserType, aTypeString, + if (EVENT_TYPE_EQUALS(listener, aEventMessage, aUserType, aTypeString, aAllEvents)) { ++typeCount; if (listener->mListener == aListenerHolder && @@ -542,7 +552,7 @@ EventListenerManager::RemoveEventListenerInternal( } if (!aAllEvents && deviceType && typeCount == 0) { - DisableDevice(aType); + DisableDevice(aEventMessage); #ifdef MOZ_B2G } else if (timeChangeEvent && typeCount == 0) { nsCOMPtr window = GetTargetAsInnerWindow(); @@ -552,7 +562,7 @@ EventListenerManager::RemoveEventListenerInternal( } else if (!aAllEvents && networkEvent && typeCount == 0) { nsCOMPtr window = GetTargetAsInnerWindow(); if (window) { - window->DisableNetworkEvent(aType); + window->DisableNetworkEvent(aEventMessage); } #endif // MOZ_B2G } @@ -564,7 +574,7 @@ EventListenerManager::ListenerCanHandle(Listener* aListener, { // This is slightly different from EVENT_TYPE_EQUALS in that it returns // true even when aEvent->mMessage == NS_USER_DEFINED_EVENT and - // aListener=>mEventType != NS_USER_DEFINED_EVENT as long as the atoms are + // aListener=>mEventMessage != NS_USER_DEFINED_EVENT as long as the atoms are // the same if (aListener->mAllEvents) { return true; @@ -576,7 +586,7 @@ EventListenerManager::ListenerCanHandle(Listener* aListener, return aListener->mTypeString.Equals(aEvent->typeString); } MOZ_ASSERT(mIsMainThreadELM); - return aListener->mEventType == aEvent->mMessage; + return aListener->mEventMessage == aEvent->mMessage; } void @@ -587,8 +597,8 @@ EventListenerManager::AddEventListenerByType( { nsCOMPtr atom = mIsMainThreadELM ? do_GetAtom(NS_LITERAL_STRING("on") + aType) : nullptr; - uint32_t type = nsContentUtils::GetEventId(atom); - AddEventListenerInternal(aListenerHolder, type, atom, aType, aFlags); + EventMessage message = nsContentUtils::GetEventMessage(atom); + AddEventListenerInternal(aListenerHolder, message, atom, aType, aFlags); } void @@ -599,12 +609,12 @@ EventListenerManager::RemoveEventListenerByType( { nsCOMPtr atom = mIsMainThreadELM ? do_GetAtom(NS_LITERAL_STRING("on") + aType) : nullptr; - uint32_t type = nsContentUtils::GetEventId(atom); - RemoveEventListenerInternal(aListenerHolder, type, atom, aType, aFlags); + EventMessage message = nsContentUtils::GetEventMessage(atom); + RemoveEventListenerInternal(aListenerHolder, message, atom, aType, aFlags); } EventListenerManager::Listener* -EventListenerManager::FindEventHandler(uint32_t aEventType, +EventListenerManager::FindEventHandler(EventMessage aEventMessage, nsIAtom* aTypeAtom, const nsAString& aTypeString) { @@ -615,7 +625,7 @@ EventListenerManager::FindEventHandler(uint32_t aEventType, for (uint32_t i = 0; i < count; ++i) { listener = &mListeners.ElementAt(i); if (listener->mListenerIsHandler && - EVENT_TYPE_EQUALS(listener, aEventType, aTypeAtom, aTypeString, + EVENT_TYPE_EQUALS(listener, aEventMessage, aTypeAtom, aTypeString, false)) { return listener; } @@ -632,8 +642,8 @@ EventListenerManager::SetEventHandlerInternal( { MOZ_ASSERT(aName || !aTypeString.IsEmpty()); - uint32_t eventType = nsContentUtils::GetEventId(aName); - Listener* listener = FindEventHandler(eventType, aName, aTypeString); + EventMessage eventMessage = nsContentUtils::GetEventMessage(aName); + Listener* listener = FindEventHandler(eventMessage, aName, aTypeString); if (!listener) { // If we didn't find a script listener or no listeners existed @@ -645,10 +655,10 @@ EventListenerManager::SetEventHandlerInternal( NS_NewJSEventHandler(mTarget, aName, aTypedHandler, getter_AddRefs(jsEventHandler)); EventListenerHolder listenerHolder(jsEventHandler); - AddEventListenerInternal(listenerHolder, eventType, aName, aTypeString, + AddEventListenerInternal(listenerHolder, eventMessage, aName, aTypeString, flags, true); - listener = FindEventHandler(eventType, aName, aTypeString); + listener = FindEventHandler(eventMessage, aName, aTypeString); } else { JSEventHandler* jsEventHandler = listener->GetJSEventHandler(); MOZ_ASSERT(jsEventHandler, @@ -781,8 +791,8 @@ EventListenerManager::RemoveEventHandler(nsIAtom* aName, return; } - uint32_t eventType = nsContentUtils::GetEventId(aName); - Listener* listener = FindEventHandler(eventType, aName, aTypeString); + EventMessage eventMessage = nsContentUtils::GetEventMessage(aName); + Listener* listener = FindEventHandler(eventMessage, aName, aTypeString); if (listener) { mListeners.RemoveElementAt(uint32_t(listener - &mListeners.ElementAt(0))); @@ -1244,8 +1254,8 @@ EventListenerManager::HasMutationListeners() uint32_t count = mListeners.Length(); for (uint32_t i = 0; i < count; ++i) { Listener* listener = &mListeners.ElementAt(i); - if (listener->mEventType >= NS_MUTATION_START && - listener->mEventType <= NS_MUTATION_END) { + if (listener->mEventMessage >= NS_MUTATION_START && + listener->mEventMessage <= NS_MUTATION_END) { return true; } } @@ -1262,12 +1272,12 @@ EventListenerManager::MutationListenerBits() uint32_t count = mListeners.Length(); for (uint32_t i = 0; i < count; ++i) { Listener* listener = &mListeners.ElementAt(i); - if (listener->mEventType >= NS_MUTATION_START && - listener->mEventType <= NS_MUTATION_END) { - if (listener->mEventType == NS_MUTATION_SUBTREEMODIFIED) { + if (listener->mEventMessage >= NS_MUTATION_START && + listener->mEventMessage <= NS_MUTATION_END) { + if (listener->mEventMessage == NS_MUTATION_SUBTREEMODIFIED) { return kAllMutationBits; } - bits |= MutationBitForEventType(listener->mEventType); + bits |= MutationBitForEventType(listener->mEventMessage); } } } @@ -1357,8 +1367,8 @@ EventListenerManager::HasUnloadListeners() uint32_t count = mListeners.Length(); for (uint32_t i = 0; i < count; ++i) { Listener* listener = &mListeners.ElementAt(i); - if (listener->mEventType == NS_PAGE_UNLOAD || - listener->mEventType == NS_BEFORE_PAGE_UNLOAD) { + if (listener->mEventMessage == NS_PAGE_UNLOAD || + listener->mEventMessage == NS_BEFORE_PAGE_UNLOAD) { return true; } } @@ -1429,8 +1439,8 @@ const TypedEventHandler* EventListenerManager::GetTypedEventHandler(nsIAtom* aEventName, const nsAString& aTypeString) { - uint32_t eventType = nsContentUtils::GetEventId(aEventName); - Listener* listener = FindEventHandler(eventType, aEventName, aTypeString); + EventMessage eventMessage = nsContentUtils::GetEventMessage(aEventName); + Listener* listener = FindEventHandler(eventMessage, aEventName, aTypeString); if (!listener) { return nullptr; diff --git a/dom/events/EventListenerManager.h b/dom/events/EventListenerManager.h index 66de15c6ee..561531483a 100644 --- a/dom/events/EventListenerManager.h +++ b/dom/events/EventListenerManager.h @@ -146,11 +146,31 @@ inline EventListenerFlags AllEventsAtSystemGroupCapture() return flags; } +class EventListenerManagerBase +{ +protected: + EventListenerManagerBase(); + + EventMessage mNoListenerForEvent; + uint16_t mMayHavePaintEventListener : 1; + uint16_t mMayHaveMutationListeners : 1; + uint16_t mMayHaveCapturingListeners : 1; + uint16_t mMayHaveSystemGroupListeners : 1; + uint16_t mMayHaveTouchEventListener : 1; + uint16_t mMayHaveMouseEnterLeaveEventListener : 1; + uint16_t mMayHavePointerEnterLeaveEventListener : 1; + uint16_t mMayHaveKeyEventListener : 1; + uint16_t mMayHaveInputOrCompositionEventListener : 1; + uint16_t mClearingListeners : 1; + uint16_t mIsMainThreadELM : 1; + // uint16_t mUnused : 5; +}; + /* * Event listener manager */ -class EventListenerManager final +class EventListenerManager final : public EventListenerManagerBase { ~EventListenerManager(); @@ -160,7 +180,7 @@ public: EventListenerHolder mListener; nsCOMPtr mTypeAtom; // for the main thread nsString mTypeString; // for non-main-threads - uint16_t mEventType; + EventMessage mEventMessage; enum ListenerType : uint8_t { @@ -453,7 +473,7 @@ protected: /** * Find the Listener for the "inline" event listener for aTypeAtom. */ - Listener* FindEventHandler(uint32_t aEventType, + Listener* FindEventHandler(EventMessage aEventMessage, nsIAtom* aTypeAtom, const nsAString& aTypeString); @@ -469,9 +489,9 @@ protected: const TypedEventHandler& aHandler, bool aPermitUntrustedEvents); - bool IsDeviceType(uint32_t aType); - void EnableDevice(uint32_t aType); - void DisableDevice(uint32_t aType); + bool IsDeviceType(EventMessage aEventMessage); + void EnableDevice(EventMessage aEventMessage); + void DisableDevice(EventMessage aEventMessage); public: /** @@ -533,14 +553,14 @@ protected: bool aUseCapture); void AddEventListenerInternal(const EventListenerHolder& aListener, - uint32_t aType, + EventMessage aEventMessage, nsIAtom* aTypeAtom, const nsAString& aTypeString, const EventListenerFlags& aFlags, bool aHandler = false, bool aAllEvents = false); void RemoveEventListenerInternal(const EventListenerHolder& aListener, - uint32_t aType, + EventMessage aEventMessage, nsIAtom* aUserType, const nsAString& aTypeString, const EventListenerFlags& aFlags, @@ -553,22 +573,14 @@ protected: bool ListenerCanHandle(Listener* aListener, WidgetEvent* aEvent); + // BE AWARE, a lot of instances of EventListenerManager will be created. + // Therefor, we need to keep this class compact. When you add integer + // members, please add them to EventListemerManagerBase and check the size + // at build time. + already_AddRefed GetScriptGlobalAndDocument(nsIDocument** aDoc); - uint32_t mMayHavePaintEventListener : 1; - uint32_t mMayHaveMutationListeners : 1; - uint32_t mMayHaveCapturingListeners : 1; - uint32_t mMayHaveSystemGroupListeners : 1; - uint32_t mMayHaveTouchEventListener : 1; - uint32_t mMayHaveMouseEnterLeaveEventListener : 1; - uint32_t mMayHavePointerEnterLeaveEventListener : 1; - uint32_t mMayHaveKeyEventListener : 1; - uint32_t mMayHaveInputOrCompositionEventListener : 1; - uint32_t mClearingListeners : 1; - uint32_t mIsMainThreadELM : 1; - uint32_t mNoListenerForEvent : 21; - nsAutoTObserverArray mListeners; dom::EventTarget* MOZ_NON_OWNING_REF mTarget; nsCOMPtr mNoListenerForEventAtom; diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 3eeeca38d9..dc3b370c65 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -641,7 +641,7 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, } GenerateMouseEnterExit(mouseEvent); //This is a window level mouse exit event and should stop here - aEvent->mMessage = 0; + aEvent->mMessage = NS_EVENT_NULL; break; } case NS_MOUSE_MOVE: @@ -852,6 +852,8 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, compositionEvent->mData = selectedText.mReply.mString; } break; + default: + break; } return NS_OK; } @@ -1210,6 +1212,8 @@ CrossProcessSafeEvent(const WidgetEvent& aEvent) case NS_DRAGDROP_EXIT: case NS_DRAGDROP_DROP: return true; + default: + break; } default: return false; @@ -3264,12 +3268,13 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, } if (dispatchedToContentProcess) { dragSession->SetCanDrop(true); - } - - // now set the drop effect in the initial dataTransfer. This ensures - // that we can get the desired drop effect in the drop event. - if (initialDataTransfer) + } else if (initialDataTransfer) { + // Now set the drop effect in the initial dataTransfer. This ensures + // that we can get the desired drop effect in the drop event. For events + // dispatched to content, the content process will take care of setting + // this. initialDataTransfer->SetDropEffectInt(dropEffect); + } } break; @@ -3343,6 +3348,9 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, } break; #endif + + default: + break; } //Reset target frame to null to avoid mistargeting after reentrant event @@ -3696,7 +3704,7 @@ EventStateManager::IsHandlingUserInput() static void CreateMouseOrPointerWidgetEvent(WidgetMouseEvent* aMouseEvent, - uint32_t aMessage, + EventMessage aMessage, nsIContent* aRelatedContent, nsAutoPtr& aNewEvent) { @@ -3736,7 +3744,7 @@ CreateMouseOrPointerWidgetEvent(WidgetMouseEvent* aMouseEvent, nsIFrame* EventStateManager::DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent, - uint32_t aMessage, + EventMessage aMessage, nsIContent* aTargetContent, nsIContent* aRelatedContent) { @@ -3828,10 +3836,11 @@ class EnterLeaveDispatcher public: EnterLeaveDispatcher(EventStateManager* aESM, nsIContent* aTarget, nsIContent* aRelatedTarget, - WidgetMouseEvent* aMouseEvent, uint32_t aType) + WidgetMouseEvent* aMouseEvent, + EventMessage aEventMessage) : mESM(aESM) , mMouseEvent(aMouseEvent) - , mType(aType) + , mEventMessage(aEventMessage) { nsPIDOMWindow* win = aTarget ? aTarget->OwnerDoc()->GetInnerWindow() : nullptr; @@ -3858,16 +3867,16 @@ public: ~EnterLeaveDispatcher() { - if (mType == NS_MOUSEENTER || - mType == NS_POINTER_ENTER) { + if (mEventMessage == NS_MOUSEENTER || + mEventMessage == NS_POINTER_ENTER) { for (int32_t i = mTargets.Count() - 1; i >= 0; --i) { - mESM->DispatchMouseOrPointerEvent(mMouseEvent, mType, mTargets[i], - mRelatedTarget); + mESM->DispatchMouseOrPointerEvent(mMouseEvent, mEventMessage, + mTargets[i], mRelatedTarget); } } else { for (int32_t i = 0; i < mTargets.Count(); ++i) { - mESM->DispatchMouseOrPointerEvent(mMouseEvent, mType, mTargets[i], - mRelatedTarget); + mESM->DispatchMouseOrPointerEvent(mMouseEvent, mEventMessage, + mTargets[i], mRelatedTarget); } } } @@ -3876,7 +3885,7 @@ public: nsCOMArray mTargets; nsCOMPtr mRelatedTarget; WidgetMouseEvent* mMouseEvent; - uint32_t mType; + EventMessage mEventMessage; }; void @@ -4065,7 +4074,8 @@ GetWindowInnerRectCenter(nsPIDOMWindow* aWindow, } void -EventStateManager::GeneratePointerEnterExit(uint32_t aMessage, WidgetMouseEvent* aEvent) +EventStateManager::GeneratePointerEnterExit(EventMessage aMessage, + WidgetMouseEvent* aEvent) { WidgetPointerEvent pointerEvent(*aEvent); pointerEvent.mMessage = aMessage; @@ -4188,6 +4198,8 @@ EventStateManager::GenerateMouseEnterExit(WidgetMouseEvent* aMouseEvent) NotifyMouseOut(aMouseEvent, nullptr); } break; + default: + break; } // reset mCurretTargetContent to what it was @@ -4334,6 +4346,9 @@ EventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext, } } break; + + default: + break; } //reset mCurretTargetContent to what it was @@ -4346,13 +4361,13 @@ EventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext, void EventStateManager::FireDragEnterOrExit(nsPresContext* aPresContext, WidgetDragEvent* aDragEvent, - uint32_t aMsg, + EventMessage aMessage, nsIContent* aRelatedTarget, nsIContent* aTargetContent, nsWeakFrame& aTargetFrame) { nsEventStatus status = nsEventStatus_eIgnore; - WidgetDragEvent event(aDragEvent->mFlags.mIsTrusted, aMsg, + WidgetDragEvent event(aDragEvent->mFlags.mIsTrusted, aMessage, aDragEvent->widget); event.refPoint = aDragEvent->refPoint; event.modifiers = aDragEvent->modifiers; @@ -4370,15 +4385,19 @@ EventStateManager::FireDragEnterOrExit(nsPresContext* aPresContext, } // adjust the drag hover if the dragenter event was cancelled or this is a drag exit - if (status == nsEventStatus_eConsumeNoDefault || aMsg == NS_DRAGDROP_EXIT) - SetContentState((aMsg == NS_DRAGDROP_ENTER) ? aTargetContent : nullptr, + if (status == nsEventStatus_eConsumeNoDefault || + aMessage == NS_DRAGDROP_EXIT) { + SetContentState((aMessage == NS_DRAGDROP_ENTER) ? + aTargetContent : nullptr, NS_EVENT_STATE_DRAGOVER); + } // collect any changes to moz cursor settings stored in the event's // data transfer. - if (aMsg == NS_DRAGDROP_LEAVE || aMsg == NS_DRAGDROP_EXIT || - aMsg == NS_DRAGDROP_ENTER) + if (aMessage == NS_DRAGDROP_LEAVE || aMessage == NS_DRAGDROP_EXIT || + aMessage == NS_DRAGDROP_ENTER) { UpdateDragDataTransfer(&event); + } } // Finally dispatch the event to the frame @@ -4490,13 +4509,13 @@ EventStateManager::SetClickCount(nsPresContext* aPresContext, nsresult EventStateManager::InitAndDispatchClickEvent(WidgetMouseEvent* aEvent, nsEventStatus* aStatus, - uint32_t aType, + EventMessage aMessage, nsIPresShell* aPresShell, nsIContent* aMouseTarget, nsWeakFrame aCurrentTarget, bool aNoContentDispatch) { - WidgetMouseEvent event(aEvent->mFlags.mIsTrusted, aType, + WidgetMouseEvent event(aEvent->mFlags.mIsTrusted, aMessage, aEvent->widget, WidgetMouseEvent::eReal); event.refPoint = aEvent->refPoint; diff --git a/dom/events/EventStateManager.h b/dom/events/EventStateManager.h index 881c813eca..af637485b4 100644 --- a/dom/events/EventStateManager.h +++ b/dom/events/EventStateManager.h @@ -303,13 +303,14 @@ protected: * if it goes away during the event). */ nsIFrame* DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent, - uint32_t aMessage, + EventMessage aMessage, nsIContent* aTargetContent, nsIContent* aRelatedContent); /** * Synthesize DOM pointerover and pointerout events */ - void GeneratePointerEnterExit(uint32_t aMessage, WidgetMouseEvent* aEvent); + void GeneratePointerEnterExit(EventMessage aMessage, + WidgetMouseEvent* aEvent); /** * Synthesize DOM and frame mouseover and mouseout events from this * MOUSE_MOVE or MOUSE_EXIT event. @@ -351,7 +352,7 @@ protected: */ void FireDragEnterOrExit(nsPresContext* aPresContext, WidgetDragEvent* aDragEvent, - uint32_t aMsg, + EventMessage aMessage, nsIContent* aRelatedTarget, nsIContent* aTargetContent, nsWeakFrame& aTargetFrame); @@ -363,7 +364,7 @@ protected: static nsresult InitAndDispatchClickEvent(WidgetMouseEvent* aEvent, nsEventStatus* aStatus, - uint32_t aType, + EventMessage aMessage, nsIPresShell* aPresShell, nsIContent* aMouseTarget, nsWeakFrame aCurrentTarget, diff --git a/dom/events/IMEStateManager.cpp b/dom/events/IMEStateManager.cpp index 3c39268913..253da56a8e 100644 --- a/dom/events/IMEStateManager.cpp +++ b/dom/events/IMEStateManager.cpp @@ -134,7 +134,7 @@ GetIMEStateSetOpenName(IMEState::Open aOpen) } static const char* -GetEventMessageName(uint32_t aMessage) +GetEventMessageName(EventMessage aMessage) { switch (aMessage) { case NS_COMPOSITION_START: diff --git a/dom/events/InputEvent.cpp b/dom/events/InputEvent.cpp index f7070435a3..af1e88aa34 100644 --- a/dom/events/InputEvent.cpp +++ b/dom/events/InputEvent.cpp @@ -15,7 +15,9 @@ InputEvent::InputEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalEditorInputEvent* aEvent) : UIEvent(aOwner, aPresContext, - aEvent ? aEvent : new InternalEditorInputEvent(false, 0, nullptr)) + aEvent ? aEvent : + new InternalEditorInputEvent(false, NS_EVENT_NULL, + nullptr)) { NS_ASSERTION(mEvent->mClass == eEditorInputEventClass, "event type mismatch"); diff --git a/dom/events/InternalMutationEvent.h b/dom/events/InternalMutationEvent.h index 75639bc2ab..d600ebe0ee 100644 --- a/dom/events/InternalMutationEvent.h +++ b/dom/events/InternalMutationEvent.h @@ -19,7 +19,7 @@ class InternalMutationEvent : public WidgetEvent public: virtual InternalMutationEvent* AsMutationEvent() override { return this; } - InternalMutationEvent(bool aIsTrusted, uint32_t aMessage) + InternalMutationEvent(bool aIsTrusted, EventMessage aMessage) : WidgetEvent(aIsTrusted, aMessage, eMutationEventClass) , mAttrChange(0) { diff --git a/dom/events/KeyboardEvent.cpp b/dom/events/KeyboardEvent.cpp index e2086abd89..761637cdff 100644 --- a/dom/events/KeyboardEvent.cpp +++ b/dom/events/KeyboardEvent.cpp @@ -15,7 +15,8 @@ KeyboardEvent::KeyboardEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetKeyboardEvent* aEvent) : UIEvent(aOwner, aPresContext, - aEvent ? aEvent : new WidgetKeyboardEvent(false, 0, nullptr)) + aEvent ? aEvent : + new WidgetKeyboardEvent(false, NS_EVENT_NULL, nullptr)) , mInitializedByCtor(false) , mInitializedWhichValue(0) { @@ -161,6 +162,8 @@ KeyboardEvent::CharCode() return 0; case NS_KEY_PRESS: return mEvent->AsKeyboardEvent()->charCode; + default: + break; } return 0; } @@ -213,6 +216,8 @@ KeyboardEvent::Which() } return CharCode(); } + default: + break; } return 0; diff --git a/dom/events/MouseEvent.cpp b/dom/events/MouseEvent.cpp index 7b8455789d..a4f09cfcc9 100644 --- a/dom/events/MouseEvent.cpp +++ b/dom/events/MouseEvent.cpp @@ -17,8 +17,9 @@ MouseEvent::MouseEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetMouseEventBase* aEvent) : UIEvent(aOwner, aPresContext, - aEvent ? aEvent : new WidgetMouseEvent(false, 0, nullptr, - WidgetMouseEvent::eReal)) + aEvent ? aEvent : + new WidgetMouseEvent(false, NS_EVENT_NULL, nullptr, + WidgetMouseEvent::eReal)) { // There's no way to make this class' ctor allocate an WidgetMouseScrollEvent. // It's not that important, though, since a scroll event is not a real diff --git a/dom/events/MouseScrollEvent.cpp b/dom/events/MouseScrollEvent.cpp index 4569137572..ea443e2465 100644 --- a/dom/events/MouseScrollEvent.cpp +++ b/dom/events/MouseScrollEvent.cpp @@ -15,7 +15,9 @@ MouseScrollEvent::MouseScrollEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetMouseScrollEvent* aEvent) : MouseEvent(aOwner, aPresContext, - aEvent ? aEvent : new WidgetMouseScrollEvent(false, 0, nullptr)) + aEvent ? aEvent : + new WidgetMouseScrollEvent(false, NS_EVENT_NULL, + nullptr)) { if (aEvent) { mEventIsInternal = false; diff --git a/dom/events/MutationEvent.cpp b/dom/events/MutationEvent.cpp index 189240a4be..f36daca8f7 100644 --- a/dom/events/MutationEvent.cpp +++ b/dom/events/MutationEvent.cpp @@ -17,7 +17,7 @@ MutationEvent::MutationEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalMutationEvent* aEvent) : Event(aOwner, aPresContext, - aEvent ? aEvent : new InternalMutationEvent(false, 0)) + aEvent ? aEvent : new InternalMutationEvent(false, NS_EVENT_NULL)) { mEventIsInternal = (aEvent == nullptr); } diff --git a/dom/events/NotifyPaintEvent.cpp b/dom/events/NotifyPaintEvent.cpp index 6c5825c058..8b96688ef3 100644 --- a/dom/events/NotifyPaintEvent.cpp +++ b/dom/events/NotifyPaintEvent.cpp @@ -18,12 +18,12 @@ namespace dom { NotifyPaintEvent::NotifyPaintEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent, - uint32_t aEventType, + EventMessage aEventMessage, nsInvalidateRequestList* aInvalidateRequests) : Event(aOwner, aPresContext, aEvent) { if (mEvent) { - mEvent->mMessage = aEventType; + mEvent->mMessage = aEventMessage; } if (aInvalidateRequests) { mInvalidateRequests.MoveElementsFrom(aInvalidateRequests->mRequests); @@ -166,11 +166,11 @@ already_AddRefed NS_NewDOMNotifyPaintEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent, - uint32_t aEventType, + EventMessage aEventMessage, nsInvalidateRequestList* aInvalidateRequests) { nsRefPtr it = - new NotifyPaintEvent(aOwner, aPresContext, aEvent, aEventType, + new NotifyPaintEvent(aOwner, aPresContext, aEvent, aEventMessage, aInvalidateRequests); return it.forget(); } diff --git a/dom/events/NotifyPaintEvent.h b/dom/events/NotifyPaintEvent.h index b0e09bb6f1..1a45736766 100644 --- a/dom/events/NotifyPaintEvent.h +++ b/dom/events/NotifyPaintEvent.h @@ -28,7 +28,7 @@ public: NotifyPaintEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent, - uint32_t aEventType, + EventMessage aEventMessage, nsInvalidateRequestList* aInvalidateRequests); NS_DECL_ISUPPORTS_INHERITED @@ -72,7 +72,9 @@ already_AddRefed NS_NewDOMNotifyPaintEvent(mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext, mozilla::WidgetEvent* aEvent, - uint32_t aEventType = 0, - nsInvalidateRequestList* aInvalidateRequests = nullptr); + mozilla::EventMessage aEventMessage = + mozilla::NS_EVENT_NULL, + nsInvalidateRequestList* aInvalidateRequests = + nullptr); #endif // mozilla_dom_NotifyPaintEvent_h_ diff --git a/dom/events/PointerEvent.cpp b/dom/events/PointerEvent.cpp index c78c4ec44f..676a814c8f 100644 --- a/dom/events/PointerEvent.cpp +++ b/dom/events/PointerEvent.cpp @@ -17,7 +17,8 @@ PointerEvent::PointerEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetPointerEvent* aEvent) : MouseEvent(aOwner, aPresContext, - aEvent ? aEvent : new WidgetPointerEvent(false, 0, nullptr)) + aEvent ? aEvent : + new WidgetPointerEvent(false, NS_EVENT_NULL, nullptr)) { NS_ASSERTION(mEvent->mClass == ePointerEventClass, "event type mismatch ePointerEventClass"); diff --git a/dom/events/SimpleGestureEvent.cpp b/dom/events/SimpleGestureEvent.cpp index 9daf8a0892..5eb3b863f1 100644 --- a/dom/events/SimpleGestureEvent.cpp +++ b/dom/events/SimpleGestureEvent.cpp @@ -16,7 +16,8 @@ SimpleGestureEvent::SimpleGestureEvent(EventTarget* aOwner, WidgetSimpleGestureEvent* aEvent) : MouseEvent(aOwner, aPresContext, aEvent ? aEvent : - new WidgetSimpleGestureEvent(false, 0, nullptr)) + new WidgetSimpleGestureEvent(false, NS_EVENT_NULL, + nullptr)) { NS_ASSERTION(mEvent->mClass == eSimpleGestureEventClass, "event type mismatch"); diff --git a/dom/events/TextComposition.cpp b/dom/events/TextComposition.cpp index 3ec0d06bb4..95ea4139f1 100644 --- a/dom/events/TextComposition.cpp +++ b/dom/events/TextComposition.cpp @@ -100,7 +100,7 @@ TextComposition::MaybeDispatchCompositionUpdate( BaseEventFlags TextComposition::CloneAndDispatchAs( const WidgetCompositionEvent* aCompositionEvent, - uint32_t aMessage, + EventMessage aMessage, nsEventStatus* aStatus, EventDispatchingCallback* aCallBack) { @@ -437,7 +437,7 @@ TextComposition::NotityUpdateComposition( } void -TextComposition::DispatchCompositionEventRunnable(uint32_t aEventMessage, +TextComposition::DispatchCompositionEventRunnable(EventMessage aEventMessage, const nsAString& aData, bool aIsSynthesizingCommit) { @@ -585,13 +585,13 @@ TextComposition::HasEditor() const TextComposition::CompositionEventDispatcher::CompositionEventDispatcher( TextComposition* aComposition, nsINode* aEventTarget, - uint32_t aEventMessage, + EventMessage aEventMessage, const nsAString& aData, bool aIsSynthesizedEvent) : mTextComposition(aComposition) , mEventTarget(aEventTarget) - , mEventMessage(aEventMessage) , mData(aData) + , mEventMessage(aEventMessage) , mIsSynthesizedEvent(aIsSynthesizedEvent) { } diff --git a/dom/events/TextComposition.h b/dom/events/TextComposition.h index 2dbf4aff98..1038629d21 100644 --- a/dom/events/TextComposition.h +++ b/dom/events/TextComposition.h @@ -319,7 +319,7 @@ private: */ BaseEventFlags CloneAndDispatchAs( const WidgetCompositionEvent* aCompositionEvent, - uint32_t aMessage, + EventMessage aMessage, nsEventStatus* aStatus = nullptr, EventDispatchingCallback* aCallBack = nullptr); @@ -353,7 +353,7 @@ private: public: CompositionEventDispatcher(TextComposition* aTextComposition, nsINode* aEventTarget, - uint32_t aEventMessage, + EventMessage aEventMessage, const nsAString& aData, bool aIsSynthesizedEvent = false); NS_IMETHOD Run() override; @@ -361,8 +361,8 @@ private: private: nsRefPtr mTextComposition; nsCOMPtr mEventTarget; - uint32_t mEventMessage; nsString mData; + EventMessage mEventMessage; bool mIsSynthesizedEvent; CompositionEventDispatcher() {}; @@ -381,7 +381,7 @@ private: * commit or cancel composition. Otherwise, * false. */ - void DispatchCompositionEventRunnable(uint32_t aEventMessage, + void DispatchCompositionEventRunnable(EventMessage aEventMessage, const nsAString& aData, bool aIsSynthesizingCommit = false); }; diff --git a/dom/events/TouchEvent.cpp b/dom/events/TouchEvent.cpp index 59da7b6e0e..d9ed30764b 100644 --- a/dom/events/TouchEvent.cpp +++ b/dom/events/TouchEvent.cpp @@ -63,7 +63,8 @@ TouchEvent::TouchEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetTouchEvent* aEvent) : UIEvent(aOwner, aPresContext, - aEvent ? aEvent : new WidgetTouchEvent(false, 0, nullptr)) + aEvent ? aEvent : + new WidgetTouchEvent(false, NS_EVENT_NULL, nullptr)) { if (aEvent) { mEventIsInternal = false; diff --git a/dom/events/TransitionEvent.cpp b/dom/events/TransitionEvent.cpp index 96231028f9..73dcace645 100644 --- a/dom/events/TransitionEvent.cpp +++ b/dom/events/TransitionEvent.cpp @@ -15,7 +15,7 @@ TransitionEvent::TransitionEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalTransitionEvent* aEvent) : Event(aOwner, aPresContext, - aEvent ? aEvent : new InternalTransitionEvent(false, 0)) + aEvent ? aEvent : new InternalTransitionEvent(false, NS_EVENT_NULL)) { if (aEvent) { mEventIsInternal = false; diff --git a/dom/events/UIEvent.cpp b/dom/events/UIEvent.cpp index 6e55d20068..c3afaea222 100644 --- a/dom/events/UIEvent.cpp +++ b/dom/events/UIEvent.cpp @@ -29,7 +29,7 @@ UIEvent::UIEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetGUIEvent* aEvent) : Event(aOwner, aPresContext, - aEvent ? aEvent : new InternalUIEvent(false, 0)) + aEvent ? aEvent : new InternalUIEvent(false, NS_EVENT_NULL, nullptr)) , mClientPoint(0, 0) , mLayerPoint(0, 0) , mPagePoint(0, 0) diff --git a/dom/events/WheelEvent.cpp b/dom/events/WheelEvent.cpp index 23b7559631..14b1b6402c 100644 --- a/dom/events/WheelEvent.cpp +++ b/dom/events/WheelEvent.cpp @@ -16,7 +16,8 @@ WheelEvent::WheelEvent(EventTarget* aOwner, WidgetWheelEvent* aWheelEvent) : MouseEvent(aOwner, aPresContext, aWheelEvent ? aWheelEvent : - new WidgetWheelEvent(false, 0, nullptr)) + new WidgetWheelEvent(false, NS_EVENT_NULL, + nullptr)) , mAppUnitsPerDevPixel(0) { if (aWheelEvent) { diff --git a/dom/events/WheelHandlingHelper.cpp b/dom/events/WheelHandlingHelper.cpp index 7012ff12a0..2213336df9 100644 --- a/dom/events/WheelHandlingHelper.cpp +++ b/dom/events/WheelHandlingHelper.cpp @@ -218,6 +218,8 @@ WheelTransaction::OnEvent(WidgetEvent* aEvent) case NS_DRAGDROP_DROP: EndTransaction(); return; + default: + break; } } diff --git a/dom/events/XULCommandEvent.cpp b/dom/events/XULCommandEvent.cpp index d56cd1e19e..68263a4aa1 100644 --- a/dom/events/XULCommandEvent.cpp +++ b/dom/events/XULCommandEvent.cpp @@ -14,7 +14,8 @@ XULCommandEvent::XULCommandEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetInputEvent* aEvent) : UIEvent(aOwner, aPresContext, - aEvent ? aEvent : new WidgetInputEvent(false, 0, nullptr)) + aEvent ? aEvent : + new WidgetInputEvent(false, NS_EVENT_NULL, nullptr)) { if (aEvent) { mEventIsInternal = false; diff --git a/dom/events/test/mochitest.ini b/dom/events/test/mochitest.ini index c4738d144e..6aa87e4fb8 100644 --- a/dom/events/test/mochitest.ini +++ b/dom/events/test/mochitest.ini @@ -191,3 +191,4 @@ support-files = [test_offsetxy.html] [test_eventhandler_scoping.html] [test_bug1298970.html] +[test_dom_activate_event.html] diff --git a/dom/events/test/test_dom_activate_event.html b/dom/events/test/test_dom_activate_event.html new file mode 100644 index 0000000000..22e32d9880 --- /dev/null +++ b/dom/events/test/test_dom_activate_event.html @@ -0,0 +1,89 @@ + + + + Test DOMActivate event + + + + + +

+link + + + + + + +

+ +
+
+
+ + diff --git a/dom/html/HTMLButtonElement.cpp b/dom/html/HTMLButtonElement.cpp index e229a3e2db..f563e1cf5b 100644 --- a/dom/html/HTMLButtonElement.cpp +++ b/dom/html/HTMLButtonElement.cpp @@ -205,7 +205,7 @@ HTMLButtonElement::ParseAttribute(int32_t aNamespaceID, } bool -HTMLButtonElement::IsDisabledForEvents(uint32_t aMessage) +HTMLButtonElement::IsDisabledForEvents(EventMessage aMessage) { nsIFormControlFrame* formControlFrame = GetFormControlFrame(false); nsIFrame* formFrame = do_QueryFrame(formControlFrame); @@ -255,10 +255,9 @@ HTMLButtonElement::PostHandleEvent(EventChainPostVisitor& aVisitor) if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault) { WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent(); if (mouseEvent && mouseEvent->IsLeftClickEvent()) { - // XXX Activating actually occurs even if it's caused by untrusted event. - // Therefore, shouldn't this be always trusted event? - InternalUIEvent actEvent(aVisitor.mEvent->mFlags.mIsTrusted, - NS_UI_ACTIVATE); + // DOMActive event should be trusted since the activation is actually + // occurred even if the cause is an untrusted click event. + InternalUIEvent actEvent(true, NS_UI_ACTIVATE, mouseEvent); actEvent.detail = 1; nsCOMPtr shell = aVisitor.mPresContext->GetPresShell(); diff --git a/dom/html/HTMLButtonElement.h b/dom/html/HTMLButtonElement.h index 8a48beaa11..b0fed57fca 100644 --- a/dom/html/HTMLButtonElement.h +++ b/dom/html/HTMLButtonElement.h @@ -52,7 +52,7 @@ public: NS_IMETHOD SubmitNamesValues(nsFormSubmission* aFormSubmission) override; NS_IMETHOD SaveState() override; bool RestoreState(nsPresState* aState) override; - virtual bool IsDisabledForEvents(uint32_t aMessage) override; + virtual bool IsDisabledForEvents(EventMessage aMessage) override; virtual void FieldSetDisabledChanged(bool aNotify) override; diff --git a/dom/html/HTMLFieldSetElement.cpp b/dom/html/HTMLFieldSetElement.cpp index ae0e3bf5f7..41462b73a8 100644 --- a/dom/html/HTMLFieldSetElement.cpp +++ b/dom/html/HTMLFieldSetElement.cpp @@ -63,7 +63,7 @@ NS_IMPL_STRING_ATTR(HTMLFieldSetElement, Name, name) NS_IMPL_NSICONSTRAINTVALIDATION(HTMLFieldSetElement) bool -HTMLFieldSetElement::IsDisabledForEvents(uint32_t aMessage) +HTMLFieldSetElement::IsDisabledForEvents(EventMessage aMessage) { return IsElementDisabledForEvents(aMessage, nullptr); } diff --git a/dom/html/HTMLFieldSetElement.h b/dom/html/HTMLFieldSetElement.h index ff2c33abe7..78896205a6 100644 --- a/dom/html/HTMLFieldSetElement.h +++ b/dom/html/HTMLFieldSetElement.h @@ -51,7 +51,7 @@ public: NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_FIELDSET; } NS_IMETHOD Reset() override; NS_IMETHOD SubmitNamesValues(nsFormSubmission* aFormSubmission) override; - virtual bool IsDisabledForEvents(uint32_t aMessage) override; + virtual bool IsDisabledForEvents(EventMessage aMessage) override; virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override; const nsIContent* GetFirstLegend() const { return mFirstLegend; } diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index 9c8e1c302a..3fce0b989e 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -548,7 +548,7 @@ nsresult HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor) { if (aVisitor.mEvent->originalTarget == static_cast(this)) { - uint32_t msg = aVisitor.mEvent->mMessage; + EventMessage msg = aVisitor.mEvent->mMessage; if (msg == NS_FORM_SUBMIT) { // let the form know not to defer subsequent submissions mDeferSubmission = false; @@ -568,8 +568,10 @@ HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor) mPendingSubmission = nullptr; } DoSubmitOrReset(aVisitor.mEvent, msg); + break; } - break; + default: + break; } } else { if (msg == NS_FORM_SUBMIT) { diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 59e06137bc..f1b628e59a 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -3033,7 +3033,7 @@ HTMLInputElement::NeedToInitializeEditorForEvent( } bool -HTMLInputElement::IsDisabledForEvents(uint32_t aMessage) +HTMLInputElement::IsDisabledForEvents(EventMessage aMessage) { return IsElementDisabledForEvents(aMessage, GetPrimaryFrame()); } @@ -3618,10 +3618,9 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent(); if (mouseEvent && mouseEvent->IsLeftClickEvent() && !ShouldPreventDOMActivateDispatch(aVisitor.mEvent->originalTarget)) { - // XXX Activating actually occurs even if it's caused by untrusted event. - // Therefore, shouldn't this be always trusted event? - InternalUIEvent actEvent(aVisitor.mEvent->mFlags.mIsTrusted, - NS_UI_ACTIVATE); + // DOMActive event should be trusted since the activation is actually + // occurred even if the cause is an untrusted click event. + InternalUIEvent actEvent(true, NS_UI_ACTIVATE, mouseEvent); actEvent.detail = 1; nsCOMPtr shell = aVisitor.mPresContext->GetPresShell(); @@ -3652,6 +3651,8 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) mForm->OnSubmitClickEnd(); } break; + default: + break; } } @@ -4133,6 +4134,9 @@ HTMLInputElement::PostHandleEventForRangeThumb(EventChainPostVisitor& aVisitor) CancelRangeThumbDrag(); } break; + + default: + break; } } diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 698ca118a2..fc44540ea6 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -140,7 +140,7 @@ public: NS_IMETHOD SaveState() override; virtual bool RestoreState(nsPresState* aState) override; virtual bool AllowDrop() override; - virtual bool IsDisabledForEvents(uint32_t aMessage) override; + virtual bool IsDisabledForEvents(EventMessage aMessage) override; virtual void FieldSetDisabledChanged(bool aNotify) override; diff --git a/dom/html/HTMLLabelElement.cpp b/dom/html/HTMLLabelElement.cpp index 25c4df795a..02082b783d 100644 --- a/dom/html/HTMLLabelElement.cpp +++ b/dom/html/HTMLLabelElement.cpp @@ -191,6 +191,9 @@ HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor) mouseEvent->mFlags.mMultipleActionsPrevented = true; } break; + + default: + break; } mHandlingEvent = false; } diff --git a/dom/html/HTMLObjectElement.cpp b/dom/html/HTMLObjectElement.cpp index 5bf4445f53..31647430dc 100644 --- a/dom/html/HTMLObjectElement.cpp +++ b/dom/html/HTMLObjectElement.cpp @@ -219,6 +219,8 @@ HTMLObjectElement::HandleFocusBlurPlugin(Element* aElement, OnFocusBlurPlugin(aElement, false); break; } + default: + break; } } diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp index 978bccb89a..1f8cc1a81e 100644 --- a/dom/html/HTMLSelectElement.cpp +++ b/dom/html/HTMLSelectElement.cpp @@ -1496,7 +1496,7 @@ HTMLSelectElement::GetAttributeMappingFunction() const } bool -HTMLSelectElement::IsDisabledForEvents(uint32_t aMessage) +HTMLSelectElement::IsDisabledForEvents(EventMessage aMessage) { nsIFormControlFrame* formControlFrame = GetFormControlFrame(false); nsIFrame* formFrame = nullptr; diff --git a/dom/html/HTMLSelectElement.h b/dom/html/HTMLSelectElement.h index 06d1a5d51c..f06c30ea5c 100644 --- a/dom/html/HTMLSelectElement.h +++ b/dom/html/HTMLSelectElement.h @@ -291,7 +291,7 @@ public: NS_IMETHOD SubmitNamesValues(nsFormSubmission* aFormSubmission) override; NS_IMETHOD SaveState() override; virtual bool RestoreState(nsPresState* aState) override; - virtual bool IsDisabledForEvents(uint32_t aMessage) override; + virtual bool IsDisabledForEvents(EventMessage aMessage) override; virtual void FieldSetDisabledChanged(bool aNotify) override; diff --git a/dom/html/HTMLTextAreaElement.cpp b/dom/html/HTMLTextAreaElement.cpp index fe075c51b9..f2d8cb0af9 100644 --- a/dom/html/HTMLTextAreaElement.cpp +++ b/dom/html/HTMLTextAreaElement.cpp @@ -467,7 +467,7 @@ HTMLTextAreaElement::GetAttributeMappingFunction() const } bool -HTMLTextAreaElement::IsDisabledForEvents(uint32_t aMessage) +HTMLTextAreaElement::IsDisabledForEvents(EventMessage aMessage) { nsIFormControlFrame* formControlFrame = GetFormControlFrame(false); nsIFrame* formFrame = do_QueryFrame(formControlFrame); diff --git a/dom/html/HTMLTextAreaElement.h b/dom/html/HTMLTextAreaElement.h index 969a66fd44..343fba93b6 100644 --- a/dom/html/HTMLTextAreaElement.h +++ b/dom/html/HTMLTextAreaElement.h @@ -75,7 +75,7 @@ public: NS_IMETHOD SubmitNamesValues(nsFormSubmission* aFormSubmission) override; NS_IMETHOD SaveState() override; virtual bool RestoreState(nsPresState* aState) override; - virtual bool IsDisabledForEvents(uint32_t aMessage) override; + virtual bool IsDisabledForEvents(EventMessage aMessage) override; virtual void FieldSetDisabledChanged(bool aNotify) override; diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 506ba6081d..e8983e91e0 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -2270,6 +2270,8 @@ nsGenericHTMLFormElement::PreHandleEvent(EventChainPreVisitor& aVisitor) formControlFrame->SetFocus(false, false); break; } + default: + break; } } @@ -2443,8 +2445,8 @@ nsGenericHTMLFormElement::FormIdUpdated(Element* aOldElement, } bool -nsGenericHTMLFormElement::IsElementDisabledForEvents(uint32_t aMessage, - nsIFrame* aFrame) +nsGenericHTMLFormElement::IsElementDisabledForEvents(EventMessage aMessage, + nsIFrame* aFrame) { switch (aMessage) { case NS_MOUSE_MOVE: diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 6d620b6af3..f92552ffb3 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -7,6 +7,7 @@ #define nsGenericHTMLElement_h___ #include "mozilla/Attributes.h" +#include "mozilla/EventForwards.h" #include "nsMappedAttributeElement.h" #include "nsIDOMHTMLElement.h" #include "nsNameSpaceManager.h" // for kNameSpaceID_None @@ -1422,7 +1423,8 @@ protected: void* aData); // Returns true if the event should not be handled from PreHandleEvent - bool IsElementDisabledForEvents(uint32_t aMessage, nsIFrame* aFrame); + bool IsElementDisabledForEvents(mozilla::EventMessage aMessage, + nsIFrame* aFrame); // The focusability state of this form control. eUnfocusable means that it // shouldn't be focused at all, eInactiveWindow means it's in an inactive diff --git a/dom/html/nsIFormControl.h b/dom/html/nsIFormControl.h index 7696563109..f64e193b05 100644 --- a/dom/html/nsIFormControl.h +++ b/dom/html/nsIFormControl.h @@ -6,7 +6,9 @@ #ifndef nsIFormControl_h___ #define nsIFormControl_h___ +#include "mozilla/EventForwards.h" #include "nsISupports.h" + class nsIDOMHTMLFormElement; class nsPresState; class nsFormSubmission; @@ -202,7 +204,7 @@ public: */ inline bool AllowDraggableChildren() const; - virtual bool IsDisabledForEvents(uint32_t aMessage) + virtual bool IsDisabledForEvents(mozilla::EventMessage aMessage) { return false; } diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 1b12f8a8f8..aace282e18 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -1091,8 +1091,6 @@ interface nsIDOMWindowUtils : nsISupports { in long aY, [optional] in unsigned long aAdditionalFlags); - // NOTE: following values are same as NS_QUERY_* in BasicEvents.h - /** * QUERY_SELECTED_TEXT queries the first selection range's information. * diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 9c0a939ccc..f66972fab2 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -64,6 +64,7 @@ using mozilla::layers::TouchBehaviorFlags from "mozilla/layers/APZUtils.h"; using nsIWidget::TouchPointerState from "nsIWidget.h"; using struct LookAndFeelInt from "mozilla/widget/WidgetMessageUtils.h"; using struct mozilla::OwningSerializedStructuredCloneBuffer from "ipc/IPCMessageUtils.h"; +using mozilla::EventMessage from "mozilla/EventForwards.h"; using nsEventStatus from "mozilla/EventForwards.h"; namespace mozilla { @@ -259,7 +260,7 @@ parent: * * message The message value of the handled event. */ - prio(urgent) async OnEventNeedingAckHandled(uint32_t message); + prio(urgent) async OnEventNeedingAckHandled(EventMessage message); /** * Tells chrome to start plugin IME. If this results in a string getting diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index 152654f10c..538f65906d 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -2120,7 +2120,7 @@ TabParent::RecvNotifyIMEPositionChange(const ContentCache& aContentCache, } bool -TabParent::RecvOnEventNeedingAckHandled(const uint32_t& aMessage) +TabParent::RecvOnEventNeedingAckHandled(const EventMessage& aMessage) { // This is called when the child process receives WidgetCompositionEvent or // WidgetSelectionEvent. @@ -2871,8 +2871,8 @@ TabParent::InjectTouchEvent(const nsAString& aType, uint32_t aCount, int32_t aModifiers) { - uint32_t msg; - nsContentUtils::GetEventIdAndAtom(aType, eTouchEventClass, &msg); + EventMessage msg; + nsContentUtils::GetEventMessageAndAtom(aType, eTouchEventClass, &msg); if (msg != NS_TOUCH_START && msg != NS_TOUCH_MOVE && msg != NS_TOUCH_END && msg != NS_TOUCH_CANCEL) { return NS_ERROR_FAILURE; diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index 0e3b052a3c..1114edad78 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -177,7 +177,7 @@ public: bool* aConsumedByIME) override; virtual bool RecvNotifyIMEPositionChange(const ContentCache& aContentCache, const widget::IMENotification& aEventMessage) override; - virtual bool RecvOnEventNeedingAckHandled(const uint32_t& aMessage) override; + virtual bool RecvOnEventNeedingAckHandled(const EventMessage& aMessage) override; virtual bool RecvEndIMEComposition(const bool& aCancel, bool* aNoCompositionEvent, nsString* aComposition) override; diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index 26117cc390..7d6f94ba2f 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -2045,6 +2045,8 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) pluginEvent.lParam = 0; pPluginEvent = &pluginEvent; break; + default: + break; } } @@ -2079,6 +2081,8 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) case NS_MOUSE_DOUBLECLICK: // Button up/down events sent instead. return rv; + default: + break; } // Get reference point relative to plugin origin. @@ -2171,6 +2175,8 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) event.same_screen = True; } break; + default: + break; } } break; @@ -2202,6 +2208,8 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) case NS_KEY_UP: event.type = KeyRelease; break; + default: + break; } #endif @@ -2225,8 +2233,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) break; default: - switch (anEvent.mMessage) - { + switch (anEvent.mMessage) { case NS_FOCUS_CONTENT: case NS_BLUR_CONTENT: { @@ -2238,7 +2245,9 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) event.detail = NotifyDetailNone; } break; - } + default: + break; + } } if (!pluginEvent.type) { @@ -2279,6 +2288,8 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) case NS_MOUSE_DOUBLECLICK: // Button up/down events sent instead. return rv; + default: + break; } // Get reference point relative to plugin origin. @@ -2320,6 +2331,8 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) mInstance->HandleEvent(&event, nullptr, NS_PLUGIN_CALL_SAFE_TO_REENTER_GECKO); } break; + default: + break; } } break; diff --git a/dom/smil/TimeEvent.cpp b/dom/smil/TimeEvent.cpp index 40a60aa882..8c180fb04f 100644 --- a/dom/smil/TimeEvent.cpp +++ b/dom/smil/TimeEvent.cpp @@ -17,7 +17,7 @@ TimeEvent::TimeEvent(EventTarget* aOwner, nsPresContext* aPresContext, InternalSMILTimeEvent* aEvent) : Event(aOwner, aPresContext, - aEvent ? aEvent : new InternalSMILTimeEvent(false, 0)) + aEvent ? aEvent : new InternalSMILTimeEvent(false, NS_EVENT_NULL)) , mDetail(mEvent->AsSMILTimeEvent()->detail) { if (aEvent) { diff --git a/dom/smil/nsSMILTimedElement.cpp b/dom/smil/nsSMILTimedElement.cpp index 4804830cc8..2858c21e08 100644 --- a/dom/smil/nsSMILTimedElement.cpp +++ b/dom/smil/nsSMILTimedElement.cpp @@ -82,12 +82,15 @@ namespace { protected: nsRefPtr mTarget; - uint32_t mMsg; + EventMessage mMsg; int32_t mDetail; public: - AsyncTimeEventRunner(nsIContent* aTarget, uint32_t aMsg, int32_t aDetail) - : mTarget(aTarget), mMsg(aMsg), mDetail(aDetail) + AsyncTimeEventRunner(nsIContent* aTarget, EventMessage aMsg, + int32_t aDetail) + : mTarget(aTarget) + , mMsg(aMsg) + , mDetail(aDetail) { } @@ -2365,7 +2368,7 @@ nsSMILTimedElement::NotifyChangedInterval(nsSMILInterval* aInterval, } void -nsSMILTimedElement::FireTimeEventAsync(uint32_t aMsg, int32_t aDetail) +nsSMILTimedElement::FireTimeEventAsync(EventMessage aMsg, int32_t aDetail) { if (!mAnimationElement) return; diff --git a/dom/smil/nsSMILTimedElement.h b/dom/smil/nsSMILTimedElement.h index c594d91c02..c07f2e008f 100644 --- a/dom/smil/nsSMILTimedElement.h +++ b/dom/smil/nsSMILTimedElement.h @@ -7,6 +7,7 @@ #ifndef NS_SMILTIMEDELEMENT_H_ #define NS_SMILTIMEDELEMENT_H_ +#include "mozilla/EventForwards.h" #include "mozilla/Move.h" #include "nsSMILInterval.h" #include "nsSMILInstanceTime.h" @@ -539,7 +540,8 @@ protected: bool aBeginObjectChanged, bool aEndObjectChanged); - void FireTimeEventAsync(uint32_t aMsg, int32_t aDetail); + void FireTimeEventAsync(mozilla::EventMessage aMsg, + int32_t aDetail); const nsSMILInstanceTime* GetEffectiveBeginInstance() const; const nsSMILInterval* GetPreviousInterval() const; bool HasPlayed() const { return !mOldIntervals.IsEmpty(); } diff --git a/editor/libeditor/IMETextTxn.cpp b/editor/libeditor/IMETextTxn.cpp index b2ba85bde6..e105f83883 100644 --- a/editor/libeditor/IMETextTxn.cpp +++ b/editor/libeditor/IMETextTxn.cpp @@ -223,7 +223,12 @@ IMETextTxn::SetIMESelection(nsEditor& aEditor, static_cast(caretOffset) <= maxOffset); rv = selection->Collapse(aTextNode, caretOffset); setCaret = setCaret || NS_SUCCEEDED(rv); - NS_ASSERTION(setCaret, "Failed to collapse normal selection"); + if (NS_WARN_IF(!setCaret)) { + continue; + } + // If caret range is specified explicitly, we should show the caret if + // it should be so. + aEditor.HideCaret(false); continue; } @@ -292,6 +297,8 @@ IMETextTxn::SetIMESelection(nsEditor& aEditor, rv = selection->Collapse(aTextNode, caretOffset); NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set caret at the end of composition string"); + // If caret range isn't specified explicitly, we should hide the caret. + aEditor.HideCaret(true); } rv = selection->EndBatchChanges(); diff --git a/editor/libeditor/nsEditor.cpp b/editor/libeditor/nsEditor.cpp index d62eef60ec..d3c6c3a744 100644 --- a/editor/libeditor/nsEditor.cpp +++ b/editor/libeditor/nsEditor.cpp @@ -147,6 +147,7 @@ nsEditor::nsEditor() , mDidPostCreate(false) , mDispatchInputEvent(true) , mIsInEditAction(false) +, mHidingCaret(false) { } @@ -158,6 +159,8 @@ nsEditor::~nsEditor() mComposition->OnEditorDestroyed(); mComposition = nullptr; } + // If this editor is still hiding the caret, we need to restore it. + HideCaret(false); mTxnMgr = nullptr; delete mPhonetic; @@ -471,6 +474,8 @@ nsEditor::PreDestroy(bool aDestroyingFrames) // Unregister event listeners RemoveEventListeners(); + // If this editor is still hiding the caret, we need to restore it. + HideCaret(false); mActionListeners.Clear(); mEditorObservers.Clear(); mDocStateListeners.Clear(); @@ -2071,6 +2076,10 @@ nsEditor::EndIMEComposition() } } + // Composition string may have hidden the caret. Therefore, we need to + // cancel it here. + HideCaret(false); + /* reset the data we need to construct a transaction */ mIMETextNode = nullptr; mIMETextOffset = 0; @@ -5225,3 +5234,23 @@ nsEditor::GetIMESelectionStartOffsetIn(nsINode* aTextNode) } return minOffset < INT32_MAX ? minOffset : -1; } + +void +nsEditor::HideCaret(bool aHide) +{ + if (mHidingCaret == aHide) { + return; + } + + nsCOMPtr presShell = GetPresShell(); + NS_ENSURE_TRUE_VOID(presShell); + nsRefPtr caret = presShell->GetCaret(); + NS_ENSURE_TRUE_VOID(caret); + + mHidingCaret = aHide; + if (aHide) { + caret->AddForceHide(); + } else { + caret->RemoveForceHide(); + } +} diff --git a/editor/libeditor/nsEditor.h b/editor/libeditor/nsEditor.h index c1adb9cbe5..d999f9d066 100644 --- a/editor/libeditor/nsEditor.h +++ b/editor/libeditor/nsEditor.h @@ -824,6 +824,13 @@ public: void FindBetterInsertionPoint(nsCOMPtr& aNode, int32_t& aOffset); + /** + * HideCaret() hides caret with nsCaret::AddForceHide() or may show carent + * with nsCaret::RemoveForceHide(). This does NOT set visibility of + * nsCaret. Therefore, this is stateless. + */ + void HideCaret(bool aHide); + protected: enum Tristate { eTriUnset, @@ -883,6 +890,7 @@ protected: bool mDidPostCreate; // whether PostCreate has been called bool mDispatchInputEvent; bool mIsInEditAction; // true while the instance is handling an edit action + bool mHidingCaret; // whether caret is hidden forcibly. friend bool NSCanUnload(nsISupports* serviceMgr); friend class nsAutoTxnsConserveSelection; diff --git a/editor/libeditor/nsEditorEventListener.cpp b/editor/libeditor/nsEditorEventListener.cpp index d141298992..21958ee206 100644 --- a/editor/libeditor/nsEditorEventListener.cpp +++ b/editor/libeditor/nsEditorEventListener.cpp @@ -469,6 +469,8 @@ nsEditorEventListener::HandleEvent(nsIDOMEvent* aEvent) case NS_COMPOSITION_END: HandleEndComposition(aEvent); return NS_OK; + default: + break; } nsAutoString eventType; diff --git a/editor/libeditor/nsPlaintextEditor.cpp b/editor/libeditor/nsPlaintextEditor.cpp index 447340bff2..b482db1f8e 100644 --- a/editor/libeditor/nsPlaintextEditor.cpp +++ b/editor/libeditor/nsPlaintextEditor.cpp @@ -1168,10 +1168,13 @@ nsPlaintextEditor::CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed) } bool -nsPlaintextEditor::FireClipboardEvent(int32_t aType, int32_t aSelectionType, bool* aActionTaken) +nsPlaintextEditor::FireClipboardEvent(EventMessage aEventMessage, + int32_t aSelectionType, + bool* aActionTaken) { - if (aType == NS_PASTE) + if (aEventMessage == NS_PASTE) { ForceCompositionEnd(); + } nsCOMPtr presShell = GetPresShell(); NS_ENSURE_TRUE(presShell, false); @@ -1181,8 +1184,10 @@ nsPlaintextEditor::FireClipboardEvent(int32_t aType, int32_t aSelectionType, boo return false; } - if (!nsCopySupport::FireClipboardEvent(aType, aSelectionType, presShell, selection, aActionTaken)) + if (!nsCopySupport::FireClipboardEvent(aEventMessage, aSelectionType, + presShell, selection, aActionTaken)) { return false; + } // If the event handler caused the editor to be destroyed, return false. // Otherwise return true to indicate that the event was not cancelled. diff --git a/editor/libeditor/nsPlaintextEditor.h b/editor/libeditor/nsPlaintextEditor.h index 5304304c62..8df00eaa5e 100644 --- a/editor/libeditor/nsPlaintextEditor.h +++ b/editor/libeditor/nsPlaintextEditor.h @@ -207,7 +207,9 @@ protected: ePasswordFieldNotAllowed }; bool CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed); - bool FireClipboardEvent(int32_t aType, int32_t aSelectionType, bool* aActionTaken = nullptr); + bool FireClipboardEvent(mozilla::EventMessage aEventMessage, + int32_t aSelectionType, + bool* aActionTaken = nullptr); bool UpdateMetaCharset(nsIDOMDocument* aDocument, const nsACString& aCharacterSet); diff --git a/gfx/cairo/cairo/src/cairo-quartz-font.c b/gfx/cairo/cairo/src/cairo-quartz-font.c index c6b32a6317..ef58c35b5f 100644 --- a/gfx/cairo/cairo/src/cairo-quartz-font.c +++ b/gfx/cairo/cairo/src/cairo-quartz-font.c @@ -76,9 +76,6 @@ static void (*CGFontGetGlyphsForUnicharsPtr) (CGFontRef, const UniChar[], const static void (*CGContextSetAllowsFontSmoothingPtr) (CGContextRef, bool) = NULL; static bool (*CGContextGetAllowsFontSmoothingPtr) (CGContextRef) = NULL; -/* Not public in the least bit */ -static CGPathRef (*CGFontGetGlyphPathPtr) (CGFontRef fontRef, CGAffineTransform *textTransform, int unknown, CGGlyph glyph) = NULL; - /* CGFontGetHMetrics isn't public, but the other functions are public/present in 10.5 */ typedef struct { int ascent; @@ -121,7 +118,6 @@ quartz_font_ensure_symbols(void) /* These have the same name in 10.4 and 10.5 */ CGFontGetUnitsPerEmPtr = dlsym(RTLD_DEFAULT, "CGFontGetUnitsPerEm"); CGFontGetGlyphAdvancesPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphAdvances"); - CGFontGetGlyphPathPtr = dlsym(RTLD_DEFAULT, "CGFontGetGlyphPath"); CGFontGetHMetricsPtr = dlsym(RTLD_DEFAULT, "CGFontGetHMetrics"); CGFontGetAscentPtr = dlsym(RTLD_DEFAULT, "CGFontGetAscent"); @@ -138,7 +134,6 @@ quartz_font_ensure_symbols(void) CGFontGetGlyphsForUnicharsPtr && CGFontGetUnitsPerEmPtr && CGFontGetGlyphAdvancesPtr && - CGFontGetGlyphPathPtr && (CGFontGetHMetricsPtr || (CGFontGetAscentPtr && CGFontGetDescentPtr && CGFontGetLeadingPtr))) _cairo_quartz_font_symbols_present = TRUE; @@ -560,6 +555,7 @@ _cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font, CGGlyph glyph = _cairo_quartz_scaled_glyph_index (scaled_glyph); CGAffineTransform textMatrix; CGPathRef glyphPath; + CTFontRef ctFont; cairo_path_fixed_t *path; if (glyph == INVALID_GLYPH) { @@ -574,7 +570,9 @@ _cairo_quartz_init_glyph_path (cairo_quartz_scaled_font_t *font, -font->base.scale.yy, 0, 0); - glyphPath = CGFontGetGlyphPathPtr (font_face->cgFont, &textMatrix, 0, glyph); + ctFont = CTFontCreateWithGraphicsFont (font_face->cgFont, 0.0, NULL, NULL); + glyphPath = CTFontCreatePathForGlyph (ctFont, glyph, &textMatrix); + CFRelease (ctFont); if (!glyphPath) return CAIRO_INT_STATUS_UNSUPPORTED; @@ -802,7 +800,7 @@ _cairo_quartz_scaled_font_get_ct_font_ref (cairo_scaled_font_t *abstract_font) return ffont->ctFont; } -#ifndef __LP64__ +#if !defined(__LP64__) && !TARGET_OS_IPHONE /* * compat with old ATSUI backend */ diff --git a/gfx/cairo/cairo/src/cairo-quartz-image.h b/gfx/cairo/cairo/src/cairo-quartz-image.h index dae234daca..2d6e8fb527 100644 --- a/gfx/cairo/cairo/src/cairo-quartz-image.h +++ b/gfx/cairo/cairo/src/cairo-quartz-image.h @@ -39,8 +39,13 @@ #include "cairo.h" #if CAIRO_HAS_QUARTZ_IMAGE_SURFACE +#include "TargetConditionals.h" +#if !TARGET_OS_IPHONE #include +#else +#include +#endif CAIRO_BEGIN_DECLS diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c index 17c1cec686..434a289839 100644 --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c @@ -34,7 +34,9 @@ * Vladimir Vukicevic */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE /* required for RTLD_DEFAULT */ +#endif #include "cairoint.h" #include "cairo-quartz-private.h" @@ -177,10 +179,15 @@ static void quartz_ensure_symbols(void) CTFontDrawGlyphsPtr = dlsym(RTLD_DEFAULT, "CTFontDrawGlyphs"); +#if !TARGET_OS_IPHONE if (Gestalt(gestaltSystemVersion, &_cairo_quartz_osx_version) != noErr) { // assume 10.5 _cairo_quartz_osx_version = 0x1050; } +#else + //TODO: this is not great + _cairo_quartz_osx_version = 0x1050; +#endif _cairo_quartz_symbol_lookup_done = TRUE; } diff --git a/gfx/cairo/cairo/src/cairo-quartz.h b/gfx/cairo/cairo/src/cairo-quartz.h index fef2724f81..2941a0339b 100644 --- a/gfx/cairo/cairo/src/cairo-quartz.h +++ b/gfx/cairo/cairo/src/cairo-quartz.h @@ -39,8 +39,14 @@ #include "cairo.h" #if CAIRO_HAS_QUARTZ_SURFACE +#include "TargetConditionals.h" +#if !TARGET_OS_IPHONE #include +#else +#include +#include +#endif CAIRO_BEGIN_DECLS @@ -88,7 +94,7 @@ cairo_quartz_surface_get_image (cairo_surface_t *surface); cairo_public cairo_font_face_t * cairo_quartz_font_face_create_for_cgfont (CGFontRef font); -#ifndef __LP64__ +#if !defined(__LP64__) && !TARGET_OS_IPHONE cairo_public cairo_font_face_t * cairo_quartz_font_face_create_for_atsu_font_id (ATSUFontID font_id); #endif diff --git a/gfx/cairo/cairo/src/moz.build b/gfx/cairo/cairo/src/moz.build index 9a9ab60d9f..6cdb12564c 100644 --- a/gfx/cairo/cairo/src/moz.build +++ b/gfx/cairo/cairo/src/moz.build @@ -56,7 +56,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': ] else: DEFINES['CAIRO_OMIT_WIN32_PRINTING'] = True -elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa': +elif CONFIG['MOZ_WIDGET_TOOLKIT'] in {'cocoa', 'uikit'}: EXPORTS.cairo += [ 'cairo-quartz-image.h', 'cairo-quartz.h', diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index e81f9b84a0..93ffdf6233 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -872,6 +872,8 @@ APZCTreeManager::UpdateWheelTransaction(WidgetInputEvent& aEvent) case NS_DRAGDROP_DROP: txn->EndTransaction(); return; + default: + break; } } diff --git a/gfx/layers/apz/util/APZCCallbackHelper.cpp b/gfx/layers/apz/util/APZCCallbackHelper.cpp index aedef28c6f..88053cf65c 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.cpp +++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp @@ -479,7 +479,7 @@ APZCCallbackHelper::DispatchWidgetEvent(WidgetGUIEvent& aEvent) } nsEventStatus -APZCCallbackHelper::DispatchSynthesizedMouseEvent(uint32_t aMsg, +APZCCallbackHelper::DispatchSynthesizedMouseEvent(EventMessage aMsg, uint64_t aTime, const LayoutDevicePoint& aRefPoint, Modifiers aModifiers, diff --git a/gfx/layers/apz/util/APZCCallbackHelper.h b/gfx/layers/apz/util/APZCCallbackHelper.h index e2d9ff607d..d3fcf91c6d 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.h +++ b/gfx/layers/apz/util/APZCCallbackHelper.h @@ -116,7 +116,7 @@ public: /* Synthesize a mouse event with the given parameters, and dispatch it * via the given widget. */ - static nsEventStatus DispatchSynthesizedMouseEvent(uint32_t aMsg, + static nsEventStatus DispatchSynthesizedMouseEvent(EventMessage aMsg, uint64_t aTime, const LayoutDevicePoint& aRefPoint, Modifiers aModifiers, diff --git a/ipc/glue/ProcessUtils_linux.cpp b/ipc/glue/ProcessUtils_linux.cpp index 35b9cf701a..cb0132cf66 100644 --- a/ipc/glue/ProcessUtils_linux.cpp +++ b/ipc/glue/ProcessUtils_linux.cpp @@ -31,6 +31,7 @@ #include "mozilla/unused.h" #include "base/process_util.h" #include "base/eintr_wrapper.h" +#include "mozilla/Preferences.h" #include "prenv.h" @@ -204,6 +205,14 @@ ProcLoaderClientGeckoInit() MOZ_ASSERT(!sProcLoaderClientGeckoInitialized, "call ProcLoaderClientGeckoInit() more than once"); + if (!Preferences::GetBool("dom.ipc.processPrelaunch.enabled", false)) { + kill(sProcLoaderPid, SIGKILL); + sProcLoaderPid = 0; + close(sProcLoaderChannelFd); + sProcLoaderChannelFd = -1; + return; + } + sProcLoaderClientGeckoInitialized = true; TransportDescriptor fd; diff --git a/js/src/asmjs/AsmJSModule.cpp b/js/src/asmjs/AsmJSModule.cpp index 05613d84d4..f03fd3107b 100644 --- a/js/src/asmjs/AsmJSModule.cpp +++ b/js/src/asmjs/AsmJSModule.cpp @@ -539,6 +539,12 @@ TryEnablingJit(JSContext* cx, AsmJSModule& module, HandleFunction fun, uint32_t return true; } + // Don't enable jit entry when we have a pending ion builder. + // Take the interpreter path which will link it and enable + // the fast path on the next call. + if (script->baselineScript()->hasPendingIonBuilder()) + return true; + // Currently we can't rectify arguments. Therefore disabling if argc is too low. if (fun->nargs() > size_t(argc)) return true; diff --git a/js/src/devtools/rootAnalysis/annotations.js b/js/src/devtools/rootAnalysis/annotations.js index 8779ede746..b9375d96ab 100644 --- a/js/src/devtools/rootAnalysis/annotations.js +++ b/js/src/devtools/rootAnalysis/annotations.js @@ -382,6 +382,11 @@ function listNonGCTypes() { function listNonGCPointers() { return [ + // Both of these are safe only because jsids are currently only made + // from "interned" (pinned) strings. Once that changes, both should be + // removed from the list. + 'NPIdentifier', + 'XPCNativeMember', ]; } diff --git a/js/src/jit-test/tests/basic/testArrayBufferTransfer.js b/js/src/jit-test/tests/basic/testArrayBufferTransfer.js index 2c2a647018..4c17dcf3c0 100644 --- a/js/src/jit-test/tests/basic/testArrayBufferTransfer.js +++ b/js/src/jit-test/tests/basic/testArrayBufferTransfer.js @@ -55,6 +55,12 @@ assertEq(buf1.byteLength, 0); assertEq(buf2.byteLength, 9); assertThrowsInstanceOf(()=>XF(buf1), TypeError); +// cross-compartment wrapper +var buf3 = newGlobal().eval("new ArrayBuffer(10)"); +var buf4 = XF(buf3, 20); +assertEq(buf4.byteLength, 20); +assertThrowsInstanceOf(()=>XF(buf3), TypeError); + // test going to from various sizes function test(N1, N2) { var buf1 = new ArrayBuffer(N1); diff --git a/js/src/jit-test/tests/gc/bug-1148383.js b/js/src/jit-test/tests/gc/bug-1148383.js new file mode 100644 index 0000000000..eea1d6c1dd --- /dev/null +++ b/js/src/jit-test/tests/gc/bug-1148383.js @@ -0,0 +1,19 @@ +// This testcase tests setting object metadata for objects created from JIT +// code. +if (!("getJitCompilerOptions" in this)) + quit(); +opts = getJitCompilerOptions(); +if (!opts['ion.enable'] || !opts['baseline.enable']) + quit(); + +function TestCase() {} +function reportCompare () { + var output = ""; + var testcase = new TestCase(); + testcase.reason = output; +} +reportCompare(); +gczeal(4, 1000); +setObjectMetadataCallback(true); +for (var i = 0; i < 10000; ++i) + reportCompare(); diff --git a/js/src/jit-test/tests/ion/bug1196648.js b/js/src/jit-test/tests/ion/bug1196648.js new file mode 100644 index 0000000000..315633a538 --- /dev/null +++ b/js/src/jit-test/tests/ion/bug1196648.js @@ -0,0 +1,18 @@ +h = function(m, foreign, n) { + "use asm"; + var ff = foreign.ff; + function f(x) { + x = +x; + ff(); + } + return f; +}(0, { + ff: function() { + return { + e: String.prototype.substring + }; + } +}, 0); +for (var k = 0; k < 999; k++) { + h(); +} diff --git a/js/src/jit/BaselineJIT.cpp b/js/src/jit/BaselineJIT.cpp index dcfcddec45..b99cfde2c0 100644 --- a/js/src/jit/BaselineJIT.cpp +++ b/js/src/jit/BaselineJIT.cpp @@ -478,6 +478,21 @@ BaselineScript::Destroy(FreeOp* fop, BaselineScript* script) fop->delete_(script); } +void +BaselineScript::clearDependentAsmJSModules() +{ + // Remove any links from AsmJSModules that contain optimized FFI calls into + // this BaselineScript. + if (dependentAsmJSModules_) { + for (size_t i = 0; i < dependentAsmJSModules_->length(); i++) { + DependentAsmJSModuleExit exit = (*dependentAsmJSModules_)[i]; + exit.module->detachJitCompilation(exit.exitIndex); + } + + dependentAsmJSModules_->clear(); + } +} + void BaselineScript::unlinkDependentAsmJSModules(FreeOp* fop) { diff --git a/js/src/jit/BaselineJIT.h b/js/src/jit/BaselineJIT.h index 2b55c91dc6..60901cdc5a 100644 --- a/js/src/jit/BaselineJIT.h +++ b/js/src/jit/BaselineJIT.h @@ -401,6 +401,7 @@ struct BaselineScript bool addDependentAsmJSModule(JSContext* cx, DependentAsmJSModuleExit exit); void unlinkDependentAsmJSModules(FreeOp* fop); + void clearDependentAsmJSModules(); void removeDependentAsmJSModule(DependentAsmJSModuleExit exit); // Toggle debug traps (used for breakpoints and step mode) in the script. @@ -477,6 +478,9 @@ struct BaselineScript pendingBuilder_ = builder; + // lazy linking cannot happen during asmjs to ion. + clearDependentAsmJSModules(); + script->updateBaselineOrIonRaw(maybecx); } void removePendingIonBuilder(JSScript* script) { diff --git a/js/src/jit/mips32/Trampoline-mips32.cpp b/js/src/jit/mips32/Trampoline-mips32.cpp index 255648b8ac..46f0420a3a 100644 --- a/js/src/jit/mips32/Trampoline-mips32.cpp +++ b/js/src/jit/mips32/Trampoline-mips32.cpp @@ -1322,7 +1322,7 @@ JitRuntime::generateProfilerExitFrameTailStub(JSContext* cx) masm.bind(&handle_IonAccessorIC); { // scratch2 := StackPointer + Descriptor.size + JitFrameLayout::Size() - masm.ma_addu(StackPointer, scratch1, scratch2); + masm.ma_addu(scratch2, StackPointer, scratch1); masm.addPtr(Imm32(JitFrameLayout::Size()), scratch2); // scratch3 := AccFrame-Descriptor.Size @@ -1346,7 +1346,7 @@ JitRuntime::generateProfilerExitFrameTailStub(JSContext* cx) // lastProfilingFrame := AccessorFrame + AccFrame-Descriptor.Size + // IonAccessorICFrameLayout::Size() - masm.ma_addu(scratch2, scratch3, scratch1); + masm.ma_addu(scratch1, scratch2, scratch3); masm.addPtr(Imm32(IonAccessorICFrameLayout::Size()), scratch1); masm.storePtr(scratch1, lastProfilingFrame); masm.ret(); diff --git a/js/src/tests/browser.js b/js/src/tests/browser.js index 3cc54a4eb9..46d03172ee 100644 --- a/js/src/tests/browser.js +++ b/js/src/tests/browser.js @@ -336,6 +336,10 @@ function jsTestDriverBrowserInit() { properties.version = '1.8'; } + else if (properties.test.match(/^ecma_6\/extensions/)) + { + properties.version = '1.8'; + } } // default to language=type;text/javascript. required for diff --git a/js/src/tests/ecma_6/Class/shell.js b/js/src/tests/ecma_6/Class/shell.js index e9d0f9e832..236efabdb9 100644 --- a/js/src/tests/ecma_6/Class/shell.js +++ b/js/src/tests/ecma_6/Class/shell.js @@ -1,4 +1,6 @@ -// Enable "let" in shell builds. So silly. +// NOTE: This only turns on 1.8.5 in shell builds. The browser requires the +// futzing in js/src/tests/browser.js (which only turns on 1.8, the most +// the browser supports). if (typeof version != 'undefined') version(185); diff --git a/js/src/tests/ecma_6/extensions/shell.js b/js/src/tests/ecma_6/extensions/shell.js index e69de29bb2..4d731295dd 100644 --- a/js/src/tests/ecma_6/extensions/shell.js +++ b/js/src/tests/ecma_6/extensions/shell.js @@ -0,0 +1,5 @@ +// NOTE: This only turns on 1.8.5 in shell builds. The browser requires the +// futzing in js/src/tests/browser.js (which only turns on 1.8, the most +// the browser supports). +if (typeof version != 'undefined') + version(185); diff --git a/js/src/vm/ArrayBufferObject.cpp b/js/src/vm/ArrayBufferObject.cpp index ebb1520a31..a39e8fe79c 100644 --- a/js/src/vm/ArrayBufferObject.cpp +++ b/js/src/vm/ArrayBufferObject.cpp @@ -369,8 +369,8 @@ ArrayBufferObject::fun_transfer(JSContext* cx, unsigned argc, Value* vp) if (oldBufferObj->is()) { oldBuffer = &oldBufferObj->as(); } else { - JSObject* unwrapped = CheckedUnwrap(oldBuffer); - if (!unwrapped->is()) { + JSObject* unwrapped = CheckedUnwrap(oldBufferObj); + if (!unwrapped || !unwrapped->is()) { JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_TYPED_ARRAY_BAD_ARGS); return false; } diff --git a/js/src/vm/Interpreter.cpp b/js/src/vm/Interpreter.cpp index be5517c1c6..e5edfa3e35 100644 --- a/js/src/vm/Interpreter.cpp +++ b/js/src/vm/Interpreter.cpp @@ -2688,9 +2688,8 @@ END_CASE(JSOP_MOD) CASE(JSOP_POW) { - RootedValue& lval = rootValue0, &rval = rootValue1; - lval = REGS.sp[-2]; - rval = REGS.sp[-1]; + ReservedRooted lval(&rootValue0, REGS.sp[-2]); + ReservedRooted rval(&rootValue1, REGS.sp[-1]); MutableHandleValue res = REGS.stackHandleAt(-2); if (!math_pow_handle(cx, lval, rval, res)) goto error; diff --git a/layout/base/gtest/TestAccessibleCaretEventHub.cpp b/layout/base/gtest/TestAccessibleCaretEventHub.cpp index 4e18fb8577..301efe3f89 100644 --- a/layout/base/gtest/TestAccessibleCaretEventHub.cpp +++ b/layout/base/gtest/TestAccessibleCaretEventHub.cpp @@ -111,7 +111,8 @@ public: EXPECT_EQ(mHub->GetState(), MockAccessibleCaretEventHub::NoActionState()); } - static UniquePtr CreateMouseEvent(uint32_t aMessage, nscoord aX, + static UniquePtr CreateMouseEvent(EventMessage aMessage, + nscoord aX, nscoord aY) { auto event = MakeUnique(true, aMessage, nullptr, @@ -143,7 +144,8 @@ public: return CreateMouseEvent(NS_MOUSE_MOZLONGTAP, aX, aY); } - static UniquePtr CreateTouchEvent(uint32_t aMessage, nscoord aX, + static UniquePtr CreateTouchEvent(EventMessage aMessage, + nscoord aX, nscoord aY) { auto event = MakeUnique(true, aMessage, nullptr); @@ -175,7 +177,7 @@ public: return CreateTouchEvent(NS_TOUCH_END, aX, aY); } - static UniquePtr CreateWheelEvent(uint32_t aMessage) + static UniquePtr CreateWheelEvent(EventMessage aMessage) { auto event = MakeUnique(true, aMessage, nullptr); diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index f2b9671940..1ea9e095df 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -127,8 +127,9 @@ IsKeyboardRTL() nsCaret::nsCaret() : mOverrideOffset(0) -, mIsBlinkOn(false) , mBlinkCount(-1) +, mHideCount(0) +, mIsBlinkOn(false) , mVisible(false) , mReadOnly(false) , mShowDuringSelection(false) @@ -266,7 +267,7 @@ void nsCaret::SetVisible(bool inMakeVisible) bool nsCaret::IsVisible() { - if (!mVisible) { + if (!mVisible || mHideCount) { return false; } @@ -303,6 +304,25 @@ bool nsCaret::IsVisible() return true; } +void nsCaret::AddForceHide() +{ + MOZ_ASSERT(mHideCount < UINT32_MAX); + if (++mHideCount > 1) { + return; + } + ResetBlinking(); + SchedulePaint(); +} + +void nsCaret::RemoveForceHide() +{ + if (!mHideCount || --mHideCount) { + return; + } + ResetBlinking(); + SchedulePaint(); +} + void nsCaret::SetCaretReadOnly(bool inMakeReadonly) { mReadOnly = inMakeReadonly; @@ -622,7 +642,7 @@ void nsCaret::ResetBlinking() { mIsBlinkOn = true; - if (mReadOnly || !mVisible) { + if (mReadOnly || !mVisible || mHideCount) { StopBlinking(); return; } diff --git a/layout/base/nsCaret.h b/layout/base/nsCaret.h index 23ac2af401..4e51d2ed02 100644 --- a/layout/base/nsCaret.h +++ b/layout/base/nsCaret.h @@ -78,6 +78,21 @@ class nsCaret final : public nsISelectionListener * because we're in non-editable/disabled content. */ bool IsVisible(); + /** + * AddForceHide() increases mHideCount and hide the caret even if + * SetVisible(true) has been or will be called. This is useful when the + * caller wants to hide caret temporarily and it needs to cancel later. + * Especially, in the latter case, it's too difficult to decide if the + * caret should be actually visible or not because caret visible state + * is set from a lot of event handlers. So, it's very stateful. + */ + void AddForceHide(); + /** + * RemoveForceHide() decreases mHideCount if it's over 0. + * If the value becomes 0, this may show the caret if SetVisible(true) + * has been called. + */ + void RemoveForceHide(); /** SetCaretReadOnly set the appearance of the caret * @param inMakeReadonly true to show the caret in a 'read only' state, * false to show the caret in normal, editing state @@ -201,17 +216,22 @@ protected: * Ignored if mOverrideContent is null. */ int32_t mOverrideOffset; - - /** - * mIsBlinkOn is true when we're in a blink cycle where the caret is on. - */ - bool mIsBlinkOn; /** * mBlinkCount is used to control the number of times to blink the caret * before stopping the blink. This is reset each time we reset the * blinking. */ int32_t mBlinkCount; + /** + * mHideCount is not 0, it means that somebody doesn't want the caret + * to be visible. See AddForceHide() and RemoveForceHide(). + */ + uint32_t mHideCount; + + /** + * mIsBlinkOn is true when we're in a blink cycle where the caret is on. + */ + bool mIsBlinkOn; /** * mIsVisible is true when SetVisible was last called with 'true'. */ diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 6f958c85e3..a74b59b5be 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -6330,6 +6330,8 @@ PresShell::UpdateActivePointerState(WidgetGUIEvent* aEvent) gActivePointersIds->Remove(mouseEvent->pointerId); } break; + default: + break; } } @@ -6612,7 +6614,7 @@ DispatchPointerFromMouseOrTouch(PresShell* aShell, nsEventStatus* aStatus, nsIContent** aTargetContent) { - uint32_t pointerMessage = 0; + EventMessage pointerMessage = NS_EVENT_NULL; if (aEvent->mClass == eMouseEventClass) { WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); // if it is not mouse then it is likely will come as touch event @@ -6797,7 +6799,7 @@ PresShell::DispatchBeforeKeyboardEventInternal(const nsTArray return; } - uint32_t message = + EventMessage message = (aEvent.mMessage == NS_KEY_DOWN) ? NS_KEY_BEFORE_DOWN : NS_KEY_BEFORE_UP; nsCOMPtr eventTarget; // Dispatch before events from the outermost element. @@ -6831,7 +6833,7 @@ PresShell::DispatchAfterKeyboardEventInternal(const nsTArray > return; } - uint32_t message = + EventMessage message = (aEvent.mMessage == NS_KEY_DOWN) ? NS_KEY_AFTER_DOWN : NS_KEY_AFTER_UP; bool embeddedCancelled = aEmbeddedCancelled; nsCOMPtr eventTarget; @@ -7476,6 +7478,8 @@ PresShell::HandleEvent(nsIFrame* aFrame, } break; } + default: + break; } // Check if we have an active EventStateManager which isn't the @@ -7838,7 +7842,7 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus) isHandlingUserInput = true; break; - case NS_DRAGDROP_DROP: + case NS_DRAGDROP_DROP: { nsCOMPtr session = nsContentUtils::GetDragSession(); if (session) { bool onlyChromeDrop = false; @@ -7850,6 +7854,10 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus) break; } + default: + break; + } + if (!mTouchManager.PreHandleEvent(aEvent, aStatus, touchIsNew, isHandlingUserInput, mCurrentEventContent)) { @@ -7941,6 +7949,8 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus) case NS_MOUSE_MOVE: nsIPresShell::AllowMouseCapture(false); break; + default: + break; } } return rv; diff --git a/layout/generic/nsFrameSetFrame.cpp b/layout/generic/nsFrameSetFrame.cpp index 9ec1a64ba1..73ee86505c 100644 --- a/layout/generic/nsFrameSetFrame.cpp +++ b/layout/generic/nsFrameSetFrame.cpp @@ -661,6 +661,8 @@ nsresult nsHTMLFramesetFrame::HandleEvent(nsPresContext* aPresContext, EndMouseDrag(aPresContext); } break; + default: + break; } *aEventStatus = nsEventStatus_eConsumeNoDefault; } else { diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index af3bd0b5ac..d903476857 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -1749,7 +1749,8 @@ nsFrameSelection::TakeFocus(nsIContent* aNewFocus, #ifdef DEBUG_TABLE_SELECTION printf(" * TakeFocus - moving into new cell\n"); #endif - WidgetMouseEvent event(false, 0, nullptr, WidgetMouseEvent::eReal); + WidgetMouseEvent event(false, NS_EVENT_NULL, nullptr, + WidgetMouseEvent::eReal); // Start selecting in the cell we were in before nsINode* parent = ParentOffset(mCellParent, &offset); diff --git a/layout/style/nsAnimationManager.cpp b/layout/style/nsAnimationManager.cpp index 13078e5db9..b99d22acf3 100644 --- a/layout/style/nsAnimationManager.cpp +++ b/layout/style/nsAnimationManager.cpp @@ -232,7 +232,7 @@ CSSAnimation::QueueEvents() mPreviousPhaseOrIteration = PREVIOUS_PHASE_AFTER; } - uint32_t message; + EventMessage message; if (!wasActive && isActive) { message = NS_ANIMATION_START; diff --git a/layout/style/nsAnimationManager.h b/layout/style/nsAnimationManager.h index 830682dcb1..1eaf6b7ebd 100644 --- a/layout/style/nsAnimationManager.h +++ b/layout/style/nsAnimationManager.h @@ -7,6 +7,7 @@ #include "mozilla/Attributes.h" #include "mozilla/ContentEvents.h" +#include "mozilla/EventForwards.h" #include "AnimationCommon.h" #include "nsCSSPseudoElements.h" #include "mozilla/dom/Animation.h" @@ -30,7 +31,7 @@ struct AnimationEventInfo { AnimationEventInfo(mozilla::dom::Element *aElement, const nsSubstring& aAnimationName, - uint32_t aMessage, + EventMessage aMessage, const mozilla::StickyTimeDuration& aElapsedTime, nsCSSPseudoElements::Type aPseudoType) : mElement(aElement), mEvent(true, aMessage) diff --git a/layout/xul/nsButtonBoxFrame.cpp b/layout/xul/nsButtonBoxFrame.cpp index 4deb15483d..85a078ce3d 100644 --- a/layout/xul/nsButtonBoxFrame.cpp +++ b/layout/xul/nsButtonBoxFrame.cpp @@ -117,6 +117,9 @@ nsButtonBoxFrame::HandleEvent(nsPresContext* aPresContext, } break; } + + default: + break; } return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus); diff --git a/layout/xul/nsImageBoxFrame.cpp b/layout/xul/nsImageBoxFrame.cpp index 8254df3e83..2238584a36 100644 --- a/layout/xul/nsImageBoxFrame.cpp +++ b/layout/xul/nsImageBoxFrame.cpp @@ -61,14 +61,14 @@ using namespace mozilla::layers; class nsImageBoxFrameEvent : public nsRunnable { public: - nsImageBoxFrameEvent(nsIContent *content, uint32_t message) + nsImageBoxFrameEvent(nsIContent *content, EventMessage message) : mContent(content), mMessage(message) {} NS_IMETHOD Run() override; private: nsCOMPtr mContent; - uint32_t mMessage; + EventMessage mMessage; }; NS_IMETHODIMP @@ -101,7 +101,7 @@ nsImageBoxFrameEvent::Run() // asynchronously. void -FireImageDOMEvent(nsIContent* aContent, uint32_t aMessage) +FireImageDOMEvent(nsIContent* aContent, EventMessage aMessage) { NS_ASSERTION(aMessage == NS_LOAD || aMessage == NS_LOAD_ERROR, "invalid message"); diff --git a/layout/xul/nsResizerFrame.cpp b/layout/xul/nsResizerFrame.cpp index 6e8f23c8fb..5bf4e98d0f 100644 --- a/layout/xul/nsResizerFrame.cpp +++ b/layout/xul/nsResizerFrame.cpp @@ -310,6 +310,9 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, } } break; + + default: + break; } if (!doDefault) diff --git a/layout/xul/nsScrollBoxFrame.cpp b/layout/xul/nsScrollBoxFrame.cpp index 87f63a277d..091dcaf343 100644 --- a/layout/xul/nsScrollBoxFrame.cpp +++ b/layout/xul/nsScrollBoxFrame.cpp @@ -111,6 +111,9 @@ nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext, } break; } + + default: + break; } return nsButtonBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus); diff --git a/layout/xul/nsScrollbarButtonFrame.cpp b/layout/xul/nsScrollbarButtonFrame.cpp index 1a40d84bb5..0a172b12be 100644 --- a/layout/xul/nsScrollbarButtonFrame.cpp +++ b/layout/xul/nsScrollbarButtonFrame.cpp @@ -73,6 +73,8 @@ nsScrollbarButtonFrame::HandleEvent(nsPresContext* aPresContext, mCursorOnThis = frameRect.Contains(cursor); break; } + default: + break; } return nsButtonBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus); diff --git a/layout/xul/nsSliderFrame.cpp b/layout/xul/nsSliderFrame.cpp index 45cb0a1ad6..80bf2d4520 100644 --- a/layout/xul/nsSliderFrame.cpp +++ b/layout/xul/nsSliderFrame.cpp @@ -511,6 +511,9 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, //we MUST call nsFrame HandleEvent for mouse ups to maintain the selection state and capture state. return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); } + + default: + break; } //return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); diff --git a/layout/xul/nsSplitterFrame.cpp b/layout/xul/nsSplitterFrame.cpp index 24c17c3d78..d95420c74a 100644 --- a/layout/xul/nsSplitterFrame.cpp +++ b/layout/xul/nsSplitterFrame.cpp @@ -391,13 +391,16 @@ nsSplitterFrame::HandleEvent(nsPresContext* aPresContext, switch (aEvent->mMessage) { case NS_MOUSE_MOVE: mInner->MouseDrag(aPresContext, aEvent); - break; + break; case NS_MOUSE_BUTTON_UP: if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { mInner->MouseUp(aPresContext, aEvent); } - break; + break; + + default: + break; } NS_ENSURE_STATE(weakFrame.IsAlive()); diff --git a/layout/xul/nsTitleBarFrame.cpp b/layout/xul/nsTitleBarFrame.cpp index f6e302e9dd..f9526e99fa 100644 --- a/layout/xul/nsTitleBarFrame.cpp +++ b/layout/xul/nsTitleBarFrame.cpp @@ -154,6 +154,9 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, } break; } + + default: + break; } if ( doDefault ) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index acefcf5797..395e6fe325 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -3395,6 +3395,10 @@ pref("intl.tsf.hack.atok.create_native_caret", true); // composition start offset. // For Free ChangJie 2010 pref("intl.tsf.hack.free_chang_jie.do_not_return_no_layout_error", true); +// For Microsoft Pinyin and Microsoft Wubi +pref("intl.tsf.hack.ms_simplified_chinese.do_not_return_no_layout_error", true); +// For Microsoft ChangJie and Microsoft Quick +pref("intl.tsf.hack.ms_traditional_chinese.do_not_return_no_layout_error", true); // For Easy Changjei pref("intl.tsf.hack.easy_changjei.do_not_return_no_layout_error", true); // Whether use previous character rect for the result of diff --git a/widget/BasicEvents.h b/widget/BasicEvents.h index 47c407ce2f..7574352ceb 100644 --- a/widget/BasicEvents.h +++ b/widget/BasicEvents.h @@ -171,7 +171,9 @@ struct EventFlags : public BaseEventFlags class WidgetEvent { protected: - WidgetEvent(bool aIsTrusted, uint32_t aMessage, EventClassID aEventClassID) + WidgetEvent(bool aIsTrusted, + EventMessage aMessage, + EventClassID aEventClassID) : mClass(aEventClassID) , mMessage(aMessage) , refPoint(0, 0) @@ -193,7 +195,7 @@ protected: } public: - WidgetEvent(bool aIsTrusted, uint32_t aMessage) + WidgetEvent(bool aIsTrusted, EventMessage aMessage) : mClass(eBasicEventClass) , mMessage(aMessage) , refPoint(0, 0) @@ -231,8 +233,7 @@ public: } EventClassID mClass; - // See GUI MESSAGES, - uint32_t mMessage; + EventMessage mMessage; // Relative to the widget of the event, or if there is no widget then it is // in screen coordinates. Not modified by layout code. LayoutDeviceIntPoint refPoint; @@ -391,7 +392,7 @@ public: class WidgetGUIEvent : public WidgetEvent { protected: - WidgetGUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, + WidgetGUIEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget, EventClassID aEventClassID) : WidgetEvent(aIsTrusted, aMessage, aEventClassID) , widget(aWidget) @@ -405,9 +406,9 @@ protected: public: virtual WidgetGUIEvent* AsGUIEvent() override { return this; } - WidgetGUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) : - WidgetEvent(aIsTrusted, aMessage, eGUIEventClass), - widget(aWidget) + WidgetGUIEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) + : WidgetEvent(aIsTrusted, aMessage, eGUIEventClass) + , widget(aWidget) { } @@ -555,7 +556,7 @@ typedef uint16_t Modifiers; class WidgetInputEvent : public WidgetGUIEvent { protected: - WidgetInputEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, + WidgetInputEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget, EventClassID aEventClassID) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, aEventClassID) , modifiers(0) @@ -569,7 +570,7 @@ protected: public: virtual WidgetInputEvent* AsInputEvent() override { return this; } - WidgetInputEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) + WidgetInputEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eInputEventClass) , modifiers(0) { @@ -719,29 +720,40 @@ class InternalUIEvent : public WidgetGUIEvent protected: InternalUIEvent() : detail(0) + , mCausedByUntrustedEvent(false) { } - InternalUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, + InternalUIEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget, EventClassID aEventClassID) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, aEventClassID) , detail(0) + , mCausedByUntrustedEvent(false) { } - InternalUIEvent(bool aIsTrusted, uint32_t aMessage, + InternalUIEvent(bool aIsTrusted, EventMessage aMessage, EventClassID aEventClassID) : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, aEventClassID) , detail(0) + , mCausedByUntrustedEvent(false) { } public: virtual InternalUIEvent* AsUIEvent() override { return this; } - InternalUIEvent(bool aIsTrusted, uint32_t aMessage) + /** + * If the UIEvent is caused by another event (e.g., click event), + * aEventCausesThisEvent should be the event. If there is no such event, + * this should be nullptr. + */ + InternalUIEvent(bool aIsTrusted, EventMessage aMessage, + const WidgetEvent* aEventCausesThisEvent) : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, eUIEventClass) , detail(0) + , mCausedByUntrustedEvent( + aEventCausesThisEvent && !aEventCausesThisEvent->mFlags.mIsTrusted) { } @@ -749,19 +761,29 @@ public: { MOZ_ASSERT(mClass == eUIEventClass, "Duplicate() must be overridden by sub class"); - InternalUIEvent* result = new InternalUIEvent(false, mMessage); + InternalUIEvent* result = new InternalUIEvent(false, mMessage, nullptr); result->AssignUIEventData(*this, true); result->mFlags = mFlags; return result; } int32_t detail; + // mCausedByUntrustedEvent is true if the event is caused by untrusted event. + bool mCausedByUntrustedEvent; + + // If you check the event is a trusted event and NOT caused by an untrusted + // event, IsTrustable() returns what you expected. + bool IsTrustable() const + { + return mFlags.mIsTrusted && !mCausedByUntrustedEvent; + } void AssignUIEventData(const InternalUIEvent& aEvent, bool aCopyTargets) { AssignGUIEventData(aEvent, aCopyTargets); detail = aEvent.detail; + mCausedByUntrustedEvent = aEvent.mCausedByUntrustedEvent; } }; diff --git a/widget/ContentCache.cpp b/widget/ContentCache.cpp index 26f43442a4..2e6bac9af2 100644 --- a/widget/ContentCache.cpp +++ b/widget/ContentCache.cpp @@ -24,7 +24,7 @@ GetBoolName(bool aBool) } static const char* -GetEventMessageName(uint32_t aMessage) +GetEventMessageName(EventMessage aMessage) { switch (aMessage) { case NS_COMPOSITION_START: @@ -676,6 +676,8 @@ ContentCacheInParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent, "Succeeded, aEvent={ mReply={ mRect=%s } }", this, GetRectText(aEvent.mReply.mRect).get())); break; + default: + break; } aEvent.mSucceeded = true; return true; @@ -915,7 +917,7 @@ ContentCacheInParent::OnSelectionEvent( void ContentCacheInParent::OnEventNeedingAckHandled(nsIWidget* aWidget, - uint32_t aMessage) + EventMessage aMessage) { // This is called when the child process receives WidgetCompositionEvent or // WidgetSelectionEvent. diff --git a/widget/ContentCache.h b/widget/ContentCache.h index acc701c755..955964b56c 100644 --- a/widget/ContentCache.h +++ b/widget/ContentCache.h @@ -322,7 +322,7 @@ public: * TabParent or aWidget. Therefore, the caller must not destroy * this instance during a call of this method. */ - void OnEventNeedingAckHandled(nsIWidget* aWidget, uint32_t aMessage); + void OnEventNeedingAckHandled(nsIWidget* aWidget, EventMessage aMessage); /** * RequestToCommitComposition() requests to commit or cancel composition to diff --git a/widget/ContentEvents.h b/widget/ContentEvents.h index 2c299b9ed3..3d78718af4 100644 --- a/widget/ContentEvents.h +++ b/widget/ContentEvents.h @@ -38,7 +38,7 @@ public: both = 2 }; - InternalScrollPortEvent(bool aIsTrusted, uint32_t aMessage, + InternalScrollPortEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eScrollPortEventClass) , orient(vertical) @@ -80,7 +80,7 @@ public: return this; } - InternalScrollAreaEvent(bool aIsTrusted, uint32_t aMessage, + InternalScrollAreaEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eScrollAreaEventClass) { @@ -121,7 +121,7 @@ class InternalFormEvent : public WidgetEvent public: virtual InternalFormEvent* AsFormEvent() override { return this; } - InternalFormEvent(bool aIsTrusted, uint32_t aMessage) + InternalFormEvent(bool aIsTrusted, EventMessage aMessage) : WidgetEvent(aIsTrusted, aMessage, eFormEventClass) , originator(nullptr) { @@ -159,7 +159,7 @@ public: return this; } - InternalClipboardEvent(bool aIsTrusted, uint32_t aMessage) + InternalClipboardEvent(bool aIsTrusted, EventMessage aMessage) : WidgetEvent(aIsTrusted, aMessage, eClipboardEventClass) { } @@ -195,7 +195,7 @@ class InternalFocusEvent : public InternalUIEvent public: virtual InternalFocusEvent* AsFocusEvent() override { return this; } - InternalFocusEvent(bool aIsTrusted, uint32_t aMessage) + InternalFocusEvent(bool aIsTrusted, EventMessage aMessage) : InternalUIEvent(aIsTrusted, aMessage, eFocusEventClass) , fromRaise(false) , isRefocus(false) @@ -240,7 +240,7 @@ public: return this; } - InternalTransitionEvent(bool aIsTrusted, uint32_t aMessage) + InternalTransitionEvent(bool aIsTrusted, EventMessage aMessage) : WidgetEvent(aIsTrusted, aMessage, eTransitionEventClass) , elapsedTime(0.0) { @@ -285,7 +285,7 @@ public: return this; } - InternalAnimationEvent(bool aIsTrusted, uint32_t aMessage) + InternalAnimationEvent(bool aIsTrusted, EventMessage aMessage) : WidgetEvent(aIsTrusted, aMessage, eAnimationEventClass) , elapsedTime(0.0) { @@ -327,7 +327,7 @@ class InternalSVGZoomEvent : public WidgetGUIEvent public: virtual InternalSVGZoomEvent* AsSVGZoomEvent() override { return this; } - InternalSVGZoomEvent(bool aIsTrusted, uint32_t aMessage) + InternalSVGZoomEvent(bool aIsTrusted, EventMessage aMessage) : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, eSVGZoomEventClass) { mFlags.mCancelable = false; @@ -363,7 +363,7 @@ public: return this; } - InternalSMILTimeEvent(bool aIsTrusted, uint32_t aMessage) + InternalSMILTimeEvent(bool aIsTrusted, EventMessage aMessage) : InternalUIEvent(aIsTrusted, aMessage, eSMILTimeEventClass) { mFlags.mBubbles = false; diff --git a/widget/EventForwards.h b/widget/EventForwards.h index d899f2f979..40aef88479 100644 --- a/widget/EventForwards.h +++ b/widget/EventForwards.h @@ -28,11 +28,15 @@ enum nsEventStatus nsEventStatus_eSentinel }; +namespace mozilla { + /** * Event messages */ -enum +typedef uint16_t EventMessageType; + +enum EventMessage : EventMessageType { #define NS_EVENT_MESSAGE(aMessage, aValue) aMessage = aValue, @@ -45,8 +49,6 @@ enum eEventMessage_MaxValue }; -namespace mozilla { - /** * Event class IDs */ diff --git a/widget/IMEData.h b/widget/IMEData.h index 7ae5ee8a7e..a3c26f76f0 100644 --- a/widget/IMEData.h +++ b/widget/IMEData.h @@ -421,7 +421,7 @@ struct IMENotification final mTextChangeData.Clear(); break; case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT: - mMouseButtonEventData.mEventMessage = 0; + mMouseButtonEventData.mEventMessage = NS_EVENT_NULL; mMouseButtonEventData.mOffset = UINT32_MAX; mMouseButtonEventData.mCursorPos.Set(nsIntPoint(0, 0)); mMouseButtonEventData.mCharRect.Set(nsIntRect(0, 0, 0, 0)); @@ -692,8 +692,8 @@ struct IMENotification final struct MouseButtonEventData { - // The value of WidgetEvent::message - uint32_t mEventMessage; + // The value of WidgetEvent::mMessage + EventMessage mEventMessage; // Character offset from the start of the focused editor under the cursor uint32_t mOffset; // Cursor position in pixels relative to the widget diff --git a/widget/InputData.cpp b/widget/InputData.cpp index fc243022cc..792fe6c513 100644 --- a/widget/InputData.cpp +++ b/widget/InputData.cpp @@ -81,27 +81,27 @@ MultiTouchInput::ToWidgetTouchEvent(nsIWidget* aWidget) const MOZ_ASSERT(NS_IsMainThread(), "Can only convert To WidgetTouchEvent on main thread"); - uint32_t touchType = NS_EVENT_NULL; + EventMessage touchEventMessage = NS_EVENT_NULL; switch (mType) { case MULTITOUCH_START: - touchType = NS_TOUCH_START; + touchEventMessage = NS_TOUCH_START; break; case MULTITOUCH_MOVE: - touchType = NS_TOUCH_MOVE; + touchEventMessage = NS_TOUCH_MOVE; break; case MULTITOUCH_END: - touchType = NS_TOUCH_END; + touchEventMessage = NS_TOUCH_END; break; case MULTITOUCH_CANCEL: - touchType = NS_TOUCH_CANCEL; + touchEventMessage = NS_TOUCH_CANCEL; break; default: MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetTouchEvent in MultiTouchInput"); break; } - WidgetTouchEvent event(true, touchType, aWidget); - if (touchType == NS_EVENT_NULL) { + WidgetTouchEvent event(true, touchEventMessage, aWidget); + if (touchEventMessage == NS_EVENT_NULL) { return event; } @@ -122,24 +122,24 @@ MultiTouchInput::ToWidgetMouseEvent(nsIWidget* aWidget) const MOZ_ASSERT(NS_IsMainThread(), "Can only convert To WidgetMouseEvent on main thread"); - uint32_t mouseEventType = NS_EVENT_NULL; + EventMessage mouseEventMessage = NS_EVENT_NULL; switch (mType) { case MultiTouchInput::MULTITOUCH_START: - mouseEventType = NS_MOUSE_BUTTON_DOWN; + mouseEventMessage = NS_MOUSE_BUTTON_DOWN; break; case MultiTouchInput::MULTITOUCH_MOVE: - mouseEventType = NS_MOUSE_MOVE; + mouseEventMessage = NS_MOUSE_MOVE; break; case MultiTouchInput::MULTITOUCH_CANCEL: case MultiTouchInput::MULTITOUCH_END: - mouseEventType = NS_MOUSE_BUTTON_UP; + mouseEventMessage = NS_MOUSE_BUTTON_UP; break; default: MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent"); break; } - WidgetMouseEvent event(true, mouseEventType, aWidget, + WidgetMouseEvent event(true, mouseEventMessage, aWidget, WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal); const SingleTouchData& firstTouch = mTouches[0]; @@ -151,7 +151,7 @@ MultiTouchInput::ToWidgetMouseEvent(nsIWidget* aWidget) const event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH; event.modifiers = modifiers; - if (mouseEventType != NS_MOUSE_MOVE) { + if (mouseEventMessage != NS_MOUSE_MOVE) { event.clickCount = 1; } diff --git a/widget/MiscEvents.h b/widget/MiscEvents.h index 62fc5c2dc5..4467a29438 100644 --- a/widget/MiscEvents.h +++ b/widget/MiscEvents.h @@ -27,7 +27,7 @@ public: return this; } - WidgetContentCommandEvent(bool aIsTrusted, uint32_t aMessage, + WidgetContentCommandEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget, bool aOnlyEnabledCheck = false) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eContentCommandEventClass) @@ -145,7 +145,7 @@ class WidgetPluginEvent : public WidgetGUIEvent public: virtual WidgetPluginEvent* AsPluginEvent() override { return this; } - WidgetPluginEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) + WidgetPluginEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, ePluginEventClass) , retargetToFocusedDocument(false) { diff --git a/widget/MouseEvents.h b/widget/MouseEvents.h index 10d66801b3..e11b101bdf 100644 --- a/widget/MouseEvents.h +++ b/widget/MouseEvents.h @@ -77,8 +77,8 @@ protected: { } - WidgetMouseEventBase(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, - EventClassID aEventClassID) + WidgetMouseEventBase(bool aIsTrusted, EventMessage aMessage, + nsIWidget* aWidget, EventClassID aEventClassID) : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID) , button(0) , buttons(0) @@ -193,7 +193,7 @@ protected: { } - WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, + WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget, EventClassID aEventClassID, reasonType aReason) : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID) , acceptActivation(false) @@ -217,7 +217,7 @@ protected: public: virtual WidgetMouseEvent* AsMouseEvent() override { return this; } - WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, + WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget, reasonType aReason, contextType aContext = eNormal) : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass), acceptActivation(false), ignoreRootScrollFrame(false), @@ -316,7 +316,7 @@ protected: public: virtual WidgetDragEvent* AsDragEvent() override { return this; } - WidgetDragEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) + WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal) , userCancelled(false) , mDefaultPreventedOnContent(false) @@ -379,7 +379,7 @@ public: return this; } - WidgetMouseScrollEvent(bool aIsTrusted, uint32_t aMessage, + WidgetMouseScrollEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseScrollEventClass) @@ -439,7 +439,7 @@ private: public: virtual WidgetWheelEvent* AsWheelEvent() override { return this; } - WidgetWheelEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) + WidgetWheelEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eWheelEventClass) , deltaX(0.0) , deltaY(0.0) @@ -587,7 +587,7 @@ class WidgetPointerEvent : public WidgetMouseEvent public: virtual WidgetPointerEvent* AsPointerEvent() override { return this; } - WidgetPointerEvent(bool aIsTrusted, uint32_t aMsg, nsIWidget* w) + WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w) : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal) , width(0) , height(0) diff --git a/widget/TextEventDispatcher.cpp b/widget/TextEventDispatcher.cpp index a9bef7a425..f0fefbb2f6 100644 --- a/widget/TextEventDispatcher.cpp +++ b/widget/TextEventDispatcher.cpp @@ -248,8 +248,8 @@ TextEventDispatcher::CommitComposition(nsEventStatus& aStatus, // End current composition and make this free for other IMEs. mIsComposing = false; - uint32_t message = aCommitString ? NS_COMPOSITION_COMMIT : - NS_COMPOSITION_COMMIT_AS_IS; + EventMessage message = aCommitString ? NS_COMPOSITION_COMMIT : + NS_COMPOSITION_COMMIT_AS_IS; WidgetCompositionEvent compositionCommitEvent(true, message, widget); InitEvent(compositionCommitEvent); if (message == NS_COMPOSITION_COMMIT) { @@ -282,7 +282,7 @@ TextEventDispatcher::NotifyIME(const IMENotification& aIMENotification) bool TextEventDispatcher::DispatchKeyboardEvent( - uint32_t aMessage, + EventMessage aMessage, const WidgetKeyboardEvent& aKeyboardEvent, nsEventStatus& aStatus, DispatchTo aDispatchTo) @@ -293,7 +293,7 @@ TextEventDispatcher::DispatchKeyboardEvent( bool TextEventDispatcher::DispatchKeyboardEventInternal( - uint32_t aMessage, + EventMessage aMessage, const WidgetKeyboardEvent& aKeyboardEvent, nsEventStatus& aStatus, DispatchTo aDispatchTo, diff --git a/widget/TextEventDispatcher.h b/widget/TextEventDispatcher.h index c576376c27..8522c8cb5b 100644 --- a/widget/TextEventDispatcher.h +++ b/widget/TextEventDispatcher.h @@ -207,7 +207,7 @@ public: * @param aDispatchTo See comments of DispatchTo. * @return true if an event is dispatched. Otherwise, false. */ - bool DispatchKeyboardEvent(uint32_t aMessage, + bool DispatchKeyboardEvent(EventMessage aMessage, const WidgetKeyboardEvent& aKeyboardEvent, nsEventStatus& aStatus, DispatchTo aDispatchTo = eDispatchToParentProcess); @@ -346,7 +346,7 @@ private: * sending only one character per event. * @return true if an event is dispatched. Otherwise, false. */ - bool DispatchKeyboardEventInternal(uint32_t aMessage, + bool DispatchKeyboardEventInternal(EventMessage aMessage, const WidgetKeyboardEvent& aKeyboardEvent, nsEventStatus& aStatus, DispatchTo aDispatchTo = diff --git a/widget/TextEvents.h b/widget/TextEvents.h index 04b17f375e..881980fb98 100644 --- a/widget/TextEvents.h +++ b/widget/TextEvents.h @@ -87,7 +87,8 @@ protected: public: virtual WidgetKeyboardEvent* AsKeyboardEvent() override { return this; } - WidgetKeyboardEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, + WidgetKeyboardEvent(bool aIsTrusted, EventMessage aMessage, + nsIWidget* aWidget, EventClassID aEventClassID = eKeyboardEventClass) : WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID) , keyCode(0) @@ -306,9 +307,10 @@ public: return this; } - InternalBeforeAfterKeyboardEvent(bool aIsTrusted, uint32_t aMessage, + InternalBeforeAfterKeyboardEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) - : WidgetKeyboardEvent(aIsTrusted, aMessage, aWidget, eBeforeAfterKeyboardEventClass) + : WidgetKeyboardEvent(aIsTrusted, aMessage, aWidget, + eBeforeAfterKeyboardEventClass) { } @@ -360,7 +362,7 @@ public: return this; } - WidgetCompositionEvent(bool aIsTrusted, uint32_t aMessage, + WidgetCompositionEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eCompositionEventClass) { @@ -410,6 +412,15 @@ public: return mRanges ? mRanges->TargetClauseOffset() : 0; } + uint32_t TargetClauseLength() const + { + uint32_t length = UINT32_MAX; + if (mRanges) { + length = mRanges->TargetClauseLength(); + } + return length == UINT32_MAX ? mData.Length() : length; + } + uint32_t RangeCount() const { return mRanges ? mRanges->Length() : 0; @@ -451,7 +462,7 @@ public: return this; } - WidgetQueryContentEvent(bool aIsTrusted, uint32_t aMessage, + WidgetQueryContentEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eQueryContentEventClass) , mSucceeded(false) @@ -615,7 +626,8 @@ public: return this; } - WidgetSelectionEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) + WidgetSelectionEvent(bool aIsTrusted, EventMessage aMessage, + nsIWidget* aWidget) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eSelectionEventClass) , mOffset(0) , mLength(0) @@ -667,7 +679,7 @@ public: return this; } - InternalEditorInputEvent(bool aIsTrusted, uint32_t aMessage, + InternalEditorInputEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : InternalUIEvent(aIsTrusted, aMessage, aWidget, eEditorInputEventClass) , mIsComposing(false) diff --git a/widget/TextRange.h b/widget/TextRange.h index 0885e2c411..122cde91a7 100644 --- a/widget/TextRange.h +++ b/widget/TextRange.h @@ -197,18 +197,32 @@ class TextRangeArray final : public nsAutoTArray NS_INLINE_DECL_REFCOUNTING(TextRangeArray) - // Returns target clase offset. If there are selected clauses, this returns - // the first selected clause offset. Otherwise, 0. - uint32_t TargetClauseOffset() const + const TextRange* GetTargetClause() const { for (uint32_t i = 0; i < Length(); ++i) { const TextRange& range = ElementAt(i); if (range.mRangeType == NS_TEXTRANGE_SELECTEDRAWTEXT || range.mRangeType == NS_TEXTRANGE_SELECTEDCONVERTEDTEXT) { - return range.mStartOffset; + return ⦥ } } - return 0; + return nullptr; + } + + // Returns target clause offset. If there are selected clauses, this returns + // the first selected clause offset. Otherwise, 0. + uint32_t TargetClauseOffset() const + { + const TextRange* range = GetTargetClause(); + return range ? range->mStartOffset : 0; + } + + // Returns target clause length. If there are selected clauses, this returns + // the first selected clause length. Otherwise, UINT32_MAX. + uint32_t TargetClauseLength() const + { + const TextRange* range = GetTargetClause(); + return range ? range->Length() : UINT32_MAX; } public: diff --git a/widget/TouchEvents.h b/widget/TouchEvents.h index 81a06a3fed..20c0eeb588 100644 --- a/widget/TouchEvents.h +++ b/widget/TouchEvents.h @@ -36,7 +36,7 @@ public: return this; } - WidgetGestureNotifyEvent(bool aIsTrusted, uint32_t aMessage, + WidgetGestureNotifyEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget *aWidget) : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eGestureNotifyEventClass) , panDirection(ePanNone) @@ -94,7 +94,7 @@ public: return this; } - WidgetSimpleGestureEvent(bool aIsTrusted, uint32_t aMessage, + WidgetSimpleGestureEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eSimpleGestureEventClass) @@ -177,7 +177,7 @@ public: MOZ_COUNT_CTOR(WidgetTouchEvent); } - WidgetTouchEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) + WidgetTouchEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget) : WidgetInputEvent(aIsTrusted, aMessage, aWidget, eTouchEventClass) { MOZ_COUNT_CTOR(WidgetTouchEvent); diff --git a/widget/cocoa/TextInputHandler.mm b/widget/cocoa/TextInputHandler.mm index 13759a5e9d..1c335f75c3 100644 --- a/widget/cocoa/TextInputHandler.mm +++ b/widget/cocoa/TextInputHandler.mm @@ -2006,7 +2006,7 @@ TextInputHandler::DispatchKeyEventForFlagsChanged(NSEvent* aNativeEvent, return; } - uint32_t message = aDispatchKeyDown ? NS_KEY_DOWN : NS_KEY_UP; + EventMessage message = aDispatchKeyDown ? NS_KEY_DOWN : NS_KEY_UP; // Fire a key event. WidgetKeyboardEvent keyEvent(true, message, mWidget); @@ -2740,7 +2740,7 @@ IMEInputHandler::DispatchCompositionCommitEvent(const nsAString* aCommitString) nsRefPtr kungFuDeathGrip(this); - uint32_t message = + EventMessage message = aCommitString ? NS_COMPOSITION_COMMIT : NS_COMPOSITION_COMMIT_AS_IS; WidgetCompositionEvent compositionCommitEvent(true, message, mWidget); compositionCommitEvent.time = PR_IntervalNow(); diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index b4dc41acd7..dc429177bd 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -262,7 +262,7 @@ typedef NSInteger NSEventGestureAxis; // Stop NSView hierarchy being changed during [ChildView drawRect:] - (void)delayedTearDown; -- (void)sendFocusEvent:(uint32_t)eventType; +- (void)sendFocusEvent:(mozilla::EventMessage)eventMessage; - (void)handleMouseMoved:(NSEvent*)aEvent; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index fa888acbdf..3562c3faf0 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -3299,13 +3299,13 @@ NSEvent* gLastDragMouseDownEvent = nil; return [[self window] isOpaque]; } -- (void)sendFocusEvent:(uint32_t)eventType +- (void)sendFocusEvent:(EventMessage)eventMessage { if (!mGeckoChild) return; nsEventStatus status = nsEventStatus_eIgnore; - WidgetGUIEvent focusGuiEvent(true, eventType, mGeckoChild); + WidgetGUIEvent focusGuiEvent(true, eventMessage, mGeckoChild); focusGuiEvent.time = PR_IntervalNow(); mGeckoChild->DispatchEvent(&focusGuiEvent, status); } @@ -4020,7 +4020,7 @@ NSEvent* gLastDragMouseDownEvent = nil; float deltaZ = [anEvent deltaZ]; - uint32_t msg; + EventMessage msg; switch (mGestureState) { case eGestureState_StartGesture: msg = NS_SIMPLE_GESTURE_MAGNIFY_START; @@ -4087,7 +4087,7 @@ NSEvent* gLastDragMouseDownEvent = nil; float rotation = [anEvent rotation]; - uint32_t msg; + EventMessage msg; switch (mGestureState) { case eGestureState_StartGesture: msg = NS_SIMPLE_GESTURE_ROTATE_START; @@ -4201,7 +4201,7 @@ NSEvent* gLastDragMouseDownEvent = nil; #ifdef __LP64__ - (bool)sendSwipeEvent:(NSEvent*)aEvent - withKind:(uint32_t)aMsg + withKind:(EventMessage)aMsg allowedDirections:(uint32_t*)aAllowedDirections direction:(uint32_t)aDirection delta:(double)aDelta @@ -4544,7 +4544,7 @@ NSEvent* gLastDragMouseDownEvent = nil; else geckoEvent.button = WidgetMouseEvent::eLeftButton; - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); mBlockedLastMouseDown = NO; // XXX maybe call markedTextSelectionChanged:client: here? @@ -4570,7 +4570,8 @@ NSEvent* gLastDragMouseDownEvent = nil; geckoEvent.button = WidgetMouseEvent::eLeftButton; // This might destroy our widget (and null out mGeckoChild). - bool defaultPrevented = mGeckoChild->DispatchWindowEvent(geckoEvent); + bool defaultPrevented = + (mGeckoChild->DispatchInputEvent(&geckoEvent) == nsEventStatus_eConsumeNoDefault); // Check to see if we are double-clicking in the titlebar. CGFloat locationInTitlebar = [[self window] frame].size.height - [theEvent locationInWindow].y; @@ -4601,7 +4602,7 @@ NSEvent* gLastDragMouseDownEvent = nil; NSPoint windowEventLocation = nsCocoaUtils::EventLocationForWindow(aEvent, [self window]); NSPoint localEventLocation = [self convertPoint:windowEventLocation fromView:nil]; - uint32_t msg = aEnter ? NS_MOUSE_ENTER_WIDGET : NS_MOUSE_EXIT_WIDGET; + EventMessage msg = aEnter ? NS_MOUSE_ENTER_WIDGET : NS_MOUSE_EXIT_WIDGET; WidgetMouseEvent event(true, msg, mGeckoChild, WidgetMouseEvent::eReal); event.refPoint = LayoutDeviceIntPoint::FromUntyped( mGeckoChild->CocoaPointsToDevPixels(localEventLocation)); @@ -4696,7 +4697,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); NS_OBJC_END_TRY_ABORT_BLOCK; } @@ -4714,7 +4715,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); // Note, sending the above event might have destroyed our widget since we didn't retain. // Fine so long as we don't access any local variables from here on. @@ -4742,7 +4743,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, geckoEvent.button = WidgetMouseEvent::eRightButton; geckoEvent.clickCount = [theEvent clickCount]; - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); if (!mGeckoChild) return; @@ -4766,7 +4767,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, geckoEvent.clickCount = [theEvent clickCount]; nsAutoRetainCocoaObject kungFuDeathGrip(self); - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); NS_OBJC_END_TRY_ABORT_BLOCK; } @@ -4783,7 +4784,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, // send event into Gecko by going directly to the // the widget. - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); } - (void)otherMouseDown:(NSEvent *)theEvent @@ -4805,7 +4806,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, geckoEvent.button = WidgetMouseEvent::eMiddleButton; geckoEvent.clickCount = [theEvent clickCount]; - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); NS_OBJC_END_TRY_ABORT_BLOCK; } @@ -4821,7 +4822,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, geckoEvent.button = WidgetMouseEvent::eMiddleButton; nsAutoRetainCocoaObject kungFuDeathGrip(self); - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); } - (void)otherMouseDragged:(NSEvent*)theEvent @@ -4836,7 +4837,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, // send event into Gecko by going directly to the // the widget. - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); } static int32_t RoundUp(double aDouble) @@ -4845,15 +4846,18 @@ static int32_t RoundUp(double aDouble) static_cast(ceil(aDouble)); } -- (void)sendWheelStartOrStop:(uint32_t)msg forEvent:(NSEvent *)theEvent +- (void)sendWheelStartOrStop:(EventMessage)msg forEvent:(NSEvent *)theEvent { WidgetWheelEvent wheelEvent(true, msg, mGeckoChild); [self convertCocoaMouseWheelEvent:theEvent toGeckoEvent:&wheelEvent]; mExpectingWheelStop = (msg == NS_WHEEL_START); - mGeckoChild->DispatchWindowEvent(wheelEvent); + mGeckoChild->DispatchAPZAwareEvent(wheelEvent.AsInputEvent()); } -- (void)sendWheelCondition:(BOOL)condition first:(uint32_t)first second:(uint32_t)second forEvent:(NSEvent *)theEvent +- (void)sendWheelCondition:(BOOL)condition + first:(EventMessage)first + second:(EventMessage)second + forEvent:(NSEvent *)theEvent { if (mExpectingWheelStop == condition) { [self sendWheelStartOrStop:first forEvent:theEvent]; @@ -5065,7 +5069,7 @@ static int32_t RoundUp(double aDouble) WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; geckoEvent.button = WidgetMouseEvent::eRightButton; - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); if (!mGeckoChild) return nil; @@ -5513,7 +5517,7 @@ static int32_t RoundUp(double aDouble) WidgetMouseEvent geckoEvent(true, NS_MOUSE_ACTIVATE, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:aEvent toGeckoEvent:&geckoEvent]; - return !mGeckoChild->DispatchWindowEvent(geckoEvent); + return (mGeckoChild->DispatchInputEvent(&geckoEvent) != nsEventStatus_eConsumeNoDefault); } // We must always call through to our superclass, even when mGeckoChild is @@ -5590,15 +5594,13 @@ static int32_t RoundUp(double aDouble) // drag'n'drop stuff #define kDragServiceContractID "@mozilla.org/widget/dragservice;1" -- (NSDragOperation)dragOperationForSession:(nsIDragSession*)aDragSession +- (NSDragOperation)dragOperationFromDragAction:(int32_t)aDragAction { - uint32_t dragAction; - aDragSession->GetDragAction(&dragAction); - if (nsIDragService::DRAGDROP_ACTION_LINK & dragAction) + if (nsIDragService::DRAGDROP_ACTION_LINK & aDragAction) return NSDragOperationLink; - if (nsIDragService::DRAGDROP_ACTION_COPY & dragAction) + if (nsIDragService::DRAGDROP_ACTION_COPY & aDragAction) return NSDragOperationCopy; - if (nsIDragService::DRAGDROP_ACTION_MOVE & dragAction) + if (nsIDragService::DRAGDROP_ACTION_MOVE & aDragAction) return NSDragOperationGeneric; return NSDragOperationNone; } @@ -5621,7 +5623,7 @@ static int32_t RoundUp(double aDouble) // This is a utility function used by NSView drag event methods // to send events. It contains all of the logic needed for Gecko // dragging to work. Returns the appropriate cocoa drag operation code. -- (NSDragOperation)doDragAction:(uint32_t)aMessage sender:(id)aSender +- (NSDragOperation)doDragAction:(EventMessage)aMessage sender:(id)aSender { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; @@ -5689,7 +5691,7 @@ static int32_t RoundUp(double aDouble) [self convertWindowCoordinates:draggingLoc]); nsAutoRetainCocoaObject kungFuDeathGrip(self); - mGeckoChild->DispatchWindowEvent(geckoEvent); + mGeckoChild->DispatchInputEvent(&geckoEvent); if (!mGeckoChild) return NSDragOperationNone; @@ -5697,7 +5699,22 @@ static int32_t RoundUp(double aDouble) switch (aMessage) { case NS_DRAGDROP_ENTER: case NS_DRAGDROP_OVER: - return [self dragOperationForSession:dragSession]; + { + uint32_t dragAction; + dragSession->GetDragAction(&dragAction); + + // If TakeChildProcessDragAction returns something other than + // DRAGDROP_ACTION_UNINITIALIZED, it means that the last event was sent + // to the child process and this event is also being sent to the child + // process. In this case, use the last event's action instead. + nsDragService* dragService = static_cast(mDragService); + int32_t childDragAction = dragService->TakeChildProcessDragAction(); + if (childDragAction != nsIDragService::DRAGDROP_ACTION_UNINITIALIZED) { + dragAction = childDragAction; + } + + return [self dragOperationFromDragAction:dragAction]; + } case NS_DRAGDROP_EXIT: case NS_DRAGDROP_DROP: { nsCOMPtr sourceNode; @@ -5710,6 +5727,8 @@ static int32_t RoundUp(double aDouble) mDragService->EndDragSession(false); } } + default: + break; } } diff --git a/widget/gonk/nsAppShell.cpp b/widget/gonk/nsAppShell.cpp index f71e01e033..5cf62dc22a 100644 --- a/widget/gonk/nsAppShell.cpp +++ b/widget/gonk/nsAppShell.cpp @@ -242,7 +242,7 @@ private: void DispatchKeyDownEvent(); void DispatchKeyUpEvent(); - nsEventStatus DispatchKeyEventInternal(uint32_t aEventMessage); + nsEventStatus DispatchKeyEventInternal(EventMessage aEventMessage); }; KeyEventDispatcher::KeyEventDispatcher(const UserInputData& aData, @@ -294,7 +294,7 @@ KeyEventDispatcher::PrintableKeyValue() const } nsEventStatus -KeyEventDispatcher::DispatchKeyEventInternal(uint32_t aEventMessage) +KeyEventDispatcher::DispatchKeyEventInternal(EventMessage aEventMessage) { WidgetKeyboardEvent event(true, aEventMessage, nullptr); if (aEventMessage == NS_KEY_PRESS) { diff --git a/widget/gtk/IMContextWrapper.cpp b/widget/gtk/IMContextWrapper.cpp index 3ce561bed9..95f630c209 100644 --- a/widget/gtk/IMContextWrapper.cpp +++ b/widget/gtk/IMContextWrapper.cpp @@ -1365,8 +1365,8 @@ IMContextWrapper::DispatchCompositionCommitEvent( nsRefPtr lastFocusedWindow(mLastFocusedWindow); - uint32_t message = aCommitString ? NS_COMPOSITION_COMMIT : - NS_COMPOSITION_COMMIT_AS_IS; + EventMessage message = aCommitString ? NS_COMPOSITION_COMMIT : + NS_COMPOSITION_COMMIT_AS_IS; mCompositionState = eCompositionState_NotComposing; mCompositionStart = UINT32_MAX; mCompositionTargetRange.Clear(); diff --git a/widget/gtk/nsDragService.cpp b/widget/gtk/nsDragService.cpp index 4934b537f7..b874037ece 100644 --- a/widget/gtk/nsDragService.cpp +++ b/widget/gtk/nsDragService.cpp @@ -2007,7 +2007,7 @@ nsDragService::DispatchDropEvent() if (mTargetWindow->IsDestroyed()) return FALSE; - uint32_t msg = mCanDrop ? NS_DRAGDROP_DROP : NS_DRAGDROP_EXIT; + EventMessage msg = mCanDrop ? NS_DRAGDROP_DROP : NS_DRAGDROP_EXIT; mTargetWindow->DispatchDragEvent(msg, mTargetWindowPoint, mTargetTime); diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 48e49946fa..6b537a2e80 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -2849,7 +2849,7 @@ nsWindow::DispatchCommandEvent(nsIAtom* aCommand) } bool -nsWindow::DispatchContentCommandEvent(int32_t aMsg) +nsWindow::DispatchContentCommandEvent(EventMessage aMsg) { nsEventStatus status; WidgetContentCommandEvent event(true, aMsg, this); @@ -3245,7 +3245,7 @@ nsWindow::ThemeChanged() } void -nsWindow::DispatchDragEvent(uint32_t aMsg, const nsIntPoint& aRefPoint, +nsWindow::DispatchDragEvent(EventMessage aMsg, const nsIntPoint& aRefPoint, guint aTime) { WidgetDragEvent event(true, aMsg, this); diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index 4016f788e7..f97a73cc78 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -249,7 +249,7 @@ public: GdkWindow* GetGdkWindow() { return mGdkWindow; } bool IsDestroyed() { return mIsDestroyed; } - void DispatchDragEvent(uint32_t aMsg, + void DispatchDragEvent(mozilla::EventMessage aMsg, const nsIntPoint& aRefPoint, guint aTime); static void UpdateDragStatus (GdkDragContext *aDragContext, @@ -357,7 +357,7 @@ private: void InitButtonEvent(mozilla::WidgetMouseEvent& aEvent, GdkEventButton* aGdkEvent); bool DispatchCommandEvent(nsIAtom* aCommand); - bool DispatchContentCommandEvent(int32_t aMsg); + bool DispatchContentCommandEvent(mozilla::EventMessage aMsg); bool CheckForRollup(gdouble aMouseX, gdouble aMouseY, bool aIsWheel, bool aAlwaysRollup); bool GetDragInfo(mozilla::WidgetMouseEvent* aMouseEvent, diff --git a/widget/nsBaseDragService.cpp b/widget/nsBaseDragService.cpp index bb8333398d..a34d137e84 100644 --- a/widget/nsBaseDragService.cpp +++ b/widget/nsBaseDragService.cpp @@ -55,7 +55,8 @@ nsBaseDragService::nsBaseDragService() : mCanDrop(false), mOnlyChromeDrop(false), mDoingDrag(false), mHasImage(false), mUserCancelled(false), mDragEventDispatchedToChildProcess(false), - mDragAction(DRAGDROP_ACTION_NONE), mTargetSize(0,0), + mDragAction(DRAGDROP_ACTION_NONE), + mDragActionFromChildProcess(DRAGDROP_ACTION_UNINITIALIZED), mTargetSize(0,0), mImageX(0), mImageY(0), mScreenX(-1), mScreenY(-1), mSuppressLevel(0), mInputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE), mEndingSession(false) @@ -333,6 +334,21 @@ nsBaseDragService::OpenDragPopup() } } +int32_t +nsBaseDragService::TakeChildProcessDragAction() +{ + // If the last event was dispatched to the child process, use the drag action + // assigned from it instead and return it. DRAGDROP_ACTION_UNINITIALIZED is + // returned otherwise. + int32_t retval = DRAGDROP_ACTION_UNINITIALIZED; + if (TakeDragEventDispatchedToChildProcess() && + mDragActionFromChildProcess != DRAGDROP_ACTION_UNINITIALIZED) { + retval = mDragActionFromChildProcess; + } + + return retval; +} + //------------------------------------------------------------------------- NS_IMETHODIMP nsBaseDragService::EndDragSession(bool aDoneDrag) @@ -391,7 +407,7 @@ nsBaseDragService::FireDragEventAtSource(uint32_t aMsg) nsCOMPtr presShell = doc->GetShell(); if (presShell) { nsEventStatus status = nsEventStatus_eIgnore; - WidgetDragEvent event(true, aMsg, nullptr); + WidgetDragEvent event(true, static_cast(aMsg), nullptr); event.inputSource = mInputSource; if (aMsg == NS_DRAGDROP_END) { event.refPoint.x = mEndDragPoint.x; @@ -722,6 +738,7 @@ nsBaseDragService::UserCancelled() NS_IMETHODIMP nsBaseDragService::UpdateDragEffect() { + mDragActionFromChildProcess = mDragAction; return NS_OK; } diff --git a/widget/nsBaseDragService.h b/widget/nsBaseDragService.h index bccc9b71ae..faf65a8a6e 100644 --- a/widget/nsBaseDragService.h +++ b/widget/nsBaseDragService.h @@ -57,6 +57,8 @@ public: uint16_t GetInputSource() { return mInputSource; } + int32_t TakeChildProcessDragAction(); + protected: virtual ~nsBaseDragService(); @@ -135,6 +137,8 @@ protected: bool mDragEventDispatchedToChildProcess; uint32_t mDragAction; + uint32_t mDragActionFromChildProcess; + nsSize mTargetSize; nsCOMPtr mSourceNode; nsCOMPtr mSourceDocument; // the document at the drag source. will be null diff --git a/widget/nsGUIEventIPC.h b/widget/nsGUIEventIPC.h index c969d6022b..b5462dc83d 100644 --- a/widget/nsGUIEventIPC.h +++ b/widget/nsGUIEventIPC.h @@ -18,6 +18,25 @@ namespace IPC { +template<> +struct ParamTraits +{ + typedef mozilla::EventMessage paramType; + + static void Write(Message* aMsg, const paramType& aParam) + { + WriteParam(aMsg, static_cast(aParam)); + } + + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) + { + mozilla::EventMessageType eventMessage = 0; + bool ret = ReadParam(aMsg, aIter, &eventMessage); + *aResult = static_cast(eventMessage); + return ret; + } +}; + template<> struct ParamTraits { diff --git a/widget/windows/nsIMM32Handler.cpp b/widget/windows/IMMHandler.cpp similarity index 66% rename from widget/windows/nsIMM32Handler.cpp rename to widget/windows/IMMHandler.cpp index 41dfcf9dba..80660db5cb 100644 --- a/widget/windows/nsIMM32Handler.cpp +++ b/widget/windows/IMMHandler.cpp @@ -6,7 +6,7 @@ #include "mozilla/Logging.h" -#include "nsIMM32Handler.h" +#include "IMMHandler.h" #include "nsWindow.h" #include "nsWindowDefs.h" #include "WinUtils.h" @@ -21,12 +21,21 @@ #define IME_PROP_ACCEPT_WIDE_VKEY 0x20 #endif -using namespace mozilla; -using namespace mozilla::widget; +//------------------------------------------------------------------------- +// +// from http://download.microsoft.com/download/6/0/9/60908e9e-d2c1-47db-98f6-216af76a235f/msime.h +// The document for this has been removed from MSDN... +// +//------------------------------------------------------------------------- -static nsIMM32Handler* gIMM32Handler = nullptr; +#define RWM_MOUSE TEXT("MSIMEMouseOperation") -PRLogModuleInfo* gIMM32Log = nullptr; +#define IMEMOUSE_NONE 0x00 // no mouse button was pushed +#define IMEMOUSE_LDOWN 0x01 +#define IMEMOUSE_RDOWN 0x02 +#define IMEMOUSE_MDOWN 0x04 +#define IMEMOUSE_WUP 0x10 // wheel up +#define IMEMOUSE_WDOWN 0x20 // wheel down static const char* GetBoolName(bool aBool) @@ -120,46 +129,93 @@ public: virtual ~GetWritingModeName() {} }; +class GetReconvertStringLog : public nsAutoCString +{ +public: + GetReconvertStringLog(RECONVERTSTRING* aReconv) + { + AssignLiteral("{ dwSize="); + AppendInt(static_cast(aReconv->dwSize)); + AppendLiteral(", dwVersion="); + AppendInt(static_cast(aReconv->dwVersion)); + AppendLiteral(", dwStrLen="); + AppendInt(static_cast(aReconv->dwStrLen)); + AppendLiteral(", dwStrOffset="); + AppendInt(static_cast(aReconv->dwStrOffset)); + AppendLiteral(", dwCompStrLen="); + AppendInt(static_cast(aReconv->dwCompStrLen)); + AppendLiteral(", dwCompStrOffset="); + AppendInt(static_cast(aReconv->dwCompStrOffset)); + AppendLiteral(", dwTargetStrLen="); + AppendInt(static_cast(aReconv->dwTargetStrLen)); + AppendLiteral(", dwTargetStrOffset="); + AppendInt(static_cast(aReconv->dwTargetStrOffset)); + AppendLiteral(", result str=\""); + if (aReconv->dwStrLen) { + char16_t* strStart = + reinterpret_cast( + reinterpret_cast(aReconv) + aReconv->dwStrOffset); + nsDependentString str(strStart, aReconv->dwStrLen); + Append(NS_ConvertUTF16toUTF8(str)); + } + AppendLiteral("\" }"); + } + virtual ~GetReconvertStringLog() {} +}; + +namespace mozilla { +namespace widget { + +static IMMHandler* gIMMHandler = nullptr; + +PRLogModuleInfo* gIMMLog = nullptr; + +/****************************************************************************** + * IMEContext + ******************************************************************************/ + +IMEContext::IMEContext(HWND aWnd) + : mWnd(aWnd) + , mIMC(::ImmGetContext(aWnd)) +{ +} + +IMEContext::IMEContext(nsWindow* aWindow) + : mWnd(aWindow->GetWindowHandle()) + , mIMC(::ImmGetContext(aWindow->GetWindowHandle())) +{ +} + +/****************************************************************************** + * IMMHandler + ******************************************************************************/ + static UINT sWM_MSIME_MOUSE = 0; // mouse message for MSIME 98/2000 -//------------------------------------------------------------------------- -// -// from http://download.microsoft.com/download/6/0/9/60908e9e-d2c1-47db-98f6-216af76a235f/msime.h -// The document for this has been removed from MSDN... -// -//------------------------------------------------------------------------- +WritingMode IMMHandler::sWritingModeOfCompositionFont; +nsString IMMHandler::sIMEName; +UINT IMMHandler::sCodePage = 0; +DWORD IMMHandler::sIMEProperty = 0; +DWORD IMMHandler::sIMEUIProperty = 0; +bool IMMHandler::sAssumeVerticalWritingModeNotSupported = false; +bool IMMHandler::sHasFocus = false; -#define RWM_MOUSE TEXT("MSIMEMouseOperation") - -#define IMEMOUSE_NONE 0x00 // no mouse button was pushed -#define IMEMOUSE_LDOWN 0x01 -#define IMEMOUSE_RDOWN 0x02 -#define IMEMOUSE_MDOWN 0x04 -#define IMEMOUSE_WUP 0x10 // wheel up -#define IMEMOUSE_WDOWN 0x20 // wheel down - -WritingMode nsIMM32Handler::sWritingModeOfCompositionFont; -nsString nsIMM32Handler::sIMEName; -UINT nsIMM32Handler::sCodePage = 0; -DWORD nsIMM32Handler::sIMEProperty = 0; -DWORD nsIMM32Handler::sIMEUIProperty = 0; -bool nsIMM32Handler::sAssumeVerticalWritingModeNotSupported = false; -bool nsIMM32Handler::sHasFocus = false; - -/* static */ void -nsIMM32Handler::EnsureHandlerInstance() +// static +void +IMMHandler::EnsureHandlerInstance() { - if (!gIMM32Handler) { - gIMM32Handler = new nsIMM32Handler(); + if (!gIMMHandler) { + gIMMHandler = new IMMHandler(); } } -/* static */ void -nsIMM32Handler::Initialize() +// static +void +IMMHandler::Initialize() { - if (!gIMM32Log) - gIMM32Log = PR_NewLogModule("nsIMM32HandlerWidgets"); - + if (!gIMMLog) { + gIMMLog = PR_NewLogModule("nsIMM32HandlerWidgets"); + } if (!sWM_MSIME_MOUSE) { sWM_MSIME_MOUSE = ::RegisterWindowMessage(RWM_MOUSE); } @@ -169,52 +225,58 @@ nsIMM32Handler::Initialize() InitKeyboardLayout(nullptr, ::GetKeyboardLayout(0)); } -/* static */ void -nsIMM32Handler::Terminate() +// static +void +IMMHandler::Terminate() { - if (!gIMM32Handler) + if (!gIMMHandler) return; - delete gIMM32Handler; - gIMM32Handler = nullptr; + delete gIMMHandler; + gIMMHandler = nullptr; } -/* static */ bool -nsIMM32Handler::IsComposingOnOurEditor() +// static +bool +IMMHandler::IsComposingOnOurEditor() { - return gIMM32Handler && gIMM32Handler->mIsComposing; + return gIMMHandler && gIMMHandler->mIsComposing; } -/* static */ bool -nsIMM32Handler::IsComposingOnPlugin() +// static +bool +IMMHandler::IsComposingOnPlugin() { - return gIMM32Handler && gIMM32Handler->mIsComposingOnPlugin; + return gIMMHandler && gIMMHandler->mIsComposingOnPlugin; } -/* static */ bool -nsIMM32Handler::IsComposingWindow(nsWindow* aWindow) +// static +bool +IMMHandler::IsComposingWindow(nsWindow* aWindow) { - return gIMM32Handler && gIMM32Handler->mComposingWindow == aWindow; + return gIMMHandler && gIMMHandler->mComposingWindow == aWindow; } -/* static */ bool -nsIMM32Handler::IsTopLevelWindowOfComposition(nsWindow* aWindow) +// static +bool +IMMHandler::IsTopLevelWindowOfComposition(nsWindow* aWindow) { - if (!gIMM32Handler || !gIMM32Handler->mComposingWindow) { + if (!gIMMHandler || !gIMMHandler->mComposingWindow) { return false; } - HWND wnd = gIMM32Handler->mComposingWindow->GetWindowHandle(); + HWND wnd = gIMMHandler->mComposingWindow->GetWindowHandle(); return WinUtils::GetTopLevelHWND(wnd, true) == aWindow->GetWindowHandle(); } -/* static */ +// static bool -nsIMM32Handler::IsJapanist2003Active() +IMMHandler::IsJapanist2003Active() { return sIMEName.EqualsLiteral("Japanist 2003"); } -/* static */ bool -nsIMM32Handler::IsGoogleJapaneseInputActive() +// static +bool +IMMHandler::IsGoogleJapaneseInputActive() { // NOTE: Even on Windows for en-US, the name of Google Japanese Input is // written in Japanese. @@ -222,8 +284,9 @@ nsIMM32Handler::IsGoogleJapaneseInputActive() L"IMM32 \x30E2\x30B8\x30E5\x30FC\x30EB"); } -/* static */ bool -nsIMM32Handler::ShouldDrawCompositionStringOurselves() +// static +bool +IMMHandler::ShouldDrawCompositionStringOurselves() { // If current IME has special UI or its composition window should not // positioned to caret position, we should now draw composition string @@ -232,8 +295,9 @@ nsIMM32Handler::ShouldDrawCompositionStringOurselves() (sIMEProperty & IME_PROP_AT_CARET); } -/* static */ bool -nsIMM32Handler::IsVerticalWritingSupported() +// static +bool +IMMHandler::IsVerticalWritingSupported() { // Even if IME claims that they support vertical writing mode but it may not // support vertical writing mode for its candidate window. @@ -248,9 +312,10 @@ nsIMM32Handler::IsVerticalWritingSupported() return !!(sIMEUIProperty & (UI_CAP_2700 | UI_CAP_ROT90 | UI_CAP_ROTANY)); } -/* static */ void -nsIMM32Handler::InitKeyboardLayout(nsWindow* aWindow, - HKL aKeyboardLayout) +// static +void +IMMHandler::InitKeyboardLayout(nsWindow* aWindow, + HKL aKeyboardLayout) { UINT IMENameLength = ::ImmGetDescriptionW(aKeyboardLayout, nullptr, 0); if (IMENameLength) { @@ -287,23 +352,24 @@ nsIMM32Handler::InitKeyboardLayout(nsWindow* aWindow, MaybeAdjustCompositionFont(aWindow, sWritingModeOfCompositionFont, true); } - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: InitKeyboardLayout, aKeyboardLayout=%08x (\"%s\"), sCodePage=%lu, " + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: InitKeyboardLayout, aKeyboardLayout=%08x (\"%s\"), sCodePage=%lu, " "sIMEProperty=%s, sIMEUIProperty=%s", aKeyboardLayout, NS_ConvertUTF16toUTF8(sIMEName).get(), sCodePage, GetIMEGeneralPropertyName(sIMEProperty).get(), GetIMEUIPropertyName(sIMEUIProperty).get())); } -/* static */ UINT -nsIMM32Handler::GetKeyboardCodePage() +// static +UINT +IMMHandler::GetKeyboardCodePage() { return sCodePage; } -/* static */ +// static nsIMEUpdatePreference -nsIMM32Handler::GetIMEUpdatePreference() +IMMHandler::GetIMEUpdatePreference() { return nsIMEUpdatePreference( nsIMEUpdatePreference::NOTIFY_POSITION_CHANGE | @@ -319,25 +385,28 @@ nsIMM32Handler::GetIMEUpdatePreference() // then, we should not set caret position to compositionchange event. #define NO_IME_CARET -1 -nsIMM32Handler::nsIMM32Handler() : - mComposingWindow(nullptr), mCursorPosition(NO_IME_CARET), mCompositionStart(0), - mIsComposing(false), mIsComposingOnPlugin(false), - mNativeCaretIsCreated(false) +IMMHandler::IMMHandler() + : mComposingWindow(nullptr) + , mCursorPosition(NO_IME_CARET) + , mCompositionStart(0) + , mIsComposing(false) + , mIsComposingOnPlugin(false) + , mNativeCaretIsCreated(false) { - MOZ_LOG(gIMM32Log, LogLevel::Info, ("IMM32: nsIMM32Handler is created\n")); + MOZ_LOG(gIMMLog, LogLevel::Debug, ("IMM: IMMHandler is created")); } -nsIMM32Handler::~nsIMM32Handler() +IMMHandler::~IMMHandler() { if (mIsComposing) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: ~nsIMM32Handler, ERROR, the instance is still composing\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: ~IMMHandler, ERROR, the instance is still composing")); } - MOZ_LOG(gIMM32Log, LogLevel::Info, ("IMM32: nsIMM32Handler is destroyed\n")); + MOZ_LOG(gIMMLog, LogLevel::Debug, ("IMM: IMMHandler is destroyed")); } nsresult -nsIMM32Handler::EnsureClauseArray(int32_t aCount) +IMMHandler::EnsureClauseArray(int32_t aCount) { NS_ENSURE_ARG_MIN(aCount, 0); mClauseArray.SetCapacity(aCount + 32); @@ -345,93 +414,95 @@ nsIMM32Handler::EnsureClauseArray(int32_t aCount) } nsresult -nsIMM32Handler::EnsureAttributeArray(int32_t aCount) +IMMHandler::EnsureAttributeArray(int32_t aCount) { NS_ENSURE_ARG_MIN(aCount, 0); mAttributeArray.SetCapacity(aCount + 64); return NS_OK; } -/* static */ void -nsIMM32Handler::CommitComposition(nsWindow* aWindow, bool aForce) +// static +void +IMMHandler::CommitComposition(nsWindow* aWindow, bool aForce) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CommitComposition, aForce=%s, aWindow=%p, hWnd=%08x, mComposingWindow=%p%s\n", - aForce ? "TRUE" : "FALSE", - aWindow, aWindow->GetWindowHandle(), - gIMM32Handler ? gIMM32Handler->mComposingWindow : nullptr, - gIMM32Handler && gIMM32Handler->mComposingWindow ? + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CommitComposition, aForce=%s, aWindow=%p, hWnd=%08x, " + "mComposingWindow=%p%s", + GetBoolName(aForce), aWindow, aWindow->GetWindowHandle(), + gIMMHandler ? gIMMHandler->mComposingWindow : nullptr, + gIMMHandler && gIMMHandler->mComposingWindow ? IsComposingOnOurEditor() ? " (composing on editor)" : " (composing on plug-in)" : "")); if (!aForce && !IsComposingWindow(aWindow)) { return; } - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - bool associated = IMEContext.AssociateDefaultContext(); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CommitComposition, associated=%s\n", - associated ? "YES" : "NO")); + IMEContext context(aWindow); + bool associated = context.AssociateDefaultContext(); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CommitComposition, associated=%s", + GetBoolName(associated))); - if (IMEContext.IsValid()) { - ::ImmNotifyIME(IMEContext.get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0); - ::ImmNotifyIME(IMEContext.get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0); + if (context.IsValid()) { + ::ImmNotifyIME(context.get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0); + ::ImmNotifyIME(context.get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0); } if (associated) { - IMEContext.Disassociate(); - } -} - -/* static */ void -nsIMM32Handler::CancelComposition(nsWindow* aWindow, bool aForce) -{ - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CancelComposition, aForce=%s, aWindow=%p, hWnd=%08x, mComposingWindow=%p%s\n", - aForce ? "TRUE" : "FALSE", - aWindow, aWindow->GetWindowHandle(), - gIMM32Handler ? gIMM32Handler->mComposingWindow : nullptr, - gIMM32Handler && gIMM32Handler->mComposingWindow ? - IsComposingOnOurEditor() ? " (composing on editor)" : - " (composing on plug-in)" : "")); - if (!aForce && !IsComposingWindow(aWindow)) { - return; - } - - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - bool associated = IMEContext.AssociateDefaultContext(); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CancelComposition, associated=%s\n", - associated ? "YES" : "NO")); - - if (IMEContext.IsValid()) { - ::ImmNotifyIME(IMEContext.get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0); - } - - if (associated) { - IMEContext.Disassociate(); + context.Disassociate(); } } // static void -nsIMM32Handler::OnFocusChange(bool aFocus, nsWindow* aWindow) +IMMHandler::CancelComposition(nsWindow* aWindow, bool aForce) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnFocusChange(aFocus=%s, aWindow=%p), sHasFocus=%s", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CancelComposition, aForce=%s, aWindow=%p, hWnd=%08x, " + "mComposingWindow=%p%s", + GetBoolName(aForce), aWindow, aWindow->GetWindowHandle(), + gIMMHandler ? gIMMHandler->mComposingWindow : nullptr, + gIMMHandler && gIMMHandler->mComposingWindow ? + IsComposingOnOurEditor() ? " (composing on editor)" : + " (composing on plug-in)" : "")); + if (!aForce && !IsComposingWindow(aWindow)) { + return; + } + + IMEContext context(aWindow); + bool associated = context.AssociateDefaultContext(); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CancelComposition, associated=%s", + GetBoolName(associated))); + + if (context.IsValid()) { + ::ImmNotifyIME(context.get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0); + } + + if (associated) { + context.Disassociate(); + } +} + +// static +void +IMMHandler::OnFocusChange(bool aFocus, nsWindow* aWindow) +{ + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnFocusChange(aFocus=%s, aWindow=%p), sHasFocus=%s", GetBoolName(aFocus), aWindow, GetBoolName(sHasFocus))); - if (gIMM32Handler) { - gIMM32Handler->mSelection.Clear(); + if (gIMMHandler) { + gIMMHandler->mSelection.Clear(); } sHasFocus = aFocus; } // static void -nsIMM32Handler::OnUpdateComposition(nsWindow* aWindow) +IMMHandler::OnUpdateComposition(nsWindow* aWindow) { - if (!gIMM32Handler) { + if (!gIMMHandler) { return; } @@ -439,33 +510,33 @@ nsIMM32Handler::OnUpdateComposition(nsWindow* aWindow) return; } - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - gIMM32Handler->SetIMERelatedWindowsPos(aWindow, IMEContext); + IMEContext context(aWindow); + gIMMHandler->SetIMERelatedWindowsPos(aWindow, context); } // static void -nsIMM32Handler::OnSelectionChange(nsWindow* aWindow, - const IMENotification& aIMENotification, - bool aIsIMMActive) +IMMHandler::OnSelectionChange(nsWindow* aWindow, + const IMENotification& aIMENotification, + bool aIsIMMActive) { if (!aIMENotification.mSelectionChangeData.mCausedByComposition && aIsIMMActive) { MaybeAdjustCompositionFont(aWindow, aIMENotification.mSelectionChangeData.GetWritingMode()); } - // MaybeAdjustCompositionFont() may create gIMM32Handler. So, check it + // MaybeAdjustCompositionFont() may create gIMMHandler. So, check it // after a call of MaybeAdjustCompositionFont(). - if (gIMM32Handler) { - gIMM32Handler->mSelection.Update(aIMENotification); + if (gIMMHandler) { + gIMMHandler->mSelection.Update(aIMENotification); } } // static void -nsIMM32Handler::MaybeAdjustCompositionFont(nsWindow* aWindow, - const WritingMode& aWritingMode, - bool aForceUpdate) +IMMHandler::MaybeAdjustCompositionFont(nsWindow* aWindow, + const WritingMode& aWritingMode, + bool aForceUpdate) { switch (sCodePage) { case 932: // Japanese Shift-JIS @@ -476,28 +547,29 @@ nsIMM32Handler::MaybeAdjustCompositionFont(nsWindow* aWindow, break; default: // If there is no instance of nsIMM32Hander, we shouldn't waste footprint. - if (!gIMM32Handler) { + if (!gIMMHandler) { return; } } // Like Navi-Bar of ATOK, some IMEs may require proper composition font even // before sending WM_IME_STARTCOMPOSITION. - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - gIMM32Handler->AdjustCompositionFont(IMEContext, aWritingMode, aForceUpdate); + IMEContext context(aWindow); + gIMMHandler->AdjustCompositionFont(context, aWritingMode, aForceUpdate); } -/* static */ bool -nsIMM32Handler::ProcessInputLangChangeMessage(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +// static +bool +IMMHandler::ProcessInputLangChangeMessage(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { aResult.mResult = 0; aResult.mConsumed = false; // We don't need to create the instance of the handler here. - if (gIMM32Handler) { - gIMM32Handler->OnInputLangChange(aWindow, wParam, lParam, aResult); + if (gIMMHandler) { + gIMMHandler->OnInputLangChange(aWindow, wParam, lParam, aResult); } InitKeyboardLayout(aWindow, reinterpret_cast(lParam)); // We can release the instance here, because the instance may be never @@ -508,10 +580,13 @@ nsIMM32Handler::ProcessInputLangChangeMessage(nsWindow* aWindow, return false; } -/* static */ bool -nsIMM32Handler::ProcessMessage(nsWindow* aWindow, UINT msg, - WPARAM &wParam, LPARAM &lParam, - MSGResult& aResult) +// static +bool +IMMHandler::ProcessMessage(nsWindow* aWindow, + UINT msg, + WPARAM& wParam, + LPARAM& lParam, + MSGResult& aResult) { // XXX We store the composing window in mComposingWindow. If IME messages are // sent to different window, we should commit the old transaction. And also @@ -530,20 +605,20 @@ nsIMM32Handler::ProcessMessage(nsWindow* aWindow, UINT msg, return ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult); case WM_IME_STARTCOMPOSITION: EnsureHandlerInstance(); - return gIMM32Handler->OnIMEStartComposition(aWindow, aResult); + return gIMMHandler->OnIMEStartComposition(aWindow, aResult); case WM_IME_COMPOSITION: EnsureHandlerInstance(); - return gIMM32Handler->OnIMEComposition(aWindow, wParam, lParam, aResult); + return gIMMHandler->OnIMEComposition(aWindow, wParam, lParam, aResult); case WM_IME_ENDCOMPOSITION: EnsureHandlerInstance(); - return gIMM32Handler->OnIMEEndComposition(aWindow, aResult); + return gIMMHandler->OnIMEEndComposition(aWindow, aResult); case WM_IME_CHAR: return OnIMEChar(aWindow, wParam, lParam, aResult); case WM_IME_NOTIFY: return OnIMENotify(aWindow, wParam, lParam, aResult); case WM_IME_REQUEST: EnsureHandlerInstance(); - return gIMM32Handler->OnIMERequest(aWindow, wParam, lParam, aResult); + return gIMMHandler->OnIMERequest(aWindow, wParam, lParam, aResult); case WM_IME_SELECT: return OnIMESelect(aWindow, wParam, lParam, aResult); case WM_IME_SETCONTEXT: @@ -551,19 +626,22 @@ nsIMM32Handler::ProcessMessage(nsWindow* aWindow, UINT msg, case WM_KEYDOWN: return OnKeyDownEvent(aWindow, wParam, lParam, aResult); case WM_CHAR: - if (!gIMM32Handler) { + if (!gIMMHandler) { return false; } - return gIMM32Handler->OnChar(aWindow, wParam, lParam, aResult); + return gIMMHandler->OnChar(aWindow, wParam, lParam, aResult); default: return false; }; } -/* static */ bool -nsIMM32Handler::ProcessMessageForPlugin(nsWindow* aWindow, UINT msg, - WPARAM &wParam, LPARAM &lParam, - MSGResult& aResult) +// static +bool +IMMHandler::ProcessMessageForPlugin(nsWindow* aWindow, + UINT msg, + WPARAM& wParam, + LPARAM& lParam, + MSGResult& aResult) { aResult.mResult = 0; aResult.mConsumed = false; @@ -574,26 +652,26 @@ nsIMM32Handler::ProcessMessageForPlugin(nsWindow* aWindow, UINT msg, return ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult); case WM_IME_COMPOSITION: EnsureHandlerInstance(); - return gIMM32Handler->OnIMECompositionOnPlugin(aWindow, wParam, lParam, - aResult); + return gIMMHandler->OnIMECompositionOnPlugin(aWindow, wParam, lParam, + aResult); case WM_IME_STARTCOMPOSITION: EnsureHandlerInstance(); - return gIMM32Handler->OnIMEStartCompositionOnPlugin(aWindow, wParam, - lParam, aResult); + return gIMMHandler->OnIMEStartCompositionOnPlugin(aWindow, wParam, + lParam, aResult); case WM_IME_ENDCOMPOSITION: EnsureHandlerInstance(); - return gIMM32Handler->OnIMEEndCompositionOnPlugin(aWindow, wParam, lParam, - aResult); + return gIMMHandler->OnIMEEndCompositionOnPlugin(aWindow, wParam, lParam, + aResult); case WM_IME_CHAR: EnsureHandlerInstance(); - return gIMM32Handler->OnIMECharOnPlugin(aWindow, wParam, lParam, aResult); + return gIMMHandler->OnIMECharOnPlugin(aWindow, wParam, lParam, aResult); case WM_IME_SETCONTEXT: return OnIMESetContextOnPlugin(aWindow, wParam, lParam, aResult); case WM_CHAR: - if (!gIMM32Handler) { + if (!gIMMHandler) { return false; } - return gIMM32Handler->OnCharOnPlugin(aWindow, wParam, lParam, aResult); + return gIMMHandler->OnCharOnPlugin(aWindow, wParam, lParam, aResult); case WM_IME_COMPOSITIONFULL: case WM_IME_CONTROL: case WM_IME_KEYDOWN: @@ -612,13 +690,13 @@ nsIMM32Handler::ProcessMessageForPlugin(nsWindow* aWindow, UINT msg, ****************************************************************************/ void -nsIMM32Handler::OnInputLangChange(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnInputLangChange(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnInputLangChange, hWnd=%08x, wParam=%08x, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnInputLangChange, hWnd=%08x, wParam=%08x, lParam=%08x", aWindow->GetWindowHandle(), wParam, lParam)); aWindow->NotifyIME(REQUEST_TO_COMMIT_COMPOSITION); @@ -632,55 +710,53 @@ nsIMM32Handler::OnInputLangChange(nsWindow* aWindow, } bool -nsIMM32Handler::OnIMEStartComposition(nsWindow* aWindow, - MSGResult& aResult) +IMMHandler::OnIMEStartComposition(nsWindow* aWindow, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEStartComposition, hWnd=%08x, mIsComposing=%s\n", - aWindow->GetWindowHandle(), mIsComposing ? "TRUE" : "FALSE")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMEStartComposition, hWnd=%08x, mIsComposing=%s", + aWindow->GetWindowHandle(), GetBoolName(mIsComposing))); aResult.mConsumed = ShouldDrawCompositionStringOurselves(); if (mIsComposing) { NS_WARNING("Composition has been already started"); return true; } - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - HandleStartComposition(aWindow, IMEContext); + IMEContext context(aWindow); + HandleStartComposition(aWindow, context); return true; } bool -nsIMM32Handler::OnIMEComposition(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnIMEComposition(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEComposition, hWnd=%08x, lParam=%08x, mIsComposing=%s\n", - aWindow->GetWindowHandle(), lParam, mIsComposing ? "TRUE" : "FALSE")); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEComposition, GCS_RESULTSTR=%s, GCS_COMPSTR=%s, GCS_COMPATTR=%s, GCS_COMPCLAUSE=%s, GCS_CURSORPOS=%s\n", - lParam & GCS_RESULTSTR ? "YES" : "no", - lParam & GCS_COMPSTR ? "YES" : "no", - lParam & GCS_COMPATTR ? "YES" : "no", - lParam & GCS_COMPCLAUSE ? "YES" : "no", - lParam & GCS_CURSORPOS ? "YES" : "no")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMEComposition, hWnd=%08x, lParam=%08x, mIsComposing=%s, " + "GCS_RESULTSTR=%s, GCS_COMPSTR=%s, GCS_COMPATTR=%s, GCS_COMPCLAUSE=%s, " + "GCS_CURSORPOS=%s,", + aWindow->GetWindowHandle(), lParam, GetBoolName(mIsComposing), + GetBoolName(lParam & GCS_RESULTSTR), GetBoolName(lParam & GCS_COMPSTR), + GetBoolName(lParam & GCS_COMPATTR), GetBoolName(lParam & GCS_COMPCLAUSE), + GetBoolName(lParam & GCS_CURSORPOS))); - NS_PRECONDITION(!aWindow->PluginHasFocus(), + MOZ_ASSERT(!aWindow->PluginHasFocus(), "OnIMEComposition should not be called when a plug-in has focus"); - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - aResult.mConsumed = HandleComposition(aWindow, IMEContext, lParam); + IMEContext context(aWindow); + aResult.mConsumed = HandleComposition(aWindow, context, lParam); return true; } bool -nsIMM32Handler::OnIMEEndComposition(nsWindow* aWindow, - MSGResult& aResult) +IMMHandler::OnIMEEndComposition(nsWindow* aWindow, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEEndComposition, hWnd=%08x, mIsComposing=%s\n", - aWindow->GetWindowHandle(), mIsComposing ? "TRUE" : "FALSE")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMEEndComposition, hWnd=%08x, mIsComposing=%s", + aWindow->GetWindowHandle(), GetBoolName(mIsComposing))); aResult.mConsumed = ShouldDrawCompositionStringOurselves(); if (!mIsComposing) { @@ -696,8 +772,8 @@ nsIMM32Handler::OnIMEEndComposition(nsWindow* aWindow, PM_NOREMOVE) && compositionMsg.message == WM_IME_COMPOSITION && IS_COMMITTING_LPARAM(compositionMsg.lParam)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEEndComposition, WM_IME_ENDCOMPOSITION is followed by " + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMEEndComposition, WM_IME_ENDCOMPOSITION is followed by " "WM_IME_COMPOSITION, ignoring the message...")); return true; } @@ -708,8 +784,8 @@ nsIMM32Handler::OnIMEEndComposition(nsWindow* aWindow, // event and a compositionend event. // XXX Shouldn't we dispatch the compositionchange event with actual or // latest composition string? - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEEndComposition, mCompositionString=\"%s\"%s", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMEEndComposition, mCompositionString=\"%s\"%s", NS_ConvertUTF16toUTF8(mCompositionString).get(), mCompositionString.IsEmpty() ? "" : ", but canceling it...")); @@ -718,14 +794,15 @@ nsIMM32Handler::OnIMEEndComposition(nsWindow* aWindow, return true; } -/* static */ bool -nsIMM32Handler::OnIMEChar(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +// static +bool +IMMHandler::OnIMEChar(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEChar, hWnd=%08x, char=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMEChar, hWnd=%08x, char=%08x", aWindow->GetWindowHandle(), wParam)); // We don't need to fire any compositionchange events from here. This method @@ -738,12 +815,13 @@ nsIMM32Handler::OnIMEChar(nsWindow* aWindow, return true; } -/* static */ bool -nsIMM32Handler::OnIMECompositionFull(nsWindow* aWindow, - MSGResult& aResult) +// static +bool +IMMHandler::OnIMECompositionFull(nsWindow* aWindow, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMECompositionFull, hWnd=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMECompositionFull, hWnd=%08x", aWindow->GetWindowHandle())); // not implement yet @@ -751,81 +829,82 @@ nsIMM32Handler::OnIMECompositionFull(nsWindow* aWindow, return true; } -/* static */ bool -nsIMM32Handler::OnIMENotify(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +// static +bool +IMMHandler::OnIMENotify(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { switch (wParam) { case IMN_CHANGECANDIDATE: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_CHANGECANDIDATE, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_CHANGECANDIDATE, lParam=%08x", aWindow->GetWindowHandle(), lParam)); break; case IMN_CLOSECANDIDATE: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_CLOSECANDIDATE, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_CLOSECANDIDATE, lParam=%08x", aWindow->GetWindowHandle(), lParam)); break; case IMN_CLOSESTATUSWINDOW: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_CLOSESTATUSWINDOW\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_CLOSESTATUSWINDOW", aWindow->GetWindowHandle())); break; case IMN_GUIDELINE: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_GUIDELINE\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_GUIDELINE", aWindow->GetWindowHandle())); break; case IMN_OPENCANDIDATE: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_OPENCANDIDATE, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_OPENCANDIDATE, lParam=%08x", aWindow->GetWindowHandle(), lParam)); break; case IMN_OPENSTATUSWINDOW: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_OPENSTATUSWINDOW\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_OPENSTATUSWINDOW", aWindow->GetWindowHandle())); break; case IMN_SETCANDIDATEPOS: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_SETCANDIDATEPOS, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_SETCANDIDATEPOS, lParam=%08x", aWindow->GetWindowHandle(), lParam)); break; case IMN_SETCOMPOSITIONFONT: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_SETCOMPOSITIONFONT\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_SETCOMPOSITIONFONT", aWindow->GetWindowHandle())); break; case IMN_SETCOMPOSITIONWINDOW: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_SETCOMPOSITIONWINDOW\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_SETCOMPOSITIONWINDOW", aWindow->GetWindowHandle())); break; case IMN_SETCONVERSIONMODE: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_SETCONVERSIONMODE\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_SETCONVERSIONMODE", aWindow->GetWindowHandle())); break; case IMN_SETOPENSTATUS: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_SETOPENSTATUS\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_SETOPENSTATUS", aWindow->GetWindowHandle())); break; case IMN_SETSENTENCEMODE: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_SETSENTENCEMODE\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_SETSENTENCEMODE", aWindow->GetWindowHandle())); break; case IMN_SETSTATUSWINDOWPOS: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_SETSTATUSWINDOWPOS\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_SETSTATUSWINDOWPOS", aWindow->GetWindowHandle())); break; case IMN_PRIVATE: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMENotify, hWnd=%08x, IMN_PRIVATE\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMENotify, hWnd=%08x, IMN_PRIVATE", aWindow->GetWindowHandle())); break; } @@ -836,48 +915,49 @@ nsIMM32Handler::OnIMENotify(nsWindow* aWindow, } bool -nsIMM32Handler::OnIMERequest(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnIMERequest(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { switch (wParam) { case IMR_RECONVERTSTRING: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMERequest, hWnd=%08x, IMR_RECONVERTSTRING\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMERequest, hWnd=%08x, IMR_RECONVERTSTRING", aWindow->GetWindowHandle())); aResult.mConsumed = HandleReconvert(aWindow, lParam, &aResult.mResult); return true; case IMR_QUERYCHARPOSITION: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMERequest, hWnd=%08x, IMR_QUERYCHARPOSITION\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMERequest, hWnd=%08x, IMR_QUERYCHARPOSITION", aWindow->GetWindowHandle())); aResult.mConsumed = HandleQueryCharPosition(aWindow, lParam, &aResult.mResult); return true; case IMR_DOCUMENTFEED: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMERequest, hWnd=%08x, IMR_DOCUMENTFEED\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMERequest, hWnd=%08x, IMR_DOCUMENTFEED", aWindow->GetWindowHandle())); aResult.mConsumed = HandleDocumentFeed(aWindow, lParam, &aResult.mResult); return true; default: - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMERequest, hWnd=%08x, wParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMERequest, hWnd=%08x, wParam=%08x", aWindow->GetWindowHandle(), wParam)); aResult.mConsumed = false; return true; } } -/* static */ bool -nsIMM32Handler::OnIMESelect(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +// static +bool +IMMHandler::OnIMESelect(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMESelect, hWnd=%08x, wParam=%08x, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMESelect, hWnd=%08x, wParam=%08x, lParam=%08x", aWindow->GetWindowHandle(), wParam, lParam)); // not implement yet @@ -885,14 +965,15 @@ nsIMM32Handler::OnIMESelect(nsWindow* aWindow, return true; } -/* static */ bool -nsIMM32Handler::OnIMESetContext(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +// static +bool +IMMHandler::OnIMESetContext(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMESetContext, hWnd=%08x, %s, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMESetContext, hWnd=%08x, %s, lParam=%08x", aWindow->GetWindowHandle(), wParam ? "Active" : "Deactive", lParam)); aResult.mConsumed = false; @@ -905,23 +986,23 @@ nsIMM32Handler::OnIMESetContext(nsWindow* aWindow, // The top level window never becomes composing window, so, we can ignore // the WM_IME_SETCONTEXT on the top level window. if (IsTopLevelWindowOfComposition(aWindow)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMESetContext, hWnd=%08x is top level window\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMESetContext, hWnd=%08x is top level window")); return true; } // When IME context is activating on another window, // we should commit the old composition on the old window. bool cancelComposition = false; - if (wParam && gIMM32Handler) { + if (wParam && gIMMHandler) { cancelComposition = - gIMM32Handler->CommitCompositionOnPreviousWindow(aWindow); + gIMMHandler->CommitCompositionOnPreviousWindow(aWindow); } if (wParam && (lParam & ISC_SHOWUICOMPOSITIONWINDOW) && ShouldDrawCompositionStringOurselves()) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMESetContext, ISC_SHOWUICOMPOSITIONWINDOW is removed\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMESetContext, ISC_SHOWUICOMPOSITIONWINDOW is removed")); lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW; } @@ -942,10 +1023,10 @@ nsIMM32Handler::OnIMESetContext(nsWindow* aWindow, } bool -nsIMM32Handler::OnChar(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnChar(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { // The return value must be same as aResult.mConsumed because only when we // consume the message, the caller shouldn't do anything anymore but @@ -957,12 +1038,10 @@ nsIMM32Handler::OnChar(nsWindow* aWindow, WPARAM recWParam; LPARAM recLParam; DequeueIMECharRecords(recWParam, recLParam); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnChar, aWindow=%p, wParam=%08x, lParam=%08x,\n", - aWindow->GetWindowHandle(), wParam, lParam)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - (" recorded: wParam=%08x, lParam=%08x\n", - recWParam, recLParam)); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnChar, aWindow=%p, wParam=%08x, lParam=%08x, " + "recorded: wParam=%08x, lParam=%08x", + aWindow->GetWindowHandle(), wParam, lParam, recWParam, recLParam)); // If an unexpected char message comes, we should reset the records, // of course, this shouldn't happen. if (recWParam != wParam || recLParam != lParam) { @@ -981,21 +1060,21 @@ nsIMM32Handler::OnChar(nsWindow* aWindow, ****************************************************************************/ bool -nsIMM32Handler::OnIMEStartCompositionOnPlugin(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnIMEStartCompositionOnPlugin(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEStartCompositionOnPlugin, hWnd=%08x, mIsComposingOnPlugin=%s\n", - aWindow->GetWindowHandle(), mIsComposingOnPlugin ? "TRUE" : "FALSE")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMEStartCompositionOnPlugin, hWnd=%08x, mIsComposingOnPlugin=%s", + aWindow->GetWindowHandle(), GetBoolName(mIsComposingOnPlugin))); mIsComposingOnPlugin = true; mComposingWindow = aWindow; - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - SetIMERelatedWindowsPosOnPlugin(aWindow, IMEContext); + IMEContext context(aWindow); + SetIMERelatedWindowsPosOnPlugin(aWindow, context); // On widnowless plugin, we should assume that the focused editor is always // in horizontal writing mode. - AdjustCompositionFont(IMEContext, WritingMode()); + AdjustCompositionFont(context, WritingMode()); aResult.mConsumed = aWindow->DispatchPluginEvent(WM_IME_STARTCOMPOSITION, wParam, lParam, false); @@ -1003,22 +1082,19 @@ nsIMM32Handler::OnIMEStartCompositionOnPlugin(nsWindow* aWindow, } bool -nsIMM32Handler::OnIMECompositionOnPlugin(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnIMECompositionOnPlugin(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMECompositionOnPlugin, hWnd=%08x, lParam=%08x, mIsComposingOnPlugin=%s\n", - aWindow->GetWindowHandle(), lParam, - mIsComposingOnPlugin ? "TRUE" : "FALSE")); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMECompositionOnPlugin, GCS_RESULTSTR=%s, GCS_COMPSTR=%s, GCS_COMPATTR=%s, GCS_COMPCLAUSE=%s, GCS_CURSORPOS=%s\n", - lParam & GCS_RESULTSTR ? "YES" : "no", - lParam & GCS_COMPSTR ? "YES" : "no", - lParam & GCS_COMPATTR ? "YES" : "no", - lParam & GCS_COMPCLAUSE ? "YES" : "no", - lParam & GCS_CURSORPOS ? "YES" : "no")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMECompositionOnPlugin, hWnd=%08x, lParam=%08x, " + "mIsComposingOnPlugin=%s, GCS_RESULTSTR=%s, GCS_COMPSTR=%s, " + "GCS_COMPATTR=%s, GCS_COMPCLAUSE=%s, GCS_CURSORPOS=%s", + aWindow->GetWindowHandle(), lParam, GetBoolName(mIsComposingOnPlugin), + GetBoolName(lParam & GCS_RESULTSTR), GetBoolName(lParam & GCS_COMPSTR), + GetBoolName(lParam & GCS_COMPATTR), GetBoolName(lParam & GCS_COMPCLAUSE), + GetBoolName(lParam & GCS_CURSORPOS))); // We should end composition if there is a committed string. if (IS_COMMITTING_LPARAM(lParam)) { mIsComposingOnPlugin = false; @@ -1028,8 +1104,8 @@ nsIMM32Handler::OnIMECompositionOnPlugin(nsWindow* aWindow, if (IS_COMPOSING_LPARAM(lParam)) { mIsComposingOnPlugin = true; mComposingWindow = aWindow; - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - SetIMERelatedWindowsPosOnPlugin(aWindow, IMEContext); + IMEContext context(aWindow); + SetIMERelatedWindowsPosOnPlugin(aWindow, context); } aResult.mConsumed = aWindow->DispatchPluginEvent(WM_IME_COMPOSITION, wParam, lParam, true); @@ -1037,14 +1113,14 @@ nsIMM32Handler::OnIMECompositionOnPlugin(nsWindow* aWindow, } bool -nsIMM32Handler::OnIMEEndCompositionOnPlugin(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnIMEEndCompositionOnPlugin(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMEEndCompositionOnPlugin, hWnd=%08x, mIsComposingOnPlugin=%s\n", - aWindow->GetWindowHandle(), mIsComposingOnPlugin ? "TRUE" : "FALSE")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMEEndCompositionOnPlugin, hWnd=%08x, mIsComposingOnPlugin=%s", + aWindow->GetWindowHandle(), GetBoolName(mIsComposingOnPlugin))); mIsComposingOnPlugin = false; mComposingWindow = nullptr; @@ -1061,13 +1137,13 @@ nsIMM32Handler::OnIMEEndCompositionOnPlugin(nsWindow* aWindow, } bool -nsIMM32Handler::OnIMECharOnPlugin(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnIMECharOnPlugin(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMECharOnPlugin, hWnd=%08x, char=%08x, scancode=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMECharOnPlugin, hWnd=%08x, char=%08x, scancode=%08x", aWindow->GetWindowHandle(), wParam, lParam)); aResult.mConsumed = @@ -1081,14 +1157,15 @@ nsIMM32Handler::OnIMECharOnPlugin(nsWindow* aWindow, return true; } -/* static */ bool -nsIMM32Handler::OnIMESetContextOnPlugin(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +// static +bool +IMMHandler::OnIMESetContextOnPlugin(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnIMESetContextOnPlugin, hWnd=%08x, %s, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnIMESetContextOnPlugin, hWnd=%08x, %s, lParam=%08x", aWindow->GetWindowHandle(), wParam ? "Active" : "Deactive", lParam)); // If the IME context becomes active on a plug-in, we should commit @@ -1096,8 +1173,8 @@ nsIMM32Handler::OnIMESetContextOnPlugin(nsWindow* aWindow, // window. Note that if IsTopLevelWindowOfComposition(aWindow) returns // true, we should ignore the message here, see the comment in // OnIMESetContext() for the detail. - if (wParam && gIMM32Handler && !IsTopLevelWindowOfComposition(aWindow)) { - if (gIMM32Handler->CommitCompositionOnPreviousWindow(aWindow)) { + if (wParam && gIMMHandler && !IsTopLevelWindowOfComposition(aWindow)) { + if (gIMMHandler->CommitCompositionOnPreviousWindow(aWindow)) { CancelComposition(aWindow); } } @@ -1120,10 +1197,10 @@ nsIMM32Handler::OnIMESetContextOnPlugin(nsWindow* aWindow, } bool -nsIMM32Handler::OnCharOnPlugin(nsWindow* aWindow, - WPARAM wParam, - LPARAM lParam, - MSGResult& aResult) +IMMHandler::OnCharOnPlugin(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { // We should never consume char message on windowless plugin. aResult.mConsumed = false; @@ -1134,12 +1211,10 @@ nsIMM32Handler::OnCharOnPlugin(nsWindow* aWindow, WPARAM recWParam; LPARAM recLParam; DequeueIMECharRecords(recWParam, recLParam); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnCharOnPlugin, aWindow=%p, wParam=%08x, lParam=%08x,\n", - aWindow->GetWindowHandle(), wParam, lParam)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - (" recorded: wParam=%08x, lParam=%08x\n", - recWParam, recLParam)); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnCharOnPlugin, aWindow=%p, wParam=%08x, lParam=%08x, " + "recorded: wParam=%08x, lParam=%08x", + aWindow->GetWindowHandle(), wParam, lParam, recWParam, recLParam)); // If an unexpected char message comes, we should reset the records, // of course, this shouldn't happen. if (recWParam != wParam || recLParam != lParam) { @@ -1154,8 +1229,8 @@ nsIMM32Handler::OnCharOnPlugin(nsWindow* aWindow, ****************************************************************************/ void -nsIMM32Handler::HandleStartComposition(nsWindow* aWindow, - const nsIMEContext &aIMEContext) +IMMHandler::HandleStartComposition(nsWindow* aWindow, + const IMEContext& aContext) { NS_PRECONDITION(!mIsComposing, "HandleStartComposition is called but mIsComposing is TRUE"); @@ -1164,15 +1239,16 @@ nsIMM32Handler::HandleStartComposition(nsWindow* aWindow, Selection& selection = GetSelection(); if (!selection.EnsureValidSelection(aWindow)) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: HandleStartComposition, FAILED, due to " + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleStartComposition, FAILED, due to " "Selection::EnsureValidSelection() failure")); return; } - AdjustCompositionFont(aIMEContext, selection.mWritingMode); + AdjustCompositionFont(aContext, selection.mWritingMode); mCompositionStart = selection.mOffset; + mCursorPosition = NO_IME_CARET; WidgetCompositionEvent event(true, NS_COMPOSITION_START, aWindow); nsIntPoint point(0, 0); @@ -1182,15 +1258,15 @@ nsIMM32Handler::HandleStartComposition(nsWindow* aWindow, mIsComposing = true; mComposingWindow = aWindow; - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleStartComposition, START composition, mCompositionStart=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleStartComposition, START composition, mCompositionStart=%ld", mCompositionStart)); } bool -nsIMM32Handler::HandleComposition(nsWindow* aWindow, - const nsIMEContext &aIMEContext, - LPARAM lParam) +IMMHandler::HandleComposition(nsWindow* aWindow, + const IMEContext& aContext, + LPARAM lParam) { NS_PRECONDITION(!aWindow->PluginHasFocus(), "HandleComposition should not be called when a plug-in has focus"); @@ -1216,8 +1292,9 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, WinUtils::PeekMessage(&msg2, wnd, WM_IME_ENDCOMPOSITION, WM_IME_COMPOSITION, PM_NOREMOVE) && msg2.message == WM_IME_COMPOSITION) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, Ignores due to find a WM_IME_STARTCOMPOSITION\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, Ignores due to find a " + "WM_IME_STARTCOMPOSITION")); return ShouldDrawCompositionStringOurselves(); } } @@ -1229,13 +1306,13 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // if (IS_COMMITTING_LPARAM(lParam)) { if (!mIsComposing) { - HandleStartComposition(aWindow, aIMEContext); + HandleStartComposition(aWindow, aContext); } - GetCompositionString(aIMEContext, GCS_RESULTSTR, mCompositionString); + GetCompositionString(aContext, GCS_RESULTSTR, mCompositionString); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, GCS_RESULTSTR\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, GCS_RESULTSTR")); HandleEndComposition(aWindow, &mCompositionString); @@ -1249,21 +1326,21 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // This provides us with a composition string // if (!mIsComposing) { - HandleStartComposition(aWindow, aIMEContext); + HandleStartComposition(aWindow, aContext); } //-------------------------------------------------------- // 1. Get GCS_COMPSTR //-------------------------------------------------------- - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, GCS_COMPSTR\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, GCS_COMPSTR")); nsAutoString previousCompositionString(mCompositionString); - GetCompositionString(aIMEContext, GCS_COMPSTR, mCompositionString); + GetCompositionString(aContext, GCS_COMPSTR, mCompositionString); if (!IS_COMPOSING_LPARAM(lParam)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, lParam doesn't indicate composing, " + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, lParam doesn't indicate composing, " "mCompositionString=\"%s\", previousCompositionString=\"%s\"", NS_ConvertUTF16toUTF8(mCompositionString).get(), NS_ConvertUTF16toUTF8(previousCompositionString).get())); @@ -1282,7 +1359,7 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, mClauseArray.Clear(); mAttributeArray.Clear(); mCursorPosition = 0; - DispatchCompositionChangeEvent(aWindow, aIMEContext); + DispatchCompositionChangeEvent(aWindow, aContext); return ShouldDrawCompositionStringOurselves(); } @@ -1301,8 +1378,8 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // string is null (it indicates the composition transaction ended), // WM_IME_ENDCOMPOSITION may not be sent. If so, we cannot run // HandleEndComposition() in other place. - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, Aborting GCS_COMPSTR\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, Aborting GCS_COMPSTR")); HandleEndComposition(aWindow); return IS_COMMITTING_LPARAM(lParam); } @@ -1311,7 +1388,7 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // 2. Get GCS_COMPCLAUSE //-------------------------------------------------------- long clauseArrayLength = - ::ImmGetCompositionStringW(aIMEContext.get(), GCS_COMPCLAUSE, nullptr, 0); + ::ImmGetCompositionStringW(aContext.get(), GCS_COMPCLAUSE, nullptr, 0); clauseArrayLength /= sizeof(uint32_t); if (clauseArrayLength > 0) { @@ -1324,23 +1401,24 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // API for it, however, we should not kill Unicode support on all IMEs. bool useA_API = !(sIMEProperty & IME_PROP_UNICODE); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, GCS_COMPCLAUSE, useA_API=%s\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, GCS_COMPCLAUSE, useA_API=%s", useA_API ? "TRUE" : "FALSE")); long clauseArrayLength2 = useA_API ? - ::ImmGetCompositionStringA(aIMEContext.get(), GCS_COMPCLAUSE, + ::ImmGetCompositionStringA(aContext.get(), GCS_COMPCLAUSE, mClauseArray.Elements(), mClauseArray.Capacity() * sizeof(uint32_t)) : - ::ImmGetCompositionStringW(aIMEContext.get(), GCS_COMPCLAUSE, + ::ImmGetCompositionStringW(aContext.get(), GCS_COMPCLAUSE, mClauseArray.Elements(), mClauseArray.Capacity() * sizeof(uint32_t)); clauseArrayLength2 /= sizeof(uint32_t); if (clauseArrayLength != clauseArrayLength2) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, GCS_COMPCLAUSE, clauseArrayLength=%ld but clauseArrayLength2=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, GCS_COMPCLAUSE, clauseArrayLength=%ld but " + "clauseArrayLength2=%ld", clauseArrayLength, clauseArrayLength2)); if (clauseArrayLength > clauseArrayLength2) clauseArrayLength = clauseArrayLength2; @@ -1368,8 +1446,8 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // may return an error code. mClauseArray.SetLength(std::max(0, clauseArrayLength)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, GCS_COMPCLAUSE, mClauseLength=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, GCS_COMPCLAUSE, mClauseLength=%ld", mClauseArray.Length())); //-------------------------------------------------------- @@ -1378,14 +1456,14 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // This provides us with the attribute string necessary // for doing hiliting long attrArrayLength = - ::ImmGetCompositionStringW(aIMEContext.get(), GCS_COMPATTR, nullptr, 0); + ::ImmGetCompositionStringW(aContext.get(), GCS_COMPATTR, nullptr, 0); attrArrayLength /= sizeof(uint8_t); if (attrArrayLength > 0) { nsresult rv = EnsureAttributeArray(attrArrayLength); NS_ENSURE_SUCCESS(rv, false); attrArrayLength = - ::ImmGetCompositionStringW(aIMEContext.get(), GCS_COMPATTR, + ::ImmGetCompositionStringW(aContext.get(), GCS_COMPATTR, mAttributeArray.Elements(), mAttributeArray.Capacity() * sizeof(uint8_t)); } @@ -1394,8 +1472,8 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // error code. mAttributeArray.SetLength(std::max(0, attrArrayLength)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, GCS_COMPATTR, mAttributeLength=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, GCS_COMPATTR, mAttributeLength=%ld", mAttributeArray.Length())); //-------------------------------------------------------- @@ -1404,7 +1482,7 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, // Some IMEs (e.g., the standard IME for Korean) don't have caret position. if (lParam & GCS_CURSORPOS) { mCursorPosition = - ::ImmGetCompositionStringW(aIMEContext.get(), GCS_CURSORPOS, nullptr, 0); + ::ImmGetCompositionStringW(aContext.get(), GCS_CURSORPOS, nullptr, 0); if (mCursorPosition < 0) { mCursorPosition = NO_IME_CARET; // The result is error } @@ -1415,29 +1493,29 @@ nsIMM32Handler::HandleComposition(nsWindow* aWindow, NS_ASSERTION(mCursorPosition <= (long)mCompositionString.Length(), "illegal pos"); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleComposition, GCS_CURSORPOS, mCursorPosition=%d\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleComposition, GCS_CURSORPOS, mCursorPosition=%d", mCursorPosition)); //-------------------------------------------------------- // 5. Send the compositionchange event //-------------------------------------------------------- - DispatchCompositionChangeEvent(aWindow, aIMEContext); + DispatchCompositionChangeEvent(aWindow, aContext); return ShouldDrawCompositionStringOurselves(); } void -nsIMM32Handler::HandleEndComposition(nsWindow* aWindow, - const nsAString* aCommitString) +IMMHandler::HandleEndComposition(nsWindow* aWindow, + const nsAString* aCommitString) { - NS_PRECONDITION(mIsComposing, + MOZ_ASSERT(mIsComposing, "HandleEndComposition is called but mIsComposing is FALSE"); - NS_PRECONDITION(!aWindow->PluginHasFocus(), + MOZ_ASSERT(!aWindow->PluginHasFocus(), "HandleComposition should not be called when a plug-in has focus"); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleEndComposition(aWindow=0x%p, aCommitString=0x%p (\"%s\"))", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleEndComposition(aWindow=0x%p, aCommitString=0x%p (\"%s\"))", aWindow, aCommitString, aCommitString ? NS_ConvertUTF16toUTF8(*aCommitString).get() : "")); @@ -1446,7 +1524,7 @@ nsIMM32Handler::HandleEndComposition(nsWindow* aWindow, mNativeCaretIsCreated = false; } - uint32_t message = + EventMessage message = aCommitString ? NS_COMPOSITION_COMMIT : NS_COMPOSITION_COMMIT_AS_IS; WidgetCompositionEvent compositionCommitEvent(true, message, aWindow); nsIntPoint point(0, 0); @@ -1459,36 +1537,18 @@ nsIMM32Handler::HandleEndComposition(nsWindow* aWindow, mComposingWindow = nullptr; } -static void -DumpReconvertString(RECONVERTSTRING* aReconv) -{ - MOZ_LOG(gIMM32Log, LogLevel::Info, - (" dwSize=%ld, dwVersion=%ld, dwStrLen=%ld, dwStrOffset=%ld\n", - aReconv->dwSize, aReconv->dwVersion, - aReconv->dwStrLen, aReconv->dwStrOffset)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - (" dwCompStrLen=%ld, dwCompStrOffset=%ld, dwTargetStrLen=%ld, dwTargetStrOffset=%ld\n", - aReconv->dwCompStrLen, aReconv->dwCompStrOffset, - aReconv->dwTargetStrLen, aReconv->dwTargetStrOffset)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - (" result str=\"%s\"\n", - NS_ConvertUTF16toUTF8( - nsAutoString((char16_t*)((char*)(aReconv) + aReconv->dwStrOffset), - aReconv->dwStrLen)).get())); -} - bool -nsIMM32Handler::HandleReconvert(nsWindow* aWindow, - LPARAM lParam, - LRESULT *oResult) +IMMHandler::HandleReconvert(nsWindow* aWindow, + LPARAM lParam, + LRESULT* oResult) { *oResult = 0; RECONVERTSTRING* pReconv = reinterpret_cast(lParam); Selection& selection = GetSelection(); if (!selection.EnsureValidSelection(aWindow)) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: HandleReconvert, FAILED, due to " + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleReconvert, FAILED, due to " "Selection::EnsureValidSelection() failure")); return false; } @@ -1499,20 +1559,20 @@ nsIMM32Handler::HandleReconvert(nsWindow* aWindow, if (!pReconv) { // Return need size to reconvert. if (len == 0) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleReconvert, There are not selected text\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleReconvert, There are not selected text")); return false; } *oResult = needSize; - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleReconvert, SUCCEEDED result=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleReconvert, succeeded, result=%ld", *oResult)); return true; } if (pReconv->dwSize < needSize) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleReconvert, FAILED pReconv->dwSize=%ld, needSize=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleReconvert, FAILED, pReconv->dwSize=%ld, needSize=%ld", pReconv->dwSize, needSize)); return false; } @@ -1531,43 +1591,44 @@ nsIMM32Handler::HandleReconvert(nsWindow* aWindow, ::CopyMemory(reinterpret_cast(lParam + sizeof(RECONVERTSTRING)), selection.mString.get(), len * sizeof(WCHAR)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleReconvert, SUCCEEDED result=%ld\n", - *oResult)); - DumpReconvertString(pReconv); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleReconvert, SUCCEEDED, pReconv=%s, result=%ld", + GetReconvertStringLog(pReconv).get(), *oResult)); return true; } bool -nsIMM32Handler::HandleQueryCharPosition(nsWindow* aWindow, - LPARAM lParam, - LRESULT *oResult) +IMMHandler::HandleQueryCharPosition(nsWindow* aWindow, + LPARAM lParam, + LRESULT* oResult) { uint32_t len = mIsComposing ? mCompositionString.Length() : 0; *oResult = false; IMECHARPOSITION* pCharPosition = reinterpret_cast(lParam); if (!pCharPosition) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleQueryCharPosition, FAILED (pCharPosition is null)\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleQueryCharPosition, FAILED, due to pCharPosition is null")); return false; } if (pCharPosition->dwSize < sizeof(IMECHARPOSITION)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleReconvert, FAILED, pCharPosition->dwSize=%ld, sizeof(IMECHARPOSITION)=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleReconvert, FAILED, pCharPosition->dwSize=%ld, " + "sizeof(IMECHARPOSITION)=%ld", pCharPosition->dwSize, sizeof(IMECHARPOSITION))); return false; } if (::GetFocus() != aWindow->GetWindowHandle()) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleReconvert, FAILED, ::GetFocus()=%08x, OurWindowHandle=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleReconvert, FAILED, ::GetFocus()=%08x, OurWindowHandle=%08x", ::GetFocus(), aWindow->GetWindowHandle())); return false; } if (pCharPosition->dwCharPos > len) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleQueryCharPosition, FAILED, pCharPosition->dwCharPos=%ld, len=%ld\n", - pCharPosition->dwCharPos, len)); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleQueryCharPosition, FAILED, pCharPosition->dwCharPos=%ld, " + "len=%ld", + pCharPosition->dwCharPos, len)); return false; } @@ -1597,8 +1658,8 @@ nsIMM32Handler::HandleQueryCharPosition(nsWindow* aWindow, aWindow->InitEvent(editorRect); aWindow->DispatchWindowEvent(&editorRect); if (NS_WARN_IF(!editorRect.mSucceeded)) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: HandleQueryCharPosition, NS_QUERY_EDITOR_RECT failed")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleQueryCharPosition, NS_QUERY_EDITOR_RECT failed")); ::GetWindowRect(aWindow->GetWindowHandle(), &pCharPosition->rcDocument); } else { nsIntRect editorRectInWindow = @@ -1614,8 +1675,8 @@ nsIMM32Handler::HandleQueryCharPosition(nsWindow* aWindow, *oResult = TRUE; - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleQueryCharPosition, SUCCEEDED, pCharPosition={ pt={ x=%d, " + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleQueryCharPosition, SUCCEEDED, pCharPosition={ pt={ x=%d, " "y=%d }, cLineHeight=%d, rcDocument={ left=%d, top=%d, right=%d, " "bottom=%d } }", pCharPosition->pt.x, pCharPosition->pt.y, pCharPosition->cLineHeight, @@ -1625,9 +1686,9 @@ nsIMM32Handler::HandleQueryCharPosition(nsWindow* aWindow, } bool -nsIMM32Handler::HandleDocumentFeed(nsWindow* aWindow, - LPARAM lParam, - LRESULT *oResult) +IMMHandler::HandleDocumentFeed(nsWindow* aWindow, + LPARAM lParam, + LRESULT* oResult) { *oResult = 0; RECONVERTSTRING* pReconv = reinterpret_cast(lParam); @@ -1641,8 +1702,8 @@ nsIMM32Handler::HandleDocumentFeed(nsWindow* aWindow, if (!hasCompositionString) { Selection& selection = GetSelection(); if (!selection.EnsureValidSelection(aWindow)) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: HandleDocumentFeed, FAILED, due to " + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleDocumentFeed, FAILED, due to " "Selection::EnsureValidSelection() failure")); return false; } @@ -1658,8 +1719,9 @@ nsIMM32Handler::HandleDocumentFeed(nsWindow* aWindow, // INT32_MAX. if (targetOffset < 0 || targetLength < 0 || targetOffset + targetLength < 0) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleDocumentFeed, FAILED (The selection is out of range)\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleDocumentFeed, FAILED, due to the selection is out of " + "range")); return false; } @@ -1669,21 +1731,22 @@ nsIMM32Handler::HandleDocumentFeed(nsWindow* aWindow, aWindow->InitEvent(textContent, &point); aWindow->DispatchWindowEvent(&textContent); if (!textContent.mSucceeded) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleDocumentFeed, FAILED (NS_QUERY_TEXT_CONTENT)\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleDocumentFeed, FAILED, due to NS_QUERY_TEXT_CONTENT " + "failure")); return false; } nsAutoString str(textContent.mReply.mString); if (targetOffset > int32_t(str.Length())) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleDocumentFeed, FAILED (The caret offset is invalid)\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleDocumentFeed, FAILED, due to the caret offset is invalid")); return false; } // Get the focused paragraph, we decide that it starts from the previous CRLF // (or start of the editor) to the next one (or the end of the editor). - int32_t paragraphStart = str.RFind("\n", false, targetOffset, -1) + 1; + int32_t paragraphStart = str.RFind("", false, targetOffset, -1) + 1; int32_t paragraphEnd = str.Find("\r", false, targetOffset + targetLength, -1); if (paragraphEnd < 0) { @@ -1697,15 +1760,15 @@ nsIMM32Handler::HandleDocumentFeed(nsWindow* aWindow, if (!pReconv) { *oResult = needSize; - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleDocumentFeed, SUCCEEDED result=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleDocumentFeed, succeeded, result=%ld", *oResult)); return true; } if (pReconv->dwSize < needSize) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleDocumentFeed, FAILED pReconv->dwSize=%ld, needSize=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleDocumentFeed, FAILED, pReconv->dwSize=%ld, needSize=%ld", pReconv->dwSize, needSize)); return false; } @@ -1721,8 +1784,9 @@ nsIMM32Handler::HandleDocumentFeed(nsWindow* aWindow, // Set composition target clause information uint32_t offset, length; if (!GetTargetClauseRange(&offset, &length)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleDocumentFeed, FAILED, by GetTargetClauseRange\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: HandleDocumentFeed, FAILED, due to GetTargetClauseRange() " + "failure")); return false; } pReconv->dwTargetStrLen = length; @@ -1741,29 +1805,29 @@ nsIMM32Handler::HandleDocumentFeed(nsWindow* aWindow, ::CopyMemory(reinterpret_cast(lParam + sizeof(RECONVERTSTRING)), paragraph.BeginReading(), len * sizeof(WCHAR)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: HandleDocumentFeed, SUCCEEDED result=%ld\n", - *oResult)); - DumpReconvertString(pReconv); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: HandleDocumentFeed, SUCCEEDED, pReconv=%s, result=%ld", + GetReconvertStringLog(pReconv).get(), *oResult)); return true; } bool -nsIMM32Handler::CommitCompositionOnPreviousWindow(nsWindow* aWindow) +IMMHandler::CommitCompositionOnPreviousWindow(nsWindow* aWindow) { if (!mComposingWindow || mComposingWindow == aWindow) { return false; } - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CommitCompositionOnPreviousWindow, mIsComposing=%s, mIsComposingOnPlugin=%s\n", - mIsComposing ? "TRUE" : "FALSE", mIsComposingOnPlugin ? "TRUE" : "FALSE")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CommitCompositionOnPreviousWindow, mIsComposing=%s, " + "mIsComposingOnPlugin=%s", + GetBoolName(mIsComposing), GetBoolName(mIsComposingOnPlugin))); // If we have composition, we should dispatch composition events internally. if (mIsComposing) { - nsIMEContext IMEContext(mComposingWindow->GetWindowHandle()); - NS_ASSERTION(IMEContext.IsValid(), "IME context must be valid"); + IMEContext context(mComposingWindow); + NS_ASSERTION(context.IsValid(), "IME context must be valid"); HandleEndComposition(mComposingWindow); return true; @@ -1815,18 +1879,18 @@ GetRangeTypeName(uint32_t aRangeType) } void -nsIMM32Handler::DispatchCompositionChangeEvent(nsWindow* aWindow, - const nsIMEContext& aIMEContext) +IMMHandler::DispatchCompositionChangeEvent(nsWindow* aWindow, + const IMEContext& aContext) { NS_ASSERTION(mIsComposing, "conflict state"); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: DispatchCompositionChangeEvent")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: DispatchCompositionChangeEvent")); // If we don't need to draw composition string ourselves, we don't need to // fire compositionchange event during composing. if (!ShouldDrawCompositionStringOurselves()) { // But we need to adjust composition window pos and native caret pos, here. - SetIMERelatedWindowsPos(aWindow, aIMEContext); + SetIMERelatedWindowsPos(aWindow, aContext); return; } @@ -1849,7 +1913,7 @@ nsIMM32Handler::DispatchCompositionChangeEvent(nsWindow* aWindow, } already_AddRefed -nsIMM32Handler::CreateTextRangeArray() +IMMHandler::CreateTextRangeArray() { // Sogou (Simplified Chinese IME) returns contradictory values: The cursor // position is actual cursor position. However, other values (composition @@ -1872,17 +1936,17 @@ nsIMM32Handler::CreateTextRangeArray() range.mRangeType = NS_TEXTRANGE_RAWINPUT; textRangeArray->AppendElement(range); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CreateTextRangeArray, mClauseLength=0\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CreateTextRangeArray, mClauseLength=0")); } else { // iterate over the attributes uint32_t lastOffset = 0; for (uint32_t i = 0; i < mClauseArray.Length() - 1; i++) { uint32_t current = mClauseArray[i + 1]; if (current > mCompositionString.Length()) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CreateTextRangeArray, mClauseArray[%ld]=%lu. " - "This is larger than mCompositionString.Length()=%lu\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CreateTextRangeArray, mClauseArray[%ld]=%lu. " + "This is larger than mCompositionString.Length()=%lu", i + 1, current, mCompositionString.Length())); current = int32_t(mCompositionString.Length()); } @@ -1894,69 +1958,82 @@ nsIMM32Handler::CreateTextRangeArray() lastOffset = current; - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CreateTextRangeArray, index=%ld, rangeType=%s, range=[%lu-%lu]\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CreateTextRangeArray, index=%ld, rangeType=%s, range=[%lu-%lu]", i, GetRangeTypeName(range.mRangeType), range.mStartOffset, range.mEndOffset)); } } if (mCursorPosition == NO_IME_CARET) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CreateTextRangeArray, no caret\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CreateTextRangeArray, no caret")); return textRangeArray.forget(); } - int32_t cursor = mCursorPosition; - if (uint32_t(cursor) > mCompositionString.Length()) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CreateTextRangeArray, mCursorPosition=%ld. " - "This is larger than mCompositionString.Length()=%lu\n", + uint32_t cursor = static_cast(mCursorPosition); + if (cursor > mCompositionString.Length()) { + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CreateTextRangeArray, mCursorPosition=%ld. " + "This is larger than mCompositionString.Length()=%lu", mCursorPosition, mCompositionString.Length())); cursor = mCompositionString.Length(); } + // If caret is in the target clause, the target clause will be painted as + // normal selection range. Since caret shouldn't be in selection range on + // Windows, we shouldn't append caret range in such case. + const TextRange* targetClause = textRangeArray->GetTargetClause(); + if (targetClause && + cursor >= targetClause->mStartOffset && + cursor <= targetClause->mEndOffset) { + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CreateTextRangeArray, no caret due to it's in the target clause")); + return textRangeArray.forget(); + } + range.mStartOffset = range.mEndOffset = cursor; range.mRangeType = NS_TEXTRANGE_CARETPOSITION; textRangeArray->AppendElement(range); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: CreateTextRangeArray, caret position=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: CreateTextRangeArray, caret position=%ld", range.mStartOffset)); return textRangeArray.forget(); } void -nsIMM32Handler::GetCompositionString(const nsIMEContext &aIMEContext, - DWORD aIndex, - nsAString& aCompositionString) const +IMMHandler::GetCompositionString(const IMEContext& aContext, + DWORD aIndex, + nsAString& aCompositionString) const { aCompositionString.Truncate(); // Retrieve the size of the required output buffer. - long lRtn = ::ImmGetCompositionStringW(aIMEContext.get(), aIndex, nullptr, 0); + long lRtn = ::ImmGetCompositionStringW(aContext.get(), aIndex, nullptr, 0); if (lRtn < 0 || !aCompositionString.SetLength((lRtn / sizeof(WCHAR)) + 1, mozilla::fallible)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: GetCompositionString, FAILED by OOM\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: GetCompositionString, FAILED, due to OOM")); return; // Error or out of memory. } // Actually retrieve the composition string information. - lRtn = ::ImmGetCompositionStringW(aIMEContext.get(), aIndex, + lRtn = ::ImmGetCompositionStringW(aContext.get(), aIndex, (LPVOID)aCompositionString.BeginWriting(), lRtn + sizeof(WCHAR)); aCompositionString.SetLength(lRtn / sizeof(WCHAR)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: GetCompositionString, SUCCEEDED aCompositionString=\"%s\"\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: GetCompositionString, succeeded, aCompositionString=\"%s\"", NS_ConvertUTF16toUTF8(aCompositionString).get())); } bool -nsIMM32Handler::GetTargetClauseRange(uint32_t *aOffset, uint32_t *aLength) +IMMHandler::GetTargetClauseRange(uint32_t* aOffset, + uint32_t* aLength) { NS_ENSURE_TRUE(aOffset, false); NS_ENSURE_TRUE(mIsComposing, false); @@ -1997,8 +2074,9 @@ nsIMM32Handler::GetTargetClauseRange(uint32_t *aOffset, uint32_t *aLength) } bool -nsIMM32Handler::ConvertToANSIString(const nsAFlatString& aStr, UINT aCodePage, - nsACString& aANSIStr) +IMMHandler::ConvertToANSIString(const nsAFlatString& aStr, + UINT aCodePage, + nsACString& aANSIStr) { int len = ::WideCharToMultiByte(aCodePage, 0, (LPCWSTR)aStr.get(), aStr.Length(), @@ -2006,8 +2084,8 @@ nsIMM32Handler::ConvertToANSIString(const nsAFlatString& aStr, UINT aCodePage, NS_ENSURE_TRUE(len >= 0, false); if (!aANSIStr.SetLength(len, mozilla::fallible)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: ConvertToANSIString, FAILED by OOM\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: ConvertToANSIString, FAILED, due to OOM")); return false; } ::WideCharToMultiByte(aCodePage, 0, (LPCWSTR)aStr.get(), aStr.Length(), @@ -2016,38 +2094,78 @@ nsIMM32Handler::ConvertToANSIString(const nsAFlatString& aStr, UINT aCodePage, } bool -nsIMM32Handler::GetCharacterRectOfSelectedTextAt(nsWindow* aWindow, - uint32_t aOffset, - nsIntRect& aCharRect, - WritingMode* aWritingMode) +IMMHandler::GetCharacterRectOfSelectedTextAt(nsWindow* aWindow, + uint32_t aOffset, + nsIntRect& aCharRect, + WritingMode* aWritingMode) { nsIntPoint point(0, 0); Selection& selection = GetSelection(); if (!selection.EnsureValidSelection(aWindow)) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: GetCharacterRectOfSelectedTextAt, FAILED, due to " + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: GetCharacterRectOfSelectedTextAt, FAILED, due to " "Selection::EnsureValidSelection() failure")); return false; } - uint32_t offset = selection.mOffset + aOffset; - bool useCaretRect = selection.mString.IsEmpty(); - if (useCaretRect && ShouldDrawCompositionStringOurselves() && - mIsComposing && !mCompositionString.IsEmpty()) { - // There is not a normal selection, but we have composition string. - // XXX mnakano - Should we implement NS_QUERY_IME_SELECTED_TEXT? - useCaretRect = false; - if (mCursorPosition != NO_IME_CARET) { - uint32_t cursorPosition = - std::min(mCursorPosition, mCompositionString.Length()); - NS_ASSERTION(offset >= cursorPosition, "offset is less than cursorPosition!"); - offset -= cursorPosition; + // The base offset of aOffset is the start of composition string during + // composing or the start of selected string not during composing. + uint32_t baseOffset = + mIsComposing ? mCompositionStart : selection.mOffset; + + CheckedInt checkingOffset = + CheckedInt(baseOffset) + aOffset; + if (NS_WARN_IF(!checkingOffset.isValid()) || + checkingOffset.value() == UINT32_MAX) { + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: GetCharacterRectOfSelectedTextAt, FAILED, due to " + "aOffset is too large (aOffset=%u, baseOffset=%u, mIsComposing=%s)", + aOffset, baseOffset, GetBoolName(mIsComposing))); + return false; + } + + // If the offset is larger than the end of composition string or selected + // string, we should return false since such case must be a bug of the caller + // or the active IME. If it's an IME's bug, we need to set targetLength to + // aOffset. + uint32_t targetLength = + mIsComposing ? mCompositionString.Length() : selection.Length(); + if (NS_WARN_IF(aOffset > targetLength)) { + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: GetCharacterRectOfSelectedTextAt, FAILED, due to " + "aOffset is too large (aOffset=%u, targetLength=%u, mIsComposing=%s)", + aOffset, targetLength, GetBoolName(mIsComposing))); + return false; + } + + uint32_t offset = checkingOffset.value(); + + // If there is caret, we might be able to use caret rect. + uint32_t caretOffset = UINT32_MAX; + // There is a caret only when the normal selection is collapsed. + if (selection.Collapsed()) { + if (mIsComposing) { + // If it's composing, mCursorPosition is the offset to caret in + // the composition string. + if (mCursorPosition != NO_IME_CARET) { + MOZ_ASSERT(mCursorPosition >= 0); + caretOffset = mCompositionStart + mCursorPosition; + } else if (!ShouldDrawCompositionStringOurselves() || + mCompositionString.IsEmpty()) { + // Otherwise, if there is no composition string, we should assume that + // there is a caret at the start of composition string. + caretOffset = mCompositionStart; + } + } else { + // If there is no composition, the selection offset is the caret offset. + caretOffset = selection.mOffset; } } - nsIntRect r; - if (!useCaretRect) { + // If there is a caret and retrieving offset is same as the caret offset, + // we should use the caret rect. + if (offset != caretOffset) { WidgetQueryContentEvent charRect(true, NS_QUERY_TEXT_RECT, aWindow); charRect.InitForQueryTextRect(offset, 1); aWindow->InitEvent(charRect, &point); @@ -2057,14 +2175,11 @@ nsIMM32Handler::GetCharacterRectOfSelectedTextAt(nsWindow* aWindow, if (aWritingMode) { *aWritingMode = charRect.GetWritingMode(); } - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: GetCharacterRectOfSelectedTextAt, aOffset=%lu, SUCCEEDED\n", - aOffset)); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: GetCharacterRectOfSelectedTextAt, " + MOZ_LOG(gIMMLog, LogLevel::Debug, + ("IMM: GetCharacterRectOfSelectedTextAt, Succeeded, aOffset=%u, " "aCharRect={ x: %ld, y: %ld, width: %ld, height: %ld }, " "charRect.GetWritingMode()=%s", - aCharRect.x, aCharRect.y, aCharRect.width, aCharRect.height, + aOffset, aCharRect.x, aCharRect.y, aCharRect.width, aCharRect.height, GetWritingModeName(charRect.GetWritingMode()).get())); return true; } @@ -2074,16 +2189,16 @@ nsIMM32Handler::GetCharacterRectOfSelectedTextAt(nsWindow* aWindow, } bool -nsIMM32Handler::GetCaretRect(nsWindow* aWindow, - nsIntRect& aCaretRect, - WritingMode* aWritingMode) +IMMHandler::GetCaretRect(nsWindow* aWindow, + nsIntRect& aCaretRect, + WritingMode* aWritingMode) { nsIntPoint point(0, 0); Selection& selection = GetSelection(); if (!selection.EnsureValidSelection(aWindow)) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: GetCaretRect, FAILED, due to " + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: GetCaretRect, FAILED, due to " "Selection::EnsureValidSelection() failure")); return false; } @@ -2093,16 +2208,16 @@ nsIMM32Handler::GetCaretRect(nsWindow* aWindow, aWindow->InitEvent(caretRect, &point); aWindow->DispatchWindowEvent(&caretRect); if (!caretRect.mSucceeded) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: GetCaretRect, FAILED (NS_QUERY_CARET_RECT)\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: GetCaretRect, FAILED, due to NS_QUERY_CARET_RECT failure")); return false; } aCaretRect = LayoutDevicePixel::ToUntyped(caretRect.mReply.mRect); if (aWritingMode) { *aWritingMode = caretRect.GetWritingMode(); } - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: GetCaretRect, SUCCEEDED, " + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: GetCaretRect, SUCCEEDED, " "aCaretRect={ x: %ld, y: %ld, width: %ld, height: %ld }, " "caretRect.GetWritingMode()=%s", aCaretRect.x, aCaretRect.y, aCaretRect.width, aCaretRect.height, @@ -2111,8 +2226,8 @@ nsIMM32Handler::GetCaretRect(nsWindow* aWindow, } bool -nsIMM32Handler::SetIMERelatedWindowsPos(nsWindow* aWindow, - const nsIMEContext &aIMEContext) +IMMHandler::SetIMERelatedWindowsPos(nsWindow* aWindow, + const IMEContext& aContext) { nsIntRect r; // Get first character rect of current a normal selected text or a composing @@ -2137,16 +2252,16 @@ nsIMM32Handler::SetIMERelatedWindowsPos(nsWindow* aWindow, if (!mNativeCaretIsCreated) { mNativeCaretIsCreated = ::CreateCaret(aWindow->GetWindowHandle(), nullptr, caretRect.width, caretRect.height); - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: SetIMERelatedWindowsPos, mNativeCaretIsCreated=%s, width=%ld height=%ld\n", - mNativeCaretIsCreated ? "TRUE" : "FALSE", - caretRect.width, caretRect.height)); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: SetIMERelatedWindowsPos, mNativeCaretIsCreated=%s, " + "width=%ld, height=%ld", + GetBoolName(mNativeCaretIsCreated), caretRect.width, caretRect.height)); } ::SetCaretPos(caretRect.x, caretRect.y); if (ShouldDrawCompositionStringOurselves()) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: SetIMERelatedWindowsPos, Set candidate window\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: SetIMERelatedWindowsPos, Set candidate window")); // Get a rect of first character in current target in composition string. nsIntRect firstTargetCharRect, lastTargetCharRect; @@ -2155,8 +2270,9 @@ nsIMM32Handler::SetIMERelatedWindowsPos(nsWindow* aWindow, // rect instead. uint32_t offset, length; if (!GetTargetClauseRange(&offset, &length)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: SetIMERelatedWindowsPos, FAILED, by GetTargetClauseRange\n")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: SetIMERelatedWindowsPos, FAILED, due to " + "GetTargetClauseRange() failure")); return false; } ret = GetCharacterRectOfSelectedTextAt(aWindow, @@ -2227,8 +2343,8 @@ nsIMM32Handler::SetIMERelatedWindowsPos(nsWindow* aWindow, candForm.ptCurrentPos.x = targetClauseRect.x; candForm.ptCurrentPos.y = targetClauseRect.YMost(); } - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: SetIMERelatedWindowsPos, Calling ImmSetCandidateWindow()... " + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: SetIMERelatedWindowsPos, Calling ImmSetCandidateWindow()... " "ptCurrentPos={ x=%d, y=%d }, " "rcArea={ left=%d, top=%d, right=%d, bottom=%d }, " "writingMode=%s", @@ -2236,10 +2352,10 @@ nsIMM32Handler::SetIMERelatedWindowsPos(nsWindow* aWindow, candForm.rcArea.left, candForm.rcArea.top, candForm.rcArea.right, candForm.rcArea.bottom, GetWritingModeName(writingMode).get())); - ::ImmSetCandidateWindow(aIMEContext.get(), &candForm); + ::ImmSetCandidateWindow(aContext.get(), &candForm); } else { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: SetIMERelatedWindowsPos, Set composition window\n")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: SetIMERelatedWindowsPos, Set composition window")); // Move the composition window to caret position (if selected some // characters, we should use first character rect of them). @@ -2251,23 +2367,23 @@ nsIMM32Handler::SetIMERelatedWindowsPos(nsWindow* aWindow, !writingMode.IsVerticalLR() ? firstSelectedCharRect.x : firstSelectedCharRect.XMost(); compForm.ptCurrentPos.y = firstSelectedCharRect.y; - ::ImmSetCompositionWindow(aIMEContext.get(), &compForm); + ::ImmSetCompositionWindow(aContext.get(), &compForm); } return true; } void -nsIMM32Handler::SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow, - const nsIMEContext& aIMEContext) +IMMHandler::SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow, + const IMEContext& aContext) { WidgetQueryContentEvent editorRectEvent(true, NS_QUERY_EDITOR_RECT, aWindow); aWindow->InitEvent(editorRectEvent); aWindow->DispatchWindowEvent(&editorRectEvent); if (!editorRectEvent.mSucceeded) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: SetIMERelatedWindowsPosOnPlugin, " - "FAILED (NS_QUERY_EDITOR_RECT)")); + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: SetIMERelatedWindowsPosOnPlugin, " + "FAILED, due to NS_QUERY_EDITOR_RECT failure")); return; } @@ -2311,19 +2427,19 @@ nsIMM32Handler::SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow, compForm.dwStyle = CFS_POINT; compForm.ptCurrentPos.x = clippedPluginRect.BottomLeft().x; compForm.ptCurrentPos.y = clippedPluginRect.BottomLeft().y; - if (!::ImmSetCompositionWindow(aIMEContext.get(), &compForm)) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: SetIMERelatedWindowsPosOnPlugin, " - "FAILED to set composition window")); + if (!::ImmSetCompositionWindow(aContext.get(), &compForm)) { + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: SetIMERelatedWindowsPosOnPlugin, " + "FAILED, due to ::ImmSetCompositionWindow() failure")); return; } } void -nsIMM32Handler::ResolveIMECaretPos(nsIWidget* aReferenceWidget, - nsIntRect& aCursorRect, - nsIWidget* aNewOriginWidget, - nsIntRect& aOutRect) +IMMHandler::ResolveIMECaretPos(nsIWidget* aReferenceWidget, + nsIntRect& aCursorRect, + nsIWidget* aNewOriginWidget, + nsIntRect& aOutRect) { aOutRect = aCursorRect; @@ -2367,11 +2483,11 @@ SetVerticalFontToLogFont(const nsAString& aFontFace, } void -nsIMM32Handler::AdjustCompositionFont(const nsIMEContext& aIMEContext, - const WritingMode& aWritingMode, - bool aForceUpdate) +IMMHandler::AdjustCompositionFont(const IMEContext& aContext, + const WritingMode& aWritingMode, + bool aForceUpdate) { - // An instance of nsIMM32Handler is destroyed when active IME is changed. + // An instance of IMMHandler is destroyed when active IME is changed. // Therefore, we need to store the information which are set to the IM // context to static variables since IM context is never recreated. static bool sCompositionFontsInitialized = false; @@ -2405,10 +2521,10 @@ nsIMM32Handler::AdjustCompositionFont(const nsIMEContext& aIMEContext, sCompositionFont.Length() > LF_FACESIZE - 1 || sCompositionFont[0] == '@') { LOGFONTW defaultLogFont; - if (NS_WARN_IF(!::ImmGetCompositionFont(aIMEContext.get(), + if (NS_WARN_IF(!::ImmGetCompositionFont(aContext.get(), &defaultLogFont))) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: AdjustCompositionFont, ::ImmGetCompositionFont() failed")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: AdjustCompositionFont, ::ImmGetCompositionFont() failed")); sCompositionFont.AssignLiteral("System"); } else { // The font face is typically, "System". @@ -2416,8 +2532,8 @@ nsIMM32Handler::AdjustCompositionFont(const nsIMEContext& aIMEContext, } } - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: AdjustCompositionFont, sCompositionFont=\"%s\" is initialized", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: AdjustCompositionFont, sCompositionFont=\"%s\" is initialized", NS_ConvertUTF16toUTF8(sCompositionFont).get())); } @@ -2441,9 +2557,9 @@ nsIMM32Handler::AdjustCompositionFont(const nsIMEContext& aIMEContext, LOGFONTW logFont; memset(&logFont, 0, sizeof(logFont)); - if (!::ImmGetCompositionFont(aIMEContext.get(), &logFont)) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: AdjustCompositionFont, ::ImmGetCompositionFont() failed")); + if (!::ImmGetCompositionFont(aContext.get(), &logFont)) { + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: AdjustCompositionFont, ::ImmGetCompositionFont() failed")); logFont.lfFaceName[0] = 0; } // Need to reset some information which should be recomputed with new font. @@ -2463,18 +2579,19 @@ nsIMM32Handler::AdjustCompositionFont(const nsIMEContext& aIMEContext, IsJapanist2003Active() ? sCompositionFontForJapanist2003 : sCompositionFont, logFont); } - MOZ_LOG(gIMM32Log, LogLevel::Warning, - ("IMM32: AdjustCompositionFont, calling ::ImmSetCompositionFont(\"%s\")", + MOZ_LOG(gIMMLog, LogLevel::Warning, + ("IMM: AdjustCompositionFont, calling ::ImmSetCompositionFont(\"%s\")", NS_ConvertUTF16toUTF8(nsDependentString(logFont.lfFaceName)).get())); - ::ImmSetCompositionFontW(aIMEContext.get(), &logFont); + ::ImmSetCompositionFontW(aContext.get(), &logFont); } -/* static */ nsresult -nsIMM32Handler::OnMouseButtonEvent(nsWindow* aWindow, - const IMENotification& aIMENotification) +// static +nsresult +IMMHandler::OnMouseButtonEvent(nsWindow* aWindow, + const IMENotification& aIMENotification) { // We don't need to create the instance of the handler here. - if (!gIMM32Handler) { + if (!gIMMHandler) { return NS_OK; } @@ -2491,9 +2608,9 @@ nsIMM32Handler::OnMouseButtonEvent(nsWindow* aWindow, // If the character under the cursor is not in the composition string, // we don't need to notify IME of it. - uint32_t compositionStart = gIMM32Handler->mCompositionStart; + uint32_t compositionStart = gIMMHandler->mCompositionStart; uint32_t compositionEnd = - compositionStart + gIMM32Handler->mCompositionString.Length(); + compositionStart + gIMMHandler->mCompositionString.Length(); if (aIMENotification.mMouseButtonEventData.mOffset < compositionStart || aIMENotification.mMouseButtonEventData.mOffset >= compositionEnd) { return NS_OK; @@ -2542,27 +2659,30 @@ nsIMM32Handler::OnMouseButtonEvent(nsWindow* aWindow, offset++; } - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnMouseButtonEvent, x,y=%ld,%ld, offset=%ld, positioning=%ld\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnMouseButtonEvent, x,y=%ld,%ld, offset=%ld, positioning=%ld", cursorPos.x, cursorPos.y, offset, positioning)); // send MS_MSIME_MOUSE message to default IME window. HWND imeWnd = ::ImmGetDefaultIMEWnd(aWindow->GetWindowHandle()); - nsIMEContext IMEContext(aWindow->GetWindowHandle()); + IMEContext context(aWindow); if (::SendMessageW(imeWnd, sWM_MSIME_MOUSE, MAKELONG(MAKEWORD(button, positioning), offset), - (LPARAM) IMEContext.get()) == 1) { + (LPARAM) context.get()) == 1) { return NS_SUCCESS_EVENT_CONSUMED; } return NS_OK; } -/* static */ bool -nsIMM32Handler::OnKeyDownEvent(nsWindow* aWindow, WPARAM wParam, LPARAM lParam, - MSGResult& aResult) +// static +bool +IMMHandler::OnKeyDownEvent(nsWindow* aWindow, + WPARAM wParam, + LPARAM lParam, + MSGResult& aResult) { - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: OnKeyDownEvent, hWnd=%08x, wParam=%08x, lParam=%08x\n", + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: OnKeyDownEvent, hWnd=%08x, wParam=%08x, lParam=%08x", aWindow->GetWindowHandle(), wParam, lParam)); aResult.mConsumed = false; switch (wParam) { @@ -2575,13 +2695,13 @@ nsIMM32Handler::OnKeyDownEvent(nsWindow* aWindow, WPARAM wParam, LPARAM lParam, case VK_UP: case VK_RIGHT: case VK_DOWN: + case VK_RETURN: // If IME didn't process the key message (the virtual key code wasn't // converted to VK_PROCESSKEY), and the virtual key code event causes - // to move caret, we should cancel the composition here. Then, this - // event will be dispatched. - // XXX I think that we should dispatch all key events during composition, - // and nsEditor should cancel/commit the composition if it *thinks* - // it's needed. + // moving caret or editing text with keeping composing state, we should + // cancel the composition here because we cannot support moving + // composition string with DOM events (IE also cancels the composition + // in same cases). Then, this event will be dispatched. if (IsComposingOnOurEditor()) { // NOTE: We don't need to cancel the composition on another window. CancelComposition(aWindow, false); @@ -2593,11 +2713,11 @@ nsIMM32Handler::OnKeyDownEvent(nsWindow* aWindow, WPARAM wParam, LPARAM lParam, } /****************************************************************************** - * nsIMM32Handler::Selection + * IMMHandler::Selection ******************************************************************************/ bool -nsIMM32Handler::Selection::IsValid() const +IMMHandler::Selection::IsValid() const { if (!mIsValid || NS_WARN_IF(mOffset == UINT32_MAX)) { return false; @@ -2608,21 +2728,21 @@ nsIMM32Handler::Selection::IsValid() const } bool -nsIMM32Handler::Selection::Update(const IMENotification& aIMENotification) +IMMHandler::Selection::Update(const IMENotification& aIMENotification) { mOffset = aIMENotification.mSelectionChangeData.mOffset; mString = aIMENotification.mSelectionChangeData.String(); mWritingMode = aIMENotification.mSelectionChangeData.GetWritingMode(); mIsValid = true; - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: Selection::Update, aIMENotification={ mSelectionChangeData={ " + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: Selection::Update, aIMENotification={ mSelectionChangeData={ " "mOffset=%u, mLength=%u, GetWritingMode()=%s } }", mOffset, mString.Length(), GetWritingModeName(mWritingMode).get())); if (!IsValid()) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: Selection::Update, FAILED, due to invalid range")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: Selection::Update, FAILED, due to invalid range")); Clear(); return false; } @@ -2630,7 +2750,7 @@ nsIMM32Handler::Selection::Update(const IMENotification& aIMENotification) } bool -nsIMM32Handler::Selection::Init(nsWindow* aWindow) +IMMHandler::Selection::Init(nsWindow* aWindow) { Clear(); @@ -2639,16 +2759,16 @@ nsIMM32Handler::Selection::Init(nsWindow* aWindow) aWindow->InitEvent(selection, &point); aWindow->DispatchWindowEvent(&selection); if (NS_WARN_IF(!selection.mSucceeded)) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: Selection::Init, FAILED, due to NS_QUERY_SELECTED_TEXT " + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: Selection::Init, FAILED, due to NS_QUERY_SELECTED_TEXT " "failure")); return false; } // If the window is destroyed during querying selected text, we shouldn't // do anymore. if (aWindow->Destroyed()) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: Selection::Init, FAILED, due to the widget destroyed")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: Selection::Init, FAILED, due to the widget destroyed")); return false; } @@ -2657,14 +2777,14 @@ nsIMM32Handler::Selection::Init(nsWindow* aWindow) mWritingMode = selection.GetWritingMode(); mIsValid = true; - MOZ_LOG(gIMM32Log, LogLevel::Info, - ("IMM32: Selection::Init, selection={ mReply={ mOffset=%u, " + MOZ_LOG(gIMMLog, LogLevel::Info, + ("IMM: Selection::Init, selection={ mReply={ mOffset=%u, " "mString.Length()=%u, mWritingMode=%s } }", mOffset, mString.Length(), GetWritingModeName(mWritingMode).get())); if (!IsValid()) { - MOZ_LOG(gIMM32Log, LogLevel::Error, - ("IMM32: Selection::Init, FAILED, due to invalid range")); + MOZ_LOG(gIMMLog, LogLevel::Error, + ("IMM: Selection::Init, FAILED, due to invalid range")); Clear(); return false; } @@ -2672,10 +2792,13 @@ nsIMM32Handler::Selection::Init(nsWindow* aWindow) } bool -nsIMM32Handler::Selection::EnsureValidSelection(nsWindow* aWindow) +IMMHandler::Selection::EnsureValidSelection(nsWindow* aWindow) { if (IsValid()) { return true; } return Init(aWindow); } + +} // namespace widget +} // namespace mozilla diff --git a/widget/windows/nsIMM32Handler.h b/widget/windows/IMMHandler.h similarity index 85% rename from widget/windows/nsIMM32Handler.h rename to widget/windows/IMMHandler.h index 8687dfa0c1..c01a8a441c 100644 --- a/widget/windows/nsIMM32Handler.h +++ b/widget/windows/IMMHandler.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsIMM32Handler_h__ -#define nsIMM32Handler_h__ +#ifndef IMMHandler_h_ +#define IMMHandler_h_ #include "nscore.h" #include @@ -23,18 +23,13 @@ namespace widget { struct MSGResult; -} // namespace widget -} // namespace mozilla - -class nsIMEContext +class IMEContext final { public: - nsIMEContext(HWND aWnd) : mWnd(aWnd) - { - mIMC = ::ImmGetContext(mWnd); - } + explicit IMEContext(HWND aWnd); + explicit IMEContext(nsWindow* aWindow); - ~nsIMEContext() + ~IMEContext() { if (mIMC) { ::ImmReleaseContext(mWnd, mIMC); @@ -95,24 +90,22 @@ public: } protected: - nsIMEContext() + IMEContext() { - NS_ERROR("Don't create nsIMEContext without window handle"); + MOZ_CRASH("Don't create IMEContext without window handle"); } - nsIMEContext(const nsIMEContext &aSrc) : mWnd(nullptr), mIMC(nullptr) + IMEContext(const IMEContext& aOther) { - NS_ERROR("Don't copy nsIMEContext"); + MOZ_CRASH("Don't copy IMEContext"); } HWND mWnd; HIMC mIMC; }; -class nsIMM32Handler +class IMMHandler final { - typedef mozilla::widget::IMENotification IMENotification; - typedef mozilla::widget::MSGResult MSGResult; public: static void Initialize(); static void Terminate(); @@ -187,8 +180,8 @@ protected: WPARAM &wParam, LPARAM &lParam, MSGResult& aResult); - nsIMM32Handler(); - ~nsIMM32Handler(); + IMMHandler(); + ~IMMHandler(); // On*() methods return true if the caller of message handler shouldn't do // anything anymore. Otherwise, false. @@ -234,9 +227,10 @@ protected: // The result of Handle* method mean "Processed" when it's TRUE. void HandleStartComposition(nsWindow* aWindow, - const nsIMEContext &aIMEContext); - bool HandleComposition(nsWindow* aWindow, const nsIMEContext &aIMEContext, - LPARAM lParam); + const IMEContext& aContext); + bool HandleComposition(nsWindow* aWindow, + const IMEContext& aContext, + LPARAM lParam); // If aCommitString is null, this commits composition with the latest // dispatched data. Otherwise, commits composition with the value. void HandleEndComposition(nsWindow* aWindow, @@ -282,18 +276,46 @@ protected: nsACString& aANSIStr); bool SetIMERelatedWindowsPos(nsWindow* aWindow, - const nsIMEContext& aIMEContext); + const IMEContext& aContext); void SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow, - const nsIMEContext& aIMEContext); + const IMEContext& aContext); + /** + * GetCharacterRectOfSelectedTextAt() returns character rect of the offset + * from the selection start or the start of composition string if there is + * a composition. + * + * @param aWindow The window which has focus. + * @param aOffset Offset from the selection start or the start of + * composition string when there is a composition. + * This must be in the selection range or + * the composition string. + * @param aCharRect The result. + * @param aWritingMode The writing mode of current selection. When this + * is nullptr, this assumes that the selection is in + * horizontal writing mode. + * @return true if this succeeded to retrieve the rect. + * Otherwise, false. + */ bool GetCharacterRectOfSelectedTextAt( nsWindow* aWindow, uint32_t aOffset, nsIntRect& aCharRect, mozilla::WritingMode* aWritingMode = nullptr); + /** + * GetCaretRect() returns caret rect at current selection start. + * + * @param aWindow The window which has focus. + * @param aCaretRect The result. + * @param aWritingMode The writing mode of current selection. When this + * is nullptr, this assumes that the selection is in + * horizontal writing mode. + * @return true if this succeeded to retrieve the rect. + * Otherwise, false. + */ bool GetCaretRect(nsWindow* aWindow, nsIntRect& aCaretRect, mozilla::WritingMode* aWritingMode = nullptr); - void GetCompositionString(const nsIMEContext &aIMEContext, + void GetCompositionString(const IMEContext& aContext, DWORD aIndex, nsAString& aCompositionString) const; @@ -302,7 +324,7 @@ protected: * If aForceUpdate is true, it will update composition font even if writing * mode isn't being changed. */ - void AdjustCompositionFont(const nsIMEContext& aIMEContext, + void AdjustCompositionFont(const IMEContext& aContext, const mozilla::WritingMode& aWritingMode, bool aForceUpdate = false); @@ -337,10 +359,10 @@ protected: * being committed, only HandleCompositionEnd() should be called. * * @param aWindow The window which has the composition. - * @param aIMEContext Native IME context which has the composition. + * @param aContext Native IME context which has the composition. */ void DispatchCompositionChangeEvent(nsWindow* aWindow, - const nsIMEContext& aIMEContext); + const IMEContext& aContext); already_AddRefed CreateTextRangeArray(); nsresult EnsureClauseArray(int32_t aCount); @@ -408,6 +430,7 @@ protected: mIsValid = false; } uint32_t Length() const { return mString.Length(); } + bool Collapsed() const { return !Length(); } bool IsValid() const; bool Update(const IMENotification& aIMENotification); @@ -432,4 +455,7 @@ protected: static bool sHasFocus; }; -#endif // nsIMM32Handler_h__ +} // namespace widget +} // namespace mozilla + +#endif // IMMHandler_h_ diff --git a/widget/windows/KeyboardLayout.cpp b/widget/windows/KeyboardLayout.cpp index 4ac1f11a60..a0d27066b4 100644 --- a/widget/windows/KeyboardLayout.cpp +++ b/widget/windows/KeyboardLayout.cpp @@ -16,7 +16,6 @@ #include "nsGkAtoms.h" #include "nsIDOMKeyEvent.h" #include "nsIIdleServiceInternal.h" -#include "nsIMM32Handler.h" #include "nsMemory.h" #include "nsPrintfCString.h" #include "nsQuickSort.h" @@ -1320,7 +1319,7 @@ NativeKey::HandleAppCommandMessage() const // supported. if (!consumed) { uint32_t appCommand = GET_APPCOMMAND_LPARAM(mMsg.lParam); - uint32_t contentCommandMessage = NS_EVENT_NULL; + EventMessage contentCommandMessage = NS_EVENT_NULL; switch (appCommand) { case APPCOMMAND_BROWSER_BACKWARD: case APPCOMMAND_BROWSER_FORWARD: diff --git a/widget/windows/nsTextStore.cpp b/widget/windows/TSFTextStore.cpp similarity index 78% rename from widget/windows/nsTextStore.cpp rename to widget/windows/TSFTextStore.cpp index 9e4128dea7..16c003b994 100644 --- a/widget/windows/nsTextStore.cpp +++ b/widget/windows/TSFTextStore.cpp @@ -19,10 +19,10 @@ #define INPUTSCOPE_INIT_GUID #define TEXTATTRS_INIT_GUID -#include "nsTextStore.h" +#include "TSFTextStore.h" -using namespace mozilla; -using namespace mozilla::widget; +namespace mozilla { +namespace widget { static const char* kPrefNameEnableTSF = "intl.tsf.enable"; static const char* kPrefNameForceEnableTSF = "intl.tsf.force_enable"; @@ -36,13 +36,13 @@ static const char* kPrefNameForceEnableTSF = "intl.tsf.force_enable"; * For logging error, use LogLevel::Error. * * When an instance method is called, start with following text: - * "TSF: 0x%p nsFoo::Bar(", the 0x%p should be the "this" of the nsFoo. + * "TSF: 0x%p TSFFoo::Bar(", the 0x%p should be the "this" of the nsFoo. * after that, start with: - * "TSF: 0x%p nsFoo::Bar(" + * "TSF: 0x%p TSFFoo::Bar(" * In an internal method, start with following text: - * "TSF: 0x%p nsFoo::Bar(" + * "TSF: 0x%p TSFFoo::Bar(" * When a static method is called, start with following text: - * "TSF: nsFoo::Bar(" + * "TSF: TSFFoo::Bar(" */ PRLogModuleInfo* sTextStoreLog = nullptr; @@ -453,7 +453,7 @@ GetTextRunTypeName(TsRunType aRunType) } static nsCString -GetColorName(const TF_DA_COLOR &aColor) +GetColorName(const TF_DA_COLOR& aColor) { switch (aColor.type) { case TF_CT_NONE: @@ -516,7 +516,7 @@ GetClauseAttrName(TF_DA_ATTR_INFO aAttr) } static nsCString -GetDisplayAttrStr(const TF_DISPLAYATTRIBUTE &aDispAttr) +GetDisplayAttrStr(const TF_DISPLAYATTRIBUTE& aDispAttr) { nsAutoCString str; str = "crText:{ "; @@ -731,10 +731,13 @@ public: return S_OK; } - STDMETHODIMP GetPhrase(BSTR **ppbstrPhrases, UINT *pcCount) { return E_NOTIMPL; } - STDMETHODIMP GetRegularExpression(BSTR *pbstrRegExp) { return E_NOTIMPL; } - STDMETHODIMP GetSRGS(BSTR *pbstrSRGS) { return E_NOTIMPL; } - STDMETHODIMP GetXML(BSTR *pbstrXML) { return E_NOTIMPL; } + STDMETHODIMP GetPhrase(BSTR **ppbstrPhrases, UINT* pcCount) + { + return E_NOTIMPL; + } + STDMETHODIMP GetRegularExpression(BSTR* pbstrRegExp) { return E_NOTIMPL; } + STDMETHODIMP GetSRGS(BSTR* pbstrSRGS) { return E_NOTIMPL; } + STDMETHODIMP GetXML(BSTR* pbstrXML) { return E_NOTIMPL; } private: nsTArray mInputScopes; @@ -804,6 +807,85 @@ public: bool EnsureInitActiveTIPKeyboard(); + /**************************************************************************** + * Japanese TIP + ****************************************************************************/ + + // Note that TIP name may depend on the language of the environment. + // For example, some TIP may use localized name for its target language + // environment but English name for the others. + bool IsGoogleJapaneseInputActive() const + { + return mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("Google \x65E5\x672C\x8A9E\x5165\x529B")) || + mActiveTIPKeyboardDescription.EqualsLiteral("Google Japanese Input"); + } + + bool IsATOKActive() const + { + // FYI: Name of ATOK includes the release year like "ATOK 2015". + return StringBeginsWith(mActiveTIPKeyboardDescription, + NS_LITERAL_STRING("ATOK ")); + } + + /**************************************************************************** + * Traditional Chinese TIP + ****************************************************************************/ + + bool IsMSChangJieActive() const + { + return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft ChangJie") || + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("\x5FAE\x8F6F\x4ED3\x9889")) || + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("\x5FAE\x8EDF\x5009\x9821")); + } + + bool IsMSQuickQuickActive() const + { + return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft Quick") || + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("\x5FAE\x8F6F\x901F\x6210")) || + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("\x5FAE\x8EDF\x901F\x6210")); + } + + bool IsFreeChangJieActive() const + { + // FYI: The TIP name is misspelled... + return mActiveTIPKeyboardDescription.EqualsLiteral("Free CangJie IME 10"); + } + + bool IsEasyChangjeiActive() const + { + return + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING( + "\x4E2D\x6587 (\x7E41\x9AD4) - \x6613\x9821\x8F38\x5165\x6CD5")); + } + + /**************************************************************************** + * Simplified Chinese TIP + ****************************************************************************/ + + bool IsMSPinyinActive() const + { + return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft Pinyin") || + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("\x5FAE\x8F6F\x62FC\x97F3")) || + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("\x5FAE\x8EDF\x62FC\x97F3")); + } + + bool IsMSWubiActive() const + { + return mActiveTIPKeyboardDescription.EqualsLiteral("Microsoft Wubi") || + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("\x5FAE\x8F6F\x4E94\x7B14")) || + mActiveTIPKeyboardDescription.Equals( + NS_LITERAL_STRING("\x5FAE\x8EDF\x4E94\x7B46")); + } + public: // ITfActiveLanguageProfileNotifySink STDMETHODIMP OnActivated(REFCLSID clsid, REFGUID guidProfile, BOOL fActivated); @@ -926,7 +1008,7 @@ TSFStaticSink::Destroy() hr = source->UnadviseSink(mIPProfileCookie); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::Shutdown() FAILED to uninstall " + ("TSF: 0x%p TSFTextStore::Shutdown() FAILED to uninstall " "ITfInputProcessorProfileActivationSink (0x%08X)", this, hr)); } @@ -1184,49 +1266,31 @@ TSFStaticSink::IsTIPCategoryKeyboard(REFCLSID aTextService, LANGID aLangID, } /******************************************************************/ -/* nsTextStore */ +/* TSFTextStore */ /******************************************************************/ -StaticRefPtr nsTextStore::sThreadMgr; -StaticRefPtr nsTextStore::sMessagePump; -StaticRefPtr nsTextStore::sKeystrokeMgr; -StaticRefPtr nsTextStore::sDisplayAttrMgr; -StaticRefPtr nsTextStore::sCategoryMgr; -StaticRefPtr nsTextStore::sDisabledDocumentMgr; -StaticRefPtr nsTextStore::sDisabledContext; -StaticRefPtr nsTextStore::sInputProcessorProfiles; -StaticRefPtr nsTextStore::sEnabledTextStore; -DWORD nsTextStore::sClientId = 0; +StaticRefPtr TSFTextStore::sThreadMgr; +StaticRefPtr TSFTextStore::sMessagePump; +StaticRefPtr TSFTextStore::sKeystrokeMgr; +StaticRefPtr TSFTextStore::sDisplayAttrMgr; +StaticRefPtr TSFTextStore::sCategoryMgr; +StaticRefPtr TSFTextStore::sDisabledDocumentMgr; +StaticRefPtr TSFTextStore::sDisabledContext; +StaticRefPtr TSFTextStore::sInputProcessorProfiles; +StaticRefPtr TSFTextStore::sEnabledTextStore; +DWORD TSFTextStore::sClientId = 0; -bool nsTextStore::sCreateNativeCaretForATOK = false; -bool nsTextStore::sDoNotReturnNoLayoutErrorToFreeChangJie = false; -bool nsTextStore::sDoNotReturnNoLayoutErrorToEasyChangjei = false; -bool nsTextStore::sDoNotReturnNoLayoutErrorToGoogleJaInputAtFirstChar = false; -bool nsTextStore::sDoNotReturnNoLayoutErrorToGoogleJaInputAtCaret = false; - -#define TIP_NAME_BEGINS_WITH_ATOK \ - (NS_LITERAL_STRING("ATOK ")) -// NOTE: Free ChangJie 2010 missspells its name... -#define TIP_NAME_FREE_CHANG_JIE_2010 \ - (NS_LITERAL_STRING("Free CangJie IME 10")) -#define TIP_NAME_EASY_CHANGJEI \ - (NS_LITERAL_STRING( \ - "\x4E2D\x6587 (\x7E41\x9AD4) - \x6613\x9821\x8F38\x5165\x6CD5")) -#define TIP_NAME_GOOGLE_JA_INPUT_JA \ - (NS_LITERAL_STRING("Google \x65E5\x672C\x8A9E\x5165\x529B")) -#define TIP_NAME_GOOGLE_JA_INPUT_EN \ - (NS_LITERAL_STRING("Google Japanese Input")) - -static bool -IsGoogleJapaneseInput(const nsAString& aTIPName) -{ - return aTIPName.Equals(TIP_NAME_GOOGLE_JA_INPUT_JA) || - aTIPName.Equals(TIP_NAME_GOOGLE_JA_INPUT_EN); -} +bool TSFTextStore::sCreateNativeCaretForATOK = false; +bool TSFTextStore::sDoNotReturnNoLayoutErrorToMSSimplifiedTIP = false; +bool TSFTextStore::sDoNotReturnNoLayoutErrorToMSTraditionalTIP = false; +bool TSFTextStore::sDoNotReturnNoLayoutErrorToFreeChangJie = false; +bool TSFTextStore::sDoNotReturnNoLayoutErrorToEasyChangjei = false; +bool TSFTextStore::sDoNotReturnNoLayoutErrorToGoogleJaInputAtFirstChar = false; +bool TSFTextStore::sDoNotReturnNoLayoutErrorToGoogleJaInputAtCaret = false; #define TEXTSTORE_DEFAULT_VIEW (1) -nsTextStore::nsTextStore() +TSFTextStore::TSFTextStore() : mEditCookie(0) , mSinkMask(0) , mLock(0) @@ -1237,6 +1301,7 @@ nsTextStore::nsTextStore() , mPendingOnSelectionChange(false) , mPendingOnLayoutChange(false) , mPendingDestroy(false) + , mPendingClearLockedContent(false) , mNativeCaretIsCreated(false) , mDeferNotifyingTSF(false) { @@ -1248,27 +1313,27 @@ nsTextStore::nsTextStore() mPendingActions.SetCapacity(5); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::nsTestStore() SUCCEEDED", this)); + ("TSF: 0x%p TSFTextStore::TSFTextStore() SUCCEEDED", this)); } -nsTextStore::~nsTextStore() +TSFTextStore::~TSFTextStore() { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore instance is destroyed", this)); + ("TSF: 0x%p TSFTextStore instance is destroyed", this)); } bool -nsTextStore::Init(nsWindowBase* aWidget) +TSFTextStore::Init(nsWindowBase* aWidget) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::Init(aWidget=0x%p)", + ("TSF: 0x%p TSFTextStore::Init(aWidget=0x%p)", this, aWidget)); TSFStaticSink::GetInstance()->EnsureInitActiveTIPKeyboard(); if (mDocumentMgr) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::Init() FAILED due to already initialized", + ("TSF: 0x%p TSFTextStore::Init() FAILED due to already initialized", this)); return false; } @@ -1277,7 +1342,7 @@ nsTextStore::Init(nsWindowBase* aWidget) HRESULT hr = sThreadMgr->CreateDocumentMgr(getter_AddRefs(mDocumentMgr)); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::Init() FAILED to create DocumentMgr " + ("TSF: 0x%p TSFTextStore::Init() FAILED to create DocumentMgr " "(0x%08X)", this, hr)); return false; } @@ -1289,7 +1354,7 @@ nsTextStore::Init(nsWindowBase* aWidget) getter_AddRefs(mContext), &mEditCookie); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::Init() FAILED to create the context " + ("TSF: 0x%p TSFTextStore::Init() FAILED to create the context " "(0x%08X)", this, hr)); mDocumentMgr = nullptr; return false; @@ -1298,7 +1363,7 @@ nsTextStore::Init(nsWindowBase* aWidget) hr = mDocumentMgr->Push(mContext); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::Init() FAILED to push the context (0x%08X)", + ("TSF: 0x%p TSFTextStore::Init() FAILED to push the context (0x%08X)", this, hr)); // XXX Why don't we use NS_IF_RELEASE() here?? mContext = nullptr; @@ -1307,7 +1372,7 @@ nsTextStore::Init(nsWindowBase* aWidget) } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::Init() succeeded: " + ("TSF: 0x%p TSFTextStore::Init() succeeded: " "mDocumentMgr=0x%p, mContext=0x%p, mEditCookie=0x%08X", this, mDocumentMgr.get(), mContext.get(), mEditCookie)); @@ -1315,10 +1380,10 @@ nsTextStore::Init(nsWindowBase* aWidget) } bool -nsTextStore::Destroy() +TSFTextStore::Destroy() { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::Destroy(), mLock=%s, " + ("TSF: 0x%p TSFTextStore::Destroy(), mLock=%s, " "mComposition.IsComposing()=%s", this, GetLockFlagNameStr(mLock).get(), GetBoolName(mComposition.IsComposing()))); @@ -1335,9 +1400,11 @@ nsTextStore::Destroy() CommitCompositionInternal(false); } + MaybeDestroyNativeCaret(); + if (mSink) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::Destroy(), calling " + ("TSF: 0x%p TSFTextStore::Destroy(), calling " "ITextStoreACPSink::OnLayoutChange(TS_LC_DESTROY)...", this)); mSink->OnLayoutChange(TS_LC_DESTROY, TEXTSTORE_DEFAULT_VIEW); @@ -1356,19 +1423,19 @@ nsTextStore::Destroy() if (!mMouseTrackers.IsEmpty()) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::Destroy(), removing a mouse tracker...", + ("TSF: 0x%p TSFTextStore::Destroy(), removing a mouse tracker...", this)); mMouseTrackers.Clear(); } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::Destroy() succeeded", this)); + ("TSF: 0x%p TSFTextStore::Destroy() succeeded", this)); return true; } STDMETHODIMP -nsTextStore::QueryInterface(REFIID riid, - void** ppv) +TSFTextStore::QueryInterface(REFIID riid, + void** ppv) { *ppv=nullptr; if ( (IID_IUnknown == riid) || (IID_ITextStoreACP == riid) ) { @@ -1384,32 +1451,32 @@ nsTextStore::QueryInterface(REFIID riid, } MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::QueryInterface() FAILED, riid=%s", + ("TSF: 0x%p TSFTextStore::QueryInterface() FAILED, riid=%s", this, GetRIIDNameStr(riid).get())); return E_NOINTERFACE; } STDMETHODIMP -nsTextStore::AdviseSink(REFIID riid, - IUnknown *punk, - DWORD dwMask) +TSFTextStore::AdviseSink(REFIID riid, + IUnknown* punk, + DWORD dwMask) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::AdviseSink(riid=%s, punk=0x%p, dwMask=%s), " + ("TSF: 0x%p TSFTextStore::AdviseSink(riid=%s, punk=0x%p, dwMask=%s), " "mSink=0x%p, mSinkMask=%s", this, GetRIIDNameStr(riid).get(), punk, GetSinkMaskNameStr(dwMask).get(), mSink.get(), GetSinkMaskNameStr(mSinkMask).get())); if (!punk) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseSink() FAILED due to the null punk", + ("TSF: 0x%p TSFTextStore::AdviseSink() FAILED due to the null punk", this)); return E_UNEXPECTED; } if (IID_ITextStoreACPSink != riid) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::AdviseSink() FAILED due to " "unsupported interface", this)); return E_INVALIDARG; // means unsupported interface. } @@ -1419,7 +1486,7 @@ nsTextStore::AdviseSink(REFIID riid, punk->QueryInterface(IID_ITextStoreACPSink, getter_AddRefs(mSink)); if (!mSink) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::AdviseSink() FAILED due to " "punk not having the interface", this)); return E_UNEXPECTED; } @@ -1431,7 +1498,7 @@ nsTextStore::AdviseSink(REFIID riid, mSink->QueryInterface(IID_IUnknown, getter_AddRefs(comparison2)); if (comparison1 != comparison2) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::AdviseSink() FAILED due to " "the sink being different from the stored sink", this)); return CONNECT_E_ADVISELIMIT; } @@ -1442,21 +1509,21 @@ nsTextStore::AdviseSink(REFIID riid, } STDMETHODIMP -nsTextStore::UnadviseSink(IUnknown *punk) +TSFTextStore::UnadviseSink(IUnknown* punk) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::UnadviseSink(punk=0x%p), mSink=0x%p", + ("TSF: 0x%p TSFTextStore::UnadviseSink(punk=0x%p), mSink=0x%p", this, punk, mSink.get())); if (!punk) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::UnadviseSink() FAILED due to the null punk", + ("TSF: 0x%p TSFTextStore::UnadviseSink() FAILED due to the null punk", this)); return E_INVALIDARG; } if (!mSink) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::UnadviseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::UnadviseSink() FAILED due to " "any sink not stored", this)); return CONNECT_E_NOCONNECTION; } @@ -1467,7 +1534,7 @@ nsTextStore::UnadviseSink(IUnknown *punk) // Unadvise only if sinks are the same if (comparison1 != comparison2) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::UnadviseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::UnadviseSink() FAILED due to " "the sink being different from the stored sink", this)); return CONNECT_E_NOCONNECTION; } @@ -1477,23 +1544,23 @@ nsTextStore::UnadviseSink(IUnknown *punk) } STDMETHODIMP -nsTextStore::RequestLock(DWORD dwLockFlags, - HRESULT *phrSession) +TSFTextStore::RequestLock(DWORD dwLockFlags, + HRESULT* phrSession) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RequestLock(dwLockFlags=%s, phrSession=0x%p), " + ("TSF: 0x%p TSFTextStore::RequestLock(dwLockFlags=%s, phrSession=0x%p), " "mLock=%s", this, GetLockFlagNameStr(dwLockFlags).get(), phrSession, GetLockFlagNameStr(mLock).get())); if (!mSink) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RequestLock() FAILED due to " + ("TSF: 0x%p TSFTextStore::RequestLock() FAILED due to " "any sink not stored", this)); return E_FAIL; } if (!phrSession) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RequestLock() FAILED due to " + ("TSF: 0x%p TSFTextStore::RequestLock() FAILED due to " "null phrSession", this)); return E_INVALIDARG; } @@ -1507,7 +1574,7 @@ nsTextStore::RequestLock(DWORD dwLockFlags, this, GetLockFlagNameStr(mLock).get())); // Don't release this instance during this lock because this is called by // TSF but they don't grab us during this call. - nsRefPtr kungFuDeathGrip(this); + nsRefPtr kungFuDeathGrip(this); *phrSession = mSink->OnLockGranted(mLock); MOZ_LOG(sTextStoreLog, LogLevel::Info, ("TSF: 0x%p Unlocked (%s) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" @@ -1535,7 +1602,7 @@ nsTextStore::RequestLock(DWORD dwLockFlags, MaybeFlushPendingNotifications(); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RequestLock() succeeded: *phrSession=%s", + ("TSF: 0x%p TSFTextStore::RequestLock() succeeded: *phrSession=%s", this, GetTextStoreReturnValueName(*phrSession))); return S_OK; } @@ -1548,26 +1615,22 @@ nsTextStore::RequestLock(DWORD dwLockFlags, mLockQueued = dwLockFlags & (~TS_LF_SYNC); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RequestLock() stores the request in the " + ("TSF: 0x%p TSFTextStore::RequestLock() stores the request in the " "queue, *phrSession=TS_S_ASYNC", this)); return S_OK; } // no more locks allowed MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RequestLock() didn't allow to lock, " + ("TSF: 0x%p TSFTextStore::RequestLock() didn't allow to lock, " "*phrSession=TS_E_SYNCHRONOUS", this)); *phrSession = TS_E_SYNCHRONOUS; return E_FAIL; } void -nsTextStore::DidLockGranted() +TSFTextStore::DidLockGranted() { - if (mNativeCaretIsCreated) { - ::DestroyCaret(); - mNativeCaretIsCreated = false; - } if (IsReadWriteLocked()) { // FreeCJ (TIP for Traditional Chinese) calls SetSelection() to set caret // to the start of composition string and insert a full width space for @@ -1587,7 +1650,7 @@ nsTextStore::DidLockGranted() } void -nsTextStore::DispatchEvent(WidgetGUIEvent& aEvent) +TSFTextStore::DispatchEvent(WidgetGUIEvent& aEvent) { if (NS_WARN_IF(!mWidget) || NS_WARN_IF(mWidget->Destroyed())) { return; @@ -1601,7 +1664,7 @@ nsTextStore::DispatchEvent(WidgetGUIEvent& aEvent) } void -nsTextStore::FlushPendingActions() +TSFTextStore::FlushPendingActions() { if (!mWidget || mWidget->Destroyed()) { mPendingActions.Clear(); @@ -1611,7 +1674,10 @@ nsTextStore::FlushPendingActions() return; } - mLockedContent.Clear(); + // If dispatching event causes NOTIFY_IME_OF_COMPOSITION_UPDATE, we should + // wait to abandon mLockedContent until it's notified because the dispatched + // event may be handled asynchronously in e10s mode. + mPendingClearLockedContent = !mPendingActions.Length(); nsRefPtr kungFuDeathGrip(mWidget); for (uint32_t i = 0; i < mPendingActions.Length(); i++) { @@ -1619,7 +1685,7 @@ nsTextStore::FlushPendingActions() switch (action.mType) { case PendingAction::COMPOSITION_START: { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::FlushPendingActions() " + ("TSF: 0x%p TSFTextStore::FlushPendingActions() " "flushing COMPOSITION_START={ mSelectionStart=%d, " "mSelectionLength=%d }", this, action.mSelectionStart, action.mSelectionLength)); @@ -1634,17 +1700,19 @@ nsTextStore::FlushPendingActions() DispatchEvent(selectionSet); if (!selectionSet.mSucceeded) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::FlushPendingActions() " + ("TSF: 0x%p TSFTextStore::FlushPendingActions() " "FAILED due to NS_SELECTION_SET failure", this)); break; } } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::FlushPendingActions() " + ("TSF: 0x%p TSFTextStore::FlushPendingActions() " "dispatching compositionstart event...", this)); WidgetCompositionEvent compositionStart(true, NS_COMPOSITION_START, mWidget); mWidget->InitEvent(compositionStart); + // NS_COMPOSITION_START always causes NOTIFY_IME_OF_COMPOSITION_UPDATE. + mPendingClearLockedContent = true; DispatchEvent(compositionStart); if (!mWidget || mWidget->Destroyed()) { break; @@ -1653,7 +1721,7 @@ nsTextStore::FlushPendingActions() } case PendingAction::COMPOSITION_UPDATE: { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::FlushPendingActions() " + ("TSF: 0x%p TSFTextStore::FlushPendingActions() " "flushing COMPOSITION_UPDATE={ mData=\"%s\", " "mRanges=0x%p, mRanges->Length()=%d }", this, NS_ConvertUTF16toUTF8(action.mData).get(), action.mRanges.get(), @@ -1694,7 +1762,7 @@ nsTextStore::FlushPendingActions() NS_LITERAL_STRING("\n")); MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::FlushPendingActions(), " + ("TSF: 0x%p TSFTextStore::FlushPendingActions(), " "dispatching compositionchange event...", this)); WidgetCompositionEvent compositionChange(true, NS_COMPOSITION_CHANGE, mWidget); @@ -1708,13 +1776,18 @@ nsTextStore::FlushPendingActions() action.mRanges->AppendElement(wholeRange); } compositionChange.mRanges = action.mRanges; + // When the NS_COMPOSITION_CHANGE causes a DOM text event, + // NOTIFY_IME_OF_COMPOSITION_UPDATE will be notified. + if (compositionChange.CausesDOMTextEvent()) { + mPendingClearLockedContent = true; + } DispatchEvent(compositionChange); // Be aware, the mWidget might already have been destroyed. break; } case PendingAction::COMPOSITION_END: { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::FlushPendingActions() " + ("TSF: 0x%p TSFTextStore::FlushPendingActions() " "flushing COMPOSITION_END={ mData=\"%s\" }", this, NS_ConvertUTF16toUTF8(action.mData).get())); @@ -1722,12 +1795,17 @@ nsTextStore::FlushPendingActions() NS_LITERAL_STRING("\n")); MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::FlushPendingActions(), " + ("TSF: 0x%p TSFTextStore::FlushPendingActions(), " "dispatching compositioncommit event...", this)); WidgetCompositionEvent compositionCommit(true, NS_COMPOSITION_COMMIT, mWidget); mWidget->InitEvent(compositionCommit); compositionCommit.mData = action.mData; + // When the NS_COMPOSITION_COMMIT causes a DOM text event, + // NOTIFY_IME_OF_COMPOSITION_UPDATE will be notified. + if (compositionCommit.CausesDOMTextEvent()) { + mPendingClearLockedContent = true; + } DispatchEvent(compositionCommit); if (!mWidget || mWidget->Destroyed()) { break; @@ -1736,7 +1814,7 @@ nsTextStore::FlushPendingActions() } case PendingAction::SELECTION_SET: { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::FlushPendingActions() " + ("TSF: 0x%p TSFTextStore::FlushPendingActions() " "flushing SELECTION_SET={ mSelectionStart=%d, " "mSelectionLength=%d, mSelectionReversed=%s }", this, action.mSelectionStart, action.mSelectionLength, @@ -1759,7 +1837,7 @@ nsTextStore::FlushPendingActions() } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::FlushPendingActions(), " + ("TSF: 0x%p TSFTextStore::FlushPendingActions(), " "qutting since the mWidget has gone", this)); break; } @@ -1767,11 +1845,11 @@ nsTextStore::FlushPendingActions() } void -nsTextStore::MaybeFlushPendingNotifications() +TSFTextStore::MaybeFlushPendingNotifications() { if (mDeferNotifyingTSF) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::MaybeFlushPendingNotifications(), " + ("TSF: 0x%p TSFTextStore::MaybeFlushPendingNotifications(), " "putting off flushing pending notifications due to being " "dispatching events...", this)); return; @@ -1779,7 +1857,7 @@ nsTextStore::MaybeFlushPendingNotifications() if (IsReadLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::MaybeFlushPendingNotifications(), " + ("TSF: 0x%p TSFTextStore::MaybeFlushPendingNotifications(), " "putting off flushing pending notifications due to being the " "document locked...", this)); return; @@ -1790,30 +1868,35 @@ nsTextStore::MaybeFlushPendingNotifications() return; } + if (mPendingClearLockedContent) { + mPendingClearLockedContent = false; + mLockedContent.Clear(); + } + if (mPendingOnLayoutChange) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::MaybeFlushPendingNotifications(), " - "calling nsTextStore::NotifyTSFOfLayoutChange()...", this)); + ("TSF: 0x%p TSFTextStore::MaybeFlushPendingNotifications(), " + "calling TSFTextStore::NotifyTSFOfLayoutChange()...", this)); NotifyTSFOfLayoutChange(true); } if (mPendingOnSelectionChange) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::MaybeFlushPendingNotifications(), " - "calling nsTextStore::NotifyTSFOfSelectionChange()...", this)); + ("TSF: 0x%p TSFTextStore::MaybeFlushPendingNotifications(), " + "calling TSFTextStore::NotifyTSFOfSelectionChange()...", this)); NotifyTSFOfSelectionChange(); } } STDMETHODIMP -nsTextStore::GetStatus(TS_STATUS *pdcs) +TSFTextStore::GetStatus(TS_STATUS* pdcs) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetStatus(pdcs=0x%p)", this, pdcs)); + ("TSF: 0x%p TSFTextStore::GetStatus(pdcs=0x%p)", this, pdcs)); if (!pdcs) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetStatus() FAILED due to null pdcs", this)); + ("TSF: 0x%p TSFTextStore::GetStatus() FAILED due to null pdcs", this)); return E_INVALIDARG; } pdcs->dwDynamicFlags = 0; @@ -1823,27 +1906,27 @@ nsTextStore::GetStatus(TS_STATUS *pdcs) } STDMETHODIMP -nsTextStore::QueryInsert(LONG acpTestStart, - LONG acpTestEnd, - ULONG cch, - LONG *pacpResultStart, - LONG *pacpResultEnd) +TSFTextStore::QueryInsert(LONG acpTestStart, + LONG acpTestEnd, + ULONG cch, + LONG* pacpResultStart, + LONG* pacpResultEnd) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::QueryInsert(acpTestStart=%ld, " + ("TSF: 0x%p TSFTextStore::QueryInsert(acpTestStart=%ld, " "acpTestEnd=%ld, cch=%lu, pacpResultStart=0x%p, pacpResultEnd=0x%p)", this, acpTestStart, acpTestEnd, cch, acpTestStart, acpTestEnd)); if (!pacpResultStart || !pacpResultEnd) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::QueryInsert() FAILED due to " + ("TSF: 0x%p TSFTextStore::QueryInsert() FAILED due to " "the null argument", this)); return E_INVALIDARG; } if (acpTestStart < 0 || acpTestStart > acpTestEnd) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::QueryInsert() FAILED due to " + ("TSF: 0x%p TSFTextStore::QueryInsert() FAILED due to " "wrong argument", this)); return E_INVALIDARG; } @@ -1854,32 +1937,32 @@ nsTextStore::QueryInsert(LONG acpTestStart, *pacpResultEnd = acpTestStart + cch; MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::QueryInsert() succeeded: " + ("TSF: 0x%p TSFTextStore::QueryInsert() succeeded: " "*pacpResultStart=%ld, *pacpResultEnd=%ld)", this, *pacpResultStart, *pacpResultEnd)); return S_OK; } STDMETHODIMP -nsTextStore::GetSelection(ULONG ulIndex, - ULONG ulCount, - TS_SELECTION_ACP *pSelection, - ULONG *pcFetched) +TSFTextStore::GetSelection(ULONG ulIndex, + ULONG ulCount, + TS_SELECTION_ACP* pSelection, + ULONG* pcFetched) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetSelection(ulIndex=%lu, ulCount=%lu, " + ("TSF: 0x%p TSFTextStore::GetSelection(ulIndex=%lu, ulCount=%lu, " "pSelection=0x%p, pcFetched=0x%p)", this, ulIndex, ulCount, pSelection, pcFetched)); if (!IsReadLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetSelection() FAILED due to not locked", + ("TSF: 0x%p TSFTextStore::GetSelection() FAILED due to not locked", this)); return TS_E_NOLOCK; } if (!ulCount || !pSelection || !pcFetched) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetSelection() FAILED due to " "null argument", this)); return E_INVALIDARG; } @@ -1889,7 +1972,7 @@ nsTextStore::GetSelection(ULONG ulIndex, if (ulIndex != static_cast(TS_DEFAULT_SELECTION) && ulIndex != 0) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetSelection() FAILED due to " "unsupported selection", this)); return TS_E_NOSELECTION; } @@ -1897,23 +1980,23 @@ nsTextStore::GetSelection(ULONG ulIndex, Selection& currentSel = CurrentSelection(); if (currentSel.IsDirty()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetSelection() FAILED due to " "CurrentSelection() failure", this)); return E_FAIL; } *pSelection = currentSel.ACP(); *pcFetched = 1; MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetSelection() succeeded", this)); + ("TSF: 0x%p TSFTextStore::GetSelection() succeeded", this)); return S_OK; } -nsTextStore::Content& -nsTextStore::LockedContent() +TSFTextStore::Content& +TSFTextStore::LockedContent() { - MOZ_ASSERT(IsReadLocked(), - "LockedContent must be called only during the document is locked"); - if (!IsReadLocked()) { + // This should be called when the document is locked or the content hasn't + // been abandoned yet. + if (NS_WARN_IF(!IsReadLocked() && !mLockedContent.IsInitialized())) { mLockedContent.Clear(); return mLockedContent; } @@ -1935,15 +2018,18 @@ nsTextStore::LockedContent() } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::LockedContent(): " - "mLockedContent={ mText.Length()=%d }", - this, mLockedContent.Text().Length())); + ("TSF: 0x%p TSFTextStore::LockedContent(): " + "mLockedContent={ mText.Length()=%d, mLastCompositionString=\"%s\", " + "mMinTextModifiedOffset=%u }", + this, mLockedContent.Text().Length(), + NS_ConvertUTF16toUTF8(mLockedContent.LastCompositionString()).get(), + mLockedContent.MinTextModifiedOffset())); return mLockedContent; } bool -nsTextStore::GetCurrentText(nsAString& aTextContent) +TSFTextStore::GetCurrentText(nsAString& aTextContent) { if (mLockedContent.IsInitialized()) { aTextContent = mLockedContent.Text(); @@ -1965,8 +2051,8 @@ nsTextStore::GetCurrentText(nsAString& aTextContent) return true; } -nsTextStore::Selection& -nsTextStore::CurrentSelection() +TSFTextStore::Selection& +TSFTextStore::CurrentSelection() { if (mSelection.IsDirty()) { // If the window has never been available, we should crash since working @@ -1988,7 +2074,7 @@ nsTextStore::CurrentSelection() } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::CurrentSelection(): " + ("TSF: 0x%p TSFTextStore::CurrentSelection(): " "acpStart=%d, acpEnd=%d (length=%d), reverted=%s", this, mSelection.StartOffset(), mSelection.EndOffset(), mSelection.Length(), @@ -2007,7 +2093,7 @@ GetRangeExtent(ITfRange* aRange, LONG* aStart, LONG* aLength) } static uint32_t -GetGeckoSelectionValue(TF_DISPLAYATTRIBUTE &aDisplayAttr) +GetGeckoSelectionValue(TF_DISPLAYATTRIBUTE& aDisplayAttr) { uint32_t result; switch (aDisplayAttr.bAttr) { @@ -2028,9 +2114,9 @@ GetGeckoSelectionValue(TF_DISPLAYATTRIBUTE &aDisplayAttr) } HRESULT -nsTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty, - ITfRange* aRange, - TF_DISPLAYATTRIBUTE* aResult) +TSFTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty, + ITfRange* aRange, + TF_DISPLAYATTRIBUTE* aResult) { NS_ENSURE_TRUE(aAttrProperty, E_FAIL); NS_ENSURE_TRUE(aRange, E_FAIL); @@ -2042,7 +2128,7 @@ nsTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty, LONG start = 0, length = 0; hr = GetRangeExtent(aRange, &start, &length); MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetDisplayAttribute(): " + ("TSF: 0x%p TSFTextStore::GetDisplayAttribute(): " "GetDisplayAttribute range=%ld-%ld (hr=%s)", this, start - mComposition.mStart, start - mComposition.mStart + length, @@ -2054,13 +2140,13 @@ nsTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty, hr = aAttrProperty->GetValue(TfEditCookie(mEditCookie), aRange, &propValue); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetDisplayAttribute() FAILED due to " "ITfProperty::GetValue() failed", this)); return hr; } if (VT_I4 != propValue.vt) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetDisplayAttribute() FAILED due to " "ITfProperty::GetValue() returns non-VT_I4 value", this)); ::VariantClear(&propValue); return E_FAIL; @@ -2072,7 +2158,7 @@ nsTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty, ::VariantClear(&propValue); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetDisplayAttribute() FAILED due to " "ITfCategoryMgr::GetGUID() failed", this)); return hr; } @@ -2083,7 +2169,7 @@ nsTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty, nullptr); if (FAILED(hr) || !info) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetDisplayAttribute() FAILED due to " "ITfDisplayAttributeMgr::GetDisplayAttributeInfo() failed", this)); return hr; } @@ -2091,28 +2177,28 @@ nsTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty, hr = info->GetAttributeInfo(aResult); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetDisplayAttribute() FAILED due to " "ITfDisplayAttributeInfo::GetAttributeInfo() failed", this)); return hr; } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetDisplayAttribute() succeeded: " + ("TSF: 0x%p TSFTextStore::GetDisplayAttribute() succeeded: " "Result={ %s }", this, GetDisplayAttrStr(*aResult).get())); return S_OK; } HRESULT -nsTextStore::RestartCompositionIfNecessary(ITfRange* aRangeNew) +TSFTextStore::RestartCompositionIfNecessary(ITfRange* aRangeNew) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary(" + ("TSF: 0x%p TSFTextStore::RestartCompositionIfNecessary(" "aRangeNew=0x%p), mComposition.mView=0x%p", this, aRangeNew, mComposition.mView.get())); if (!mComposition.IsComposing()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() FAILED " + ("TSF: 0x%p TSFTextStore::RestartCompositionIfNecessary() FAILED " "due to no composition view", this)); return E_FAIL; } @@ -2124,8 +2210,8 @@ nsTextStore::RestartCompositionIfNecessary(ITfRange* aRangeNew) hr = pComposition->GetRange(getter_AddRefs(composingRange)); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() FAILED " - "due to pComposition->GetRange() failure", this)); + ("TSF: 0x%p TSFTextStore::RestartCompositionIfNecessary() " + "FAILED due to pComposition->GetRange() failure", this)); return hr; } } @@ -2135,13 +2221,13 @@ nsTextStore::RestartCompositionIfNecessary(ITfRange* aRangeNew) hr = GetRangeExtent(composingRange, &compStart, &compLength); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() FAILED " + ("TSF: 0x%p TSFTextStore::RestartCompositionIfNecessary() FAILED " "due to GetRangeExtent() failure", this)); return hr; } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary(), " + ("TSF: 0x%p TSFTextStore::RestartCompositionIfNecessary(), " "range=%ld-%ld, mComposition={ mStart=%ld, mString.Length()=%lu }", this, compStart, compStart + compLength, mComposition.mStart, mComposition.mString.Length())); @@ -2154,21 +2240,21 @@ nsTextStore::RestartCompositionIfNecessary(ITfRange* aRangeNew) hr = RestartComposition(pComposition, composingRange); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() FAILED " - "due to RestartComposition() failure", this)); + ("TSF: 0x%p TSFTextStore::RestartCompositionIfNecessary() " + "FAILED due to RestartComposition() failure", this)); return hr; } } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() succeeded", + ("TSF: 0x%p TSFTextStore::RestartCompositionIfNecessary() succeeded", this)); return S_OK; } HRESULT -nsTextStore::RestartComposition(ITfCompositionView* aCompositionView, - ITfRange* aNewRange) +TSFTextStore::RestartComposition(ITfCompositionView* aCompositionView, + ITfRange* aNewRange) { Selection& currentSelection = CurrentSelection(); @@ -2177,7 +2263,7 @@ nsTextStore::RestartComposition(ITfCompositionView* aCompositionView, LONG newEnd = newStart + newLength; MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RestartComposition(aCompositionView=0x%p, " + ("TSF: 0x%p TSFTextStore::RestartComposition(aCompositionView=0x%p, " "aNewRange=0x%p { newStart=%d, newLength=%d }), " "mComposition={ mStart=%d, mCompositionString.Length()=%d }, " "currentSelection={ IsDirty()=%s, StartOffset()=%d, Length()=%d }", @@ -2188,14 +2274,14 @@ nsTextStore::RestartComposition(ITfCompositionView* aCompositionView, if (currentSelection.IsDirty()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RestartComposition() FAILED " + ("TSF: 0x%p TSFTextStore::RestartComposition() FAILED " "due to CurrentSelection() failure", this)); return E_FAIL; } if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RestartComposition() FAILED " + ("TSF: 0x%p TSFTextStore::RestartComposition() FAILED " "due to GetRangeExtent() failure", this)); return hr; } @@ -2232,7 +2318,7 @@ nsTextStore::RestartComposition(ITfCompositionView* aCompositionView, Content& lockedContent = LockedContent(); if (!lockedContent.IsInitialized()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RestartComposition() FAILED " + ("TSF: 0x%p TSFTextStore::RestartComposition() FAILED " "due to LockedContent() failure", this)); return E_FAIL; } @@ -2265,7 +2351,7 @@ nsTextStore::RestartComposition(ITfCompositionView* aCompositionView, currentSelection = oldSelection; MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RestartComposition() succeeded, " + ("TSF: 0x%p TSFTextStore::RestartComposition() succeeded, " "mComposition={ mStart=%d, mCompositionString.Length()=%d }, " "currentSelection={ IsDirty()=%s, StartOffset()=%d, Length()=%d }", this, mComposition.mStart, mComposition.mString.Length(), @@ -2276,7 +2362,7 @@ nsTextStore::RestartComposition(ITfCompositionView* aCompositionView, } static bool -GetColor(const TF_DA_COLOR &aTSFColor, nscolor &aResult) +GetColor(const TF_DA_COLOR& aTSFColor, nscolor& aResult) { switch (aTSFColor.type) { case TF_CT_SYSCOLOR: { @@ -2296,7 +2382,7 @@ GetColor(const TF_DA_COLOR &aTSFColor, nscolor &aResult) } static bool -GetLineStyle(TF_DA_LINESTYLE aTSFLineStyle, uint8_t &aTextRangeLineStyle) +GetLineStyle(TF_DA_LINESTYLE aTSFLineStyle, uint8_t& aTextRangeLineStyle) { switch (aTSFLineStyle) { case TF_LS_NONE: @@ -2320,10 +2406,10 @@ GetLineStyle(TF_DA_LINESTYLE aTSFLineStyle, uint8_t &aTextRangeLineStyle) } HRESULT -nsTextStore::RecordCompositionUpdateAction() +TSFTextStore::RecordCompositionUpdateAction() { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction(), " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction(), " "mComposition={ mView=0x%p, mStart=%d, mString=\"%s\" " "(Length()=%d) }", this, mComposition.mView.get(), mComposition.mStart, @@ -2332,7 +2418,7 @@ nsTextStore::RecordCompositionUpdateAction() if (!mComposition.IsComposing()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() FAILED " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction() FAILED " "due to no composition view", this)); return E_FAIL; } @@ -2350,7 +2436,7 @@ nsTextStore::RecordCompositionUpdateAction() getter_AddRefs(attrPropetry)); if (FAILED(hr) || !attrPropetry) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() FAILED " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction() FAILED " "due to mContext->GetProperty() failure", this)); return FAILED(hr) ? hr : E_FAIL; } @@ -2359,7 +2445,7 @@ nsTextStore::RecordCompositionUpdateAction() hr = mComposition.mView->GetRange(getter_AddRefs(composingRange)); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction() " "FAILED due to mComposition.mView->GetRange() failure", this)); return hr; } @@ -2369,7 +2455,7 @@ nsTextStore::RecordCompositionUpdateAction() getter_AddRefs(enumRanges), composingRange); if (FAILED(hr) || !enumRanges) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() FAILED " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction() FAILED " "due to attrPropetry->EnumRanges() failure", this)); return FAILED(hr) ? hr : E_FAIL; } @@ -2378,7 +2464,7 @@ nsTextStore::RecordCompositionUpdateAction() Selection& currentSel = CurrentSelection(); if (currentSel.IsDirty()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() FAILED " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction() FAILED " "due to CurrentSelection() failure", this)); return E_FAIL; } @@ -2415,7 +2501,7 @@ nsTextStore::RecordCompositionUpdateAction() LONG length = end - start; if (length < 0) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction() " "ignores invalid range (%d-%d)", this, rangeStart - mComposition.mStart, rangeStart - mComposition.mStart + rangeLength)); @@ -2423,7 +2509,7 @@ nsTextStore::RecordCompositionUpdateAction() } if (!length) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction() " "ignores a range due to outside of the composition or empty " "(%d-%d)", this, rangeStart - mComposition.mStart, @@ -2495,28 +2581,38 @@ nsTextStore::RecordCompositionUpdateAction() } // The caret position has to be collapsed. - LONG caretPosition = currentSel.MaxOffset(); - caretPosition -= mComposition.mStart; - TextRange caretRange; - caretRange.mStartOffset = caretRange.mEndOffset = uint32_t(caretPosition); - caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION; - action->mRanges->AppendElement(caretRange); + uint32_t caretPosition = + static_cast(currentSel.MaxOffset() - mComposition.mStart); + + // If caret is in the target clause and it doesn't have specific style, + // the target clause will be painted as normal selection range. Since caret + // shouldn't be in selection range on Windows, we shouldn't append caret + // range in such case. + const TextRange* targetClause = action->mRanges->GetTargetClause(); + if (!targetClause || targetClause->mRangeStyle.IsDefined() || + caretPosition < targetClause->mStartOffset || + caretPosition > targetClause->mEndOffset) { + TextRange caretRange; + caretRange.mStartOffset = caretRange.mEndOffset = caretPosition; + caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION; + action->mRanges->AppendElement(caretRange); + } action->mIncomplete = false; MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() " + ("TSF: 0x%p TSFTextStore::RecordCompositionUpdateAction() " "succeeded", this)); return S_OK; } HRESULT -nsTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection, - bool aDispatchCompositionChangeEvent) +TSFTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection, + bool aDispatchCompositionChangeEvent) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::SetSelectionInternal(pSelection={ " + ("TSF: 0x%p TSFTextStore::SetSelectionInternal(pSelection={ " "acpStart=%ld, acpEnd=%ld, style={ ase=%s, fInterimChar=%s} }, " "aDispatchCompositionChangeEvent=%s), mComposition.IsComposing()=%s", this, pSelection->acpStart, pSelection->acpEnd, @@ -2530,7 +2626,7 @@ nsTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection, Selection& currentSel = CurrentSelection(); if (currentSel.IsDirty()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetSelectionInternal() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetSelectionInternal() FAILED due to " "CurrentSelection() failure", this)); return E_FAIL; } @@ -2540,7 +2636,7 @@ nsTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection, HRESULT hr = RestartCompositionIfNecessary(); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetSelectionInternal() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetSelectionInternal() FAILED due to " "RestartCompositionIfNecessary() failure", this)); return hr; } @@ -2548,7 +2644,7 @@ nsTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection, if (pSelection->acpStart < mComposition.mStart || pSelection->acpEnd > mComposition.EndOffset()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetSelectionInternal() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetSelectionInternal() FAILED due to " "the selection being out of the composition string", this)); return TS_E_INVALIDPOS; } @@ -2558,7 +2654,7 @@ nsTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection, HRESULT hr = RecordCompositionUpdateAction(); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetSelectionInternal() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetSelectionInternal() FAILED due to " "RecordCompositionUpdateAction() failure", this)); return hr; } @@ -2579,11 +2675,11 @@ nsTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection, } STDMETHODIMP -nsTextStore::SetSelection(ULONG ulCount, - const TS_SELECTION_ACP *pSelection) +TSFTextStore::SetSelection(ULONG ulCount, + const TS_SELECTION_ACP* pSelection) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::SetSelection(ulCount=%lu, pSelection=%p { " + ("TSF: 0x%p TSFTextStore::SetSelection(ulCount=%lu, pSelection=%p { " "acpStart=%ld, acpEnd=%ld, style={ ase=%s, fInterimChar=%s } }), " "mComposition.IsComposing()=%s", this, ulCount, pSelection, @@ -2595,19 +2691,19 @@ nsTextStore::SetSelection(ULONG ulCount, if (!IsReadWriteLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetSelection() FAILED due to " "not locked (read-write)", this)); return TS_E_NOLOCK; } if (ulCount != 1) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetSelection() FAILED due to " "trying setting multiple selection", this)); return E_INVALIDARG; } if (!pSelection) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetSelection() FAILED due to " "null argument", this)); return E_INVALIDARG; } @@ -2615,28 +2711,28 @@ nsTextStore::SetSelection(ULONG ulCount, HRESULT hr = SetSelectionInternal(pSelection, true); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetSelection() FAILED due to " "SetSelectionInternal() failure", this)); } else { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::SetSelection() succeeded", this)); + ("TSF: 0x%p TSFTextStore::SetSelection() succeeded", this)); } return hr; } STDMETHODIMP -nsTextStore::GetText(LONG acpStart, - LONG acpEnd, - WCHAR *pchPlain, - ULONG cchPlainReq, - ULONG *pcchPlainOut, - TS_RUNINFO *prgRunInfo, - ULONG ulRunInfoReq, - ULONG *pulRunInfoOut, - LONG *pacpNext) +TSFTextStore::GetText(LONG acpStart, + LONG acpEnd, + WCHAR* pchPlain, + ULONG cchPlainReq, + ULONG* pcchPlainOut, + TS_RUNINFO* prgRunInfo, + ULONG ulRunInfoReq, + ULONG* pulRunInfoOut, + LONG* pacpNext) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetText(acpStart=%ld, acpEnd=%ld, pchPlain=0x%p, " + ("TSF: 0x%p TSFTextStore::GetText(acpStart=%ld, acpEnd=%ld, pchPlain=0x%p, " "cchPlainReq=%lu, pcchPlainOut=0x%p, prgRunInfo=0x%p, ulRunInfoReq=%lu, " "pulRunInfoOut=0x%p, pacpNext=0x%p), mComposition={ mStart=%ld, " "mString.Length()=%lu, IsComposing()=%s }", @@ -2647,7 +2743,7 @@ nsTextStore::GetText(LONG acpStart, if (!IsReadLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetText() FAILED due to " "not locked (read)", this)); return TS_E_NOLOCK; } @@ -2655,14 +2751,14 @@ nsTextStore::GetText(LONG acpStart, if (!pcchPlainOut || (!pchPlain && !prgRunInfo) || !cchPlainReq != !pchPlain || !ulRunInfoReq != !prgRunInfo) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetText() FAILED due to " "invalid argument", this)); return E_INVALIDARG; } if (acpStart < 0 || acpEnd < -1 || (acpEnd != -1 && acpStart > acpEnd)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetText() FAILED due to " "invalid position", this)); return TS_E_INVALIDPOS; } @@ -2680,20 +2776,20 @@ nsTextStore::GetText(LONG acpStart, Content& lockedContent = LockedContent(); if (!lockedContent.IsInitialized()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetText() FAILED due to " "LockedContent() failure", this)); return E_FAIL; } if (lockedContent.Text().Length() < static_cast(acpStart)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetText() FAILED due to " "acpStart is larger offset than the actual text length", this)); return TS_E_INVALIDPOS; } if (acpEnd != -1 && lockedContent.Text().Length() < static_cast(acpEnd)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetText() FAILED due to " "acpEnd is larger offset than the actual text length", this)); return TS_E_INVALIDPOS; } @@ -2720,7 +2816,7 @@ nsTextStore::GetText(LONG acpStart, } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetText() succeeded: pcchPlainOut=0x%p, " + ("TSF: 0x%p TSFTextStore::GetText() succeeded: pcchPlainOut=0x%p, " "*prgRunInfo={ uCount=%lu, type=%s }, *pulRunInfoOut=%lu, " "*pacpNext=%ld)", this, pcchPlainOut, prgRunInfo ? prgRunInfo->uCount : 0, @@ -2730,15 +2826,15 @@ nsTextStore::GetText(LONG acpStart, } STDMETHODIMP -nsTextStore::SetText(DWORD dwFlags, - LONG acpStart, - LONG acpEnd, - const WCHAR *pchText, - ULONG cch, - TS_TEXTCHANGE *pChange) +TSFTextStore::SetText(DWORD dwFlags, + LONG acpStart, + LONG acpEnd, + const WCHAR* pchText, + ULONG cch, + TS_TEXTCHANGE* pChange) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::SetText(dwFlags=%s, acpStart=%ld, " + ("TSF: 0x%p TSFTextStore::SetText(dwFlags=%s, acpStart=%ld, " "acpEnd=%ld, pchText=0x%p \"%s\", cch=%lu, pChange=0x%p), " "mComposition.IsComposing()=%s", this, dwFlags == TS_ST_CORRECTION ? "TS_ST_CORRECTION" : @@ -2753,7 +2849,7 @@ nsTextStore::SetText(DWORD dwFlags, // call SetSelection followed by InsertTextAtSelection if (!IsReadWriteLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetText() FAILED due to " "not locked (read)", this)); return TS_E_NOLOCK; } @@ -2767,7 +2863,7 @@ nsTextStore::SetText(DWORD dwFlags, HRESULT hr = SetSelectionInternal(&selection); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetText() FAILED due to " "SetSelectionInternal() failure", this)); return hr; } @@ -2775,13 +2871,13 @@ nsTextStore::SetText(DWORD dwFlags, if (!InsertTextAtSelectionInternal(nsDependentSubstring(pchText, cch), pChange)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::SetText() FAILED due to " + ("TSF: 0x%p TSFTextStore::SetText() FAILED due to " "InsertTextAtSelectionInternal() failure", this)); return E_FAIL; } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::SetText() succeeded: pChange={ " + ("TSF: 0x%p TSFTextStore::SetText() succeeded: pChange={ " "acpStart=%ld, acpOldEnd=%ld, acpNewEnd=%ld }", this, pChange ? pChange->acpStart : 0, pChange ? pChange->acpOldEnd : 0, pChange ? pChange->acpNewEnd : 0)); @@ -2789,12 +2885,12 @@ nsTextStore::SetText(DWORD dwFlags, } STDMETHODIMP -nsTextStore::GetFormattedText(LONG acpStart, - LONG acpEnd, - IDataObject **ppDataObject) +TSFTextStore::GetFormattedText(LONG acpStart, + LONG acpEnd, + IDataObject** ppDataObject) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetFormattedText() called " + ("TSF: 0x%p TSFTextStore::GetFormattedText() called " "but not supported (E_NOTIMPL)", this)); // no support for formatted text @@ -2802,13 +2898,13 @@ nsTextStore::GetFormattedText(LONG acpStart, } STDMETHODIMP -nsTextStore::GetEmbedded(LONG acpPos, - REFGUID rguidService, - REFIID riid, - IUnknown **ppunk) +TSFTextStore::GetEmbedded(LONG acpPos, + REFGUID rguidService, + REFIID riid, + IUnknown** ppunk) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetEmbedded() called " + ("TSF: 0x%p TSFTextStore::GetEmbedded() called " "but not supported (E_NOTIMPL)", this)); // embedded objects are not supported @@ -2816,12 +2912,12 @@ nsTextStore::GetEmbedded(LONG acpPos, } STDMETHODIMP -nsTextStore::QueryInsertEmbedded(const GUID *pguidService, - const FORMATETC *pFormatEtc, - BOOL *pfInsertable) +TSFTextStore::QueryInsertEmbedded(const GUID* pguidService, + const FORMATETC* pFormatEtc, + BOOL* pfInsertable) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::QueryInsertEmbedded() called " + ("TSF: 0x%p TSFTextStore::QueryInsertEmbedded() called " "but not supported, *pfInsertable=FALSE (S_OK)", this)); // embedded objects are not supported @@ -2830,14 +2926,14 @@ nsTextStore::QueryInsertEmbedded(const GUID *pguidService, } STDMETHODIMP -nsTextStore::InsertEmbedded(DWORD dwFlags, - LONG acpStart, - LONG acpEnd, - IDataObject *pDataObject, - TS_TEXTCHANGE *pChange) +TSFTextStore::InsertEmbedded(DWORD dwFlags, + LONG acpStart, + LONG acpEnd, + IDataObject* pDataObject, + TS_TEXTCHANGE* pChange) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::InsertEmbedded() called " + ("TSF: 0x%p TSFTextStore::InsertEmbedded() called " "but not supported (E_NOTIMPL)", this)); // embedded objects are not supported @@ -2845,7 +2941,7 @@ nsTextStore::InsertEmbedded(DWORD dwFlags, } void -nsTextStore::SetInputScope(const nsString& aHTMLInputType) +TSFTextStore::SetInputScope(const nsString& aHTMLInputType) { mInputScopes.Clear(); if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) { @@ -2880,7 +2976,7 @@ nsTextStore::SetInputScope(const nsString& aHTMLInputType) } int32_t -nsTextStore::GetRequestedAttrIndex(const TS_ATTRID& aAttrID) +TSFTextStore::GetRequestedAttrIndex(const TS_ATTRID& aAttrID) { if (IsEqualGUID(aAttrID, GUID_PROP_INPUTSCOPE)) { return eInputScope; @@ -2895,7 +2991,7 @@ nsTextStore::GetRequestedAttrIndex(const TS_ATTRID& aAttrID) } TS_ATTRID -nsTextStore::GetAttrID(int32_t aIndex) +TSFTextStore::GetAttrID(int32_t aIndex) { switch (aIndex) { case eInputScope: @@ -2911,12 +3007,12 @@ nsTextStore::GetAttrID(int32_t aIndex) } HRESULT -nsTextStore::HandleRequestAttrs(DWORD aFlags, - ULONG aFilterCount, - const TS_ATTRID* aFilterAttrs) +TSFTextStore::HandleRequestAttrs(DWORD aFlags, + ULONG aFilterCount, + const TS_ATTRID* aFilterAttrs) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::HandleRequestAttrs(aFlags=%s, " + ("TSF: 0x%p TSFTextStore::HandleRequestAttrs(aFlags=%s, " "aFilterCount=%u)", this, GetFindFlagName(aFlags).get(), aFilterCount)); @@ -2933,7 +3029,7 @@ nsTextStore::HandleRequestAttrs(DWORD aFlags, for (uint32_t i = 0; i < aFilterCount; i++) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::HandleRequestAttrs(), " + ("TSF: 0x%p TSFTextStore::HandleRequestAttrs(), " "requested attr=%s", this, GetGUIDNameStrWithTable(aFilterAttrs[i]).get())); int32_t index = GetRequestedAttrIndex(aFilterAttrs[i]); @@ -2945,12 +3041,12 @@ nsTextStore::HandleRequestAttrs(DWORD aFlags, } STDMETHODIMP -nsTextStore::RequestSupportedAttrs(DWORD dwFlags, - ULONG cFilterAttrs, - const TS_ATTRID *paFilterAttrs) +TSFTextStore::RequestSupportedAttrs(DWORD dwFlags, + ULONG cFilterAttrs, + const TS_ATTRID* paFilterAttrs) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RequestSupportedAttrs(dwFlags=%s, " + ("TSF: 0x%p TSFTextStore::RequestSupportedAttrs(dwFlags=%s, " "cFilterAttrs=%lu)", this, GetFindFlagName(dwFlags).get(), cFilterAttrs)); @@ -2958,13 +3054,13 @@ nsTextStore::RequestSupportedAttrs(DWORD dwFlags, } STDMETHODIMP -nsTextStore::RequestAttrsAtPosition(LONG acpPos, - ULONG cFilterAttrs, - const TS_ATTRID *paFilterAttrs, - DWORD dwFlags) +TSFTextStore::RequestAttrsAtPosition(LONG acpPos, + ULONG cFilterAttrs, + const TS_ATTRID* paFilterAttrs, + DWORD dwFlags) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RequestAttrsAtPosition(acpPos=%ld, " + ("TSF: 0x%p TSFTextStore::RequestAttrsAtPosition(acpPos=%ld, " "cFilterAttrs=%lu, dwFlags=%s)", this, acpPos, cFilterAttrs, GetFindFlagName(dwFlags).get())); @@ -2973,13 +3069,13 @@ nsTextStore::RequestAttrsAtPosition(LONG acpPos, } STDMETHODIMP -nsTextStore::RequestAttrsTransitioningAtPosition(LONG acpPos, - ULONG cFilterAttrs, - const TS_ATTRID *paFilterAttr, - DWORD dwFlags) +TSFTextStore::RequestAttrsTransitioningAtPosition(LONG acpPos, + ULONG cFilterAttrs, + const TS_ATTRID* paFilterAttr, + DWORD dwFlags) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RequestAttrsTransitioningAtPosition(" + ("TSF: 0x%p TSFTextStore::RequestAttrsTransitioningAtPosition(" "acpPos=%ld, cFilterAttrs=%lu, dwFlags=%s) called but not supported " "(S_OK)", this, acpPos, cFilterAttrs, GetFindFlagName(dwFlags).get())); @@ -2989,24 +3085,24 @@ nsTextStore::RequestAttrsTransitioningAtPosition(LONG acpPos, } STDMETHODIMP -nsTextStore::FindNextAttrTransition(LONG acpStart, - LONG acpHalt, - ULONG cFilterAttrs, - const TS_ATTRID *paFilterAttrs, - DWORD dwFlags, - LONG *pacpNext, - BOOL *pfFound, - LONG *plFoundOffset) +TSFTextStore::FindNextAttrTransition(LONG acpStart, + LONG acpHalt, + ULONG cFilterAttrs, + const TS_ATTRID* paFilterAttrs, + DWORD dwFlags, + LONG* pacpNext, + BOOL* pfFound, + LONG* plFoundOffset) { if (!pacpNext || !pfFound || !plFoundOffset) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::FindNextAttrTransition() FAILED due to " + ("TSF: 0x%p TSFTextStore::FindNextAttrTransition() FAILED due to " "null argument", this)); return E_INVALIDARG; } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::FindNextAttrTransition() called " + ("TSF: 0x%p TSFTextStore::FindNextAttrTransition() called " "but not supported (S_OK)", this)); // no per character attributes defined @@ -3016,13 +3112,13 @@ nsTextStore::FindNextAttrTransition(LONG acpStart, } STDMETHODIMP -nsTextStore::RetrieveRequestedAttrs(ULONG ulCount, - TS_ATTRVAL *paAttrVals, - ULONG *pcFetched) +TSFTextStore::RetrieveRequestedAttrs(ULONG ulCount, + TS_ATTRVAL* paAttrVals, + ULONG* pcFetched) { if (!pcFetched || !paAttrVals) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() FAILED due to " + ("TSF: 0x%p TSFTextStore::RetrieveRequestedAttrs() FAILED due to " "null argument", this)); return E_INVALIDARG; } @@ -3035,14 +3131,14 @@ nsTextStore::RetrieveRequestedAttrs(ULONG ulCount, } if (ulCount < expectedCount) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() FAILED due to " + ("TSF: 0x%p TSFTextStore::RetrieveRequestedAttrs() FAILED due to " "not enough count ulCount=%u, expectedCount=%u", this, ulCount, expectedCount)); return E_INVALIDARG; } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() called " + ("TSF: 0x%p TSFTextStore::RetrieveRequestedAttrs() called " "ulCount=%d, mRequestedAttrValues=%s", this, ulCount, GetBoolName(mRequestedAttrValues))); @@ -3056,7 +3152,7 @@ nsTextStore::RetrieveRequestedAttrs(ULONG ulCount, TS_ATTRID attrID = GetAttrID(i); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() for %s", + ("TSF: 0x%p TSFTextStore::RetrieveRequestedAttrs() for %s", this, GetGUIDNameStrWithTable(attrID).get())); paAttrVals[count].idAttr = attrID; @@ -3103,7 +3199,7 @@ nsTextStore::RetrieveRequestedAttrs(ULONG ulCount, } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() called " + ("TSF: 0x%p TSFTextStore::RetrieveRequestedAttrs() called " "for unknown TS_ATTRVAL, *pcFetched=0 (S_OK)", this)); paAttrVals->dwOverlapId = 0; @@ -3113,21 +3209,21 @@ nsTextStore::RetrieveRequestedAttrs(ULONG ulCount, } STDMETHODIMP -nsTextStore::GetEndACP(LONG *pacp) +TSFTextStore::GetEndACP(LONG* pacp) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetEndACP(pacp=0x%p)", this, pacp)); + ("TSF: 0x%p TSFTextStore::GetEndACP(pacp=0x%p)", this, pacp)); if (!IsReadLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetEndACP() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetEndACP() FAILED due to " "not locked (read)", this)); return TS_E_NOLOCK; } if (!pacp) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetEndACP() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetEndACP() FAILED due to " "null argument", this)); return E_INVALIDARG; } @@ -3135,7 +3231,7 @@ nsTextStore::GetEndACP(LONG *pacp) Content& lockedContent = LockedContent(); if (!lockedContent.IsInitialized()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetEndACP() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetEndACP() FAILED due to " "LockedContent() failure", this)); return E_FAIL; } @@ -3144,14 +3240,15 @@ nsTextStore::GetEndACP(LONG *pacp) } STDMETHODIMP -nsTextStore::GetActiveView(TsViewCookie *pvcView) +TSFTextStore::GetActiveView(TsViewCookie* pvcView) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetActiveView(pvcView=0x%p)", this, pvcView)); + ("TSF: 0x%p TSFTextStore::GetActiveView(pvcView=0x%p)", + this, pvcView)); if (!pvcView) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetActiveView() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetActiveView() FAILED due to " "null argument", this)); return E_INVALIDARG; } @@ -3159,19 +3256,19 @@ nsTextStore::GetActiveView(TsViewCookie *pvcView) *pvcView = TEXTSTORE_DEFAULT_VIEW; MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetActiveView() succeeded: *pvcView=%ld", + ("TSF: 0x%p TSFTextStore::GetActiveView() succeeded: *pvcView=%ld", this, *pvcView)); return S_OK; } STDMETHODIMP -nsTextStore::GetACPFromPoint(TsViewCookie vcView, - const POINT *pt, - DWORD dwFlags, - LONG *pacp) +TSFTextStore::GetACPFromPoint(TsViewCookie vcView, + const POINT* pt, + DWORD dwFlags, + LONG* pacp) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetACPFromPoint(pvcView=%d, pt=%p (x=%d, " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint(pvcView=%d, pt=%p (x=%d, " "y=%d), dwFlags=%s, pacp=%p, mDeferNotifyingTSF=%s", this, vcView, pt, pt ? pt->x : 0, pt ? pt->y : 0, GetACPFromPointFlagName(dwFlags).get(), pacp, @@ -3179,35 +3276,35 @@ nsTextStore::GetACPFromPoint(TsViewCookie vcView, if (!IsReadLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to " "not locked (read)", this)); return TS_E_NOLOCK; } if (vcView != TEXTSTORE_DEFAULT_VIEW) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to " "called with invalid view", this)); return E_INVALIDARG; } if (!pt) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to " "null pt", this)); return E_INVALIDARG; } if (!pacp) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to " "null pacp", this)); return E_INVALIDARG; } if (mLockedContent.IsLayoutChanged()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to " "layout not recomputed", this)); mPendingOnLayoutChange = true; return TS_E_NOLAYOUT; @@ -3225,24 +3322,24 @@ nsTextStore::GetACPFromPoint(TsViewCookie vcView, // FYI: WidgetQueryContentEvent may cause flushing pending layout and it // may cause focus change or something. - nsRefPtr kungFuDeathGrip(this); + nsRefPtr kungFuDeathGrip(this); DispatchEvent(charAtPt); if (!mWidget || mWidget->Destroyed()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to " "mWidget was destroyed during NS_QUERY_CHARACTER_AT_POINT", this)); return E_FAIL; } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetACPFromPoint(), charAtPt={ " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint(), charAtPt={ " "mSucceeded=%s, mReply={ mOffset=%u, mTentativeCaretOffset=%u }}", this, GetBoolName(charAtPt.mSucceeded), charAtPt.mReply.mOffset, charAtPt.mReply.mTentativeCaretOffset)); if (NS_WARN_IF(!charAtPt.mSucceeded)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to " "NS_QUERY_CHARACTER_AT_POINT failure", this)); return E_FAIL; } @@ -3252,7 +3349,7 @@ nsTextStore::GetACPFromPoint(TsViewCookie vcView, if (!(dwFlags & GXFPF_NEAREST) && charAtPt.mReply.mOffset == WidgetQueryContentEvent::NOT_FOUND) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to the " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to the " "point contained by no bounding box", this)); return TS_E_INVALIDPOINT; } @@ -3290,7 +3387,7 @@ nsTextStore::GetACPFromPoint(TsViewCookie vcView, Content& lockedContent = LockedContent(); if (!lockedContent.IsInitialized()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to " "LockedContent() failure", this)); return E_FAIL; } @@ -3303,27 +3400,27 @@ nsTextStore::GetACPFromPoint(TsViewCookie vcView, if (NS_WARN_IF(offset > LONG_MAX)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to out of " + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() FAILED due to out of " "range of the result", this)); return TS_E_INVALIDPOINT; } *pacp = static_cast(offset); - MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetACPFromPoint() succeeded: *pacp=%d", + MOZ_LOG(sTextStoreLog, LogLevel::Info, + ("TSF: 0x%p TSFTextStore::GetACPFromPoint() succeeded: *pacp=%d", this, *pacp)); return S_OK; } STDMETHODIMP -nsTextStore::GetTextExt(TsViewCookie vcView, - LONG acpStart, - LONG acpEnd, - RECT *prc, - BOOL *pfClipped) +TSFTextStore::GetTextExt(TsViewCookie vcView, + LONG acpStart, + LONG acpEnd, + RECT* prc, + BOOL* pfClipped) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetTextExt(vcView=%ld, " + ("TSF: 0x%p TSFTextStore::GetTextExt(vcView=%ld, " "acpStart=%ld, acpEnd=%ld, prc=0x%p, pfClipped=0x%p), " "mDeferNotifyingTSF=%s", this, vcView, acpStart, acpEnd, prc, pfClipped, @@ -3331,28 +3428,28 @@ nsTextStore::GetTextExt(TsViewCookie vcView, if (!IsReadLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetTextExt() FAILED due to " "not locked (read)", this)); return TS_E_NOLOCK; } if (vcView != TEXTSTORE_DEFAULT_VIEW) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetTextExt() FAILED due to " "called with invalid view", this)); return E_INVALIDARG; } if (!prc || !pfClipped) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetTextExt() FAILED due to " "null argument", this)); return E_INVALIDARG; } if (acpStart < 0 || acpEnd < acpStart) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetTextExt() FAILED due to " "invalid position", this)); return TS_E_INVALIDPOS; } @@ -3361,12 +3458,13 @@ nsTextStore::GetTextExt(TsViewCookie vcView, // caller even if we return it. It's converted to just E_FAIL. // However, this is fixed on Win 10. - const nsString& activeTIPKeyboardDescription = - TSFStaticSink::GetInstance()->GetActiveTIPKeyboardDescription(); + const TSFStaticSink* kSink = TSFStaticSink::GetInstance(); if (mComposition.IsComposing() && mComposition.mStart < acpEnd && mLockedContent.IsLayoutChangedAfter(acpEnd)) { const Selection& currentSel = CurrentSelection(); - if (!IsWin10OrLater()) { + if ((sDoNotReturnNoLayoutErrorToGoogleJaInputAtFirstChar || + sDoNotReturnNoLayoutErrorToGoogleJaInputAtCaret) && + kSink->IsGoogleJapaneseInputActive()) { // Google Japanese Input doesn't handle ITfContextView::GetTextExt() // properly due to the same bug of TSF mentioned above. Google Japanese // Input calls this twice for the first character of changing range of @@ -3374,13 +3472,12 @@ nsTextStore::GetTextExt(TsViewCookie vcView, // composition string. The formar is used for showing candidate window. // This is typically shown at wrong position. We should avoid only this // case. This is not necessary on Windows 10. - if (!mLockedContent.IsLayoutChangedAfter(acpStart) && - acpStart < acpEnd && - sDoNotReturnNoLayoutErrorToGoogleJaInputAtFirstChar && - IsGoogleJapaneseInput(activeTIPKeyboardDescription)) { + if (sDoNotReturnNoLayoutErrorToGoogleJaInputAtFirstChar && + !mLockedContent.IsLayoutChangedAfter(acpStart) && + acpStart < acpEnd) { acpEnd = acpStart; MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetTextExt() hacked the offsets of " + ("TSF: 0x%p TSFTextStore::GetTextExt() hacked the offsets of " "the first character of changing range of the composition " "string for TIP acpStart=%d, acpEnd=%d", this, acpStart, acpEnd)); @@ -3390,13 +3487,12 @@ nsTextStore::GetTextExt(TsViewCookie vcView, // offset of selected clause. However, it's difficult to get where is // selected clause for now. Instead, we should use the first character // which is modified. This is useful in most cases. - else if (acpStart == acpEnd && - currentSel.IsCollapsed() && currentSel.EndOffset() == acpEnd && - sDoNotReturnNoLayoutErrorToGoogleJaInputAtCaret && - IsGoogleJapaneseInput(activeTIPKeyboardDescription)) { + else if (sDoNotReturnNoLayoutErrorToGoogleJaInputAtCaret && + acpStart == acpEnd && + currentSel.IsCollapsed() && currentSel.EndOffset() == acpEnd) { acpEnd = acpStart = mLockedContent.MinOffsetOfLayoutChanged(); MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetTextExt() hacked the offsets of " + ("TSF: 0x%p TSFTextStore::GetTextExt() hacked the offsets of " "the caret of the composition string for TIP acpStart=%d, " "acpEnd=%d", this, acpStart, acpEnd)); } @@ -3406,21 +3502,35 @@ nsTextStore::GetTextExt(TsViewCookie vcView, // TSF. We need to check if this is necessary on Windows 10 before // disabling this on Windows 10. else if ((sDoNotReturnNoLayoutErrorToFreeChangJie && - activeTIPKeyboardDescription.Equals( - TIP_NAME_FREE_CHANG_JIE_2010)) || + kSink->IsFreeChangJieActive()) || (sDoNotReturnNoLayoutErrorToEasyChangjei && - activeTIPKeyboardDescription.Equals(TIP_NAME_EASY_CHANGJEI))) { + kSink->IsEasyChangjeiActive())) { acpEnd = mComposition.mStart; acpStart = std::min(acpStart, acpEnd); MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetTextExt() hacked the offsets for " + ("TSF: 0x%p TSFTextStore::GetTextExt() hacked the offsets for " + "TIP acpStart=%d, acpEnd=%d", this, acpStart, acpEnd)); + } + // Some Chinese TIPs of Microsoft doesn't show candidate window in e10s + // mode on Win8 or later. + else if (IsWin8OrLater() && + ((sDoNotReturnNoLayoutErrorToMSTraditionalTIP && + (kSink->IsMSChangJieActive() || + kSink->IsMSQuickQuickActive())) || + (sDoNotReturnNoLayoutErrorToMSSimplifiedTIP && + (kSink->IsMSPinyinActive() || + kSink->IsMSWubiActive())))) { + acpEnd = mComposition.mStart; + acpStart = std::min(acpStart, acpEnd); + MOZ_LOG(sTextStoreLog, LogLevel::Debug, + ("TSF: 0x%p TSFTextStore::GetTextExt() hacked the offsets for " "TIP acpStart=%d, acpEnd=%d", this, acpStart, acpEnd)); } } if (mLockedContent.IsLayoutChangedAfter(acpEnd)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetTextExt() FAILED due to " "layout not recomputed at %d", this, acpEnd)); mPendingOnLayoutChange = true; return TS_E_NOLAYOUT; @@ -3433,7 +3543,7 @@ nsTextStore::GetTextExt(TsViewCookie vcView, DispatchEvent(event); if (!event.mSucceeded) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetTextExt() FAILED due to " "NS_QUERY_TEXT_RECT failure", this)); return TS_E_INVALIDPOS; // but unexpected failure, maybe. } @@ -3450,7 +3560,7 @@ nsTextStore::GetTextExt(TsViewCookie vcView, refWindow = refWindow->GetTopLevelWindow(false); if (!refWindow) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetTextExt() FAILED due to " "no top level window", this)); return E_FAIL; } @@ -3460,7 +3570,7 @@ nsTextStore::GetTextExt(TsViewCookie vcView, // get bounding screen rect to test for clipping if (!GetScreenExtInternal(*prc)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetTextExt() FAILED due to " "GetScreenExtInternal() failure", this)); return E_FAIL; } @@ -3479,21 +3589,15 @@ nsTextStore::GetTextExt(TsViewCookie vcView, // ATOK refers native caret position and size on Desktop applications for // deciding candidate window. Therefore, we need to create native caret // for hacking the bug. - if (sCreateNativeCaretForATOK && - StringBeginsWith( - activeTIPKeyboardDescription, TIP_NAME_BEGINS_WITH_ATOK) && + if (sCreateNativeCaretForATOK && kSink->IsATOKActive() && mComposition.IsComposing() && mComposition.mStart <= acpStart && mComposition.EndOffset() >= acpStart && mComposition.mStart <= acpEnd && mComposition.EndOffset() >= acpEnd) { - if (mNativeCaretIsCreated) { - ::DestroyCaret(); - mNativeCaretIsCreated = false; - } CreateNativeCaret(); } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetTextExt() succeeded: " + ("TSF: 0x%p TSFTextStore::GetTextExt() succeeded: " "*prc={ left=%ld, top=%ld, right=%ld, bottom=%ld }, *pfClipped=%s", this, prc->left, prc->top, prc->right, prc->bottom, GetBoolName(*pfClipped))); @@ -3502,46 +3606,46 @@ nsTextStore::GetTextExt(TsViewCookie vcView, } STDMETHODIMP -nsTextStore::GetScreenExt(TsViewCookie vcView, - RECT *prc) +TSFTextStore::GetScreenExt(TsViewCookie vcView, + RECT* prc) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetScreenExt(vcView=%ld, prc=0x%p)", + ("TSF: 0x%p TSFTextStore::GetScreenExt(vcView=%ld, prc=0x%p)", this, vcView, prc)); if (vcView != TEXTSTORE_DEFAULT_VIEW) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetScreenExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetScreenExt() FAILED due to " "called with invalid view", this)); return E_INVALIDARG; } if (!prc) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetScreenExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetScreenExt() FAILED due to " "null argument", this)); return E_INVALIDARG; } if (!GetScreenExtInternal(*prc)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetScreenExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetScreenExt() FAILED due to " "GetScreenExtInternal() failure", this)); return E_FAIL; } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetScreenExt() succeeded: " + ("TSF: 0x%p TSFTextStore::GetScreenExt() succeeded: " "*prc={ left=%ld, top=%ld, right=%ld, bottom=%ld }", this, prc->left, prc->top, prc->right, prc->bottom)); return S_OK; } bool -nsTextStore::GetScreenExtInternal(RECT &aScreenExt) +TSFTextStore::GetScreenExtInternal(RECT& aScreenExt) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetScreenExtInternal()", this)); + ("TSF: 0x%p TSFTextStore::GetScreenExtInternal()", this)); // use NS_QUERY_EDITOR_RECT to get rect in system, screen coordinates WidgetQueryContentEvent event(true, NS_QUERY_EDITOR_RECT, mWidget); @@ -3549,7 +3653,7 @@ nsTextStore::GetScreenExtInternal(RECT &aScreenExt) DispatchEvent(event); if (!event.mSucceeded) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetScreenExtInternal() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetScreenExtInternal() FAILED due to " "NS_QUERY_EDITOR_RECT failure", this)); return false; } @@ -3561,7 +3665,7 @@ nsTextStore::GetScreenExtInternal(RECT &aScreenExt) refWindow = refWindow->GetTopLevelWindow(false); if (!refWindow) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetScreenExtInternal() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetScreenExtInternal() FAILED due to " "no top level window", this)); return false; } @@ -3569,7 +3673,7 @@ nsTextStore::GetScreenExtInternal(RECT &aScreenExt) nsIntRect boundRect; if (NS_FAILED(refWindow->GetClientBounds(boundRect))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetScreenExtInternal() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetScreenExtInternal() FAILED due to " "failed to get the client bounds", this)); return false; } @@ -3587,7 +3691,7 @@ nsTextStore::GetScreenExtInternal(RECT &aScreenExt) } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::GetScreenExtInternal() succeeded: " + ("TSF: 0x%p TSFTextStore::GetScreenExtInternal() succeeded: " "aScreenExt={ left=%ld, top=%ld, right=%ld, bottom=%ld }", this, aScreenExt.left, aScreenExt.top, aScreenExt.right, aScreenExt.bottom)); @@ -3595,24 +3699,24 @@ nsTextStore::GetScreenExtInternal(RECT &aScreenExt) } STDMETHODIMP -nsTextStore::GetWnd(TsViewCookie vcView, - HWND *phwnd) +TSFTextStore::GetWnd(TsViewCookie vcView, + HWND* phwnd) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetWnd(vcView=%ld, phwnd=0x%p), " + ("TSF: 0x%p TSFTextStore::GetWnd(vcView=%ld, phwnd=0x%p), " "mWidget=0x%p", this, vcView, phwnd, mWidget.get())); if (vcView != TEXTSTORE_DEFAULT_VIEW) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetWnd() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetWnd() FAILED due to " "called with invalid view", this)); return E_INVALIDARG; } if (!phwnd) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::GetScreenExt() FAILED due to " + ("TSF: 0x%p TSFTextStore::GetScreenExt() FAILED due to " "null argument", this)); return E_INVALIDARG; } @@ -3620,21 +3724,21 @@ nsTextStore::GetWnd(TsViewCookie vcView, *phwnd = mWidget->GetWindowHandle(); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::GetWnd() succeeded: *phwnd=0x%p", + ("TSF: 0x%p TSFTextStore::GetWnd() succeeded: *phwnd=0x%p", this, static_cast(*phwnd))); return S_OK; } STDMETHODIMP -nsTextStore::InsertTextAtSelection(DWORD dwFlags, - const WCHAR *pchText, - ULONG cch, - LONG *pacpStart, - LONG *pacpEnd, - TS_TEXTCHANGE *pChange) +TSFTextStore::InsertTextAtSelection(DWORD dwFlags, + const WCHAR* pchText, + ULONG cch, + LONG* pacpStart, + LONG* pacpEnd, + TS_TEXTCHANGE* pChange) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection(dwFlags=%s, " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection(dwFlags=%s, " "pchText=0x%p \"%s\", cch=%lu, pacpStart=0x%p, pacpEnd=0x%p, " "pChange=0x%p), IsComposing()=%s", this, dwFlags == 0 ? "0" : @@ -3647,7 +3751,7 @@ nsTextStore::InsertTextAtSelection(DWORD dwFlags, if (cch && !pchText) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() FAILED due to " "null pchText", this)); return E_INVALIDARG; } @@ -3655,14 +3759,14 @@ nsTextStore::InsertTextAtSelection(DWORD dwFlags, if (TS_IAS_QUERYONLY == dwFlags) { if (!IsReadLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() FAILED due to " "not locked (read)", this)); return TS_E_NOLOCK; } if (!pacpStart || !pacpEnd) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() FAILED due to " "null argument", this)); return E_INVALIDARG; } @@ -3671,7 +3775,7 @@ nsTextStore::InsertTextAtSelection(DWORD dwFlags, Selection& currentSel = CurrentSelection(); if (currentSel.IsDirty()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() FAILED due to " "CurrentSelection() failure", this)); return E_FAIL; } @@ -3687,21 +3791,21 @@ nsTextStore::InsertTextAtSelection(DWORD dwFlags, } else { if (!IsReadWriteLocked()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() FAILED due to " "not locked (read-write)", this)); return TS_E_NOLOCK; } if (!pChange) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() FAILED due to " "null pChange", this)); return E_INVALIDARG; } if (TS_IAS_NOQUERY != dwFlags && (!pacpStart || !pacpEnd)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() FAILED due to " "null argument", this)); return E_INVALIDARG; } @@ -3709,7 +3813,7 @@ nsTextStore::InsertTextAtSelection(DWORD dwFlags, if (!InsertTextAtSelectionInternal(nsDependentSubstring(pchText, cch), pChange)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() FAILED due to " "InsertTextAtSelectionInternal() failure", this)); return E_FAIL; } @@ -3720,7 +3824,7 @@ nsTextStore::InsertTextAtSelection(DWORD dwFlags, } } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::InsertTextAtSelection() succeeded: " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelection() succeeded: " "*pacpStart=%ld, *pacpEnd=%ld, " "*pChange={ acpStart=%ld, acpOldEnd=%ld, acpNewEnd=%ld })", this, pacpStart ? *pacpStart : 0, pacpEnd ? *pacpEnd : 0, @@ -3730,11 +3834,11 @@ nsTextStore::InsertTextAtSelection(DWORD dwFlags, } bool -nsTextStore::InsertTextAtSelectionInternal(const nsAString &aInsertStr, - TS_TEXTCHANGE* aTextChange) +TSFTextStore::InsertTextAtSelectionInternal(const nsAString& aInsertStr, + TS_TEXTCHANGE* aTextChange) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::InsertTextAtSelectionInternal(" + ("TSF: 0x%p TSFTextStore::InsertTextAtSelectionInternal(" "aInsertStr=\"%s\", aTextChange=0x%p), IsComposing=%s", this, NS_ConvertUTF16toUTF8(aInsertStr).get(), aTextChange, GetBoolName(mComposition.IsComposing()))); @@ -3742,7 +3846,7 @@ nsTextStore::InsertTextAtSelectionInternal(const nsAString &aInsertStr, Content& lockedContent = LockedContent(); if (!lockedContent.IsInitialized()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::InsertTextAtSelectionInternal() failed " + ("TSF: 0x%p TSFTextStore::InsertTextAtSelectionInternal() failed " "due to LockedContent() failure()", this)); return false; } @@ -3770,9 +3874,9 @@ nsTextStore::InsertTextAtSelectionInternal(const nsAString &aInsertStr, } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::InsertTextAtSelectionInternal() succeeded: " - "mWidget=0x%p, mWidget->Destroyed()=%s, aTextChange={ acpStart=%ld, " - "acpOldEnd=%ld, acpNewEnd=%ld }", + ("TSF: 0x%p TSFTextStore::InsertTextAtSelectionInternal() " + "succeeded: mWidget=0x%p, mWidget->Destroyed()=%s, aTextChange={ " + "acpStart=%ld, acpOldEnd=%ld, acpNewEnd=%ld }", this, mWidget.get(), GetBoolName(mWidget ? mWidget->Destroyed() : true), aTextChange ? aTextChange->acpStart : 0, @@ -3782,14 +3886,14 @@ nsTextStore::InsertTextAtSelectionInternal(const nsAString &aInsertStr, } STDMETHODIMP -nsTextStore::InsertEmbeddedAtSelection(DWORD dwFlags, - IDataObject *pDataObject, - LONG *pacpStart, - LONG *pacpEnd, - TS_TEXTCHANGE *pChange) +TSFTextStore::InsertEmbeddedAtSelection(DWORD dwFlags, + IDataObject* pDataObject, + LONG* pacpStart, + LONG* pacpEnd, + TS_TEXTCHANGE* pChange) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::InsertEmbeddedAtSelection() called " + ("TSF: 0x%p TSFTextStore::InsertEmbeddedAtSelection() called " "but not supported (E_NOTIMPL)", this)); // embedded objects are not supported @@ -3797,12 +3901,12 @@ nsTextStore::InsertEmbeddedAtSelection(DWORD dwFlags, } HRESULT -nsTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, - ITfRange* aRange, - bool aPreserveSelection) +TSFTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, + ITfRange* aRange, + bool aPreserveSelection) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RecordCompositionStartAction(" + ("TSF: 0x%p TSFTextStore::RecordCompositionStartAction(" "aComposition=0x%p, aRange=0x%p, aPreserveSelection=%s), " "mComposition.mView=0x%p", this, aComposition, aRange, GetBoolName(aPreserveSelection), @@ -3812,7 +3916,7 @@ nsTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, HRESULT hr = GetRangeExtent(aRange, &start, &length); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionStartAction() FAILED " + ("TSF: 0x%p TSFTextStore::RecordCompositionStartAction() FAILED " "due to GetRangeExtent() failure", this)); return hr; } @@ -3822,13 +3926,13 @@ nsTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, } HRESULT -nsTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, - LONG aStart, - LONG aLength, - bool aPreserveSelection) +TSFTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, + LONG aStart, + LONG aLength, + bool aPreserveSelection) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RecordCompositionStartAction(" + ("TSF: 0x%p TSFTextStore::RecordCompositionStartAction(" "aComposition=0x%p, aStart=%d, aLength=%d, aPreserveSelection=%s), " "mComposition.mView=0x%p", this, aComposition, aStart, aLength, GetBoolName(aPreserveSelection), @@ -3837,7 +3941,7 @@ nsTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, Content& lockedContent = LockedContent(); if (!lockedContent.IsInitialized()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionStartAction() FAILED " + ("TSF: 0x%p TSFTextStore::RecordCompositionStartAction() FAILED " "due to LockedContent() failure", this)); return E_FAIL; } @@ -3851,7 +3955,7 @@ nsTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, Selection& currentSel = CurrentSelection(); if (currentSel.IsDirty()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionStartAction() FAILED " + ("TSF: 0x%p TSFTextStore::RecordCompositionStartAction() FAILED " "due to CurrentSelection() failure", this)); action->mAdjustSelection = true; } else if (currentSel.MinOffset() != aStart || @@ -3870,7 +3974,7 @@ nsTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, lockedContent.StartComposition(aComposition, *action, aPreserveSelection); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RecordCompositionStartAction() succeeded: " + ("TSF: 0x%p TSFTextStore::RecordCompositionStartAction() succeeded: " "mComposition={ mStart=%ld, mString.Length()=%ld, " "mSelection={ acpStart=%ld, acpEnd=%ld, style.ase=%s, " "style.fInterimChar=%s } }", @@ -3882,10 +3986,10 @@ nsTextStore::RecordCompositionStartAction(ITfCompositionView* aComposition, } HRESULT -nsTextStore::RecordCompositionEndAction() +TSFTextStore::RecordCompositionEndAction() { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::RecordCompositionEndAction(), " + ("TSF: 0x%p TSFTextStore::RecordCompositionEndAction(), " "mComposition={ mView=0x%p, mString=\"%s\" }", this, mComposition.mView.get(), NS_ConvertUTF16toUTF8(mComposition.mString).get())); @@ -3900,24 +4004,24 @@ nsTextStore::RecordCompositionEndAction() Content& lockedContent = LockedContent(); if (!lockedContent.IsInitialized()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::RecordCompositionEndAction() FAILED due " + ("TSF: 0x%p TSFTextStore::RecordCompositionEndAction() FAILED due " "to LockedContent() failure", this)); return E_FAIL; } lockedContent.EndComposition(*action); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::RecordCompositionEndAction(), succeeded", + ("TSF: 0x%p TSFTextStore::RecordCompositionEndAction(), succeeded", this)); return S_OK; } STDMETHODIMP -nsTextStore::OnStartComposition(ITfCompositionView* pComposition, - BOOL* pfOk) +TSFTextStore::OnStartComposition(ITfCompositionView* pComposition, + BOOL* pfOk) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnStartComposition(pComposition=0x%p, " + ("TSF: 0x%p TSFTextStore::OnStartComposition(pComposition=0x%p, " "pfOk=0x%p), mComposition.mView=0x%p", this, pComposition, pfOk, mComposition.mView.get())); @@ -3928,7 +4032,7 @@ nsTextStore::OnStartComposition(ITfCompositionView* pComposition, // Only one composition at a time if (mComposition.IsComposing()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnStartComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnStartComposition() FAILED due to " "there is another composition already (but returns S_OK)", this)); return S_OK; } @@ -3937,30 +4041,30 @@ nsTextStore::OnStartComposition(ITfCompositionView* pComposition, HRESULT hr = pComposition->GetRange(getter_AddRefs(range)); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnStartComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnStartComposition() FAILED due to " "pComposition->GetRange() failure", this)); return hr; } hr = RecordCompositionStartAction(pComposition, range, false); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnStartComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnStartComposition() FAILED due to " "RecordCompositionStartAction() failure", this)); return hr; } *pfOk = TRUE; MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnStartComposition() succeeded", this)); + ("TSF: 0x%p TSFTextStore::OnStartComposition() succeeded", this)); return S_OK; } STDMETHODIMP -nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, - ITfRange* pRangeNew) +TSFTextStore::OnUpdateComposition(ITfCompositionView* pComposition, + ITfRange* pRangeNew) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnUpdateComposition(pComposition=0x%p, " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition(pComposition=0x%p, " "pRangeNew=0x%p), mComposition.mView=0x%p", this, pComposition, pRangeNew, mComposition.mView.get())); @@ -3968,19 +4072,19 @@ nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, if (!mDocumentMgr || !mContext) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition() FAILED due to " "not ready for the composition", this)); return E_UNEXPECTED; } if (!mComposition.IsComposing()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition() FAILED due to " "no active composition", this)); return E_UNEXPECTED; } if (mComposition.mView != pComposition) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition() FAILED due to " "different composition view specified", this)); return E_UNEXPECTED; } @@ -3990,7 +4094,7 @@ nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, PendingAction* action = LastOrNewPendingCompositionUpdate(); action->mIncomplete = true; MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnUpdateComposition() succeeded but " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition() succeeded but " "not complete", this)); return S_OK; } @@ -3998,7 +4102,7 @@ nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, HRESULT hr = RestartCompositionIfNecessary(pRangeNew); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition() FAILED due to " "RestartCompositionIfNecessary() failure", this)); return hr; } @@ -4006,7 +4110,7 @@ nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, hr = RecordCompositionUpdateAction(); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition() FAILED due to " "RecordCompositionUpdateAction() failure", this)); return hr; } @@ -4015,12 +4119,12 @@ nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, Selection& currentSel = CurrentSelection(); if (currentSel.IsDirty()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition() FAILED due to " "CurrentSelection() failure", this)); return E_FAIL; } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnUpdateComposition() succeeded: " + ("TSF: 0x%p TSFTextStore::OnUpdateComposition() succeeded: " "mComposition={ mStart=%ld, mString=\"%s\" }, " "CurrentSelection()={ acpStart=%ld, acpEnd=%ld, style.ase=%s }", this, mComposition.mStart, @@ -4032,10 +4136,10 @@ nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition, } STDMETHODIMP -nsTextStore::OnEndComposition(ITfCompositionView* pComposition) +TSFTextStore::OnEndComposition(ITfCompositionView* pComposition) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnEndComposition(pComposition=0x%p), " + ("TSF: 0x%p TSFTextStore::OnEndComposition(pComposition=0x%p), " "mComposition={ mView=0x%p, mString=\"%s\" }", this, pComposition, mComposition.mView.get(), NS_ConvertUTF16toUTF8(mComposition.mString).get())); @@ -4044,14 +4148,14 @@ nsTextStore::OnEndComposition(ITfCompositionView* pComposition) if (!mComposition.IsComposing()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnEndComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnEndComposition() FAILED due to " "no active composition", this)); return E_UNEXPECTED; } if (mComposition.mView != pComposition) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnEndComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnEndComposition() FAILED due to " "different composition view specified", this)); return E_UNEXPECTED; } @@ -4059,28 +4163,28 @@ nsTextStore::OnEndComposition(ITfCompositionView* pComposition) HRESULT hr = RecordCompositionEndAction(); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::OnEndComposition() FAILED due to " + ("TSF: 0x%p TSFTextStore::OnEndComposition() FAILED due to " "RecordCompositionEndAction() failure", this)); return hr; } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnEndComposition(), succeeded", this)); + ("TSF: 0x%p TSFTextStore::OnEndComposition(), succeeded", this)); return S_OK; } STDMETHODIMP -nsTextStore::AdviseMouseSink(ITfRangeACP* range, - ITfMouseSink* pSink, - DWORD* pdwCookie) +TSFTextStore::AdviseMouseSink(ITfRangeACP* range, + ITfMouseSink* pSink, + DWORD* pdwCookie) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::AdviseMouseSink(range=0x%p, pSink=0x%p, " + ("TSF: 0x%p TSFTextStore::AdviseMouseSink(range=0x%p, pSink=0x%p, " "pdwCookie=0x%p)", this, range, pSink, pdwCookie)); if (!pdwCookie) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseMouseSink() FAILED due to the " + ("TSF: 0x%p TSFTextStore::AdviseMouseSink() FAILED due to the " "pdwCookie is null", this)); return E_INVALIDARG; } @@ -4089,13 +4193,13 @@ nsTextStore::AdviseMouseSink(ITfRangeACP* range, if (!range) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseMouseSink() FAILED due to the " + ("TSF: 0x%p TSFTextStore::AdviseMouseSink() FAILED due to the " "range is null", this)); return E_INVALIDARG; } if (!pSink) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseMouseSink() FAILED due to the " + ("TSF: 0x%p TSFTextStore::AdviseMouseSink() FAILED due to the " "pSink is null", this)); return E_INVALIDARG; } @@ -4115,7 +4219,7 @@ nsTextStore::AdviseMouseSink(ITfRangeACP* range, HRESULT hr = tracker->Init(this); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseMouseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::AdviseMouseSink() FAILED due to " "failure of MouseTracker::Init()", this)); return hr; } @@ -4123,26 +4227,26 @@ nsTextStore::AdviseMouseSink(ITfRangeACP* range, HRESULT hr = tracker->AdviseSink(this, range, pSink); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::AdviseMouseSink() FAILED due to failure " + ("TSF: 0x%p TSFTextStore::AdviseMouseSink() FAILED due to failure " "of MouseTracker::Init()", this)); return hr; } *pdwCookie = tracker->Cookie(); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::AdviseMouseSink(), succeeded, " + ("TSF: 0x%p TSFTextStore::AdviseMouseSink(), succeeded, " "*pdwCookie=%d", this, *pdwCookie)); return S_OK; } STDMETHODIMP -nsTextStore::UnadviseMouseSink(DWORD dwCookie) +TSFTextStore::UnadviseMouseSink(DWORD dwCookie) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::UnadviseMouseSink(dwCookie=%d)", + ("TSF: 0x%p TSFTextStore::UnadviseMouseSink(dwCookie=%d)", this, dwCookie)); if (dwCookie == MouseTracker::kInvalidCookie) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::UnadviseMouseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::UnadviseMouseSink() FAILED due to " "the cookie is invalid value", this)); return E_INVALIDARG; } @@ -4150,31 +4254,31 @@ nsTextStore::UnadviseMouseSink(DWORD dwCookie) // We can use this shortcut for now. if (static_cast(dwCookie) >= mMouseTrackers.Length()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::UnadviseMouseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::UnadviseMouseSink() FAILED due to " "the cookie is too large value", this)); return E_INVALIDARG; } MouseTracker& tracker = mMouseTrackers[dwCookie]; if (!tracker.IsUsing()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::UnadviseMouseSink() FAILED due to " + ("TSF: 0x%p TSFTextStore::UnadviseMouseSink() FAILED due to " "the found tracker uninstalled already", this)); return E_INVALIDARG; } tracker.UnadviseSink(); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::UnadviseMouseSink(), succeeded", this)); + ("TSF: 0x%p TSFTextStore::UnadviseMouseSink(), succeeded", this)); return S_OK; } // static nsresult -nsTextStore::OnFocusChange(bool aGotFocus, - nsWindowBase* aFocusedWidget, - const InputContext& aContext) +TSFTextStore::OnFocusChange(bool aGotFocus, + nsWindowBase* aFocusedWidget, + const InputContext& aContext) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: nsTextStore::OnFocusChange(aGotFocus=%s, " + ("TSF: TSFTextStore::OnFocusChange(aGotFocus=%s, " "aFocusedWidget=0x%p, aContext={ mIMEState={ mEnabled=%s }, " "mHTMLInputType=\"%s\" }), " "sThreadMgr=0x%p, sEnabledTextStore=0x%p", @@ -4187,9 +4291,10 @@ nsTextStore::OnFocusChange(bool aGotFocus, return NS_ERROR_NOT_AVAILABLE; } + nsRefPtr prevFocusedDocumentMgr; + // If currently sEnableTextStore has focus, notifies TSF of losing focus. if (ThinksHavingFocus()) { - nsRefPtr prevFocusedDocumentMgr; DebugOnly hr = sThreadMgr->AssociateFocus( sEnabledTextStore->mWidget->GetWindowHandle(), @@ -4212,7 +4317,7 @@ nsTextStore::OnFocusChange(bool aGotFocus, HRESULT hr = sThreadMgr->SetFocus(sDisabledDocumentMgr); if (NS_WARN_IF(FAILED(hr))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::OnFocusChange() FAILED due to " + ("TSF: TSFTextStore::OnFocusChange() FAILED due to " "ITfThreadMgr::SetFocus() failure")); return NS_ERROR_FAILURE; } @@ -4222,7 +4327,7 @@ nsTextStore::OnFocusChange(bool aGotFocus, // If an editor is getting focus, create new TextStore and set focus. if (NS_WARN_IF(!CreateAndSetFocus(aFocusedWidget, aContext))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::OnFocusChange() FAILED due to " + ("TSF: TSFTextStore::OnFocusChange() FAILED due to " "ITfThreadMgr::CreateAndSetFocus() failure")); // If setting focus, we should destroy the TextStore completely because // it causes memory leak. @@ -4237,23 +4342,23 @@ nsTextStore::OnFocusChange(bool aGotFocus, // static bool -nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget, - const InputContext& aContext) +TSFTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget, + const InputContext& aContext) { // TSF might do something which causes that we need to access static methods - // of nsTextStore. At that time, sEnabledTextStore may be necessary. + // of TSFTextStore. At that time, sEnabledTextStore may be necessary. // So, we should set sEnabledTextStore directly. - sEnabledTextStore = new nsTextStore(); + sEnabledTextStore = new TSFTextStore(); if (NS_WARN_IF(!sEnabledTextStore->Init(aFocusedWidget))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::CreateAndSetFocus() FAILED due to " - "nsTextStore::Init() failure")); + ("TSF: TSFTextStore::CreateAndSetFocus() FAILED due to " + "TSFTextStore::Init() failure")); return false; } if (NS_WARN_IF(!sEnabledTextStore->mDocumentMgr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::CreateAndSetFocus() FAILED due to " - "invalid nsTextStore::mDocumentMgr")); + ("TSF: TSFTextStore::CreateAndSetFocus() FAILED due to " + "invalid TSFTextStore::mDocumentMgr")); return false; } if (aContext.mIMEState.mEnabled == IMEState::PASSWORD) { @@ -4267,7 +4372,7 @@ nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget, HRESULT hr = sThreadMgr->SetFocus(sEnabledTextStore->mDocumentMgr); if (NS_WARN_IF(FAILED(hr))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::CreateAndSetFocus() FAILED due to " + ("TSF: TSFTextStore::CreateAndSetFocus() FAILED due to " "ITfTheadMgr::SetFocus() failure")); return false; } @@ -4279,7 +4384,7 @@ nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget, getter_AddRefs(prevFocusedDocumentMgr)); if (NS_WARN_IF(FAILED(hr))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::CreateAndSetFocus() FAILED due to " + ("TSF: TSFTextStore::CreateAndSetFocus() FAILED due to " "ITfTheadMgr::AssociateFocus() failure")); return false; } @@ -4287,7 +4392,7 @@ nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget, if (sEnabledTextStore->mSink) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: nsTextStore::CreateAndSetFocus(), calling " + ("TSF: TSFTextStore::CreateAndSetFocus(), calling " "ITextStoreACPSink::OnLayoutChange(TS_LC_CREATE) for 0x%p...", sEnabledTextStore.get())); sEnabledTextStore->mSink->OnLayoutChange(TS_LC_CREATE, @@ -4298,7 +4403,7 @@ nsTextStore::CreateAndSetFocus(nsWindowBase* aFocusedWidget, // static nsIMEUpdatePreference -nsTextStore::GetIMEUpdatePreference() +TSFTextStore::GetIMEUpdatePreference() { if (sThreadMgr && sEnabledTextStore && sEnabledTextStore->mDocumentMgr) { nsRefPtr docMgr; @@ -4310,7 +4415,7 @@ nsTextStore::GetIMEUpdatePreference() nsIMEUpdatePreference::NOTIFY_POSITION_CHANGE | nsIMEUpdatePreference::NOTIFY_MOUSE_BUTTON_EVENT_ON_CHAR | nsIMEUpdatePreference::NOTIFY_DURING_DEACTIVE); - // nsTextStore shouldn't notify TSF of selection change and text change + // TSFTextStore shouldn't notify TSF of selection change and text change // which are caused by composition. updatePreference.DontNotifyChangesCausedByComposition(); return updatePreference; @@ -4320,10 +4425,10 @@ nsTextStore::GetIMEUpdatePreference() } nsresult -nsTextStore::OnTextChangeInternal(const IMENotification& aIMENotification) +TSFTextStore::OnTextChangeInternal(const IMENotification& aIMENotification) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::OnTextChangeInternal(aIMENotification={ " + ("TSF: 0x%p TSFTextStore::OnTextChangeInternal(aIMENotification={ " "mMessage=0x%08X, mTextChangeData={ mStartOffset=%lu, " "mRemovedEndOffset=%lu, mAddedEndOffset=%lu}), mSink=0x%p, " "mSinkMask=%s, mComposition.IsComposing()=%s", @@ -4360,7 +4465,7 @@ nsTextStore::OnTextChangeInternal(const IMENotification& aIMENotification) NotifyTSFOfTextChange(textChange); } else { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::NotifyTSFOfTextChange() FAILED due to " + ("TSF: 0x%p TSFTextStore::NotifyTSFOfTextChange() FAILED due to " "offset is too big for calling " "ITextStoreACPSink::OnTextChange()...", this)); @@ -4372,8 +4477,10 @@ nsTextStore::OnTextChangeInternal(const IMENotification& aIMENotification) } void -nsTextStore::NotifyTSFOfTextChange(const TS_TEXTCHANGE& aTextChange) +TSFTextStore::NotifyTSFOfTextChange(const TS_TEXTCHANGE& aTextChange) { + // XXX We need to cache the text change ranges and notify TSF of that + // the document is unlocked. if (NS_WARN_IF(IsReadLocked())) { return; } @@ -4383,7 +4490,7 @@ nsTextStore::NotifyTSFOfTextChange(const TS_TEXTCHANGE& aTextChange) // For preventing it, let's commit the composition. if (mComposition.IsComposing()) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::NotifyTSFOfTextChange(), " + ("TSF: 0x%p TSFTextStore::NotifyTSFOfTextChange(), " "committing the composition for avoiding making TIP confused...", this)); CommitCompositionInternal(false); @@ -4391,7 +4498,7 @@ nsTextStore::NotifyTSFOfTextChange(const TS_TEXTCHANGE& aTextChange) } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::NotifyTSFOfTextChange(), calling " + ("TSF: 0x%p TSFTextStore::NotifyTSFOfTextChange(), calling " "ITextStoreACPSink::OnTextChange(0, { acpStart=%ld, acpOldEnd=%ld, " "acpNewEnd=%ld })...", this, aTextChange.acpStart, aTextChange.acpOldEnd, aTextChange.acpNewEnd)); @@ -4399,12 +4506,12 @@ nsTextStore::NotifyTSFOfTextChange(const TS_TEXTCHANGE& aTextChange) } nsresult -nsTextStore::OnSelectionChangeInternal(const IMENotification& aIMENotification) +TSFTextStore::OnSelectionChangeInternal(const IMENotification& aIMENotification) { const IMENotification::SelectionChangeData& selectionChangeData = aIMENotification.mSelectionChangeData; MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::OnSelectionChangeInternal(" + ("TSF: 0x%p TSFTextStore::OnSelectionChangeInternal(" "aIMENotification={ mSelectionChangeData={ mOffset=%lu, " "Length()=%lu, mReversed=%s, mWritingMode=%s, " "mCausedByComposition=%s, mCausedBySelectionEvent=%s } }), " @@ -4438,7 +4545,7 @@ nsTextStore::OnSelectionChangeInternal(const IMENotification& aIMENotification) mPendingOnSelectionChange = true; if (mIsRecordingActionsWithoutLock) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnSelectionChangeInternal(), putting " + ("TSF: 0x%p TSFTextStore::OnSelectionChangeInternal(), putting " "off notifying TSF of selection change...", this)); return NS_OK; } @@ -4457,7 +4564,7 @@ nsTextStore::OnSelectionChangeInternal(const IMENotification& aIMENotification) } void -nsTextStore::NotifyTSFOfSelectionChange() +TSFTextStore::NotifyTSFOfSelectionChange() { if (NS_WARN_IF(IsReadLocked())) { return; @@ -4474,7 +4581,7 @@ nsTextStore::NotifyTSFOfSelectionChange() // For preventing it, let's commit the composition. if (mComposition.IsComposing()) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::NotifyTSFOfSelectionChange(), " + ("TSF: 0x%p TSFTextStore::NotifyTSFOfSelectionChange(), " "committing the composition for avoiding making TIP confused...", this)); CommitCompositionInternal(false); @@ -4482,13 +4589,13 @@ nsTextStore::NotifyTSFOfSelectionChange() } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::NotifyTSFOfSelectionChange(), calling " + ("TSF: 0x%p TSFTextStore::NotifyTSFOfSelectionChange(), calling " "ITextStoreACPSink::OnSelectionChange()...", this)); mSink->OnSelectionChange(); } nsresult -nsTextStore::OnLayoutChangeInternal() +TSFTextStore::OnLayoutChangeInternal() { NS_ENSURE_TRUE(mContext, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mSink, NS_ERROR_FAILURE); @@ -4501,14 +4608,14 @@ nsTextStore::OnLayoutChangeInternal() // So, don't use MaybeFlushPendingNotifications() for flushing pending // layout change. MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::OnLayoutChangeInternal(), calling " + ("TSF: 0x%p TSFTextStore::OnLayoutChangeInternal(), calling " "NotifyTSFOfLayoutChange()...", this)); if (NS_WARN_IF(!NotifyTSFOfLayoutChange(mPendingOnLayoutChange))) { rv = NS_ERROR_FAILURE; } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::OnLayoutChangeInternal(), calling " + ("TSF: 0x%p TSFTextStore::OnLayoutChangeInternal(), calling " "MaybeFlushPendingNotifications()...", this)); MaybeFlushPendingNotifications(); @@ -4516,16 +4623,26 @@ nsTextStore::OnLayoutChangeInternal() } bool -nsTextStore::NotifyTSFOfLayoutChange(bool aFlush) +TSFTextStore::NotifyTSFOfLayoutChange(bool aFlush) { mPendingOnLayoutChange = false; + // Now, layout has been computed. We should notify mLockedContent for + // making GetTextExt() and GetACPFromPoint() not return TS_E_NOLAYOUT. + if (mLockedContent.IsInitialized()) { + mLockedContent.OnLayoutChanged(); + } + + // Now, the caret position is different from ours. Destroy the native caret + // if there is. + MaybeDestroyNativeCaret(); + // This method should return true if either way succeeds. bool ret = false; if (mSink) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::NotifyTSFOfLayoutChange(), " + ("TSF: 0x%p TSFTextStore::NotifyTSFOfLayoutChange(), " "calling ITextStoreACPSink::OnLayoutChange()...", this)); HRESULT hr = mSink->OnLayoutChange(TS_LC_CHANGE, TEXTSTORE_DEFAULT_VIEW); @@ -4540,7 +4657,7 @@ nsTextStore::NotifyTSFOfLayoutChange(bool aFlush) getter_AddRefs(service)); if (service) { MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::NotifyTSFOfLayoutChange(), " + ("TSF: 0x%p TSFTextStore::NotifyTSFOfLayoutChange(), " "calling ITfContextOwnerServices::OnLayoutChange()...", this)); HRESULT hr = service->OnLayoutChange(); @@ -4552,30 +4669,29 @@ nsTextStore::NotifyTSFOfLayoutChange(bool aFlush) } nsresult -nsTextStore::OnUpdateCompositionInternal() +TSFTextStore::OnUpdateCompositionInternal() { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::OnUpdateCompositionInternal(), " + ("TSF: 0x%p TSFTextStore::OnUpdateCompositionInternal(), " "mDeferNotifyingTSF=%s", this, GetBoolName(mDeferNotifyingTSF))); - if (!mDeferNotifyingTSF) { - return NS_OK; - } + mPendingClearLockedContent = true; mDeferNotifyingTSF = false; MaybeFlushPendingNotifications(); return NS_OK; } nsresult -nsTextStore::OnMouseButtonEventInternal(const IMENotification& aIMENotification) +TSFTextStore::OnMouseButtonEventInternal( + const IMENotification& aIMENotification) { if (mMouseTrackers.IsEmpty()) { return NS_OK; } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::OnMouseButtonEventInternal(" + ("TSF: 0x%p TSFTextStore::OnMouseButtonEventInternal(" "aIMENotification={ mEventMessage=%s, mOffset=%u, mCursorPos={ " "mX=%d, mY=%d }, mCharRect={ mX=%d, mY=%d, mWidth=%d, mHeight=%d }, " "mButton=%s, mButtons=%s, mModifiers=%s })", @@ -4642,17 +4758,19 @@ nsTextStore::OnMouseButtonEventInternal(const IMENotification& aIMENotification) } void -nsTextStore::CreateNativeCaret() +TSFTextStore::CreateNativeCaret() { + MaybeDestroyNativeCaret(); + MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::CreateNativeCaret(), " + ("TSF: 0x%p TSFTextStore::CreateNativeCaret(), " "mComposition.IsComposing()=%s", this, GetBoolName(mComposition.IsComposing()))); Selection& currentSel = CurrentSelection(); if (currentSel.IsDirty()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::CreateNativeCaret() FAILED due to " + ("TSF: 0x%p TSFTextStore::CreateNativeCaret() FAILED due to " "CurrentSelection() failure", this)); return; } @@ -4667,7 +4785,7 @@ nsTextStore::CreateNativeCaret() DispatchEvent(queryCaretRect); if (!queryCaretRect.mSucceeded) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::CreateNativeCaret() FAILED due to " + ("TSF: 0x%p TSFTextStore::CreateNativeCaret() FAILED due to " "NS_QUERY_CARET_RECT failure (offset=%d)", this, caretOffset)); return; } @@ -4677,7 +4795,7 @@ nsTextStore::CreateNativeCaret() caretRect.width, caretRect.height); if (!mNativeCaretIsCreated) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::CreateNativeCaret() FAILED due to " + ("TSF: 0x%p TSFTextStore::CreateNativeCaret() FAILED due to " "CreateCaret() failure", this)); return; } @@ -4686,7 +4804,7 @@ nsTextStore::CreateNativeCaret() nsWindow* toplevelWindow = window->GetTopLevelWindow(false); if (!toplevelWindow) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::CreateNativeCaret() FAILED due to " + ("TSF: 0x%p TSFTextStore::CreateNativeCaret() FAILED due to " "no top level window", this)); return; } @@ -4700,10 +4818,25 @@ nsTextStore::CreateNativeCaret() } void -nsTextStore::CommitCompositionInternal(bool aDiscard) +TSFTextStore::MaybeDestroyNativeCaret() +{ + if (!mNativeCaretIsCreated) { + return; + } + + MOZ_LOG(sTextStoreLog, LogLevel::Debug, + ("TSF: 0x%p TSFTextStore::MaybeDestroyNativeCaret(), " + "destroying native caret", this)); + + ::DestroyCaret(); + mNativeCaretIsCreated = false; +} + +void +TSFTextStore::CommitCompositionInternal(bool aDiscard) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::CommitCompositionInternal(aDiscard=%s), " + ("TSF: 0x%p TSFTextStore::CommitCompositionInternal(aDiscard=%s), " "mSink=0x%p, mContext=0x%p, mComposition.mView=0x%p, " "mComposition.mString=\"%s\"", this, GetBoolName(aDiscard), mSink.get(), mContext.get(), @@ -4719,7 +4852,7 @@ nsTextStore::CommitCompositionInternal(bool aDiscard) textChange.acpOldEnd = endOffset; textChange.acpNewEnd = mComposition.mStart; MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: 0x%p nsTextStore::CommitCompositionInternal(), calling" + ("TSF: 0x%p TSFTextStore::CommitCompositionInternal(), calling" "mSink->OnTextChange(0, { acpStart=%ld, acpOldEnd=%ld, " "acpNewEnd=%ld })...", this, textChange.acpStart, textChange.acpOldEnd, textChange.acpNewEnd)); @@ -4736,7 +4869,7 @@ nsTextStore::CommitCompositionInternal(bool aDiscard) getter_AddRefs(services)); if (services) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::CommitCompositionInternal(), " + ("TSF: 0x%p TSFTextStore::CommitCompositionInternal(), " "requesting TerminateComposition() for the context 0x%p...", this, context.get())); services->TerminateComposition(nullptr); @@ -4767,17 +4900,18 @@ GetCompartment(IUnknown* pUnk, // static void -nsTextStore::SetIMEOpenState(bool aState) +TSFTextStore::SetIMEOpenState(bool aState) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: nsTextStore::SetIMEOpenState(aState=%s)", GetBoolName(aState))); + ("TSF: TSFTextStore::SetIMEOpenState(aState=%s)", + GetBoolName(aState))); nsRefPtr comp; if (!GetCompartment(sThreadMgr, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, getter_AddRefs(comp))) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: nsTextStore::SetIMEOpenState() FAILED due to" + ("TSF: TSFTextStore::SetIMEOpenState() FAILED due to" "no compartment available")); return; } @@ -4786,7 +4920,7 @@ nsTextStore::SetIMEOpenState(bool aState) variant.vt = VT_I4; variant.lVal = aState; MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: nsTextStore::SetIMEOpenState(), setting " + ("TSF: TSFTextStore::SetIMEOpenState(), setting " "0x%04X to GUID_COMPARTMENT_KEYBOARD_OPENCLOSE...", variant.lVal)); comp->SetValue(sClientId, &variant); @@ -4794,7 +4928,7 @@ nsTextStore::SetIMEOpenState(bool aState) // static bool -nsTextStore::GetIMEOpenState(void) +TSFTextStore::GetIMEOpenState() { nsRefPtr comp; if (!GetCompartment(sThreadMgr, @@ -4813,12 +4947,12 @@ nsTextStore::GetIMEOpenState(void) // static void -nsTextStore::SetInputContext(nsWindowBase* aWidget, +TSFTextStore::SetInputContext(nsWindowBase* aWidget, const InputContext& aContext, const InputContextAction& aAction) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: nsTextStore::SetInputContext(aWidget=%p, " + ("TSF: TSFTextStore::SetInputContext(aWidget=%p, " "aContext.mIMEState.mEnabled=%s, aAction.mFocusChange=%s), " "sEnabledTextStore=0x%p, ThinksHavingFocus()=%s", aWidget, GetIMEEnabledName(aContext.mIMEState.mEnabled), @@ -4845,7 +4979,7 @@ nsTextStore::SetInputContext(nsWindowBase* aWidget, // static void -nsTextStore::MarkContextAsKeyboardDisabled(ITfContext* aContext) +TSFTextStore::MarkContextAsKeyboardDisabled(ITfContext* aContext) { VARIANT variant_int4_value1; variant_int4_value1.vt = VT_I4; @@ -4856,13 +4990,13 @@ nsTextStore::MarkContextAsKeyboardDisabled(ITfContext* aContext) GUID_COMPARTMENT_KEYBOARD_DISABLED, getter_AddRefs(comp))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::MarkContextAsKeyboardDisabled() failed" + ("TSF: TSFTextStore::MarkContextAsKeyboardDisabled() failed" "aContext=0x%p...", aContext)); return; } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: nsTextStore::MarkContextAsKeyboardDisabled(), setting " + ("TSF: TSFTextStore::MarkContextAsKeyboardDisabled(), setting " "to disable context 0x%p...", aContext)); comp->SetValue(sClientId, &variant_int4_value1); @@ -4870,7 +5004,7 @@ nsTextStore::MarkContextAsKeyboardDisabled(ITfContext* aContext) // static void -nsTextStore::MarkContextAsEmpty(ITfContext* aContext) +TSFTextStore::MarkContextAsEmpty(ITfContext* aContext) { VARIANT variant_int4_value1; variant_int4_value1.vt = VT_I4; @@ -4881,40 +5015,39 @@ nsTextStore::MarkContextAsEmpty(ITfContext* aContext) GUID_COMPARTMENT_EMPTYCONTEXT, getter_AddRefs(comp))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::MarkContextAsEmpty() failed" + ("TSF: TSFTextStore::MarkContextAsEmpty() failed" "aContext=0x%p...", aContext)); return; } MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: nsTextStore::MarkContextAsEmpty(), setting " + ("TSF: TSFTextStore::MarkContextAsEmpty(), setting " "to mark empty context 0x%p...", aContext)); comp->SetValue(sClientId, &variant_int4_value1); } // static void -nsTextStore::Initialize() +TSFTextStore::Initialize() { if (!sTextStoreLog) { sTextStoreLog = PR_NewLogModule("nsTextStoreWidgets"); } MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: nsTextStore::Initialize() is called...")); + ("TSF: TSFTextStore::Initialize() is called...")); if (sThreadMgr) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED due to already initialized")); + ("TSF: TSFTextStore::Initialize() FAILED due to already initialized")); return; } bool enableTsf = Preferences::GetBool(kPrefNameForceEnableTSF, false) || - (IsVistaOrLater() && Preferences::GetBool(kPrefNameEnableTSF, false) && - !BrowserTabsRemoteAutostart()); + (IsVistaOrLater() && Preferences::GetBool(kPrefNameEnableTSF, false)); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: nsTextStore::Initialize(), TSF is %s", + ("TSF: TSFTextStore::Initialize(), TSF is %s", enableTsf ? "enabled" : "disabled")); if (!enableTsf) { return; @@ -4932,7 +5065,7 @@ nsTextStore::Initialize() getter_AddRefs(inputProcessorProfiles)); if (FAILED(hr) || !inputProcessorProfiles) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to create input processor " + ("TSF: TSFTextStore::Initialize() FAILED to create input processor " "profiles, hr=0x%08X", hr)); return; } @@ -4943,7 +5076,7 @@ nsTextStore::Initialize() getter_AddRefs(threadMgr)); if (FAILED(hr) || !threadMgr) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to " + ("TSF: TSFTextStore::Initialize() FAILED to " "create the thread manager, hr=0x%08X", hr)); return; } @@ -4953,7 +5086,7 @@ nsTextStore::Initialize() getter_AddRefs(messagePump)); if (FAILED(hr) || !messagePump) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to " + ("TSF: TSFTextStore::Initialize() FAILED to " "QI message pump from the thread manager, hr=0x%08X", hr)); return; } @@ -4963,7 +5096,7 @@ nsTextStore::Initialize() getter_AddRefs(keystrokeMgr)); if (FAILED(hr) || !keystrokeMgr) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to " + ("TSF: TSFTextStore::Initialize() FAILED to " "QI keystroke manager from the thread manager, hr=0x%08X", hr)); return; } @@ -4971,7 +5104,7 @@ nsTextStore::Initialize() hr = threadMgr->Activate(&sClientId); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to activate, hr=0x%08X", hr)); + ("TSF: TSFTextStore::Initialize() FAILED to activate, hr=0x%08X", hr)); return; } @@ -4981,7 +5114,7 @@ nsTextStore::Initialize() getter_AddRefs(displayAttributeMgr)); if (FAILED(hr) || !displayAttributeMgr) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to create " + ("TSF: TSFTextStore::Initialize() FAILED to create " "a display attribute manager instance, hr=0x%08X", hr)); return; } @@ -4992,7 +5125,7 @@ nsTextStore::Initialize() getter_AddRefs(categoryMgr)); if (FAILED(hr) || !categoryMgr) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to create " + ("TSF: TSFTextStore::Initialize() FAILED to create " "a category manager instance, hr=0x%08X", hr)); return; } @@ -5001,7 +5134,7 @@ nsTextStore::Initialize() hr = threadMgr->CreateDocumentMgr(getter_AddRefs(disabledDocumentMgr)); if (FAILED(hr) || !disabledDocumentMgr) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to create " + ("TSF: TSFTextStore::Initialize() FAILED to create " "a document manager for disabled mode, hr=0x%08X", hr)); return; } @@ -5013,7 +5146,7 @@ nsTextStore::Initialize() &editCookie); if (FAILED(hr) || !disabledContext) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to create " + ("TSF: TSFTextStore::Initialize() FAILED to create " "a context for disabled mode, hr=0x%08X", hr)); return; } @@ -5022,13 +5155,13 @@ nsTextStore::Initialize() MarkContextAsEmpty(disabledContext); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: nsTextStore::Initialize() is creating " + ("TSF: TSFTextStore::Initialize() is creating " "a TSFStaticSink instance...")); TSFStaticSink* staticSink = TSFStaticSink::GetInstance(); if (!staticSink->Init(threadMgr, inputProcessorProfiles)) { TSFStaticSink::Shutdown(); MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::Initialize() FAILED to initialize TSFStaticSink " + ("TSF: TSFTextStore::Initialize() FAILED to initialize TSFStaticSink " "instance")); return; } @@ -5044,6 +5177,14 @@ nsTextStore::Initialize() sCreateNativeCaretForATOK = Preferences::GetBool("intl.tsf.hack.atok.create_native_caret", true); + sDoNotReturnNoLayoutErrorToMSSimplifiedTIP = + Preferences::GetBool( + "intl.tsf.hack.ms_simplified_chinese.do_not_return_no_layout_error", + true); + sDoNotReturnNoLayoutErrorToMSTraditionalTIP = + Preferences::GetBool( + "intl.tsf.hack.ms_traditional_chinese.do_not_return_no_layout_error", + true); sDoNotReturnNoLayoutErrorToFreeChangJie = Preferences::GetBool( "intl.tsf.hack.free_chang_jie.do_not_return_no_layout_error", true); @@ -5060,13 +5201,13 @@ nsTextStore::Initialize() true); MOZ_LOG(sTextStoreLog, LogLevel::Info, - ("TSF: nsTextStore::Initialize(), sThreadMgr=0x%p, " + ("TSF: TSFTextStore::Initialize(), sThreadMgr=0x%p, " "sClientId=0x%08X, sDisplayAttrMgr=0x%p, " "sCategoryMgr=0x%p, sDisabledDocumentMgr=0x%p, sDisabledContext=%p, " "sCreateNativeCaretForATOK=%s, " "sDoNotReturnNoLayoutErrorToFreeChangJie=%s, " "sDoNotReturnNoLayoutErrorToEasyChangjei=%s, " - "sDoNotReturnNoLayoutErrorToGoogleJaInputAtFirstChar=%s, ", + "sDoNotReturnNoLayoutErrorToGoogleJaInputAtFirstChar=%s, " "sDoNotReturnNoLayoutErrorToGoogleJaInputAtCaret=%s", sThreadMgr.get(), sClientId, sDisplayAttrMgr.get(), sCategoryMgr.get(), sDisabledDocumentMgr.get(), sDisabledContext.get(), @@ -5079,9 +5220,9 @@ nsTextStore::Initialize() // static void -nsTextStore::Terminate(void) +TSFTextStore::Terminate() { - MOZ_LOG(sTextStoreLog, LogLevel::Info, ("TSF: nsTextStore::Terminate()")); + MOZ_LOG(sTextStoreLog, LogLevel::Info, ("TSF: TSFTextStore::Terminate()")); TSFStaticSink::Shutdown(); @@ -5102,7 +5243,7 @@ nsTextStore::Terminate(void) // static bool -nsTextStore::ProcessRawKeyMessage(const MSG& aMsg) +TSFTextStore::ProcessRawKeyMessage(const MSG& aMsg) { if (!sKeystrokeMgr) { return false; // not in TSF mode @@ -5131,9 +5272,11 @@ nsTextStore::ProcessRawKeyMessage(const MSG& aMsg) // static void -nsTextStore::ProcessMessage(nsWindowBase* aWindow, UINT aMessage, - WPARAM& aWParam, LPARAM& aLParam, - MSGResult& aResult) +TSFTextStore::ProcessMessage(nsWindowBase* aWindow, + UINT aMessage, + WPARAM& aWParam, + LPARAM& aLParam, + MSGResult& aResult) { switch (aMessage) { case WM_IME_SETCONTEXT: @@ -5159,19 +5302,19 @@ nsTextStore::ProcessMessage(nsWindowBase* aWindow, UINT aMessage, // static bool -nsTextStore::IsIMM_IME() +TSFTextStore::IsIMM_IME() { return TSFStaticSink::IsIMM_IME(); } /******************************************************************/ -/* nsTextStore::Composition */ +/* TSFTextStore::Composition */ /******************************************************************/ void -nsTextStore::Composition::Start(ITfCompositionView* aCompositionView, - LONG aCompositionStartOffset, - const nsAString& aCompositionString) +TSFTextStore::Composition::Start(ITfCompositionView* aCompositionView, + LONG aCompositionStartOffset, + const nsAString& aCompositionString) { mView = aCompositionView; mString = aCompositionString; @@ -5179,18 +5322,18 @@ nsTextStore::Composition::Start(ITfCompositionView* aCompositionView, } void -nsTextStore::Composition::End() +TSFTextStore::Composition::End() { mView = nullptr; mString.Truncate(); } /****************************************************************************** - * nsTextStore::Content + * TSFTextStore::Content *****************************************************************************/ const nsDependentSubstring -nsTextStore::Content::GetSelectedText() const +TSFTextStore::Content::GetSelectedText() const { MOZ_ASSERT(mInitialized); return GetSubstring(static_cast(mSelection.StartOffset()), @@ -5198,14 +5341,14 @@ nsTextStore::Content::GetSelectedText() const } const nsDependentSubstring -nsTextStore::Content::GetSubstring(uint32_t aStart, uint32_t aLength) const +TSFTextStore::Content::GetSubstring(uint32_t aStart, uint32_t aLength) const { MOZ_ASSERT(mInitialized); return nsDependentSubstring(mText, aStart, aLength); } void -nsTextStore::Content::ReplaceSelectedTextWith(const nsAString& aString) +TSFTextStore::Content::ReplaceSelectedTextWith(const nsAString& aString) { MOZ_ASSERT(mInitialized); ReplaceTextWith(mSelection.StartOffset(), mSelection.Length(), aString); @@ -5224,8 +5367,9 @@ FirstDifferentCharOffset(const nsAString& aStr1, const nsAString& aStr2) } void -nsTextStore::Content::ReplaceTextWith(LONG aStart, LONG aLength, - const nsAString& aReplaceString) +TSFTextStore::Content::ReplaceTextWith(LONG aStart, + LONG aLength, + const nsAString& aReplaceString) { MOZ_ASSERT(mInitialized); const nsDependentSubstring replacedString = @@ -5252,7 +5396,29 @@ nsTextStore::Content::ReplaceTextWith(LONG aStart, LONG aLength, mComposition.mStart + FirstDifferentCharOffset(mComposition.mString, mLastCompositionString); + // The previous change to the composition string is canceled. + if (mMinTextModifiedOffset >= + static_cast(mComposition.mStart) && + mMinTextModifiedOffset < firstDifferentOffset) { + mMinTextModifiedOffset = firstDifferentOffset; + } + } else if (mMinTextModifiedOffset >= + static_cast(mComposition.mStart) && + mMinTextModifiedOffset < + static_cast(mComposition.EndOffset())) { + // The previous change to the composition string is canceled. + mMinTextModifiedOffset = firstDifferentOffset = + mComposition.EndOffset(); } + MOZ_LOG(sTextStoreLog, LogLevel::Debug, + ("TSF: 0x%p TSFTextStore::Content::ReplaceTextWith(aStart=%d, " + "aLength=%d, aReplaceString=\"%s\"), mComposition={ mStart=%d, " + "mString=\"%s\" }, mLastCompositionString=\"%s\", " + "mMinTextModifiedOffset=%u, firstDifferentOffset=%u", + this, aStart, aLength, NS_ConvertUTF16toUTF8(aReplaceString).get(), + mComposition.mStart, NS_ConvertUTF16toUTF8(mComposition.mString).get(), + NS_ConvertUTF16toUTF8(mLastCompositionString).get(), + mMinTextModifiedOffset, firstDifferentOffset)); } else { firstDifferentOffset = static_cast(aStart) + @@ -5269,9 +5435,9 @@ nsTextStore::Content::ReplaceTextWith(LONG aStart, LONG aLength, } void -nsTextStore::Content::StartComposition(ITfCompositionView* aCompositionView, - const PendingAction& aCompStart, - bool aPreserveSelection) +TSFTextStore::Content::StartComposition(ITfCompositionView* aCompositionView, + const PendingAction& aCompStart, + bool aPreserveSelection) { MOZ_ASSERT(mInitialized); MOZ_ASSERT(aCompositionView); @@ -5290,7 +5456,7 @@ nsTextStore::Content::StartComposition(ITfCompositionView* aCompositionView, } void -nsTextStore::Content::EndComposition(const PendingAction& aCompEnd) +TSFTextStore::Content::EndComposition(const PendingAction& aCompEnd) { MOZ_ASSERT(mInitialized); MOZ_ASSERT(mComposition.mView); @@ -5301,10 +5467,10 @@ nsTextStore::Content::EndComposition(const PendingAction& aCompEnd) } /****************************************************************************** - * nsTextStore::MouseTracker + * TSFTextStore::MouseTracker *****************************************************************************/ -nsTextStore::MouseTracker::MouseTracker() +TSFTextStore::MouseTracker::MouseTracker() : mStart(-1) , mLength(-1) , mCookie(kInvalidCookie) @@ -5312,45 +5478,45 @@ nsTextStore::MouseTracker::MouseTracker() } HRESULT -nsTextStore::MouseTracker::Init(nsTextStore* aTextStore) +TSFTextStore::MouseTracker::Init(TSFTextStore* aTextStore) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::MouseTracker::Init(aTextStore=0x%p), " + ("TSF: 0x%p TSFTextStore::MouseTracker::Init(aTextStore=0x%p), " "aTextStore->mMouseTrackers.Length()=%d", this, aTextStore->mMouseTrackers.Length())); if (&aTextStore->mMouseTrackers.LastElement() != this) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::MouseTracker::Init() FAILED due to " + ("TSF: 0x%p TSFTextStore::MouseTracker::Init() FAILED due to " "this is not the last element of mMouseTrackers", this)); return E_FAIL; } if (aTextStore->mMouseTrackers.Length() > kInvalidCookie) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::MouseTracker::Init() FAILED due to " + ("TSF: 0x%p TSFTextStore::MouseTracker::Init() FAILED due to " "no new cookie available", this)); return E_FAIL; } MOZ_ASSERT(!aTextStore->mMouseTrackers.IsEmpty(), - "This instance must be in nsTextStore::mMouseTrackers"); + "This instance must be in TSFTextStore::mMouseTrackers"); mCookie = static_cast(aTextStore->mMouseTrackers.Length() - 1); return S_OK; } HRESULT -nsTextStore::MouseTracker::AdviseSink(nsTextStore* aTextStore, - ITfRangeACP* aTextRange, - ITfMouseSink* aMouseSink) +TSFTextStore::MouseTracker::AdviseSink(TSFTextStore* aTextStore, + ITfRangeACP* aTextRange, + ITfMouseSink* aMouseSink) { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::MouseTracker::AdviseSink(aTextStore=0x%p, " + ("TSF: 0x%p TSFTextStore::MouseTracker::AdviseSink(aTextStore=0x%p, " "aTextRange=0x%p, aMouseSink=0x%p), mCookie=%d, mSink=0x%p", this, aTextStore, aTextRange, aMouseSink, mCookie, mSink.get())); MOZ_ASSERT(mCookie != kInvalidCookie, "This hasn't been initalized?"); if (mSink) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::MouseTracker::AdviseMouseSink() FAILED " + ("TSF: 0x%p TSFTextStore::MouseTracker::AdviseMouseSink() FAILED " "due to already being used", this)); return E_FAIL; } @@ -5358,14 +5524,14 @@ nsTextStore::MouseTracker::AdviseSink(nsTextStore* aTextStore, HRESULT hr = aTextRange->GetExtent(&mStart, &mLength); if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::MouseTracker::AdviseMouseSink() FAILED " + ("TSF: 0x%p TSFTextStore::MouseTracker::AdviseMouseSink() FAILED " "due to failure of ITfRangeACP::GetExtent()", this)); return hr; } if (mStart < 0 || mLength <= 0) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::MouseTracker::AdviseMouseSink() FAILED " + ("TSF: 0x%p TSFTextStore::MouseTracker::AdviseMouseSink() FAILED " "due to odd result of ITfRangeACP::GetExtent(), " "mStart=%d, mLength=%d", this, mStart, mLength)); return E_INVALIDARG; @@ -5374,15 +5540,15 @@ nsTextStore::MouseTracker::AdviseSink(nsTextStore* aTextStore, nsAutoString textContent; if (NS_WARN_IF(!aTextStore->GetCurrentText(textContent))) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::MouseTracker::AdviseMouseSink() FAILED " - "due to failure of nsTextStore::GetCurrentText()", this)); + ("TSF: 0x%p TSFTextStore::MouseTracker::AdviseMouseSink() FAILED " + "due to failure of TSFTextStore::GetCurrentText()", this)); return E_FAIL; } if (textContent.Length() <= static_cast(mStart) || textContent.Length() < static_cast(mStart + mLength)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: 0x%p nsTextStore::MouseTracker::AdviseMouseSink() FAILED " + ("TSF: 0x%p TSFTextStore::MouseTracker::AdviseMouseSink() FAILED " "due to out of range, mStart=%d, mLength=%d, " "textContent.Length()=%d", this, mStart, mLength, textContent.Length())); @@ -5392,17 +5558,17 @@ nsTextStore::MouseTracker::AdviseSink(nsTextStore* aTextStore, mSink = aMouseSink; MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::MouseTracker::AdviseMouseSink(), " + ("TSF: 0x%p TSFTextStore::MouseTracker::AdviseMouseSink(), " "succeeded, mStart=%d, mLength=%d, textContent.Length()=%d", this, mStart, mLength, textContent.Length())); return S_OK; } void -nsTextStore::MouseTracker::UnadviseSink() +TSFTextStore::MouseTracker::UnadviseSink() { MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::MouseTracker::UnadviseSink(), " + ("TSF: 0x%p TSFTextStore::MouseTracker::UnadviseSink(), " "mCookie=%d, mSink=0x%p, mStart=%d, mLength=%d", this, mCookie, mSink.get(), mStart, mLength)); mSink = nullptr; @@ -5410,9 +5576,9 @@ nsTextStore::MouseTracker::UnadviseSink() } bool -nsTextStore::MouseTracker::OnMouseButtonEvent(ULONG aEdge, - ULONG aQuadrant, - DWORD aButtonStatus) +TSFTextStore::MouseTracker::OnMouseButtonEvent(ULONG aEdge, + ULONG aQuadrant, + DWORD aButtonStatus) { MOZ_ASSERT(IsUsing(), "The caller must check before calling OnMouseEvent()"); @@ -5420,7 +5586,7 @@ nsTextStore::MouseTracker::OnMouseButtonEvent(ULONG aEdge, HRESULT hr = mSink->OnMouseEvent(aEdge, aQuadrant, aButtonStatus, &eaten); MOZ_LOG(sTextStoreLog, LogLevel::Debug, - ("TSF: 0x%p nsTextStore::MouseTracker::OnMouseEvent(aEdge=%d, " + ("TSF: 0x%p TSFTextStore::MouseTracker::OnMouseEvent(aEdge=%d, " "aQuadrant=%d, aButtonStatus=0x%08X), hr=0x%08X, eaten=%s", this, aEdge, aQuadrant, aButtonStatus, hr, GetBoolName(!!eaten))); @@ -5430,12 +5596,12 @@ nsTextStore::MouseTracker::OnMouseButtonEvent(ULONG aEdge, #ifdef DEBUG // static bool -nsTextStore::CurrentKeyboardLayoutHasIME() +TSFTextStore::CurrentKeyboardLayoutHasIME() { if (!sInputProcessorProfiles) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::CurrentKeyboardLayoutHasIME() FAILED due to there is " - "no input processor profiles instance")); + ("TSF: TSFTextStore::CurrentKeyboardLayoutHasIME() FAILED due to " + "there is no input processor profiles instance")); return false; } nsRefPtr profileMgr; @@ -5448,7 +5614,7 @@ nsTextStore::CurrentKeyboardLayoutHasIME() // keyboard layout has IME. if (IsVistaOrLater()) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::CurrentKeyboardLayoutHasIME() FAILED to query " + ("TSF: TSFTextStore::CurrentKeyboardLayoutHasIME() FAILED to query " "ITfInputProcessorProfileMgr")); return false; } @@ -5465,10 +5631,14 @@ nsTextStore::CurrentKeyboardLayoutHasIME() } if (FAILED(hr)) { MOZ_LOG(sTextStoreLog, LogLevel::Error, - ("TSF: nsTextStore::CurrentKeyboardLayoutHasIME() FAILED to retreive " + ("TSF: TSFTextStore::CurrentKeyboardLayoutHasIME() FAILED to retreive " "active profile")); return false; } return (profile.dwProfileType == TF_PROFILETYPE_INPUTPROCESSOR); } #endif // #ifdef DEBUG + +} // name widget +} // name mozilla + diff --git a/widget/windows/nsTextStore.h b/widget/windows/TSFTextStore.h similarity index 89% rename from widget/windows/nsTextStore.h rename to widget/windows/TSFTextStore.h index 2aba208c21..410f2615ef 100644 --- a/widget/windows/nsTextStore.h +++ b/widget/windows/TSFTextStore.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef NSTEXTSTORE_H_ -#define NSTEXTSTORE_H_ +#ifndef TSFTextStore_h_ +#define TSFTextStore_h_ #include "nsAutoPtr.h" #include "nsString.h" @@ -41,22 +41,21 @@ class nsWindow; namespace mozilla { namespace widget { + struct MSGResult; -} // namespace widget -} // namespace mozilla /* * Text Services Framework text store */ -class nsTextStore final : public ITextStoreACP - , public ITfContextOwnerCompositionSink - , public ITfMouseTrackerACP +class TSFTextStore final : public ITextStoreACP + , public ITfContextOwnerCompositionSink + , public ITfMouseTrackerACP { public: /*IUnknown*/ STDMETHODIMP QueryInterface(REFIID, void**); - NS_INLINE_DECL_IUNKNOWN_REFCOUNTING(nsTextStore) + NS_INLINE_DECL_IUNKNOWN_REFCOUNTING(TSFTextStore) public: /*ITextStoreACP*/ STDMETHODIMP AdviseSink(REFIID, IUnknown*, DWORD); @@ -100,12 +99,6 @@ public: /*ITfMouseTrackerACP*/ STDMETHODIMP AdviseMouseSink(ITfRangeACP*, ITfMouseSink*, DWORD*); STDMETHODIMP UnadviseMouseSink(DWORD); -protected: - typedef mozilla::widget::IMENotification IMENotification; - typedef mozilla::widget::IMEState IMEState; - typedef mozilla::widget::InputContext InputContext; - typedef mozilla::widget::InputContextAction InputContextAction; - public: static void Initialize(void); static void Terminate(void); @@ -113,7 +106,7 @@ public: static bool ProcessRawKeyMessage(const MSG& aMsg); static void ProcessMessage(nsWindowBase* aWindow, UINT aMessage, WPARAM& aWParam, LPARAM& aLParam, - mozilla::widget::MSGResult& aResult); + MSGResult& aResult); static void SetIMEOpenState(bool); @@ -227,8 +220,8 @@ public: #endif // #ifdef DEBUG protected: - nsTextStore(); - ~nsTextStore(); + TSFTextStore(); + ~TSFTextStore(); static bool CreateAndSetFocus(nsWindowBase* aFocusedWidget, const InputContext& aContext); @@ -253,7 +246,7 @@ protected: // Note that mLock isn't cleared yet when this is called. void DidLockGranted(); - bool GetScreenExtInternal(RECT &aScreenExt); + bool GetScreenExtInternal(RECT& aScreenExt); // If aDispatchCompositionChangeEvent is true, this method will dispatch // compositionchange event if this is called during IME composing. // aDispatchCompositionChangeEvent should be true only when this is called @@ -261,7 +254,7 @@ protected: // not be sent from here. HRESULT SetSelectionInternal(const TS_SELECTION_ACP*, bool aDispatchCompositionChangeEvent = false); - bool InsertTextAtSelectionInternal(const nsAString &aInsertStr, + bool InsertTextAtSelectionInternal(const nsAString& aInsertStr, TS_TEXTCHANGE* aTextChange); void CommitCompositionInternal(bool); nsresult OnTextChangeInternal(const IMENotification& aIMENotification); @@ -289,7 +282,7 @@ protected: // DispatchEvent() dispatches the event and if it may not be handled // synchronously, this makes the instance not notify TSF of pending // notifications until next notification from content. - void DispatchEvent(mozilla::WidgetGUIEvent& aEvent); + void DispatchEvent(WidgetGUIEvent& aEvent); void OnLayoutInformationAvaliable(); // FlushPendingActions() performs pending actions recorded in mPendingActions @@ -313,6 +306,8 @@ protected: // Creates native caret over our caret. This method only works on desktop // application. Otherwise, this does nothing. void CreateNativeCaret(); + // Destroys native caret if there is. + void MaybeDestroyNativeCaret(); // Holds the pointer to our current win32 widget nsRefPtr mWidget; @@ -369,7 +364,7 @@ protected: // While the document is locked, we cannot dispatch any events which cause // DOM events since the DOM events' handlers may modify the locked document. // However, even while the document is locked, TSF may queries us. - // For that, nsTextStore modifies mComposition even while the document is + // For that, TSFTextStore modifies mComposition even while the document is // locked. With mComposition, query methods can returns the text content // information. Composition mComposition; @@ -401,8 +396,10 @@ protected: mACP.style.fInterimChar = FALSE; } - void SetSelection(uint32_t aStart, uint32_t aLength, bool aReversed, - mozilla::WritingMode aWritingMode) + void SetSelection(uint32_t aStart, + uint32_t aLength, + bool aReversed, + WritingMode aWritingMode) { mDirty = false; mACP.acpStart = static_cast(aStart); @@ -484,7 +481,7 @@ protected: return (mACP.style.fInterimChar != FALSE); } - mozilla::WritingMode GetWritingMode() const + WritingMode GetWritingMode() const { MOZ_ASSERT(!mDirty); return mWritingMode; @@ -492,7 +489,7 @@ protected: private: TS_SELECTION_ACP mACP; - mozilla::WritingMode mWritingMode; + WritingMode mWritingMode; bool mDirty; }; // Don't access mSelection directly except at calling MarkDirty(). @@ -523,7 +520,7 @@ protected: // For compositionupdate and compositionend nsString mData; // For compositionupdate - nsRefPtr mRanges; + nsRefPtr mRanges; // For selectionset bool mSelectionReversed; // For compositionupdate @@ -547,7 +544,7 @@ protected: } PendingAction* newAction = mPendingActions.AppendElement(); newAction->mType = PendingAction::COMPOSITION_UPDATE; - newAction->mRanges = new mozilla::TextRangeArray(); + newAction->mRanges = new TextRangeArray(); newAction->mIncomplete = true; return newAction; } @@ -576,7 +573,7 @@ protected: class MOZ_STACK_CLASS AutoPendingActionAndContentFlusher final { public: - AutoPendingActionAndContentFlusher(nsTextStore* aTextStore) + AutoPendingActionAndContentFlusher(TSFTextStore* aTextStore) : mTextStore(aTextStore) { MOZ_ASSERT(!mTextStore->mIsRecordingActionsWithoutLock); @@ -597,14 +594,14 @@ protected: private: AutoPendingActionAndContentFlusher() {} - nsRefPtr mTextStore; + nsRefPtr mTextStore; }; class Content final { public: - Content(nsTextStore::Composition& aComposition, - nsTextStore::Selection& aSelection) : + Content(TSFTextStore::Composition& aComposition, + TSFTextStore::Selection& aSelection) : mComposition(aComposition), mSelection(aSelection) { Clear(); @@ -624,11 +621,18 @@ protected: mText = aText; if (mComposition.IsComposing()) { mLastCompositionString = mComposition.mString; + } else { + mLastCompositionString.Truncate(); } mMinTextModifiedOffset = NOT_MODIFIED; mInitialized = true; } + void OnLayoutChanged() + { + mMinTextModifiedOffset = NOT_MODIFIED; + } + const nsDependentSubstring GetSelectedText() const; const nsDependentSubstring GetSubstring(uint32_t aStart, uint32_t aLength) const; @@ -645,6 +649,16 @@ protected: MOZ_ASSERT(mInitialized); return mText; } + const nsString& LastCompositionString() const + { + MOZ_ASSERT(mInitialized); + return mLastCompositionString; + } + uint32_t MinTextModifiedOffset() const + { + MOZ_ASSERT(mInitialized); + return mMinTextModifiedOffset; + } // Returns true if layout of the character at the aOffset has not been // calculated. @@ -664,16 +678,16 @@ protected: return mInitialized ? mMinTextModifiedOffset : NOT_MODIFIED; } - nsTextStore::Composition& Composition() { return mComposition; } - nsTextStore::Selection& Selection() { return mSelection; } + TSFTextStore::Composition& Composition() { return mComposition; } + TSFTextStore::Selection& Selection() { return mSelection; } private: nsString mText; // mLastCompositionString stores the composition string when the document // is locked. This is necessary to compute mMinTextModifiedOffset. nsString mLastCompositionString; - nsTextStore::Composition& mComposition; - nsTextStore::Selection& mSelection; + TSFTextStore::Composition& mComposition; + TSFTextStore::Selection& mSelection; // The minimum offset of modified part of the text. enum : uint32_t @@ -684,9 +698,9 @@ protected: bool mInitialized; }; - // mLockedContent caches content of the document ONLY while the document - // is locked. I.e., the content is cleared at unlocking the document since - // we need to reduce the memory usage. This is initialized by + // mLockedContent starts to cache content of the document at first query of + // the content during a document lock. This is abandoned after document is + // unlocked and dispatched events are handled. This is initialized by // LockedContent() automatically. So, don't access this member directly // except at calling Clear(), IsInitialized(), IsLayoutChangedAfter() or // IsLayoutChanged(). @@ -705,8 +719,8 @@ protected: MouseTracker(); - HRESULT Init(nsTextStore* aTextStore); - HRESULT AdviseSink(nsTextStore* aTextStore, + HRESULT Init(TSFTextStore* aTextStore); + HRESULT AdviseSink(TSFTextStore* aTextStore, ITfRangeACP* aTextRange, ITfMouseSink* aMouseSink); void UnadviseSink(); @@ -779,6 +793,9 @@ protected: // During the documet is locked, we shouldn't destroy the instance. // If this is true, the instance will be destroyed after unlocked. bool mPendingDestroy; + // If this is true, MaybeFlushPendingNotifications() will clear the + // mLockedContent. + bool mPendingClearLockedContent; // While there is native caret, this is true. Otherwise, false. bool mNativeCaretIsCreated; // While the instance is dispatching events, the event may not be handled @@ -791,38 +808,42 @@ protected: // TSF thread manager object for the current application - static mozilla::StaticRefPtr sThreadMgr; + static StaticRefPtr sThreadMgr; // sMessagePump is QI'ed from sThreadMgr - static mozilla::StaticRefPtr sMessagePump; + static StaticRefPtr sMessagePump; // sKeystrokeMgr is QI'ed from sThreadMgr - static mozilla::StaticRefPtr sKeystrokeMgr; + static StaticRefPtr sKeystrokeMgr; // TSF display attribute manager - static mozilla::StaticRefPtr sDisplayAttrMgr; + static StaticRefPtr sDisplayAttrMgr; // TSF category manager - static mozilla::StaticRefPtr sCategoryMgr; + static StaticRefPtr sCategoryMgr; // Current text store which is managing a keyboard enabled editor (i.e., - // editable editor). Currently only ONE nsTextStore instance is ever used, + // editable editor). Currently only ONE TSFTextStore instance is ever used, // although Create is called when an editor is focused and Destroy called // when the focused editor is blurred. - static mozilla::StaticRefPtr sEnabledTextStore; + static StaticRefPtr sEnabledTextStore; // For IME (keyboard) disabled state: - static mozilla::StaticRefPtr sDisabledDocumentMgr; - static mozilla::StaticRefPtr sDisabledContext; + static StaticRefPtr sDisabledDocumentMgr; + static StaticRefPtr sDisabledContext; - static mozilla::StaticRefPtr - sInputProcessorProfiles; + static StaticRefPtr sInputProcessorProfiles; // TSF client ID for the current application static DWORD sClientId; // Enables/Disables hack for specific TIP. static bool sCreateNativeCaretForATOK; + static bool sDoNotReturnNoLayoutErrorToMSSimplifiedTIP; + static bool sDoNotReturnNoLayoutErrorToMSTraditionalTIP; static bool sDoNotReturnNoLayoutErrorToFreeChangJie; static bool sDoNotReturnNoLayoutErrorToEasyChangjei; static bool sDoNotReturnNoLayoutErrorToGoogleJaInputAtFirstChar; static bool sDoNotReturnNoLayoutErrorToGoogleJaInputAtCaret; }; -#endif /*NSTEXTSTORE_H_*/ +} // namespace widget +} // namespace mozilla + +#endif // #ifndef TSFTextStore_h_ diff --git a/widget/windows/WinIMEHandler.cpp b/widget/windows/WinIMEHandler.cpp index 6631c1a2cc..695c9d6c54 100644 --- a/widget/windows/WinIMEHandler.cpp +++ b/widget/windows/WinIMEHandler.cpp @@ -5,12 +5,12 @@ #include "WinIMEHandler.h" +#include "IMMHandler.h" #include "mozilla/Preferences.h" -#include "nsIMM32Handler.h" #include "nsWindowDefs.h" #ifdef NS_ENABLE_TSF -#include "nsTextStore.h" +#include "TSFTextStore.h" #endif // #ifdef NS_ENABLE_TSF #include "nsWindow.h" @@ -35,12 +35,12 @@ void IMEHandler::Initialize() { #ifdef NS_ENABLE_TSF - nsTextStore::Initialize(); - sIsInTSFMode = nsTextStore::IsInTSFMode(); + TSFTextStore::Initialize(); + sIsInTSFMode = TSFTextStore::IsInTSFMode(); sIsIMMEnabled = !sIsInTSFMode || Preferences::GetBool("intl.tsf.support_imm", true); if (!sIsInTSFMode) { - // When full nsTextStore is not available, try to use SetInputScopes API + // When full TSFTextStore is not available, try to use SetInputScopes API // to enable at least InputScope. Use GET_MODULE_HANDLE_EX_FLAG_PIN to // ensure that msctf.dll will not be unloaded. HMODULE module = nullptr; @@ -52,7 +52,7 @@ IMEHandler::Initialize() } #endif // #ifdef NS_ENABLE_TSF - nsIMM32Handler::Initialize(); + IMMHandler::Initialize(); } // static @@ -61,12 +61,12 @@ IMEHandler::Terminate() { #ifdef NS_ENABLE_TSF if (sIsInTSFMode) { - nsTextStore::Terminate(); + TSFTextStore::Terminate(); sIsInTSFMode = false; } #endif // #ifdef NS_ENABLE_TSF - nsIMM32Handler::Terminate(); + IMMHandler::Terminate(); } // static @@ -74,7 +74,7 @@ void* IMEHandler::GetNativeData(uint32_t aDataType) { #ifdef NS_ENABLE_TSF - void* result = nsTextStore::GetNativeData(aDataType); + void* result = TSFTextStore::GetNativeData(aDataType); if (!result || !(*(static_cast(result)))) { return nullptr; } @@ -95,7 +95,7 @@ IMEHandler::ProcessRawKeyMessage(const MSG& aMsg) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { - return nsTextStore::ProcessRawKeyMessage(aMsg); + return TSFTextStore::ProcessRawKeyMessage(aMsg); } #endif // #ifdef NS_ENABLE_TSF return false; // noting to do in IMM mode. @@ -109,24 +109,24 @@ IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage, { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { - nsTextStore::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aResult); + TSFTextStore::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aResult); if (aResult.mConsumed) { return true; } - // If we don't support IMM in TSF mode, we don't use nsIMM32Handler. + // If we don't support IMM in TSF mode, we don't use IMMHandler. if (!sIsIMMEnabled) { return false; } - // IME isn't implemented with IMM, nsIMM32Handler shouldn't handle any + // IME isn't implemented with IMM, IMMHandler shouldn't handle any // messages. - if (!nsTextStore::IsIMM_IME()) { + if (!TSFTextStore::IsIMM_IME()) { return false; } } #endif // #ifdef NS_ENABLE_TSF - return nsIMM32Handler::ProcessMessage(aWindow, aMessage, aWParam, aLParam, - aResult); + return IMMHandler::ProcessMessage(aWindow, aMessage, aWParam, aLParam, + aResult); } #ifdef NS_ENABLE_TSF @@ -134,7 +134,7 @@ IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage, bool IMEHandler::IsIMMActive() { - return nsTextStore::IsIMM_IME(); + return TSFTextStore::IsIMM_IME(); } #endif // #ifdef NS_ENABLE_TSF @@ -144,11 +144,11 @@ IMEHandler::IsComposing() { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { - return nsTextStore::IsComposing() || nsIMM32Handler::IsComposing(); + return TSFTextStore::IsComposing() || IMMHandler::IsComposing(); } #endif // #ifdef NS_ENABLE_TSF - return nsIMM32Handler::IsComposing(); + return IMMHandler::IsComposing(); } // static @@ -157,12 +157,12 @@ IMEHandler::IsComposingOn(nsWindow* aWindow) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { - return nsTextStore::IsComposingOn(aWindow) || - nsIMM32Handler::IsComposingOn(aWindow); + return TSFTextStore::IsComposingOn(aWindow) || + IMMHandler::IsComposingOn(aWindow); } #endif // #ifdef NS_ENABLE_TSF - return nsIMM32Handler::IsComposingOn(aWindow); + return IMMHandler::IsComposingOn(aWindow); } // static @@ -174,60 +174,59 @@ IMEHandler::NotifyIME(nsWindow* aWindow, if (IsTSFAvailable()) { switch (aIMENotification.mMessage) { case NOTIFY_IME_OF_SELECTION_CHANGE: { - nsresult rv = nsTextStore::OnSelectionChange(aIMENotification); - // If IMM IME is active, we need to notify nsIMM32Handler of updating + nsresult rv = TSFTextStore::OnSelectionChange(aIMENotification); + // If IMM IME is active, we need to notify IMMHandler of updating // composition change. It will adjust candidate window position or // composition window position. bool isIMMActive = IsIMMActive(); if (isIMMActive) { - nsIMM32Handler::OnUpdateComposition(aWindow); + IMMHandler::OnUpdateComposition(aWindow); } - nsIMM32Handler::OnSelectionChange(aWindow, aIMENotification, - isIMMActive); + IMMHandler::OnSelectionChange(aWindow, aIMENotification, isIMMActive); return rv; } case NOTIFY_IME_OF_COMPOSITION_UPDATE: - // If IMM IME is active, we need to notify nsIMM32Handler of updating + // If IMM IME is active, we need to notify IMMHandler of updating // composition change. It will adjust candidate window position or // composition window position. if (IsIMMActive()) { - nsIMM32Handler::OnUpdateComposition(aWindow); + IMMHandler::OnUpdateComposition(aWindow); } else { - nsTextStore::OnUpdateComposition(); + TSFTextStore::OnUpdateComposition(); } return NS_OK; case NOTIFY_IME_OF_TEXT_CHANGE: - return nsTextStore::OnTextChange(aIMENotification); + return TSFTextStore::OnTextChange(aIMENotification); case NOTIFY_IME_OF_FOCUS: - nsIMM32Handler::OnFocusChange(true, aWindow); - return nsTextStore::OnFocusChange(true, aWindow, - aWindow->GetInputContext()); + IMMHandler::OnFocusChange(true, aWindow); + return TSFTextStore::OnFocusChange(true, aWindow, + aWindow->GetInputContext()); case NOTIFY_IME_OF_BLUR: - nsIMM32Handler::OnFocusChange(false, aWindow); - return nsTextStore::OnFocusChange(false, aWindow, - aWindow->GetInputContext()); + IMMHandler::OnFocusChange(false, aWindow); + return TSFTextStore::OnFocusChange(false, aWindow, + aWindow->GetInputContext()); case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT: // If IMM IME is active, we should send a mouse button event via IMM. if (IsIMMActive()) { - return nsIMM32Handler::OnMouseButtonEvent(aWindow, aIMENotification); + return IMMHandler::OnMouseButtonEvent(aWindow, aIMENotification); } - return nsTextStore::OnMouseButtonEvent(aIMENotification); + return TSFTextStore::OnMouseButtonEvent(aIMENotification); case REQUEST_TO_COMMIT_COMPOSITION: - if (nsTextStore::IsComposingOn(aWindow)) { - nsTextStore::CommitComposition(false); + if (TSFTextStore::IsComposingOn(aWindow)) { + TSFTextStore::CommitComposition(false); } else if (IsIMMActive()) { - nsIMM32Handler::CommitComposition(aWindow); + IMMHandler::CommitComposition(aWindow); } return NS_OK; case REQUEST_TO_CANCEL_COMPOSITION: - if (nsTextStore::IsComposingOn(aWindow)) { - nsTextStore::CommitComposition(true); + if (TSFTextStore::IsComposingOn(aWindow)) { + TSFTextStore::CommitComposition(true); } else if (IsIMMActive()) { - nsIMM32Handler::CancelComposition(aWindow); + IMMHandler::CancelComposition(aWindow); } return NS_OK; case NOTIFY_IME_OF_POSITION_CHANGE: - return nsTextStore::OnLayoutChange(); + return TSFTextStore::OnLayoutChange(); default: return NS_ERROR_NOT_IMPLEMENTED; } @@ -236,31 +235,31 @@ IMEHandler::NotifyIME(nsWindow* aWindow, switch (aIMENotification.mMessage) { case REQUEST_TO_COMMIT_COMPOSITION: - nsIMM32Handler::CommitComposition(aWindow); + IMMHandler::CommitComposition(aWindow); return NS_OK; case REQUEST_TO_CANCEL_COMPOSITION: - nsIMM32Handler::CancelComposition(aWindow); + IMMHandler::CancelComposition(aWindow); return NS_OK; case NOTIFY_IME_OF_POSITION_CHANGE: case NOTIFY_IME_OF_COMPOSITION_UPDATE: - nsIMM32Handler::OnUpdateComposition(aWindow); + IMMHandler::OnUpdateComposition(aWindow); return NS_OK; case NOTIFY_IME_OF_SELECTION_CHANGE: - nsIMM32Handler::OnSelectionChange(aWindow, aIMENotification, true); + IMMHandler::OnSelectionChange(aWindow, aIMENotification, true); return NS_OK; case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT: - return nsIMM32Handler::OnMouseButtonEvent(aWindow, aIMENotification); + return IMMHandler::OnMouseButtonEvent(aWindow, aIMENotification); case NOTIFY_IME_OF_FOCUS: - nsIMM32Handler::OnFocusChange(true, aWindow); + IMMHandler::OnFocusChange(true, aWindow); return NS_OK; case NOTIFY_IME_OF_BLUR: - nsIMM32Handler::OnFocusChange(false, aWindow); + IMMHandler::OnFocusChange(false, aWindow); #ifdef NS_ENABLE_TSF // If a plugin gets focus while TSF has focus, we need to notify TSF of // the blur. - if (nsTextStore::ThinksHavingFocus()) { - return nsTextStore::OnFocusChange(false, aWindow, - aWindow->GetInputContext()); + if (TSFTextStore::ThinksHavingFocus()) { + return TSFTextStore::OnFocusChange(false, aWindow, + aWindow->GetInputContext()); } #endif //NS_ENABLE_TSF return NS_OK; @@ -275,11 +274,11 @@ IMEHandler::GetUpdatePreference() { #ifdef NS_ENABLE_TSF if (IsTSFAvailable()) { - return nsTextStore::GetIMEUpdatePreference(); + return TSFTextStore::GetIMEUpdatePreference(); } #endif //NS_ENABLE_TSF - return nsIMM32Handler::GetIMEUpdatePreference(); + return IMMHandler::GetIMEUpdatePreference(); } // static @@ -288,12 +287,12 @@ IMEHandler::GetOpenState(nsWindow* aWindow) { #ifdef NS_ENABLE_TSF if (IsTSFAvailable() && !IsIMMActive()) { - return nsTextStore::GetIMEOpenState(); + return TSFTextStore::GetIMEOpenState(); } #endif //NS_ENABLE_TSF - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - return IMEContext.GetOpenState(); + IMEContext context(aWindow); + return context.GetOpenState(); } // static @@ -337,9 +336,9 @@ IMEHandler::SetInputContext(nsWindow* aWindow, #ifdef NS_ENABLE_TSF // Note that even while a plugin has focus, we need to notify TSF of that. if (sIsInTSFMode) { - nsTextStore::SetInputContext(aWindow, aInputContext, aAction); + TSFTextStore::SetInputContext(aWindow, aInputContext, aAction); if (IsTSFAvailable()) { - aInputContext.mNativeIMEContext = nsTextStore::GetThreadManager(); + aInputContext.mNativeIMEContext = TSFTextStore::GetThreadManager(); if (sIsIMMEnabled) { // Associate IME context for IMM-IMEs. AssociateIMEContext(aWindow, enable); @@ -349,7 +348,7 @@ IMEHandler::SetInputContext(nsWindow* aWindow, AssociateIMEContext(aWindow, false); } if (adjustOpenState) { - nsTextStore::SetIMEOpenState(open); + TSFTextStore::SetIMEOpenState(open); } return; } @@ -361,9 +360,9 @@ IMEHandler::SetInputContext(nsWindow* aWindow, AssociateIMEContext(aWindow, enable); - nsIMEContext IMEContext(aWindow->GetWindowHandle()); + IMEContext context(aWindow); if (adjustOpenState) { - IMEContext.SetOpenState(open); + context.SetOpenState(open); } if (aInputContext.mNativeIMEContext) { @@ -373,23 +372,23 @@ IMEHandler::SetInputContext(nsWindow* aWindow, // The old InputContext must store the default IMC or old TextStore. // When IME context is disassociated from the window, use it. aInputContext.mNativeIMEContext = enable ? - static_cast(IMEContext.get()) : oldInputContext.mNativeIMEContext; + static_cast(context.get()) : oldInputContext.mNativeIMEContext; } // static void IMEHandler::AssociateIMEContext(nsWindow* aWindow, bool aEnable) { - nsIMEContext IMEContext(aWindow->GetWindowHandle()); + IMEContext context(aWindow); if (aEnable) { - IMEContext.AssociateDefaultContext(); + context.AssociateDefaultContext(); return; } // Don't disassociate the context after the window is destroyed. if (aWindow->Destroyed()) { return; } - IMEContext.Disassociate(); + context.Disassociate(); } // static @@ -401,10 +400,10 @@ IMEHandler::InitInputContext(nsWindow* aWindow, InputContext& aInputContext) #ifdef NS_ENABLE_TSF if (sIsInTSFMode) { - nsTextStore::SetInputContext(aWindow, aInputContext, + TSFTextStore::SetInputContext(aWindow, aInputContext, InputContextAction(InputContextAction::CAUSE_UNKNOWN, InputContextAction::GOT_FOCUS)); - aInputContext.mNativeIMEContext = nsTextStore::GetThreadManager(); + aInputContext.mNativeIMEContext = TSFTextStore::GetThreadManager(); MOZ_ASSERT(aInputContext.mNativeIMEContext); // IME context isn't necessary in pure TSF mode. if (!sIsIMMEnabled) { @@ -415,8 +414,8 @@ IMEHandler::InitInputContext(nsWindow* aWindow, InputContext& aInputContext) #endif // #ifdef NS_ENABLE_TSF // NOTE: mNativeIMEContext may be null if IMM module isn't installed. - nsIMEContext IMEContext(aWindow->GetWindowHandle()); - aInputContext.mNativeIMEContext = static_cast(IMEContext.get()); + IMEContext context(aWindow); + aInputContext.mNativeIMEContext = static_cast(context.get()); MOZ_ASSERT(aInputContext.mNativeIMEContext || !CurrentKeyboardLayoutHasIME()); // If no IME context is available, we should set the widget's pointer since // nullptr indicates there is only one context per process on the platform. @@ -432,11 +431,11 @@ IMEHandler::CurrentKeyboardLayoutHasIME() { #ifdef NS_ENABLE_TSF if (sIsInTSFMode) { - return nsTextStore::CurrentKeyboardLayoutHasIME(); + return TSFTextStore::CurrentKeyboardLayoutHasIME(); } #endif // #ifdef NS_ENABLE_TSF - return nsIMM32Handler::IsIMEAvailable(); + return IMMHandler::IsIMEAvailable(); } #endif // #ifdef DEBUG diff --git a/widget/windows/WinUtils.cpp b/widget/windows/WinUtils.cpp index fc7e37d344..5f4ee10d6d 100644 --- a/widget/windows/WinUtils.cpp +++ b/widget/windows/WinUtils.cpp @@ -47,7 +47,7 @@ #ifdef NS_ENABLE_TSF #include -#include "nsTextStore.h" +#include "TSFTextStore.h" #endif // #ifdef NS_ENABLE_TSF PRLogModuleInfo* gWindowsLog = nullptr; @@ -572,7 +572,7 @@ WinUtils::PeekMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage, UINT aLastMessage, UINT aOption) { #ifdef NS_ENABLE_TSF - ITfMessagePump* msgPump = nsTextStore::GetMessagePump(); + ITfMessagePump* msgPump = TSFTextStore::GetMessagePump(); if (msgPump) { BOOL ret = FALSE; HRESULT hr = msgPump->PeekMessageW(aMsg, aWnd, aFirstMessage, aLastMessage, @@ -590,7 +590,7 @@ WinUtils::GetMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage, UINT aLastMessage) { #ifdef NS_ENABLE_TSF - ITfMessagePump* msgPump = nsTextStore::GetMessagePump(); + ITfMessagePump* msgPump = TSFTextStore::GetMessagePump(); if (msgPump) { BOOL ret = FALSE; HRESULT hr = msgPump->GetMessageW(aMsg, aWnd, aFirstMessage, aLastMessage, @@ -939,15 +939,17 @@ WinUtils::GetMouseInputSource() return static_cast(inputSource); } +/* static */ bool -WinUtils::GetIsMouseFromTouch(uint32_t aEventType) +WinUtils::GetIsMouseFromTouch(EventMessage aEventMessage) { -#define MOUSEEVENTF_FROMTOUCH 0xFF515700 - return (aEventType == NS_MOUSE_BUTTON_DOWN || - aEventType == NS_MOUSE_BUTTON_UP || - aEventType == NS_MOUSE_MOVE || - aEventType == NS_MOUSE_DOUBLECLICK) && - (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH); + const uint32_t MOZ_T_I_SIGNATURE = TABLET_INK_TOUCH | TABLET_INK_SIGNATURE; + const uint32_t MOZ_T_I_CHECK_TCH = TABLET_INK_TOUCH | TABLET_INK_CHECK; + return ((aEventMessage == NS_MOUSE_MOVE || + aEventMessage == NS_MOUSE_BUTTON_DOWN || + aEventMessage == NS_MOUSE_BUTTON_UP || + aEventMessage == NS_MOUSE_DOUBLECLICK) && + (GetMessageExtraInfo() & MOZ_T_I_SIGNATURE) == MOZ_T_I_CHECK_TCH); } /* static */ diff --git a/widget/windows/WinUtils.h b/widget/windows/WinUtils.h index 71e2be6be9..8cce2e7176 100644 --- a/widget/windows/WinUtils.h +++ b/widget/windows/WinUtils.h @@ -35,6 +35,7 @@ #include "nsIThread.h" #include "mozilla/Attributes.h" +#include "mozilla/EventForwards.h" /** * NS_INLINE_DECL_IUNKNOWN_REFCOUNTING should be used for defining and @@ -308,7 +309,7 @@ public: */ static uint16_t GetMouseInputSource(); - static bool GetIsMouseFromTouch(uint32_t aEventType); + static bool GetIsMouseFromTouch(EventMessage aEventType); /** * SHCreateItemFromParsingName() calls native SHCreateItemFromParsingName() diff --git a/widget/windows/moz.build b/widget/windows/moz.build index 123f493af1..4371a74f58 100644 --- a/widget/windows/moz.build +++ b/widget/windows/moz.build @@ -20,6 +20,7 @@ UNIFIED_SOURCES += [ 'AudioSession.cpp', 'GfxInfo.cpp', 'IEnumFE.cpp', + 'IMMHandler.cpp', 'InkCollector.cpp', 'JumpListItem.cpp', 'KeyboardLayout.cpp', @@ -31,7 +32,6 @@ UNIFIED_SOURCES += [ 'nsDragService.cpp', 'nsIdleServiceWin.cpp', 'nsImageClipboard.cpp', - 'nsIMM32Handler.cpp', 'nsLookAndFeel.cpp', 'nsNativeDragSource.cpp', 'nsNativeDragTarget.cpp', @@ -75,7 +75,7 @@ if CONFIG['NS_PRINTING']: if CONFIG['NS_ENABLE_TSF']: SOURCES += [ - 'nsTextStore.cpp', + 'TSFTextStore.cpp', ] include('/ipc/chromium/chromium-config.mozbuild') diff --git a/widget/windows/nsNativeDragTarget.cpp b/widget/windows/nsNativeDragTarget.cpp index 516fa64f9a..ffab0c402b 100644 --- a/widget/windows/nsNativeDragTarget.cpp +++ b/widget/windows/nsNativeDragTarget.cpp @@ -152,10 +152,11 @@ IsKeyDown(char key) } void -nsNativeDragTarget::DispatchDragDropEvent(uint32_t aEventType, POINTL aPT) +nsNativeDragTarget::DispatchDragDropEvent(EventMessage aEventMessage, + const POINTL& aPT) { nsEventStatus status; - WidgetDragEvent event(true, aEventType, mWidget); + WidgetDragEvent event(true, aEventMessage, mWidget); nsWindow * win = static_cast(mWidget); win->InitEvent(event); @@ -182,7 +183,7 @@ nsNativeDragTarget::DispatchDragDropEvent(uint32_t aEventType, POINTL aPT) } void -nsNativeDragTarget::ProcessDrag(uint32_t aEventType, +nsNativeDragTarget::ProcessDrag(EventMessage aEventMessage, DWORD grfKeyState, POINTL ptl, DWORD* pdwEffect) @@ -201,9 +202,34 @@ nsNativeDragTarget::ProcessDrag(uint32_t aEventType, currSession->SetDragAction(geckoAction); // Dispatch the event into Gecko - DispatchDragDropEvent(aEventType, ptl); + DispatchDragDropEvent(aEventMessage, ptl); - if (aEventType != NS_DRAGDROP_DROP) { + // If TakeChildProcessDragAction returns something other than + // DRAGDROP_ACTION_UNINITIALIZED, it means that the last event was sent + // to the child process and this event is also being sent to the child + // process. In this case, use the last event's action instead. + nsDragService* dragService = static_cast(mDragService); + currSession->GetDragAction(&geckoAction); + + int32_t childDragAction = dragService->TakeChildProcessDragAction(); + if (childDragAction != nsIDragService::DRAGDROP_ACTION_UNINITIALIZED) { + geckoAction = childDragAction; + } + + if (nsIDragService::DRAGDROP_ACTION_LINK & geckoAction) { + *pdwEffect = DROPEFFECT_LINK; + } + else if (nsIDragService::DRAGDROP_ACTION_COPY & geckoAction) { + *pdwEffect = DROPEFFECT_COPY; + } + else if (nsIDragService::DRAGDROP_ACTION_MOVE & geckoAction) { + *pdwEffect = DROPEFFECT_MOVE; + } + else { + *pdwEffect = DROPEFFECT_NONE; + } + + if (aEventMessage != NS_DRAGDROP_DROP) { // Get the cached drag effect from the drag service, the data member should // have been set by whoever handled the WidgetGUIEvent or nsIDOMEvent on // drags. diff --git a/widget/windows/nsNativeDragTarget.h b/widget/windows/nsNativeDragTarget.h index 703fa96d88..fbc28fc929 100644 --- a/widget/windows/nsNativeDragTarget.h +++ b/widget/windows/nsNativeDragTarget.h @@ -16,6 +16,7 @@ #endif #include "mozilla/Attributes.h" +#include "mozilla/EventForwards.h" class nsIDragService; class nsIWidget; @@ -71,9 +72,10 @@ protected: void GetGeckoDragAction(DWORD grfKeyState, LPDWORD pdwEffect, uint32_t * aGeckoAction); - void ProcessDrag(uint32_t aEventType, DWORD grfKeyState, + void ProcessDrag(mozilla::EventMessage aEventMessage, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); - void DispatchDragDropEvent(uint32_t aType, POINTL pt); + void DispatchDragDropEvent(mozilla::EventMessage aEventMessage, + const POINTL& aPT); void AddLinkSupportIfCanBeGenerated(LPDATAOBJECT aIDataSource); // Native Stuff diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index b82701a4b2..a98250485a 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -94,7 +94,6 @@ #include "nsIRollupListener.h" #include "nsIServiceManager.h" #include "nsIClipboard.h" -#include "nsIMM32Handler.h" #include "WinMouseScrollHandler.h" #include "nsFontMetrics.h" #include "nsIFontEnumerator.h" @@ -3642,7 +3641,7 @@ NS_IMETHODIMP nsWindow::DispatchEvent(WidgetGUIEvent* event, return NS_OK; } -bool nsWindow::DispatchStandardEvent(uint32_t aMsg) +bool nsWindow::DispatchStandardEvent(EventMessage aMsg) { WidgetGUIEvent event(true, aMsg, this); InitEvent(event); @@ -3752,9 +3751,10 @@ bool nsWindow::DispatchPluginEvent(UINT aMessage, } // Deal with all sort of mouse event -bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, - LPARAM lParam, bool aIsContextMenuKey, - int16_t aButton, uint16_t aInputSource) +bool +nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, + LPARAM lParam, bool aIsContextMenuKey, + int16_t aButton, uint16_t aInputSource) { bool result = false; @@ -3764,21 +3764,25 @@ bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, return result; } - // Checking for NS_MOUSE_MOVE prevents a largest waterfall of unused initializations. - if (NS_MOUSE_MOVE != aEventType - // Since it is unclear whether a user will use the digitizer, - // Postpone initialization until first PEN message will be found. - && nsIDOMMouseEvent::MOZ_SOURCE_PEN == aInputSource + if (mTouchWindow && WinUtils::GetIsMouseFromTouch(aEventMessage)) { + // If mTouchWindow is true, then we must have APZ enabled and be + // feeding it raw touch events. In that case we don't need to + // send touch-generated mouse events to content. + MOZ_ASSERT(mAPZC); + return result; + } + + // Since it is unclear whether a user will use the digitizer, + // Postpone initialization until first PEN message will be found. + if (nsIDOMMouseEvent::MOZ_SOURCE_PEN == aInputSource // Messages should be only at topLevel window. && nsWindowType::eWindowType_toplevel == mWindowType // Currently this scheme is used only when pointer events is enabled. - && gfxPrefs::PointerEventsEnabled() - // NS_MOUSE_EXIT_WIDGET is received, when InkCollector has been already initialized. - && NS_MOUSE_EXIT_WIDGET != aEventType) { + && gfxPrefs::PointerEventsEnabled()) { InkCollector::sInkCollector->SetTarget(mWnd); } - switch (aEventType) { + switch (aEventMessage) { case NS_MOUSE_BUTTON_DOWN: CaptureMouse(true); break; @@ -3801,10 +3805,10 @@ bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, eventPoint.x = GET_X_LPARAM(lParam); eventPoint.y = GET_Y_LPARAM(lParam); - WidgetMouseEvent event(true, aEventType, this, WidgetMouseEvent::eReal, + WidgetMouseEvent event(true, aEventMessage, this, WidgetMouseEvent::eReal, aIsContextMenuKey ? WidgetMouseEvent::eContextMenuKey : WidgetMouseEvent::eNormal); - if (aEventType == NS_CONTEXTMENU && aIsContextMenuKey) { + if (aEventMessage == NS_CONTEXTMENU && aIsContextMenuKey) { nsIntPoint zero(0, 0); InitEvent(event, &zero); } else { @@ -3815,16 +3819,14 @@ bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, modifierKeyState.InitInputEvent(event); event.button = aButton; event.inputSource = aInputSource; - // Convert Mouse events generated by pen device or if mouse not generated from touch - event.convertToPointer = - aInputSource == nsIDOMMouseEvent::MOZ_SOURCE_PEN || - !(WinUtils::GetIsMouseFromTouch(aEventType) && mTouchWindow); + // If we get here the mouse events must be from non-touch sources, so + // convert it to pointer events as well + event.convertToPointer = true; nsIntPoint mpScreen = eventPoint + WidgetToScreenOffsetUntyped(); // Suppress mouse moves caused by widget creation - if (aEventType == NS_MOUSE_MOVE) - { + if (aEventMessage == NS_MOUSE_MOVE) { if ((sLastMouseMovePoint.x == mpScreen.x) && (sLastMouseMovePoint.y == mpScreen.y)) return result; sLastMouseMovePoint.x = mpScreen.x; @@ -3854,36 +3856,43 @@ bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, // We're going to time double-clicks from mouse *up* to next mouse *down* LONG curMsgTime = ::GetMessageTime(); - if (aEventType == NS_MOUSE_DOUBLECLICK) { - event.mMessage = NS_MOUSE_BUTTON_DOWN; - event.button = aButton; - sLastClickCount = 2; - sLastMouseDownTime = curMsgTime; - } - else if (aEventType == NS_MOUSE_BUTTON_UP) { - // remember when this happened for the next mouse down - sLastMousePoint.x = eventPoint.x; - sLastMousePoint.y = eventPoint.y; - sLastMouseButton = eventButton; - } - else if (aEventType == NS_MOUSE_BUTTON_DOWN) { - // now look to see if we want to convert this to a double- or triple-click - if (((curMsgTime - sLastMouseDownTime) < (LONG)::GetDoubleClickTime()) && insideMovementThreshold && - eventButton == sLastMouseButton) { - sLastClickCount ++; - } else { - // reset the click count, to count *this* click - sLastClickCount = 1; - } - // Set last Click time on MouseDown only - sLastMouseDownTime = curMsgTime; - } - else if (aEventType == NS_MOUSE_MOVE && !insideMovementThreshold) { - sLastClickCount = 0; - } - else if (aEventType == NS_MOUSE_EXIT_WIDGET) { - event.exit = IsTopLevelMouseExit(mWnd) ? - WidgetMouseEvent::eTopLevel : WidgetMouseEvent::eChild; + switch (aEventMessage) { + case NS_MOUSE_DOUBLECLICK: + event.mMessage = NS_MOUSE_BUTTON_DOWN; + event.button = aButton; + sLastClickCount = 2; + sLastMouseDownTime = curMsgTime; + break; + case NS_MOUSE_BUTTON_UP: + // remember when this happened for the next mouse down + sLastMousePoint.x = eventPoint.x; + sLastMousePoint.y = eventPoint.y; + sLastMouseButton = eventButton; + break; + case NS_MOUSE_BUTTON_DOWN: + // now look to see if we want to convert this to a double- or triple-click + if (((curMsgTime - sLastMouseDownTime) < (LONG)::GetDoubleClickTime()) && + insideMovementThreshold && + eventButton == sLastMouseButton) { + sLastClickCount ++; + } else { + // reset the click count, to count *this* click + sLastClickCount = 1; + } + // Set last Click time on MouseDown only + sLastMouseDownTime = curMsgTime; + break; + case NS_MOUSE_MOVE: + if (!insideMovementThreshold) { + sLastClickCount = 0; + } + break; + case NS_MOUSE_EXIT_WIDGET: + event.exit = IsTopLevelMouseExit(mWnd) ? + WidgetMouseEvent::eTopLevel : WidgetMouseEvent::eChild; + break; + default: + break; } event.clickCount = sLastClickCount; @@ -3894,8 +3903,7 @@ bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, NPEvent pluginEvent; - switch (aEventType) - { + switch (aEventMessage) { case NS_MOUSE_BUTTON_DOWN: switch (aButton) { case WidgetMouseEvent::eLeftButton: @@ -3961,7 +3969,7 @@ bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, if (mWidgetListener) { if (nsToolkit::gMouseTrailer) nsToolkit::gMouseTrailer->Disable(); - if (aEventType == NS_MOUSE_MOVE) { + if (aEventMessage == NS_MOUSE_MOVE) { if (nsToolkit::gMouseTrailer && !sIsInMouseCapture) { nsToolkit::gMouseTrailer->SetMouseTrailerWindow(mWnd); } @@ -3987,7 +3995,7 @@ bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, } } } - } else if (aEventType == NS_MOUSE_EXIT_WIDGET) { + } else if (aEventMessage == NS_MOUSE_EXIT_WIDGET) { if (sCurrentWindow == this) { sCurrentWindow = nullptr; } @@ -6207,7 +6215,7 @@ bool nsWindow::OnTouch(WPARAM wParam, LPARAM lParam) // Walk across the touch point array processing each contact point for (uint32_t i = 0; i < cInputs; i++) { - uint32_t msg; + EventMessage msg; if (pInputs[i].dwFlags & (TOUCHEVENTF_DOWN | TOUCHEVENTF_MOVE)) { // Create a standard touch event to send @@ -6341,7 +6349,7 @@ bool nsWindow::OnGesture(WPARAM wParam, LPARAM lParam) } // Other gestures translate into simple gesture events: - WidgetSimpleGestureEvent event(true, 0, this); + WidgetSimpleGestureEvent event(true, NS_EVENT_NULL, this); if ( !mGesture.ProcessGestureMessage(mWnd, wParam, lParam, event) ) { return false; // fall through to DefWndProc } diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 644cd6e79a..31874e6c85 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -202,11 +202,15 @@ public: /** * Event helpers */ - virtual bool DispatchMouseEvent(uint32_t aEventType, WPARAM wParam, - LPARAM lParam, - bool aIsContextMenuKey = false, - int16_t aButton = mozilla::WidgetMouseEvent::eLeftButton, - uint16_t aInputSource = nsIDOMMouseEvent::MOZ_SOURCE_MOUSE); + virtual bool DispatchMouseEvent( + mozilla::EventMessage aEventMessage, + WPARAM wParam, + LPARAM lParam, + bool aIsContextMenuKey = false, + int16_t aButton = + mozilla::WidgetMouseEvent::eLeftButton, + uint16_t aInputSource = + nsIDOMMouseEvent::MOZ_SOURCE_MOUSE); virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent, nsEventStatus& aStatus); void DispatchPendingEvents(); @@ -352,7 +356,7 @@ protected: * Event processing helpers */ void DispatchFocusToTopLevelWindow(bool aIsActivate); - bool DispatchStandardEvent(uint32_t aMsg); + bool DispatchStandardEvent(mozilla::EventMessage aMsg); void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam); virtual bool ProcessMessage(UINT msg, WPARAM &wParam, LPARAM &lParam, LRESULT *aRetValue);