2008-02-19 23:40:04 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2008-02-19 23:40:04 -08:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
#ifndef nsContentEventHandler_h__
|
|
|
|
#define nsContentEventHandler_h__
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsISelection.h"
|
2012-01-10 06:19:54 -08:00
|
|
|
#include "nsRange.h"
|
2008-02-19 23:40:04 -08:00
|
|
|
#include "nsIDOMTreeWalker.h"
|
|
|
|
|
2013-03-21 17:05:20 -07:00
|
|
|
class nsCaret;
|
|
|
|
class nsIContent;
|
2008-02-19 23:40:04 -08:00
|
|
|
class nsIPresShell;
|
2013-03-21 17:05:20 -07:00
|
|
|
class nsPresContext;
|
2008-02-19 23:40:04 -08:00
|
|
|
class nsQueryContentEvent;
|
2009-02-10 12:56:51 -08:00
|
|
|
class nsSelectionEvent;
|
2013-03-21 17:05:20 -07:00
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
struct nsRect;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Query Content Event Handler
|
2009-02-10 12:56:51 -08:00
|
|
|
* nsContentEventHandler is a helper class for nsEventStateManager.
|
2008-02-19 23:40:04 -08:00
|
|
|
* The platforms request some content informations, e.g., the selected text,
|
|
|
|
* the offset of the selected text and the text for specified range.
|
|
|
|
* This class answers to NS_QUERY_* events from actual contents.
|
|
|
|
*/
|
|
|
|
|
2013-04-11 20:20:09 -07:00
|
|
|
class MOZ_STACK_CLASS nsContentEventHandler {
|
2008-02-19 23:40:04 -08:00
|
|
|
public:
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler(nsPresContext *aPresContext);
|
2008-02-19 23:40:04 -08:00
|
|
|
|
|
|
|
// NS_QUERY_SELECTED_TEXT event handler
|
|
|
|
nsresult OnQuerySelectedText(nsQueryContentEvent* aEvent);
|
|
|
|
// NS_QUERY_TEXT_CONTENT event handler
|
|
|
|
nsresult OnQueryTextContent(nsQueryContentEvent* aEvent);
|
|
|
|
// NS_QUERY_CARET_RECT event handler
|
|
|
|
nsresult OnQueryCaretRect(nsQueryContentEvent* aEvent);
|
2009-02-10 12:56:51 -08:00
|
|
|
// NS_QUERY_TEXT_RECT event handler
|
|
|
|
nsresult OnQueryTextRect(nsQueryContentEvent* aEvent);
|
|
|
|
// NS_QUERY_EDITOR_RECT event handler
|
|
|
|
nsresult OnQueryEditorRect(nsQueryContentEvent* aEvent);
|
2009-03-17 19:04:01 -07:00
|
|
|
// NS_QUERY_CONTENT_STATE event handler
|
|
|
|
nsresult OnQueryContentState(nsQueryContentEvent* aEvent);
|
|
|
|
// NS_QUERY_SELECTION_AS_TRANSFERABLE event handler
|
|
|
|
nsresult OnQuerySelectionAsTransferable(nsQueryContentEvent* aEvent);
|
2009-05-14 17:46:24 -07:00
|
|
|
// NS_QUERY_CHARACTER_AT_POINT event handler
|
|
|
|
nsresult OnQueryCharacterAtPoint(nsQueryContentEvent* aEvent);
|
2011-03-01 13:15:23 -08:00
|
|
|
// NS_QUERY_DOM_WIDGET_HITTEST event handler
|
|
|
|
nsresult OnQueryDOMWidgetHittest(nsQueryContentEvent* aEvent);
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// NS_SELECTION_* event
|
|
|
|
nsresult OnSelectionEvent(nsSelectionEvent* aEvent);
|
|
|
|
|
2008-02-19 23:40:04 -08:00
|
|
|
protected:
|
|
|
|
nsPresContext* mPresContext;
|
2010-08-05 07:42:02 -07:00
|
|
|
nsCOMPtr<nsIPresShell> mPresShell;
|
2008-02-19 23:40:04 -08:00
|
|
|
nsCOMPtr<nsISelection> mSelection;
|
2012-01-10 06:19:54 -08:00
|
|
|
nsRefPtr<nsRange> mFirstSelectedRange;
|
2008-02-19 23:40:04 -08:00
|
|
|
nsCOMPtr<nsIContent> mRootContent;
|
|
|
|
|
|
|
|
nsresult Init(nsQueryContentEvent* aEvent);
|
2010-03-18 22:02:53 -07:00
|
|
|
nsresult Init(nsSelectionEvent* aEvent);
|
|
|
|
|
|
|
|
// InitCommon() is called from each Init().
|
|
|
|
nsresult InitCommon();
|
2008-02-19 23:40:04 -08:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
public:
|
2008-02-19 23:40:04 -08:00
|
|
|
// FlatText means the text that is generated from DOM tree. The BR elements
|
|
|
|
// are replaced to native linefeeds. Other elements are ignored.
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// Get the offset in FlatText of the range. (also used by nsIMEStateManager)
|
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
|
|
|
nsINode* aNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNodeOffset,
|
|
|
|
uint32_t* aOffset);
|
2009-02-10 12:56:51 -08:00
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
2012-01-10 06:19:54 -08:00
|
|
|
nsRange* aRange,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* aOffset);
|
2012-12-05 08:09:56 -08:00
|
|
|
// Get the native text length of a content node excluding any children
|
|
|
|
static uint32_t GetNativeTextLength(nsIContent* aContent,
|
|
|
|
uint32_t aMaxLength = UINT32_MAX);
|
2009-02-10 12:56:51 -08:00
|
|
|
protected:
|
2008-02-19 23:40:04 -08:00
|
|
|
// Make the DOM range from the offset of FlatText and the text length.
|
|
|
|
// If aExpandToClusterBoundaries is true, the start offset and the end one are
|
|
|
|
// expanded to nearest cluster boundaries.
|
2012-01-10 06:19:54 -08:00
|
|
|
nsresult SetRangeFromFlatTextOffset(nsRange* aRange,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aNativeOffset,
|
|
|
|
uint32_t aNativeLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aExpandToClusterBoundaries);
|
2008-02-19 23:40:04 -08:00
|
|
|
// Find the first textframe for the range, and get the start offset in
|
|
|
|
// the frame.
|
2012-01-10 06:19:54 -08:00
|
|
|
nsresult GetStartFrameAndOffset(nsRange* aRange,
|
2009-02-10 12:56:51 -08:00
|
|
|
nsIFrame** aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aOffsetInFrame);
|
2008-02-19 23:40:04 -08:00
|
|
|
// Convert the frame relative offset to the root view relative offset.
|
2009-02-10 12:56:51 -08:00
|
|
|
nsresult ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
|
|
|
|
nsRect& aRect);
|
2008-02-19 23:40:04 -08:00
|
|
|
// Expand aXPOffset to the nearest offset in cluster boundary. aForward is
|
|
|
|
// true, it is expanded to forward.
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult ExpandToClusterBoundary(nsIContent* aContent, bool aForward,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* aXPOffset);
|
2008-02-19 23:40:04 -08:00
|
|
|
};
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
#endif // nsContentEventHandler_h__
|