mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
866ef525d9
- Bug 895274 part.155 Rename NS_QUERY_EDITOR_RECT to eQueryEditorRect r=smaug (74e932536f) - Bug 895274 part.156 Rename NS_QUERY_CONTENT_STATE to eQueryContentState r=smaug (f4a51e204a) - Bug 895274 part.157 Rename NS_QUERY_CHARACTER_AT_POINT to eQueryCharacterAtPoint r=smaug (6d9e90ad3b) - Bug 895274 part.158 Rename NS_QUERY_DOM_WIDGET_HITTEST to eQueryDOMWidgetHittest r=smaug (6f2a3f4254) - Bug 895274 part.140 Rename NS_VOLUMECHANGE to eVolumeChange r=smaug (874a0753c3) - Bug 895274 part.159 Rename NS_NOTIFYPAINT_START to ePaintEventFirst r=smaug (f736154b47) - Bug 895274 part.160 Rename NS_AFTERPAINT to eAfterPaint r=smaug (5de66bb8be) - Bug 895274 part.161 Rename NS_CONTENT_COMMAND_EVENT_START to eContentCommandEventFirst r=smaug (c7e8a02019) - Bug 895274 part.162 Rename NS_CONTENT_COMMAND_PASTE_TRANSFERABLE to eContentCommandPasteTransferable r=smaug (18fa878452) - Bug 895274 part.163 Rename NS_CONTENT_COMMAND_CUT to eContentCommandCut r=smaug (1c3f6b8edc) - Bug 895274 part.164 Rename NS_CONTENT_COMMAND_COPY to eContentCommandCopy r=smaug (81f0bb72b9) - Bug 895274 part.165 Rename NS_CONTENT_COMMAND_PASTE to eContentCommandPaste r=smaug (689c779c5c) - Bug 895274 part.166 Rename NS_CONTENT_COMMAND_DELETE to eContentCommandDelete r=smaug (39e08c0e83) - Bug 895274 part.167 Rename NS_CONTENT_COMMAND_UNDO to eContentCommandUndo r=smaug (8e7deef845) - Bug 895274 part.168 Rename NS_CONTENT_COMMAND_REDO to eContentCommandRedo r=smaug (1fe84ff23b) - Bug 895274 part.169 Rename NS_CONTENT_COMMAND_SCROLL to eContentCommandScroll r=smaug (c33ee94df0) - Bug 895274 part.171 Rename NS_ANIMATION_START to eAnimationStart r=smaug (17d52b1a77) - Bug 895274 part.172 Rename NS_ANIMATION_END to eAnimationEnd r=smaug (4ebb43e533) - Bug 895274 part.173 Rename NS_ANIMATION_ITERATION to eAnimationIteration r=smaug (1e62da736c) - Bug 895274 part.174 Rename NS_NOTIFYSCRIPT_START to eScriptEventFirst r=smaug (ef80d7b39a) - Bug 895274 part.175 Rename NS_BEFORE_SCRIPT_EXECUTE to eBeforeScriptExecute r=smaug (e29384af8d) - Bug 895274 part.176 Rename NS_AFTER_SCRIPT_EXECUTE to eAfterScriptExecute r=smaug (4a06741336) - Bug 895274 part.177 Rename NS_OPENCLOSE_EVENT_START to eOpenCloseEventFirst r=smaug (cd7f0cc550) - Bug 895274 part.178 Rename NS_OPEN to eOpen r=smaug (11380035a7) - Bug 895274 part.179 Remove NS_CLOSE due to unused r=smaug (a07e7b30dd) - Bug 895274 part.180 Rename NS_FULL_SCREEN_EVENT_START to eFullscreenEventFirst r=smaug (a934ba9c99) - Bug 895274 part.181 Rename NS_FULLSCREENCHANGE to eFullscreenChange r=smaug (b4ea2761a0) - Bug 895274 part.182 Rename NS_FULLSCREENERROR to eFullscreenError r=smaug (910a1d77af) - Bug 895274 part.183 Rename NS_WHEEL_EVENT_START to eWheelEventFirst r=smaug (b7277d4c57) - Bug 1171029 - Only omit legacy scroll events on GTK3. r=karlt (03eaad6c98)
184 lines
5.0 KiB
C++
184 lines
5.0 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()
|
|
: mEventMessage(eVoidEvent)
|
|
, mSucceeded(false)
|
|
{
|
|
}
|
|
|
|
nsQueryContentEventResult::~nsQueryContentEventResult()
|
|
{
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsQueryContentEventResult::GetOffset(uint32_t *aOffset)
|
|
{
|
|
bool notFound;
|
|
nsresult rv = GetNotFound(¬Found);
|
|
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(¬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;
|
|
}
|
|
|
|
static bool IsRectEnabled(EventMessage aEventMessage)
|
|
{
|
|
return aEventMessage == eQueryCaretRect ||
|
|
aEventMessage == NS_QUERY_TEXT_RECT ||
|
|
aEventMessage == eQueryEditorRect ||
|
|
aEventMessage == eQueryCharacterAtPoint;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsQueryContentEventResult::GetReversed(bool *aReversed)
|
|
{
|
|
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
|
NS_ENSURE_TRUE(mEventMessage == eQuerySelectedText, 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(mEventMessage),
|
|
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(mEventMessage),
|
|
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(mEventMessage),
|
|
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(mEventMessage),
|
|
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(mEventMessage == eQuerySelectedText ||
|
|
mEventMessage == eQueryTextContent,
|
|
NS_ERROR_NOT_AVAILABLE);
|
|
aText = mString;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsQueryContentEventResult::GetSucceeded(bool *aSucceeded)
|
|
{
|
|
NS_ENSURE_TRUE(mEventMessage != eVoidEvent, 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(mEventMessage == eQuerySelectedText ||
|
|
mEventMessage == eQueryCharacterAtPoint,
|
|
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(mEventMessage != eQueryCharacterAtPoint)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
*aNotFound = (mTentativeCaretOffset == WidgetQueryContentEvent::NOT_FOUND);
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsQueryContentEventResult::SetEventResult(nsIWidget* aWidget,
|
|
const WidgetQueryContentEvent &aEvent)
|
|
{
|
|
mEventMessage = aEvent.mMessage;
|
|
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(mEventMessage) || !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);
|
|
}
|