Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / gfx / range / range_win.cc
blob1180e1bf7a8571702b8dfb8320ac8f0236253b07
1 // Copyright (c) 2011 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.
5 #include "ui/gfx/range/range.h"
7 #include <limits>
9 #include "base/logging.h"
11 namespace gfx {
13 Range::Range(const CHARRANGE& range, LONG total_length) {
14 // Check if this is an invalid range.
15 if (range.cpMin == -1 && range.cpMax == -1) {
16 *this = InvalidRange();
17 } else {
18 DCHECK_GE(range.cpMin, 0);
19 set_start(range.cpMin);
20 // {0,-1} is the "whole range" but that doesn't mean much out of context,
21 // so use the |total_length| parameter.
22 if (range.cpMax == -1) {
23 DCHECK_EQ(0, range.cpMin);
24 DCHECK_NE(-1, total_length);
25 set_end(total_length);
26 } else {
27 set_end(range.cpMax);
32 CHARRANGE Range::ToCHARRANGE() const {
33 CHARRANGE r = { -1, -1 };
34 if (!IsValid())
35 return r;
37 const LONG kLONGMax = std::numeric_limits<LONG>::max();
38 CHECK_LE(static_cast<LONG>(start()), kLONGMax);
39 CHECK_LE(static_cast<LONG>(end()), kLONGMax);
40 r.cpMin = static_cast<LONG>(start());
41 r.cpMax = static_cast<LONG>(end());
42 return r;
45 } // namespace gfx