summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/geometry/dom_rect_read_only.h
blob: 77398f0ee11e21e54c5e7ccd284e1d0ee0d944da (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
// Copyright 2014 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_GEOMETRY_DOM_RECT_READ_ONLY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_GEOMETRY_DOM_RECT_READ_ONLY_H_

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/geometry/int_rect.h"

namespace blink {

class DOMRectInit;
class ScriptValue;
class ScriptState;

class CORE_EXPORT DOMRectReadOnly : public ScriptWrappable {
  DEFINE_WRAPPERTYPEINFO();

 public:
  static DOMRectReadOnly* Create(double x,
                                 double y,
                                 double width,
                                 double height);
  static DOMRectReadOnly* FromIntRect(const IntRect&);
  static DOMRectReadOnly* FromFloatRect(const FloatRect&);
  static DOMRectReadOnly* fromRect(const DOMRectInit*);

  DOMRectReadOnly(double x, double y, double width, double height);

  double x() const { return x_; }
  double y() const { return y_; }
  double width() const { return width_; }
  double height() const { return height_; }

  double top() const { return std::min(y_, y_ + height_); }
  double right() const { return std::max(x_, x_ + width_); }
  double bottom() const { return std::max(y_, y_ + height_); }
  double left() const { return std::min(x_, x_ + width_); }

  ScriptValue toJSONForBinding(ScriptState*) const;

 protected:
  double x_;
  double y_;
  double width_;
  double height_;
};

}  // namespace blink

#endif