Index: ui/views/examples/multiline_example.cc |
diff --git a/ui/views/examples/multiline_example.cc b/ui/views/examples/multiline_example.cc |
index 858b739be8d7df8abe83c82d4f94f075dbc530b0..15e78c0d3ed935a0bb323a766530e39bcd712c0e 100644 |
--- a/ui/views/examples/multiline_example.cc |
+++ b/ui/views/examples/multiline_example.cc |
@@ -9,7 +9,6 @@ |
#include "base/macros.h" |
#include "base/strings/utf_string_conversions.h" |
#include "ui/events/event.h" |
-#include "ui/gfx/render_text.h" |
#include "ui/views/background.h" |
#include "ui/views/border.h" |
#include "ui/views/controls/button/checkbox.h" |
@@ -48,85 +47,83 @@ class PreferredSizeLabel : public Label { |
} // namespace |
-// A simple View that hosts a RenderText object. |
-class MultilineExample::RenderTextView : public View { |
- public: |
- RenderTextView() : render_text_(gfx::RenderText::CreateInstanceForEditing()) { |
- render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
- render_text_->SetColor(SK_ColorBLACK); |
- render_text_->SetMultiline(true); |
- SetBorder(Border::CreateSolidBorder(2, SK_ColorGRAY)); |
- } |
- |
- void OnPaint(gfx::Canvas* canvas) override { |
- View::OnPaint(canvas); |
- render_text_->Draw(canvas); |
- } |
+MultilineExample::RenderTextView::RenderTextView() |
+ : render_text_(gfx::RenderText::CreateInstanceForEditing()) { |
+ render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
+ render_text_->SetColor(SK_ColorBLACK); |
+ render_text_->SetMultiline(true); |
+ SetBorder(Border::CreateSolidBorder(2, SK_ColorGRAY)); |
+} |
- gfx::Size GetPreferredSize() const override { |
- // Turn off multiline mode to get the single-line text size, which is the |
- // preferred size for this view. |
- render_text_->SetMultiline(false); |
- gfx::Size size(render_text_->GetContentWidth(), |
- render_text_->GetStringSize().height()); |
- size.Enlarge(GetInsets().width(), GetInsets().height()); |
- render_text_->SetMultiline(true); |
- return size; |
- } |
+MultilineExample::RenderTextView::~RenderTextView() {} |
+ |
+void MultilineExample::RenderTextView::SetText( |
+ const base::string16& new_contents) { |
+ // Color and style the text inside |test_range| to test colors and styles. |
+ const size_t range_max = new_contents.length(); |
+ gfx::Range color_range = ClampRange(gfx::Range(1, 21), range_max); |
+ gfx::Range bold_range = ClampRange(gfx::Range(4, 10), range_max); |
+ gfx::Range italic_range = ClampRange(gfx::Range(7, 13), range_max); |
+ |
+ render_text_->SetText(new_contents); |
+ render_text_->SetColor(SK_ColorBLACK); |
+ render_text_->ApplyColor(0xFFFF0000, color_range); |
+ render_text_->SetStyle(gfx::DIAGONAL_STRIKE, false); |
+ render_text_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, color_range); |
tapted
2016/05/10 08:45:53
One big factor seems to be these 4 "ApplyStyle" ca
|
+ render_text_->SetStyle(gfx::UNDERLINE, false); |
+ render_text_->ApplyStyle(gfx::UNDERLINE, true, color_range); |
+ render_text_->ApplyStyle(gfx::BOLD, true, bold_range); |
+ render_text_->ApplyStyle(gfx::ITALIC, true, italic_range); |
+ InvalidateLayout(); |
+} |
- int GetHeightForWidth(int w) const override { |
- // TODO(ckocagil): Why does this happen? |
- if (w == 0) |
- return View::GetHeightForWidth(w); |
- const gfx::Rect old_rect = render_text_->display_rect(); |
- gfx::Rect rect = old_rect; |
- rect.set_width(w - GetInsets().width()); |
- render_text_->SetDisplayRect(rect); |
- int height = render_text_->GetStringSize().height() + GetInsets().height(); |
- render_text_->SetDisplayRect(old_rect); |
- return height; |
- } |
+void MultilineExample::RenderTextView::OnPaint(gfx::Canvas* canvas) { |
+ View::OnPaint(canvas); |
+ render_text_->Draw(canvas); |
+} |
- void SetText(const base::string16& new_contents) { |
- // Color and style the text inside |test_range| to test colors and styles. |
- const size_t range_max = new_contents.length(); |
- gfx::Range color_range = ClampRange(gfx::Range(1, 21), range_max); |
- gfx::Range bold_range = ClampRange(gfx::Range(4, 10), range_max); |
- gfx::Range italic_range = ClampRange(gfx::Range(7, 13), range_max); |
- |
- render_text_->SetText(new_contents); |
- render_text_->SetColor(SK_ColorBLACK); |
- render_text_->ApplyColor(0xFFFF0000, color_range); |
- render_text_->SetStyle(gfx::DIAGONAL_STRIKE, false); |
- render_text_->ApplyStyle(gfx::DIAGONAL_STRIKE, true, color_range); |
- render_text_->SetStyle(gfx::UNDERLINE, false); |
- render_text_->ApplyStyle(gfx::UNDERLINE, true, color_range); |
- render_text_->ApplyStyle(gfx::BOLD, true, bold_range); |
- render_text_->ApplyStyle(gfx::ITALIC, true, italic_range); |
- InvalidateLayout(); |
- } |
+gfx::Size MultilineExample::RenderTextView::GetPreferredSize() const { |
+ // Turn off multiline mode to get the single-line text size, which is the |
+ // preferred size for this view. |
+ render_text_->SetMultiline(false); |
+ gfx::Size size(render_text_->GetContentWidth(), |
+ render_text_->GetStringSize().height()); |
+ size.Enlarge(GetInsets().width(), GetInsets().height()); |
+ render_text_->SetMultiline(true); |
+ return size; |
+} |
- private: |
- void OnBoundsChanged(const gfx::Rect& previous_bounds) override { |
- gfx::Rect bounds = GetLocalBounds(); |
- bounds.Inset(GetInsets()); |
- render_text_->SetDisplayRect(bounds); |
- } |
+int MultilineExample::RenderTextView::GetHeightForWidth(int w) const { |
+ // TODO(ckocagil): Why does this happen? |
+ if (w == 0) |
+ return View::GetHeightForWidth(w); |
+ const gfx::Rect old_rect = render_text_->display_rect(); |
+ gfx::Rect rect = old_rect; |
+ rect.set_width(w - GetInsets().width()); |
+ render_text_->SetDisplayRect(rect); |
+ int height = render_text_->GetStringSize().height() + GetInsets().height(); |
+ render_text_->SetDisplayRect(old_rect); |
+ return height; |
+} |
- std::unique_ptr<gfx::RenderText> render_text_; |
+void MultilineExample::RenderTextView::OnBoundsChanged( |
+ const gfx::Rect& previous_bounds) { |
+ gfx::Rect bounds = GetLocalBounds(); |
+ bounds.Inset(GetInsets()); |
+ render_text_->SetDisplayRect(bounds); |
+} |
- DISALLOW_COPY_AND_ASSIGN(RenderTextView); |
-}; |
+MultilineExample::MultilineExample(const char* name) |
+ : ExampleBase(name), |
+ render_text_view_(nullptr), |
+ label_(nullptr), |
+ textfield_(nullptr), |
+ label_checkbox_(nullptr) {} |
-MultilineExample::MultilineExample() |
- : ExampleBase("Multiline RenderText"), |
- render_text_view_(NULL), |
- label_(NULL), |
- textfield_(NULL), |
- label_checkbox_(NULL) { |
-} |
+MultilineExample::~MultilineExample() {} |
-MultilineExample::~MultilineExample() { |
+MultilineExample::RenderTextView* MultilineExample::CreateTextView() { |
+ return new RenderTextView(); |
} |
void MultilineExample::CreateExampleView(View* container) { |
@@ -134,7 +131,7 @@ void MultilineExample::CreateExampleView(View* container) { |
L"\x627\x644\x631\x626\x64A\x633\x64A\x629" |
L"asdfgh"); |
- render_text_view_ = new RenderTextView(); |
+ render_text_view_ = CreateTextView(); |
render_text_view_->SetText(kTestString); |
label_ = new PreferredSizeLabel(); |