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

Side by Side Diff: ui/views/view.h

Issue 22891016: Add support for rect-based event targeting in views (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tab strip problems addressed Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef UI_VIEWS_VIEW_H_ 5 #ifndef UI_VIEWS_VIEW_H_
6 #define UI_VIEWS_VIEW_H_ 6 #define UI_VIEWS_VIEW_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 442
443 // Convert a point from the coordinate system of one View to another. 443 // Convert a point from the coordinate system of one View to another.
444 // 444 //
445 // |source| and |target| must be in the same widget, but doesn't need to be in 445 // |source| and |target| must be in the same widget, but doesn't need to be in
446 // the same view hierarchy. 446 // the same view hierarchy.
447 // |source| can be NULL in which case it means the screen coordinate system. 447 // |source| can be NULL in which case it means the screen coordinate system.
448 static void ConvertPointToTarget(const View* source, 448 static void ConvertPointToTarget(const View* source,
449 const View* target, 449 const View* target,
450 gfx::Point* point); 450 gfx::Point* point);
451 451
452 // Convert |rect| from the coordinate system of |source| to the coordinate
453 // system of |target|.
454 //
455 // |source| and |target| must be in the same widget, but doesn't need to be in
456 // the same view hierarchy.
457 // |source| can be NULL in which case it means the screen coordinate system.
458 static void ConvertRectToTarget(const View* source,
459 const View* target,
460 gfx::Rect* rect);
461
452 // Convert a point from a View's coordinate system to that of its Widget. 462 // Convert a point from a View's coordinate system to that of its Widget.
453 static void ConvertPointToWidget(const View* src, gfx::Point* point); 463 static void ConvertPointToWidget(const View* src, gfx::Point* point);
454 464
455 // Convert a point from the coordinate system of a View's Widget to that 465 // Convert a point from the coordinate system of a View's Widget to that
456 // View's coordinate system. 466 // View's coordinate system.
457 static void ConvertPointFromWidget(const View* dest, gfx::Point* p); 467 static void ConvertPointFromWidget(const View* dest, gfx::Point* p);
458 468
459 // Convert a point from a View's coordinate system to that of the screen. 469 // Convert a point from a View's coordinate system to that of the screen.
460 static void ConvertPointToScreen(const View* src, gfx::Point* point); 470 static void ConvertPointToScreen(const View* src, gfx::Point* point);
461 471
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 flip_canvas_on_paint_for_rtl_ui_ = enable; 552 flip_canvas_on_paint_for_rtl_ui_ = enable;
543 } 553 }
544 554
545 // Accelerated painting ------------------------------------------------------ 555 // Accelerated painting ------------------------------------------------------
546 556
547 // Enable/Disable accelerated compositing. 557 // Enable/Disable accelerated compositing.
548 static void set_use_acceleration_when_possible(bool use); 558 static void set_use_acceleration_when_possible(bool use);
549 static bool get_use_acceleration_when_possible(); 559 static bool get_use_acceleration_when_possible();
550 560
551 // Input --------------------------------------------------------------------- 561 // Input ---------------------------------------------------------------------
552 // The points (and mouse locations) in the following functions are in the 562 // The points, rects, mouse locations, and touch locations in the following
553 // view's coordinates, except for a RootView. 563 // functions are in the view's coordinates, except for a RootView.
554 564
555 // Returns the deepest visible descendant that contains the specified point 565 // Convenience functions which calls into GetEventHandler() with
556 // and supports event handling. 566 // a 1x1 rect centered at |point|.
557 virtual View* GetEventHandlerForPoint(const gfx::Point& point); 567 View* GetEventHandlerForPoint(const gfx::Point& point);
568
569 // If point-based targeting should be used, return the deepest visible
570 // descendant that contains the center point of |rect|.
571 // If rect-based targeting (i.e., fuzzing) should be used, return the
572 // closest visible descendant having at least kViewsFuzzingOverlap of
573 // its area covered by |rect|. If no such descendant exists, return the
574 // deepest visible descendant that contains the center point of |rect|.
575 virtual View* GetEventHandlerForRect(const gfx::Rect& rect);
558 576
559 // Returns the deepest visible descendant that contains the specified point 577 // Returns the deepest visible descendant that contains the specified point
560 // and supports tooltips. If the view does not contain the point, returns 578 // and supports tooltips. If the view does not contain the point, returns
561 // NULL. 579 // NULL.
562 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point); 580 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point);
563 581
564 // Return the cursor that should be used for this view or the default cursor. 582 // Return the cursor that should be used for this view or the default cursor.
565 // The event location is in the receiver's coordinate system. The caller is 583 // The event location is in the receiver's coordinate system. The caller is
566 // responsible for managing the lifetime of the returned object, though that 584 // responsible for managing the lifetime of the returned object, though that
567 // lifetime may vary from platform to platform. On Windows and Aura, 585 // lifetime may vary from platform to platform. On Windows and Aura,
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 // to scroll. ScrollView interprets a return value of 0 (or negative) 971 // to scroll. ScrollView interprets a return value of 0 (or negative)
954 // to scroll by a default amount. 972 // to scroll by a default amount.
955 // 973 //
956 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for 974 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for
957 // implementations of common cases. 975 // implementations of common cases.
958 virtual int GetPageScrollIncrement(ScrollView* scroll_view, 976 virtual int GetPageScrollIncrement(ScrollView* scroll_view,
959 bool is_horizontal, bool is_positive); 977 bool is_horizontal, bool is_positive);
960 virtual int GetLineScrollIncrement(ScrollView* scroll_view, 978 virtual int GetLineScrollIncrement(ScrollView* scroll_view,
961 bool is_horizontal, bool is_positive); 979 bool is_horizontal, bool is_positive);
962 980
981 // Views fuzzing -------------------------------------------------------------
982 // Helper functions used by the views fuzzing algorithm.
983
984 // Returns true if |rect| is 1x1.
985 static bool UsePointBasedTargeting(const gfx::Rect& rect);
sky 2013/10/04 17:03:49 Other than UsePointBasedTargeting does any of this
tdanderson 2013/10/07 21:35:21 Moved these into ui/views/rect_based_targeting_uti
986
987 // Returns the percentage of |rect_1|'s area that is covered by |rect_2|.
988 static float PercentCoveredBy(const gfx::Rect& rect_1,
989 const gfx::Rect& rect_2);
990
991 // Returns the square of the distance from |point| to the center line of
992 // |target_rect|. The center line of a rectangle is obtained by repeatedly
993 // stripping away 1px borders around the rectangle until a line remains.
994 static int DistanceSquaredFromCenterLineToPoint(const gfx::Point& point,
995 const gfx::Rect& target_rect);
996
963 protected: 997 protected:
964 // Used to track a drag. RootView passes this into 998 // Used to track a drag. RootView passes this into
965 // ProcessMousePressed/Dragged. 999 // ProcessMousePressed/Dragged.
966 struct DragInfo { 1000 struct DragInfo {
967 // Sets possible_drag to false and start_x/y to 0. This is invoked by 1001 // Sets possible_drag to false and start_x/y to 0. This is invoked by
968 // RootView prior to invoke ProcessMousePressed. 1002 // RootView prior to invoke ProcessMousePressed.
969 void Reset(); 1003 void Reset();
970 1004
971 // Sets possible_drag to true and start_pt to the specified point. 1005 // Sets possible_drag to true and start_pt to the specified point.
972 // This is invoked by the target view if it detects the press may generate 1006 // This is invoked by the target view if it detects the press may generate
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 1333
1300 // Coordinate conversion ----------------------------------------------------- 1334 // Coordinate conversion -----------------------------------------------------
1301 1335
1302 // Convert a point in the view's coordinate to an ancestor view's coordinate 1336 // Convert a point in the view's coordinate to an ancestor view's coordinate
1303 // system using necessary transformations. Returns whether the point was 1337 // system using necessary transformations. Returns whether the point was
1304 // successfully converted to the ancestor's coordinate system. 1338 // successfully converted to the ancestor's coordinate system.
1305 bool ConvertPointForAncestor(const View* ancestor, gfx::Point* point) const; 1339 bool ConvertPointForAncestor(const View* ancestor, gfx::Point* point) const;
1306 1340
1307 // Convert a point in the ancestor's coordinate system to the view's 1341 // Convert a point in the ancestor's coordinate system to the view's
1308 // coordinate system using necessary transformations. Returns whether the 1342 // coordinate system using necessary transformations. Returns whether the
1309 // point was successfully from the ancestor's coordinate system to the view's 1343 // point was successfully converted from the ancestor's coordinate system
1310 // coordinate system. 1344 // to the view's coordinate system.
1311 bool ConvertPointFromAncestor(const View* ancestor, gfx::Point* point) const; 1345 bool ConvertPointFromAncestor(const View* ancestor, gfx::Point* point) const;
1312 1346
1347 // Convert a rect in the view's coordinate to an ancestor view's coordinate
1348 // system using necessary transformations. Returns whether the rect was
1349 // successfully converted to the ancestor's coordinate system.
1350 bool ConvertRectForAncestor(const View* ancestor, gfx::Rect* rect) const;
1351
1352 // Convert a rect in the ancestor's coordinate system to the view's
1353 // coordinate system using necessary transformations. Returns whether the
1354 // rect was successfully converted from the ancestor's coordinate system
1355 // to the view's coordinate system.
1356 bool ConvertRectFromAncestor(const View* ancestor, gfx::Rect* rect) const;
1357
1313 // Accelerated painting ------------------------------------------------------ 1358 // Accelerated painting ------------------------------------------------------
1314 1359
1315 // Creates the layer and related fields for this view. 1360 // Creates the layer and related fields for this view.
1316 void CreateLayer(); 1361 void CreateLayer();
1317 1362
1318 // Parents all un-parented layers within this view's hierarchy to this view's 1363 // Parents all un-parented layers within this view's hierarchy to this view's
1319 // layer. 1364 // layer.
1320 void UpdateParentLayers(); 1365 void UpdateParentLayers();
1321 1366
1322 // Parents this view's layer to |parent_layer|, and sets its bounds and other 1367 // Parents this view's layer to |parent_layer|, and sets its bounds and other
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 // Belongs to this view, but it's reference-counted on some platforms 1576 // Belongs to this view, but it's reference-counted on some platforms
1532 // so we can't use a scoped_ptr. It's dereferenced in the destructor. 1577 // so we can't use a scoped_ptr. It's dereferenced in the destructor.
1533 NativeViewAccessibility* native_view_accessibility_; 1578 NativeViewAccessibility* native_view_accessibility_;
1534 1579
1535 DISALLOW_COPY_AND_ASSIGN(View); 1580 DISALLOW_COPY_AND_ASSIGN(View);
1536 }; 1581 };
1537 1582
1538 } // namespace views 1583 } // namespace views
1539 1584
1540 #endif // UI_VIEWS_VIEW_H_ 1585 #endif // UI_VIEWS_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698