diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 01:08:44 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 01:08:44 +0000 |
commit | c9408bca7cc3e45ab12bff6b3c4d554e4414c903 (patch) | |
tree | 26aa96dbbcc7fa1b91ed46716311b2dd7bcd8e22 | |
parent | 7e9e8584da57a63465cd9619fb023a427e8d6bfe (diff) | |
download | chromium_src-c9408bca7cc3e45ab12bff6b3c4d554e4414c903.zip chromium_src-c9408bca7cc3e45ab12bff6b3c4d554e4414c903.tar.gz chromium_src-c9408bca7cc3e45ab12bff6b3c4d554e4414c903.tar.bz2 |
* Password style support for gtk's textfield impl.
* Added x11 dependency to view_examples. Looks like dependency has changed a bit.
BUG=none
TEST=build & run view_examples target.
Review URL: http://codereview.chromium.org/270032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28501 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.cc | 7 | ||||
-rw-r--r-- | views/examples/examples_main_base.cc | 2 | ||||
-rw-r--r-- | views/examples/textfield_example.h | 76 | ||||
-rw-r--r-- | views/views.gyp | 2 |
4 files changed, 87 insertions, 0 deletions
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index ebaa614..9704e7e 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -12,6 +12,8 @@ #include "views/controls/textfield/textfield.h" namespace views { +// A character used to hide a text in password mode. +const char kPasswordChar = '*'; //////////////////////////////////////////////////////////////////////////////// // NativeTextfieldGtk, public: @@ -229,6 +231,11 @@ gboolean NativeTextfieldGtk::OnChanged() { void NativeTextfieldGtk::CreateNativeControl() { NativeControlCreated(gtk_entry_new()); + if (textfield_->IsPassword()) { + gtk_entry_set_invisible_char(GTK_ENTRY(native_view()), + static_cast<gunichar>(kPasswordChar)); + gtk_entry_set_visibility(GTK_ENTRY(native_view()), false); + } } void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { diff --git a/views/examples/examples_main_base.cc b/views/examples/examples_main_base.cc index b407347..9a1644b 100644 --- a/views/examples/examples_main_base.cc +++ b/views/examples/examples_main_base.cc @@ -20,6 +20,7 @@ #include "views/examples/radio_button_example.h" #include "views/examples/scroll_view_example.h" #include "views/examples/tabbed_pane_example.h" +#include "views/examples/textfield_example.h" namespace examples { @@ -70,6 +71,7 @@ void ExamplesMainBase::Run() { layout->StartRow(0 /* no expand */, 0); layout->AddView(message); + TextfieldExample textfield_example(tabbed_pane, message); ButtonExample button_example(tabbed_pane, message); ComboboxExample combobox_example(tabbed_pane, message); TabbedPaneExample tabbed_pane_example(tabbed_pane, message); diff --git a/views/examples/textfield_example.h b/views/examples/textfield_example.h new file mode 100644 index 0000000..75e3e7f --- /dev/null +++ b/views/examples/textfield_example.h @@ -0,0 +1,76 @@ +// Copyright (c) 2009 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. + +#ifndef VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ +#define VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ + +#include "base/string_util.h" +#include "views/controls/label.h" +#include "views/controls/tabbed_pane/tabbed_pane.h" +#include "views/controls/textfield/textfield.h" +#include "views/examples/example_base.h" + +namespace examples { + +using views::Textfield; + +// TextfieldExample mimics login screen. +class TextfieldExample : protected ExampleBase, + public Textfield::Controller { + public: + TextfieldExample(views::TabbedPane* tabbed_pane, views::Label* message) + : ExampleBase(message), + name_(new Textfield()), + password_(new Textfield(Textfield::STYLE_PASSWORD)) { + name_->SetController(this); + password_->SetController(this); + + views::View* container = new views::View(); + tabbed_pane->AddTab(L"Textfield", container); + views::GridLayout* layout = new views::GridLayout(container); + container->SetLayoutManager(layout); + + views::ColumnSet* column_set = layout->AddColumnSet(0); + column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, + 0.2f, views::GridLayout::USE_PREF, 0, 0); + column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, + 0.8f, views::GridLayout::USE_PREF, 0, 0); + layout->StartRow(0, 0); + layout->AddView(new views::Label(L"Name:")); + layout->AddView(name_); + layout->StartRow(0, 0); + layout->AddView(new views::Label(L"Password:")); + layout->AddView(password_); + } + + virtual ~TextfieldExample() {} + + private: + // Textfield::Controller implementations: + // This method is called whenever the text in the field changes. + virtual void ContentsChanged(Textfield* sender, + const string16& new_contents) { + if (sender == name_) { + PrintStatus(L"Name [%ls]", UTF16ToWideHack(new_contents).c_str()); + } else if (sender == password_) { + PrintStatus(L"Password [%ls]", UTF16ToWideHack(new_contents).c_str()); + } + } + + // Let the control handle keystrokes. + virtual bool HandleKeystroke(Textfield* sender, + const Textfield::Keystroke& keystroke) { + return false; + } + + // Textfields for name and password. + views::Textfield* name_, *password_; + + DISALLOW_COPY_AND_ASSIGN(TextfieldExample); +}; + +} // namespace examples + +#endif // VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_ + diff --git a/views/views.gyp b/views/views.gyp index 5fb4279..56cfdf3 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -349,6 +349,7 @@ 'dependencies': [ '../base/base.gyp:base', '../skia/skia.gyp:skia', + '../build/linux/system.gyp:x11', 'views', ], 'include_dirs': [ @@ -365,6 +366,7 @@ 'examples/message_box_example.h', 'examples/radio_button_example.h', 'examples/tabbed_pane_example.h', + 'examples/textfield_example.h', ], 'conditions': [ ['OS=="linux"', { |