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" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 clip_y_(0.0), | 109 clip_y_(0.0), |
109 needs_layout_(true), | 110 needs_layout_(true), |
110 flip_canvas_on_paint_for_rtl_ui_(false), | 111 flip_canvas_on_paint_for_rtl_ui_(false), |
111 accelerator_registration_delayed_(false), | 112 accelerator_registration_delayed_(false), |
112 accelerator_focus_manager_(NULL), | 113 accelerator_focus_manager_(NULL), |
113 registered_accelerator_count_(0), | 114 registered_accelerator_count_(0), |
114 next_focusable_view_(NULL), | 115 next_focusable_view_(NULL), |
115 previous_focusable_view_(NULL), | 116 previous_focusable_view_(NULL), |
116 focusable_(false), | 117 focusable_(false), |
117 accessibility_focusable_(false), | 118 accessibility_focusable_(false), |
| 119 painting_enabled_(true), |
118 context_menu_controller_(NULL), | 120 context_menu_controller_(NULL), |
119 drag_controller_(NULL) { | 121 drag_controller_(NULL) { |
120 } | 122 } |
121 | 123 |
122 View::~View() { | 124 View::~View() { |
123 if (parent_) | 125 if (parent_) |
124 parent_->RemoveChildView(this); | 126 parent_->RemoveChildView(this); |
125 | 127 |
126 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { | 128 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { |
127 (*i)->parent_ = NULL; | 129 (*i)->parent_ = NULL; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 406 } |
405 | 407 |
406 bool View::IsEnabled() const { | 408 bool View::IsEnabled() const { |
407 return enabled_; | 409 return enabled_; |
408 } | 410 } |
409 | 411 |
410 void View::OnEnabledChanged() { | 412 void View::OnEnabledChanged() { |
411 SchedulePaint(); | 413 SchedulePaint(); |
412 } | 414 } |
413 | 415 |
| 416 void View::SetPaintingEnabled(bool enabled) { |
| 417 painting_enabled_ = enabled; |
| 418 } |
| 419 |
| 420 bool View::IsPaintingEnabled() const { |
| 421 return painting_enabled_; |
| 422 } |
| 423 |
414 // Transformations ------------------------------------------------------------- | 424 // Transformations ------------------------------------------------------------- |
415 | 425 |
416 const ui::Transform& View::GetTransform() const { | 426 const ui::Transform& View::GetTransform() const { |
417 static const ui::Transform* no_op = new ui::Transform; | 427 static const ui::Transform* no_op = new ui::Transform; |
418 return transform() ? *transform() : *no_op; | 428 return transform() ? *transform() : *no_op; |
419 } | 429 } |
420 | 430 |
421 void View::SetTransform(const ui::Transform& transform) { | 431 void View::SetTransform(const ui::Transform& transform) { |
422 if (!transform.HasChange()) { | 432 if (!transform.HasChange()) { |
423 if (!layer_helper_.get() || !this->transform()) | 433 if (!layer_helper_.get() || !this->transform()) |
424 return; | 434 return; |
425 layer_helper_->SetTransform(transform); | 435 layer_helper_->SetTransform(transform); |
426 | 436 |
427 if (!ShouldPaintToLayer()) | 437 if (!ShouldPaintToLayer()) |
428 DestroyLayerAndReparent(); | 438 DestroyLayerAndReparent(); |
429 else if (layer()) | 439 else if (layer()) |
430 layer_helper_->property_setter()->SetTransform(layer(), transform); | 440 layer_helper_->property_setter()->SetTransform(layer(), transform); |
431 | 441 |
432 SchedulePaint(); | 442 SchedulePaint(); |
433 } else { | 443 } else { |
434 // Make sure if the view didn't have its own texture and was painting onto | |
435 // something else, that gets refreshed too. | |
436 if (!ShouldPaintToLayer()) | |
437 MarkLayerDirty(); | |
438 | |
439 if (!layer_helper_.get()) | 444 if (!layer_helper_.get()) |
440 layer_helper_.reset(new internal::LayerHelper()); | 445 layer_helper_.reset(new internal::LayerHelper()); |
441 layer_helper_->SetTransform(transform); | 446 layer_helper_->SetTransform(transform); |
442 if (!layer()) { | 447 if (!layer()) { |
443 CreateLayer(); | 448 CreateLayer(); |
444 SchedulePaint(); | 449 SchedulePaint(); |
445 } else { | 450 } else { |
446 layer_helper_->property_setter()->SetTransform(layer(), transform); | 451 layer_helper_->property_setter()->SetTransform(layer(), transform); |
447 // We have a layer. When the transform changes and the layer is up to | 452 ScheduleComposite(); |
448 // date we don't want to SchedulePaint as it'll trigger painting to the | |
449 // layer. Instead we tell the Widget to paint, which makes the | |
450 // compositor draw using the existing layer. | |
451 // We schedule paint the complete bounds as compositor generally don't | |
452 // support partial painting. | |
453 Widget* widget = GetWidget(); | |
454 if (widget) | |
455 widget->SchedulePaintInRect(widget->GetRootView()->bounds()); | |
456 } | 453 } |
457 } | 454 } |
458 } | 455 } |
459 | 456 |
460 void View::SetPaintToLayer(bool value) { | 457 void View::SetPaintToLayer(bool value) { |
461 bool paint_to_layer = layer_helper_.get() && layer_helper_->paint_to_layer(); | 458 bool paint_to_layer = layer_helper_.get() && layer_helper_->paint_to_layer(); |
462 if (value == paint_to_layer) | 459 if (value == paint_to_layer) |
463 return; | 460 return; |
464 | 461 |
465 if (value) { | 462 if (value) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 return base::i18n::IsRTL() ? width() - x : x; | 508 return base::i18n::IsRTL() ? width() - x : x; |
512 } | 509 } |
513 | 510 |
514 int View::GetMirroredXWithWidthInView(int x, int w) const { | 511 int View::GetMirroredXWithWidthInView(int x, int w) const { |
515 return base::i18n::IsRTL() ? width() - x - w : x; | 512 return base::i18n::IsRTL() ? width() - x - w : x; |
516 } | 513 } |
517 | 514 |
518 // Layout ---------------------------------------------------------------------- | 515 // Layout ---------------------------------------------------------------------- |
519 | 516 |
520 void View::Layout() { | 517 void View::Layout() { |
| 518 TRACE_EVENT0("View", "Layout"); |
521 needs_layout_ = false; | 519 needs_layout_ = false; |
522 | 520 |
523 // If we have a layout manager, let it handle the layout for us. | 521 // If we have a layout manager, let it handle the layout for us. |
524 if (layout_manager_.get()) | 522 if (layout_manager_.get()) |
525 layout_manager_->Layout(this); | 523 layout_manager_->Layout(this); |
526 | 524 |
527 // Make sure to propagate the Layout() call to any children that haven't | 525 // Make sure to propagate the Layout() call to any children that haven't |
528 // received it yet through the layout manager and need to be laid out. This | 526 // received it yet through the layout manager and need to be laid out. This |
529 // is needed for the case when the child requires a layout but its bounds | 527 // is needed for the case when the child requires a layout but its bounds |
530 // weren't changed by the layout manager. If there is no layout manager, we | 528 // weren't changed by the layout manager. If there is no layout manager, we |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 } | 677 } |
680 | 678 |
681 void View::SchedulePaintInRect(const gfx::Rect& rect) { | 679 void View::SchedulePaintInRect(const gfx::Rect& rect) { |
682 if (!IsVisible()) | 680 if (!IsVisible()) |
683 return; | 681 return; |
684 | 682 |
685 MarkLayerDirty(); | 683 MarkLayerDirty(); |
686 SchedulePaintInternal(rect); | 684 SchedulePaintInternal(rect); |
687 } | 685 } |
688 | 686 |
| 687 void View::ScheduleComposite() { |
| 688 ScheduleCompositeInRect(GetLocalBounds()); |
| 689 } |
| 690 |
| 691 void View::ScheduleCompositeInRect(const gfx::Rect& rect) { |
| 692 if (!IsVisible()) |
| 693 return; |
| 694 |
| 695 SchedulePaintInternal(rect); |
| 696 } |
| 697 |
689 void View::Paint(gfx::Canvas* canvas) { | 698 void View::Paint(gfx::Canvas* canvas) { |
690 if (!IsVisible()) | 699 TRACE_EVENT0("View", "Paint"); |
| 700 if (!IsVisible() || !IsPaintingEnabled()) |
691 return; | 701 return; |
692 | 702 |
693 ScopedCanvas scoped_canvas(NULL); | 703 ScopedCanvas scoped_canvas(NULL); |
694 scoped_ptr<gfx::Canvas> layer_canvas; | 704 scoped_ptr<gfx::Canvas> layer_canvas; |
695 gfx::Rect layer_rect; | 705 gfx::Rect layer_rect; |
696 | 706 |
697 if (layer()) { | 707 if (layer()) { |
698 gfx::Rect dirty_rect; | 708 gfx::Rect dirty_rect; |
699 if (!layer_helper_->clip_rect().IsEmpty()) { | 709 if (!layer_helper_->clip_rect().IsEmpty()) { |
700 dirty_rect = layer_helper_->clip_rect(); | 710 dirty_rect = layer_helper_->clip_rect(); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 } | 1159 } |
1150 | 1160 |
1151 void View::OnPaintFocusBorder(gfx::Canvas* canvas) { | 1161 void View::OnPaintFocusBorder(gfx::Canvas* canvas) { |
1152 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) | 1162 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) |
1153 canvas->DrawFocusRect(0, 0, width(), height()); | 1163 canvas->DrawFocusRect(0, 0, width(), height()); |
1154 } | 1164 } |
1155 | 1165 |
1156 // Accelerated Painting -------------------------------------------------------- | 1166 // Accelerated Painting -------------------------------------------------------- |
1157 | 1167 |
1158 void View::PaintComposite() { | 1168 void View::PaintComposite() { |
| 1169 TRACE_EVENT0("View", "PaintComposite"); |
1159 if (!IsVisible()) | 1170 if (!IsVisible()) |
1160 return; | 1171 return; |
1161 | 1172 |
1162 if (layer()) { | 1173 if (layer()) { |
1163 OnWillCompositeLayer(); | 1174 OnWillCompositeLayer(); |
1164 layer()->Draw(); | 1175 layer()->Draw(); |
1165 } | 1176 } |
1166 | 1177 |
1167 for (int i = 0, count = child_count(); i < count; ++i) | 1178 for (int i = 0, count = child_count(); i < count; ++i) |
1168 child_at(i)->PaintComposite(); | 1179 child_at(i)->PaintComposite(); |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2030 result.append(child_at(i)->PrintViewGraph(false)); | 2041 result.append(child_at(i)->PrintViewGraph(false)); |
2031 | 2042 |
2032 if (first) | 2043 if (first) |
2033 result.append("}\n"); | 2044 result.append("}\n"); |
2034 | 2045 |
2035 return result; | 2046 return result; |
2036 } | 2047 } |
2037 #endif | 2048 #endif |
2038 | 2049 |
2039 } // namespace views | 2050 } // namespace views |
OLD | NEW |