Commit 8287a0b5 authored by stanguturi@google.com's avatar stanguturi@google.com

Made changes to display tooltip window when user navigates through the icons...

Made changes to display tooltip window when user navigates through the icons in the toolbar using keyboard arrow keys.

I have already fixed this issue. (Issue:801). I have got LGTM also. But, I have checked in the code when tree was closed. So, all my changes were reverted. So, this new issue is created to upload the same changes.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139 0039d316-1c4b-4281-b951-d872f2087c98
parent a9da16d0
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include "chrome/views/view_container.h" #include "chrome/views/view_container.h"
#include "chrome/views/background.h" #include "chrome/views/background.h"
#include "chrome/views/label.h" #include "chrome/views/label.h"
#include "chrome/views/tooltip_manager.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
#include "generated_resources.h" #include "generated_resources.h"
...@@ -372,6 +373,9 @@ void BrowserToolbarView::DidGainFocus() { ...@@ -372,6 +373,9 @@ void BrowserToolbarView::DidGainFocus() {
void BrowserToolbarView::WillLoseFocus() { void BrowserToolbarView::WillLoseFocus() {
// Resetting focus state. // Resetting focus state.
acc_focused_view_->SetHotTracked(false); acc_focused_view_->SetHotTracked(false);
// Any tooltips that are active should be hidden when toolbar loses focus.
if (GetViewContainer() && GetViewContainer()->GetTooltipManager())
GetViewContainer()->GetTooltipManager()->HideKeyboardTooltip();
acc_focused_view_ = NULL; acc_focused_view_ = NULL;
} }
...@@ -395,6 +399,10 @@ bool BrowserToolbarView::OnKeyPressed(const ChromeViews::KeyEvent& e) { ...@@ -395,6 +399,10 @@ bool BrowserToolbarView::OnKeyPressed(const ChromeViews::KeyEvent& e) {
// VK_SPACE is already handled by the default case. // VK_SPACE is already handled by the default case.
if (acc_focused_view_->GetID() == VIEW_ID_PAGE_MENU || if (acc_focused_view_->GetID() == VIEW_ID_PAGE_MENU ||
acc_focused_view_->GetID() == VIEW_ID_APP_MENU) { acc_focused_view_->GetID() == VIEW_ID_APP_MENU) {
// If a menu button in toolbar is activated and its menu is displayed,
// then active tooltip should be hidden.
if (GetViewContainer()->GetTooltipManager())
GetViewContainer()->GetTooltipManager()->HideKeyboardTooltip();
// Safe to cast, given to above check. // Safe to cast, given to above check.
static_cast<ChromeViews::MenuButton*>(acc_focused_view_)->Activate(); static_cast<ChromeViews::MenuButton*>(acc_focused_view_)->Activate();
// Re-enable hot-tracking, as Activate() will disable it. // Re-enable hot-tracking, as Activate() will disable it.
...@@ -425,6 +433,10 @@ bool BrowserToolbarView::OnKeyPressed(const ChromeViews::KeyEvent& e) { ...@@ -425,6 +433,10 @@ bool BrowserToolbarView::OnKeyPressed(const ChromeViews::KeyEvent& e) {
int view_id = acc_focused_view_->GetID(); int view_id = acc_focused_view_->GetID();
HWND hwnd = GetViewContainer()->GetHWND(); HWND hwnd = GetViewContainer()->GetHWND();
// Show the tooltip for the view that got the focus.
if (GetViewContainer()->GetTooltipManager())
GetViewContainer()->GetTooltipManager()->
ShowKeyboardTooltip(GetChildViewAt(next_view));
// Notify Access Technology that there was a change in keyboard focus. // Notify Access Technology that there was a change in keyboard focus.
::NotifyWinEvent(EVENT_OBJECT_FOCUS, hwnd, OBJID_CLIENT, ::NotifyWinEvent(EVENT_OBJECT_FOCUS, hwnd, OBJID_CLIENT,
static_cast<LONG>(view_id)); static_cast<LONG>(view_id));
......
...@@ -63,6 +63,7 @@ void AeroTooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { ...@@ -63,6 +63,7 @@ void AeroTooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) {
if (last_mouse_x_ != x || last_mouse_y_ != y) { if (last_mouse_x_ != x || last_mouse_y_ != y) {
last_mouse_x_ = x; last_mouse_x_ = x;
last_mouse_y_ = y; last_mouse_y_ = y;
HideKeyboardTooltip();
UpdateTooltip(x, y); UpdateTooltip(x, y);
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/chrome_font.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/message_loop.h"
#include "chrome/common/l10n_util.h" #include "chrome/common/l10n_util.h"
#include "chrome/common/gfx/url_elider.h" #include "chrome/common/gfx/url_elider.h"
#include "chrome/common/win_util.h" #include "chrome/common/win_util.h"
...@@ -44,6 +45,10 @@ namespace ChromeViews { ...@@ -44,6 +45,10 @@ namespace ChromeViews {
//static //static
int TooltipManager::tooltip_height_ = 0; int TooltipManager::tooltip_height_ = 0;
// Default timeout for the tooltip displayed using keyboard.
// Timeout is mentioned in milliseconds.
static const int kDefaultTimeout = 4000;
// Maximum number of lines we allow in the tooltip. // Maximum number of lines we allow in the tooltip.
static const int kMaxLines = 6; static const int kMaxLines = 6;
...@@ -101,7 +106,10 @@ TooltipManager::TooltipManager(ViewContainer* container, HWND parent) ...@@ -101,7 +106,10 @@ TooltipManager::TooltipManager(ViewContainer* container, HWND parent)
tooltip_showing_(false), tooltip_showing_(false),
last_tooltip_view_(NULL), last_tooltip_view_(NULL),
last_view_out_of_sync_(false), last_view_out_of_sync_(false),
tooltip_width_(0) { tooltip_width_(0),
keyboard_tooltip_hwnd_(NULL),
#pragma warning(suppress: 4355)
keyboard_tooltip_factory_(this) {
DCHECK(container && parent); DCHECK(container && parent);
Init(); Init();
} }
...@@ -109,6 +117,8 @@ TooltipManager::TooltipManager(ViewContainer* container, HWND parent) ...@@ -109,6 +117,8 @@ TooltipManager::TooltipManager(ViewContainer* container, HWND parent)
TooltipManager::~TooltipManager() { TooltipManager::~TooltipManager() {
if (tooltip_hwnd_) if (tooltip_hwnd_)
DestroyWindow(tooltip_hwnd_); DestroyWindow(tooltip_hwnd_);
if (keyboard_tooltip_hwnd_)
DestroyWindow(keyboard_tooltip_hwnd_);
} }
void TooltipManager::Init() { void TooltipManager::Init() {
...@@ -154,7 +164,7 @@ void TooltipManager::TooltipTextChanged(View* view) { ...@@ -154,7 +164,7 @@ void TooltipManager::TooltipTextChanged(View* view) {
LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) { LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) {
*handled = false; *handled = false;
if (l_param->hwndFrom == tooltip_hwnd_) { if (l_param->hwndFrom == tooltip_hwnd_ && keyboard_tooltip_hwnd_ == NULL) {
switch (l_param->code) { switch (l_param->code) {
case TTN_GETDISPINFO: { case TTN_GETDISPINFO: {
if (last_view_out_of_sync_) { if (last_view_out_of_sync_) {
...@@ -183,7 +193,8 @@ LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) { ...@@ -183,7 +193,8 @@ LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) {
!tooltip_text_.empty()) { !tooltip_text_.empty()) {
// View has a valid tip, copy it into TOOLTIPINFO. // View has a valid tip, copy it into TOOLTIPINFO.
clipped_text_ = tooltip_text_; clipped_text_ = tooltip_text_;
TrimTooltipToFit(&clipped_text_, &tooltip_width_, &line_count_); TrimTooltipToFit(&clipped_text_, &tooltip_width_, &line_count_,
last_mouse_x_, last_mouse_y_, tooltip_hwnd_);
tooltip_info->lpszText = const_cast<WCHAR*>(clipped_text_.c_str()); tooltip_info->lpszText = const_cast<WCHAR*>(clipped_text_.c_str());
} else { } else {
tooltip_text_.clear(); tooltip_text_.clear();
...@@ -279,18 +290,21 @@ int TooltipManager::CalcTooltipHeight() { ...@@ -279,18 +290,21 @@ int TooltipManager::CalcTooltipHeight() {
void TooltipManager::TrimTooltipToFit(std::wstring* text, void TooltipManager::TrimTooltipToFit(std::wstring* text,
int* max_width, int* max_width,
int* line_count) { int* line_count,
int position_x,
int position_y,
HWND window) {
*max_width = 0; *max_width = 0;
*line_count = 0; *line_count = 0;
// Determine the available width for the tooltip. // Determine the available width for the tooltip.
CPoint screen_loc(last_mouse_x_, last_mouse_y_); CPoint screen_loc(position_x, position_y);
View::ConvertPointToScreen(view_container_->GetRootView(), &screen_loc); View::ConvertPointToScreen(view_container_->GetRootView(), &screen_loc);
gfx::Rect monitor_bounds = gfx::Rect monitor_bounds =
win_util::GetMonitorBoundsForRect(gfx::Rect(screen_loc.x, screen_loc.y, win_util::GetMonitorBoundsForRect(gfx::Rect(screen_loc.x, screen_loc.y,
0, 0)); 0, 0));
RECT tooltip_margin; RECT tooltip_margin;
SendMessage(tooltip_hwnd_, TTM_GETMARGIN, 0, (LPARAM)&tooltip_margin); SendMessage(window, TTM_GETMARGIN, 0, (LPARAM)&tooltip_margin);
const int available_width = monitor_bounds.width() - tooltip_margin.left - const int available_width = monitor_bounds.width() - tooltip_margin.left -
tooltip_margin.right; tooltip_margin.right;
if (available_width <= 0) if (available_width <= 0)
...@@ -352,6 +366,7 @@ void TooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { ...@@ -352,6 +366,7 @@ void TooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) {
if (u_msg != WM_MOUSEMOVE || last_mouse_x_ != x || last_mouse_y_ != y) { if (u_msg != WM_MOUSEMOVE || last_mouse_x_ != x || last_mouse_y_ != y) {
last_mouse_x_ = x; last_mouse_x_ = x;
last_mouse_y_ = y; last_mouse_y_ = y;
HideKeyboardTooltip();
UpdateTooltip(x, y); UpdateTooltip(x, y);
} }
// Forward the message onto the tooltip. // Forward the message onto the tooltip.
...@@ -363,4 +378,70 @@ void TooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { ...@@ -363,4 +378,70 @@ void TooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) {
SendMessage(tooltip_hwnd_, TTM_RELAYEVENT, 0, (LPARAM)&msg); SendMessage(tooltip_hwnd_, TTM_RELAYEVENT, 0, (LPARAM)&msg);
} }
void TooltipManager::ShowKeyboardTooltip(View* focused_view) {
if (tooltip_showing_) {
SendMessage(tooltip_hwnd_, TTM_POP, 0, 0);
tooltip_text_.clear();
}
HideKeyboardTooltip();
std::wstring tooltip_text;
if (!focused_view->GetTooltipText(0, 0, &tooltip_text))
return ;
CRect bounds;
focused_view->GetBounds(&bounds);
CPoint screen_point;
focused_view->ConvertPointToScreen(focused_view, &screen_point);
CPoint relative_point_coordinates;
focused_view->ConvertPointToViewContainer(focused_view,
&relative_point_coordinates);
keyboard_tooltip_hwnd_ = CreateWindowEx(
WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(),
TOOLTIPS_CLASS, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
SendMessage(keyboard_tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0,
std::numeric_limits<short>::max());
int tooltip_width;
int line_count;
TrimTooltipToFit(&tooltip_text, &tooltip_width, &line_count,
relative_point_coordinates.x, relative_point_coordinates.y,
keyboard_tooltip_hwnd_);
TOOLINFO keyboard_toolinfo;
memset(&keyboard_toolinfo, 0, sizeof(keyboard_toolinfo));
keyboard_toolinfo.cbSize = sizeof(keyboard_toolinfo);
keyboard_toolinfo.hwnd = parent_;
keyboard_toolinfo.uFlags = TTF_TRACK | TTF_TRANSPARENT | TTF_IDISHWND ;
keyboard_toolinfo.lpszText = const_cast<WCHAR*>(tooltip_text.c_str());
SendMessage(keyboard_tooltip_hwnd_, TTM_ADDTOOL, 0,
reinterpret_cast<LPARAM>(&keyboard_toolinfo));
SendMessage(keyboard_tooltip_hwnd_, TTM_TRACKACTIVATE, TRUE,
reinterpret_cast<LPARAM>(&keyboard_toolinfo));
if (!tooltip_height_)
tooltip_height_ = CalcTooltipHeight();
RECT rect_bounds = {screen_point.x, screen_point.y + bounds.Height(),
screen_point.x + tooltip_width,
screen_point.y + bounds.Height() +
line_count * tooltip_height_ };
gfx::Rect monitor_bounds =
win_util::GetMonitorBoundsForRect(gfx::Rect(rect_bounds));
rect_bounds = gfx::Rect(rect_bounds).AdjustToFit(monitor_bounds).ToRECT();
::SetWindowPos(keyboard_tooltip_hwnd_, NULL, rect_bounds.left,
rect_bounds.top, 0, 0,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
MessageLoop::current()->PostDelayedTask(FROM_HERE,
keyboard_tooltip_factory_.NewRunnableMethod(
&TooltipManager::DestroyKeyboardTooltipWindow, keyboard_tooltip_hwnd_),
kDefaultTimeout);
}
void TooltipManager::HideKeyboardTooltip() {
if (keyboard_tooltip_hwnd_ != NULL) {
SendMessage(keyboard_tooltip_hwnd_, WM_CLOSE, 0, 0);
keyboard_tooltip_hwnd_ = NULL;
}
}
void TooltipManager::DestroyKeyboardTooltipWindow(HWND window_to_destroy) {
if (keyboard_tooltip_hwnd_ == window_to_destroy)
HideKeyboardTooltip();
}
} // namespace ChromeViews } // namespace ChromeViews
\ No newline at end of file
...@@ -92,6 +92,12 @@ class TooltipManager { ...@@ -92,6 +92,12 @@ class TooltipManager {
// Invoked when the tooltip text changes for the specified views. // Invoked when the tooltip text changes for the specified views.
void TooltipTextChanged(View* view); void TooltipTextChanged(View* view);
// Invoked when toolbar icon gets focus.
void ShowKeyboardTooltip(View* view);
// Invoked when toolbar loses focus.
void HideKeyboardTooltip();
// Message handlers. These forward to the tooltip control. // Message handlers. These forward to the tooltip control.
virtual void OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param); virtual void OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param);
LRESULT OnNotify(int w_param, NMHDR* l_param, bool* handled); LRESULT OnNotify(int w_param, NMHDR* l_param, bool* handled);
...@@ -132,7 +138,13 @@ class TooltipManager { ...@@ -132,7 +138,13 @@ class TooltipManager {
// of text in the tooltip. // of text in the tooltip.
void TrimTooltipToFit(std::wstring* text, void TrimTooltipToFit(std::wstring* text,
int* width, int* width,
int* line_count); int* line_count,
int position_x,
int position_y,
HWND window);
// Invoked when the timer elapses and tooltip has to be destroyed.
void DestroyKeyboardTooltipWindow(HWND window_to_destroy);
// Hosting view container. // Hosting view container.
ViewContainer* view_container_; ViewContainer* view_container_;
...@@ -161,6 +173,13 @@ class TooltipManager { ...@@ -161,6 +173,13 @@ class TooltipManager {
// Height for a tooltip; lazily calculated. // Height for a tooltip; lazily calculated.
static int tooltip_height_; static int tooltip_height_;
// control window for tooltip displayed using keyboard.
HWND keyboard_tooltip_hwnd_;
// Used to register DestroyTooltipWindow function with postdelayedtask
// function.
ScopedRunnableMethodFactory<TooltipManager> keyboard_tooltip_factory_;
DISALLOW_EVIL_CONSTRUCTORS(TooltipManager); DISALLOW_EVIL_CONSTRUCTORS(TooltipManager);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment