2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-03-19 08:02:53 +03:00
|
|
|
|
|
|
|
#include "nsQueryContentEventResult.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsPoint.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2010-03-19 08:02:53 +03:00
|
|
|
|
2013-10-01 11:23:00 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-03-19 08:02:53 +03:00
|
|
|
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)
|
|
|
|
|
2015-09-10 04:40:05 +03:00
|
|
|
nsQueryContentEventResult::nsQueryContentEventResult()
|
|
|
|
: mEventMessage(eVoidEvent)
|
|
|
|
, mSucceeded(false)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsQueryContentEventResult::~nsQueryContentEventResult()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsQueryContentEventResult::GetOffset(uint32_t *aOffset)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool notFound;
|
2010-03-19 08:02:53 +03:00
|
|
|
nsresult rv = GetNotFound(¬Found);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(!notFound, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
*aOffset = mOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-14 08:27:37 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsQueryContentEventResult::GetTentativeCaretOffset(uint32_t* aOffset)
|
|
|
|
{
|
|
|
|
bool notFound;
|
|
|
|
nsresult rv = GetTentativeCaretOffsetNotFound(¬Found);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(notFound)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
*aOffset = mTentativeCaretOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-10 04:40:05 +03:00
|
|
|
static bool IsRectEnabled(EventMessage aEventMessage)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
2015-09-10 04:40:06 +03:00
|
|
|
return aEventMessage == eQueryCaretRect ||
|
2015-09-11 15:21:26 +03:00
|
|
|
aEventMessage == eQueryTextRect ||
|
2015-09-10 04:40:06 +03:00
|
|
|
aEventMessage == eQueryEditorRect ||
|
2015-09-10 04:40:06 +03:00
|
|
|
aEventMessage == eQueryCharacterAtPoint;
|
2010-03-19 08:02:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsQueryContentEventResult::GetReversed(bool *aReversed)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
2015-09-10 04:40:05 +03:00
|
|
|
NS_ENSURE_TRUE(mEventMessage == eQuerySelectedText, NS_ERROR_NOT_AVAILABLE);
|
2010-03-19 08:02:53 +03:00
|
|
|
*aReversed = mReversed;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsQueryContentEventResult::GetLeft(int32_t *aLeft)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
2015-09-10 04:40:05 +03:00
|
|
|
NS_ENSURE_TRUE(IsRectEnabled(mEventMessage),
|
2010-03-19 08:02:53 +03:00
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
|
|
|
*aLeft = mRect.x;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsQueryContentEventResult::GetWidth(int32_t *aWidth)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
2015-09-10 04:40:05 +03:00
|
|
|
NS_ENSURE_TRUE(IsRectEnabled(mEventMessage),
|
2010-03-19 08:02:53 +03:00
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
|
|
|
*aWidth = mRect.width;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsQueryContentEventResult::GetTop(int32_t *aTop)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
2015-09-10 04:40:05 +03:00
|
|
|
NS_ENSURE_TRUE(IsRectEnabled(mEventMessage),
|
2010-03-19 08:02:53 +03:00
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
|
|
|
*aTop = mRect.y;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsQueryContentEventResult::GetHeight(int32_t *aHeight)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
2015-09-10 04:40:05 +03:00
|
|
|
NS_ENSURE_TRUE(IsRectEnabled(mEventMessage),
|
2010-03-19 08:02:53 +03:00
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
|
|
|
*aHeight = mRect.height;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsQueryContentEventResult::GetText(nsAString &aText)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
2015-09-10 04:40:05 +03:00
|
|
|
NS_ENSURE_TRUE(mEventMessage == eQuerySelectedText ||
|
2015-09-10 04:40:05 +03:00
|
|
|
mEventMessage == eQueryTextContent,
|
2010-03-19 08:02:53 +03:00
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
|
|
|
aText = mString;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsQueryContentEventResult::GetSucceeded(bool *aSucceeded)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
2015-09-10 04:40:05 +03:00
|
|
|
NS_ENSURE_TRUE(mEventMessage != eVoidEvent, NS_ERROR_NOT_INITIALIZED);
|
2010-03-19 08:02:53 +03:00
|
|
|
*aSucceeded = mSucceeded;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsQueryContentEventResult::GetNotFound(bool *aNotFound)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
2015-09-10 04:40:05 +03:00
|
|
|
NS_ENSURE_TRUE(mEventMessage == eQuerySelectedText ||
|
2015-09-10 04:40:06 +03:00
|
|
|
mEventMessage == eQueryCharacterAtPoint,
|
2010-03-19 08:02:53 +03:00
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
2013-10-01 11:23:00 +04:00
|
|
|
*aNotFound = (mOffset == WidgetQueryContentEvent::NOT_FOUND);
|
2010-03-19 08:02:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-14 08:27:37 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsQueryContentEventResult::GetTentativeCaretOffsetNotFound(bool* aNotFound)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!mSucceeded)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2015-09-10 04:40:06 +03:00
|
|
|
if (NS_WARN_IF(mEventMessage != eQueryCharacterAtPoint)) {
|
2015-04-14 08:27:37 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
*aNotFound = (mTentativeCaretOffset == WidgetQueryContentEvent::NOT_FOUND);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-19 08:02:53 +03:00
|
|
|
void
|
|
|
|
nsQueryContentEventResult::SetEventResult(nsIWidget* aWidget,
|
2013-10-01 11:23:00 +04:00
|
|
|
const WidgetQueryContentEvent &aEvent)
|
2010-03-19 08:02:53 +03:00
|
|
|
{
|
2015-09-10 04:40:05 +03:00
|
|
|
mEventMessage = aEvent.mMessage;
|
2010-03-19 08:02:53 +03:00
|
|
|
mSucceeded = aEvent.mSucceeded;
|
|
|
|
mReversed = aEvent.mReply.mReversed;
|
|
|
|
mRect = aEvent.mReply.mRect;
|
|
|
|
mOffset = aEvent.mReply.mOffset;
|
2015-04-14 08:27:37 +03:00
|
|
|
mTentativeCaretOffset = aEvent.mReply.mTentativeCaretOffset;
|
2010-03-19 08:02:53 +03:00
|
|
|
mString = aEvent.mReply.mString;
|
|
|
|
|
2015-09-10 04:40:05 +03:00
|
|
|
if (!IsRectEnabled(mEventMessage) || !aWidget || !mSucceeded) {
|
2010-03-19 08:02:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget* topWidget = aWidget->GetTopLevelWidget();
|
|
|
|
if (!topWidget || topWidget == aWidget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the top widget related coordinates to the given widget's.
|
2015-02-04 23:21:03 +03:00
|
|
|
LayoutDeviceIntPoint offset =
|
2010-03-19 08:02:53 +03:00
|
|
|
aWidget->WidgetToScreenOffset() - topWidget->WidgetToScreenOffset();
|
2015-02-04 23:21:03 +03:00
|
|
|
mRect.MoveBy(-offset);
|
2010-03-19 08:02:53 +03:00
|
|
|
}
|