Bug 1077515 - part 4 - Add writing-mode to the reply to the NS_QUERY_SELECTED_TEXT event. r=roc

This commit is contained in:
Jonathan Kew 2014-11-22 14:39:03 +00:00
parent 8faf68508f
commit d0f9e25a27
2 changed files with 28 additions and 17 deletions

View File

@ -604,6 +604,23 @@ ContentEventHandler::GetLineBreakType(bool aUseNativeLineBreak)
LINE_BREAK_TYPE_NATIVE : LINE_BREAK_TYPE_XP;
}
// Similar to nsFrameSelection::GetFrameForNodeOffset,
// but this is more flexible for OnQueryTextRect to use
static nsresult GetFrameForTextRect(nsINode* aNode,
int32_t aNodeOffset,
bool aHint,
nsIFrame** aReturnFrame)
{
NS_ENSURE_TRUE(aNode && aNode->IsNodeOfType(nsINode::eCONTENT),
NS_ERROR_UNEXPECTED);
nsIContent* content = static_cast<nsIContent*>(aNode);
nsIFrame* frame = content->GetPrimaryFrame();
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
int32_t childNodeOffset = 0;
return frame->GetChildFrameContainingOffset(aNodeOffset, aHint,
&childNodeOffset, aReturnFrame);
}
nsresult
ContentEventHandler::OnQuerySelectedText(WidgetQueryContentEvent* aEvent)
{
@ -646,6 +663,14 @@ ContentEventHandler::OnQuerySelectedText(WidgetQueryContentEvent* aEvent)
NS_ENSURE_SUCCESS(rv, rv);
}
nsIFrame* frame = nullptr;
rv = GetFrameForTextRect(focusNode, focusOffset, true, &frame);
if (NS_SUCCEEDED(rv) && frame) {
aEvent->mReply.mWritingMode = frame->GetWritingMode();
} else {
aEvent->mReply.mWritingMode = WritingMode();
}
aEvent->mSucceeded = true;
return NS_OK;
}
@ -697,23 +722,6 @@ static nsINode* AdjustTextRectNode(nsINode* aNode,
return node;
}
// Similar to nsFrameSelection::GetFrameForNodeOffset,
// but this is more flexible for OnQueryTextRect to use
static nsresult GetFrameForTextRect(nsINode* aNode,
int32_t aNodeOffset,
bool aHint,
nsIFrame** aReturnFrame)
{
NS_ENSURE_TRUE(aNode && aNode->IsNodeOfType(nsINode::eCONTENT),
NS_ERROR_UNEXPECTED);
nsIContent* content = static_cast<nsIContent*>(aNode);
nsIFrame* frame = content->GetPrimaryFrame();
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
int32_t childNodeOffset = 0;
return frame->GetChildFrameContainingOffset(aNodeOffset, aHint,
&childNodeOffset, aReturnFrame);
}
nsresult
ContentEventHandler::OnQueryTextRect(WidgetQueryContentEvent* aEvent)
{

View File

@ -18,6 +18,7 @@
#include "nsRect.h"
#include "nsStringGlue.h"
#include "nsTArray.h"
#include "WritingModes.h"
/******************************************************************************
* virtual keycode values
@ -455,6 +456,8 @@ public:
bool mHasSelection;
// true if DOM element under mouse belongs to widget
bool mWidgetIsHit;
// mozilla::WritingMode value at the end (focus) of the selection
mozilla::WritingMode mWritingMode;
// used by NS_QUERY_SELECTION_AS_TRANSFERABLE
nsCOMPtr<nsITransferable> mTransferable;
} mReply;