Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch support #48

Merged
merged 4 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}