Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: chrome/views/view.cc

Issue 7317: Change all ConvertPointTo* methods to use gfx::Point instead of CPoint.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/views/view.h ('k') | chrome/views/view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/views/view.h" 5 #include "chrome/views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #ifndef NDEBUG 9 #ifndef NDEBUG
10 #include <iostream> 10 #include <iostream>
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // Fall through to return value based on context menu controller. 562 // Fall through to return value based on context menu controller.
563 } 563 }
564 // WARNING: we may have been deleted. 564 // WARNING: we may have been deleted.
565 return (context_menu_controller != NULL) || possible_drag; 565 return (context_menu_controller != NULL) || possible_drag;
566 } 566 }
567 567
568 void View::ProcessMouseReleased(const MouseEvent& e, bool canceled) { 568 void View::ProcessMouseReleased(const MouseEvent& e, bool canceled) {
569 if (!canceled && context_menu_controller_ && e.IsOnlyRightMouseButton()) { 569 if (!canceled && context_menu_controller_ && e.IsOnlyRightMouseButton()) {
570 // Assume that if there is a context menu controller we won't be deleted 570 // Assume that if there is a context menu controller we won't be deleted
571 // from mouse released. 571 // from mouse released.
572 CPoint location(e.x(), e.y()); 572 gfx::Point location(e.location());
573 ConvertPointToScreen(this, &location); 573 ConvertPointToScreen(this, &location);
574 ContextMenuController* context_menu_controller = context_menu_controller_; 574 ContextMenuController* context_menu_controller = context_menu_controller_;
575 OnMouseReleased(e, canceled); 575 OnMouseReleased(e, canceled);
576 context_menu_controller_->ShowContextMenu(this, location.x, location.y, 576 context_menu_controller_->ShowContextMenu(this, location.x(), location.y(),
577 true); 577 true);
578 } else { 578 } else {
579 OnMouseReleased(e, canceled); 579 OnMouseReleased(e, canceled);
580 } 580 }
581 // WARNING: we may have been deleted. 581 // WARNING: we may have been deleted.
582 } 582 }
583 583
584 void View::DoDrag(const MouseEvent& e, int press_x, int press_y) { 584 void View::DoDrag(const MouseEvent& e, int press_x, int press_y) {
585 scoped_refptr<OSExchangeData> data = new OSExchangeData; 585 scoped_refptr<OSExchangeData> data = new OSExchangeData;
586 WriteDragData(press_x, press_y, data.get()); 586 WriteDragData(press_x, press_y, data.get());
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 } 776 }
777 777
778 View* View::GetViewForPoint(const CPoint& point, bool can_create_floating) { 778 View* View::GetViewForPoint(const CPoint& point, bool can_create_floating) {
779 // Walk the child Views recursively looking for the View that most 779 // Walk the child Views recursively looking for the View that most
780 // tightly encloses the specified point. 780 // tightly encloses the specified point.
781 for (int i = GetChildViewCount() - 1 ; i >= 0 ; --i) { 781 for (int i = GetChildViewCount() - 1 ; i >= 0 ; --i) {
782 View* child = GetChildViewAt(i); 782 View* child = GetChildViewAt(i);
783 if (!child->IsVisible()) 783 if (!child->IsVisible())
784 continue; 784 continue;
785 785
786 CPoint point_in_child_coords(point); 786 gfx::Point point_in_child_coords(point);
787 View::ConvertPointToView(this, child, &point_in_child_coords); 787 View::ConvertPointToView(this, child, &point_in_child_coords);
788 if (child->HitTest(point_in_child_coords)) 788 if (child->HitTest(point_in_child_coords.ToPOINT()))
789 return child->GetViewForPoint(point_in_child_coords, true); 789 return child->GetViewForPoint(point_in_child_coords.ToPOINT(), true);
790 } 790 }
791 791
792 // We haven't found a view for the point. Try to create floating views 792 // We haven't found a view for the point. Try to create floating views
793 // and try again if one was created. 793 // and try again if one was created.
794 // can_create_floating makes sure we don't try forever even if 794 // can_create_floating makes sure we don't try forever even if
795 // GetFloatingViewIDForPoint lies or if RetrieveFloatingViewForID creates a 795 // GetFloatingViewIDForPoint lies or if RetrieveFloatingViewForID creates a
796 // view which doesn't contain the provided point 796 // view which doesn't contain the provided point
797 int id; 797 int id;
798 if (can_create_floating && GetFloatingViewIDForPoint(point.x, point.y, &id)) { 798 if (can_create_floating && GetFloatingViewIDForPoint(point.x, point.y, &id)) {
799 RetrieveFloatingViewForID(id); // This creates the floating view. 799 RetrieveFloatingViewForID(id); // This creates the floating view.
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 return true; 1277 return true;
1278 } 1278 }
1279 return false; 1279 return false;
1280 default: 1280 default:
1281 NOTREACHED(); 1281 NOTREACHED();
1282 } 1282 }
1283 return false; 1283 return false;
1284 } 1284 }
1285 1285
1286 // static 1286 // static
1287 void View::ConvertPointToView(View* src, 1287 void View::ConvertPointToView(View* src, View* dst, gfx::Point* point) {
1288 View* dst,
1289 gfx::Point* point) {
1290 ConvertPointToView(src, dst, point, true); 1288 ConvertPointToView(src, dst, point, true);
1291 } 1289 }
1292 1290
1293 // static 1291 // static
1294 void View::ConvertPointToView(View* src, 1292 void View::ConvertPointToView(View* src, View* dst, gfx::Point* point,
1295 View* dst,
1296 CPoint* point) {
1297 gfx::Point tmp_point(point->x, point->y);
1298 ConvertPointToView(src, dst, &tmp_point, true);
1299 point->x = tmp_point.x();
1300 point->y = tmp_point.y();
1301 }
1302
1303 // static
1304 void View::ConvertPointToView(View* src,
1305 View* dst,
1306 gfx::Point* point,
1307 bool try_other_direction) { 1293 bool try_other_direction) {
1308 // src can be NULL 1294 // src can be NULL
1309 DCHECK(dst); 1295 DCHECK(dst);
1310 DCHECK(point); 1296 DCHECK(point);
1311 1297
1312 View* v; 1298 View* v;
1313 gfx::Point offset; 1299 gfx::Point offset;
1314 1300
1315 for (v = dst; v && v != src; v = v->GetParent()) { 1301 for (v = dst; v && v != src; v = v->GetParent()) {
1316 offset.SetPoint(offset.x() + v->GetX(APPLY_MIRRORING_TRANSFORMATION), 1302 offset.SetPoint(offset.x() + v->GetX(APPLY_MIRRORING_TRANSFORMATION),
(...skipping 19 matching lines...) Expand all
1336 if (vc) { 1322 if (vc) {
1337 CRect b; 1323 CRect b;
1338 vc->GetBounds(&b, false); 1324 vc->GetBounds(&b, false);
1339 point->SetPoint(point->x() - b.left, point->y() - b.top); 1325 point->SetPoint(point->x() - b.left, point->y() - b.top);
1340 } 1326 }
1341 } 1327 }
1342 } 1328 }
1343 } 1329 }
1344 1330
1345 // static 1331 // static
1346 void View::ConvertPointToViewContainer(View* src, CPoint* p) { 1332 void View::ConvertPointToViewContainer(View* src, gfx::Point* p) {
1347 DCHECK(src); 1333 DCHECK(src);
1348 DCHECK(p); 1334 DCHECK(p);
1335
1349 View *v; 1336 View *v;
1350 CPoint offset(0, 0); 1337 gfx::Point offset;
1351
1352 for (v = src; v; v = v->GetParent()) { 1338 for (v = src; v; v = v->GetParent()) {
1353 offset.x += v->GetX(APPLY_MIRRORING_TRANSFORMATION); 1339 offset.set_x(offset.x() + v->GetX(APPLY_MIRRORING_TRANSFORMATION));
1354 offset.y += v->y(); 1340 offset.set_y(offset.y() + v->y());
1355 } 1341 }
1356 p->x += offset.x; 1342 p->SetPoint(p->x() + offset.x(), p->y() + offset.y());
1357 p->y += offset.y;
1358 } 1343 }
1359 1344
1360 // static 1345 // static
1361 void View::ConvertPointFromViewContainer(View *source, CPoint *p) { 1346 void View::ConvertPointFromViewContainer(View *source, gfx::Point* p) {
1362 CPoint t(0, 0); 1347 gfx::Point t;
1363 ConvertPointToViewContainer(source, &t); 1348 ConvertPointToViewContainer(source, &t);
1364 p->x -= t.x; 1349 p->SetPoint(p->x() - t.x(), p->y() - t.y());
1365 p->y -= t.y;
1366 } 1350 }
1367 1351
1368 // static 1352 // static
1369 void View::ConvertPointToScreen(View* src, CPoint* p) { 1353 void View::ConvertPointToScreen(View* src, gfx::Point* p) {
1370 DCHECK(src); 1354 DCHECK(src);
1371 DCHECK(p); 1355 DCHECK(p);
1372 1356
1373 // If the view is not connected to a tree, do nothing 1357 // If the view is not connected to a tree, there's nothing we can do.
1374 if (src->GetViewContainer() == NULL) {
1375 return;
1376 }
1377
1378 ConvertPointToViewContainer(src, p);
1379 ViewContainer* vc = src->GetViewContainer(); 1358 ViewContainer* vc = src->GetViewContainer();
1380 if (vc) { 1359 if (vc) {
1360 ConvertPointToViewContainer(src, p);
1381 CRect r; 1361 CRect r;
1382 vc->GetBounds(&r, false); 1362 vc->GetBounds(&r, false);
1383 p->x += r.left; 1363 p->SetPoint(p->x() + r.left, p->y() + r.top);
1384 p->y += r.top;
1385 } 1364 }
1386 } 1365 }
1387 1366
1388 ///////////////////////////////////////////////////////////////////////////// 1367 /////////////////////////////////////////////////////////////////////////////
1389 // 1368 //
1390 // View - event handlers 1369 // View - event handlers
1391 // 1370 //
1392 ///////////////////////////////////////////////////////////////////////////// 1371 /////////////////////////////////////////////////////////////////////////////
1393 1372
1394 bool View::OnMousePressed(const MouseEvent& e) { 1373 bool View::OnMousePressed(const MouseEvent& e) {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 } 1682 }
1704 1683
1705 void View::DragInfo::PossibleDrag(int x, int y) { 1684 void View::DragInfo::PossibleDrag(int x, int y) {
1706 possible_drag = true; 1685 possible_drag = true;
1707 start_x = x; 1686 start_x = x;
1708 start_y = y; 1687 start_y = y;
1709 } 1688 }
1710 1689
1711 } // namespace 1690 } // namespace
1712 1691
OLDNEW
« no previous file with comments | « chrome/views/view.h ('k') | chrome/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698