mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
2ddfe368e1
- bug 1215748 - use llvm-dsymutil for mac builds. r=mshal (a217006d89) - warnings (31ea43d0d8) - Bug 1175154 - Unit tests for IAC on 3.0. r=ferjm (12c424bab3) - Bug 1219543 - Part 1: isRunningOnCompositor flag is now a member of AnimationProperty. r=bbirtles (85bc668501) - Bug 1219543 - Part 2: Avoid the period that mIsRunningOnCompositor is false between restyling and building display list. r=bbirtles (597e46d479) - Bug 1219543 - Part 3: MutationObserver should disconnect when the test is finished. r=bbirtles (70c26a266e) - Bug 1214148 - patch 1 - propagation from the nested iframe back to the toplevel iframe, r=alwu (b42002f43a) - Bug 1214148 - patch 2 - from toplevel iframe to the nested iframe, r=alwu (7b07fe5399) - Bug 1214148 - patch 3 - correct window for nested iframes, r=alwu (27ee08caf1) - Bug 1166910 - put referrer attribute behind pref in webidl, r=bz (93e421fa1b) - Bug 1187357 - rename referrer attribute to referrerpolicy. r=hsivonen (70c67f5def) - Bug 1187357 - Generated code for renaming referrer to referrerpolicy in html parser. r=hsivonen (738de3f278) - Bug 1221341. Snap box shadow clip rect to device pixels. r=mstange (b63b783714) - Bug 1228634 - Implement Element.getAttributeNames, r=peterv (4594d9c14c) - Bug 1216193. Implement webkitMatchesSelector. r=khuey (39742b7e0b) - Bug 1134648, handle dynamic changes to rel=dns-prefetch, r=bz (e27638080e) - Bug 1229962 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in parser/html/; r=hsivonen (75de6314f1) - Bug 1226437 - Speculative CSP should set speculative referrer policy instead of actual referrer policy. r=sicking (f7dfd3fd18) - Bug 1227554 - Default to NullPrincipal if doc is not available within expatdriver. r=bz (336a562965) - Bug 1215781 - Use MOZ_UTF16 to generate sTagUnicodeTable. r=mrbkap (eca371a36b) - Bug 1082598 - Part 5: Fix NPAPI for Skia update. r=jrmuizel (25c4d080ab) - Bug 1183828 - Remove 'nsWindow::GetNativeData not implemented for this type' warning. r=roc (0a60404b57) - Bug 1224445 - Add NS_NATIVE_OPENGL_CONTEXT handling to nsWindow::GetNativeData() r=mwu (ee35844be4) - Bug 1179632 part.1 native IME context should not be stored in InputContext but should be able to retrieve with nsIWidget::GetNativeData() r=smaug (5f1804bb72) - Bug 1179632 part.2 WidgetCompositionEvent should store NativeIMEContext which caused the event and PuppetWidget should store it for GetNativeIMEContext() r=smaug, sr=smaug (e00ca78e3f) - Bug 1179632 part.3 TabParent::RecvEndIMEComposition() shouldn't return true with aNoCompositionEvent when there is no widget r=smaug (ee065ed491) - Bug 1179632 part.4 Clean up the code to request IME to commit composition across process boundary r=smaug (9567c4dc57) - Bug 1179632 part.5 WidgetCompositionEvent::mNativeIMEContext should be used at looking for a TextComposition instance for a WidgetCompositionEvent r=smaug (f4e27ec28c) - Bug 1179632 part.6 KeyboardEvent.isComposing shouldn't expose IME state on different document r=smaug (ca8b8a6a02) - Bug 1227544 - Scaling on 720p devices is broken. r=timdream (cb89af839f)
385 lines
12 KiB
C++
385 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* vim: sw=2 ts=8 et :
|
|
*/
|
|
/* 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_ContentCache_h
|
|
#define mozilla_ContentCache_h
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "mozilla/Assertions.h"
|
|
#include "mozilla/CheckedInt.h"
|
|
#include "mozilla/EventForwards.h"
|
|
#include "mozilla/WritingModes.h"
|
|
#include "nsIWidget.h"
|
|
#include "nsString.h"
|
|
#include "nsTArray.h"
|
|
#include "Units.h"
|
|
|
|
namespace mozilla {
|
|
|
|
class ContentCacheInParent;
|
|
|
|
/**
|
|
* ContentCache stores various information of the child content.
|
|
* This class has members which are necessary both in parent process and
|
|
* content process.
|
|
*/
|
|
|
|
class ContentCache
|
|
{
|
|
public:
|
|
typedef InfallibleTArray<LayoutDeviceIntRect> RectArray;
|
|
typedef widget::IMENotification IMENotification;
|
|
|
|
ContentCache();
|
|
|
|
protected:
|
|
// Whole text in the target
|
|
nsString mText;
|
|
|
|
struct Selection final
|
|
{
|
|
// Following values are offset in "flat text".
|
|
uint32_t mAnchor;
|
|
uint32_t mFocus;
|
|
|
|
WritingMode mWritingMode;
|
|
|
|
// Character rects at next character of mAnchor and mFocus.
|
|
LayoutDeviceIntRect mAnchorCharRect;
|
|
LayoutDeviceIntRect mFocusCharRect;
|
|
|
|
// Whole rect of selected text. This is empty if the selection is collapsed.
|
|
LayoutDeviceIntRect mRect;
|
|
|
|
Selection()
|
|
: mAnchor(UINT32_MAX)
|
|
, mFocus(UINT32_MAX)
|
|
{
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
mAnchor = mFocus = UINT32_MAX;
|
|
mWritingMode = WritingMode();
|
|
mAnchorCharRect.SetEmpty();
|
|
mFocusCharRect.SetEmpty();
|
|
mRect.SetEmpty();
|
|
}
|
|
|
|
bool IsValid() const
|
|
{
|
|
return mAnchor != UINT32_MAX && mFocus != UINT32_MAX;
|
|
}
|
|
bool Collapsed() const
|
|
{
|
|
NS_ASSERTION(IsValid(),
|
|
"The caller should check if the selection is valid");
|
|
return mFocus == mAnchor;
|
|
}
|
|
bool Reversed() const
|
|
{
|
|
NS_ASSERTION(IsValid(),
|
|
"The caller should check if the selection is valid");
|
|
return mFocus < mAnchor;
|
|
}
|
|
uint32_t StartOffset() const
|
|
{
|
|
NS_ASSERTION(IsValid(),
|
|
"The caller should check if the selection is valid");
|
|
return Reversed() ? mFocus : mAnchor;
|
|
}
|
|
uint32_t EndOffset() const
|
|
{
|
|
NS_ASSERTION(IsValid(),
|
|
"The caller should check if the selection is valid");
|
|
return Reversed() ? mAnchor : mFocus;
|
|
}
|
|
uint32_t Length() const
|
|
{
|
|
NS_ASSERTION(IsValid(),
|
|
"The caller should check if the selection is valid");
|
|
return Reversed() ? mAnchor - mFocus : mFocus - mAnchor;
|
|
}
|
|
} mSelection;
|
|
|
|
bool IsSelectionValid() const
|
|
{
|
|
return mSelection.IsValid() && mSelection.EndOffset() <= mText.Length();
|
|
}
|
|
|
|
// Stores first char rect because Yosemite's Japanese IME sometimes tries
|
|
// to query it. If there is no text, this is caret rect.
|
|
LayoutDeviceIntRect mFirstCharRect;
|
|
|
|
struct Caret final
|
|
{
|
|
uint32_t mOffset;
|
|
LayoutDeviceIntRect mRect;
|
|
|
|
Caret()
|
|
: mOffset(UINT32_MAX)
|
|
{
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
mOffset = UINT32_MAX;
|
|
mRect.SetEmpty();
|
|
}
|
|
|
|
bool IsValid() const { return mOffset != UINT32_MAX; }
|
|
|
|
uint32_t Offset() const
|
|
{
|
|
NS_ASSERTION(IsValid(),
|
|
"The caller should check if the caret is valid");
|
|
return mOffset;
|
|
}
|
|
} mCaret;
|
|
|
|
struct TextRectArray final
|
|
{
|
|
uint32_t mStart;
|
|
RectArray mRects;
|
|
|
|
TextRectArray()
|
|
: mStart(UINT32_MAX)
|
|
{
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
mStart = UINT32_MAX;
|
|
mRects.Clear();
|
|
}
|
|
|
|
bool IsValid() const
|
|
{
|
|
if (mStart == UINT32_MAX) {
|
|
return false;
|
|
}
|
|
CheckedInt<uint32_t> endOffset =
|
|
CheckedInt<uint32_t>(mStart) + mRects.Length();
|
|
return endOffset.isValid();
|
|
}
|
|
uint32_t StartOffset() const
|
|
{
|
|
NS_ASSERTION(IsValid(),
|
|
"The caller should check if the caret is valid");
|
|
return mStart;
|
|
}
|
|
uint32_t EndOffset() const
|
|
{
|
|
NS_ASSERTION(IsValid(),
|
|
"The caller should check if the caret is valid");
|
|
if (!IsValid()) {
|
|
return UINT32_MAX;
|
|
}
|
|
return mStart + mRects.Length();
|
|
}
|
|
bool InRange(uint32_t aOffset) const
|
|
{
|
|
return IsValid() &&
|
|
StartOffset() <= aOffset && aOffset < EndOffset();
|
|
}
|
|
bool InRange(uint32_t aOffset, uint32_t aLength) const
|
|
{
|
|
CheckedInt<uint32_t> endOffset =
|
|
CheckedInt<uint32_t>(aOffset) + aLength;
|
|
if (NS_WARN_IF(!endOffset.isValid())) {
|
|
return false;
|
|
}
|
|
return InRange(aOffset) && aOffset + aLength <= EndOffset();
|
|
}
|
|
bool IsOverlappingWith(uint32_t aOffset, uint32_t aLength) const
|
|
{
|
|
if (!IsValid() || aOffset == UINT32_MAX) {
|
|
return false;
|
|
}
|
|
CheckedInt<uint32_t> endOffset =
|
|
CheckedInt<uint32_t>(aOffset) + aLength;
|
|
if (NS_WARN_IF(!endOffset.isValid())) {
|
|
return false;
|
|
}
|
|
return aOffset <= EndOffset() && endOffset.value() >= mStart;
|
|
}
|
|
LayoutDeviceIntRect GetRect(uint32_t aOffset) const;
|
|
LayoutDeviceIntRect GetUnionRect(uint32_t aOffset, uint32_t aLength) const;
|
|
LayoutDeviceIntRect GetUnionRectAsFarAsPossible(uint32_t aOffset,
|
|
uint32_t aLength) const;
|
|
} mTextRectArray;
|
|
|
|
LayoutDeviceIntRect mEditorRect;
|
|
|
|
friend class ContentCacheInParent;
|
|
friend struct IPC::ParamTraits<ContentCache>;
|
|
};
|
|
|
|
class ContentCacheInChild final : public ContentCache
|
|
{
|
|
public:
|
|
ContentCacheInChild();
|
|
|
|
/**
|
|
* When IME loses focus, this should be called and making this forget the
|
|
* content for reducing footprint.
|
|
*/
|
|
void Clear();
|
|
|
|
/**
|
|
* Cache*() retrieves the latest content information and store them.
|
|
* Be aware, CacheSelection() calls CacheTextRects(), and also CacheText()
|
|
* calls CacheSelection(). So, related data is also retrieved automatically.
|
|
*/
|
|
bool CacheEditorRect(nsIWidget* aWidget,
|
|
const IMENotification* aNotification = nullptr);
|
|
bool CacheSelection(nsIWidget* aWidget,
|
|
const IMENotification* aNotification = nullptr);
|
|
bool CacheText(nsIWidget* aWidget,
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
bool CacheAll(nsIWidget* aWidget,
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
/**
|
|
* SetSelection() modifies selection with specified raw data. And also this
|
|
* tries to retrieve text rects too.
|
|
*/
|
|
void SetSelection(nsIWidget* aWidget,
|
|
uint32_t aStartOffset,
|
|
uint32_t aLength,
|
|
bool aReversed,
|
|
const WritingMode& aWritingMode);
|
|
|
|
private:
|
|
bool QueryCharRect(nsIWidget* aWidget,
|
|
uint32_t aOffset,
|
|
LayoutDeviceIntRect& aCharRect) const;
|
|
bool CacheCaret(nsIWidget* aWidget,
|
|
const IMENotification* aNotification = nullptr);
|
|
bool CacheTextRects(nsIWidget* aWidget,
|
|
const IMENotification* aNotification = nullptr);
|
|
};
|
|
|
|
class ContentCacheInParent final : public ContentCache
|
|
{
|
|
public:
|
|
ContentCacheInParent();
|
|
|
|
/**
|
|
* AssignContent() is called when TabParent receives ContentCache from
|
|
* the content process. This doesn't copy composition information because
|
|
* it's managed by TabParent itself.
|
|
*/
|
|
void AssignContent(const ContentCache& aOther,
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
/**
|
|
* HandleQueryContentEvent() sets content data to aEvent.mReply.
|
|
*
|
|
* For eQuerySelectedText, fail if the cache doesn't contain the whole
|
|
* selected range. (This shouldn't happen because PuppetWidget should have
|
|
* already sent the whole selection.)
|
|
*
|
|
* For eQueryTextContent, fail only if the cache doesn't overlap with
|
|
* the queried range. Note the difference from above. We use
|
|
* this behavior because a normal eQueryTextContent event is allowed to
|
|
* have out-of-bounds offsets, so that widget can request content without
|
|
* knowing the exact length of text. It's up to widget to handle cases when
|
|
* the returned offset/length are different from the queried offset/length.
|
|
*
|
|
* For eQueryTextRect, fail if cached offset/length aren't equals to input.
|
|
* Cocoa widget always queries selected offset, so it works on it.
|
|
*
|
|
* For eQueryCaretRect, fail if cached offset isn't equals to input
|
|
*
|
|
* For eQueryEditorRect, always success
|
|
*/
|
|
bool HandleQueryContentEvent(WidgetQueryContentEvent& aEvent,
|
|
nsIWidget* aWidget) const;
|
|
|
|
/**
|
|
* OnCompositionEvent() should be called before sending composition string.
|
|
* This returns true if the event should be sent. Otherwise, false.
|
|
*/
|
|
bool OnCompositionEvent(const WidgetCompositionEvent& aCompositionEvent);
|
|
|
|
/**
|
|
* OnSelectionEvent() should be called before sending selection event.
|
|
*/
|
|
void OnSelectionEvent(const WidgetSelectionEvent& aSelectionEvent);
|
|
|
|
/**
|
|
* OnEventNeedingAckHandled() should be called after the child process
|
|
* handles a sent event which needs acknowledging.
|
|
*
|
|
* WARNING: This may send notifications to IME. That might cause destroying
|
|
* TabParent or aWidget. Therefore, the caller must not destroy
|
|
* this instance during a call of this method.
|
|
*/
|
|
void OnEventNeedingAckHandled(nsIWidget* aWidget, EventMessage aMessage);
|
|
|
|
/**
|
|
* RequestIMEToCommitComposition() requests aWidget to commit or cancel
|
|
* composition. If it's handled synchronously, this returns true.
|
|
*
|
|
* @param aWidget The widget to be requested to commit or cancel
|
|
* the composition.
|
|
* @param aCancel When the caller tries to cancel the composition, true.
|
|
* Otherwise, i.e., tries to commit the composition, false.
|
|
* @param aCommittedString The committed string (i.e., the last data of
|
|
* dispatched composition events during requesting
|
|
* IME to commit composition.
|
|
* @return Whether the composition is actually committed
|
|
* synchronously.
|
|
*/
|
|
bool RequestIMEToCommitComposition(nsIWidget* aWidget,
|
|
bool aCancel,
|
|
nsAString& aCommittedString);
|
|
|
|
/**
|
|
* MaybeNotifyIME() may notify IME of the notification. If child process
|
|
* hasn't been handled all sending events yet, this stores the notification
|
|
* and flush it later.
|
|
*/
|
|
void MaybeNotifyIME(nsIWidget* aWidget,
|
|
const IMENotification& aNotification);
|
|
|
|
private:
|
|
IMENotification mPendingSelectionChange;
|
|
IMENotification mPendingTextChange;
|
|
IMENotification mPendingLayoutChange;
|
|
IMENotification mPendingCompositionUpdate;
|
|
|
|
// This is not nullptr only while the instance is requesting IME to
|
|
// composition. Then, data value of dispatched composition events should
|
|
// be stored into the instance.
|
|
nsAString* mCommitStringByRequest;
|
|
// Start offset of the composition string.
|
|
uint32_t mCompositionStart;
|
|
// mPendingEventsNeedingAck is increased before sending a composition event or
|
|
// a selection event and decreased after they are received in the child
|
|
// process.
|
|
uint32_t mPendingEventsNeedingAck;
|
|
|
|
bool mIsComposing;
|
|
|
|
bool GetCaretRect(uint32_t aOffset, LayoutDeviceIntRect& aCaretRect) const;
|
|
bool GetTextRect(uint32_t aOffset,
|
|
LayoutDeviceIntRect& aTextRect) const;
|
|
bool GetUnionTextRects(uint32_t aOffset,
|
|
uint32_t aLength,
|
|
LayoutDeviceIntRect& aUnionTextRect) const;
|
|
|
|
void FlushPendingNotifications(nsIWidget* aWidget);
|
|
};
|
|
|
|
} // namespace mozilla
|
|
|
|
#endif // mozilla_ContentCache_h
|