Back to index

lightning-sunbird  0.9+nobinonly
nsMaiInterfaceComponent.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 /* ***** BEGIN LICENSE BLOCK *****
00005  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  *
00008  * The contents of this file are subject to the Mozilla Public
00009  * License Version 1.1 (the "License"); you may not use this file
00010  * except in compliance with the License. You may obtain a copy of
00011  * the License at http://www.mozilla.org/MPL/
00012  *
00013  * Software distributed under the License is distributed on an "AS
00014  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00015  * implied. See the License for the specific language governing
00016  * rights and limitations under the License.
00017  *
00018  * The Original Code is mozilla.org code.
00019  *
00020  * The Initial Developer of the Original Code is Sun Microsystems, Inc.
00021  * Portions created by Sun Microsystems are Copyright (C) 2002 Sun
00022  * Microsystems, Inc. All Rights Reserved.
00023  *
00024  * Original Author: Bolian Yin (bolian.yin@sun.com)
00025  *
00026  * Contributor(s):
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the NPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the NPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 #include "nsMaiInterfaceComponent.h"
00043 #include "nsAccessibleWrap.h"
00044 
00045 G_BEGIN_DECLS
00046 
00047 /* component interface callbacks */
00048 static void interfaceInitCB(AtkComponentIface *aIface);
00049 static AtkObject *refAccessibleAtPointCB(AtkComponent *aComponent,
00050                                          gint aAccX, gint aAccY,
00051                                          AtkCoordType aCoordType);
00052 static void getExtentsCB(AtkComponent *aComponent,
00053                          gint *aAccX, gint *aAccY,
00054                          gint *aAccWidth, gint *aAccHeight,
00055                          AtkCoordType aCoordType);
00056 /* the "contains", "get_position", "get_size" can take advantage of
00057  * "get_extents", there is no need to implement them now.
00058  */
00059 static gboolean grabFocusCB(AtkComponent *aComponent);
00060 
00061 /* what are missing now for atk component */
00062 
00063 /* ==================================================
00064  * add_focus_handler
00065  * remove_focus_handler
00066  * set_extents
00067  * set_position
00068  * set_size
00069  * get_layer
00070  * get_mdi_zorder
00071  * ==================================================
00072  */
00073 G_END_DECLS
00074 
00075 MaiInterfaceComponent::MaiInterfaceComponent(nsAccessibleWrap *aAccWrap):
00076     MaiInterface(aAccWrap)
00077 {
00078 }
00079 
00080 MaiInterfaceComponent::~MaiInterfaceComponent()
00081 {
00082 }
00083 
00084 MaiInterfaceType
00085 MaiInterfaceComponent::GetType()
00086 {
00087     return MAI_INTERFACE_COMPONENT;
00088 }
00089 
00090 const GInterfaceInfo *
00091 MaiInterfaceComponent::GetInterfaceInfo()
00092 {
00093     static const GInterfaceInfo atk_if_component_info = {
00094         (GInterfaceInitFunc)interfaceInitCB,
00095         (GInterfaceFinalizeFunc) NULL,
00096         NULL
00097     };
00098     return &atk_if_component_info;
00099 }
00100 
00101 /* static functions */
00102 
00103 void
00104 interfaceInitCB(AtkComponentIface *aIface)
00105 {
00106     NS_ASSERTION(aIface, "Invalid Interface");
00107     if(!aIface)
00108         return;
00109 
00110     /*
00111      * Use default implementation in atk for contains, get_position,
00112      * and get_size
00113      */
00114     aIface->ref_accessible_at_point = refAccessibleAtPointCB;
00115     aIface->get_extents = getExtentsCB;
00116     aIface->grab_focus = grabFocusCB;
00117 }
00118 
00119 AtkObject *
00120 refAccessibleAtPointCB(AtkComponent *aComponent,
00121                        gint aAccX, gint aAccY,
00122                        AtkCoordType aCoordType)
00123 {
00124     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
00125     NS_ENSURE_TRUE(accWrap, nsnull);
00126 
00127     // or ATK_XY_SCREEN  what is definition this in nsIAccessible ???
00128     if (aCoordType == ATK_XY_WINDOW) {
00129         /* deal with the coord type */
00130     }
00131 
00132     nsCOMPtr<nsIAccessible> pointAcc;
00133     nsresult rv = accWrap->GetChildAtPoint(aAccX, aAccY, getter_AddRefs(pointAcc));
00134     if (NS_FAILED(rv))
00135         return nsnull;
00136 
00137     nsIAccessible *tmpAcc = pointAcc;
00138     nsAccessibleWrap *tmpAccWrap =
00139         NS_STATIC_CAST(nsAccessibleWrap *, tmpAcc);
00140     AtkObject *atkObj = tmpAccWrap->GetAtkObject();
00141     if (!atkObj)
00142         return nsnull;
00143     g_object_ref(atkObj);
00144     return atkObj;
00145 }
00146 
00147 void
00148 getExtentsCB(AtkComponent *aComponent,
00149              gint *aAccX,
00150              gint *aAccY,
00151              gint *aAccWidth,
00152              gint *aAccHeight,
00153              AtkCoordType aCoordType)
00154 {
00155     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
00156     if (!accWrap)
00157         return;
00158 
00159     PRInt32 nsAccX, nsAccY, nsAccWidth, nsAccHeight;
00160     nsresult rv = accWrap->GetBounds(&nsAccX, &nsAccY,
00161                                            &nsAccWidth, &nsAccHeight);
00162     if (NS_FAILED(rv))
00163         return;
00164     // or ATK_XY_SCREEN  what is definition this in nsIAccessible?
00165     if (aCoordType == ATK_XY_WINDOW) {
00166         /* deal with the coord type */
00167     }
00168 
00169     *aAccX = nsAccX;
00170     *aAccY = nsAccY;
00171     *aAccWidth = nsAccWidth;
00172     *aAccHeight = nsAccHeight;
00173 }
00174 
00175 gboolean
00176 grabFocusCB(AtkComponent *aComponent)
00177 {
00178     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
00179     NS_ENSURE_TRUE(accWrap, FALSE);
00180 
00181     nsresult rv = accWrap->TakeFocus();
00182     return (NS_FAILED(rv)) ? FALSE : TRUE;
00183 }