summaryrefslogtreecommitdiffstats
path: root/chrome/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-14 23:45:09 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-14 23:45:09 +0000
commit613b80638081101368e31300f6e729c720b160e0 (patch)
tree0b3dc7c7e0dde27abc814d13bdff3a1758ccde2f /chrome/views
parent41a5ca123f45f471457485e87681c02a21a2f052 (diff)
downloadchromium_src-613b80638081101368e31300f6e729c720b160e0.zip
chromium_src-613b80638081101368e31300f6e729c720b160e0.tar.gz
chromium_src-613b80638081101368e31300f6e729c720b160e0.tar.bz2
Convert HitTest/GetViewForPoint to use gfx::Point
http://crbug.com/2186 Review URL: http://codereview.chromium.org/7331 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3384 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r--chrome/views/accessibility/view_accessibility.cc4
-rw-r--r--chrome/views/base_button.cc8
-rw-r--r--chrome/views/button_dropdown.cc4
-rw-r--r--chrome/views/chrome_menu.cc6
-rw-r--r--chrome/views/link.cc4
-rw-r--r--chrome/views/menu_button.cc4
-rw-r--r--chrome/views/root_view.cc6
-rw-r--r--chrome/views/root_view_drop_target.cc2
-rw-r--r--chrome/views/tooltip_manager.cc5
-rw-r--r--chrome/views/view.cc22
-rw-r--r--chrome/views/view.h7
-rw-r--r--chrome/views/view_unittest.cc12
12 files changed, 44 insertions, 40 deletions
diff --git a/chrome/views/accessibility/view_accessibility.cc b/chrome/views/accessibility/view_accessibility.cc
index 6122757..af502fc 100644
--- a/chrome/views/accessibility/view_accessibility.cc
+++ b/chrome/views/accessibility/view_accessibility.cc
@@ -495,7 +495,7 @@ STDMETHODIMP ViewAccessibility::accHitTest(LONG x_left, LONG y_top,
gfx::Point pt(x_left, y_top);
ChromeViews::View::ConvertPointToView(NULL, view_, &pt);
- if (!view_->HitTest(pt.ToPOINT())) {
+ if (!view_->HitTest(pt)) {
// If containing parent is not hit, return with failure.
child->vt = VT_EMPTY;
return S_FALSE;
@@ -508,7 +508,7 @@ STDMETHODIMP ViewAccessibility::accHitTest(LONG x_left, LONG y_top,
// Search for hit within any of the children.
child_view = view_->GetChildViewAt(child_id);
ChromeViews::View::ConvertPointToView(view_, child_view, &pt);
- if (child_view->HitTest(pt.ToPOINT())) {
+ if (child_view->HitTest(pt)) {
// Store child_id (adjusted with +1 to convert to MSAA indexing).
child->lVal = child_id + 1;
child_hit = true;
diff --git a/chrome/views/base_button.cc b/chrome/views/base_button.cc
index e9ab838..325fc4d 100644
--- a/chrome/views/base_button.cc
+++ b/chrome/views/base_button.cc
@@ -144,7 +144,7 @@ void BaseButton::SetTooltipText(const std::wstring& tooltip) {
bool BaseButton::OnMousePressed(const ChromeViews::MouseEvent& e) {
if (state_ != BS_DISABLED) {
- if (IsTriggerableEvent(e) && HitTest(WTL::CPoint(e.x(), e.y()))) {
+ if (IsTriggerableEvent(e) && HitTest(e.location())) {
SetState(BS_PUSHED);
}
if (IsFocusable())
@@ -155,7 +155,7 @@ bool BaseButton::OnMousePressed(const ChromeViews::MouseEvent& e) {
bool BaseButton::OnMouseDragged(const ChromeViews::MouseEvent& e) {
if (state_ != BS_DISABLED) {
- if (!HitTest(WTL::CPoint(e.x(), e.y())))
+ if (!HitTest(e.location()))
SetState(BS_NORMAL);
else if (IsTriggerableEvent(e))
SetState(BS_PUSHED);
@@ -173,7 +173,7 @@ void BaseButton::OnMouseReleased(const ChromeViews::MouseEvent& e,
}
if (state_ != BS_DISABLED) {
- if (canceled || !HitTest(WTL::CPoint(e.x(), e.y()))) {
+ if (canceled || !HitTest(e.location())) {
SetState(BS_NORMAL);
} else {
SetState(BS_HOT);
@@ -198,7 +198,7 @@ void BaseButton::OnMouseMoved(const ChromeViews::MouseEvent& e) {
using namespace ChromeViews;
if (state_ != BS_DISABLED) {
- if (HitTest(WTL::CPoint(e.x(), e.y()))) {
+ if (HitTest(e.location())) {
SetState(BS_HOT);
} else {
SetState(BS_NORMAL);
diff --git a/chrome/views/button_dropdown.cc b/chrome/views/button_dropdown.cc
index 11523b6..a2d473b 100644
--- a/chrome/views/button_dropdown.cc
+++ b/chrome/views/button_dropdown.cc
@@ -40,7 +40,7 @@ ButtonDropDown::~ButtonDropDown() {
////////////////////////////////////////////////////////////////////////////////
bool ButtonDropDown::OnMousePressed(const ChromeViews::MouseEvent& e) {
- if (IsEnabled() && e.IsLeftMouseButton() && HitTest(WTL::CPoint(e.x(), e.y()))) {
+ if (IsEnabled() && e.IsLeftMouseButton() && HitTest(e.location())) {
// Store the y pos of the mouse coordinates so we can use them later to
// determine if the user dragged the mouse down (which should pop up the
// drag down menu immediately, instead of waiting for the timer)
@@ -66,7 +66,7 @@ void ButtonDropDown::OnMouseReleased(const ChromeViews::MouseEvent& e,
if (e.IsLeftMouseButton())
show_menu_factory_.RevokeAll();
- if (IsEnabled() && e.IsRightMouseButton() && HitTest(WTL::CPoint(e.x(), e.y()))) {
+ if (IsEnabled() && e.IsRightMouseButton() && HitTest(e.location())) {
show_menu_factory_.RevokeAll();
// Make the button look depressed while the menu is open.
// NOTE: SetState() schedules a paint, but it won't occur until after the
diff --git a/chrome/views/chrome_menu.cc b/chrome/views/chrome_menu.cc
index 1e73954..a343efa 100644
--- a/chrome/views/chrome_menu.cc
+++ b/chrome/views/chrome_menu.cc
@@ -2148,7 +2148,7 @@ void MenuController::CloseAllNestedMenus() {
}
MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) {
- View* child_under_mouse = source->GetViewForPoint(CPoint(x, y));
+ View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y));
if (child_under_mouse && child_under_mouse->IsEnabled() &&
child_under_mouse->GetID() == MenuItemView::kMenuItemViewID) {
return static_cast<MenuItemView*>(child_under_mouse);
@@ -2157,7 +2157,7 @@ MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) {
}
MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) {
- View* child_under_mouse = source->GetViewForPoint(CPoint(x, y));
+ View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y));
if (child_under_mouse &&
child_under_mouse->GetID() == EmptyMenuMenuItem::kEmptyMenuItemViewID) {
return static_cast<MenuItemView*>(child_under_mouse);
@@ -2170,7 +2170,7 @@ bool MenuController::IsScrollButtonAt(SubmenuView* source,
int y,
MenuPart::Type* part) {
MenuScrollViewContainer* scroll_view = source->GetScrollViewContainer();
- View* child_under_mouse = scroll_view->GetViewForPoint(CPoint(x, y));
+ View* child_under_mouse = scroll_view->GetViewForPoint(gfx::Point(x, y));
if (child_under_mouse && child_under_mouse->IsEnabled()) {
if (child_under_mouse == scroll_view->scroll_up_button()) {
*part = MenuPart::SCROLL_UP;
diff --git a/chrome/views/link.cc b/chrome/views/link.cc
index 8350a7b..2d04864 100644
--- a/chrome/views/link.cc
+++ b/chrome/views/link.cc
@@ -84,7 +84,7 @@ bool Link::OnMousePressed(const MouseEvent& e) {
bool Link::OnMouseDragged(const MouseEvent& e) {
SetHighlighted(enabled_ &&
(e.IsLeftMouseButton() || e.IsMiddleMouseButton()) &&
- HitTest(WTL::CPoint(e.x(), e.y())));
+ HitTest(e.location()));
return true;
}
@@ -94,7 +94,7 @@ void Link::OnMouseReleased(const MouseEvent& e, bool canceled) {
SetHighlighted(false);
if (enabled_ && !canceled &&
(e.IsLeftMouseButton() || e.IsMiddleMouseButton()) &&
- HitTest(WTL::CPoint(e.x(), e.y()))) {
+ HitTest(e.location())) {
// Focus the link on click.
RequestFocus();
diff --git a/chrome/views/menu_button.cc b/chrome/views/menu_button.cc
index f8b0980..b8fd1b6 100644
--- a/chrome/views/menu_button.cc
+++ b/chrome/views/menu_button.cc
@@ -183,7 +183,7 @@ bool MenuButton::OnMousePressed(const ChromeViews::MouseEvent& e) {
if (GetState() != BS_DISABLED) {
// If we're draggable (GetDragOperations returns a non-zero value), then
// don't pop on press, instead wait for release.
- if (e.IsOnlyLeftMouseButton() && HitTest(WTL::CPoint(e.x(), e.y())) &&
+ if (e.IsOnlyLeftMouseButton() && HitTest(e.location()) &&
GetDragOperations(e.x(), e.y()) == DragDropTypes::DRAG_NONE) {
TimeDelta delta = Time::Now() - menu_closed_time_;
int64 delta_in_milliseconds = delta.InMilliseconds();
@@ -199,7 +199,7 @@ void MenuButton::OnMouseReleased(const ChromeViews::MouseEvent& e,
bool canceled) {
if (GetDragOperations(e.x(), e.y()) != DragDropTypes::DRAG_NONE &&
GetState() != BS_DISABLED && !canceled && !InDrag() &&
- e.IsOnlyLeftMouseButton() && HitTest(WTL::CPoint(e.x(), e.y()))) {
+ e.IsOnlyLeftMouseButton() && HitTest(e.location())) {
Activate();
} else {
TextButton::OnMouseReleased(e, canceled);
diff --git a/chrome/views/root_view.cc b/chrome/views/root_view.cc
index 3004db9..c5b1979 100644
--- a/chrome/views/root_view.cc
+++ b/chrome/views/root_view.cc
@@ -278,7 +278,7 @@ bool RootView::OnMousePressed(const MouseEvent& e) {
bool hit_disabled_view = false;
// Walk up the tree until we find a view that wants the mouse event.
- for (mouse_pressed_handler_ = GetViewForPoint(WTL::CPoint(e.x(), e.y()));
+ for (mouse_pressed_handler_ = GetViewForPoint(e.location());
mouse_pressed_handler_ && (mouse_pressed_handler_ != this);
mouse_pressed_handler_ = mouse_pressed_handler_->GetParent()) {
if (!mouse_pressed_handler_->IsEnabled()) {
@@ -387,7 +387,7 @@ void RootView::OnMouseReleased(const MouseEvent& e, bool canceled) {
}
void RootView::UpdateCursor(const MouseEvent& e) {
- View *v = GetViewForPoint(e.location().ToPOINT());
+ View *v = GetViewForPoint(e.location());
if (v && v != this) {
gfx::Point l(e.location());
@@ -404,7 +404,7 @@ void RootView::UpdateCursor(const MouseEvent& e) {
}
void RootView::OnMouseMoved(const MouseEvent& e) {
- View *v = GetViewForPoint(WTL::CPoint(e.x(), e.y()));
+ View *v = GetViewForPoint(e.location());
// Find the first enabled view.
while (v && !v->IsEnabled())
v = v->GetParent();
diff --git a/chrome/views/root_view_drop_target.cc b/chrome/views/root_view_drop_target.cc
index 405f17b..fae3265 100644
--- a/chrome/views/root_view_drop_target.cc
+++ b/chrome/views/root_view_drop_target.cc
@@ -100,7 +100,7 @@ DWORD RootViewDropTarget::OnDrop(IDataObject* data_object,
View* RootViewDropTarget::CalculateTargetView(
const gfx::Point& root_view_location,
const OSExchangeData& data) {
- View* view = root_view_->GetViewForPoint(root_view_location.ToPOINT());
+ View* view = root_view_->GetViewForPoint(root_view_location);
if (view == deepest_view_) {
// The view the mouse is over hasn't changed; reuse the target.
return target_view_;
diff --git a/chrome/views/tooltip_manager.cc b/chrome/views/tooltip_manager.cc
index 4d4e4d8..e4ea574 100644
--- a/chrome/views/tooltip_manager.cc
+++ b/chrome/views/tooltip_manager.cc
@@ -148,7 +148,8 @@ LRESULT TooltipManager::OnNotify(int w_param, NMHDR* l_param, bool* handled) {
if (last_view_out_of_sync_) {
// View under the mouse is out of sync, determine it now.
RootView* root_view = view_container_->GetRootView();
- last_tooltip_view_ = root_view->GetViewForPoint(CPoint(last_mouse_x_, last_mouse_y_));
+ last_tooltip_view_ = root_view->GetViewForPoint(
+ gfx::Point(last_mouse_x_, last_mouse_y_));
last_view_out_of_sync_ = false;
}
// Tooltip control is asking for the tooltip to display.
@@ -319,7 +320,7 @@ void TooltipManager::TrimTooltipToFit(std::wstring* text,
void TooltipManager::UpdateTooltip(int x, int y) {
RootView* root_view = view_container_->GetRootView();
- View* view = root_view->GetViewForPoint(CPoint(x, y));
+ View* view = root_view->GetViewForPoint(gfx::Point(x, y));
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.
diff --git a/chrome/views/view.cc b/chrome/views/view.cc
index 5c86215..f73ca92 100644
--- a/chrome/views/view.cc
+++ b/chrome/views/view.cc
@@ -529,7 +529,7 @@ void View::SetContextMenuController(ContextMenuController* menu_controller) {
bool View::ProcessMousePressed(const MouseEvent& e, DragInfo* drag_info) {
const bool enabled = enabled_;
int drag_operations;
- if (enabled && e.IsOnlyLeftMouseButton() && HitTest(WTL::CPoint(e.x(), e.y())))
+ if (enabled && e.IsOnlyLeftMouseButton() && HitTest(e.location()))
drag_operations = GetDragOperations(e.x(), e.y());
else
drag_operations = 0;
@@ -754,7 +754,7 @@ void View::PropagateVisibilityNotifications(View* start, bool is_visible) {
void View::VisibilityChanged(View* starting_from, bool is_visible) {
}
-View* View::GetViewForPoint(const CPoint& point) {
+View* View::GetViewForPoint(const gfx::Point& point) {
return GetViewForPoint(point, true);
}
@@ -775,7 +775,8 @@ bool View::GetNotifyWhenVisibleBoundsInRootChanges() {
return notify_when_visible_bounds_in_root_changes_;
}
-View* View::GetViewForPoint(const CPoint& point, bool can_create_floating) {
+View* View::GetViewForPoint(const gfx::Point& point,
+ bool can_create_floating) {
// Walk the child Views recursively looking for the View that most
// tightly encloses the specified point.
for (int i = GetChildViewCount() - 1 ; i >= 0 ; --i) {
@@ -785,8 +786,8 @@ View* View::GetViewForPoint(const CPoint& point, bool can_create_floating) {
gfx::Point point_in_child_coords(point);
View::ConvertPointToView(this, child, &point_in_child_coords);
- if (child->HitTest(point_in_child_coords.ToPOINT()))
- return child->GetViewForPoint(point_in_child_coords.ToPOINT(), true);
+ if (child->HitTest(point_in_child_coords))
+ return child->GetViewForPoint(point_in_child_coords, true);
}
// We haven't found a view for the point. Try to create floating views
@@ -795,7 +796,8 @@ View* View::GetViewForPoint(const CPoint& point, bool can_create_floating) {
// GetFloatingViewIDForPoint lies or if RetrieveFloatingViewForID creates a
// view which doesn't contain the provided point
int id;
- if (can_create_floating && GetFloatingViewIDForPoint(point.x, point.y, &id)) {
+ if (can_create_floating &&
+ GetFloatingViewIDForPoint(point.x(), point.y(), &id)) {
RetrieveFloatingViewForID(id); // This creates the floating view.
return GetViewForPoint(point, false);
}
@@ -1425,14 +1427,14 @@ bool View::IsVisibleInRootView() const {
return false;
}
-bool View::HitTest(const CPoint& l) const {
- if (l.x >= 0 && l.x < static_cast<int>(width()) &&
- l.y >= 0 && l.y < static_cast<int>(height())) {
+bool View::HitTest(const gfx::Point& l) const {
+ if (l.x() >= 0 && l.x() < static_cast<int>(width()) &&
+ l.y() >= 0 && l.y() < static_cast<int>(height())) {
if (HasHitTestMask()) {
gfx::Path mask;
GetHitTestMask(&mask);
ScopedHRGN rgn(mask.CreateHRGN());
- return !!PtInRegion(rgn, l.x, l.y);
+ return !!PtInRegion(rgn, l.x(), l.y());
}
// No mask, but inside our bounds.
return true;
diff --git a/chrome/views/view.h b/chrome/views/view.h
index 75ef38e..d56d94f 100644
--- a/chrome/views/view.h
+++ b/chrome/views/view.h
@@ -427,7 +427,7 @@ class View : public AcceleratorTarget {
int GetChildViewCount() const;
// Get the child View at the specified point.
- virtual View* GetViewForPoint(const CPoint& point);
+ virtual View* GetViewForPoint(const gfx::Point& point);
// Get the containing ViewContainer
virtual ViewContainer* GetViewContainer() const;
@@ -893,7 +893,7 @@ class View : public AcceleratorTarget {
virtual HCURSOR GetCursorForPoint(Event::EventType event_type, int x, int y);
// Convenience to test whether a point is within this view's bounds
- virtual bool HitTest(const CPoint &l) const;
+ virtual bool HitTest(const gfx::Point& l) const;
// Gets the tooltip for this View. If the View does not have a tooltip,
// return false. If the View does have a tooltip, copy the tooltip into
@@ -1022,7 +1022,8 @@ class View : public AcceleratorTarget {
void TooltipTextChanged();
// Actual implementation of GetViewForPoint.
- virtual View* GetViewForPoint(const CPoint& point, bool can_create_floating);
+ virtual View* GetViewForPoint(const gfx::Point& point,
+ bool can_create_floating);
// Sets whether this view wants notification when its visible bounds relative
// to the root view changes. If true, this view is notified any time the
diff --git a/chrome/views/view_unittest.cc b/chrome/views/view_unittest.cc
index e476bd1..91c556c 100644
--- a/chrome/views/view_unittest.cc
+++ b/chrome/views/view_unittest.cc
@@ -538,10 +538,10 @@ class HitTestView : public ChromeViews::View {
DISALLOW_COPY_AND_ASSIGN(HitTestView);
};
-POINT ConvertPointToView(ChromeViews::View* view, const POINT& p) {
+gfx::Point ConvertPointToView(ChromeViews::View* view, const gfx::Point& p) {
gfx::Point tmp(p);
ChromeViews::View::ConvertPointToView(view->GetRootView(), view, &tmp);
- return tmp.ToPOINT();
+ return tmp;
}
}
@@ -560,10 +560,10 @@ TEST_F(ViewTest, HitTestMasks) {
v2->SetBounds(v2_bounds.ToRECT());
root_view->AddChildView(v2);
- POINT v1_centerpoint = v1_bounds.CenterPoint().ToPOINT();
- POINT v2_centerpoint = v2_bounds.CenterPoint().ToPOINT();
- POINT v1_origin = v1_bounds.origin().ToPOINT();
- POINT v2_origin = v2_bounds.origin().ToPOINT();
+ gfx::Point v1_centerpoint = v1_bounds.CenterPoint();
+ gfx::Point v2_centerpoint = v2_bounds.CenterPoint();
+ gfx::Point v1_origin = v1_bounds.origin();
+ gfx::Point v2_origin = v2_bounds.origin();
// Test HitTest
EXPECT_EQ(true, v1->HitTest(ConvertPointToView(v1, v1_centerpoint)));