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

Side by Side Diff: ui/views/controls/scroll_view_unittest.cc

Issue 273223002: views: Make view::Views::GetPreferredSize() const. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More compile fix for ToT Created 6 years, 7 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
« no previous file with comments | « ui/views/controls/scroll_view.cc ('k') | ui/views/controls/scrollbar/base_scroll_bar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/views/controls/scroll_view.h" 5 #include "ui/views/controls/scroll_view.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" 8 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
9 #include "ui/views/test/test_views.h" 9 #include "ui/views/test/test_views.h"
10 10
11 namespace views { 11 namespace views {
12 12
13 namespace { 13 namespace {
14 14
15 const int kWidth = 100; 15 const int kWidth = 100;
16 const int kMinHeight = 50; 16 const int kMinHeight = 50;
17 const int kMaxHeight = 100; 17 const int kMaxHeight = 100;
18 18
19 // View implementation that allows setting the preferred size. 19 // View implementation that allows setting the preferred size.
20 class CustomView : public View { 20 class CustomView : public View {
21 public: 21 public:
22 CustomView() {} 22 CustomView() {}
23 23
24 void SetPreferredSize(const gfx::Size& size) { 24 void SetPreferredSize(const gfx::Size& size) {
25 preferred_size_ = size; 25 preferred_size_ = size;
26 PreferredSizeChanged(); 26 PreferredSizeChanged();
27 } 27 }
28 28
29 virtual gfx::Size GetPreferredSize() OVERRIDE { return preferred_size_; } 29 virtual gfx::Size GetPreferredSize() const OVERRIDE {
30 return preferred_size_;
31 }
30 32
31 virtual void Layout() OVERRIDE { 33 virtual void Layout() OVERRIDE {
32 gfx::Size pref = GetPreferredSize(); 34 gfx::Size pref = GetPreferredSize();
33 int width = pref.width(); 35 int width = pref.width();
34 int height = pref.height(); 36 int height = pref.height();
35 if (parent()) { 37 if (parent()) {
36 width = std::max(parent()->width(), width); 38 width = std::max(parent()->width(), width);
37 height = std::max(parent()->height(), height); 39 height = std::max(parent()->height(), height);
38 } 40 }
39 SetBounds(x(), y(), width, height); 41 SetBounds(x(), y(), width, height);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 scroll_view.Layout(); 328 scroll_view.Layout();
327 329
328 int scroll_bar_width = scroll_view.GetScrollBarWidth(); 330 int scroll_bar_width = scroll_view.GetScrollBarWidth();
329 int expected_width = kWidth - scroll_bar_width; 331 int expected_width = kWidth - scroll_bar_width;
330 EXPECT_EQ(scroll_view.contents()->size().width(), expected_width); 332 EXPECT_EQ(scroll_view.contents()->size().width(), expected_width);
331 EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width); 333 EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width);
332 EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size()); 334 EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size());
333 } 335 }
334 336
335 } // namespace views 337 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scroll_view.cc ('k') | ui/views/controls/scrollbar/base_scroll_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698