OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #pragma warning(push, 0) |
| 8 #include "RenderLayer.h" |
| 9 #include "RenderObject.h" |
| 10 #pragma warning(pop) |
| 11 #undef LOG |
| 12 |
| 13 #include "webkit/glue/stacking_order_iterator.h" |
| 14 |
| 15 // |
| 16 // RenderLayerIterator |
| 17 // |
| 18 |
| 19 RenderLayerIterator::RenderLayerIterator() { |
| 20 } |
| 21 |
| 22 void RenderLayerIterator::Reset(WebCore::RenderLayer* rl) { |
| 23 if (rl) { |
| 24 context_stack_.push_back(Context(rl)); |
| 25 } |
| 26 } |
| 27 |
| 28 WebCore::RenderLayer* RenderLayerIterator::Next() { |
| 29 while (context_stack_.size()) { |
| 30 Context* ctx = &(context_stack_.back()); |
| 31 if (ctx->HasMoreNeg()) { |
| 32 context_stack_.push_back(ctx->NextNeg()); |
| 33 } else if (ctx->HasSelf()) { |
| 34 // Emit self. |
| 35 return ctx->NextSelf(); |
| 36 } else if (ctx->HasMoreOverflow()) { |
| 37 context_stack_.push_back(ctx->NextOverflow()); |
| 38 } else if (ctx->HasMorePos()) { |
| 39 context_stack_.push_back(ctx->NextPos()); |
| 40 } else { |
| 41 // Nothing left in this context. Pop. |
| 42 context_stack_.pop_back(); |
| 43 } |
| 44 } |
| 45 return NULL; |
| 46 } |
| 47 |
| 48 RenderLayerIterator::Context::Context(WebCore::RenderLayer* layer) |
| 49 : layer_(layer), |
| 50 next_neg_(0), |
| 51 next_self_(0), |
| 52 next_overflow_(0), |
| 53 next_pos_(0) { |
| 54 ASSERT(layer_); |
| 55 layer_->updateZOrderLists(); |
| 56 layer_->updateOverflowList(); |
| 57 } |
| 58 |
| 59 bool RenderLayerIterator::Context::HasMoreNeg() { |
| 60 return layer_->negZOrderList() && |
| 61 next_neg_ < layer_->negZOrderList()->size(); |
| 62 } |
| 63 |
| 64 RenderLayerIterator::Context RenderLayerIterator::Context::NextNeg() { |
| 65 ASSERT(HasMoreNeg()); |
| 66 return Context(layer_->negZOrderList()->at(next_neg_++)); |
| 67 } |
| 68 |
| 69 bool RenderLayerIterator::Context::HasSelf() { |
| 70 return next_self_ < 1; |
| 71 } |
| 72 |
| 73 WebCore::RenderLayer* RenderLayerIterator::Context::NextSelf() { |
| 74 ASSERT(HasSelf()); |
| 75 next_self_ = 1; |
| 76 return layer_; |
| 77 } |
| 78 |
| 79 bool RenderLayerIterator::Context::HasMoreOverflow() { |
| 80 return layer_->overflowList() && |
| 81 next_overflow_ >= 0 && |
| 82 next_overflow_ < layer_->overflowList()->size(); |
| 83 } |
| 84 |
| 85 RenderLayerIterator::Context RenderLayerIterator::Context::NextOverflow() { |
| 86 ASSERT(HasMoreOverflow()); |
| 87 return Context(layer_->overflowList()->at(next_overflow_++)); |
| 88 } |
| 89 |
| 90 bool RenderLayerIterator::Context::HasMorePos() { |
| 91 return layer_->posZOrderList() && |
| 92 next_pos_ < layer_->posZOrderList()->size(); |
| 93 } |
| 94 |
| 95 RenderLayerIterator::Context RenderLayerIterator::Context::NextPos() { |
| 96 ASSERT(HasMorePos()); |
| 97 return Context(layer_->posZOrderList()->at(next_pos_++)); |
| 98 } |
| 99 |
| 100 // |
| 101 // StackingOrderIterator |
| 102 // |
| 103 |
| 104 StackingOrderIterator::StackingOrderIterator() { |
| 105 Reset(NULL); |
| 106 } |
| 107 |
| 108 void StackingOrderIterator::Reset(WebCore::RenderLayer* rl) { |
| 109 layer_iterator_.Reset(rl); |
| 110 current_object_ = NULL; |
| 111 current_layer_root_ = NULL; |
| 112 } |
| 113 |
| 114 WebCore::RenderObject* StackingOrderIterator::Next() { |
| 115 if (current_object_) { |
| 116 // Get the next object inside the current layer. |
| 117 current_object_ = current_object_->nextInPreOrder(current_layer_root_); |
| 118 |
| 119 // Skip any sub-layers we encounter along the way; they are |
| 120 // visited (in the correct stacking order) by layer_iterator_. |
| 121 while (current_object_ && current_object_->hasLayer()) { |
| 122 current_object_ = current_object_-> |
| 123 nextInPreOrderAfterChildren(current_layer_root_); |
| 124 } |
| 125 } |
| 126 |
| 127 if (!current_object_) { |
| 128 // Start the next layer. |
| 129 WebCore::RenderLayer* layer = layer_iterator_.Next(); |
| 130 if (layer) { |
| 131 current_object_ = layer->renderer(); |
| 132 current_layer_root_ = current_object_; |
| 133 } |
| 134 // No more layers. |
| 135 } |
| 136 return current_object_; |
| 137 } |
OLD | NEW |