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:
@ -395,7 +395,14 @@ void BrowserWebViewDelegate::setKeyboardFocusURL(const WebKit::WebURL& url) {
|
||||
}
|
||||
|
||||
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(
|
||||
|
@ -128,6 +128,10 @@ LRESULT CALLBACK WebWidgetHost::WndProc(HWND hwnd, UINT message, WPARAM wparam,
|
||||
case WM_KILLFOCUS:
|
||||
host->SetFocus(false);
|
||||
break;
|
||||
|
||||
case WM_NOTIFY:
|
||||
host->OnNotify(0, (NMHDR*)lparam);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,7 +192,9 @@ WebWidgetHost::WebWidgetHost()
|
||||
webwidget_(NULL),
|
||||
track_mouse_leave_(false),
|
||||
scroll_dx_(0),
|
||||
scroll_dy_(0) {
|
||||
scroll_dy_(0),
|
||||
tooltip_view_(NULL),
|
||||
tooltip_showing_(false) {
|
||||
set_painting(false);
|
||||
}
|
||||
|
||||
@ -196,6 +202,7 @@ WebWidgetHost::~WebWidgetHost() {
|
||||
win_util::SetWindowUserData(view_, 0);
|
||||
|
||||
TrackMouseLeave(false);
|
||||
ResetTooltip();
|
||||
}
|
||||
|
||||
bool WebWidgetHost::WndProc(UINT message, WPARAM wparam, LPARAM lparam) {
|
||||
@ -280,6 +287,7 @@ void WebWidgetHost::Resize(LPARAM lparam) {
|
||||
DiscardBackingStore();
|
||||
|
||||
webwidget_->resize(WebSize(LOWORD(lparam), HIWORD(lparam)));
|
||||
EnsureTooltip();
|
||||
}
|
||||
|
||||
void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) {
|
||||
@ -329,6 +337,80 @@ void WebWidgetHost::SetFocus(bool 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) {
|
||||
if (track == track_mouse_leave_)
|
||||
return;
|
||||
|
@ -59,6 +59,8 @@ class WebWidgetHost {
|
||||
|
||||
void PaintRect(const gfx::Rect& rect);
|
||||
|
||||
void SetTooltipText(const std::wstring& tooltip_text);
|
||||
|
||||
protected:
|
||||
WebWidgetHost();
|
||||
~WebWidgetHost();
|
||||
@ -73,6 +75,7 @@ class WebWidgetHost {
|
||||
void KeyEvent(UINT message, WPARAM wparam, LPARAM lparam);
|
||||
void CaptureLostEvent();
|
||||
void SetFocus(bool enable);
|
||||
void OnNotify(WPARAM wparam, NMHDR* header);
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
#elif defined(OS_MACOSX)
|
||||
@ -108,6 +111,9 @@ class WebWidgetHost {
|
||||
painting_ = value;
|
||||
#endif
|
||||
}
|
||||
|
||||
void EnsureTooltip();
|
||||
void ResetTooltip();
|
||||
|
||||
gfx::NativeView view_;
|
||||
WebKit::WebWidget* webwidget_;
|
||||
@ -125,6 +131,10 @@ class WebWidgetHost {
|
||||
|
||||
WebKit::WebKeyboardEvent last_key_event_;
|
||||
|
||||
gfx::NativeView tooltip_view_;
|
||||
std::wstring tooltip_text_;
|
||||
bool tooltip_showing_;
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool painting_;
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user