Closed Bug 23498 Opened 25 years ago Closed 25 years ago

[FEATURE] Need to be able to programmatically focus XUL elements (like trees and titledbuttons)

Categories

(Core :: XUL, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: plaster, Assigned: hyatt)

References

Details

(Whiteboard: Fix in hand. Needs review.)

Can't focus a tree without clicking the mouse in it's content.  This happens in
mail as well as address book.  When you bring up these windows (as well as the
one that I am writing) it would be nice to be able to focus the tree in the
OnLoad function so that the tree got events (like up and down arrow keys).
Status: NEW → ASSIGNED
Target Milestone: M14
Summary: Can't focus a tree without clicking the mouse in it's content → [FEATURE] Need to be able to programmatically focus XUL elements (like trees and titledbuttons)
Blocks: 15681
Wanna look at this one for me, waterson?

All I had to do was add focus/blur to the XULElement IDL (and to those DOM props 
files).  Then the only other change was to XUL element.  The methods are 
included below.

NS_IMETHODIMP
nsXULElement::Focus()
{
  // Make sure we're focusable.
  nsCOMPtr<nsIFocusableContent> focusable = 
do_QueryInterface((nsIStyledContent*)this);
  if (!focusable)
    return NS_OK;

  // Obtain a presentation context and then call SetFocus.
  PRInt32 count = mDocument->GetNumberOfShells();
  if (count == 0)
    return NS_OK;

  nsCOMPtr<nsIPresShell> shell = getter_AddRefs(mDocument->GetShellAt(0));
  
  // Retrieve the context
  nsCOMPtr<nsIPresContext> aPresContext;
  shell->GetPresContext(getter_AddRefs(aPresContext));

  // Set focus
  return SetFocus(aPresContext);
}

NS_IMETHODIMP
nsXULElement::Blur()
{
  // Make sure we're focusable.
  nsCOMPtr<nsIFocusableContent> focusable = 
do_QueryInterface((nsIStyledContent*)this);
  if (!focusable)
    return NS_OK;

  // Obtain a presentation context and then call SetFocus.
  PRInt32 count = mDocument->GetNumberOfShells();
  if (count == 0)
    return NS_OK;

  nsCOMPtr<nsIPresShell> shell = getter_AddRefs(mDocument->GetShellAt(0));
  
  // Retrieve the context
  nsCOMPtr<nsIPresContext> aPresContext;
  shell->GetPresContext(getter_AddRefs(aPresContext));

  // Set focus
  return RemoveFocus(aPresContext);
}
Whiteboard: Fix in hand. Needs review.
Fixed.
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
please ignore, massive spam giving jrgm@netscape.com backlog of XPToolkits
resolved fixed bugs to verify
QA Contact: paulmac → jrgm
You need to log in before you can comment on or make changes to this bug.