OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/view.h" | 5 #include "views/view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
| 9 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "third_party/skia/include/core/SkRect.h" | 14 #include "third_party/skia/include/core/SkRect.h" |
14 #include "ui/base/accessibility/accessibility_types.h" | 15 #include "ui/base/accessibility/accessibility_types.h" |
15 #include "ui/base/dragdrop/drag_drop_types.h" | 16 #include "ui/base/dragdrop/drag_drop_types.h" |
16 #include "ui/gfx/canvas_skia.h" | 17 #include "ui/gfx/canvas_skia.h" |
17 #include "ui/gfx/compositor/compositor.h" | 18 #include "ui/gfx/compositor/compositor.h" |
18 #include "ui/gfx/compositor/layer.h" | 19 #include "ui/gfx/compositor/layer.h" |
19 #include "ui/gfx/path.h" | 20 #include "ui/gfx/path.h" |
20 #include "ui/gfx/point3.h" | 21 #include "ui/gfx/point3.h" |
21 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
22 #include "views/background.h" | 23 #include "views/background.h" |
23 #include "views/context_menu_controller.h" | 24 #include "views/context_menu_controller.h" |
24 #include "views/drag_controller.h" | 25 #include "views/drag_controller.h" |
25 #include "views/layer_property_setter.h" | 26 #include "views/layer_property_setter.h" |
26 #include "views/layout/layout_manager.h" | 27 #include "views/layout/layout_manager.h" |
| 28 #include "views/paint_listener.h" |
27 #include "views/views_delegate.h" | 29 #include "views/views_delegate.h" |
28 #include "views/widget/native_widget_private.h" | 30 #include "views/widget/native_widget_private.h" |
29 #include "views/widget/native_widget_views.h" | 31 #include "views/widget/native_widget_views.h" |
30 #include "views/widget/root_view.h" | 32 #include "views/widget/root_view.h" |
31 #include "views/widget/tooltip_manager.h" | 33 #include "views/widget/tooltip_manager.h" |
32 #include "views/widget/widget.h" | 34 #include "views/widget/widget.h" |
33 | 35 |
34 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
35 #include "base/win/scoped_gdi_object.h" | 37 #include "base/win/scoped_gdi_object.h" |
36 #include "views/accessibility/native_view_accessibility_win.h" | 38 #include "views/accessibility/native_view_accessibility_win.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 102 |
101 // Creation and lifetime ------------------------------------------------------- | 103 // Creation and lifetime ------------------------------------------------------- |
102 | 104 |
103 View::View() | 105 View::View() |
104 : parent_owned_(true), | 106 : parent_owned_(true), |
105 id_(0), | 107 id_(0), |
106 group_(-1), | 108 group_(-1), |
107 parent_(NULL), | 109 parent_(NULL), |
108 visible_(true), | 110 visible_(true), |
109 enabled_(true), | 111 enabled_(true), |
| 112 painting_enabled_(true), |
110 registered_for_visible_bounds_notification_(false), | 113 registered_for_visible_bounds_notification_(false), |
111 clip_x_(0.0), | 114 clip_x_(0.0), |
112 clip_y_(0.0), | 115 clip_y_(0.0), |
113 needs_layout_(true), | 116 needs_layout_(true), |
114 flip_canvas_on_paint_for_rtl_ui_(false), | 117 flip_canvas_on_paint_for_rtl_ui_(false), |
115 accelerator_registration_delayed_(false), | 118 accelerator_registration_delayed_(false), |
116 accelerator_focus_manager_(NULL), | 119 accelerator_focus_manager_(NULL), |
117 registered_accelerator_count_(0), | 120 registered_accelerator_count_(0), |
118 next_focusable_view_(NULL), | 121 next_focusable_view_(NULL), |
119 previous_focusable_view_(NULL), | 122 previous_focusable_view_(NULL), |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 return x_rect; | 681 return x_rect; |
679 } | 682 } |
680 | 683 |
681 // Painting -------------------------------------------------------------------- | 684 // Painting -------------------------------------------------------------------- |
682 | 685 |
683 void View::SchedulePaint() { | 686 void View::SchedulePaint() { |
684 SchedulePaintInRect(GetLocalBounds()); | 687 SchedulePaintInRect(GetLocalBounds()); |
685 } | 688 } |
686 | 689 |
687 void View::SchedulePaintInRect(const gfx::Rect& rect) { | 690 void View::SchedulePaintInRect(const gfx::Rect& rect) { |
688 if (!IsVisible()) | 691 if (!IsVisible() || !painting_enabled_) |
689 return; | 692 return; |
690 | 693 |
691 MarkLayerDirty(); | 694 MarkLayerDirty(); |
692 SchedulePaintInternal(rect); | 695 SchedulePaintInternal(rect); |
693 } | 696 } |
694 | 697 |
695 void View::Paint(gfx::Canvas* canvas) { | 698 void View::Paint(gfx::Canvas* canvas) { |
696 if (!IsVisible()) | 699 TRACE_EVENT0("View", "Paint"); |
| 700 if (!IsVisible() || !painting_enabled_) |
697 return; | 701 return; |
698 | 702 |
699 ScopedCanvas scoped_canvas(NULL); | 703 ScopedCanvas scoped_canvas(NULL); |
700 scoped_ptr<gfx::Canvas> layer_canvas; | 704 scoped_ptr<gfx::Canvas> layer_canvas; |
701 gfx::Rect layer_rect; | 705 gfx::Rect layer_rect; |
702 | 706 |
703 if (layer()) { | 707 if (layer()) { |
704 gfx::Rect dirty_rect; | 708 gfx::Rect dirty_rect; |
705 if (!layer_helper_->clip_rect().IsEmpty()) { | 709 if (!layer_helper_->clip_rect().IsEmpty()) { |
706 dirty_rect = layer_helper_->clip_rect(); | 710 dirty_rect = layer_helper_->clip_rect(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 | 768 |
765 OnPaint(canvas); | 769 OnPaint(canvas); |
766 } | 770 } |
767 | 771 |
768 PaintChildren(canvas); | 772 PaintChildren(canvas); |
769 | 773 |
770 if (layer_canvas.get()) { | 774 if (layer_canvas.get()) { |
771 layer()->SetCanvas(*layer_canvas->AsCanvasSkia(), layer_rect.origin()); | 775 layer()->SetCanvas(*layer_canvas->AsCanvasSkia(), layer_rect.origin()); |
772 layer_helper_->set_bitmap_needs_updating(false); | 776 layer_helper_->set_bitmap_needs_updating(false); |
773 } | 777 } |
| 778 |
| 779 // Make a copy of the listeners in case they remove themselves when notified. |
| 780 std::set<PaintListener*> listeners = paint_listeners_; |
| 781 for (std::set<PaintListener*>::iterator i = listeners.begin(); |
| 782 i != listeners.end(); ++i) { |
| 783 (*i)->OnPainted(this); |
| 784 } |
774 } | 785 } |
775 | 786 |
776 ThemeProvider* View::GetThemeProvider() const { | 787 ThemeProvider* View::GetThemeProvider() const { |
777 const Widget* widget = GetWidget(); | 788 const Widget* widget = GetWidget(); |
778 return widget ? widget->GetThemeProvider() : NULL; | 789 return widget ? widget->GetThemeProvider() : NULL; |
779 } | 790 } |
780 | 791 |
| 792 void View::AddPaintListener(PaintListener* listener) { |
| 793 paint_listeners_.insert(listener); |
| 794 } |
| 795 |
| 796 void View::RemovePaintListener(PaintListener* listener) { |
| 797 paint_listeners_.erase(listener); |
| 798 } |
| 799 |
781 // Accelerated Painting -------------------------------------------------------- | 800 // Accelerated Painting -------------------------------------------------------- |
782 | 801 |
783 // static | 802 // static |
784 void View::set_use_acceleration_when_possible(bool use) { | 803 void View::set_use_acceleration_when_possible(bool use) { |
785 use_acceleration_when_possible = use; | 804 use_acceleration_when_possible = use; |
786 } | 805 } |
787 | 806 |
788 // static | 807 // static |
789 bool View::get_use_acceleration_when_possible() { | 808 bool View::get_use_acceleration_when_possible() { |
790 return use_acceleration_when_possible; | 809 return use_acceleration_when_possible; |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 if (!IsVisible()) | 1185 if (!IsVisible()) |
1167 return; | 1186 return; |
1168 | 1187 |
1169 if (layer()) { | 1188 if (layer()) { |
1170 OnWillCompositeLayer(); | 1189 OnWillCompositeLayer(); |
1171 layer()->Draw(); | 1190 layer()->Draw(); |
1172 } | 1191 } |
1173 | 1192 |
1174 for (int i = 0, count = child_count(); i < count; ++i) | 1193 for (int i = 0, count = child_count(); i < count; ++i) |
1175 child_at(i)->PaintComposite(); | 1194 child_at(i)->PaintComposite(); |
| 1195 |
| 1196 // Make a copy of the listeners in case they remove themselves when notified. |
| 1197 std::set<PaintListener*> listeners = paint_listeners_; |
| 1198 for (std::set<PaintListener*>::iterator i = listeners.begin(); |
| 1199 i != listeners.end(); ++i) { |
| 1200 (*i)->OnComposited(this); |
| 1201 } |
1176 } | 1202 } |
1177 | 1203 |
1178 void View::SchedulePaintInternal(const gfx::Rect& rect) { | 1204 void View::SchedulePaintInternal(const gfx::Rect& rect) { |
1179 if (parent_ && parent_->IsVisible()) { | 1205 if (parent_ && parent_->IsVisible() && painting_enabled_) { |
1180 // Translate the requested paint rect to the parent's coordinate system | 1206 // Translate the requested paint rect to the parent's coordinate system |
1181 // then pass this notification up to the parent. | 1207 // then pass this notification up to the parent. |
1182 parent_->SchedulePaintInternal(ConvertRectToParent(rect)); | 1208 parent_->SchedulePaintInternal(ConvertRectToParent(rect)); |
1183 } | 1209 } |
1184 } | 1210 } |
1185 | 1211 |
1186 void View::PaintToLayer(const gfx::Rect& dirty_region) { | 1212 void View::PaintToLayer(const gfx::Rect& dirty_region) { |
1187 if (!IsVisible()) | 1213 if (!IsVisible()) |
1188 return; | 1214 return; |
1189 | 1215 |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 result.append(child_at(i)->PrintViewGraph(false)); | 2097 result.append(child_at(i)->PrintViewGraph(false)); |
2072 | 2098 |
2073 if (first) | 2099 if (first) |
2074 result.append("}\n"); | 2100 result.append("}\n"); |
2075 | 2101 |
2076 return result; | 2102 return result; |
2077 } | 2103 } |
2078 #endif | 2104 #endif |
2079 | 2105 |
2080 } // namespace views | 2106 } // namespace views |
OLD | NEW |