2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsMenuFrame.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsMenuPopupFrame.h"
|
|
|
|
#include "nsMenuBarFrame.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsIReflowCallback.h"
|
2008-12-10 09:23:20 -08:00
|
|
|
#include "nsISound.h"
|
2010-04-19 07:12:58 -07:00
|
|
|
#include "nsIDOMXULMenuListElement.h"
|
2012-07-10 21:03:55 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-31 21:09:23 -07:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2011-05-24 23:32:00 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
#define NS_MENU_POPUP_LIST_INDEX 0
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-10 14:57:01 -08:00
|
|
|
#if defined(XP_WIN)
|
2007-03-22 10:30:00 -07:00
|
|
|
#define NSCONTEXTMENUISMOUSEUP 1
|
|
|
|
#endif
|
|
|
|
|
2012-03-07 17:57:37 -08:00
|
|
|
static void
|
|
|
|
AssertNotCalled(void* aPropertyValue)
|
|
|
|
{
|
|
|
|
NS_ERROR("popup list should never be destroyed by the FramePropertyTable");
|
|
|
|
}
|
|
|
|
NS_DECLARE_FRAME_PROPERTY(PopupListProperty, AssertNotCalled)
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t gEatMouseMove = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t kBlinkDelay = 67; // milliseconds
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-25 21:14:32 -07:00
|
|
|
// this class is used for dispatching menu activation events asynchronously.
|
|
|
|
class nsMenuActivateEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsMenuActivateEvent(nsIContent *aMenu,
|
|
|
|
nsPresContext* aPresContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsActivate)
|
2007-07-25 21:14:32 -07:00
|
|
|
: mMenu(aMenu), mPresContext(aPresContext), mIsActivate(aIsActivate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2007-07-25 21:14:32 -07:00
|
|
|
{
|
|
|
|
nsAutoString domEventToFire;
|
|
|
|
|
|
|
|
if (mIsActivate) {
|
|
|
|
// Highlight the menu.
|
|
|
|
mMenu->SetAttr(kNameSpaceID_None, nsGkAtoms::menuactive,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("true"), true);
|
2007-07-25 21:14:32 -07:00
|
|
|
// The menuactivated event is used by accessibility to track the user's
|
|
|
|
// movements through menus
|
|
|
|
domEventToFire.AssignLiteral("DOMMenuItemActive");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Unhighlight the menu.
|
2011-10-17 07:59:28 -07:00
|
|
|
mMenu->UnsetAttr(kNameSpaceID_None, nsGkAtoms::menuactive, true);
|
2007-07-25 21:14:32 -07:00
|
|
|
domEventToFire.AssignLiteral("DOMMenuItemInactive");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2014-03-17 21:48:21 -07:00
|
|
|
if (NS_SUCCEEDED(EventDispatcher::CreateEvent(mMenu, mPresContext, nullptr,
|
|
|
|
NS_LITERAL_STRING("Events"),
|
|
|
|
getter_AddRefs(event)))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
event->InitEvent(domEventToFire, true, true);
|
2007-07-25 21:14:32 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
event->SetTrusted(true);
|
2007-07-25 21:14:32 -07:00
|
|
|
|
2014-03-17 21:48:21 -07:00
|
|
|
EventDispatcher::DispatchDOMEvent(mMenu, nullptr, event,
|
|
|
|
mPresContext, nullptr);
|
2007-07-25 21:14:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mMenu;
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsActivate;
|
2007-07-25 21:14:32 -07:00
|
|
|
};
|
|
|
|
|
2010-08-12 04:59:03 -07:00
|
|
|
class nsMenuAttributeChangedEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsMenuAttributeChangedEvent(nsIFrame* aFrame, nsIAtom* aAttr)
|
|
|
|
: mFrame(aFrame), mAttr(aAttr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2010-08-12 04:59:03 -07:00
|
|
|
{
|
|
|
|
nsMenuFrame* frame = static_cast<nsMenuFrame*>(mFrame.GetFrame());
|
|
|
|
NS_ENSURE_STATE(frame);
|
|
|
|
if (mAttr == nsGkAtoms::checked) {
|
|
|
|
frame->UpdateMenuSpecialState(frame->PresContext());
|
|
|
|
} else if (mAttr == nsGkAtoms::acceltext) {
|
|
|
|
// someone reset the accelText attribute,
|
|
|
|
// so clear the bit that says *we* set it
|
2011-02-13 04:28:00 -08:00
|
|
|
frame->RemoveStateBits(NS_STATE_ACCELTEXT_IS_DERIVED);
|
2011-10-17 07:59:28 -07:00
|
|
|
frame->BuildAcceleratorText(true);
|
2011-02-13 04:28:00 -08:00
|
|
|
}
|
|
|
|
else if (mAttr == nsGkAtoms::key) {
|
2011-10-17 07:59:28 -07:00
|
|
|
frame->BuildAcceleratorText(true);
|
2010-08-12 04:59:03 -07:00
|
|
|
} else if (mAttr == nsGkAtoms::type || mAttr == nsGkAtoms::name) {
|
|
|
|
frame->UpdateMenuType(frame->PresContext());
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
nsWeakFrame mFrame;
|
|
|
|
nsCOMPtr<nsIAtom> mAttr;
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2009-01-19 10:31:33 -08:00
|
|
|
// NS_NewMenuFrame and NS_NewMenuItemFrame
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2009-01-19 10:31:33 -08:00
|
|
|
// Wrappers for creating a new menu popup container
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:33 -08:00
|
|
|
NS_NewMenuFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsMenuFrame* it = new (aPresShell) nsMenuFrame (aPresShell, aContext);
|
2012-11-07 11:55:53 -08:00
|
|
|
it->SetIsMenu(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:31:33 -08:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewMenuItemFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
nsMenuFrame* it = new (aPresShell) nsMenuFrame (aPresShell, aContext);
|
2012-11-07 11:55:53 -08:00
|
|
|
it->SetIsMenu(false);
|
2009-01-19 10:31:33 -08:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMenuFrame)
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsMenuFrame)
|
2011-07-11 07:05:07 -07:00
|
|
|
NS_QUERYFRAME_ENTRY(nsMenuFrame)
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsMenuFrame::nsMenuFrame(nsIPresShell* aShell, nsStyleContext* aContext):
|
|
|
|
nsBoxFrame(aShell, aContext),
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsMenu(false),
|
|
|
|
mChecked(false),
|
|
|
|
mIgnoreAccelTextChange(false),
|
2007-03-22 10:30:00 -07:00
|
|
|
mType(eMenuType_Normal),
|
2012-07-30 07:20:58 -07:00
|
|
|
mMenuParent(nullptr),
|
2010-04-19 07:12:58 -07:00
|
|
|
mBlinkState(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-30 17:46:26 -07:00
|
|
|
void
|
2014-05-24 15:20:39 -07:00
|
|
|
nsMenuFrame::SetParent(nsContainerFrame* aParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsBoxFrame::SetParent(aParent);
|
2010-08-30 17:46:26 -07:00
|
|
|
InitMenuParent(aParent);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
|
|
|
nsMenuFrame::InitMenuParent(nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
while (aParent) {
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuPopupFrame* popup = do_QueryFrame(aParent);
|
|
|
|
if (popup) {
|
|
|
|
mMenuParent = popup;
|
2007-07-04 08:49:38 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-07-30 17:43:28 -07:00
|
|
|
|
|
|
|
nsMenuBarFrame* menubar = do_QueryFrame(aParent);
|
|
|
|
if (menubar) {
|
|
|
|
mMenuParent = menubar;
|
2007-07-04 08:49:38 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-07-30 17:43:28 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
aParent = aParent->GetParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-10 21:03:55 -07:00
|
|
|
class nsASyncMenuInitialization MOZ_FINAL : public nsIReflowCallback
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsASyncMenuInitialization(nsIFrame* aFrame)
|
|
|
|
: mWeakFrame(aFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual bool ReflowFinished() MOZ_OVERRIDE
|
2007-11-30 23:22:44 -08:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shouldFlush = false;
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(mWeakFrame.GetFrame());
|
|
|
|
if (menu) {
|
|
|
|
menu->UpdateMenuType(menu->PresContext());
|
|
|
|
shouldFlush = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
delete this;
|
|
|
|
return shouldFlush;
|
|
|
|
}
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual void ReflowCallbackCanceled() MOZ_OVERRIDE
|
2007-11-30 23:22:44 -08:00
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWeakFrame mWeakFrame;
|
|
|
|
};
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Set up a mediator which can be used for callbacks on this frame.
|
|
|
|
mTimerMediator = new nsMenuTimerMediator(this);
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
InitMenuParent(aParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
BuildAcceleratorText(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIReflowCallback* cb = new nsASyncMenuInitialization(this);
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->PostReflowCallback(cb);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-07 17:57:37 -08:00
|
|
|
const nsFrameList&
|
2011-08-24 13:54:29 -07:00
|
|
|
nsMenuFrame::GetChildList(ChildListID aListID) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-24 13:54:29 -07:00
|
|
|
if (kPopupList == aListID) {
|
2012-03-07 17:57:37 -08:00
|
|
|
nsFrameList* list = GetPopupList();
|
|
|
|
return list ? *list : nsFrameList::EmptyList();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-24 13:54:29 -07:00
|
|
|
return nsBoxFrame::GetChildList(aListID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::GetChildLists(nsTArray<ChildList>* aLists) const
|
|
|
|
{
|
|
|
|
nsBoxFrame::GetChildLists(aLists);
|
2012-03-07 17:57:37 -08:00
|
|
|
nsFrameList* list = GetPopupList();
|
|
|
|
if (list) {
|
|
|
|
list->AppendIfNonempty(aLists, kPopupList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMenuPopupFrame*
|
|
|
|
nsMenuFrame::GetPopup()
|
|
|
|
{
|
|
|
|
nsFrameList* popupList = GetPopupList();
|
|
|
|
return popupList ? static_cast<nsMenuPopupFrame*>(popupList->FirstChild()) :
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr;
|
2012-03-07 17:57:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameList*
|
|
|
|
nsMenuFrame::GetPopupList() const
|
|
|
|
{
|
|
|
|
if (!HasPopup()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-07 17:57:37 -08:00
|
|
|
}
|
|
|
|
nsFrameList* prop =
|
|
|
|
static_cast<nsFrameList*>(Properties().Get(PopupListProperty()));
|
|
|
|
NS_ASSERTION(prop && prop->GetLength() == 1 &&
|
|
|
|
prop->FirstChild()->GetType() == nsGkAtoms::menuPopupFrame,
|
|
|
|
"popup list should have exactly one nsMenuPopupFrame");
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::DestroyPopupList()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(HasPopup(), "huh?");
|
|
|
|
nsFrameList* prop =
|
|
|
|
static_cast<nsFrameList*>(Properties().Remove(PopupListProperty()));
|
|
|
|
NS_ASSERTION(prop && prop->IsEmpty(),
|
|
|
|
"popup list must exist and be empty when destroying");
|
|
|
|
RemoveStateBits(NS_STATE_MENU_HAS_POPUP_LIST);
|
2013-04-01 08:26:02 -07:00
|
|
|
prop->Delete(PresContext()->PresShell());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-28 05:53:20 -07:00
|
|
|
void
|
|
|
|
nsMenuFrame::SetPopupFrame(nsFrameList& aFrameList)
|
|
|
|
{
|
|
|
|
for (nsFrameList::Enumerator e(aFrameList); !e.AtEnd(); e.Next()) {
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(e.get());
|
|
|
|
if (popupFrame) {
|
2012-03-07 17:57:37 -08:00
|
|
|
// Remove the frame from the list and store it in a nsFrameList* property.
|
|
|
|
aFrameList.RemoveFrame(popupFrame);
|
2013-04-01 08:26:02 -07:00
|
|
|
nsFrameList* popupList = new (PresContext()->PresShell()) nsFrameList(popupFrame, popupFrame);
|
2012-03-07 17:57:37 -08:00
|
|
|
Properties().Set(PopupListProperty(), popupList);
|
|
|
|
AddStateBits(NS_STATE_MENU_HAS_POPUP_LIST);
|
2007-07-04 08:49:38 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-06-29 15:15:59 -07:00
|
|
|
}
|
2007-11-17 07:47:38 -08:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMenuFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-11-17 07:47:38 -08:00
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
NS_ASSERTION(!HasPopup(), "SetInitialChildList called twice?");
|
2011-08-24 13:54:30 -07:00
|
|
|
if (aListID == kPrincipalList || aListID == kPopupList) {
|
2009-07-28 05:53:20 -07:00
|
|
|
SetPopupFrame(aChildList);
|
2011-08-24 13:54:30 -07:00
|
|
|
}
|
|
|
|
return nsBoxFrame::SetInitialChildList(aListID, aChildList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsMenuFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Kill our timer if one is active. This is not strictly necessary as
|
|
|
|
// the pointer to this frame will be cleared from the mediator, but
|
|
|
|
// this is done for added safety.
|
|
|
|
if (mOpenTimer) {
|
|
|
|
mOpenTimer->Cancel();
|
|
|
|
}
|
|
|
|
|
2010-04-19 07:12:58 -07:00
|
|
|
StopBlinking();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Null out the pointer to this frame in the mediator wrapper so that it
|
|
|
|
// doesn't try to interact with a deallocated frame.
|
|
|
|
mTimerMediator->ClearFrame();
|
|
|
|
|
2008-01-29 23:18:07 -08:00
|
|
|
// if the menu content is just being hidden, it may be made visible again
|
|
|
|
// later, so make sure to clear the highlighting.
|
2011-10-17 07:59:28 -07:00
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::menuactive, false);
|
2008-01-29 23:18:07 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// are we our menu parent's current menu item?
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mMenuParent && mMenuParent->GetCurrentMenuItem() == this) {
|
|
|
|
// yes; tell it that we're going away
|
|
|
|
mMenuParent->CurrentMenuIsBeingDestroyed();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-07 17:57:37 -08:00
|
|
|
nsFrameList* popupList = GetPopupList();
|
|
|
|
if (popupList) {
|
|
|
|
popupList->DestroyFramesFrom(aDestructRoot);
|
|
|
|
DestroyPopupList();
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
2013-02-14 03:12:27 -08:00
|
|
|
if (!aBuilder->IsForEventDelivery()) {
|
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsDisplayListCollection set;
|
2013-02-14 03:12:27 -08:00
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, set);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
WrapListsInRedirector(aBuilder, set, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
2010-04-19 07:12:58 -07:00
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus ||
|
|
|
|
(mMenuParent && mMenuParent->IsMenuLocked())) {
|
2009-02-27 02:48:25 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
if (*aEventStatus == nsEventStatus_eIgnore)
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool onmenu = IsOnMenu();
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEvent->message == NS_KEY_PRESS && !IsDisabled()) {
|
2013-10-17 23:10:24 -07:00
|
|
|
WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t keyCode = keyEvent->keyCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// On mac, open menulist on either up/down arrow or space (w/o Cmd pressed)
|
2012-04-24 20:00:02 -07:00
|
|
|
if (!IsOpen() && ((keyEvent->charCode == NS_VK_SPACE && !keyEvent->IsMeta()) ||
|
2009-05-01 05:24:49 -07:00
|
|
|
(keyCode == NS_VK_UP || keyCode == NS_VK_DOWN))) {
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2011-10-17 07:59:28 -07:00
|
|
|
OpenMenu(false);
|
2009-05-01 05:24:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
|
|
|
// On other platforms, toggle menulist on unmodified F4 or Alt arrow
|
2012-04-24 20:00:02 -07:00
|
|
|
if ((keyCode == NS_VK_F4 && !keyEvent->IsAlt()) ||
|
|
|
|
((keyCode == NS_VK_UP || keyCode == NS_VK_DOWN) && keyEvent->IsAlt())) {
|
2009-05-01 05:24:49 -07:00
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2007-07-04 08:49:38 -07:00
|
|
|
ToggleMenuState();
|
2009-05-01 05:24:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
2013-10-22 01:55:20 -07:00
|
|
|
else if (aEvent->message == NS_MOUSE_BUTTON_DOWN &&
|
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton &&
|
2007-03-22 10:30:00 -07:00
|
|
|
!IsDisabled() && IsMenu()) {
|
|
|
|
// The menu item was selected. Bring up the menu.
|
|
|
|
// We have children.
|
2009-06-03 19:43:03 -07:00
|
|
|
// Don't prevent the default action here, since that will also cancel
|
|
|
|
// potential drag starts.
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!mMenuParent || mMenuParent->IsMenuBar()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
ToggleMenuState();
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
else {
|
2009-05-01 05:24:49 -07:00
|
|
|
if (!IsOpen()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
OpenMenu(false);
|
2009-05-01 05:24:49 -07:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (
|
|
|
|
#ifndef NSCONTEXTMENUISMOUSEUP
|
2013-10-22 01:55:20 -07:00
|
|
|
(aEvent->message == NS_MOUSE_BUTTON_UP &&
|
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eRightButton) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2013-10-22 01:55:20 -07:00
|
|
|
aEvent->message == NS_CONTEXTMENU &&
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2013-10-22 01:55:20 -07:00
|
|
|
onmenu && !IsMenu() && !IsDisabled()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// if this menu is a context menu it accepts right-clicks...fire away!
|
|
|
|
// Make sure we cancel default processing of the context menu event so
|
|
|
|
// that it doesn't bubble and get seen again by the popuplistener and show
|
|
|
|
// another context menu.
|
|
|
|
//
|
|
|
|
// Furthermore (there's always more, isn't there?), on some platforms (win32
|
|
|
|
// being one of them) we get the context menu event on a mouse up while
|
|
|
|
// on others we get it on a mouse down. For the ones where we get it on a
|
|
|
|
// mouse down, we must continue listening for the right button up event to
|
|
|
|
// dismiss the menu.
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mMenuParent->IsContextMenu()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
Execute(aEvent);
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 01:55:20 -07:00
|
|
|
else if (aEvent->message == NS_MOUSE_BUTTON_UP &&
|
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton &&
|
2007-07-04 08:49:38 -07:00
|
|
|
!IsMenu() && !IsDisabled()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Execute the execute event handler.
|
2009-05-01 05:24:49 -07:00
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2007-03-22 10:30:00 -07:00
|
|
|
Execute(aEvent);
|
|
|
|
}
|
|
|
|
else if (aEvent->message == NS_MOUSE_EXIT_SYNTH) {
|
|
|
|
// Kill our timer if one is active.
|
|
|
|
if (mOpenTimer) {
|
|
|
|
mOpenTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mOpenTimer = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Deactivate the menu.
|
|
|
|
if (mMenuParent) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool onmenubar = mMenuParent->IsMenuBar();
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!(onmenubar && mMenuParent->IsActive())) {
|
|
|
|
if (IsMenu() && !onmenubar && IsOpen()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Submenus don't get closed up immediately.
|
|
|
|
}
|
2007-10-02 02:41:29 -07:00
|
|
|
else if (this == mMenuParent->GetCurrentMenuItem()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mMenuParent->ChangeMenuItem(nullptr, false);
|
2007-10-02 02:41:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
else if (aEvent->message == NS_MOUSE_MOVE &&
|
|
|
|
(onmenu || (mMenuParent && mMenuParent->IsMenuBar()))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (gEatMouseMove) {
|
2011-10-17 07:59:28 -07:00
|
|
|
gEatMouseMove = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let the menu parent know we're the new item.
|
2011-10-17 07:59:28 -07:00
|
|
|
mMenuParent->ChangeMenuItem(this, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(weakFrame.IsAlive(), NS_OK);
|
|
|
|
NS_ENSURE_TRUE(mMenuParent, NS_OK);
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// we need to check if we really became the current menu
|
|
|
|
// item or not
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame *realCurrentItem = mMenuParent->GetCurrentMenuItem();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (realCurrentItem != this) {
|
|
|
|
// we didn't (presumably because a context menu was active)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// Hovering over a menu in a popup should open it without a need for a click.
|
|
|
|
// A timer is used so that it doesn't open if the user moves the mouse quickly
|
|
|
|
// past the menu. This conditional check ensures that only menus have this
|
|
|
|
// behaviour
|
|
|
|
if (!IsDisabled() && IsMenu() && !IsOpen() && !mOpenTimer && !mMenuParent->IsMenuBar()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t menuDelay =
|
2011-09-08 19:27:13 -07:00
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_SubmenuDelay, 300); // ms
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// We're a menu, we're built, we're closed, and no timer has been kicked off.
|
|
|
|
mOpenTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
mOpenTimer->InitWithCallback(mTimerMediator, menuDelay, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuFrame::ToggleMenuState()
|
2007-06-29 12:04:45 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
if (IsOpen())
|
2011-10-17 07:59:28 -07:00
|
|
|
CloseMenu(false);
|
2007-12-03 08:33:42 -08:00
|
|
|
else
|
2011-10-17 07:59:28 -07:00
|
|
|
OpenMenu(false);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::PopupOpened()
|
|
|
|
{
|
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::open,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("true"), true);
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mMenuParent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mMenuParent->SetActive(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make sure the current menu which is being toggled on
|
|
|
|
// the menubar is highlighted
|
|
|
|
mMenuParent->SetCurrentMenuItem(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuFrame::PopupClosed(bool aDeselectMenu)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsWeakFrame weakFrame(this);
|
2008-12-03 02:56:58 -08:00
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new nsUnsetAttrRunnable(mContent, nsGkAtoms::open));
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
// if the popup is for a menu on a menubar, inform menubar to deactivate
|
|
|
|
if (mMenuParent && mMenuParent->MenuClosed()) {
|
2007-07-25 21:14:32 -07:00
|
|
|
if (aDeselectMenu) {
|
2011-10-17 07:59:28 -07:00
|
|
|
SelectMenu(false);
|
2007-07-25 21:14:32 -07:00
|
|
|
} else {
|
|
|
|
// We are not deselecting the parent menu while closing the popup, so send
|
|
|
|
// a DOMMenuItemActive event to the menu to indicate that the menu is
|
|
|
|
// becoming active again.
|
|
|
|
nsMenuFrame *current = mMenuParent->GetCurrentMenuItem();
|
|
|
|
if (current) {
|
2013-01-11 12:21:48 -08:00
|
|
|
// However, if the menu is a descendant on a menubar, and the menubar
|
|
|
|
// has the 'stay active' flag set, it means that the menubar is switching
|
|
|
|
// to another toplevel menu entirely (for example from Edit to View), so
|
|
|
|
// don't fire the DOMMenuItemActive event or else we'll send extraneous
|
|
|
|
// events for submenus. nsMenuBarFrame::ChangeMenuItem has already deselected
|
|
|
|
// the old menu, so it doesn't need to happen again here, and the new
|
|
|
|
// menu can be selected right away.
|
|
|
|
nsIFrame* parent = current;
|
|
|
|
while (parent) {
|
|
|
|
nsMenuBarFrame* menubar = do_QueryFrame(parent);
|
|
|
|
if (menubar && menubar->GetStayActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
2007-07-25 21:14:32 -07:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new nsMenuActivateEvent(current->GetContent(),
|
2011-10-17 07:59:28 -07:00
|
|
|
PresContext(), true);
|
2007-07-25 21:14:32 -07:00
|
|
|
NS_DispatchToCurrentThread(event);
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-25 21:14:32 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-29 15:15:59 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuFrame::SelectMenu(bool aActivateFlag)
|
2007-06-29 15:15:59 -07:00
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mContent) {
|
2007-07-11 05:05:40 -07:00
|
|
|
// When a menu opens a submenu, the mouse will often be moved onto a
|
|
|
|
// sibling before moving onto an item within the submenu, causing the
|
|
|
|
// parent to become deselected. We need to ensure that the parent menu
|
|
|
|
// is reselected when an item in the submenu is selected, so navigate up
|
|
|
|
// from the item to its popup, and then to the popup above that.
|
|
|
|
if (aActivateFlag) {
|
|
|
|
nsIFrame* parent = GetParent();
|
|
|
|
while (parent) {
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuPopupFrame* menupopup = do_QueryFrame(parent);
|
|
|
|
if (menupopup) {
|
2007-07-11 05:05:40 -07:00
|
|
|
// a menu is always the direct parent of a menupopup
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(menupopup->GetParent());
|
|
|
|
if (menu) {
|
2007-07-11 05:05:40 -07:00
|
|
|
// a popup however is not necessarily the direct parent of a menu
|
2012-07-30 17:43:28 -07:00
|
|
|
nsIFrame* popupParent = menu->GetParent();
|
2007-07-11 05:05:40 -07:00
|
|
|
while (popupParent) {
|
2012-07-30 17:43:28 -07:00
|
|
|
menupopup = do_QueryFrame(popupParent);
|
|
|
|
if (menupopup) {
|
|
|
|
menupopup->SetCurrentMenuItem(menu);
|
2007-07-11 05:05:40 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
popupParent = popupParent->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// cancel the close timer if selecting a menu within the popup to be closed
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
|
|
|
pm->CancelMenuTimer(mMenuParent);
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new nsMenuActivateEvent(mContent, PresContext(), aActivateFlag);
|
|
|
|
NS_DispatchToCurrentThread(event);
|
2007-06-29 15:15:59 -07:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-06-29 15:15:59 -07:00
|
|
|
return NS_OK;
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMenuFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-02-13 04:28:00 -08:00
|
|
|
if (aAttribute == nsGkAtoms::acceltext && mIgnoreAccelTextChange) {
|
|
|
|
// Reset the flag so that only one change is ignored.
|
2011-10-17 07:59:28 -07:00
|
|
|
mIgnoreAccelTextChange = false;
|
2011-02-13 04:28:00 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-12 04:59:03 -07:00
|
|
|
if (aAttribute == nsGkAtoms::checked ||
|
|
|
|
aAttribute == nsGkAtoms::acceltext ||
|
|
|
|
aAttribute == nsGkAtoms::key ||
|
|
|
|
aAttribute == nsGkAtoms::type ||
|
|
|
|
aAttribute == nsGkAtoms::name) {
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
|
|
|
new nsMenuAttributeChangedEvent(this, aAttribute);
|
|
|
|
nsContentUtils::AddScriptRunner(event);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-28 08:28:45 -08:00
|
|
|
nsIContent*
|
|
|
|
nsMenuFrame::GetAnchor()
|
|
|
|
{
|
|
|
|
mozilla::dom::Element* anchor = nullptr;
|
|
|
|
|
|
|
|
nsAutoString id;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::anchor, id);
|
|
|
|
if (!id.IsEmpty()) {
|
|
|
|
nsIDocument* doc = mContent->OwnerDoc();
|
|
|
|
|
|
|
|
anchor =
|
|
|
|
doc->GetAnonymousElementByAttribute(mContent, nsGkAtoms::anonid, id);
|
|
|
|
if (!anchor) {
|
|
|
|
anchor = doc->GetElementById(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always return the menu's content if the anchor wasn't set or wasn't found.
|
|
|
|
return anchor && anchor->GetPrimaryFrame() ? anchor : mContent;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuFrame::OpenMenu(bool aSelectFirstItem)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mContent)
|
2007-06-29 15:15:59 -07:00
|
|
|
return;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
gEatMouseMove = true;
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
pm->KillMenuTimer();
|
|
|
|
// This opens the menu asynchronously
|
2011-10-17 07:59:28 -07:00
|
|
|
pm->ShowMenu(mContent, aSelectFirstItem, true);
|
2007-06-29 15:15:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuFrame::CloseMenu(bool aDeselectMenu)
|
2007-06-29 15:15:59 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
gEatMouseMove = true;
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
// Close the menu asynchronously
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2012-03-07 17:57:37 -08:00
|
|
|
if (pm && HasPopup())
|
2014-04-08 05:45:52 -07:00
|
|
|
pm->HidePopup(GetPopup()->GetContent(), false, aDeselectMenu, true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsMenuFrame::IsSizedToPopup(nsIContent* aContent, bool aRequireAlways)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-01-14 19:07:31 -08:00
|
|
|
nsAutoString sizedToPopup;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::sizetopopup, sizedToPopup);
|
|
|
|
return sizedToPopup.EqualsLiteral("always") ||
|
|
|
|
(!aRequireAlways && sizedToPopup.EqualsLiteral("pref"));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsMenuFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
|
|
|
|
{
|
|
|
|
nsSize size = nsBoxFrame::GetMinSize(aBoxLayoutState);
|
|
|
|
DISPLAY_MIN_SIZE(this, size);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
if (IsSizedToPopup(mContent, true))
|
2007-03-22 10:30:00 -07:00
|
|
|
SizeToPopup(aBoxLayoutState, size);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::DoLayout(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
// lay us out
|
|
|
|
nsresult rv = nsBoxFrame::DoLayout(aState);
|
|
|
|
|
2012-03-07 17:57:37 -08:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopup();
|
|
|
|
if (popupFrame) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool sizeToPopup = IsSizedToPopup(mContent, false);
|
2014-01-28 08:28:45 -08:00
|
|
|
popupFrame->LayoutPopup(aState, this, GetAnchor()->GetPrimaryFrame(), sizeToPopup);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuFrame::SetDebug(nsBoxLayoutState& aState, bool aDebug)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// see if our state matches the given debug state
|
2011-09-28 23:19:26 -07:00
|
|
|
bool debugSet = mState & NS_STATE_CURRENTLY_IN_DEBUG;
|
|
|
|
bool debugChanged = (!aDebug && debugSet) || (aDebug && !debugSet);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// if it doesn't then tell each child below us the new debug state
|
|
|
|
if (debugChanged)
|
|
|
|
{
|
|
|
|
nsBoxFrame::SetDebug(aState, aDebug);
|
2012-03-07 17:57:37 -08:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopup();
|
|
|
|
if (popupFrame)
|
|
|
|
SetDebug(aState, popupFrame, aDebug);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuFrame::SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, bool aDebug)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aList)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
while (aList) {
|
|
|
|
if (aList->IsBoxFrame())
|
|
|
|
aList->SetDebug(aState, aDebug);
|
|
|
|
|
|
|
|
aList = aList->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// Enter
|
|
|
|
//
|
|
|
|
// Called when the user hits the <Enter>/<Return> keys or presses the
|
|
|
|
// shortcut key. If this is a leaf item, the item's action will be executed.
|
|
|
|
// In either case, do nothing if the item is disabled.
|
|
|
|
//
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame*
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuFrame::Enter(WidgetGUIEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (IsDisabled()) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// behavior on Windows - close the popup chain
|
2007-07-04 08:49:38 -07:00
|
|
|
if (mMenuParent) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2007-09-18 08:00:43 -07:00
|
|
|
if (pm) {
|
|
|
|
nsIFrame* popup = pm->GetTopPopup(ePopupTypeAny);
|
|
|
|
if (popup)
|
2014-04-08 05:45:52 -07:00
|
|
|
pm->HidePopup(popup->GetContent(), true, true, true, false);
|
2007-09-18 08:00:43 -07:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // #ifdef XP_WIN
|
|
|
|
// this menu item was disabled - exit
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
if (!IsOpen()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The enter key press applies to us.
|
|
|
|
if (!IsMenu() && mMenuParent)
|
2011-04-13 10:53:24 -07:00
|
|
|
Execute(aEvent); // Execute our event handler
|
2007-07-04 08:49:38 -07:00
|
|
|
else
|
|
|
|
return this;
|
2007-06-29 15:15:59 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame::IsOpen()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopup();
|
|
|
|
return popupFrame && popupFrame->IsOpen();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuFrame::IsMenu()
|
|
|
|
{
|
|
|
|
return mIsMenu;
|
|
|
|
}
|
|
|
|
|
2011-06-24 14:00:35 -07:00
|
|
|
nsMenuListType
|
|
|
|
nsMenuFrame::GetParentMenuListType()
|
|
|
|
{
|
|
|
|
if (mMenuParent && mMenuParent->IsMenu()) {
|
|
|
|
nsMenuPopupFrame* popupFrame = static_cast<nsMenuPopupFrame*>(mMenuParent);
|
|
|
|
nsIFrame* parentMenu = popupFrame->GetParent();
|
|
|
|
if (parentMenu) {
|
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menulist = do_QueryInterface(parentMenu->GetContent());
|
|
|
|
if (menulist) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEditable = false;
|
2011-06-24 14:00:35 -07:00
|
|
|
menulist->GetEditable(&isEditable);
|
|
|
|
return isEditable ? eEditableMenuList : eReadonlyMenuList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return eNotMenuList;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsMenuFrame::Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
// Our timer has fired.
|
|
|
|
if (aTimer == mOpenTimer.get()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mOpenTimer = nullptr;
|
2007-07-04 08:49:38 -07:00
|
|
|
|
|
|
|
if (!IsOpen() && mMenuParent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// make sure we didn't open a context menu in the meantime
|
|
|
|
// (i.e. the user right-clicked while hovering over a submenu).
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2012-07-30 07:20:58 -07:00
|
|
|
if ((!pm->HasContextMenu(nullptr) || mMenuParent->IsContextMenu()) &&
|
2007-07-04 08:49:38 -07:00
|
|
|
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::menuactive,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
OpenMenu(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-19 07:12:58 -07:00
|
|
|
} else if (aTimer == mBlinkTimer) {
|
|
|
|
switch (mBlinkState++) {
|
|
|
|
case 0:
|
|
|
|
NS_ASSERTION(false, "Blink timer fired while not blinking");
|
|
|
|
StopBlinking();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// Turn the highlight back on and wait for a while before closing the menu.
|
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::menuactive,
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_LITERAL_STRING("true"), true);
|
2010-04-19 07:12:58 -07:00
|
|
|
if (weakFrame.IsAlive()) {
|
|
|
|
aTimer->InitWithCallback(mTimerMediator, kBlinkDelay, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (mMenuParent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mMenuParent->LockMenuUntilClosed(false);
|
2010-04-19 07:12:58 -07:00
|
|
|
}
|
|
|
|
PassMenuCommandEventToPopupManager();
|
|
|
|
StopBlinking();
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuFrame::IsDisabled()
|
|
|
|
{
|
|
|
|
return mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::UpdateMenuType(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::checkbox, &nsGkAtoms::radio, nullptr};
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0: mType = eMenuType_Checkbox; break;
|
|
|
|
case 1:
|
|
|
|
mType = eMenuType_Radio;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::name, mGroupName);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (mType != eMenuType_Normal) {
|
|
|
|
nsWeakFrame weakFrame(this);
|
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::checked,
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
ENSURE_TRUE(weakFrame.IsAlive());
|
|
|
|
}
|
|
|
|
mType = eMenuType_Normal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
UpdateMenuSpecialState(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update checked-ness for type="checkbox" and type="radio" */
|
|
|
|
void
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame::UpdateMenuSpecialState(nsPresContext* aPresContext)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool newChecked =
|
2007-03-22 10:30:00 -07:00
|
|
|
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::checked,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
|
|
if (newChecked == mChecked) {
|
|
|
|
/* checked state didn't change */
|
|
|
|
|
|
|
|
if (mType != eMenuType_Radio)
|
|
|
|
return; // only Radio possibly cares about other kinds of change
|
|
|
|
|
|
|
|
if (!mChecked || mGroupName.IsEmpty())
|
|
|
|
return; // no interesting change
|
|
|
|
} else {
|
|
|
|
mChecked = newChecked;
|
|
|
|
if (mType != eMenuType_Radio || !mChecked)
|
|
|
|
/*
|
|
|
|
* Unchecking something requires no further changes, and only
|
|
|
|
* menuRadio has to do additional work when checked.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we get this far, we're type=radio, and:
|
|
|
|
* - our name= changed, or
|
|
|
|
* - we went from checked="false" to checked="true"
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Behavioural note:
|
|
|
|
* If we're checked and renamed _into_ an existing radio group, we are
|
|
|
|
* made the new checked item, and we unselect the previous one.
|
|
|
|
*
|
|
|
|
* The only other reasonable behaviour would be to check for another selected
|
|
|
|
* item in that group. If found, unselect ourselves, otherwise we're the
|
|
|
|
* selected item. That, however, would be a lot more work, and I don't think
|
|
|
|
* it's better at all.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* walk siblings, looking for the other checked item with the same name */
|
|
|
|
// get the first sibling in this menu popup. This frame may be it, and if we're
|
|
|
|
// being called at creation time, this frame isn't yet in the parent's child list.
|
|
|
|
// All I'm saying is that this may fail, but it's most likely alright.
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* sib = GetParent()->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
while (sib) {
|
2012-07-30 17:43:28 -07:00
|
|
|
if (sib != this) {
|
|
|
|
nsMenuFrame* menu = do_QueryFrame(sib);
|
|
|
|
if (menu && menu->GetMenuType() == eMenuType_Radio &&
|
|
|
|
menu->IsChecked() && menu->GetRadioGroupName() == mGroupName) {
|
2007-07-04 08:49:38 -07:00
|
|
|
/* uncheck the old item */
|
|
|
|
sib->GetContent()->UnsetAttr(kNameSpaceID_None, nsGkAtoms::checked,
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-07-04 08:49:38 -07:00
|
|
|
/* XXX in DEBUG, check to make sure that there aren't two checked items */
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
sib = sib->GetNextSibling();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsMenuFrame::BuildAcceleratorText(bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsAutoString accelText;
|
|
|
|
|
|
|
|
if ((GetStateBits() & NS_STATE_ACCELTEXT_IS_DERIVED) == 0) {
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, accelText);
|
|
|
|
if (!accelText.IsEmpty())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// accelText is definitely empty here.
|
|
|
|
|
|
|
|
// Now we're going to compute the accelerator text, so remember that we did.
|
|
|
|
AddStateBits(NS_STATE_ACCELTEXT_IS_DERIVED);
|
|
|
|
|
|
|
|
// If anything below fails, just leave the accelerator text blank.
|
|
|
|
nsWeakFrame weakFrame(this);
|
2011-02-13 04:28:00 -08:00
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
ENSURE_TRUE(weakFrame.IsAlive());
|
|
|
|
|
|
|
|
// See if we have a key node and use that instead.
|
|
|
|
nsAutoString keyValue;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyValue);
|
|
|
|
if (keyValue.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Turn the document into a DOM document so we can use getElementById
|
2010-06-23 14:35:57 -07:00
|
|
|
nsIDocument *document = mContent->GetDocument();
|
|
|
|
if (!document)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2010-06-23 14:35:57 -07:00
|
|
|
nsIContent *keyElement = document->GetElementById(keyValue);
|
|
|
|
if (!keyElement) {
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsAutoString label;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, label);
|
|
|
|
nsAutoString msg = NS_LITERAL_STRING("Key '") +
|
|
|
|
keyValue +
|
|
|
|
NS_LITERAL_STRING("' of menu item '") +
|
|
|
|
label +
|
|
|
|
NS_LITERAL_STRING("' could not be found");
|
|
|
|
NS_WARNING(NS_ConvertUTF16toUTF8(msg).get());
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the string to display as accelerator text
|
|
|
|
// check the key element's attributes in this order:
|
|
|
|
// |keytext|, |key|, |keycode|
|
|
|
|
nsAutoString accelString;
|
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::keytext, accelString);
|
|
|
|
|
|
|
|
if (accelString.IsEmpty()) {
|
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::key, accelString);
|
|
|
|
|
|
|
|
if (!accelString.IsEmpty()) {
|
|
|
|
ToUpperCase(accelString);
|
|
|
|
} else {
|
|
|
|
nsAutoString keyCode;
|
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::keycode, keyCode);
|
|
|
|
ToUpperCase(keyCode);
|
|
|
|
|
|
|
|
nsresult rv;
|
2010-05-14 02:24:41 -07:00
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
|
|
|
if (bundleService) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
rv = bundleService->CreateBundle("chrome://global/locale/keys.properties",
|
|
|
|
getter_AddRefs(bundle));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && bundle) {
|
|
|
|
nsXPIDLString keyName;
|
|
|
|
rv = bundle->GetStringFromName(keyCode.get(), getter_Copies(keyName));
|
|
|
|
if (keyName)
|
|
|
|
accelString = keyName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nothing usable found, bail
|
|
|
|
if (accelString.IsEmpty())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString modifiers;
|
|
|
|
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiers);
|
|
|
|
|
|
|
|
char* str = ToNewCString(modifiers);
|
|
|
|
char* newStr;
|
|
|
|
char* token = nsCRT::strtok(str, ", \t", &newStr);
|
2011-07-31 12:43:54 -07:00
|
|
|
|
|
|
|
nsAutoString shiftText;
|
|
|
|
nsAutoString altText;
|
|
|
|
nsAutoString metaText;
|
|
|
|
nsAutoString controlText;
|
2012-07-18 18:28:16 -07:00
|
|
|
nsAutoString osText;
|
2011-07-31 12:43:54 -07:00
|
|
|
nsAutoString modifierSeparator;
|
|
|
|
|
|
|
|
nsContentUtils::GetShiftText(shiftText);
|
|
|
|
nsContentUtils::GetAltText(altText);
|
|
|
|
nsContentUtils::GetMetaText(metaText);
|
|
|
|
nsContentUtils::GetControlText(controlText);
|
2012-07-18 18:28:16 -07:00
|
|
|
nsContentUtils::GetOSText(osText);
|
2011-07-31 12:43:54 -07:00
|
|
|
nsContentUtils::GetModifierSeparatorText(modifierSeparator);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
while (token) {
|
|
|
|
|
|
|
|
if (PL_strcmp(token, "shift") == 0)
|
2011-07-31 12:43:54 -07:00
|
|
|
accelText += shiftText;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (PL_strcmp(token, "alt") == 0)
|
2011-07-31 12:43:54 -07:00
|
|
|
accelText += altText;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (PL_strcmp(token, "meta") == 0)
|
2011-07-31 12:43:54 -07:00
|
|
|
accelText += metaText;
|
2012-07-18 18:28:16 -07:00
|
|
|
else if (PL_strcmp(token, "os") == 0)
|
|
|
|
accelText += osText;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (PL_strcmp(token, "control") == 0)
|
2011-07-31 12:43:54 -07:00
|
|
|
accelText += controlText;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (PL_strcmp(token, "accel") == 0) {
|
2014-05-21 21:06:06 -07:00
|
|
|
switch (WidgetInputEvent::AccelModifier()) {
|
|
|
|
case MODIFIER_META:
|
2011-07-31 12:43:54 -07:00
|
|
|
accelText += metaText;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2014-05-21 21:06:06 -07:00
|
|
|
case MODIFIER_OS:
|
2012-07-18 18:28:16 -07:00
|
|
|
accelText += osText;
|
|
|
|
break;
|
2014-05-21 21:06:06 -07:00
|
|
|
case MODIFIER_ALT:
|
2011-07-31 12:43:54 -07:00
|
|
|
accelText += altText;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2014-05-21 21:06:06 -07:00
|
|
|
case MODIFIER_CONTROL:
|
2011-07-31 12:43:54 -07:00
|
|
|
accelText += controlText;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2014-05-21 21:06:06 -07:00
|
|
|
default:
|
|
|
|
MOZ_CRASH(
|
|
|
|
"Handle the new result of WidgetInputEvent::AccelModifier()");
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-31 12:43:54 -07:00
|
|
|
accelText += modifierSeparator;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
token = nsCRT::strtok(newStr, ", \t", &newStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMemory::Free(str);
|
|
|
|
|
|
|
|
accelText += accelString;
|
2011-02-13 04:28:00 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIgnoreAccelTextChange = true;
|
2011-02-13 04:28:00 -08:00
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::acceltext, accelText, aNotify);
|
|
|
|
ENSURE_TRUE(weakFrame.IsAlive());
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIgnoreAccelTextChange = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuFrame::Execute(WidgetGUIEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// flip "checked" state if we're a checkbox menu, or an un-checked radio menu
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needToFlipChecked = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mType == eMenuType_Checkbox || (mType == eMenuType_Radio && !mChecked)) {
|
2010-04-19 07:12:58 -07:00
|
|
|
needToFlipChecked = !mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::autocheck,
|
|
|
|
nsGkAtoms::_false, eCaseMatters);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-12-10 09:23:20 -08:00
|
|
|
nsCOMPtr<nsISound> sound(do_CreateInstance("@mozilla.org/sound;1"));
|
|
|
|
if (sound)
|
2009-07-08 18:55:46 -07:00
|
|
|
sound->PlayEventSound(nsISound::EVENT_MENU_EXECUTE);
|
2008-12-10 09:23:20 -08:00
|
|
|
|
2010-04-19 07:12:58 -07:00
|
|
|
StartBlinking(aEvent, needToFlipChecked);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-04-19 07:12:58 -07:00
|
|
|
nsMenuFrame::ShouldBlink()
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t shouldBlink =
|
2011-09-08 19:27:13 -07:00
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_ChosenMenuItemsShouldBlink, 0);
|
2010-04-19 07:12:58 -07:00
|
|
|
if (!shouldBlink)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-19 07:12:58 -07:00
|
|
|
|
|
|
|
// Don't blink in editable menulists.
|
2011-06-24 14:00:35 -07:00
|
|
|
if (GetParentMenuListType() == eEditableMenuList)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-06-24 14:00:35 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-04-19 07:12:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuFrame::StartBlinking(WidgetGUIEvent* aEvent, bool aFlipChecked)
|
2010-04-19 07:12:58 -07:00
|
|
|
{
|
|
|
|
StopBlinking();
|
|
|
|
CreateMenuCommandEvent(aEvent, aFlipChecked);
|
|
|
|
|
|
|
|
if (!ShouldBlink()) {
|
|
|
|
PassMenuCommandEventToPopupManager();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blink off.
|
|
|
|
nsWeakFrame weakFrame(this);
|
2011-10-17 07:59:28 -07:00
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::menuactive, true);
|
2010-04-19 07:12:58 -07:00
|
|
|
if (!weakFrame.IsAlive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mMenuParent) {
|
|
|
|
// Make this menu ignore events from now on.
|
2011-10-17 07:59:28 -07:00
|
|
|
mMenuParent->LockMenuUntilClosed(true);
|
2010-04-19 07:12:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up a timer to blink back on.
|
|
|
|
mBlinkTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
mBlinkTimer->InitWithCallback(mTimerMediator, kBlinkDelay, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
mBlinkState = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::StopBlinking()
|
|
|
|
{
|
|
|
|
mBlinkState = 0;
|
|
|
|
if (mBlinkTimer) {
|
|
|
|
mBlinkTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mBlinkTimer = nullptr;
|
2010-04-19 07:12:58 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mDelayedMenuCommandEvent = nullptr;
|
2010-04-19 07:12:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-01 20:46:03 -07:00
|
|
|
nsMenuFrame::CreateMenuCommandEvent(WidgetGUIEvent* aEvent, bool aFlipChecked)
|
2010-04-19 07:12:58 -07:00
|
|
|
{
|
|
|
|
// Create a trusted event if the triggering event was trusted, or if
|
|
|
|
// we're called from chrome code (since at least one of our caller
|
|
|
|
// passes in a null event).
|
2012-12-15 17:26:03 -08:00
|
|
|
bool isTrusted = aEvent ? aEvent->mFlags.mIsTrusted :
|
2010-04-19 07:12:58 -07:00
|
|
|
nsContentUtils::IsCallerChrome();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shift = false, control = false, alt = false, meta = false;
|
2013-10-17 23:10:26 -07:00
|
|
|
WidgetInputEvent* inputEvent = aEvent ? aEvent->AsInputEvent() : nullptr;
|
|
|
|
if (inputEvent) {
|
|
|
|
shift = inputEvent->IsShift();
|
|
|
|
control = inputEvent->IsControl();
|
|
|
|
alt = inputEvent->IsAlt();
|
|
|
|
meta = inputEvent->IsMeta();
|
2010-04-19 07:12:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Because the command event is firing asynchronously, a flag is needed to
|
|
|
|
// indicate whether user input is being handled. This ensures that a popup
|
|
|
|
// window won't get blocked.
|
2014-03-31 21:09:23 -07:00
|
|
|
bool userinput = EventStateManager::IsHandlingUserInput();
|
2010-04-19 07:12:58 -07:00
|
|
|
|
|
|
|
mDelayedMenuCommandEvent =
|
|
|
|
new nsXULMenuCommandEvent(mContent, isTrusted, shift, control, alt, meta,
|
|
|
|
userinput, aFlipChecked);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMenuFrame::PassMenuCommandEventToPopupManager()
|
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
2010-04-19 07:12:58 -07:00
|
|
|
if (pm && mMenuParent && mDelayedMenuCommandEvent) {
|
|
|
|
pm->ExecuteMenu(mContent, mDelayedMenuCommandEvent);
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mDelayedMenuCommandEvent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMenuFrame::RemoveFrame(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
nsFrameList* popupList = GetPopupList();
|
2013-02-27 15:05:45 -08:00
|
|
|
if (popupList && popupList->FirstChild() == aOldFrame) {
|
|
|
|
popupList->RemoveFirstChild();
|
|
|
|
aOldFrame->Destroy();
|
2012-03-07 17:57:37 -08:00
|
|
|
DestroyPopupList();
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell()->
|
2007-05-06 12:16:51 -07:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2012-03-07 17:57:37 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-07 17:57:37 -08:00
|
|
|
return nsBoxFrame::RemoveFrame(aListID, aOldFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMenuFrame::InsertFrames(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
if (!HasPopup() && (aListID == kPrincipalList || aListID == kPopupList)) {
|
2009-07-30 10:23:32 -07:00
|
|
|
SetPopupFrame(aFrameList);
|
2012-03-07 17:57:37 -08:00
|
|
|
if (HasPopup()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG_LAYOUT
|
2007-11-17 07:47:38 -08:00
|
|
|
nsBoxLayoutState state(PresContext());
|
|
|
|
SetDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2007-11-17 07:47:38 -08:00
|
|
|
|
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-10-19 22:43:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-30 10:23:32 -07:00
|
|
|
if (aFrameList.IsEmpty())
|
2007-11-17 07:47:38 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(aPrevFrame && aPrevFrame == GetPopup())) {
|
2012-07-30 07:20:58 -07:00
|
|
|
aPrevFrame = nullptr;
|
2007-11-17 07:47:38 -08:00
|
|
|
}
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
return nsBoxFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMenuFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
if (!HasPopup() && (aListID == kPrincipalList || aListID == kPopupList)) {
|
2009-07-30 10:23:32 -07:00
|
|
|
SetPopupFrame(aFrameList);
|
2012-03-07 17:57:37 -08:00
|
|
|
if (HasPopup()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
2007-11-17 07:47:38 -08:00
|
|
|
nsBoxLayoutState state(PresContext());
|
|
|
|
SetDebug(state, aFrameList, mState & NS_STATE_CURRENTLY_IN_DEBUG);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2007-11-17 07:47:38 -08:00
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-30 10:23:32 -07:00
|
|
|
if (aFrameList.IsEmpty())
|
2007-11-17 07:47:38 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
return nsBoxFrame::AppendFrames(aListID, aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuFrame::SizeToPopup(nsBoxLayoutState& aState, nsSize& aSize)
|
|
|
|
{
|
2011-06-15 14:03:49 -07:00
|
|
|
if (!IsCollapsed()) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool widthSet, heightSet;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSize tmpSize(-1, 0);
|
2012-08-05 20:00:57 -07:00
|
|
|
nsIFrame::AddCSSPrefSize(this, tmpSize, widthSet, heightSet);
|
2010-03-18 12:58:15 -07:00
|
|
|
if (!widthSet && GetFlex(aState) == 0) {
|
2012-03-07 17:57:37 -08:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopup();
|
|
|
|
if (!popupFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-03-07 17:57:37 -08:00
|
|
|
tmpSize = popupFrame->GetPrefSize(aState);
|
2011-06-29 14:39:21 -07:00
|
|
|
|
|
|
|
// Produce a size such that:
|
|
|
|
// (1) the menu and its popup can be the same width
|
|
|
|
// (2) there's enough room in the menu for the content and its
|
|
|
|
// border-padding
|
|
|
|
// (3) there's enough room in the popup for the content and its
|
|
|
|
// scrollbar
|
|
|
|
nsMargin borderPadding;
|
|
|
|
GetBorderAndPadding(borderPadding);
|
2010-09-15 08:25:08 -07:00
|
|
|
|
|
|
|
// if there is a scroll frame, add the desired width of the scrollbar as well
|
2012-03-07 17:57:37 -08:00
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(popupFrame->GetFirstPrincipalChild());
|
2011-06-29 14:39:21 -07:00
|
|
|
nscoord scrollbarWidth = 0;
|
2010-09-15 08:25:08 -07:00
|
|
|
if (scrollFrame) {
|
2011-06-29 14:39:21 -07:00
|
|
|
scrollbarWidth =
|
|
|
|
scrollFrame->GetDesiredScrollbarSizes(&aState).LeftRight();
|
2010-09-15 08:25:08 -07:00
|
|
|
}
|
|
|
|
|
2011-06-29 14:39:21 -07:00
|
|
|
aSize.width =
|
2013-01-15 04:22:03 -08:00
|
|
|
tmpSize.width + std::max(borderPadding.LeftRight(), scrollbarWidth);
|
2011-06-29 14:39:21 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSize
|
|
|
|
nsMenuFrame::GetPrefSize(nsBoxLayoutState& aState)
|
|
|
|
{
|
|
|
|
nsSize size = nsBoxFrame::GetPrefSize(aState);
|
|
|
|
DISPLAY_PREF_SIZE(this, size);
|
|
|
|
|
|
|
|
// If we are using sizetopopup="always" then
|
|
|
|
// nsBoxFrame will already have enforced the minimum size
|
2011-10-17 07:59:28 -07:00
|
|
|
if (!IsSizedToPopup(mContent, true) &&
|
|
|
|
IsSizedToPopup(mContent, false) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
SizeToPopup(aState, size)) {
|
|
|
|
// We now need to ensure that size is within the min - max range.
|
|
|
|
nsSize minSize = nsBoxFrame::GetMinSize(aState);
|
|
|
|
nsSize maxSize = GetMaxSize(aState);
|
2008-01-04 21:49:44 -08:00
|
|
|
size = BoundsCheck(minSize, size, maxSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::GetActiveChild(nsIDOMElement** aResult)
|
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopup();
|
|
|
|
if (!popupFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-03-07 17:57:37 -08:00
|
|
|
nsMenuFrame* menuFrame = popupFrame->GetCurrentMenuItem();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!menuFrame) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2007-07-04 08:49:38 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(menuFrame->GetContent()));
|
2007-03-22 10:30:00 -07:00
|
|
|
*aResult = elt;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMenuFrame::SetActiveChild(nsIDOMElement* aChild)
|
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopup();
|
|
|
|
if (!popupFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!aChild) {
|
|
|
|
// Remove the current selection
|
2012-07-30 07:20:58 -07:00
|
|
|
popupFrame->ChangeMenuItem(nullptr, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child(do_QueryInterface(aChild));
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(child->GetPrimaryFrame());
|
|
|
|
if (menu)
|
|
|
|
popupFrame->ChangeMenuItem(menu, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-01 04:22:31 -07:00
|
|
|
nsIScrollableFrame* nsMenuFrame::GetScrollTargetFrame()
|
|
|
|
{
|
2012-03-07 17:57:37 -08:00
|
|
|
nsMenuPopupFrame* popupFrame = GetPopup();
|
|
|
|
if (!popupFrame)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-07 17:57:37 -08:00
|
|
|
nsIFrame* childFrame = popupFrame->GetFirstPrincipalChild();
|
2009-09-01 04:22:31 -07:00
|
|
|
if (childFrame)
|
2012-03-07 17:57:37 -08:00
|
|
|
return popupFrame->GetScrollFrame(childFrame);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-09-01 04:22:31 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsMenuTimerMediator implementation.
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsMenuTimerMediator, nsITimerCallback)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a wrapper around an nsMenuFrame.
|
|
|
|
* @param aFrame nsMenuFrame to create a wrapper around.
|
|
|
|
*/
|
|
|
|
nsMenuTimerMediator::nsMenuTimerMediator(nsMenuFrame *aFrame) :
|
|
|
|
mFrame(aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mFrame, "Must have frame");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMenuTimerMediator::~nsMenuTimerMediator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delegates the notification to the contained frame if it has not been destroyed.
|
|
|
|
* @param aTimer Timer which initiated the callback.
|
|
|
|
* @return NS_ERROR_FAILURE if the frame has been destroyed.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP nsMenuTimerMediator::Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return mFrame->Notify(aTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the pointer to the contained nsMenuFrame. This should be called
|
|
|
|
* when the contained nsMenuFrame is destroyed.
|
|
|
|
*/
|
|
|
|
void nsMenuTimerMediator::ClearFrame()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|