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

Side by Side Diff: chrome/views/view.cc

Issue 7344: Convert GetPreferredSize from:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 months 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/views/view.h" 5 #include "chrome/views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #ifndef NDEBUG 9 #ifndef NDEBUG
10 #include <iostream> 10 #include <iostream>
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (size_changed || position_changed) 162 if (size_changed || position_changed)
163 root->ViewBoundsChanged(this, size_changed, position_changed); 163 root->ViewBoundsChanged(this, size_changed, position_changed);
164 } 164 }
165 } 165 }
166 166
167 void View::SetBounds(int x, int y, int width, int height) { 167 void View::SetBounds(int x, int y, int width, int height) {
168 CRect tmp(x, y, x + width, y + height); 168 CRect tmp(x, y, x + width, y + height);
169 SetBounds(tmp); 169 SetBounds(tmp);
170 } 170 }
171 171
172 void View::SetBounds(const gfx::Point& origin, const gfx::Size& size) {
173 SetBounds(origin.x(), origin.y(), size.width(), size.height());
174 }
175
172 void View::GetLocalBounds(CRect* out, bool include_border) const { 176 void View::GetLocalBounds(CRect* out, bool include_border) const {
173 if (include_border || border_ == NULL) { 177 if (include_border || border_ == NULL) {
174 out->left = 0; 178 out->left = 0;
175 out->top = 0; 179 out->top = 0;
176 out->right = width(); 180 out->right = width();
177 out->bottom = height(); 181 out->bottom = height();
178 } else { 182 } else {
179 gfx::Insets insets; 183 gfx::Insets insets;
180 border_->GetInsets(&insets); 184 border_->GetInsets(&insets);
181 out->left = insets.left(); 185 out->left = insets.left();
182 out->top = insets.top(); 186 out->top = insets.top();
183 out->right = width() - insets.left(); 187 out->right = width() - insets.left();
184 out->bottom = height() - insets.top(); 188 out->bottom = height() - insets.top();
185 } 189 }
186 } 190 }
187 191
188 void View::GetSize(CSize* sz) const { 192 void View::GetSize(CSize* sz) const {
189 sz->cx = width(); 193 sz->cx = width();
190 sz->cy = height(); 194 sz->cy = height();
191 } 195 }
192 196
193 void View::GetPosition(CPoint* p) const { 197 void View::GetPosition(CPoint* p) const {
194 p->x = GetX(APPLY_MIRRORING_TRANSFORMATION); 198 p->x = GetX(APPLY_MIRRORING_TRANSFORMATION);
195 p->y = y(); 199 p->y = y();
196 } 200 }
197 201
198 void View::GetPreferredSize(CSize* out) { 202 gfx::Size View::GetPreferredSize() {
199 if (layout_manager_.get()) { 203 if (layout_manager_.get())
200 layout_manager_->GetPreferredSize(this, out); 204 return layout_manager_->GetPreferredSize(this);
201 } else { 205 return gfx::Size();
202 out->cx = out->cy = 0;
203 }
204 } 206 }
205 207
206 void View::SizeToPreferredSize() { 208 void View::SizeToPreferredSize() {
207 CSize size; 209 gfx::Size prefsize = GetPreferredSize();
208 GetPreferredSize(&size); 210 if ((prefsize.width() != width()) || (prefsize.height() != height()))
209 if ((size.cx != width()) || (size.cy != height())) 211 SetBounds(x(), y(), prefsize.width(), prefsize.height());
210 SetBounds(x(), y(), size.cx, size.cy);
211 } 212 }
212 213
213 void View::GetMinimumSize(CSize* out) { 214 gfx::Size View::GetMinimumSize() {
214 GetPreferredSize(out); 215 return GetPreferredSize();
215 } 216 }
216 217
217 int View::GetHeightForWidth(int w) { 218 int View::GetHeightForWidth(int w) {
218 if (layout_manager_.get()) 219 if (layout_manager_.get())
219 return layout_manager_->GetPreferredHeightForWidth(this, w); 220 return layout_manager_->GetPreferredHeightForWidth(this, w);
220 221
221 CSize size; 222 return GetPreferredSize().height();
222 GetPreferredSize(&size);
223 return size.cy;
224 } 223 }
225 224
226 void View::DidChangeBounds(const CRect& previous, const CRect& current) { 225 void View::DidChangeBounds(const CRect& previous, const CRect& current) {
227 } 226 }
228 227
229 void View::ScrollRectToVisible(int x, int y, int width, int height) { 228 void View::ScrollRectToVisible(int x, int y, int width, int height) {
230 View* parent = GetParent(); 229 View* parent = GetParent();
231 230
232 // We must take RTL UI mirroring into account when adjusting the position of 231 // We must take RTL UI mirroring into account when adjusting the position of
233 // the region. 232 // the region.
(...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 } 1683 }
1685 1684
1686 void View::DragInfo::PossibleDrag(int x, int y) { 1685 void View::DragInfo::PossibleDrag(int x, int y) {
1687 possible_drag = true; 1686 possible_drag = true;
1688 start_x = x; 1687 start_x = x;
1689 start_y = y; 1688 start_y = y;
1690 } 1689 }
1691 1690
1692 } // namespace 1691 } // namespace
1693 1692
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698