зеркало из https://github.com/mozilla/pjs.git
Enhancing the tracking so that I can get keyboard navigation to work in
the presence of cascading.
This commit is contained in:
Родитель
c0bcca9f17
Коммит
d50be34a2c
|
@ -31,9 +31,9 @@ class nsIMenuParent : public nsISupports {
|
|||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IMENUPARENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD SetCurrentMenuItem(nsIContent* aMenuItem) = 0;
|
||||
NS_IMETHOD GetNextMenuItem(nsIContent* aStart, nsIContent** aResult) = 0;
|
||||
NS_IMETHOD GetPreviousMenuItem(nsIContent* aStart, nsIContent** aResult) = 0;
|
||||
NS_IMETHOD SetCurrentMenuItem(nsIFrame* aMenuItem) = 0;
|
||||
NS_IMETHOD GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult) = 0;
|
||||
NS_IMETHOD GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,9 +31,9 @@ class nsIMenuParent : public nsISupports {
|
|||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IMENUPARENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD SetCurrentMenuItem(nsIContent* aMenuItem) = 0;
|
||||
NS_IMETHOD GetNextMenuItem(nsIContent* aStart, nsIContent** aResult) = 0;
|
||||
NS_IMETHOD GetPreviousMenuItem(nsIContent* aStart, nsIContent** aResult) = 0;
|
||||
NS_IMETHOD SetCurrentMenuItem(nsIFrame* aMenuItem) = 0;
|
||||
NS_IMETHOD GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult) = 0;
|
||||
NS_IMETHOD GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -128,7 +128,9 @@ nsMenuBarFrame::ToggleMenuActiveState()
|
|||
mIsActive = PR_FALSE;
|
||||
if (mCurrentMenu) {
|
||||
// Deactivate the menu.
|
||||
mCurrentMenu->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mCurrentMenu->GetContent(getter_AddRefs(content));
|
||||
content->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
||||
mCurrentMenu = nsnull;
|
||||
}
|
||||
}
|
||||
|
@ -139,13 +141,15 @@ nsMenuBarFrame::ToggleMenuActiveState()
|
|||
// Set the active menu to be the top left item (e.g., the File menu).
|
||||
// We use an attribute called "active" to track the current active menu.
|
||||
nsCOMPtr<nsIContent> firstMenuItem;
|
||||
GetNextMenuItem(nsnull, getter_AddRefs(firstMenuItem));
|
||||
if (firstMenuItem) {
|
||||
nsIFrame* firstFrame;
|
||||
GetNextMenuItem(nsnull, &firstFrame);
|
||||
if (firstFrame) {
|
||||
// Activate the item.
|
||||
firstFrame->GetContent(getter_AddRefs(firstMenuItem));
|
||||
firstMenuItem->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
|
||||
|
||||
// Track this item for keyboard navigation.
|
||||
mCurrentMenu = firstMenuItem.get();
|
||||
mCurrentMenu = firstFrame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,138 +162,121 @@ nsMenuBarFrame::KeyboardNavigation(PRUint32 aDirection)
|
|||
|
||||
if (aDirection == NS_VK_RIGHT ||
|
||||
aDirection == NS_VK_LEFT) {
|
||||
// Determine the index on the menu bar.
|
||||
PRInt32 index;
|
||||
mContent->IndexOf(mCurrentMenu, index);
|
||||
if (index >= 0) {
|
||||
// Activate the child at the position specified by index.
|
||||
nsCOMPtr<nsIContent> nextItem;
|
||||
|
||||
if (aDirection == NS_VK_RIGHT)
|
||||
GetNextMenuItem(mCurrentMenu, getter_AddRefs(nextItem));
|
||||
else GetPreviousMenuItem(mCurrentMenu, getter_AddRefs(nextItem));
|
||||
|
||||
// Activate the child at the position specified by index.
|
||||
nsIFrame* nextItem;
|
||||
|
||||
if (aDirection == NS_VK_RIGHT)
|
||||
GetNextMenuItem(mCurrentMenu, &nextItem);
|
||||
else GetPreviousMenuItem(mCurrentMenu, &nextItem);
|
||||
|
||||
SetCurrentMenuItem(nextItem);
|
||||
}
|
||||
SetCurrentMenuItem(nextItem);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBarFrame::GetNextMenuItem(nsIContent* aStart, nsIContent** aResult)
|
||||
nsMenuBarFrame::GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult)
|
||||
{
|
||||
PRInt32 index = 0;
|
||||
if (aStart) {
|
||||
// Determine the index of start.
|
||||
mContent->IndexOf(aStart, index);
|
||||
index++;
|
||||
}
|
||||
|
||||
PRInt32 count;
|
||||
mContent->ChildCount(count);
|
||||
|
||||
// Begin the search from index.
|
||||
PRInt32 i;
|
||||
for (i = index; i < count; i++) {
|
||||
nsIFrame* currFrame = aStart ? aStart : mFrames.FirstChild();
|
||||
currFrame->GetNextSibling(&currFrame);
|
||||
while (currFrame) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
mContent->ChildAt(i, *getter_AddRefs(current));
|
||||
|
||||
currFrame->GetContent(getter_AddRefs(current));
|
||||
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = current;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
*aResult = currFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
currFrame->GetNextSibling(&currFrame);
|
||||
}
|
||||
|
||||
currFrame = mFrames.FirstChild();
|
||||
|
||||
// Still don't have anything. Try cycling from the beginning.
|
||||
for (i = 0; i <= index; i++) {
|
||||
while (currFrame && currFrame != aStart) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
mContent->ChildAt(i, *getter_AddRefs(current));
|
||||
currFrame->GetContent(getter_AddRefs(current));
|
||||
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = current;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
*aResult = currFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
currFrame->GetNextSibling(&currFrame);
|
||||
}
|
||||
|
||||
// No luck. Just return our start value.
|
||||
*aResult = aStart;
|
||||
NS_IF_ADDREF(aStart);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuBarFrame::GetPreviousMenuItem(nsIContent* aStart, nsIContent** aResult)
|
||||
nsMenuBarFrame::GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult)
|
||||
{
|
||||
PRInt32 count;
|
||||
mContent->ChildCount(count);
|
||||
nsIFrame* currFrame = aStart ? aStart : mFrames.LastChild();
|
||||
currFrame = mFrames.GetPrevSiblingFor(currFrame);
|
||||
while (currFrame) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
currFrame->GetContent(getter_AddRefs(current));
|
||||
|
||||
PRInt32 index = count-1;
|
||||
if (aStart) {
|
||||
// Determine the index of start.
|
||||
mContent->IndexOf(aStart, index);
|
||||
index--;
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = currFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
currFrame = mFrames.GetPrevSiblingFor(currFrame);
|
||||
}
|
||||
|
||||
|
||||
// Begin the search from index.
|
||||
PRInt32 i;
|
||||
for (i = index; i >= 0; i--) {
|
||||
currFrame = mFrames.LastChild();
|
||||
|
||||
// Still don't have anything. Try cycling from the end.
|
||||
while (currFrame && currFrame != aStart) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
mContent->ChildAt(i, *getter_AddRefs(current));
|
||||
currFrame->GetContent(getter_AddRefs(current));
|
||||
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = current;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
*aResult = currFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Still don't have anything. Try cycling from the beginning.
|
||||
for (i = count-1; i >= index; i--) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
mContent->ChildAt(i, *getter_AddRefs(current));
|
||||
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = current;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
currFrame = mFrames.GetPrevSiblingFor(currFrame);
|
||||
}
|
||||
|
||||
// No luck. Just return our start value.
|
||||
*aResult = aStart;
|
||||
NS_IF_ADDREF(aStart);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMenuBarFrame::SetCurrentMenuItem(nsIContent* aMenuItem)
|
||||
NS_IMETHODIMP nsMenuBarFrame::SetCurrentMenuItem(nsIFrame* aMenuItem)
|
||||
{
|
||||
if (mCurrentMenu == aMenuItem)
|
||||
return NS_OK;
|
||||
|
||||
// Unset the current child.
|
||||
if (mCurrentMenu)
|
||||
mCurrentMenu->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
||||
|
||||
// Unset the current child.
|
||||
if (mCurrentMenu) {
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mCurrentMenu->GetContent(getter_AddRefs(content));
|
||||
content->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
||||
}
|
||||
|
||||
// Set the new child.
|
||||
if (aMenuItem)
|
||||
aMenuItem->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
|
||||
if (aMenuItem) {
|
||||
nsCOMPtr<nsIContent> content;
|
||||
aMenuItem->GetContent(getter_AddRefs(content));
|
||||
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
|
||||
}
|
||||
mCurrentMenu = aMenuItem;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
|
@ -42,9 +42,9 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIMenuParentInterface
|
||||
NS_IMETHOD SetCurrentMenuItem(nsIContent* aMenuItem);
|
||||
NS_IMETHOD GetNextMenuItem(nsIContent* aStart, nsIContent** aResult);
|
||||
NS_IMETHOD GetPreviousMenuItem(nsIContent* aStart, nsIContent** aResult);
|
||||
NS_IMETHOD SetCurrentMenuItem(nsIFrame* aMenuItem);
|
||||
NS_IMETHOD GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult);
|
||||
NS_IMETHOD GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult);
|
||||
|
||||
NS_IMETHOD IsActive() { return mIsActive; };
|
||||
|
||||
|
@ -61,7 +61,7 @@ public:
|
|||
protected:
|
||||
nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events.
|
||||
PRBool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown).
|
||||
nsIContent* mCurrentMenu; // The current menu that is active.
|
||||
nsIFrame* mCurrentMenu; // The current menu that is active.
|
||||
}; // class nsMenuBarFrame
|
||||
|
||||
#endif
|
||||
|
|
|
@ -205,7 +205,7 @@ nsMenuFrame::HandleEvent(nsIPresContext& aPresContext,
|
|||
else if (aEvent->message == NS_MOUSE_ENTER) {
|
||||
// Let the menu parent know we're the new item.
|
||||
if (mMenuParent)
|
||||
mMenuParent->SetCurrentMenuItem(mContent);
|
||||
mMenuParent->SetCurrentMenuItem(this);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -217,123 +217,106 @@ nsMenuPopupFrame::DidReflow(nsIPresContext& aPresContext,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuPopupFrame::GetNextMenuItem(nsIContent* aStart, nsIContent** aResult)
|
||||
nsMenuPopupFrame::GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult)
|
||||
{
|
||||
PRInt32 index = 0;
|
||||
if (aStart) {
|
||||
// Determine the index of start.
|
||||
mContent->IndexOf(aStart, index);
|
||||
index++;
|
||||
}
|
||||
|
||||
PRInt32 count;
|
||||
mContent->ChildCount(count);
|
||||
|
||||
// Begin the search from index.
|
||||
PRInt32 i;
|
||||
for (i = index; i < count; i++) {
|
||||
nsIFrame* currFrame = aStart ? aStart : mFrames.FirstChild();
|
||||
currFrame->GetNextSibling(&currFrame);
|
||||
while (currFrame) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
mContent->ChildAt(i, *getter_AddRefs(current));
|
||||
|
||||
currFrame->GetContent(getter_AddRefs(current));
|
||||
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = current;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
*aResult = currFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
currFrame->GetNextSibling(&currFrame);
|
||||
}
|
||||
|
||||
currFrame = mFrames.FirstChild();
|
||||
|
||||
// Still don't have anything. Try cycling from the beginning.
|
||||
for (i = 0; i <= index; i++) {
|
||||
while (currFrame && currFrame != aStart) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
mContent->ChildAt(i, *getter_AddRefs(current));
|
||||
currFrame->GetContent(getter_AddRefs(current));
|
||||
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = current;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
*aResult = currFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
currFrame->GetNextSibling(&currFrame);
|
||||
}
|
||||
|
||||
// No luck. Just return our start value.
|
||||
*aResult = aStart;
|
||||
NS_IF_ADDREF(aStart);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMenuPopupFrame::GetPreviousMenuItem(nsIContent* aStart, nsIContent** aResult)
|
||||
nsMenuPopupFrame::GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult)
|
||||
{
|
||||
PRInt32 count;
|
||||
mContent->ChildCount(count);
|
||||
nsIFrame* currFrame = aStart ? aStart : mFrames.LastChild();
|
||||
currFrame = mFrames.GetPrevSiblingFor(currFrame);
|
||||
while (currFrame) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
currFrame->GetContent(getter_AddRefs(current));
|
||||
|
||||
PRInt32 index = count-1;
|
||||
if (aStart) {
|
||||
// Determine the index of start.
|
||||
mContent->IndexOf(aStart, index);
|
||||
index--;
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = currFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
currFrame = mFrames.GetPrevSiblingFor(currFrame);
|
||||
}
|
||||
|
||||
|
||||
// Begin the search from index.
|
||||
PRInt32 i;
|
||||
for (i = index; i >= 0; i--) {
|
||||
currFrame = mFrames.LastChild();
|
||||
|
||||
// Still don't have anything. Try cycling from the end.
|
||||
while (currFrame && currFrame != aStart) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
mContent->ChildAt(i, *getter_AddRefs(current));
|
||||
currFrame->GetContent(getter_AddRefs(current));
|
||||
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = current;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
*aResult = currFrame;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Still don't have anything. Try cycling from the beginning.
|
||||
for (i = count-1; i >= index; i--) {
|
||||
nsCOMPtr<nsIContent> current;
|
||||
mContent->ChildAt(i, *getter_AddRefs(current));
|
||||
|
||||
// See if it's a menu item.
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
current->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::xpmenu) {
|
||||
*aResult = current;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
currFrame = mFrames.GetPrevSiblingFor(currFrame);
|
||||
}
|
||||
|
||||
// No luck. Just return our start value.
|
||||
*aResult = aStart;
|
||||
NS_IF_ADDREF(aStart);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMenuPopupFrame::SetCurrentMenuItem(nsIContent* aMenuItem)
|
||||
NS_IMETHODIMP nsMenuPopupFrame::SetCurrentMenuItem(nsIFrame* aMenuItem)
|
||||
{
|
||||
if (mCurrentMenu == aMenuItem)
|
||||
return NS_OK;
|
||||
|
||||
// Unset the current child.
|
||||
// Unset the current child.
|
||||
if (mCurrentMenu) {
|
||||
//printf("Unsetting current child.\n");
|
||||
mCurrentMenu->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
||||
nsCOMPtr<nsIContent> content;
|
||||
mCurrentMenu->GetContent(getter_AddRefs(content));
|
||||
content->UnsetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, PR_TRUE);
|
||||
}
|
||||
|
||||
// Set the new child.
|
||||
if (aMenuItem) {
|
||||
//printf("Setting new child.\n");
|
||||
aMenuItem->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
|
||||
nsCOMPtr<nsIContent> content;
|
||||
aMenuItem->GetContent(getter_AddRefs(content));
|
||||
content->SetAttribute(kNameSpaceID_None, nsXULAtoms::menuactive, "true", PR_TRUE);
|
||||
}
|
||||
mCurrentMenu = aMenuItem;
|
||||
|
||||
|
|
|
@ -43,9 +43,9 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIMenuParentInterface
|
||||
NS_IMETHOD SetCurrentMenuItem(nsIContent* aMenuItem);
|
||||
NS_IMETHOD GetNextMenuItem(nsIContent* aStart, nsIContent** aResult);
|
||||
NS_IMETHOD GetPreviousMenuItem(nsIContent* aStart, nsIContent** aResult);
|
||||
NS_IMETHOD SetCurrentMenuItem(nsIFrame* aMenuItem);
|
||||
NS_IMETHOD GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult);
|
||||
NS_IMETHOD GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult);
|
||||
|
||||
// Overridden methods
|
||||
NS_IMETHOD Init(nsIPresContext& aPresContext,
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
NS_IMETHOD CaptureMouseEvents(PRBool aGrabMouseEvents);
|
||||
|
||||
protected:
|
||||
nsIContent* mCurrentMenu; // The current menu that is active.
|
||||
nsIFrame* mCurrentMenu; // The current menu that is active.
|
||||
PRBool mIsCapturingMouseEvents; // Whether or not we're grabbing the mouse events.
|
||||
}; // class nsMenuPopupFrame
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче