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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 class Insets; | 44 class Insets; |
45 class Path; | 45 class Path; |
46 class Transform; | 46 class Transform; |
47 } | 47 } |
48 | 48 |
49 namespace ui { | 49 namespace ui { |
50 struct AXViewState; | 50 struct AXViewState; |
51 class Compositor; | 51 class Compositor; |
52 class Layer; | 52 class Layer; |
53 class NativeTheme; | 53 class NativeTheme; |
| 54 class PaintContext; |
54 class TextInputClient; | 55 class TextInputClient; |
55 class Texture; | 56 class Texture; |
56 class ThemeProvider; | 57 class ThemeProvider; |
57 } | 58 } |
58 | 59 |
59 namespace views { | 60 namespace views { |
60 | 61 |
61 class Background; | 62 class Background; |
62 class Border; | 63 class Border; |
63 class ContextMenuController; | 64 class ContextMenuController; |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 485 |
485 // Mark all or part of the View's bounds as dirty (needing repaint). | 486 // Mark all or part of the View's bounds as dirty (needing repaint). |
486 // |r| is in the View's coordinates. | 487 // |r| is in the View's coordinates. |
487 // Rectangle |r| should be in the view's coordinate system. The | 488 // Rectangle |r| should be in the view's coordinate system. The |
488 // transformations are applied to it to convert it into the parent coordinate | 489 // transformations are applied to it to convert it into the parent coordinate |
489 // system before propagating SchedulePaint up the view hierarchy. | 490 // system before propagating SchedulePaint up the view hierarchy. |
490 // TODO(beng): Make protected. | 491 // TODO(beng): Make protected. |
491 virtual void SchedulePaint(); | 492 virtual void SchedulePaint(); |
492 virtual void SchedulePaintInRect(const gfx::Rect& r); | 493 virtual void SchedulePaintInRect(const gfx::Rect& r); |
493 | 494 |
494 class PaintContext { | |
495 public: | |
496 explicit PaintContext(gfx::Canvas* canvas) | |
497 : PaintContext(canvas, gfx::Rect()) {} | |
498 PaintContext(gfx::Canvas* canvas, const gfx::Rect& invalidation) | |
499 : canvas_(canvas), invalidation_(invalidation) { | |
500 #if DCHECK_IS_ON() | |
501 root_visited_ = nullptr; | |
502 #endif | |
503 } | |
504 | |
505 // TODO(danakj): Remove this once everything is painting to display lists. | |
506 gfx::Canvas* canvas() const { return canvas_; } | |
507 | |
508 bool CanCheckInvalidated() const { return !invalidation_.IsEmpty(); } | |
509 | |
510 // When true, the |bounds| touches an invalidated area, so should be | |
511 // re-painted. When false, re-painting can be skipped. Bounds should be in | |
512 // the local space with offsets up to the painting root in the PaintContext. | |
513 bool IsRectInvalidated(const gfx::Rect& bounds) const { | |
514 DCHECK(CanCheckInvalidated()); | |
515 return invalidation_.Intersects(bounds + offset_); | |
516 } | |
517 | |
518 PaintContext CloneWithPaintOffset(const gfx::Vector2d& offset) const { | |
519 return PaintContext(*this, offset); | |
520 } | |
521 | |
522 PaintContext CloneWithoutInvalidation() const { | |
523 return PaintContext(canvas_, gfx::Rect()); | |
524 } | |
525 | |
526 #if DCHECK_IS_ON() | |
527 void Visited(void* visited) const { | |
528 if (!root_visited_) | |
529 root_visited_ = visited; | |
530 } | |
531 void* RootVisited() const { return root_visited_; } | |
532 const gfx::Vector2d& PaintOffset() const { return offset_; } | |
533 #endif | |
534 | |
535 private: | |
536 PaintContext(const PaintContext& other, const gfx::Vector2d& offset) | |
537 : canvas_(other.canvas_), | |
538 invalidation_(other.invalidation_), | |
539 offset_(other.offset_ + offset) { | |
540 #if DCHECK_IS_ON() | |
541 root_visited_ = other.root_visited_; | |
542 #endif | |
543 } | |
544 | |
545 gfx::Canvas* canvas_; | |
546 // Invalidation in the space of the paint root (ie the space of the layer | |
547 // backing the paint taking place). | |
548 gfx::Rect invalidation_; | |
549 // Offset from the PaintContext to the space of the paint root and the | |
550 // |invalidation_|. | |
551 gfx::Vector2d offset_; | |
552 | |
553 #if DCHECK_IS_ON() | |
554 // Used to verify that the |invalidation_| is only used to compare against | |
555 // rects in the same space. | |
556 mutable void* root_visited_; | |
557 #endif | |
558 }; | |
559 | |
560 // Called by the framework to paint a View. Performs translation and clipping | 495 // Called by the framework to paint a View. Performs translation and clipping |
561 // for View coordinates and language direction as required, allows the View | 496 // for View coordinates and language direction as required, allows the View |
562 // to paint itself via the various OnPaint*() event handlers and then paints | 497 // to paint itself via the various OnPaint*() event handlers and then paints |
563 // the hierarchy beneath it. | 498 // the hierarchy beneath it. |
564 void Paint(const PaintContext& parent_context); | 499 void Paint(const ui::PaintContext& parent_context); |
565 | 500 |
566 // The background object is owned by this object and may be NULL. | 501 // The background object is owned by this object and may be NULL. |
567 void set_background(Background* b); | 502 void set_background(Background* b); |
568 const Background* background() const { return background_.get(); } | 503 const Background* background() const { return background_.get(); } |
569 Background* background() { return background_.get(); } | 504 Background* background() { return background_.get(); } |
570 | 505 |
571 // The border object is owned by this object and may be NULL. | 506 // The border object is owned by this object and may be NULL. |
572 virtual void SetBorder(scoped_ptr<Border> b); | 507 virtual void SetBorder(scoped_ptr<Border> b); |
573 const Border* border() const { return border_.get(); } | 508 const Border* border() const { return border_.get(); } |
574 Border* border() { return border_.get(); } | 509 Border* border() { return border_.get(); } |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 // ViewHierarchyChanged() is called when the parent NativeView of the widget | 1065 // ViewHierarchyChanged() is called when the parent NativeView of the widget |
1131 // that the view is attached to is changed as a result of changing the view | 1066 // that the view is attached to is changed as a result of changing the view |
1132 // hierarchy. Overriding this method is useful for tracking which | 1067 // hierarchy. Overriding this method is useful for tracking which |
1133 // FocusManager manages this view. | 1068 // FocusManager manages this view. |
1134 virtual void NativeViewHierarchyChanged(); | 1069 virtual void NativeViewHierarchyChanged(); |
1135 | 1070 |
1136 // Painting ------------------------------------------------------------------ | 1071 // Painting ------------------------------------------------------------------ |
1137 | 1072 |
1138 // Responsible for calling Paint() on child Views. Override to control the | 1073 // Responsible for calling Paint() on child Views. Override to control the |
1139 // order child Views are painted. | 1074 // order child Views are painted. |
1140 virtual void PaintChildren(const PaintContext& context); | 1075 virtual void PaintChildren(const ui::PaintContext& context); |
1141 | 1076 |
1142 // Override to provide rendering in any part of the View's bounds. Typically | 1077 // Override to provide rendering in any part of the View's bounds. Typically |
1143 // this is the "contents" of the view. If you override this method you will | 1078 // this is the "contents" of the view. If you override this method you will |
1144 // have to call the subsequent OnPaint*() methods manually. | 1079 // have to call the subsequent OnPaint*() methods manually. |
1145 virtual void OnPaint(gfx::Canvas* canvas); | 1080 virtual void OnPaint(gfx::Canvas* canvas); |
1146 | 1081 |
1147 // Override to paint a background before any content is drawn. Typically this | 1082 // Override to paint a background before any content is drawn. Typically this |
1148 // is done if you are satisfied with a default OnPaint handler but wish to | 1083 // is done if you are satisfied with a default OnPaint handler but wish to |
1149 // supply a different background. | 1084 // supply a different background. |
1150 virtual void OnPaintBackground(gfx::Canvas* canvas); | 1085 virtual void OnPaintBackground(gfx::Canvas* canvas); |
(...skipping 18 matching lines...) Expand all Loading... |
1169 // recurses through all children. This is used when adding a layer to an | 1104 // recurses through all children. This is used when adding a layer to an |
1170 // existing view to make sure all descendants that have layers are parented to | 1105 // existing view to make sure all descendants that have layers are parented to |
1171 // the right layer. | 1106 // the right layer. |
1172 void MoveLayerToParent(ui::Layer* parent_layer, const gfx::Point& point); | 1107 void MoveLayerToParent(ui::Layer* parent_layer, const gfx::Point& point); |
1173 | 1108 |
1174 // Called to update the bounds of any child layers within this View's | 1109 // Called to update the bounds of any child layers within this View's |
1175 // hierarchy when something happens to the hierarchy. | 1110 // hierarchy when something happens to the hierarchy. |
1176 void UpdateChildLayerBounds(const gfx::Vector2d& offset); | 1111 void UpdateChildLayerBounds(const gfx::Vector2d& offset); |
1177 | 1112 |
1178 // Overridden from ui::LayerDelegate: | 1113 // Overridden from ui::LayerDelegate: |
1179 void OnPaintLayer(gfx::Canvas* canvas) override; | 1114 void OnPaintLayer(const ui::PaintContext& context) override; |
1180 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override; | 1115 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override; |
1181 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 1116 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
1182 base::Closure PrepareForLayerBoundsChange() override; | 1117 base::Closure PrepareForLayerBoundsChange() override; |
1183 | 1118 |
1184 // Finds the layer that this view paints to (it may belong to an ancestor | 1119 // Finds the layer that this view paints to (it may belong to an ancestor |
1185 // view), then reorders the immediate children of that layer to match the | 1120 // view), then reorders the immediate children of that layer to match the |
1186 // order of the view tree. | 1121 // order of the view tree. |
1187 virtual void ReorderLayers(); | 1122 virtual void ReorderLayers(); |
1188 | 1123 |
1189 // This reorders the immediate children of |*parent_layer| to match the | 1124 // This reorders the immediate children of |*parent_layer| to match the |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 // Belongs to this view, but it's reference-counted on some platforms | 1564 // Belongs to this view, but it's reference-counted on some platforms |
1630 // so we can't use a scoped_ptr. It's dereferenced in the destructor. | 1565 // so we can't use a scoped_ptr. It's dereferenced in the destructor. |
1631 NativeViewAccessibility* native_view_accessibility_; | 1566 NativeViewAccessibility* native_view_accessibility_; |
1632 | 1567 |
1633 DISALLOW_COPY_AND_ASSIGN(View); | 1568 DISALLOW_COPY_AND_ASSIGN(View); |
1634 }; | 1569 }; |
1635 | 1570 |
1636 } // namespace views | 1571 } // namespace views |
1637 | 1572 |
1638 #endif // UI_VIEWS_VIEW_H_ | 1573 #endif // UI_VIEWS_VIEW_H_ |
OLD | NEW |