OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 void View::SetTransform(const gfx::Transform& transform) { | 445 void View::SetTransform(const gfx::Transform& transform) { |
446 if (transform.IsIdentity()) { | 446 if (transform.IsIdentity()) { |
447 if (layer()) { | 447 if (layer()) { |
448 layer()->SetTransform(transform); | 448 layer()->SetTransform(transform); |
449 if (!paint_to_layer_) | 449 if (!paint_to_layer_) |
450 DestroyLayer(); | 450 DestroyLayer(); |
451 } else { | 451 } else { |
452 // Nothing. | 452 // Nothing. |
453 } | 453 } |
454 } else { | 454 } else { |
455 if (!layer()) | 455 if (!layer()) { |
456 CreateLayer(); | 456 CreateLayer(); |
457 // TODO(bruthig): Should a paint be scheduled on the parent here? | |
458 } | |
457 layer()->SetTransform(transform); | 459 layer()->SetTransform(transform); |
458 layer()->ScheduleDraw(); | 460 layer()->ScheduleDraw(); |
459 } | 461 } |
460 } | 462 } |
461 | 463 |
462 void View::SetPaintToLayer(bool paint_to_layer) { | 464 void View::SetPaintToLayer(bool paint_to_layer) { |
463 if (paint_to_layer_ == paint_to_layer) | 465 if (paint_to_layer_ == paint_to_layer) |
464 return; | 466 return; |
465 | 467 |
466 paint_to_layer_ = paint_to_layer; | 468 paint_to_layer_ = paint_to_layer; |
467 if (paint_to_layer_ && !layer()) { | 469 if (paint_to_layer_ && !layer()) { |
468 CreateLayer(); | 470 CreateLayer(); |
471 // The parent layer may be dirty due to a previous paint by |this|. | |
472 SchedulePaintOnParent(); | |
sky
2015/12/27 23:55:04
I think you should move this to CreateLayer, just
bruthig
2016/01/04 19:00:15
Done.
| |
469 } else if (!paint_to_layer_ && layer()) { | 473 } else if (!paint_to_layer_ && layer()) { |
470 DestroyLayer(); | 474 DestroyLayer(); |
471 } | 475 } |
472 } | 476 } |
473 | 477 |
474 scoped_ptr<ui::Layer> View::RecreateLayer() { | 478 scoped_ptr<ui::Layer> View::RecreateLayer() { |
475 scoped_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); | 479 scoped_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer(); |
476 Widget* widget = GetWidget(); | 480 Widget* widget = GetWidget(); |
477 if (widget) | 481 if (widget) |
478 widget->UpdateRootLayers(); | 482 widget->UpdateRootLayers(); |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 "width", canvas->sk_canvas()->getBaseLayerSize().width(), | 1415 "width", canvas->sk_canvas()->getBaseLayerSize().width(), |
1412 "height", canvas->sk_canvas()->getBaseLayerSize().height()); | 1416 "height", canvas->sk_canvas()->getBaseLayerSize().height()); |
1413 border_->Paint(*this, canvas); | 1417 border_->Paint(*this, canvas); |
1414 } | 1418 } |
1415 } | 1419 } |
1416 | 1420 |
1417 // Accelerated Painting -------------------------------------------------------- | 1421 // Accelerated Painting -------------------------------------------------------- |
1418 | 1422 |
1419 void View::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 1423 void View::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
1420 // This method should not have the side-effect of creating the layer. | 1424 // This method should not have the side-effect of creating the layer. |
1421 if (layer()) | 1425 if (!layer() || layer()->fills_bounds_opaquely() == fills_bounds_opaquely) |
1422 layer()->SetFillsBoundsOpaquely(fills_bounds_opaquely); | 1426 return; |
1427 | |
1428 layer()->SetFillsBoundsOpaquely(fills_bounds_opaquely); | |
1429 if (!fills_bounds_opaquely) | |
1430 SchedulePaintOnParent(); | |
sky
2015/12/27 23:55:04
I'm not following why this needed. If it is needed
bruthig
2016/01/04 19:00:15
Removed, I talked with ajuma@ about layers and thi
| |
1423 } | 1431 } |
1424 | 1432 |
1425 gfx::Vector2d View::CalculateOffsetToAncestorWithLayer( | 1433 gfx::Vector2d View::CalculateOffsetToAncestorWithLayer( |
1426 ui::Layer** layer_parent) { | 1434 ui::Layer** layer_parent) { |
1427 if (layer()) { | 1435 if (layer()) { |
1428 if (layer_parent) | 1436 if (layer_parent) |
1429 *layer_parent = layer(); | 1437 *layer_parent = layer(); |
1430 return gfx::Vector2d(); | 1438 return gfx::Vector2d(); |
1431 } | 1439 } |
1432 if (!parent_) | 1440 if (!parent_) |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1760 SchedulePaint(); | 1768 SchedulePaint(); |
1761 } else if (parent_ && type == SCHEDULE_PAINT_SIZE_SAME) { | 1769 } else if (parent_ && type == SCHEDULE_PAINT_SIZE_SAME) { |
1762 // The compositor doesn't Draw() until something on screen changes, so | 1770 // The compositor doesn't Draw() until something on screen changes, so |
1763 // if our position changes but nothing is being animated on screen, then | 1771 // if our position changes but nothing is being animated on screen, then |
1764 // tell the compositor to redraw the scene. We know layer() exists due to | 1772 // tell the compositor to redraw the scene. We know layer() exists due to |
1765 // the above if clause. | 1773 // the above if clause. |
1766 layer()->ScheduleDraw(); | 1774 layer()->ScheduleDraw(); |
1767 } | 1775 } |
1768 } | 1776 } |
1769 | 1777 |
1778 void View::SchedulePaintOnParent() { | |
1779 if (parent_) { | |
1780 // Translate the requested paint rect to the parent's coordinate system | |
1781 // then pass this notification up to the parent. | |
1782 parent_->SchedulePaintInRect(ConvertRectToParent(GetLocalBounds())); | |
1783 } | |
1784 } | |
1785 | |
1770 // Tree operations ------------------------------------------------------------- | 1786 // Tree operations ------------------------------------------------------------- |
1771 | 1787 |
1772 void View::DoRemoveChildView(View* view, | 1788 void View::DoRemoveChildView(View* view, |
1773 bool update_focus_cycle, | 1789 bool update_focus_cycle, |
1774 bool update_tool_tip, | 1790 bool update_tool_tip, |
1775 bool delete_removed_view, | 1791 bool delete_removed_view, |
1776 View* new_parent) { | 1792 View* new_parent) { |
1777 DCHECK(view); | 1793 DCHECK(view); |
1778 | 1794 |
1779 const Views::iterator i(std::find(children_.begin(), children_.end(), view)); | 1795 const Views::iterator i(std::find(children_.begin(), children_.end(), view)); |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2388 // Message the RootView to do the drag and drop. That way if we're removed | 2404 // Message the RootView to do the drag and drop. That way if we're removed |
2389 // the RootView can detect it and avoid calling us back. | 2405 // the RootView can detect it and avoid calling us back. |
2390 gfx::Point widget_location(event.location()); | 2406 gfx::Point widget_location(event.location()); |
2391 ConvertPointToWidget(this, &widget_location); | 2407 ConvertPointToWidget(this, &widget_location); |
2392 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2408 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2393 // WARNING: we may have been deleted. | 2409 // WARNING: we may have been deleted. |
2394 return true; | 2410 return true; |
2395 } | 2411 } |
2396 | 2412 |
2397 } // namespace views | 2413 } // namespace views |
OLD | NEW |