Files
palemoon27/dom/base/nsQueryContentEventResult.cpp
T
roytam1 43d0e566ce import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1172466 part.1 Make helper classes to notify IME nested classes of IMEContentObserver r=smaug (95efd78dc)
- Bug 1162818 part.1 nsEditor shouldn't release/forget mComposition becuase it should be handled by it after reframing r=ehsan (8adf7d49b)
- Bug 1162818 part.2 Make it possible to set IME selection from outside of IMETextTxn r=ehsan (ea30e4b7b)
- Bug 1162818 part.3 nsEditor should store actual composition string length in it r=ehsan (dd64d5d4e)
- Bug 1162818 part.4 Restore IME selection at initializing selection of the editor r=ehsan (5c3971072)
- Bug 1162818 part.5 The offset of nsEditor::InsertTextImpl() should be minimum offset of IME selections if there is r=ehsan (0ddabbc7b)
- Bug 1162818 part.6 Don't notify IME of anything during reframing the editor r=smaug (63362909f)
- Bug 1162818 part.7 Add test for reframing focused editor when it has composition r=smaug (0e8a59014)
- Bug 1172466 part.2 Use runnable event for notifying IME of focus r=smaug (698bc5257)
- Bug 1172466 part.3 Create an abstruct class which is a base class of classes notifying IME r=smaug (93f543ab7)
- Bug 1172466 part.4 Don't notify IME during reflow r=smaug (873102a98)
- Bug 1175392 part.1 IMEContentObserver and TabParent should use IMEStateManager::NotifyIME() r=smaug (3f13c391f)
- Bug 1175392 part.2 IMEStateManager should manage notifications to IME especially delayed notifications from remote process r=smaug (32f0ab730)
- Bug 1176954 part.1 Child process should notify its parent process when it dispatches composition or selection event into the DOM tree r=smaug (7466055f6)
- Bug 1171810 ContentCache should store union text rect of whole selected text r=m_kato (6d1265a41)
- Bug 1171814 ContentCache should store first character rect because Yosemite's Japanese IME sometimes tries to query it r=m_kato (966fcbca1)
- Bug 1173678 ContentCache should return union rect even if some character rects are not cached but the first character of the range is cached r=m_kato (e979292dd)
- Bug 1177388 Create ContentCacheInParent and ContentCacheInChild for making their purpose clearer r=m_kato (1418b32cc)
- Bug 1176954 part.2 ContentCache in parent process should manage how many events are sent but not yet received r=smaug (0219843ee)
- Bug 1176954 part.3 Don't send selection change, text change nor composition update notification to IME from TabParent until all events sent to the child process is received by it r=smaug (9a5195af7)
- Bug 492394 part.1 NS_QUERY_CHARACTER_AT_POINT should also return tentative caret offset for the point r=smaug, sr=smaug (24fe80f6b)
- Bug 492394 part.2 Implement ITextStoreACP::GetACPFromPoint() r=emk (b0df3db89)
- Bug 1172219 part.1 nsTextStore shouldn't notify IME while events are being dispatched and until they have not been handled yet r=emk (00149b33d)
- Bug 1172219 part.2 Notify TSF of layout creation and destruction r=emk (c2a3bcbbf)
- Bug 1172219 part.3 Modify nsTextStore::mSelection with new selection in OnSelectionChangeInternal() r=emk (47ebf2d2b)
- Bug 1176954 part.4 Define IMENotification::TextChangeDataBase and whose member names should be same as IMEContentObserver::TextChangeData's r=smaug (ea0e0f8a1)
2021-03-01 12:01:50 +08:00

184 lines
4.9 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "nsQueryContentEventResult.h"
#include "nsIWidget.h"
#include "nsPoint.h"
#include "mozilla/TextEvents.h"
using namespace mozilla;
NS_INTERFACE_MAP_BEGIN(nsQueryContentEventResult)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIQueryContentEventResult)
NS_INTERFACE_MAP_ENTRY(nsIQueryContentEventResult)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsQueryContentEventResult)
NS_IMPL_RELEASE(nsQueryContentEventResult)
nsQueryContentEventResult::nsQueryContentEventResult() :
mEventID(0), mSucceeded(false)
{
}
nsQueryContentEventResult::~nsQueryContentEventResult()
{
}
NS_IMETHODIMP
nsQueryContentEventResult::GetOffset(uint32_t *aOffset)
{
bool notFound;
nsresult rv = GetNotFound(&notFound);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(!notFound, NS_ERROR_NOT_AVAILABLE);
*aOffset = mOffset;
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetTentativeCaretOffset(uint32_t* aOffset)
{
bool notFound;
nsresult rv = GetTentativeCaretOffsetNotFound(&notFound);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (NS_WARN_IF(notFound)) {
return NS_ERROR_NOT_AVAILABLE;
}
*aOffset = mTentativeCaretOffset;
return NS_OK;
}
static bool IsRectEnabled(uint32_t aEventID)
{
return aEventID == NS_QUERY_CARET_RECT ||
aEventID == NS_QUERY_TEXT_RECT ||
aEventID == NS_QUERY_EDITOR_RECT ||
aEventID == NS_QUERY_CHARACTER_AT_POINT;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetReversed(bool *aReversed)
{
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(mEventID == NS_QUERY_SELECTED_TEXT,
NS_ERROR_NOT_AVAILABLE);
*aReversed = mReversed;
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetLeft(int32_t *aLeft)
{
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(IsRectEnabled(mEventID),
NS_ERROR_NOT_AVAILABLE);
*aLeft = mRect.x;
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetWidth(int32_t *aWidth)
{
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(IsRectEnabled(mEventID),
NS_ERROR_NOT_AVAILABLE);
*aWidth = mRect.width;
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetTop(int32_t *aTop)
{
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(IsRectEnabled(mEventID),
NS_ERROR_NOT_AVAILABLE);
*aTop = mRect.y;
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetHeight(int32_t *aHeight)
{
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(IsRectEnabled(mEventID),
NS_ERROR_NOT_AVAILABLE);
*aHeight = mRect.height;
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetText(nsAString &aText)
{
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(mEventID == NS_QUERY_SELECTED_TEXT ||
mEventID == NS_QUERY_TEXT_CONTENT,
NS_ERROR_NOT_AVAILABLE);
aText = mString;
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetSucceeded(bool *aSucceeded)
{
NS_ENSURE_TRUE(mEventID != 0, NS_ERROR_NOT_INITIALIZED);
*aSucceeded = mSucceeded;
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetNotFound(bool *aNotFound)
{
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(mEventID == NS_QUERY_SELECTED_TEXT ||
mEventID == NS_QUERY_CHARACTER_AT_POINT,
NS_ERROR_NOT_AVAILABLE);
*aNotFound = (mOffset == WidgetQueryContentEvent::NOT_FOUND);
return NS_OK;
}
NS_IMETHODIMP
nsQueryContentEventResult::GetTentativeCaretOffsetNotFound(bool* aNotFound)
{
if (NS_WARN_IF(!mSucceeded)) {
return NS_ERROR_NOT_AVAILABLE;
}
if (NS_WARN_IF(mEventID != NS_QUERY_CHARACTER_AT_POINT)) {
return NS_ERROR_NOT_AVAILABLE;
}
*aNotFound = (mTentativeCaretOffset == WidgetQueryContentEvent::NOT_FOUND);
return NS_OK;
}
void
nsQueryContentEventResult::SetEventResult(nsIWidget* aWidget,
const WidgetQueryContentEvent &aEvent)
{
mEventID = aEvent.message;
mSucceeded = aEvent.mSucceeded;
mReversed = aEvent.mReply.mReversed;
mRect = aEvent.mReply.mRect;
mOffset = aEvent.mReply.mOffset;
mTentativeCaretOffset = aEvent.mReply.mTentativeCaretOffset;
mString = aEvent.mReply.mString;
if (!IsRectEnabled(mEventID) || !aWidget || !mSucceeded) {
return;
}
nsIWidget* topWidget = aWidget->GetTopLevelWidget();
if (!topWidget || topWidget == aWidget) {
return;
}
// Convert the top widget related coordinates to the given widget's.
LayoutDeviceIntPoint offset =
aWidget->WidgetToScreenOffset() - topWidget->WidgetToScreenOffset();
mRect.MoveBy(-offset);
}