LCOV - app.info - dom/base/nsQueryContentEventResult.cpp

LCOV - code coverage report
| Current view: | directory - dom/base - nsQueryContentEventResult.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 72 | 0 | 0.0 %
| Date: | 2012-04-21 | Functions: | 16 | 0 | 0.0 %

           1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is mozilla.org code.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is
          18                 :  * Mozilla Japan.
          19                 :  * Portions created by the Initial Developer are Copyright (C) 2009
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *   Masayuki Nakano <masayuki@d-toybox.com>
          24                 :  *
          25                 :  * Alternatively, the contents of this file may be used under the terms of
          26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
          27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          29                 :  * of those above. If you wish to allow use of your version of this file only
          30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          31                 :  * use your version of this file under the terms of the MPL, indicate your
          32                 :  * decision by deleting the provisions above and replace them with the notice
          33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          34                 :  * the provisions above, a recipient may use your version of this file under
          35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          36                 :  *
          37                 :  * ***** END LICENSE BLOCK ***** */
          38                 :
          39                 : #include "nsQueryContentEventResult.h"
          40                 : #include "nsGUIEvent.h"
          41                 : #include "nsIWidget.h"
          42                 : #include "nsPoint.h"
          43                 :
          44               0 : NS_INTERFACE_MAP_BEGIN(nsQueryContentEventResult)
          45               0 :   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIQueryContentEventResult)
          46               0 :   NS_INTERFACE_MAP_ENTRY(nsIQueryContentEventResult)
          47               0 : NS_INTERFACE_MAP_END
          48                 :
          49               0 : NS_IMPL_ADDREF(nsQueryContentEventResult)
          50               0 : NS_IMPL_RELEASE(nsQueryContentEventResult)
          51                 :
          52               0 : nsQueryContentEventResult::nsQueryContentEventResult() :
          53               0 :   mEventID(0), mSucceeded(false)
          54                 : {
          55               0 : }
          56                 :
          57               0 : nsQueryContentEventResult::~nsQueryContentEventResult()
          58                 : {
          59               0 : }
          60                 :
          61                 : NS_IMETHODIMP
          62               0 : nsQueryContentEventResult::GetOffset(PRUint32 *aOffset)
          63                 : {
          64                 :   bool notFound;
          65               0 :   nsresult rv = GetNotFound(&notFound);
          66               0 :   NS_ENSURE_SUCCESS(rv, rv);
          67               0 :   NS_ENSURE_TRUE(!notFound, NS_ERROR_NOT_AVAILABLE);
          68               0 :   *aOffset = mOffset;
          69               0 :   return NS_OK;
          70                 : }
          71                 :
          72               0 : static bool IsRectEnabled(PRUint32 aEventID)
          73                 : {
          74                 :   return aEventID == NS_QUERY_CARET_RECT ||
          75                 :          aEventID == NS_QUERY_TEXT_RECT ||
          76                 :          aEventID == NS_QUERY_EDITOR_RECT ||
          77               0 :          aEventID == NS_QUERY_CHARACTER_AT_POINT;
          78                 : }
          79                 :
          80                 : NS_IMETHODIMP
          81               0 : nsQueryContentEventResult::GetReversed(bool *aReversed)
          82                 : {
          83               0 :   NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
          84               0 :   NS_ENSURE_TRUE(mEventID == NS_QUERY_SELECTED_TEXT,
          85                 :                  NS_ERROR_NOT_AVAILABLE);
          86               0 :   *aReversed = mReversed;
          87               0 :   return NS_OK;
          88                 : }
          89                 :
          90                 : NS_IMETHODIMP
          91               0 : nsQueryContentEventResult::GetLeft(PRInt32 *aLeft)
          92                 : {
          93               0 :   NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
          94               0 :   NS_ENSURE_TRUE(IsRectEnabled(mEventID),
          95                 :                  NS_ERROR_NOT_AVAILABLE);
          96               0 :   *aLeft = mRect.x;
          97               0 :   return NS_OK;
          98                 : }
          99                 :
         100                 : NS_IMETHODIMP
         101               0 : nsQueryContentEventResult::GetWidth(PRInt32 *aWidth)
         102                 : {
         103               0 :   NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
         104               0 :   NS_ENSURE_TRUE(IsRectEnabled(mEventID),
         105                 :                  NS_ERROR_NOT_AVAILABLE);
         106               0 :   *aWidth = mRect.width;
         107               0 :   return NS_OK;
         108                 : }
         109                 :
         110                 : NS_IMETHODIMP
         111               0 : nsQueryContentEventResult::GetTop(PRInt32 *aTop)
         112                 : {
         113               0 :   NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
         114               0 :   NS_ENSURE_TRUE(IsRectEnabled(mEventID),
         115                 :                  NS_ERROR_NOT_AVAILABLE);
         116               0 :   *aTop = mRect.y;
         117               0 :   return NS_OK;
         118                 : }
         119                 :
         120                 : NS_IMETHODIMP
         121               0 : nsQueryContentEventResult::GetHeight(PRInt32 *aHeight)
         122                 : {
         123               0 :   NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
         124               0 :   NS_ENSURE_TRUE(IsRectEnabled(mEventID),
         125                 :                  NS_ERROR_NOT_AVAILABLE);
         126               0 :   *aHeight = mRect.height;
         127               0 :   return NS_OK;
         128                 : }
         129                 :
         130                 : NS_IMETHODIMP
         131               0 : nsQueryContentEventResult::GetText(nsAString &aText)
         132                 : {
         133               0 :   NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
         134               0 :   NS_ENSURE_TRUE(mEventID == NS_QUERY_SELECTED_TEXT ||
         135                 :                  mEventID == NS_QUERY_TEXT_CONTENT,
         136                 :                  NS_ERROR_NOT_AVAILABLE);
         137               0 :   aText = mString;
         138               0 :   return NS_OK;
         139                 : }
         140                 :
         141                 : NS_IMETHODIMP
         142               0 : nsQueryContentEventResult::GetSucceeded(bool *aSucceeded)
         143                 : {
         144               0 :   NS_ENSURE_TRUE(mEventID != 0, NS_ERROR_NOT_INITIALIZED);
         145               0 :   *aSucceeded = mSucceeded;
         146               0 :   return NS_OK;
         147                 : }
         148                 :
         149                 : NS_IMETHODIMP
         150               0 : nsQueryContentEventResult::GetNotFound(bool *aNotFound)
         151                 : {
         152               0 :   NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
         153               0 :   NS_ENSURE_TRUE(mEventID == NS_QUERY_SELECTED_TEXT ||
         154                 :                  mEventID == NS_QUERY_CHARACTER_AT_POINT,
         155                 :                  NS_ERROR_NOT_AVAILABLE);
         156               0 :   *aNotFound = (mOffset == nsQueryContentEvent::NOT_FOUND);
         157               0 :   return NS_OK;
         158                 : }
         159                 :
         160                 : void
         161               0 : nsQueryContentEventResult::SetEventResult(nsIWidget* aWidget,
         162                 :                                           const nsQueryContentEvent &aEvent)
         163                 : {
         164               0 :   mEventID = aEvent.message;
         165               0 :   mSucceeded = aEvent.mSucceeded;
         166               0 :   mReversed = aEvent.mReply.mReversed;
         167               0 :   mRect = aEvent.mReply.mRect;
         168               0 :   mOffset = aEvent.mReply.mOffset;
         169               0 :   mString = aEvent.mReply.mString;
         170                 :
         171               0 :   if (!IsRectEnabled(mEventID) || !aWidget || !mSucceeded) {
         172               0 :     return;
         173                 :   }
         174                 :
         175               0 :   nsIWidget* topWidget = aWidget->GetTopLevelWidget();
         176               0 :   if (!topWidget || topWidget == aWidget) {
         177               0 :     return;
         178                 :   }
         179                 :
         180                 :   // Convert the top widget related coordinates to the given widget's.
         181                 :   nsIntPoint offset =
         182               0 :     aWidget->WidgetToScreenOffset() - topWidget->WidgetToScreenOffset();
         183               0 :   mRect.MoveBy(-offset);
         184                 : }

Generated by: LCOV version 1.7