Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: ui/gfx/rect_base_impl.h

Issue 11293194: ui: Prefer +/- operators to apply offsets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gfx:: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/rect_base.h" 5 #include "ui/gfx/rect_base.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 9
10 // This file provides the implementation for RectBaese template and 10 // This file provides the implementation for RectBaese template and
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 template<typename Class, 97 template<typename Class,
98 typename PointClass, 98 typename PointClass,
99 typename SizeClass, 99 typename SizeClass,
100 typename InsetsClass, 100 typename InsetsClass,
101 typename VectorClass, 101 typename VectorClass,
102 typename Type> 102 typename Type>
103 void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: 103 void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>::
104 Inset(Type left, Type top, Type right, Type bottom) { 104 Inset(Type left, Type top, Type right, Type bottom) {
105 Offset(left, top); 105 origin_ += VectorClass(left, top);
106 set_width(std::max(width() - left - right, static_cast<Type>(0))); 106 set_width(std::max(width() - left - right, static_cast<Type>(0)));
107 set_height(std::max(height() - top - bottom, static_cast<Type>(0))); 107 set_height(std::max(height() - top - bottom, static_cast<Type>(0)));
108 } 108 }
109 109
110 template<typename Class, 110 template<typename Class,
111 typename PointClass, 111 typename PointClass,
112 typename SizeClass, 112 typename SizeClass,
113 typename InsetsClass, 113 typename InsetsClass,
114 typename VectorClass, 114 typename VectorClass,
115 typename Type> 115 typename Type>
116 void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: 116 void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>::
117 Offset(Type horizontal, Type vertical) { 117 Offset(Type horizontal, Type vertical) {
118 origin_.Offset(horizontal, vertical); 118 origin_ += VectorClass(horizontal, vertical);
119 } 119 }
120 120
121 template<typename Class, 121 template<typename Class,
122 typename PointClass,
123 typename SizeClass,
124 typename InsetsClass,
125 typename VectorClass,
126 typename Type>
127 void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>::
128 operator+=(const VectorClass& offset) {
129 origin_ += offset;
130 }
131
132 template<typename Class,
133 typename PointClass,
134 typename SizeClass,
135 typename InsetsClass,
136 typename VectorClass,
137 typename Type>
138 void RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>::
139 operator-=(const VectorClass& offset) {
140 origin_ -= offset;
141 }
142
143 template<typename Class,
122 typename PointClass, 144 typename PointClass,
123 typename SizeClass, 145 typename SizeClass,
124 typename InsetsClass, 146 typename InsetsClass,
125 typename VectorClass, 147 typename VectorClass,
126 typename Type> 148 typename Type>
127 bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: 149 bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>::
128 operator<(const Class& other) const { 150 operator<(const Class& other) const {
129 if (origin_ == other.origin_) { 151 if (origin_ == other.origin_) {
130 if (width() == other.width()) { 152 if (width() == other.width()) {
131 return height() < other.height(); 153 return height() < other.height();
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 typename Type> 349 typename Type>
328 bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>:: 350 bool RectBase<Class, PointClass, SizeClass, InsetsClass, VectorClass, Type>::
329 SharesEdgeWith(const Class& rect) const { 351 SharesEdgeWith(const Class& rect) const {
330 return (y() == rect.y() && height() == rect.height() && 352 return (y() == rect.y() && height() == rect.height() &&
331 (x() == rect.right() || right() == rect.x())) || 353 (x() == rect.right() || right() == rect.x())) ||
332 (x() == rect.x() && width() == rect.width() && 354 (x() == rect.x() && width() == rect.width() &&
333 (y() == rect.bottom() || bottom() == rect.y())); 355 (y() == rect.bottom() || bottom() == rect.y()));
334 } 356 }
335 357
336 } // namespace gfx 358 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698