Bug 1494000, use Element::GetFrame in XULMenuElement and XULPopupElement, r=bz
--- a/dom/xul/XULMenuElement.cpp
+++ b/dom/xul/XULMenuElement.cpp
@@ -20,45 +20,32 @@ namespace mozilla {
namespace dom {
JSObject*
XULMenuElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return XULMenuElement_Binding::Wrap(aCx, this, aGivenProto);
}
-nsIFrame*
-XULMenuElement::GetFrame()
-{
- nsCOMPtr<nsIContent> kungFuDeathGrip = this; // keep a reference
-
- nsCOMPtr<nsIDocument> doc = GetUncomposedDoc();
- if (doc) {
- doc->FlushPendingNotifications(FlushType::Frames);
- }
-
- return GetPrimaryFrame();
-}
-
already_AddRefed<Element>
XULMenuElement::GetActiveChild()
{
- nsMenuFrame* menu = do_QueryFrame(GetFrame());
+ nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (menu) {
RefPtr<Element> el;
menu->GetActiveChild(getter_AddRefs(el));
return el.forget();
}
return nullptr;
}
void
XULMenuElement::SetActiveChild(Element* arg)
{
- nsMenuFrame* menu = do_QueryFrame(GetFrame());
+ nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (menu) {
menu->SetActiveChild(arg);
}
}
bool
XULMenuElement::HandleKeyPress(KeyboardEvent& keyEvent)
{
@@ -70,17 +57,17 @@ XULMenuElement::HandleKeyPress(KeyboardE
// if event has already been handled, bail
if (keyEvent.DefaultPrevented()) {
return false;
}
if (nsMenuBarListener::IsAccessKeyPressed(&keyEvent))
return false;
- nsMenuFrame* menu = do_QueryFrame(GetFrame());
+ nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (!menu) {
return false;
}
nsMenuPopupFrame* popupFrame = menu->GetPopup();
if (!popupFrame) {
return false;
}
@@ -99,17 +86,17 @@ XULMenuElement::HandleKeyPress(KeyboardE
default:
return pm->HandleShortcutNavigation(&keyEvent, popupFrame);
}
}
bool
XULMenuElement::OpenedWithKey()
{
- nsMenuFrame* menuframe = do_QueryFrame(GetFrame());
+ nsMenuFrame* menuframe = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (!menuframe) {
return false;
}
nsIFrame* frame = menuframe->GetParent();
while (frame) {
nsMenuBarFrame* menubar = do_QueryFrame(frame);
if (menubar) {
--- a/dom/xul/XULPopupElement.cpp
+++ b/dom/xul/XULPopupElement.cpp
@@ -28,29 +28,16 @@ NS_NewXULPopupElement(already_AddRefed<m
}
JSObject*
XULPopupElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
{
return XULPopupElement_Binding::Wrap(aCx, this, aGivenProto);
}
-nsIFrame*
-XULPopupElement::GetFrame(bool aFlushLayout)
-{
- nsCOMPtr<nsIContent> kungFuDeathGrip = this; // keep a reference
-
- nsCOMPtr<nsIDocument> doc = GetUncomposedDoc();
- if (doc) {
- doc->FlushPendingNotifications(aFlushLayout ? FlushType::Layout : FlushType::Frames);
- }
-
- return GetPrimaryFrame();
-}
-
void
XULPopupElement::OpenPopup(Element* aAnchorElement,
const StringOrOpenPopupOptions& aOptions,
int32_t aXPos, int32_t aYPos,
bool aIsContextMenu,
bool aAttributesOverride,
Event* aTriggerEvent)
{
@@ -238,17 +225,17 @@ XULPopupElement::GetAnchorNode() const
}
already_AddRefed<DOMRect>
XULPopupElement::GetOuterScreenRect()
{
RefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
// Return an empty rectangle if the popup is not open.
- nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+ nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (!menuPopupFrame || !menuPopupFrame->IsOpen()) {
return rect.forget();
}
nsView* view = menuPopupFrame->GetView();
if (view) {
nsIWidget* widget = view->GetWidget();
if (widget) {
@@ -262,17 +249,17 @@ XULPopupElement::GetOuterScreenRect()
}
void
XULPopupElement::GetAlignmentPosition(nsString& positionStr)
{
positionStr.Truncate();
// This needs to flush layout.
- nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(true));
+ nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetPrimaryFrame(FlushType::Layout));
if (!menuPopupFrame)
return;
int8_t position = menuPopupFrame->GetAlignmentPosition();
switch (position) {
case POPUPPOSITION_AFTERSTART:
positionStr.AssignLiteral("after_start");
break;
@@ -310,33 +297,33 @@ XULPopupElement::GetAlignmentPosition(ns
// Leave as an empty string.
break;
}
}
int32_t
XULPopupElement::AlignmentOffset()
{
- nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+ nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (!menuPopupFrame)
return 0;
int32_t pp = mozilla::AppUnitsPerCSSPixel();
// Note that the offset might be along either the X or Y axis, but for the
// sake of simplicity we use a point with only the X axis set so we can
// use ToNearestPixels().
nsPoint appOffset(menuPopupFrame->GetAlignmentOffset(), 0);
nsIntPoint popupOffset = appOffset.ToNearestPixels(pp);
return popupOffset.x;
}
void
XULPopupElement::SetConstraintRect(dom::DOMRectReadOnly& aRect)
{
- nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+ nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (menuPopupFrame) {
menuPopupFrame->SetOverrideConstraintRect(
LayoutDeviceIntRect::Truncate(aRect.Left(), aRect.Top(), aRect.Width(), aRect.Height()));
}
}
} // namespace dom
} // namespace mozilla
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -523,34 +523,28 @@ nsXULElement::HasMenu()
{
nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame());
return menu != nullptr;
}
void
nsXULElement::OpenMenu(bool aOpenFlag)
{
- nsCOMPtr<nsIDocument> doc = GetUncomposedDoc();
- if (doc) {
- doc->FlushPendingNotifications(FlushType::Frames);
- }
+ nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) {
if (aOpenFlag) {
// Nothing will happen if this element isn't a menu.
pm->ShowMenu(this, false, false);
}
- else {
- nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame());
- if (menu) {
- nsMenuPopupFrame* popupFrame = menu->GetPopup();
- if (popupFrame) {
- pm->HidePopup(popupFrame->GetContent(), false, true, false, false);
- }
+ else if (menu) {
+ nsMenuPopupFrame* popupFrame = menu->GetPopup();
+ if (popupFrame) {
+ pm->HidePopup(popupFrame->GetContent(), false, true, false, false);
}
}
}
}
bool
nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
bool aIsTrustedEvent)