range_mac.mm 751 B

123456789101112131415161718192021222324252627282930313233343536
  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.
  4. #include "ui/gfx/range/range.h"
  5. #include <stddef.h>
  6. #include <limits>
  7. #include "base/check_op.h"
  8. namespace gfx {
  9. Range::Range(const NSRange& range) {
  10. *this = range;
  11. }
  12. Range& Range::operator=(const NSRange& range) {
  13. if (range.location == NSNotFound) {
  14. DCHECK_EQ(0U, range.length);
  15. *this = InvalidRange();
  16. } else {
  17. set_start(range.location);
  18. set_end(start() + range.length);
  19. }
  20. return *this;
  21. }
  22. NSRange Range::ToNSRange() const {
  23. if (!IsValid())
  24. return NSMakeRange(NSNotFound, 0);
  25. return NSMakeRange(GetMin(), length());
  26. }
  27. } // namespace gfx