widget/TextEvents.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef mozilla_TextEvents_h__
michael@0 7 #define mozilla_TextEvents_h__
michael@0 8
michael@0 9 #include <stdint.h>
michael@0 10
michael@0 11 #include "mozilla/Assertions.h"
michael@0 12 #include "mozilla/BasicEvents.h"
michael@0 13 #include "mozilla/EventForwards.h" // for KeyNameIndex, temporarily
michael@0 14 #include "mozilla/TextRange.h"
michael@0 15 #include "nsCOMPtr.h"
michael@0 16 #include "nsIDOMKeyEvent.h"
michael@0 17 #include "nsITransferable.h"
michael@0 18 #include "nsRect.h"
michael@0 19 #include "nsStringGlue.h"
michael@0 20 #include "nsTArray.h"
michael@0 21
michael@0 22 /******************************************************************************
michael@0 23 * virtual keycode values
michael@0 24 ******************************************************************************/
michael@0 25
michael@0 26 #define NS_DEFINE_VK(aDOMKeyName, aDOMKeyCode) NS_##aDOMKeyName = aDOMKeyCode
michael@0 27
michael@0 28 enum
michael@0 29 {
michael@0 30 #include "mozilla/VirtualKeyCodeList.h"
michael@0 31 };
michael@0 32
michael@0 33 #undef NS_DEFINE_VK
michael@0 34
michael@0 35 #define kLatestSeqno UINT32_MAX
michael@0 36
michael@0 37 namespace mozilla {
michael@0 38
michael@0 39 namespace dom {
michael@0 40 class PBrowserParent;
michael@0 41 class PBrowserChild;
michael@0 42 } // namespace dom
michael@0 43 namespace plugins {
michael@0 44 class PPluginInstanceChild;
michael@0 45 } // namespace plugins
michael@0 46
michael@0 47 /******************************************************************************
michael@0 48 * mozilla::AlternativeCharCode
michael@0 49 *
michael@0 50 * This stores alternative charCode values of a key event with some modifiers.
michael@0 51 * The stored values proper for testing shortcut key or access key.
michael@0 52 ******************************************************************************/
michael@0 53
michael@0 54 struct AlternativeCharCode
michael@0 55 {
michael@0 56 AlternativeCharCode(uint32_t aUnshiftedCharCode, uint32_t aShiftedCharCode) :
michael@0 57 mUnshiftedCharCode(aUnshiftedCharCode), mShiftedCharCode(aShiftedCharCode)
michael@0 58 {
michael@0 59 }
michael@0 60 uint32_t mUnshiftedCharCode;
michael@0 61 uint32_t mShiftedCharCode;
michael@0 62 };
michael@0 63
michael@0 64 /******************************************************************************
michael@0 65 * mozilla::WidgetKeyboardEvent
michael@0 66 ******************************************************************************/
michael@0 67
michael@0 68 class WidgetKeyboardEvent : public WidgetInputEvent
michael@0 69 {
michael@0 70 private:
michael@0 71 friend class dom::PBrowserParent;
michael@0 72 friend class dom::PBrowserChild;
michael@0 73
michael@0 74 WidgetKeyboardEvent()
michael@0 75 {
michael@0 76 }
michael@0 77
michael@0 78 public:
michael@0 79 virtual WidgetKeyboardEvent* AsKeyboardEvent() MOZ_OVERRIDE { return this; }
michael@0 80
michael@0 81 WidgetKeyboardEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget)
michael@0 82 : WidgetInputEvent(aIsTrusted, aMessage, aWidget, NS_KEY_EVENT)
michael@0 83 , keyCode(0)
michael@0 84 , charCode(0)
michael@0 85 , location(nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD)
michael@0 86 , isChar(false)
michael@0 87 , mIsRepeat(false)
michael@0 88 , mIsComposing(false)
michael@0 89 , mKeyNameIndex(mozilla::KEY_NAME_INDEX_Unidentified)
michael@0 90 , mNativeKeyEvent(nullptr)
michael@0 91 , mUniqueId(0)
michael@0 92 {
michael@0 93 }
michael@0 94
michael@0 95 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
michael@0 96 {
michael@0 97 MOZ_ASSERT(eventStructType == NS_KEY_EVENT,
michael@0 98 "Duplicate() must be overridden by sub class");
michael@0 99 // Not copying widget, it is a weak reference.
michael@0 100 WidgetKeyboardEvent* result =
michael@0 101 new WidgetKeyboardEvent(false, message, nullptr);
michael@0 102 result->AssignKeyEventData(*this, true);
michael@0 103 result->mFlags = mFlags;
michael@0 104 return result;
michael@0 105 }
michael@0 106
michael@0 107 // A DOM keyCode value or 0. If a keypress event whose charCode is 0, this
michael@0 108 // should be 0.
michael@0 109 uint32_t keyCode;
michael@0 110 // If the instance is a keypress event of a printable key, this is a UTF-16
michael@0 111 // value of the key. Otherwise, 0. This value must not be a control
michael@0 112 // character when some modifiers are active. Then, this value should be an
michael@0 113 // unmodified value except Shift and AltGr.
michael@0 114 uint32_t charCode;
michael@0 115 // One of nsIDOMKeyEvent::DOM_KEY_LOCATION_*
michael@0 116 uint32_t location;
michael@0 117 // OS translated Unicode chars which are used for accesskey and accelkey
michael@0 118 // handling. The handlers will try from first character to last character.
michael@0 119 nsTArray<AlternativeCharCode> alternativeCharCodes;
michael@0 120 // Indicates whether the event signifies a printable character
michael@0 121 bool isChar;
michael@0 122 // Indicates whether the event is generated by auto repeat or not.
michael@0 123 // if this is keyup event, always false.
michael@0 124 bool mIsRepeat;
michael@0 125 // Indicates whether the event is generated during IME (or deadkey)
michael@0 126 // composition. This is initialized by EventStateManager. So, key event
michael@0 127 // dispatchers don't need to initialize this.
michael@0 128 bool mIsComposing;
michael@0 129 // DOM KeyboardEvent.key
michael@0 130 KeyNameIndex mKeyNameIndex;
michael@0 131 // DOM KeyboardEvent.key only when mKeyNameIndex is KEY_NAME_INDEX_USE_STRING.
michael@0 132 nsString mKeyValue;
michael@0 133 // OS-specific native event can optionally be preserved
michael@0 134 void* mNativeKeyEvent;
michael@0 135 // Unique id associated with a keydown / keypress event. Used in identifing
michael@0 136 // keypress events for removal from async event dispatch queue in metrofx
michael@0 137 // after preventDefault is called on keydown events. It's ok if this wraps
michael@0 138 // over long periods.
michael@0 139 uint32_t mUniqueId;
michael@0 140
michael@0 141 void GetDOMKeyName(nsAString& aKeyName)
michael@0 142 {
michael@0 143 if (mKeyNameIndex == KEY_NAME_INDEX_USE_STRING) {
michael@0 144 aKeyName = mKeyValue;
michael@0 145 return;
michael@0 146 }
michael@0 147 GetDOMKeyName(mKeyNameIndex, aKeyName);
michael@0 148 }
michael@0 149
michael@0 150 static void GetDOMKeyName(mozilla::KeyNameIndex aKeyNameIndex,
michael@0 151 nsAString& aKeyName);
michael@0 152
michael@0 153 static const char* GetCommandStr(Command aCommand);
michael@0 154
michael@0 155 void AssignKeyEventData(const WidgetKeyboardEvent& aEvent, bool aCopyTargets)
michael@0 156 {
michael@0 157 AssignInputEventData(aEvent, aCopyTargets);
michael@0 158
michael@0 159 keyCode = aEvent.keyCode;
michael@0 160 charCode = aEvent.charCode;
michael@0 161 location = aEvent.location;
michael@0 162 alternativeCharCodes = aEvent.alternativeCharCodes;
michael@0 163 isChar = aEvent.isChar;
michael@0 164 mIsRepeat = aEvent.mIsRepeat;
michael@0 165 mIsComposing = aEvent.mIsComposing;
michael@0 166 mKeyNameIndex = aEvent.mKeyNameIndex;
michael@0 167 mKeyValue = aEvent.mKeyValue;
michael@0 168 // Don't copy mNativeKeyEvent because it may be referred after its instance
michael@0 169 // is destroyed.
michael@0 170 mNativeKeyEvent = nullptr;
michael@0 171 mUniqueId = aEvent.mUniqueId;
michael@0 172 }
michael@0 173 };
michael@0 174
michael@0 175 /******************************************************************************
michael@0 176 * mozilla::WidgetTextEvent
michael@0 177 *
michael@0 178 * XXX WidgetTextEvent is fired with compositionupdate event almost every time.
michael@0 179 * This wastes performance and the cost of mantaining each platform's
michael@0 180 * implementation. Therefore, we should merge WidgetTextEvent and
michael@0 181 * WidgetCompositionEvent. Then, DOM compositionupdate should be fired
michael@0 182 * from TextComposition automatically.
michael@0 183 ******************************************************************************/
michael@0 184
michael@0 185 class WidgetTextEvent : public WidgetGUIEvent
michael@0 186 {
michael@0 187 private:
michael@0 188 friend class dom::PBrowserParent;
michael@0 189 friend class dom::PBrowserChild;
michael@0 190 friend class plugins::PPluginInstanceChild;
michael@0 191
michael@0 192 WidgetTextEvent()
michael@0 193 : mSeqno(kLatestSeqno)
michael@0 194 , isChar(false)
michael@0 195 {
michael@0 196 }
michael@0 197
michael@0 198 public:
michael@0 199 uint32_t mSeqno;
michael@0 200
michael@0 201 public:
michael@0 202 virtual WidgetTextEvent* AsTextEvent() MOZ_OVERRIDE { return this; }
michael@0 203
michael@0 204 WidgetTextEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget)
michael@0 205 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_TEXT_EVENT)
michael@0 206 , mSeqno(kLatestSeqno)
michael@0 207 , isChar(false)
michael@0 208 {
michael@0 209 }
michael@0 210
michael@0 211 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
michael@0 212 {
michael@0 213 MOZ_ASSERT(eventStructType == NS_TEXT_EVENT,
michael@0 214 "Duplicate() must be overridden by sub class");
michael@0 215 // Not copying widget, it is a weak reference.
michael@0 216 WidgetTextEvent* result = new WidgetTextEvent(false, message, nullptr);
michael@0 217 result->AssignTextEventData(*this, true);
michael@0 218 result->mFlags = mFlags;
michael@0 219 return result;
michael@0 220 }
michael@0 221
michael@0 222 // The composition string or the commit string.
michael@0 223 nsString theText;
michael@0 224 // Indicates whether the event signifies printable text.
michael@0 225 // XXX This is not a standard, and most platforms don't set this properly.
michael@0 226 // So, perhaps, we can get rid of this.
michael@0 227 bool isChar;
michael@0 228
michael@0 229 nsRefPtr<TextRangeArray> mRanges;
michael@0 230
michael@0 231 void AssignTextEventData(const WidgetTextEvent& aEvent, bool aCopyTargets)
michael@0 232 {
michael@0 233 AssignGUIEventData(aEvent, aCopyTargets);
michael@0 234
michael@0 235 isChar = aEvent.isChar;
michael@0 236
michael@0 237 // Currently, we don't need to copy the other members because they are
michael@0 238 // for internal use only (not available from JS).
michael@0 239 }
michael@0 240
michael@0 241 bool IsComposing() const
michael@0 242 {
michael@0 243 return mRanges && mRanges->IsComposing();
michael@0 244 }
michael@0 245
michael@0 246 uint32_t TargetClauseOffset() const
michael@0 247 {
michael@0 248 return mRanges ? mRanges->TargetClauseOffset() : 0;
michael@0 249 }
michael@0 250
michael@0 251 uint32_t RangeCount() const
michael@0 252 {
michael@0 253 return mRanges ? mRanges->Length() : 0;
michael@0 254 }
michael@0 255 };
michael@0 256
michael@0 257 /******************************************************************************
michael@0 258 * mozilla::WidgetCompositionEvent
michael@0 259 ******************************************************************************/
michael@0 260
michael@0 261 class WidgetCompositionEvent : public WidgetGUIEvent
michael@0 262 {
michael@0 263 private:
michael@0 264 friend class mozilla::dom::PBrowserParent;
michael@0 265 friend class mozilla::dom::PBrowserChild;
michael@0 266
michael@0 267 WidgetCompositionEvent()
michael@0 268 : mSeqno(kLatestSeqno)
michael@0 269 {
michael@0 270 }
michael@0 271
michael@0 272 public:
michael@0 273 uint32_t mSeqno;
michael@0 274
michael@0 275 public:
michael@0 276 virtual WidgetCompositionEvent* AsCompositionEvent() MOZ_OVERRIDE
michael@0 277 {
michael@0 278 return this;
michael@0 279 }
michael@0 280
michael@0 281 WidgetCompositionEvent(bool aIsTrusted, uint32_t aMessage,
michael@0 282 nsIWidget* aWidget)
michael@0 283 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_COMPOSITION_EVENT)
michael@0 284 , mSeqno(kLatestSeqno)
michael@0 285 {
michael@0 286 // XXX compositionstart is cancelable in draft of DOM3 Events.
michael@0 287 // However, it doesn't make sense for us, we cannot cancel composition
michael@0 288 // when we send compositionstart event.
michael@0 289 mFlags.mCancelable = false;
michael@0 290 }
michael@0 291
michael@0 292 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
michael@0 293 {
michael@0 294 MOZ_ASSERT(eventStructType == NS_COMPOSITION_EVENT,
michael@0 295 "Duplicate() must be overridden by sub class");
michael@0 296 // Not copying widget, it is a weak reference.
michael@0 297 WidgetCompositionEvent* result =
michael@0 298 new WidgetCompositionEvent(false, message, nullptr);
michael@0 299 result->AssignCompositionEventData(*this, true);
michael@0 300 result->mFlags = mFlags;
michael@0 301 return result;
michael@0 302 }
michael@0 303
michael@0 304 // The composition string or the commit string. If the instance is a
michael@0 305 // compositionstart event, this is initialized with selected text by
michael@0 306 // TextComposition automatically.
michael@0 307 nsString data;
michael@0 308
michael@0 309 void AssignCompositionEventData(const WidgetCompositionEvent& aEvent,
michael@0 310 bool aCopyTargets)
michael@0 311 {
michael@0 312 AssignGUIEventData(aEvent, aCopyTargets);
michael@0 313
michael@0 314 data = aEvent.data;
michael@0 315 }
michael@0 316 };
michael@0 317
michael@0 318 /******************************************************************************
michael@0 319 * mozilla::WidgetQueryContentEvent
michael@0 320 ******************************************************************************/
michael@0 321
michael@0 322 class WidgetQueryContentEvent : public WidgetGUIEvent
michael@0 323 {
michael@0 324 private:
michael@0 325 friend class dom::PBrowserParent;
michael@0 326 friend class dom::PBrowserChild;
michael@0 327
michael@0 328 WidgetQueryContentEvent()
michael@0 329 {
michael@0 330 MOZ_CRASH("WidgetQueryContentEvent is created without proper arguments");
michael@0 331 }
michael@0 332
michael@0 333 public:
michael@0 334 virtual WidgetQueryContentEvent* AsQueryContentEvent() MOZ_OVERRIDE
michael@0 335 {
michael@0 336 return this;
michael@0 337 }
michael@0 338
michael@0 339 WidgetQueryContentEvent(bool aIsTrusted, uint32_t aMessage,
michael@0 340 nsIWidget* aWidget)
michael@0 341 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_QUERY_CONTENT_EVENT)
michael@0 342 , mSucceeded(false)
michael@0 343 , mWasAsync(false)
michael@0 344 , mUseNativeLineBreak(true)
michael@0 345 {
michael@0 346 }
michael@0 347
michael@0 348 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
michael@0 349 {
michael@0 350 // This event isn't an internal event of any DOM event.
michael@0 351 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
michael@0 352 "WidgetQueryContentEvent needs to support Duplicate()");
michael@0 353 MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
michael@0 354 return nullptr;
michael@0 355 }
michael@0 356
michael@0 357 void InitForQueryTextContent(uint32_t aOffset, uint32_t aLength,
michael@0 358 bool aUseNativeLineBreak = true)
michael@0 359 {
michael@0 360 NS_ASSERTION(message == NS_QUERY_TEXT_CONTENT,
michael@0 361 "wrong initializer is called");
michael@0 362 mInput.mOffset = aOffset;
michael@0 363 mInput.mLength = aLength;
michael@0 364 mUseNativeLineBreak = aUseNativeLineBreak;
michael@0 365 }
michael@0 366
michael@0 367 void InitForQueryCaretRect(uint32_t aOffset,
michael@0 368 bool aUseNativeLineBreak = true)
michael@0 369 {
michael@0 370 NS_ASSERTION(message == NS_QUERY_CARET_RECT,
michael@0 371 "wrong initializer is called");
michael@0 372 mInput.mOffset = aOffset;
michael@0 373 mUseNativeLineBreak = aUseNativeLineBreak;
michael@0 374 }
michael@0 375
michael@0 376 void InitForQueryTextRect(uint32_t aOffset, uint32_t aLength,
michael@0 377 bool aUseNativeLineBreak = true)
michael@0 378 {
michael@0 379 NS_ASSERTION(message == NS_QUERY_TEXT_RECT,
michael@0 380 "wrong initializer is called");
michael@0 381 mInput.mOffset = aOffset;
michael@0 382 mInput.mLength = aLength;
michael@0 383 mUseNativeLineBreak = aUseNativeLineBreak;
michael@0 384 }
michael@0 385
michael@0 386 void InitForQueryDOMWidgetHittest(const mozilla::LayoutDeviceIntPoint& aPoint)
michael@0 387 {
michael@0 388 NS_ASSERTION(message == NS_QUERY_DOM_WIDGET_HITTEST,
michael@0 389 "wrong initializer is called");
michael@0 390 refPoint = aPoint;
michael@0 391 }
michael@0 392
michael@0 393 uint32_t GetSelectionStart(void) const
michael@0 394 {
michael@0 395 NS_ASSERTION(message == NS_QUERY_SELECTED_TEXT,
michael@0 396 "not querying selection");
michael@0 397 return mReply.mOffset + (mReply.mReversed ? mReply.mString.Length() : 0);
michael@0 398 }
michael@0 399
michael@0 400 uint32_t GetSelectionEnd(void) const
michael@0 401 {
michael@0 402 NS_ASSERTION(message == NS_QUERY_SELECTED_TEXT,
michael@0 403 "not querying selection");
michael@0 404 return mReply.mOffset + (mReply.mReversed ? 0 : mReply.mString.Length());
michael@0 405 }
michael@0 406
michael@0 407 bool mSucceeded;
michael@0 408 bool mWasAsync;
michael@0 409 bool mUseNativeLineBreak;
michael@0 410 struct
michael@0 411 {
michael@0 412 uint32_t mOffset;
michael@0 413 uint32_t mLength;
michael@0 414 } mInput;
michael@0 415 struct
michael@0 416 {
michael@0 417 void* mContentsRoot;
michael@0 418 uint32_t mOffset;
michael@0 419 nsString mString;
michael@0 420 // Finally, the coordinates is system coordinates.
michael@0 421 nsIntRect mRect;
michael@0 422 // The return widget has the caret. This is set at all query events.
michael@0 423 nsIWidget* mFocusedWidget;
michael@0 424 // true if selection is reversed (end < start)
michael@0 425 bool mReversed;
michael@0 426 // true if the selection exists
michael@0 427 bool mHasSelection;
michael@0 428 // true if DOM element under mouse belongs to widget
michael@0 429 bool mWidgetIsHit;
michael@0 430 // used by NS_QUERY_SELECTION_AS_TRANSFERABLE
michael@0 431 nsCOMPtr<nsITransferable> mTransferable;
michael@0 432 } mReply;
michael@0 433
michael@0 434 enum
michael@0 435 {
michael@0 436 NOT_FOUND = UINT32_MAX
michael@0 437 };
michael@0 438
michael@0 439 // values of mComputedScrollAction
michael@0 440 enum
michael@0 441 {
michael@0 442 SCROLL_ACTION_NONE,
michael@0 443 SCROLL_ACTION_LINE,
michael@0 444 SCROLL_ACTION_PAGE
michael@0 445 };
michael@0 446 };
michael@0 447
michael@0 448 /******************************************************************************
michael@0 449 * mozilla::WidgetSelectionEvent
michael@0 450 ******************************************************************************/
michael@0 451
michael@0 452 class WidgetSelectionEvent : public WidgetGUIEvent
michael@0 453 {
michael@0 454 private:
michael@0 455 friend class mozilla::dom::PBrowserParent;
michael@0 456 friend class mozilla::dom::PBrowserChild;
michael@0 457
michael@0 458 WidgetSelectionEvent()
michael@0 459 : mSeqno(kLatestSeqno)
michael@0 460 , mOffset(0)
michael@0 461 , mLength(0)
michael@0 462 , mReversed(false)
michael@0 463 , mExpandToClusterBoundary(true)
michael@0 464 , mSucceeded(false)
michael@0 465 {
michael@0 466 }
michael@0 467
michael@0 468 public:
michael@0 469 uint32_t mSeqno;
michael@0 470
michael@0 471 public:
michael@0 472 virtual WidgetSelectionEvent* AsSelectionEvent() MOZ_OVERRIDE
michael@0 473 {
michael@0 474 return this;
michael@0 475 }
michael@0 476
michael@0 477 WidgetSelectionEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget)
michael@0 478 : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SELECTION_EVENT)
michael@0 479 , mSeqno(kLatestSeqno)
michael@0 480 , mOffset(0)
michael@0 481 , mLength(0)
michael@0 482 , mReversed(false)
michael@0 483 , mExpandToClusterBoundary(true)
michael@0 484 , mSucceeded(false)
michael@0 485 , mUseNativeLineBreak(true)
michael@0 486 {
michael@0 487 }
michael@0 488
michael@0 489 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
michael@0 490 {
michael@0 491 // This event isn't an internal event of any DOM event.
michael@0 492 NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
michael@0 493 "WidgetSelectionEvent needs to support Duplicate()");
michael@0 494 MOZ_CRASH("WidgetSelectionEvent doesn't support Duplicate()");
michael@0 495 return nullptr;
michael@0 496 }
michael@0 497
michael@0 498 // Start offset of selection
michael@0 499 uint32_t mOffset;
michael@0 500 // Length of selection
michael@0 501 uint32_t mLength;
michael@0 502 // Selection "anchor" should be in front
michael@0 503 bool mReversed;
michael@0 504 // Cluster-based or character-based
michael@0 505 bool mExpandToClusterBoundary;
michael@0 506 // true if setting selection succeeded.
michael@0 507 bool mSucceeded;
michael@0 508 // true if native line breaks are used for mOffset and mLength
michael@0 509 bool mUseNativeLineBreak;
michael@0 510 };
michael@0 511
michael@0 512 /******************************************************************************
michael@0 513 * mozilla::InternalEditorInputEvent
michael@0 514 ******************************************************************************/
michael@0 515
michael@0 516 class InternalEditorInputEvent : public InternalUIEvent
michael@0 517 {
michael@0 518 private:
michael@0 519 InternalEditorInputEvent()
michael@0 520 : mIsComposing(false)
michael@0 521 {
michael@0 522 }
michael@0 523
michael@0 524 public:
michael@0 525 virtual InternalEditorInputEvent* AsEditorInputEvent() MOZ_OVERRIDE
michael@0 526 {
michael@0 527 return this;
michael@0 528 }
michael@0 529
michael@0 530 InternalEditorInputEvent(bool aIsTrusted, uint32_t aMessage,
michael@0 531 nsIWidget* aWidget)
michael@0 532 : InternalUIEvent(aIsTrusted, aMessage, aWidget, NS_EDITOR_INPUT_EVENT)
michael@0 533 , mIsComposing(false)
michael@0 534 {
michael@0 535 if (!aIsTrusted) {
michael@0 536 mFlags.mBubbles = false;
michael@0 537 mFlags.mCancelable = false;
michael@0 538 return;
michael@0 539 }
michael@0 540
michael@0 541 mFlags.mBubbles = true;
michael@0 542 mFlags.mCancelable = false;
michael@0 543 }
michael@0 544
michael@0 545 virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
michael@0 546 {
michael@0 547 MOZ_ASSERT(eventStructType == NS_EDITOR_INPUT_EVENT,
michael@0 548 "Duplicate() must be overridden by sub class");
michael@0 549 // Not copying widget, it is a weak reference.
michael@0 550 InternalEditorInputEvent* result =
michael@0 551 new InternalEditorInputEvent(false, message, nullptr);
michael@0 552 result->AssignEditorInputEventData(*this, true);
michael@0 553 result->mFlags = mFlags;
michael@0 554 return result;
michael@0 555 }
michael@0 556
michael@0 557 bool mIsComposing;
michael@0 558
michael@0 559 void AssignEditorInputEventData(const InternalEditorInputEvent& aEvent,
michael@0 560 bool aCopyTargets)
michael@0 561 {
michael@0 562 AssignUIEventData(aEvent, aCopyTargets);
michael@0 563
michael@0 564 mIsComposing = aEvent.mIsComposing;
michael@0 565 }
michael@0 566 };
michael@0 567
michael@0 568 } // namespace mozilla
michael@0 569
michael@0 570 #endif // mozilla_TextEvents_h__

mercurial