Skip to content

Commit

Permalink
Merge pull request #48 from CheYHinSpark/master
Browse files Browse the repository at this point in the history
Touch support
  • Loading branch information
chenguanzhou authored Aug 20, 2020
2 parents d1e3973 + 11fce60 commit 65acd1d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions MarkDownEditor/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
</i:EventTrigger>
</i:Interaction.Triggers>
<view:MvvmTextEditor
x:Name="mvvmTextEditor"
PreviewTouchDown="MvvmTextEditor_PreviewTouchDown"
PreviewTouchMove="MvvmTextEditor_PreviewTouchMove"
SyntaxHighlighting="MarkDown"
Background="{DynamicResource WhiteBrush}"
Foreground="{DynamicResource BlackBrush}"
Expand Down Expand Up @@ -154,6 +157,9 @@
<view:PreviewToolBarControl>
</view:PreviewToolBarControl>
<view:MvvmChromiumWebBrowser
x:Name="mvvmCWBrowser"
PreviewTouchDown="MvvmCWBrowser_PreviewTouchDown"
PreviewTouchMove="MvvmCWBrowser_PreviewTouchMove"
Grid.Row="1" Margin="10"
ShouldReload="{Binding ShouldReload,Mode=TwoWay}"
ScrollOffsetRatio="{Binding ScrollOffsetRatio,Mode=TwoWay}"
Expand Down
32 changes: 32 additions & 0 deletions MarkDownEditor/View/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,39 @@ private void ExitFullScreenButton_Click(object sender, RoutedEventArgs e)
ToggleFullScreen = false;
}
#endregion


private Point touchStartPoint;
private Point touchEndPoint;
//Touch support for Browser
private void MvvmCWBrowser_PreviewTouchDown(object sender, System.Windows.Input.TouchEventArgs e)
{
string src = $"onmousedown=new Function(\"return false\")";
mvvmCWBrowser.GetMainFrame().ExecuteJavaScriptAsync(src);
touchStartPoint = e.GetTouchPoint(mvvmCWBrowser).Position;
}

private void MvvmCWBrowser_PreviewTouchMove(object sender, System.Windows.Input.TouchEventArgs e)
{
touchEndPoint = e.GetTouchPoint(mvvmCWBrowser).Position;
string src = $"scrollBy({-touchEndPoint.X+touchStartPoint.X}, {-touchEndPoint.Y + touchStartPoint.Y})";
mvvmCWBrowser.GetMainFrame().ExecuteJavaScriptAsync(src);
touchStartPoint = touchEndPoint;
}

//Touch support of TextEditor
private void MvvmTextEditor_PreviewTouchDown(object sender, System.Windows.Input.TouchEventArgs e)
{
touchStartPoint = e.GetTouchPoint(mvvmTextEditor).Position;
mvvmTextEditor.IsTouched = true;
}

private void MvvmTextEditor_PreviewTouchMove(object sender, System.Windows.Input.TouchEventArgs e)
{
touchEndPoint = e.GetTouchPoint(mvvmTextEditor).Position;
mvvmTextEditor.ScrollToVerticalOffset(mvvmTextEditor.VerticalOffset + (touchStartPoint.Y - touchEndPoint.Y));
touchStartPoint = touchEndPoint;
}

}
}
26 changes: 26 additions & 0 deletions MarkDownEditor/View/MvvmChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,31 @@ public void RaisePropertyChanged(string info)
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}

//support touch
public bool IsTouched = false;
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
if (!IsTouched)
{
base.OnPreviewMouseDown(e);
}
else
{
e.Handled = true;
}
}
protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
if (!IsTouched)
{
base.OnPreviewMouseUp(e);
}
else
{
e.Handled = true;
}
IsTouched = false;
}
}
}
7 changes: 7 additions & 0 deletions MarkDownEditor/View/MvvmTextEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,12 @@ public void RaisePropertyChanged(string info)
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}

protected override void OnMouseUp(MouseButtonEventArgs e)
{
base.OnMouseUp(e);
string src = $"onmousedown=new Function(\"return true\")";
this.GetMainFrame().ExecuteJavaScriptAsync(src);
}
}
}

0 comments on commit 65acd1d

Please sign in to comment.