mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Add CefHandler::HandleTooltip and default tooltip implementation (issue #61).
- Add Common Controls to cefclient manifest because it's required for the default tooltip implementation. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@96 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -724,6 +724,15 @@ public:
|
|||||||
int modifiers,
|
int modifiers,
|
||||||
bool isSystemKey) =0;
|
bool isSystemKey) =0;
|
||||||
|
|
||||||
|
// Event called when the browser is about to display a tooltip. |text|
|
||||||
|
// contains the text that will be displayed in the tooltip. To handle
|
||||||
|
// the display of the tooltip yourself return RV_HANDLED. Otherwise,
|
||||||
|
// you can optionally modify |text| and then return RV_CONTINUE to allow
|
||||||
|
// the browser to display the tooltip.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
|
||||||
|
std::wstring& text) =0;
|
||||||
|
|
||||||
// Called to display a console message. Return RV_HANDLED to stop the message
|
// Called to display a console message. Return RV_HANDLED to stop the message
|
||||||
// from being output to the console.
|
// from being output to the console.
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
|
@ -534,6 +534,10 @@ typedef struct _cef_handler_t
|
|||||||
enum cef_handler_keyevent_type_t type, int code, int modifiers,
|
enum cef_handler_keyevent_type_t type, int code, int modifiers,
|
||||||
int isSystemKey);
|
int isSystemKey);
|
||||||
|
|
||||||
|
enum cef_retval_t (CEF_CALLBACK *handle_tooltip)(
|
||||||
|
struct _cef_handler_t* self, struct _cef_browser_t* browser,
|
||||||
|
cef_string_t* text);
|
||||||
|
|
||||||
// Called to display a console message. Return RV_HANDLED to stop the message
|
// Called to display a console message. Return RV_HANDLED to stop the message
|
||||||
// from being output to the console.
|
// from being output to the console.
|
||||||
enum cef_retval_t (CEF_CALLBACK *handle_console_message)(
|
enum cef_retval_t (CEF_CALLBACK *handle_console_message)(
|
||||||
|
@ -395,7 +395,14 @@ void BrowserWebViewDelegate::setKeyboardFocusURL(const WebKit::WebURL& url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWebViewDelegate::setToolTipText(
|
void BrowserWebViewDelegate::setToolTipText(
|
||||||
const WebString& text, WebTextDirection hint) {
|
const WebString& text, WebTextDirection hint)
|
||||||
|
{
|
||||||
|
std::wstring tooltipText(UTF8ToWide(webkit_glue::WebStringToStdString(text)));
|
||||||
|
|
||||||
|
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||||
|
if(handler.get() && handler->HandleTooltip(browser_, tooltipText) == RV_CONTINUE){
|
||||||
|
GetWidgetHost()->SetTooltipText(tooltipText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWebViewDelegate::startDragging(
|
void BrowserWebViewDelegate::startDragging(
|
||||||
|
@ -128,6 +128,10 @@ LRESULT CALLBACK WebWidgetHost::WndProc(HWND hwnd, UINT message, WPARAM wparam,
|
|||||||
case WM_KILLFOCUS:
|
case WM_KILLFOCUS:
|
||||||
host->SetFocus(false);
|
host->SetFocus(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WM_NOTIFY:
|
||||||
|
host->OnNotify(0, (NMHDR*)lparam);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +192,9 @@ WebWidgetHost::WebWidgetHost()
|
|||||||
webwidget_(NULL),
|
webwidget_(NULL),
|
||||||
track_mouse_leave_(false),
|
track_mouse_leave_(false),
|
||||||
scroll_dx_(0),
|
scroll_dx_(0),
|
||||||
scroll_dy_(0) {
|
scroll_dy_(0),
|
||||||
|
tooltip_view_(NULL),
|
||||||
|
tooltip_showing_(false) {
|
||||||
set_painting(false);
|
set_painting(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +202,7 @@ WebWidgetHost::~WebWidgetHost() {
|
|||||||
win_util::SetWindowUserData(view_, 0);
|
win_util::SetWindowUserData(view_, 0);
|
||||||
|
|
||||||
TrackMouseLeave(false);
|
TrackMouseLeave(false);
|
||||||
|
ResetTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebWidgetHost::WndProc(UINT message, WPARAM wparam, LPARAM lparam) {
|
bool WebWidgetHost::WndProc(UINT message, WPARAM wparam, LPARAM lparam) {
|
||||||
@ -280,6 +287,7 @@ void WebWidgetHost::Resize(LPARAM lparam) {
|
|||||||
DiscardBackingStore();
|
DiscardBackingStore();
|
||||||
|
|
||||||
webwidget_->resize(WebSize(LOWORD(lparam), HIWORD(lparam)));
|
webwidget_->resize(WebSize(LOWORD(lparam), HIWORD(lparam)));
|
||||||
|
EnsureTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) {
|
void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) {
|
||||||
@ -329,6 +337,80 @@ void WebWidgetHost::SetFocus(bool enable) {
|
|||||||
webwidget_->setFocus(enable);
|
webwidget_->setFocus(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebWidgetHost::OnNotify(WPARAM wparam, NMHDR* header) {
|
||||||
|
if (tooltip_view_ == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (header->code) {
|
||||||
|
case TTN_GETDISPINFO:
|
||||||
|
{
|
||||||
|
NMTTDISPINFOW* tooltip_info = reinterpret_cast<NMTTDISPINFOW*>(header);
|
||||||
|
tooltip_info->szText[0] = L'\0';
|
||||||
|
tooltip_info->lpszText = const_cast<wchar_t*>(tooltip_text_.c_str());
|
||||||
|
::SendMessage(tooltip_view_, TTM_SETMAXTIPWIDTH, 0, 1024);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TTN_POP:
|
||||||
|
tooltip_showing_ = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TTN_SHOW:
|
||||||
|
tooltip_showing_ = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebWidgetHost::SetTooltipText(const std::wstring& new_tooltip_text) {
|
||||||
|
if (new_tooltip_text != tooltip_text_) {
|
||||||
|
tooltip_text_ = new_tooltip_text;
|
||||||
|
|
||||||
|
// Need to check if the tooltip is already showing so that we don't
|
||||||
|
// immediately show the tooltip with no delay when we move the mouse from
|
||||||
|
// a region with no tooltip to a region with a tooltip.
|
||||||
|
if (::IsWindow(tooltip_view_) && tooltip_showing_) {
|
||||||
|
::SendMessage(tooltip_view_, TTM_POP, 0, 0);
|
||||||
|
::SendMessage(tooltip_view_, TTM_POPUP, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Make sure the tooltip gets closed after TTN_POP gets sent. For some
|
||||||
|
// reason this doesn't happen automatically, so moving the mouse around
|
||||||
|
// within the same link/image/etc doesn't cause the tooltip to re-appear.
|
||||||
|
if (!tooltip_showing_) {
|
||||||
|
if (::IsWindow(tooltip_view_))
|
||||||
|
::SendMessage(tooltip_view_, TTM_POP, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebWidgetHost::EnsureTooltip() {
|
||||||
|
UINT message = TTM_NEWTOOLRECT;
|
||||||
|
|
||||||
|
TOOLINFO ti;
|
||||||
|
ti.cbSize = sizeof(ti);
|
||||||
|
ti.hwnd = view_handle();
|
||||||
|
ti.uId = 0;
|
||||||
|
if (!::IsWindow(tooltip_view_)) {
|
||||||
|
message = TTM_ADDTOOL;
|
||||||
|
tooltip_view_ = CreateWindowEx(
|
||||||
|
WS_EX_TRANSPARENT,
|
||||||
|
TOOLTIPS_CLASS, L"tooltip_view_", TTS_NOPREFIX, 0, 0, 0, 0, view_handle(), NULL,
|
||||||
|
NULL, NULL);
|
||||||
|
ti.uFlags = TTF_SUBCLASS;
|
||||||
|
ti.lpszText = LPSTR_TEXTCALLBACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetClientRect(view_handle(), &ti.rect);
|
||||||
|
SendMessage(tooltip_view_, message, NULL, reinterpret_cast<LPARAM>(&ti));
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebWidgetHost::ResetTooltip() {
|
||||||
|
if (::IsWindow(tooltip_view_))
|
||||||
|
::DestroyWindow(tooltip_view_);
|
||||||
|
tooltip_view_ = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void WebWidgetHost::TrackMouseLeave(bool track) {
|
void WebWidgetHost::TrackMouseLeave(bool track) {
|
||||||
if (track == track_mouse_leave_)
|
if (track == track_mouse_leave_)
|
||||||
return;
|
return;
|
||||||
|
@ -59,6 +59,8 @@ class WebWidgetHost {
|
|||||||
|
|
||||||
void PaintRect(const gfx::Rect& rect);
|
void PaintRect(const gfx::Rect& rect);
|
||||||
|
|
||||||
|
void SetTooltipText(const std::wstring& tooltip_text);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
WebWidgetHost();
|
WebWidgetHost();
|
||||||
~WebWidgetHost();
|
~WebWidgetHost();
|
||||||
@ -73,6 +75,7 @@ class WebWidgetHost {
|
|||||||
void KeyEvent(UINT message, WPARAM wparam, LPARAM lparam);
|
void KeyEvent(UINT message, WPARAM wparam, LPARAM lparam);
|
||||||
void CaptureLostEvent();
|
void CaptureLostEvent();
|
||||||
void SetFocus(bool enable);
|
void SetFocus(bool enable);
|
||||||
|
void OnNotify(WPARAM wparam, NMHDR* header);
|
||||||
|
|
||||||
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||||
#elif defined(OS_MACOSX)
|
#elif defined(OS_MACOSX)
|
||||||
@ -108,6 +111,9 @@ class WebWidgetHost {
|
|||||||
painting_ = value;
|
painting_ = value;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EnsureTooltip();
|
||||||
|
void ResetTooltip();
|
||||||
|
|
||||||
gfx::NativeView view_;
|
gfx::NativeView view_;
|
||||||
WebKit::WebWidget* webwidget_;
|
WebKit::WebWidget* webwidget_;
|
||||||
@ -125,6 +131,10 @@ class WebWidgetHost {
|
|||||||
|
|
||||||
WebKit::WebKeyboardEvent last_key_event_;
|
WebKit::WebKeyboardEvent last_key_event_;
|
||||||
|
|
||||||
|
gfx::NativeView tooltip_view_;
|
||||||
|
std::wstring tooltip_text_;
|
||||||
|
bool tooltip_showing_;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
bool painting_;
|
bool painting_;
|
||||||
#endif
|
#endif
|
||||||
|
@ -457,6 +457,28 @@ enum cef_retval_t CEF_CALLBACK handler_handle_key_event(
|
|||||||
modifiers, isSystemKey?true:false);
|
modifiers, isSystemKey?true:false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum cef_retval_t CEF_CALLBACK handler_handle_tooltip(
|
||||||
|
struct _cef_handler_t* self, struct _cef_browser_t* browser,
|
||||||
|
cef_string_t* text)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
DCHECK(browser);
|
||||||
|
DCHECK(text);
|
||||||
|
if(!self || !browser || !text)
|
||||||
|
return RV_CONTINUE;
|
||||||
|
|
||||||
|
std::wstring textStr;
|
||||||
|
if(*text)
|
||||||
|
textStr = *text;
|
||||||
|
|
||||||
|
enum cef_retval_t rv = CefHandlerCppToC::Get(self)->HandleTooltip(
|
||||||
|
CefBrowserCToCpp::Wrap(browser), textStr);
|
||||||
|
|
||||||
|
transfer_string_contents(textStr, text);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
enum cef_retval_t CEF_CALLBACK handler_handle_console_message(
|
enum cef_retval_t CEF_CALLBACK handler_handle_console_message(
|
||||||
struct _cef_handler_t* self, cef_browser_t* browser, const wchar_t* message,
|
struct _cef_handler_t* self, cef_browser_t* browser, const wchar_t* message,
|
||||||
const wchar_t* source, int line)
|
const wchar_t* source, int line)
|
||||||
@ -521,6 +543,7 @@ CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
|
|||||||
struct_.struct_.handle_take_focus = handler_handle_take_focus;
|
struct_.struct_.handle_take_focus = handler_handle_take_focus;
|
||||||
struct_.struct_.handle_set_focus = handler_handle_set_focus;
|
struct_.struct_.handle_set_focus = handler_handle_set_focus;
|
||||||
struct_.struct_.handle_key_event = handler_handle_key_event;
|
struct_.struct_.handle_key_event = handler_handle_key_event;
|
||||||
|
struct_.struct_.handle_tooltip = handler_handle_tooltip;
|
||||||
struct_.struct_.handle_console_message = handler_handle_console_message;
|
struct_.struct_.handle_console_message = handler_handle_console_message;
|
||||||
struct_.struct_.handle_find_result = handler_handle_find_result;
|
struct_.struct_.handle_find_result = handler_handle_find_result;
|
||||||
}
|
}
|
||||||
|
@ -348,6 +348,23 @@ CefHandler::RetVal CefHandlerCToCpp::HandleKeyEvent(
|
|||||||
type, code, modifiers, isSystemKey);
|
type, code, modifiers, isSystemKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CefHandler::RetVal CefHandlerCToCpp::HandleTooltip(
|
||||||
|
CefRefPtr<CefBrowser> browser, std::wstring& text)
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, handle_tooltip))
|
||||||
|
return RV_CONTINUE;
|
||||||
|
cef_string_t textRet = NULL;
|
||||||
|
if(!text.empty())
|
||||||
|
textRet = cef_string_alloc(text.c_str());
|
||||||
|
|
||||||
|
cef_retval_t rv = struct_->handle_tooltip(struct_,
|
||||||
|
CefBrowserCppToC::Wrap(browser), &textRet);
|
||||||
|
|
||||||
|
transfer_string_contents(textRet, text, true);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
CefHandler::RetVal CefHandlerCToCpp::HandleConsoleMessage(
|
CefHandler::RetVal CefHandlerCToCpp::HandleConsoleMessage(
|
||||||
CefRefPtr<CefBrowser> browser, const std::wstring& message,
|
CefRefPtr<CefBrowser> browser, const std::wstring& message,
|
||||||
const std::wstring& source, int line)
|
const std::wstring& source, int line)
|
||||||
|
@ -76,6 +76,8 @@ public:
|
|||||||
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser, bool isWidget);
|
virtual RetVal HandleSetFocus(CefRefPtr<CefBrowser> browser, bool isWidget);
|
||||||
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
virtual RetVal HandleKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||||
KeyEventType type, int code, int modifiers, bool isSystemKey);
|
KeyEventType type, int code, int modifiers, bool isSystemKey);
|
||||||
|
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
|
||||||
|
std::wstring& text);
|
||||||
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||||
const std::wstring& message, const std::wstring& source, int line);
|
const std::wstring& message, const std::wstring& source, int line);
|
||||||
virtual RetVal HandleFindResult(CefRefPtr<CefBrowser> browser, int identifier,
|
virtual RetVal HandleFindResult(CefRefPtr<CefBrowser> browser, int identifier,
|
||||||
|
@ -36,6 +36,11 @@ BOOL InitInstance(HINSTANCE, int);
|
|||||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||||
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
// Add Common Controls to the application manifest because it's required to
|
||||||
|
// support the default tooltip implementation.
|
||||||
|
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||||
|
#endif
|
||||||
|
|
||||||
// Program entry point function.
|
// Program entry point function.
|
||||||
int APIENTRY wWinMain(HINSTANCE hInstance,
|
int APIENTRY wWinMain(HINSTANCE hInstance,
|
||||||
@ -518,6 +523,17 @@ public:
|
|||||||
return RV_CONTINUE;
|
return RV_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Event called when the browser is about to display a tooltip. |text|
|
||||||
|
// contains the text that will be displayed in the tooltip. To handle
|
||||||
|
// the display of the tooltip yourself return RV_HANDLED. Otherwise,
|
||||||
|
// you can optionally modify |text| and then return RV_CONTINUE to allow
|
||||||
|
// the browser to display the tooltip.
|
||||||
|
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
|
||||||
|
std::wstring& text)
|
||||||
|
{
|
||||||
|
return RV_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
// Called when the browser component receives a keyboard event.
|
// Called when the browser component receives a keyboard event.
|
||||||
// |type| is the type of keyboard event (see |KeyEventType|).
|
// |type| is the type of keyboard event (see |KeyEventType|).
|
||||||
// |code| is the windows scan-code for the event.
|
// |code| is the windows scan-code for the event.
|
||||||
|
@ -203,6 +203,12 @@ public:
|
|||||||
return RV_CONTINUE;
|
return RV_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual RetVal HandleTooltip(CefRefPtr<CefBrowser> browser,
|
||||||
|
std::wstring& text)
|
||||||
|
{
|
||||||
|
return RV_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
virtual RetVal HandleConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||||
const std::wstring& message,
|
const std::wstring& message,
|
||||||
const std::wstring& source, int line)
|
const std::wstring& source, int line)
|
||||||
|
Reference in New Issue
Block a user