Chromium Code Reviews| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 clip_y_(0.0), | 110 clip_y_(0.0), |
| 110 needs_layout_(true), | 111 needs_layout_(true), |
| 111 flip_canvas_on_paint_for_rtl_ui_(false), | 112 flip_canvas_on_paint_for_rtl_ui_(false), |
| 112 accelerator_registration_delayed_(false), | 113 accelerator_registration_delayed_(false), |
| 113 accelerator_focus_manager_(NULL), | 114 accelerator_focus_manager_(NULL), |
| 114 registered_accelerator_count_(0), | 115 registered_accelerator_count_(0), |
| 115 next_focusable_view_(NULL), | 116 next_focusable_view_(NULL), |
| 116 previous_focusable_view_(NULL), | 117 previous_focusable_view_(NULL), |
| 117 focusable_(false), | 118 focusable_(false), |
| 118 accessibility_focusable_(false), | 119 accessibility_focusable_(false), |
| 120 painting_enabled_(true), | |
| 119 context_menu_controller_(NULL), | 121 context_menu_controller_(NULL), |
| 120 drag_controller_(NULL) { | 122 drag_controller_(NULL) { |
| 121 } | 123 } |
| 122 | 124 |
| 123 View::~View() { | 125 View::~View() { |
| 124 if (parent_) | 126 if (parent_) |
| 125 parent_->RemoveChildView(this); | 127 parent_->RemoveChildView(this); |
| 126 | 128 |
| 127 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { | 129 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { |
| 128 (*i)->parent_ = NULL; | 130 (*i)->parent_ = NULL; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 return; | 427 return; |
| 426 layer_helper_->SetTransform(transform); | 428 layer_helper_->SetTransform(transform); |
| 427 | 429 |
| 428 if (!ShouldPaintToLayer()) | 430 if (!ShouldPaintToLayer()) |
| 429 DestroyLayerAndReparent(); | 431 DestroyLayerAndReparent(); |
| 430 else if (layer()) | 432 else if (layer()) |
| 431 layer_helper_->property_setter()->SetTransform(layer(), transform); | 433 layer_helper_->property_setter()->SetTransform(layer(), transform); |
| 432 | 434 |
| 433 SchedulePaint(); | 435 SchedulePaint(); |
| 434 } else { | 436 } else { |
| 435 // Make sure if the view didn't have its own texture and was painting onto | |
| 436 // something else, that gets refreshed too. | |
| 437 if (!ShouldPaintToLayer()) | |
|
sky
2011/08/17 16:39:42
How come you're removing this case?
| |
| 438 MarkLayerDirty(); | |
| 439 | |
| 440 if (!layer_helper_.get()) | 437 if (!layer_helper_.get()) |
| 441 layer_helper_.reset(new internal::LayerHelper()); | 438 layer_helper_.reset(new internal::LayerHelper()); |
| 442 layer_helper_->SetTransform(transform); | 439 layer_helper_->SetTransform(transform); |
| 443 if (!layer()) { | 440 if (!layer()) { |
| 444 CreateLayer(); | 441 CreateLayer(); |
| 445 SchedulePaint(); | 442 SchedulePaint(); |
| 446 } else { | 443 } else { |
| 447 layer_helper_->property_setter()->SetTransform(layer(), transform); | 444 layer_helper_->property_setter()->SetTransform(layer(), transform); |
| 448 // We have a layer. When the transform changes and the layer is up to | 445 ScheduleComposite(); |
| 449 // date we don't want to SchedulePaint as it'll trigger painting to the | |
| 450 // layer. Instead we tell the Widget to paint, which makes the | |
| 451 // compositor draw using the existing layer. | |
| 452 // We schedule paint the complete bounds as compositor generally don't | |
| 453 // support partial painting. | |
| 454 Widget* widget = GetWidget(); | |
| 455 if (widget) | |
| 456 widget->SchedulePaintInRect(widget->GetRootView()->bounds()); | |
| 457 } | 446 } |
| 458 } | 447 } |
| 459 } | 448 } |
| 460 | 449 |
| 461 void View::EnqueueAnimation(ui::LayerAnimation* animation) { | 450 void View::EnqueueAnimation(ui::LayerAnimation* animation) { |
| 462 if (!layer_helper_.get()) | 451 if (!layer_helper_.get()) |
| 463 layer_helper_.reset(new internal::LayerHelper()); | 452 layer_helper_.reset(new internal::LayerHelper()); |
| 464 | 453 |
| 465 if (!layer()) | 454 if (!layer()) |
| 466 CreateLayer(); | 455 CreateLayer(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 return base::i18n::IsRTL() ? width() - x : x; | 516 return base::i18n::IsRTL() ? width() - x : x; |
| 528 } | 517 } |
| 529 | 518 |
| 530 int View::GetMirroredXWithWidthInView(int x, int w) const { | 519 int View::GetMirroredXWithWidthInView(int x, int w) const { |
| 531 return base::i18n::IsRTL() ? width() - x - w : x; | 520 return base::i18n::IsRTL() ? width() - x - w : x; |
| 532 } | 521 } |
| 533 | 522 |
| 534 // Layout ---------------------------------------------------------------------- | 523 // Layout ---------------------------------------------------------------------- |
| 535 | 524 |
| 536 void View::Layout() { | 525 void View::Layout() { |
| 526 TRACE_EVENT0("View", "Layout"); | |
| 537 needs_layout_ = false; | 527 needs_layout_ = false; |
| 538 | 528 |
| 539 // If we have a layout manager, let it handle the layout for us. | 529 // If we have a layout manager, let it handle the layout for us. |
| 540 if (layout_manager_.get()) | 530 if (layout_manager_.get()) |
| 541 layout_manager_->Layout(this); | 531 layout_manager_->Layout(this); |
| 542 | 532 |
| 543 // Make sure to propagate the Layout() call to any children that haven't | 533 // Make sure to propagate the Layout() call to any children that haven't |
| 544 // received it yet through the layout manager and need to be laid out. This | 534 // received it yet through the layout manager and need to be laid out. This |
| 545 // is needed for the case when the child requires a layout but its bounds | 535 // is needed for the case when the child requires a layout but its bounds |
| 546 // weren't changed by the layout manager. If there is no layout manager, we | 536 // 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... | |
| 695 } | 685 } |
| 696 | 686 |
| 697 void View::SchedulePaintInRect(const gfx::Rect& rect) { | 687 void View::SchedulePaintInRect(const gfx::Rect& rect) { |
| 698 if (!IsVisible()) | 688 if (!IsVisible()) |
| 699 return; | 689 return; |
| 700 | 690 |
| 701 MarkLayerDirty(); | 691 MarkLayerDirty(); |
| 702 SchedulePaintInternal(rect); | 692 SchedulePaintInternal(rect); |
| 703 } | 693 } |
| 704 | 694 |
| 695 void View::ScheduleComposite() { | |
| 696 if (parent_) { | |
|
sky
2011/08/17 16:39:42
no {}
| |
| 697 parent_->ScheduleComposite(); | |
| 698 } | |
| 699 } | |
| 700 | |
| 705 void View::Paint(gfx::Canvas* canvas) { | 701 void View::Paint(gfx::Canvas* canvas) { |
| 706 if (!IsVisible()) | 702 TRACE_EVENT0("View", "Paint"); |
| 703 if (!IsVisible() || !painting_enabled()) | |
| 707 return; | 704 return; |
| 708 | 705 |
| 709 ScopedCanvas scoped_canvas(NULL); | 706 ScopedCanvas scoped_canvas(NULL); |
| 710 scoped_ptr<gfx::Canvas> layer_canvas; | 707 scoped_ptr<gfx::Canvas> layer_canvas; |
| 711 gfx::Rect layer_rect; | 708 gfx::Rect layer_rect; |
| 712 | 709 |
| 713 if (layer()) { | 710 if (layer()) { |
| 714 gfx::Rect dirty_rect; | 711 gfx::Rect dirty_rect; |
| 715 if (!layer_helper_->clip_rect().IsEmpty()) { | 712 if (!layer_helper_->clip_rect().IsEmpty()) { |
| 716 dirty_rect = layer_helper_->clip_rect(); | 713 dirty_rect = layer_helper_->clip_rect(); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1163 } | 1160 } |
| 1164 | 1161 |
| 1165 void View::OnPaintFocusBorder(gfx::Canvas* canvas) { | 1162 void View::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 1166 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) | 1163 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) |
| 1167 canvas->DrawFocusRect(0, 0, width(), height()); | 1164 canvas->DrawFocusRect(0, 0, width(), height()); |
| 1168 } | 1165 } |
| 1169 | 1166 |
| 1170 // Accelerated Painting -------------------------------------------------------- | 1167 // Accelerated Painting -------------------------------------------------------- |
| 1171 | 1168 |
| 1172 void View::PaintComposite() { | 1169 void View::PaintComposite() { |
| 1170 TRACE_EVENT0("View", "PaintComposite"); | |
| 1173 if (!IsVisible()) | 1171 if (!IsVisible()) |
| 1174 return; | 1172 return; |
| 1175 | 1173 |
| 1176 if (layer()) { | 1174 if (layer()) { |
| 1177 OnWillCompositeLayer(); | 1175 OnWillCompositeLayer(); |
| 1178 layer()->Draw(); | 1176 layer()->Draw(); |
| 1179 } | 1177 } |
| 1180 | 1178 |
| 1181 for (int i = 0, count = child_count(); i < count; ++i) | 1179 for (int i = 0, count = child_count(); i < count; ++i) |
| 1182 child_at(i)->PaintComposite(); | 1180 child_at(i)->PaintComposite(); |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2062 result.append(child_at(i)->PrintViewGraph(false)); | 2060 result.append(child_at(i)->PrintViewGraph(false)); |
| 2063 | 2061 |
| 2064 if (first) | 2062 if (first) |
| 2065 result.append("}\n"); | 2063 result.append("}\n"); |
| 2066 | 2064 |
| 2067 return result; | 2065 return result; |
| 2068 } | 2066 } |
| 2069 #endif | 2067 #endif |
| 2070 | 2068 |
| 2071 } // namespace views | 2069 } // namespace views |
| OLD | NEW |