Skip to content

Commit 93f30ab

Browse files
committed
Merge in 'release/3.1' changes
2 parents e16a9d7 + d1dfb43 commit 93f30ab

File tree

3 files changed

+56
-45
lines changed

3 files changed

+56
-45
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/WebBrowserEvent.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
using MS.Internal.AppModel;
2525
using MS.Internal.Interop;
2626

27-
//In order to avoid generating warnings about unknown message numbers and
28-
//unknown pragmas when compiling your C# source code with the actual C# compiler,
27+
//In order to avoid generating warnings about unknown message numbers and
28+
//unknown pragmas when compiling your C# source code with the actual C# compiler,
2929
//you need to disable warnings 1634 and 1691. (Presharp Documentation)
3030
#pragma warning disable 1634, 1691
3131

@@ -72,15 +72,15 @@ public void BeforeNavigate2(object pDisp, ref object url, ref object flags, ref
7272

7373
UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp;
7474
// If _parent.AxIWebBrowser2 != axIWebBrowser2, navigation happens in a nested [i]frame.
75-
// in that case we do not want to enforce site locking as we want the default IE behavior to take
76-
// over.
75+
// in that case we do not want to enforce site locking as we want the default IE behavior to take
76+
// over.
7777
if (_parent.AxIWebBrowser2 == axIWebBrowser2)
7878
{
7979
// The NavigatingToAboutBlank property indicates whether we are navigating to "about:blank"
8080
// as a result of navigating to null or stream/string navigation.
8181
// We set the NavigatingToAboutBlank bit to true in the WebBrowser DoNavigate method. When the above
82-
// conditions occur, the NavigatingToAboutBlank is true and the source must be "about:blank".
83-
//
82+
// conditions occur, the NavigatingToAboutBlank is true and the source must be "about:blank".
83+
//
8484
// But when end user navigates away from the current about:blank page (by clicking
8585
// on a hyperlink, Goback/Forward), or programmatically call GoBack and Forward,
8686
// When we get the navigating event, NavigatingToAboutBlank is true, but the source is not "about:blank".
@@ -174,11 +174,11 @@ public void NavigateComplete2(object pDisp, ref object url)
174174
{
175175
Debug.Assert(url == null || url is string, "invalid url type");
176176

177-
// Events only fired for top level navigation.
177+
// Events only fired for top level navigation.
178178
UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp;
179-
if (_parent.AxIWebBrowser2 == axIWebBrowser2)
179+
if (_parent.AxIWebBrowser2 == axIWebBrowser2 && !ShouldIgnoreCompletionEvent(ref url))
180180
{
181-
// If we are loading from stream.
181+
// If we are loading from stream.
182182
if (_parent.DocumentStream != null)
183183
{
184184
Invariant.Assert(_parent.NavigatingToAboutBlank &&
@@ -207,7 +207,7 @@ public void NavigateComplete2(object pDisp, ref object url)
207207
{
208208
string urlString = (string)url;
209209
// When source set to null or navigating to stream/string, we navigate to "about:blank"
210-
// internally. Make sure we pass null in the event args.
210+
// internally. Make sure we pass null in the event args.
211211
if (_parent.NavigatingToAboutBlank)
212212
{
213213
Invariant.Assert(String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0);
@@ -229,13 +229,13 @@ public void DocumentComplete(object pDisp, ref object url)
229229
{
230230
Debug.Assert(url == null || url is string, "invalid url type");
231231

232-
// Events only fired for top level navigation.
232+
// Events only fired for top level navigation.
233233
UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)pDisp;
234-
if (_parent.AxIWebBrowser2 == axIWebBrowser2)
234+
if (_parent.AxIWebBrowser2 == axIWebBrowser2 && !ShouldIgnoreCompletionEvent(ref url))
235235
{
236236
string urlString = (string)url;
237237
// When source set to null or navigating to stream/string, we navigate to "about:blank"
238-
// internally. Make sure we pass null in the event args.
238+
// internally. Make sure we pass null in the event args.
239239
if (_parent.NavigatingToAboutBlank)
240240
{
241241
Invariant.Assert(String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) == 0);
@@ -248,6 +248,17 @@ public void DocumentComplete(object pDisp, ref object url)
248248
}
249249
}
250250

251+
// if we are navigating to "about:blank", ignore completion events
252+
// for any other url. These can happen despite our attempt to cancel
253+
// outstanding navigations (see WebBrowser.DoNavigate), due to race
254+
// conditions between the browser and us.
255+
private bool ShouldIgnoreCompletionEvent(ref object url)
256+
{
257+
string urlString = url as string;
258+
return (_parent.NavigatingToAboutBlank &&
259+
String.Compare(urlString, WebBrowser.AboutBlankUriString, StringComparison.OrdinalIgnoreCase) != 0);
260+
}
261+
251262
public void CommandStateChange(long command, bool enable)
252263
{
253264
if (command == NativeMethods.CSC_NAVIGATEBACK)

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ScrollViewer.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void InvalidateScrollInfo()
246246
// We also don't invalidate measure if we are in the middle of the
247247
// measure pass, as the ScrollViewer will already be updating the
248248
// visibility of the autoscrollbars.
249-
if(!MeasureInProgress &&
249+
if(!MeasureInProgress &&
250250
(!ArrangeInProgress || !InvalidatedMeasureFromArrange))
251251
{
252252
//
@@ -892,7 +892,7 @@ public event ScrollChangedEventHandler ScrollChanged
892892
protected override void OnStylusSystemGesture(StylusSystemGestureEventArgs e)
893893
{
894894
// DevDiv:1139804
895-
// Keep track of seeing a tap gesture so that we can use this information to
895+
// Keep track of seeing a tap gesture so that we can use this information to
896896
// make decisions about panning.
897897
_seenTapGesture = e.SystemGesture == SystemGesture.Tap;
898898
}
@@ -1175,7 +1175,7 @@ protected override Size MeasureOverride(Size constraint)
11751175
ScrollBarVisibility vsbv = VerticalScrollBarVisibility;
11761176
ScrollBarVisibility hsbv = HorizontalScrollBarVisibility;
11771177
Size desiredSize = new Size();
1178-
1178+
11791179
if (child != null)
11801180
{
11811181
bool etwTracingEnabled = EventTrace.IsEnabled(EventTrace.Keyword.KeywordGeneral, EventTrace.Level.Info);
@@ -1511,7 +1511,7 @@ private void OnPanningModeChanged()
15111511
PanningMode mode = PanningMode;
15121512

15131513
// Call InvalidateProperty for IsManipulationEnabledProperty
1514-
// to reset previous SetCurrentValueInternal if any.
1514+
// to reset previous SetCurrentValueInternal if any.
15151515
// Then call SetCurrentValueInternal to
15161516
// set the value of these properties if needed.
15171517
InvalidateProperty(IsManipulationEnabledProperty);
@@ -1742,7 +1742,7 @@ protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
17421742
// High precision touch devices can trigger a panning manipulation
17431743
// due to the low threshold we set for pan initiation. This may be
17441744
// undesirable since we may enter pan for what the system considers a
1745-
// tap. Panning should be contingent on a drag gesture as that is the
1745+
// tap. Panning should be contingent on a drag gesture as that is the
17461746
// most consistent with the system at large. So if we have seen a tap
17471747
// on our main input, we should cancel any panning.
17481748
if (_seenTapGesture)
@@ -1831,7 +1831,7 @@ private void ManipulateScroll(double delta, double cumulativeTranslation, bool i
18311831

18321832
if (DoubleUtil.AreClose(scrollableLength, 0))
18331833
{
1834-
// If the Scrollable length in this direction is 0,
1834+
// If the Scrollable length in this direction is 0,
18351835
// then we should neither scroll nor report the boundary feedback
18361836
unused = 0;
18371837
delta = 0;
@@ -1846,7 +1846,7 @@ private void ManipulateScroll(double delta, double cumulativeTranslation, bool i
18461846
}
18471847
else if (DoubleUtil.LessThan(delta, 0) && DoubleUtil.GreaterThan(unused, 0))
18481848
{
1849-
// If we are past the boundary in positive direction
1849+
// If we are past the boundary in positive direction
18501850
// and the delta is in negative direction,
18511851
// then compensate the delta from unused vector.
18521852
double newUnused = Math.Max(unused + delta, 0);
@@ -1855,7 +1855,7 @@ private void ManipulateScroll(double delta, double cumulativeTranslation, bool i
18551855
}
18561856
else if (DoubleUtil.GreaterThan(delta, 0) && DoubleUtil.LessThan(unused, 0))
18571857
{
1858-
// If we are past the boundary in negative direction
1858+
// If we are past the boundary in negative direction
18591859
// and the delta is in positive direction,
18601860
// then compensate the delta from unused vector.
18611861
double newUnused = Math.Min(unused + delta, 0);
@@ -1878,7 +1878,7 @@ private void ManipulateScroll(double delta, double cumulativeTranslation, bool i
18781878
if (!DoubleUtil.AreClose(delta, 0))
18791879
{
18801880
// if there is any delta left, then re-evalute the vertical offset
1881-
ScrollToVerticalOffset(_panningInfo.OriginalVerticalOffset -
1881+
ScrollToVerticalOffset(_panningInfo.OriginalVerticalOffset -
18821882
Math.Round(PanningRatio * cumulativeTranslation / _panningInfo.DeltaPerVerticalOffset));
18831883
}
18841884
_panningInfo.UnusedTranslation = new Vector(_panningInfo.UnusedTranslation.X, unused);
@@ -1903,7 +1903,7 @@ private bool IsPastInertialLimit()
19031903

19041904
/// <summary>
19051905
/// Scrolling due to manipulation can start only if there is a considerable delta
1906-
/// in the direction based on the mode. This method makes sure that the delta is
1906+
/// in the direction based on the mode. This method makes sure that the delta is
19071907
/// considerable.
19081908
/// </summary>
19091909
private bool CanStartScrollManipulation(Vector translation, out bool cancelManipulation)
@@ -2312,6 +2312,15 @@ private bool ExecuteNextCommand()
23122312

23132313
if (!rcNew.IsEmpty)
23142314
{
2315+
// clip the new rect to isi's bounds, in case isi didn't.
2316+
// The ancestor's scroll should only depend on the visible
2317+
// portion of the new rect.
2318+
UIElement uie = visi as UIElement;
2319+
if (uie != null)
2320+
{
2321+
rcNew.Intersect(new Rect(uie.RenderSize));
2322+
}
2323+
23152324
GeneralTransform t = visi.TransformToAncestor(this);
23162325
rcNew = t.TransformBounds(rcNew);
23172326
}
@@ -2609,7 +2618,7 @@ private static void OnScrollCommand(object target, ExecutedRoutedEventArgs args)
26092618
ScrollViewer sv = target as ScrollViewer;
26102619
if (sv != null)
26112620
{
2612-
// If any of the ScrollBar scroll commands are raised while
2621+
// If any of the ScrollBar scroll commands are raised while
26132622
// scroll manipulation is in its inertia, then the manipualtion
26142623
// should be completed.
26152624
sv.CompleteScrollManipulation = true;
@@ -2636,8 +2645,8 @@ private static void OnQueryScrollCommand(object target, CanExecuteRoutedEventArg
26362645
{
26372646
args.CanExecute = false;
26382647
args.ContinueRouting = true;
2639-
2640-
// It is important to handle this event to prevent any
2648+
2649+
// It is important to handle this event to prevent any
26412650
// other ScrollViewers in the ancestry from claiming it.
26422651
args.Handled = true;
26432652
}
@@ -2654,7 +2663,7 @@ private static void OnQueryScrollCommand(object target, CanExecuteRoutedEventArg
26542663
{
26552664
args.CanExecute = false;
26562665

2657-
// It is important to handle this event to prevent any
2666+
// It is important to handle this event to prevent any
26582667
// other ScrollViewers in the ancestry from claiming it.
26592668
args.Handled = true;
26602669
}
@@ -2933,7 +2942,7 @@ internal bool InChildMeasurePass3
29332942

29342943
private PanningInfo _panningInfo = null;
29352944
private Flags _flags = Flags.HandlesMouseWheelScrolling;
2936-
2945+
29372946
#endregion
29382947

29392948
//-------------------------------------------------------------------

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizingStackPanel.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11139,32 +11139,23 @@ private void MakeVisiblePhysicalHelper(Rect r, ref Vector newOffset, ref Rect ne
1113911139
viewportOffset, viewportOffset + viewportSize, targetRectOffset, targetRectOffset + targetRectSize, ref alignTop, ref alignBottom);
1114011140

1114111141
// Compute the visible rectangle of the child relative to the viewport.
11142+
double start = targetRectOffset - minPhysicalOffset;
11143+
double end = start + targetRectSize;
1114211144

11143-
if (alignTop)
11144-
{
11145-
targetRectOffset = viewportOffset;
11146-
}
11147-
else if (alignBottom)
11148-
{
11149-
targetRectOffset = viewportOffset + viewportSize - targetRectSize;
11150-
}
11151-
11152-
double left = Math.Max(targetRectOffset, minPhysicalOffset);
11153-
targetRectSize = Math.Max(Math.Min(targetRectSize + targetRectOffset, minPhysicalOffset + viewportSize) - left, 0);
11154-
targetRectOffset = left;
11155-
targetRectOffset -= viewportOffset;
11145+
double visibleStart = Math.Max(start, 0);
11146+
double visibleEnd = Math.Max(Math.Min(end, viewportSize), visibleStart);
1115611147

1115711148
if (isHorizontal)
1115811149
{
1115911150
newOffset.X = minPhysicalOffset;
11160-
newRect.X = targetRectOffset;
11161-
newRect.Width = targetRectSize;
11151+
newRect.X = visibleStart;
11152+
newRect.Width = visibleEnd - visibleStart;
1116211153
}
1116311154
else
1116411155
{
1116511156
newOffset.Y = minPhysicalOffset;
11166-
newRect.Y = targetRectOffset;
11167-
newRect.Height = targetRectSize;
11157+
newRect.Y = visibleStart;
11158+
newRect.Height = visibleEnd - visibleStart;
1116811159
}
1116911160
}
1117011161

0 commit comments

Comments
 (0)