Bug 1179632 part.6 KeyboardEvent.isComposing shouldn't expose IME state on different document r=smaug

This commit is contained in:
Masayuki Nakano 2015-12-04 18:50:43 +09:00
parent cabb3fe88d
commit dd30739445
5 changed files with 38 additions and 15 deletions

View File

@ -760,15 +760,17 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
if (content)
mCurrentTargetContent = content;
// NOTE: Don't refer TextComposition::IsComposing() since DOM Level 3
// Events defines that KeyboardEvent.isComposing is true when it's
// NOTE: Don't refer TextComposition::IsComposing() since UI Events
// defines that KeyboardEvent.isComposing is true when it's
// dispatched after compositionstart and compositionend.
// TextComposition::IsComposing() is false even before
// compositionend if there is no composing string.
WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
// And also don't expose other document's composition state.
// A native IME context is typically shared by multiple documents.
// So, don't use GetTextCompositionFor(nsIWidget*) here.
RefPtr<TextComposition> composition =
IMEStateManager::GetTextCompositionFor(keyEvent);
keyEvent->mIsComposing = !!composition;
IMEStateManager::GetTextCompositionFor(aPresContext);
aEvent->AsKeyboardEvent()->mIsComposing = !!composition;
}
break;
case eWheel:

View File

@ -1660,14 +1660,6 @@ IMEStateManager::GetTextCompositionFor(nsIWidget* aWidget)
return textComposition.forget();
}
// static
already_AddRefed<TextComposition>
IMEStateManager::GetTextCompositionFor(
const WidgetKeyboardEvent* aKeyboardEvent)
{
return GetTextCompositionFor(aKeyboardEvent->widget);
}
// static
already_AddRefed<TextComposition>
IMEStateManager::GetTextCompositionFor(
@ -1681,4 +1673,16 @@ IMEStateManager::GetTextCompositionFor(
return textComposition.forget();
}
// static
already_AddRefed<TextComposition>
IMEStateManager::GetTextCompositionFor(nsPresContext* aPresContext)
{
if (!sTextCompositions) {
return nullptr;
}
RefPtr<TextComposition> textComposition =
sTextCompositions->GetCompositionFor(aPresContext);
return textComposition.forget();
}
} // namespace mozilla

View File

@ -182,11 +182,17 @@ public:
/**
* Returns TextComposition instance for the event.
*/
static already_AddRefed<TextComposition>
GetTextCompositionFor(const WidgetKeyboardEvent* aKeyboardEvent);
static already_AddRefed<TextComposition>
GetTextCompositionFor(const WidgetCompositionEvent* aCompositionEvent);
/**
* Returns TextComposition instance for the pres context.
* Be aware, even if another pres context which shares native IME context with
* specified pres context has composition, this returns nullptr.
*/
static already_AddRefed<TextComposition>
GetTextCompositionFor(nsPresContext* aPresContext);
/**
* Send a notification to IME. It depends on the IME or platform spec what
* will occur (or not occur).

View File

@ -710,6 +710,16 @@ TextCompositionArray::GetCompositionFor(
return ElementAt(i);
}
TextComposition*
TextCompositionArray::GetCompositionFor(nsPresContext* aPresContext)
{
index_type i = IndexOf(aPresContext);
if (i == NoIndex) {
return nullptr;
}
return ElementAt(i);
}
TextComposition*
TextCompositionArray::GetCompositionFor(nsPresContext* aPresContext,
nsINode* aNode)

View File

@ -415,6 +415,7 @@ public:
index_type IndexOf(nsPresContext* aPresContext);
index_type IndexOf(nsPresContext* aPresContext, nsINode* aNode);
TextComposition* GetCompositionFor(nsPresContext* aPresContext);
TextComposition* GetCompositionFor(nsPresContext* aPresContext,
nsINode* aNode);
TextComposition* GetCompositionInContent(nsPresContext* aPresContext,