Bug 1494000, use Element::GetFrame in XULMenuElement and XULPopupElement, r=bz

This commit is contained in:
Neil Deakin 2018-10-18 08:40:10 -04:00
Родитель 4ebf5b4364
Коммит 51f69a2c2a
3 изменённых файлов: 13 добавлений и 45 удалений

Просмотреть файл

@ -25,23 +25,10 @@ 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));
@ -53,7 +40,7 @@ XULMenuElement::GetActiveChild()
void
XULMenuElement::SetActiveChild(Element* arg)
{
nsMenuFrame* menu = do_QueryFrame(GetFrame());
nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (menu) {
menu->SetActiveChild(arg);
}
@ -75,7 +62,7 @@ XULMenuElement::HandleKeyPress(KeyboardEvent& keyEvent)
if (nsMenuBarListener::IsAccessKeyPressed(&keyEvent))
return false;
nsMenuFrame* menu = do_QueryFrame(GetFrame());
nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (!menu) {
return false;
}
@ -104,7 +91,7 @@ XULMenuElement::HandleKeyPress(KeyboardEvent& keyEvent)
bool
XULMenuElement::OpenedWithKey()
{
nsMenuFrame* menuframe = do_QueryFrame(GetFrame());
nsMenuFrame* menuframe = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (!menuframe) {
return false;
}

Просмотреть файл

@ -33,19 +33,6 @@ 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,
@ -243,7 +230,7 @@ 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();
}
@ -267,7 +254,7 @@ 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;
@ -315,7 +302,7 @@ XULPopupElement::GetAlignmentPosition(nsString& positionStr)
int32_t
XULPopupElement::AlignmentOffset()
{
nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
if (!menuPopupFrame)
return 0;
@ -331,7 +318,7 @@ XULPopupElement::AlignmentOffset()
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()));

Просмотреть файл

@ -528,10 +528,7 @@ nsXULElement::HasMenu()
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) {
@ -539,13 +536,10 @@ nsXULElement::OpenMenu(bool 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);
}
}
}