Skip to content

Commit

Permalink
Updated OnTooltipChanged to allow for modifying text (cefsharp#1953)
Browse files Browse the repository at this point in the history
* Updated OnTooltipChanged to allow for modifying text

* Updated examples
  • Loading branch information
merceyz committed May 15, 2017
1 parent 1609379 commit 2b7bdf8
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 12 deletions.
20 changes: 11 additions & 9 deletions CefSharp.Core/Internals/ClientAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,25 +329,27 @@ namespace CefSharp
{
auto tooltip = StringUtils::ToClr(text);
bool hasChanged = tooltip != _tooltip;
bool returnFlag = true;

//NOTE: Only called if tooltip changed otherwise called many times
// also only appears to be called with OSR rendering at the moment
if(hasChanged)
// also only called when using OSR, https://bitbucket.org/chromiumembedded/cef/issues/783

if (hasChanged)
{
if (!browser->IsPopup())
auto handler = _browserControl->DisplayHandler;
if (handler != nullptr)
{
_tooltip = tooltip;
_browserControl->SetTooltipText(_tooltip);
returnFlag = handler->OnTooltipChanged(_browserControl, tooltip);
}

auto handler = _browserControl->DisplayHandler;
if (handler != nullptr)
if (!browser->IsPopup())
{
return handler->OnTooltipChanged(_browserControl, tooltip);
_tooltip = tooltip;
_browserControl->SetTooltipText(_tooltip);
}
}

return true;
return returnFlag;
}

bool ClientAdapter::OnConsoleMessage(CefRefPtr<CefBrowser> browser, const CefString& message, const CefString& source, int line)
Expand Down
3 changes: 2 additions & 1 deletion CefSharp.WinForms.Example/Handlers/DisplayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ void IDisplayHandler.OnFullscreenModeChange(IWebBrowser browserControl, IBrowser
});
}

bool IDisplayHandler.OnTooltipChanged(IWebBrowser browserControl, string text)
bool IDisplayHandler.OnTooltipChanged(IWebBrowser browserControl, ref string text)
{
//text = "Sample text";
return false;
}

Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
</Page>
<Compile Include="Controls\CefSharpCommands.cs" />
<Compile Include="Controls\NonReloadingTabControl.cs" />
<Compile Include="Handlers\DisplayHandler.cs" />
<Compile Include="Handlers\DragHandler.cs" />
<Compile Include="Handlers\GeolocationHandler.cs" />
<Compile Include="Handlers\MenuHandler.cs" />
Expand Down
48 changes: 48 additions & 0 deletions CefSharp.Wpf.Example/Handlers/DisplayHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright © 2010-2016 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System.Collections.Generic;

namespace CefSharp.Wpf.Example.Handlers
{
public class DisplayHandler : IDisplayHandler
{

void IDisplayHandler.OnAddressChanged(IWebBrowser browserControl, AddressChangedEventArgs addressChangedArgs)
{

}

void IDisplayHandler.OnTitleChanged(IWebBrowser browserControl, TitleChangedEventArgs titleChangedArgs)
{

}

void IDisplayHandler.OnFaviconUrlChange(IWebBrowser browserControl, IBrowser browser, IList<string> urls)
{

}

void IDisplayHandler.OnFullscreenModeChange(IWebBrowser browserControl, IBrowser browser, bool fullscreen)
{

}

bool IDisplayHandler.OnTooltipChanged(IWebBrowser browserControl, ref string text)
{
//text = "Sample text";
return false;
}

void IDisplayHandler.OnStatusMessage(IWebBrowser browserControl, StatusMessageEventArgs statusMessageArgs)
{

}

bool IDisplayHandler.OnConsoleMessage(IWebBrowser browserControl, ConsoleMessageEventArgs consoleMessageArgs)
{
return false;
}
}
}
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public BrowserTabView()
// Enable touch scrolling - once properly tested this will likely become the default
//browser.IsManipulationEnabled = true;

browser.DisplayHandler = new DisplayHandler();
browser.LifeSpanHandler = new LifespanHandler();
browser.MenuHandler = new MenuHandler();
browser.GeolocationHandler = new GeolocationHandler();
Expand Down
4 changes: 2 additions & 2 deletions CefSharp/Handler/IDisplayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public interface IDisplayHandler
/// <param name="text">the text that will be displayed in the tooltip</param>
/// <returns>To handle the display of the tooltip yourself return true otherwise return false
/// to allow the browser to display the tooltip.</returns>
/// <remarks>Option to modify tooltip is not currently implemented.</remarks>
bool OnTooltipChanged(IWebBrowser browserControl, string text);
/// <remarks>Only called when using Off-screen rendering (WPF and OffScreen)</remarks>
bool OnTooltipChanged(IWebBrowser browserControl, ref string text);

/// <summary>
/// Called when the browser receives a status message.
Expand Down

0 comments on commit 2b7bdf8

Please sign in to comment.