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/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 view->PropagateAddNotifications(this, view); | 180 view->PropagateAddNotifications(this, view); |
181 UpdateTooltip(); | 181 UpdateTooltip(); |
182 if (GetWidget()) { | 182 if (GetWidget()) { |
183 RegisterChildrenForVisibleBoundsNotification(view); | 183 RegisterChildrenForVisibleBoundsNotification(view); |
184 view->CreateLayerIfNecessary(); | 184 view->CreateLayerIfNecessary(); |
185 } | 185 } |
186 | 186 |
187 if (layout_manager_.get()) | 187 if (layout_manager_.get()) |
188 layout_manager_->ViewAdded(this, view); | 188 layout_manager_->ViewAdded(this, view); |
189 | |
190 view->MarkLayerDirty(); | |
191 } | 189 } |
192 | 190 |
193 void View::ReorderChildView(View* view, int index) { | 191 void View::ReorderChildView(View* view, int index) { |
194 DCHECK_EQ(view->parent_, this); | 192 DCHECK_EQ(view->parent_, this); |
195 if (index < 0) | 193 if (index < 0) |
196 index = child_count() - 1; | 194 index = child_count() - 1; |
197 else if (index >= child_count()) | 195 else if (index >= child_count()) |
198 return; | 196 return; |
199 if (children_[index] == view) | 197 if (children_[index] == view) |
200 return; | 198 return; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 361 } |
364 | 362 |
365 int View::GetHeightForWidth(int w) { | 363 int View::GetHeightForWidth(int w) { |
366 if (layout_manager_.get()) | 364 if (layout_manager_.get()) |
367 return layout_manager_->GetPreferredHeightForWidth(this, w); | 365 return layout_manager_->GetPreferredHeightForWidth(this, w); |
368 return GetPreferredSize().height(); | 366 return GetPreferredSize().height(); |
369 } | 367 } |
370 | 368 |
371 void View::SetVisible(bool visible) { | 369 void View::SetVisible(bool visible) { |
372 if (visible != visible_) { | 370 if (visible != visible_) { |
373 // If the tab is currently visible, schedule paint to refresh parent. | 371 // If the View is currently visible, schedule paint to refresh parent. |
374 if (visible_) | 372 if (visible_) |
375 SchedulePaint(); | 373 SchedulePaint(); |
376 | 374 |
377 visible_ = visible; | 375 visible_ = visible; |
378 | 376 |
379 if (visible_) | 377 if (visible_) |
380 CreateLayerIfNecessary(); | 378 CreateLayerIfNecessary(); |
381 else | 379 else |
382 // Destroy layer if tab is invisible as invisible tabs never paint | 380 // Destroy layer if the View is invisible as invisible Views never paint. |
383 DestroyLayerRecurse(); | 381 DestroyLayerRecurse(); |
384 | 382 |
385 // This notifies all sub-views recursively. | 383 // This notifies all sub-views recursively. |
386 PropagateVisibilityNotifications(this, visible_); | 384 PropagateVisibilityNotifications(this, visible_); |
387 | 385 |
388 // If we are newly visible, schedule paint. | 386 // If we are newly visible, schedule paint. |
389 if (visible_) | 387 if (visible_) |
390 SchedulePaint(); | 388 SchedulePaint(); |
391 } | 389 } |
392 } | 390 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 return; | 425 return; |
428 layer_helper_->SetTransform(transform); | 426 layer_helper_->SetTransform(transform); |
429 | 427 |
430 if (!ShouldPaintToLayer()) | 428 if (!ShouldPaintToLayer()) |
431 DestroyLayerAndReparent(); | 429 DestroyLayerAndReparent(); |
432 else if (layer()) | 430 else if (layer()) |
433 layer_helper_->property_setter()->SetTransform(layer(), transform); | 431 layer_helper_->property_setter()->SetTransform(layer(), transform); |
434 | 432 |
435 SchedulePaint(); | 433 SchedulePaint(); |
436 } else { | 434 } else { |
437 // Make sure if the view didn't have its own texture and was painting onto | |
438 // something else, that gets refreshed too. | |
439 if (!ShouldPaintToLayer()) | |
440 MarkLayerDirty(); | |
441 | |
442 if (!layer_helper_.get()) | 435 if (!layer_helper_.get()) |
443 layer_helper_.reset(new internal::LayerHelper()); | 436 layer_helper_.reset(new internal::LayerHelper()); |
444 layer_helper_->SetTransform(transform); | 437 layer_helper_->SetTransform(transform); |
445 if (!layer()) { | 438 if (!layer()) { |
446 CreateLayer(); | 439 CreateLayer(); |
447 SchedulePaint(); | 440 SchedulePaint(); |
448 } else { | 441 } else { |
449 layer_helper_->property_setter()->SetTransform(layer(), transform); | 442 layer_helper_->property_setter()->SetTransform(layer(), transform); |
450 // We have a layer. When the transform changes and the layer is up to | 443 // We have a layer. When the transform changes and the layer is up to |
451 // date we don't want to SchedulePaint as it'll trigger painting to the | 444 // date we don't want to SchedulePaint as it'll trigger painting to the |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 // Painting -------------------------------------------------------------------- | 671 // Painting -------------------------------------------------------------------- |
679 | 672 |
680 void View::SchedulePaint() { | 673 void View::SchedulePaint() { |
681 SchedulePaintInRect(GetLocalBounds()); | 674 SchedulePaintInRect(GetLocalBounds()); |
682 } | 675 } |
683 | 676 |
684 void View::SchedulePaintInRect(const gfx::Rect& rect) { | 677 void View::SchedulePaintInRect(const gfx::Rect& rect) { |
685 if (!IsVisible() || !painting_enabled_) | 678 if (!IsVisible() || !painting_enabled_) |
686 return; | 679 return; |
687 | 680 |
688 MarkLayerDirty(); | 681 if (layer()) { |
689 SchedulePaintInternal(rect); | 682 layer()->SchedulePaint(rect); |
| 683 } else if (parent_) { |
| 684 // Translate the requested paint rect to the parent's coordinate system |
| 685 // then pass this notification up to the parent. |
| 686 parent_->SchedulePaintInRect(ConvertRectToParent(rect)); |
| 687 } |
690 } | 688 } |
691 | 689 |
692 void View::Paint(gfx::Canvas* canvas) { | 690 void View::Paint(gfx::Canvas* canvas) { |
693 TRACE_EVENT0("View", "Paint"); | 691 TRACE_EVENT0("View", "Paint"); |
694 if (!IsVisible() || !painting_enabled_) | 692 |
| 693 ScopedCanvas scoped_canvas(canvas); |
| 694 |
| 695 // Paint this View and its children, setting the clip rect to the bounds |
| 696 // of this View and translating the origin to the local bounds' top left |
| 697 // point. |
| 698 // |
| 699 // Note that the X (or left) position we pass to ClipRectInt takes into |
| 700 // consideration whether or not the view uses a right-to-left layout so that |
| 701 // we paint our view in its mirrored position if need be. |
| 702 if (!canvas->ClipRectInt(GetMirroredX(), y(), |
| 703 width() - static_cast<int>(clip_x_), |
| 704 height() - static_cast<int>(clip_y_))) { |
695 return; | 705 return; |
| 706 } |
| 707 // Non-empty clip, translate the graphics such that 0,0 corresponds to |
| 708 // where this view is located (related to its parent). |
| 709 canvas->TranslateInt(GetMirroredX(), y()); |
696 | 710 |
697 ScopedCanvas scoped_canvas(NULL); | 711 if (transform()) |
698 scoped_ptr<gfx::Canvas> layer_canvas; | 712 canvas->Transform(*transform()); |
699 gfx::Rect layer_rect; | |
700 | 713 |
701 if (layer()) { | 714 PaintCommon(canvas); |
702 gfx::Rect dirty_rect; | |
703 if (!layer_helper_->clip_rect().IsEmpty()) { | |
704 dirty_rect = layer_helper_->clip_rect(); | |
705 } else { | |
706 // TODO: clip against dirty rect of canvas (if canvas is non-null). | |
707 dirty_rect = gfx::Rect(0, 0, width(), height()); | |
708 } | |
709 if (dirty_rect.IsEmpty()) | |
710 return; | |
711 | |
712 if (!layer_helper_->bitmap_needs_updating()) { | |
713 // We don't need to be painted. Iterate over descendants in case one of | |
714 // them is dirty. | |
715 PaintToLayer(dirty_rect); | |
716 return; | |
717 } | |
718 | |
719 layer_canvas.reset(gfx::Canvas::CreateCanvas(dirty_rect.width(), | |
720 dirty_rect.height(), false)); | |
721 layer_canvas->AsCanvasSkia()->drawColor( | |
722 SK_ColorBLACK, SkXfermode::kClear_Mode); | |
723 layer_canvas->TranslateInt(-dirty_rect.x(), -dirty_rect.y()); | |
724 canvas = layer_canvas.get(); | |
725 layer_rect = dirty_rect; | |
726 } else { | |
727 // We're going to modify the canvas, save its state first. | |
728 scoped_canvas.SetCanvas(canvas); | |
729 | |
730 // Paint this View and its children, setting the clip rect to the bounds | |
731 // of this View and translating the origin to the local bounds' top left | |
732 // point. | |
733 // | |
734 // Note that the X (or left) position we pass to ClipRectInt takes into | |
735 // consideration whether or not the view uses a right-to-left layout so that | |
736 // we paint our view in its mirrored position if need be. | |
737 if (!canvas->ClipRectInt(GetMirroredX(), y(), | |
738 width() - static_cast<int>(clip_x_), | |
739 height() - static_cast<int>(clip_y_))) { | |
740 return; | |
741 } | |
742 // Non-empty clip, translate the graphics such that 0,0 corresponds to | |
743 // where this view is located (related to its parent). | |
744 canvas->TranslateInt(GetMirroredX(), y()); | |
745 | |
746 if (transform()) | |
747 canvas->Transform(*transform()); | |
748 } | |
749 | |
750 { | |
751 // If the View we are about to paint requested the canvas to be flipped, we | |
752 // should change the transform appropriately. | |
753 // The canvas mirroring is undone once the View is done painting so that we | |
754 // don't pass the canvas with the mirrored transform to Views that didn't | |
755 // request the canvas to be flipped. | |
756 | |
757 ScopedCanvas scoped(canvas); | |
758 if (FlipCanvasOnPaintForRTLUI()) { | |
759 canvas->TranslateInt(width(), 0); | |
760 canvas->ScaleInt(-1, 1); | |
761 } | |
762 | |
763 OnPaint(canvas); | |
764 } | |
765 | |
766 PaintChildren(canvas); | |
767 | |
768 if (layer_canvas.get()) { | |
769 layer()->SetCanvas(*layer_canvas->AsCanvasSkia(), layer_rect.origin()); | |
770 layer_helper_->set_bitmap_needs_updating(false); | |
771 } | |
772 } | 715 } |
773 | 716 |
774 ThemeProvider* View::GetThemeProvider() const { | 717 ThemeProvider* View::GetThemeProvider() const { |
775 const Widget* widget = GetWidget(); | 718 const Widget* widget = GetWidget(); |
776 return widget ? widget->GetThemeProvider() : NULL; | 719 return widget ? widget->GetThemeProvider() : NULL; |
777 } | 720 } |
778 | 721 |
779 // Accelerated Painting -------------------------------------------------------- | 722 // Accelerated Painting -------------------------------------------------------- |
780 | 723 |
781 // static | 724 // static |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 border_->Paint(*this, canvas); | 1093 border_->Paint(*this, canvas); |
1151 } | 1094 } |
1152 | 1095 |
1153 void View::OnPaintFocusBorder(gfx::Canvas* canvas) { | 1096 void View::OnPaintFocusBorder(gfx::Canvas* canvas) { |
1154 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) | 1097 if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) |
1155 canvas->DrawFocusRect(0, 0, width(), height()); | 1098 canvas->DrawFocusRect(0, 0, width(), height()); |
1156 } | 1099 } |
1157 | 1100 |
1158 // Accelerated Painting -------------------------------------------------------- | 1101 // Accelerated Painting -------------------------------------------------------- |
1159 | 1102 |
1160 void View::PaintComposite() { | |
1161 if (!IsVisible()) | |
1162 return; | |
1163 | |
1164 if (layer()) { | |
1165 OnWillCompositeLayer(); | |
1166 layer()->Draw(); | |
1167 } | |
1168 | |
1169 for (int i = 0, count = child_count(); i < count; ++i) | |
1170 child_at(i)->PaintComposite(); | |
1171 } | |
1172 | |
1173 void View::SchedulePaintInternal(const gfx::Rect& rect) { | |
1174 if (parent_ && parent_->IsVisible() && painting_enabled_) { | |
1175 // Translate the requested paint rect to the parent's coordinate system | |
1176 // then pass this notification up to the parent. | |
1177 parent_->SchedulePaintInternal(ConvertRectToParent(rect)); | |
1178 } | |
1179 } | |
1180 | |
1181 void View::PaintToLayer(const gfx::Rect& dirty_region) { | |
1182 if (!IsVisible()) | |
1183 return; | |
1184 | |
1185 if (layer() && layer_helper_->bitmap_needs_updating()) { | |
1186 if (!layer_helper_->needs_paint_all()) | |
1187 layer_helper_->set_clip_rect(dirty_region); | |
1188 else | |
1189 layer_helper_->set_needs_paint_all(false); | |
1190 Paint(NULL); | |
1191 layer_helper_->set_clip_rect(gfx::Rect()); | |
1192 } else { | |
1193 // Forward to all children as a descendant may be dirty and have a layer. | |
1194 for (int i = child_count() - 1; i >= 0; --i) { | |
1195 View* child_view = child_at(i); | |
1196 | |
1197 gfx::Rect child_dirty_rect = dirty_region; | |
1198 child_dirty_rect.Offset(-child_view->GetMirroredX(), -child_view->y()); | |
1199 child_view->GetTransform().TransformRectReverse(&child_dirty_rect); | |
1200 child_dirty_rect = gfx::Rect(gfx::Point(), child_view->size()).Intersect( | |
1201 child_dirty_rect); | |
1202 | |
1203 if (!child_dirty_rect.IsEmpty()) | |
1204 child_at(i)->PaintToLayer(child_dirty_rect); | |
1205 } | |
1206 } | |
1207 } | |
1208 | |
1209 void View::OnWillCompositeLayer() { | |
1210 } | |
1211 | |
1212 void View::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { | 1103 void View::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { |
1213 if (!layer_helper_.get()) | 1104 if (!layer_helper_.get()) |
1214 layer_helper_.reset(new internal::LayerHelper()); | 1105 layer_helper_.reset(new internal::LayerHelper()); |
1215 | 1106 |
1216 layer_helper_->set_fills_bounds_opaquely(fills_bounds_opaquely); | 1107 layer_helper_->set_fills_bounds_opaquely(fills_bounds_opaquely); |
1217 | 1108 |
1218 if (layer()) | 1109 if (layer()) |
1219 layer()->SetFillsBoundsOpaquely(fills_bounds_opaquely); | 1110 layer()->SetFillsBoundsOpaquely(fills_bounds_opaquely); |
1220 } | 1111 } |
1221 | 1112 |
(...skipping 13 matching lines...) Expand all Loading... |
1235 return false; | 1126 return false; |
1236 | 1127 |
1237 // Child views must not paint into the external texture. So make sure each | 1128 // Child views must not paint into the external texture. So make sure each |
1238 // child view has its own layer to paint into. | 1129 // child view has its own layer to paint into. |
1239 if (use_external) { | 1130 if (use_external) { |
1240 for (Views::iterator i = children_.begin(); i != children_.end(); ++i) | 1131 for (Views::iterator i = children_.begin(); i != children_.end(); ++i) |
1241 (*i)->SetPaintToLayer(true); | 1132 (*i)->SetPaintToLayer(true); |
1242 } | 1133 } |
1243 | 1134 |
1244 layer_helper_->set_layer_updated_externally(use_external); | 1135 layer_helper_->set_layer_updated_externally(use_external); |
1245 layer_helper_->set_bitmap_needs_updating(!use_external); | |
1246 if (layer()) | 1136 if (layer()) |
1247 layer()->SetTexture(texture); | 1137 layer()->SetTexture(texture); |
1248 | 1138 |
1249 if (IsVisible()) | 1139 SchedulePaintInRect(GetLocalBounds()); |
1250 SchedulePaintInternal(GetLocalBounds()); | |
1251 | 1140 |
1252 return true; | 1141 return true; |
1253 } | 1142 } |
1254 | 1143 |
1255 const ui::Compositor* View::GetCompositor() const { | 1144 const ui::Compositor* View::GetCompositor() const { |
1256 return parent_ ? parent_->GetCompositor() : NULL; | 1145 return parent_ ? parent_->GetCompositor() : NULL; |
1257 } | 1146 } |
1258 | 1147 |
1259 ui::Compositor* View::GetCompositor() { | 1148 ui::Compositor* View::GetCompositor() { |
1260 return parent_ ? parent_->GetCompositor() : NULL; | 1149 return parent_ ? parent_->GetCompositor() : NULL; |
1261 } | 1150 } |
1262 | 1151 |
1263 void View::MarkLayerDirty() { | |
1264 if (!use_acceleration_when_possible) | |
1265 return; | |
1266 | |
1267 if (ShouldPaintToLayer()) { | |
1268 if (!layer_helper_->layer_updated_externally()) | |
1269 layer_helper_->set_bitmap_needs_updating(true); | |
1270 return; | |
1271 } | |
1272 if (parent_) | |
1273 parent_->MarkLayerDirty(); | |
1274 } | |
1275 | |
1276 void View::CalculateOffsetToAncestorWithLayer(gfx::Point* offset, | 1152 void View::CalculateOffsetToAncestorWithLayer(gfx::Point* offset, |
1277 View** ancestor) { | 1153 ui::Layer** layer_parent) { |
1278 if (layer()) { | 1154 if (layer()) { |
1279 if (ancestor) | 1155 if (layer_parent) |
1280 *ancestor = this; | 1156 *layer_parent = layer(); |
1281 return; | 1157 return; |
1282 } | 1158 } |
1283 if (!parent_) | 1159 if (!parent_) |
1284 return; | 1160 return; |
1285 | 1161 |
1286 offset->Offset(x(), y()); | 1162 offset->Offset(x(), y()); |
1287 parent_->CalculateOffsetToAncestorWithLayer(offset, ancestor); | 1163 parent_->CalculateOffsetToAncestorWithLayer(offset, layer_parent); |
1288 } | 1164 } |
1289 | 1165 |
1290 void View::CreateLayerIfNecessary() { | 1166 void View::CreateLayerIfNecessary() { |
1291 if (ShouldPaintToLayer()) | 1167 if (ShouldPaintToLayer()) |
1292 CreateLayer(); | 1168 CreateLayer(); |
1293 | 1169 |
1294 for (int i = 0, count = child_count(); i < count; ++i) | 1170 for (int i = 0, count = child_count(); i < count; ++i) |
1295 child_at(i)->CreateLayerIfNecessary(); | 1171 child_at(i)->CreateLayerIfNecessary(); |
1296 } | 1172 } |
1297 | 1173 |
(...skipping 23 matching lines...) Expand all Loading... |
1321 layer_helper_->property_setter()->SetBounds( | 1197 layer_helper_->property_setter()->SetBounds( |
1322 layer(), | 1198 layer(), |
1323 gfx::Rect(offset.x() + x(), offset.y() + y(), width(), height())); | 1199 gfx::Rect(offset.x() + x(), offset.y() + y(), width(), height())); |
1324 } else { | 1200 } else { |
1325 gfx::Point new_offset(offset.x() + x(), offset.y() + y()); | 1201 gfx::Point new_offset(offset.x() + x(), offset.y() + y()); |
1326 for (int i = 0, count = child_count(); i < count; ++i) | 1202 for (int i = 0, count = child_count(); i < count; ++i) |
1327 child_at(i)->UpdateLayerBounds(new_offset); | 1203 child_at(i)->UpdateLayerBounds(new_offset); |
1328 } | 1204 } |
1329 } | 1205 } |
1330 | 1206 |
| 1207 void View::OnPaintLayer(gfx::Canvas* canvas) { |
| 1208 // If someone else is directly providing our Layer's texture, we should not |
| 1209 // do any rendering. |
| 1210 if (layer_helper_->layer_updated_externally()) |
| 1211 return; |
| 1212 canvas->AsCanvasSkia()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); |
| 1213 PaintCommon(canvas); |
| 1214 } |
| 1215 |
1331 // Input ----------------------------------------------------------------------- | 1216 // Input ----------------------------------------------------------------------- |
1332 | 1217 |
1333 bool View::HasHitTestMask() const { | 1218 bool View::HasHitTestMask() const { |
1334 return false; | 1219 return false; |
1335 } | 1220 } |
1336 | 1221 |
1337 void View::GetHitTestMask(gfx::Path* mask) const { | 1222 void View::GetHitTestMask(gfx::Path* mask) const { |
1338 DCHECK(mask); | 1223 DCHECK(mask); |
1339 } | 1224 } |
1340 | 1225 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 } | 1308 } |
1424 | 1309 |
1425 void View::DragInfo::PossibleDrag(const gfx::Point& p) { | 1310 void View::DragInfo::PossibleDrag(const gfx::Point& p) { |
1426 possible_drag = true; | 1311 possible_drag = true; |
1427 start_pt = p; | 1312 start_pt = p; |
1428 } | 1313 } |
1429 | 1314 |
1430 // Painting -------------------------------------------------------------------- | 1315 // Painting -------------------------------------------------------------------- |
1431 | 1316 |
1432 void View::SchedulePaintBoundsChanged(SchedulePaintType type) { | 1317 void View::SchedulePaintBoundsChanged(SchedulePaintType type) { |
1433 if (layer() && type == SCHEDULE_PAINT_SIZE_SAME) { | 1318 // If we have a layer and the View's size did not change, we do not need to |
1434 // If only the positions changes and we have a layer, we don't need to mark | 1319 // schedule any paints since the layer will be redrawn at its new location |
1435 // the layer as dirty (which SchedulePaint does), only paint the bounds. | 1320 // during the next Draw() cycle in the compositor. |
1436 SchedulePaintInternal(gfx::Rect(0, 0, width(), height())); | 1321 if (!layer() || type == SCHEDULE_PAINT_SIZE_CHANGED) { |
1437 } else { | 1322 // Otherwise, if the size changes or we don't have a layer then we need to |
1438 // If the size changes, or we don't have a layer then we need to use | 1323 // use SchedulePaint to invalidate the area occupied by the View. |
1439 // SchedulePaint to make sure the layer is marked as dirty. | |
1440 SchedulePaint(); | 1324 SchedulePaint(); |
1441 } | 1325 } |
1442 } | 1326 } |
1443 | 1327 |
| 1328 void View::PaintCommon(gfx::Canvas* canvas) { |
| 1329 if (!IsVisible() || !painting_enabled_) |
| 1330 return; |
| 1331 |
| 1332 { |
| 1333 // If the View we are about to paint requested the canvas to be flipped, we |
| 1334 // should change the transform appropriately. |
| 1335 // The canvas mirroring is undone once the View is done painting so that we |
| 1336 // don't pass the canvas with the mirrored transform to Views that didn't |
| 1337 // request the canvas to be flipped. |
| 1338 ScopedCanvas scoped(canvas); |
| 1339 if (FlipCanvasOnPaintForRTLUI()) { |
| 1340 canvas->TranslateInt(width(), 0); |
| 1341 canvas->ScaleInt(-1, 1); |
| 1342 } |
| 1343 |
| 1344 OnPaint(canvas); |
| 1345 } |
| 1346 |
| 1347 PaintChildren(canvas); |
| 1348 } |
| 1349 |
1444 // Tree operations ------------------------------------------------------------- | 1350 // Tree operations ------------------------------------------------------------- |
1445 | 1351 |
1446 void View::DoRemoveChildView(View* view, | 1352 void View::DoRemoveChildView(View* view, |
1447 bool update_focus_cycle, | 1353 bool update_focus_cycle, |
1448 bool update_tool_tip, | 1354 bool update_tool_tip, |
1449 bool delete_removed_view) { | 1355 bool delete_removed_view) { |
1450 DCHECK(view); | 1356 DCHECK(view); |
1451 const Views::iterator i(std::find(children_.begin(), children_.end(), view)); | 1357 const Views::iterator i(std::find(children_.begin(), children_.end(), view)); |
1452 scoped_ptr<View> view_to_be_deleted; | 1358 scoped_ptr<View> view_to_be_deleted; |
1453 if (i != children_.end()) { | 1359 if (i != children_.end()) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 offset.Offset(x(), y()); | 1466 offset.Offset(x(), y()); |
1561 layer_helper_->property_setter()->SetBounds( | 1467 layer_helper_->property_setter()->SetBounds( |
1562 layer(), gfx::Rect(offset, size())); | 1468 layer(), gfx::Rect(offset, size())); |
1563 } else { | 1469 } else { |
1564 layer_helper_->property_setter()->SetBounds(layer(), bounds_); | 1470 layer_helper_->property_setter()->SetBounds(layer(), bounds_); |
1565 } | 1471 } |
1566 if (previous_bounds.size() != bounds_.size() && | 1472 if (previous_bounds.size() != bounds_.size() && |
1567 !layer_helper_->layer_updated_externally()) { | 1473 !layer_helper_->layer_updated_externally()) { |
1568 // If our bounds have changed then we need to update the complete | 1474 // If our bounds have changed then we need to update the complete |
1569 // texture. | 1475 // texture. |
1570 layer_helper_->set_needs_paint_all(true); | 1476 layer()->SchedulePaint(GetLocalBounds()); |
1571 } | 1477 } |
1572 } else if (GetCompositor()) { | 1478 } else if (GetCompositor()) { |
1573 // If our bounds have changed, then any descendant layer bounds may | 1479 // If our bounds have changed, then any descendant layer bounds may |
1574 // have changed. Update them accordingly. | 1480 // have changed. Update them accordingly. |
1575 gfx::Point offset; | 1481 gfx::Point offset; |
1576 CalculateOffsetToAncestorWithLayer(&offset, NULL); | 1482 CalculateOffsetToAncestorWithLayer(&offset, NULL); |
1577 // CalculateOffsetToAncestorWithLayer includes our location as does | 1483 // CalculateOffsetToAncestorWithLayer includes our location as does |
1578 // UpdateLayerBounds. | 1484 // UpdateLayerBounds. |
1579 offset.Offset(-x(), -y()); | 1485 offset.Offset(-x(), -y()); |
1580 UpdateLayerBounds(offset); | 1486 UpdateLayerBounds(offset); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 void View::CreateLayer() { | 1657 void View::CreateLayer() { |
1752 if (!ShouldPaintToLayer() || layer()) | 1658 if (!ShouldPaintToLayer() || layer()) |
1753 return; | 1659 return; |
1754 | 1660 |
1755 ui::Compositor* compositor = GetCompositor(); | 1661 ui::Compositor* compositor = GetCompositor(); |
1756 if (!compositor) | 1662 if (!compositor) |
1757 return; | 1663 return; |
1758 | 1664 |
1759 DCHECK(layer_helper_.get()); | 1665 DCHECK(layer_helper_.get()); |
1760 | 1666 |
1761 View* ancestor_with_layer = NULL; | 1667 ui::Layer* layer_parent = NULL; |
1762 gfx::Point offset; | 1668 gfx::Point offset; |
1763 CalculateOffsetToAncestorWithLayer(&offset, &ancestor_with_layer); | 1669 CalculateOffsetToAncestorWithLayer(&offset, &layer_parent); |
1764 | 1670 |
1765 DCHECK(ancestor_with_layer || parent_ == NULL); | 1671 DCHECK(layer_parent || parent_ == NULL); |
1766 | 1672 |
1767 layer_helper_->SetLayer(new ui::Layer(compositor)); | 1673 layer_helper_->SetLayer(new ui::Layer(compositor)); |
| 1674 layer()->set_delegate(this); |
1768 layer()->SetFillsBoundsOpaquely(layer_helper_->fills_bounds_opaquely()); | 1675 layer()->SetFillsBoundsOpaquely(layer_helper_->fills_bounds_opaquely()); |
1769 layer()->SetBounds(gfx::Rect(offset.x(), offset.y(), width(), height())); | 1676 layer()->SetBounds(gfx::Rect(offset.x(), offset.y(), width(), height())); |
1770 layer()->SetTransform(GetTransform()); | 1677 layer()->SetTransform(GetTransform()); |
1771 if (ancestor_with_layer) | 1678 if (layer_parent) |
1772 ancestor_with_layer->layer()->Add(layer()); | 1679 layer_parent->Add(layer()); |
1773 layer_helper_->set_bitmap_needs_updating(true); | 1680 layer()->SchedulePaint(GetLocalBounds()); |
1774 layer_helper_->set_needs_paint_all(true); | |
1775 | 1681 |
1776 MoveLayerToParent(layer(), gfx::Point()); | 1682 MoveLayerToParent(layer(), gfx::Point()); |
1777 } | 1683 } |
1778 | 1684 |
1779 void View::DestroyLayerAndReparent() { | 1685 void View::DestroyLayerAndReparent() { |
1780 if (!layer()) | 1686 if (!layer()) |
1781 return; | 1687 return; |
1782 | 1688 |
1783 ui::Layer* new_parent = layer()->parent(); | 1689 ui::Layer* new_parent = layer()->parent(); |
1784 std::vector<ui::Layer*> children = layer()->children(); | 1690 std::vector<ui::Layer*> children = layer()->children(); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2066 result.append(child_at(i)->PrintViewGraph(false)); | 1972 result.append(child_at(i)->PrintViewGraph(false)); |
2067 | 1973 |
2068 if (first) | 1974 if (first) |
2069 result.append("}\n"); | 1975 result.append("}\n"); |
2070 | 1976 |
2071 return result; | 1977 return result; |
2072 } | 1978 } |
2073 #endif | 1979 #endif |
2074 | 1980 |
2075 } // namespace views | 1981 } // namespace views |
OLD | NEW |