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

Unified Diff: ui/views/examples/multiline_example.cc

Issue 16867016: Windows implementation of multiline RenderText (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix ComputeLines and rects Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« ui/gfx/render_text_win.cc ('K') | « ui/views/examples/multiline_example.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/examples/multiline_example.cc
diff --git a/ui/views/examples/multiline_example.cc b/ui/views/examples/multiline_example.cc
index 04fdde7c96b916cdfae5c174ff0abe07210bb0dd..be9d9dc4adcb70f2a16d6603685574f237d0c644 100644
--- a/ui/views/examples/multiline_example.cc
+++ b/ui/views/examples/multiline_example.cc
@@ -7,8 +7,10 @@
#include "base/strings/utf_string_conversions.h"
#include "ui/base/events/event.h"
#include "ui/gfx/render_text.h"
+#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
+#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/view.h"
@@ -20,7 +22,9 @@ class MultilineExample::RenderTextView : public View {
public:
explicit RenderTextView(gfx::RenderText* render_text)
: render_text_(render_text) {
+ render_text->SetHorizontalAlignment(gfx::ALIGN_CENTER);
render_text_->SetColor(SK_ColorBLACK);
+ render_text_->set_multiline(true);
set_border(Border::CreateSolidBorder(2, SK_ColorGRAY));
}
@@ -30,12 +34,19 @@ class MultilineExample::RenderTextView : public View {
}
virtual gfx::Size GetPreferredSize() OVERRIDE {
- return gfx::Size(0,
- render_text_->GetFont().GetHeight() + GetInsets().height());
+ return gfx::Size(render_text_->GetMultilineTextSize().width(),
msw 2013/07/10 04:01:56 This probably creates an odd feedback loop, since
ckocagil 2013/07/13 16:05:10 Done except for the newline characters: this class
+ render_text_->GetMultilineTextSize().height() +
+ GetInsets().height());
}
void SetText(const string16& new_contents) {
render_text_->SetText(new_contents);
+ render_text_->MoveCursorTo(gfx::SelectionModel(ui::Range(1, 11),
Alexei Svitkine (slow) 2013/07/09 15:35:13 Nit: Extract the range to a local variable.
ckocagil 2013/07/13 16:05:10 Done.
+ gfx::CURSOR_FORWARD));
+ render_text_->set_selection_background_focused_color(0xFFFF0000);
+ render_text_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, ui::Range(1, 11));
+ render_text_->ApplyStyle(gfx::UNDERLINE, true, ui::Range(1, 11));
+ InvalidateLayout();
SchedulePaint();
}
@@ -44,6 +55,7 @@ class MultilineExample::RenderTextView : public View {
gfx::Rect bounds = GetLocalBounds();
bounds.Inset(GetInsets());
render_text_->SetDisplayRect(bounds);
+ InvalidateLayout();
}
scoped_ptr<gfx::RenderText> render_text_;
@@ -53,8 +65,11 @@ class MultilineExample::RenderTextView : public View {
MultilineExample::MultilineExample()
: ExampleBase("Multiline RenderText"),
+ container_(NULL),
render_text_view_(NULL),
label_(NULL),
+ label_container_(NULL),
+ label_checkbox_(NULL),
textfield_(NULL) {
}
@@ -65,17 +80,27 @@ void MultilineExample::CreateExampleView(View* container) {
const char kTestString[] = "test string asdf 1234 test string asdf 1234 "
"test string asdf 1234 test string asdf 1234";
+ container_ = container;
+
gfx::RenderText* render_text = gfx::RenderText::CreateInstance();
- render_text->SetText(ASCIIToUTF16(kTestString));
- render_text->SetHorizontalAlignment(gfx::ALIGN_CENTER);
render_text_view_ = new RenderTextView(render_text);
+ render_text_view_->SetText(ASCIIToUTF16(kTestString));
label_ = new Label();
label_->SetText(ASCIIToUTF16(kTestString));
label_->SetMultiLine(true);
label_->set_border(Border::CreateSolidBorder(2, SK_ColorCYAN));
+ label_container_ = new View;
+ label_container_->SetLayoutManager(new FillLayout);
+ label_container_->AddChildView(label_);
+
+ label_checkbox_ = new Checkbox(string16());
+ label_checkbox_->SetChecked(true);
+ label_checkbox_->set_listener(this);
+ label_checkbox_->set_request_focus_on_press(false);
+
textfield_ = new Textfield();
textfield_->SetController(this);
textfield_->SetText(ASCIIToUTF16(kTestString));
@@ -86,18 +111,23 @@ void MultilineExample::CreateExampleView(View* container) {
ColumnSet* column_set = layout->AddColumnSet(0);
column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
0.0f, GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
+ 0.0f, GridLayout::USE_PREF, 0, 0);
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL,
1.0f, GridLayout::FIXED, 0, 0);
layout->StartRow(0, 0);
+ layout->AddView(new View);
layout->AddView(new Label(ASCIIToUTF16("gfx::RenderText:")));
layout->AddView(render_text_view_);
layout->StartRow(0, 0);
+ layout->AddView(label_checkbox_);
layout->AddView(new Label(ASCIIToUTF16("views::Label:")));
- layout->AddView(label_);
+ layout->AddView(label_container_);
layout->StartRow(0, 0);
+ layout->AddView(new View);
layout->AddView(new Label(ASCIIToUTF16("Sample Text:")));
layout->AddView(textfield_);
}
@@ -106,6 +136,8 @@ void MultilineExample::ContentsChanged(Textfield* sender,
const string16& new_contents) {
render_text_view_->SetText(new_contents);
label_->SetText(new_contents);
+ container_->Layout();
+ container_->SchedulePaint();
}
bool MultilineExample::HandleKeyEvent(Textfield* sender,
@@ -113,5 +145,20 @@ bool MultilineExample::HandleKeyEvent(Textfield* sender,
return false;
}
+void MultilineExample::ButtonPressed(Button* sender, const ui::Event& event) {
+ if (sender != label_checkbox_)
+ return;
+ if (label_checkbox_->checked()) {
+ label_container_->RemoveAllChildViews(true);
+ label_container_->AddChildView(label_);
+ } else {
+ label_container_->RemoveAllChildViews(false);
+ label_container_->AddChildView(new View);
+ }
+ container_->Layout(); // TODO: we seem to require laying out twice. why?
Alexei Svitkine (slow) 2013/07/09 15:35:13 TODO -> TODO(ckocagil) Also, consider filing a bu
ckocagil 2013/07/13 16:05:10 Done. I don't think I will forget this, resolving
+ container_->Layout();
+ container_->SchedulePaint();
+}
+
} // namespace examples
} // namespace views
« ui/gfx/render_text_win.cc ('K') | « ui/views/examples/multiline_example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698