2008-02-20 07:40:04 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Japan.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
2009-02-10 20:56:51 +00:00
|
|
|
* Ningjie Chen <chenn@email.uc.edu>
|
2008-02-20 07:40:04 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2009-02-10 20:56:51 +00:00
|
|
|
#ifndef nsContentEventHandler_h__
|
|
|
|
#define nsContentEventHandler_h__
|
2008-02-20 07:40:04 +00:00
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsISelection.h"
|
2012-01-10 14:19:54 +00:00
|
|
|
#include "nsRange.h"
|
2008-02-20 07:40:04 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMTreeWalker.h"
|
|
|
|
|
|
|
|
class nsPresContext;
|
|
|
|
class nsIPresShell;
|
|
|
|
class nsQueryContentEvent;
|
2009-02-10 20:56:51 +00:00
|
|
|
class nsSelectionEvent;
|
2008-07-16 10:52:01 +00:00
|
|
|
class nsCaret;
|
2008-02-20 07:40:04 +00:00
|
|
|
struct nsRect;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Query Content Event Handler
|
2009-02-10 20:56:51 +00:00
|
|
|
* nsContentEventHandler is a helper class for nsEventStateManager.
|
2008-02-20 07:40:04 +00: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.
|
|
|
|
*/
|
|
|
|
|
2009-02-10 20:56:51 +00:00
|
|
|
class NS_STACK_CLASS nsContentEventHandler {
|
2008-02-20 07:40:04 +00:00
|
|
|
public:
|
2009-02-10 20:56:51 +00:00
|
|
|
nsContentEventHandler(nsPresContext *aPresContext);
|
2008-02-20 07:40:04 +00: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 20:56:51 +00:00
|
|
|
// NS_QUERY_TEXT_RECT event handler
|
|
|
|
nsresult OnQueryTextRect(nsQueryContentEvent* aEvent);
|
|
|
|
// NS_QUERY_EDITOR_RECT event handler
|
|
|
|
nsresult OnQueryEditorRect(nsQueryContentEvent* aEvent);
|
2009-03-18 02:04:01 +00:00
|
|
|
// NS_QUERY_CONTENT_STATE event handler
|
|
|
|
nsresult OnQueryContentState(nsQueryContentEvent* aEvent);
|
|
|
|
// NS_QUERY_SELECTION_AS_TRANSFERABLE event handler
|
|
|
|
nsresult OnQuerySelectionAsTransferable(nsQueryContentEvent* aEvent);
|
2009-05-15 00:46:24 +00:00
|
|
|
// NS_QUERY_CHARACTER_AT_POINT event handler
|
|
|
|
nsresult OnQueryCharacterAtPoint(nsQueryContentEvent* aEvent);
|
2011-03-01 21:15:23 +00:00
|
|
|
// NS_QUERY_DOM_WIDGET_HITTEST event handler
|
|
|
|
nsresult OnQueryDOMWidgetHittest(nsQueryContentEvent* aEvent);
|
2009-02-10 20:56:51 +00:00
|
|
|
|
|
|
|
// NS_SELECTION_* event
|
|
|
|
nsresult OnSelectionEvent(nsSelectionEvent* aEvent);
|
|
|
|
|
2008-02-20 07:40:04 +00:00
|
|
|
protected:
|
|
|
|
nsPresContext* mPresContext;
|
2010-08-05 14:42:02 +00:00
|
|
|
nsCOMPtr<nsIPresShell> mPresShell;
|
2008-02-20 07:40:04 +00:00
|
|
|
nsCOMPtr<nsISelection> mSelection;
|
2012-01-10 14:19:54 +00:00
|
|
|
nsRefPtr<nsRange> mFirstSelectedRange;
|
2008-02-20 07:40:04 +00:00
|
|
|
nsCOMPtr<nsIContent> mRootContent;
|
|
|
|
|
|
|
|
nsresult Init(nsQueryContentEvent* aEvent);
|
2010-03-19 05:02:53 +00:00
|
|
|
nsresult Init(nsSelectionEvent* aEvent);
|
|
|
|
|
|
|
|
// InitCommon() is called from each Init().
|
|
|
|
nsresult InitCommon();
|
2008-02-20 07:40:04 +00:00
|
|
|
|
2009-02-10 20:56:51 +00:00
|
|
|
public:
|
2008-02-20 07:40:04 +00: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 20:56:51 +00:00
|
|
|
// Get the offset in FlatText of the range. (also used by nsIMEStateManager)
|
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
|
|
|
nsINode* aNode,
|
|
|
|
PRInt32 aNodeOffset,
|
|
|
|
PRUint32* aOffset);
|
|
|
|
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
|
2012-01-10 14:19:54 +00:00
|
|
|
nsRange* aRange,
|
2009-02-10 20:56:51 +00:00
|
|
|
PRUint32* aOffset);
|
|
|
|
protected:
|
2008-02-20 07:40:04 +00: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 14:19:54 +00:00
|
|
|
nsresult SetRangeFromFlatTextOffset(nsRange* aRange,
|
2008-02-20 07:40:04 +00:00
|
|
|
PRUint32 aNativeOffset,
|
|
|
|
PRUint32 aNativeLength,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aExpandToClusterBoundaries);
|
2008-02-20 07:40:04 +00:00
|
|
|
// Find the first textframe for the range, and get the start offset in
|
|
|
|
// the frame.
|
2012-01-10 14:19:54 +00:00
|
|
|
nsresult GetStartFrameAndOffset(nsRange* aRange,
|
2009-02-10 20:56:51 +00:00
|
|
|
nsIFrame** aFrame,
|
|
|
|
PRInt32* aOffsetInFrame);
|
2008-02-20 07:40:04 +00:00
|
|
|
// Convert the frame relative offset to the root view relative offset.
|
2009-02-10 20:56:51 +00:00
|
|
|
nsresult ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
|
|
|
|
nsRect& aRect);
|
2008-02-20 07:40:04 +00:00
|
|
|
// Expand aXPOffset to the nearest offset in cluster boundary. aForward is
|
|
|
|
// true, it is expanded to forward.
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult ExpandToClusterBoundary(nsIContent* aContent, bool aForward,
|
2008-02-20 07:40:04 +00:00
|
|
|
PRUint32* aXPOffset);
|
|
|
|
};
|
|
|
|
|
2009-02-10 20:56:51 +00:00
|
|
|
#endif // nsContentEventHandler_h__
|