1<?php
2
3class StrategyPositionAbsolute {
4  function StrategyPositionAbsolute() {
5  }
6
7  function apply(&$box) {
8    /**
9     * Box having 'position: absolute' are positioned relatively to their "containing blocks".
10     *
11     * @link http://www.w3.org/TR/CSS21/visudet.html#x0 CSS 2.1 Definition of "containing block"
12     */
13    $containing_block =& $box->_get_containing_block();
14
15    $this->_positionAbsoluteVertically($box, $containing_block);
16    $this->_positionAbsoluteHorizontally($box, $containing_block);
17  }
18
19  /**
20   * Note that if both top and bottom are 'auto', box will use vertical coordinate
21   * calculated using guess_corder in 'reflow' method which could be used if this
22   * box had 'position: static'
23   */
24  function _positionAbsoluteVertically(&$box, &$containing_block) {
25    $bottom = $box->get_css_property(CSS_BOTTOM);
26    $top    = $box->get_css_property(CSS_TOP);
27
28    if (!$top->isAuto()) {
29      if ($top->isPercentage()) {
30        $top_value = ($containing_block['top'] - $containing_block['bottom']) / 100 * $top->getPercentage();
31      } else {
32        $top_value = $top->getPoints();
33      };
34      $box->put_top($containing_block['top'] - $top_value - $box->get_extra_top());
35    } elseif (!$bottom->isAuto()) {
36      if ($bottom->isPercentage()) {
37        $bottom_value = ($containing_block['top'] - $containing_block['bottom']) / 100 * $bottom->getPercentage();
38      } else {
39        $bottom_value = $bottom->getPoints();
40      };
41      $box->put_top($containing_block['bottom'] + $bottom_value + $box->get_extra_bottom() + $box->get_height());
42    };
43
44//     $bottom = $box->get_css_property(CSS_BOTTOM);
45//     $top    = $box->get_css_property(CSS_TOP);
46//     if ($top->isAuto() && !$bottom->isAuto()) {
47//       $box->offset(0, $box->get_height());
48//     };
49  }
50
51  /**
52   * Note that  if both  'left' and 'right'  are 'auto', box  will use
53   * horizontal coordinate  calculated using guess_corder  in 'reflow'
54   * method which could be used if this box had 'position: static'
55   */
56  function _positionAbsoluteHorizontally(&$box, &$containing_block) {
57    $left  = $box->get_css_property(CSS_LEFT);
58    $right = $box->get_css_property(CSS_RIGHT);
59
60    if (!$left->isAuto()) {
61      if ($left->isPercentage()) {
62        $left_value = ($containing_block['right'] - $containing_block['left']) / 100 * $left->getPercentage();
63      } else {
64        $left_value = $left->getPoints();
65      };
66      $box->put_left($containing_block['left'] + $left_value + $box->get_extra_left());
67    } elseif (!$right->isAuto()) {
68      if ($right->isPercentage()) {
69        $right_value = ($containing_block['right'] - $containing_block['left']) / 100 * $right->getPercentage();
70      } else {
71        $right_value = $right->getPoints();
72      };
73
74      $left = $containing_block['right'] - $right_value - $box->get_extra_right() - $box->get_width();
75      $box->put_left($left);
76    };
77
78//     $right = $box->get_css_property(CSS_RIGHT);
79//     $left  = $box->get_css_property(CSS_LEFT);
80//     if ($left->isAuto() && !$right->isAuto()) {
81//       $box->offset(-$box->get_width(), 0);
82//     };
83  }
84}
85
86?>
87