Index: views/view.cc |
diff --git a/views/view.cc b/views/view.cc |
index 75a93b1f4602f55fc203202937bc158a52184f42..f2a3306bbda01d9ff4ed8432932f3589e016cb4c 100644 |
--- a/views/view.cc |
+++ b/views/view.cc |
@@ -6,6 +6,7 @@ |
#include <algorithm> |
+#include "base/debug/trace_event.h" |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/message_loop.h" |
@@ -24,6 +25,7 @@ |
#include "views/drag_controller.h" |
#include "views/layer_property_setter.h" |
#include "views/layout/layout_manager.h" |
+#include "views/paint_listener.h" |
#include "views/views_delegate.h" |
#include "views/widget/native_widget_private.h" |
#include "views/widget/native_widget_views.h" |
@@ -107,6 +109,7 @@ View::View() |
parent_(NULL), |
visible_(true), |
enabled_(true), |
+ painting_enabled_(true), |
registered_for_visible_bounds_notification_(false), |
clip_x_(0.0), |
clip_y_(0.0), |
@@ -685,7 +688,7 @@ void View::SchedulePaint() { |
} |
void View::SchedulePaintInRect(const gfx::Rect& rect) { |
- if (!IsVisible()) |
+ if (!IsVisible() || !painting_enabled_) |
return; |
MarkLayerDirty(); |
@@ -693,7 +696,8 @@ void View::SchedulePaintInRect(const gfx::Rect& rect) { |
} |
void View::Paint(gfx::Canvas* canvas) { |
- if (!IsVisible()) |
+ TRACE_EVENT0("View", "Paint"); |
+ if (!IsVisible() || !painting_enabled_) |
return; |
ScopedCanvas scoped_canvas(NULL); |
@@ -771,6 +775,13 @@ void View::Paint(gfx::Canvas* canvas) { |
layer()->SetCanvas(*layer_canvas->AsCanvasSkia(), layer_rect.origin()); |
layer_helper_->set_bitmap_needs_updating(false); |
} |
+ |
+ // Make a copy of the listeners in case they remove themselves when notified. |
+ std::set<PaintListener*> listeners = paint_listeners_; |
+ for (std::set<PaintListener*>::iterator i = listeners.begin(); |
+ i != listeners.end(); ++i) { |
+ (*i)->OnPainted(this); |
+ } |
} |
ThemeProvider* View::GetThemeProvider() const { |
@@ -778,6 +789,14 @@ ThemeProvider* View::GetThemeProvider() const { |
return widget ? widget->GetThemeProvider() : NULL; |
} |
+void View::AddPaintListener(PaintListener* listener) { |
+ paint_listeners_.insert(listener); |
+} |
+ |
+void View::RemovePaintListener(PaintListener* listener) { |
+ paint_listeners_.erase(listener); |
+} |
+ |
// Accelerated Painting -------------------------------------------------------- |
// static |
@@ -1173,10 +1192,17 @@ void View::PaintComposite() { |
for (int i = 0, count = child_count(); i < count; ++i) |
child_at(i)->PaintComposite(); |
+ |
+ // Make a copy of the listeners in case they remove themselves when notified. |
+ std::set<PaintListener*> listeners = paint_listeners_; |
+ for (std::set<PaintListener*>::iterator i = listeners.begin(); |
+ i != listeners.end(); ++i) { |
+ (*i)->OnComposited(this); |
+ } |
} |
void View::SchedulePaintInternal(const gfx::Rect& rect) { |
- if (parent_ && parent_->IsVisible()) { |
+ if (parent_ && parent_->IsVisible() && painting_enabled_) { |
// Translate the requested paint rect to the parent's coordinate system |
// then pass this notification up to the parent. |
parent_->SchedulePaintInternal(ConvertRectToParent(rect)); |