summaryrefslogtreecommitdiff
path: root/mozilla-1708709.patch
blob: 8ee1b3556d1b5a810c553fff14efa9068d10c4da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
diff -up firefox-92.0/dom/xul/XULPopupElement.cpp.1708709 firefox-92.0/dom/xul/XULPopupElement.cpp
--- firefox-92.0/dom/xul/XULPopupElement.cpp.1708709	2021-09-01 19:14:41.000000000 +0200
+++ firefox-92.0/dom/xul/XULPopupElement.cpp	2021-09-07 10:33:55.686223973 +0200
@@ -271,8 +271,7 @@ already_AddRefed<DOMRect> XULPopupElemen
     // For native menus we can't query the true size. Use the anchor rect
     // instead, which at least has the position at which we were intending to
     // open the menu.
-    screenRect = Some(CSSRect(
-        CSSIntRect::FromUnknownRect(menuPopupFrame->GetScreenAnchorRect())));
+    screenRect = Some(CSSRect(menuPopupFrame->GetScreenAnchorRect()));
   } else {
     // For non-native menus, query the bounds from the widget.
     if (nsView* view = menuPopupFrame->GetView()) {
diff -up firefox-92.0/layout/xul/nsMenuPopupFrame.cpp.1708709 firefox-92.0/layout/xul/nsMenuPopupFrame.cpp
--- firefox-92.0/layout/xul/nsMenuPopupFrame.cpp.1708709	2021-09-01 19:15:06.000000000 +0200
+++ firefox-92.0/layout/xul/nsMenuPopupFrame.cpp	2021-09-07 10:33:55.686223973 +0200
@@ -868,8 +868,9 @@ void nsMenuPopupFrame::InitializePopup(n
       InitPositionFromAnchorAlign(anchor, align);
     }
   }
-
-  mScreenRect = nsIntRect(-1, -1, 0, 0);
+  // When converted back to CSSIntRect it is (-1, -1, 0, 0) - as expected in
+  // nsXULPopupManager::Rollup
+  mScreenRect = nsRect(-AppUnitsPerCSSPixel(), -AppUnitsPerCSSPixel(), 0, 0);
 
   if (aAttributesOverride) {
     // Use |left| and |top| dimension attributes to position the popup if
@@ -881,11 +882,15 @@ void nsMenuPopupFrame::InitializePopup(n
     nsresult err;
     if (!left.IsEmpty()) {
       int32_t x = left.ToInteger(&err);
-      if (NS_SUCCEEDED(err)) mScreenRect.x = x;
+      if (NS_SUCCEEDED(err)) {
+        mScreenRect.x = CSSPixel::ToAppUnits(x);
+      }
     }
     if (!top.IsEmpty()) {
       int32_t y = top.ToInteger(&err);
-      if (NS_SUCCEEDED(err)) mScreenRect.y = y;
+      if (NS_SUCCEEDED(err)) {
+        mScreenRect.y = CSSPixel::ToAppUnits(y);
+      }
     }
   }
 }
@@ -900,7 +905,8 @@ void nsMenuPopupFrame::InitializePopupAt
   mPopupState = ePopupShowing;
   mAnchorContent = nullptr;
   mTriggerContent = aTriggerContent;
-  mScreenRect = nsIntRect(aXPos, aYPos, 0, 0);
+  mScreenRect =
+      nsRect(CSSPixel::ToAppUnits(aXPos), CSSPixel::ToAppUnits(aYPos), 0, 0);
   mXPos = 0;
   mYPos = 0;
   mFlip = FlipType_Default;
@@ -920,7 +926,8 @@ void nsMenuPopupFrame::InitializePopupAs
   mTriggerContent = aTriggerContent;
   mPopupState = ePopupShowing;
   mAnchorContent = nullptr;
-  mScreenRect = nsIntRect(aXPos, aYPos, 0, 0);
+  mScreenRect =
+      nsRect(CSSPixel::ToAppUnits(aXPos), CSSPixel::ToAppUnits(aYPos), 0, 0);
   mXPos = 0;
   mYPos = 0;
   mFlip = FlipType_Default;
@@ -941,7 +948,7 @@ void nsMenuPopupFrame::InitializePopupAt
                                              bool aAttributesOverride) {
   InitializePopup(nullptr, aTriggerContent, aPosition, 0, 0,
                   MenuPopupAnchorType_Rect, aAttributesOverride);
-  mScreenRect = aRect;
+  mScreenRect = ToAppUnits(aRect, AppUnitsPerCSSPixel());
 }
 
 void nsMenuPopupFrame::ShowPopup(bool aIsContextMenu) {
@@ -1430,7 +1437,7 @@ nsresult nsMenuPopupFrame::SetPopupPosit
     // If anchored to a rectangle, use that rectangle. Otherwise, determine the
     // rectangle from the anchor.
     if (mAnchorType == MenuPopupAnchorType_Rect) {
-      anchorRect = ToAppUnits(mScreenRect, AppUnitsPerCSSPixel());
+      anchorRect = mScreenRect;
     } else {
       // if the frame is not specified, use the anchor node passed to OpenPopup.
       // If that wasn't specified either, use the root frame. Note that
@@ -1517,7 +1524,7 @@ nsresult nsMenuPopupFrame::SetPopupPosit
     // mXPos and mYPos specify an additonal offset passed to OpenPopup that
     // should be added to the position.  We also add the offset to the anchor
     // pos so a later flip/resize takes the offset into account.
-    nscoord anchorXOffset = nsPresContext::CSSPixelsToAppUnits(mXPos);
+    nscoord anchorXOffset = CSSPixel::ToAppUnits(mXPos);
     if (IsDirectionRTL()) {
       screenPoint.x -= anchorXOffset;
       anchorRect.x -= anchorXOffset;
@@ -1525,7 +1532,7 @@ nsresult nsMenuPopupFrame::SetPopupPosit
       screenPoint.x += anchorXOffset;
       anchorRect.x += anchorXOffset;
     }
-    nscoord anchorYOffset = nsPresContext::CSSPixelsToAppUnits(mYPos);
+    nscoord anchorYOffset = CSSPixel::ToAppUnits(mYPos);
     screenPoint.y += anchorYOffset;
     anchorRect.y += anchorYOffset;
 
@@ -1539,10 +1546,8 @@ nsresult nsMenuPopupFrame::SetPopupPosit
       // Account for the margin that will end up being added to the screen
       // coordinate the next time SetPopupPosition is called.
       mAnchorType = MenuPopupAnchorType_Point;
-      mScreenRect.x =
-          nsPresContext::AppUnitsToIntCSSPixels(screenPoint.x - margin.left);
-      mScreenRect.y =
-          nsPresContext::AppUnitsToIntCSSPixels(screenPoint.y - margin.top);
+      mScreenRect.x = screenPoint.x - margin.left;
+      mScreenRect.y = screenPoint.y - margin.top;
     }
   } else {
     // The popup is positioned at a screen coordinate.
@@ -1557,11 +1562,11 @@ nsresult nsMenuPopupFrame::SetPopupPosit
     if (mAdjustOffsetForContextMenu) {
       nsPoint offsetForContextMenuDev;
       offsetForContextMenuDev.x =
-          nsPresContext::CSSPixelsToAppUnits(LookAndFeel::GetInt(
+          CSSPixel::ToAppUnits(LookAndFeel::GetInt(
               LookAndFeel::IntID::ContextMenuOffsetHorizontal)) /
           factor;
       offsetForContextMenuDev.y =
-          nsPresContext::CSSPixelsToAppUnits(LookAndFeel::GetInt(
+          CSSPixel::ToAppUnits(LookAndFeel::GetInt(
               LookAndFeel::IntID::ContextMenuOffsetVertical)) /
           factor;
       offsetForContextMenu.x =
@@ -1571,10 +1576,8 @@ nsresult nsMenuPopupFrame::SetPopupPosit
     }
 
     // next, convert into app units accounting for the zoom
-    screenPoint.x = presContext->DevPixelsToAppUnits(
-        nsPresContext::CSSPixelsToAppUnits(mScreenRect.x) / factor);
-    screenPoint.y = presContext->DevPixelsToAppUnits(
-        nsPresContext::CSSPixelsToAppUnits(mScreenRect.y) / factor);
+    screenPoint.x = presContext->DevPixelsToAppUnits(mScreenRect.x / factor);
+    screenPoint.y = presContext->DevPixelsToAppUnits(mScreenRect.y / factor);
     anchorRect = nsRect(screenPoint, nsSize(0, 0));
 
     // add the margins on the popup
@@ -2377,9 +2380,10 @@ void nsMenuPopupFrame::DestroyFrom(nsIFr
   nsBoxFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
 }
 
-void nsMenuPopupFrame::MoveTo(const CSSIntPoint& aPos, bool aUpdateAttrs) {
+void nsMenuPopupFrame::MoveTo(const CSSPoint& aPos, bool aUpdateAttrs) {
   nsIWidget* widget = GetWidget();
-  if ((mScreenRect.x == aPos.x && mScreenRect.y == aPos.y) &&
+  nsPoint appUnitsPos = CSSPixel::ToAppUnits(aPos);
+  if ((mScreenRect.x == appUnitsPos.x && mScreenRect.y == appUnitsPos.y) &&
       (!widget || widget->GetClientOffset() == mLastClientOffset)) {
     return;
   }
@@ -2393,15 +2397,15 @@ void nsMenuPopupFrame::MoveTo(const CSSI
 
   // Workaround for bug 788189.  See also bug 708278 comment #25 and following.
   if (mAdjustOffsetForContextMenu) {
-    margin.left += nsPresContext::CSSPixelsToAppUnits(
+    margin.left += CSSPixel::ToAppUnits(
         LookAndFeel::GetInt(LookAndFeel::IntID::ContextMenuOffsetHorizontal));
-    margin.top += nsPresContext::CSSPixelsToAppUnits(
+    margin.top += CSSPixel::ToAppUnits(
         LookAndFeel::GetInt(LookAndFeel::IntID::ContextMenuOffsetVertical));
   }
 
   mAnchorType = MenuPopupAnchorType_Point;
-  mScreenRect.x = aPos.x - nsPresContext::AppUnitsToIntCSSPixels(margin.left);
-  mScreenRect.y = aPos.y - nsPresContext::AppUnitsToIntCSSPixels(margin.top);
+  mScreenRect.x = appUnitsPos.x - margin.left;
+  mScreenRect.y = appUnitsPos.y - margin.top;
 
   SetPopupPosition(nullptr, true, false);
 
@@ -2409,8 +2413,8 @@ void nsMenuPopupFrame::MoveTo(const CSSI
   if (aUpdateAttrs && (popup->HasAttr(kNameSpaceID_None, nsGkAtoms::left) ||
                        popup->HasAttr(kNameSpaceID_None, nsGkAtoms::top))) {
     nsAutoString left, top;
-    left.AppendInt(aPos.x);
-    top.AppendInt(aPos.y);
+    left.AppendInt(RoundedToInt(aPos).x);
+    top.AppendInt(RoundedToInt(aPos).y);
     popup->SetAttr(kNameSpaceID_None, nsGkAtoms::left, left, false);
     popup->SetAttr(kNameSpaceID_None, nsGkAtoms::top, top, false);
   }
diff -up firefox-92.0/layout/xul/nsMenuPopupFrame.h.1708709 firefox-92.0/layout/xul/nsMenuPopupFrame.h
--- firefox-92.0/layout/xul/nsMenuPopupFrame.h.1708709	2021-09-01 19:15:06.000000000 +0200
+++ firefox-92.0/layout/xul/nsMenuPopupFrame.h	2021-09-07 10:46:10.360036429 +0200
@@ -321,7 +321,7 @@ class nsMenuPopupFrame final : public ns
   // If aUpdateAttrs is true, and the popup already has left or top attributes,
   // then those attributes are updated to the new location.
   // The frame may be destroyed by this method.
-  void MoveTo(const mozilla::CSSIntPoint& aPos, bool aUpdateAttrs);
+  void MoveTo(const mozilla::CSSPoint& aPos, bool aUpdateAttrs);
 
   void MoveToAnchor(nsIContent* aAnchorContent, const nsAString& aPosition,
                     int32_t aXPos, int32_t aYPos, bool aAttributesOverride);
@@ -370,7 +370,9 @@ class nsMenuPopupFrame final : public ns
 
   // Return the screen coordinates in CSS pixels of the popup,
   // or (-1, -1, 0, 0) if anchored.
-  nsIntRect GetScreenAnchorRect() const { return mScreenRect; }
+  mozilla::CSSIntRect GetScreenAnchorRect() const {
+    return mozilla::CSSRect::FromAppUnitsRounded(mScreenRect);
+  }
 
   mozilla::LayoutDeviceIntPoint GetLastClientOffset() const {
     return mLastClientOffset;
@@ -557,7 +559,7 @@ class nsMenuPopupFrame final : public ns
   // override mXPos and mYPos.
   int32_t mXPos;
   int32_t mYPos;
-  nsIntRect mScreenRect;
+  nsRect mScreenRect;
   // Used for store rectangle which the popup is going to be anchored to,
   // we need that for Wayland
 #ifdef MOZ_WAYLAND
diff -up firefox-92.0/layout/xul/nsXULPopupManager.cpp.1708709 firefox-92.0/layout/xul/nsXULPopupManager.cpp
--- firefox-92.0/layout/xul/nsXULPopupManager.cpp.1708709	2021-09-01 19:15:01.000000000 +0200
+++ firefox-92.0/layout/xul/nsXULPopupManager.cpp	2021-09-07 10:33:55.686223973 +0200
@@ -343,8 +343,7 @@ bool nsXULPopupManager::Rollup(uint32_t
       if (popupFrame->IsAnchored()) {
         // Check if the popup has a screen anchor rectangle. If not, get the
         // rectangle from the anchor element.
-        anchorRect =
-            CSSIntRect::FromUnknownRect(popupFrame->GetScreenAnchorRect());
+        anchorRect = popupFrame->GetScreenAnchorRect();
         if (anchorRect.x == -1 || anchorRect.y == -1) {
           nsCOMPtr<nsIContent> anchor = popupFrame->GetAnchor();
 
@@ -581,7 +580,7 @@ void nsXULPopupManager::PopupMoved(nsIFr
   } else {
     CSSPoint cssPos = LayoutDeviceIntPoint::FromUnknownPoint(aPnt) /
                       menuPopupFrame->PresContext()->CSSToDevPixelScale();
-    menuPopupFrame->MoveTo(RoundedToInt(cssPos), false);
+    menuPopupFrame->MoveTo(cssPos, false);
   }
 }
 
bgstack15