summaryrefslogtreecommitdiffstats
path: root/webkit/glue/stacking_order_iterator.h
blob: 20dea41afe8c5af3a1b11a43d4f212e9b992c8ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Provides some utilities for iterating over a RenderObject graph in
// stacking order.

#ifndef WEBKIT_GLUE_STACKING_ORDER_ITERATOR_H__
#define WEBKIT_GLUE_STACKING_ORDER_ITERATOR_H__

#include <vector>

namespace WebCore {
class RenderLayer;
class RenderObject;
}

// Iterates over a subtree of RenderLayers in stacking order, back to
// front.  Modifying the RenderObject graph invalidates this iterator.
//
// TODO(tulrich): this could go in webkit.
// TODO(tulrich): needs unittests.
class RenderLayerIterator {
 public:
  RenderLayerIterator();

  // Sets the RenderLayer subtree to iterate over.
  void Reset(WebCore::RenderLayer* rl);

  // Returns the next RenderLayer in stacking order, back to front.
  WebCore::RenderLayer* Next();
 private:
  class Context {
   public:
    Context(WebCore::RenderLayer* layer);

    bool HasMoreNeg();
    Context NextNeg();
    bool HasSelf();
    WebCore::RenderLayer* NextSelf();
    bool HasMoreOverflow();
    Context NextOverflow();
    bool HasMorePos();
    Context NextPos();

   private:
    WebCore::RenderLayer* layer_;
    size_t next_neg_;
    size_t next_self_;
    size_t next_overflow_;
    size_t next_pos_;
  };

  std::vector<Context> context_stack_;
};

// Iterates over a subtree of RenderObjects below a given RenderLayer.
//
// TODO(tulrich): this could go in webkit.
// TODO(tulrich): needs unittests.
class StackingOrderIterator {
 public:
  StackingOrderIterator();
  void Reset(WebCore::RenderLayer* rl);
  WebCore::RenderObject* Next();

 private:
  RenderLayerIterator layer_iterator_;
  WebCore::RenderObject* current_object_;
  WebCore::RenderObject* current_layer_root_;
};

#endif  // WEBKIT_GLUE_STACKING_ORDER_ITERATOR_H__