1 // Copyright 2015 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ 7 8 #include "base/logging.h" 9 10 namespace mojo { 11 namespace test { 12 13 // An implementation of a hypothetical Rect type specifically for consumers in 14 // in Blink. Unlike the Chromium variant (see rect_chromium.h) this does not 15 // support negative origin coordinates and is not copyable. 16 class RectBlink { 17 public: RectBlink()18 RectBlink() {} RectBlink(int x,int y,int width,int height)19 RectBlink(int x, int y, int width, int height) : 20 x_(x), y_(y), width_(width), height_(height) { 21 DCHECK_GE(x_, 0); 22 DCHECK_GE(y_, 0); 23 DCHECK_GE(width_, 0); 24 DCHECK_GE(height_, 0); 25 } ~RectBlink()26 ~RectBlink() {} 27 x()28 int x() const { return x_; } setX(int x)29 void setX(int x) { 30 DCHECK_GE(x, 0); 31 x_ = x; 32 } 33 y()34 int y() const { return y_; } setY(int y)35 void setY(int y) { 36 DCHECK_GE(y, 0); 37 y_ = y; 38 } 39 width()40 int width() const { return width_; } setWidth(int width)41 void setWidth(int width) { 42 DCHECK_GE(width, 0); 43 width_ = width; 44 } 45 height()46 int height() const { return height_; } setHeight(int height)47 void setHeight(int height) { 48 DCHECK_GE(height, 0); 49 height_ = height; 50 } 51 computeArea()52 int computeArea() const { return width_ * height_; } 53 54 bool operator==(const RectBlink& other) const { 55 return (x() == other.x() && y() == other.y() && width() == other.width() && 56 height() == other.height()); 57 } 58 bool operator!=(const RectBlink& other) const { return !(*this == other); } 59 60 private: 61 int x_ = 0; 62 int y_ = 0; 63 int width_ = 0; 64 int height_ = 0; 65 }; 66 67 } // namespace test 68 } // namespace mojo 69 70 namespace std { 71 72 template <> 73 struct hash<mojo::test::RectBlink> { 74 size_t operator()(const mojo::test::RectBlink& value) { 75 // Terrible hash function: 76 return (std::hash<int>()(value.x()) ^ std::hash<int>()(value.y()) ^ 77 std::hash<int>()(value.width()) ^ std::hash<int>()(value.height())); 78 } 79 }; 80 81 } // namespace std 82 83 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_RECT_BLINK_H_ 84