Closed Bug 790516 Opened 12 years ago Closed 12 years ago

[TSF] Should dispatch DOM events when document is unlocked

Categories

(Core :: Widget: Win32, defect)

x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla22

People

(Reporter: masayuki, Assigned: masayuki)

References

(Blocks 1 open bug)

Details

(Keywords: inputmethod)

Attachments

(10 files, 49 obsolete files)

(deleted), patch
jimm
: review+
Details | Diff | Splinter Review
(deleted), patch
emk
: review+
Details | Diff | Splinter Review
(deleted), patch
emk
: review+
Details | Diff | Splinter Review
(deleted), patch
jimm
: review+
Details | Diff | Splinter Review
(deleted), patch
Details | Diff | Splinter Review
(deleted), patch
jimm
: review+
Details | Diff | Splinter Review
(deleted), patch
Details | Diff | Splinter Review
(deleted), patch
Details | Diff | Splinter Review
(deleted), patch
jimm
: review+
Details | Diff | Splinter Review
(deleted), patch
jimm
: review+
Details | Diff | Splinter Review
Now, nsTextStore dispatches DOM events (composition events and set selection event) during document locked. However, it may cause document is changed by DOM event handlers.

We should dispatch such DOM events after RequestLock() called OnLockGranted().
The part.3 patch does NOT work fine without this patch. They're separated for easier review.
Attachment #691765 - Attachment is obsolete: true
Attached patch part.5 Cache content during document lock (obsolete) (deleted) — Splinter Review
Attachment #691805 - Attachment is obsolete: true
Attachment #694303 - Attachment is obsolete: true
Attachment #694304 - Attachment is obsolete: true
Attachment #694306 - Attachment is obsolete: true
Attachment #694307 - Attachment is obsolete: true
Attachment #694308 - Attachment is obsolete: true
Attachment #696937 - Attachment is obsolete: true
Attached patch part.6 Cache content during document lock (obsolete) (deleted) — Splinter Review
Attachment #696938 - Attachment is obsolete: true
Attached patch part.7 Remove nsTextStore::Composition::mLength (obsolete) (deleted) — Splinter Review
Attachment #696939 - Attachment is obsolete: true
Attached patch part.6 Cache content during document lock (obsolete) (deleted) — Splinter Review
Attachment #697022 - Attachment is obsolete: true
First of all, let's move composition data into new struct. This makes each member meaning clearer.
Attachment #697016 - Attachment is obsolete: true
Attachment #706830 - Flags: review?(VYV03354)
Note: mLastDispatchedTextEvent will be moved into another struct, don't mind about that.
(In reply to Masayuki Nakano (:masayuki) (Mozilla Japan) from comment #35)
> Note: mLastDispatchedTextEvent will be moved into another struct, don't mind
> about that.

Oops, not moved, it will be removed. Sorry for the bug spam.
These new methods of nsTextStore::Composition make the code simple.
Attachment #697017 - Attachment is obsolete: true
Attachment #706831 - Flags: review?(VYV03354)
This patch is the first important part of this bug.

We should just recode the action during document lock and need to flush the recorded actions at unlocking the document.

Note that On(Start|Update|End)Composition() are even called without document lock. Therefore, we need the FlushPendingActionsIfNotLocked class.

Note that only with this patch, all Get*() methods return information which are not changed by pending actions. This issue will be fixed by part.6.
Attachment #697018 - Attachment is obsolete: true
Attachment #706832 - Flags: review?(VYV03354)
Just refines logging code for the document lock.
Attachment #697019 - Attachment is obsolete: true
Attachment #706833 - Flags: review?(VYV03354)
Selection can be changed by SetSelection() and InsertTextAtSelection(). So, now, we should store the latest selection information which is also modified by pending actions outside of nsTextStore::Composition.

CurrentSelection() synchronizes the mSelection with actual selection of the focused content. So, before referencing the mSelection, the clients need to call CurrentSelection() first and they should use the result which references mSelection.
Attachment #697020 - Attachment is obsolete: true
Attachment #706834 - Flags: review?(VYV03354)
Attached patch part.6 Cache content during document lock (obsolete) (deleted) — Splinter Review
Similar to the Selection, we should store the content text and modify it during the document locked for Get*() methods returning the latest content and selection which may be modified by SetSelection(), SetText() or InsertTextAtSelection().
Attachment #697869 - Attachment is obsolete: true
Attachment #706835 - Flags: review?(VYV03354)
By the part.6, GetText() don't need to emulate the latest content and Composition::mLength is always same as Composition.mString.Length(). So, Composition::mLength is not necessary. We can remove it now.
Attachment #697023 - Attachment is obsolete: true
Attachment #706836 - Flags: review?(VYV03354)
Now, UpdateCompositionExtent() just does restarting composition if it's necessary. So, let's rename it with RestartCompositionIfNecessary().
Attachment #697024 - Attachment is obsolete: true
Attachment #706837 - Flags: review?(VYV03354)
OnStartCompositionInternal() isn't good name because it's also called by RestartCompositionIfNecessary().

Now, the method records compositionstart action. So, it should be RecordCompositionStartAction().
Attachment #697025 - Attachment is obsolete: true
Attachment #706838 - Flags: review?(VYV03354)
Similar to part.9, let's make RecordCompositionEndAction().
Attachment #697031 - Attachment is obsolete: true
Attachment #706839 - Flags: review?(VYV03354)
By these changes, no DOM events fired during document lock being granted. That means the content is actually locked from content script.

Now, changes which are caused by flushing pending actions are not notified to TSF via OnTextChange() or OnSelectionChange(). This is the requirements of TSF application.

However, even if content script changes the content at handling composition events or something, it should be notified by OnTextChange() and/or OnSelectionChange(). I have no idea how to implement this behavior. But this isn't a new bug, let's put off this issue.
Attachment #706830 - Flags: review?(VYV03354) → review+
Comment on attachment 706831 [details] [diff] [review]
part.2 Make some useful methods on nsTextStore::Composition

>+++ b/widget/windows/nsTextStore.cpp
>@@ -1265,36 +1266,31 @@ nsTextStore::SendTextEventForComposition
>-  if (mComposition.mSelection.acpStart !=
>-        mComposition.mSelection.acpEnd &&
>-      textRanges.Length() == 1) {
>+  if (mComposition.IsSelectionCollapsed() && textRanges.Length() == 1) {

|!mComposition.IsSelectionCollapsed()|?

>@@ -2486,25 +2471,26 @@ nsTextStore::OnStartCompositionInternal(
>   mWidget->InitEvent(event);
>   mWidget->DispatchWindowEvent(&event);
> 
>+  mComposition.Start(this);
>+
>   PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
>          ("TSF: 0x%p   nsTextStore::OnStartCompositionInternal() succeeded: "

>@@ -2543,18 +2529,16 @@ nsTextStore::OnStartComposition(ITfCompo
>     return hr;
>   }
> 
>-  mComposition.StartLayoutChangeTimer(this);
>-
>   *pfOk = TRUE;
>   PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,

Why did you move the position?
Attachment #706831 - Flags: review?(VYV03354) → review+
Attachment #706833 - Flags: review?(VYV03354) → review+
Attachment #706837 - Flags: review?(VYV03354) → review+
Attachment #706838 - Flags: review?(VYV03354) → review+
(In reply to Masatoshi Kimura [:emk] from comment #48)
> Comment on attachment 706831 [details] [diff] [review]
> part.2 Make some useful methods on nsTextStore::Composition
> 
> >+++ b/widget/windows/nsTextStore.cpp
> >@@ -1265,36 +1266,31 @@ nsTextStore::SendTextEventForComposition
> >-  if (mComposition.mSelection.acpStart !=
> >-        mComposition.mSelection.acpEnd &&
> >-      textRanges.Length() == 1) {
> >+  if (mComposition.IsSelectionCollapsed() && textRanges.Length() == 1) {
> 
> |!mComposition.IsSelectionCollapsed()|?

Good catch! Thanks!

> >@@ -2486,25 +2471,26 @@ nsTextStore::OnStartCompositionInternal(
> >   mWidget->InitEvent(event);
> >   mWidget->DispatchWindowEvent(&event);
> > 
> >+  mComposition.Start(this);
> >+
> >   PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
> >          ("TSF: 0x%p   nsTextStore::OnStartCompositionInternal() succeeded: "
> 
> >@@ -2543,18 +2529,16 @@ nsTextStore::OnStartComposition(ITfCompo
> >     return hr;
> >   }
> > 
> >-  mComposition.StartLayoutChangeTimer(this);
> >-
> >   *pfOk = TRUE;
> >   PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
> 
> Why did you move the position?

I don't think it's good to start the timer which is a part of composition start from OnCompositionStart(). The processing in OnCompositionStartInternal() will be moved to FlushPendingActions(). And then, it needs to start the timer in it. So, this change is a preparation of part.3.
Updated for the part.2's change.
Attachment #706834 - Attachment is obsolete: true
Attachment #706834 - Flags: review?(VYV03354)
Attachment #706980 - Flags: review?(VYV03354)
Removing MOZ_ASSERT() from CurrentSelection() since it may be called without document lock. E.g., from On*Composition().
Attachment #706980 - Attachment is obsolete: true
Attachment #706980 - Flags: review?(VYV03354)
Attachment #707471 - Flags: review?(VYV03354)
Attached patch part.6 Cache content during document lock (obsolete) (deleted) — Splinter Review
Updated for the new part.5.
Attachment #706835 - Attachment is obsolete: true
Attachment #706835 - Flags: review?(VYV03354)
Attachment #707472 - Flags: review?(VYV03354)
Comment on attachment 706832 [details] [diff] [review]
part.3 Store edit actions during document lock and flush them at unlocking the document

I find a mistake of this patch's design. On*Composition() may be called without document lock. Then, the actions are performed at quitting the called method (by FlushPendingActionsIfNotLocked). However, this can cause OnSelectionChangeInternal(). Then, TSF may request lock for checking the new selection. At this time, FlushPendingActions() call is nested.
Attachment #706832 - Flags: review?(VYV03354) → review-
This patch delays to call mSink->OnChangeSelection() when FlushPendingActions() causes nsTextStore::OnChangeSelectionInternal() without document lock. It will be called at the end of FlushPendingActions().
Attachment #706832 - Attachment is obsolete: true
Attachment #707471 - Attachment is obsolete: true
Attachment #707471 - Flags: review?(VYV03354)
Attached patch part.6 Cache content during document lock (obsolete) (deleted) — Splinter Review
I'll request reviews again after test the patched build.
Attachment #707472 - Attachment is obsolete: true
Attachment #707472 - Flags: review?(VYV03354)
Okay, ready for the review now.

See comment 38 for the detail. And let me know if you have some questions.
Attachment #707548 - Attachment is obsolete: true
Attachment #711852 - Flags: review?(VYV03354)
See comment 40 for the detail.
Attachment #707550 - Attachment is obsolete: true
Attachment #711855 - Flags: review?(VYV03354)
Attached patch part.6 Cache content during document lock (obsolete) (deleted) — Splinter Review
See comment 41 for the detail.
Attachment #707551 - Attachment is obsolete: true
Attachment #711856 - Flags: review?(VYV03354)
Comment on attachment 711852 [details] [diff] [review]
part.3 Store edit actions during document lock and flush them at unlocking the document

>@@ -736,27 +738,46 @@ nsTextStore::RequestLock(DWORD dwLockFla
>        "null phrSession", this));
>     return E_INVALIDARG;
>   }
> 
>   if (!mLock) {
>     // put on lock
>     mLock = dwLockFlags & (~TS_LF_SYNC);
>     PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
>-      ("TSF: 0x%p   nsTextStore::RequestLock() notifying OnLockGranted()...",
>-       this));
>+      ("TSF: 0x%p   Locking (%s) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
>+       ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
>+       ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
>+       this, GetLockFlagNameStr(mLock).get()));
>     *phrSession = mSink->OnLockGranted(mLock);
>+    PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
>+      ("TSF: 0x%p   Unlocked (%s) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
>+       "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
>+       "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
>+       this, GetLockFlagNameStr(mLock).get()));
>+    if (IsReadWriteLocked()) {
>+      FlushPendingActions();

Does this patch satisfy the condition required by the following MSDN sentence?

http://msdn.microsoft.com/en-us/library/windows/desktop/ms538447%28v=vs.85%29.aspx
> Applications must never modify the document or send change notifications
> using the ITextStoreACPSink::OnTextChange method from within the
> ITextStoreACP::RequestLock method. If the application has pending changes to
> report, the application can only respond to the asynchronous lock request.

In other words, will FlushPendingActions() never modify the document?

>+  class NS_STACK_CLASS FlushPendingActionsIfNotLocked MOZ_FINAL

nit: The class name should be a noun rather than a verb.
(In reply to Masatoshi Kimura [:emk] from comment #63)
> Comment on attachment 711852 [details] [diff] [review]
> part.3 Store edit actions during document lock and flush them at unlocking
> the document
> 
> Does this patch satisfy the condition required by the following MSDN
> sentence?
> 
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms538447%28v=vs.
> 85%29.aspx
> > Applications must never modify the document or send change notifications
> > using the ITextStoreACPSink::OnTextChange method from within the
> > ITextStoreACP::RequestLock method. If the application has pending changes to
> > report, the application can only respond to the asynchronous lock request.
> 
> In other words, will FlushPendingActions() never modify the document?

Hmm, FlushPendingAction() modifies the document from RequestLock(), of course. But I feel the document is odd. My understanding is, the document lock is only valid during OnLockGranted() call.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms538064%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms538403%28v=vs.85%29.aspx
So, at unlocking the document, i.e.. immediately after OnLockGranted() call, we should modify the document (by FlushPendinActions()) but it's still in RequestLock(), therefore, we never call OnTextChange() (since mLock value is still non-zero at FlushPendingActions() call).

If we needed to modify the document asynchronously after returning from RequestLock(), it would be possible with message hack or something. However, I don't guess that works fine because I guess that TIP (the caller) attempts to confirm the document's state after RequestLock() call synchronously.

And the document uses "or", not "and". So, I think that it's safe if we don't call OnTextChange() during RequestLock() call even we modify the document at that timing.

I'd like to know jimm's advice if he has.
Flags: needinfo?(jmathies)
(In reply to Masayuki Nakano (:masayuki) (Mozilla Japan) from comment #64)
> My understanding is, the document
> lock is only valid during OnLockGranted() call.
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms538064%28v=vs.
> 85%29.aspx
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms538403%28v=vs.
> 85%29.aspx

I'm confused. According to the document, TSF manager can modify the document only inside a read/write lock. But your patch is doing the exact opposite.

> And the document uses "or", not "and". So, I think that it's safe if we
> don't call OnTextChange() during RequestLock() call even we modify the
> document at that timing.

I think "not A or B" means "not (A or B)" here. (But let's hear it from a native English speaker.)
(In reply to Masatoshi Kimura [:emk] from comment #65)
> (In reply to Masayuki Nakano (:masayuki) (Mozilla Japan) from comment #64)
> > My understanding is, the document
> > lock is only valid during OnLockGranted() call.
> > http://msdn.microsoft.com/en-us/library/windows/desktop/ms538064%28v=vs.
> > 85%29.aspx
> > http://msdn.microsoft.com/en-us/library/windows/desktop/ms538403%28v=vs.
> > 85%29.aspx
> 
> I'm confused. According to the document, TSF manager can modify the document
> only inside a read/write lock. But your patch is doing the exact opposite.

Ah, okay. I need to explain the strategy of this bug for you.

Yes, the callers (typically, TIP) can call SetSelection(), SetText() and InsertTextAtSelection() which can modify the document only while OnLockGranted() is called for read-write lock request.

During the document lock, the documents must not be modified by non-callers such as DOM event handler (i.e., web application or chrome). Therefore, we need to *delay* the DOM event dispatch after unlocking the document. That's the main purpose of this bug. For example, if a web application destroys the window during OnLockGranted() call, TIP may be confused. And also shouldn't cause committing composition string. If we allow them, that means the document is NOT locked actually even during OnLockGranted() call.

During the read-write lock, changes caused by the methods called by TIP modify the cached content and the cached selection which are implemented by part.6 and part.5. The cached data is used for result of Get*() method during the document lock. By this change, I realized that the code becomes simpler since a lot of query-content events can be removed and widget-destroyed check isn't necessary.

Note that, ideally, if a DOM event handler changes the content or selection from a DOM composition event handler, we need to call OnTextChange() and OnSelectionChange() for TIP outside the RequestLock() call. However, this mechanism has never been implemented yet because we must not call them if changes are caused by TIP. These patches also still have this bug. But we should put off this issue latter since it needs a lot of other work.
Then document modifications by TIPs will be invisible from non-TIPs until the document is unlocked. Is it correct?
(In reply to Masatoshi Kimura [:emk] from comment #67)
> Then document modifications by TIPs will be invisible from non-TIPs until
> the document is unlocked. Is it correct?

If the non-TIPs means web apps, Yes. Exactly.
Consider the following scenario:
1. A TIP obtains a document lock and makes some modifications to the document. The modifications will be pending.
2. A web app obtains a text via DOM.
3. The TIP unlocked the document. All pending modifications will be committed.
4. The web app makes a modification to the text based on the text obtained in step 2. All modifications made by the TIP will be lost because they were invisible from the web app.
No, #2 must not happen. The possible scenario is:

1. A TIP requests read-write lock
2. TIP receives OnLockGranted() call and may modify the document.
3. Immediately after returning from OnLockGranted(), FlushPendingActions() dispatches one or more DOM events. At this time, web application can do anything. But neither OnTextChange() nor OnSelectionChange() are called for TIP (this is a bug, I think).
4. Returning from RequestLock() called for #1.
The problem of current code is, during #2, web applications can do anything.
(In reply to Masayuki Nakano (:masayuki) (Mozilla Japan) from comment #70)
> No, #2 must not happen. The possible scenario is:
> 
> 1. A TIP requests read-write lock
> 2. TIP receives OnLockGranted() call and may modify the document.
> 3. Immediately after returning from OnLockGranted(), FlushPendingActions()
> dispatches one or more DOM events. At this time, web application can do
> anything. But neither OnTextChange() nor OnSelectionChange() are called for
> TIP (this is a bug, I think).
> 4. Returning from RequestLock() called for #1.

Will web apps never executed during the step 2. by, for example, setTimeout?
(In reply to Masayuki Nakano (:masayuki) (Mozilla Japan) from comment #64)
> Hmm, FlushPendingAction() modifies the document from RequestLock(), of
> course. But I feel the document is odd. My understanding is, the document
> lock is only valid during OnLockGranted() call.

"The lock is only valid during the OnLockGranted call. When OnLockGranted returns, the document is considered unlocked."

Seems pretty clear - modifying the doc after OnLockGranted returns seems ok.
Flags: needinfo?(jmathies)
(In reply to Jim Mathies [:jimm] from comment #74)
> "The lock is only valid during the OnLockGranted call. When OnLockGranted
> returns, the document is considered unlocked."
> 
> Seems pretty clear - modifying the doc after OnLockGranted returns seems ok.

When the document is unlocked, *TIPs* cannot change the document (via the TSF manager). But the following sentence is a requirement to the *applications*. No?
> Applications must never modify the document or send change notifications
> using the ITextStoreACPSink::OnTextChange method from within the
> ITextStoreACP::RequestLock method. If the application has pending changes to
> report, the application can only respond to the asynchronous lock request.
Hmm, you might be right. However, I think that we have no plan B for now.

First, we never call OnTextChange() at Flushing the pending actions because mLock is still non-zero at that time. This is not problem for your concern.

Next, dispatching composition or text events may cause changing the document by (web) applications. This is what you're concerned. However, even in this time, we don't call OnTextChange() (I mentioned this at the last paragraph in comment 66, but this is NOT a new bug with the patches).

So, I think, ideally, we should NOT dispatch the events into the DOM tree at that time but should modify nsEditor directly instead. And after that, we should dispatch DOM composition events (and other events such as input events).

But this needs a lot of additional work in XP level (not impossible).

Therefore, I think that we should land these patches for now because this patch prevents the change during calling OnLockGranted() and makes accessing contents faster. And then, I should work for making dispatching DOM events asynchronous in another bug.
Let's sort out the issues:

1. Current m-c code dispatches DOM events during calling OnLockGranted(). This may cause unexpected result of Get*() methods during OnLockGranted() call. And also, the text store may be destroyed during OnLockGranted() call.

2. Even with the patches of this bug, DOM events are dispatched during RequestLock() call. Then, DOM event handler may modify the content but that doesn't cause OnTextChange() call. I.e., cached content in TIP and actual content may not match at that time.

The patches only fixed #1. In the future, TextComposition class should modify editor directly. And DOM composition event (and other all events which are fixed by the change, e.g., input event, select event) should be dispatched asynchronously after RequestLock() call.

So, please focus #1 for now. I believe these patches really improve the code in nsTextStore and avoid a lot of strange behavior which TIP feels.
updated for latest m-c.
Attachment #706830 - Attachment is obsolete: true
Kimura-san, if you don't have much time to review them, let me know. If so, I think that jimm is a better reviewer.
Flags: needinfo?(VYV03354)
Sorry, I'm busy for the time being. I have no time to review the substantial patch. Feel free to reassign the reviewer.
Flags: needinfo?(VYV03354)
Thank you, Kimura-san. No problem. Most Japanese people are busy in February and March.

Jimm, so, it's difficult Kimura-san to review these big patches. Could you review them?

See comment 38 for the detail of this patch.
Attachment #711852 - Attachment is obsolete: true
Attachment #711852 - Flags: review?(VYV03354)
Attachment #723147 - Flags: review?(jmathies)
Comment on attachment 711855 [details] [diff] [review]
part.5 Store selection even if there is no composition

See comment 40 for the detail of this patch.
Attachment #711855 - Flags: review?(VYV03354) → review?(jmathies)
See comment 41 for the detail of this patch.
Attachment #711856 - Attachment is obsolete: true
Attachment #711856 - Flags: review?(VYV03354)
Attachment #723149 - Flags: review?(jmathies)
Comment on attachment 706836 [details] [diff] [review]
part.7 Remove nsTextStore::Composition::mLength

See comment 42 for the detail of this patch.
Attachment #706836 - Flags: review?(VYV03354) → review?(jmathies)
Comment on attachment 706839 [details] [diff] [review]
part.10 Make nsTextStore::RecordCompositionEndAction() for processing composition end action

See comment 45 for the detail of this patch.
Attachment #706839 - Flags: review?(VYV03354) → review?(jmathies)
Attachment #706836 - Flags: review?(jmathies) → review+
Comment on attachment 706839 [details] [diff] [review]
part.10 Make nsTextStore::RecordCompositionEndAction() for processing composition end action

Review of attachment 706839 [details] [diff] [review]:
-----------------------------------------------------------------

::: widget/windows/nsTextStore.cpp
@@ +2672,5 @@
> +           ("TSF: 0x%p   nsTextStore::RecordCompositionEndAction() FAILED due "
> +            "to CurrentContent() failure", this));
> +    return E_FAIL;
> +  }
> +  currentContent.EndComposition(*action);

This seems odd. You've added action to mPendingActions but if you fail due to !currentContent.IsInitialized() we never call EndComposition. Plus the action stays in the pending array?
Comment on attachment 711855 [details] [diff] [review]
part.5 Store selection even if there is no composition

Review of attachment 711855 [details] [diff] [review]:
-----------------------------------------------------------------

::: widget/windows/nsTextStore.cpp
@@ +1133,5 @@
> +  if (mSelection.IsDirty()) {
> +    // If the window has never been available, we should crash since working
> +    // with broken values may make TIP confused.
> +    if (!mWidget || mWidget->Destroyed()) {
> +      MOZ_CRASH();

Crashing the browser is the only solution we have here? This seems rather extreme.
Attachment #723147 - Flags: review?(jmathies) → review+
Attachment #723149 - Flags: review?(jmathies) → review+
(In reply to Jim Mathies [:jimm] from comment #89)
> Comment on attachment 711855 [details] [diff] [review]
> part.5 Store selection even if there is no composition
> 
> Review of attachment 711855 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: widget/windows/nsTextStore.cpp
> @@ +1133,5 @@
> > +  if (mSelection.IsDirty()) {
> > +    // If the window has never been available, we should crash since working
> > +    // with broken values may make TIP confused.
> > +    if (!mWidget || mWidget->Destroyed()) {
> > +      MOZ_CRASH();
> 
> Crashing the browser is the only solution we have here? This seems rather
> extreme.

Basically, it should never happen. When mWidget is cleared or destroyed, nsTextStore::Destroy() must be called at that time. So, after that, the link between nsTextStore and TIP should be disconnected. Why I used MOZ_CRASH() is easier to find such critical bug than assertion because assertions are usually not filed as bug :-(

However, I don't mind if you don't like crashing here. Just returning from here is Okay.
(In reply to Jim Mathies [:jimm] from comment #88)
> Comment on attachment 706839 [details] [diff] [review]
> part.10 Make nsTextStore::RecordCompositionEndAction() for processing
> composition end action
> 
> Review of attachment 706839 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: widget/windows/nsTextStore.cpp
> @@ +2672,5 @@
> > +           ("TSF: 0x%p   nsTextStore::RecordCompositionEndAction() FAILED due "
> > +            "to CurrentContent() failure", this));
> > +    return E_FAIL;
> > +  }
> > +  currentContent.EndComposition(*action);
> 
> This seems odd. You've added action to mPendingActions but if you fail due
> to !currentContent.IsInitialized() we never call EndComposition.

currentContent.EndComposition() is called for synchronizing the cached content as expected by TIP. Therefore, If |!currentContent.IsInitialized()| happened, there is no cached content which should be synchronized.

> Plus the action stays in the pending array?

No. If it's called during document lock, FlushPendingActions() must be called by nsTextStore::RequestLock(). Otherwise, i.e., nsTextStore::OnEndComposition() is called without document lock, AutoPendingActionAndContentFlusher instance in OnEndComposition() will call FlushPendingActions(). (Of course, if somebody forgot to create an auto flusher, it would occur such bug you concerned)
Attachment #706839 - Flags: review?(jmathies) → review+
Comment on attachment 711855 [details] [diff] [review]
part.5 Store selection even if there is no composition

Review of attachment 711855 [details] [diff] [review]:
-----------------------------------------------------------------

Well if it is never going to happen. (Although with mozilla I've learned to never say never. ;)
Attachment #711855 - Flags: review?(jmathies) → review+
Thank you jimm for your review for such difficult patches! (separated patches are sometimes not easy to read)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: