summaryrefslogtreecommitdiffstats
path: root/webkit/glue/stacking_order_iterator.h
blob: 9e75d21f0100cd4a48256a6d8631805cda52cf5c (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
74
75
76
77
78
79
80
81
82
// 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>
#include "IntRect.h"

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, and the bounding
  // box we are interested in.  The bounds coordinates are relative to
  // the given layer.
  void Reset(const WebCore::IntRect& bounds, 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();

    WebCore::RenderLayer* layer() const {
      return layer_;
    }

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

  WebCore::IntRect bounds_;
  const WebCore::RenderLayer* root_layer_;
  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(const WebCore::IntRect& bounds, 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__