diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 21:29:16 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-04 21:29:16 +0000 |
commit | 8cefdea4356a7007ddc26fc77c6cad2fac0ce7d0 (patch) | |
tree | fc172944eb761781da019c8de96f512db624902e /views | |
parent | fcc4447615226cb80f28fade563e50d3328d5908 (diff) | |
download | chromium_src-8cefdea4356a7007ddc26fc77c6cad2fac0ce7d0.zip chromium_src-8cefdea4356a7007ddc26fc77c6cad2fac0ce7d0.tar.gz chromium_src-8cefdea4356a7007ddc26fc77c6cad2fac0ce7d0.tar.bz2 |
Clean up TooltipManagerWin a bit. Original patch by Jay Soffian (see http://codereview.chromium.org/668021 ), r=me.
BUG=37368
TEST=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40662 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/widget/aero_tooltip_manager.cc | 15 | ||||
-rw-r--r-- | views/widget/tooltip_manager_win.cc | 39 | ||||
-rw-r--r-- | views/widget/tooltip_manager_win.h | 10 |
3 files changed, 28 insertions, 36 deletions
diff --git a/views/widget/aero_tooltip_manager.cc b/views/widget/aero_tooltip_manager.cc index 8c50099..b7ae5d2 100644 --- a/views/widget/aero_tooltip_manager.cc +++ b/views/widget/aero_tooltip_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -39,11 +39,10 @@ void AeroTooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { ::MapWindowPoints(HWND_DESKTOP, GetParent(), &temp, 1); mouse_pos.SetPoint(temp.x, temp.y); } - if (last_mouse_x_ != mouse_pos.x() || last_mouse_y_ != mouse_pos.y()) { - last_mouse_x_ = mouse_pos.x(); - last_mouse_y_ = mouse_pos.y(); + if (last_mouse_pos_ != mouse_pos) { + last_mouse_pos_ = mouse_pos; HideKeyboardTooltip(); - UpdateTooltip(mouse_pos.x(), mouse_pos.y()); + UpdateTooltip(mouse_pos); } // Delay opening of the tooltip just in case the user moves their @@ -64,7 +63,7 @@ void AeroTooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { } void AeroTooltipManager::OnMouseLeave() { - last_mouse_x_ = last_mouse_y_ = -1; + last_mouse_pos_.SetPoint(-1, -1); UpdateTooltip(); } @@ -99,9 +98,7 @@ void AeroTooltipManager::Init() { void AeroTooltipManager::OnTimer() { initial_timer_ = NULL; - POINT pt; - pt.x = last_mouse_x_; - pt.y = last_mouse_y_; + POINT pt = last_mouse_pos_.ToPOINT(); ::ClientToScreen(GetParent(), &pt); // Set the position and visibility. diff --git a/views/widget/tooltip_manager_win.cc b/views/widget/tooltip_manager_win.cc index cee8248..c86bc76 100644 --- a/views/widget/tooltip_manager_win.cc +++ b/views/widget/tooltip_manager_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -70,8 +70,7 @@ int TooltipManager::GetMaxWidth(int x, int y) { TooltipManagerWin::TooltipManagerWin(Widget* widget) : widget_(widget), - last_mouse_x_(-1), - last_mouse_y_(-1), + last_mouse_pos_(-1,-1), tooltip_showing_(false), last_tooltip_view_(NULL), last_view_out_of_sync_(false), @@ -135,7 +134,7 @@ void TooltipManagerWin::UpdateTooltip() { void TooltipManagerWin::TooltipTextChanged(View* view) { if (view == last_tooltip_view_) - UpdateTooltip(last_mouse_x_, last_mouse_y_); + UpdateTooltip(last_mouse_pos_); } LRESULT TooltipManagerWin::OnNotify(int w_param, @@ -148,8 +147,7 @@ LRESULT TooltipManagerWin::OnNotify(int w_param, if (last_view_out_of_sync_) { // View under the mouse is out of sync, determine it now. RootView* root_view = widget_->GetRootView(); - last_tooltip_view_ = root_view->GetViewForPoint( - gfx::Point(last_mouse_x_, last_mouse_y_)); + last_tooltip_view_ = root_view->GetViewForPoint(last_mouse_pos_); last_view_out_of_sync_ = false; } // Tooltip control is asking for the tooltip to display. @@ -164,7 +162,7 @@ LRESULT TooltipManagerWin::OnNotify(int w_param, if (last_tooltip_view_ != NULL) { tooltip_text_.clear(); // Mouse is over a View, ask the View for it's tooltip. - gfx::Point view_loc(last_mouse_x_, last_mouse_y_); + gfx::Point view_loc = last_mouse_pos_; View::ConvertPointToView(widget_->GetRootView(), last_tooltip_view_, &view_loc); if (last_tooltip_view_->GetTooltipText(view_loc.x(), view_loc.y(), @@ -172,7 +170,7 @@ LRESULT TooltipManagerWin::OnNotify(int w_param, !tooltip_text_.empty()) { // View has a valid tip, copy it into TOOLTIPINFO. clipped_text_ = tooltip_text_; - gfx::Point screen_loc(last_mouse_x_, last_mouse_y_); + gfx::Point screen_loc = last_mouse_pos_; View::ConvertPointToScreen(widget_->GetRootView(), &screen_loc); TrimTooltipToFit(&clipped_text_, &tooltip_width_, &line_count_, screen_loc.x(), screen_loc.y()); @@ -198,7 +196,7 @@ LRESULT TooltipManagerWin::OnNotify(int w_param, gfx::Point text_origin; if (tooltip_height_ == 0) tooltip_height_ = CalcTooltipHeight(); - gfx::Point view_loc(last_mouse_x_, last_mouse_y_); + gfx::Point view_loc = last_mouse_pos_; View::ConvertPointToView(widget_->GetRootView(), last_tooltip_view_, &view_loc); if (last_tooltip_view_->GetTooltipTextOrigin( @@ -272,9 +270,9 @@ int TooltipManagerWin::CalcTooltipHeight() { return height + tooltip_margin.top + tooltip_margin.bottom; } -void TooltipManagerWin::UpdateTooltip(int x, int y) { +void TooltipManagerWin::UpdateTooltip(const gfx::Point& mouse_pos) { RootView* root_view = widget_->GetRootView(); - View* view = root_view->GetViewForPoint(gfx::Point(x, y)); + View* view = root_view->GetViewForPoint(mouse_pos); if (view != last_tooltip_view_) { // NOTE: This *must* be sent regardless of the visibility of the tooltip. // It triggers Windows to ask for the tooltip again. @@ -283,7 +281,7 @@ void TooltipManagerWin::UpdateTooltip(int x, int y) { } else if (last_tooltip_view_ != NULL) { // Tooltip is showing, and mouse is over the same view. See if the tooltip // text has changed. - gfx::Point view_point(x, y); + gfx::Point view_point = mouse_pos; View::ConvertPointToView(root_view, last_tooltip_view_, &view_point); std::wstring new_tooltip_text; bool has_tooltip_text = last_tooltip_view_->GetTooltipText( @@ -300,22 +298,19 @@ void TooltipManagerWin::UpdateTooltip(int x, int y) { } void TooltipManagerWin::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { - int x = GET_X_LPARAM(l_param); - int y = GET_Y_LPARAM(l_param); + gfx::Point mouse_pos(l_param); if (u_msg >= WM_NCMOUSEMOVE && u_msg <= WM_NCXBUTTONDBLCLK) { // NC message coordinates are in screen coordinates. - gfx::Rect frame_bounds; - widget_->GetBounds(&frame_bounds, true); - x -= frame_bounds.x(); - y -= frame_bounds.y(); + POINT temp = mouse_pos.ToPOINT(); + ::MapWindowPoints(HWND_DESKTOP, GetParent(), &temp, 1); + mouse_pos.SetPoint(temp.x, temp.y); } - if (u_msg != WM_MOUSEMOVE || last_mouse_x_ != x || last_mouse_y_ != y) { - last_mouse_x_ = x; - last_mouse_y_ = y; + if (u_msg != WM_MOUSEMOVE || last_mouse_pos_ != mouse_pos) { + last_mouse_pos_ = mouse_pos; HideKeyboardTooltip(); - UpdateTooltip(x, y); + UpdateTooltip(mouse_pos); } // Forward the message onto the tooltip. MSG msg; diff --git a/views/widget/tooltip_manager_win.h b/views/widget/tooltip_manager_win.h index af5e3fe..5a05a45 100644 --- a/views/widget/tooltip_manager_win.h +++ b/views/widget/tooltip_manager_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,11 +11,12 @@ #include "app/gfx/native_widget_types.h" #include "base/basictypes.h" +#include "base/gfx/point.h" #include "base/task.h" #include "views/widget/tooltip_manager.h" namespace gfx { -class Font; +class Point; } namespace views { @@ -84,7 +85,7 @@ class TooltipManagerWin : public TooltipManager { gfx::NativeView GetParent(); // Updates the tooltip for the specified location. - void UpdateTooltip(int x, int y); + void UpdateTooltip(const gfx::Point& location); // Tooltip control window. HWND tooltip_hwnd_; @@ -93,8 +94,7 @@ class TooltipManagerWin : public TooltipManager { TOOLINFO toolinfo_; // Last location of the mouse. This is in the coordinates of the rootview. - int last_mouse_x_; - int last_mouse_y_; + gfx::Point last_mouse_pos_; // Whether or not the tooltip is showing. bool tooltip_showing_; |