aboutsummaryrefslogtreecommitdiff
path: root/ui/gfx/range
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gfx/range')
-rw-r--r--ui/gfx/range/BUILD.gn33
-rw-r--r--ui/gfx/range/gfx_range_export.h29
-rw-r--r--ui/gfx/range/range.cc34
-rw-r--r--ui/gfx/range/range.h139
-rw-r--r--ui/gfx/range/range_f.cc58
-rw-r--r--ui/gfx/range/range_f.h101
-rw-r--r--ui/gfx/range/range_mac.mm38
-rw-r--r--ui/gfx/range/range_mac_unittest.mm43
-rw-r--r--ui/gfx/range/range_unittest.cc266
-rw-r--r--ui/gfx/range/range_win.cc45
-rw-r--r--ui/gfx/range/range_win_unittest.cc63
11 files changed, 0 insertions, 849 deletions
diff --git a/ui/gfx/range/BUILD.gn b/ui/gfx/range/BUILD.gn
deleted file mode 100644
index 0a8d8b2..0000000
--- a/ui/gfx/range/BUILD.gn
+++ /dev/null
@@ -1,33 +0,0 @@
-# Copyright 2016 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.
-
-component("range") {
- sources = [
- "gfx_range_export.h",
- "range.cc",
- "range.h",
- "range_f.cc",
- "range_f.h",
- "range_mac.mm",
- "range_win.cc",
- ]
-
- if (is_ios) {
- set_sources_assignment_filter([])
- sources += [ "range_mac.mm" ]
- set_sources_assignment_filter(sources_assignment_filter)
- }
-
- configs += [
- # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
- "//build/config/compiler:no_size_t_to_int_warning",
- ]
-
- defines = [ "GFX_RANGE_IMPLEMENTATION" ]
-
- deps = [
- "//base",
- "//ui/gfx:gfx_export",
- ]
-}
diff --git a/ui/gfx/range/gfx_range_export.h b/ui/gfx/range/gfx_range_export.h
deleted file mode 100644
index 5634c49..0000000
--- a/ui/gfx/range/gfx_range_export.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2016 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 GFX_RANGE_EXPORT_H_
-#define GFX_RANGE_EXPORT_H_
-
-#if defined(COMPONENT_BUILD)
-#if defined(WIN32)
-
-#if defined(GFX_RANGE_IMPLEMENTATION)
-#define GFX_RANGE_EXPORT __declspec(dllexport)
-#else
-#define GFX_RANGE_EXPORT __declspec(dllimport)
-#endif // defined(GFX_RANGE_IMPLEMENTATION)
-
-#else // defined(WIN32)
-#if defined(GFX_RANGE_IMPLEMENTATION)
-#define GFX_RANGE_EXPORT __attribute__((visibility("default")))
-#else
-#define GFX_RANGE_EXPORT
-#endif
-#endif
-
-#else // defined(COMPONENT_BUILD)
-#define GFX_RANGE_EXPORT
-#endif
-
-#endif // GFX_RANGE_EXPORT_H_
diff --git a/ui/gfx/range/range.cc b/ui/gfx/range/range.cc
deleted file mode 100644
index fa837d0..0000000
--- a/ui/gfx/range/range.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "ui/gfx/range/range.h"
-
-#include <inttypes.h>
-
-#include <algorithm>
-
-#include "base/logging.h"
-#include "base/strings/stringprintf.h"
-
-namespace gfx {
-
-Range Range::Intersect(const Range& range) const {
- uint32_t min = std::max(GetMin(), range.GetMin());
- uint32_t max = std::min(GetMax(), range.GetMax());
-
- if (min >= max) // No intersection.
- return InvalidRange();
-
- return Range(min, max);
-}
-
-std::string Range::ToString() const {
- return base::StringPrintf("{%" PRIu32 ",%" PRIu32 "}", start(), end());
-}
-
-std::ostream& operator<<(std::ostream& os, const Range& range) {
- return os << range.ToString();
-}
-
-} // namespace gfx
diff --git a/ui/gfx/range/range.h b/ui/gfx/range/range.h
deleted file mode 100644
index e785eb6..0000000
--- a/ui/gfx/range/range.h
+++ /dev/null
@@ -1,139 +0,0 @@
-// Copyright (c) 2012 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 UI_GFX_RANGE_RANGE_H_
-#define UI_GFX_RANGE_RANGE_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <limits>
-#include <ostream>
-#include <string>
-
-#include "build/build_config.h"
-#include "ui/gfx/range/gfx_range_export.h"
-
-#if defined(OS_MACOSX)
-#if __OBJC__
-#import <Foundation/Foundation.h>
-#else
-typedef struct _NSRange NSRange;
-#endif
-#endif // defined(OS_MACOSX)
-
-#if defined(OS_WIN)
-#include <windows.h>
-#include <richedit.h>
-#endif
-
-namespace gfx {
-
-// A Range contains two integer values that represent a numeric range, like the
-// range of characters in a text selection. A range is made of a start and end
-// position; when they are the same, the Range is akin to a caret. Note that
-// |start_| can be greater than |end_| to respect the directionality of the
-// range.
-class GFX_RANGE_EXPORT Range {
- public:
- // Creates an empty range {0,0}.
- constexpr Range() : Range(0) {}
-
- // Initializes the range with a start and end.
- constexpr Range(uint32_t start, uint32_t end) : start_(start), end_(end) {}
-
- // Initializes the range with the same start and end positions.
- constexpr explicit Range(uint32_t position) : Range(position, position) {}
-
- // Platform constructors.
-#if defined(OS_MACOSX)
- explicit Range(const NSRange& range);
-#elif defined(OS_WIN)
- // The |total_length| paramater should be used if the CHARRANGE is set to
- // {0,-1} to indicate the whole range.
- Range(const CHARRANGE& range, LONG total_length = -1);
-#endif
-
- // Returns a range that is invalid, which is {UINT32_MAX,UINT32_MAX}.
- static constexpr Range InvalidRange() {
- return Range(std::numeric_limits<uint32_t>::max());
- }
-
- // Checks if the range is valid through comparison to InvalidRange().
- constexpr bool IsValid() const { return *this != InvalidRange(); }
-
- // Getters and setters.
- constexpr uint32_t start() const { return start_; }
- void set_start(uint32_t start) { start_ = start; }
-
- constexpr uint32_t end() const { return end_; }
- void set_end(uint32_t end) { end_ = end; }
-
- // Returns the absolute value of the length.
- constexpr uint32_t length() const { return GetMax() - GetMin(); }
-
- constexpr bool is_reversed() const { return start() > end(); }
- constexpr bool is_empty() const { return start() == end(); }
-
- // Returns the minimum and maximum values.
- constexpr uint32_t GetMin() const {
- return start() < end() ? start() : end();
- }
- constexpr uint32_t GetMax() const {
- return start() > end() ? start() : end();
- }
-
- constexpr bool operator==(const Range& other) const {
- return start() == other.start() && end() == other.end();
- }
- constexpr bool operator!=(const Range& other) const {
- return !(*this == other);
- }
- constexpr bool EqualsIgnoringDirection(const Range& other) const {
- return GetMin() == other.GetMin() && GetMax() == other.GetMax();
- }
-
- // Returns true if this range intersects the specified |range|.
- constexpr bool Intersects(const Range& range) const {
- return IsValid() && range.IsValid() &&
- !(range.GetMax() < GetMin() || range.GetMin() >= GetMax());
- }
-
- // Returns true if this range contains the specified |range|.
- constexpr bool Contains(const Range& range) const {
- return IsValid() && range.IsValid() && GetMin() <= range.GetMin() &&
- range.GetMax() <= GetMax();
- }
-
- // Computes the intersection of this range with the given |range|.
- // If they don't intersect, it returns an InvalidRange().
- // The returned range is always empty or forward (never reversed).
- Range Intersect(const Range& range) const;
-
-#if defined(OS_MACOSX)
- Range& operator=(const NSRange& range);
-
- // NSRange does not store the directionality of a range, so if this
- // is_reversed(), the range will get flipped when converted to an NSRange.
- NSRange ToNSRange() const;
-#elif defined(OS_WIN)
- CHARRANGE ToCHARRANGE() const;
-#endif
- // GTK+ has no concept of a range.
-
- std::string ToString() const;
-
- private:
- // Note: we use uint32_t instead of size_t because this struct is sent over
- // IPC which could span 32 & 64 bit processes. This is fine since text spans
- // shouldn't exceed UINT32_MAX even on 64 bit builds.
- uint32_t start_;
- uint32_t end_;
-};
-
-GFX_RANGE_EXPORT std::ostream& operator<<(std::ostream& os, const Range& range);
-
-} // namespace gfx
-
-#endif // UI_GFX_RANGE_RANGE_H_
diff --git a/ui/gfx/range/range_f.cc b/ui/gfx/range/range_f.cc
deleted file mode 100644
index b3bfc69..0000000
--- a/ui/gfx/range/range_f.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2015 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.
-
-#include "ui/gfx/range/range_f.h"
-
-#include <stddef.h>
-
-#include <algorithm>
-#include <cmath>
-
-#include "base/format_macros.h"
-#include "base/strings/stringprintf.h"
-
-namespace gfx {
-
-RangeF RangeF::Intersect(const RangeF& range) const {
- float min = std::max(GetMin(), range.GetMin());
- float max = std::min(GetMax(), range.GetMax());
-
- if (min >= max) // No intersection.
- return InvalidRange();
-
- return RangeF(min, max);
-}
-
-RangeF RangeF::Intersect(const Range& range) const {
- RangeF range_f(range.start(), range.end());
- return Intersect(range_f);
-}
-
-Range RangeF::Floor() const {
- uint32_t start = start_ > 0 ? static_cast<uint32_t>(std::floor(start_)) : 0;
- uint32_t end = end_ > 0 ? static_cast<uint32_t>(std::floor(end_)) : 0;
- return Range(start, end);
-}
-
-Range RangeF::Ceil() const {
- uint32_t start = start_ > 0 ? static_cast<uint32_t>(std::ceil(start_)) : 0;
- uint32_t end = end_ > 0 ? static_cast<uint32_t>(std::ceil(end_)) : 0;
- return Range(start, end);
-}
-
-Range RangeF::Round() const {
- uint32_t start = start_ > 0 ? static_cast<uint32_t>(std::round(start_)) : 0;
- uint32_t end = end_ > 0 ? static_cast<uint32_t>(std::round(end_)) : 0;
- return Range(start, end);
-}
-
-std::string RangeF::ToString() const {
- return base::StringPrintf("{%f,%f}", start(), end());
-}
-
-std::ostream& operator<<(std::ostream& os, const RangeF& range) {
- return os << range.ToString();
-}
-
-} // namespace gfx
diff --git a/ui/gfx/range/range_f.h b/ui/gfx/range/range_f.h
deleted file mode 100644
index 1d58ad4..0000000
--- a/ui/gfx/range/range_f.h
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright 2015 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 UI_GFX_RANGE_RANGE_F_H_
-#define UI_GFX_RANGE_RANGE_F_H_
-
-#include <limits>
-#include <ostream>
-#include <string>
-
-#include "ui/gfx/range/gfx_range_export.h"
-#include "ui/gfx/range/range.h"
-
-namespace gfx {
-
-// A float version of Range. RangeF is made of a start and end position; when
-// they are the same, the range is empty. Note that |start_| can be greater
-// than |end_| to respect the directionality of the range.
-class GFX_RANGE_EXPORT RangeF {
- public:
- // Creates an empty range {0,0}.
- constexpr RangeF() : RangeF(0.f) {}
-
- // Initializes the range with a start and end.
- constexpr RangeF(float start, float end) : start_(start), end_(end) {}
-
- // Initializes the range with the same start and end positions.
- constexpr explicit RangeF(float position) : RangeF(position, position) {}
-
- // Returns a range that is invalid, which is {float_max,float_max}.
- static constexpr RangeF InvalidRange() {
- return RangeF(std::numeric_limits<float>::max());
- }
-
- // Checks if the range is valid through comparison to InvalidRange().
- constexpr bool IsValid() const { return *this != InvalidRange(); }
-
- // Getters and setters.
- constexpr float start() const { return start_; }
- void set_start(float start) { start_ = start; }
-
- constexpr float end() const { return end_; }
- void set_end(float end) { end_ = end; }
-
- // Returns the absolute value of the length.
- constexpr float length() const { return GetMax() - GetMin(); }
-
- constexpr bool is_reversed() const { return start() > end(); }
- constexpr bool is_empty() const { return start() == end(); }
-
- // Returns the minimum and maximum values.
- constexpr float GetMin() const { return start() < end() ? start() : end(); }
- constexpr float GetMax() const { return start() > end() ? start() : end(); }
-
- constexpr bool operator==(const RangeF& other) const {
- return start() == other.start() && end() == other.end();
- }
- constexpr bool operator!=(const RangeF& other) const {
- return !(*this == other);
- }
- constexpr bool EqualsIgnoringDirection(const RangeF& other) const {
- return GetMin() == other.GetMin() && GetMax() == other.GetMax();
- }
-
- // Returns true if this range intersects the specified |range|.
- constexpr bool Intersects(const RangeF& range) const {
- return IsValid() && range.IsValid() &&
- !(range.GetMax() < GetMin() || range.GetMin() >= GetMax());
- }
-
- // Returns true if this range contains the specified |range|.
- constexpr bool Contains(const RangeF& range) const {
- return IsValid() && range.IsValid() && GetMin() <= range.GetMin() &&
- range.GetMax() <= GetMax();
- }
-
- // Computes the intersection of this range with the given |range|.
- // If they don't intersect, it returns an InvalidRange().
- // The returned range is always empty or forward (never reversed).
- RangeF Intersect(const RangeF& range) const;
- RangeF Intersect(const Range& range) const;
-
- // Floor/Ceil/Round the start and end values of the given RangeF.
- Range Floor() const;
- Range Ceil() const;
- Range Round() const;
-
- std::string ToString() const;
-
- private:
- float start_;
- float end_;
-};
-
-GFX_RANGE_EXPORT std::ostream& operator<<(std::ostream& os,
- const RangeF& range);
-
-} // namespace gfx
-
-#endif // UI_GFX_RANGE_RANGE_F_H_
diff --git a/ui/gfx/range/range_mac.mm b/ui/gfx/range/range_mac.mm
deleted file mode 100644
index ad7ea6a..0000000
--- a/ui/gfx/range/range_mac.mm
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "ui/gfx/range/range.h"
-
-#include <stddef.h>
-
-#include <limits>
-
-#include "base/logging.h"
-
-namespace gfx {
-
-Range::Range(const NSRange& range) {
- *this = range;
-}
-
-Range& Range::operator=(const NSRange& range) {
- if (range.location == NSNotFound) {
- DCHECK_EQ(0U, range.length);
- *this = InvalidRange();
- } else {
- set_start(range.location);
- // Don't overflow |end_|.
- DCHECK_LE(range.length, std::numeric_limits<size_t>::max() - start());
- set_end(start() + range.length);
- }
- return *this;
-}
-
-NSRange Range::ToNSRange() const {
- if (!IsValid())
- return NSMakeRange(NSNotFound, 0);
- return NSMakeRange(GetMin(), length());
-}
-
-} // namespace gfx
diff --git a/ui/gfx/range/range_mac_unittest.mm b/ui/gfx/range/range_mac_unittest.mm
deleted file mode 100644
index 85323f2..0000000
--- a/ui/gfx/range/range_mac_unittest.mm
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/range/range.h"
-
-TEST(RangeTest, FromNSRange) {
- NSRange nsr = NSMakeRange(10, 3);
- gfx::Range r(nsr);
- EXPECT_EQ(nsr.location, r.start());
- EXPECT_EQ(13U, r.end());
- EXPECT_EQ(nsr.length, r.length());
- EXPECT_FALSE(r.is_reversed());
- EXPECT_TRUE(r.IsValid());
-}
-
-TEST(RangeTest, ToNSRange) {
- gfx::Range r(10, 12);
- NSRange nsr = r.ToNSRange();
- EXPECT_EQ(10U, nsr.location);
- EXPECT_EQ(2U, nsr.length);
-}
-
-TEST(RangeTest, ReversedToNSRange) {
- gfx::Range r(20, 10);
- NSRange nsr = r.ToNSRange();
- EXPECT_EQ(10U, nsr.location);
- EXPECT_EQ(10U, nsr.length);
-}
-
-TEST(RangeTest, FromNSRangeInvalid) {
- NSRange nsr = NSMakeRange(NSNotFound, 0);
- gfx::Range r(nsr);
- EXPECT_FALSE(r.IsValid());
-}
-
-TEST(RangeTest, ToNSRangeInvalid) {
- gfx::Range r(gfx::Range::InvalidRange());
- NSRange nsr = r.ToNSRange();
- EXPECT_EQ(static_cast<NSUInteger>(NSNotFound), nsr.location);
- EXPECT_EQ(0U, nsr.length);
-}
diff --git a/ui/gfx/range/range_unittest.cc b/ui/gfx/range/range_unittest.cc
deleted file mode 100644
index 4ae7a67..0000000
--- a/ui/gfx/range/range_unittest.cc
+++ /dev/null
@@ -1,266 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include <sstream>
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/range/range.h"
-#include "ui/gfx/range/range_f.h"
-
-namespace {
-
-template <typename T>
-class RangeTest : public testing::Test {
-};
-
-typedef testing::Types<gfx::Range, gfx::RangeF> RangeTypes;
-TYPED_TEST_CASE(RangeTest, RangeTypes);
-
-template <typename T>
-void TestContainsAndIntersects(const T& r1,
- const T& r2,
- const T& r3) {
- EXPECT_TRUE(r1.Intersects(r1));
- EXPECT_TRUE(r1.Contains(r1));
- EXPECT_EQ(T(10, 12), r1.Intersect(r1));
-
- EXPECT_FALSE(r1.Intersects(r2));
- EXPECT_FALSE(r1.Contains(r2));
- EXPECT_TRUE(r1.Intersect(r2).is_empty());
- EXPECT_FALSE(r2.Intersects(r1));
- EXPECT_FALSE(r2.Contains(r1));
- EXPECT_TRUE(r2.Intersect(r1).is_empty());
-
- EXPECT_TRUE(r1.Intersects(r3));
- EXPECT_TRUE(r3.Intersects(r1));
- EXPECT_TRUE(r3.Contains(r1));
- EXPECT_FALSE(r1.Contains(r3));
- EXPECT_EQ(T(10, 12), r1.Intersect(r3));
- EXPECT_EQ(T(10, 12), r3.Intersect(r1));
-
- EXPECT_TRUE(r2.Intersects(r3));
- EXPECT_TRUE(r3.Intersects(r2));
- EXPECT_FALSE(r3.Contains(r2));
- EXPECT_FALSE(r2.Contains(r3));
- EXPECT_EQ(T(5, 8), r2.Intersect(r3));
- EXPECT_EQ(T(5, 8), r3.Intersect(r2));
-}
-
-} // namespace
-
-TYPED_TEST(RangeTest, EmptyInit) {
- TypeParam r;
- EXPECT_EQ(0U, r.start());
- EXPECT_EQ(0U, r.end());
- EXPECT_EQ(0U, r.length());
- EXPECT_FALSE(r.is_reversed());
- EXPECT_TRUE(r.is_empty());
- EXPECT_TRUE(r.IsValid());
- EXPECT_EQ(0U, r.GetMin());
- EXPECT_EQ(0U, r.GetMax());
-}
-
-TYPED_TEST(RangeTest, StartEndInit) {
- TypeParam r(10, 15);
- EXPECT_EQ(10U, r.start());
- EXPECT_EQ(15U, r.end());
- EXPECT_EQ(5U, r.length());
- EXPECT_FALSE(r.is_reversed());
- EXPECT_FALSE(r.is_empty());
- EXPECT_TRUE(r.IsValid());
- EXPECT_EQ(10U, r.GetMin());
- EXPECT_EQ(15U, r.GetMax());
-}
-
-TYPED_TEST(RangeTest, StartEndReversedInit) {
- TypeParam r(10, 5);
- EXPECT_EQ(10U, r.start());
- EXPECT_EQ(5U, r.end());
- EXPECT_EQ(5U, r.length());
- EXPECT_TRUE(r.is_reversed());
- EXPECT_FALSE(r.is_empty());
- EXPECT_TRUE(r.IsValid());
- EXPECT_EQ(5U, r.GetMin());
- EXPECT_EQ(10U, r.GetMax());
-}
-
-TYPED_TEST(RangeTest, PositionInit) {
- TypeParam r(12);
- EXPECT_EQ(12U, r.start());
- EXPECT_EQ(12U, r.end());
- EXPECT_EQ(0U, r.length());
- EXPECT_FALSE(r.is_reversed());
- EXPECT_TRUE(r.is_empty());
- EXPECT_TRUE(r.IsValid());
- EXPECT_EQ(12U, r.GetMin());
- EXPECT_EQ(12U, r.GetMax());
-}
-
-TYPED_TEST(RangeTest, InvalidRange) {
- TypeParam r(TypeParam::InvalidRange());
- EXPECT_EQ(0U, r.length());
- EXPECT_EQ(r.start(), r.end());
- EXPECT_EQ(r.GetMax(), r.GetMin());
- EXPECT_FALSE(r.is_reversed());
- EXPECT_TRUE(r.is_empty());
- EXPECT_FALSE(r.IsValid());
- EXPECT_EQ(r, TypeParam::InvalidRange());
- EXPECT_TRUE(r.EqualsIgnoringDirection(TypeParam::InvalidRange()));
-}
-
-TYPED_TEST(RangeTest, Equality) {
- TypeParam r1(10, 4);
- TypeParam r2(10, 4);
- TypeParam r3(10, 2);
- EXPECT_EQ(r1, r2);
- EXPECT_NE(r1, r3);
- EXPECT_NE(r2, r3);
-
- TypeParam r4(11, 4);
- EXPECT_NE(r1, r4);
- EXPECT_NE(r2, r4);
- EXPECT_NE(r3, r4);
-
- TypeParam r5(12, 5);
- EXPECT_NE(r1, r5);
- EXPECT_NE(r2, r5);
- EXPECT_NE(r3, r5);
-}
-
-TYPED_TEST(RangeTest, EqualsIgnoringDirection) {
- TypeParam r1(10, 5);
- TypeParam r2(5, 10);
- EXPECT_TRUE(r1.EqualsIgnoringDirection(r2));
-}
-
-TYPED_TEST(RangeTest, SetStart) {
- TypeParam r(10, 20);
- EXPECT_EQ(10U, r.start());
- EXPECT_EQ(10U, r.length());
-
- r.set_start(42);
- EXPECT_EQ(42U, r.start());
- EXPECT_EQ(20U, r.end());
- EXPECT_EQ(22U, r.length());
- EXPECT_TRUE(r.is_reversed());
-}
-
-TYPED_TEST(RangeTest, SetEnd) {
- TypeParam r(10, 13);
- EXPECT_EQ(10U, r.start());
- EXPECT_EQ(3U, r.length());
-
- r.set_end(20);
- EXPECT_EQ(10U, r.start());
- EXPECT_EQ(20U, r.end());
- EXPECT_EQ(10U, r.length());
-}
-
-TYPED_TEST(RangeTest, SetStartAndEnd) {
- TypeParam r;
- r.set_end(5);
- r.set_start(1);
- EXPECT_EQ(1U, r.start());
- EXPECT_EQ(5U, r.end());
- EXPECT_EQ(4U, r.length());
- EXPECT_EQ(1U, r.GetMin());
- EXPECT_EQ(5U, r.GetMax());
-}
-
-TYPED_TEST(RangeTest, ReversedRange) {
- TypeParam r(10, 5);
- EXPECT_EQ(10U, r.start());
- EXPECT_EQ(5U, r.end());
- EXPECT_EQ(5U, r.length());
- EXPECT_TRUE(r.is_reversed());
- EXPECT_TRUE(r.IsValid());
- EXPECT_EQ(5U, r.GetMin());
- EXPECT_EQ(10U, r.GetMax());
-}
-
-TYPED_TEST(RangeTest, SetReversedRange) {
- TypeParam r(10, 20);
- r.set_start(25);
- EXPECT_EQ(25U, r.start());
- EXPECT_EQ(20U, r.end());
- EXPECT_EQ(5U, r.length());
- EXPECT_TRUE(r.is_reversed());
- EXPECT_TRUE(r.IsValid());
-
- r.set_end(21);
- EXPECT_EQ(25U, r.start());
- EXPECT_EQ(21U, r.end());
- EXPECT_EQ(4U, r.length());
- EXPECT_TRUE(r.IsValid());
- EXPECT_EQ(21U, r.GetMin());
- EXPECT_EQ(25U, r.GetMax());
-}
-
-TYPED_TEST(RangeTest, ContainAndIntersect) {
- {
- SCOPED_TRACE("contain and intersect");
- TypeParam r1(10, 12);
- TypeParam r2(1, 8);
- TypeParam r3(5, 12);
- TestContainsAndIntersects(r1, r2, r3);
- }
- {
- SCOPED_TRACE("contain and intersect: reversed");
- TypeParam r1(12, 10);
- TypeParam r2(8, 1);
- TypeParam r3(12, 5);
- TestContainsAndIntersects(r1, r2, r3);
- }
- // Invalid rect tests
- TypeParam r1(10, 12);
- TypeParam r2(8, 1);
- TypeParam invalid = r1.Intersect(r2);
- EXPECT_FALSE(invalid.IsValid());
- EXPECT_FALSE(invalid.Contains(invalid));
- EXPECT_FALSE(invalid.Contains(r1));
- EXPECT_FALSE(invalid.Intersects(invalid));
- EXPECT_FALSE(invalid.Intersects(r1));
- EXPECT_FALSE(r1.Contains(invalid));
- EXPECT_FALSE(r1.Intersects(invalid));
-}
-
-TEST(RangeTest, RangeFConverterTest) {
- gfx::RangeF range_f(1.2f, 3.9f);
- gfx::Range range = range_f.Floor();
- EXPECT_EQ(1U, range.start());
- EXPECT_EQ(3U, range.end());
-
- range = range_f.Ceil();
- EXPECT_EQ(2U, range.start());
- EXPECT_EQ(4U, range.end());
-
- range = range_f.Round();
- EXPECT_EQ(1U, range.start());
- EXPECT_EQ(4U, range.end());
-
- // Test for negative values.
- range_f.set_start(-1.2f);
- range_f.set_end(-3.8f);
- range = range_f.Floor();
- EXPECT_EQ(0U, range.start());
- EXPECT_EQ(0U, range.end());
-
- range = range_f.Ceil();
- EXPECT_EQ(0U, range.start());
- EXPECT_EQ(0U, range.end());
-
- range = range_f.Round();
- EXPECT_EQ(0U, range.start());
- EXPECT_EQ(0U, range.end());
-}
-
-TEST(RangeTest, ToString) {
- gfx::Range range(4, 7);
- EXPECT_EQ("{4,7}", range.ToString());
-
- range = gfx::Range::InvalidRange();
- std::ostringstream expected;
- expected << "{" << range.start() << "," << range.end() << "}";
- EXPECT_EQ(expected.str(), range.ToString());
-}
diff --git a/ui/gfx/range/range_win.cc b/ui/gfx/range/range_win.cc
deleted file mode 100644
index 1180e1b..0000000
--- a/ui/gfx/range/range_win.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "ui/gfx/range/range.h"
-
-#include <limits>
-
-#include "base/logging.h"
-
-namespace gfx {
-
-Range::Range(const CHARRANGE& range, LONG total_length) {
- // Check if this is an invalid range.
- if (range.cpMin == -1 && range.cpMax == -1) {
- *this = InvalidRange();
- } else {
- DCHECK_GE(range.cpMin, 0);
- set_start(range.cpMin);
- // {0,-1} is the "whole range" but that doesn't mean much out of context,
- // so use the |total_length| parameter.
- if (range.cpMax == -1) {
- DCHECK_EQ(0, range.cpMin);
- DCHECK_NE(-1, total_length);
- set_end(total_length);
- } else {
- set_end(range.cpMax);
- }
- }
-}
-
-CHARRANGE Range::ToCHARRANGE() const {
- CHARRANGE r = { -1, -1 };
- if (!IsValid())
- return r;
-
- const LONG kLONGMax = std::numeric_limits<LONG>::max();
- CHECK_LE(static_cast<LONG>(start()), kLONGMax);
- CHECK_LE(static_cast<LONG>(end()), kLONGMax);
- r.cpMin = static_cast<LONG>(start());
- r.cpMax = static_cast<LONG>(end());
- return r;
-}
-
-} // namespace gfx
diff --git a/ui/gfx/range/range_win_unittest.cc b/ui/gfx/range/range_win_unittest.cc
deleted file mode 100644
index d15375b..0000000
--- a/ui/gfx/range/range_win_unittest.cc
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/range/range.h"
-
-TEST(RangeTest, FromCHARRANGE) {
- CHARRANGE cr = { 10, 32 };
- gfx::Range r(cr, 50);
- EXPECT_EQ(10U, r.start());
- EXPECT_EQ(32U, r.end());
- EXPECT_EQ(22U, r.length());
- EXPECT_FALSE(r.is_reversed());
- EXPECT_TRUE(r.IsValid());
-}
-
-TEST(RangeTest, FromReversedCHARRANGE) {
- CHARRANGE cr = { 20, 10 };
- gfx::Range r(cr, 40);
- EXPECT_EQ(20U, r.start());
- EXPECT_EQ(10U, r.end());
- EXPECT_EQ(10U, r.length());
- EXPECT_TRUE(r.is_reversed());
- EXPECT_TRUE(r.IsValid());
-}
-
-TEST(RangeTest, FromCHARRANGETotal) {
- CHARRANGE cr = { 0, -1 };
- gfx::Range r(cr, 20);
- EXPECT_EQ(0U, r.start());
- EXPECT_EQ(20U, r.end());
- EXPECT_EQ(20U, r.length());
- EXPECT_FALSE(r.is_reversed());
- EXPECT_TRUE(r.IsValid());
-}
-
-TEST(RangeTest, ToCHARRANGE) {
- gfx::Range r(10, 30);
- CHARRANGE cr = r.ToCHARRANGE();
- EXPECT_EQ(10, cr.cpMin);
- EXPECT_EQ(30, cr.cpMax);
-}
-
-TEST(RangeTest, ReversedToCHARRANGE) {
- gfx::Range r(20, 10);
- CHARRANGE cr = r.ToCHARRANGE();
- EXPECT_EQ(20, cr.cpMin);
- EXPECT_EQ(10, cr.cpMax);
-}
-
-TEST(RangeTest, FromCHARRANGEInvalid) {
- CHARRANGE cr = { -1, -1 };
- gfx::Range r(cr, 30);
- EXPECT_FALSE(r.IsValid());
-}
-
-TEST(RangeTest, ToCHARRANGEInvalid) {
- gfx::Range r(gfx::Range::InvalidRange());
- CHARRANGE cr = r.ToCHARRANGE();
- EXPECT_EQ(-1, cr.cpMin);
- EXPECT_EQ(-1, cr.cpMax);
-}