| OLD | NEW |
| 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 441 |
| 442 // Convert a point from the coordinate system of one View to another. | 442 // Convert a point from the coordinate system of one View to another. |
| 443 // | 443 // |
| 444 // |source| and |target| must be in the same widget, but doesn't need to be in | 444 // |source| and |target| must be in the same widget, but doesn't need to be in |
| 445 // the same view hierarchy. | 445 // the same view hierarchy. |
| 446 // |source| can be NULL in which case it means the screen coordinate system. | 446 // |source| can be NULL in which case it means the screen coordinate system. |
| 447 static void ConvertPointToTarget(const View* source, | 447 static void ConvertPointToTarget(const View* source, |
| 448 const View* target, | 448 const View* target, |
| 449 gfx::Point* point); | 449 gfx::Point* point); |
| 450 | 450 |
| 451 // Convert |rect| from the coordinate system of |source| to the coordinate |
| 452 // system of |target|. |
| 453 // |
| 454 // |source| and |target| must be in the same widget, but doesn't need to be in |
| 455 // the same view hierarchy. |
| 456 // |source| can be NULL in which case it means the screen coordinate system. |
| 457 static void ConvertRectToTarget(const View* source, |
| 458 const View* target, |
| 459 gfx::Rect* rect); |
| 460 |
| 451 // Convert a point from a View's coordinate system to that of its Widget. | 461 // Convert a point from a View's coordinate system to that of its Widget. |
| 452 static void ConvertPointToWidget(const View* src, gfx::Point* point); | 462 static void ConvertPointToWidget(const View* src, gfx::Point* point); |
| 453 | 463 |
| 454 // Convert a point from the coordinate system of a View's Widget to that | 464 // Convert a point from the coordinate system of a View's Widget to that |
| 455 // View's coordinate system. | 465 // View's coordinate system. |
| 456 static void ConvertPointFromWidget(const View* dest, gfx::Point* p); | 466 static void ConvertPointFromWidget(const View* dest, gfx::Point* p); |
| 457 | 467 |
| 458 // Convert a point from a View's coordinate system to that of the screen. | 468 // Convert a point from a View's coordinate system to that of the screen. |
| 459 static void ConvertPointToScreen(const View* src, gfx::Point* point); | 469 static void ConvertPointToScreen(const View* src, gfx::Point* point); |
| 460 | 470 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 flip_canvas_on_paint_for_rtl_ui_ = enable; | 551 flip_canvas_on_paint_for_rtl_ui_ = enable; |
| 542 } | 552 } |
| 543 | 553 |
| 544 // Accelerated painting ------------------------------------------------------ | 554 // Accelerated painting ------------------------------------------------------ |
| 545 | 555 |
| 546 // Enable/Disable accelerated compositing. | 556 // Enable/Disable accelerated compositing. |
| 547 static void set_use_acceleration_when_possible(bool use); | 557 static void set_use_acceleration_when_possible(bool use); |
| 548 static bool get_use_acceleration_when_possible(); | 558 static bool get_use_acceleration_when_possible(); |
| 549 | 559 |
| 550 // Input --------------------------------------------------------------------- | 560 // Input --------------------------------------------------------------------- |
| 551 // The points (and mouse locations) in the following functions are in the | 561 // The points, rects, mouse locations, and touch locations in the following |
| 552 // view's coordinates, except for a RootView. | 562 // functions are in the view's coordinates, except for a RootView. |
| 553 | 563 |
| 554 // Returns the deepest visible descendant that contains the specified point | 564 // Convenience functions which calls into GetEventHandler() with |
| 555 // and supports event handling. | 565 // a 1x1 rect centered at |point|. |
| 556 virtual View* GetEventHandlerForPoint(const gfx::Point& point); | 566 View* GetEventHandlerForPoint(const gfx::Point& point); |
| 567 |
| 568 // If point-based targeting should be used, return the deepest visible |
| 569 // descendant that contains the center point of |rect|. |
| 570 // If rect-based targeting (i.e., fuzzing) should be used, return the |
| 571 // closest visible descendant having at least kViewsFuzzingOverlap of |
| 572 // its area covered by |rect|. If no such descendant exists, return the |
| 573 // deepest visible descendant that contains the center point of |rect|. |
| 574 virtual View* GetEventHandlerForRect(const gfx::Rect& rect); |
| 557 | 575 |
| 558 // Returns the deepest visible descendant that contains the specified point | 576 // Returns the deepest visible descendant that contains the specified point |
| 559 // and supports tooltips. If the view does not contain the point, returns | 577 // and supports tooltips. If the view does not contain the point, returns |
| 560 // NULL. | 578 // NULL. |
| 561 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point); | 579 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point); |
| 562 | 580 |
| 563 // Return the cursor that should be used for this view or the default cursor. | 581 // Return the cursor that should be used for this view or the default cursor. |
| 564 // The event location is in the receiver's coordinate system. The caller is | 582 // The event location is in the receiver's coordinate system. The caller is |
| 565 // responsible for managing the lifetime of the returned object, though that | 583 // responsible for managing the lifetime of the returned object, though that |
| 566 // lifetime may vary from platform to platform. On Windows and Aura, | 584 // lifetime may vary from platform to platform. On Windows and Aura, |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 // to scroll. ScrollView interprets a return value of 0 (or negative) | 970 // to scroll. ScrollView interprets a return value of 0 (or negative) |
| 953 // to scroll by a default amount. | 971 // to scroll by a default amount. |
| 954 // | 972 // |
| 955 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for | 973 // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for |
| 956 // implementations of common cases. | 974 // implementations of common cases. |
| 957 virtual int GetPageScrollIncrement(ScrollView* scroll_view, | 975 virtual int GetPageScrollIncrement(ScrollView* scroll_view, |
| 958 bool is_horizontal, bool is_positive); | 976 bool is_horizontal, bool is_positive); |
| 959 virtual int GetLineScrollIncrement(ScrollView* scroll_view, | 977 virtual int GetLineScrollIncrement(ScrollView* scroll_view, |
| 960 bool is_horizontal, bool is_positive); | 978 bool is_horizontal, bool is_positive); |
| 961 | 979 |
| 980 // Views fuzzing ------------------------------------------------------------- |
| 981 // Helper functions used by the views fuzzing algorithm. |
| 982 |
| 983 // Returns true if |rect| is 1x1. |
| 984 static bool UsePointBasedTargeting(const gfx::Rect& rect); |
| 985 |
| 986 // Returns the percentage of |rect_1|'s area that is covered by |rect_2|. |
| 987 static float PercentCoveredBy(const gfx::Rect& rect_1, |
| 988 const gfx::Rect& rect_2); |
| 989 |
| 990 // Returns the square of the distance from |point| to the center line of |
| 991 // |target_rect|. The center line of a rectangle is obtained by repeatedly |
| 992 // stripping away 1px borders around the rectangle until a line remains. |
| 993 static int DistanceSquaredFromCenterLineToPoint(const gfx::Point& point, |
| 994 const gfx::Rect& target_rect); |
| 995 |
| 962 protected: | 996 protected: |
| 963 // Used to track a drag. RootView passes this into | 997 // Used to track a drag. RootView passes this into |
| 964 // ProcessMousePressed/Dragged. | 998 // ProcessMousePressed/Dragged. |
| 965 struct DragInfo { | 999 struct DragInfo { |
| 966 // Sets possible_drag to false and start_x/y to 0. This is invoked by | 1000 // Sets possible_drag to false and start_x/y to 0. This is invoked by |
| 967 // RootView prior to invoke ProcessMousePressed. | 1001 // RootView prior to invoke ProcessMousePressed. |
| 968 void Reset(); | 1002 void Reset(); |
| 969 | 1003 |
| 970 // Sets possible_drag to true and start_pt to the specified point. | 1004 // Sets possible_drag to true and start_pt to the specified point. |
| 971 // This is invoked by the target view if it detects the press may generate | 1005 // This is invoked by the target view if it detects the press may generate |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 | 1341 |
| 1308 // Coordinate conversion ----------------------------------------------------- | 1342 // Coordinate conversion ----------------------------------------------------- |
| 1309 | 1343 |
| 1310 // Convert a point in the view's coordinate to an ancestor view's coordinate | 1344 // Convert a point in the view's coordinate to an ancestor view's coordinate |
| 1311 // system using necessary transformations. Returns whether the point was | 1345 // system using necessary transformations. Returns whether the point was |
| 1312 // successfully converted to the ancestor's coordinate system. | 1346 // successfully converted to the ancestor's coordinate system. |
| 1313 bool ConvertPointForAncestor(const View* ancestor, gfx::Point* point) const; | 1347 bool ConvertPointForAncestor(const View* ancestor, gfx::Point* point) const; |
| 1314 | 1348 |
| 1315 // Convert a point in the ancestor's coordinate system to the view's | 1349 // Convert a point in the ancestor's coordinate system to the view's |
| 1316 // coordinate system using necessary transformations. Returns whether the | 1350 // coordinate system using necessary transformations. Returns whether the |
| 1317 // point was successfully from the ancestor's coordinate system to the view's | 1351 // point was successfully converted from the ancestor's coordinate system |
| 1318 // coordinate system. | 1352 // to the view's coordinate system. |
| 1319 bool ConvertPointFromAncestor(const View* ancestor, gfx::Point* point) const; | 1353 bool ConvertPointFromAncestor(const View* ancestor, gfx::Point* point) const; |
| 1320 | 1354 |
| 1355 // Convert a rect in the view's coordinate to an ancestor view's coordinate |
| 1356 // system using necessary transformations. Returns whether the rect was |
| 1357 // successfully converted to the ancestor's coordinate system. |
| 1358 bool ConvertRectForAncestor(const View* ancestor, gfx::Rect* rect) const; |
| 1359 |
| 1360 // Convert a rect in the ancestor's coordinate system to the view's |
| 1361 // coordinate system using necessary transformations. Returns whether the |
| 1362 // rect was successfully converted from the ancestor's coordinate system |
| 1363 // to the view's coordinate system. |
| 1364 bool ConvertRectFromAncestor(const View* ancestor, gfx::Rect* rect) const; |
| 1365 |
| 1321 // Accelerated painting ------------------------------------------------------ | 1366 // Accelerated painting ------------------------------------------------------ |
| 1322 | 1367 |
| 1323 // Creates the layer and related fields for this view. | 1368 // Creates the layer and related fields for this view. |
| 1324 void CreateLayer(); | 1369 void CreateLayer(); |
| 1325 | 1370 |
| 1326 // Parents all un-parented layers within this view's hierarchy to this view's | 1371 // Parents all un-parented layers within this view's hierarchy to this view's |
| 1327 // layer. | 1372 // layer. |
| 1328 void UpdateParentLayers(); | 1373 void UpdateParentLayers(); |
| 1329 | 1374 |
| 1330 // Parents this view's layer to |parent_layer|, and sets its bounds and other | 1375 // 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 Loading... |
| 1539 // Belongs to this view, but it's reference-counted on some platforms | 1584 // Belongs to this view, but it's reference-counted on some platforms |
| 1540 // so we can't use a scoped_ptr. It's dereferenced in the destructor. | 1585 // so we can't use a scoped_ptr. It's dereferenced in the destructor. |
| 1541 NativeViewAccessibility* native_view_accessibility_; | 1586 NativeViewAccessibility* native_view_accessibility_; |
| 1542 | 1587 |
| 1543 DISALLOW_COPY_AND_ASSIGN(View); | 1588 DISALLOW_COPY_AND_ASSIGN(View); |
| 1544 }; | 1589 }; |
| 1545 | 1590 |
| 1546 } // namespace views | 1591 } // namespace views |
| 1547 | 1592 |
| 1548 #endif // UI_VIEWS_VIEW_H_ | 1593 #endif // UI_VIEWS_VIEW_H_ |
| OLD | NEW |