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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 return; | 426 return; |
425 layer_helper_->SetTransform(transform); | 427 layer_helper_->SetTransform(transform); |
426 | 428 |
427 if (!ShouldPaintToLayer()) | 429 if (!ShouldPaintToLayer()) |
428 DestroyLayerAndReparent(); | 430 DestroyLayerAndReparent(); |
429 else if (layer()) | 431 else if (layer()) |
430 layer_helper_->property_setter()->SetTransform(layer(), transform); | 432 layer_helper_->property_setter()->SetTransform(layer(), transform); |
431 | 433 |
432 SchedulePaint(); | 434 SchedulePaint(); |
433 } else { | 435 } 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()) | 436 if (!layer_helper_.get()) |
440 layer_helper_.reset(new internal::LayerHelper()); | 437 layer_helper_.reset(new internal::LayerHelper()); |
441 layer_helper_->SetTransform(transform); | 438 layer_helper_->SetTransform(transform); |
442 if (!layer()) { | 439 if (!layer()) { |
443 CreateLayer(); | 440 CreateLayer(); |
444 SchedulePaint(); | 441 SchedulePaint(); |
445 } else { | 442 } else { |
446 layer_helper_->property_setter()->SetTransform(layer(), transform); | 443 layer_helper_->property_setter()->SetTransform(layer(), transform); |
447 // We have a layer. When the transform changes and the layer is up to | 444 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 } | 445 } |
457 } | 446 } |
458 } | 447 } |
459 | 448 |
460 void View::SetPaintToLayer(bool value) { | 449 void View::SetPaintToLayer(bool value) { |
461 bool paint_to_layer = layer_helper_.get() && layer_helper_->paint_to_layer(); | 450 bool paint_to_layer = layer_helper_.get() && layer_helper_->paint_to_layer(); |
462 if (value == paint_to_layer) | 451 if (value == paint_to_layer) |
463 return; | 452 return; |
464 | 453 |
465 if (value) { | 454 if (value) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 return base::i18n::IsRTL() ? width() - x : x; | 500 return base::i18n::IsRTL() ? width() - x : x; |
512 } | 501 } |
513 | 502 |
514 int View::GetMirroredXWithWidthInView(int x, int w) const { | 503 int View::GetMirroredXWithWidthInView(int x, int w) const { |
515 return base::i18n::IsRTL() ? width() - x - w : x; | 504 return base::i18n::IsRTL() ? width() - x - w : x; |
516 } | 505 } |
517 | 506 |
518 // Layout ---------------------------------------------------------------------- | 507 // Layout ---------------------------------------------------------------------- |
519 | 508 |
520 void View::Layout() { | 509 void View::Layout() { |
| 510 TRACE_EVENT0("View", "Layout"); |
521 needs_layout_ = false; | 511 needs_layout_ = false; |
522 | 512 |
523 // If we have a layout manager, let it handle the layout for us. | 513 // If we have a layout manager, let it handle the layout for us. |
524 if (layout_manager_.get()) | 514 if (layout_manager_.get()) |
525 layout_manager_->Layout(this); | 515 layout_manager_->Layout(this); |
526 | 516 |
527 // Make sure to propagate the Layout() call to any children that haven't | 517 // 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 | 518 // 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 | 519 // 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 | 520 // 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 } | 669 } |
680 | 670 |
681 void View::SchedulePaintInRect(const gfx::Rect& rect) { | 671 void View::SchedulePaintInRect(const gfx::Rect& rect) { |
682 if (!IsVisible()) | 672 if (!IsVisible()) |
683 return; | 673 return; |
684 | 674 |
685 MarkLayerDirty(); | 675 MarkLayerDirty(); |
686 SchedulePaintInternal(rect); | 676 SchedulePaintInternal(rect); |
687 } | 677 } |
688 | 678 |
| 679 void View::ScheduleComposite() { |
| 680 ScheduleCompositeInRect(GetLocalBounds()); |
| 681 } |
| 682 |
| 683 void View::ScheduleCompositeInRect(const gfx::Rect& rect) { |
| 684 if (!IsVisible()) |
| 685 return; |
| 686 |
| 687 SchedulePaintInternal(rect); |
| 688 } |
| 689 |
689 void View::Paint(gfx::Canvas* canvas) { | 690 void View::Paint(gfx::Canvas* canvas) { |
690 if (!IsVisible()) | 691 TRACE_EVENT0("View", "Paint"); |
| 692 if (!IsVisible() || !painting_enabled()) |
691 return; | 693 return; |
692 | 694 |
693 ScopedCanvas scoped_canvas(NULL); | 695 ScopedCanvas scoped_canvas(NULL); |
694 scoped_ptr<gfx::Canvas> layer_canvas; | 696 scoped_ptr<gfx::Canvas> layer_canvas; |
695 gfx::Rect layer_rect; | 697 gfx::Rect layer_rect; |
696 | 698 |
697 if (layer()) { | 699 if (layer()) { |
698 gfx::Rect dirty_rect; | 700 gfx::Rect dirty_rect; |
699 if (!layer_helper_->clip_rect().IsEmpty()) { | 701 if (!layer_helper_->clip_rect().IsEmpty()) { |
700 dirty_rect = layer_helper_->clip_rect(); | 702 dirty_rect = layer_helper_->clip_rect(); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 } | 1151 } |
1150 | 1152 |
1151 void View::OnPaintFocusBorder(gfx::Canvas* canvas) { | 1153 void View::OnPaintFocusBorder(gfx::Canvas* canvas) { |
1152 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) | 1154 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) |
1153 canvas->DrawFocusRect(0, 0, width(), height()); | 1155 canvas->DrawFocusRect(0, 0, width(), height()); |
1154 } | 1156 } |
1155 | 1157 |
1156 // Accelerated Painting -------------------------------------------------------- | 1158 // Accelerated Painting -------------------------------------------------------- |
1157 | 1159 |
1158 void View::PaintComposite() { | 1160 void View::PaintComposite() { |
| 1161 TRACE_EVENT0("View", "PaintComposite"); |
1159 if (!IsVisible()) | 1162 if (!IsVisible()) |
1160 return; | 1163 return; |
1161 | 1164 |
1162 if (layer()) { | 1165 if (layer()) { |
1163 OnWillCompositeLayer(); | 1166 OnWillCompositeLayer(); |
1164 layer()->Draw(); | 1167 layer()->Draw(); |
1165 } | 1168 } |
1166 | 1169 |
1167 for (int i = 0, count = child_count(); i < count; ++i) | 1170 for (int i = 0, count = child_count(); i < count; ++i) |
1168 child_at(i)->PaintComposite(); | 1171 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)); | 2033 result.append(child_at(i)->PrintViewGraph(false)); |
2031 | 2034 |
2032 if (first) | 2035 if (first) |
2033 result.append("}\n"); | 2036 result.append("}\n"); |
2034 | 2037 |
2035 return result; | 2038 return result; |
2036 } | 2039 } |
2037 #endif | 2040 #endif |
2038 | 2041 |
2039 } // namespace views | 2042 } // namespace views |
OLD | NEW |