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

Side by Side Diff: ui/views/examples/text_example.cc

Issue 9864048: Add a border to views_examples' text styles example. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | « no previous file | no next file » | 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/examples/text_example.h" 5 #include "ui/views/examples/text_example.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/views/controls/button/checkbox.h" 10 #include "ui/views/controls/button/checkbox.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 : font_(ResourceBundle::GetSharedInstance().GetFont( 93 : font_(ResourceBundle::GetSharedInstance().GetFont(
94 ResourceBundle::BaseFont)), 94 ResourceBundle::BaseFont)),
95 text_(ASCIIToUTF16(kShortText)), 95 text_(ASCIIToUTF16(kShortText)),
96 text_flags_(0), 96 text_flags_(0),
97 halo_(false), 97 halo_(false),
98 fade_(false), 98 fade_(false),
99 fade_mode_(gfx::Canvas::TruncateFadeTail) { 99 fade_mode_(gfx::Canvas::TruncateFadeTail) {
100 } 100 }
101 101
102 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 102 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
103 View::OnPaint(canvas);
104
105 const gfx::Rect bounds = GetContentsBounds();
106
103 #if defined(OS_WIN) 107 #if defined(OS_WIN)
104 if (fade_) { 108 if (fade_) {
105 size_t characters_to_truncate_from_head = 109 size_t characters_to_truncate_from_head =
106 gfx::Canvas::TruncateFadeHeadAndTail ? 10 : 0; 110 gfx::Canvas::TruncateFadeHeadAndTail ? 10 : 0;
107 canvas->DrawFadeTruncatingString(text_, fade_mode_, 111 canvas->DrawFadeTruncatingString(text_, fade_mode_,
108 characters_to_truncate_from_head, font_, SK_ColorDKGRAY, 112 characters_to_truncate_from_head, font_, SK_ColorDKGRAY, bounds);
109 GetLocalBounds());
110 return; 113 return;
111 } 114 }
112 #endif 115 #endif
113 116
114 if (halo_) { 117 if (halo_) {
115 canvas->DrawStringWithHalo(text_, font_, SK_ColorDKGRAY, SK_ColorWHITE, 0, 118 canvas->DrawStringWithHalo(text_, font_, SK_ColorDKGRAY, SK_ColorWHITE,
116 0, width(), height(), text_flags_); 119 bounds.x(), bounds.y(), bounds.width(), bounds.height(), text_flags_);
117 } else { 120 } else {
118 canvas->DrawStringInt(text_, font_, SK_ColorDKGRAY, 0, 0, width(), 121 canvas->DrawStringInt(text_, font_, SK_ColorDKGRAY, bounds.x(),
119 height(), text_flags_); 122 bounds.y(), bounds.width(), bounds.height(), text_flags_);
120 } 123 }
121 } 124 }
122 125
123 int text_flags() const { return text_flags_; } 126 int text_flags() const { return text_flags_; }
124 void set_text_flags(int text_flags) { text_flags_ = text_flags; } 127 void set_text_flags(int text_flags) { text_flags_ = text_flags; }
125 128
126 const string16& text() const { return text_; } 129 const string16& text() const { return text_; }
127 void set_text(const string16& text) { text_ = text; } 130 void set_text(const string16& text) { text_ = text; }
128 131
129 bool halo() const { return halo_; } 132 bool halo() const { return halo_; }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 example_combobox_model_.push_back(new_model); 194 example_combobox_model_.push_back(new_model);
192 Combobox* combo_box = new Combobox(new_model); 195 Combobox* combo_box = new Combobox(new_model);
193 combo_box->SetSelectedItem(0); 196 combo_box->SetSelectedItem(0);
194 combo_box->set_listener(this); 197 combo_box->set_listener(this);
195 layout->AddView(combo_box, kNumColumns - 1, 1); 198 layout->AddView(combo_box, kNumColumns - 1, 1);
196 return combo_box; 199 return combo_box;
197 } 200 }
198 201
199 void TextExample::CreateExampleView(View* container) { 202 void TextExample::CreateExampleView(View* container) {
200 text_view_ = new TextExampleView; 203 text_view_ = new TextExampleView;
204 text_view_->set_border(views::Border::CreateSolidBorder(1, SK_ColorGRAY));
201 205
202 GridLayout* layout = new GridLayout(container); 206 GridLayout* layout = new GridLayout(container);
203 container->SetLayoutManager(layout); 207 container->SetLayoutManager(layout);
204 208
205 layout->AddPaddingRow(0, 8); 209 layout->AddPaddingRow(0, 8);
206 210
207 ColumnSet* column_set = layout->AddColumnSet(0); 211 ColumnSet* column_set = layout->AddColumnSet(0);
208 column_set->AddPaddingColumn(0, 8); 212 column_set->AddPaddingColumn(0, 8);
209 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 213 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
210 0.1f, GridLayout::USE_PREF, 0, 0); 214 0.1f, GridLayout::USE_PREF, 0, 0);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 text_flags |= gfx::Canvas::HIDE_PREFIX; 367 text_flags |= gfx::Canvas::HIDE_PREFIX;
364 break; 368 break;
365 } 369 }
366 } 370 }
367 text_view_->set_text_flags(text_flags); 371 text_view_->set_text_flags(text_flags);
368 text_view_->SchedulePaint(); 372 text_view_->SchedulePaint();
369 } 373 }
370 374
371 } // namespace examples 375 } // namespace examples
372 } // namespace views 376 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698