Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLAreaAccessible.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Author: Aaron Leventhal (aaronl@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsHTMLAreaAccessible.h"
00040 #include "nsIAccessibilityService.h"
00041 #include "nsIServiceManager.h"
00042 #include "nsIDOMElement.h"
00043 #include "nsIDOMHTMLAreaElement.h"
00044 #include "nsIFrame.h"
00045 #include "nsIImageFrame.h"
00046 #include "nsIImageMap.h"
00047 
00048 
00049 // --- area -----
00050 
00051 nsHTMLAreaAccessible::nsHTMLAreaAccessible(nsIDOMNode *aDomNode, nsIAccessible *aParent, nsIWeakReference* aShell):
00052 nsLinkableAccessible(aDomNode, aShell)
00053 { 
00054 }
00055 
00056 /* wstring getName (); */
00057 NS_IMETHODIMP nsHTMLAreaAccessible::GetName(nsAString & aName)
00058 {
00059   nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
00060   if (!content) {
00061     return NS_ERROR_FAILURE;
00062   }
00063 
00064   aName.Truncate();
00065   if (mRoleMapEntry) {
00066     nsresult rv = nsAccessible::GetName(aName);
00067     if (!aName.IsEmpty()) {
00068       return rv;
00069     }
00070   }
00071   if (NS_CONTENT_ATTR_NO_VALUE ==
00072       content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, aName) &&  
00073       NS_CONTENT_ATTR_NO_VALUE ==
00074       content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title, aName)) {
00075     return GetValue(aName);
00076   }
00077 
00078   return NS_OK;
00079 }
00080 
00081 /* unsigned long getRole (); */
00082 NS_IMETHODIMP nsHTMLAreaAccessible::GetRole(PRUint32 *_retval)
00083 {
00084   *_retval = ROLE_LINK;
00085   return NS_OK;
00086 }
00087 
00088 /* wstring getDescription (); */
00089 NS_IMETHODIMP nsHTMLAreaAccessible::GetDescription(nsAString& _retval)
00090 {
00091   // Still to do - follow IE's standard here
00092   nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(mDOMNode));
00093   if (area) 
00094     area->GetShape(_retval);
00095   return NS_OK;
00096 }
00097 
00098 
00099 /* nsIAccessible getFirstChild (); */
00100 NS_IMETHODIMP nsHTMLAreaAccessible::GetFirstChild(nsIAccessible **_retval)
00101 {
00102   *_retval = nsnull;
00103   return NS_OK;
00104 }
00105 
00106 /* nsIAccessible getLastChild (); */
00107 NS_IMETHODIMP nsHTMLAreaAccessible::GetLastChild(nsIAccessible **_retval)
00108 {
00109   *_retval = nsnull;
00110   return NS_OK;
00111 }
00112 
00113 /* long getAccChildCount (); */
00114 NS_IMETHODIMP nsHTMLAreaAccessible::GetChildCount(PRInt32 *_retval)
00115 {
00116   *_retval = 0;
00117   return NS_OK;
00118 }
00119 
00120 /* void accGetBounds (out long x, out long y, out long width, out long height); */
00121 NS_IMETHODIMP nsHTMLAreaAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
00122 {
00123   // Essentially this uses GetRect on mAreas of nsImageMap from nsImageFrame
00124 
00125   *x = *y = *width = *height = 0;
00126 
00127   nsPresContext *presContext = GetPresContext();
00128   NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
00129 
00130   nsCOMPtr<nsIContent> ourContent(do_QueryInterface(mDOMNode));
00131   NS_ENSURE_TRUE(ourContent, NS_ERROR_FAILURE);
00132 
00133   nsIFrame *frame = GetFrame();
00134   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
00135   nsIImageFrame *imageFrame;
00136   nsresult rv = frame->QueryInterface(NS_GET_IID(nsIImageFrame), (void**)&imageFrame);
00137   NS_ENSURE_SUCCESS(rv, rv);
00138 
00139   nsCOMPtr<nsIImageMap> map;
00140   imageFrame->GetImageMap(presContext, getter_AddRefs(map));
00141   NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
00142 
00143   nsRect rect, orgRectPixels, pageRectPixels;
00144   rv = map->GetBoundsForAreaContent(ourContent, presContext, rect);
00145   NS_ENSURE_SUCCESS(rv, rv);
00146 
00147   // Convert from twips to pixels
00148   float t2p;
00149   t2p = presContext->TwipsToPixels();   // Get pixels conversion factor
00150   *x      = NSTwipsToIntPixels(rect.x, t2p); 
00151   *y      = NSTwipsToIntPixels(rect.y, t2p); 
00152 
00153   // XXX aaronl not sure why we have to subtract the x,y from the width, height
00154   //     -- but it works perfectly!
00155   *width  = NSTwipsToIntPixels(rect.width, t2p) - *x;
00156   *height = NSTwipsToIntPixels(rect.height, t2p) - *y;
00157 
00158   // Put coords in absolute screen coords
00159   GetScreenOrigin(presContext, frame, &orgRectPixels);
00160   *x += orgRectPixels.x;
00161   *y += orgRectPixels.y;
00162 
00163   return NS_OK;
00164 }
00165