// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/views/examples/textfield_example.h" #include #include #include #include "base/strings/utf_string_conversions.h" #include "ui/base/l10n/l10n_util.h" #include "ui/events/event.h" #include "ui/gfx/color_palette.h" #include "ui/gfx/range/range.h" #include "ui/gfx/render_text.h" #include "ui/views/controls/button/label_button.h" #include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/examples/examples_window.h" #include "ui/views/examples/grit/views_examples_resources.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/view.h" using l10n_util::GetStringUTF16; using l10n_util::GetStringUTF8; namespace views { namespace examples { namespace { template T* MakeRow(GridLayout* layout, std::unique_ptr view1, std::unique_ptr view2) { layout->StartRowWithPadding(0, 0, 0, 5); if (view1) layout->AddView(std::move(view1)); return layout->AddView(std::move(view2)); } } // namespace TextfieldExample::TextfieldExample() : ExampleBase(GetStringUTF8(IDS_TEXTFIELD_SELECT_LABEL).c_str()) {} TextfieldExample::~TextfieldExample() = default; void TextfieldExample::CreateExampleView(View* container) { auto name = std::make_unique(); name->set_controller(this); auto password = std::make_unique(); password->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); password->SetPlaceholderText( GetStringUTF16(IDS_TEXTFIELD_PASSWORD_PLACEHOLDER)); password->set_controller(this); auto disabled = std::make_unique(); disabled->SetEnabled(false); disabled->SetText(GetStringUTF16(IDS_TEXTFIELD_DISABLED_PLACEHOLDER)); auto read_only = std::make_unique(); read_only->SetReadOnly(true); read_only->SetText(GetStringUTF16(IDS_TEXTFFIELD_READ_ONLY_PLACEHOLDER)); auto invalid = std::make_unique(); invalid->SetInvalid(true); auto rtl = std::make_unique(); rtl->ChangeTextDirectionAndLayoutAlignment(base::i18n::RIGHT_TO_LEFT); GridLayout* layout = container->SetLayoutManager(std::make_unique()); ColumnSet* column_set = layout->AddColumnSet(0); column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0.2f, GridLayout::ColumnSize::kUsePreferred, 0, 0); column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0.8f, GridLayout::ColumnSize::kUsePreferred, 0, 0); name_ = MakeRow( layout, std::make_unique