зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1275473 - Implement CompositionEvent.ranges. r=masayuki, r=smaug
This commit is contained in:
Родитель
8f7ffc84b7
Коммит
5362a0f92e
|
@ -69,6 +69,27 @@ CompositionEvent::InitCompositionEvent(const nsAString& aType,
|
||||||
mLocale = aLocale;
|
mLocale = aLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CompositionEvent::GetRanges(TextClauseArray& aRanges)
|
||||||
|
{
|
||||||
|
// If the mRanges is not empty, we return the cached value.
|
||||||
|
if (!mRanges.IsEmpty()) {
|
||||||
|
aRanges = mRanges;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RefPtr<TextRangeArray> textRangeArray = mEvent->AsCompositionEvent()->mRanges;
|
||||||
|
if (!textRangeArray) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mOwner);
|
||||||
|
const TextRange* targetRange = textRangeArray->GetTargetClause();
|
||||||
|
for (size_t i = 0; i < textRangeArray->Length(); i++) {
|
||||||
|
const TextRange& range = textRangeArray->ElementAt(i);
|
||||||
|
mRanges.AppendElement(new TextClause(window, range, targetRange));
|
||||||
|
}
|
||||||
|
aRanges = mRanges;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,16 @@
|
||||||
#define mozilla_dom_CompositionEvent_h_
|
#define mozilla_dom_CompositionEvent_h_
|
||||||
|
|
||||||
#include "mozilla/dom/CompositionEventBinding.h"
|
#include "mozilla/dom/CompositionEventBinding.h"
|
||||||
|
#include "mozilla/dom/TextClause.h"
|
||||||
|
#include "mozilla/dom/TypedArray.h"
|
||||||
#include "mozilla/dom/UIEvent.h"
|
#include "mozilla/dom/UIEvent.h"
|
||||||
#include "mozilla/EventForwards.h"
|
#include "mozilla/EventForwards.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
|
typedef nsTArray<RefPtr<TextClause>> TextClauseArray;
|
||||||
|
|
||||||
class CompositionEvent : public UIEvent
|
class CompositionEvent : public UIEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -37,12 +41,14 @@ public:
|
||||||
const nsAString& aLocale);
|
const nsAString& aLocale);
|
||||||
void GetData(nsAString&) const;
|
void GetData(nsAString&) const;
|
||||||
void GetLocale(nsAString&) const;
|
void GetLocale(nsAString&) const;
|
||||||
|
void GetRanges(TextClauseArray& aRanges);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~CompositionEvent() {}
|
~CompositionEvent() {}
|
||||||
|
|
||||||
nsString mData;
|
nsString mData;
|
||||||
nsString mLocale;
|
nsString mLocale;
|
||||||
|
TextClauseArray mRanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* 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/. */
|
||||||
|
|
||||||
|
#include "mozilla/dom/TextClause.h"
|
||||||
|
#include "mozilla/dom/TextClauseBinding.h"
|
||||||
|
#include "mozilla/TextEvents.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
// Only needed for refcounted objects.
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(TextClause)
|
||||||
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TextClause)
|
||||||
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(TextClause)
|
||||||
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextClause)
|
||||||
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||||
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||||
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
|
TextClause::TextClause(nsPIDOMWindowInner* aOwner, const TextRange& aRange,
|
||||||
|
const TextRange* aTargetRange)
|
||||||
|
: mOwner(aOwner)
|
||||||
|
, mIsTargetClause(false)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aOwner);
|
||||||
|
mStartOffset = aRange.mStartOffset;
|
||||||
|
mEndOffset = aRange.mEndOffset;
|
||||||
|
if (aRange.IsClause()) {
|
||||||
|
mIsCaret = false;
|
||||||
|
if (aTargetRange && aTargetRange->mStartOffset == mStartOffset) {
|
||||||
|
mIsTargetClause = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mIsCaret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JSObject*
|
||||||
|
TextClause::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||||
|
{
|
||||||
|
return TextClauseBinding::Wrap(aCx, this, aGivenProto);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextClause::~TextClause() {}
|
||||||
|
|
||||||
|
} // namespace dom
|
||||||
|
} // namespace mozilla
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* 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 mozilla_dom_TextClause_h
|
||||||
|
#define mozilla_dom_TextClause_h
|
||||||
|
|
||||||
|
#include "js/TypeDecls.h"
|
||||||
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/ErrorResult.h"
|
||||||
|
#include "mozilla/dom/BindingDeclarations.h"
|
||||||
|
#include "nsCycleCollectionParticipant.h"
|
||||||
|
#include "nsWrapperCache.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
class TextClause final : public nsISupports
|
||||||
|
, public nsWrapperCache
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextClause)
|
||||||
|
|
||||||
|
nsPIDOMWindowInner* GetParentObject() const { return mOwner; }
|
||||||
|
|
||||||
|
TextClause(nsPIDOMWindowInner* aWindow, const TextRange& aRange,
|
||||||
|
const TextRange* targetRange);
|
||||||
|
|
||||||
|
virtual JSObject* WrapObject(JSContext* aCx,
|
||||||
|
JS::Handle<JSObject*> aGivenProto) override;
|
||||||
|
|
||||||
|
inline uint32_t StartOffset() const { return mStartOffset; }
|
||||||
|
|
||||||
|
inline uint32_t EndOffset() const { return mEndOffset; }
|
||||||
|
|
||||||
|
inline bool IsCaret() const { return mIsCaret; }
|
||||||
|
|
||||||
|
inline bool IsTargetClause() const { return mIsTargetClause; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
~TextClause();
|
||||||
|
nsCOMPtr<nsPIDOMWindowInner> mOwner;
|
||||||
|
|
||||||
|
// Following members, please take look at widget/TextRange.h.
|
||||||
|
uint32_t mStartOffset;
|
||||||
|
uint32_t mEndOffset;
|
||||||
|
bool mIsCaret;
|
||||||
|
bool mIsTargetClause;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dom
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif // mozilla_dom_TextClause_h
|
|
@ -64,6 +64,7 @@ EXPORTS.mozilla.dom += [
|
||||||
'ScrollAreaEvent.h',
|
'ScrollAreaEvent.h',
|
||||||
'SimpleGestureEvent.h',
|
'SimpleGestureEvent.h',
|
||||||
'StorageEvent.h',
|
'StorageEvent.h',
|
||||||
|
'TextClause.h',
|
||||||
'Touch.h',
|
'Touch.h',
|
||||||
'TouchEvent.h',
|
'TouchEvent.h',
|
||||||
'TransitionEvent.h',
|
'TransitionEvent.h',
|
||||||
|
@ -112,6 +113,7 @@ UNIFIED_SOURCES += [
|
||||||
'ScrollAreaEvent.cpp',
|
'ScrollAreaEvent.cpp',
|
||||||
'SimpleGestureEvent.cpp',
|
'SimpleGestureEvent.cpp',
|
||||||
'StorageEvent.cpp',
|
'StorageEvent.cpp',
|
||||||
|
'TextClause.cpp',
|
||||||
'TextComposition.cpp',
|
'TextComposition.cpp',
|
||||||
'Touch.cpp',
|
'Touch.cpp',
|
||||||
'TouchEvent.cpp',
|
'TouchEvent.cpp',
|
||||||
|
|
|
@ -13,6 +13,13 @@ interface CompositionEvent : UIEvent
|
||||||
{
|
{
|
||||||
readonly attribute DOMString? data;
|
readonly attribute DOMString? data;
|
||||||
readonly attribute DOMString locale;
|
readonly attribute DOMString locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ranges is trying to expose TextRangeArray in Gecko so a
|
||||||
|
* js-plugin couble be able to know the clauses information
|
||||||
|
*/
|
||||||
|
[ChromeOnly,Cached,Pure]
|
||||||
|
readonly attribute sequence<TextClause> ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
partial interface CompositionEvent
|
partial interface CompositionEvent
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* 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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
[ChromeOnly]
|
||||||
|
interface TextClause
|
||||||
|
{
|
||||||
|
// The start offset of TextClause
|
||||||
|
readonly attribute long startOffset;
|
||||||
|
|
||||||
|
// The end offset of TextClause
|
||||||
|
readonly attribute long endOffset;
|
||||||
|
|
||||||
|
// If the TextClause is Caret or not
|
||||||
|
readonly attribute boolean isCaret;
|
||||||
|
|
||||||
|
// If the TextClause is TargetClause or not
|
||||||
|
readonly attribute boolean isTargetClause;
|
||||||
|
};
|
|
@ -545,6 +545,7 @@ WEBIDL_FILES = [
|
||||||
'TelephonyCallGroup.webidl',
|
'TelephonyCallGroup.webidl',
|
||||||
'TelephonyCallId.webidl',
|
'TelephonyCallId.webidl',
|
||||||
'Text.webidl',
|
'Text.webidl',
|
||||||
|
'TextClause.webidl',
|
||||||
'TextDecoder.webidl',
|
'TextDecoder.webidl',
|
||||||
'TextEncoder.webidl',
|
'TextEncoder.webidl',
|
||||||
'TextTrack.webidl',
|
'TextTrack.webidl',
|
||||||
|
|
|
@ -548,6 +548,7 @@ public:
|
||||||
|
|
||||||
mData = aEvent.mData;
|
mData = aEvent.mData;
|
||||||
mOriginalMessage = aEvent.mOriginalMessage;
|
mOriginalMessage = aEvent.mOriginalMessage;
|
||||||
|
mRanges = aEvent.mRanges;
|
||||||
|
|
||||||
// Currently, we don't need to copy the other members because they are
|
// Currently, we don't need to copy the other members because they are
|
||||||
// for internal use only (not available from JS).
|
// for internal use only (not available from JS).
|
||||||
|
|
Загрузка…
Ссылка в новой задаче