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

Side by Side Diff: ui/views/examples/multiline_example.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/examples/label_example.cc ('k') | ui/views/examples/scroll_view_example.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/examples/multiline_example.h" 5 #include "ui/views/examples/multiline_example.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/gfx/render_text.h" 9 #include "ui/gfx/render_text.h"
10 #include "ui/views/background.h" 10 #include "ui/views/background.h"
(...skipping 17 matching lines...) Expand all
28 render_text_->SetColor(SK_ColorBLACK); 28 render_text_->SetColor(SK_ColorBLACK);
29 render_text_->SetMultiline(true); 29 render_text_->SetMultiline(true);
30 SetBorder(Border::CreateSolidBorder(2, SK_ColorGRAY)); 30 SetBorder(Border::CreateSolidBorder(2, SK_ColorGRAY));
31 } 31 }
32 32
33 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 33 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
34 View::OnPaint(canvas); 34 View::OnPaint(canvas);
35 render_text_->Draw(canvas); 35 render_text_->Draw(canvas);
36 } 36 }
37 37
38 virtual gfx::Size GetPreferredSize() OVERRIDE { 38 virtual gfx::Size GetPreferredSize() const OVERRIDE {
39 // Turn off multiline mode to get the single-line text size, which is the 39 // Turn off multiline mode to get the single-line text size, which is the
40 // preferred size for this view. 40 // preferred size for this view.
41 render_text_->SetMultiline(false); 41 render_text_->SetMultiline(false);
42 gfx::Size size(render_text_->GetContentWidth(), 42 gfx::Size size(render_text_->GetContentWidth(),
43 render_text_->GetStringSize().height()); 43 render_text_->GetStringSize().height());
44 size.Enlarge(GetInsets().width(), GetInsets().height()); 44 size.Enlarge(GetInsets().width(), GetInsets().height());
45 render_text_->SetMultiline(true); 45 render_text_->SetMultiline(true);
46 return size; 46 return size;
47 } 47 }
48 48
49 virtual int GetHeightForWidth(int w) OVERRIDE { 49 virtual int GetHeightForWidth(int w) const OVERRIDE {
50 // TODO(ckocagil): Why does this happen? 50 // TODO(ckocagil): Why does this happen?
51 if (w == 0) 51 if (w == 0)
52 return View::GetHeightForWidth(w); 52 return View::GetHeightForWidth(w);
53 const gfx::Rect old_rect = render_text_->display_rect(); 53 const gfx::Rect old_rect = render_text_->display_rect();
54 gfx::Rect rect = old_rect; 54 gfx::Rect rect = old_rect;
55 rect.set_width(w - GetInsets().width()); 55 rect.set_width(w - GetInsets().width());
56 render_text_->SetDisplayRect(rect); 56 render_text_->SetDisplayRect(rect);
57 int height = render_text_->GetStringSize().height() + GetInsets().height(); 57 int height = render_text_->GetStringSize().height() + GetInsets().height();
58 render_text_->SetDisplayRect(old_rect); 58 render_text_->SetDisplayRect(old_rect);
59 return height; 59 return height;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void MultilineExample::ButtonPressed(Button* sender, const ui::Event& event) { 158 void MultilineExample::ButtonPressed(Button* sender, const ui::Event& event) {
159 DCHECK_EQ(sender, label_checkbox_); 159 DCHECK_EQ(sender, label_checkbox_);
160 label_->SetText(label_checkbox_->checked() ? textfield_->text() : 160 label_->SetText(label_checkbox_->checked() ? textfield_->text() :
161 base::string16()); 161 base::string16());
162 container()->Layout(); 162 container()->Layout();
163 container()->SchedulePaint(); 163 container()->SchedulePaint();
164 } 164 }
165 165
166 } // namespace examples 166 } // namespace examples
167 } // namespace views 167 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/label_example.cc ('k') | ui/views/examples/scroll_view_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698