1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
4 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is mozilla.org code.
19 * The Initial Developer of the Original Code is
21 * Portions created by the Initial Developer are Copyright (C) 2007
22 * the Initial Developer. All Rights Reserved.
25 * Alexander Surkov <surkov.alexander@gmail.com> (original author)
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include "CAccessibleComponent.h"
43 #include "AccessibleComponent_i.c"
45 #include "nsIAccessNode.h"
46 #include "nsIAccessible.h"
47 #include "nsIAccessibleStates.h"
48 #include "nsAccessNodeWrap.h"
53 #include "nsIDOMCSSPrimitiveValue.h"
54 #include "nsIDOMNSRGBAColor.h"
66 CAccessibleComponent::QueryInterface(REFIID iid
, void** ppv
)
70 if (IID_IAccessibleComponent
== iid
) {
71 *ppv
= static_cast<IAccessibleComponent
*>(this);
72 (reinterpret_cast<IUnknown
*>(*ppv
))->AddRef();
79 // IAccessibleComponent
82 CAccessibleComponent::get_locationInParent(long *aX
, long *aY
)
88 nsCOMPtr
<nsIAccessible
> acc(do_QueryInterface(this));
92 // If the object is not on any screen the returned position is (0,0).
94 nsresult rv
= acc
->GetFinalState(&states
, nsnull
);
96 return GetHRESULT(rv
);
98 if (states
& nsIAccessibleStates::STATE_INVISIBLE
)
101 PRInt32 x
= 0, y
= 0, width
= 0, height
= 0;
102 rv
= acc
->GetBounds(&x
, &y
, &width
, &height
);
104 return GetHRESULT(rv
);
106 nsCOMPtr
<nsIAccessible
> parentAcc
;
107 rv
= acc
->GetParent(getter_AddRefs(parentAcc
));
109 return GetHRESULT(rv
);
111 // The coordinates of the returned position are relative to this object's
112 // parent or relative to the screen on which this object is rendered if it
120 // The coordinates of the bounding box are given relative to the parent's
121 // coordinate system.
122 PRInt32 parentx
= 0, parenty
= 0;
123 rv
= acc
->GetBounds(&parentx
, &parenty
, &width
, &height
);
125 return GetHRESULT(rv
);
131 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
136 CAccessibleComponent::get_foreground(IA2Color
*aForeground
)
139 return GetARGBValueFromCSSProperty(NS_LITERAL_STRING("color"), aForeground
);
140 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
146 CAccessibleComponent::get_background(IA2Color
*aBackground
)
149 return GetARGBValueFromCSSProperty(NS_LITERAL_STRING("background-color"),
151 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
157 CAccessibleComponent::GetARGBValueFromCSSProperty(const nsAString
& aPropName
,
158 IA2Color
*aColorValue
)
163 nsCOMPtr
<nsIAccessNode
> acc(do_QueryInterface(this));
167 nsCOMPtr
<nsIDOMCSSPrimitiveValue
> cssValue
;
168 nsresult rv
= acc
->GetComputedStyleCSSValue(EmptyString(), aPropName
,
169 getter_AddRefs(cssValue
));
170 if (NS_FAILED(rv
) || !cssValue
)
171 return GetHRESULT(rv
);
173 nsCOMPtr
<nsIDOMRGBColor
> rgbColor
;
174 rv
= cssValue
->GetRGBColorValue(getter_AddRefs(rgbColor
));
175 if (NS_FAILED(rv
) || !rgbColor
)
176 return GetHRESULT(rv
);
178 nsCOMPtr
<nsIDOMNSRGBAColor
> rgbaColor(do_QueryInterface(rgbColor
));
180 return GetHRESULT(rv
);
183 nsCOMPtr
<nsIDOMCSSPrimitiveValue
> alphaValue
;
184 rv
= rgbaColor
->GetAlpha(getter_AddRefs(alphaValue
));
185 if (NS_FAILED(rv
) || !alphaValue
)
186 return GetHRESULT(rv
);
189 rv
= alphaValue
->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER
, &alpha
);
191 return GetHRESULT(rv
);
194 nsCOMPtr
<nsIDOMCSSPrimitiveValue
> redValue
;
195 rv
= rgbaColor
->GetRed(getter_AddRefs(redValue
));
196 if (NS_FAILED(rv
) || !redValue
)
197 return GetHRESULT(rv
);
200 rv
= redValue
->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER
, &red
);
202 return GetHRESULT(rv
);
205 nsCOMPtr
<nsIDOMCSSPrimitiveValue
> greenValue
;
206 rv
= rgbaColor
->GetGreen(getter_AddRefs(greenValue
));
207 if (NS_FAILED(rv
) || !greenValue
)
208 return GetHRESULT(rv
);
211 rv
= greenValue
->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER
, &green
);
213 return GetHRESULT(rv
);
216 nsCOMPtr
<nsIDOMCSSPrimitiveValue
> blueValue
;
217 rv
= rgbaColor
->GetBlue(getter_AddRefs(blueValue
));
218 if (NS_FAILED(rv
) || !blueValue
)
219 return GetHRESULT(rv
);
222 rv
= blueValue
->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER
, &blue
);
224 return GetHRESULT(rv
);
226 // compose ARGB value
227 *aColorValue
= (((IA2Color
) blue
) << IA2BlueShift
) |
228 (((IA2Color
) green
) << IA2GreenShift
) |
229 (((IA2Color
) red
) << IA2RedShift
) |
230 (((IA2Color
) (alpha
* 0xff)) << IA2AlphaShift
);
233 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }