Bug 165998. Option and select bounds incorrect. r=pkwarren, sr=roc

This commit is contained in:
aaronleventhal%moonset.net 2004-08-18 14:39:45 +00:00
parent ce8560ba60
commit 8a5328d65b
8 changed files with 102 additions and 75 deletions

View File

@ -67,6 +67,7 @@ ACCESSIBILITY_ATOM(label, "label")
ACCESSIBILITY_ATOM(ol, "ol")
ACCESSIBILITY_ATOM(optgroup, "optgroup")
ACCESSIBILITY_ATOM(option, "option")
ACCESSIBILITY_ATOM(select, "select")
ACCESSIBILITY_ATOM(ul, "ul")
// Alphabetical list of attributes

View File

@ -640,65 +640,34 @@ void nsAccessible::GetScreenOrigin(nsPresContext *aPresContext, nsIFrame *aFrame
{
aRect->x = aRect->y = 0;
if (aPresContext) {
PRInt32 offsetX = 0;
PRInt32 offsetY = 0;
nsIWidget* widget = nsnull;
while (aFrame) {
// Look for a widget so we can get screen coordinates
nsIView* view = aFrame->GetViewExternal();
if (view) {
widget = view->GetWidget();
if (widget)
break;
}
// No widget yet, so count up the coordinates of the frame
nsPoint origin = aFrame->GetPosition();
offsetX += origin.x;
offsetY += origin.y;
if (!aPresContext) {
return;
}
nsPoint origin(0,0);
nsIView *view = aFrame->GetViewExternal();
if (!view) {
aFrame->GetOffsetFromView(aPresContext, origin, &view);
NS_ASSERTION(view, "Frame has no view");
}
nsPoint viewOrigin(0,0);
nsIWidget *widget = view->GetNearestWidget(&viewOrigin);
origin += viewOrigin;
// Get the scale from that Presentation Context
float t2p = aPresContext->TwipsToPixels();
// Convert to pixels using that scale
origin.x = NSTwipsToIntPixels(origin.x, t2p);
origin.y = NSTwipsToIntPixels(origin.y, t2p);
aFrame = aFrame->GetParent();
}
if (widget) {
// Get the scale from that Presentation Context
float t2p;
t2p = aPresContext->TwipsToPixels();
// Convert to pixels using that scale
offsetX = NSTwipsToIntPixels(offsetX, t2p);
offsetY = NSTwipsToIntPixels(offsetY, t2p);
// Add the widget's screen coordinates to the offset we've counted
nsRect oldBox(0,0,0,0);
widget->WidgetToScreen(oldBox, *aRect);
aRect->x += offsetX;
aRect->y += offsetY;
}
}
// Add the widget's screen coordinates to the offset we've counted
//nsIWidget *widget = view->GetWidget();
NS_ASSERTION(widget, "No widget for top view");
widget->WidgetToScreen(nsRect(origin.x, origin.y, 1, 1), *aRect);
}
void nsAccessible::GetScrollOffset(nsRect *aRect)
{
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mWeakShell));
if (shell) {
nsCOMPtr<nsIDOMDocumentView> docView(do_QueryInterface(shell->GetDocument()));
if (!docView)
return;
nsCOMPtr<nsIDOMAbstractView> abstractView;
docView->GetDefaultView(getter_AddRefs(abstractView));
if (!abstractView)
return;
nsCOMPtr<nsIDOMWindowInternal> window(do_QueryInterface(abstractView));
window->GetPageXOffset(&aRect->x);
window->GetPageYOffset(&aRect->y);
}
}
void nsAccessible::GetBoundsRect(nsRect& aTotalBounds, nsIFrame** aBoundingFrame)
{
/*
@ -828,12 +797,8 @@ NS_IMETHODIMP nsAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PR
nsRect orgRectPixels, pageRectPixels;
GetScreenOrigin(presContext, aBoundingFrame, &orgRectPixels);
PRUint32 role;
GetRole(&role);
if (role != ROLE_PANE)
GetScrollOffset(&pageRectPixels); // Add scroll offsets if not the document itself
*x += orgRectPixels.x - pageRectPixels.x;
*y += orgRectPixels.y - pageRectPixels.y;
*x += orgRectPixels.x;
*y += orgRectPixels.y;
return NS_OK;
}

View File

@ -104,7 +104,6 @@ protected:
// helper method to verify frames
static nsresult GetFullKeyName(const nsAString& aModifierName, const nsAString& aKeyName, nsAString& aStringOut);
static nsresult GetTranslatedString(const nsAString& aKey, nsAString& aStringOut);
void GetScrollOffset(nsRect *aRect);
void GetScreenOrigin(nsPresContext *aPresContext, nsIFrame *aFrame, nsRect *aRect);
nsresult AppendFlatStringFromSubtreeRecurse(nsIContent *aContent, nsAString *aFlatString);
virtual void CacheChildren(PRBool aWalkAnonContent);

View File

@ -147,9 +147,8 @@ NS_IMETHODIMP nsHTMLAreaAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *w
// Put coords in absolute screen coords
GetScreenOrigin(presContext, frame, &orgRectPixels);
GetScrollOffset(&pageRectPixels);
*x += orgRectPixels.x - pageRectPixels.x;
*y += orgRectPixels.y - pageRectPixels.y;
*x += orgRectPixels.x;
*y += orgRectPixels.y;
return NS_OK;
}

View File

@ -598,6 +598,37 @@ NS_IMETHODIMP nsHTMLSelectOptionAccessible::GetPreviousSibling(nsIAccessible **_
return NS_OK;
}
nsIFrame* nsHTMLSelectOptionAccessible::GetBoundsFrame()
{
nsCOMPtr<nsIContent> selectContent(do_QueryInterface(mDOMNode));
while (selectContent && selectContent->Tag() != nsAccessibilityAtoms::select) {
selectContent = selectContent->GetParent();
}
nsCOMPtr<nsIDOMNode> selectNode(do_QueryInterface(selectContent));
if (selectNode) {
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
nsCOMPtr<nsIAccessible> selAcc;
if (NS_SUCCEEDED(accService->GetAccessibleFor(selectNode,
getter_AddRefs(selAcc)))) {
PRUint32 state;
selAcc->GetState(&state);
if (state & STATE_COLLAPSED) {
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
if (!presShell) {
return nsnull;
}
nsIFrame *selectFrame = nsnull;
presShell->GetPrimaryFrameFor(selectContent, &selectFrame);
return selectFrame;
}
}
}
return nsAccessible::GetBoundsFrame();
}
/**
* As a nsHTMLSelectOptionAccessible we can have the following states:
* STATE_SELECTABLE

View File

@ -40,10 +40,11 @@
#define __nsHTMLSelectAccessible_h__
#include "nsIAccessibleSelectable.h"
#include "nsAccessibilityAtoms.h"
#include "nsFormControlAccessible.h"
#include "nsIDOMHTMLOptionsCollection.h"
#include "nsIDOMHTMLOptionElement.h"
#include "nsIDOMNode.h"
#include "nsFormControlAccessible.h"
#include "nsIAccessibilityService.h"
/**
@ -151,6 +152,7 @@ public:
NS_IMETHOD GetRole(PRUint32 *aRole);
NS_IMETHOD GetParent(nsIAccessible **aParent);
NS_IMETHOD GetName(nsAString& aName);
nsIFrame* GetBoundsFrame();
static nsresult GetFocusedOptionNode(nsIDOMNode *aListNode, nsIDOMNode **aFocusedOptionNode);
};

View File

@ -38,17 +38,19 @@
* ***** END LICENSE BLOCK ***** */
#include "nsXULSelectAccessible.h"
#include "nsArray.h"
#include "nsIContent.h"
#include "nsIDOMXULMenuListElement.h"
#include "nsIDOMXULMultSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsIDOMXULSelectCntrlEl.h"
#include "nsIDOMXULTextboxElement.h"
#include "nsIPresShell.h"
#include "nsIServiceManager.h"
#include "nsArray.h"
/**
* Selects, Listboxes and Comboboxes, are made up of a number of different
* widgets, some of which are shared between the two. This file contains
* widgets, some of which are shared between the two. This file contains
* all of the widgets for both of the Selects, for XUL only.
*
* Listbox:
@ -69,7 +71,7 @@
/** ------------------------------------------------------ */
// Helper methos
nsXULSelectableAccessible::nsXULSelectableAccessible(nsIDOMNode* aDOMNode,
nsXULSelectableAccessible::nsXULSelectableAccessible(nsIDOMNode* aDOMNode,
nsIWeakReference* aShell):
nsAccessibleWrap(aDOMNode, aShell)
{
@ -152,7 +154,7 @@ NS_IMETHODIMP nsXULSelectableAccessible::GetSelectedChildren(nsIArray **_retval)
}
PRUint32 uLength = 0;
selectedAccessibles->GetLength(&uLength);
selectedAccessibles->GetLength(&uLength);
if (uLength != 0) { // length of nsIArray containing selected options
*_retval = selectedAccessibles;
NS_ADDREF(*_retval);
@ -263,7 +265,7 @@ NS_IMETHODIMP nsXULSelectableAccessible::SelectAllSelection(PRBool *_retval)
/** ----- nsXULSelectListAccessible ----- */
/** Default Constructor */
nsXULSelectListAccessible::nsXULSelectListAccessible(nsIDOMNode* aDOMNode,
nsXULSelectListAccessible::nsXULSelectListAccessible(nsIDOMNode* aDOMNode,
nsIWeakReference* aShell)
:nsAccessibleWrap(aDOMNode, aShell)
{
@ -281,7 +283,7 @@ NS_IMETHODIMP nsXULSelectListAccessible::GetRole(PRUint32 *_retval)
* STATE_EXTSELECTABLE
*/
NS_IMETHODIMP nsXULSelectListAccessible::GetState(PRUint32 *_retval)
{
{
*_retval = 0;
nsAutoString selectionTypeString;
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
@ -327,6 +329,33 @@ NS_IMETHODIMP nsXULSelectOptionAccessible::GetState(PRUint32 *_retval)
return NS_OK;
}
nsIFrame* nsXULSelectOptionAccessible::GetBoundsFrame()
{
nsCOMPtr<nsIContent> menuListContent(do_QueryInterface(mDOMNode));
while (menuListContent) {
nsCOMPtr<nsIDOMXULMenuListElement> menuListControl =
do_QueryInterface(menuListContent);
if (menuListControl) {
PRBool isOpen;
menuListControl->GetOpen(&isOpen);
if (!isOpen) {
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
if (!presShell) {
return nsnull;
}
nsIFrame *menuListFrame = nsnull;
presShell->GetPrimaryFrameFor(menuListContent, &menuListFrame);
return menuListFrame;
}
break;
}
menuListContent = menuListContent->GetParent();
}
return nsXULMenuitemAccessible::GetBoundsFrame();
}
/** ------------------------------------------------------ */
/** Secondly, the Listbox widget */
/** ------------------------------------------------------ */
@ -480,12 +509,12 @@ NS_IMETHODIMP nsXULListitemAccessible::GetActionName(PRUint8 index, nsAString& _
// check or uncheck
PRUint32 state;
GetState(&state);
if (state & STATE_CHECKED)
_retval = NS_LITERAL_STRING("uncheck");
else
_retval = NS_LITERAL_STRING("check");
return NS_OK;
}
return NS_ERROR_INVALID_ARG;

View File

@ -115,6 +115,7 @@ public:
/* ----- nsIAccessible ----- */
NS_IMETHOD GetRole(PRUint32 *_retval);
NS_IMETHOD GetState(PRUint32 *_retval);
nsIFrame* GetBoundsFrame();
};
/** ------------------------------------------------------ */